Re: [dev] [sbase] printf(1)
On Wed, Dec 18, 2013 at 11:36 PM, Maurice Quennet <mjq_AT_web.de> wrote:
> Hello dev_AT_,
>
Hello mjq_AT_,
> diff --git a/Makefile b/Makefile
> index 2a72a1c..e93f570 100644
[...]
> +void
> +printfmt(void)
> +{
> + int e;
> + long l;
> + double d;
> + char c, f, *tmp;
> +
> + if (*end == '%') {
> + putchar('%');
> + fmt = ++end;
> + return;
> + }
> +
> + if (*arg == NULL)
> + eprintf("missing argument\n");
> +
> + if (*end == 'b') {
> + fmt = *arg;
> + tmp = end;
> +
> + while (*fmt) {
> + if (*fmt == '\\') {
> + ++fmt;
> + printesc();
> + continue;
> + }
> + putchar(*fmt);
> + ++fmt;
> + }
> +
> + fmt = end = tmp + 1;
> + return;
> + }
> +
> + for (; *end; ++end) {
> + if (!isdigit(*end) && *end != '#' && *end != '.' &&
> + *end != '+' && *end != '-' && *end != ' ')
> + break;
> + }
> +
> + if (*end == '\0')
> + eprintf("%s: invalid directive\n", fmt);
> +
> + f = *end;
> + c = *++end;
> + *end = '\0';
> +
> + switch (f) {
> + case 'c':
> + printf(fmt, **arg++);
> + break;
> + case 's':
> + printf(fmt, *arg++);
> + break;
> + case 'd': case 'i': case 'o':
> + case 'u': case 'X': case 'x':
> + e = errno;
> + errno = 0;
> + l = strtol(*arg, NULL, 0);
> + if (errno)
> + eprintf("%s: invalid value\n", *arg);
> + printf(fmt, l);
> + ++arg;
> + errno = e;
> + break;
> + case 'a': case 'A': case 'e': case 'E':
> + case 'f': case 'F': case 'g': case 'G':
> + e = errno;
> + errno = 0;
> + d = strtod(*arg, NULL);
> + if (errno)
> + eprintf("%s: invalid value\n", *arg);
> + printf(fmt, d);
> + ++arg;
> + errno = e;
> + break;
> + default:
> + eprintf("%s: invalid directive\n", fmt);
> + }
> +
> + *end = c;
> + fmt = end;
> +}
> +
I'm confused about what you're trying to accomplish here.
How about you just copy the format part from the for loop up there and
throw it into the standard library's printf?
cheers!
mar77i
Received on Thu Dec 19 2013 - 08:50:46 CET
This archive was generated by hypermail 2.3.0
: Thu Dec 19 2013 - 09:00:07 CET