Update of /cvsroot/libexif/exif/exif
In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv29938/exif
Modified Files:
main.c
Log Message:
Improved support for --set-value by supporting sshort and rational types.
Give errors/warnings when the incorrect number of components is given.
Index: main.c
===================================================================
RCS file: /cvsroot/libexif/exif/exif/main.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -p -d -r1.58 -r1.59
--- main.c 9 Nov 2007 06:54:54 -0000 1.58
+++ main.c 24 Jan 2008 21:36:41 -0000 1.59
@@ -104,7 +104,7 @@ search_entry (ExifData *ed, ExifTag tag,
static void
convert_arg_to_entry (const char *set_value, ExifEntry *e, ExifByteOrder o)
{
- unsigned int i;
+ unsigned int i, numcomponents;
char *value_p;
/*
@@ -125,16 +125,27 @@ convert_arg_to_entry (const char *set_va
return;
}
+ /*
+ * Make sure we can handle this entry
+ */
+ if ((e->components == 0) && *set_value) {
+ fprintf (stderr, _("Setting a value for this tag "
+ "is unsupported!"));
+ fputc ('\n', stderr);
+ exit (1);
+ }
+
value_p = (char*) set_value;
- for (i = 0; i < e->components; i++) {
+ numcomponents = e->components;
+ for (i = 0; i < numcomponents; ++i) {
const char *begin, *end;
unsigned char *buf, s;
- const char comp_separ = ' ';
+ static const char comp_separ = ' ';
begin = value_p;
value_p = strchr (begin, comp_separ);
if (!value_p) {
- if (i != e->components - 1) {
+ if (i != numcomponents - 1) {
fprintf (stderr, _("Too few components "
"specified!"));
fputc ('\n', stderr);
@@ -155,15 +166,36 @@ convert_arg_to_entry (const char *set_va
case EXIF_FORMAT_SHORT:
exif_set_short (e->data + (s * i), o, atoi ((char *) buf));
break;
+ case EXIF_FORMAT_SSHORT:
+ exif_set_sshort (e->data + (s * i), o, atoi ((char *) buf));
+ break;
+ case EXIF_FORMAT_RATIONAL:
+ /*
+ * Hack to simplify the loop for rational numbers.
+ * Should really be using exif_set_rational instead
+ */
+ if (i == 0) numcomponents *= 2;
+ s /= 2;
+ /* Fall through to LONG handler */
case EXIF_FORMAT_LONG:
exif_set_long (e->data + (s * i), o, atol ((char *) buf));
break;
+ case EXIF_FORMAT_SRATIONAL:
+ /*
+ * Hack to simplify the loop for rational numbers.
+ * Should really be using exif_set_srational instead
+ */
+ if (i == 0) numcomponents *= 2;
+ s /= 2;
+ /* Fall through to SLONG handler */
case EXIF_FORMAT_SLONG:
exif_set_slong (e->data + (s * i), o, atol ((char *) buf));
break;
- case EXIF_FORMAT_RATIONAL:
- case EXIF_FORMAT_SRATIONAL:
case EXIF_FORMAT_BYTE:
+ case EXIF_FORMAT_SBYTE:
+ case EXIF_FORMAT_FLOAT:
+ case EXIF_FORMAT_DOUBLE:
+ case EXIF_FORMAT_UNDEFINED:
default:
fprintf (stderr, _("Not yet implemented!"));
fputc ('\n', stderr);
@@ -171,6 +203,10 @@ convert_arg_to_entry (const char *set_va
}
free (buf);
}
+ if (value_p && *value_p) {
+ fprintf (stderr, _("Warning; Too many components specified!"));
+ fputc ('\n', stderr);
+ }
}
/* escape codes for output colors */
|