summaryrefslogtreecommitdiff
path: root/libc/stdio
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-10-09 20:06:30 +0000
committerEric Andersen <andersen@codepoet.org>2000-10-09 20:06:30 +0000
commitc1fe19d4c1db610692365472a90f4661e48449c1 (patch)
treed0b0219ffca3c4c4256f55c4aea4513e43d6aecd /libc/stdio
parent9efafb8bbc7408b04643dcd53825d971577b4d9d (diff)
Bug ugly formatting update
Diffstat (limited to 'libc/stdio')
-rw-r--r--libc/stdio/.indent.pro33
-rw-r--r--libc/stdio/Makefile11
-rw-r--r--libc/stdio/printf.c610
-rw-r--r--libc/stdio/scanf.c827
-rw-r--r--libc/stdio/stdio.c1330
5 files changed, 1398 insertions, 1413 deletions
diff --git a/libc/stdio/.indent.pro b/libc/stdio/.indent.pro
new file mode 100644
index 000000000..492ecf1c7
--- /dev/null
+++ b/libc/stdio/.indent.pro
@@ -0,0 +1,33 @@
+--blank-lines-after-declarations
+--blank-lines-after-procedures
+--break-before-boolean-operator
+--no-blank-lines-after-commas
+--braces-on-if-line
+--braces-on-struct-decl-line
+--comment-indentation25
+--declaration-comment-column25
+--no-comment-delimiters-on-blank-lines
+--cuddle-else
+--continuation-indentation4
+--case-indentation0
+--else-endif-column33
+--space-after-cast
+--line-comments-indentation0
+--declaration-indentation1
+--dont-format-first-column-comments
+--dont-format-comments
+--honour-newlines
+--indent-level4
+/* changed from 0 to 4 */
+--parameter-indentation4
+--line-length78 /* changed from 75 */
+--continue-at-parentheses
+--no-space-after-function-call-names
+--dont-break-procedure-type
+--dont-star-comments
+--leave-optional-blank-lines
+--dont-space-special-semicolon
+--tab-size4
+/* additions by Mark */
+--case-brace-indentation0
+--leave-preprocessor-space
diff --git a/libc/stdio/Makefile b/libc/stdio/Makefile
index 048483d13..fbd0bbf15 100644
--- a/libc/stdio/Makefile
+++ b/libc/stdio/Makefile
@@ -38,12 +38,15 @@ MOBJ3=scanf.o sscanf.o fscanf.o vscanf.o vsscanf.o vfscanf.o
CSRC=dputs.c
COBJS=$(patsubst %.c,%.o, $(CSRC))
+OBJS=$(MOBJ) $(MOBJ2) $(MOBJ3) $(COBJS)
-all: $(MOBJ) $(MOBJ2) $(MOBJ3) $(COBJS) $(LIBC)
+all: $(OBJS) $(LIBC)
-$(LIBC): $(MOBJ) $(MOBJ2) $(MOBJ3) $(COBJS)
- $(AR) $(ARFLAGS) $(LIBC) $(MOBJ) $(MOBJ2) $(MOBJ3) $(COBJS)
+$(LIBC): ar-target
+
+ar-target: $(OBJS)
+ $(AR) $(ARFLAGS) $(LIBC) $(OBJS)
$(MOBJ): $(MSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
@@ -54,6 +57,8 @@ $(MOBJ2): $(MSRC2)
$(MOBJ3): $(MSRC3)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+$(OBJS): Makefile
+
clean:
rm -f *.[oa] *~ core
diff --git a/libc/stdio/printf.c b/libc/stdio/printf.c
index 7aba8c74d..d987966f6 100644
--- a/libc/stdio/printf.c
+++ b/libc/stdio/printf.c
@@ -34,115 +34,117 @@
-extern int vfnprintf(FILE *op, size_t max_size, register __const char *fmt, register va_list ap);
+extern int vfnprintf(FILE * op, size_t max_size,
+ register __const char *fmt, register va_list ap);
#ifdef L_printf
-int printf(const char * fmt, ...)
+int printf(const char *fmt, ...)
{
- va_list ptr;
- int rv;
+ va_list ptr;
+ int rv;
- va_strt(ptr, fmt);
- rv = vfnprintf(stdout, -1, fmt, ptr);
- va_end(ptr);
- return rv;
+ va_strt(ptr, fmt);
+ rv = vfnprintf(stdout, -1, fmt, ptr);
+ va_end(ptr);
+ return rv;
}
#endif
#ifdef L_sprintf
-int sprintf(char * sp, const char * fmt, ...)
+int sprintf(char *sp, const char *fmt, ...)
{
- static FILE string[1] =
- {
- {0, 0, (char*)(unsigned) -1, 0, (char*) (unsigned) -1, -1,
- _IOFBF | __MODE_WRITE}
- };
-
- va_list ptr;
- int rv;
- va_strt(ptr, fmt);
- string->bufpos = sp;
- rv = vfnprintf(string, -1, fmt, ptr);
- va_end(ptr);
- *(string->bufpos) = 0;
- return rv;
+ static FILE string[1] = {
+ {0, 0, (char *) (unsigned) -1, 0, (char *) (unsigned) -1, -1,
+ _IOFBF | __MODE_WRITE}
+ };
+
+ va_list ptr;
+ int rv;
+
+ va_strt(ptr, fmt);
+ string->bufpos = sp;
+ rv = vfnprintf(string, -1, fmt, ptr);
+ va_end(ptr);
+ *(string->bufpos) = 0;
+ return rv;
}
#endif
#ifdef L_snprintf
-int snprintf(char * sp, size_t size, const char * fmt, ...)
+int snprintf(char *sp, size_t size, const char *fmt, ...)
{
- static FILE string[1] =
- {
- {0, 0, (char*)(unsigned) -1, 0, (char*) (unsigned) -1, -1,
- _IOFBF | __MODE_WRITE}
- };
-
- va_list ptr;
- int rv;
- va_strt(ptr, fmt);
- string->bufpos = sp;
- rv = vfnprintf(string, size, fmt, ptr);
- va_end(ptr);
- *(string->bufpos) = 0;
- return rv;
+ static FILE string[1] = {
+ {0, 0, (char *) (unsigned) -1, 0, (char *) (unsigned) -1, -1,
+ _IOFBF | __MODE_WRITE}
+ };
+
+ va_list ptr;
+ int rv;
+
+ va_strt(ptr, fmt);
+ string->bufpos = sp;
+ rv = vfnprintf(string, size, fmt, ptr);
+ va_end(ptr);
+ *(string->bufpos) = 0;
+ return rv;
}
#endif
#ifdef L_fprintf
-int fprintf(FILE * fp, const char * fmt, ...)
+int fprintf(FILE * fp, const char *fmt, ...)
{
- va_list ptr;
- int rv;
- va_strt(ptr, fmt);
- rv = vfnprintf(fp, -1, fmt, ptr);
- va_end(ptr);
- return rv;
+ va_list ptr;
+ int rv;
+
+ va_strt(ptr, fmt);
+ rv = vfnprintf(fp, -1, fmt, ptr);
+ va_end(ptr);
+ return rv;
}
#endif
#ifdef L_vprintf
-int vprintf(const char * fmt, va_list ap)
+int vprintf(const char *fmt, va_list ap)
{
- return vfprintf(stdout,fmt,ap);
+ return vfprintf(stdout, fmt, ap);
}
#endif
#ifdef L_vsprintf
-int vsprintf( char * sp, __const char *fmt, va_list ap)
+int vsprintf(char *sp, __const char *fmt, va_list ap)
{
- static FILE string[1] =
- {
- {0, 0, (char*)(unsigned) -1, 0, (char*) (unsigned) -1, -1,
- _IOFBF | __MODE_WRITE}
- };
-
- int rv;
- string->bufpos = sp;
- rv = vfnprintf(string, -1, fmt, ap);
- *(string->bufpos) = 0;
- return rv;
+ static FILE string[1] = {
+ {0, 0, (char *) (unsigned) -1, 0, (char *) (unsigned) -1, -1,
+ _IOFBF | __MODE_WRITE}
+ };
+
+ int rv;
+
+ string->bufpos = sp;
+ rv = vfnprintf(string, -1, fmt, ap);
+ *(string->bufpos) = 0;
+ return rv;
}
#endif
#ifdef L_vsprintf
-int vsnprintf( char * sp, size_t size, __const char *fmt, va_list ap)
+int vsnprintf(char *sp, size_t size, __const char *fmt, va_list ap)
{
- static FILE string[1] =
- {
- {0, 0, (char*)(unsigned) -1, 0, (char*) (unsigned) -1, -1,
- _IOFBF | __MODE_WRITE}
- };
-
- int rv;
- string->bufpos = sp;
- rv = vfnprintf(string, size, fmt, ap);
- *(string->bufpos) = 0;
- return rv;
+ static FILE string[1] = {
+ {0, 0, (char *) (unsigned) -1, 0, (char *) (unsigned) -1, -1,
+ _IOFBF | __MODE_WRITE}
+ };
+
+ int rv;
+
+ string->bufpos = sp;
+ rv = vfnprintf(string, size, fmt, ap);
+ *(string->bufpos) = 0;
+ return rv;
}
#endif
@@ -155,261 +157,265 @@ int _vfprintf_fp_ref = 0;
#endif
static int
-printfield(op, buf, ljustf, sign, pad, width, preci, buffer_mode, max_size, current_size)
+printfield(op, buf, ljustf, sign, pad, width, preci, buffer_mode, max_size,
+ current_size)
register FILE *op;
register unsigned char *buf;
-int ljustf;
+int ljustf;
register char sign;
-char pad;
+char pad;
register int width;
-int preci;
-int buffer_mode;
+int preci;
+int buffer_mode;
size_t max_size;
size_t current_size;
+
/*
* Output the given field in the manner specified by the arguments. Return
* the number of characters output.
*/
{
- register int cnt = 0, len;
- register unsigned char ch;
-
- len = strlen(buf);
-
- if (*buf == '-')
- sign = *buf++;
- else if (sign)
- len++;
-
- if ((preci != -1) && (len > preci)) /* limit max data width */
- len = preci;
-
- if (width < len) /* flexible field width or width overflow */
- width = len;
-
- /*
- * at this point: width = total field width len = actual data width
- * (including possible sign character)
- */
- cnt = width;
- width -= len;
-
- while (width || len)
- {
- if (!ljustf && width) /* left padding */
- {
- if (len && sign && (pad == '0'))
- goto showsign;
- ch = pad;
- --width;
- }
- else if (len)
- {
- if (sign)
- {
- showsign:ch = sign; /* sign */
- sign = '\0';
- }
- else
- ch = *buf++; /* main field */
- --len;
- }
- else
- {
- ch = pad; /* right padding */
- --width;
- }
- current_size++;
- if (max_size>0 && current_size < max_size)
- putc(ch, op);
- if( ch == '\n' && buffer_mode == _IOLBF ) fflush(op);
- }
-
- return (cnt);
+ register int cnt = 0, len;
+ register unsigned char ch;
+
+ len = strlen(buf);
+
+ if (*buf == '-')
+ sign = *buf++;
+ else if (sign)
+ len++;
+
+ if ((preci != -1) && (len > preci)) /* limit max data width */
+ len = preci;
+
+ if (width < len) /* flexible field width or width overflow */
+ width = len;
+
+ /*
+ * at this point: width = total field width len = actual data width
+ * (including possible sign character)
+ */
+ cnt = width;
+ width -= len;
+
+ while (width || len) {
+ if (!ljustf && width) { /* left padding */
+ if (len && sign && (pad == '0'))
+ goto showsign;
+ ch = pad;
+ --width;
+ } else if (len) {
+ if (sign) {
+ showsign:ch = sign;
+ /* sign */
+ sign = '\0';
+ } else
+ ch = *buf++; /* main field */
+ --len;
+ } else {
+ ch = pad; /* right padding */
+ --width;
+ }
+ current_size++;
+ if (max_size > 0 && current_size < max_size)
+ putc(ch, op);
+ if (ch == '\n' && buffer_mode == _IOLBF)
+ fflush(op);
+ }
+
+ return (cnt);
}
-int vfnprintf(FILE *op, size_t max_size, register __const char *fmt, register va_list ap)
+int vfnprintf(FILE * op, size_t max_size, register __const char *fmt,
+ register va_list ap)
{
- register int i, cnt = 0, ljustf, lval;
- int preci, dpoint, width;
- char pad, sign, radix, hash;
- register char *ptmp;
- char tmp[64], *ltostr(), *ultostr();
- int buffer_mode;
-
- /* This speeds things up a bit for unbuffered */
- buffer_mode = (op->mode&__MODE_BUF);
- op->mode &= (~__MODE_BUF);
-
- while (*fmt)
- {
- if (*fmt == '%')
- {
- if( buffer_mode == _IONBF ) fflush(op);
- ljustf = 0; /* left justify flag */
- sign = '\0'; /* sign char & status */
- pad = ' '; /* justification padding char */
- width = -1; /* min field width */
- dpoint = 0; /* found decimal point */
- preci = -1; /* max data width */
- radix = 10; /* number base */
- ptmp = tmp; /* pointer to area to print */
- hash = 0;
- lval = (sizeof(int)==sizeof(long)); /* long value flaged */
- fmtnxt:
- i = 0;
- for(;;)
- {
- ++fmt;
- if(*fmt < '0' || *fmt > '9' ) break;
- i = (i * 10) + (*fmt - '0');
- if (dpoint)
- preci = i;
- else if (!i && (pad == ' '))
- {
- pad = '0';
- goto fmtnxt;
- }
- else
- width = i;
- }
-
- switch (*fmt)
- {
- case '\0': /* early EOS */
- --fmt;
- goto charout;
-
- case '-': /* left justification */
- ljustf = 1;
- goto fmtnxt;
-
- case ' ':
- case '+': /* leading sign flag */
- sign = *fmt;
- goto fmtnxt;
-
- case '*': /* parameter width value */
- i = va_arg(ap, int);
- if (dpoint)
- preci = i;
- else
- width = i;
- goto fmtnxt;
-
- case '.': /* secondary width field */
- dpoint = 1;
- goto fmtnxt;
-
- case 'l': /* long data */
- lval = 1;
- goto fmtnxt;
-
- case 'h': /* short data */
- lval = 0;
- goto fmtnxt;
-
- case 'd': /* Signed decimal */
- case 'i':
- ptmp = ltostr((long) ((lval)
- ? va_arg(ap, long)
- : va_arg(ap, short)),
- 10, 0);
- goto printit;
-
- case 'b': /* Unsigned binary */
- radix = 2;
- goto usproc;
-
- case 'o': /* Unsigned octal */
- radix = 8;
- goto usproc;
-
- case 'p': /* Pointer */
- lval = (sizeof(char*) == sizeof(long));
- pad = '0';
- width = 6;
- preci = 8;
- /* fall thru */
-
- case 'x': /* Unsigned hexadecimal */
- case 'X':
- radix = 16;
- /* fall thru */
-
- case 'u': /* Unsigned decimal */
- usproc:
- ptmp = ultostr((unsigned long) ((lval)
- ? va_arg(ap, unsigned long)
- : va_arg(ap, unsigned short)),
- radix, (*fmt == 'X') ? 1 : 0);
- if( hash && radix == 8 ) { width = strlen(ptmp)+1; pad='0'; }
- goto printit;
-
- case '#':
- hash=1;
- goto fmtnxt;
-
- case 'c': /* Character */
- ptmp[0] = va_arg(ap, int);
- ptmp[1] = '\0';
- goto nopad;
-
- case 's': /* String */
- ptmp = va_arg(ap, char*);
- nopad:
- sign = '\0';
- pad = ' ';
- printit:
- cnt += printfield(op, ptmp, ljustf, sign, pad, width,
- preci, buffer_mode, max_size, cnt);
- break;
+ register int i, cnt = 0, ljustf, lval;
+ int preci, dpoint, width;
+ char pad, sign, radix, hash;
+ register char *ptmp;
+ char tmp[64], *ltostr(), *ultostr();
+ int buffer_mode;
+
+ /* This speeds things up a bit for unbuffered */
+ buffer_mode = (op->mode & __MODE_BUF);
+ op->mode &= (~__MODE_BUF);
+
+ while (*fmt) {
+ if (*fmt == '%') {
+ if (buffer_mode == _IONBF)
+ fflush(op);
+ ljustf = 0; /* left justify flag */
+ sign = '\0'; /* sign char & status */
+ pad = ' '; /* justification padding char */
+ width = -1; /* min field width */
+ dpoint = 0; /* found decimal point */
+ preci = -1; /* max data width */
+ radix = 10; /* number base */
+ ptmp = tmp; /* pointer to area to print */
+ hash = 0;
+ lval = (sizeof(int) == sizeof(long)); /* long value flaged */
+
+ fmtnxt:
+ i = 0;
+ for (;;) {
+ ++fmt;
+ if (*fmt < '0' || *fmt > '9')
+ break;
+ i = (i * 10) + (*fmt - '0');
+ if (dpoint)
+ preci = i;
+ else if (!i && (pad == ' ')) {
+ pad = '0';
+ goto fmtnxt;
+ } else
+ width = i;
+ }
+
+ switch (*fmt) {
+ case '\0': /* early EOS */
+ --fmt;
+ goto charout;
+
+ case '-': /* left justification */
+ ljustf = 1;
+ goto fmtnxt;
+
+ case ' ':
+ case '+': /* leading sign flag */
+ sign = *fmt;
+ goto fmtnxt;
+
+ case '*': /* parameter width value */
+ i = va_arg(ap, int);
+
+ if (dpoint)
+ preci = i;
+ else
+ width = i;
+ goto fmtnxt;
+
+ case '.': /* secondary width field */
+ dpoint = 1;
+ goto fmtnxt;
+
+ case 'l': /* long data */
+ lval = 1;
+ goto fmtnxt;
+
+ case 'h': /* short data */
+ lval = 0;
+ goto fmtnxt;
+
+ case 'd': /* Signed decimal */
+ case 'i':
+ ptmp = ltostr((long) ((lval)
+ ? va_arg(ap, long)
+ : va_arg(ap, short)), 10, 0);
+
+ goto printit;
+
+ case 'b': /* Unsigned binary */
+ radix = 2;
+ goto usproc;
+
+ case 'o': /* Unsigned octal */
+ radix = 8;
+ goto usproc;
+
+ case 'p': /* Pointer */
+ lval = (sizeof(char *) == sizeof(long));
+
+ pad = '0';
+ width = 6;
+ preci = 8;
+ /* fall thru */
+
+ case 'x': /* Unsigned hexadecimal */
+ case 'X':
+ radix = 16;
+ /* fall thru */
+
+ case 'u': /* Unsigned decimal */
+ usproc:
+ ptmp = ultostr((unsigned long) ((lval)
+ ? va_arg(ap, unsigned long)
+ : va_arg(ap,
+ unsigned short)),
+ radix, (*fmt == 'X') ? 1 : 0);
+
+ if (hash && radix == 8) {
+ width = strlen(ptmp) + 1;
+ pad = '0';
+ }
+ goto printit;
+
+ case '#':
+ hash = 1;
+ goto fmtnxt;
+
+ case 'c': /* Character */
+ ptmp[0] = va_arg(ap, int);
+
+ ptmp[1] = '\0';
+ goto nopad;
+
+ case 's': /* String */
+ ptmp = va_arg(ap, char *);
+
+ nopad:
+ sign = '\0';
+ pad = ' ';
+ printit:
+ cnt += printfield(op, ptmp, ljustf, sign, pad, width,
+ preci, buffer_mode, max_size, cnt);
+ break;
#if FLOATS
- case 'e': /* float */
- case 'f':
- case 'g':
- case 'E':
- case 'G':
- fprintf(stderr, "LIBM:PRINTF");
- gcvt(va_arg(ap, double), preci, ptmp);
- preci = -1;
- goto printit;
+ case 'e': /* float */
+ case 'f':
+ case 'g':
+ case 'E':
+ case 'G':
+ fprintf(stderr, "LIBM:PRINTF");
+ gcvt(va_arg(ap, double), preci, ptmp);
+
+ preci = -1;
+ goto printit;
#else
- case 'e': /* float */
- case 'f':
- case 'g':
- case 'E':
- case 'G':
- fprintf(stderr, "LIBC:PRINTF");
- exit(-1);
+ case 'e': /* float */
+ case 'f':
+ case 'g':
+ case 'E':
+ case 'G':
+ fprintf(stderr, "LIBC:PRINTF");
+ exit(-1);
#endif
- default: /* unknown character */
- goto charout;
- }
- }
- else
- {
- charout:
- if (max_size>0 && ++cnt<max_size)
- putc(*fmt, op); /* normal char out */
- if( *fmt == '\n' && buffer_mode == _IOLBF ) fflush(op);
- }
- ++fmt;
- }
- op->mode |= buffer_mode;
- if( buffer_mode == _IONBF ) fflush(op);
- if( buffer_mode == _IOLBF ) op->bufwrite = op->bufstart;
- return (cnt);
+ default: /* unknown character */
+ goto charout;
+ }
+ } else {
+ charout:
+ if (max_size > 0 && ++cnt < max_size)
+ putc(*fmt, op); /* normal char out */
+ if (*fmt == '\n' && buffer_mode == _IOLBF)
+ fflush(op);
+ }
+ ++fmt;
+ }
+ op->mode |= buffer_mode;
+ if (buffer_mode == _IONBF)
+ fflush(op);
+ if (buffer_mode == _IOLBF)
+ op->bufwrite = op->bufstart;
+ return (cnt);
}
-int vfprintf(FILE *op, register __const char *fmt, register va_list ap)
+int vfprintf(FILE * op, register __const char *fmt, register va_list ap)
{
- return(vfnprintf(op, -1, fmt, ap));
+ return (vfnprintf(op, -1, fmt, ap));
}
#endif
-
diff --git a/libc/stdio/scanf.c b/libc/stdio/scanf.c
index 593e01d25..8ce590684 100644
--- a/libc/stdio/scanf.c
+++ b/libc/stdio/scanf.c
@@ -14,64 +14,66 @@
#ifdef L_scanf
#ifdef __STDC__
-int scanf(const char * fmt, ...)
+int scanf(const char *fmt, ...)
#else
int scanf(fmt, va_alist)
__const char *fmt;
va_dcl
#endif
{
- va_list ptr;
- int rv;
- va_strt(ptr, fmt);
- rv = vfscanf(stdin,fmt,ptr);
- va_end(ptr);
- return rv;
+ va_list ptr;
+ int rv;
+
+ va_strt(ptr, fmt);
+ rv = vfscanf(stdin, fmt, ptr);
+ va_end(ptr);
+ return rv;
}
#endif
#ifdef L_sscanf
#ifdef __STDC__
-int sscanf(const char * sp, const char * fmt, ...)
+int sscanf(const char *sp, const char *fmt, ...)
#else
int sscanf(sp, fmt, va_alist)
-__const char * sp;
+__const char *sp;
__const char *fmt;
va_dcl
#endif
{
- FILE string[1] =
- {
- {0, (char*)(unsigned) -1, 0, 0, (char*) (unsigned) -1, -1,
- _IOFBF | __MODE_READ}
- };
-
- va_list ptr;
- int rv;
- va_strt(ptr, fmt);
- string->bufpos = (unsigned char *)((void*)sp);
- rv = vfscanf(string,fmt,ptr);
- va_end(ptr);
- return rv;
+ FILE string[1] = {
+ {0, (char *) (unsigned) -1, 0, 0, (char *) (unsigned) -1, -1,
+ _IOFBF | __MODE_READ}
+ };
+
+ va_list ptr;
+ int rv;
+
+ va_strt(ptr, fmt);
+ string->bufpos = (unsigned char *) ((void *) sp);
+ rv = vfscanf(string, fmt, ptr);
+ va_end(ptr);
+ return rv;
}
#endif
#ifdef L_fscanf
#ifdef __STDC__
-int fscanf(FILE * fp, const char * fmt, ...)
+int fscanf(FILE * fp, const char *fmt, ...)
#else
int fscanf(fp, fmt, va_alist)
-FILE * fp;
+FILE *fp;
__const char *fmt;
va_dcl
#endif
{
- va_list ptr;
- int rv;
- va_strt(ptr, fmt);
- rv = vfscanf(fp,fmt,ptr);
- va_end(ptr);
- return rv;
+ va_list ptr;
+ int rv;
+
+ va_strt(ptr, fmt);
+ rv = vfscanf(fp, fmt, ptr);
+ va_end(ptr);
+ return rv;
}
#endif
@@ -80,21 +82,20 @@ int vscanf(fmt, ap)
__const char *fmt;
va_list ap;
{
- return vfscanf(stdin,fmt,ap);
+ return vfscanf(stdin, fmt, ap);
}
#endif
#ifdef L_vsscanf
int vsscanf(__const char *sp, __const char *fmt, va_list ap)
{
- FILE string[1] =
- {
- {0, (char*)(unsigned) -1, 0, 0, (char*) (unsigned) -1, -1,
- _IOFBF | __MODE_READ}
- };
-
- string->bufpos = (unsigned char *)((void*)sp);
- return vfscanf(string,fmt,ap);
+ FILE string[1] = {
+ {0, (char *) (unsigned) -1, 0, 0, (char *) (unsigned) -1, -1,
+ _IOFBF | __MODE_READ}
+ };
+
+ string->bufpos = (unsigned char *) ((void *) sp);
+ return vfscanf(string, fmt, ap);
}
#endif
@@ -112,23 +113,23 @@ int _vfscanf_fp_ref = 0;
#if FLOATS
/* fp scan actions */
-#define F_NADA 0 /* just change state */
-#define F_SIGN 1 /* set sign */
-#define F_ESIGN 2 /* set exponent's sign */
-#define F_INT 3 /* adjust integer part */
-#define F_FRAC 4 /* adjust fraction part */
-#define F_EXP 5 /* adjust exponent part */
+#define F_NADA 0 /* just change state */
+#define F_SIGN 1 /* set sign */
+#define F_ESIGN 2 /* set exponent's sign */
+#define F_INT 3 /* adjust integer part */
+#define F_FRAC 4 /* adjust fraction part */
+#define F_EXP 5 /* adjust exponent part */
#define F_QUIT 6
#define NSTATE 8
-#define FS_INIT 0 /* initial state */
-#define FS_SIGNED 1 /* saw sign */
-#define FS_DIGS 2 /* saw digits, no . */
-#define FS_DOT 3 /* saw ., no digits */
-#define FS_DD 4 /* saw digits and . */
-#define FS_E 5 /* saw 'e' */
-#define FS_ESIGN 6 /* saw exp's sign */
-#define FS_EDIGS 7 /* saw exp's digits */
+#define FS_INIT 0 /* initial state */
+#define FS_SIGNED 1 /* saw sign */
+#define FS_DIGS 2 /* saw digits, no . */
+#define FS_DOT 3 /* saw ., no digits */
+#define FS_DD 4 /* saw digits and . */
+#define FS_E 5 /* saw 'e' */
+#define FS_ESIGN 6 /* saw exp's sign */
+#define FS_EDIGS 7 /* saw exp's digits */
#define FC_DIG 0
#define FC_DOT 1
@@ -137,400 +138,376 @@ int _vfscanf_fp_ref = 0;
/* given transition,state do what action? */
int fp_do[][NSTATE] = {
- {F_INT,F_INT,F_INT,
- F_FRAC,F_FRAC,
- F_EXP,F_EXP,F_EXP}, /* see digit */
- {F_NADA,F_NADA,F_NADA,
- F_QUIT,F_QUIT,F_QUIT,F_QUIT,F_QUIT}, /* see '.' */
- {F_QUIT,F_QUIT,
- F_NADA,F_QUIT,F_NADA,
- F_QUIT,F_QUIT,F_QUIT}, /* see e/E */
- {F_SIGN,F_QUIT,F_QUIT,F_QUIT,F_QUIT,
- F_ESIGN,F_QUIT,F_QUIT}, /* see sign */
+ {F_INT, F_INT, F_INT,
+ F_FRAC, F_FRAC,
+ F_EXP, F_EXP, F_EXP}, /* see digit */
+ {F_NADA, F_NADA, F_NADA,
+ F_QUIT, F_QUIT, F_QUIT, F_QUIT, F_QUIT}, /* see '.' */
+ {F_QUIT, F_QUIT,
+ F_NADA, F_QUIT, F_NADA,
+ F_QUIT, F_QUIT, F_QUIT}, /* see e/E */
+ {F_SIGN, F_QUIT, F_QUIT, F_QUIT, F_QUIT,
+ F_ESIGN, F_QUIT, F_QUIT}, /* see sign */
};
+
/* given transition,state what is new state? */
int fp_ns[][NSTATE] = {
- {FS_DIGS,FS_DIGS,FS_DIGS,
- FS_DD,FS_DD,
- FS_EDIGS,FS_EDIGS,FS_EDIGS}, /* see digit */
- {FS_DOT,FS_DOT,FS_DD,
- }, /* see '.' */
- {0,0,
- FS_E,0,FS_E,
- }, /* see e/E */
- {FS_SIGNED,0,0,0,0,
- FS_ESIGN,0,0}, /* see sign */
+ {FS_DIGS, FS_DIGS, FS_DIGS,
+ FS_DD, FS_DD,
+ FS_EDIGS, FS_EDIGS, FS_EDIGS}, /* see digit */
+ {FS_DOT, FS_DOT, FS_DD,
+ }, /* see '.' */
+ {0, 0,
+ FS_E, 0, FS_E,
+ }, /* see e/E */
+ {FS_SIGNED, 0, 0, 0, 0,
+ FS_ESIGN, 0, 0}, /* see sign */
};
+
/* which states are valid terminators? */
int fp_sval[NSTATE] = {
- 0,0,1,0,1,0,0,1
+ 0, 0, 1, 0, 1, 0, 0, 1
};
#endif
-int
-vfscanf(fp, fmt, ap)
+int vfscanf(fp, fmt, ap)
register FILE *fp;
register const char *fmt;
va_list ap;
{
- register long n;
- register int c, width, lval, cnt = 0;
- int store, neg, base, wide1, endnull, rngflag, c2;
- register unsigned char *p;
- unsigned char delim[128], digits[17], *q;
+ register long n;
+ register int c, width, lval, cnt = 0;
+ int store, neg, base, wide1, endnull, rngflag, c2;
+ register unsigned char *p;
+ unsigned char delim[128], digits[17], *q;
+
#if FLOATS
- long frac, expo;
- int eneg, fraclen, fstate, trans;
- double fx, fp_scan();
+ long frac, expo;
+ int eneg, fraclen, fstate, trans;
+ double fx, fp_scan();
#endif
- if (!*fmt)
- return (0);
-
- c = getc(fp);
- while (c > 0)
- {
- store = 0;
- if (*fmt == '%')
- {
- n = 0;
- width = -1;
- wide1 = 1;
- base = 10;
- lval = (sizeof(long) == sizeof(int));
- store = 1;
- endnull = 1;
- neg = -1;
-
- strcpy(delim, "\011\012\013\014\015 ");
- strcpy(digits, "0123456789ABCDEF");
-
- if (fmt[1] == '*')
- {
- endnull = store = 0;
- ++fmt;
- }
-
- while (isdigit(*++fmt))/* width digit(s) */
- {
- if (width == -1)
- width = 0;
- wide1 = width = (width * 10) + (*fmt - '0');
- }
- --fmt;
- fmtnxt:
- ++fmt;
- switch (tolower(*fmt)) /* tolower() is a MACRO! */
- {
- case '*':
- endnull = store = 0;
- goto fmtnxt;
-
- case 'l': /* long data */
- lval = 1;
- goto fmtnxt;
- case 'h': /* short data */
- lval = 0;
- goto fmtnxt;
-
- case 'i': /* any-base numeric */
- base = 0;
- goto numfmt;
-
- case 'b': /* unsigned binary */
- base = 2;
- goto numfmt;
-
- case 'o': /* unsigned octal */
- base = 8;
- goto numfmt;
-
- case 'x': /* unsigned hexadecimal */
- base = 16;
- goto numfmt;
-
- case 'd': /* SIGNED decimal */
- neg = 0;
- /* FALL-THRU */
-
- case 'u': /* unsigned decimal */
- numfmt:skip();
-
- if (isupper(*fmt))
- lval = 1;
-
- if (!base)
- {
- base = 10;
- neg = 0;
- if (c == '%')
- {
- base = 2;
- goto skip1;
- }
- else if (c == '0')
- {
- c = getc(fp);
- if (c < 1)
- goto savnum;
- if ((c != 'x')
- && (c != 'X'))
- {
- base = 8;
- digits[8] = '\0';
- goto zeroin;
- }
- base = 16;
- goto skip1;
- }
- }
-
- if ((neg == 0) && (base == 10)
- && ((neg = (c == '-')) || (c == '+')))
- {
- skip1:
- c = getc(fp);
- if (c < 1)
- goto done;
- }
-
- digits[base] = '\0';
- p = ((unsigned char *)
- strchr(digits, toupper(c)));
-
- if ((!c || !p) && width)
- goto done;
-
- while (p && width-- && c)
- {
- n = (n * base) + (p - digits);
- c = getc(fp);
- zeroin:
- p = ((unsigned char *)
- strchr(digits, toupper(c)));
- }
- savnum:
- if (store)
- {
- if (neg == 1)
- n = -n;
- if (lval)
- *va_arg(ap, long*) = n;
- else
- *va_arg(ap, short*) = n;
- ++cnt;
- }
- break;
+ if (!*fmt)
+ return (0);
+
+ c = getc(fp);
+ while (c > 0) {
+ store = 0;
+ if (*fmt == '%') {
+ n = 0;
+ width = -1;
+ wide1 = 1;
+ base = 10;
+ lval = (sizeof(long) == sizeof(int));
+
+ store = 1;
+ endnull = 1;
+ neg = -1;
+
+ strcpy(delim, "\011\012\013\014\015 ");
+ strcpy(digits, "0123456789ABCDEF");
+
+ if (fmt[1] == '*') {
+ endnull = store = 0;
+ ++fmt;
+ }
+
+ while (isdigit(*++fmt)) { /* width digit(s) */
+ if (width == -1)
+ width = 0;
+ wide1 = width = (width * 10) + (*fmt - '0');
+ }
+ --fmt;
+ fmtnxt:
+ ++fmt;
+ switch (tolower(*fmt)) { /* tolower() is a MACRO! */
+ case '*':
+ endnull = store = 0;
+ goto fmtnxt;
+
+ case 'l': /* long data */
+ lval = 1;
+ goto fmtnxt;
+ case 'h': /* short data */
+ lval = 0;
+ goto fmtnxt;
+
+ case 'i': /* any-base numeric */
+ base = 0;
+ goto numfmt;
+
+ case 'b': /* unsigned binary */
+ base = 2;
+ goto numfmt;
+
+ case 'o': /* unsigned octal */
+ base = 8;
+ goto numfmt;
+
+ case 'x': /* unsigned hexadecimal */
+ base = 16;
+ goto numfmt;
+
+ case 'd': /* SIGNED decimal */
+ neg = 0;
+ /* FALL-THRU */
+
+ case 'u': /* unsigned decimal */
+ numfmt:skip();
+
+ if (isupper(*fmt))
+ lval = 1;
+
+ if (!base) {
+ base = 10;
+ neg = 0;
+ if (c == '%') {
+ base = 2;
+ goto skip1;
+ } else if (c == '0') {
+ c = getc(fp);
+ if (c < 1)
+ goto savnum;
+ if ((c != 'x')
+ && (c != 'X')) {
+ base = 8;
+ digits[8] = '\0';
+ goto zeroin;
+ }
+ base = 16;
+ goto skip1;
+ }
+ }
+
+ if ((neg == 0) && (base == 10)
+ && ((neg = (c == '-')) || (c == '+'))) {
+ skip1:
+ c = getc(fp);
+ if (c < 1)
+ goto done;
+ }
+
+ digits[base] = '\0';
+ p = ((unsigned char *)
+ strchr(digits, toupper(c)));
+
+ if ((!c || !p) && width)
+ goto done;
+
+ while (p && width-- && c) {
+ n = (n * base) + (p - digits);
+ c = getc(fp);
+ zeroin:
+ p = ((unsigned char *)
+ strchr(digits, toupper(c)));
+ }
+ savnum:
+ if (store) {
+ if (neg == 1)
+ n = -n;
+ if (lval)
+ *va_arg(ap, long *) = n;
+
+ else
+ *va_arg(ap, short *) = n;
+
+ ++cnt;
+ }
+ break;
#if FLOATS
- case 'e': /* float */
- case 'f':
- case 'g':
- skip();
- fprintf(stderr,"LIBM:SCANF");
-
- if (isupper(*fmt))