Sigrid Haflínudóttirremove aa_readfp and simplify readinga5cbab76 years agoHistory
76 lines · 1.3 KB · C
RawDownload
#include <u.h>#include <libc.h>#include <bio.h>#include "aa.h"#include "aa_math.h" /* need this for note handling * FIXME in threaded program we'd probably use thread local storage? */static aaContext *curctx; static jmp_buf toplevel;static char buf[64000]; static voidonerror(aaContext *ctx, const char *msg, aaObject *cl){	USED(cl);	Bprint(ctx->fd[2], "error: %s\n", msg);	Bflush(ctx->fd[2]);	longjmp(toplevel, -1);} static voidonnote(void *uregs, char *msg){	if(strncmp(msg, "sys: trap: ", 11) == 0)		noted(NDFLT);	Bprint(curctx->fd[2], "error: %s\n", msg);	Bflush(curctx->fd[2]);	notejmp(uregs, toplevel, -1);} voidmain(int argc, char **argv){	int gc;	aaObject *obj;	Biobuf *fp;	aaContext *ctx = aa_open(buf, sizeof(buf), 0); 	aa_include_math(ctx);	curctx = ctx;	notify(onnote); 	if(argc > 1){		if((fp = Bopen(argv[1], OREAD)) == nil)			aa_error(ctx, "could not open input file");		else			ctx->fd[0] = fp;	}else{		fp = ctx->fd[0];		aa_handlers(ctx)->error = onerror;		Bprint(ctx->fd[2], "aa v0.0.1\n");	} 	gc = aa_savegc(ctx);	setjmp(toplevel); 	for(;;){		aa_restoregc(ctx, gc);		if(fp->fid == 0){			Bflush(ctx->fd[2]);			Bflush(ctx->fd[1]);		}		if((obj = aa_read(ctx, fp)) == nil)			break;		obj = aa_eval(ctx, obj);		if(fp->fid == 0)			Bprint(ctx->fd[2], "\x08 ⇒ %§\n", obj);	} 	aa_close(ctx); 	exits(nil);}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t