tvrange_size = { 0, (size_t)-1 },
tvrange_byte = { 0, 255 },
tvrange_u16 = { 0, 65535 },
- tvrange_u32 = { 0, 4294967296 };
+ tvrange_u32 = { 0, 4294967295 };
/* --- @tvec_claimeq_int@ --- *
*
{ 0 }
};
+/* --- @tvec_parsedurunit@ --- *
+ *
+ * Arguments: @double *scale_out@ = where to leave the scale
+ * @const char **p_inout@ = input unit string, updated
+ *
+ * Returns: Zero on success, %$-1$% on error.
+ *
+ * Use: If @*p_inout@ begins with a unit string followed by the end
+ * of the string or some non-alphanumeric character, then store
+ * the corresponding scale factor in @*scale_out@, advance
+ * @*p_inout@ past the unit string, and return zero. Otherwise,
+ * return %$-1$%.
+ */
+
+int tvec_parsedurunit(double *scale_out, const char **p_inout)
+{
+ const char *p = *p_inout, *q;
+ const struct duration_unit *u;
+ size_t n;
+
+ while (ISSPACE(*p)) p++;
+ for (q = p; *q && ISALNUM(*q); q++);
+ n = q - p; if (!n) { *scale_out = 1.0; return (0); }
+
+ for (u = duration_units; u->unit; u++)
+ if (STRNCMP(p, ==, u->unit, n) && !u->unit[n])
+ { *scale_out = u->scale; *p_inout = q; return (0); }
+ return (-1);
+}
+
/* --- @parse_duration@ --- *
*
* Arguments: @union tvec_regval *rv@ = register value
const struct tvec_regdef *rd,
struct tvec_state *tv)
{
- unsigned long sz, a = 0, m = 0;
+ size_t sz, a = 0, m = 0;
int ch, rc;
if (parse_size(tv, &sz, "@;", "buffer length")) { rc = -1; goto end; }
}
}
if (!(style&TVSF_COMPACT)) {
- gprintf(gops, go, " ; = %lu", rv->buf.sz);
+ gprintf(gops, go, " ; = %lu", (unsigned long)rv->buf.sz);
if (rv->buf.m) {
- gprintf(gops, go, " @ %lu", rv->buf.m);
- if (rv->buf.a) gprintf(gops, go, " + %lu", rv->buf.a);
+ gprintf(gops, go, " @ %lu", (unsigned long)rv->buf.m);
+ if (rv->buf.a) gprintf(gops, go, " + %lu", (unsigned long)rv->buf.a);
}
gprintf(gops, go, " = "); format_unsigned_hex(gops, go, rv->buf.sz);
if (rv->buf.m) {