V10/cmd/docgen/cov.cpio

0707070035330205021006640000510000040000010144070423770206100001100000001163Makefile# docgen defaults to coversheet script mcsdata
# timestamp is used by tmac.cs to compute timestamp for itds
# cstrans is used by tmac.cs to package & ship coversheet
#	to itds database
all:	cstrans timestamp docgen
docgen: docgen.c
cstrans:	header.h trans.l getstamp.o
	lex trans.l
	cc lex.yy.c getstamp.o -ll -o cstrans
timestamp: timestamp.o getstamp.o
	cc timestamp.o getstamp.o -o timestamp
install: cstrans timestamp docgen
	cp docgen /usr/bin
	cp mcsdata /usr/lib/docgen
	cp cstrans /usr/lib/tmac
	cp timestamp /usr/lib/tmac
	cp name.sed /usr/lib/tmac
	cp sendcover.sh /usr/lib/tmac/sendcover
clean:
	rm cstrans lex.yy.c
0707070035330025251006640000510000040000010073170412351073100001100000043541docgen.c/**********
				docgen.c

	(091984 version: from llc 080284; minor changes by vbt)

	modify *mmfile, *msfile, and *mcfile strings as needed to supply
		full pathnames for mmdata, msdata, and mcsdata files;

**********/
#include <stdio.h>
#include <signal.h>
char *mmfile="/usr/lib/docgen/mmdata";
char *msfile="/usr/lib/docgen/msdata";
char *mcfile="/usr/lib/docgen/mcsdata";
char *wr = "/usr/lib/docgen/wr";
#define eatblanks(a) while((c=getc(a)) == ' '|| c == '\t')
#define MAX 100
#define CMAX 7500
#define LMAX 200
#define QMAX 100
#define NPATH 10
#define NENT 200
#define BUFS 512
#define LABMAX 20
#define STACK 10
#define NEST 10

int inap;
int debug = 0;
int sdebug = 0;
int verbose = 0;
#define ARGS 1
#define ONELINE 2
#define MANY 4
#define OUT 8
#define PRINT 16
#define SKIP 32
#define BLOOP 128
#define PATH 256
#define QUEST 512
#define STUFF 1024
#define NAME 2048
#define SUM 4096
#define PAR 8192
#define FLOOP 16384
#define SEVERAL	32768
#define QSTUFF 65536

struct q_a {
	char *qtext;
	char *text;
	char *macro;
	unsigned long type;
	struct qa *argq;
}  s[MAX];
struct q_a *p = s;

unsigned long gettype();
int sig_in_ed();
char buf[CMAX];
char *ptr = buf;
char obuf[BUFS];
char *optr = obuf;
FILE *outp;
char *ofile;
char line[LMAX];
char sline[LMAX];
char *first;
int lineno = 1;

struct qa {
	char *text;
	struct qa *nexta;
} ques[QMAX];
struct qa *qp = ques;

struct pa {
	char *name;
	struct list *root;
} paths[NPATH];
struct pa *pp = paths;

struct list {
	struct q_a *entry;
	struct list *next;
	struct list *loop;
	char *quest;
	struct list *floop;
} list[NENT];
struct list *lp = list;
struct list *stack[STACK];
struct list **st = stack;

struct pa *findpath();
struct lab {
	struct list *path;
	struct list *place;
} save[LABMAX], *sav=save;
struct lab *savp;
struct lab *savc[10];
unsigned stype[10];
int curly = 0;
char *onepath;
char *qfile;
char *namesf="tagfile";
char nname[50];
FILE *popen(), *edp;

main(argc,argv)
int argc;
char *argv[];
{

	qfile = mcfile;
	while(argc > 1 && *argv[1] == '-'){
		switch(argv[1][1]){
		case 'f':
			if(argc > 2)qfile=argv[2];
			argc--;
			argv++;
			break;
		case 'm':
			if(argv[1][2] == 's')qfile=msfile;
			else if(argv[1][2] == 'c')qfile=mcfile;
			else if(argv[1][2] == 'm')qfile=mmfile;
			else {
				fprintf("unknown macro package %s\n",argv);
				exit(0);
			}
			break;
		case 'w':
			qfile = wr;
			break;
		case 'd':
			sdebug=1;
			break;
		case 'p':
			debug=1;
			break;
		case 'v':
			verbose=1;
			break;
		default:
			fprintf(stderr,"unknown flag %c\n",argv[1][1]);
			exit(0);
		}
		argc--; argv++;
	}
	if(argc > 1)ofile=argv[1];
	init(qfile);
	if(onepath != 0){
		pp=findpath(onepath);
		lp=pp->root;
		process(1);
	}
	else process(0);
	done();
}
init(file)
char *file;
{
	FILE *inp;
	int c;
	int i;
	int printall=0;
	char command[50];
	FILE *dumb;

	if(ofile == 0){
		if(file == wr){
			printf("Tags going to file tagfile\n");
			ofile = namesf;
		}
		else if(file == mcfile){
			printf("Output going to file temp.cover\n");
			ofile = "temp.cover";
		}
		else {
			printf("Output going to file temp\n");
			ofile = "temp";
		}
	}
	if((inp=fopen(file,"r"))==NULL){
		fprintf(stderr,"can't open script file %s\n",file);
		exit(0);
	}
	pp->name = onepath = ptr;
	i=0;
	while((c=getc(inp)) != '\n'){
		if(c == ','){
			*ptr++ = '\0';
			(++pp)->name = ptr;
			i++;
			if(pp > &paths[NPATH-1])
				error("more than 10 paths-NPATH");
		}
		else if(c != ' ' && c != '\t')
			*ptr++ = c;
	}
	*ptr++ = '\0';
	if(i > 0)onepath=0;
	lineno++;
	first = ptr;
	if(getstr(inp)== 0)
		if(onepath == 0)
			error("text string expected");
	while(getentry(inp) != 0){
		if(p++ >= &s[MAX-1])
			error("number of instructions exceeded-MAX");
	}
	if(debug)printf("\n");
	if((dumb = fopen(ofile,"r")) != NULL){
		if(file == wr){
		printf("File %s already exists; Tags will be appended\n",ofile);
		printall++;
		}
		else {
			printf("File %s already exists; Text will be appended\n",ofile);
		}
		fclose(dumb);
	}
	if((dumb = fopen(ofile,"a")) == NULL){
		fprintf(stderr,"can't open %s\n",ofile);
		exit(1);
	}
	fclose(dumb);
	sprintf(command,"ed - %s\n",ofile);
	signal(SIGINT,sig_in_ed);
	if((edp = popen(command,"w")) == NULL){
		printf("can't involk ed\n");
		exit(0);
	}
	setbuf(edp,NULL);
	if(printall){
		printf("The following tags are already defined:\n");
		fputs("1,$p\n",edp);
		fflush(edp);
		sleep(8);
		printf("\n");
	}
	fputs("a\n",edp);
	inap = 1;
}

getentry(inp)
FILE *inp;
{
	char *l;
	int c;
	int comment = 0;

	if(debug)printf("\n place %o ",p);
	savp = sav;
	l = line;
	while((*l = c = getc(inp)) != ':'){
		if(c == EOF)return(0);
		if(c == '*'){
			if(comment){
				comment=0;
				continue;
			}
			else {
				comment=1;
				continue;
			}
		}
		if(comment){
			if(c == '\n')lineno++;
			continue;
		}
		if(c == '\\'){
			*l = getc(inp);
			if(++l >= &line[LMAX-1])
				error("line length exceeded-LMAX");
			continue;
		}
		if(c == '}'){
			if(debug)printf("found }\n");
			l=ptr;
			getstr(inp);
			addloop(--curly,l);
			eatline(inp);
			sav = savc[curly];
			p->type = BLOOP;
			return(1);
		}
		if(c == ','){
			*l = '\0';
			addentry(line,p);
			l=line;
		}
		else if(c == '\n'){
			l=line;
			lineno++;
		}
		else if(c != ' ' && c != '\t'){
			if(l++ >= &line[LMAX-1])
				error("line length exceeded-LMAX");
		}
	}
	*l = '\0';
	addentry(line,p);
	p->macro = ptr;
	while((*ptr = c = getc(inp))!= ':'){
		if(c == '\\'){
			*ptr = getc(inp);
			if(++ptr >= &buf[CMAX-1])
				error("string buffer exceeded-CMAX");
		}
		else if(c == ' ' && ptr == p->macro);
		else if(c == '{' && ptr == p->macro){
			if(debug)printf("in { savp %o\n",savp);
			(sav++)->path = 0;
			stype[curly] = BLOOP;
			savc[curly++] = savp;
			if(curly >= NEST)
				error("nesting depth exceeded-NEST");
			if((c = getc(inp)) == ' '|| c == '\t')
				eatblanks(inp);
			if(c == '\n'){
				lineno++;
				if((c = getc(inp)) == ' '|| c == '\t')
					eatblanks(inp);
			}
			if(c == '"'){
				p->type = FLOOP;
				ungetc(c,inp);
				l=ptr;
				getstr(inp);
				p->qtext = l;
				stype[curly-1] = FLOOP;
			}
			else {
				ungetc(c,inp);
				p->type = BLOOP;
			}
			return(1);
		}
		else if(ptr++ >= &buf[CMAX-1])
			error("string buffer exceeded-CMAX");
	}
	if(p->macro == ptr)p->macro=0;
	else *ptr++ = '\0';
	p->type = gettype(inp);
	if(p->type&QUEST){
		p->qtext = ptr;
		if(getstr(inp) == 0)
			error("text string expected");
	}
	else p->qtext = 0;
	p->text = ptr;
	if(p->type&(ONELINE|SEVERAL|PRINT|MANY|PATH))
		if(getstr(inp)== 0)
			error("text string expected");
	if(p->text == ptr)p->text = 0;
	if(debug)printf(" macro %s type %d text %s ",p->macro,p->type,p->text);
	if(sdebug)db(p);
	if(p->type & (ARGS |SKIP)){
		p->argq = qp;
		qp->text = ptr;
		while(getstr(inp) != 0){
			qp->nexta = (qp+1);
			if(debug||sdebug)printf("\n	arg question= %s",qp->text);
			if(debug)printf(" next %o",qp->nexta);
			if(qp++ >= &ques[QMAX-1])
				error("number of questions exceeded-QMAX");
			qp->text = ptr;
		}
		(qp-1)->nexta = 0;
		if(debug)printf("\n	last %s next %o",(qp-1)->text,(qp-1)->nexta);
		if(sdebug)printf("\n");
	}
	sav = savp;
	return(1);
}
getstr(inp)
FILE *inp;
{
	int c;
	while((c=getc(inp)) == ' ' || c == '\t' || c == '\n')if(c == '\n')lineno++;
	if(c != '\"'){
		ungetc(c,inp);
		return(0);
	}
	while((*ptr=c=getc(inp)) != '\"'){
		if(ptr++ >= &buf[CMAX])
			error("string buffer exceeded-CMAX");
		if(c == '\n')lineno++;
	}
	*ptr++ = '\0';
	return(1);
}
addentry(ch,p)
char *ch;
struct q_a *p;
{
	struct list *ll;
	if(debug || sdebug)printf("path= %s, ",ch);

	for(pp=paths;pp->name != 0 && pp < &paths[NPATH];pp++){
		if(match(ch,pp->name)){
			if(pp->root == 0){
				pp->root = lp;
			}
			else {
				ll=pp->root;
				while(ll->next != 0)ll=ll->next;
				ll->next = lp;
			}
			if(debug)printf("entry %o path %o\n",lp,pp);
			sav->path = (struct list *)pp;
			sav->place = lp;
			lp->entry = p;
			if(lp++ >= &list[NENT-1])
				error("tree exceeded-NENT");
			if(sav++ >= &save[LABMAX-1])
				error("saved paths exceeded-LABMAX");
			return;
		}
	}
	printf("no path to %s\n",ch);
	exit(0);
}

addloop(in,cp)
char *cp;
{
	struct lab *sp;
	struct list *ll;

	sp = savc[in];
	while((ll = sp->path) != 0){
		if(debug)printf("addloop sp %o path %o",sp,sp->path);
		while(ll->next != 0){
			ll=ll->next;
		}
		if(debug)printf("ll %o place %o\n",ll,sp->place);
		if(ll->loop != 0){
			ll->next = lp;
			lp->loop = sp->place;
			lp->quest = cp;
			lp->entry = p;
			if(lp++ >= &list[NENT-1])
				error("tree exceeded - NENT");
		}
		else {
			ll->loop = sp->place;
			ll->quest = cp;
		}
		if(stype[in] == FLOOP){
			sp->place->floop = lp;
			lp->entry = p;
			if(lp++ >= &list[NENT-1])
				error("tree exceeded - NENT");
		}
		sp++;
	}
}
unsigned long
gettype(inp)
FILE *inp;
{
	int c;
	unsigned long i;
	i=0;
another:
	while((c=getc(inp)) == ' ' || c == '\t');
	switch(c){
	case 'A':
		i |= ARGS;
		break;
	case 'M':
		i |= MANY;
		break;
	case 'O':
		if((c=getc(inp)) == 'U')
			i |= OUT;
		else if(c == 'N')
			i|= ONELINE;
		else error("unknown action");
		break;
	case 'P':
		if((c=getc(inp)) == 'R')
			i |= PRINT;
		else if(c == 'A'){
			if((c=getc(inp)) == 'T')
				i |= PATH;
			else if(c == 'R')
				i |= PAR|MANY;
			else error("unknown action");
		}
		else error("unknown action");
		break;
	case 'S':
		if((c=getc(inp)) == 'T')
			i |= STUFF|ARGS;
		else if(c == 'K')
			i |= SKIP;
		else if(c == 'U')
			i |= SUM|MANY;
		else if(c == 'E')
			i |= SEVERAL;
		else error("unknown action");
		break;
	case 'Q':
		if((c=getc(inp)) == 'U')
			i |= QUEST;
		else if(c == 'S')
			i |= QSTUFF|ARGS;
		else error("unknown action");
		break;
	case 'N':
		i |= NAME|ONELINE;
		break;
	default:
		error("unknown action");
	}
	while((c=getc(inp))!= '\n')
		if(c == '&')goto another;
	lineno++;
	if(i&OUT)
		if(i & ~OUT){
			if(i & ~(OUT|QUEST))
				error("action error - OUT not alone");
		}
	if(i & PRINT)
		if(i & ~PRINT){
			if(i & ~(PRINT|QUEST))
				error("action error - PRINT not alone");
		}
	if(i & PATH)
		if(i & ~PATH)error("action error - PATH not alone");
	if((i&(MANY|ONELINE))==(MANY|ONELINE))
		error("contridictory actions - MANY & ONELINE");
	return(i);
}

process(start)
int start;
{
	if(start == 0){
		printf("%s\n",first);
		getl(stdin,line);
		pp=findpath(line);
		lp = pp->root;
	}
more:
	while(lp){
		if(question(lp->entry)== 1)
			continue;
		if(lp->loop != 0){
			printf("%s\n",lp->quest);
			getl(stdin,line);
			if(line[0] == 'y'|| line[0] == 'Y')
				lp=lp->loop;
			else{
				if(lp->loop->entry->type & 1){
					lp->loop->entry->type &= 0177776;
				}
				if(line[0] == 'q')done();
				else lp=lp->next;
			}
		}
		else
			lp = lp->next;
	}
	if(*st != 0){
		lp = *st--;
		if(lp->loop != 0){
			printf("%s\n",lp->quest);
			getl(stdin,line);
			if(line[0] == 'y' || line[0] == 'Y')
				lp=lp->loop;
			else{
				if(lp->loop->entry->type & 1)
					lp->loop->entry->type &= 0177776;
				if(line[0] == 'q')done();
				else lp=lp->next;
			}
		}
		else lp=lp->next;
		goto more;
	}
}

question(rp)
struct q_a *rp;
{
	int blanks;
	char *ch, *sv;

rest:
	if(debug)printf("in question %o\n",rp);
	if(rp->type & BLOOP)
		return(0);
	if(rp->type & FLOOP){
		if(rp->type & 1)return(0);
		printf("%s\n",rp->qtext);
		getl(stdin,line);
		if(line[0] == 'y' || line[0] == 'Y'){
			lp = lp->next;
			rp->type |= 1;
		}
		else if(line[0] == 'q')done();
		else lp= lp->floop;
		return(1);
	}
	if(rp->type & PATH){
		*(++st) = lp;
		if(st >= &stack[STACK-1])
			error("stack depth exceeded-STACK");
		printf("%s\n",rp->text);
		getl(stdin,line);
		if(line[0] == '\0'){
			st--;
			return(0);
		}
		pp=findpath(line);
		lp = pp->root;
		return(1);
	}
	if(rp->type&QUEST){
		printf("%s\n",rp->qtext);
		getl(stdin,line);
		if(line[0] != 'Y' && line[0] != 'y')return(0);
	}
	if(rp->text != 0)
		if((rp->type&MANY) == 0)printf("%s\n",rp->text);
	if(rp->type&(ONELINE|SEVERAL))
		getl(stdin,sline);
	if(rp->type&NAME){
		return(newname(sline));
	}
	if(rp->type&SUM){
		summary();
	}
	if(rp->type&PAR){
		par();
	}
	if(rp->type&(STUFF|QSTUFF)){
		sv = ch = rp->macro;
		qp = rp->argq;
		do{
			while(*ch != '$'){
				if(*ch == '\\')ch++;
				if(*ch == '\0')break;
				ch++;
			}
			if(*ch == '$'){
				*ch = '\0';
				out(sv);
				*ch++ = '$';
				sv = ch;
			}
			printf("%s\n",qp->text);
			getl(stdin,line);
			if(rp->type&QSTUFF)
				if(line[0] == '\0')break;
			if(*(ch-1) == '$')
				out(line);
			qp = qp->nexta;
		} while(qp != 0);
		if(rp->type&STUFF)
			out(sv);
		else if(*sv == '"')out("\"");
		out("\n");
	}
	else if(rp->type&(ARGS | SKIP)){
		if((rp->type&SKIP) == 0 && rp->macro != 0)
			out(rp->macro);
		qp = rp->argq;
		do{
			printf("%s\n",qp->text);
			blanks = getl(stdin,line);
			if(rp->type&SKIP){
				if(line[0] == '\0')
					return(0);
				else out(rp->macro);
			}
			out(" ");
			if(line[0] == '\0')blanks++;
			if(blanks)out("\"");
			out(line);
			if(blanks)out("\"");
			qp=qp->nexta;
		} while(qp != 0);
		out("\n");
	}
	else if((rp->type&(OUT|ONELINE|MANY))&& rp->macro != 0){
		out(rp->macro);
		out("\n");
	}
	if(rp->type&SEVERAL){
		out(rp->macro);
		out(" ");
		out(sline);
		out("\n");
	}
	if(rp->type&ONELINE){
		out(sline);
		out("\n");
	}
	if(rp->type&MANY){
		if(rp->type&(SUM))
			printf("%s named %s.sum\n",rp->text,nname);
		else if(rp->type&PAR)
			printf("%s named %s.par\n",rp->text,nname);
		else printf("%s\n",rp->text);
		printf("	end with : alone on a line (or read a file with :r filename)\n");
		getl(stdin,line);
		if(line[0] == ':' && line[1] == 'r'){
			ch = &line[2];
	more:
			readfiles(ch);
			printf("Type other file names or return\n");
			getl(stdin,line);
			if(line[0] == '\0')return(0);
			ch = line;
			goto more;
		}
		toed();
	}
	return(0);
}
sig_in_ed(){
	inap = 0;
	printf("type q to quit ");
	getl(stdin,line);
	if(line[0] == 'q')done();
	fputs("a\n",edp);
	optr = obuf;
	inap=1;
	signal(SIGINT,sig_in_ed);
	process(1);
	done();
}

getl(inp,l)
char *l;
FILE *inp;
{
	int c;
	int blanks;

	blanks=0;
	while((*l = c = getc(inp)) != '\n'){
		l++;
		if(c == ' ' || c == '\t')blanks++;
	}
	*l++ = 0;
	return(blanks);
}

out(ch)
char *ch;
{
	char c;

	while(*ch != '\0'){
		if(*ch == '\n'){
			*optr++ = *ch++;
			*optr = '\0';
			fputs(obuf,edp);
			optr=obuf;
			if(verbose)printf("%s",obuf);
		}
		else *optr++ = *ch++;
		if(optr >= &obuf[BUFS-1]){
			*optr = '\0';
			fputs(obuf,edp);
			optr = obuf;
		}
	}
}
ofl()
{
	if(optr != obuf){
		*optr='\0';
		fputs(obuf,edp);
		optr=obuf;
	}
	if(inap)
		fputs(".\nw\na\n",edp);
	else {
		fputs("w\na\n",edp);
		inap=1;
	}
}
done(){
	ofl();
	fputs(".\nq\n",edp);
	exit(0);
}

match(ch,hh)
char *ch, *hh;
{
	while(*ch == *hh){
		if(*ch == '\0')return(1);
		ch++;
		hh++;
	}
	return(0);
}

struct pa *
findpath(ch)
char *ch;
{
	for(pp=paths;pp->name != 0;pp++){
		if(match(ch,pp->name))
			return(pp);
	}
	printf("can't find path for %s\n",ch);
	exit(0);
}
eatline(inp)
FILE *inp;
{
	while(getc(inp) != '\n');
	lineno++;
}
readfiles(ptr)
char *ptr;
{
	FILE *io;
	int nomore;
	char *bp;
	char fname[50];

	ofl();
	fputs(".\n",edp);
	nomore = 0;
	while(1){
		while(*ptr == ' ')ptr++;
		bp = ptr;
		while(*ptr != ' ' && *ptr != '\0')ptr++;
		if(*ptr == '\0')nomore++;
		else *ptr++ = '\0';
		sprintf(fname,"$r %s\n",bp);
		fputs(fname,edp);
		if(nomore != 0)break;
	}
	fputs("a\n",edp);
}
error(sp)
char *sp;
{
	fprintf(stderr,"%s at line %d file %s\n",sp,lineno,qfile);
	exit(1);
}
db(dbp)
struct q_a *dbp;
{
	printf(" macro= %s type=",dbp->macro);
	if(dbp->type&ARGS)printf(" ARGS");
	if(dbp->type&SKIP)printf(" SKIP");
	if(dbp->type&OUT)printf(" OUT");
	if(dbp->type&PRINT)printf(" PRINT");
	if(dbp->type&ONELINE)printf(" ONELINE");
	if(dbp->type&SEVERAL)printf(" SEVERAL");
	if(dbp->type&MANY)printf(" MANY");
	if(dbp->type&PATH)printf(" PATH");
	if(dbp->text != 0)printf("\nmain text= %s\n",dbp->text);
	else printf("\n");
}
newname(s)
char *s;
{
	int i;
	char *name1, *name2;
	int pid, rpid, retcode;
	char *sp,spac[10];
restart:
	sp = spac;
	*sp = '\0';
	if(*s == ' ' || *s == '\t')
		while(*s== ' ' || *s == '\t')*sp++ = *s++;
	*sp = '\0';
	for(i=0;*s != '\0';i++)
		nname[i] = *s++;
	if(nname[0] == ':'){
		switch(nname[1]){
		case 'p':
			sprintf(line,".\nw\ne %s\n1,$p\na\n",ofile);
			fputs(line,edp);
			sleep(8);
			return(1);
		case 'r':
			sprintf(line,".\nw\ne %s\na\n",&nname[3]);
			printf("Type text to append to file %s\n",&nname[3]);
			fputs(line,edp);
			getl(stdin,line);
			toed();
			return(1);
		case 'j':
			name1=0;
			name2 = nname;
	nextn:
			for(; *name2 != ' ';name2++)
				if(*name2 == '\0'){
					printf("error in command line: %s\nplease retype\n",nname);
					getl(stdin,sline);
					s=sline;
					goto restart;
				}
			*name2++ = '\0';
			while(*name2 == ' ')name2++;
			if(name1 == 0){
				name1 = name2;
				goto nextn;
			}
			sprintf(line,".\nw\ne %s.sum\n$r %s.sum\nw\n",name1,name2);
			fputs(line,edp);
			sprintf(line,"e %s.par\n$r %s.par\nw\n",name1,name2);
			fputs(line,edp);
			sprintf(line,"e %s\n/%s/d\nw\na\n",ofile);
			fputs(line,edp);
			return(1);
		default:
			printf("unknown command %s\n",nname);
			printf("please retype\n");
			goto restart;
		}
	}
	if(nname[0] == '!'){
		if((pid = fork()) == 0){
			execl("/bin/sh","sh","-c",&nname[1],0);
			exit(0);
		}
		while((rpid=wait(&retcode))!=pid&& rpid != -1);
		printf("!\n");
		return(1);
	}
	if(i > 10){
		printf("tag too long - please type new tag ");
		getl(stdin,sline);
		s=sline;
		goto restart;
	}
	nname[i] = '\0';
	sprintf(line, ".\nw\ne %s\na\n%s%s\n",ofile,spac,nname);
	fputs(line,edp);
	return(0);
}
summary(){
	FILE *ff;
	sprintf(line,"%s.sum",nname);
	if((ff = fopen(line,"a")) == NULL){
		printf("can't open %s\n",line);
	}
	sprintf(line,".\nw\ne %s.sum\na\n",nname);
	fputs(line,edp);
	fclose(ff);
}
par(){
	FILE *ff;
	sprintf(line,"%s.par",nname);
	if((ff=fopen(line,"a")) == NULL){
		printf("can't open %s\n",line);
		exit(1);
	}
	sprintf(line,".\nw\ne %s.par\na\n",nname);
	fputs(line,edp);
	fclose(ff);
}
toed(){
	while(1){
		if(line[1] == '\0'){
		switch(line[0]){
		case 'i':
		case 'a':
		case 'c':
			inap++;
			break;
		case '.':
			inap = 0;
			break;
		case 'q':
			if(inap != 0)break;
		case ':':
			if(inap == 0){fputs("a\n",edp);
				inap++;
			}
			return(0);
		}
		}
		fputs(line,edp);
		fputs("\n",edp);
		getl(stdin,line);
	}
}
0707070035330205151006640000510000040000010235620412351407300001300000000414getstamp.c#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
long
getstamp(filename)
char *filename;
{
	long mtime;
	struct stat fbuf, *fp = &fbuf;
	struct tm t, *tp = &t;
	stat(filename, fp);
	t = *localtime(&fp->st_mtime);
	mtime = fp->st_mtime;
	return(mtime);
}
0707070035330205051006640000510000040000010235640412351413100001100000001552header.h/**********		docsend.h - 092884		**********/

#define HEADSIZE 160
#define UJN 0		/* unique job name - 14 bytes */
#define ULOG 15		/* user login - 8 bytes */
#define CO 24		/* company code - 2 bytes */
#define DOCNUM 28	/* first document number (cover sheet only) - 18 bytes */
#define TIMESTAMP 53	/* docsend timestamp - 9 bytes */
#define DEVICE 64	/* device: aps (APS-5), i10 (imagen), X97 (troff xerox), X (nroff xerox), 450 (nroff terminal), a.i (imagen with APS-5 simulation) - 3 bytes */
#define NETWORK 68	/* network - nusend (1), usend (2), others (0) - 1 byte */
#define TODSEND 70	/* TOD of docsend - 10 bytes */
#define DEST 81		/* JES remote station - 5 bytes */
#define BIN 87		/* bin or mail info - 34 bytes */
#define PAGES 90	/* TP%d total pages */
#define DUMMY 122	/* position for next field */
#define VERSION 152	/* docsend version (vbt) - 6 bytes */

0707070035330155531007750000510000040000010311640423770172700001500000000155sendcover.shtrap 'rm -f /tmp/cs$$; trap 0; exit' 0 1 2 3 15
L=/usr/lib/tmac
T=/tmp/cs$$
	$L/cstrans $T $1 $2
sh $T
rm $T
0707070035330205071006640000510000040000010235610412351405300001400000000261timestamp.c#include <stdio.h>
main(argc, argv)
char *argv[];
{
	long mtime, getstamp();
	char *filename;
	filename = argv[1];
	mtime = getstamp(filename);
	printf(".ds s) %ld\n",mtime);
}
0707070035330165711006640021230000040000010214560421531217500001000000012541trans.l%{
#include <sys/types.h>
#include <pwd.h>
#include <sys/stat.h>
#include <time.h>
#include <libc.h>
#include "header.h"

#define DATE DOCNUM+6
#define SEQNUM DOCNUM+13
#define TYPE DOCNUM+15
#define SOFT DOCNUM+17
struct passwd *getpwuid(), *ps;
int soft;
char *p, *s1, *s2;
int type, ci=0, pm=0, rl=0;
char buf[HEADSIZE];
char *co = &buf[CO];
char *dept = &buf[DOCNUM], *date = &buf[DATE], *seqnum = &buf[SEQNUM];
char *stype = &buf[TYPE], *ssoft = &buf[SOFT];
char *machine = buf;
char *login = &buf[ULOG], *timestamp = &buf[TIMESTAMP];
char *version = &buf[VERSION];
char *pages = &buf[PAGES];
int more = 1;
%}
%%
^".so".*	;
^".TI"	{
	printf(".TL\n");
	}
^".DT".*	;
^".AH".*	{
	yytext[yyleng] = '\0';
	p = strtok(&yytext[3], " \n");
	printf(".AU %s", p);
	if (*p == '"') {
		p = strtok((char *)0, "\"");
		printf(" %s", p);
	}
	p = strtok((char *)0, "\n");
	printf(" \"\"%s\n", p);
	}
^".AP".*	{
	yytext[yyleng] = '\0';
	printf(".rP %s\n",&yytext[3]);
	}
^".SA"	{
	printf(".AS\n");
	}
^".SE"	{
	printf(".AE\n");
	}
^".KW".*	{
	printf(".OK %s\n",&yytext[3]);
	}
^".TY".*	{
	for(p = &yytext[3]; *p == ' ';p++);
	if(*p == 'I')type=2;
	else if(*(p+1) == 'M')type=1;
	else type=3;
	*stype = *p;
	*(stype+1) = *(p+1);
	while(*p != ' '){
		if(*p == '\n'){
			soft=0;
			break;
		}
		p++;
	}
	if(*p == ' ')
		if(*++p == 'y')
			soft=1;
	printf(".MT %d\n",type);
	if(soft){
		*ssoft = 'S';
		printf(".sF\n");
	}
	}
^".MT".*	{
	for(p = &yytext[3]; *p == ' ';p++);
	if(*p == '1') {
		type=1;
		*stype = 'T';
		*(stype+1) = 'M';
	} else if(*p == '2') {
		type=2;
		*stype = 'I';
		*(stype+1) = 'M';
	} else type=3;
	printf(".MT %d\n",type);
	}
^".sF".*	{
	soft = 1;
	*ssoft = 'S';
	printf(".sF\n");
	}
^(".NU"|".dN").*	{
	p = strtok(&yytext[3], "- \n\"");
	if(p != 0){
		sprintf(dept,"%s-",p);
		printf(".dN %s-",p);
		type = 1;
	}
	p = strtok((char *)0, "- \n\"");
	if(p != 0){
		sprintf(date,"%s-",p);
		printf("%s-",p);
	}
	p = strtok((char *)0, "- \n\"");
	if(p != 0){
		*seqnum = *p;
		*(seqnum+1) = *(p+1);
		printf("%s\n",p);
	}
	else if(type) printf("\n");
	p = strtok((char *)0, " \n\"");
	if(p != 0)
		printf(".fC %s\n",p);
	p = strtok((char *)0, " \n\"");
	if(p != 0)
		printf(".wP %s\n",p);
	}
^".MY".*	{
	printf(".mE %s\n",&yytext[3]);
	}
^".ED".*	{
	printf(".eD %s'n",&yytext[3]);
	}
^".PR".*	{
	pm=1;
	printf(".PM %s\n",&yytext[3]);
	}
^".RL".*	{
	rl=1;
	if(yyleng>3){
		p=&yytext[3];
		while(*p == ' ')p++;
		if(*p == '\"')p++;
		if(*p == 'n')printf(".fA n\n");
		else printf(".fA y\n");
	}
	else printf(".fA y\n");
	}
^".GS"	{
	printf(".gS\n");
	}
^".CI".*	{
/*	ci = 1;		gone away
	if(yyleng == 3)
		printf(".cI n\n");
	else {
		p = &yytext[3];
		while(*p == ' ')p++;
		if(*p == '\n' || *p == 'n')
			printf(".cI n\n");
		else if(*p == '\"')p++;
		if(*p == 'y')
			printf(".cI y\n");
		else if(*p == '\"' || *p == 'n')
			printf(".cI n\n");
		else	fprintf(stderr,".CI unknown argument %c\n",*p);
	}*/
	}
^".CO".*	{
/*	if(!ci){
		printf(".cI n\n");
		ci = 1;
	}*/
	if(!rl){
		printf(".fA y\n");
		rl = 1;
	}
	printf(".cC\n");
	}
^".CE"	{
	printf(".cE\n");
	}
^".CV".*	{
/*	if(!ci){
		printf(".cI n\n");
		ci = 1;
	}*/
	if(!rl){
		printf(".fA y\n");
		rl = 1;
	}
	printf(".cS\n");
	}
^".CS".*	{
	ECHO;
	printf("\n");
	return(0);
	}
^".SC".*	{
/*	if(!ci){
		printf(".cI n\n");
		ci = 1;
	}*/
	if(!rl){
		printf(".fA y\n");
		rl = 1;
	}
	p = s1 = &yytext[3];
	while(*s1 == ' ')s1++;
	while(*s1 != ' ')s1++;
	while(*s1 == ' ')s1++;
	while(*s1 != ' ')s1++;
	*s1 = '\0';
	s1++;
	printf(".CS %s \"\" %s\n", p, s1);
	return(0);
	}
.*	{
	ECHO;
	printf("\n");
	}
\n	;
%%
char *header="/tmp/            ";
char *dest = "mhuxd!/usr/spool/uucppublic/doc.mcs";
char *dco = "BL";
main(argc, argv)
char *argv[];
{
	FILE *inp;
	char *filename, *name, *cover, *pid;
	int nuchars, npid, uid, days;
	long mtime;
	if(argc < 3){
		fprintf(stderr,"file name must be supplied to sendcover\n");
		exit(1);
	}
	if((inp=fopen("/etc/whoami","r")) == NULL){
		fprintf(stderr,"can't open /etc/whoami\n");
		exit(1);
	}
	nuchars = fread(machine, sizeof(char), 10, inp);
	nuchars -= 1;
	if(nuchars < 5)pid = machine + nuchars +1;
	else pid = machine + 6;
	cover = pid + 5;
	fclose(inp);
	*(pid-1) = '.';
	npid = getpid();
	sprintf(pid,"%05d",npid);
	*cover = 'c';
	sprintf(&header[5],"%s",machine);
	uid = getuid();
	if ((ps = getpwuid(uid)) == NULL){
		fprintf(stderr, "login not found");
		exit(1);
	}
	strcpy (login,ps->pw_name);
	sprintf(version,"030388L");	/*version*/
	strcpy(co, dco);	/*company name=BL*/
	name = argv[1];
	argc--; argv++;
	if(freopen(argv[1],"r",stdin)==NULL) {
		fprintf(stderr,"%s: cannot open\n", argv[1]);
		exit(1);
	}
	if(freopen(header,"w",stdout)== NULL){
		fprintf(stderr,"%s: cannot open\n",header);
		exit(1);
	}
	if((nuchars = fwrite(buf,sizeof(char),HEADSIZE,stdout)) != HEADSIZE){
		fprintf(stderr,"wrong number of characters written %d\n",nuchars);
			exit(1);
	}
	filename = argv[1];
	mtime = getstamp(filename);
	sprintf(timestamp,"%ld",mtime);
	argv++;
	sprintf(pages,"TP%s",argv[1]);
	yylex();
	rewind(stdout);
	for(p=buf; p < &buf[HEADSIZE-1]; p++)
		if(*p == '\0')*p = ' ';
	*p = '\n';
	if((nuchars = fwrite(buf,sizeof(char),HEADSIZE,stdout)) != HEADSIZE){
		fprintf(stderr,"wrong number of characters written %d\n",nuchars);
			exit(1);
	}
	*(cover+1) = '\0';
	if((inp=fopen(name,"a")) == NULL){
		fprintf(stderr,"can't open tmp file %s\n",name);
		exit(1);
	}
	fprintf(inp,"cd /tmp; uucp -m -C %s %s; rm %s\n",machine,dest,machine);
	fclose(inp);
}	
0707070035330165711006640021230000040000010214560421531217500001300000000000TRAILER!!!printf(stderr,"wrong number of characters written %d\n",nuchars);
			exit(1);
	}
	*(cover+1) = '\0';
	if((inp=fopen(name,"a")) == NUL