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 4 (of 7)."
# Contents: fgets.c fopen.c fprintf.c fputc.c fputs.c fread.c
# freopen.c fscanf.c fseek.c ftell.c
# Wrapped by cechew@bruce on Mon Sep 4 12:50:16 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'fgets.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fgets.c'\"
else
echo shar: Extracting \"'fgets.c'\" \(1588 characters\)
sed "s/^X//" >'fgets.c' <<'END_OF_FILE'
X/* f g e t s
X *
X * Read a line from the specified stream. The function will read
X * characters until n-1 characters are read or a newline character
X * is read or an EOF is encountered. The string is then terminated
X * with a null character. The newline character is placed into the
X * string, unlike gets which strips the newline character. The
X * function returns the first argument, but will return the NULL
X * pointer if no character was read before EOF was read.
X *
X * Patchlevel 1.0
X *
X * Edit History:
X * 02-Sep-1989 Speed up by retrieving directly from buffer.
X */
X
X#include "stdiolib.h"
X
X/*LINTLIBRARY*/
X
Xchar *fgets(buf, n, fp)
X
Xchar *buf; /* buffer for input */
Xint n; /* size of buffer */
XFILE *fp; /* stream */
X
X{
X int ch; /* character read */
X unsigned char *q; /* input buffer pointer */
X unsigned char *s; /* output buffer */
X unsigned int bytesleft; /* bytes left in current load */
X
X if (n <= 1)
X return n > 0 ? (buf[0] = 0, buf) : NULL;
X
X if (fp == stdin && TESTFLAG(stdout, _IOLBF))
X (void) fflush(stdout);
X
X for (s = (unsigned char *) buf, --n; ; ) {
X if ((bytesleft = BYTESINREADBUFFER(fp)) != 0) {
X if (bytesleft > n)
X bytesleft = n;
X n -= bytesleft;
X q = GETREADPTR(fp);
X UNROLL_DO(fgetsbytes, bytesleft, if ((*s++ = *q++) == '\n') break);
X SETREADPTR(fp, q);
X }
X *s = 0;
X if (bytesleft != 0 || n == 0)
X return buf;
X if ((ch = getc(fp)) == EOF)
X return s == (unsigned char *) buf ? NULL : buf;
X if ((*s++ = ch) == '\n' || --n == 0) {
X *s = 0;
X return buf;
X }
X }
X}
END_OF_FILE
if test 1588 -ne `wc -c <'fgets.c'`; then
echo shar: \"'fgets.c'\" unpacked with wrong size!
fi
# end of 'fgets.c'
fi
if test -f 'fopen.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fopen.c'\"
else
echo shar: Extracting \"'fopen.c'\" \(814 characters\)
sed "s/^X//" >'fopen.c' <<'END_OF_FILE'
X/* f o p e n
X *
X * Open a stream and associate it with the named file. The name
X * of the file is passed as a character string. The type of
X * stream is passed as a string with the first character indicating
X * the mode with which the file is to be opened.
X *
X * The function returns a pointer to the stream if successful
X * otherwise it returns NULL.
X *
X * Patchlevel 1.0
X *
X * Edit History:
X */
X
X#include "stdiolib.h"
X
X/*LINTLIBRARY*/
X
XFILE *fopen(name, mode)
X
Xchar *name; /* name of file */
Xchar *mode; /* mode to open */
X
X{
X FILE **sp; /* slot in table */
X int fd; /* opened file descriptor */
X short flags; /* flag settings */
X
X return (sp = _slot((FILE *) NULL)) == NULL ||
X (fd = _fopen(name, mode, -1, &flags)) == -1
X ? NULL
X : (*sp = _file((FILE *) NULL, fd, flags));
X}
END_OF_FILE
if test 814 -ne `wc -c <'fopen.c'`; then
echo shar: \"'fopen.c'\" unpacked with wrong size!
fi
# end of 'fopen.c'
fi
if test -f 'fprintf.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fprintf.c'\"
else
echo shar: Extracting \"'fprintf.c'\" \(606 characters\)
sed "s/^X//" >'fprintf.c' <<'END_OF_FILE'
X/* f p r i n t f
X *
X * Formatted output to a named stream. A pointer to the required
X * stream is passed to the function and the output will be directed
X * to that stream.
X *
X * The function returns the number of bytes output on success, and
X * EOF on failure.
X *
X * Patchlevel 1.0
X *
X * Edit History:
X */
X
X#include "stdiolib.h"
X
X/*LINTLIBRARY*/
X/*VARARGS2*/
X
Xint fprintf(fp, fmt, va_alist)
X
XFILE *fp; /* stream */
Xchar *fmt; /* format */
Xva_dcl
X
X{
X va_list arg; /* argument vector */
X int v; /* return value */
X
X va_start(arg);
X v = vfprintf(fp, fmt, arg);
X va_end(arg);
X return v;
X}
END_OF_FILE
if test 606 -ne `wc -c <'fprintf.c'`; then
echo shar: \"'fprintf.c'\" unpacked with wrong size!
fi
# end of 'fprintf.c'
fi
if test -f 'fputc.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fputc.c'\"
else
echo shar: Extracting \"'fputc.c'\" \(441 characters\)
sed "s/^X//" >'fputc.c' <<'END_OF_FILE'
X/* f p u t c
X *
X * This is putc wrapped inside a function. This behaves like
X * putc but runs more slowly. It takes less space per invocation
X * and its name can be passed as an argument to a function.
X *
X * The function returns the character output on success and
X * EOF on failure.
X *
X * Patchlevel 1.0
X *
X * Edit History:
X */
X
X#include "stdiolib.h"
X
X/*LINTLIBRARY*/
X
Xint fputc(ch, iop)
X
Xint ch;
XFILE *iop;
X
X{
X return putc(ch, iop);
X}
X
END_OF_FILE
if test 441 -ne `wc -c <'fputc.c'`; then
echo shar: \"'fputc.c'\" unpacked with wrong size!
fi
# end of 'fputc.c'
fi
if test -f 'fputs.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fputs.c'\"
else
echo shar: Extracting \"'fputs.c'\" \(1745 characters\)
sed "s/^X//" >'fputs.c' <<'END_OF_FILE'
X/* f p u t s
X *
X * Write a string onto the specified stream. The terminating null
X * character in the string is not written.
X *
X * The function returns EOF on error, otherwise it will return the
X * last character written.
X *
X * Patchlevel 1.0
X *
X * Edit History:
X * 03-Sep-1989 Accommodate line buffered streams by flushing
X * afterwards. Don't even bother looking for '\n'.
X * Call NPUTC() for faster processing of unbuffered
X * streams.
X * 02-Sep-1989 Speed up by writing directly to buffer.
X */
X
X#include "stdiolib.h"
X
X/*LINTLIBRARY*/
X
Xint fputs(s, fp)
X
Xchar *s; /* string */
XFILE *fp; /* stream */
X
X{
X char flush; /* flush line buffered stream */
X int lastch; /* last character */
X unsigned int bytesleft; /* bytes left in output buffer */
X unsigned char *q; /* output buffer pointer */
X
X/* Check for output buffer */
X if (! HASBUFFER(fp)) {
X if (_allocbuf(fp) < 0)
X return EOF;
X SETCLEANUP();
X }
X
X if (TESTFLAG(fp, _IONBF)) {
X for (lastch = 0; *s; lastch = (unsigned char) *s++) {
X if (NPUTC(*s, fp) == EOF)
X return EOF;
X }
X return lastch;
X }
X
X/* Buffered mode --- write directly to buffer */
X for (lastch = s[0]; ; ) {
X if ((bytesleft = UNUSEDINWRITEBUFFER(fp)) != 0) {
X flush = 0;
X q = GETWRITEPTR(fp);
X if (TESTFLAG(fp, _IOLBF)) {
X UNROLL_DO(fputslb, bytesleft,
X if (*s == '\n') flush = 1;
X if ((*q++ = *((unsigned char *) s)++) == 0) break);
X }
X else {
X UNROLL_DO(fputsfb, bytesleft,
X if ((*q++ = *((unsigned char *) s)++) == 0) break);
X }
X if (bytesleft) {
X SETWRITEPTR(fp, q-1);
X if (flush)
X (void) fflush(fp);
X return lastch ? s[-2] : 0;
X }
X SETWRITEPTR(fp, q);
X }
X if (fflush(fp) == EOF)
X return EOF;
X }
X}
END_OF_FILE
if test 1745 -ne `wc -c <'fputs.c'`; then
echo shar: \"'fputs.c'\" unpacked with wrong size!
fi
# end of 'fputs.c'
fi
if test -f 'fread.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fread.c'\"
else
echo shar: Extracting \"'fread.c'\" \(4034 characters\)
sed "s/^X//" >'fread.c' <<'END_OF_FILE'
X/* f r e a d
X *
X * Read a series of records from an input stream. The function
X * returns the number of items (not bytes) read. The function
X * stops reading when the number of items is satisfied or when
X * EOF is encountered.
X *
X * Patchlevel 1.0
X *
X * Edit History:
X * 04-Sep-1989 Add code for reading very large objects.
X * 01-Sep-1989 Use Henry Spencer's ideas to speed up code by reading
X * directly into buffer.
X */
X
X#include "stdiolib.h"
X
X#if defined(BSD)
X# include <values.h>
X# define INT_MAX (MAXINT)
X#endif
X
X#if defined(MINIX) || defined(MSDOS) || defined(__MSDOS__)
X# include <limits.h>
X#endif
X
X/*LINTLIBRARY*/
X
Xint fread(p, size, nitems, fp)
X
Xvoid *p; /* buffer */
Xunsigned size; /* size of record */
Xunsigned nitems; /* number of items */
XFILE *fp; /* stream */
X
X{
X int red; /* bytes read in read call */
X int read(); /* read call */
X
X/* Phase 1 --- Amount to read overflows INT_MAX */
X unsigned int burstsize; /* size aligned chunk to read */
X unsigned int itemsperburst; /* items read per burst */
X unsigned int itemsleft; /* items left */
X unsigned int copyitems; /* items to copy */
X
X/* Phase 2 --- Write remainder */
X unsigned int bytestotal; /* total number of bytes */
X unsigned int bytesleft; /* total number of bytes left */
X unsigned int copybytes; /* bytes to copy directly to buffer */
X unsigned char *q; /* pointer into getc buffer */
X
X/* Items left to read */
X if ((itemsleft = nitems) == 0 || size == 0)
X return 0;
X
X/* Flush stdout */
X if (fp == stdin && TESTFLAG(stdout, _IOLBF))
X (void) fflush(stdout);
X
X/* Read very large objects */
X if ((itemsperburst = INT_MAX / size) == 0) {
X do {
X bytesleft = size;
X do {
X if ((burstsize = BYTESINREADBUFFER(fp)) != 0) {
X if (burstsize > bytesleft)
X burstsize = bytesleft;
X q = GETREADPTR(fp);
X UNROLL_DO(freadlarge, burstsize, (* ((unsigned char *) p)++ = *q++));
X SETREADPTR(fp, q);
X }
X else {
X if ((burstsize = INT_MAX) > bytesleft)
X burstsize = bytesleft;
X if ((red = read(fileno(fp), (char *) p, (int) burstsize)) !=
X burstsize)
X return (nitems-itemsleft);
X p = (void *) ((unsigned char *) p + burstsize);
X }
X } while ((bytesleft -= burstsize) != 0);
X } while (--itemsleft);
X return nitems;
X }
X
X/* Read large amounts of data first */
X for (burstsize = itemsperburst * size; itemsleft > itemsperburst; ) {
X if (itemsleft == nitems &&
X (copybytes = BYTESINREADBUFFER(fp)) != 0) {
X copyitems = copybytes/size;
X if (copyitems > itemsleft)
X copybytes = (copyitems = itemsleft) * size;
X itemsleft -= copyitems;
X if ((bytesleft = copybytes%size) != 0)
X bytesleft = size-bytesleft;
X q = GETREADPTR(fp);
X UNROLL_DO(freadburst, copybytes, (* ((unsigned char *) p)++ = *q++));
X SETREADPTR(fp, q);
X if (bytesleft != 0) {
X if ((red = read(fileno(fp), (char *) p, (int) bytesleft)) !=
X bytesleft) {
X if (red == -1)
X red = 0;
X return (nitems-itemsleft);
X }
X itemsleft--;
X }
X }
X else {
X if ((red = read(fileno(fp), (char *) p, (int) burstsize)) !=
X burstsize) {
X if (red == -1)
X red = 0;
X return (nitems-itemsleft) + (red/size);
X }
X p = (void *) ((unsigned char *) p + burstsize);
X itemsleft -= itemsperburst;
X }
X }
X
X/* At this point itemsleft contains the number of items left to
X * read. The read buffer may not be empty. itemsleft*size
X * will not overflow INT_MAX.
X */
X
X if ((bytesleft = bytestotal = size*itemsleft) != 0) {
X
X/* Partially filled read buffer */
X if ((copybytes = BYTESINREADBUFFER(fp)) != 0) {
X if (copybytes > bytesleft)
X copybytes = bytesleft;
X bytesleft -= copybytes;
X q = GETREADPTR(fp);
X UNROLL_DO(freadbytes, copybytes, (* ((unsigned char *) p)++ = *q++));
X SETREADPTR(fp, q);
X }
X
X/* Read rest of object directly to user buffer */
X if (bytesleft != 0 &&
X (red = read(fileno(fp), (char *) p, (int) bytesleft)) != -1)
X bytesleft -= red;
X }
X
X return (nitems-itemsleft) + (bytestotal-bytesleft)/size;
X}
END_OF_FILE
if test 4034 -ne `wc -c <'fread.c'`; then
echo shar: \"'fread.c'\" unpacked with wrong size!
fi
# end of 'fread.c'
fi
if test -f 'freopen.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'freopen.c'\"
else
echo shar: Extracting \"'freopen.c'\" \(1028 characters\)
sed "s/^X//" >'freopen.c' <<'END_OF_FILE'
X/* f r e o p e n
X *
X * Open the named file and associate it with the stream indicated.
X * The type of the stream is interpreted in the same manner as
X * for fopen(). The original stream is closed using fclose()
X * regardless of whether the open succeeds or not.
X *
X * The function returns a pointer to the stream on success, otherwise
X * it returns NULL.
X *
X * Patchlevel 1.0
X *
X * Edit History:
X */
X
X#include "stdiolib.h"
X
X/*LINTLIBRARY*/
X
XFILE *freopen(name, mode, fp)
X
Xchar *name; /* name to open */
Xchar *mode; /* mode to open with */
XFILE *fp; /* stream */
X
X{
X int fd; /* opened file descriptor */
X short flags; /* flag settings */
X int close(); /* close a channel */
X void free(); /* free memory */
X
X/* Close this stream */
X (void) fflush(fp);
X (void) close(fp->_file);
X
X/* Free any buffers */
X if (TESTFLAG(fp, _IOMYBUF))
X free((void *) fp->_base);
X
X/* Open according to the specified mode */
X return (fd = _fopen(name, mode, -1, &flags)) == -1
X ? NULL
X : _file(fp, fd, flags);
X}
END_OF_FILE
if test 1028 -ne `wc -c <'freopen.c'`; then
echo shar: \"'freopen.c'\" unpacked with wrong size!
fi
# end of 'freopen.c'
fi
if test -f 'fscanf.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fscanf.c'\"
else
echo shar: Extracting \"'fscanf.c'\" \(597 characters\)
sed "s/^X//" >'fscanf.c' <<'END_OF_FILE'
X/* f s c a n f
X *
X * Formatted input from a named stream. A pointer to the required
X * stream is passed to the function and items will be scanned from
X * that stream.
X *
X * The function returns the number items scanned on success, and
X * EOF on failure.
X *
X * Patchlevel 1.0
X *
X * Edit History:
X */
X
X#include "stdiolib.h"
X
X/*LINTLIBRARY*/
X/*VARARGS2*/
X
Xint fscanf(fp, fmt, va_alist)
X
XFILE *fp; /* stream */
Xchar *fmt; /* format */
Xva_dcl
X
X{
X va_list arg; /* argument vector */
X int v; /* return value */
X
X va_start(arg);
X v = vfscanf(fp, fmt, arg);
X va_end(arg);
X return v;
X}
END_OF_FILE
if test 597 -ne `wc -c <'fscanf.c'`; then
echo shar: \"'fscanf.c'\" unpacked with wrong size!
fi
# end of 'fscanf.c'
fi
if test -f 'fseek.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fseek.c'\"
else
echo shar: Extracting \"'fseek.c'\" \(735 characters\)
sed "s/^X//" >'fseek.c' <<'END_OF_FILE'
X/* f s e e k
X *
X * Set the position of a stream. The new position is at the signed
X * distance offset bytes from either the beginning, current position
X * of end of the file. Any effects of ungetc() are undone.
X *
X * The function returns EOF for improper seeks, otherwise zero.
X *
X * Patchlevel 1.0
X *
X * Edit History:
X */
X
X#include "stdiolib.h"
X
X/*LINTLIBRARY*/
X
Xint fseek(fp, offset, ptr)
X
XFILE *fp; /* stream */
Xlong offset; /* offset */
Xint ptr; /* reference */
X
X{
X long lseek(); /* seek on file */
X
X if (fflush(fp) || lseek(fp->_file, offset, ptr) == EOF)
X return EOF;
X
X CLEARFLAG(fp, _IOEOF);
X
X if (TESTFLAG(fp, _IORW)) {
X CLEARFLAG(fp, (_IOREAD | _IOWRITE));
X FLUSHNEXTACCESS(fp);
X }
X
X return 0;
X}
END_OF_FILE
if test 735 -ne `wc -c <'fseek.c'`; then
echo shar: \"'fseek.c'\" unpacked with wrong size!
fi
# end of 'fseek.c'
fi
if test -f 'ftell.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'ftell.c'\"
else
echo shar: Extracting \"'ftell.c'\" \(603 characters\)
sed "s/^X//" >'ftell.c' <<'END_OF_FILE'
X/* f t e l l
X *
X * Report the position within a stream. The function returns
X * the offset of the current byte relative to the beginning
X * of the file associated with the named stream.
X *
X * Patchlevel 1.0
X *
X * Edit History:
X */
X
X#include "stdiolib.h"
X
X/*LINTLIBRARY*/
X
Xlong ftell(fp)
X
XFILE *fp; /* stream */
X
X{
X long pos; /* current location */
X long tell(); /* location within file */
X
X if ((pos = tell(fp->_file)) == -1L || TESTFLAG(fp, _IONBF))
X return pos;
X
X if (TESTFLAG(fp, _IOWRITE))
X return pos + (fp->_ptr - fp->_base);
X else
X return pos - (fp->_end - fp->_ptr);
X}
END_OF_FILE
if test 603 -ne `wc -c <'ftell.c'`; then
echo shar: \"'ftell.c'\" unpacked with wrong size!
fi
# end of 'ftell.c'
fi
echo shar: End of archive 4 \(of 7\).
cp /dev/null ark4isdone
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