12149Seric # include "../hdr/defines.h"
22149Seric # include "../hdr/had.h"
32149Seric 
4*33423Sbostic static char Sccsid[] = "@(#)prt.c	4.3	02/02/88";
52149Seric 
62149Seric /*
72149Seric 	Program to print parts or all of an SCCS file.
82149Seric 	Arguments to the program may appear in any order
92149Seric 	and consist of keyletters, which begin with '-',
102149Seric 	and named files.
112149Seric 
122149Seric 	If a direcory is given as an argument, each
132149Seric 	SCCS file within the directory is processed as if
142149Seric 	it had been specifically named. If a name of '-'
152149Seric 	is given, the standard input is read for a list
162149Seric 	of names of SCCS files to be processed.
172149Seric 	Non-SCCS files are ignored.
182149Seric */
192149Seric 
202149Seric # define NOEOF	0
212149Seric # define BLANK(p)	while (!(*p == ' ' || *p == '\t')) p++;
222149Seric 
232149Seric char had[26];
242149Seric FILE *iptr;
252149Seric char line[512];
262149Seric char statistics[25];
272149Seric struct delent {
282149Seric 	char type;
292149Seric 	char *osid;
302149Seric 	char *datetime;
312149Seric 	char *pgmr;
322149Seric 	char *serial;
332149Seric 	char *pred;
342149Seric } del;
352149Seric int num_files;
362149Seric int prefix;
372149Seric long cutoff;
382149Seric long revcut;
392149Seric int linenum;
402149Seric char *ysid;
4130498Slepreau char *flagdesc[26] = {	"",
422149Seric 			"branch",
432149Seric 			"ceiling",
442149Seric 			"default SID",
452149Seric 			"",
462149Seric 			"floor",
472149Seric 			"",
482149Seric 			"",
492149Seric 			"id keywd err/warn",
502149Seric 			"",
512149Seric 			"",
522149Seric 			"",
532149Seric 			"module",
542149Seric 			"null delta",
552149Seric 			"",
562149Seric 			"",
572149Seric 			"",
582149Seric 			"",
592149Seric 			"",
602149Seric 			"type",
612149Seric 			"",
622149Seric 			"validate MRs",
632149Seric 			"",
642149Seric 			"",
652149Seric 			"",
662149Seric 			""
672149Seric };
682149Seric 
main(argc,argv)692149Seric main(argc,argv)
702149Seric int argc;
712149Seric char *argv[];
722149Seric {
732149Seric 	register int j;
742149Seric 	register char *p;
752149Seric 	char c;
762149Seric 	int testklt;
772149Seric 	extern prt();
782149Seric 	extern int Fcnt;
792149Seric 
802149Seric 	/*
812149Seric 	Set flags for 'fatal' to issue message, call clean-up
822149Seric 	routine, and terminate processing.
832149Seric 	*/
842149Seric 	Fflags = FTLMSG | FTLCLN | FTLEXIT;
852149Seric 
862149Seric 	testklt = 1;
872149Seric 
882149Seric 	/*
892149Seric 	The following loop processes keyletters and arguments.
902149Seric 	Note that these are processed only once for each
912149Seric 	invocation of 'main'.
922149Seric 	*/
932149Seric 	for (j = 1; j < argc; j++)
942149Seric 		if (argv[j][0] == '-' && (c = argv[j][1])) {
952149Seric 			p = &argv[j][2];
962149Seric 			switch (c) {
972149Seric 			case 'e':	/* print everything but body */
982149Seric 			case 's':	/* print only delta desc. and stats */
992149Seric 			case 'd':	/* print whole delta table */
1002149Seric 			case 'a':	/* print all deltas */
1012149Seric 			case 'i':	/* print inc, exc, and ignore info */
1022149Seric 			case 'u':	/* print users allowed to do deltas */
1032149Seric 			case 'f':	/* print flags */
1042149Seric 			case 't':	/* print descriptive user-text */
1052149Seric 			case 'b':	/* print body */
1062149Seric 				break;
1072149Seric 
1082149Seric 			case 'y':	/* delta cutoff */
1092149Seric 				ysid = p;
1102149Seric 				prefix++;
1112149Seric 				break;
1122149Seric 
1132149Seric 			case 'c':	/* time cutoff */
1142149Seric 				if (*p && date_ab(p,&cutoff))
1152149Seric 					fatal("bad date/time (cm5)");
1162149Seric 				prefix++;
1172149Seric 				break;
1182149Seric 
1192149Seric 			case 'r':	/* reverse time cutoff */
1202149Seric 				if (*p && date_ab(p,&revcut))
1212149Seric 					fatal ("bad date/time (cm5)");
1222149Seric 				prefix++;
1232149Seric 				break;
1242149Seric 
1252149Seric 			default:
1262149Seric 				fatal("unknown key letter (cm1)");
1272149Seric 			}
1282149Seric 
1292149Seric 			if (had[c - 'a']++ && testklt++)
1302149Seric 				fatal("key letter twice (cm2)");
1312149Seric 			argv[j] = 0;
1322149Seric 		}
1332149Seric 		else
1342149Seric 			num_files++;
1352149Seric 
1362149Seric 	if (num_files == 0)
1372149Seric 		fatal("missing file arg (cm3)");
1382149Seric 
1392149Seric 	if (HADC && HADR)
1402149Seric 		fatal("both 'c' and 'r' keyletters specified (pr2)");
1412149Seric 
1422149Seric 	setsig();
1432149Seric 
1442149Seric 	/*
1452149Seric 	Change flags for 'fatal' so that it will return to this
1462149Seric 	routine (main) instead of terminating processing.
1472149Seric 	*/
14830498Slepreau 	Fflags &= ~FTLEXIT;
14930498Slepreau 	Fflags |= FTLJMP;
1502149Seric 
1512149Seric 	/*
1522149Seric 	Call 'prt' routine for each file argument.
1532149Seric 	*/
1542149Seric 	for (j = 1; j < argc; j++)
1552149Seric 		if (p = argv[j])
1562149Seric 			do_file(p,prt);
1572149Seric 
1582149Seric 	exit(Fcnt ? 1 : 0);
1592149Seric }
1602149Seric 
1612149Seric 
1622149Seric /*
1632149Seric 	Routine that actually performs the 'prt' functions.
1642149Seric */
1652149Seric 
prt(file)1662149Seric prt(file)
1672149Seric char *file;
1682149Seric {
1692149Seric 	int stopdel;
1702149Seric 	int user, flag, text;
1712149Seric 	char *p;
1722149Seric 	long bindate;
1732149Seric 
1742149Seric 	if (setjmp(Fjmp))	/* set up to return here from 'fatal' */
1752149Seric 		return;		/* and return to caller of prt */
1762149Seric 
1772149Seric 	if (HADE)
1782149Seric 		HADD = HADI = HADU = HADF = HADT = 1;
1792149Seric 
1802149Seric 	if (!HADU && !HADF && !HADT && !HADB)
1812149Seric 		HADD = 1;
1822149Seric 
1832149Seric 	if (!HADD)
1842149Seric 		HADR = HADS = HADA = HADI = HADY = HADC = 0;
1852149Seric 
1862149Seric 	if (HADS && HADI)
1872149Seric 		fatal("s and i conflict (pr1)");
1882149Seric 
1892149Seric 	iptr = xfopen(file,0);
1902149Seric 
1912149Seric 	p = lineread(NOEOF);
1922149Seric 	if (*p++ != CTLCHAR || *p != HEAD)
1932149Seric 		fatal("not an sccs file (co2)");
1942149Seric 
1952149Seric 	stopdel = 0;
1962149Seric 
1972149Seric 	if (!prefix)
1982149Seric 		printf("\n%s:\n",file);
1992149Seric 
2002149Seric 	if (HADD) {
2012149Seric 		while ((p = lineread(NOEOF)) && *p++ == CTLCHAR &&
2022149Seric 				*p++ == STATS && !stopdel) {
2032149Seric 			NONBLANK(p);
2042149Seric 			copy(p,statistics);
2052149Seric 
2062149Seric 			p = lineread(NOEOF);
2072149Seric 			getdel(&del,p);
2082149Seric 
2092149Seric 			if (!HADA && del.type != 'D') {
2102149Seric 				read_to(EDELTAB);
2112149Seric 				continue;
2122149Seric 			}
2132149Seric 			if (HADC) {
2142149Seric 				date_ab(del.datetime,&bindate);
2152149Seric 				if (bindate < cutoff) {
2162149Seric 					stopdel = 1;
2172149Seric 					break;
2182149Seric 				}
2192149Seric 			}
2202149Seric 			if (HADR) {
2212149Seric 				date_ab(del.datetime,&bindate);
2222149Seric 				if (bindate >= revcut) {
2232149Seric 					read_to(EDELTAB);
2242149Seric 					continue;
2252149Seric 				}
2262149Seric 			}
2272149Seric 			if (HADY && (equal(del.osid,ysid) || !(*ysid)))
2282149Seric 				stopdel = 1;
2292149Seric 
2302149Seric 			printdel(file,&del);
2312149Seric 
2322149Seric 			while ((p = lineread(NOEOF)) && *p++ == CTLCHAR) {
2332149Seric 				if (*p == EDELTAB)
2342149Seric 					break;
2352149Seric 				switch (*p) {
2362149Seric 				case INCLUDE:
2372149Seric 					if (HADI)
2382149Seric 						printit(file,"Included:\t",p);
2392149Seric 					break;
2402149Seric 
2412149Seric 				case EXCLUDE:
2422149Seric 					if (HADI)
2432149Seric 						printit(file,"Excluded:\t",p);
2442149Seric 					break;
2452149Seric 
2462149Seric 				case IGNORE:
2472149Seric 					if (HADI)
2482149Seric 						printit(file,"Ignored:\t",p);
2492149Seric 					break;
2502149Seric 
2512149Seric 				case MRNUM:
2522149Seric 					if (!HADS)
2532149Seric 						printit(file,"MRs:\t",p);
2542149Seric 					break;
2552149Seric 
2562149Seric 				case COMMENTS:
2572149Seric 					if (!HADS)
2582149Seric 						printit(file,"",p);
2592149Seric 					break;
2602149Seric 
2612149Seric 				default:
262*33423Sbostic 					sprintf(Error, "format error at line %d (co4)",linenum);
263*33423Sbostic 					fatal(Error);
2642149Seric 				}
2652149Seric 			}
2662149Seric 		}
2672149Seric 		if (prefix)
2682149Seric 			printf("\n");
2692149Seric 
2702149Seric 		if (stopdel && !(line[0] == CTLCHAR && line[1] == BUSERNAM))
2712149Seric 			read_to(BUSERNAM);
2722149Seric 	}
2732149Seric 	else
2742149Seric 		read_to(BUSERNAM);
2752149Seric 
2762149Seric 	if (HADU) {
2772149Seric 		user = 0;
2782149Seric 		printf("\nUsers allowed to make deltas --\n");
2792149Seric 		while ((p = lineread(NOEOF)) && *p != CTLCHAR) {
2802149Seric 			user = 1;
2812149Seric 			printf("\t%s",p);
2822149Seric 		}
2832149Seric 		if (!user)
2842149Seric 			printf("\teveryone\n");
2852149Seric 	}
2862149Seric 	else
2872149Seric 		read_to(EUSERNAM);
2882149Seric 
2892149Seric 	if (HADF) {
2902149Seric 		flag = 0;
2912149Seric 		printf("\nFlags --\n");
2922149Seric 		while ((p = lineread(NOEOF)) && *p++ == CTLCHAR &&
2932149Seric 				*p++ == FLAG) {
2942149Seric 			flag = 1;
2952149Seric 			NONBLANK(p);
2962149Seric 			printf("\t%s",flagdesc[*p - 'a']);
2972149Seric 
2982149Seric 			if (*++p) {
2992149Seric 				NONBLANK(p);
3002149Seric 				printf("\t%s",p);
3012149Seric 			}
3022149Seric 		}
3032149Seric 		if (!flag)
3042149Seric 			printf("\tnone\n");
3052149Seric 	}
3062149Seric 	else
3072149Seric 		read_to(BUSERTXT);
3082149Seric 
3092149Seric 	if (HADT) {
3102149Seric 		text = 0;
3112149Seric 		printf("\nDescription --\n");
3122149Seric 		while ((p = lineread(NOEOF)) && *p != CTLCHAR) {
3132149Seric 			text = 1;
3142149Seric 			printf("\t%s",p);
3152149Seric 		}
3162149Seric 		if (!text)
3172149Seric 			printf("\tnone\n");
3182149Seric 	}
3192149Seric 	else
3202149Seric 		read_to(EUSERTXT);
3212149Seric 
3222149Seric 	if (HADB) {
3232149Seric 		printf("\n");
3242149Seric 		while (p = lineread(EOF))
3252149Seric 			if (*p == CTLCHAR)
3262149Seric 				printf("*** %s", ++p);
3272149Seric 			else
3282149Seric 				printf("\t%s", p);
3292149Seric 	}
3302149Seric 
3312149Seric 	fclose(iptr);
3322149Seric }
3332149Seric 
3342149Seric 
getdel(delp,lp)3352149Seric getdel(delp,lp)
3362149Seric register struct delent *delp;
3372149Seric register char *lp;
3382149Seric {
33930498Slepreau 	lp += 2;
3402149Seric 	NONBLANK(lp);
3412149Seric 	delp->type = *lp++;
3422149Seric 	NONBLANK(lp);
3432149Seric 	delp->osid = lp;
3442149Seric 	BLANK(lp);
3452149Seric 	*lp++ = '\0';
3462149Seric 	NONBLANK(lp);
3472149Seric 	delp->datetime = lp;
3482149Seric 	BLANK(lp);
3492149Seric 	NONBLANK(lp);
3502149Seric 	BLANK(lp);
3512149Seric 	*lp++ = '\0';
3522149Seric 	NONBLANK(lp);
3532149Seric 	delp->pgmr = lp;
3542149Seric 	BLANK(lp);
3552149Seric 	*lp++ = '\0';
3562149Seric 	NONBLANK(lp);
3572149Seric 	delp->serial = lp;
3582149Seric 	BLANK(lp);
3592149Seric 	*lp++ = '\0';
3602149Seric 	NONBLANK(lp);
3612149Seric 	delp->pred = lp;
3622149Seric 	repl(lp,'\n','\0');
3632149Seric }
3642149Seric 
3652149Seric 
read_to(ch)3662149Seric read_to(ch)
3672149Seric register char ch;
3682149Seric {
3692149Seric 	char *n;
3702149Seric 
3712149Seric 	while ((n = lineread(NOEOF)) &&
3722149Seric 			!(*n++ == CTLCHAR && *n == ch))
3732149Seric 		;
3742149Seric 
3752149Seric 	return(n);
3762149Seric }
3772149Seric 
3782149Seric 
lineread(eof)3792149Seric lineread(eof)
3802149Seric register int eof;
3812149Seric {
3822149Seric 	char *k;
3832149Seric 
3842149Seric 	k = fgets(line,512,iptr);
3852149Seric 
3862149Seric 	if (k == NULL && !eof)
3872149Seric 		fatal("premature eof (co5)");
3882149Seric 
3892149Seric 	linenum++;
3902149Seric 
3912149Seric 	return(k);
3922149Seric }
3932149Seric 
3942149Seric 
printdel(file,delp)3952149Seric printdel(file,delp)
3962149Seric register char *file;
3972149Seric register struct delent *delp;
3982149Seric {
3992149Seric 	printf("\n");
4002149Seric 
4012149Seric 	if (prefix) {
4022149Seric 		statistics[length(statistics) - 1] = '\0';
4032149Seric 		printf("%s:\t",file);
4042149Seric 	}
4052149Seric 
4062149Seric 	printf("%c %s\t%s\t%s\t%s\t%s\t%s",delp->type,delp->osid,
4072149Seric 		delp->datetime,delp->pgmr,delp->serial,delp->pred,statistics);
4082149Seric }
4092149Seric 
4102149Seric 
printit(file,str,cp)4112149Seric printit(file,str,cp)
4122149Seric register char *file;
4132149Seric register char *str, *cp;
4142149Seric {
4152149Seric 	cp++;
4162149Seric 	NONBLANK(cp);
4172149Seric 
4182149Seric 	if (prefix) {
4192149Seric 		cp[length(cp) - 1] = '\0';
4202149Seric 		printf(" ");
4212149Seric 	}
4222149Seric 
4232149Seric 	printf("%s%s",str,cp);
4242149Seric }
425