]> git.imager.perl.org - imager.git/blobdiff - tags.c
fix broken commit
[imager.git] / tags.c
diff --git a/tags.c b/tags.c
index 09880667eea1a90771a69f68057a12b2d362153c..bf8d3a5b8dda3cb9d22d631f7d44bf2ea80fb32f 100644 (file)
--- a/tags.c
+++ b/tags.c
@@ -15,6 +15,10 @@ tags.c - functions for manipulating an images tags list
   i_tags_delete(&tags, index);
   count = i_tags_delbyname(tags, name);
   count = i_tags_delbycode(tags, code);
+  if (i_tags_get_float(&tags, name, code, &float_value)) { found }
+  i_tags_set_float(&tags, name, code, value);
+  i_tags_set_float2(&tags, name, code, value, sig_digits);
+  i_tags_get_int(&tags, name, code, &int_value);
 
 =head1 DESCRIPTION
 
@@ -258,9 +262,31 @@ int i_tags_get_float(i_img_tags *tags, char const *name, int code,
 
 int i_tags_set_float(i_img_tags *tags, char const *name, int code, 
                      double value) {
+  return i_tags_set_float2(tags, name, code, value, 30);
+}
+
+/*
+=item i_tags_set_float2(tags, name, code, value, places)
+
+Sets the tag with the given name and code to the given floating point
+value.
+
+Since tags are strings or ints, we convert the value to a string before
+storage at the precision specified by C<places>.
+
+=cut
+*/
+
+int i_tags_set_float2(i_img_tags *tags, char const *name, int code, 
+                      double value, int places) {
   char temp[40];
 
-  sprintf(temp, "%.30g", value);
+  if (places < 0) 
+    places = 30;
+  else if (places > 30) 
+    places = 30;
+
+  sprintf(temp, "%.*g", places, value);
   if (name)
     i_tags_delbyname(tags, name);
   else
@@ -291,29 +317,6 @@ int i_tags_get_int(i_img_tags *tags, char const *name, int code, int *value) {
 }
 
 static int parse_long(char *data, char **end, long *out) {
-#if 0
-  /* I wrote this without thinking about strtol */
-  long x = 0;
-  int neg = *data == '-';
-
-  if (neg)
-    ++data;
-  if (!isdigit(*data))
-    return 0;
-  while (isdigit(*data)) {
-    /* this check doesn't guarantee we don't overflow, but it helps */
-    if (x > LONG_MAX / 10)
-      return 0; 
-    x = x * 10 + *data - '0';
-    ++data;
-  }
-  if (neg)
-    x = -x;
-
-  *end = data;
-
-  return 1;
-#else
   long result;
   int savederr = errno;
   char *myend;
@@ -322,14 +325,15 @@ static int parse_long(char *data, char **end, long *out) {
   result = strtol(data, &myend, 10);
   if ((result == LONG_MIN || result == LONG_MAX) && errno == ERANGE
       || myend == data) {
+    errno = savederr;
     return 0;
   }
 
+  errno = savederr;
   *out = result;
   *end = myend;
 
   return 1;
-#endif
 }
 
 /* parse a comma-separated list of integers
@@ -438,7 +442,7 @@ int i_tags_get_string(i_img_tags *tags, char const *name, int code,
     value[cpsize] = '\0';
   }
   else {
-    sprintf(value, "%d", entry->data);
+    sprintf(value, "%d", entry->idata);
   }
 
   return 1;