X-Git-Url: https://git.distorted.org.uk/~mdw/mLib/blobdiff_plain/adec5584e13c63662fda18915280ec026063b29d..d056fbdff1c5a26be055c38eee4c273ee6a0cba7:/test/tvec-types.c diff --git a/test/tvec-types.c b/test/tvec-types.c index 068d565..87748eb 100644 --- a/test/tvec-types.c +++ b/test/tvec-types.c @@ -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) { @@ -3486,18 +3516,18 @@ const struct tvec_regty tvty_buffer = { /* --- @tvec_initbuffer@ --- * * * Arguments: @union tvec_regval *rv@ = register value - * @const union tvec_regval *src@ = source buffer + * @const union tvec_regval *ref@ = source buffer * @size_t sz@ = size to allocate * * Returns: --- * - * Use: Initialize the alignment parameters in @rv@ to match @src@, + * Use: Initialize the alignment parameters in @rv@ to match @ref@, * and the size to @sz@. */ void tvec_initbuffer(union tvec_regval *rv, - const union tvec_regval *src, size_t sz) - { rv->buf.sz = sz; rv->buf.a = src->buf.a; rv->buf.m = src->buf.m; } + const union tvec_regval *ref, size_t sz) + { rv->buf.sz = sz; rv->buf.a = ref->buf.a; rv->buf.m = ref->buf.m; } /* --- @tvec_allocbuffer@ --- * *