prs.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 1,249 行 · 第 1/2 页

C
1,249
字号
					printf("yes");				else printf("no");				break;			case 256*'B'+'F':	/* :FB: Floor Boundry */				if (k = Sflags[FLORFLAG - 'a'])					printf("%s",k);				else printf("none");				break;			case 256*'B'+'C':	/* :CB: Ceiling Boundry */				if (k = Sflags[CEILFLAG - 'a'])					printf("%s",k);				else printf("none");				break;			case 256*'s'+'D':	/* :Ds: Default SID */				if (k = Sflags[DEFTFLAG - 'a'])					printf("%s",k);				else printf("none");				break;			case 256*'D'+'N':	/* :ND: Null delta */				if (Sflags[NULLFLAG - 'a'])					printf("yes");				else printf("no");				break;			case 256*'D'+'F':	/* :FD: File descriptive text */				if (exists(uttmp))					printfile(uttmp);				break;			case 256*'D'+'B':	/* :BD: Entire file body */				if (exists(bdtmp))					printfile(bdtmp);				break;			case 256*'B'+'G':	/* :GB: Gotten body from 'get' */				getbody(&dtp->d_sid,&gpkt);				break;			case 256*'N'+'P':	/* :PN: Full pathname of File */				copy(gpkt.p_file,Dir);				dname(Dir);				if(curdir(Olddir) != 0)					fatal("curdir failed (prs2)");				if(chdir(Dir) != 0)					fatal("cannot change directory (prs3)");				if(curdir(Pname) != 0)					fatal("curdir failed (prs2)");				if(chdir(Olddir) != 0)					fatal("cannot change directory (prs3)");				printf("%s/",Pname);				printf("%s",sname(gpkt.p_file));				break;			case 256*'L'+'F':	/* :FL: Flag descriptions (as in 'prt') */				printflags();				break;			case 256*'t'+'D':	/* :Dt: Whole delta table line */				/*				replace newline with null char to make				data keyword simple format				*/				repl(dt_line,'\n','\0');				k = dt_line;				/*				skip control char, line flag, and blank				*/				k += 3;				printf("%s",k);				break;			default:				putchar(':');				lp -= 2;				continue;			}			lp++;		}		else {			c = *lp;			if (c == '\\') {				switch(*++lp) {				case 'n':	/* for newline */					putchar('\n');					break;				case ':':	/* for wanted colon */					putchar(':');					break;				case 't':	/* for tab */					putchar('\t');					break;				case 'b':	/* for backspace */					putchar('\b');					break;				case 'r':	/* for carriage return */					putchar('\r');					break;				case 'f':	/* for form feed */					putchar('\f');					break;				case '\\':	/* for backslash */					putchar('\\');					break;				case '\'':	/* for single quote */					putchar('\'');					break;				default:	/* unknown case */					putchar('\\');					putchar(*lp);					break;				}			}			else putchar(*lp);		}	}	/*	zero out first char of global string lines in case	a value is not gotten in next delta table entry	*/	iline[0] = xline[0] = gline[0] = 0;	putchar('\n');	return;}/* * This procedure cleans up all temporary files created during * 'process' that are used for data keyword substitution*/clean_up(){	if (gpkt.p_iop)		/* if SCCS file is open, close it */		fclose(gpkt.p_iop);	xrm(&gpkt);	      /* remove the 'packet' used for this SCCS file */	unlink(mrtmp);		/* remove all temporary files from /tmp */	unlink(cmtmp);		/*			"		*/	unlink(untmp);		/*			"		*/	unlink(uttmp);		/*			"		*/	unlink(bdtmp);		/*			"		*/}/* This function takes as it's argument the SID inputed and determines * whether or not it is valid (e. g. not ambiguous or illegal).*/invalid(i_sid)register char	*i_sid;{	register int count;	register int digits;	count = digits = 0;	if (*i_sid == '0' || *i_sid == '.')		return (1);	i_sid++;	digits++;	while (*i_sid != '\0') {		if (*i_sid++ == '.') {			digits = 0;			count++;			if (*i_sid == '0' || *i_sid == '.')				return (1);		}		digits++;		if (digits > 5)			return (1);	}	if (*(--i_sid) == '.' )		return (1);	if (count == 1 || count == 3)		return (0);	return (1);}/* * This procedure checks the delta table entries for correct format. * It also checks to see if the SID specified by the -r keyletter * is contained in the file.  If no SID was specified assumes the top * delta created (last in time).*/deltblchk(pkt)register struct packet *pkt;{	char	*n;	int	have;	int	found;	struct	deltab	dt;	struct	stats	stats;	have = found = 0;	/*	Read entire delta table.	*/	while (getstats(pkt,&stats)) {		if (getadel(pkt,&dt) != BDELTAB)			fmterr(pkt);		/*		if no SID was specified, get top delta		*/		if (pkt->p_reqsid.s_rel == 0 && !have) {			/*			ignore if "removed" delta 			*/			if (!HADA && dt.d_type != 'D') {				read_to(EDELTAB,pkt);				continue;			}			/*			move current SID into SID to look at			*/			gpkt.p_reqsid = dt.d_sid;			found = have = 1;		}		/*		if SID was specified but not located yet check		to see if this SID is the one		*/		if (pkt->p_reqsid.s_rel != 0 && !found)			if (eqsid(&gpkt.p_reqsid, &dt.d_sid))				found = 1;		/*		Read rest of delta entry. 		*/		while ((n = getline(pkt)) != NULL)			if (pkt->p_line[0] != CTLCHAR)				break;			else {				switch (pkt->p_line[1]) {				case EDELTAB:					break;				case INCLUDE:				case EXCLUDE:				case IGNORE:				case MRNUM:				case COMMENTS:					continue;				default:					fmterr(pkt);				}				break;			}		if (n == NULL || pkt->p_line[0] != CTLCHAR)			fmterr(pkt);	}	/*	if not at the beginning of the User Name section	there is an internal error	*/	if (pkt->p_line[1] != BUSERNAM)		fmterr(pkt);	/*	if SID did not exist (the one specified by -r keyletter)	then there exists an error	*/	if (!found)		fatal("nonexistent SID (prs1)");}/* * This procedure reads the stats line from the delta table entry * and places the statisitics into a structure called "stats".*/getstats(pkt,statp)register struct packet *pkt;register struct stats *statp;{	register char *p;	p = pkt->p_line;	if (getline(pkt) == NULL || *p++ != CTLCHAR || *p++ != STATS)		return(0);	NONBLANK(p);	p = satoi(p,&statp->s_ins);	p = satoi(++p,&statp->s_del);	satoi(++p,&statp->s_unc);	return(1);}/* * This procedure reads a delta table entry line from the delta * table entry and places the contents of the line into a structure * called "deltab".*/getadel(pkt,dt)register struct packet *pkt;register struct deltab *dt;{	if (getline(pkt) == NULL)		fmterr(pkt);	copy(pkt->p_line,dt_line);  /* copy delta table line for :Dt: keywd */	return(del_ab(pkt->p_line,dt,pkt));}FILE *fdfopen();/* * This procedure creates the temporary file used during the * "process" subroutine.  The skeleton defined at the beginning * of the program is filled in in this function*/FILE	*maket(file)char	*file;{	FILE *iop;	char *mktemp();	copy(tempskel,file);	/* copy file name into the skeleton */	iop = xfcreat(mktemp(file),0644);	return(iop);}/* * This procedure prints (on the standard output) the contents of any___ * temporary file that may have been created during "process".*/printfile(file)register	char	*file;{	register	char	*p;	FILE	*iop;	iop = xfopen(file,0);	while ((p = fgets(line,sizeof(line),iop)) != NULL)		printf("%s",p);	fclose(iop);}/* * This procedure reads the body of the SCCS file from beginning to end. * It also creates the temporary file /tmp/prbdtmp____________ which contains * the body of the SCCS file for data keyword substitution.*/read_mod(pkt)register struct packet *pkt;{	register char *p;	int ser;	int iod;	register struct apply *ap;	int level = 0;	if (HAD_BD)		BDiop = maket(bdtmp);	while (getline(pkt) != NULL) {		p = pkt->p_line;		if (HAD_BD)			fputs(p,BDiop);		if (*p++ != CTLCHAR)			continue;		else {			if (!((iod = *p++) == INS || iod == DEL || iod == END))				fmterr(pkt);			NONBLANK(p);			satoi(p,&ser);/* * The logic here is really wrong. Best I can tell, pkt->p_apply can never * be anything but NULL in prs. No routine ever sets it. It appears * that the only intent of the code was to check that INS and DEL commands * were matched with an equal amount of END commands. So we'll do that * instead. *			if (iod == END) *				remq(pkt,ser); *			else if ((ap = &pkt->p_apply[ser])->a_code == APPLY) *				addq(pkt,ser,iod == INS ? YES : NO,iod,ap->a_reason & USER); *			else *				addq(pkt,ser,iod == INS ? NO : NULL,iod,ap->a_reason & USER); */			if (iod == END) {				if (--level < 0)					fmterr(pkt);			} else				level++;		}	}	if (HAD_BD)		fclose(BDiop);	if (level != 0)		fatal("premature eof (co5)");	return(0);}/* * This procedure is only called if the :GB: data keyword is specified. * It forks and creates a child process to invoke 'get' with the '-p' * and '-s' options for the SID currently being processed.  Upon * completion, control of the program is returned to 'prs'.*/getbody(gsid,pkt)struct	sid	*gsid;struct packet *pkt;{	int	i;	int	status;	extern	char	Getpgm[];	char	str[128];	char	rarg[20];	char	filearg[80];	sid_ba(gsid,str);	sprintf(rarg,"-r%s",str);	sprintf(filearg,"%s",pkt->p_file);	/*	fork here so 'getbody' can execute 'get' to	print out gotten body :GB:	*/	if ((i = fork()) < 0)		fatal("cannot fork, try again");	if (i == 0) {		/*		perform 'get' and redirect output		to standard output		*/		execlp(Getpgm,Getpgm,"-s","-p",rarg,filearg,0);		sprintf(Error,"cannot execute '%s'",Getpgm);		fatal(Error);	}	else {		wait(&status);		return;	}}/* * This procedure places the line read in "dodeltbl" into a global string * 'str'.  This procedure is only called for include, exclude or ignore * lines.*/getit(str,cp)register	char	*str, *cp;{	cp += 2;	NONBLANK(cp);	cp[length(cp) - 1] = '\0';	sprintf(str,"%s",cp);}/* * This procedure creates an auxiliary file for the iop passed as an argument * for the file name also passed as an argument.  If no text exists for the * named file, an auxiliary file is still created with the text "(none)".*/aux_create(iop,file,delchar)FILE	*iop;char	*file;char	delchar;{	char	*n;	int	text;	/*	create auxiliary file for the named section	*/	text = 0;	iop = maket(file);	while ((n = getline(&gpkt)) != NULL && gpkt.p_line[0] != CTLCHAR) {		text = 1;		fputs(n,iop);	}	/*	check to see that delimiter found is correct	*/	if (n == NULL || gpkt.p_line[0] != CTLCHAR || gpkt.p_line[1] != delchar)		fmterr(&gpkt);	if (!text)		fprintf(iop,"(none)\n");	fclose(iop);}/* * This procedure sets the values for certain data keywords which are * either shared by more than one data keyword or because substitution * here would be easier than doing it in "scanspec" (more efficient etc.)*/idsetup(gsid,pkt,bdate)struct	sid	*gsid;struct	packet	*pkt;long	*bdate;{	register	char	*p;	extern	struct	tm	*localtime();	char *auxf(), *date_ba();	/***  There doesn't seem to be a comparable routine in Ultrix	sccs_tzset();	 ***  and it also doesn't appear to be needed -- depp */	date_ba(bdate,Deltadate);	Deltatime = &Deltadate[9];	Deltadate[8] = 0;	sid_ba(gsid,Sid);	Dtime = localtime(bdate);	if (p = Sflags[MODFLAG - 'a'])		copy(p,Mod);	else sprintf(Mod,"%s",auxf(pkt->p_file,'g'));	if (!(Type = Sflags[TYPEFLAG - 'a']))		Type = Null;	if (!(Qsect = Sflags[QSECTFLAG - 'a']))		Qsect = Null;}/* * This procedure places any MRs that are found in the delta table entry * into the temporary file created for that express purpose (/tmp/prmrtmp____________).*/putmr(cp)register char	*cp;{	cp += 3;	if (!(*cp) || (*cp == '\n')) {/* 1/25/88 - DAL		fclose(MRiop);		unlink(mrtmp);*/		return;	}	fputs(cp,MRiop);}/* * This procedure is the same as "putmr" except it is used for the comment * section of the delta table entries.*/putcom(cp)register char	*cp;{	cp += 3;	fputs(cp,CMiop);}/* * This procedure reads through the SCCS file until a line is found * containing the character passed as an argument in the 2nd__ position * of the line.*/read_to(ch,pkt)register char	ch;register struct packet *pkt;{	register char *p;	while ((p = getline(pkt)) &&			!(*p++ == CTLCHAR && *p == ch))		;	return;}/* * This procedure prints a list of all the flags that are present in the * SCCS file.  The format is the same as 'prt' except the flag description * is _n_o_t preceeded by a "tab".*/printflags(){	register	char	*k;	if (Sflags[BRCHFLAG - 'a'])	/* check for 'branch' flag */		printf("branch\n");	if ((k = (Sflags[CEILFLAG - 'a'])))	/* check for 'ceiling flag */		printf("ceiling\t%s\n",k);	if ((k = (Sflags[DEFTFLAG - 'a'])))  /* check for 'default SID' flag */		printf("default SID\t%s\n",k);	if ((k = (Sflags[FLORFLAG - 'a'])))	/* check for 'floor' flag */		printf("floor\t%s\n",k);	if (Sflags[IDFLAG - 'a'])	/* check for 'id err/warn' flag */		printf("id keywd err/warn\n");	if (Sflags[JOINTFLAG - 'a'])	/* check for joint edit flag */		printf("joint edit\n");	if ((k = (Sflags[LOCKFLAG - 'a'])))	/* check for 'lock' flag */		printf("locked releases\t%s\n",k);	if ((k = (Sflags[MODFLAG - 'a'])))	/* check for 'module' flag */		printf("module\t%s\n",k);	if (Sflags[NULLFLAG - 'a'])	/* check for 'null delta' flag */		printf("null delta\n");	if ((k = (Sflags[QSECTFLAG - 'a'])))	/* check for 'qsect' flag */		printf("csect name\t%s\n",k);	if ((k = (Sflags[TYPEFLAG - 'a'])))	/* check for 'type' flag */		printf("type\t%s\n",k);	if (Sflags[VALFLAG - 'a']) {	/* check for 'MR valid' flag */		printf("validate MRs\t");		/*		check for MR validating program		(optional)		*/		if (k = (Sflags[VALFLAG - 'a']))			printf("%s\n",k);		else putchar('\n');	}	return;}/* * This procedure checks the `dataspec' (if user defined) and determines * if any temporary files need be created for future keyword replacement*/ck_spec(p)register char *p;{	if (libPW_index(p,":C:") != -1)	/* check for Comment keyword */		HAD_CM = 1;	if (libPW_index(p,":MR:") != -1)/* check for MR keyword */		HAD_MR = 1;	if (libPW_index(p,":UN:") != -1)/* check for User name keyword */		HAD_UN = 1;	if (libPW_index(p,":FD:") != -1)/* check for descriptive text kyword */		HAD_FD = 1;	if (libPW_index(p,":BD:") != -1)/* check for body keyword */		HAD_BD = 1;}

⌨️ 快捷键说明

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