コード例 #1
0
ファイル: input.c プロジェクト: 00001/plan9port
int
getrune(void)
{
	Rune r;
	int c;
	
top:
	if(istack == nil)
		return -1;
	if(istack->nunget)
		return istack->unget[--istack->nunget];
	else if(istack->p){
		if(istack->p >= istack->ep){
			popinput();
			goto top;
		}
		r = *istack->p++;
	}else if(istack->b){
		if((c = Bgetrune(istack->b)) < 0){
			popinput();
			goto top;
		}
		r = c;
	}else{
		r = 0;
		sysfatal("getrune - can't happen");
	}
	if(r == '\n')
		istack->lineno++;	
	return r;
}
コード例 #2
0
ファイル: t18.c プロジェクト: 99years/plan9
/* terminate exactly as if input had ended */
void
r_ex(int argc, Rune **argv)
{
	USED(argc);
	USED(argv);
	
	while(popinput())
		;
}
コード例 #3
0
ファイル: plumber.c プロジェクト: 99years/plan9
void
parseerror(char *fmt, ...)
{
	char buf[512];
	va_list args;

	va_start(args, fmt);
	vseprint(buf, buf+sizeof buf, fmt, args);
	va_end(args);

	if(printerrors){
		printinputstack();
		fprint(2, "%s\n", buf);
	}
	do; while(popinput());
	lasterror = estrdup(buf);
	longjmp(parsejmp, 1);
}
コード例 #4
0
ファイル: roff.c プロジェクト: AustenConrad/plan-9
void
run(void)
{
	t1init();
	t2init();
	t3init();
	t4init();
	t5init();
	t6init();
	t7init();
	t8init();
	/* t9init(); t9.c */
	t10init();
	t11init();
	/* t12init(); t12.c */
	t13init();
	t14init();
	t15init();
	t16init();
	t17init();
	t18init();
	t19init();
	t20init();
	htmlinit();
	hideihtml();
	
	addreq(L("margin"), r_margin, 1);
	nr(L(".margin"), 1);
	nr(L(".paragraph"), 1);

	runinput();
	while(popinput())
		;
	dot = '.';
	if(verbose)
		fprint(2, "eof\n");
	runmacro1(L("eof"));
	closehtml();
}
コード例 #5
0
ファイル: rules.c プロジェクト: 99years/plan9
uchar*
morerules(uchar *text, int done)
{
	int n;
	Ruleset *rs;
	uchar *otext, *s, *endofrule;

	pushinput("<rules input>", -1, text);
	if(done)
		input->end = text+strlen((char*)text);
	else{
		/*
		 * Help user by sending any full rules to parser so any parse errors will
		 * occur on write rather than close. A heuristic will do: blank line ends rule.
		 */
		endofrule = nil;
		for(s=text; *s!='\0'; s++)
			if(*s=='\n' && *++s=='\n')
				endofrule = s+1;
		if(endofrule == nil)
			return text;
		input->end = endofrule;
	}
	for(n=0; rules[n]; n++)
		;
	while((rs=readruleset()) != nil){
		rules = erealloc(rules, (n+2)*sizeof(Ruleset*));
		rules[n++] = rs;
		rules[n] = nil;
	}
	otext =text;
	if(input == nil)
		text = (uchar*)estrdup("");
	else
		text = (uchar*)estrdup((char*)input->end);
	popinput();
	free(otext);
	return text;
}
コード例 #6
0
ファイル: except.c プロジェクト: muennich/rc3
extern void rc_raise(ecodes e) {
	if (e == eError && rc_pid != getpid())
		exit(1); /* child processes exit on an error/signal */
	for (; estack != NULL; estack = estack->prev)
		if (estack->e != e) {
			if (e == eBreak && estack->e != eArena && estack->e != eVarstack)
				rc_error("break outside of loop");
			else if (e == eReturn && estack->e == eError) /* can return from loops inside functions */
				rc_error("return outside of function");
			switch (estack->e) {
			default:
				break;
			case eVarstack:
				varrm(estack->data.name, TRUE);
				break;
			case eArena:
				restoreblock(estack->data.b);
				break;
			case eFifo:
				unlink(estack->data.name);
				break;
			case eFd:
				close(estack->data.fd);
				break;
			}
		} else {
			if (e == eError && !estack->interactive) {
				popinput();
			} else {
				Jbwrap *j = estack->data.jb;

				interactive = estack->interactive;
				estack = estack->prev;
				siglongjmp(j->j, 1);
			}
		}
	rc_exit(1); /* top of exception stack */
}
コード例 #7
0
ファイル: rules.c プロジェクト: 99years/plan9
Rule*
readrule(int *eof)
{
	Rule *rp;
	char *line, *p;
	char *word;

Top:
	line = getline();
	if(line == nil){
		/*
		 * if input is from string, and bytes remain (input->end is within string),
		 * morerules() will pop input and save remaining data.  otherwise pop
		 * the stack here, and if there's more input, keep reading.
		 */
		if((input!=nil && input->end==nil) && popinput())
			goto Top;
		*eof = 1;
		return nil;
	}
	input->lineno++;

	for(p=line; *p==' ' || *p=='\t'; p++)
		;
	if(*p=='\0' || *p=='#')	/* empty or comment line */
		return nil;

	if(include(p))
		goto Top;

	if(assignment(p))
		return nil;

	rp = emalloc(sizeof(Rule));

	/* object */
	for(word=p; *p!=' ' && *p!='\t'; p++)
		if(*p == '\0')
			parseerror("malformed rule");
	*p++ = '\0';
	rp->obj = lookup(word, objects);
	if(rp->obj < 0){
		if(strcmp(word, "kind") == 0)	/* backwards compatibility */
			rp->obj = OType;
		else
			parseerror("unknown object %s", word);
	}

	/* verb */
	while(*p==' ' || *p=='\t')
		p++;
	for(word=p; *p!=' ' && *p!='\t'; p++)
		if(*p == '\0')
			parseerror("malformed rule");
	*p++ = '\0';
	rp->verb = lookup(word, verbs);
	if(rp->verb < 0)
		parseerror("unknown verb %s", word);

	/* argument */
	while(*p==' ' || *p=='\t')
		p++;
	if(*p == '\0')
		parseerror("malformed rule");
	rp->arg = estrdup(p);

	parserule(rp);

	return rp;
}