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
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
}
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;
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
value[cpsize] = '\0';
}
else {
- sprintf(value, "%d", entry->data);
+ sprintf(value, "%d", entry->idata);
}
return 1;