⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 n3.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 2 页
字号:
	}	nextb = (Offset) i * BLK;	return nextb;}void ffree(Offset i)	/* free list of blocks starting at blist(o) */{			/* (doesn't actually free the blocks, just the pointers) */	int j;	for ( ; blist[j = bindex(i)].nextoff != -1; ) {		if (bfree > j)			bfree = j;		i = blist[j].nextoff;		blist[j].nextoff = 0;	}	blist[j].nextoff = 0;}void wbf(Tchar i)	/* store i into offset, get ready for next one */{	int j, off;	if (!offset)		return;	j = bindex(offset);	if (i == 0)		contabp[savslot].emx = offset;	off = boffset(offset);	blist[j].bp[off++] = i;	offset++;	if (pastend(offset)) {	/* off the end of this block */		if (blist[j].nextoff == -1) {			if ((nextb = alloc()) == -1) {				ERROR "Out of temp file space" WARN;				done2(01);			}			blist[j].nextoff = nextb;		}		offset = blist[j].nextoff;	}}Tchar rbf(void)	/* return next char from blist[] block */{	Tchar i, j;	if (ip == RD_OFFSET) {		/* for rdtty */		if (j = rdtty())			return(j);		else			return(popi());	}		i = rbf0(ip);	if (i == 0) {		if (!app)			i = popi();		return(i);	}	ip = incoff(ip);	return(i);}Offset xxxincoff(Offset p)		/* get next blist[] block */{	p++;	if (pastend(p)) {		/* off the end of this block */		if ((p = blist[bindex(p-1)].nextoff) == -1) {	/* and nothing was allocated after it */			ERROR "Bad storage allocation" WARN;			done2(-5);		}	}	return(p);}Tchar popi(void){	Stack *p;	if (frame == stk)		return(0);	if (strflg)		strflg--;	p = nxf = frame;	p->nargs = 0;	frame = p->pframe;	ip = p->pip;	pendt = p->ppendt;	lastpbp = p->lastpbp;	return(p->pch);}/* *	test that the end of the allocation is above a certain location *	in memory */#define SPACETEST(base, size) \	if ((char*)base + size >= (char*)stk+STACKSIZE) \		ERROR "Stacksize overflow in n3" WARNOffset pushi(Offset newip, int  mname){	Stack *p;	SPACETEST(nxf, sizeof(Stack));	p = nxf;	p->pframe = frame;	p->pip = ip;	p->ppendt = pendt;	p->pch = ch;	p->lastpbp = lastpbp;	p->mname = mname;	lastpbp = pbp;	pendt = ch = 0;	frame = nxf;	if (nxf->nargs == 0) 		nxf += 1;	else 		nxf = (Stack *)argtop;	return(ip = newip);}void *setbrk(int x){	char *i;	if ((i = (char *) calloc(x, 1)) == 0) {		ERROR "Core limit reached" WARN;		edone(0100);	}	return(i);}int getsn(void){	int i;	if ((i = getach()) == 0)		return(0);	if (i == '(')		return(getrq());	else 		return(i);}Offset setstr(void){	int i, j;	lgf++;	if ((i = getsn()) == 0 || (j = findmn(i)) == -1 || !contabp[j].mx) {		lgf--;		return(0);	} else {		SPACETEST(nxf, sizeof(Stack));		nxf->nargs = 0;		strflg++;		lgf--;		return pushi(contabp[j].mx, i);	}}void collect(void){	int j;	Tchar i, *strp, *lim, **argpp, **argppend;	int quote;	Stack *savnxf;	copyf++;	nxf->nargs = 0;	savnxf = nxf;	if (skip())		goto rtn;	{		char *memp;		memp = (char *)savnxf;		/*		 *	1 s structure for the macro descriptor		 *	APERMAC Tchar *'s for pointers into the strings		 *	space for the Tchar's themselves		 */		memp += sizeof(Stack);		/*		 *	CPERMAC = the total # of characters for ALL arguments		 */#define	CPERMAC	200#define	APERMAC	9		memp += APERMAC * sizeof(Tchar *);		memp += CPERMAC * sizeof(Tchar);		nxf = (Stack *)memp;	}	lim = (Tchar *)nxf;	argpp = (Tchar **)(savnxf + 1);	argppend = &argpp[APERMAC];	SPACETEST(argppend, sizeof(Tchar *));	strp = (Tchar *)argppend;	/*	 *	Zero out all the string pointers before filling them in.	 */	for (j = 0; j < APERMAC; j++)		argpp[j] = 0;	/* ERROR "savnxf=0x%x,nxf=0x%x,argpp=0x%x,strp=argppend=0x%x, lim=0x%x",	 * 	savnxf, nxf, argpp, strp, lim WARN;	 */	strflg = 0;	while (argpp != argppend && !skip()) {		*argpp++ = strp;		quote = 0;		if (cbits(i = getch()) == '"')			quote++;		else 			ch = i;		while (1) {			i = getch();/* fprintf(stderr, "collect %c %d\n", cbits(i), cbits(i)); */			if (nlflg || (!quote && argpp != argppend && cbits(i) == ' '))				break;	/* collects rest into $9 */			if (   quote			    && cbits(i) == '"'			    && cbits(i = getch()) != '"') {				ch = i;				break;			}			*strp++ = i;			if (strflg && strp >= lim) {				/* ERROR "strp=0x%x, lim = 0x%x", strp, lim WARN; */				ERROR "Macro argument too long" WARN;				copyf--;				edone(004);			}			SPACETEST(strp, 3 * sizeof(Tchar));		}		*strp++ = 0;	}	nxf = savnxf;	nxf->nargs = argpp - (Tchar **)(savnxf + 1);	argtop = strp;rtn:	copyf--;}void seta(void){	int i;	i = cbits(getch()) - '0';	if (i > 0 && i <= APERMAC && i <= frame->nargs)		pushback(*(((Tchar **)(frame + 1)) + i - 1));}void caseda(void){	app++;	casedi();}void casegd(void){	int i, j;	skip();	if ((i = getrq()) == 0)		return;	if ((j = findmn(i)) >= 0) {		if (contabp[j].divsiz != NULL) {			numtabp[DN].val = contabp[j].divsiz->dix;			numtabp[DL].val = contabp[j].divsiz->diy;		}	}}#define FINDDIV(o) if ((o =  findmn(dip->curd)) < 0) \			ERROR "lost diversion %s", unpair(dip->curd) WARNvoid casedi(void){	int i, j, *k;	lgf++;	if (skip() || (i = getrq()) == 0) {		if (dip != d) {			FINDDIV(savslot);			wbf((Tchar)0);		}		if (dilev > 0) {			numtabp[DN].val = dip->dnl;			numtabp[DL].val = dip->maxl;			FINDDIV(j);			if ((contabp[j].divsiz = (Divsiz *) malloc(sizeof(Divsiz))) == NULL) {				ERROR "Cannot alloc diversion size" WARN;				done2(1);			} else {				contabp[j].divsiz->dix = numtabp[DN].val;				contabp[j].divsiz->diy = numtabp[DL].val;			}			dip = &d[--dilev];			offset = dip->op;		}		goto rtn;	}	if (++dilev == NDI) {		--dilev;		ERROR "Diversions nested too deep" WARN;		edone(02);	}	if (dip != d) {		FINDDIV(j);		savslot = j;		wbf((Tchar)0);	}	diflg++;	dip = &d[dilev];	dip->op = finds(i);	dip->curd = i;	clrmn(oldmn);	k = (int *) & dip->dnl;	for (j = 0; j < 10; j++)		k[j] = 0;	/*not op and curd*/rtn:	app = 0;	diflg = 0;}void casedt(void){	lgf++;	dip->dimac = dip->ditrap = dip->ditf = 0;	skip();	dip->ditrap = vnumb((int *)0);	if (nonumb)		return;	skip();	dip->dimac = getrq();}#define LNSIZE 4000void casetl(void){	int j;	int w[3];	Tchar buf[LNSIZE];	Tchar *tp;	Tchar i, delim; 	/* 	 * bug fix 	 * 	 * if .tl is the first thing in the file, the p1 	 * doesn't come out, also the pagenumber will be 0 	 * 	 * tends too confuse the device filter (and the user as well) 	 */ 	if (dip == d && numtabp[NL].val == -1) 		newline(1);	dip->nls = 0;	skip();	if (ismot(delim = getch())) {		ch = delim;		delim = '\'';	} else 		delim = cbits(delim);	tp = buf;	numtabp[HP].val = 0;	w[0] = w[1] = w[2] = 0;	j = 0;	while (cbits(i = getch()) != '\n') {		if (cbits(i) == cbits(delim)) {			if (j < 3)				w[j] = numtabp[HP].val;			numtabp[HP].val = 0;			if (w[j] != 0)				*tp++ = WORDSP;			j++;			*tp++ = 0;		} else {			if (cbits(i) == pagech) {				setn1(numtabp[PN].val, numtabp[findr('%')].fmt,				      i&SFMASK);				continue;			}			numtabp[HP].val += width(i);			if (tp < &buf[LNSIZE-10]) {				if (cbits(i) == ' ' && *tp != WORDSP)					*tp++ = WORDSP;				*tp++ = i;			} else {				ERROR "Overflow in casetl" WARN;			}		}	}	if (j<3)		w[j] = numtabp[HP].val;	*tp++ = 0;	*tp++ = 0;	*tp = 0;	tp = buf;	if (NROFF)		horiz(po);	while (i = *tp++)		pchar(i);	if (w[1] || w[2])		horiz(j = quant((lt - w[1]) / 2 - w[0], HOR));	while (i = *tp++)		pchar(i);	if (w[2]) {		horiz(lt - w[0] - w[1] - w[2] - j);		while (i = *tp++)			pchar(i);	}	newline(0);	if (dip != d) {		if (dip->dnl > dip->hnl)			dip->hnl = dip->dnl;	} else {		if (numtabp[NL].val > dip->hnl)			dip->hnl = numtabp[NL].val;	}}void casepc(void){	pagech = chget(IMP);}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);}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");	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -