2 * \brief Completely parse all files given on the command line.
4 * Copyright (C) 2007 Hans Ulrich Niedermann <gp@n-dimensional.de>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA.
23 #include "libexif/exif-data.h"
24 #include "libexif/exif-system.h"
30 static unsigned entry_count;
32 /** Callback function handling an ExifEntry. */
33 static void content_foreach_func(ExifEntry *entry, void *UNUSED(callback_data))
36 exif_entry_get_value(entry, buf, sizeof(buf));
37 printf(" Entry %u: %s (%s)\n"
38 " Size, Comps: %d, %d\n"
41 exif_tag_get_name(entry->tag),
42 exif_format_get_name(entry->format),
44 (int)(entry->components),
45 exif_entry_get_value(entry, buf, sizeof(buf)));
50 /** Callback function handling an ExifContent (corresponds 1:1 to an IFD). */
51 static void data_foreach_func(ExifContent *content, void *callback_data)
53 static unsigned content_count;
55 printf(" Content %u: ifd=%d\n", content_count, exif_content_get_ifd(content));
56 exif_content_foreach_entry(content, content_foreach_func, callback_data);
60 static void dump_makernote(ExifData *d) {
61 ExifMnoteData *mn = exif_data_get_mnote_data(d);
65 int num = exif_mnote_data_count(mn);
66 printf(" MakerNote\n");
67 for (i=0; i < num; ++i) {
68 if (exif_mnote_data_get_value(mn, i, buf, sizeof(buf))) {
69 const char *name = exif_mnote_data_get_name(mn, i);
70 unsigned int id = exif_mnote_data_get_id(mn, i);
73 printf(" Entry %u: %u, %s\n"
75 " Value: %s\n", i, id, name, strlen(buf), buf);
81 /** Run EXIF parsing test on the given file. */
82 static void test_parse(const char *filename, void *callback_data, int swap)
86 /* Skip over path to display only the file name */
87 const char *fn = strrchr(filename, '/');
92 printf("File %s\n", fn);
94 d = exif_data_new_from_file(filename);
95 printf("Byte order: %s\n",
96 exif_byte_order_get_name(exif_data_get_byte_order(d)));
99 ExifByteOrder order = EXIF_BYTE_ORDER_INTEL;
100 if (exif_data_get_byte_order(d) == order) {
101 order = EXIF_BYTE_ORDER_MOTOROLA;
103 /* This switches the byte order of the entire EXIF data structure,
104 * including the MakerNote */
105 exif_data_set_byte_order(d, order);
106 printf("New byte order: %s\n",
107 exif_byte_order_get_name(exif_data_get_byte_order(d)));
110 exif_data_foreach_content(d, data_foreach_func, callback_data);
118 /** Callback function prototype for string parsing. */
119 typedef void (*test_parse_func) (const char *filename, void *callback_data, int swap);
122 /** Split string at whitespace and call callback with each substring. */
123 static void split_ws_string(const char *string, test_parse_func func, void *callback_data)
125 const char *start = string;
126 const char *p = start;
128 if (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || *p == '\0' ) {
129 size_t len = p-start;
131 /* emulate strndup */
132 char *str = malloc(1+len);
134 memcpy(str, start, len);
136 func(str, callback_data, 0);
153 int main(const int argc, const char *argv[])
156 void *callback_data = NULL;
160 if (argc > 1 && !strcmp(argv[1], "--swap-byte-order")) {
166 for (i=first; i<argc; i++) {
167 test_parse(argv[i], callback_data, swap);
170 /* If no command-line argument is found, get the file names from
172 const char *envar = getenv("TEST_IMAGES");
174 split_ws_string(envar, test_parse, callback_data);