Initial revision
This commit is contained in:
parent
8f2fe1c003
commit
69f02d8abc
51 changed files with 2589 additions and 0 deletions
50
lang/cem/libcc.ansi/stdio/LIST
Normal file
50
lang/cem/libcc.ansi/stdio/LIST
Normal file
|
@ -0,0 +1,50 @@
|
|||
llib
|
||||
tmpfile.c
|
||||
tmpnam.c
|
||||
rename.c
|
||||
remove.c
|
||||
fopen.c
|
||||
freopen.c
|
||||
setbuf.c
|
||||
setvbuf.c
|
||||
perror.c
|
||||
fprintf.c
|
||||
printf.c
|
||||
sprintf.c
|
||||
vfprintf.c
|
||||
vprintf.c
|
||||
vsprintf.c
|
||||
doprnt.c
|
||||
fscanf.c
|
||||
scanf.c
|
||||
sscanf.c
|
||||
doscan.c
|
||||
fgetc.c
|
||||
fgets.c
|
||||
getc.c
|
||||
getchar.c
|
||||
gets.c
|
||||
putc.c
|
||||
putchar.c
|
||||
fputc.c
|
||||
puts.c
|
||||
fputs.c
|
||||
ungetc.c
|
||||
fread.c
|
||||
fwrite.c
|
||||
fgetpos.c
|
||||
fsetpos.c
|
||||
rewind.c
|
||||
fseek.c
|
||||
ftell.c
|
||||
clearerr.c
|
||||
feof.c
|
||||
ferror.c
|
||||
fltpr.c
|
||||
ecvt.c
|
||||
gcvt.c
|
||||
fillbuf.c
|
||||
fclose.c
|
||||
flushbuf.c
|
||||
fflush.c
|
||||
data.c
|
12
lang/cem/libcc.ansi/stdio/clearerr.c
Normal file
12
lang/cem/libcc.ansi/stdio/clearerr.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* clearerr.c - clear error and end-of-file indicators of a stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
clearerr(FILE *stream)
|
||||
{
|
||||
stream->_flags &= ~(_IOERR|_IOEOF);
|
||||
}
|
28
lang/cem/libcc.ansi/stdio/data.c
Normal file
28
lang/cem/libcc.ansi/stdio/data.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* data.c - this is the initialization for the standard streams
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
struct _iobuf _stdin = {
|
||||
0, 0, _IOREAD, 0,
|
||||
(char *)NULL, (unsigned char *)NULL, (unsigned char *)NULL,
|
||||
};
|
||||
|
||||
struct _iobuf _stdout = {
|
||||
1, 0, _IOWRITE, 0,
|
||||
(char *)NULL, (unsigned char *)NULL, (unsigned char *)NULL,
|
||||
};
|
||||
|
||||
struct _iobuf _stderr = {
|
||||
2, 0, _IOWRITE | _IONBF, 0,
|
||||
(char *)NULL, (unsigned char *)NULL, (unsigned char *)NULL,
|
||||
};
|
||||
|
||||
struct _iobuf *_iotable[FOPEN_MAX] = {
|
||||
&_stdin,
|
||||
&_stdout,
|
||||
&_stderr,
|
||||
0
|
||||
};
|
368
lang/cem/libcc.ansi/stdio/doprnt.c
Normal file
368
lang/cem/libcc.ansi/stdio/doprnt.c
Normal file
|
@ -0,0 +1,368 @@
|
|||
/*
|
||||
* doprnt.c - print formatted output
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
static char *
|
||||
gnum(register const char *f, int *ip, va_list *app)
|
||||
{
|
||||
register int i, c;
|
||||
|
||||
if (*f == '*') {
|
||||
*ip = va_arg((*app), int);
|
||||
f++;
|
||||
} else {
|
||||
i = 0;
|
||||
while ((c = *f - '0') >= 0 && c <= 9) {
|
||||
i = i*10 + c;
|
||||
f++;
|
||||
}
|
||||
*ip = i;
|
||||
}
|
||||
return(f);
|
||||
}
|
||||
|
||||
#if EM_WSIZE == EM_PSIZE
|
||||
#define set_pointer(flags) /* nothing */
|
||||
#elif EM_LSIZE == EM_PSIZE
|
||||
#define set_pointer(flags) (flags |= FL_LONG)
|
||||
#else
|
||||
#define set_pointer(flags) /* nothing */
|
||||
#error garbage pointer size
|
||||
#endif
|
||||
|
||||
char *
|
||||
i_compute(unsigned long val, int base, char *s, int nrdigits)
|
||||
{
|
||||
int c;
|
||||
|
||||
c= val % base ;
|
||||
val /= base ;
|
||||
if (val || nrdigits > 0)
|
||||
s = i_compute(val, base, s, nrdigits - 1);
|
||||
*s++ = (c>9 ? c-10+'a' : c+'0');
|
||||
return(s);
|
||||
}
|
||||
|
||||
/* print an ordinal number */
|
||||
static char *
|
||||
o_print(va_list *ap, int flags, char *s, char c, int precision, int is_signed)
|
||||
{
|
||||
long signed_val;
|
||||
unsigned long unsigned_val;
|
||||
char *old_s = s;
|
||||
int i, base, is_zero = 0, is_neg = 0;
|
||||
|
||||
switch (flags & (FL_SHORT | FL_LONG)) {
|
||||
case FL_SHORT:
|
||||
if (is_signed) {
|
||||
signed_val = (short) va_arg(*ap, int);
|
||||
} else {
|
||||
unsigned_val = (unsigned short) va_arg(*ap, unsigned);
|
||||
}
|
||||
break;
|
||||
case FL_LONG:
|
||||
if (is_signed) {
|
||||
signed_val = va_arg(*ap, long);
|
||||
} else {
|
||||
unsigned_val = va_arg(*ap, unsigned long);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (is_signed) {
|
||||
signed_val = va_arg(*ap, int);
|
||||
} else {
|
||||
unsigned_val = va_arg(*ap, unsigned int);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_signed) {
|
||||
if (signed_val < 0) {
|
||||
*s++ = '-';
|
||||
signed_val = -signed_val;
|
||||
} else if (flags & FL_SIGN) *s++ = '+';
|
||||
else if (flags & FL_SPACE) *s++ = ' ';
|
||||
unsigned_val = signed_val;
|
||||
}
|
||||
if (!unsigned_val) {
|
||||
if (precision != 0)
|
||||
*s++ = '0';
|
||||
return s;
|
||||
}
|
||||
if (((flags & FL_ALT) && (c == 'x' || c == 'X' || c == 'o'))
|
||||
|| c == 'p') {
|
||||
*s++ = '0';
|
||||
if (c != 'o')
|
||||
*s++ = (c == 'X') ? 'X' : 'x';
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'b': base = 2; break;
|
||||
case 'o': base = 8; break;
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'u': base = 10; break;
|
||||
case 'x':
|
||||
case 'X':
|
||||
case 'p': base = 16; break;
|
||||
}
|
||||
|
||||
s = i_compute(unsigned_val, base, s, precision - 1);
|
||||
|
||||
if (c == 'X')
|
||||
while (old_s != s) {
|
||||
*old_s = toupper(*old_s);
|
||||
old_s++;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef NOFLOAT
|
||||
static char *
|
||||
f_print(va_list *ap, int flags, char *s, char c, int precision)
|
||||
{
|
||||
register char *old_s = s;
|
||||
double d_val;
|
||||
|
||||
#if EM_DSIZE != EM_LDSIZE
|
||||
long double ld_val;
|
||||
|
||||
if (flags & FL_LONGDOUBLE) ld_val = va_arg(*ap, long double);
|
||||
else
|
||||
#endif
|
||||
d_val = va_arg(*ap, double);
|
||||
|
||||
switch(c) {
|
||||
case 'f':
|
||||
#if EM_DSIZE != EM_LDSIZE
|
||||
if (flags & FL_LONGDOUBLE)
|
||||
s = _pfloat_ldbl(ld_val, s, precision, flags);
|
||||
else
|
||||
#endif
|
||||
s = _pfloat(d_val, s, precision, flags);
|
||||
break;
|
||||
case 'e':
|
||||
case 'E':
|
||||
#if EM_DSIZE != EM_LDSIZE
|
||||
if (flags & FL_LONGDOUBLE)
|
||||
s = _pscien_ldbl(ld_val, s, precision, flags);
|
||||
else
|
||||
#endif
|
||||
s = _pscien(d_val, s, precision, flags);
|
||||
break;
|
||||
case 'g':
|
||||
case 'G':
|
||||
#if EM_DSIZE != EM_LDSIZE
|
||||
if (flags & FL_LONGDOUBLE)
|
||||
s = gcvt_ldbl(ld_val, precision, s, flags) + strlen(s);
|
||||
else
|
||||
#endif
|
||||
s = gcvt(d_val, precision, s, flags) + strlen(s);
|
||||
break;
|
||||
}
|
||||
if ( c == 'E' || c == 'G') {
|
||||
while (*old_s && *old_s != 'e') old_s++;
|
||||
if (*old_s == 'e') *old_s = 'E';
|
||||
}
|
||||
return s;
|
||||
}
|
||||
#endif /* NOFLOAT */
|
||||
|
||||
int
|
||||
_doprnt(register const char *fmt, va_list ap, FILE *stream)
|
||||
{
|
||||
register char *s;
|
||||
unsigned int uint;
|
||||
register int j;
|
||||
int i, c, width, precision, zfill, flags, between_fill;
|
||||
int nrchars=0;
|
||||
char *oldfmt, *s1, buf[1025];
|
||||
|
||||
while (c = *fmt++) {
|
||||
if (c != '%') {
|
||||
#ifdef CPM
|
||||
if (c == '\n') {
|
||||
putc('\r', stream);
|
||||
nrchars++;
|
||||
}
|
||||
#endif
|
||||
putc(c, stream);
|
||||
nrchars++;
|
||||
continue;
|
||||
}
|
||||
flags = 0;
|
||||
do {
|
||||
switch(*fmt) {
|
||||
case '-': flags |= FL_LJUST; break;
|
||||
case '+': flags |= FL_SIGN; break;
|
||||
case ' ': flags |= FL_SPACE; break;
|
||||
case '#': flags |= FL_ALT; break;
|
||||
case '0': flags |= FL_ZEROFILL; break;
|
||||
default: flags |= FL_NOMORE; continue;
|
||||
}
|
||||
fmt++;
|
||||
} while(!(flags & FL_NOMORE));
|
||||
|
||||
oldfmt = fmt;
|
||||
fmt = gnum(fmt, &width, &ap);
|
||||
if (fmt != oldfmt) flags |= FL_WIDTHSPEC;
|
||||
|
||||
if (*fmt == '.') {
|
||||
fmt++; oldfmt = fmt;
|
||||
fmt = gnum(fmt, &precision, &ap);
|
||||
if (precision >= 0) flags |= FL_PRECSPEC;
|
||||
}
|
||||
|
||||
if ((flags & FL_WIDTHSPEC) && width < 0) {
|
||||
width = -width;
|
||||
flags |= FL_LJUST;
|
||||
}
|
||||
if (!(flags & FL_WIDTHSPEC)) width = 1;
|
||||
|
||||
if (flags & FL_SIGN)
|
||||
flags &= ~FL_SPACE;
|
||||
|
||||
if (flags & (FL_LJUST | FL_PRECSPEC))
|
||||
flags &= ~FL_ZEROFILL;
|
||||
|
||||
zfill = ' ';
|
||||
if (flags & FL_ZEROFILL)
|
||||
zfill = '0';
|
||||
|
||||
s = s1 = buf;
|
||||
|
||||
switch (*fmt) {
|
||||
case 'h': flags |= FL_SHORT; fmt++; break;
|
||||
case 'l': flags |= FL_LONG; fmt++; break;
|
||||
case 'L': flags |= FL_LONGDOUBLE; fmt++; break;
|
||||
}
|
||||
|
||||
switch (c = *fmt++) {
|
||||
default:
|
||||
#ifdef CPM
|
||||
if (c == '\n') {
|
||||
putc('\r', stream);
|
||||
nrchars++;
|
||||
}
|
||||
#endif
|
||||
putc(c, stream);
|
||||
nrchars++;
|
||||
continue;
|
||||
case 'n':
|
||||
if (flags & FL_SHORT)
|
||||
*va_arg(ap, short *) = (short) nrchars;
|
||||
else if (flags & FL_LONG)
|
||||
*va_arg(ap, long *) = (long) nrchars;
|
||||
else
|
||||
*va_arg(ap, int *) = (int) nrchars;
|
||||
continue;
|
||||
case 's':
|
||||
s1 = va_arg(ap, char *);
|
||||
if (s1 == NULL)
|
||||
s1 = "(null)";
|
||||
s = s1;
|
||||
do {
|
||||
if (*s == '\0')
|
||||
break;
|
||||
s++;
|
||||
} while (!(flags & FL_PRECSPEC) || --precision);
|
||||
break;
|
||||
case 'p':
|
||||
set_pointer(flags);
|
||||
/* fallthrough */
|
||||
case 'b':
|
||||
case 'o':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
if (!(flags & FL_PRECSPEC)) precision = 1;
|
||||
s = o_print(&ap, flags, s, c, precision, 0);
|
||||
break;
|
||||
case 'd':
|
||||
case 'i':
|
||||
flags |= FL_SIGNEDCONV;
|
||||
if (!(flags & FL_PRECSPEC)) precision = 1;
|
||||
s = o_print(&ap, flags, s, c, precision, 1);
|
||||
break;
|
||||
case 'c':
|
||||
uint = va_arg(ap, unsigned int);
|
||||
for ( i= sizeof(uint) -1 ; i>=0 ; i-- ) {
|
||||
if ( *s = uint%256 ) s++;
|
||||
uint/= 256 ;
|
||||
}
|
||||
break;
|
||||
#ifndef NOFLOAT
|
||||
case 'G':
|
||||
case 'g':
|
||||
if ((flags & FL_PRECSPEC) && (precision == 0))
|
||||
precision = 1;
|
||||
case 'f':
|
||||
case 'E':
|
||||
case 'e':
|
||||
if (!(flags & FL_PRECSPEC))
|
||||
precision = 6;
|
||||
|
||||
if (precision >= sizeof(buf))
|
||||
precision = sizeof(buf) - 1;
|
||||
|
||||
flags |= FL_SIGNEDCONV;
|
||||
s = f_print(&ap, flags, s, c, precision);
|
||||
break;
|
||||
#endif /* NOFLOAT */
|
||||
case 'r':
|
||||
ap = va_arg(ap, va_list);
|
||||
fmt = va_arg(ap, char *);
|
||||
continue;
|
||||
}
|
||||
j = s - s1;
|
||||
|
||||
/* between_fill is true under the following conditions:
|
||||
* 1- the fill character is '0'
|
||||
* and
|
||||
* 2a- the number is of the form 0x... or 0X...
|
||||
* or
|
||||
* 2b- the number contains a sign or space
|
||||
*/
|
||||
between_fill = 0;
|
||||
if ((flags & FL_ZEROFILL)
|
||||
&& (((c == 'x' || c == 'X') && (flags & FL_ALT))
|
||||
|| (c == 'p')
|
||||
|| ((flags & FL_SIGNEDCONV)
|
||||
&& ( *s1 == '+' || *s1 == '-' || *s1 == ' '))))
|
||||
between_fill++;
|
||||
|
||||
if ((i = width - j) > 0)
|
||||
if (!(flags & FL_LJUST)) { /* right justify */
|
||||
nrchars += i;
|
||||
if (between_fill) {
|
||||
if (flags & FL_SIGNEDCONV) {
|
||||
j--; nrchars++;
|
||||
putc(*s1++, stream);
|
||||
} else {
|
||||
j -= 2; nrchars += 2;
|
||||
putc(*s1++, stream);
|
||||
putc(*s1++, stream);
|
||||
}
|
||||
}
|
||||
do putc(zfill, stream);
|
||||
while (--i);
|
||||
}
|
||||
|
||||
nrchars += j;
|
||||
while (--j >= 0)
|
||||
putc(*s1++, stream);
|
||||
|
||||
if (i > 0) nrchars += i;
|
||||
while (--i >= 0)
|
||||
putc(zfill, stream);
|
||||
}
|
||||
return nrchars;
|
||||
}
|
410
lang/cem/libcc.ansi/stdio/doscan.c
Normal file
410
lang/cem/libcc.ansi/stdio/doscan.c
Normal file
|
@ -0,0 +1,410 @@
|
|||
/*
|
||||
* doscan.c - scan formatted input
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
#define NUMLEN 128
|
||||
|
||||
static char Xtable[128];
|
||||
static char inp_buf[NUMLEN];
|
||||
|
||||
/* Collect a number of characters which constitite an ordinal number.
|
||||
* When the type is 'i', the base can be 8, 10, or 16, depending on the
|
||||
* first 1 or 2 characters. This means that the base must be adjusted
|
||||
* according to the format of the number. At the end of the function, base
|
||||
* is then set to 0, so strtol() will get the right argument.
|
||||
*/
|
||||
static char *
|
||||
o_collect(register int c, register FILE *stream, char type,
|
||||
int width, int *base)
|
||||
{
|
||||
register char *bufp = inp_buf;
|
||||
|
||||
switch (type) {
|
||||
case 'i': /* i means octal, decimal or hexadecimal */
|
||||
case 'p':
|
||||
case 'x':
|
||||
case 'X': *base = 16; break;
|
||||
case 'd':
|
||||
case 'u': *base = 10; break;
|
||||
case 'o': *base = 8; break;
|
||||
case 'b': *base = 2; break;
|
||||
}
|
||||
|
||||
if (c == '-' || c == '+') {
|
||||
*bufp++ = c;
|
||||
width--;
|
||||
c = getc(stream);
|
||||
}
|
||||
|
||||
if (width && c == '0' && *base == 16) {
|
||||
*bufp++ = c;
|
||||
width--;
|
||||
c = getc(stream);
|
||||
if (c != 'x' && c != 'X') {
|
||||
if (type == 'i') *base = 8;
|
||||
}
|
||||
else if (width) {
|
||||
*bufp++ = c;
|
||||
width--;
|
||||
c = getc(stream);
|
||||
}
|
||||
}
|
||||
else if (type == 'i') *base = 10;
|
||||
|
||||
while (width) {
|
||||
if (((*base == 10) && isdigit(c))
|
||||
|| ((*base == 16) && isxdigit(c))
|
||||
|| ((*base == 8) && isdigit(c) && (c < '8'))
|
||||
|| ((*base == 2) && isdigit(c) && (c < '2'))) {
|
||||
*bufp++ = c;
|
||||
width--;
|
||||
c = getc(stream);
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
if (c != EOF) ungetc(c, stream);
|
||||
if (type == 'i') *base = 0;
|
||||
*bufp-- = '\0';
|
||||
return bufp;
|
||||
}
|
||||
|
||||
#ifndef NOFLOAT
|
||||
/* The function f_collect() reads a string that has the format of a
|
||||
* floating-point number. The function returns as soon as a format-error
|
||||
* is encountered, leaving the offending character in the input. This means
|
||||
* that 1.el leaves the 'l' in the input queue. Since all detection of
|
||||
* format errors is done here, _doscan() doesn't call strtod() when it's
|
||||
* not necessary.
|
||||
*/
|
||||
static char *
|
||||
f_collect(register int c, register FILE *stream, int width)
|
||||
{
|
||||
register char *bufp = inp_buf;
|
||||
int digit_seen = 0;
|
||||
|
||||
if (c == '-' || c == '+') {
|
||||
*bufp++ = c;
|
||||
width--;
|
||||
c = getc(stream);
|
||||
}
|
||||
|
||||
while (width && isdigit(c)) {
|
||||
digit_seen++;
|
||||
*bufp++ = c;
|
||||
width--;
|
||||
c = getc(stream);
|
||||
}
|
||||
if (width && c == '.') {
|
||||
*bufp++ = c;
|
||||
width--;
|
||||
c = getc(stream);
|
||||
while (width && isdigit(c)) {
|
||||
digit_seen++;
|
||||
*bufp++ = c;
|
||||
width--;
|
||||
c = getc(stream);
|
||||
}
|
||||
}
|
||||
|
||||
if (!digit_seen) {
|
||||
if (c != EOF) ungetc(c, stream);
|
||||
return inp_buf - 1;
|
||||
}
|
||||
else digit_seen = 0;
|
||||
|
||||
if (width && (c == 'e' || c == 'E')) {
|
||||
*bufp++ = c;
|
||||
width--;
|
||||
c = getc(stream);
|
||||
if (width && (c == '+' || c == '-')) {
|
||||
*bufp++ = c;
|
||||
width--;
|
||||
c = getc(stream);
|
||||
}
|
||||
while (width && isdigit(c)) {
|
||||
digit_seen++;
|
||||
*bufp++ = c;
|
||||
width--;
|
||||
c = getc(stream);
|
||||
}
|
||||
if (!digit_seen) {
|
||||
if (c != EOF) ungetc(c,stream);
|
||||
return inp_buf - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (c != EOF) ungetc(c, stream);
|
||||
*bufp-- = '\0';
|
||||
return bufp;
|
||||
}
|
||||
#endif /* NOFLOAT */
|
||||
|
||||
|
||||
/*
|
||||
* the routine that does the scanning
|
||||
*/
|
||||
|
||||
int
|
||||
_doscan(register FILE *stream, const char *format, va_list ap)
|
||||
{
|
||||
int done = 0; /* number of items done */
|
||||
int nrchars = 0; /* number of characters read */
|
||||
int base; /* conversion base */
|
||||
unsigned long val; /* an integer value */
|
||||
char *str, *tmp_string; /* temporary pointers */
|
||||
unsigned width; /* width of field */
|
||||
int flags; /* some flags */
|
||||
int reverse; /* reverse the checking in [...] */
|
||||
int kind;
|
||||
register int ic;
|
||||
#ifndef NOFLOAT
|
||||
double d_val;
|
||||
#endif
|
||||
|
||||
ic = getc(stream);
|
||||
if (ic == EOF)
|
||||
return EOF;
|
||||
ungetc(ic,stream);
|
||||
|
||||
while (1) {
|
||||
if (isspace(*format)) {
|
||||
while (isspace (*format))
|
||||
++format; /* skip whitespace */
|
||||
ic = getc(stream);
|
||||
nrchars++;
|
||||
while (isspace (ic)) {
|
||||
ic = getc(stream);
|
||||
nrchars++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ic = getc(stream);
|
||||
nrchars++;
|
||||
}
|
||||
if (!*format)
|
||||
break; /* end of format */
|
||||
if (ic == EOF)
|
||||
return done; /* seen an error */
|
||||
if (*format != '%') {
|
||||
if (ic != *format)
|
||||
break; /* matching error */
|
||||
++format;
|
||||
continue;
|
||||
}
|
||||
++format;
|
||||
if (*format == '%') {
|
||||
if (ic == '%') {
|
||||
format++;
|
||||
continue;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
flags = 0;
|
||||
if (*format == '*') {
|
||||
++format;
|
||||
flags |= FL_NOASSIGN;
|
||||
}
|
||||
if (isdigit (*format)) {
|
||||
flags |= FL_WIDTHSPEC;
|
||||
for (width = 0; isdigit (*format);)
|
||||
width = width * 10 + *format++ - '0';
|
||||
}
|
||||
|
||||
switch (*format) {
|
||||
case 'h': flags |= FL_SHORT; format++; break;
|
||||
case 'l': flags |= FL_LONG; format++; break;
|
||||
case 'L': flags |= FL_LONGDOUBLE; format++; break;
|
||||
}
|
||||
kind = *format;
|
||||
if ((kind != 'c') && (kind != '[') && (kind != 'n')) {
|
||||
while (ic != EOF && isspace(ic)) {
|
||||
ic = getc(stream);
|
||||
nrchars++;
|
||||
}
|
||||
}
|
||||
switch (kind) {
|
||||
default:
|
||||
if (kind == ic) continue;
|
||||
break;
|
||||
case 'n':
|
||||
if (ic != EOF)
|
||||
ungetc(ic, stream);
|
||||
nrchars--;
|
||||
if (flags & FL_SHORT)
|
||||
*va_arg(ap, short *) = (short) nrchars;
|
||||
else if (flags & FL_LONG)
|
||||
*va_arg(ap, long *) = (long) nrchars;
|
||||
else
|
||||
*va_arg(ap, int *) = (int) nrchars;
|
||||
break;
|
||||
case 'b': /* binary */
|
||||
case 'd': /* decimal */
|
||||
case 'i': /* general integer */
|
||||
case 'o': /* octal */
|
||||
case 'p': /* pointer */
|
||||
case 'u': /* unsigned */
|
||||
case 'x': /* hexadecimal */
|
||||
case 'X': /* ditto */
|
||||
if (!(flags & FL_WIDTHSPEC))
|
||||
width = NUMLEN;
|
||||
if (!width) return done;
|
||||
str = o_collect(ic, stream, kind, width, &base);
|
||||
if (str < inp_buf) return done;
|
||||
nrchars += str - inp_buf + 1;
|
||||
if (!(flags & FL_NOASSIGN)) {
|
||||
if (kind == 'd' || kind == 'i')
|
||||
val = strtol(inp_buf, &tmp_string, base);
|
||||
else
|
||||
val = strtoul(inp_buf, &tmp_string, base);
|
||||
if (flags & FL_LONG)
|
||||
*va_arg(ap, unsigned long *) = (unsigned long) val;
|
||||
else if (flags & FL_SHORT)
|
||||
*va_arg(ap, unsigned short *) = (unsigned short) val;
|
||||
else
|
||||
*va_arg(ap, unsigned *) = (unsigned) val;
|
||||
done++;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
if (!(flags & FL_WIDTHSPEC))
|
||||
width = 1;
|
||||
if (!(flags & FL_NOASSIGN))
|
||||
tmp_string = va_arg(ap, char *);
|
||||
if (!width) return done;
|
||||
if (width && !(flags & FL_NOASSIGN) && (ic != EOF))
|
||||
++done;
|
||||
while (width && ic != EOF) {
|
||||
if (!(flags & FL_NOASSIGN))
|
||||
*tmp_string++ = (char) ic;
|
||||
width--;
|
||||
ic = getc(stream);
|
||||
nrchars++;
|
||||
}
|
||||
|
||||
if (ic != EOF)
|
||||
ungetc(ic,stream);
|
||||
nrchars--;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if (!(flags & FL_WIDTHSPEC))
|
||||
width = 0xffff;
|
||||
if (!(flags & FL_NOASSIGN))
|
||||
tmp_string = va_arg(ap, char *);
|
||||
if (!width) return done;
|
||||
if (!(flags & FL_NOASSIGN))
|
||||
++done;
|
||||
while (width && ic != EOF && !isspace(ic)) {
|
||||
if (!(flags & FL_NOASSIGN))
|
||||
*tmp_string++ = (char) ic;
|
||||
width--;
|
||||
ic = getc(stream);
|
||||
nrchars++;
|
||||
/* terminate the string */
|
||||
if (!(flags & FL_NOASSIGN))
|
||||
*tmp_string = '\0';
|
||||
}
|
||||
if (ic != EOF)
|
||||
ungetc(ic,stream);
|
||||
nrchars--;
|
||||
break;
|
||||
|
||||
case '[':
|
||||
if (!(flags & FL_WIDTHSPEC))
|
||||
width = 0xffff;
|
||||
|
||||
if (!width) return done;
|
||||
if ( *(++format) == '^' ) {
|
||||
reverse = 1;
|
||||
format++;
|
||||
} else
|
||||
reverse = 0;
|
||||
|
||||
for (tmp_string = Xtable; tmp_string < &Xtable[128]
|
||||
; tmp_string++)
|
||||
*tmp_string = 0;
|
||||
|
||||
if (*format == ']') Xtable[*format++] = 1;
|
||||
while (*format && *format != ']') {
|
||||
Xtable[*format++] = 1;
|
||||
if (*format == '-') {
|
||||
format++;
|
||||
if (*format
|
||||
&& *format != ']'
|
||||
&& *(format) >= *(format -2)) {
|
||||
int c;
|
||||
|
||||
for( c = *(format -2) + 1
|
||||
; c <= *format ; c++)
|
||||
Xtable[c] = 1;
|
||||
format++;
|
||||
}
|
||||
else Xtable['-'] = 1;
|
||||
}
|
||||
}
|
||||
if (!*format)
|
||||
return done;
|
||||
|
||||
if (!(flags & FL_NOASSIGN))
|
||||
tmp_string = va_arg(ap, char *);
|
||||
while (width && ic != EOF && (Xtable[ic] ^ reverse)) {
|
||||
if (!(flags & FL_NOASSIGN))
|
||||
*tmp_string++ = (char) ic;
|
||||
width--;
|
||||
ic = getc(stream);
|
||||
nrchars++;
|
||||
}
|
||||
if (ic != EOF)
|
||||
ungetc(ic, stream);
|
||||
nrchars--;
|
||||
if (!(flags & FL_NOASSIGN)) { /* terminate string */
|
||||
*tmp_string = '\0';
|
||||
++done;
|
||||
}
|
||||
break;
|
||||
#ifndef NOFLOAT:
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'f':
|
||||
case 'g':
|
||||
case 'G':
|
||||
if (!(flags & FL_WIDTHSPEC)) width = NUMLEN;
|
||||
if (width > NUMLEN) width = NUMLEN;
|
||||
|
||||
if (!width) return done;
|
||||
str = f_collect(ic, stream, width);
|
||||
if (str < inp_buf) return done;
|
||||
nrchars += str - inp_buf + 1;
|
||||
if (!(flags & FL_NOASSIGN)) {
|
||||
d_val = strtod(inp_buf, &tmp_string);
|
||||
#if EM_DSIZE != EM_LDSIZE
|
||||
if (flags & FL_LONGDOUBLE)
|
||||
*va_arg(ap, long double *) = (long double) d_val;
|
||||
else
|
||||
#endif /* EM_DSIZE != EM_LDSIZE */
|
||||
if (flags & FL_LONG)
|
||||
*va_arg(ap, double *) = (double) d_val;
|
||||
else
|
||||
*va_arg(ap, float *) = (float) d_val;
|
||||
done++;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
} /* end switch */
|
||||
++format;
|
||||
}
|
||||
all_done:
|
||||
if (ic != EOF)
|
||||
ungetc(ic, stream);
|
||||
/* nrchars--; just to keep it clean */
|
||||
quit:
|
||||
return done;
|
||||
}
|
196
lang/cem/libcc.ansi/stdio/ecvt.c
Normal file
196
lang/cem/libcc.ansi/stdio/ecvt.c
Normal file
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
* ecvt.c - conversion routines for printing floating point numbers
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#ifndef NOFLOAT
|
||||
|
||||
static char *cvt(double value, int ndigit, int *decpt, int *sign, int ecvtflag);
|
||||
#define NDIGITS 128
|
||||
|
||||
char *
|
||||
ecvt(double value, int ndigit, int *decpt, int *sign)
|
||||
{
|
||||
return cvt(value, ndigit, decpt, sign, 1);
|
||||
}
|
||||
|
||||
char *
|
||||
fcvt(double value, int ndigit, int *decpt, int *sign)
|
||||
{
|
||||
return cvt(value, ndigit, decpt, sign, 0);
|
||||
}
|
||||
|
||||
static struct powers_of_10 {
|
||||
double pval;
|
||||
double rpval;
|
||||
int exp;
|
||||
} p10[] = {
|
||||
1.0e32, 1.0e-32, 32,
|
||||
1.0e16, 1.0e-16, 16,
|
||||
1.0e8, 1.0e-8, 8,
|
||||
1.0e4, 1.0e-4, 4,
|
||||
1.0e2, 1.0e-2, 2,
|
||||
1.0e1, 1.0e-1, 1,
|
||||
1.0e0, 1.0e0, 0
|
||||
};
|
||||
|
||||
static char *
|
||||
cvt(double value, int ndigit, int *decpt, int *sign, int ecvtflag)
|
||||
{
|
||||
static char buf[NDIGITS+1];
|
||||
register char *p = buf;
|
||||
register char *pe;
|
||||
|
||||
if (ndigit < 0) ndigit = 0;
|
||||
if (ndigit > NDIGITS) ndigit = NDIGITS;
|
||||
pe = &buf[ndigit];
|
||||
buf[0] = '\0';
|
||||
|
||||
*sign = 0;
|
||||
if (value < 0) {
|
||||
*sign = 1;
|
||||
value = -value;
|
||||
}
|
||||
|
||||
*decpt = 0;
|
||||
if (value != 0.0) {
|
||||
register struct powers_of_10 *pp = &p10[0];
|
||||
|
||||
if (value >= 10.0) do {
|
||||
while (value >= pp->pval) {
|
||||
value *= pp->rpval;
|
||||
*decpt += pp->exp;
|
||||
}
|
||||
} while ((++pp)->exp > 0);
|
||||
|
||||
pp = &p10[0];
|
||||
if (value < 1.0) do {
|
||||
while (value * pp->pval < 10.0) {
|
||||
value *= pp->pval;
|
||||
*decpt -= pp->exp;
|
||||
}
|
||||
} while ((++pp)->exp > 0);
|
||||
|
||||
(*decpt)++; /* because now value in [1.0, 10.0) */
|
||||
}
|
||||
if (!ecvtflag) {
|
||||
/* for fcvt() we need ndigit digits behind the dot */
|
||||
pe += *decpt;
|
||||
if (pe > &buf[NDIGITS]) pe = &buf[NDIGITS];
|
||||
}
|
||||
while (p <= pe) {
|
||||
*p++ = (int)value + '0';
|
||||
value = 10.0 * (value - (int)value);
|
||||
}
|
||||
if (pe >= buf) {
|
||||
p = pe;
|
||||
*p += 5; /* round of at the end */
|
||||
while (*p > '9') {
|
||||
*p = '0';
|
||||
if (p > buf) ++*--p;
|
||||
else {
|
||||
*p = '1';
|
||||
++*decpt;
|
||||
if (!ecvtflag) {
|
||||
/* maybe add another digit at the end,
|
||||
because the point was shifted right
|
||||
*/
|
||||
if (pe > buf) *pe = '0';
|
||||
pe++;
|
||||
}
|
||||
}
|
||||
}
|
||||
*pe = '\0';
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
#if EM_DSIZE != EM_LDSIZE
|
||||
|
||||
static char *cvt_ldbl(long double value, int ndigit, int *decpt,
|
||||
int *sign, int ecvtflag);
|
||||
|
||||
char *
|
||||
ecvt_ldbl(long double value, int ndigit, int *decpt, int *sign)
|
||||
{
|
||||
return cvt_ldbl(value, ndigit, decpt, sign, 1);
|
||||
}
|
||||
|
||||
char *
|
||||
fcvt_ldbl(long double value, int ndigit, int *decpt, int *sign)
|
||||
{
|
||||
return cvt_ldbl(value, ndigit, decpt, sign, 0);
|
||||
}
|
||||
|
||||
static char *
|
||||
cvt_ldbl(long double value, int ndigit, int *decpt, int *sign, int ecvtflag)
|
||||
{
|
||||
static char buf[NDIGITS+1];
|
||||
register char *p = buf;
|
||||
register char *pe;
|
||||
|
||||
if (ndigit < 0) ndigit = 0;
|
||||
if (ndigit > NDIGITS) ndigit = NDIGITS;
|
||||
pe = &buf[ndigit];
|
||||
buf[0] = '\0';
|
||||
|
||||
*sign = 0;
|
||||
if (value < 0) {
|
||||
*sign = 1;
|
||||
value = -value;
|
||||
}
|
||||
|
||||
*decpt = 0;
|
||||
if (value != 0.0) {
|
||||
register struct powers_of_10 *pp = &p10[0];
|
||||
|
||||
if (value >= 10.0) do {
|
||||
while (value >= pp->pval) {
|
||||
value *= pp->rpval;
|
||||
*decpt += pp->exp;
|
||||
}
|
||||
} while ((++pp)->exp > 0);
|
||||
|
||||
pp = &p10[0];
|
||||
if (value < 1.0) do {
|
||||
while (value * pp->pval < 10.0) {
|
||||
value *= pp->pval;
|
||||
*decpt -= pp->exp;
|
||||
}
|
||||
} while ((++pp)->exp > 0);
|
||||
|
||||
(*decpt)++; /* because now value in [1.0, 10.0) */
|
||||
}
|
||||
if (!ecvtflag) {
|
||||
/* for fcvt() we need ndigit digits behind the dot */
|
||||
pe += *decpt;
|
||||
if (pe > &buf[NDIGITS]) pe = &buf[NDIGITS];
|
||||
}
|
||||
while (p <= pe) {
|
||||
*p++ = (int)value + '0';
|
||||
value = 10.0 * (value - (int)value);
|
||||
}
|
||||
if (pe >= buf) {
|
||||
p = pe;
|
||||
*p += 5; /* round of at the end */
|
||||
while (*p > '9') {
|
||||
*p = '0';
|
||||
if (p > buf) ++*--p;
|
||||
else {
|
||||
*p = '1';
|
||||
++*decpt;
|
||||
if (!ecvtflag) {
|
||||
/* maybe add another digit at the end,
|
||||
because the point was shifted right
|
||||
*/
|
||||
if (pe > buf) *pe = '0';
|
||||
pe++;
|
||||
}
|
||||
}
|
||||
}
|
||||
*pe = '\0';
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
#endif /* EM_DSIZE != EM_LDSIZE */
|
||||
#endif /* NOFLOAT */
|
31
lang/cem/libcc.ansi/stdio/fclose.c
Normal file
31
lang/cem/libcc.ansi/stdio/fclose.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* fclose.c - flush a stream and close the file
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int close(int d);
|
||||
|
||||
int
|
||||
fclose(FILE *fp)
|
||||
{
|
||||
register int i, retval = 0;
|
||||
|
||||
for (i=0; i<FOPEN_MAX; i++)
|
||||
if (fp == _iotable[i]) {
|
||||
_iotable[i] = 0;
|
||||
break;
|
||||
}
|
||||
if (i >= FOPEN_MAX)
|
||||
return(EOF);
|
||||
if (fflush(fp)) retval = EOF; /* ??? */
|
||||
if (close(fileno(fp))) retval = EOF; /* ??? */
|
||||
if ( io_testflag(fp,_IOMYBUF) && fp->_buf )
|
||||
free((void *)fp->_buf);
|
||||
if (fp != &_stdin && fp != &_stdout && fp != &_stderr)
|
||||
free((void *)fp);
|
||||
return(retval);
|
||||
}
|
14
lang/cem/libcc.ansi/stdio/feof.c
Normal file
14
lang/cem/libcc.ansi/stdio/feof.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* feof.c - test if eof on a stream occurred
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#undef feof
|
||||
|
||||
int
|
||||
feof(FILE *stream)
|
||||
{
|
||||
return (stream->_flags & _IOEOF) != 0;
|
||||
}
|
14
lang/cem/libcc.ansi/stdio/ferror.c
Normal file
14
lang/cem/libcc.ansi/stdio/ferror.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* ferror .c - test if an error on a stream occurred
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#undef ferror
|
||||
|
||||
int
|
||||
ferror(FILE *stream)
|
||||
{
|
||||
return (stream->_flags & _IOERR) != 0;
|
||||
}
|
47
lang/cem/libcc.ansi/stdio/fflush.c
Normal file
47
lang/cem/libcc.ansi/stdio/fflush.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* fflush.c - flush stream(s)
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int write(int d, static char *buf, int nbytes);
|
||||
|
||||
int
|
||||
fflush(FILE *stream)
|
||||
{
|
||||
int count, c1, i, retval = 0;
|
||||
|
||||
if (!stream) {
|
||||
for(i= 0; i < FOPEN_MAX; i++)
|
||||
if (_iotable[i] && fflush(_iotable[i]))
|
||||
retval = EOF;
|
||||
return retval;
|
||||
}
|
||||
|
||||
if (!stream->_buf ||
|
||||
io_testflag(stream,_IONBF) ||
|
||||
!io_testflag(stream,_IOWRITE) )
|
||||
return(0);
|
||||
|
||||
if (io_testflag(stream, _IOLBF))
|
||||
count = -stream->_count;
|
||||
else count = stream->_bufsiz - stream->_count;
|
||||
|
||||
if ( count <= 0 )
|
||||
return(0);
|
||||
|
||||
c1 = write(stream->_fd, (char *)stream->_buf, count);
|
||||
|
||||
if ( count == c1 ) {
|
||||
if (io_testflag(stream, _IOLBF))
|
||||
stream->_count = 0;
|
||||
else stream->_count = stream->_bufsiz;
|
||||
stream->_ptr = stream->_buf;
|
||||
return(count);
|
||||
}
|
||||
|
||||
stream->_flags |= _IOERR;
|
||||
return(EOF);
|
||||
}
|
12
lang/cem/libcc.ansi/stdio/fgetc.c
Normal file
12
lang/cem/libcc.ansi/stdio/fgetc.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* fgetc - get an unsigned character and return it as an int
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
fgetc(FILE *stream)
|
||||
{
|
||||
return getc(stream);
|
||||
}
|
15
lang/cem/libcc.ansi/stdio/fgetpos.c
Normal file
15
lang/cem/libcc.ansi/stdio/fgetpos.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* fgetpos.c - get the position in the file
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
int
|
||||
fgetpos(FILE *stream, fpos_t *pos)
|
||||
{
|
||||
*pos = ftell(stream);
|
||||
if (*pos == -1) return -1;
|
||||
return 0;
|
||||
}
|
24
lang/cem/libcc.ansi/stdio/fgets.c
Normal file
24
lang/cem/libcc.ansi/stdio/fgets.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* fgets.c - get a string from a file
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
char *
|
||||
fgets(char *s, int n, FILE *stream)
|
||||
{
|
||||
register int ch;
|
||||
register char *ptr;
|
||||
|
||||
ptr = s;
|
||||
while (--n > 0 && (ch = getc(stream)) != EOF) {
|
||||
*ptr++ = ch;
|
||||
if ( ch == '\n')
|
||||
break;
|
||||
}
|
||||
if (ch == EOF && ptr==s)
|
||||
return(NULL);
|
||||
*ptr = '\0';
|
||||
return(s);
|
||||
}
|
54
lang/cem/libcc.ansi/stdio/fillbuf.c
Normal file
54
lang/cem/libcc.ansi/stdio/fillbuf.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* fillbuf.c - fill a buffer
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int read(int d, char *buf, int nbytes);
|
||||
|
||||
int
|
||||
_fillbuf(register FILE *stream)
|
||||
{
|
||||
static unsigned char ch[FOPEN_MAX];
|
||||
|
||||
stream->_count = 0;
|
||||
if (fileno(stream) < 0) return EOF;
|
||||
if (io_testflag(stream, (_IOEOF | _IOERR )))
|
||||
return (EOF);
|
||||
|
||||
if (!io_testflag(stream, _IOREAD) )
|
||||
return (EOF);
|
||||
|
||||
if (!io_testflag(stream, _IONBF) && !stream->_buf) {
|
||||
stream->_buf = (unsigned char *) malloc(BUFSIZ);
|
||||
if (!stream->_buf) {
|
||||
stream->_flags |= _IONBF;
|
||||
}
|
||||
else {
|
||||
stream->_flags |= _IOMYBUF;
|
||||
stream->_bufsiz = BUFSIZ;
|
||||
}
|
||||
}
|
||||
if (!stream->_buf) {
|
||||
stream->_buf = &ch[fileno(stream)];
|
||||
stream->_bufsiz = 1;
|
||||
}
|
||||
stream->_ptr = stream->_buf;
|
||||
stream->_count = read(stream->_fd, (char *)stream->_buf, stream->_bufsiz);
|
||||
|
||||
if (stream->_count <= 0){
|
||||
if (stream->_count == 0) {
|
||||
stream->_flags |= _IOEOF;
|
||||
}
|
||||
else
|
||||
stream->_flags |= _IOERR;
|
||||
|
||||
return (EOF);
|
||||
}
|
||||
stream->_count--;
|
||||
|
||||
return *stream->_ptr++;
|
||||
}
|
148
lang/cem/libcc.ansi/stdio/fltpr.c
Normal file
148
lang/cem/libcc.ansi/stdio/fltpr.c
Normal file
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* floatpr.c - print floating point numbers
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#ifndef NOFLOAT
|
||||
#include "loc_incl.h"
|
||||
|
||||
char *
|
||||
_pfloat(double r, register char *s, int n, int flags)
|
||||
{
|
||||
register char *s1;
|
||||
int sign, dp;
|
||||
register int i;
|
||||
|
||||
s1 = fcvt(r, n, &dp, &sign);
|
||||
if (sign)
|
||||
*s++ = '-';
|
||||
else if (flags & FL_SIGN)
|
||||
*s++ = '+';
|
||||
else if (flags & FL_SPACE)
|
||||
*s++ = ' ';
|
||||
|
||||
if (dp<=0)
|
||||
*s++ = '0';
|
||||
for (i=dp; i>0; i--)
|
||||
if (*s1) *s++ = *s1++;
|
||||
else *s++ = '0';
|
||||
if (((i=n) > 0) || (flags & FL_ALT))
|
||||
*s++ = '.';
|
||||
while (++dp <= 0) {
|
||||
if (--i<0)
|
||||
break;
|
||||
*s++ = '0';
|
||||
}
|
||||
while (--i >= 0)
|
||||
if (*s1) *s++ = *s1++;
|
||||
else *s++ = '0';
|
||||
return(s);
|
||||
}
|
||||
|
||||
char *
|
||||
_pscien(double r, register char *s, int n, int flags)
|
||||
{
|
||||
int sign, dp;
|
||||
register char *s1;
|
||||
|
||||
s1 = ecvt(r, n + 1, &dp, &sign);
|
||||
if (sign)
|
||||
*s++ = '-';
|
||||
else if (flags & FL_SIGN)
|
||||
*s++ = '+';
|
||||
else if (flags & FL_SPACE)
|
||||
*s++ = ' ';
|
||||
|
||||
*s++ = *s1++;
|
||||
if ((n > 0) || (flags & FL_ALT))
|
||||
*s++ = '.';
|
||||
while (--n>0)
|
||||
if (*s1) *s++ = *s1++;
|
||||
else *s++ = '0';
|
||||
*s++ = 'e';
|
||||
if ( r != 0 ) --dp ;
|
||||
if ( dp<0 ) {
|
||||
*s++ = '-' ; dp= -dp ;
|
||||
} else {
|
||||
*s++ = '+' ;
|
||||
}
|
||||
if (dp >= 100) {
|
||||
*s++ = '0' + (dp / 100);
|
||||
dp %= 100;
|
||||
}
|
||||
*s++ = '0' + (dp/10);
|
||||
*s++ = '0' + (dp%10);
|
||||
return(s);
|
||||
}
|
||||
|
||||
#if EM_DSIZE != EM_LDSIZE
|
||||
char *
|
||||
_pfloat_ldbl(long double r, register char *s, int n, int flags)
|
||||
{
|
||||
register char *s1;
|
||||
int sign, dp;
|
||||
register int i;
|
||||
|
||||
s1 = fcvt(r, n, &dp, &sign);
|
||||
if (sign)
|
||||
*s++ = '-';
|
||||
else if (flags & FL_SIGN)
|
||||
*s++ = '+';
|
||||
else if (flags & FL_SPACE)
|
||||
*s++ = ' ';
|
||||
|
||||
if (dp<=0)
|
||||
*s++ = '0';
|
||||
for (i=dp; i>0; i--)
|
||||
if (*s1) *s++ = *s1++;
|
||||
else *s++ = '0';
|
||||
if (((i=n) > 0) || (flags & FL_ALT))
|
||||
*s++ = '.';
|
||||
while (++dp <= 0) {
|
||||
if (--i<0)
|
||||
break;
|
||||
*s++ = '0';
|
||||
}
|
||||
while (--i >= 0)
|
||||
if (*s1) *s++ = *s1++;
|
||||
else *s++ = '0';
|
||||
return(s);
|
||||
}
|
||||
|
||||
char *
|
||||
_pscien_ldbl(long double r, register char *s, int n, int flags)
|
||||
{
|
||||
int sign, dp;
|
||||
register char *s1;
|
||||
|
||||
s1 = ecvt(r, n + 1, &dp, &sign);
|
||||
if (sign)
|
||||
*s++ = '-';
|
||||
else if (flags & FL_SIGN)
|
||||
*s++ = '+';
|
||||
else if (flags & FL_SPACE)
|
||||
*s++ = ' ';
|
||||
|
||||
*s++ = *s1++;
|
||||
if ((n > 0) || (flags & FL_ALT))
|
||||
*s++ = '.';
|
||||
while (--n>0)
|
||||
if (*s1) *s++ = *s1++;
|
||||
else *s++ = '0';
|
||||
*s++ = 'e';
|
||||
if ( r != 0 ) --dp ;
|
||||
if ( dp<0 ) {
|
||||
*s++ = '-' ; dp= -dp ;
|
||||
} else {
|
||||
*s++ = '+' ;
|
||||
}
|
||||
if (dp >= 100) {
|
||||
*s++ = '0' + (dp / 100);
|
||||
dp %= 100;
|
||||
}
|
||||
*s++ = '0' + (dp/10);
|
||||
*s++ = '0' + (dp%10);
|
||||
return(s);
|
||||
}
|
||||
#endif /* EM_DSIZE != EM_LDSIZE */
|
||||
#endif /* NOFLOAT */
|
96
lang/cem/libcc.ansi/stdio/flushbuf.c
Normal file
96
lang/cem/libcc.ansi/stdio/flushbuf.c
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* flushbuf.c - flush a buffer
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int write(int d, const char *buf, int nbytes);
|
||||
int isatty(int d);
|
||||
|
||||
int
|
||||
_flushbuf(int c, FILE * stream)
|
||||
{
|
||||
if (fileno(stream) < 0) return EOF;
|
||||
if (!io_testflag(stream, _IONBF)) {
|
||||
if (!stream->_buf) {
|
||||
if (stream == stdout && isatty(fileno(stdout))) {
|
||||
if (!(stream->_buf =
|
||||
(unsigned char *) malloc(BUFSIZ))) {
|
||||
stream->_flags |= _IONBF;
|
||||
}
|
||||
else {
|
||||
stream->_flags |= _IOLBF;
|
||||
stream->_bufsiz = BUFSIZ;
|
||||
stream->_count = -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!(stream->_buf =
|
||||
(unsigned char *) malloc(BUFSIZ))) {
|
||||
stream->_flags |= _IONBF;
|
||||
}
|
||||
else {
|
||||
stream->_flags |= _IOMYBUF;
|
||||
stream->_bufsiz = BUFSIZ;
|
||||
stream->_count = BUFSIZ - 1;
|
||||
}
|
||||
}
|
||||
stream->_ptr = stream->_buf;
|
||||
}
|
||||
}
|
||||
|
||||
if (io_testflag(stream, _IONBF)) {
|
||||
char c1 = c;
|
||||
|
||||
stream->_count = 0;
|
||||
if (write(fileno(stream), &c1, 1) != 1) {
|
||||
stream->_flags |= _IOERR;
|
||||
return EOF;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
else if (io_testflag(stream, _IOLBF)) {
|
||||
*stream->_ptr++ = c;
|
||||
if (c == '\n' || stream->_count == -stream->_bufsiz) {
|
||||
if (write(fileno(stream), (char *)stream->_buf,
|
||||
-stream->_count) != -stream->_count) {
|
||||
stream->_flags |= _IOERR;
|
||||
return EOF;
|
||||
}
|
||||
else {
|
||||
stream->_ptr = stream->_buf;
|
||||
stream->_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
int count = stream->_ptr - stream->_buf;
|
||||
|
||||
stream->_count = stream->_bufsiz - 1;
|
||||
stream->_ptr = stream->_buf + 1;
|
||||
|
||||
if (count > 0) {
|
||||
if (write(fileno(stream), (char *)stream->_buf, count)
|
||||
!= count) {
|
||||
*(stream->_buf) = c;
|
||||
stream->_flags |= _IOERR;
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
*(stream->_buf) = c;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void
|
||||
_cleanup(void) /* fflush((FILE *)NULL) ??? */
|
||||
{
|
||||
register int i;
|
||||
|
||||
for( i = 0; i < FOPEN_MAX; i++ )
|
||||
if (_iotable[i])
|
||||
fclose(_iotable[i]);
|
||||
}
|
83
lang/cem/libcc.ansi/stdio/fopen.c
Normal file
83
lang/cem/libcc.ansi/stdio/fopen.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* fopen.c - open a stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/file.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
#define PMODE 0666
|
||||
|
||||
int open(const char *path, int flags, int mode);
|
||||
int close(int d);
|
||||
|
||||
FILE *
|
||||
fopen(const char *name, const char *mode)
|
||||
{
|
||||
register int i;
|
||||
int rwmode = 0, rwflags = 0;
|
||||
FILE *stream;
|
||||
int fd, flags = 0;
|
||||
|
||||
for (i = 0; _iotable[i] != 0 ; i++)
|
||||
if ( i >= FOPEN_MAX )
|
||||
return (FILE *)NULL;
|
||||
|
||||
switch(*mode++) {
|
||||
|
||||
case 'r':
|
||||
flags |= _IOREAD;
|
||||
rwmode = O_RDONLY;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
flags |= _IOWRITE;
|
||||
rwmode = O_WRONLY;
|
||||
rwflags = O_CREAT | O_TRUNC;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
flags |= _IOWRITE;
|
||||
rwmode = O_WRONLY;
|
||||
rwflags |= O_APPEND | O_CREAT;
|
||||
break;
|
||||
|
||||
default:
|
||||
return (FILE *)NULL;
|
||||
}
|
||||
|
||||
while (*mode) {
|
||||
switch(*mode++) {
|
||||
|
||||
case 'b':
|
||||
break;
|
||||
|
||||
case '+':
|
||||
rwmode = O_RDWR;
|
||||
flags |= _IOREAD | _IOWRITE;
|
||||
break;
|
||||
|
||||
default:
|
||||
return (FILE *)NULL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fd = open(name, rwmode | rwflags, PMODE);
|
||||
|
||||
if (fd < 0) return (FILE *)NULL;
|
||||
|
||||
if (( stream = (FILE *) malloc(sizeof(FILE))) == NULL ) {
|
||||
close(fd);
|
||||
return (FILE *)NULL;
|
||||
}
|
||||
|
||||
stream->_count = 0;
|
||||
stream->_fd = fd;
|
||||
stream->_flags = flags;
|
||||
stream->_buf = 0;
|
||||
_iotable[i] = stream;
|
||||
return stream;
|
||||
}
|
25
lang/cem/libcc.ansi/stdio/fprintf.c
Normal file
25
lang/cem/libcc.ansi/stdio/fprintf.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* fprintf - write output on a stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int
|
||||
fprintf(FILE *stream, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int retval;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
retval = _doprnt (format, ap, stream);
|
||||
if ( io_testflag(stream,_IOLBF) )
|
||||
fflush(stream);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return retval;
|
||||
}
|
12
lang/cem/libcc.ansi/stdio/fputc.c
Normal file
12
lang/cem/libcc.ansi/stdio/fputc.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* fputc.c - print an unsigned character
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
fputc(int c, FILE *stream)
|
||||
{
|
||||
return putc(c, stream);
|
||||
}
|
18
lang/cem/libcc.ansi/stdio/fputs.c
Normal file
18
lang/cem/libcc.ansi/stdio/fputs.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* fputs - print a string
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
fputs(register const char *s, register FILE *stream)
|
||||
{
|
||||
register int retval = 0;
|
||||
|
||||
while (*s)
|
||||
if (putc(*s++, stream) == EOF) return -1;
|
||||
else retval++;
|
||||
|
||||
return retval;
|
||||
}
|
27
lang/cem/libcc.ansi/stdio/fread.c
Normal file
27
lang/cem/libcc.ansi/stdio/fread.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* fread.c - read a number of members into an array
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
size_t
|
||||
fread(register void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
{
|
||||
int c;
|
||||
size_t ndone = 0, s;
|
||||
|
||||
if (size)
|
||||
while ( ndone < nmemb ) {
|
||||
s = size;
|
||||
do {
|
||||
if ((c = getc(stream)) != EOF)
|
||||
*ptr++ = c;
|
||||
else
|
||||
return ndone;
|
||||
} while (--s);
|
||||
ndone++;
|
||||
}
|
||||
|
||||
return ndone;
|
||||
}
|
88
lang/cem/libcc.ansi/stdio/freopen.c
Normal file
88
lang/cem/libcc.ansi/stdio/freopen.c
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* freopen.c - open a file and associate a stream with it
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/file.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
#define PMODE 0666
|
||||
int open(const char *path, int flags, int mode);
|
||||
int close(int d);
|
||||
|
||||
FILE *
|
||||
freopen(const char *name, const char *mode, FILE *stream)
|
||||
{
|
||||
register int i;
|
||||
int rwmode = 0, rwflags = 0;
|
||||
int fd, flags = stream->_flags & ~(_IOWRITE|_IOREAD|_IOERR|_IOEOF);
|
||||
|
||||
(void) fflush(stream); /* ignore errors */
|
||||
(void) close(fileno(stream));
|
||||
|
||||
switch(*mode++) {
|
||||
|
||||
case 'r':
|
||||
flags |= _IOREAD;
|
||||
rwmode = O_RDONLY;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
flags |= _IOWRITE;
|
||||
rwmode = O_WRONLY;
|
||||
rwflags = O_CREAT | O_TRUNC;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
flags |= _IOWRITE;
|
||||
rwmode = O_WRONLY;
|
||||
rwflags |= O_APPEND | O_CREAT;
|
||||
break;
|
||||
|
||||
default:
|
||||
return (FILE *)NULL;
|
||||
}
|
||||
|
||||
while (*mode) {
|
||||
switch(*mode++) {
|
||||
|
||||
case 'b':
|
||||
break;
|
||||
|
||||
case '+':
|
||||
rwmode = O_RDWR;
|
||||
flags |= _IOREAD | _IOWRITE;
|
||||
break;
|
||||
|
||||
default:
|
||||
return (FILE *)NULL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fd = open(name, rwmode | rwflags, PMODE);
|
||||
|
||||
if (fd < 0) {
|
||||
for( i = 0; i < FOPEN_MAX; i++) {
|
||||
if (stream == _iotable[i]) {
|
||||
_iotable[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (stream != stdin && stream != stdout && stream != stderr)
|
||||
free((void *)stream);
|
||||
return (FILE *)NULL;
|
||||
}
|
||||
|
||||
stream->_count = 0;
|
||||
if (stream->_buf && !(flags & _IONBF) && (flags & _IOWRITE))
|
||||
if (flags & _IOLBF)
|
||||
stream->_count = 0;
|
||||
else stream->_count = stream->_bufsiz;
|
||||
|
||||
stream->_fd = fd;
|
||||
stream->_flags = flags;
|
||||
return(stream);
|
||||
}
|
23
lang/cem/libcc.ansi/stdio/fscanf.c
Normal file
23
lang/cem/libcc.ansi/stdio/fscanf.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* fscanf.c - read formatted input from stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int
|
||||
fscanf(FILE *stream, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int retval;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
retval = _doscan(stream, format, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return retval;
|
||||
}
|
60
lang/cem/libcc.ansi/stdio/fseek.c
Normal file
60
lang/cem/libcc.ansi/stdio/fseek.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* fseek.c - perform an fseek
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/file.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int lseek(int d, int offset, int whence);
|
||||
|
||||
int
|
||||
fseek(FILE *stream, long int offset, int whence)
|
||||
{
|
||||
int count;
|
||||
long pos;
|
||||
|
||||
#if (SEEK_CUR != L_INCR) || (SEEK_SET != L_SET) || (SEEK_END != L_XTND)
|
||||
int swhence; /* the real whence for lseek */
|
||||
|
||||
switch(whence) { /* map to UNIX values */
|
||||
case SEEK_CUR: swhence = L_INCR; break;
|
||||
case SEEK_SET: swhence = L_SET; break;
|
||||
case SEEK_END: swhence = L_XTND; break;
|
||||
default: swhence = whence; break;
|
||||
}
|
||||
#else
|
||||
#define swhence whence
|
||||
#endif
|
||||
|
||||
stream->_flags &= ~(_IOEOF | _IOERR);
|
||||
/* Clear both the end of file and error flags */
|
||||
|
||||
if ( io_testflag(stream,_IOREAD) ) {
|
||||
if ( whence < 2 && stream->_buf
|
||||
&& !io_testflag(stream,_IONBF) ) {
|
||||
count = stream->_count;
|
||||
pos = offset;
|
||||
|
||||
if ( whence == SEEK_SET )
|
||||
pos +=
|
||||
count - lseek(fileno(stream), 0L, swhence);
|
||||
else
|
||||
offset -= count;
|
||||
|
||||
if ( count > 0 && pos <= count
|
||||
&& pos >= stream->_buf - stream->_ptr ) {
|
||||
stream->_ptr += (int) pos;
|
||||
stream->_count -= (int) pos;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
pos = lseek(fileno(stream), offset, swhence);
|
||||
stream->_count = 0;
|
||||
} else if ( io_testflag(stream,_IOWRITE) ) {
|
||||
fflush(stream);
|
||||
pos = lseek(fileno(stream), offset, swhence);
|
||||
}
|
||||
return((pos == -1) ? -1 : 0 );
|
||||
}
|
12
lang/cem/libcc.ansi/stdio/fsetpos.c
Normal file
12
lang/cem/libcc.ansi/stdio/fsetpos.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* fsetpos.c - set the position in the file
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
fsetpos(FILE *stream, fpos_t *pos)
|
||||
{
|
||||
return fseek(stream, *pos, SEEK_SET);
|
||||
}
|
33
lang/cem/libcc.ansi/stdio/ftell.c
Normal file
33
lang/cem/libcc.ansi/stdio/ftell.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* ftell.c - obtain the value of the file-position indicator of a stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/file.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int lseek(int d, int offset, int whence);
|
||||
|
||||
long ftell(FILE * stream)
|
||||
{
|
||||
long result;
|
||||
int adjust;
|
||||
|
||||
if ( io_testflag(stream,_IOREAD) )
|
||||
adjust = -stream->_count;
|
||||
else if (io_testflag(stream,_IOWRITE)
|
||||
&& stream->_buf
|
||||
&& !io_testflag(stream,_IONBF))
|
||||
adjust = stream->_ptr - stream->_buf;
|
||||
else
|
||||
return -1L;
|
||||
|
||||
result = lseek(fileno(stream), 0, L_INCR);
|
||||
|
||||
if ( result == -1 )
|
||||
return result;
|
||||
|
||||
result += (long) adjust;
|
||||
return result;
|
||||
}
|
28
lang/cem/libcc.ansi/stdio/fwrite.c
Normal file
28
lang/cem/libcc.ansi/stdio/fwrite.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* fwrite.c - write a number of array elements on a file
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
size_t
|
||||
fwrite(register const void *ptr, size_t size, size_t nmemb,
|
||||
register FILE *stream)
|
||||
{
|
||||
unsigned s;
|
||||
unsigned ndone = 0;
|
||||
|
||||
if (size)
|
||||
while ( ndone < nmemb ) {
|
||||
s = size;
|
||||
do {
|
||||
if (putc((int)*(unsigned char *)ptr, stream)
|
||||
== EOF)
|
||||
return(ndone);
|
||||
ptr++;
|
||||
}
|
||||
while (--s);
|
||||
ndone++;
|
||||
}
|
||||
return(ndone);
|
||||
}
|
144
lang/cem/libcc.ansi/stdio/gcvt.c
Normal file
144
lang/cem/libcc.ansi/stdio/gcvt.c
Normal file
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* gcvt.c - conversion for printing a floating point number
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#ifndef NOFLOAT
|
||||
#include "loc_incl.h"
|
||||
|
||||
#define NDIGINEXP(exp) (((exp) >= 100 || (exp) <= -100) ? 3 : 2)
|
||||
#define LOW_EXP -4
|
||||
#define USE_EXP(exp, ndigits) (((exp) < LOW_EXP + 1) || (exp >= ndigits + 1))
|
||||
|
||||
char *
|
||||
gcvt(double value, int ndigit, char *s, int flags)
|
||||
{
|
||||
int sign, dp;
|
||||
register char *s1, *s2;
|
||||
register int i;
|
||||
register int nndigit = ndigit;
|
||||
|
||||
s1 = ecvt(value, ndigit, &dp, &sign);
|
||||
s2 = s;
|
||||
if (sign) *s2++ = '-';
|
||||
else if (flags & FL_SIGN)
|
||||
*s2++ = '+';
|
||||
else if (flags & FL_SPACE)
|
||||
*s2++ = ' ';
|
||||
|
||||
if (!(flags & FL_ALT))
|
||||
for (i = nndigit - 1; i > 0 && s1[i] == '0'; i--)
|
||||
nndigit--;
|
||||
|
||||
if (USE_EXP(dp,ndigit)) {
|
||||
/* Use E format */
|
||||
dp--;
|
||||
*s2++ = *s1++;
|
||||
if ((nndigit > 1) || (flags & FL_ALT)) *s2++ = '.';
|
||||
while (--nndigit > 0) *s2++ = *s1++;
|
||||
*s2++ = 'e';
|
||||
if (dp < 0) {
|
||||
*s2++ = '-';
|
||||
dp = -dp;
|
||||
}
|
||||
else *s2++ = '+';
|
||||
s2 += NDIGINEXP(dp);
|
||||
*s2 = 0;
|
||||
for (i = NDIGINEXP(dp); i > 0; i--) {
|
||||
*--s2 = dp % 10 + '0';
|
||||
dp /= 10;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
/* Use f format */
|
||||
if (dp <= 0) {
|
||||
if (*s1 != '0') {
|
||||
/* otherwise the whole number is 0 */
|
||||
*s2++ = '0';
|
||||
*s2++ = '.';
|
||||
}
|
||||
while (dp < 0) {
|
||||
dp++;
|
||||
*s2++ = '0';
|
||||
}
|
||||
}
|
||||
for (i = 1; i <= nndigit; i++) {
|
||||
*s2++ = *s1++;
|
||||
if (i == dp) *s2++ = '.';
|
||||
}
|
||||
if (i <= dp) {
|
||||
while (i++ <= dp) *s2++ = '0';
|
||||
*s2++ = '.';
|
||||
}
|
||||
if ((s2[-1]=='.') && !(flags & FL_ALT)) s2--;
|
||||
*s2 = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
#if EM_DSIZE != EM_LDSIZE
|
||||
char *
|
||||
gcvt_ldbl(long double value, int ndigit, char *s, int flags)
|
||||
{
|
||||
int sign, dp;
|
||||
register char *s1, *s2;
|
||||
register int i;
|
||||
register int nndigit = ndigit;
|
||||
|
||||
s1 = ecvt_ldbl(value, ndigit, &dp, &sign);
|
||||
s2 = s;
|
||||
if (sign) *s2++ = '-';
|
||||
else if (flags & FL_SIGN)
|
||||
*s2++ = '+';
|
||||
else if (flags & FL_SPACE)
|
||||
*s2++ = ' ';
|
||||
|
||||
if (!(flags & FL_ALT))
|
||||
for (i = nndigit - 1; i > 0 && s1[i] == '0'; i--)
|
||||
nndigit--;
|
||||
|
||||
if (USE_EXP(dp,ndigit)) {
|
||||
/* Use E format */
|
||||
dp--;
|
||||
*s2++ = *s1++;
|
||||
if ((nndigit > 1) || (flags & FL_ALT)) *s2++ = '.';
|
||||
while (--nndigit > 0) *s2++ = *s1++;
|
||||
*s2++ = 'e';
|
||||
if (dp < 0) {
|
||||
*s2++ = '-';
|
||||
dp = -dp;
|
||||
}
|
||||
else *s2++ = '+';
|
||||
s2 += NDIGINEXP(dp);
|
||||
*s2 = 0;
|
||||
for (i = NDIGINEXP(dp); i > 0; i--) {
|
||||
*--s2 = dp % 10 + '0';
|
||||
dp /= 10;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
/* Use f format */
|
||||
if (dp <= 0) {
|
||||
if (*s1 != '0') {
|
||||
/* otherwise the whole number is 0 */
|
||||
*s2++ = '0';
|
||||
*s2++ = '.';
|
||||
}
|
||||
while (dp < 0) {
|
||||
dp++;
|
||||
*s2++ = '0';
|
||||
}
|
||||
}
|
||||
for (i = 1; i <= nndigit; i++) {
|
||||
*s2++ = *s1++;
|
||||
if (i == dp) *s2++ = '.';
|
||||
}
|
||||
if (i <= dp) {
|
||||
while (i++ <= dp) *s2++ = '0';
|
||||
*s2++ = '.';
|
||||
}
|
||||
if ((s2[-1]=='.') && !(flags & FL_ALT)) s2--;
|
||||
*s2 = '\0';
|
||||
return s;
|
||||
}
|
||||
#endif /* EM_DSIZE != EM_LDSIZE */
|
||||
#endif /* NOFLOAT */
|
14
lang/cem/libcc.ansi/stdio/getc.c
Normal file
14
lang/cem/libcc.ansi/stdio/getc.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* getc.c - read an unsigned character
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#undef getc
|
||||
|
||||
int
|
||||
getc(FILE *stream)
|
||||
{
|
||||
return fgetc(stream);
|
||||
}
|
14
lang/cem/libcc.ansi/stdio/getchar.c
Normal file
14
lang/cem/libcc.ansi/stdio/getchar.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* getchar.c - read a character from the standard input stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#undef getchar
|
||||
|
||||
int
|
||||
getchar(void)
|
||||
{
|
||||
return getc(stdin);
|
||||
}
|
23
lang/cem/libcc.ansi/stdio/gets.c
Normal file
23
lang/cem/libcc.ansi/stdio/gets.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* gets.c - read a line from a stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
char *
|
||||
gets(char *s)
|
||||
{
|
||||
register int ch;
|
||||
register char *ptr;
|
||||
|
||||
ptr = s;
|
||||
while ((ch = getc(stdin)) != EOF && ch != '\n')
|
||||
*ptr++ = ch;
|
||||
|
||||
if (ch == EOF && ptr==s)
|
||||
return (char *)NULL;
|
||||
|
||||
*ptr = '\0';
|
||||
return s;
|
||||
}
|
50
lang/cem/libcc.ansi/stdio/loc_incl.h
Normal file
50
lang/cem/libcc.ansi/stdio/loc_incl.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* loc_incl.h - local include file for stdio library
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define fileno(p) ((p)->_fd)
|
||||
#define io_testflag(p,x) ((p)->_flags & (x))
|
||||
|
||||
#include <stdarg.h>
|
||||
int _doprnt(const char *format, va_list ap, FILE *stream);
|
||||
int _doscan(FILE * stream, const char *format, va_list ap);
|
||||
char *i_compute(unsigned long val, int base, char *s, int nrdigits);
|
||||
|
||||
#ifndef NOFLOAT
|
||||
char *_pfloat(double r, register char *s, int n, int flags);
|
||||
char *_pscien(double r, register char *s, int n, int flags);
|
||||
char *ecvt(double value, int ndigit, int *decpt, int *sign);
|
||||
char *fcvt(double value, int ndigit, int *decpt, int *sign);
|
||||
char *gcvt(double value, int ndigit, char *buf, int flags);
|
||||
|
||||
/*
|
||||
* When the sizes of doubles and long doubles are equal, the formats must
|
||||
* be equal (since a backend only knows the size of a floating-point
|
||||
* number). This means that the special routines for long doubles are not
|
||||
* necessary.
|
||||
*/
|
||||
#if EM_DSIZE != EM_LDSIZE
|
||||
char *_pfloat_ldbl(long double r, register char *s, int n, int flags);
|
||||
char *_pscien_ldbl(long double r, register char *s, int n, int flags);
|
||||
char *ecvt_ldbl(long double value, int ndigit, int *decpt, int *sign);
|
||||
char *fcvt_ldbl(long double value, int ndigit, int *decpt, int *sign);
|
||||
char *gcvt_ldbl(long double value, int ndigit, char *s, int flags);
|
||||
#endif /* EM_DSIZE != EM_LDSIZE */
|
||||
#endif /* NOFLOAT */
|
||||
|
||||
#define FL_LJUST 0x0001 /* left-justify field */
|
||||
#define FL_SIGN 0x0002 /* sign in signed conversions */
|
||||
#define FL_SPACE 0x0004 /* space in signed conversions */
|
||||
#define FL_ALT 0x0008 /* alternate form */
|
||||
#define FL_ZEROFILL 0x0010 /* fill with zero's */
|
||||
#define FL_SHORT 0x0020 /* optional h */
|
||||
#define FL_LONG 0x0040 /* optional l */
|
||||
#define FL_LONGDOUBLE 0x0080 /* optional L */
|
||||
#define FL_WIDTHSPEC 0x0100 /* field width is specified */
|
||||
#define FL_PRECSPEC 0x0200 /* precision is specified */
|
||||
#define FL_SIGNEDCONV 0x0400 /* may contain a sign */
|
||||
#define FL_NOASSIGN 0x0800 /* do not assign (in scanf) */
|
||||
#define FL_NOMORE 0x1000 /* all flags collected */
|
16
lang/cem/libcc.ansi/stdio/perror.c
Normal file
16
lang/cem/libcc.ansi/stdio/perror.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* perror.c - print an error message on the standard error output
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
perror(const char *s)
|
||||
{
|
||||
if (s && *s)
|
||||
(void) fprintf(stderr,"%s: ", s);
|
||||
(void) fprintf(stderr,"%s\n", strerror(errno));
|
||||
}
|
25
lang/cem/libcc.ansi/stdio/printf.c
Normal file
25
lang/cem/libcc.ansi/stdio/printf.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* printf - write on the standard output stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int
|
||||
printf(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int retval;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
retval = _doprnt(format, ap, stdout);
|
||||
if (io_testflag(stdout,_IOLBF))
|
||||
fflush(stdout);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return retval;
|
||||
}
|
14
lang/cem/libcc.ansi/stdio/putc.c
Normal file
14
lang/cem/libcc.ansi/stdio/putc.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* putc.c - print (or buffer) one character
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#undef putc
|
||||
|
||||
int
|
||||
putc(int c, FILE *stream)
|
||||
{
|
||||
return fputc(c, stream);
|
||||
}
|
14
lang/cem/libcc.ansi/stdio/putchar.c
Normal file
14
lang/cem/libcc.ansi/stdio/putchar.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* putchar.c - print (or buffer) a character on the standard output stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#undef putchar
|
||||
|
||||
int
|
||||
putchar(int c)
|
||||
{
|
||||
return putc(c, stdout);
|
||||
}
|
12
lang/cem/libcc.ansi/stdio/puts.c
Normal file
12
lang/cem/libcc.ansi/stdio/puts.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* puts.c - print a string onto the standard output stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
puts(register const char *s)
|
||||
{
|
||||
return fputs(s, stdout);
|
||||
}
|
13
lang/cem/libcc.ansi/stdio/remove.c
Normal file
13
lang/cem/libcc.ansi/stdio/remove.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* remove.c - remove a file
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int unlink(const char *path);
|
||||
|
||||
int
|
||||
remove(const char *filename) {
|
||||
return unlink(filename);
|
||||
}
|
16
lang/cem/libcc.ansi/stdio/rename.c
Normal file
16
lang/cem/libcc.ansi/stdio/rename.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* rename.c - rename a file
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int link(const char *name1, const char *name2);
|
||||
int unlink(const char *path);
|
||||
|
||||
int
|
||||
rename(const char *old, const char *new) {
|
||||
if (!link(old, new))
|
||||
return remove(old);
|
||||
else return -1;
|
||||
}
|
14
lang/cem/libcc.ansi/stdio/rewind.c
Normal file
14
lang/cem/libcc.ansi/stdio/rewind.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* rewind.c - set the file position indicator of a stream to the start
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
void
|
||||
rewind(FILE *stream)
|
||||
{
|
||||
(void) fseek(stream, 0L, SEEK_SET);
|
||||
clearerr(stream);
|
||||
}
|
25
lang/cem/libcc.ansi/stdio/scanf.c
Normal file
25
lang/cem/libcc.ansi/stdio/scanf.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* scanf.c - read formatted input from the standard input stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int
|
||||
scanf(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int retval;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
retval = _doscan(stdin, format, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
18
lang/cem/libcc.ansi/stdio/setbuf.c
Normal file
18
lang/cem/libcc.ansi/stdio/setbuf.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* setbuf.c - control buffering of a stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
void
|
||||
setbuf(register FILE *stream, char *buf)
|
||||
{
|
||||
int mode;
|
||||
|
||||
if (buf) mode = _IOFBF;
|
||||
else mode = _IONBF;
|
||||
|
||||
(void) setvbuf(stream, buf, mode, (size_t) BUFSIZ);
|
||||
}
|
42
lang/cem/libcc.ansi/stdio/setvbuf.c
Normal file
42
lang/cem/libcc.ansi/stdio/setvbuf.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* setbuf.c - control buffering of a stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int
|
||||
setvbuf(register FILE *stream, char *buf, int mode, size_t size)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (mode != _IOFBF && mode != _IOLBF && mode != _IONBF)
|
||||
return EOF;
|
||||
|
||||
if ( stream->_buf && io_testflag(stream,_IOMYBUF) )
|
||||
free((void *)stream->_buf);
|
||||
|
||||
stream->_flags &= ~(_IOMYBUF | _IONBF | _IOLBF);
|
||||
|
||||
if (!buf && (mode != _IONBF))
|
||||
if ((buf = (char *) malloc(size)) == NULL) retval = -1;
|
||||
|
||||
stream->_buf = (unsigned char *) buf;
|
||||
|
||||
stream->_count = 0;
|
||||
stream->_flags |= mode;
|
||||
stream->_ptr = stream->_buf;
|
||||
|
||||
if (!buf) {
|
||||
stream->_bufsiz = 1;
|
||||
} else {
|
||||
if (io_testflag(stream, _IOWRITE)
|
||||
&& !io_testflag(stream, _IOLBF))
|
||||
stream->_count = size;
|
||||
stream->_bufsiz = size;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
31
lang/cem/libcc.ansi/stdio/sprintf.c
Normal file
31
lang/cem/libcc.ansi/stdio/sprintf.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* sprintf - print formatted output on an array
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int
|
||||
sprintf(char * s, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int retval;
|
||||
FILE tmp_stream;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
tmp_stream._fd = -1;
|
||||
tmp_stream._flags = _IOWRITE + _IONBF;
|
||||
tmp_stream._buf = (unsigned char *) s;
|
||||
tmp_stream._ptr = (unsigned char *) s;
|
||||
tmp_stream._count = 32767;
|
||||
|
||||
retval = _doprnt(format, ap, &tmp_stream);
|
||||
putc('\0',&tmp_stream);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return retval;
|
||||
}
|
29
lang/cem/libcc.ansi/stdio/sscanf.c
Normal file
29
lang/cem/libcc.ansi/stdio/sscanf.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* sscanf - read formatted output from a string
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int sscanf(const char *s, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int retval;
|
||||
FILE tmp_stream;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
tmp_stream._fd = -1;
|
||||
tmp_stream._flags = _IOREAD + _IONBF;
|
||||
tmp_stream._buf = (unsigned char *) s;
|
||||
tmp_stream._ptr = (unsigned char *) s;
|
||||
tmp_stream._count = 32767;
|
||||
|
||||
retval = _doscan(&tmp_stream, format, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return retval;
|
||||
}
|
29
lang/cem/libcc.ansi/stdio/tmpfile.c
Normal file
29
lang/cem/libcc.ansi/stdio/tmpfile.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* tmpfile.c - create and open a temporary file
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
unsigned int getpid(void);
|
||||
|
||||
FILE *
|
||||
tmpfile(void) {
|
||||
static char name_buffer[L_tmpnam] = "/tmp/tmp." ;
|
||||
static char *name = NULL;
|
||||
FILE *file;
|
||||
|
||||
if (!name) {
|
||||
name = name_buffer + strlen(name_buffer);
|
||||
i_compute(getpid(), 10, name, 5);
|
||||
name += strlen(name);
|
||||
*name++ = '\0';
|
||||
}
|
||||
|
||||
file = fopen(name_buffer,"wb+");
|
||||
if (!file) return (FILE *)NULL;
|
||||
if (remove(name_buffer)) return (FILE *)NULL;
|
||||
return file;
|
||||
}
|
28
lang/cem/libcc.ansi/stdio/tmpnam.c
Normal file
28
lang/cem/libcc.ansi/stdio/tmpnam.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* tmpnam.c - create a unique filename
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
unsigned int getpid(void);
|
||||
|
||||
char *
|
||||
tmpnam(char *s) {
|
||||
static char name_buffer[L_tmpnam] = "/tmp/tmp.";
|
||||
static unsigned long count = 0;
|
||||
static char *name = NULL;
|
||||
|
||||
if (!name) {
|
||||
name = name_buffer + strlen(name_buffer);
|
||||
name = i_compute(getpid(), 10, name, 5);
|
||||
*name++ = '.';
|
||||
*name++ = '\0';
|
||||
}
|
||||
if (++count > TMP_MAX) count = 1; /* wrap-around */
|
||||
*i_compute(count, 10, name, 3) = '\0';
|
||||
if (s) return strcpy(s, name_buffer);
|
||||
else return name_buffer;
|
||||
}
|
24
lang/cem/libcc.ansi/stdio/ungetc.c
Normal file
24
lang/cem/libcc.ansi/stdio/ungetc.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* ungetc.c - push a character back onto an imput stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int
|
||||
ungetc(int ch, FILE *stream)
|
||||
{
|
||||
unsigned char *p;
|
||||
|
||||
if (ch == EOF || !io_testflag(stream,_IOREAD))
|
||||
return EOF;
|
||||
if (stream->_ptr == stream->_buf) {
|
||||
if (stream->_count != 0) return EOF;
|
||||
stream->_ptr++;
|
||||
}
|
||||
stream->_count++;
|
||||
p = --(stream->_ptr); /* ??? Bloody vax assembler !!! */
|
||||
*p = (unsigned char) ch;
|
||||
return ch;
|
||||
}
|
20
lang/cem/libcc.ansi/stdio/vfprintf.c
Normal file
20
lang/cem/libcc.ansi/stdio/vfprintf.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* vfprintf - formatted output without ellipsis
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int
|
||||
vfprintf(FILE *stream, const char *format, va_list arg)
|
||||
{
|
||||
int retval;
|
||||
|
||||
retval = _doprnt (format, arg, stream);
|
||||
if (io_testflag(stream, _IOLBF))
|
||||
fflush(stream);
|
||||
|
||||
return retval;
|
||||
}
|
20
lang/cem/libcc.ansi/stdio/vprintf.c
Normal file
20
lang/cem/libcc.ansi/stdio/vprintf.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* vprintf - formatted output without ellipsis to the standard output stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int
|
||||
vprintf(const char *format, va_list arg)
|
||||
{
|
||||
int retval;
|
||||
|
||||
retval = _doprnt(format, arg, stdout);
|
||||
if (io_testflag(stdout, _IOLBF))
|
||||
fflush(stdout);
|
||||
|
||||
return retval;
|
||||
}
|
26
lang/cem/libcc.ansi/stdio/vsprintf.c
Normal file
26
lang/cem/libcc.ansi/stdio/vsprintf.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* vsprintf - print formatted output without ellipsis on an array
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
int
|
||||
vsprintf(char *s, const char *format, va_list arg)
|
||||
{
|
||||
int retval;
|
||||
FILE tmp_stream;
|
||||
|
||||
tmp_stream._fd = -1;
|
||||
tmp_stream._flags = _IOWRITE + _IONBF;
|
||||
tmp_stream._buf = (unsigned char *) s;
|
||||
tmp_stream._ptr = (unsigned char *) s;
|
||||
tmp_stream._count = 32767;
|
||||
|
||||
retval = _doprnt(format, arg, &tmp_stream);
|
||||
putc('\0',&tmp_stream);
|
||||
|
||||
return retval;
|
||||
}
|
Loading…
Reference in a new issue