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

📄 cpp.c

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻 C
📖 第 1 页 / 共 3 页
字号:
	/* copy to avoid running off end of world when param list is at end */	p=buf; while (*p++= *s++);	p=buf; while (isid(*p++)); /* skip first identifier */	if (*--p=='=') {*p++=' '; while (*p++);}	else {s=" 1"; while (*p++= *s++);}	pend=p; *--p='\n';	sloscan(); dodef(buf); return(lastsym);}struct symtab *ppsym(s) char *s; {/* kluge */	register struct symtab *sp;	cinit=SALT; *savch++=SALT; sp=stsym(s); --sp->name; cinit=0; return(sp);}/* VARARGS1 */pperror(s,x,y) char *s; {	if (fnames[ifno][0]) fprintf(stderr,# if gcos			"*%c*   \"%s\", line ", exfail >= 0 ? 'F' : 'W',# else			"%s: ",# endif				 fnames[ifno]);	fprintf(stderr, "%d: ",lineno[ifno]);	fprintf(stderr, s, x, y);	fprintf(stderr,"\n");	++exfail;}yyerror(s,a,b) char *s; {	pperror(s,a,b);}ppwarn(s,x) char *s; {	int fail = exfail;	exfail = -1;	pperror(s,x);	exfail = fail;}struct symtab *lookup(namep, enterf)char *namep;{	register char *np, *snp;	register int c, i; int around;	register struct symtab *sp;	/* namep had better not be too long (currently, <=8 chars) */	np=namep; around=0; i=cinit;	while (c= *np++) i += i+c; c=i;	/* c=i for register usage on pdp11 */	c %= symsiz; if (c<0) c += symsiz;	sp = &stab[c];	while (snp=sp->name) {		np = namep;		while (*snp++ == *np) if (*np++ == '\0') {				if (enterf==DROP) {sp->name[0]= DROP; sp->value=0;}				return(lastsym=sp);			}		if (--sp < &stab[0])			if (around) {pperror("too many defines", 0); exit(exfail);}			else {++around; sp = &stab[symsiz-1];}	}	if (enterf>0) sp->name=namep;	return(lastsym=sp);}struct symtab *slookup(p1,p2,enterf) register char *p1,*p2; int enterf;{	register char *p3; char c2,c3; struct symtab *np;	         c2= *p2; *p2='\0';	/* mark end of token */	if ((p2-p1)>8) p3=p1+8; else p3=p2;			 c3= *p3; *p3='\0';	/* truncate to 8 chars or less */	if (enterf==1) p1=copy(p1);	np=lookup(p1,enterf); *p3=c3; *p2=c2;	if (np->value!=0 && flslvl==0) newp=subst(p2,np);	else newp=0;	return(np);}char *subst(p,sp) register char *p; struct symtab *sp; {	static char match[]="%s: argument mismatch";	register char *ca,*vp; int params;	char *actual[MAXFRM]; /* actual[n] is text of nth actual */	char acttxt[BUFSIZ]; /* space for actuals */	if (0==(vp=sp->value)) return(p);	if ((p-macforw)<=macdam) {		if (++maclvl>symsiz && !rflag) {			pperror("%s: macro recursion",sp->name); return(p);		}	} else maclvl=0;	/* level decreased */	macforw=p; macdam=0;	/* new target for decrease in level */	macnam=sp->name;	dump();	if (sp==ulnloc) {		vp=acttxt; *vp++='\0';		sprintf(vp,"%d",lineno[ifno]); while (*vp++);	} else if (sp==uflloc) {		vp=acttxt; *vp++='\0';		sprintf(vp,"\"%s\"",fnames[ifno]); while (*vp++);	}	if (0!=(params= *--vp&0xFF)) {/* definition calls for params */		register char **pa;		ca=acttxt; pa=actual;		if (params==0xFF) params=1;	/* #define foo() ... */		sloscan(); ++flslvl; /* no expansion during search for actuals */		plvl= -1;		do p=skipbl(p); while (*inp=='\n');	/* skip \n too */		if (*inp=='(') {			maclin=lineno[ifno]; macfil=fnames[ifno];			for (plvl=1; plvl!=0; ) {				*ca++='\0';				for (;;) {					outp=inp=p; p=cotoken(p);					if (*inp=='(') ++plvl;					if (*inp==')' && --plvl==0) {--params; break;}					if (plvl==1 && *inp==',') {--params; break;}					while (inp<p) *ca++= *inp++;					if (ca> &acttxt[BUFSIZ])						pperror("%s: actuals too long",sp->name);				}				if (pa>= &actual[MAXFRM]) ppwarn(match,sp->name);				else *pa++=ca;			}		}		if (params!=0) ppwarn(match,sp->name);		while (--params>=0) *pa++=""+1;	/* null string for missing actuals */		--flslvl; fasscan();	}	for (;;) {/* push definition onto front of input stack */		while (!iswarn(*--vp)) {			if (bob(p)) {outp=inp=p; p=unfill(p);}			*--p= *vp;		}		if (*vp==warnc) {/* insert actual param */			ca=actual[*--vp-1];			while (*--ca) {				if (bob(p)) {outp=inp=p; p=unfill(p);}				*--p= *ca;			}		} else break;	}	outp=inp=p;	return(p);}char *trmdir(s) register char *s; {	register char *p = s;	while (*p++); --p; while (p>s && *--p!='/');# if unix	if (p==s) *p++='.';# endif	*p='\0';	return(s);}STATIC char *copy(s) register char *s; {	register char *old;	old = savch; while (*savch++ = *s++);	return(old);}char *strdex(s,c) char *s,c; {	while (*s) if (*s++==c) return(--s);	return(0);}yywrap(){ return(1); }main(argc,argv)	char *argv[];{	register int i,c;	register char *p;	char *tf,**cp2;# if gcos	if (setjmp(env)) return (exfail);# endif	p="_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";		i=0;		while (c= *p++) {			(fastab+COFF)[c] |= IB|NB|SB; (toktyp+COFF)[c]=IDENT;#if scw2			/* 53 == 63-10; digits rarely appear in identifiers,			/* and can never be the first char of an identifier.			/* 11 == 53*53/sizeof(macbit) .			*/			++i; (t21+COFF)[c]=(53*i)/11; (t22+COFF)[c]=i%11;#endif		}	p="0123456789.";		while (c= *p++) {(fastab+COFF)[c] |= NB|SB; (toktyp+COFF)[c]=NUMBR;}# if gcos	p="\n\"'`/\\";# else	p="\n\"'/\\";# endif		while (c= *p++) (fastab+COFF)[c] |= SB;# if gcos	p="\n\"'`\\";# else	p="\n\"'\\";# endif		while (c= *p++) (fastab+COFF)[c] |= QB;	p="*\n"; while (c= *p++) (fastab+COFF)[c] |= CB;	(fastab+COFF)[warnc] |= WB;	(fastab+COFF)['\0'] |= CB|QB|SB|WB;	for (i=ALFSIZ; --i>=0; ) slotab[i]=fastab[i]|SB;	p=" \t\013\f\r";	/* note no \n;	\v not legal for vertical tab? */		while (c= *p++) (toktyp+COFF)[c]=BLANK;#if scw2	for ((t23+COFF)[i=ALFSIZ+7-COFF]=1; --i>=-COFF; )		if (((t23+COFF)[i]=(t23+COFF+1)[i]<<1)==0) (t23+COFF)[i]=1;#endif# if unix	fnames[ifno=0] = "";# endif# if ibm	fnames[ifno=0] = "";# endif# if gcos	if (inquire(stdin, _TTY)) freopen("*src", "rt", stdin);# endif# if gimpel || gcos	fnames[ifno=0] = (char *)inquire(stdin, _FILENAME);	dirnams[0] = dirs[0] = trmdir(copy(fnames[0]));# endif	for(i=1; i<argc; i++)		{		switch(argv[i][0])			{			case '-':# if gcos			switch(toupper(argv[i][1])) { /* case-independent on GCOS */# else			switch(argv[i][1]) {# endif				case 'P': pflag++;				case 'E': continue;				case 'R': ++rflag; continue;				case 'C': passcom++; continue;				case 'D':					if (predef>prespc+NPREDEF) {						pperror("too many -D options, ignoring %s",argv[i]);						continue;					}					/* ignore plain "-D" (no argument) */					if (*(argv[i]+2)) *predef++ = argv[i]+2;					continue;				case 'U':					if (prund>punspc+NPREDEF) {						pperror("too many -U options, ignoring %s",argv[i]);						continue;					}					*prund++ = argv[i]+2;					continue;				case 'I':					if (nd>8) pperror("excessive -I file (%s) ignored",argv[i]);					else dirs[nd++] = argv[i]+2;					continue;				case '\0': continue;				default: 					pperror("unknown flag %s", argv[i]);					continue;				}			default:				if (fin==STDIN) {					if (0>(fin=open(argv[i], READ))) {						pperror("No source file %s",argv[i]); exit(8);					}					fnames[ifno]=copy(argv[i]);					dirs[0]=dirnams[ifno]=trmdir(argv[i]);# ifndef gcos/* too dangerous to have file name in same syntactic position   be input or output file depending on file redirections,   so force output to stdout, willy-nilly	[i don't see what the problem is.  jfr]*/				} else if (fout==stdout) {					extern char _sobuf[BUFSIZ];					if (NULL==(fout=fopen(argv[i], "w"))) {						pperror("Can't create %s", argv[i]); exit(8);					} else {fclose(stdout); setbuf(fout,_sobuf);}# endif				} else pperror("extraneous name %s", argv[i]);			}		}	fins[ifno]=fin;	exfail = 0;		/* after user -I files here are the standard include libraries */# if unix	dirs[nd++] = "/usr/include";# endif# if gcos	dirs[nd++] = "cc/include";# endif# if ibm# ifndef gimpel	dirs[nd++] = "BTL$CLIB";# endif# endif# ifdef gimpel	dirs[nd++] = intss() ?  "SYS3.C." : "" ;# endif	/* dirs[nd++] = "/compool"; */	dirs[nd++] = 0;	defloc=ppsym("define");	udfloc=ppsym("undef");	incloc=ppsym("include");	elsloc=ppsym("else");	eifloc=ppsym("endif");	ifdloc=ppsym("ifdef");	ifnloc=ppsym("ifndef");	ifloc=ppsym("if");	lneloc=ppsym("line");	for (i=sizeof(macbit)/sizeof(macbit[0]); --i>=0; ) macbit[i]=0;# if unix	ysysloc=stsym("unix");# endif# if gcos	ysysloc=stsym ("gcos");# endif# if ibm	ysysloc=stsym ("ibm");# endif# if pdp11	varloc=stsym("pdp11");# endif# if vax	varloc=stsym("vax");# endif# if interdata	varloc=stsym ("interdata");# endif# if tss	varloc=stsym ("tss");# endif# if os	varloc=stsym ("os");# endif# if mert	varloc=stsym ("mert");# endif	ulnloc=stsym ("__LINE__");	uflloc=stsym ("__FILE__");	tf=fnames[ifno]; fnames[ifno]="command line"; lineno[ifno]=1;	cp2=prespc;	while (cp2<predef) stsym(*cp2++);	cp2=punspc;	while (cp2<prund) {		if (p=strdex(*cp2, '=')) *p++='\0';		lookup(*cp2++, DROP);	}	fnames[ifno]=tf;	pbeg=buffer+8; pbuf=pbeg+BUFSIZ; pend=pbuf+BUFSIZ;	trulvl = 0; flslvl = 0;	lineno[0] = 1; sayline();	outp=inp=pend;	control(pend);	return (exfail);}

⌨️ 快捷键说明

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