~ubuntu-branches/ubuntu/raring/exif/raring

« back to all changes in this revision

Viewing changes to exif/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Emmanuel Bouthenot
  • Date: 2008-03-31 19:39:44 UTC
  • mfrom: (4.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080331193944-xndxlofl9m7h7a83
Tags: 0.6.15-5
* Adopt the package within pkg-phototools:
  - Set the Maintainer to the group
  - Add Frederic Peters and myself as Uploaders.
  - Add Vcs-Browser and Vcs-Git fields accordingly.
* debian/control:
  - Add a Homepage field.
  - Update Standards-Version to 3.7.3
  - Fix build dep version for libexif-dev.
  - Add build dep on quilt for patches extracted from package diff.
  - Add build dep on gettext for swedish translation.
* debian/copyright:
  - convert file to utf-8.
  - Point to LGPL-2 rather than just LGPL, which now points to
    LGPL-3.
* debian/rules
  - Fix autotools timestamp issues which causes FTBFS (closes: #445609)
  - Fix lintian 'clean error' warning.
* debian/patches
  - Extract swedish translation patch from package diff (cf. bug 397370).
  - Extract patch related to default ifd from package diff (cf. bug 428255).
  - Extract patch related to manpage improvements from package diff (cf.
    bugs 320497 and 321855).

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * Boston, MA 02111-1307, USA.
19
19
 */
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
22
22
 
23
23
#include <errno.h>
24
24
#include <stdlib.h>
26
26
#include <string.h>
27
27
#include <popt.h>
28
28
 
 
29
#ifdef HAVE_UNISTD_H
 
30
#  include <unistd.h>
 
31
#endif
 
32
 
29
33
#include <libexif/exif-data.h>
30
34
#include <libexif/exif-utils.h>
31
35
#include <libexif/exif-loader.h>
36
40
#include "exif-i18n.h"
37
41
#include "utils.h"
38
42
 
39
 
#ifdef HAVE_LOCAL_H
 
43
#ifdef HAVE_LOCALE_H
40
44
#  include <locale.h>
41
45
#endif
42
46
 
49
53
internal_error (void)
50
54
{
51
55
        fprintf (stderr, _("Internal error. Please "
52
 
                           "contact <libexif-devel@"
53
 
                           "lists.sourceforge.net>."));
 
56
                           "contact <%s>.)"),
 
57
                 PACKAGE_BUGREPORT);
54
58
        fputc ('\n', stderr);
55
59
        exit (1);
56
60
}
57
61
 
58
62
static void
59
 
show_entry (ExifEntry *entry, const char *caption)
 
63
show_entry (ExifEntry *entry, unsigned int machine_readable)
60
64
{
 
65
        ExifIfd ifd = exif_entry_get_ifd (entry);
 
66
 
 
67
        if (machine_readable) {
 
68
                char b[1024];
 
69
 
 
70
                fprintf (stdout, "%s\n", C(exif_entry_get_value (entry, b, sizeof (b))));
 
71
                return;
 
72
        }
 
73
 
61
74
        printf (_("EXIF entry '%s' (0x%x, '%s') exists in IFD '%s':"),
62
 
                C(exif_tag_get_title (entry->tag)), entry->tag,
63
 
                C(exif_tag_get_name (entry->tag)), caption);
 
75
                C(exif_tag_get_title_in_ifd (entry->tag, ifd)), entry->tag,
 
76
                C(exif_tag_get_name_in_ifd (entry->tag, ifd)), 
 
77
                C(exif_ifd_get_name (ifd)));
64
78
        printf ("\n");
65
79
 
66
 
        exif_entry_dump(entry, 0);
 
80
        exif_entry_dump (entry, 0);
67
81
}
68
82
 
69
83
static void
70
 
search_entry (ExifData *ed, ExifTag tag)
 
84
search_entry (ExifData *ed, ExifTag tag, unsigned int machine_readable)
71
85
{
72
86
        ExifEntry *entry;
73
87
        unsigned int i;
75
89
        for (i = 0; i < EXIF_IFD_COUNT; i++) {
76
90
                entry = exif_content_get_entry (ed->ifd[i], tag);
77
91
                if (entry)
78
 
                        show_entry (entry, exif_ifd_get_name (i));
 
92
                        show_entry (entry, machine_readable);
79
93
        }
80
94
}
81
95
 
99
113
                        fputc ('\n', stderr);
100
114
                        exit (1);
101
115
                }
102
 
                strcpy (e->data, set_value);
 
116
                strcpy ((char *) e->data, (char *) set_value);
103
117
                return;
104
118
        }
105
119
 
110
124
                const char comp_separ = ' ';
111
125
 
112
126
                begin = value_p;
113
 
                value_p = index (begin, comp_separ);
 
127
                value_p = strchr (begin, comp_separ);
114
128
                if (!value_p) {
115
129
                        if (i != e->components - 1) {
116
130
                                fprintf (stderr, _("Too few components "
122
136
                } else end = value_p++;
123
137
 
124
138
                buf = malloc ((end - begin + 1) * sizeof (char));
125
 
                strncpy (buf, begin, end - begin);
 
139
                strncpy ((char *) buf, (char *) begin, end - begin);
126
140
                buf[end - begin] = '\0';
127
141
 
128
142
                s = exif_format_get_size (e->format);
129
143
                switch (e->format) {
130
144
                case EXIF_FORMAT_ASCII:
131
 
                        internal_error (); /* Previously handled */
 
145
                        internal_error (); /* Previously handled */
132
146
                        break;
133
147
                case EXIF_FORMAT_SHORT:
134
 
                        exif_set_short (e->data + (s * i), o, atoi (buf));
 
148
                        exif_set_short (e->data + (s * i), o, atoi ((char *) buf));
135
149
                        break;
136
150
                case EXIF_FORMAT_LONG:
137
 
                        exif_set_long (e->data + (s * i), o, atol (buf));
 
151
                        exif_set_long (e->data + (s * i), o, atol ((char *) buf));
138
152
                        break;
139
153
                case EXIF_FORMAT_SLONG:
140
 
                        exif_set_slong (e->data + (s * i), o, atol (buf));
 
154
                        exif_set_slong (e->data + (s * i), o, atol ((char *) buf));
141
155
                        break;
142
156
                case EXIF_FORMAT_RATIONAL:
143
157
                case EXIF_FORMAT_SRATIONAL:
147
161
                        fputc ('\n', stderr);
148
162
                        exit (1);
149
163
                }
150
 
 
151
 
                free (buf);
 
164
                free (buf);
 
165
        }
 
166
}
 
167
 
 
168
/* escape codes for output colors */
 
169
#define COL_BLUE   "\033[34m"
 
170
#define COL_GREEN  "\033[32m"
 
171
#define COL_RED    "\033[31m"
 
172
#define COL_NORMAL "\033[0m"
 
173
 
 
174
/* Ensure that we're actuall printing the escape codes to a TTY.
 
175
 * FIXME: We should make sure the terminal can actually understand these
 
176
 *        escape sequences
 
177
 */
 
178
 
 
179
#if defined(HAVE_ISATTY) && defined(HAVE_FILENO)
 
180
#  define file_is_tty(file) (isatty(fileno(file)))
 
181
#else
 
182
#  define file_is_tty(file) (0==1)
 
183
#endif
 
184
 
 
185
#define put_colorstring(file, colorstring) \
 
186
        do { \
 
187
                if (file_is_tty(file)) { \
 
188
                        fputs (colorstring, file); \
 
189
                } \
 
190
        } while (0)
 
191
 
 
192
static void
 
193
log_func_exit (ExifLog *log, ExifLogCode code, const char *domain,
 
194
                const char *format, va_list args, void *data)
 
195
{
 
196
        switch (code) {
 
197
        case -1:
 
198
                put_colorstring (stderr, COL_RED);
 
199
                vfprintf (stderr, format, args);
 
200
                fprintf (stderr, "\n");
 
201
                put_colorstring (stderr, COL_NORMAL);
 
202
                exit (1);
 
203
        case EXIF_LOG_CODE_NO_MEMORY:
 
204
        case EXIF_LOG_CODE_CORRUPT_DATA:
 
205
                put_colorstring (stderr, COL_RED);
 
206
                fprintf (stderr, "%s (%s):\n", exif_log_code_get_title (code), domain);
 
207
                vfprintf (stderr, format, args);
 
208
                fprintf (stderr, "\n");
 
209
                put_colorstring (stderr, COL_NORMAL);
 
210
                exit (1);
 
211
        default:
 
212
                return;
152
213
        }
153
214
}
154
215
 
155
216
static int
156
 
save_exif_data_to_file (ExifData *ed, const char *fname, const char *target)
 
217
save_exif_data_to_file (ExifData *ed, ExifLog *log, 
 
218
                const char *fname, const char *target)
157
219
{
158
220
        JPEGData *jdata;
159
221
        unsigned char *d = NULL;
160
222
        unsigned int ds;
161
223
 
162
 
        /* Parse the JPEG file */
163
 
        jdata = jpeg_data_new_from_file (fname);
164
 
        if (!jdata) {
165
 
                fprintf (stderr, _("Could not parse JPEG file '%s'."),
166
 
                         fname);
167
 
                fputc ('\n', stderr);
168
 
                return (1);
169
 
        }
 
224
        /* Parse the JPEG file. */
 
225
        jdata = jpeg_data_new ();
 
226
        jpeg_data_log (jdata, log);
 
227
        jpeg_data_load_file (jdata, fname);
170
228
 
171
229
        /* Make sure the EXIF data is not too big. */
172
230
        exif_data_save_data (ed, &d, &ds);
192
250
        return (0);
193
251
}
194
252
 
195
 
#define COL_BLUE   "\033[34m"
196
 
#define COL_GREEN  "\033[32m"
197
 
#define COL_RED    "\033[31m"
198
 
#define COL_NORMAL "\033[0m"
199
 
 
200
253
static void
201
254
log_func (ExifLog *log, ExifLogCode code, const char *domain,
202
255
          const char *format, va_list args, void *data)
203
256
{
204
257
        switch (code) {
 
258
        case -1:
 
259
                put_colorstring (stderr, COL_RED);
 
260
                vfprintf (stderr, format, args);
 
261
                fprintf (stderr, "\n");
 
262
                put_colorstring (stderr, COL_NORMAL);
 
263
                exit (1);
205
264
        case EXIF_LOG_CODE_DEBUG:
206
 
                printf (COL_GREEN);
207
 
                printf ("%s: ", domain);
208
 
                vprintf (format, args);
209
 
                printf (COL_NORMAL);
 
265
                put_colorstring (stdout, COL_GREEN);
 
266
                fprintf (stdout, "%s: ", domain);
 
267
                vfprintf (stdout, format, args);
 
268
                put_colorstring (stdout, COL_NORMAL);
210
269
                printf ("\n");
211
270
                break;
212
271
        case EXIF_LOG_CODE_NO_MEMORY:
213
 
                printf (COL_RED);
214
 
                printf ("%s: ", domain);
215
 
                vprintf (format, args);
216
 
                printf (COL_NORMAL);
217
 
                printf ("\n");
 
272
        case EXIF_LOG_CODE_CORRUPT_DATA:
 
273
                put_colorstring (stderr, "\033[31;1m");
 
274
                put_colorstring (stderr, "\033[31;4m");
 
275
                fprintf (stderr, exif_log_code_get_title (code));
 
276
                fprintf (stderr, "\n");
 
277
                put_colorstring (stderr, "\033[;0m");
 
278
                put_colorstring (stderr, COL_RED);
 
279
                fprintf (stderr, exif_log_code_get_message (code));
 
280
                fprintf (stderr, "\n");
 
281
                fprintf (stderr, "%s: ", domain);
 
282
                vfprintf (stderr, format, args);
 
283
                put_colorstring (stderr, COL_NORMAL);
 
284
                fprintf (stderr, "\n");
218
285
                break;
219
286
        default:
220
 
                printf (COL_BLUE);
 
287
                put_colorstring (stdout, COL_BLUE);
221
288
                printf ("%s: ", domain);
222
289
                vprintf (format, args);
223
 
                printf (COL_NORMAL);
 
290
                put_colorstring (stdout, COL_NORMAL);
224
291
                printf ("\n");
225
292
                break;
226
293
        }
239
306
 * these variables belong into main ().
240
307
 */
241
308
static unsigned int list_tags = 0, show_description = 0, machine_readable = 0;
 
309
static unsigned int xml_output = 0;
242
310
static unsigned int extract_thumbnail = 0, remove_thumbnail = 0;
243
311
static unsigned int remove_tag = 0;
244
312
static unsigned int list_mnote = 0, debug = 0;
 
313
static unsigned int show_version = 0;
245
314
static const char *set_value = NULL, *ifd_string = NULL, *tag_string = NULL;
246
 
static ExifIfd ifd = -1;
 
315
static ExifIfd ifd = EXIF_IFD_0;
247
316
static ExifTag tag = 0;
248
317
static ExifOptions eo = {0, 0};
249
318
 
256
325
        const char *ithumbnail = NULL;
257
326
        struct poptOption options[] = {
258
327
                POPT_AUTOHELP
 
328
    {"version", 'v', POPT_ARG_NONE, &show_version, 0,
 
329
      N_("Display software version"), NULL},
259
330
                {"ids", 'i', POPT_ARG_NONE, &eo.use_ids, 0,
260
331
                 N_("Show IDs instead of tag names"), NULL},
261
332
                {"tag", 't', POPT_ARG_STRING, &tag_string, 0,
283
354
                {"machine-readable", 'm', POPT_ARG_NONE, &machine_readable, 0,
284
355
                 N_("Output in a machine-readable (tab delimited) format"),
285
356
                 NULL},
 
357
                {"xml-output", 'x', POPT_ARG_NONE, &xml_output, 0,
 
358
                 N_("Output in a XML format"),
 
359
                 NULL},
286
360
                {"debug", 'd', POPT_ARG_NONE, &debug, 0,
287
361
                 N_("Show debugging messages"), NULL},
288
362
                POPT_TABLEEND};
296
370
#ifdef HAVE_LOCALE_H
297
371
        setlocale (LC_ALL, "");
298
372
#endif
299
 
        bindtextdomain (PACKAGE, EXIF_LOCALEDIR);
 
373
        bindtextdomain (PACKAGE, LOCALEDIR);
300
374
        textdomain (PACKAGE);
301
375
#endif
302
376
 
304
378
        poptSetOtherOptionHelp (ctx, _("[OPTION...] file"));
305
379
        while (poptGetNextOpt (ctx) > 0);
306
380
 
307
 
        if (debug) {
308
 
                log = exif_log_new ();
309
 
                exif_log_set_func (log, log_func, NULL);
310
 
        }
 
381
        /*
 
382
         * When debugging, continue as far as possible. If not, make all errors
 
383
         * fatal.
 
384
         */
 
385
        log = exif_log_new ();
 
386
        exif_log_set_func (log, debug ? log_func : log_func_exit, NULL);
311
387
 
312
 
        /* Any option? */
 
388
        /* Any command line parameters ? */
313
389
        if (argc <= 1) {
314
390
                poptPrintHelp (ctx, stdout, 0);
315
 
                return (0);
 
391
                return (1);
 
392
        }
 
393
 
 
394
  if (show_version) {
 
395
    printf ("%s\n", VERSION);
 
396
    return 0;
 
397
  }
 
398
 
 
399
        if (ifd_string) {
 
400
                ifd = exif_ifd_from_string (ifd_string);
 
401
                if ((ifd < EXIF_IFD_0) || (ifd >= EXIF_IFD_COUNT) ||
 
402
                    !exif_ifd_get_name (ifd))
 
403
                        exif_log (log, -1, "exif", _("Invalid IFD '%s'. Valid IFDs are "
 
404
                                                "'0', '1', 'EXIF', 'GPS', and "
 
405
                                                "'Interoperability'."), ifd_string);
316
406
        }
317
407
 
318
408
        if (tag_string) {
319
409
                tag = exif_tag_from_string (tag_string);
320
 
                if (!tag || !exif_tag_get_name (tag)) {
321
 
                        fprintf (stderr, _("Invalid tag '%s'!"), tag_string);
322
 
                        fputc ('\n', stderr);
323
 
                        return (1);
324
 
                }
 
410
                if (tag == 0xffff)
 
411
                        exif_log (log, -1, "exif", _("Invalid tag '%s'!"), tag_string);
325
412
                eo.tag = tag;
326
413
        }
327
414
 
328
 
        if (ifd_string) {
329
 
                ifd = exif_ifd_from_string (ifd_string);
330
 
                if ((ifd < EXIF_IFD_0) || (ifd >= EXIF_IFD_COUNT) ||
331
 
                    !exif_ifd_get_name (ifd)) {
332
 
                        fprintf (stderr, _("Invalid IFD '%s'. Valid IFDs are "
333
 
                                "'0', '1', 'EXIF', 'GPS', and "
334
 
                                "'Interoperability'."), ifd_string);
335
 
                        fputc ('\n', stderr);
336
 
                        return (1);
337
 
                }
338
 
        }
339
 
 
340
415
        if (show_description) {
341
 
                if (!eo.tag) {
342
 
                        fprintf (stderr, _("Please specify a tag!"));
343
 
                        fputc ('\n', stderr);
344
 
                        return (1);
345
 
                }
 
416
                if (!eo.tag) exif_log (log, -1, "exif", _("Please specify a tag!"));
346
417
                printf (_("Tag '%s' (0x%04x, '%s'): %s"),
347
 
                        C(exif_tag_get_title (eo.tag)), eo.tag,
348
 
                        C(exif_tag_get_name (eo.tag)),
349
 
                        C(exif_tag_get_description (eo.tag)));
 
418
                        C(exif_tag_get_title_in_ifd (eo.tag, ifd)), eo.tag,
 
419
                        C(exif_tag_get_name_in_ifd (eo.tag, ifd)),
 
420
                        C(exif_tag_get_description_in_ifd (eo.tag, ifd)));
350
421
                printf ("\n");
351
422
                return (0);
352
423
        }
366
437
                        exif_loader_write_file (l, *args);
367
438
                        ed = exif_loader_get_data (l);
368
439
                        exif_loader_unref (l);
369
 
                        if (!ed) {
370
 
                                fprintf (stderr, _("'%s' does not "
371
 
                                         "contain EXIF data!"), *args);
372
 
                                fputc ('\n', stderr);
373
 
                                exit (1);
374
 
                        }
 
440
                        if (!ed || ! (ed->data || ed->size ||
 
441
                                                ed->ifd[EXIF_IFD_0]->count ||
 
442
                                                ed->ifd[EXIF_IFD_1]->count ||
 
443
                                                ed->ifd[EXIF_IFD_EXIF]->count ||
 
444
                                                ed->ifd[EXIF_IFD_GPS]->count ||
 
445
                                                ed->ifd[EXIF_IFD_INTEROPERABILITY]->count))
 
446
                                exif_log (log, -1, "exif", _("'%s' does not "
 
447
                                                        "contain EXIF data!"), *args);
375
448
 
376
449
                        /* Where do we save the output? */
377
450
                        memset (fname, 0, sizeof (fname));
385
458
 
386
459
                        if (list_tags) {
387
460
                                action_tag_table (*args, ed);
388
 
                        } else if (tag && !set_value) {
 
461
                        } else if (tag && !set_value && !remove_tag) {
389
462
                                if ((ifd >= EXIF_IFD_0) &&
390
463
                                    (ifd < EXIF_IFD_COUNT)) {
391
464
                                        e = exif_content_get_entry (
392
465
                                                        ed->ifd[ifd], tag);
393
466
                                        if (e)
394
 
                                                show_entry (e, ifd_string);
395
 
                                        else {
396
 
                                                fprintf (stderr, _("IFD '%s' "
397
 
                                                        "does not contain tag "
398
 
                                                        "'%s'."), 
399
 
                                                        ifd_string, tag_string);
400
 
                                                fputc ('\n', stderr);
401
 
                                                return (1);
402
 
                                        }
 
467
                                                show_entry (e, machine_readable);
 
468
                                        else
 
469
                                                exif_log (log, -1, "exif", _("IFD '%s' "
 
470
                                                                        "does not contain tag '%s'."), ifd_string, tag_string);
403
471
                                } else {
404
 
                                        search_entry (ed, eo.tag);
 
472
                                        search_entry (ed, eo.tag, machine_readable);
405
473
                                }
406
474
                        } else if (extract_thumbnail) {
407
475
 
408
476
                                /* No thumbnail? Exit. */
409
 
                                if (!ed->data) {
410
 
                                        fprintf (stderr, _("'%s' does not "
411
 
                                                "contain a thumbnail!"),
412
 
                                                *args);
413
 
                                        fputc ('\n', stderr);
414
 
                                        return (1);
415
 
                                }
 
477
                                if (!ed->data)
 
478
                                        exif_log (log, -1, "exif", _("'%s' does not "
 
479
                                                                "contain a thumbnail!"), *args);
416
480
 
417
481
                                /* Save the thumbnail */
418
482
                                f = fopen (fname, "wb");
419
 
                                if (!f) {
 
483
                                if (!f)
420
484
#ifdef __GNUC__
421
 
                                        fprintf (stderr,
 
485
                                        exif_log (log, -1, "exif",
422
486
                                                _("Could not open '%s' for "
423
487
                                                "writing (%m)!"), fname);
424
488
#else
425
 
                                        fprintf (stderr,
 
489
                                        exif_log (log, -1, "exif", 
426
490
                                                _("Could not open '%s' for "
427
491
                                                "writing (%s)!"), fname,
428
492
                                                strerror (errno));
429
493
#endif
430
 
                                        fputc ('\n', stderr);
431
 
                                        return (1);
432
 
                                }
433
494
                                fwrite (ed->data, 1, ed->size, f);
434
495
                                fclose (f);
435
496
                                fprintf (stdout, _("Wrote file '%s'."),
446
507
                                ed->size = 0;
447
508
 
448
509
                                /* Save the new data. */
449
 
                                save_exif_data_to_file (ed, *args, fname);
 
510
                                save_exif_data_to_file (ed, log, *args, fname);
450
511
 
451
512
                        } else if (ithumbnail) {
452
513
 
459
520
 
460
521
                                /* Insert new thumbnail */
461
522
                                f = fopen (ithumbnail, "rb");
462
 
                                if (!f) {
 
523
                                if (!f)
463
524
#ifdef __GNUC__
464
 
                                        fprintf (stderr, _("Could not open "
 
525
                                        exif_log (log, -1, "exif", _("Could not open "
465
526
                                                "'%s' (%m)!"), ithumbnail);
466
527
#else
467
 
                                        fprintf (stderr, _("Could not open "
 
528
                                        exif_log (log, -1, "exif", _("Could not open "
468
529
                                                "'%s' (%s)!"), ithumbnail,
469
530
                                                strerror (errno));
470
531
#endif
471
 
                                        fputc ('\n', stderr);
472
 
                                        return (1);
473
 
                                }
474
532
                                fseek (f, 0, SEEK_END);
475
533
                                ed->size = ftell (f);
476
534
                                ed->data = malloc (sizeof (char) * ed->size);
477
 
                                if (ed->size && !ed->data) {
478
 
                                        fprintf (stderr, _("Could not "
479
 
                                                "allocate %i byte(s)."),
480
 
                                                ed->size);
481
 
                                        fputc ('\n', stderr);
482
 
                                        return (1);
483
 
                                }
 
535
                                if (ed->size && !ed->data) EXIF_LOG_NO_MEMORY (log, "exif", ed->size);
484
536
                                fseek (f, 0, SEEK_SET);
485
537
                                if (fread (ed->data, sizeof (char),
486
 
                                           ed->size, f) != ed->size) {
 
538
                                           ed->size, f) != ed->size)
487
539
#ifdef __GNUC__
488
 
                                        fprintf (stderr, _("Could not read "
 
540
                                        exif_log (log, -1, "exif", _("Could not read "
489
541
                                                "'%s' (%m)."), ithumbnail);
490
542
#else
491
 
                                        fprintf (stderr, _("Could not read "
 
543
                                        exif_log (log, -1, "exif", _("Could not read "
492
544
                                                "'%s' (%s)."), ithumbnail,
493
545
                                                strerror (errno));
494
546
#endif
495
 
                                        fputc ('\n', stderr);
496
 
                                        return (1);
497
 
                                }
498
547
                                fclose (f);
499
548
 
500
 
                                save_exif_data_to_file (ed, *args, fname);
 
549
                                save_exif_data_to_file (ed, log, *args, fname);
501
550
 
502
551
                        } else if (set_value) {
503
552
 
504
553
                                /* We need a tag... */
505
 
                                if (!tag) {
506
 
                                        fprintf (stderr, _("You need to "
507
 
                                                "specify a tag!"));
508
 
                                        fputc ('\n', stderr);
509
 
                                        return (1);
510
 
                                }
 
554
                                if (!tag) exif_log (log, -1, "exif", _("You need to specify a tag!"));
511
555
 
512
556
                                /* ... and an IFD. */
513
557
                                if ((ifd < EXIF_IFD_0) ||
514
 
                                    (ifd >= EXIF_IFD_COUNT)) {
515
 
                                        fprintf (stderr, _("You need to "
516
 
                                                "specify an IFD!"));
517
 
                                        fputc ('\n', stderr);
518
 
                                        return (1);
519
 
                                }
 
558
                                    (ifd >= EXIF_IFD_COUNT))
 
559
                                        exif_log (log, -1, "exif", _("You need to specify an IFD!"));
520
560
 
521
561
                                /* If the entry doesn't exist, create it. */
522
562
                                e = exif_content_get_entry (ed->ifd[ifd], tag);
529
569
                                /* Now set the value and save the data. */
530
570
                                convert_arg_to_entry (set_value, e,
531
571
                                                exif_data_get_byte_order (ed));
532
 
                                save_exif_data_to_file (ed, *args, fname);
 
572
                                save_exif_data_to_file (ed, log, *args, fname);
533
573
                        } else if (remove_tag) {
534
574
                                
535
575
                                /* We need an IFD. */
536
576
                                if ((ifd < EXIF_IFD_0) ||
537
 
                                    (ifd >= EXIF_IFD_COUNT)) {
538
 
                                        fprintf (stderr, _("You need to "
539
 
                                                 "specify an IFD!"));
540
 
                                        fputc ('\n', stderr);
541
 
                                        return (1);
542
 
                                }
 
577
                                    (ifd >= EXIF_IFD_COUNT))
 
578
                                        exif_log (log, -1, "exif", _("You need to specify an IFD!"));
543
579
 
544
580
                                if (!tag) {
545
581
                                        while (ed->ifd[ifd] &&
550
586
                                } else {
551
587
                                        e = exif_content_get_entry (
552
588
                                                        ed->ifd[ifd], tag);
553
 
                                        if (!e) {
554
 
                                            fprintf (stderr, _("IFD '%s' "
555
 
                                                 "does not contain a "
 
589
                                        if (!e)
 
590
                                            exif_log (log, -1, "exif", _("IFD '%s' does not contain a "
556
591
                                                 "tag '%s'!"),
557
592
                                                exif_ifd_get_name (ifd),
558
 
                                                exif_tag_get_name (tag));
559
 
                                            fputc ('\n', stderr);
560
 
                                            return (1);
561
 
                                        }
562
 
                                        exif_content_remove_entry (ed->ifd[ifd],
563
 
                                                                   e);
 
593
                                                exif_tag_get_name_in_ifd (tag, ifd));
 
594
                                        exif_content_remove_entry (ed->ifd[ifd], e);
564
595
                                }
565
596
 
566
597
                                /* Save modified data. */
567
 
                                save_exif_data_to_file (ed, *args, fname);
 
598
                                save_exif_data_to_file (ed, log, *args, fname);
568
599
 
569
600
                        } else if (machine_readable) {
570
601
                                action_tag_list_machine (*args, ed, eo.use_ids);
 
602
                        } else if (xml_output) {
 
603
                                action_tag_list_xml (*args, ed, eo.use_ids);
571
604
                        } else if (list_mnote) {
572
 
                                action_mnote_list (*args, ed);
 
605
                                action_mnote_list (*args, ed, eo.use_ids);
573
606
                        } else
574
607
                                action_tag_list (*args, ed, eo.use_ids);
575
608
                        exif_data_unref (ed);
576
609
                        args++;
577
610
                }
578
 
        } else
 
611
        } else {
579
612
                poptPrintHelp (ctx, stdout, 0);
 
613
                return(1);
 
614
        }
580
615
 
581
616
        poptFreeContext (ctx);
582
617