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>
This commit is contained in:
parent
e1d8c1f8ca
commit
ab59209ea6
1 changed files with 9 additions and 13 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue