-
-#define SKIP1 "#-+ 0"
-#define SKIP2 "*0123456789"
- do {
- /*
- * Basic algorithm is to scan the format string for conversion
- * specifications -- once one is found, find out if the field
- * width or precision is a '*'; if it is, gather up value.
- * Note, format strings are reused as necessary to use up the
- * provided arguments, arguments of zero/null string are
- * provided to use up the format string.
- */
-
- /* find next format specification */
- for (fmt = format; *fmt; fmt++) {
- switch (*fmt) {
- case '%':
- start = fmt++;
-
- if (*fmt == '%') {
- (void)putchar('%');
- break;
- } else if (*fmt == 'b') {
- char *p = getstr();
- if (print_escape_str(p)) {
- return (rval);
- }
- break;
- }
-
- /* skip to field width */
- for (; strchr(SKIP1, *fmt); ++fmt) ;
- fieldwidth = *fmt == '*' ? getint() : 0;
-
- /* skip to possible '.', get following precision */
- for (; strchr(SKIP2, *fmt); ++fmt) ;
- if (*fmt == '.')
- ++fmt;
- precision = *fmt == '*' ? getint() : 0;
-
- for (; strchr(SKIP2, *fmt); ++fmt) ;
- if (!*fmt) {
- warnx ("missing format character");
- return(1);
- }
-
- convch = *fmt;
- nextch = *(fmt + 1);
- *(fmt + 1) = '\0';
- switch(convch) {
- case 'c': {
- char p = getchr();
- PF(start, p);
- break;
- }
- case 's': {
- char *p = getstr();
- PF(start, p);
- break;
- }
- case 'd':
- case 'i': {
- char *f = mklong(start, convch);
- long p = getlong();
- PF(f, p);
- break;
+ for (;;) {
+ start = fmt;
+ while (fmt < format + len) {
+ if (fmt[0] == '%') {
+ fwrite(start, 1, fmt - start, stdout);
+ if (fmt[1] == '%') {
+ /* %% prints a % */
+ putchar('%');
+ fmt += 2;
+ } else {
+ fmt = doformat(fmt, &rval);
+ if (fmt == NULL)
+ return (1);
+ end = 0;