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

📄 cpp.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 4 页
字号:
char *refill(p) register char *p; {/* dump buffer.  save chars from inp to p.  read into buffer at pbuf,/* contiguous with p.  update pointers, return new p.*/	register char *np,*op; register int ninbuf;	dump(); np=pbuf-(p-inp); op=inp;	if (bob(np+1)) {pperror("token too long"); np=pbeg; p=inp+BUFSIZ;}	macdam += np-inp; outp=inp=np;	while (op<p) *np++= *op++;	p=np;	for (;;) {		if (mactop>inctop[ifno]) {/* retrieve hunk of pushed-back macro text */			op=instack[--mactop]; np=pbuf;			do {while (*np++= *op++);} while (op<endbuf[mactop]); pend=np-1;			/* make buffer space avail for 'include' processing */			if (fretop<MAXFRE) bufstack[fretop++]=instack[mactop];			return(p);		} else {/* get more text from file(s) */			maclvl=0;			if (0<(ninbuf=read(fin,pbuf,BUFSIZ))) {				pend=pbuf+ninbuf; *pend='\0';				return(p);			}			/* end of #include file */			if (ifno==0) {/* end of input */				if (plvl!=0) {					int n=plvl,tlin=lineno[ifno]; char *tfil=fnames[ifno];					lineno[ifno]=maclin; fnames[ifno]=macfil;					pperror("%s: unterminated macro call",macnam);					lineno[ifno]=tlin; fnames[ifno]=tfil;					np=p; *np++='\n';	/* shut off unterminated quoted string */					while (--n>=0) *np++=')';	/* supply missing parens */					pend=np; *np='\0'; if (plvl<0) plvl=0;					return(p);				}				if (trulvl || flslvl)					if (incomment)						pperror("unterminated comment");					else						pperror("missing endif");				inp=p; dump(); exit(exfail);			}			close(fin); fin=fins[--ifno]; dirs[0]=dirnams[ifno]; sayline(BACK);		}	}}#define BEG 0#define LF 1char *cotoken(p) register char *p; {	register int c,i; char quoc;	static int state = BEG;	if (state!=BEG) goto prevlf;for (;;) {again:	while (!isspc(*p++));	switch (*(inp=p-1)) {	case 0: {		if (eob(--p)) {p=refill(p); goto again;}		else ++p; /* ignore null byte */	} break;	case '|': case '&': for (;;) {/* sloscan only */		if (*p++== *inp) break;		if (eob(--p)) p=refill(p);		else break;	} break;	case '=': case '!': for (;;) {/* sloscan only */		if (*p++=='=') break;		if (eob(--p)) p=refill(p);		else break;	} break;	case '<': case '>': for (;;) {/* sloscan only */		if (*p++=='=' || p[-2]==p[-1]) break;		if (eob(--p)) p=refill(p);		else break;	} break;	case '\\': for (;;) {		if (*p++=='\n') {++lineno[ifno]; break;}		if (eob(--p)) p=refill(p);		else {++p; break;}	} break;	case '/': 	  for (;;) {		if (*p=='/' && eolcom) {			p++;			incomment++;			if (!passcom) {inp=p-2; dump(); ++flslvl;}			for (;;) {				while (*p && *p++ != '\n');				if (p[-1]=='\n') {					p--;					goto endcpluscom;				} else if (eob(--p)) {					if(!passcom) {inp=p; p=refill(p);}					else if ((p-inp) >= BUFSIZ) {/* split long comment */						inp=p; refill(p);					} else p=refill(p);				} else p+=2; /* jlr012 ignore null byte */			}		endcpluscom:			if (!passcom) {outp=inp=p; --flslvl;}			incomment--;			goto prevlf; /* AR's "newline"->++lineno jlr009 */			break;		}		else if (*p++=='*') {	/* C style comment */			incomment++;			if (!passcom) {inp=p-2; dump(); ++flslvl;}			for (;;) {				while (!iscom(*p++));				if (p[-1]=='*') for (;;) {					if (*p++=='/') goto endcom;					if (eob(--p)) {						if (!passcom) {inp=p; p=refill(p);}						else if ((p-inp)>=BUFSIZ) {/* split long comment */							inp=p; p=refill(p);	/* last char written is '*' */							cputc('/',fout);	/* terminate first part */							/* 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);						cputc('*',fout); cputc('/',fout);						outp=inp=p-=2; *p++='/'; *p++='*';					} else p=refill(p);				} else ++p; /* ignore null byte */			}		endcom:			incomment--;			if (!passcom) {outp=inp=p; --flslvl; goto again;}			break;		}		if (eob(--p)) p=refill(p);		else break;	} break;	  /* 3-9-88 LFL */	  /* Handle pascal comments if appropriate */	case '(':	  if (*p != '*') break;	  /* else fallthrough */	case '{':	  if (!pascal_file) break;	  /* LFL 6-19-88 */	  if (flslvl) break;	/* Don't bother with comments after #if 0 */	  if (p[-1] == '{') --p;	  incomment++;	  if (!passcom) {	    *inp++=' ';		/* 8-4-88 LFL - Hack to handle const{}a=1; */	    dump();	    ++flslvl;	  }	  for (;;) {		/* Loop until out of comment */	    ++p;	    if eob(p) {	      if (!passcom)		inp = p;	      p = refill(p);	    }	    if (*p=='}')	      break;	    if (*p=='*') {	      if (eob(++p)) {		if (!passcom)		  inp = p;		p = refill(p);	      }	      if (*p==')')		break;	      else		--p;		/* Undo eob(++p) LFL 6-19-88 */	    }	    if (*p == '\n') {	      ++lineno[ifno];	      putc('\n',fout);	    }	  }	  if (eob(++p)) {	    if (!passcom) 	      inp = p;	    p = refill(p);	  }	  incomment--;	  if (!passcom) {	    outp=inp=p;	    flslvl--;	  }	  goto again;	  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': {/* newline: jlr009 -- not needed with fix to AR's code */		++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 (*(p-1) == '.') {                        if (*p == '.'){ p++; break;}                     }                                         }		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=malloc(BUFSIZ+1);		if (np==NULL) {pperror("no space"); exit(exfail);}		np[BUFSIZ]='\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; {	register int filok,inctype;	register char *cp; register char **dirp,*nfil; char filname[BUFSIZ];	p=skipbl(p); cp=filname;	if (*inp++=='<') {/* special <> syntax */		inctype=1;		++flslvl;	/* prevent macro expansion */		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++;		}		--flslvl;	/* reenable macro expansion */	} 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=malloc(BUFSIZ))==NULL) {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);free(nfil);}	else {		nfil=realloc(nfil,strlen(nfil)+1);		lineno[ifno]=1; fnames[ifno]=nfil;		dirnams[ifno]=dirs[0]=trmdir(copy(nfil));		sayline(START);		/* 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; register int flag;	c= *p2; *p2='\0';	flag=strcmp(a,p1); *p2=c; return(flag==SAME);}char *dopragma(p)   /* process '#pragma' */   char *p;

⌨️ 快捷键说明

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