Initial revision
This commit is contained in:
7
lang/cem/libcc/stdio/clearerr.c
Normal file
7
lang/cem/libcc/stdio/clearerr.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
clearerr(iop)
|
||||
FILE *iop;
|
||||
{
|
||||
iop->_flags &= ~(IO_ERR|IO_EOF);
|
||||
}
|
||||
23
lang/cem/libcc/stdio/data.c
Normal file
23
lang/cem/libcc/stdio/data.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned char __stdin[BUFSIZ];
|
||||
unsigned char __stdout[BUFSIZ];
|
||||
|
||||
struct _io_buf _stdin = {
|
||||
0, 0, IO_READMODE , __stdin, __stdin
|
||||
};
|
||||
|
||||
struct _io_buf _stdout = {
|
||||
1, 0, IO_WRITEMODE, 0, 0
|
||||
};
|
||||
|
||||
struct _io_buf _stderr = {
|
||||
2, 0, IO_WRITEMODE + IO_UNBUFF, NULL, NULL
|
||||
};
|
||||
|
||||
struct _io_buf *_io_table[_NFILES] = {
|
||||
&_stdin,
|
||||
&_stdout,
|
||||
&_stderr,
|
||||
0
|
||||
};
|
||||
242
lang/cem/libcc/stdio/doprnt.c
Normal file
242
lang/cem/libcc/stdio/doprnt.c
Normal file
@@ -0,0 +1,242 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef NOFLOAT
|
||||
extern char *_pfloat();
|
||||
extern char *_pscien();
|
||||
#endif
|
||||
|
||||
static int *nextarg ;
|
||||
|
||||
static geta(p,size) int *p; int size; {
|
||||
/* get 'size' words from arglist */
|
||||
|
||||
if ( (int *)&p - &size >0 ) {
|
||||
p += size;
|
||||
while ( size-- ) {
|
||||
*--p = *nextarg--;
|
||||
}
|
||||
} else {
|
||||
while ( size-- ) {
|
||||
*p++ = *nextarg++ ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# define wsize(par) ( (sizeof par) / sizeof (int) )
|
||||
|
||||
|
||||
static char *gnum(f,ip) register char *f; int *ip; {
|
||||
register int i,c;
|
||||
|
||||
if (*f == '*') {
|
||||
geta(ip,wsize(i)) ;
|
||||
f++;
|
||||
} else {
|
||||
i = 0;
|
||||
while ((c = *f - '0') >= 0 && c <= 9) {
|
||||
i = i*10 + c;
|
||||
f++;
|
||||
}
|
||||
*ip = i;
|
||||
}
|
||||
return(f);
|
||||
}
|
||||
|
||||
#define signbit(par) (1L<<(sizeof par*8 -1))
|
||||
|
||||
static char *i_compute(val,base,s) unsigned val; char *s; {
|
||||
int c;
|
||||
|
||||
c= val % base ;
|
||||
val/= base ;
|
||||
if (val)
|
||||
s = i_compute(val,base,s);
|
||||
*s++ = (c>9 ? c-10+'a' : c+'0');
|
||||
return(s);
|
||||
}
|
||||
|
||||
#ifndef NOLONG
|
||||
static char *l_compute(l1,d,s) long l1; char *s; {
|
||||
int c;
|
||||
long l2;
|
||||
|
||||
if ( l1<0 ) {
|
||||
/* assumption: d is a multiple of 2 */
|
||||
c= l1&1 ;
|
||||
l2= ( (l1>>1) & ~signbit(l1) );
|
||||
l1= l2/(d>>1) ;
|
||||
c += (l2%(d>>1))<<1 ;
|
||||
} else {
|
||||
c= l1 % d ;
|
||||
l1= l1 / d ;
|
||||
}
|
||||
if (l1)
|
||||
s = l_compute(l1,d,s);
|
||||
*s++ = (c>9 ? c-10+'a' : c+'0');
|
||||
return(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
_doprnt(fmt,args,stream)
|
||||
register char *fmt; int *args ; FILE *stream;
|
||||
{
|
||||
register char *s;
|
||||
#ifndef NOLONG
|
||||
long l;
|
||||
int lflag ;
|
||||
#else
|
||||
#define lflag 0
|
||||
#endif
|
||||
#ifndef NOFLOAT
|
||||
double dbl ;
|
||||
#endif
|
||||
int inte ;
|
||||
unsigned int uint ;
|
||||
register int j ;
|
||||
int i,c,rjust,width,ndigit,ndfnd,zfill;
|
||||
char *oldfmt,*s1,buf[40];
|
||||
|
||||
nextarg = args;
|
||||
while (c = *fmt++) {
|
||||
if (c != '%') {
|
||||
#ifdef CPM
|
||||
if (c == '\n') putc('\r',stream);
|
||||
#endif
|
||||
putc(c,stream);
|
||||
continue;
|
||||
}
|
||||
#ifndef NOLONG
|
||||
lflag = 0 ;
|
||||
#endif
|
||||
j = 10 ;
|
||||
rjust = 0;
|
||||
if (*fmt == '-') {
|
||||
fmt++;
|
||||
rjust++;
|
||||
}
|
||||
zfill = ' ';
|
||||
if (*fmt == '0') {
|
||||
fmt++;
|
||||
zfill = '0';
|
||||
}
|
||||
fmt = gnum(fmt,&width);
|
||||
ndigit = 0; ndfnd = 0;
|
||||
if (*fmt == '.') {
|
||||
fmt++; oldfmt = fmt;
|
||||
fmt = gnum(fmt,&ndigit);
|
||||
ndfnd = (fmt != oldfmt);
|
||||
}
|
||||
s = s1 = buf;
|
||||
#ifndef NOLONG
|
||||
if ( *fmt == 'l' || *fmt == 'L' ) {
|
||||
fmt++ ; lflag++ ;
|
||||
}
|
||||
#endif
|
||||
switch (c = *fmt++) {
|
||||
default:
|
||||
#ifdef CPM
|
||||
if (c == '\n') putc('r',stream);
|
||||
#endif
|
||||
putc(c,stream);
|
||||
continue;
|
||||
case 's':
|
||||
geta(&s1,wsize(s1)) ;
|
||||
s = s1;
|
||||
do {
|
||||
if (*s == 0)
|
||||
break;
|
||||
s++;
|
||||
} while (--ndigit);
|
||||
break;
|
||||
case 'b':
|
||||
j = 2;
|
||||
case 'u':
|
||||
getu:
|
||||
if ( !lflag ) {
|
||||
geta(&inte,wsize(inte)) ;
|
||||
goto i_unsignd ;
|
||||
}
|
||||
#ifndef NOLONG
|
||||
case 'U':
|
||||
getlu:
|
||||
geta( &l,wsize(l)) ;
|
||||
goto l_unsignd ;
|
||||
case 'B':
|
||||
j = 2 ;
|
||||
goto getlu ;
|
||||
case 'X':
|
||||
j = 16;
|
||||
goto getlu ;
|
||||
case 'O':
|
||||
j = 8;
|
||||
goto getlu ;
|
||||
case 'D':
|
||||
l_signed:
|
||||
geta(&l,wsize(l)) ;
|
||||
if (l < 0) {
|
||||
*s++ = '-';
|
||||
l = -l;
|
||||
}
|
||||
goto do_l;
|
||||
l_unsignd:
|
||||
if (l && ndigit)
|
||||
*s++ = '0';
|
||||
do_l:
|
||||
s = l_compute(l,j,s);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case 'x':
|
||||
j = 16;
|
||||
goto getu ;
|
||||
case 'o':
|
||||
j = 8;
|
||||
goto getu ;
|
||||
case 'd':
|
||||
if ( lflag ) goto l_signed; ;
|
||||
geta(&inte,wsize(inte)) ;
|
||||
if ( inte<0 ) {
|
||||
*s++ = '-';
|
||||
inte= -inte ;
|
||||
}
|
||||
goto do_i ;
|
||||
i_unsignd:
|
||||
if (inte && ndigit)
|
||||
*s++ = '0';
|
||||
do_i:
|
||||
s = i_compute(inte,j,s);
|
||||
break;
|
||||
case 'c':
|
||||
geta ( &uint, wsize(uint)) ;
|
||||
for ( i= sizeof uint -1 ; i>=0 ; i-- ) {
|
||||
if ( *s = uint%256 ) s++;
|
||||
uint/= 256 ;
|
||||
}
|
||||
break;
|
||||
#ifndef NOFLOAT
|
||||
case 'e':
|
||||
geta(&dbl,wsize(dbl)) ;
|
||||
s = _pscien(dbl,s,ndigit,ndfnd);
|
||||
break;
|
||||
case 'f':
|
||||
geta(&dbl,wsize(dbl)) ;
|
||||
s = _pfloat(dbl,s,ndigit,ndfnd);
|
||||
break;
|
||||
#endif
|
||||
case 'r':
|
||||
geta(&nextarg,wsize(nextarg)) ;
|
||||
geta(&oldfmt,wsize(fmt)) ;
|
||||
fmt=oldfmt;
|
||||
continue;
|
||||
}
|
||||
j = s - s1;
|
||||
if ((c = width - j) > 0)
|
||||
if (rjust == 0)
|
||||
do putc(zfill,stream);
|
||||
while (--c);
|
||||
while (--j >= 0)
|
||||
putc(*s1++,stream);
|
||||
while (--c >= 0)
|
||||
putc(zfill,stream);
|
||||
}
|
||||
}
|
||||
278
lang/cem/libcc/stdio/doscan.c
Normal file
278
lang/cem/libcc/stdio/doscan.c
Normal file
@@ -0,0 +1,278 @@
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
union ptr_union {
|
||||
char *chr_p;
|
||||
unsigned short *ushort_p;
|
||||
unsigned int *uint_p;
|
||||
unsigned long *ulong_p;
|
||||
#ifndef NOFLOAT
|
||||
float *float_p;
|
||||
double *double_p;
|
||||
#endif
|
||||
};
|
||||
|
||||
static char Xtable[128];
|
||||
|
||||
/*
|
||||
* the routine that does the job
|
||||
*/
|
||||
|
||||
_doscanf (iop, format, argp)
|
||||
register FILE *iop;
|
||||
char *format; /* the format control string */
|
||||
union ptr_union *argp; /* our argument list */
|
||||
{
|
||||
int done = 0; /* number of items done */
|
||||
int base; /* conversion base */
|
||||
long val; /* an integer value */
|
||||
int sign; /* sign flag */
|
||||
int do_assign; /* assignment suppression flag */
|
||||
unsigned width; /* width of field */
|
||||
int widflag; /* width was specified */
|
||||
int longflag; /* true if long */
|
||||
int shortflag; /* true if short */
|
||||
int done_some; /* true if we have seen some data */
|
||||
int reverse; /* reverse the checking in [...] */
|
||||
int kind;
|
||||
register int ic;
|
||||
#ifndef NOFLOAT
|
||||
extern double atof();
|
||||
int dotseen;
|
||||
int expseen;
|
||||
char buffer[128];
|
||||
#endif
|
||||
|
||||
ic = getc(iop);
|
||||
if (ic == EOF) {
|
||||
done = EOF;
|
||||
goto quit;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
if (isspace(*format)) {
|
||||
while (isspace (*format))
|
||||
++format; /* skip whitespace */
|
||||
while (isspace (ic)) ic = getc(iop);
|
||||
}
|
||||
if (!*format)
|
||||
goto all_done; /* end of format */
|
||||
if (ic < 0)
|
||||
goto quit; /* seen an error */
|
||||
if (*format != '%') {
|
||||
if (ic != *format)
|
||||
goto all_done;
|
||||
++format;
|
||||
ic = getc(iop);
|
||||
++done;
|
||||
continue;
|
||||
}
|
||||
++format;
|
||||
do_assign = 1;
|
||||
if (*format == '*') {
|
||||
++format;
|
||||
do_assign = 0;
|
||||
}
|
||||
if (isdigit (*format)) {
|
||||
widflag = 1;
|
||||
for (width = 0; isdigit (*format);)
|
||||
width = width * 10 + *format++ - '0';
|
||||
} else
|
||||
widflag = 0; /* no width spec */
|
||||
if (longflag = (tolower (*format) == 'l'))
|
||||
++format;
|
||||
else if (shortflag = (tolower(*format) == 'h'))
|
||||
++format;
|
||||
if (isupper(*format)) {
|
||||
kind = tolower(*format);
|
||||
longflag = 1;
|
||||
}
|
||||
else kind = *format;
|
||||
if (kind != 'c')
|
||||
while (isspace (ic))
|
||||
ic = getc(iop);
|
||||
done_some = 0; /* nothing yet */
|
||||
switch (kind) {
|
||||
case 'o':
|
||||
base = 8;
|
||||
goto decimal;
|
||||
case 'u':
|
||||
case 'd':
|
||||
base = 10;
|
||||
goto decimal;
|
||||
case 'x':
|
||||
base = 16;
|
||||
if (((!widflag) || width >= 2) && ic == '0') {
|
||||
ic = getc(iop);
|
||||
if (tolower (ic) == 'x') {
|
||||
width -= 2;
|
||||
done_some = 1;
|
||||
ic = getc(iop);
|
||||
} else {
|
||||
ungetc(ic, iop);
|
||||
ic = '0';
|
||||
}
|
||||
}
|
||||
decimal:
|
||||
val = 0L; /* our result value */
|
||||
sign = 0; /* assume positive */
|
||||
if (!widflag)
|
||||
width = 0xffff; /* very wide */
|
||||
if (width && ic == '+')
|
||||
ic = getc(iop);
|
||||
else if (width && ic == '-') {
|
||||
sign = 1;
|
||||
ic = getc(iop);
|
||||
}
|
||||
while (width--) {
|
||||
if (isdigit (ic) && ic - '0' < base)
|
||||
ic -= '0';
|
||||
else if (base == 16 && tolower (ic) >= 'a' && tolower (ic) <= 'f')
|
||||
ic = 10 + tolower (ic) - 'a';
|
||||
else
|
||||
break;
|
||||
val = val * base + ic;
|
||||
ic = getc(iop);
|
||||
done_some = 1;
|
||||
}
|
||||
if (do_assign) {
|
||||
if (sign)
|
||||
val = -val;
|
||||
if (longflag)
|
||||
*(argp++)->ulong_p = (unsigned long) val;
|
||||
else if (shortflag)
|
||||
*(argp++)->ushort_p = (unsigned short) val;
|
||||
else
|
||||
*(argp++)->uint_p = (unsigned) val;
|
||||
}
|
||||
if (done_some)
|
||||
++done;
|
||||
else
|
||||
goto all_done;
|
||||
break;
|
||||
case 'c':
|
||||
if (!widflag)
|
||||
width = 1;
|
||||
while (width-- && ic >= 0) {
|
||||
if (do_assign)
|
||||
*(argp)->chr_p++ = (char) ic;
|
||||
ic = getc(iop);
|
||||
done_some = 1;
|
||||
}
|
||||
if (do_assign)
|
||||
argp++; /* done with this one */
|
||||
if (done_some)
|
||||
++done;
|
||||
break;
|
||||
case 's':
|
||||
if (!widflag)
|
||||
width = 0xffff;
|
||||
while (width-- && !isspace (ic) && ic > 0) {
|
||||
if (do_assign)
|
||||
*(argp)->chr_p++ = (char) ic;
|
||||
ic = getc(iop);
|
||||
done_some = 1;
|
||||
}
|
||||
if (do_assign) /* terminate the string */
|
||||
*(argp++)->chr_p = '\0';
|
||||
if (done_some)
|
||||
++done;
|
||||
else
|
||||
goto all_done;
|
||||
break;
|
||||
case '[':
|
||||
if (!widflag)
|
||||
width = 0xffff;
|
||||
|
||||
if ( *(++format) == '^' ) {
|
||||
reverse = 1;
|
||||
format++;
|
||||
} else
|
||||
reverse = 0;
|
||||
|
||||
{ register char *c;
|
||||
for (c = Xtable; c < &Xtable[128]; c++) *c = 0;
|
||||
}
|
||||
while (*format && *format != ']') {
|
||||
Xtable[*format] = 1;
|
||||
}
|
||||
if (!*format)
|
||||
goto quit;
|
||||
|
||||
while (width-- && !isspace (ic) && ic > 0 &&
|
||||
(Xtable[ic] ^ reverse)) {
|
||||
if (do_assign)
|
||||
*(argp)->chr_p++ = (char) ic;
|
||||
ic = getc(iop);
|
||||
done_some = 1;
|
||||
}
|
||||
if (do_assign) /* terminate the string */
|
||||
*(argp++)->chr_p = '\0';
|
||||
if (done_some)
|
||||
++done;
|
||||
else
|
||||
goto all_done;
|
||||
break;
|
||||
#ifndef NOFLOAT:
|
||||
case 'e':
|
||||
case 'f': {
|
||||
register char *c = buffer;
|
||||
|
||||
if (width >= 128) width = 127;
|
||||
if (width && (ic == '+' || ic == '-')) {
|
||||
*c++ = ic;
|
||||
width--;
|
||||
ic = getc(iop);
|
||||
}
|
||||
while (isdigit(ic) && width) {
|
||||
width--;
|
||||
*c++ = ic;
|
||||
ic = getc(iop);
|
||||
}
|
||||
if (ic == '.' && width) {
|
||||
width--;
|
||||
*c++ = ic;
|
||||
ic = getc(iop);
|
||||
}
|
||||
while (isdigit(ic) && width) {
|
||||
width--;
|
||||
*c++ = ic;
|
||||
ic = getc(iop);
|
||||
}
|
||||
if (width && (ic == 'e' || ic == 'E')) {
|
||||
width--;
|
||||
*c++ = ic;
|
||||
ic = getc(iop);
|
||||
if (width && (ic == '+' || ic == '-')) {
|
||||
width--;
|
||||
*c++ = ic;
|
||||
ic = getc(iop);
|
||||
}
|
||||
}
|
||||
while (isdigit(ic) && width) {
|
||||
width--;
|
||||
*c++ = ic;
|
||||
ic = getc(iop);
|
||||
}
|
||||
if (c == buffer) goto all_done;
|
||||
*c = 0;
|
||||
done++;
|
||||
|
||||
if (do_assign) {
|
||||
if (longflag)
|
||||
*(argp++)->double_p = atof(buffer);
|
||||
else
|
||||
*(argp++)->float_p = atof(buffer);
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
} /* end switch */
|
||||
++format;
|
||||
}
|
||||
all_done:
|
||||
if (ic >= 0)
|
||||
ungetc(ic, iop);
|
||||
quit:
|
||||
return done;
|
||||
}
|
||||
22
lang/cem/libcc/stdio/fclose.c
Normal file
22
lang/cem/libcc/stdio/fclose.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
fclose(fp)
|
||||
FILE *fp;
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i=0; i<_NFILES; i++)
|
||||
if (fp == _io_table[i]) {
|
||||
_io_table[i] = 0;
|
||||
break;
|
||||
}
|
||||
if (i >= _NFILES)
|
||||
return(EOF);
|
||||
fflush(fp);
|
||||
close(fileno(fp));
|
||||
if ( io_testflag(fp,IO_MYBUF) && fp->_buf )
|
||||
free( fp->_buf );
|
||||
free(fp);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
38
lang/cem/libcc/stdio/fdopen.c
Normal file
38
lang/cem/libcc/stdio/fdopen.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <stdio.h>
|
||||
|
||||
FILE *fdopen(fd,mode)
|
||||
char *mode;
|
||||
{
|
||||
register int i;
|
||||
FILE *fp;
|
||||
char *malloc();
|
||||
int flags = 0;
|
||||
|
||||
if (fd < 0) return NULL;
|
||||
for (i = 0; _io_table[i] != 0 ; i++)
|
||||
if ( i >= _NFILES )
|
||||
return(NULL);
|
||||
|
||||
switch(*mode) {
|
||||
case 'r':
|
||||
flags |= IO_READMODE;
|
||||
break;
|
||||
case 'a':
|
||||
lseek(fd, 0L, 2);
|
||||
case 'w':
|
||||
flags |= IO_WRITEMODE;
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (( fp = (FILE *) malloc (sizeof( FILE))) == NULL ) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
fp->_count = 0;
|
||||
fp->_fd = fd;
|
||||
fp->_flags = flags;
|
||||
_io_table[i] = fp;
|
||||
return(fp);
|
||||
}
|
||||
26
lang/cem/libcc/stdio/fflush.c
Normal file
26
lang/cem/libcc/stdio/fflush.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
fflush(iop)
|
||||
FILE *iop;
|
||||
{
|
||||
int count, c1;
|
||||
|
||||
if ( io_testflag(iop,IO_UNBUFF) || !io_testflag(iop,IO_WRITEMODE) )
|
||||
return(0);
|
||||
|
||||
count = BUFSIZ - iop->_count;
|
||||
if ( count <= 0 )
|
||||
return(0);
|
||||
|
||||
c1 = write(iop->_fd,iop->_buf,count);
|
||||
|
||||
if ( count == c1 ) {
|
||||
iop->_count = BUFSIZ;
|
||||
iop->_ptr = iop->_buf;
|
||||
return(count);
|
||||
}
|
||||
|
||||
iop->_flags |= IO_ERR;
|
||||
return(EOF);
|
||||
}
|
||||
7
lang/cem/libcc/stdio/fgetc.c
Normal file
7
lang/cem/libcc/stdio/fgetc.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
fgetc(f)
|
||||
register FILE *f;
|
||||
{
|
||||
return getc(f);
|
||||
}
|
||||
21
lang/cem/libcc/stdio/fgets.c
Normal file
21
lang/cem/libcc/stdio/fgets.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
char *fgets(str, n, file)
|
||||
char *str;
|
||||
unsigned n;
|
||||
FILE *file;
|
||||
{
|
||||
register int ch;
|
||||
register char *ptr;
|
||||
|
||||
ptr = str;
|
||||
while ( --n > 0 && (ch = getc(file)) != EOF){
|
||||
*ptr++ = ch;
|
||||
if ( ch == '\n')
|
||||
break;
|
||||
}
|
||||
if (ch == EOF && ptr==str)
|
||||
return(NULL);
|
||||
*ptr = '\0';
|
||||
return(str);
|
||||
}
|
||||
37
lang/cem/libcc/stdio/fillbuf.c
Normal file
37
lang/cem/libcc/stdio/fillbuf.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
|
||||
_fillbuf(iop)
|
||||
register FILE *iop;
|
||||
{
|
||||
unsigned char ch[_NFILES];
|
||||
|
||||
iop->_count = 0;
|
||||
if (fileno(iop) < 0) return EOF;
|
||||
if ( io_testflag(iop, (IO_EOF | IO_ERR )))
|
||||
return (EOF);
|
||||
|
||||
if ( !io_testflag(iop, IO_READMODE) )
|
||||
return (EOF);
|
||||
|
||||
if (! io_testflag(iop, IO_UNBUFF) && ! iop->_buf) {
|
||||
iop->_buf = (unsigned char *) malloc(BUFSIZ);
|
||||
if (! iop->_buf) iop->_flags |= IO_UNBUFF;
|
||||
else iop->_flags |= IO_MYBUF;
|
||||
}
|
||||
if (! iop->_buf) iop->_buf = &ch[fileno(iop)];
|
||||
iop->_ptr = iop->_buf;
|
||||
iop->_count = read(iop->_fd, iop->_buf, io_testflag(iop, IO_UNBUFF)? 1 : BUFSIZ);
|
||||
|
||||
if (iop->_count <= 0){
|
||||
if (iop->_count == 0) {
|
||||
iop->_flags |= IO_EOF;
|
||||
}
|
||||
else
|
||||
iop->_flags |= IO_ERR;
|
||||
|
||||
return (EOF);
|
||||
}
|
||||
iop->_count--;
|
||||
|
||||
return *iop->_ptr++;
|
||||
}
|
||||
57
lang/cem/libcc/stdio/fltpr.c
Normal file
57
lang/cem/libcc/stdio/fltpr.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef NOFLOAT
|
||||
extern char *fcvt();
|
||||
extern char *ecvt();
|
||||
|
||||
char *
|
||||
_pfloat(r,s,n,b)
|
||||
double r;
|
||||
register char *s;
|
||||
{
|
||||
int sign,dp,i; char *s1;
|
||||
|
||||
if (b == 0)
|
||||
n = 6;
|
||||
s1 = fcvt(r,n,&dp,&sign);
|
||||
if (sign)
|
||||
*s++ = '-';
|
||||
if (dp<=0)
|
||||
*s++ = '0';
|
||||
for (i=dp; i>0; i--)
|
||||
*s++ = *s1++;
|
||||
if ((i=n) > 0)
|
||||
*s++ = '.';
|
||||
while (++dp <= 0) {
|
||||
if (--i<0)
|
||||
break;
|
||||
*s++ = '0';
|
||||
}
|
||||
while (--i >= 0)
|
||||
*s++ = *s1++;
|
||||
return(s);
|
||||
}
|
||||
|
||||
char *_pscien(r,s,n,b) float r; char *s; {
|
||||
int sign,dp; char *s1;
|
||||
|
||||
if (b == 0)
|
||||
n = 7;
|
||||
else n += 1;
|
||||
s1 = ecvt(r,n,&dp,&sign);
|
||||
if (sign)
|
||||
*s++ = '-';
|
||||
*s++ = *s1++;
|
||||
*s++ = '.';
|
||||
while (--n>0)
|
||||
*s++ = *s1++;
|
||||
*s++ = 'e';
|
||||
if ( r ) --dp ;
|
||||
if ( dp<0 ) {
|
||||
*s++ = '-' ; dp= -dp ;
|
||||
} else {
|
||||
*s++ = '+' ;
|
||||
}
|
||||
*s++ = '0' + (dp/10);
|
||||
*s++ = '0' + (dp%10);
|
||||
return(s);
|
||||
}
|
||||
#endif
|
||||
71
lang/cem/libcc/stdio/flushbuf.c
Normal file
71
lang/cem/libcc/stdio/flushbuf.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
_flushbuf(c, iop)
|
||||
register FILE *iop;
|
||||
{
|
||||
if (fileno(iop) < 0) return EOF;
|
||||
if (! io_testflag(iop, IO_UNBUFF)) {
|
||||
if (iop->_buf == 0) {
|
||||
if (iop == stdout) {
|
||||
if (isatty(fileno(stdout))) {
|
||||
iop->_flags |= IO_UNBUFF;
|
||||
}
|
||||
else {
|
||||
extern unsigned char __stdout[];
|
||||
|
||||
iop->_buf = iop->_ptr = __stdout;
|
||||
iop->_count = BUFSIZ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
extern char *malloc();
|
||||
|
||||
if (!(iop->_buf = (unsigned char *) malloc(BUFSIZ))) {
|
||||
iop->_flags |= IO_UNBUFF;
|
||||
}
|
||||
else {
|
||||
iop->_ptr = iop->_buf;
|
||||
iop->_flags |= IO_MYBUF;
|
||||
iop->_count = BUFSIZ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (io_testflag(iop, IO_UNBUFF)) {
|
||||
char c1 = c;
|
||||
|
||||
iop->_count = 0;
|
||||
if (write(fileno(iop), &c1, 1) != 1) {
|
||||
iop->_flags |= IO_ERR;
|
||||
return EOF;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
else {
|
||||
int count = BUFSIZ - iop->_count;
|
||||
|
||||
iop->_count = BUFSIZ - 1;
|
||||
iop->_ptr = iop->_buf + 1;
|
||||
|
||||
if (count > 0) {
|
||||
if (write(fileno(iop), iop->_buf, count) != count) {
|
||||
*(iop->_buf) = c;
|
||||
iop->_flags |= IO_ERR;
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
*(iop->_buf) = c;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
_cleanup()
|
||||
{
|
||||
register int i;
|
||||
|
||||
for ( i = 0 ; i < _NFILES ; i++ )
|
||||
if ( _io_table[i] != NULL )
|
||||
fclose(_io_table[i]);
|
||||
}
|
||||
56
lang/cem/libcc/stdio/fopen.c
Normal file
56
lang/cem/libcc/stdio/fopen.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define PMODE 0666
|
||||
|
||||
|
||||
FILE *fopen(name,mode)
|
||||
char *name , *mode;
|
||||
{
|
||||
register int i;
|
||||
FILE *fp;
|
||||
char *malloc();
|
||||
int fd,
|
||||
flags = 0;
|
||||
|
||||
for (i = 0; _io_table[i] != 0 ; i++)
|
||||
if ( i >= _NFILES )
|
||||
return(NULL);
|
||||
|
||||
switch(*mode){
|
||||
|
||||
case 'w':
|
||||
flags |= IO_WRITEMODE;
|
||||
fd = creat (name,PMODE);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
flags |= IO_WRITEMODE;
|
||||
if (( fd = open(name, 1)) < 0 )
|
||||
fd = creat(name, PMODE);
|
||||
if (fd >= 0) lseek(fd,0L,2);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
flags |= IO_READMODE;
|
||||
if (( fd = open (name, 0)) < 0 )
|
||||
return(NULL);
|
||||
break;
|
||||
|
||||
default:
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
||||
if (fd < 0) return NULL;
|
||||
|
||||
if (( fp = (FILE *) malloc (sizeof( FILE))) == NULL ) {
|
||||
close(fd);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
fp->_count = 0;
|
||||
fp->_fd = fd;
|
||||
fp->_flags = flags;
|
||||
_io_table[i] = fp;
|
||||
return(fp);
|
||||
}
|
||||
11
lang/cem/libcc/stdio/fprintf.c
Normal file
11
lang/cem/libcc/stdio/fprintf.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
fprintf (file, fmt, args)
|
||||
FILE *file;
|
||||
char *fmt;
|
||||
int args;
|
||||
{
|
||||
_doprnt (fmt, &args, file);
|
||||
if ( io_testflag(file,IO_PERPRINTF) )
|
||||
fflush(file);
|
||||
}
|
||||
7
lang/cem/libcc/stdio/fputc.c
Normal file
7
lang/cem/libcc/stdio/fputc.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
fputc(c, iop)
|
||||
register FILE *iop;
|
||||
{
|
||||
return putc(c, iop);
|
||||
}
|
||||
9
lang/cem/libcc/stdio/fputs.c
Normal file
9
lang/cem/libcc/stdio/fputs.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
fputs(s,file)
|
||||
register char *s;
|
||||
register FILE *file;
|
||||
{
|
||||
while ( *s )
|
||||
putc(*s++,file);
|
||||
}
|
||||
25
lang/cem/libcc/stdio/fread.c
Normal file
25
lang/cem/libcc/stdio/fread.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
|
||||
fread(ptr, size, count, file)
|
||||
register char *ptr;
|
||||
unsigned size, count;
|
||||
register FILE *file;
|
||||
{
|
||||
int c;
|
||||
unsigned ndone = 0, s;
|
||||
|
||||
ndone = 0;
|
||||
if (size)
|
||||
while ( ndone < count ) {
|
||||
s = size;
|
||||
do {
|
||||
if ((c = getc(file)) != EOF)
|
||||
*ptr++ = c;
|
||||
else
|
||||
return(ndone);
|
||||
} while (--s);
|
||||
ndone++;
|
||||
}
|
||||
return(ndone);
|
||||
}
|
||||
|
||||
59
lang/cem/libcc/stdio/freopen.c
Normal file
59
lang/cem/libcc/stdio/freopen.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define PMODE 0666
|
||||
|
||||
|
||||
FILE *freopen(name,mode,fp)
|
||||
char *name , *mode;
|
||||
FILE *fp;
|
||||
{
|
||||
FILE *fp;
|
||||
char *malloc();
|
||||
int fd,
|
||||
flags = 0;
|
||||
|
||||
close(fileno(fp));
|
||||
if (io_testflag(fp, IO_MYBUF) && fp->_buf) free(fp->_buf);
|
||||
|
||||
switch(*mode){
|
||||
|
||||
case 'w':
|
||||
flags |= IO_WRITEMODE;
|
||||
fd = creat (name,PMODE);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
flags |= IO_WRITEMODE;
|
||||
if (( fd = open(name, 1)) < 0 )
|
||||
fd = creat(name, PMODE);
|
||||
if (fd >= 0) lseek(fd,0L,2);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
flags |= IO_READMODE;
|
||||
fd = open(name, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
fd = -1;
|
||||
}
|
||||
|
||||
if (fd < 0) {
|
||||
register int i;
|
||||
|
||||
for (i = 0; i < _NFILES; i++) {
|
||||
if (fp == _io_table[i]) {
|
||||
_io_table[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fp->_count = 0;
|
||||
fp->_fd = fd;
|
||||
fp->_flags = flags;
|
||||
fp->_buf = 0;
|
||||
return(fp);
|
||||
}
|
||||
10
lang/cem/libcc/stdio/fscanf.c
Normal file
10
lang/cem/libcc/stdio/fscanf.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int fscanf (fp, format, args)
|
||||
FILE *fp;
|
||||
char *format;
|
||||
unsigned args;
|
||||
{
|
||||
return _doscanf (fp, format, &args);
|
||||
}
|
||||
|
||||
39
lang/cem/libcc/stdio/fseek.c
Normal file
39
lang/cem/libcc/stdio/fseek.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
fseek(iop, offset, where)
|
||||
FILE *iop;
|
||||
long offset;
|
||||
{
|
||||
int count;
|
||||
long lseek();
|
||||
long pos;
|
||||
|
||||
iop->_flags &= ~(IO_EOF | IO_ERR);
|
||||
/* Clear both the end of file and error flags */
|
||||
|
||||
if ( io_testflag(iop,IO_READMODE) ) {
|
||||
if ( where < 2 && iop->_buf && !io_testflag(iop,IO_UNBUFF) ) {
|
||||
count = iop->_count;
|
||||
pos = offset;
|
||||
|
||||
if ( where == 0 )
|
||||
pos += count - lseek(fileno(iop), 0L,1);
|
||||
else
|
||||
offset -= count;
|
||||
|
||||
if ( count > 0 && pos <= count
|
||||
&& pos >= iop->_buf - iop->_ptr ) {
|
||||
iop->_ptr += (int) pos;
|
||||
iop->_count -= (int) pos;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
pos = lseek(fileno(iop), offset, where);
|
||||
iop->_count = 0;
|
||||
} else if ( io_testflag(iop,IO_WRITEMODE) ) {
|
||||
fflush(iop);
|
||||
pos = lseek(fileno(iop), offset, where);
|
||||
}
|
||||
return((pos == -1) ? -1 : 0 );
|
||||
}
|
||||
25
lang/cem/libcc/stdio/ftell.c
Normal file
25
lang/cem/libcc/stdio/ftell.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
long ftell(iop)
|
||||
FILE *iop;
|
||||
{
|
||||
long result;
|
||||
long lseek();
|
||||
int adjust = 0;
|
||||
|
||||
if ( io_testflag(iop,IO_READMODE) )
|
||||
adjust -= iop->_count;
|
||||
else if ( io_testflag(iop,IO_WRITEMODE) && iop->_buf && !io_testflag(iop,IO_UNBUFF))
|
||||
adjust = iop->_ptr - iop->_buf;
|
||||
else
|
||||
return(-1);
|
||||
|
||||
result = lseek(fileno(iop), 0L, 1);
|
||||
|
||||
if ( result < 0 )
|
||||
return ( result );
|
||||
|
||||
result += (long) adjust;
|
||||
return(result);
|
||||
}
|
||||
23
lang/cem/libcc/stdio/fwrite.c
Normal file
23
lang/cem/libcc/stdio/fwrite.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
|
||||
fwrite(ptr, size, count, file)
|
||||
unsigned size, count;
|
||||
register char *ptr;
|
||||
register FILE *file;
|
||||
{
|
||||
unsigned s;
|
||||
unsigned ndone = 0;
|
||||
|
||||
if (size)
|
||||
while ( ndone < count ) {
|
||||
s = size;
|
||||
do {
|
||||
putc(*ptr++, file);
|
||||
if (ferror(file))
|
||||
return(ndone);
|
||||
}
|
||||
while (--s);
|
||||
ndone++;
|
||||
}
|
||||
return(ndone);
|
||||
}
|
||||
8
lang/cem/libcc/stdio/getchar.c
Normal file
8
lang/cem/libcc/stdio/getchar.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#undef getchar
|
||||
|
||||
getchar()
|
||||
{
|
||||
return getc(stdin);
|
||||
}
|
||||
115
lang/cem/libcc/stdio/getgrent.c
Normal file
115
lang/cem/libcc/stdio/getgrent.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* get entry from group file
|
||||
*
|
||||
* By: Patrick van Kleef
|
||||
*/
|
||||
|
||||
#include <grp.h>
|
||||
|
||||
#define PRIVATE static
|
||||
|
||||
PRIVATE char _gr_file[] = "/etc/group";
|
||||
PRIVATE char _grbuf[256];
|
||||
PRIVATE char _buffer[1024];
|
||||
PRIVATE char *_pnt;
|
||||
PRIVATE char *_buf;
|
||||
PRIVATE int _gfd = -1;
|
||||
PRIVATE int _bufcnt;
|
||||
PRIVATE struct group grp;
|
||||
|
||||
setgrent ()
|
||||
{
|
||||
if (_gfd >= 0)
|
||||
lseek (_gfd, 0L, 0);
|
||||
else
|
||||
_gfd = open (_gr_file, 0);
|
||||
|
||||
_bufcnt = 0;
|
||||
return (_gfd);
|
||||
}
|
||||
|
||||
|
||||
endgrent ()
|
||||
{
|
||||
if (_gfd >= 0)
|
||||
close (_gfd);
|
||||
|
||||
_gfd = -1;
|
||||
_bufcnt = 0;
|
||||
}
|
||||
|
||||
|
||||
static getline ()
|
||||
{
|
||||
if (_gfd < 0 && setgrent () < 0)
|
||||
return (0);
|
||||
|
||||
_buf = _grbuf;
|
||||
do {
|
||||
if (--_bufcnt <= 0){
|
||||
if ((_bufcnt = read (_gfd, _buffer, 1024)) <= 0)
|
||||
return (0);
|
||||
else
|
||||
_pnt = _buffer;
|
||||
}
|
||||
*_buf++ = *_pnt++;
|
||||
} while (*_pnt != '\n');
|
||||
_pnt++;
|
||||
_bufcnt--;
|
||||
*_buf = 0;
|
||||
_buf = _grbuf;
|
||||
return (1);
|
||||
}
|
||||
|
||||
static skip_period ()
|
||||
{
|
||||
while (*_buf != ':')
|
||||
_buf++;
|
||||
*_buf++ = '\0';
|
||||
}
|
||||
|
||||
struct group *getgrent ()
|
||||
{
|
||||
if (getline () == 0)
|
||||
return (0);
|
||||
|
||||
grp.gr_name = _buf;
|
||||
skip_period ();
|
||||
grp.gr_passwd = _buf;
|
||||
skip_period ();
|
||||
grp.gr_gid = atoi (_buf);
|
||||
skip_period ();
|
||||
return (&grp);
|
||||
}
|
||||
|
||||
struct group *getgrnam (name)
|
||||
char *name;
|
||||
{
|
||||
struct group *grp;
|
||||
|
||||
setgrent ();
|
||||
while ((grp = getgrent ()) != 0)
|
||||
if (!strcmp (grp -> gr_name, name))
|
||||
break;
|
||||
endgrent ();
|
||||
if (grp != 0)
|
||||
return (grp);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
struct group *getgrgid (gid)
|
||||
int gid;
|
||||
{
|
||||
struct group *grp;
|
||||
|
||||
setgrent ();
|
||||
while ((grp = getgrent ()) != 0)
|
||||
if (grp -> gr_gid == gid)
|
||||
break;
|
||||
endgrent ();
|
||||
if (grp != 0)
|
||||
return (grp);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
29
lang/cem/libcc/stdio/getpass.c
Normal file
29
lang/cem/libcc/stdio/getpass.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <signal.h>
|
||||
#include <sgtty.h>
|
||||
|
||||
char * getpass(prompt)
|
||||
char *prompt;
|
||||
{
|
||||
int i = 0;
|
||||
struct sgttyb tty, ttysave;
|
||||
static char pwdbuf[9];
|
||||
int fd;
|
||||
int (*savesig)();
|
||||
|
||||
if ((fd = open("/dev/tty", 0)) < 0) fd = 0;
|
||||
savesig = signal(SIGINT, SIG_IGN);
|
||||
write(2, prompt, strlen(prompt));
|
||||
gtty(fd, &tty);
|
||||
ttysave = tty;
|
||||
tty.sg_flags &= ~ECHO;
|
||||
stty(fd, &tty);
|
||||
i = read(fd, pwdbuf, 9);
|
||||
while (pwdbuf[i - 1] != '\n')
|
||||
read(fd, &pwdbuf[i - 1], 1);
|
||||
pwdbuf[i - 1] = '\0';
|
||||
stty(fd, &ttysave);
|
||||
write(2, "\n", 1);
|
||||
if (fd != 0) close(fd);
|
||||
signal(SIGINT, savesig);
|
||||
return(pwdbuf);
|
||||
}
|
||||
35
lang/cem/libcc/stdio/getpw.c
Normal file
35
lang/cem/libcc/stdio/getpw.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <stdio.h>
|
||||
|
||||
getpw(uid, buf)
|
||||
int uid;
|
||||
char buf[];
|
||||
{
|
||||
register FILE *pwf;
|
||||
register int ch, i;
|
||||
register char *bp;
|
||||
|
||||
pwf = fopen("/etc/passwd", "r");
|
||||
if (pwf == NULL) return(1);
|
||||
|
||||
for (;;) {
|
||||
bp = buf;
|
||||
while ((ch = getc(pwf)) != '\n') {
|
||||
if (ch == EOF) return 1;
|
||||
*bp++ = ch;
|
||||
}
|
||||
*bp++ = '\0';
|
||||
bp = buf;
|
||||
for (i = 2; i; i--) {
|
||||
while ((ch = *bp++) != ':') {
|
||||
if(ch = '\0') return 1;
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
while ((ch = *bp++) != ':') {
|
||||
if (ch < '0' || ch > '9') return 1;
|
||||
i = i * 10 + (ch - '0');
|
||||
}
|
||||
if (i == uid) return(0);
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
125
lang/cem/libcc/stdio/getpwent.c
Normal file
125
lang/cem/libcc/stdio/getpwent.c
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* get entry from password file
|
||||
*
|
||||
* By Patrick van Kleef
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <pwd.h>
|
||||
|
||||
#define PRIVATE static
|
||||
|
||||
|
||||
PRIVATE char _pw_file[] = "/etc/passwd";
|
||||
PRIVATE char _pwbuf[256];
|
||||
PRIVATE char _buffer[1024];
|
||||
PRIVATE char *_pnt;
|
||||
PRIVATE char *_buf;
|
||||
PRIVATE int _pw = -1;
|
||||
PRIVATE int _bufcnt;
|
||||
PRIVATE struct passwd pwd;
|
||||
|
||||
setpwent()
|
||||
{
|
||||
if (_pw >= 0)
|
||||
lseek (_pw, 0L, 0);
|
||||
else
|
||||
_pw = open (_pw_file, 0);
|
||||
|
||||
_bufcnt = 0;
|
||||
return (_pw);
|
||||
}
|
||||
|
||||
|
||||
endpwent ()
|
||||
{
|
||||
if (_pw >= 0)
|
||||
close (_pw);
|
||||
|
||||
_pw = -1;
|
||||
_bufcnt = 0;
|
||||
}
|
||||
|
||||
static getline ()
|
||||
{
|
||||
if (_pw < 0 && setpwent () < 0)
|
||||
return (0);
|
||||
_buf = _pwbuf;
|
||||
do {
|
||||
if (--_bufcnt <= 0){
|
||||
if ((_bufcnt = read (_pw, _buffer, 1024)) <= 0)
|
||||
return (0);
|
||||
else
|
||||
_pnt = _buffer;
|
||||
}
|
||||
*_buf++ = *_pnt++;
|
||||
} while (*_pnt != '\n');
|
||||
_pnt++;
|
||||
_bufcnt--;
|
||||
*_buf = 0;
|
||||
_buf = _pwbuf;
|
||||
return (1);
|
||||
}
|
||||
|
||||
static skip_period ()
|
||||
{
|
||||
while (*_buf != ':')
|
||||
_buf++;
|
||||
|
||||
*_buf++ = '\0';
|
||||
}
|
||||
|
||||
struct passwd *getpwent ()
|
||||
{
|
||||
if (getline () == 0)
|
||||
return (0);
|
||||
|
||||
pwd.pw_name = _buf;
|
||||
skip_period ();
|
||||
pwd.pw_passwd = _buf;
|
||||
skip_period ();
|
||||
pwd.pw_uid = atoi (_buf);
|
||||
skip_period ();
|
||||
pwd.pw_gid = atoi (_buf);
|
||||
skip_period ();
|
||||
pwd.pw_gecos = _buf;
|
||||
skip_period ();
|
||||
pwd.pw_dir = _buf;
|
||||
skip_period ();
|
||||
pwd.pw_shell = _buf;
|
||||
|
||||
return (&pwd);
|
||||
}
|
||||
|
||||
struct passwd *getpwnam (name)
|
||||
char *name;
|
||||
{
|
||||
struct passwd *pwd;
|
||||
|
||||
setpwent ();
|
||||
while ((pwd = getpwent ()) != 0)
|
||||
if (!strcmp (pwd -> pw_name, name))
|
||||
break;
|
||||
endpwent ();
|
||||
if (pwd != 0)
|
||||
return (pwd);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
struct passwd *getpwuid (uid)
|
||||
int uid;
|
||||
{
|
||||
struct passwd *pwd;
|
||||
|
||||
setpwent ();
|
||||
while ((pwd = getpwent ()) != 0)
|
||||
if (pwd -> pw_uid == uid)
|
||||
break;
|
||||
endpwent ();
|
||||
if (pwd != 0)
|
||||
return (pwd);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
17
lang/cem/libcc/stdio/gets.c
Normal file
17
lang/cem/libcc/stdio/gets.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
char *gets(str)
|
||||
char *str;
|
||||
{
|
||||
register int ch;
|
||||
register char *ptr;
|
||||
|
||||
ptr = str;
|
||||
while ((ch = getc(stdin)) != EOF && ch != '\n')
|
||||
*ptr++ = ch;
|
||||
|
||||
if (ch == EOF && ptr==str)
|
||||
return(NULL);
|
||||
*ptr = '\0';
|
||||
return(str);
|
||||
}
|
||||
15
lang/cem/libcc/stdio/getw.c
Normal file
15
lang/cem/libcc/stdio/getw.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int getw(iop)
|
||||
register FILE *iop;
|
||||
{
|
||||
register int cnt = sizeof(int);
|
||||
int w;
|
||||
register char *p = (char *) &w;
|
||||
|
||||
while (cnt--) {
|
||||
*p++ = getc(iop);
|
||||
}
|
||||
if (foef(iop) || ferror(iop)) return EOF;
|
||||
return w;
|
||||
}
|
||||
54
lang/cem/libcc/stdio/popen.c
Normal file
54
lang/cem/libcc/stdio/popen.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
static int pids[20];
|
||||
|
||||
FILE *
|
||||
popen(command, type)
|
||||
char *command, *type;
|
||||
{
|
||||
int piped[2];
|
||||
int Xtype = *type == 'r' ? 0 : *type == 'w' ? 1 : 2;
|
||||
int pid;
|
||||
|
||||
if (Xtype == 2 ||
|
||||
pipe(piped) < 0 ||
|
||||
(pid = fork()) < 0) return 0;
|
||||
|
||||
if (pid == 0) {
|
||||
/* child */
|
||||
register int *p;
|
||||
|
||||
for (p = pids; p < &pids[20]; p++) {
|
||||
if (*p) close(p - pids);
|
||||
}
|
||||
close(piped[Xtype]);
|
||||
dup2(piped[!Xtype], !Xtype);
|
||||
close(piped[!Xtype]);
|
||||
execl("/bin/sh", "sh", "-c", command, (char *) 0);
|
||||
_exit(127); /* like system() ??? */
|
||||
}
|
||||
|
||||
pids[piped[Xtype]] = pid;
|
||||
close(piped[!Xtype]);
|
||||
return fdopen(piped[Xtype], type);
|
||||
}
|
||||
|
||||
pclose(iop)
|
||||
FILE *iop;
|
||||
{
|
||||
int fd = fileno(iop);
|
||||
int status, wret;
|
||||
int (*intsave)() = signal(SIGINT, SIG_IGN);
|
||||
int (*quitsave)() = signal(SIGQUIT, SIG_IGN);
|
||||
|
||||
fclose(iop);
|
||||
while ((wret = wait(&status)) != -1) {
|
||||
if (wret == pids[fd]) break;
|
||||
}
|
||||
if (wret == -1) status = -1;
|
||||
signal(SIGINT, intsave);
|
||||
signal(SIGQUIT, quitsave);
|
||||
pids[fd] = 0;
|
||||
return status;
|
||||
}
|
||||
10
lang/cem/libcc/stdio/printf.c
Normal file
10
lang/cem/libcc/stdio/printf.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
printf (fmt, args)
|
||||
char *fmt;
|
||||
int args;
|
||||
{
|
||||
_doprnt (fmt, &args, stdout);
|
||||
if ( io_testflag(stdout,IO_PERPRINTF) )
|
||||
fflush(stdout);
|
||||
}
|
||||
8
lang/cem/libcc/stdio/putchar.c
Normal file
8
lang/cem/libcc/stdio/putchar.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#undef putchar
|
||||
|
||||
putchar(c)
|
||||
{
|
||||
return putc(c, stdout);
|
||||
}
|
||||
10
lang/cem/libcc/stdio/puts.c
Normal file
10
lang/cem/libcc/stdio/puts.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
puts(s)
|
||||
register char *s;
|
||||
{
|
||||
register FILE *file = stdout;
|
||||
while ( *s )
|
||||
putc(*s++,file);
|
||||
putc('\n', file);
|
||||
}
|
||||
15
lang/cem/libcc/stdio/putw.c
Normal file
15
lang/cem/libcc/stdio/putw.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
putw(w, iop)
|
||||
register FILE *iop;
|
||||
{
|
||||
register int cnt = sizeof(int);
|
||||
register char *p = (char *) &w;
|
||||
|
||||
while (cnt--) {
|
||||
putc(*p++, iop);
|
||||
}
|
||||
if (ferror(iop)) return EOF;
|
||||
return w;
|
||||
}
|
||||
7
lang/cem/libcc/stdio/rewind.c
Normal file
7
lang/cem/libcc/stdio/rewind.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
rewind(iop)
|
||||
FILE *iop;
|
||||
{
|
||||
return fseek(iop, 0L, 0);
|
||||
}
|
||||
10
lang/cem/libcc/stdio/scanf.c
Normal file
10
lang/cem/libcc/stdio/scanf.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int scanf (format, args)
|
||||
char *format;
|
||||
unsigned args;
|
||||
{
|
||||
return _doscanf (stdin, format, &args);
|
||||
}
|
||||
|
||||
|
||||
20
lang/cem/libcc/stdio/setbuf.c
Normal file
20
lang/cem/libcc/stdio/setbuf.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
setbuf(iop, buffer)
|
||||
register FILE *iop;
|
||||
char *buffer;
|
||||
{
|
||||
if ( iop->_buf && io_testflag(iop,IO_MYBUF) )
|
||||
free(iop->_buf);
|
||||
|
||||
iop->_flags &= ~(IO_MYBUF | IO_UNBUFF | IO_PERPRINTF);
|
||||
|
||||
iop->_buf = (unsigned char *) buffer;
|
||||
|
||||
if ( iop->_buf == NULL )
|
||||
iop->_flags |= IO_UNBUFF;
|
||||
|
||||
iop->_ptr = iop->_buf;
|
||||
iop->_count = 0;
|
||||
}
|
||||
19
lang/cem/libcc/stdio/sprintf.c
Normal file
19
lang/cem/libcc/stdio/sprintf.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
|
||||
char *sprintf(buf,format,args)
|
||||
char *buf, *format;
|
||||
int args;
|
||||
{
|
||||
FILE _tempfile;
|
||||
|
||||
_tempfile._fd = -1;
|
||||
_tempfile._flags = IO_WRITEMODE + IO_UNBUFF;
|
||||
_tempfile._buf = (unsigned char *) buf;
|
||||
_tempfile._ptr = (unsigned char *) buf;
|
||||
_tempfile._count = 32767;
|
||||
|
||||
_doprintf(format, &args, &_tempfile);
|
||||
putc('\0',&_tempfile);
|
||||
|
||||
return buf;
|
||||
}
|
||||
17
lang/cem/libcc/stdio/sscanf.c
Normal file
17
lang/cem/libcc/stdio/sscanf.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int sscanf (string, format, args)
|
||||
char *string; /* source of data */
|
||||
char *format; /* control string */
|
||||
unsigned args; /* our args */
|
||||
{
|
||||
FILE _tempfile;
|
||||
|
||||
_tempfile._fd = -1;
|
||||
_tempfile._flags = IO_READMODE + IO_UNBUFF;
|
||||
_tempfile._buf = (unsigned char *) string;
|
||||
_tempfile._ptr = (unsigned char *) string;
|
||||
_tempfile._count = 32767;
|
||||
|
||||
return _doscanf (&_tempfile, format, &args);
|
||||
}
|
||||
24
lang/cem/libcc/stdio/system.c
Normal file
24
lang/cem/libcc/stdio/system.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <signal.h>
|
||||
|
||||
system(str)
|
||||
char *str;
|
||||
{
|
||||
int pid, exitstatus, waitval;
|
||||
int i;
|
||||
|
||||
if ((pid = fork()) < 0) return -1;
|
||||
if (pid == 0) {
|
||||
for (i = 3; i <= 20; i++) close(i);
|
||||
execl("/bin/sh", "sh", "-c", str, (char *) 0);
|
||||
/* get here if execl fails ... */
|
||||
_exit(127); /* see manual page */
|
||||
}
|
||||
while ((waitval = wait(&exitstatus)) != pid) {
|
||||
if (waitval == -1) break;
|
||||
}
|
||||
if (waitval == -1) {
|
||||
/* no child ??? or maybe interrupted ??? */
|
||||
exitstatus = -1;
|
||||
}
|
||||
return exitstatus;
|
||||
}
|
||||
59
lang/cem/libcc/stdio/timezone.c
Normal file
59
lang/cem/libcc/stdio/timezone.c
Normal file
@@ -0,0 +1,59 @@
|
||||
static struct zonetable {
|
||||
int offset;
|
||||
char *stdzone;
|
||||
char *dstzone;
|
||||
} zonetable[] = {
|
||||
-3*60-30, "NST", 0, /* new foundland ??? */
|
||||
-4*60, "AST", "ADT", /* atlanic */
|
||||
-5*60, "EST", "EDT", /* eastern */
|
||||
-6*60, "CST", "CDT", /* central */
|
||||
-7*60, "MST", "MDT", /* mountain */
|
||||
-8*60, "PST", "PDT", /* pacific */
|
||||
-9*60, "YST", "YDT", /* yukon */
|
||||
-10*60, "AST", "ADT", /* aleutian */
|
||||
-10*60, "HST", "HDT", /* hawai, never found */
|
||||
0, "GMT", 0, /* Greenwich */
|
||||
0, "WET", "WDT", /* west european, never found */
|
||||
1*60,"MET", "MDT", /* middle european */
|
||||
2*60, "EET", "EDT", /* east european */
|
||||
8*60, "WST", 0, /* west australia */
|
||||
9*60, "JST", 0, /* japan */
|
||||
9*60+30, "CST", 0, /* also australia ??? */
|
||||
10*60, "EST", 0, /* also australia ??? */
|
||||
-1
|
||||
};
|
||||
|
||||
char *
|
||||
timezone(zone, dst)
|
||||
{
|
||||
register struct zonetable *p = zonetable;
|
||||
static char buf[16];
|
||||
register char *c;
|
||||
int i;
|
||||
|
||||
while (p->offset != -1) {
|
||||
if (zone == -p->offset) {
|
||||
if (dst && p->dstzone) return p->dstzone;
|
||||
if (!dst && p->stdzone) return p->stdzone;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
*c++ = 'G';
|
||||
*c++ = 'M';
|
||||
*c++ = 'T';
|
||||
if (zone < 0) {
|
||||
zone = - zone;
|
||||
*c++ = '+';
|
||||
}
|
||||
else *c++ = '-';
|
||||
i = (zone / 60) % 24;
|
||||
if (i >= 10) {
|
||||
*c++ = i / 10 + '0';
|
||||
}
|
||||
*c++ = i % 10 + '0';
|
||||
i = zone % 60;
|
||||
*c++ = i / 10 + '0';
|
||||
*c++ = i % 10 + '0';
|
||||
*c = '\0';
|
||||
return buf;
|
||||
}
|
||||
16
lang/cem/libcc/stdio/ungetc.c
Normal file
16
lang/cem/libcc/stdio/ungetc.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
ungetc(ch, iop)
|
||||
int ch;
|
||||
FILE *iop;
|
||||
{
|
||||
if ( ch < 0 || !io_testflag(iop,IO_READMODE))
|
||||
return EOF;
|
||||
if (iop->_ptr == iop->_buf) {
|
||||
if (iop->_count != 0) return EOF;
|
||||
iop->_ptr++;
|
||||
}
|
||||
iop->_count++;
|
||||
*--iop->_ptr = ch;
|
||||
return(ch);
|
||||
}
|
||||
Reference in New Issue
Block a user