Interdata_v6/usr/source/stdio/src/src.a
ecalloc.c p #include "stdio.h"
/* calloc - allocate and clear memory block
*/
#define BYTESPERWD (sizeof(int)/sizeof(char))
int *malloc();
int *calloc(num, size)
unsigned num;
{
register *p, *q;
register m;
num =* size;
if((p=malloc(num)) != NULL) {
q = p;
m = (num+BYTESPERWD-1)/BYTESPERWD;
while(--m>=0)
*q++ = 0;
}
return(p);
}
cfree(p)
int *p;
{
free(p);
}
clrerr.c d #include "stdio.h"
clearerr(iop)
register struct _iobuf *iop;
{
iop->_flag =& ~(_IOERR|_IOEOF);
}
ctype.c #include "ctype.h"
char _ctype[] {
0, 0, 0, 0, 0, 0, 0, 0,
0, _S, _S, _S, _S, _S, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
_S, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
_N, _N, _N, _N, _N, _N, _N, _N,
_N, _N, 0, 0, 0, 0, 0, 0,
0, _U, _U, _U, _U, _U, _U, _U,
_U, _U, _U, _U, _U, _U, _U, _U,
_U, _U, _U, _U, _U, _U, _U, _U,
_U, _U, _U, 0, 0, 0, 0, 0,
0, _L, _L, _L, _L, _L, _L, _L,
_L, _L, _L, _L, _L, _L, _L, _L,
_L, _L, _L, _L, _L, _L, _L, _L,
_L, _L, _L, 0, 0, 0, 0, 0
};
data.c #include "stdio.h"
char _sibuf[BUFSIZ];
char _sobuf[BUFSIZ];
struct _iobuf _iob[_NFILE] {
{ _sibuf, 0, _sibuf, _IOREAD, 0},
{ NULL, 0, NULL, _IOWRT, 1},
{NULL, 0, NULL, _IOWRT+_IONBF, 2},
};
/*
* Ptr to end of buffers
*/
struct _iobuf *_lastbuf { &_iob[_NFILE] };
doprnt.c H /***
*** Quick-and-dirty modification of printf to make a _doprnt
*** for the standard i/o library
***/
/*
* Printf:
* Print formatted data to standard output file.
* For external description, see man(iii).
*
*/
#include "stdio.h"
int _prfwidth, _prfprec; /* Width & precision */
_doprnt(afmt, aargs, file)
char *afmt;
int *aargs;
FILE *file;
{
register char *fmt, *p;
register int *argp, left, c, n;
static char buff[128];
/*
* argp is used to step along list of arguments, since
* the number of args is not known in advance.
*/
argp = aargs;
p = buff;
for (fmt = afmt; c = *fmt; fmt++) {
/*
* Copy format string to output string until
* escape character is encountered.
*/
if (c != '%') {
*p++ = c;
continue;
}
if (p > buff)
_strout(buff, p-buff, 0, file);
/* '-' means left-justification of field. */
left = 0;
if ((c = *++fmt) == '-') {
left++;
fmt++;
}
/* Convert width field if present. */
n = 0;
while ((c = *fmt) <= '9' && c >= '0') {
n =* 10;
n =+ c - '0';
fmt++;
}
_prfwidth = n;
/* Convert precision field if present. */
n = 0;
if (c == '.')
while ((c = *++fmt) <= '9' && c >= '0') {
n =* 10;
n =+ c - '0';
}
_prfprec = n;
/*
* Print the argument in the requested format.
* If _prf1() returns <0, an unknown character followed
* the '%', so the argument was not used. Otherwise,
* step to the next argument.
*/
if (_prf1(c, *argp, left, buff, file) >= 0)
argp++;
p = buff;
}
if (p > buff)
_strout(buff, p-buff, 0, file);
}
/*
* Print a single argument according to the given format character.
* Left-justify if left == 1.
*/
char prfhex[] { "0123456789ABCDEF" }; /* Hexadecimal digits */
_prf1(fmt, arg, left, buff, file)
char *buff;
FILE *file;
{
register int x, len, c;
register char *p, *lastc;
/* Initialize pointers to first & last+1 char in buffer. */
x = arg;
lastc = p = &buff[32];
switch (fmt) {
/* Unknown character: just print the format char. */
default:
*--p = fmt;
fmt = -1;
break;
/* Single character */
case 'c': case 'C':
if (x)
*--p = x;
break;
/* String: set pointers to first & last+1 char. */
case 's': case 'S':
p = lastc = x;
while (*lastc)
lastc++;
break;
/* Octal */
case 'o': case 'O':
do
*--p = (x & 07) + '0';
while (x =>> 3);
break;
/* Hexadecimal */
case 'x': case 'X':
do
*--p = prfhex[x & 017];
while (x =>> 4);
break;
/* Signed decimal */
case 'd': case 'D':
if (x < 0)
x = -arg;
/* Unsigned decimal */
case 'l': case 'L':
do
*--p = (x % 10) + '0';
while (x =/ 10);
if (arg < 0 && (fmt == 'd' || fmt == 'D'))
*--p = '-';
break;
/* Floating point */
case 'f': case 'F':
case 'e': case 'E':
p = lastc = buff;
ftoa(x, p, _prfprec, fmt);
while (*lastc)
lastc++;
_prfprec = 0;
break;
}
/* Compute len = -(no. of pad chars needed to fill width) */
len = lastc - p;
if (_prfprec && len > _prfprec) {
len = _prfprec;
lastc = p + len;
}
if ((len =- _prfwidth) > 0)
len = 0;
if (left)
len = -len;
_strout(p, lastc-p, len, file, ' ');
/* Returned value >=0 asks printf to step to next argument. */
return(fmt);
}
doscan.c # #include "stdio.h"
#define SPC 01
#define STP 02
char *_getccl();
char _sctab[128] {
0,0,0,0,0,0,0,0,
0,SPC,SPC,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
SPC,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
};
_doscan(iop, fmt, argp)
register char *fmt;
register int *argp;
{
register int ch;
int nmatch, len, ch1;
int *ptr, fileended;
nmatch = 0;
fileended = 0;
for (;;) switch (ch = *fmt++) {
case '\0':
return (nmatch);
case '%':
if ((ch = *fmt++) == '%')
goto def;
ptr = 0;
if (ch != '*')
ptr = *argp++;
else
ch = *fmt++;
len = 0;
while (ch>='0' && ch <='9') {
len = len*10 + ch - '0';
ch = *fmt++;
}
if (len == 0)
len = 30000;
if (ch=='l') {
ch = *fmt++;
if (ch>='a' && ch<='z')
ch =+ 'A'-'a';
} else if (ch=='[')
fmt = _getccl(fmt);
if (ch == '\0')
_error("scanf\n");
if (_innum(ptr, ch, len, iop, &fileended) && ptr)
nmatch++;
if (fileended)
return(nmatch? nmatch: -1);
break;
case ' ':
case '\n':
case '\t':
break;
default:
def:
if (ch != (ch1 = getc(iop)))
return(ch1==EOF? -1: nmatch);
}
}
_innum(ptr, type, len, iop, eofptr)
int *ptr, *eofptr;
struct _iobuf *iop;
{
extern double atof();
struct { double *dblptr;};
struct { long *longptr;};
struct { float *fltptr;};
register char *np;
char numbuf[64];
register c, base;
int expseen, scale, size, negflg, c1, ndigit;
long lcval;
if (type=='c' || type=='s' || type=='[')
return(_instr(ptr, type, len, iop, eofptr));
lcval = 0;
ndigit = 0;
size = 0;
if (type>='A' && type <='Z') {
size++;
type =+ 'a'-'A';
}
scale = 0;
if (type=='e'||type=='f')
scale++;
base = 10;
if (type=='o')
base = 8;
else if (type=='x')
base = 16;
np = numbuf;
expseen = 0;
negflg = 0;
while ((c = getc(iop))==' ' || c=='\t' || c=='\n');
if (c=='-') {
negflg++;
*np++ = c;
c = getc(iop);
len--;
} else if (c=='+') {
len--;
c = getc(iop);
}
for ( ; --len>=0; *np++ = c, c = getc(iop)) {
if ('0'<=c && c<='9'
|| base==16 && ('a'<=c && c<='f' || 'A'<=c && c<='F')) {
ndigit++;
if (base==8)
lcval =<<3;
else if (base==10)
lcval = ((lcval<<2) + lcval)<<1;
else
lcval =<< 4;
c1 = c;
if ('0'<=c && c<='9')
c =- '0';
else if ('a'<=c && c<='f')
c =- 'a'-10;
else
c =- 'A'-10;
lcval =+ c;
c = c1;
continue;
} else if (c=='.') {
if (base!=10 || scale==0)
break;
ndigit++;
continue;
} else if ((c=='e'||c=='E') && expseen==0) {
if (base!=10 || scale==0 || ndigit==0)
break;
expseen++;
*np++ = c;
c = getc(iop);
if (c!='+'&&c!='-'&&('0'>c||c>'9'))
break;
} else
break;
}
if (negflg)
lcval = -lcval;
if (c != EOF) {
ungetc(c, iop);
*eofptr = 0;
} else
*eofptr = 1;
if (ptr==NULL || np==numbuf)
return(0);
*np++ = 0;
if (scale==0)
if (size)
*ptr.longptr = lcval;
else
*ptr = lcval;
else
if (size)
*ptr.dblptr = atof(numbuf);
else
*ptr.fltptr = atof(numbuf);
return(1);
}
_instr(ptr, type, len, iop, eofptr)
register char *ptr;
register struct _iobuf *iop;
int *eofptr;
{
register ch;
register char *optr;
int ignstp;
*eofptr = 0;
optr = ptr;
if (type=='c' && len==30000)
len = 1;
ignstp = 0;
if (type=='s')
ignstp = SPC;
while (_sctab[ch = getc(iop)] & ignstp)
if (ch==EOF)
break;
ignstp = SPC;
if (type=='c')
ignstp = 0;
else if (type=='[')
ignstp = STP;
while (--len>=0 && ch>=0 && (_sctab[ch]&ignstp)==0) {
if (ptr)
*ptr++ = ch;
ch = getc(iop);
}
if (ch != EOF) {
ungetc(ch, iop);
*eofptr = 0;
} else
*eofptr = 1;
if (ptr && ptr!=optr) {
if (type!='c')
*ptr++ = '\0';
return(1);
}
return(0);
}
char *
_getccl(s)
register char *s;
{
register c, t;
t = 0;
if (*s == '^') {
t++;
s++;
}
for (c = 0; c < 128; c++)
if (t)
_sctab[c] =& ~STP;
else
_sctab[c] =| STP;
while (((c = *s++)&0177) != ']') {
if (t)
_sctab[c++] =| STP;
else
_sctab[c++] =& ~STP;
if (c==0)
return(--s);
}
return(s);
}
herror.c % #include "stdio.h"
_error(s)
register char *s;
{
static reentered;
if (reentered)
_exit(0177);
write(2, s, strlen(s));
exit(0176);
}
exit.c ' { /***
*** Special version of exit() to flush all output buffers
***/
exit(code)
int code;
{
_cleanup();
_exit(code);
}
)fftoa.c /*
* Fake version of ftoa for programs with no floating pt
*/
ftoa(x, str, prec, format)
float x;
char *str;
{
str[0] = '?';
str[1] = '\0';
}
fgetc.c ' ? #include "stdio.h"
fgetc(fp)
FILE *fp;
{
return(getc(fp));
}
fgets.c ( #include "stdio.h"
fgets(s, n, iop)
char *s;
register FILE *iop;
{
register c;
register char *cs;
cs = s;
while (--n>0 && (c = getc(iop))>=0) {
*cs++ = c;
if (c=='\n')
break;
}
if (c<0 && cs==s)
return(NULL);
*cs++ = '\0';
return(s);
}
tfilbuf.c ) #include "stdio.h"
_filbuf(iop)
register struct _iobuf *iop;
{
static char smallbuf[_NFILE];
if ((iop->_flag&_IOREAD) == 0)
_error("Reading bad file\n");
if (iop->_flag&_IOSTRG)
return(-1);
tryagain:
if (iop->_base==NULL) {
if (iop->_flag&_IONBF) {
iop->_base = &smallbuf[fileno(iop)];
goto tryagain;
}
if ((iop->_base = malloc(BUFSIZ)) == NULL) {
iop->_flag =| _IONBF;
goto tryagain;
}
iop->_flag =| _IOMYBUF;
}
iop->_ptr = iop->_base;
iop->_cnt = read(fileno(iop), iop->_ptr, iop->_flag&_IONBF?1:BUFSIZ);
if (--iop->_cnt < 0) {
if (iop->_cnt == -1)
iop->_flag =| _IOEOF;
else
iop->_flag =| _IOERR;
iop->_cnt = 0;
return(-1);
}
return(*iop->_ptr++&0377);
}
flsbuf.c + L #include "stdio.h"
_flsbuf(c, iop)
register struct _iobuf *iop;
{
register n;
register char *base;
char c1;
static gttybuf[4];
extern char _sobuf[];
if ((iop->_flag&_IOWRT)==0)
_error("writing\n");
tryagain:
if (iop->_flag&_IONBF) {
c1 = c;
n = write(fileno(iop), &c1, 1);
iop->_cnt = 0;
} else {
if ((base=iop->_base)==NULL) {
if (iop==stdout) {
if (gtty(1, gttybuf)>=0) {
iop->_flag =| _IONBF;
goto tryagain;
}
iop->_base = _sobuf;
iop->_ptr = _sobuf;
goto tryagain;
}
if ((iop->_base=base=malloc(BUFSIZ)) == NULL) {
iop->_flag =| _IONBF;
goto tryagain;
}
iop->_flag =| _IOMYBUF;
n = 1;
} else if ((n = iop->_ptr - base) > 0)
n = write(fileno(iop), base, n);
iop->_cnt = BUFSIZ-1;
*base++ = c;
iop->_ptr = base;
}
if (n < 0) {
iop->_flag =| _IOERR;
return(-1);
}
return(c);
}
fflush(iop)
register struct _iobuf *iop;
{
register char *base;
register n;
if ((iop->_flag&(_IONBF|_IOWRT))==_IOWRT
&& (base=iop->_base)!=NULL && (n=iop->_ptr-base)>0) {
iop->_ptr = base;
iop->_cnt = BUFSIZ;
if (write(fileno(iop), base, n)!=n)
iop->_flag =| _IOERR;
}
}
/*
* Flush buffers on exit
*/
_cleanup()
{
register struct _iobuf *iop;
extern struct _iobuf *_lastbuf;
for (iop = _iob; iop < _lastbuf; iop++)
fclose(iop);
}
fclose(iop)
register struct _iobuf *iop;
{
if (iop->_flag&(_IOREAD|_IOWRT)) {
fflush(iop);
close(fileno(iop));
if (iop->_flag&_IOMYBUF)
free(iop->_base);
}
iop->_base = NULL;
iop->_flag =& ~(_IOREAD|_IOWRT|_IONBF|_IOMYBUF|_IOERR|_IOEOF);
iop->_cnt = 0;
return(0);
}
fopen.c , I #include "stdio.h"
struct _iobuf *fopen(file, mode)
register char *mode;
{
register f;
register struct _iobuf *iop;
extern struct _iobuf *_lastbuf;
for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT); iop++)
if (iop >= _lastbuf)
return(NULL);
if (*mode=='w')
f = creat(file, 0666);
else if (*mode=='a') {
if ((f = open(file, 1)) < 0)
f = creat(file, 0666);
seek(f, 0, 2);
} else
f = open(file, 0);
if (f < 0)
return(NULL);
iop->_flag =& ~(_IOREAD|_IOWRT);
iop->_file = f;
if (*mode != 'r')
iop->_flag =| _IOWRT;
else
iop->_flag =| _IOREAD;
return(iop);
}
fprintf.c e j #include "stdio.h"
fprintf(iop, fmt, args)
struct _iobuf *iop;
char *fmt;
{
_doprnt(fmt, &args, iop);
}
fputc.c , E #include "stdio.h"
fputc(c, fp)
FILE *fp;
{
return(putc(c, fp));
}
*fputs.c , | #include "stdio.h"
fputs(s, iop)
register char *s;
register FILE *iop;
{
register c;
while (c = *s++)
putc(c, iop);
}
freopen.c i #include "stdio.h"
struct _iobuf *freopen(file, mode, iop)
char *file;
register char *mode;
register struct _iobuf *iop;
{
register f;
fclose(iop);
if (*mode=='w')
f = creat(file, 0666);
else if (*mode=='a') {
if ((f = open(file, 1)) < 0)
f = creat(file, 0666);
seek(f, 0, 2);
} else
f = open(file, 0);
if (f < 0)
return(NULL);
iop->_file = f;
if (*mode != 'r')
iop->_flag =| _IOWRT;
else
iop->_flag =| _IOREAD;
return(iop);
}
fseek.c - % #include "stdio.h"
/*
* Seek for standard library. Coordinates with buffering.
*/
fseek(iop, offset, ptrname)
FILE *iop;
long offset;
{
register n, resync;
if (iop->_flag&_IOREAD) {
resync = 0;
if (ptrname==1) { /* relative */
n = iop->_cnt;
if (n<0)
n = 0;
} else {
n = offset&01;
resync = n;
}
n = lseek(fileno(iop), offset - n, ptrname);
iop->_cnt = 0;
if (resync)
getc(iop);
return(n);
}
if (iop->_flag&_IOWRT) {
fflush(iop);
return(lseek(fileno(iop), offset, ptrname));
}
_error("fseek\n");
}
nftell.c . #include "stdio.h"
/*
* Return file offset.
* Coordinates with buffering.
*/
long tell();
long ftell(iop)
FILE *iop;
{
long tres;
register adjust;
if (iop->_cnt < 0)
iop->_cnt = 0;
if (iop->_flag&_IOREAD)
adjust = - iop->_cnt;
else if (iop->_flag&_IOWRT) {
adjust = 0;
if (iop->_base && (iop->_flag&_IONBF)==0)
adjust = iop->_ptr - iop->_base;
} else
_error("ftell\n");
tres = tell(fileno(iop));
if (tres<0)
return(tres);
tres =+ adjust;
return(tres);
}
ftoa.c ? /*
* Floating-point to ASCII conversion
*/
int fltused 0; /* forces loading if floating pt used in C program */
ftoa (x, str, prec, format)
float x;
char *str;
{
/* converts a floating point number to an ascii string */
/* x is stored into str, which should be at least 30 chars long */
int ie, i, k, ndig, fstyle;
double y;
ndig= ( prec<=0) ? 7 : (prec > 22 ? 23 : prec+1);
if (format == 'f' || format == 'F')
fstyle = 1;
else
fstyle = 0;
/* print in eformat unless last arg is 'f' */
ie = 0;
/* if x negative, write minus and reverse */
if ( x < 0)
{
*str++ = '-';
x = -x;
}
/* put x in range 1 <= x < 10 */
if (x > 0.0) while (x < 1.0)
{
x =* 10.0;
ie--;
}
while (x >= 10.0)
{
x = x/10.0;
ie++;
}
/* in f format, number of digits is related to size */
if (fstyle) ndig =+ ie;
/* round. x is between 1 and 10 and ndig will be printed to
right of decimal point so rounding is ... */
for (y = i = 1; i < ndig; i++)
y = y/10.;
x =+ y/2.;
if (x >= 10.0) {x = 1.0; ie++;} /* repair rounding disasters */
/* now loop. put out a digit (obtain by multiplying by
10, truncating, subtracting) until enough digits out */
/* if fstyle, and leading zeros, they go out special */
if (fstyle && ie<0)
{
*str++ = '0'; *str++ = '.';
if (ndig < 0) ie = ie-ndig; /* limit zeros if underflow */
for (i = -1; i > ie; i--)
*str++ = '0';
}
for (i=0; i < ndig; i++)
{
k = x;
*str++ = k + '0';
if (i == (fstyle ? ie : 0)) /* where is decimal point */
*str++ = '.';
x =- (y=k);
x =* 10.0;
}
/* now, in estyle, put out exponent if not zero */
if (!fstyle && ie!= 0)
{
*str++ = 'E';
if (ie < 0)
{
ie = -ie;
*str++ = '-';
}
for (k=100; k > ie; k =/10);
for (; k >0; k =/10)
{
*str++ = ie/k + '0';
ie = ie%k;
}
}
*str = '\0';
return;
}
egcvt.c . /*
* gcvt - Floating output conversion to
* minimal length string
*/
gcvt(number, ndigit, buf)
double number;
char *buf;
{
int sign, decpt;
register char *p1, *p2;
register i;
p1 = ecvt(number, ndigit, &decpt, &sign);
p2 = buf;
if (sign)
*p2++ = '-';
for (i=ndigit-1; i>0 && p1[i]=='0'; i--)
ndigit--;
if (decpt >= 0 && decpt-ndigit > 4
|| decpt < 0 && decpt < -3) { /* use E-style */
decpt--;
*p2++ = *p1++;
*p2++ = '.';
for (i=1; i<ndigit; i++)
*p2++ = *p1++;
*p2++ = 'e';
if (decpt<0) {
decpt = -decpt;
*p2++ = '-';
} else
*p2++ = '+';
*p2++ = decpt/10 + '0';
*p2++ = decpt%10 + '0';
} else {
if (decpt<=0) {
*p2++ = '.';
while (decpt<0) {
decpt++;
*p2++ = '0';
}
}
for (i=1; i<=ndigit; i++) {
*p2++ = *p1++;
if (i==decpt)
*p2++ = '.';
}
if (ndigit<decpt) {
while (ndigit++<decpt)
*p2++ = '0';
*p2++ = '.';
}
}
*p2++ = '\0';
return(buf);
}
getpw.c / <