~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/metadata/xmpdump.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* simple program to test the XMP parser on files given on the command line */
 
2
 
 
3
#include <stdio.h>
 
4
#include <string.h>
 
5
#include <glib/gprintf.h>
 
6
#include "xmp-parse.h"
 
7
 
 
8
static gpointer
 
9
start_schema (XMPParseContext     *context,
 
10
              const gchar         *ns_uri,
 
11
              const gchar         *ns_prefix,
 
12
              gpointer             user_data,
 
13
              GError             **error)
 
14
{
 
15
  g_print ("Schema %s = \"%s\"\n", ns_prefix, ns_uri);
 
16
  return (gpointer) ns_prefix;
 
17
}
 
18
 
 
19
static void
 
20
end_schema (XMPParseContext     *context,
 
21
            gpointer             user_ns_data,
 
22
            gpointer             user_data,
 
23
            GError             **error)
 
24
{
 
25
  /* g_print ("End of %s\n", user_ns_prefix); */
 
26
}
 
27
 
 
28
static void
 
29
set_property (XMPParseContext     *context,
 
30
              const gchar         *name,
 
31
              XMPParseType         type,
 
32
              const gchar        **value,
 
33
              gpointer             user_ns_data,
 
34
              gpointer             user_data,
 
35
              GError             **error)
 
36
{
 
37
  const gchar *ns_prefix = user_ns_data;
 
38
  int          i;
 
39
 
 
40
  switch (type)
 
41
    {
 
42
    case XMP_PTYPE_TEXT:
 
43
      g_print ("\t%s:%s = \"%s\"\n", ns_prefix, name,
 
44
               value[0]);
 
45
      break;
 
46
 
 
47
    case XMP_PTYPE_RESOURCE:
 
48
      g_print ("\t%s:%s @ = \"%s\"\n", ns_prefix, name,
 
49
               value[0]);
 
50
      break;
 
51
 
 
52
    case XMP_PTYPE_ORDERED_LIST:
 
53
    case XMP_PTYPE_UNORDERED_LIST:
 
54
      g_print ("\t%s:%s [] =", ns_prefix, name);
 
55
      for (i = 0; value[i] != NULL; i++)
 
56
        if (i == 0)
 
57
          g_print (" \"%s\"", value[i]);
 
58
      else
 
59
          g_print (", \"%s\"", value[i]);
 
60
      g_print ("\n");
 
61
      break;
 
62
 
 
63
    case XMP_PTYPE_ALT_THUMBS:
 
64
      for (i = 0; value[i] != NULL; i += 2)
 
65
        g_print ("\t%s:%s [size = %d] = \"...\"\n", ns_prefix, name,
 
66
                 *(int*)(value[i])); /* FIXME: show part of image */
 
67
      break;
 
68
 
 
69
    case XMP_PTYPE_ALT_LANG:
 
70
      for (i = 0; value[i] != NULL; i += 2)
 
71
        g_print ("\t%s:%s [lang:%s] = \"%s\"\n", ns_prefix, name,
 
72
                 value[i], value[i + 1]);
 
73
      break;
 
74
 
 
75
    case XMP_PTYPE_STRUCTURE:
 
76
      g_print ("\tLocal schema %s = \"%s\"\n", value[0], value[1]);
 
77
      for (i = 2; value[i] != NULL; i += 2)
 
78
        g_print ("\t%s:%s [%s] = \"%s\"\n", ns_prefix, name,
 
79
                 value[i], value[i + 1]);
 
80
      break;
 
81
 
 
82
    default:
 
83
      g_print ("\t%s:%s = ?\n", ns_prefix, name);
 
84
      break;
 
85
    }
 
86
}
 
87
 
 
88
static void
 
89
print_error (XMPParseContext *context,
 
90
             GError          *error,
 
91
             gpointer         user_data)
 
92
{
 
93
  gchar *filename = user_data;
 
94
 
 
95
  g_printerr ("While parsing XMP metadata in %s:\n%s\n",
 
96
              filename, error->message);
 
97
}
 
98
 
 
99
static XMPParser xmp_parser = {
 
100
  start_schema,
 
101
  end_schema,
 
102
  set_property,
 
103
  print_error
 
104
};
 
105
 
 
106
static int
 
107
scan_file (const gchar *filename)
 
108
{
 
109
  gchar *contents;
 
110
  gsize  length;
 
111
  GError *error;
 
112
  XMPParseContext *context;
 
113
 
 
114
  g_print ("\nFile: %s\n", filename);
 
115
  error = NULL;
 
116
  if (!g_file_get_contents (filename,
 
117
                            &contents,
 
118
                            &length,
 
119
                            &error))
 
120
    {
 
121
      print_error (NULL, error, (gpointer) filename);
 
122
      g_error_free (error);
 
123
      return 1;
 
124
    }
 
125
 
 
126
  context = xmp_parse_context_new (&xmp_parser,
 
127
                                   XMP_FLAG_FIND_XPACKET,
 
128
                                   (gpointer) filename,
 
129
                                   NULL);
 
130
 
 
131
  if (! xmp_parse_context_parse (context, contents, length, NULL))
 
132
    {
 
133
      xmp_parse_context_free (context);
 
134
      return 1;
 
135
    }
 
136
 
 
137
  if (! xmp_parse_context_end_parse (context, NULL))
 
138
    {
 
139
      xmp_parse_context_free (context);
 
140
      return 1;
 
141
    }
 
142
 
 
143
  xmp_parse_context_free (context);
 
144
  return 0;
 
145
}
 
146
 
 
147
int
 
148
main (int   argc,
 
149
      char *argv[])
 
150
{
 
151
  g_set_prgname ("xmpdump");
 
152
  if (argc > 1)
 
153
    {
 
154
      for (argv++, argc--; argc; argv++, argc--)
 
155
        if (scan_file (*argv) != 0)
 
156
          return 1;
 
157
      return 0;
 
158
    }
 
159
  else
 
160
    {
 
161
      g_print ("Usage:\n"
 
162
               "\txmpdump file [file [...]]\n\n"
 
163
               "The file(s) given on the command line will be scanned "
 
164
               "for XMP metadata\n");
 
165
      return 1;
 
166
    }
 
167
}