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

📄 cpp.c

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻 C
📖 第 1 页 / 共 3 页
字号:
							/* and fake start of 2nd */							outp=inp=p-=3; *p++='/'; *p++='*'; *p++='*';						} else p=refill(p);					} else break;				} else if (p[-1]=='\n') {					++lineno[ifno]; if (!passcom) putc('\n',fout);				} else if (eob(--p)) {					if (!passcom) {inp=p; p=refill(p);}					else if ((p-inp)>=BUFSIZ) {/* split long comment */						inp=p; p=refill(p);						putc('*',fout); putc('/',fout);						outp=inp=p-=2; *p++='/'; *p++='*';					} else p=refill(p);				} else ++p; /* ignore null byte */			}		endcom:			if (!passcom) {outp=inp=p; --flslvl; goto again;}			break;		}		if (eob(--p)) p=refill(p);		else break;	} break;# if gcos	case '`':# endif	case '"': case '\'': {		quoc=p[-1];		for (;;) {			while (!isquo(*p++));			if (p[-1]==quoc) break;			if (p[-1]=='\n') {--p; break;} /* bare \n terminates quotation */			if (p[-1]=='\\') for (;;) {				if (*p++=='\n') {++lineno[ifno]; break;} /* escaped \n ignored */				if (eob(--p)) p=refill(p);				else {++p; break;}			} else if (eob(--p)) p=refill(p);			else ++p;	/* it was a different quote character */		}	} break;	case '\n': {		++lineno[ifno]; if (isslo) {state=LF; return(p);}prevlf:		state=BEG;		for (;;) {			if (*p++=='#') return(p);			if (eob(inp= --p)) p=refill(p);			else goto again;		}	} break;	case '0': case '1': case '2': case '3': case '4':	case '5': case '6': case '7': case '8': case '9':	for (;;) {		while (isnum(*p++));		if (eob(--p)) p=refill(p);		else break;	} break;	case 'A': case 'B': case 'C': case 'D': case 'E':	case 'F': case 'G': case 'H': case 'I': case 'J':	case 'K': case 'L': case 'M': case 'N': case 'O':	case 'P': case 'Q': case 'R': case 'S': case 'T':	case 'U': case 'V': case 'W': case 'X': case 'Y':	case 'Z': case '_':	case 'a': case 'b': case 'c': case 'd': case 'e':	case 'f': case 'g': case 'h': case 'i': case 'j':	case 'k': case 'l': case 'm': case 'n': case 'o':	case 'p': case 'q': case 'r': case 's': case 't':	case 'u': case 'v': case 'w': case 'x': case 'y':	case 'z':#if scw1#define tmac1(c,bit) if (!xmac1(c,bit,&)) goto nomac#define xmac1(c,bit,op) ((macbit+COFF)[c] op (bit))#else#define tmac1(c,bit)#define xmac1(c,bit,op)#endif#if scw2#define tmac2(c0,c1,cpos) if (!xmac2(c0,c1,cpos,&)) goto nomac#define xmac2(c0,c1,cpos,op)\	((macbit+COFF)[(t21+COFF)[c0]+(t22+COFF)[c1]] op (t23+COFF+cpos)[c0])#else#define tmac2(c0,c1,cpos)#define xmac2(c0,c1,cpos,op)#endif	if (flslvl) goto nomac;	for (;;) {		c= p[-1];                          tmac1(c,b0);		i= *p++; if (!isid(i)) goto endid; tmac1(i,b1); tmac2(c,i,0);		c= *p++; if (!isid(c)) goto endid; tmac1(c,b2); tmac2(i,c,1);		i= *p++; if (!isid(i)) goto endid; tmac1(i,b3); tmac2(c,i,2);		c= *p++; if (!isid(c)) goto endid; tmac1(c,b4); tmac2(i,c,3);		i= *p++; if (!isid(i)) goto endid; tmac1(i,b5); tmac2(c,i,4);		c= *p++; if (!isid(c)) goto endid; tmac1(c,b6); tmac2(i,c,5);		i= *p++; if (!isid(i)) goto endid; tmac1(i,b7); tmac2(c,i,6);		                                                tmac2(i,0,7);		while (isid(*p++));		if (eob(--p)) {refill(p); p=inp+1; continue;}		goto lokid;	endid:		if (eob(--p)) {refill(p); p=inp+1; continue;}		tmac2(p[-1],0,-1+(p-inp));	lokid:		slookup(inp,p,0); if (newp) {p=newp; goto again;}		else break;	nomac:		while (isid(*p++));		if (eob(--p)) {p=refill(p); goto nomac;}		else break;	} break;	} /* end of switch */		if (isslo) return(p);} /* end of infinite loop */}char *skipbl(p) register char *p; {/* get next non-blank token */	do {outp=inp=p; p=cotoken(p);} while ((toktyp+COFF)[*inp]==BLANK);	return(p);}char *unfill(p) register char *p; {/* take <= BUFSIZ chars from right end of buffer and put them on instack ./* slide rest of buffer to the right, update pointers, return new p.*/	register char *np,*op; register int d;	if (mactop>=MAXFRE) {		pperror("%s: too much pushback",macnam);		p=inp=pend; dump();	/* begin flushing pushback */		while (mactop>inctop[ifno]) {p=refill(p); p=inp=pend; dump();}	}	if (fretop>0) np=bufstack[--fretop];	else {		np=savch; savch+=BUFSIZ;		if (savch>=sbf+SBSIZE) {pperror("no space"); exit(exfail);}		*savch++='\0';	}	instack[mactop]=np; op=pend-BUFSIZ; if (op<p) op=p;	for (;;) {while (*np++= *op++); if (eob(op)) break;} /* out with old */	endbuf[mactop++]=np;	/* mark end of saved text */	np=pbuf+BUFSIZ; op=pend-BUFSIZ; pend=np; if (op<p) op=p;	while (outp<op) *--np= *--op; /* slide over new */	if (bob(np)) pperror("token too long");	d=np-outp; outp+=d; inp+=d; macdam+=d; return(p+d);}char *doincl(p) register char *p; {	int filok,inctype;	register char *cp; char **dirp,*nfil; char filname[BUFSIZ];	p=skipbl(p); cp=filname;	if (*inp++=='<') {/* special <> syntax */		inctype=1;		for (;;) {			outp=inp=p; p=cotoken(p);			if (*inp=='\n') {--p; *cp='\0'; break;}			if (*inp=='>') {      *cp='\0'; break;}# ifdef gimpel			if (*inp=='.' && !intss()) *inp='#';# endif			while (inp<p) *cp++= *inp++;		}	} else if (inp[-1]=='"') {/* regular "" syntax */		inctype=0;# ifdef gimpel		while (inp<p) {if (*inp=='.' && !intss()) *inp='#'; *cp++= *inp++;}# else		while (inp<p) *cp++= *inp++;# endif		if (*--cp=='"') *cp='\0';	} else {pperror("bad include syntax",0); inctype=2;}	/* flush current file to \n , then write \n */	++flslvl; do {outp=inp=p; p=cotoken(p);} while (*inp!='\n'); --flslvl;	inp=p; dump(); if (inctype==2) return(p);	/* look for included file */	if (ifno+1 >=MAXINC) {		pperror("Unreasonable include nesting",0); return(p);	}	if((nfil=savch)>sbf+SBSIZE-BUFSIZ) {pperror("no space"); exit(exfail);}	filok=0;	for (dirp=dirs+inctype; *dirp; ++dirp) {		if (# if gcos			strdex(filname, '/')# else			filname[0]=='/' # endif				|| **dirp=='\0') strcpy(nfil,filname);		else {			strcpy(nfil,*dirp);# if unix || gcos			strcat(nfil,"/");# endif#ifdef ibm#ifndef gimpel			strcat(nfil,".");#endif#endif			strcat(nfil,filname);		}		if (0<(fins[ifno+1]=open(nfil,READ))) {			filok=1; fin=fins[++ifno]; break;		}	}	if (filok==0) pperror("Can't find include file %s",filname);	else {		lineno[ifno]=1; fnames[ifno]=cp=nfil; while (*cp++); savch=cp;		dirnams[ifno]=dirs[0]=trmdir(copy(nfil));		sayline();		/* save current contents of buffer */		while (!eob(p)) p=unfill(p);		inctop[ifno]=mactop;	}	return(p);}equfrm(a,p1,p2) register char *a,*p1,*p2; {	register char c; int flag;	c= *p2; *p2='\0';	flag=strcmp(a,p1); *p2=c; return(flag==SAME);}char *dodef(p) char *p; {/* process '#define' */	register char *pin,*psav,*cf;	char **pf,**qf; int b,c,params; struct symtab *np;	char *oldval,*oldsavch;	char *formal[MAXFRM]; /* formal[n] is name of nth formal */	char formtxt[BUFSIZ]; /* space for formal names */	if (savch>sbf+SBSIZE-BUFSIZ) {pperror("too much defining"); return(p);}	oldsavch=savch; /* to reclaim space if redefinition */	++flslvl; /* prevent macro expansion during 'define' */	p=skipbl(p); pin=inp;	if ((toktyp+COFF)[*pin]!=IDENT) {		ppwarn("illegal macro name"); while (*inp!='\n') p=skipbl(p); return(p);	}	np=slookup(pin,p,1);	if (oldval=np->value) savch=oldsavch;	/* was previously defined */	b=1; cf=pin;	while (cf<p) {/* update macbit */		c= *cf++; xmac1(c,b,|=); b=(b+b)&0xFF;		if (cf!=p) xmac2(c,*cf,-1+(cf-pin),|=);		else xmac2(c,0,-1+(cf-pin),|=);	}	params=0; outp=inp=p; p=cotoken(p); pin=inp;	if (*pin=='(') {/* with parameters; identify the formals */		cf=formtxt; pf=formal;		for (;;) {			p=skipbl(p); pin=inp;			if (*pin=='\n') {				--lineno[ifno]; --p; pperror("%s: missing )",np->name); break;			}			if (*pin==')') break;			if (*pin==',') continue;			if ((toktyp+COFF)[*pin]!=IDENT) {				c= *p; *p='\0'; pperror("bad formal: %s",pin); *p=c;			} else if (pf>= &formal[MAXFRM]) {				c= *p; *p='\0'; pperror("too many formals: %s",pin); *p=c;			} else {				*pf++=cf; while (pin<p) *cf++= *pin++; *cf++='\0'; ++params;			}		}		if (params==0) --params; /* #define foo() ... */	} else if (*pin=='\n') {--lineno[ifno]; --p;}	/* remember beginning of macro body, so that we can	/* warn if a redefinition is different from old value.	*/	oldsavch=psav=savch;	for (;;) {/* accumulate definition until linefeed */		outp=inp=p; p=cotoken(p); pin=inp;		if (*pin=='\\' && pin[1]=='\n') continue;	/* ignore escaped lf */		if (*pin=='\n') break;		if (params) {/* mark the appearance of formals in the definiton */			if ((toktyp+COFF)[*pin]==IDENT) {				for (qf=pf; --qf>=formal; ) {					if (equfrm(*qf,pin,p)) {						*psav++=qf-formal+1; *psav++=WARN; pin=p; break;					}				}			} else if (*pin=='"' || *pin=='\''# if gcos					|| *pin=='`'# endif						) {/* inside quotation marks, too */				char quoc= *pin;				for (*psav++= *pin++; pin<p && *pin!=quoc; ) {					while (pin<p && !isid(*pin)) *psav++= *pin++;					cf=pin; while (cf<p && isid(*cf)) ++cf;					for (qf=pf; --qf>=formal; ) {						if (equfrm(*qf,pin,cf)) {							*psav++=qf-formal+1; *psav++=WARN; pin=cf; break;						}					}					while (pin<cf) *psav++= *pin++;				}			}		}		while (pin<p) *psav++= *pin++;	}	*psav++=params; *psav++='\0';	if ((cf=oldval)!=NULL) {/* redefinition */		--cf;	/* skip no. of params, which may be zero */		while (*--cf);	/* go back to the beginning */		if (0!=strcmp(++cf,oldsavch)) {/* redefinition different from old */			--lineno[ifno]; ppwarn("%s redefined",np->name); ++lineno[ifno];			np->value=psav-1;		} else psav=oldsavch; /* identical redef.; reclaim space */	} else np->value=psav-1;	--flslvl; inp=pin; savch=psav; return(p);}#define fasscan() ptrtab=fastab+COFF#define sloscan() ptrtab=slotab+COFFchar *control(p) register char *p; {/* find and handle preprocessor control lines */	register struct symtab *np;for (;;) {	fasscan(); p=cotoken(p); if (*inp=='\n') ++inp; dump();	sloscan(); p=skipbl(p);	*--inp=SALT; outp=inp; ++flslvl; np=slookup(inp,p,0); --flslvl;	if (np==defloc) {/* define */		if (flslvl==0) {p=dodef(p); continue;}	} else if (np==incloc) {/* include */		if (flslvl==0) {p=doincl(p); continue;}	} else if (np==ifnloc) {/* ifndef */		++flslvl; p=skipbl(p); np=slookup(inp,p,0); --flslvl;		if (flslvl==0 && np->value==0) ++trulvl;		else ++flslvl;	} else if (np==ifdloc) {/* ifdef */		++flslvl; p=skipbl(p); np=slookup(inp,p,0); --flslvl;		if (flslvl==0 && np->value!=0) ++trulvl;		else ++flslvl;	} else if (np==eifloc) {/* endif */		if (flslvl) {if (--flslvl==0) sayline();}		else if (trulvl) --trulvl;		else pperror("If-less endif",0);	} else if (np==elsloc) {/* else */		if (flslvl) {			if (--flslvl!=0) ++flslvl;			else {++trulvl; sayline();}		}		else if (trulvl) {++flslvl; --trulvl;}		else pperror("If-less else",0);	} else if (np==udfloc) {/* undefine */		if (flslvl==0) {			++flslvl; p=skipbl(p); slookup(inp,p,DROP); --flslvl;		}	} else if (np==ifloc) {/* if */#if tgp		pperror(" IF not implemented, true assumed", 0);		if (flslvl==0) ++trulvl; else ++flslvl;#else		newp=p;		if (flslvl==0 && yyparse()) ++trulvl; else ++flslvl;		p=newp;#endif	} else if (np==lneloc) {/* line */		if (flslvl==0 && pflag==0) {			outp=inp=p; *--outp='#'; while (*inp!='\n') p=cotoken(p);			continue;		}	} else if (*++inp=='\n') outp=inp;	/* allows blank line after # */	else pperror("undefined control",0);	/* flush to lf */	++flslvl; while (*inp!='\n') {outp=inp=p; p=cotoken(p);} --flslvl;}}struct symtab *stsym(s) register char *s; {	char buf[BUFSIZ]; register char *p;	/* make definition look exactly like end of #define line */

⌨️ 快捷键说明

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