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

📄 nreq.c

📁 操作系统源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *	nreq.c - cawf(1) processing of nroff requests *//* *	Copyright (c) 1991 Purdue University Research Foundation, *	West Lafayette, Indiana 47907.  All rights reserved. * *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue *	University Computing Center.  Not derived from licensed software; *	derived from awf(1) by Henry Spencer of the University of Toronto. * *	Permission is granted to anyone to use this software for any *	purpose on any computer system, and to alter it and redistribute *	it freely, subject to the following restrictions: * *	1. The author is not responsible for any consequences of use of *	   this software, even if they arise from flaws in it. * *	2. The origin of this software must not be misrepresented, either *	   by explicit claim or by omission.  Credits must appear in the *	   documentation. * *	3. Altered versions must be plainly marked as such, and must not *	   be misrepresented as being the original software.  Credits must *	   appear in the documentation. * *	4. This notice may not be removed or altered. */#include "cawf.h"#include <ctype.h>/* * Prototypes for request processing functions. */_PROTOTYPE(static void nr_UL,(unsigned char *line, int brk));_PROTOTYPE(static void nr_Ub,(unsigned char *line, int brk));_PROTOTYPE(static void nr_Uc,(unsigned char *line, int brk));_PROTOTYPE(static void nr_Uf,(unsigned char *line, int brk));_PROTOTYPE(static void nr_Ur,(unsigned char *line, int brk));_PROTOTYPE(static void nr_ad,(unsigned char *line, int brk));_PROTOTYPE(static void nr_bp,(unsigned char *line, int brk));_PROTOTYPE(static void nr_br,(unsigned char *line, int brk));_PROTOTYPE(static void nr_ce,(unsigned char *line, int brk));_PROTOTYPE(static void nr_di,(unsigned char *line, int brk));_PROTOTYPE(static void nr_ds,(unsigned char *line, int brk));_PROTOTYPE(static void nr_fi,(unsigned char *line, int brk));_PROTOTYPE(static void nr_fl,(unsigned char *line, int brk));_PROTOTYPE(static void nr_ft,(unsigned char *line, int brk));_PROTOTYPE(static void nr_it,(unsigned char *line, int brk));_PROTOTYPE(static void nr_na,(unsigned char *line, int brk));_PROTOTYPE(static void nr_nf,(unsigned char *line, int brk));_PROTOTYPE(static void nr_ns,(unsigned char *line, int brk));_PROTOTYPE(static void nr_rm,(unsigned char *line, int brk));_PROTOTYPE(static void nr_rn,(unsigned char *line, int brk));_PROTOTYPE(static void nr_rr,(unsigned char *line, int brk));_PROTOTYPE(static void nr_rs,(unsigned char *line, int brk));_PROTOTYPE(static void nr_tm,(unsigned char *line, int brk));_PROTOTYPE(static void nr_tr,(unsigned char *line, int brk));_PROTOTYPE(static void nr_nil,(unsigned char *line, int brk));/* * NrReqt[] - nroff request processing table * * CAUTION: place new entries in their proper alphabetical order, since *	    this table is processed with a binary search. */static struct nr_req {	char *nm;			/* nroff request */	void (*fun)();			/* processing function */} NrReqt[] = {	{ "\\\"",	nr_nil },	/* backslash-quote */	{ "^#",		nr_UL  },	{ "^=",		nr_UL  },	{ "^b",		nr_Ub  },	{ "^c",		nr_Uc  },	{ "^d",		nr_nil },	{ "^e",		nr_nil },	{ "^f",		nr_Uf  },	{ "^r",		nr_Ur  },	{ "^x",		nr_nil },	{ "ad",		nr_ad  },	{ "bp",		nr_bp  },	{ "br",		nr_br  },	{ "ce",		nr_ce  },	{ "di",		nr_di  },	{ "ds",		nr_ds  },	{ "fi",		nr_fi  },	{ "fl",		nr_fl  },	{ "ft",		nr_ft  },	{ "i0",		nr_nil },	{ "it",		nr_it  },	{ "lg",		nr_nil },	{ "li",		nr_nil },	{ "na",		nr_na  },	{ "nf",		nr_nf  },	{ "ns",		nr_ns  },	{ "ps",		nr_nil },	{ "rm",		nr_rm  },	{ "rn",		nr_rn  },	{ "rr",		nr_rr  },	{ "rs",		nr_rs  },	{ "tm",		nr_tm  },	{ "tr",		nr_tr  },	{ "vs",		nr_nil },};/* * Nreq(line, brk) - process miscellaneous nroff requests from line *		     buffer with request status of (brk) */voidNreq(line, brk)	unsigned char *line;	int brk;{	unsigned char c[3];		/* command buffer */	int cmp, hi, low, mid;		/* binary search indixes */	c[0] = c[1] = c[2] = '\0';	if ((c[0] = line[1]) != '\0')		c[1] = line[2];	low = mid = 0;	hi = sizeof(NrReqt) / sizeof(struct nr_req);	while (low <= hi) {		mid = (low + hi) / 2;		if ((cmp = strcmp((char *)c, NrReqt[mid].nm)) < 0)			hi = mid - 1;		else if (cmp > 0)			low = mid + 1;		else {			(void) (*NrReqt[mid].fun)(line, brk);			return;		}	}    /*     * Unknown request starting with a '.' or '\''..     */	Error(WARN, LINE, " unknown request", NULL);}/* * Adjust - "^[.']ad" */static voidnr_ad(line, brk)	unsigned char *line;	int brk;{	Pass3(NOBREAK, (unsigned char *)"both", NULL, 0);}/** Begin new page - "^[.']bp"*/static voidnr_bp(line, brk)	unsigned char *line;	int brk;{	Pass3(brk, (unsigned char *)"need", NULL, 999);}/** Break - "^[.']br"*/static voidnr_br(line, brk)	unsigned char *line;	int brk;{	Pass3(brk, (unsigned char *)"flush", NULL, 0);}/* * Center - "^[.']ce" */static voidnr_ce(line, brk)	unsigned char *line;	int brk;{	unsigned char *s;			/* string poiner */	if ((s = Field(2, line, 0)) != NULL)		Centering = atoi((char *)s);	else		Centering = 1;}/* * Diversion on and off - "^[.']di" */static voidnr_di(line, brk)	unsigned char *line;	int brk;{	Pass3(DOBREAK, (unsigned char *)"flush", NULL, 0);	Divert ^= 1;}/* * Define string - "^[.']ds" */static voidnr_ds(line, brk)	unsigned char *line;	int brk;{	unsigned char buf[MAXLINE];	/* temporary buffer */	unsigned char nm[4], nm1[4];	/* name buffers */	unsigned char *s1, *s2, *s3,	/* temporary string pointers */		       *s4;	if (Asmname(&line[3], nm) == 0) {		Error(WARN, LINE, " no name", NULL);		return;	}	s1 = Field(3, line, 0);	s2 = Findstr(nm, s1, 1);	while (*s2 == '\\' && *(s2 + 1) == '*') {		s2++;		s3 = Asmcode(&s2, nm1);		s2 = Findstr(nm1, NULL, 0);	}	if (Hdft) {	/*	 * Look for names LH, LF, CH, CF, RH, RF.	 */		if ((nm[0]=='L' || nm[0]=='C' || nm[0]=='R')		&&  (nm[1]=='F' || nm[1]=='H')) {			(void) sprintf((char *)buf, "%s", (char *)nm);			Pass3(NOBREAK, buf, s2, 0);		}	}}/* * Fill - "^[.']fi" */static voidnr_fi(line, brk)	unsigned char *line;	int brk;{	Fill = 1;	Pass3(brk, (unsigned char *)"flush", NULL, 0);}/* * Flush - "^[.']fl" */static voidnr_fl(line, brk)	unsigned char *line;	int brk;{	Pass3(brk, (unsigned char *)"flush", NULL, 0);}/* * Font - "^[.']ft <font_name>" */static voidnr_ft(line, brk)	unsigned char *line;	int brk;{	int i;				/* temporary index */	if (line[3] == '\0' || line[4] == '\0')		line[4] = 'P';	if (line[4] == 'P') {		Font[0] = Prevfont;		return;	}	for (i = 0; Fcode[i].nm; i++) {		if (Fcode[i].nm == line[4])		break;	}	if (Fcode[i].status == '\0') {		Error(WARN, LINE, " bad font code", NULL);		return;	}	Prevfont = Font[0];	Font[0] = line[4];}/* * Input trap - "^[.']it [1 <request>]" */static voidnr_it(line, brk)	unsigned char *line;	int brk;{	unsigned char buf[MAXLINE];	/* temporary buffer */	int i;				/* temporary index */	unsigned char *s1, *s2;		/* temporary string pointers */	if ((s1 = Field(2, line, 0)) == NULL) {		Free(&Aftnxt);		return;	}	if ((i = atoi((char *)s1)) != 1) {		Error(WARN, LINE, " first .it arg must be 1", NULL);		return;	}	if ((s2 = Field(3, line, 0)) == NULL)		Free(&Aftnxt);	else {		(void) sprintf((char *)buf, "%s,%s",			(Aftnxt == NULL) ? "" : (char *)Aftnxt,			(char *)s2);		Free(&Aftnxt);		Aftnxt = Newstr(buf);	}}/* * Comment - "^[.']\\" - do nothing * * Debug - "^[.']\^d" - do nothing * * Finalization - "[.']\^e" - do nothing * * Error file - "^[.']\^x <name>" - do nothing * * "^[.']i0", "^[.']lg" and "^[.']li" - do nothing * * Point size - "^[.']ps" - do nothing * * Vertical spacing - "^[.']vs" - do nothing * */static voidnr_nil(line, brk)	unsigned char *line;	int brk;{}/* * No adjust "^[.']na" */static voidnr_na(line, brk)	unsigned char *line;	int brk;{	Pass3(NOBREAK, (unsigned char *)"left", NULL, 0);}/* * No fill - "^[.']nf" */static voidnr_nf(line, brk)	unsigned char *line;	int brk;{	Fill = 0;	Pass3(brk, (unsigned char *)"flush", NULL, 0);}/* * No space - "^[.']ns" */static voidnr_ns(line, brk)	unsigned char *line;	int brk;{	Pass3(NOBREAK, (unsigned char *)"nospace", NULL, 0);}/* * Remove macro or string - "^[.']rm" */static voidnr_rm(line, brk)	unsigned char *line;	int brk;{	int i;				/* temporary index */	unsigned char nm[4];		/* name buffer */	if (Asmname(&line[3], nm) == 0) {		Error(WARN, LINE, " no name", NULL);		return;	}	if ((i = Findmacro(nm, 0)) >= 0) {		Delmacro(i);		return;			}	(void) Findstr(nm, NULL, 0);		if (Sx >= 0) {			Delstr(Sx);			return;

⌨️ 快捷键说明

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