~kris/9p

9hist

1214df8fcc50a0953dea9f88912916c0f3cbbb5a — David du Colombier 30 years ago 069da42
Plan 9 from Bell Labs 1996-02-14
9 files changed, 112 insertions(+), 101 deletions(-)

M boot/boot.c
M carrera/ns16552.h
M pc/main.c
M pc/u.h
M port/devcons.c
M port/lib.h
M port/print.c
M power/devduart.c
M power/u.h
M boot/boot.c => boot/boot.c +2 -2
@@ 28,11 28,11 @@ static void	recover(Method*);
static Method	*rootserver(char*);

static int
rconv(void *o, Fconv *fp)
rconv(va_list *arg, Fconv *fp)
{
	char s[ERRLEN];

	USED(o);
	USED(arg);

	s[0] = 0;
	errstr(s);

M carrera/ns16552.h => carrera/ns16552.h +5 -1
@@ 32,8 32,12 @@ iprint(char *fmt, ...)
{
	int n, i;
	char buf[512];
	va_list arg;

	va_start(arg, fmt);
	n = doprint(buf, buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);

	n = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	for(i = 0; i < n; i++)
		ns16552iputc(buf[i]);
	

M pc/main.c => pc/main.c +5 -1
@@ 835,8 835,12 @@ iprint(char *fmt, ...)
{
	char buf[PRINTSIZE];
	int n;
	va_list arg;

	va_start(arg, fmt);
	n = doprint(buf, buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);

	n = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	screenputs(buf, n);

	return n;

M pc/u.h => pc/u.h +2 -0
@@ 15,3 15,5 @@ union Length
		long	length;
	};
};

#include <stdarg.h>

M port/devcons.c => port/devcons.c +30 -8
@@ 99,22 99,36 @@ putstrn(char *str, int n)
int
snprint(char *s, int n, char *fmt, ...)
{
	return doprint(s, s+n, fmt, (&fmt+1)) - s;
	va_list arg;

	va_start(arg, fmt);
	n = doprint(s, s+n, fmt, arg) - s;
	va_end(arg);
	return n;
}

int
sprint(char *s, char *fmt, ...)
{
	return doprint(s, s+PRINTSIZE, fmt, (&fmt+1)) - s;
	va_list arg;
	int n;

	va_start(arg, fmt);
	n = doprint(s, s+PRINTSIZE, fmt, arg) - s;
	va_end(arg);
	return n;
}

int
print(char *fmt, ...)
{
	char buf[PRINTSIZE];
	va_list arg;
	int n;

	n = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	va_start(arg, fmt);
	n = doprint(buf, buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);
	putstrn(buf, n);

	return n;


@@ 124,9 138,12 @@ int
fprint(int, char *fmt, ...)	/* needed so we can use user-level libg */
{
	char buf[PRINTSIZE];
	va_list arg;
	int n;

	n = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	va_start(arg, fmt);
	n = doprint(buf, buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);
	putstrn(buf, n);

	return n;


@@ 136,10 153,13 @@ void
panic(char *fmt, ...)
{
	char buf[PRINTSIZE];
	va_list arg;
	int n;

	strcpy(buf, "panic: ");
	n = doprint(buf+strlen(buf), buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	va_start(arg, fmt);
	n = doprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);
	buf[n] = '\n';
	putstrn(buf, n+1);
	spllo();


@@ 154,6 174,7 @@ pprint(char *fmt, ...)
{
	char buf[2*PRINTSIZE];
	Chan *c;
	va_list arg;
	int n;

	if(up->fgrp == 0)


@@ 163,7 184,9 @@ pprint(char *fmt, ...)
	if(c==0 || (c->mode!=OWRITE && c->mode!=ORDWR))
		return 0;
	n = sprint(buf, "%s %d: ", up->text, up->pid);
	n = doprint(buf+n, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	va_start(arg, fmt);
	n = doprint(buf+n, buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);

	if(waserror())
		return 0;


@@ 387,9 410,8 @@ int
readnum(ulong off, char *buf, ulong n, ulong val, int size)
{
	char tmp[64];
	Fconv fconv = (Fconv){ tmp, tmp+sizeof(tmp), size-1, 0, 0, 'u' };

	numbconv(&val, &fconv);
	snprint(tmp, sizeof(tmp), "%*.0ud", size-1, val);
	tmp[size-1] = ' ';
	if(off >= size)
		return 0;

M port/lib.h => port/lib.h +3 -3
@@ 56,9 56,9 @@ struct
	int	chr;
} Fconv;
extern	void	strconv(char*, Fconv*);
extern	int	numbconv(void*, Fconv*);
extern	char	*doprint(char*, char*, char*, void*);
extern	int	fmtinstall(int, int (*)(void*, Fconv*));
extern	int	numbconv(va_list*, Fconv*);
extern	char	*doprint(char*, char*, char*, va_list);
extern	int	fmtinstall(int, int (*)(va_list*, Fconv*));
extern	int	sprint(char*, char*, ...);
extern	int	snprint(char*, int, char*, ...);
extern	int	print(char*, ...);

M port/print.c => port/print.c +56 -82
@@ 11,37 11,31 @@ enum
	NONE	= -1000,
	MAXFMT	= 512,

	FPLUS	= (1<<0),
	FMINUS	= (1<<1),
	FSHARP	= (1<<2),
	FLONG	= (1<<3),
	FSHORT	= (1<<4),
	FUNSIGN	= (1<<5),
	FVLONG	= (1<<6),
	FPLUS	= 1<<0,
	FMINUS	= 1<<1,
	FSHARP	= 1<<2,
	FLONG	= 1<<3,
	FSHORT	= 1<<4,
	FUNSIGN	= 1<<5,
	FVLONG	= 1<<6,
};

#define	PTR	sizeof(char*)
#define	SHORT	sizeof(int)
#define	INT	sizeof(int)
#define	LONG	sizeof(long)
#define	VLONG	sizeof(vlong)

int	printcol;

static	int	convcount;
static	char	fmtindex[MAXFMT];

static	int	noconv(void*, Fconv*);
static	int	flags(void*, Fconv*);
static	int	noconv(va_list*, Fconv*);
static	int	flags(va_list*, Fconv*);

static	int	cconv(void*, Fconv*);
static	int	sconv(void*, Fconv*);
static	int	percent(void*, Fconv*);
static	int	cconv(va_list*, Fconv*);
static	int	sconv(va_list*, Fconv*);
static	int	percent(va_list*, Fconv*);

int	numbconv(void*, Fconv*);
int	numbconv(va_list*, Fconv*);

static
int	(*fmtconv[MAXCONV])(void*, Fconv*) =
int	(*fmtconv[MAXCONV])(va_list*, Fconv*) =
{
	noconv
};


@@ 90,15 84,15 @@ initfmt(void)
}

int
fmtinstall(int c, int (*f)(void*, Fconv*))
fmtinstall(int c, int (*f)(va_list*, Fconv*))
{

	if(convcount == 0)
		initfmt();
	if(c < 0 || c >= MAXFMT)
		return 1;
		return -1;
	if(convcount >= MAXCONV)
		return 1;
		return -1;
	fmtconv[convcount] = f;
	fmtindex[c] = convcount;
	convcount++;


@@ 106,14 100,14 @@ fmtinstall(int c, int (*f)(void*, Fconv*))
}

char*
doprint(char *s, char *es, char *fmt, void *argp)
doprint(char *s, char *es, char *fmt, va_list argp)
{
	int n, c;
	Rune rune;
	Fconv local;

	local.out = s;
	local.eout = es-4;		/* room for multi-byte character and 0 */
	local.eout = es-UTFmax-1;

loop:
	c = *fmt & 0xff;


@@ 144,7 138,7 @@ loop:
		if(local.out < local.eout)
			if(c >= Runeself) {
				rune = c;
				n = runetochar(local.out, &rune);	/* BUG */
				n = runetochar(local.out, &rune);
				local.out += n;
			} else
				*local.out++ = c;


@@ 199,8 193,7 @@ l1:
		goto l1;
	}
	if(c == '*') {
		n = *(int*)argp;
		argp = (char*)argp + INT;
		n = va_arg(argp, int);
		if(local.f1 == NONE)
			local.f1 = n;
		else


@@ 211,26 204,21 @@ l1:
	if(c >= 0 && c < MAXFMT)
		n = fmtindex[c];
	local.chr = c;
	n = (*fmtconv[n])(argp, &local);
	n = (*fmtconv[n])(&argp, &local);
	if(n < 0) {
		local.f3 |= -n;
		goto l0;
	}
	argp = (char*)argp + n;
	goto loop;
}

int
numbconv(void *o, Fconv *fp)
numbconv(va_list *arg, Fconv *fp)
{
	char s[IDIGIT];
	int i, f, n, r, b, ucase;
	int i, f, n, b, ucase;
	short h;
	long v;
	vlong vl;

	SET(v);
	SET(vl);

	ucase = 0;
	b = fp->chr;


@@ 253,42 241,31 @@ numbconv(void *o, Fconv *fp)
	}

	f = 0;
	switch(fp->f3 & (FVLONG|FLONG|FSHORT|FUNSIGN)) {
	case FVLONG|FLONG:
		vl = *(vlong*)o;
		r = VLONG;
		break;

	switch(fp->f3 & (FLONG|FSHORT|FUNSIGN)) {
	case FLONG:
		v = *(long*)o;
		r = LONG;
		v = va_arg(*arg, long);
		break;

	case FUNSIGN|FLONG:
		v = *(ulong*)o;
		r = LONG;
		v = va_arg(*arg, ulong);
		break;

	case FSHORT:
		h = *(int*)o;
		h = va_arg(*arg, int);
		v = h;
		r = SHORT;
		break;

	case FUNSIGN|FSHORT:
		h = *(int*)o;
		h = va_arg(*arg, int);
		v = (ushort)h;
		r = SHORT;
		break;

	default:
		v = *(int*)o;
		r = INT;
		v = va_arg(*arg, int);
		break;

	case FUNSIGN:
		v = *(unsigned*)o;
		r = INT;
		v = va_arg(*arg, unsigned);
		break;
	}
	if(!(fp->f3 & FUNSIGN) && v < 0) {


@@ 297,10 274,7 @@ numbconv(void *o, Fconv *fp)
	}
	s[IDIGIT-1] = 0;
	for(i = IDIGIT-2;; i--) {
		if(fp->f3 & FVLONG)
			n = vl % b;
		else
			n = (ulong)v % b;
		n = (ulong)v % b;
		n += '0';
		if(n > '9') {
			n += 'a' - ('9'+1);


@@ 310,23 284,16 @@ numbconv(void *o, Fconv *fp)
		s[i] = n;
		if(i < 2)
			break;
		if(fp->f3 & FVLONG)
			vl = vl / b;
		else
			v = (ulong)v / b;
		v = (ulong)v / b;
		if(fp->f2 != NONE && i >= IDIGIT-fp->f2)
			continue;
		if(fp->f3 & FVLONG)
			if(vl <= 0)
				break;
		if(v <= 0)
			break;
	}
	if(fp->f3 & FSHARP)
	if(s[i] != '0') {
		if(b == 8)

	if(fp->f3 & FSHARP) {
		if(b == 8 && s[i] != '0')
			s[--i] = '0';
		else
		if(b == 16) {
			if(ucase)
				s[--i] = 'X';


@@ 339,7 306,7 @@ numbconv(void *o, Fconv *fp)
		s[--i] = '-';
	fp->f2 = NONE;
	strconv(s+i, fp);
	return r;
	return 0;
}

void


@@ 465,7 432,7 @@ strconv(char *s, Fconv *fp)

static
int
noconv(void *o, Fconv *fp)
noconv(va_list *arg, Fconv *fp)
{
	int n;
	char s[10];


@@ 475,9 442,12 @@ noconv(void *o, Fconv *fp)
		n = 0;
		if(fp->chr >= 0 && fp->chr < MAXFMT)
			n = fmtindex[fp->chr];
		return (*fmtconv[n])(o, fp);
		return (*fmtconv[n])(arg, fp);
	}
	sprint(s, "*%c*", fp->chr);
	s[0] = '*';
	s[1] = fp->chr;
	s[2] = '*';
	s[3] = 0;
	fp->f1 = 0;
	fp->f2 = NONE;
	fp->f3 = 0;


@@ 487,58 457,62 @@ noconv(void *o, Fconv *fp)

static
int
cconv(void *o, Fconv *fp)
cconv(va_list *arg, Fconv *fp)
{
	char s[10];
	Rune rune;

	rune = *(int*)o;
	rune = va_arg(*arg, int);
	if(fp->chr == 'c')
		rune &= 0xff;
	s[runetochar(s, &rune)] = 0;

	fp->f2 = NONE;
	strconv(s, fp);
	return INT;
	return 0;
}

static
int
sconv(void *o, Fconv *fp)
sconv(va_list *arg, Fconv *fp)
{
	char *s;
	Rune *r;

	if(fp->chr == 's') {
		s = *(char**)o;
		s = va_arg(*arg, char*);
		if(s == 0)
			s = "<null>";
		strconv(s, fp);
	} else {
		r = *(Rune**)o;
		r = va_arg(*arg, Rune*);
		if(r == 0)
			r = L"<null>";
		Strconv(r, fp);
	}
	return PTR;
	return 0;
}

static
int
percent(void*, Fconv *fp)
percent(va_list *arg, Fconv *fp)
{

	USED(arg);
	if(fp->out < fp->eout)
		*fp->out++ = '%';
	printcol++;
	return 0;
}

static
int
flags(void*, Fconv *fp)
flags(va_list *arg, Fconv *fp)
{
	int f;

	USED(arg);

	f = 0;
	switch(fp->chr) {
	case '+':

M power/devduart.c => power/devduart.c +7 -4
@@ 442,8 442,12 @@ iprint(char *fmt, ...)
{
	int n, i;
	char buf[512];
	va_list arg;

	va_start(arg, fmt);
	n = doprint(buf, buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);

	n = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	for(i = 0; i < n; i++)
		duartrawputc(buf[i]);
	return n;


@@ 630,13 634,12 @@ duartctl(Uart *p, char *cmd)
	for(i = 0; i < 16 && qlen(p->oq); i++)
		tsleep(&p->r, qlen, p->oq, 125);

	if(strncmp(cmd, "break", 5) == 0)
		cmed += 4;

	n = atoi(cmd+1);
	switch(cmd[0]){
	case 'B':
	case 'b':
		if(strncmp(cmd+1, "reak", 4) == 0)
			break;
		p->val = n;
		p->op = Dbaud;
		sleep(&p->opr, opdone, p);

M power/u.h => power/u.h +2 -0
@@ 15,3 15,5 @@ union Length
		long	length;
	};
};

#include <stdarg.h>