make to use varargs.h
This commit is contained in:
parent
16e2e6f346
commit
ecaea97a99
8 changed files with 140 additions and 94 deletions
|
@ -1,36 +1,20 @@
|
||||||
/* $Header$ */
|
/* $Header$ */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <varargs.h>
|
||||||
|
|
||||||
#ifndef NOFLOAT
|
#ifndef NOFLOAT
|
||||||
extern char *_pfloat();
|
extern char *_pfloat();
|
||||||
extern char *_pscien();
|
extern char *_pscien();
|
||||||
#endif
|
#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) )
|
# define wsize(par) ( (sizeof par) / sizeof (int) )
|
||||||
|
|
||||||
|
|
||||||
static char *gnum(f,ip) register char *f; int *ip; {
|
static char *gnum(f,ip,app) register char *f; int *ip; va_list *app; {
|
||||||
register int i,c;
|
register int i,c;
|
||||||
|
|
||||||
if (*f == '*') {
|
if (*f == '*') {
|
||||||
geta(ip,wsize(i)) ;
|
*ip = va_arg((*app), int);
|
||||||
f++;
|
f++;
|
||||||
} else {
|
} else {
|
||||||
i = 0;
|
i = 0;
|
||||||
|
@ -78,8 +62,8 @@ static char *l_compute(l1,d,s) long l1; char *s; {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_doprnt(fmt,args,stream)
|
_doprnt(fmt,ap,stream)
|
||||||
register char *fmt; int *args ; FILE *stream;
|
register char *fmt; va_list ap ; FILE *stream;
|
||||||
{
|
{
|
||||||
register char *s;
|
register char *s;
|
||||||
#ifndef NOLONG
|
#ifndef NOLONG
|
||||||
|
@ -97,7 +81,6 @@ _doprnt(fmt,args,stream)
|
||||||
int i,c,rjust,width,ndigit,ndfnd,zfill;
|
int i,c,rjust,width,ndigit,ndfnd,zfill;
|
||||||
char *oldfmt,*s1,buf[1025];
|
char *oldfmt,*s1,buf[1025];
|
||||||
|
|
||||||
nextarg = args;
|
|
||||||
while (c = *fmt++) {
|
while (c = *fmt++) {
|
||||||
if (c != '%') {
|
if (c != '%') {
|
||||||
#ifdef CPM
|
#ifdef CPM
|
||||||
|
@ -120,11 +103,11 @@ _doprnt(fmt,args,stream)
|
||||||
fmt++;
|
fmt++;
|
||||||
zfill = '0';
|
zfill = '0';
|
||||||
}
|
}
|
||||||
fmt = gnum(fmt,&width);
|
fmt = gnum(fmt,&width,&ap);
|
||||||
ndigit = 0; ndfnd = 0;
|
ndigit = 0; ndfnd = 0;
|
||||||
if (*fmt == '.') {
|
if (*fmt == '.') {
|
||||||
fmt++; oldfmt = fmt;
|
fmt++; oldfmt = fmt;
|
||||||
fmt = gnum(fmt,&ndigit);
|
fmt = gnum(fmt,&ndigit,&ap);
|
||||||
ndfnd = (fmt != oldfmt);
|
ndfnd = (fmt != oldfmt);
|
||||||
}
|
}
|
||||||
s = s1 = buf;
|
s = s1 = buf;
|
||||||
|
@ -141,7 +124,9 @@ _doprnt(fmt,args,stream)
|
||||||
putc(c,stream);
|
putc(c,stream);
|
||||||
continue;
|
continue;
|
||||||
case 's':
|
case 's':
|
||||||
geta(&s1,wsize(s1)) ;
|
s1 = va_arg(ap, char *);
|
||||||
|
if (s1 == 0)
|
||||||
|
s1 = "(null)";
|
||||||
s = s1;
|
s = s1;
|
||||||
do {
|
do {
|
||||||
if (*s == 0)
|
if (*s == 0)
|
||||||
|
@ -154,13 +139,13 @@ _doprnt(fmt,args,stream)
|
||||||
case 'u':
|
case 'u':
|
||||||
getu:
|
getu:
|
||||||
if ( !lflag ) {
|
if ( !lflag ) {
|
||||||
geta(&inte,wsize(inte)) ;
|
inte = va_arg(ap, int);
|
||||||
goto i_unsignd ;
|
goto i_unsignd ;
|
||||||
}
|
}
|
||||||
#ifndef NOLONG
|
#ifndef NOLONG
|
||||||
case 'U':
|
case 'U':
|
||||||
getlu:
|
getlu:
|
||||||
geta( &l,wsize(l)) ;
|
l = va_arg(ap, long);
|
||||||
goto l_unsignd ;
|
goto l_unsignd ;
|
||||||
case 'B':
|
case 'B':
|
||||||
j = 2 ;
|
j = 2 ;
|
||||||
|
@ -173,7 +158,7 @@ _doprnt(fmt,args,stream)
|
||||||
goto getlu ;
|
goto getlu ;
|
||||||
case 'D':
|
case 'D':
|
||||||
l_signed:
|
l_signed:
|
||||||
geta(&l,wsize(l)) ;
|
l = va_arg(ap, long);
|
||||||
if (l < 0) {
|
if (l < 0) {
|
||||||
*s++ = '-';
|
*s++ = '-';
|
||||||
l = -l;
|
l = -l;
|
||||||
|
@ -195,7 +180,7 @@ _doprnt(fmt,args,stream)
|
||||||
goto getu ;
|
goto getu ;
|
||||||
case 'd':
|
case 'd':
|
||||||
if ( lflag ) goto l_signed; ;
|
if ( lflag ) goto l_signed; ;
|
||||||
geta(&inte,wsize(inte)) ;
|
inte = va_arg(ap, int);
|
||||||
if ( inte<0 ) {
|
if ( inte<0 ) {
|
||||||
*s++ = '-';
|
*s++ = '-';
|
||||||
inte= -inte ;
|
inte= -inte ;
|
||||||
|
@ -208,7 +193,7 @@ _doprnt(fmt,args,stream)
|
||||||
s = i_compute(inte,j,s);
|
s = i_compute(inte,j,s);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
geta ( &uint, wsize(uint)) ;
|
uint = va_arg(ap, unsigned int);
|
||||||
for ( i= sizeof uint -1 ; i>=0 ; i-- ) {
|
for ( i= sizeof uint -1 ; i>=0 ; i-- ) {
|
||||||
if ( *s = uint%256 ) s++;
|
if ( *s = uint%256 ) s++;
|
||||||
uint/= 256 ;
|
uint/= 256 ;
|
||||||
|
@ -217,18 +202,18 @@ _doprnt(fmt,args,stream)
|
||||||
#ifndef NOFLOAT
|
#ifndef NOFLOAT
|
||||||
case 'e':
|
case 'e':
|
||||||
if (ndigit >= sizeof(buf)) ndigit = sizeof(buf) - 1;
|
if (ndigit >= sizeof(buf)) ndigit = sizeof(buf) - 1;
|
||||||
geta(&dbl,wsize(dbl)) ;
|
dbl = va_arg(ap, double);
|
||||||
s = _pscien(dbl,s,ndigit,ndfnd);
|
s = _pscien(dbl,s,ndigit,ndfnd);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
if (ndigit >= sizeof(buf)) ndigit = sizeof(buf) - 1;
|
if (ndigit >= sizeof(buf)) ndigit = sizeof(buf) - 1;
|
||||||
geta(&dbl,wsize(dbl)) ;
|
dbl = va_arg(ap, double);
|
||||||
s = _pfloat(dbl,s,ndigit,ndfnd);
|
s = _pfloat(dbl,s,ndigit,ndfnd);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'r':
|
case 'r':
|
||||||
geta(&nextarg,wsize(nextarg)) ;
|
ap = va_arg(ap, char *);
|
||||||
geta(&oldfmt,wsize(fmt)) ;
|
fmt = va_arg(ap, char *);
|
||||||
fmt=oldfmt;
|
fmt=oldfmt;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* $Header$ */
|
/* $Header$ */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <varargs.h>
|
||||||
|
|
||||||
union ptr_union {
|
union ptr_union {
|
||||||
char *chr_p;
|
char *chr_p;
|
||||||
|
@ -19,10 +20,10 @@ static char Xtable[128];
|
||||||
* the routine that does the job
|
* the routine that does the job
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_doscanf (iop, format, argp)
|
_doscanf (iop, format, ap)
|
||||||
register FILE *iop;
|
register FILE *iop;
|
||||||
char *format; /* the format control string */
|
char *format; /* the format control string */
|
||||||
union ptr_union *argp; /* our argument list */
|
va_list ap;
|
||||||
{
|
{
|
||||||
int done = 0; /* number of items done */
|
int done = 0; /* number of items done */
|
||||||
int base; /* conversion base */
|
int base; /* conversion base */
|
||||||
|
@ -139,28 +140,32 @@ union ptr_union *argp; /* our argument list */
|
||||||
if (sign)
|
if (sign)
|
||||||
val = -val;
|
val = -val;
|
||||||
if (longflag)
|
if (longflag)
|
||||||
*(argp++)->ulong_p = (unsigned long) val;
|
*va_arg(ap, unsigned long *) = (unsigned long) val;
|
||||||
else if (shortflag)
|
else if (shortflag)
|
||||||
*(argp++)->ushort_p = (unsigned short) val;
|
*va_arg(ap, unsigned short *) = (unsigned short) val;
|
||||||
else
|
else
|
||||||
*(argp++)->uint_p = (unsigned) val;
|
*va_arg(ap, unsigned *) = (unsigned) val;
|
||||||
}
|
}
|
||||||
if (done_some)
|
if (done_some) {
|
||||||
if (do_assign) ++done;
|
if (do_assign) ++done;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
goto all_done;
|
goto all_done;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
if (!widflag)
|
if (!widflag)
|
||||||
width = 1;
|
width = 1;
|
||||||
|
{ register char *p;
|
||||||
|
if (do_assign)
|
||||||
|
p = va_arg(ap, char *);
|
||||||
while (width-- && ic >= 0) {
|
while (width-- && ic >= 0) {
|
||||||
if (do_assign)
|
if (do_assign)
|
||||||
*(argp)->chr_p++ = (char) ic;
|
*p++ = (char) ic;
|
||||||
ic = getc(iop);
|
ic = getc(iop);
|
||||||
done_some = 1;
|
done_some = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (do_assign) {
|
if (do_assign) {
|
||||||
argp++; /* done with this one */
|
|
||||||
if (done_some)
|
if (done_some)
|
||||||
++done;
|
++done;
|
||||||
}
|
}
|
||||||
|
@ -168,16 +173,22 @@ union ptr_union *argp; /* our argument list */
|
||||||
case 's':
|
case 's':
|
||||||
if (!widflag)
|
if (!widflag)
|
||||||
width = 0xffff;
|
width = 0xffff;
|
||||||
|
{ register char *p;
|
||||||
|
if (do_assign)
|
||||||
|
p = va_arg(ap, char *);
|
||||||
while (width-- && !isspace (ic) && ic > 0) {
|
while (width-- && !isspace (ic) && ic > 0) {
|
||||||
if (do_assign)
|
if (do_assign)
|
||||||
*(argp)->chr_p++ = (char) ic;
|
*p++ = (char) ic;
|
||||||
ic = getc(iop);
|
ic = getc(iop);
|
||||||
done_some = 1;
|
done_some = 1;
|
||||||
}
|
}
|
||||||
if (do_assign) /* terminate the string */
|
if (do_assign) /* terminate the string */
|
||||||
*(argp++)->chr_p = '\0';
|
*p = '\0';
|
||||||
if (done_some)
|
}
|
||||||
|
if (done_some) {
|
||||||
|
if (do_assign)
|
||||||
++done;
|
++done;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
goto all_done;
|
goto all_done;
|
||||||
break;
|
break;
|
||||||
|
@ -200,17 +211,23 @@ union ptr_union *argp; /* our argument list */
|
||||||
if (!*format)
|
if (!*format)
|
||||||
goto quit;
|
goto quit;
|
||||||
|
|
||||||
|
{ register char *p;
|
||||||
|
if (do_assign)
|
||||||
|
p = va_arg(ap, char *);
|
||||||
while (width-- && !isspace (ic) && ic > 0 &&
|
while (width-- && !isspace (ic) && ic > 0 &&
|
||||||
(Xtable[ic] ^ reverse)) {
|
(Xtable[ic] ^ reverse)) {
|
||||||
if (do_assign)
|
if (do_assign)
|
||||||
*(argp)->chr_p++ = (char) ic;
|
*p++ = (char) ic;
|
||||||
ic = getc(iop);
|
ic = getc(iop);
|
||||||
done_some = 1;
|
done_some = 1;
|
||||||
}
|
}
|
||||||
if (do_assign) /* terminate the string */
|
if (do_assign) /* terminate the string */
|
||||||
*(argp++)->chr_p = '\0';
|
*p = '\0';
|
||||||
if (done_some && do_assign)
|
}
|
||||||
|
if (done_some) {
|
||||||
|
if (do_assign)
|
||||||
++done;
|
++done;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
goto all_done;
|
goto all_done;
|
||||||
break;
|
break;
|
||||||
|
@ -262,9 +279,9 @@ union ptr_union *argp; /* our argument list */
|
||||||
if (do_assign) {
|
if (do_assign) {
|
||||||
done++;
|
done++;
|
||||||
if (longflag)
|
if (longflag)
|
||||||
*(argp++)->double_p = atof(buffer);
|
*va_arg(ap, double *) = atof(buffer);
|
||||||
else
|
else
|
||||||
*(argp++)->float_p = atof(buffer);
|
*va_arg(ap, float *) = atof(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
/* $Header$ */
|
/* $Header$ */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <varargs.h>
|
||||||
|
|
||||||
fprintf (file, fmt, args)
|
fprintf(va_alist)
|
||||||
|
va_dcl
|
||||||
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char *fmt;
|
char *fmt;
|
||||||
int args;
|
va_list ap;
|
||||||
{
|
|
||||||
_doprnt (fmt, &args, file);
|
va_start(ap);
|
||||||
|
file = va_arg(ap, FILE *);
|
||||||
|
fmt = va_arg(ap, char *);
|
||||||
|
_doprnt (fmt, ap, file);
|
||||||
if ( io_testflag(file,IO_PERPRINTF) )
|
if ( io_testflag(file,IO_PERPRINTF) )
|
||||||
fflush(file);
|
fflush(file);
|
||||||
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
/* $Header$ */
|
/* $Header$ */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <varargs.h>
|
||||||
|
|
||||||
int fscanf (fp, format, args)
|
int fscanf(va_alist)
|
||||||
|
va_dcl
|
||||||
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *format;
|
char *format;
|
||||||
unsigned args;
|
va_list ap;
|
||||||
{
|
int retval;
|
||||||
return _doscanf (fp, format, &args);
|
|
||||||
|
va_start(ap);
|
||||||
|
fp = va_arg(ap, FILE *);
|
||||||
|
format = va_arg(ap, char *);
|
||||||
|
retval = _doscanf (fp, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
/* $Header$ */
|
/* $Header$ */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <varargs.h>
|
||||||
|
|
||||||
printf (fmt, args)
|
printf(va_alist)
|
||||||
char *fmt;
|
va_dcl
|
||||||
int args;
|
|
||||||
{
|
{
|
||||||
_doprnt (fmt, &args, stdout);
|
char *fmt;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap);
|
||||||
|
fmt = va_arg(ap, char *);
|
||||||
|
_doprnt (fmt, ap, stdout);
|
||||||
if ( io_testflag(stdout,IO_PERPRINTF) )
|
if ( io_testflag(stdout,IO_PERPRINTF) )
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
va_end(list);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
/* $Header$ */
|
/* $Header$ */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <varargs.h>
|
||||||
|
|
||||||
int scanf (format, args)
|
int scanf(va_alist)
|
||||||
char *format;
|
va_dcl
|
||||||
unsigned args;
|
|
||||||
{
|
{
|
||||||
return _doscanf (stdin, format, &args);
|
char *format;
|
||||||
|
va_list ap;
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
va_start(ap);
|
||||||
|
format = va_arg(ap, char *);
|
||||||
|
retval = _doscanf (stdin, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,26 @@
|
||||||
/* $Header$ */
|
/* $Header$ */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <varargs.h>
|
||||||
|
|
||||||
char *sprintf(buf,format,args)
|
char *sprintf(va_alist)
|
||||||
char *buf, *format;
|
va_dcl
|
||||||
int args;
|
|
||||||
{
|
{
|
||||||
|
char *buf, *format;
|
||||||
FILE _tempfile;
|
FILE _tempfile;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap);
|
||||||
|
buf = va_arg(ap, char *);
|
||||||
|
format = va_arg(ap, char *);
|
||||||
_tempfile._fd = -1;
|
_tempfile._fd = -1;
|
||||||
_tempfile._flags = IO_WRITEMODE + IO_UNBUFF;
|
_tempfile._flags = IO_WRITEMODE + IO_UNBUFF;
|
||||||
_tempfile._buf = (unsigned char *) buf;
|
_tempfile._buf = (unsigned char *) buf;
|
||||||
_tempfile._ptr = (unsigned char *) buf;
|
_tempfile._ptr = (unsigned char *) buf;
|
||||||
_tempfile._count = 32767;
|
_tempfile._count = 32767;
|
||||||
|
|
||||||
_doprnt(format, &args, &_tempfile);
|
_doprnt(format, ap, &_tempfile);
|
||||||
putc('\0',&_tempfile);
|
putc('\0',&_tempfile);
|
||||||
|
|
||||||
|
va_end(ap);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,26 @@
|
||||||
/* $Header$ */
|
/* $Header$ */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <varargs.h>
|
||||||
|
|
||||||
int sscanf (string, format, args)
|
int sscanf(va_alist)
|
||||||
|
va_dcl
|
||||||
|
{
|
||||||
char *string; /* source of data */
|
char *string; /* source of data */
|
||||||
char *format; /* control string */
|
char *format; /* control string */
|
||||||
unsigned args; /* our args */
|
|
||||||
{
|
|
||||||
FILE _tempfile;
|
FILE _tempfile;
|
||||||
|
va_list ap;
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
va_start(ap);
|
||||||
|
string = va_arg(ap, char *);
|
||||||
|
format = va_arg(ap, char *);
|
||||||
_tempfile._fd = -1;
|
_tempfile._fd = -1;
|
||||||
_tempfile._flags = IO_READMODE + IO_UNBUFF;
|
_tempfile._flags = IO_READMODE + IO_UNBUFF;
|
||||||
_tempfile._buf = (unsigned char *) string;
|
_tempfile._buf = (unsigned char *) string;
|
||||||
_tempfile._ptr = (unsigned char *) string;
|
_tempfile._ptr = (unsigned char *) string;
|
||||||
_tempfile._count = 32767;
|
_tempfile._count = 32767;
|
||||||
|
|
||||||
return _doscanf (&_tempfile, format, &args);
|
retval = _doscanf (&_tempfile, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue