use varargs when needed

This commit is contained in:
ceriel 1988-04-15 15:34:19 +00:00
parent 2549099d3b
commit f5be4dafc6
6 changed files with 44 additions and 26 deletions

View file

@ -5,14 +5,15 @@
/* $Header$ */
#include <system.h>
#include <varargs.h>
#include "param.h"
doprnt(fp, fmt, argp)
File *fp;
char *fmt;
int argp[];
va_list argp;
{
char buf[SSIZE];
sys_write(fp, buf, _format(buf, fmt, (char *)argp));
sys_write(fp, buf, _format(buf, fmt, argp));
}

View file

@ -4,6 +4,8 @@
*/
/* $Header$ */
#include <varargs.h>
char *long2str();
static int
@ -27,9 +29,9 @@ integral(c)
int
_format(buf, fmt, argp)
char *buf, *fmt;
char *argp;
register va_list argp;
{
register char *pf = fmt, *pa = argp;
register char *pf = fmt;
register char *pb = buf;
while (*pf) {
@ -52,24 +54,20 @@ _format(buf, fmt, argp)
while (*pf >= '0' && *pf <= '9')
width = 10 * width + *pf++ - '0';
/* get text and move pa */
if (*pf == 's') {
arg = *(char **)pa;
pa += sizeof(char *);
arg = va_arg(argp, char *);
}
else
if (*pf == 'c') {
cbuf[0] = * (int *) pa;
cbuf[0] = va_arg(argp, int);
cbuf[1] = '\0';
pa += sizeof(int);
arg = &cbuf[0];
}
else
if (*pf == 'l') {
/* alignment ??? */
if (base = integral(*++pf)) {
arg = long2str(*(long *)pa, base);
pa += sizeof(long);
arg = long2str(va_arg(argp,long), base);
}
else {
pf--;
@ -78,8 +76,7 @@ _format(buf, fmt, argp)
}
else
if (base = integral(*pf)) {
arg = long2str((long)*(int *)pa, base);
pa += sizeof(int);
arg = long2str((long)va_arg(argp,int), base);
}
else
if (*pf == '%')

View file

@ -4,16 +4,23 @@
*/
/* $Header$ */
#include <varargs.h>
#include <system.h>
#include "param.h"
/*VARARGS1*/
fprint(fp, fmt, args)
fprint(va_alist)
va_dcl
{
File *fp;
char *fmt;
int args;
{
va_list args;
char buf[SSIZE];
sys_write(fp, buf, _format(buf, fmt, &args));
va_start(args);
fp = va_arg(args, File *);
fmt = va_arg(args, char *);
sys_write(fp, buf, _format(buf, fmt, args));
va_end(args);
}

View file

@ -5,6 +5,7 @@ print, fprint, sprint, doprnt -- very simple formatted-output routines
.SH SYNOPSIS
.nf
.B #include <system.h>
.B #include <varargs.h>
.PP
.B print(format [, arg] ... )
.B char *format;
@ -19,7 +20,7 @@ print, fprint, sprint, doprnt -- very simple formatted-output routines
.B doprnt(filep, format, args)
.B File *filep;
.B char *format;
.B int args[];
.B va_list args;
.fi
.SH DESCRIPTION
.I Print

View file

@ -4,15 +4,20 @@
*/
/* $Header$ */
#include <varargs.h>
#include <system.h>
#include "param.h"
/*VARARGS1*/
print(fmt, args)
char *fmt;
int args;
print(va_alist)
va_dcl
{
char *fmt;
va_list args;
char buf[SSIZE];
sys_write(STDOUT, buf, _format(buf, fmt, &args));
va_start(args);
fmt = va_arg(args, char *);
sys_write(STDOUT, buf, _format(buf, fmt, args));
va_end(args);
}

View file

@ -4,15 +4,22 @@
*/
/* $Header$ */
#include <varargs.h>
#include <system.h>
#include "param.h"
/*VARARGS1*/
char *
sprint(buf, fmt, args)
char *buf, *fmt;
int args;
sprint(va_alist)
va_dcl
{
buf[_format(buf, fmt, &args)] = '\0';
char *buf, *fmt;
va_list args;
va_start(args);
buf = va_arg(args, char *);
fmt = va_arg(args, char *);
buf[_format(buf, fmt, args)] = '\0';
va_end(args);
return buf;
}