Plan 9 from Bell Labs’s /usr/web/sources/contrib/rsc/86a/main.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include "all.h"

void
usage(void)
{
	fprint(2, "usage: 86a file.s86\n");
	exits("usage");
}

char *file;
int line;

void
main(int argc, char **argv)
{
	int i, n, ninst;
	Inst **inst;
	char *s;
	Biobuf *b;

	ARGBEGIN{
	default:
		usage();
	}ARGEND

	if(argc != 1)
		usage();

	fmtinstall('I', instfmt);
	fmtinstall('E', exprfmt);
	plan9order();

	file = argv[0];
	if((b = Bopen(file, OREAD)) == nil)
		sysfatal("open %s: %r", argv[0]);

	inst = nil;
	ninst = 0;
	line = 0;
	while((s = Brdstr(b, '\n', 1)) != nil){
		line++;
		if(ninst%64==0)
			inst = erealloc(inst, (ninst+64)*sizeof(inst[0]));
		if(assinst(inst[ninst] = parseinst(s)) < 0){
			print("%s:%d: couldn't assemble '%I'\n", argv[0], n, inst);
			inst[ninst]->nbyte = 0;
		}
		ninst++;
	}

	for(i=0; i<n; i++){
		resolve const names
	}
}

void
parseerror(char *s, ...)
{
	Fmt f;
	char buf[256];
	va_list arg;

	fprint(2, "parse error: %s:%d: ", file, line);
	fmtfdinit(&f, 2, buf, sizeof buf);
	va_start(arg, s);
	fmtvprint(&f, s, arg);
	va_end(arg);
	fmtfdflush(&f);
	fprint(2, "\n");
	exits("parse error");
}

void*
emalloc(int n)
{
	void *a;

	a = mallocz(n, 1);
	if(a == nil)
		sysfatal("out of memory");
	return a;
}

char*
estrdup(char *s)
{
	s = strdup(s);
	if(s == nil)
		sysfatal("out of memory");
	return s;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.