@@@ bench wip
[mLib] / test / tvec-types.c
index 068d565..20c2930 100644 (file)
@@ -1553,7 +1553,7 @@ const struct tvec_urange
   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@ --- *
  *
@@ -1873,6 +1873,36 @@ static const struct duration_unit {
   { 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
@@ -3395,7 +3425,7 @@ static int parse_buffer(union tvec_regval *rv,
                        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; }
@@ -3460,10 +3490,10 @@ static void dump_buffer(const union tvec_regval *rv,
     }
   }
   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) {