From: Dan F. <dfa...@us...> - 2009-10-01 06:50:51
|
Update of /cvsroot/libexif/exif/exif In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv15439/exif Modified Files: actions.c actions.h main.c Log Message: Added --width option to allow setting width of output Index: main.c =================================================================== RCS file: /cvsroot/libexif/exif/exif/main.c,v retrieving revision 1.74 retrieving revision 1.75 diff -u -p -d -r1.74 -r1.75 --- main.c 1 Oct 2009 06:10:39 -0000 1.74 +++ main.c 1 Oct 2009 06:50:34 -0000 1.75 @@ -48,6 +48,12 @@ #include <mcheck.h> #endif +/*! The minimum width of output that we can support */ +#define MIN_WIDTH 52 + +/*! A sane limit on output width */ +#define MAX_WIDTH 9999 + /* Old versions of popt.h don't define POPT_TABLEEND */ #ifndef POPT_TABLEEND # define POPT_TABLEEND { NULL, '\0', 0, 0, 0, NULL, NULL } @@ -174,7 +180,8 @@ static unsigned int list_mnote = 0; static unsigned int show_version = 0; static const char *output = NULL; static const char *ifd_string = NULL, *tag_string = NULL; -static ExifParams p = {EXIF_INVALID_TAG, EXIF_IFD_COUNT, 0, 0, NULL, NULL,NULL}; +static ExifParams p = {EXIF_INVALID_TAG, EXIF_IFD_COUNT, 0, 0, 80, + NULL, NULL,NULL}; LogArg log_arg = {0, 0, 0}; int @@ -218,6 +225,8 @@ main (int argc, const char **argv) {"machine-readable", 'm', POPT_ARG_NONE, &p.machine_readable, 0, N_("Output in a machine-readable (tab delimited) format"), NULL}, + {"width", 'w', POPT_ARG_INT, &p.width, 0, + N_("Width of output"), N_("WIDTH")}, {"xml-output", 'x', POPT_ARG_NONE, &xml_output, 0, N_("Output in a XML format"), NULL}, @@ -251,7 +260,10 @@ main (int argc, const char **argv) ctx = poptGetContext (PACKAGE, argc, argv, options, 0); poptSetOtherOptionHelp (ctx, _("[OPTION...] file")); - while (poptGetNextOpt (ctx) > 0); + while (poptGetNextOpt (ctx) > 0) + ; + + p.width = MIN(MAX_WIDTH, MAX(MIN_WIDTH, p.width)); log = exif_log_new (); exif_log_set_func (log, log_func, &log_arg); Index: actions.c =================================================================== RCS file: /cvsroot/libexif/exif/exif/actions.c,v retrieving revision 1.44 retrieving revision 1.45 diff -u -p -d -r1.44 -r1.45 --- actions.c 29 Sep 2009 04:31:04 -0000 1.44 +++ actions.c 1 Oct 2009 06:50:34 -0000 1.45 @@ -35,9 +35,6 @@ #define TAG_VALUE_BUF 1024 -/* TODO: make this a member of ExifParams */ -#define SCREEN_WIDTH 80 - static void convert_arg_to_entry (const char *set_value, ExifEntry *e, ExifByteOrder o, ExifLog *log) { @@ -400,7 +397,7 @@ action_tag_table (ExifData *ed, ExifPara if (!name) continue; - fieldwidth = width = SCREEN_WIDTH - 38 - 13; + fieldwidth = width = p.width - 38 - 13; bytes = exif_mbstrlen(C(name), &width); printf (" 0x%04x %.*s%*s", tag, bytes, C(name), fieldwidth-width, ""); @@ -416,13 +413,13 @@ action_tag_table (ExifData *ed, ExifPara static void show_entry_list (ExifEntry *e, void *data) { - unsigned char *ids = data; + const ExifParams *p = data; char v[TAG_VALUE_BUF]; ExifIfd ifd = exif_entry_get_ifd (e); const char *str; size_t fieldwidth, width, bytes; - if (*ids) + if (p->use_ids) printf("0x%04x", e->tag); else { str = C(exif_tag_get_title_in_ifd (e->tag, ifd)); @@ -432,7 +429,7 @@ show_entry_list (ExifEntry *e, void *dat } printf ("|"); - fieldwidth = width = *ids ? SCREEN_WIDTH-8 : SCREEN_WIDTH-22; + fieldwidth = width = p->use_ids ? p->width-8 : p->width-22; str = C(exif_entry_get_value (e, v, sizeof(v))); bytes = exif_mbstrlen(str, &width); printf("%.*s", bytes, str); @@ -446,7 +443,7 @@ show_ifd (ExifContent *content, void *da } static void -print_hline (unsigned char ids) +print_hline (unsigned char ids, unsigned int screenwidth) { unsigned int i, width; @@ -454,7 +451,7 @@ print_hline (unsigned char ids) for (i = 0; i < width; i++) fputc ('-', stdout); fputc ('+', stdout); - for (i = 0; i < SCREEN_WIDTH - 2 - width; i++) + for (i = 0; i < screenwidth - 2 - width; i++) fputc ('-', stdout); fputc ('\n', stdout); } @@ -504,7 +501,7 @@ action_mnote_list (ExifData *ed, ExifPar if (p.use_ids) { fputs (b2, stdout); } else { - fieldwidth = width = SCREEN_WIDTH-22; + fieldwidth = width = p.width-22; bytes = exif_mbstrlen(b2, &width); printf ("%.*s", bytes, b2); } @@ -526,7 +523,7 @@ action_tag_list (ExifData *ed, ExifParam printf (_("EXIF tags in '%s' ('%s' byte order):"), p.fin, exif_byte_order_get_name (order)); fputc ('\n', stdout); - print_hline (p.use_ids); + print_hline (p.use_ids, p.width); fieldwidth = width = p.use_ids ? 6 : 20; s = _("Tag"); @@ -534,21 +531,21 @@ action_tag_list (ExifData *ed, ExifParam printf ("%.*s%*s", bytes, s, fieldwidth-width, ""); fputc ('|', stdout); - fieldwidth = width = p.use_ids ? SCREEN_WIDTH-8 : SCREEN_WIDTH-22; + fieldwidth = width = p.use_ids ? p.width-8 : p.width-22; s = _("Value"); bytes = exif_mbstrlen(s, &width); printf ("%.*s", bytes, s); fputc ('\n', stdout); - print_hline (p.use_ids); + print_hline (p.use_ids, p.width); if (p.ifd < EXIF_IFD_COUNT) /* Show only a single IFD */ - show_ifd(ed->ifd[p.ifd], &p.use_ids); + show_ifd(ed->ifd[p.ifd], &p); else /* Show contents of all IFDs */ - exif_data_foreach_content (ed, show_ifd, &p.use_ids); + exif_data_foreach_content (ed, show_ifd, &p); - print_hline (p.use_ids); + print_hline (p.use_ids, p.width); if (ed->size) { printf (_("EXIF data contains a thumbnail " "(%i bytes)."), ed->size); Index: actions.h =================================================================== RCS file: /cvsroot/libexif/exif/exif/actions.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -p -d -r1.11 -r1.12 --- actions.h 22 Jan 2009 07:41:11 -0000 1.11 +++ actions.h 1 Oct 2009 06:50:34 -0000 1.12 @@ -29,6 +29,7 @@ typedef struct { unsigned int machine_readable; unsigned int use_ids; + unsigned int width; const char *fin; |