Skip to content
Permalink
Browse files

prf.c: abstract output method call

This makes for nicer code by avoiding repetitions of the same pattern.
Changes to come will make more use of it.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
  • Loading branch information...
Nicolas Pitre authored and nashif committed Jun 18, 2019
1 parent e1d8c1f commit ab59209ea6d249a8b3179639b4351c90bd5655f2
Showing with 9 additions and 13 deletions.
  1. +9 −13 lib/libc/minimal/source/stdout/prf.c
@@ -462,16 +462,14 @@ int z_prf(int (*func)(), void *dest, const char *format, va_list vargs)
int width;
VALTYPE val;

#define PUTC(c) do { if ((*func)(c, dest) == EOF) return EOF; } while (false)

count = 0;

while ((c = *format++)) {
if (c != '%') {
if ((*func) (c, dest) == EOF) {
return EOF;
}

PUTC(c);
count++;

} else {
fminus = fplus = fspace = falt = false;
pad = ' '; /* Default pad character */
@@ -735,10 +733,7 @@ int z_prf(int (*func)(), void *dest, const char *format, va_list vargs)
break;

case '%':
if ((*func)('%', dest) == EOF) {
return EOF;
}

PUTC('%');
count++;
break;

@@ -773,13 +768,14 @@ int z_prf(int (*func)(), void *dest, const char *format, va_list vargs)
c = width;
}

for (cptr = buf; c > 0; c--, cptr++, count++) {
if ((*func)(*cptr, dest) == EOF) {
return EOF;
}
count += c;
for (cptr = buf; c > 0; c--, cptr++) {
PUTC(*cptr);
}
}
}
}
return count;

#undef PUTC
}

0 comments on commit ab59209

Please sign in to comment.
You can’t perform that action at this time.