cechew@bruce.OZ (Earl Chew) (09/04/89)
#! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 6 (of 7)." # Contents: tfwrite.c tprintf.c tputc.c ungetc.c vfprintf.c vfscanf.c # Wrapped by cechew@bruce on Mon Sep 4 12:50:19 1989 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'tfwrite.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'tfwrite.c'\" else echo shar: Extracting \"'tfwrite.c'\" \(290 characters\) sed "s/^X//" >'tfwrite.c' <<'END_OF_FILE' X#include <stdio.h> X Xmain() X X{ X char *malloc(); X void exit(); X char *b; X int i; X X if ((b = malloc(48*1024)) == 0) { X fputs("No memory for buffer\n", stderr); X exit(1); X } X X for (i = 0; i < 100; i++) X fwrite(b, 1023, 1, stdout); X X fwrite(b, 1023, 48, stdout); X X return 0; X} END_OF_FILE if test 290 -ne `wc -c <'tfwrite.c'`; then echo shar: \"'tfwrite.c'\" unpacked with wrong size! fi # end of 'tfwrite.c' fi if test -f 'tprintf.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'tprintf.c'\" else echo shar: Extracting \"'tprintf.c'\" \(235 characters\) sed "s/^X//" >'tprintf.c' <<'END_OF_FILE' X#include <stdio.h> X Xmain() X X{ X int i; X X for (i = 0; i < 1000; i++) { X printf(" Heading Line \n\ X%70s\n\ X%70d\n\ X%70ld\n", X"String to be printed as a test", 0x7fff, 0x7ffffffL); X } X return 0; X} END_OF_FILE if test 235 -ne `wc -c <'tprintf.c'`; then echo shar: \"'tprintf.c'\" unpacked with wrong size! fi # end of 'tprintf.c' fi if test -f 'tputc.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'tputc.c'\" else echo shar: Extracting \"'tputc.c'\" \(150 characters\) sed "s/^X//" >'tputc.c' <<'END_OF_FILE' X#include <stdio.h> X Xmain() X X{ X int i, j; X X for (i = 0; i < 1000; i++) { X for (j = 0; j < 26; j++) X putchar('a'+j); X putchar('\n'); X } X} END_OF_FILE if test 150 -ne `wc -c <'tputc.c'`; then echo shar: \"'tputc.c'\" unpacked with wrong size! fi # end of 'tputc.c' fi if test -f 'ungetc.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ungetc.c'\" else echo shar: Extracting \"'ungetc.c'\" \(859 characters\) sed "s/^X//" >'ungetc.c' <<'END_OF_FILE' X/* u n g e t c X * X * This function pushes a character back into an input stream. The X * character will be returned by the next getc call on the stream. X * One character of pushback is guaranteed provided something X * is read from the stream. X * X * Attempts to pushback EOF will fail and the function will return X * EOF, otherwise the character pushed back will be returned. EOF X * will also be returned if the attempt to pushback fails. X * X * Patchlevel 1.0 X * X * Edit History: X */ X X#include "stdiolib.h" X X/*LINTLIBRARY*/ X Xint ungetc(ch, fp) X Xint ch; /* character to push back */ XFILE *fp; X X{ X if (ch == EOF || TESTFLAG(fp, _IOREAD) == 0 || X fp->_base == NULL || (fp->_ptr == fp->_base && ! TESTFLAG(fp, _IONBF))) X return EOF; X X if (TESTFLAG(fp, _IONBF) != 0) X fp->_ptr = fp->_end = fp->_base + fp->_bufsiz; X X return *--fp->_ptr = ch; X} END_OF_FILE if test 859 -ne `wc -c <'ungetc.c'`; then echo shar: \"'ungetc.c'\" unpacked with wrong size! fi # end of 'ungetc.c' fi if test -f 'vfprintf.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'vfprintf.c'\" else echo shar: Extracting \"'vfprintf.c'\" \(7073 characters\) sed "s/^X//" >'vfprintf.c' <<'END_OF_FILE' X/* v f p r i n t f X * X * This routine provides the same functionality as fprintf X * except that it uses varargs.h. X * X * In this implementation, this routine is basis for all the X * formatted output routines. printf, fprintf, and sprintf X * are all defined in terms of vfprintf. X * X * The user is referred to the manual page for a full X * description of the formats available. X * X * The function returns the number of bytes generated, or X * EOF in the case of an error. X * X * Patchlevel 1.0 X * X * Edit History: X * 03-Sep-1989 Use PUTC() for faster printf processing. Unroll X * formatting loops. X */ X X#include "stdiolib.h" X X/*LINTLIBRARY*/ X X#define MINBITS 3 /* least bits required --- octal */ X#define MAXPREFIX 3 /* overhead for prefix */ X X#define MAXDIGITS ((sizeof(long)+MINBITS-1)/MINBITS*MINBITS) X#define VBUFFERSIZE MAXDIGITS+MAXPREFIX X X#define OPTIONAL(p,c,f,v) if(*(p)==(c)){(f)=(v);(p)++;} X X/* Get an integer argument X * X * Scan the string beginning at the point indicated for an X * integer argument. If a '*' is found, the argument pointer X * is used to retrieve a remote integer. X */ X Xstatic int integer(p, ap) X Xchar **p; /* pointer to string pointer */ Xva_list *ap; /* pointer to argument list */ X X{ X char *cp; /* character pointer */ X int v; /* return value */ X X cp = *p; X X if (*cp == '*') { X v = va_arg(*ap, int); X cp++; X } X else { X for (v = 0; *cp >= '0' && *cp <= '9'; ) { X v *= 10; X v += (*cp++ - '0'); X } X } X *p = cp; X return v; X} X Xint vfprintf(fp, fmt, args) X XFILE *fp; /* stream for output */ Xchar *fmt; /* format for output */ Xva_list args; /* argument list */ X X{ X char buf[VBUFFERSIZE]; /* workspace */ X int bytes; /* bytes output */ X X char *p, *q; /* pointers into workspace */ X X char leftjustify; /* left justify */ X char showsign; /* display a sign */ X char blankprefix; /* prefix with blank */ X char alternate; /* alternate format */ X X char zerofill; /* fill with zeros */ X char flush; /* need to flush afterwards */ X int width; /* field width */ X X int precision; /* precision */ X X char longflag; /* number is long */ X X char capitals; /* capitals */ X char backward; /* direction for scan */ X X char prefix; /* number has prefix -/ /+ */ X X unsigned int radix; /* radix for conversion */ X char sign; /* conversion is signed */ X char negative; /* number is negative */ X long vl; /* conversion temporary */ X unsigned short vs; /* conversion temporary */ X char shortint; /* short or long */ X int c; /* conversion temporary */ X int length; /* raw length of output */ X X for (flush = bytes = 0; *fmt != 0; ) { X X/* Look for the next format field */ X for (p = fmt; ; ) { X if (*p == 0 || *p == '%') break; X if (PUTC(*p++, fp) == '\n') flush = 1; X if (*p == 0 || *p == '%') break; X if (PUTC(*p++, fp) == '\n') flush = 1; X } X bytes += p - fmt; X if (*p == 0) break; X fmt = p + 1; X X/* Initialise conversion variables */ X p = q = buf; X X leftjustify = 0; X showsign = 0; X blankprefix = 0; X alternate = 0; X X zerofill = ' '; X width = 0; X X precision = -1; X X longflag = 0; X capitals = 0; X X backward = 0; X X prefix = 0; X X/* Check for optional flags */ X for ( ; ; ) { X switch (*fmt) { X case '-': leftjustify = 1; break; X case '+': showsign = 1; break; X case ' ': blankprefix = 1; break; X case '#': alternate = 1; break; X default: goto DoneFlags; X } X fmt++; X } XDoneFlags: X X/* Check for field width */ X OPTIONAL(fmt, '0', zerofill, '0'); X width = integer(&fmt, &args); X X/* Check for precision */ X if (*fmt == '.') { X fmt++; X precision = integer(&fmt, &args); X } X X/* Check for longs */ X OPTIONAL(fmt, 'l', longflag, 1); X X/* Switch through all the format options */ X switch (*fmt) { X X case 'X': X capitals++; X case 'x': X radix = 16; X sign = 0; X goto oxud; X X case 'u': X radix = 10; X sign = 0; X goto oxud; X X case 'o': X radix = 8; X sign = 0; X goto oxud; X X case 'd': X radix = 10; X sign = 1; X Xoxud: X backward++; X vs = shortint = 0; X if (longflag) X if (sign) vl = va_arg(args, long); X else vl = va_arg(args, unsigned long); X else X if (sign) vl = va_arg(args, int); X else vl = va_arg(args, unsigned); X if ((negative = sign && vl < 0) != 0) X vl = -vl; X do { XConversion: X if (shortint) { X c = (vs % (unsigned short) radix) + '0'; X vs /= (unsigned short) radix; X } X else { X if (vl == (unsigned short) vl) { X vs = (unsigned short) vl; X shortint = 1; X goto Conversion; X } X else { X c = (int) ((unsigned long) (vl) % radix) + '0'; X vl = (unsigned long) (vl) / radix; X } X } X if (c > '9') { X c += ('a' - '9' - 1); X if (capitals) X c+= ('A' - 'a'); X } X *p++ = c; X } while (shortint ? (vs != 0) : (vl != 0)); X if (precision > width) { X width = precision; X zerofill = '0'; X } X if (negative) { X prefix++; X *p++ = '-'; X } X else if (sign) { X if (showsign) { X prefix++; X *p++ = '+'; X } X else if (blankprefix) { X prefix++; X *p++ = ' '; X } X } X if (alternate) { X if (radix == 8) { X prefix++; X *p++ = '0'; X } X else if (radix == 16) { X prefix += 2; X *p++ = capitals ? 'X' : 'x'; X *p++ = '0'; X } X } X break; X X/* Single character format */ X case 'c': X if ((*p++ = va_arg(args, int)) == '\n') X flush = 1; X break; X X/* String format */ X case 's': X if ((q = va_arg(args, char *)) == NULL) X q = "(null)"; X p = q; X if (precision > 0) { X UNROLL_DO(dostring, precision, X if (*p == 0) break; X if (*p++ == '\n') flush = 1); X } X else if (precision < 0) { X for ( ; ; ) { X if (*p == 0) break; X if (*p++ == '\n') flush = 1; X } X } X break; X X/* Default just print it */ X default: X if ((*p++ = *fmt) == '\n') X flush = 1; X break; X } X X/* Scan past conversion character */ X fmt++; X X/* Length of string to be printed */ X length = p - q; X X/* Subtract to find padding required */ X if ((width -= length) < 0) X width = 0; X X/* Signal left justification */ X if (leftjustify == 0) X width = -width; X X/* Check for left justification */ X if (width < 0) { X X/* Check for negative and zero fill */ X if (zerofill == '0') { X if (prefix != 0) { X bytes += prefix; X length -= prefix; X UNROLL_DO(doprefix, prefix, PUTC(backward ? *--p : *q++, fp)); X } X } X X/* Now output the rest of the padding */ X width = -width; X bytes += width; X UNROLL_DO(doleft, width, PUTC(zerofill, fp)); X } X X/* Output the string proper */ X if (length > 0) { X bytes += length; X UNROLL_DO(dooutput, length, PUTC(backward ? *--p : *q++, fp)); X } X X/* Do right padding */ X if (width != 0) { X bytes += width; X UNROLL_DO(doright, width, PUTC(' ', fp)); X } X } X X/* Flush line buffered streams */ X if (flush && TESTFLAG(fp, _IOLBF)) X (void) fflush(fp); X X return ferror(fp) ? EOF : bytes; X} END_OF_FILE if test 7073 -ne `wc -c <'vfprintf.c'`; then echo shar: \"'vfprintf.c'\" unpacked with wrong size! fi # end of 'vfprintf.c' fi if test -f 'vfscanf.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'vfscanf.c'\" else echo shar: Extracting \"'vfscanf.c'\" \(6291 characters\) sed "s/^X//" >'vfscanf.c' <<'END_OF_FILE' X/* v f s c a n f X * X * Formatted read from a stream. This function uses varargs to X * obtain the argument list. It is the basis of the family of X * scanf functions in this stdio implementation. X * X * The user is referred to the manual page for a full X * description of the formats available. X * X * The function returns EOF on end of input, and a short count X * for missing or illegal data items. X * X * Patchlevel 1.0 X * X * Edit History: X */ X X#include <ctype.h> X#include "stdiolib.h" X#include "bitset.h" X X#if defined(BSD) X# include <values.h> X# define TOLOWER(c) (isupper((c)) ? tolower((c)) : (c)) X# define CHARSET (1 << (BITSPERBYTE)) X#endif X X#if defined(MINIX) || defined(__MSDOS__) || defined(MSDOS) X# include <limits.h> X# define TOLOWER(c) (tolower((c))) X# define CHARSET (1 << (CHAR_BIT)) X extern int tolower Prototype((int)); X#endif X X#define WHITESPACE(c) ((c)==' '||(c)=='\t'||(c)=='\n') X#define NEXTCH() (ch = getc(fp)) X#define ENDFIELD() \ X if (fieldok) { \ X if (! noassign) items++; \ X } \ X else \ X goto Putback; X Xint vfscanf(fp, fmt, args) X XFILE *fp; /* stream */ Xchar *fmt; /* format */ Xva_list args; /* arguments */ X X{ X bitstring(cset, CHARSET); /* set for %[] */ X int items; /* number of items done */ X int ch; /* next character */ X int lch; /* lowercase version of character */ X int i; /* general index */ X char *p; /* string pointer */ X char skipspace; /* force white space skip */ X char noassign; /* do not do assignment */ X char longflag; /* pointer is long */ X char shortflag; /* pointer is short */ X char fieldok; /* this field parsed ok */ X char invertedset; /* inverted set */ X char sign; /* conversion is signed */ X char negative; /* number is negative */ X int fieldwidth; /* width of field */ X unsigned radix; /* radix for conversion */ X unsigned lastdigit; /* last digit (0-9) in radix */ X long longv; /* long value for conversion */ X X/* Prime the look ahead character */ X if (NEXTCH() == EOF) X return EOF; X X for (items = 0; ; fmt++) { X X/* Skip whitespace in format */ X for (skipspace = 0; WHITESPACE(*fmt); fmt++) X skipspace = 1; X X/* Check for end of format or end of input */ X if (*fmt == 0 || ch == EOF) X goto Putback; X X/* Check for verbatim character */ X if (*fmt != '%') { X while (WHITESPACE(ch)) X NEXTCH(); X X if (ch != *fmt) X goto Putback; X X NEXTCH(); X continue; X } X X/* Format precursor seen --- see if assignment required */ X if ((noassign = *++fmt == '*') != 0) X fmt++; X X/* Check for width specification */ X fieldwidth = -1; X if (*fmt >= '0' && *fmt <= '9') { X for (fieldwidth = 0; *fmt >= '0' && *fmt <= '9'; ) X fieldwidth = fieldwidth * 10 + *fmt++ - '0'; X } X X/* Check for long or short pointers */ X if ((longflag = *fmt == 'l') != 0 || (shortflag = *fmt == 'h') != 0) X fmt++; X X/* Skip whitespace in the input stream */ X if (skipspace || (*fmt != 'c' && *fmt != '[')) { X while (WHITESPACE(ch)) X NEXTCH(); X } X X/* Assume that field is not parsed */ X fieldok = 0; X X switch (*fmt) { X X case 'O': longflag = 1; X case 'o': radix = 8; lastdigit = '7'; sign = 0; goto oxud; X case 'U': longflag = 1; X case 'u': radix = 10; lastdigit = '9'; sign = 0; goto oxud; X case 'D': longflag = 1; X case 'd': radix = 10; lastdigit = '9'; sign = 1; goto oxud; X case 'X': longflag = 1; X case 'x': radix = 16; lastdigit = '9'; sign = 0; X Xoxud: X longv = 0; X negative = 0; X X/* Look for sign if number is signed */ X if (fieldwidth != 0 && sign && ch == '+') X NEXTCH(); X else if (fieldwidth != 0 && sign && ch == '-') { X negative = 1; X NEXTCH(); X } X X/* Scan and convert */ X while (fieldwidth < 0 || fieldwidth--) { X if (ch >= '0' && ch <= lastdigit) X ch -= '0'; X else { X lch = TOLOWER(ch); X if (lch >= 'a' && (lch += 10 - 'a') < radix) X ch = lch; X else X break; X } X longv = longv * radix + ch; X NEXTCH(); X fieldok = 1; X } X X/* Complete the conversion */ X if (! noassign) { X if (negative) X longv = -longv; X if (longflag) X if (sign) *va_arg(args, long *) = longv; X else *va_arg(args, unsigned long *) = longv; X else if (shortflag) X if (sign) *va_arg(args, short *) = (short) longv; X else *va_arg(args, unsigned short *) = (unsigned short) longv; X else X if (sign) *va_arg(args, int *) = (int) longv; X else *va_arg(args, unsigned int *) = (unsigned int) longv; X } X ENDFIELD(); X break; X X case 'c': X if (fieldwidth == -1) X fieldwidth = 1; X X/* Initialise the string pointer */ X if (! noassign) X p = va_arg(args, char *); X X while (fieldwidth-- && ch >= 0) { X *p++ = ch; X NEXTCH(); X fieldok = 1; X } X ENDFIELD(); X break; X X case 's': X X/* Initialise the string pointer */ X if (! noassign) X p = va_arg(args, char *); X X while (fieldwidth < 0 || fieldwidth--) { X if (ch <= 0 || WHITESPACE(ch)) X break; X *p++ = ch; X NEXTCH(); X fieldok = 1; X } X X/* Terminate the string with a null */ X if (! noassign) X *p++ = 0; X ENDFIELD(); X break; X X case '[': X X /* Clear the bit set */ X bitempty(cset, CHARSET); X X/* Check for inverted set */ X if ((invertedset = *++fmt == '^') != 0) X fmt++; X X/* Check for right bracket in set */ X if (*fmt == ']') X bitset(cset, *fmt++); X X/* Scan search set, setting bits */ X while (*fmt != 0 && *fmt != ']') { X if (fmt[1] != '-' || fmt[2] == ']' || fmt[2] == 0 || fmt[0] > fmt[2]) X bitset(cset, *fmt++); X else { X for (i = fmt[0]; i <= fmt[2]; i++) X bitset(cset, i); X fmt += 3; X } X } X X/* Check for unsatisfactory set construction */ X if (*fmt != ']') X goto Putback; X X/* Initialise string pointer */ X if (! noassign) X p = va_arg(args, char *); X X/* Scan input for satisfactory characters */ X while (fieldwidth < 0 || fieldwidth--) { X if (WHITESPACE(ch) || ch <= 0 || ! (bittest(cset, ch) ^ invertedset)) X break; X *p++ = ch; X NEXTCH(); X fieldok = 1; X } X X/* Terminate string with null */ X if (! noassign) X *p++ = 0; X ENDFIELD(); X break; X } X } X X/* Restore the look ahead character */ XPutback: X if (ch != EOF) X (void) ungetc(ch, fp); X return items; X} END_OF_FILE if test 6291 -ne `wc -c <'vfscanf.c'`; then echo shar: \"'vfscanf.c'\" unpacked with wrong size! fi # end of 'vfscanf.c' fi echo shar: End of archive 6 \(of 7\). cp /dev/null ark6isdone MISSING="" for I in 1 2 3 4 5 6 7 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 7 archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0