示例#1
0
文件: n1.c 项目: 99years/plan9
int control(int a, int b)
{
	int j, k;
	extern Contab *contabp;

	numerr.type = RQERR;
	numerr.req = a;
	if (a == 0 || (j = findmn(a)) == -1)
		return(0);
	if (contabp[j].f == 0) {
		if (trace & TRMAC)
			fprintf(stderr, "invoke macro %s\n", unpair(a));
		if (dip != d)
			for (k = dilev; k; k--)
				if (d[k].curd == a) {
					ERROR "diversion %s invokes itself during diversion",
								unpair(a) WARN;
					edone(0100);
				}
		nxf->nargs = 0;
		if (b)
			collect();
		flushi();
		return pushi(contabp[j].mx, a);	/* BUG??? all that matters is 0/!0 */
	}
	if (b) {
		if (trace & TRREQ)
			fprintf(stderr, "invoke request %s\n", unpair(a));
		 (*contabp[j].f)();
	}
	return(0);
}
示例#2
0
文件: n3.c 项目: AustenConrad/plan-9
void stackdump(void)	/* dumps stack of macros in process */
{
	Stack *p;

	if (frame != stk) {
		fprintf(stderr, "stack: ");
		for (p = frame; p != stk; p = p->pframe)
			fprintf(stderr, "%s ", unpair(p->mname));
		fprintf(stderr, "\n");
	}
}
示例#3
0
文件: n4.c 项目: aahud/harvey
void prnumtab(Numtab *p)
{
	int i;
	for (i = 0; i < ncnt; i++)
		if (p)
			if (p[i].r != 0)
				fprintf(stderr, "slot %d, %s, val %d\n", i, unpair(p[i].r), p[i].val);
			else
				fprintf(stderr, "slot %d empty\n", i);
		else
			fprintf(stderr, "slot %d empty\n", i);
}
示例#4
0
文件: n3.c 项目: AustenConrad/plan-9
void prcontab(Contab *p)
{
	int i;
	for (i = 0; i < nm; i++)
		if (p)
			if (p[i].rq != 0)
				fprintf(stderr, "slot %d, %-2.2s\n", i, unpair(p[i].rq));
			else
				fprintf(stderr, "slot %d empty\n", i);
		else
			fprintf(stderr, "slot %d empty\n", i);
}
示例#5
0
文件: n4.c 项目: aahud/harvey
/*
 * print error about illegal numeric argument;
 */
void prnumerr(void)
{
	char err_buf[40];
	static char warn[] = "Numeric argument expected";
	int savcd = numtabp[CD].val;

	if (numerr.type == RQERR)
		sprintf(err_buf, "%c%s: %s", nb ? cbits(c2) : cbits(cc),
						unpair(numerr.req), warn);
	else
		sprintf(err_buf, "\\%c'%s': %s", numerr.esc, &numerr.escarg,
									warn);
	if (frame != stk)	/* uncertainty correction */
		numtabp[CD].val--;
	ERROR err_buf WARN;
	numtabp[CD].val = savcd;
}
示例#6
0
文件: n3.c 项目: AustenConrad/plan-9
void caserm(void)
{
	int j;
	int k = 0;

	lgf++;
g0:
	while (!skip() && (j = getrq()) != 0) {
		if (dip != d)
			for (k = dilev; k; k--)
				if (d[k].curd == j) {
					ERROR "cannot remove diversion %s during definition",
								unpair(j) WARN;
					goto g0;
				}
		clrmn(findmn(j));
	}
	lgf--;
}
示例#7
0
文件: n3.c 项目: AustenConrad/plan-9
void casepm(void)
{
	int i, k;
	int xx, cnt, tcnt, kk, tot;
	Offset j;

	kk = cnt = tcnt = 0;
	tot = !skip();
	stackdump();
	for (i = 0; i < nm; i++) {
		if ((xx = contabp[i].rq) == 0 || contabp[i].mx == 0)
			continue;
		tcnt++;
		j = contabp[i].mx;
		for (k = 1; (j = blist[bindex(j)].nextoff) != -1; )
			k++; 
		cnt++;
		kk += k;
		if (!tot)
			fprintf(stderr, "%-2.2s %d\n", unpair(xx), k);
	}
	fprintf(stderr, "pm: total %d, macros %d, space %d\n", tcnt, cnt, kk);
}
示例#8
0
文件: n4.c 项目: aahud/harvey
void setn(void)
{
	int i, j, f;
	Tchar ii;
	Uchar *p;
	char buf[NTM];		/* for \n(.S */

	f = nform = 0;
	if ((i = cbits(ii = getach())) == '+')
		f = 1;
	else if (i == '-')
		f = -1;
	else if (ii)	/* don't put it back if it's already back (thanks to jaap) */
		ch = ii;
	if (falsef)
		f = 0;
	if ((i = getsn()) == 0)
		return;
	p = unpair(i);
	if (p[0] == '.')
		switch (p[1]) {
		case 's':
			i = pts;
			break;
		case 'v':
			i = lss;
			break;
		case 'f':
			i = font;
			break;
		case 'p':
			i = pl;
			break;
		case 't':
			i = findt1();
			break;
		case 'o':
			i = po;
			break;
		case 'l':
			i = ll;
			break;
		case 'i':
			i = in;
			break;
		case '$':
			i = frame->nargs;
			break;
		case 'A':
			i = ascii;
			break;
		case 'c':
			i = numtabp[CD].val;
			break;
		case 'n':
			i = lastl;
			break;
		case 'a':
			i = ralss;
			break;
		case 'h':
			i = dip->hnl;
			break;
		case 'd':
			if (dip != d)
				i = dip->dnl;
			else
				i = numtabp[NL].val;
			break;
		case 'u':
			i = fi;
			break;
		case 'j':
			i = ad + 2 * admod;
			break;
		case 'w':
			i = widthp;
			break;
		case 'x':
			i = nel;
			break;
		case 'y':
			i = un;
			break;
		case 'T':
			i = dotT;
			break;	 /* -Tterm used in nroff */
		case 'V':
			i = VERT;
			break;
		case 'H':
			i = HOR;
			break;
		case 'k':
			i = ne;
			break;
		case 'P':
			i = print;
			break;
		case 'L':
			i = ls;
			break;
		case 'R':	/* maximal # of regs that can be addressed */
			i = 255*256 - regcnt; 
			break;
		case 'z':
			p = unpair(dip->curd);
			*pbp++ = p[1];	/* watch order */
			*pbp++ = p[0];
			return;
		case 'b':
			i = bdtab[font];
			break;
		case 'F':
			cpushback(cfname[ifi]);
			return;
 		case 'S':
 			buf[0] = j = 0;	
 			for( i = 0; tabtab[i] != 0 && i < NTAB; i++) {
 				if (i > 0)
 					buf[j++] = ' ';
 				sprintf(&buf[j], "%d", tabtab[i] & TABMASK);
 				j = strlen(buf);
 				if ( tabtab[i] & RTAB)
 					sprintf(&buf[j], "uR");
 				else if (tabtab[i] & CTAB)
 					sprintf(&buf[j], "uC");
 				else
 					sprintf(&buf[j], "uL");
 				j += 2;
 			}
 			cpushback(buf);
 			return;
		default:
			goto s0;
		}
	else {
s0:
		if ((j = findr(i)) == -1)
			i = 0;
		else {
			i = numtabp[j].val = numtabp[j].val + numtabp[j].inc * f;
			nform = numtabp[j].fmt;
		}
	}
	setn1(i, nform, (Tchar) 0);
}
示例#9
0
文件: n3.c 项目: AustenConrad/plan-9
int copyb(void)
{
	int i, j, state;
	Tchar ii;
	int req, k;
	Offset savoff;
	Uchar *p;

	if (skip() || !(j = getrq()))
		j = '.';
	req = j;
	p = unpair(j);
	/* was: k = j >> BYTE; j &= BYTEMASK; */
	j = p[0];
	k = p[1];
	copyf++;
	flushi();
	nlflg = 0;
	state = 1;

/* state 0	eat up
 * state 1	look for .
 * state 2	look for first char of end macro
 * state 3	look for second char of end macro
 */

	while (1) {
		i = cbits(ii = getch());
		if (state == 3) {
			if (i == k)
				break;
			if (!k) {
				ch = ii;
				i = getach();
				ch = ii;
				if (!i)
					break;
			}
			state = 0;
			goto c0;
		}
		if (i == '\n') {
			state = 1;
			nlflg = 0;
			goto c0;
		}
		if (state == 1 && i == '.') {
			state++;
			savoff = offset;
			goto c0;
		}
		if (state == 2 && i == j) {
			state++;
			goto c0;
		}
		state = 0;
c0:
		if (offset)
			wbf(ii);
	}
	if (offset) {
		offset = savoff;
		wbf((Tchar)0);
	}
	copyf--;
	return(req);
}