[net.sources] New NRO file 3 of 3

ron@trsvax.UUCP (09/16/83)

#N:trsvax:66500004:000:23000
trsvax!ron    Sep  9 00:37:00 1983

--------------------------------------------------------------------------------
: Run this shell script with "sh" not "csh"
#! /bin/sh
PATH=:/bin:/usr/bin:/usr/ucb
export PATH
all=FALSE
if [ $1x = -ax ]; then
	all=TRUE
fi
/bin/echo 'Extracting nrotxt.c'
sed 's/^X//' <<'//go.sysin dd *' >nrotxt.c
X/*
X *	Text processing portion of NRO word processor
X *
X *	Stephen L. Browning
X *	5723 North Parker Avenue
X *	Indianapolis, Indiana 46220
X *
X *	Modified and enhanced by:
X *		Ron Light
X *		6016 Croftway Ct.
X *		Ft. Worth, Tx. 76131
X */
X
X#include <stdio.h>
X#include "nro.h"
X
X
Xextern	struct docctl	dc;
Xextern	struct page	pg;
Xextern	FILE   		*pout;
Xextern	struct cout	co;
Xextern	struct macros	mac;
Xextern	struct file	file[NFILES];
Xextern	unsigned char	disk;
Xextern	unsigned char	raw;
Xextern	unsigned char	*divertbuf;
Xextern	unsigned char	*divpnt;
Xstatic	unsigned char	lastflag = 0;
Xunsigned char		inbuf[MAXLINE] = 0;
X
X
X
Xtext(p)
Xregister unsigned char	*p;
X{
X	register unsigned int	i;
X		 unsigned char	wrdbuf[MAXLINE];
X
X
X	if(dc.literal)
X	{
X		put(p);
X		--dc.literal;
X		return;
X	}
X
X	if (isspace(*p) || iscr(*p))
X		 leadbl(p);
X
X	expesc(p, wrdbuf);
X	mask(p);
X	checkul(p);
X
X	if (dc.ceval > 0) 
X	{
X		center(p);
X		put(p);
X		--dc.ceval;
X	}
X	else if (iscr(*p))
X		 put(p);	/* all blank line */
X	else if (dc.fill == NO)
X		 put(p);	 /* unfilled */
X	else
X	{
X		while ((i = getwrd(p, wrdbuf)) > 0) 
X		{
X			putwrd(wrdbuf);
X			p += i;
X		}
X	}
X
X
X	if(lastflag == 1)
X	{
X		i = co.outp - 1;
X
X		while(isspace(co.outbuf[i]))
X			co.outbuf[i--] = ' ';
X	}
X
X	lastflag = 0;
X}
X
X
X/*
X *	insert bold face text
X */
X
Xbold(p0, p1)
Xregister unsigned char	*p0, *p1;
X{
X	register unsigned int	i, j, k;
X
X
X	j = 0;
X
X	for (i = 0; j < MAXLINE - 1; ++i) 
X	{
X		if(isterm(p0[i]))
X			break;
X
X		if (isalpha(p0[i]) || isdigit(p0[i]) || dc.cbold) 
X		{
X			if(!iswhite(p0[i]))
X			{
X				p1[j++] = p0[i];
X				p1[j++] = '\b';
X				continue;
X			}
X		}
X
X		p1[j++] = p0[i];
X	}
X
X	p1[j++] = '\n';
X	p1[j] = EOS;
X	strcpy(p0, p1);
X}
X
X
X
X
X/*
X *	center a line by setting tival
X */
X
Xcenter(p)
Xregister unsigned char	*p;
X{
X	dc.tival = max((dc.rmval - width(p)) >> 1, 0);
X}
X
X
X/*
X *	expand title buffer to include character string
X */
X
Xexpand(p0, c, s)
Xregister unsigned char	*p0, *s;
Xregister unsigned char	c;
X{
X	register unsigned char	*p, *q, *r;
X		 unsigned char	tmp[MAXLINE];
X
X	p = p0;
X	q = tmp;
X
X	while (*p != EOS) 
X	{
X		if (*p == c) 
X		{
X			r = s;
X
X			while (*r != EOS)
X				*q++ = *r++;
X		}
X		else
X			*q++ = *p;
X
X		++p;
X	}
X
X	*q = EOS;
X	strcpy(p0, tmp);	 /* copy it back */
X}
X
X
X/*
X *	get field from title
X */
X
Xchar *getfield(p, q, delim)
Xregister unsigned char	*p, *q;
Xregister unsigned char	delim;
X{
X	while (*p != delim && !isterm(*p))
X		*q++ = *p++;
X
X	*q = EOS;
X
X	if (*p == delim)
X		++p;
X
X	return (p);
X}
X
X
X
X/*
X *	get non-blank word from p0 into p1.
X *	return number of characters processed.
X */
X
Xgetwrd(p0, p1)
Xregister unsigned char	*p0, *p1;
X{
X	register unsigned int	i, j;
X
X
X	j =
X	i = 0;
X
X	while (isspace(*p0))
X	{
X		++i;
X		++p0;
X	}
X
X	while (!isspace(*p0) && *p0)
X	{
X		if (isterm(*p0))
X			 break;
X
X		*p1++ = *p0++;
X		++i;
X		++j;
X	}
X
X	*p1 = 0;
X
X	if(!j)
X		i = 0;
X
X	return (i);
X}
X
X
X/*
X *	convert integer to decimal ascii string
X */
X
Xitoda(value, p, size)
Xregister	  int	value;
Xregister unsigned int	size;
Xregister unsigned char	*p;
X{
X	if(dc.roman)
X	{
X		roman(value, p);
X		return(strlen(p)+1);
X	}
X
X	sprintf(p, "%d", value);
X	return (strlen(p) + 1);
X}
X
X
X/*
X *	center title text into print buffer
X */
X
Xjustcntr(p, q, limit)
Xregister unsigned char	*p, *q;
Xunsigned int		limit[];
X{
X	register unsigned int	len;
X
X	len = width(p);
X	q = &q[(limit[RIGHT] + limit[LEFT] - len) >> 1];
X
X	while (*p != EOS)
X		*q++ = *p++;
X}
X
X
X
X/*
X *	left justify title text into print buffer
X */
X
Xjustleft(p, q, limit)
Xregister unsigned char	*p, *q;
Xregister unsigned int	limit;
X{
X	q = &q[limit];
X
X	while (*p != EOS)
X		*q++ = *p++;
X}
X
X
X/*
X *	right justify title text into print buffer
X */
X
Xjustrite(p, q, limit)
Xregister unsigned char	*p, *q;
Xregister unsigned int	limit;
X{
X	register unsigned int	len;
X
X	len = width(p);
X	q = &q[limit - len];
X
X	while (*p != EOS)
X		*q++ = *p++;
X}
X
X
X
X
X/*
X *	delete leading blanks, set tival
X */
X
Xleadbl(p)
Xregister unsigned char	*p;
X{
X	register unsigned int	i, j;
X
X	br();
X
X	for (i = 0; ; ++i)
X		if(!isspace(p[i]))
X			break;
X
X	if (!iscr(p[i]))
X		 dc.tival = i;
X
X	if(i)
X	{
X		for (j = 0; p[i] != EOS; ++j)
X			p[j] = p[i++];
X
X
X		p[j] = EOS;
X	}
X}
X
X
X
X/*
X *	find minimum of two integer
X */
X
Xmin(v1, v2)
Xregister int	v1, v2;
X{
X	return ((v1 < v2) ? v1 : v2);
X}
X
X
X
X/*
X *	find maximum of two integers
X */
X
Xmax(v1, v2)
Xregister int	v1, v2;
X{
X	return ((v1 > v2) ? v1 : v2);
X}
X
X
X
X/*
X *	put out page footer
X */
X
Xpfoot()
X{
X	if(dc.divert)
X		return;
X
X	dumpdivert();
X	skip(pg.m3val);
X
X	if (pg.m4val > 0) 
X	{
X		if ((pg.curpag % 2) == 0) 
X			puttl(pg.efoot, pg.eflim, pg.curpag);
X		else
X			puttl(pg.ofoot, pg.oflim, pg.curpag);
X
X		while(pg.lineno <= pg.plval)
X			skip(1);
X	}
X
X	if(dc.divsav)
X	{
X		dc.divlin = dc.divsav;
X		dc.divsav = 0;
X	}
X
X/*	pg.lineno = 0;	*/
X	setbot();
X}
X
X
X
X/*
X *	put out page header
X */
X
Xphead()
X{
X	if(dc.divert)
X		return;
X
X	pg.curpag = pg.newpag;
X	pg.lineno = 1;
X	pg.eooset = (pg.curpag % 2) ? pg.oofset : pg.eofset;
X
X	if (pg.curpag >= pg.frstpg && pg.curpag <= pg.lastpg) 
X		dc.prflg = TRUE;
X	else
X		dc.prflg = FALSE;
X
X	++pg.newpag;
X
X	if (pg.m1val > 0) 
X	{
X		skip(pg.m1val - 1);
X
X		if ((pg.curpag % 2) == 0) 
X			puttl(pg.ehead, pg.ehlim, pg.curpag);
X		else
X			puttl(pg.ohead, pg.ohlim, pg.curpag);
X	}
X
X	skip(pg.m2val);
X	setbot();
X}
X
X
X/*
X *	print character with test for printer
X */
X
Xprchar(byte)
Xregister unsigned char	byte;
X{
X	register	unsigned char	c;
X	static		unsigned char	last;
X
X	if(dc.divert)
X		c = byte;
X	else
X		c = byte & (unsigned) 0x7f;
X
X	if(dc.divert)
X	{
X		*divpnt++ = c;
X		*divpnt = EOS;
X
X		if(iscr(c))
X			++dc.divlin;
X	}
X#ifdef PRINT
X	else if (co.lpr == TRUE) 
X	{
X		if(dc.prflg == TRUE)
X		{
X			if(raw)
X			{
X				if(c != '\b');
X					putc(c, xxxx);
X
X				goto lok;
X			}
X
X			if(c == '\b')
X			{
X				fprintf(xxxx, "\b%c\b%c\b%c", last, last, last);
X				return;
X			}
X
X			if(byte & 0x80)
X				fprintf(xxxx, "_\b");
X
X			putc(c, xxxx);
X			last = c;
X		}
Xlok:
X
X		if(iscr(c))
X			++pg.lineno;
X		else if(c == '\f')
X			pg.lineno = 0;
X	}
X#endif
X	else
X	{
X		if(dc.prflg == TRUE)
X		{
X			if(raw)
X			{
X				if(c != '\b')
X					putc(c, pout);
X
X				goto vok;
X			}
X
X			if(c == '\b')
X			{
X				fprintf(pout, "\b%c", last);
X				return;
X			}
X
X			if(byte & 0x80)
X				fprintf(pout, "_\b%c", c);
X			else
X				putc(c, pout);
X
X			last = c;
X		}
X
Xvok:
X
X		if(iscr(c))
X			++pg.lineno;
X		else if(c == '\f')
X			pg.lineno = 0;
X	}
X}
X
X
X
X
X/*
X *	put out line with proper spacing and indenting
X */
X
Xput(p)
Xregister unsigned char	*p;
X{
X	register unsigned int	j;
X
X	if (pg.lineno == 0 || pg.lineno > pg.bottom) 
X		phead();
X
X	both();
X	putlin(p, 1);
X	reset();
X
X	if(iscr(p[strlen(p) - 1]))
X	{
X		skip(min(dc.lsval - 1, pg.bottom+1 - pg.lineno));
X		chkbot();
X	}
X}
X
X
X/*
X *	output a null terminated string to the output file
X */
X
Xputlin(q, flag)
Xregister unsigned char	*q;
Xregister unsigned int	flag;
X{
X	register unsigned char	*p = q;
X
X
X	if(dc.aindex && !dc.divert)
X		cindex(q);
X
X	while (*q)
X	{
X		if(!dc.divert)
X		{
X			if(isspace(*q) && iscr(q[1]))
X			{
X				++q;
X				continue;
X			}
X		}
X
X		prchar(*q++);
X	}
X}
X
X
X
X/*
X *	put out title or footer
X */
X
Xputtl(p, lim, pgno)
Xregister unsigned char	*p;
Xregister unsigned int	lim[];
Xregister unsigned int	pgno;
X{
X	register unsigned int	i;
X		 unsigned char	pn[80];
X		 unsigned char	t[MAXLINE];
X		 unsigned char	h[MAXLINE];
X	register unsigned char	delim;
X
X	itoda(pgno, pn, 6);
X	blank(h);
X	delim = *p++;
X	p = getfield(p, t, delim);
X	expand(t, dc.pgchr, pn);
X	justleft(t, h, lim[LEFT]);
X	p = getfield(p, t, delim);
X	expand(t, dc.pgchr, pn);
X	justcntr(t, h, lim);
X	p = getfield(p, t, delim);
X	expand(t, dc.pgchr, pn);
X	justrite(t, h, lim[RIGHT]);
X	clobber(h);
X	mask(h);
X
X	if (strlen(h) > 1) 
X		ofset();
X
X	putlin(h, 0);
X}
X
X
X
X/*
X *	put out temporary title
X */
X
Xtitle(p, lim, pgno)
Xregister unsigned char	*p;
Xregister unsigned int	lim[];
Xregister unsigned int	pgno;
X{
X	register unsigned int	i;
X		 unsigned char	pn[80];
X		 unsigned char	t[MAXLINE];
X		 unsigned char	h[MAXLINE];
X	register unsigned char	delim;
X
X
X	if (pg.lineno == 0 || pg.lineno > pg.bottom) 
X		phead();
X
X	itoda(pgno, pn, 6);
X	blank(h);
X	delim = *p++;
X	p = getfield(p, t, delim);
X	expand(t, dc.pgchr, pn);
X	justleft(t, h, lim[LEFT]);
X	p = getfield(p, t, delim);
X	expand(t, dc.pgchr, pn);
X	justcntr(t, h, lim);
X	p = getfield(p, t, delim);
X	expand(t, dc.pgchr, pn);
X	justrite(t, h, lim[RIGHT]);
X	clobber(h);
X	mask(h);
X	ofset();
X	checkul(h);
X	putlin(h, 1);
X	reset();
X	skip(min(dc.lsval - 1, pg.bottom+1 - pg.lineno));
X	chkbot();
X}
X
X
X
X
X/*
X *	put out into indent field
X */
X
Xputin(p)
Xregister unsigned char	*p;
X{
X	register unsigned char	*q;
X		 unsigned char	pn[80];
X		 unsigned char	t[MAXLINE];
X
X
X	itoda(pg.curpag, pn, 6);
X	expesc(skipbl(skipwd(p)), t);
X	expand(t, dc.pgchr, pn);
X	justleft(t, inbuf, 0);
X	inbuf[dc.tival] = 0;
X	mask(inbuf);
X	checkul(inbuf);
X	q = &inbuf[strlen(inbuf) - 1];
X
X	if(*q == '\n')
X		*q = 0;
X}
X
X
X
X/*
X *	put word in output buffer
X */
X
Xputwrd(wrdbuf)
Xregister unsigned char	*wrdbuf;
X{
X	register int		w, last, llval, nextra;
X	register unsigned char	c;
X
X	w = width(wrdbuf);
X	last = strlen(wrdbuf) + co.outp;
X	llval = dc.rmval - dc.tival;
X
X	if ((co.outp && ((co.outw + w) > llval)) || (last > MAXLINE)) 
X	{
X		last -= co.outp;
X
X		if (dc.juval == YES) 
X		{
X			nextra = llval - co.outw + 1;
X			/*
X			 *	 Check whether last word was end of
X			 *	 sentence and modify counts so that
X			 *	 it is right justified.
X			 */
X			if (isspace(co.outbuf[co.outp - 2]))
X			{
X				--co.outp;
X				++nextra;
X			}
X
X			spread(co.outbuf, co.outp - 1, nextra, co.outwds);
X
X			if ((nextra > 0) && (co.outwds > 1)) 
X				co.outp += (nextra - 1);
X		}
X
X		br();
X	}
X
X	strcpy(co.outbuf+co.outp, wrdbuf);
X	co.outp = last;
X
X	/* add additional space if end of sentence */
X	c = wrdbuf[strlen(wrdbuf) - 1] & 0x7f;
X
X	if(c == '"')
X		c = wrdbuf[strlen(wrdbuf) - 2] & 0x7f;
X
X	if(c == '.' || c == '?' || c == '!')
X	{
X		addspace();
X		++w;
X	}
X
X	addspace();
X	co.outbuf[co.outp] = 0;
X	co.outw += (w + 1);
X	++co.outwds;
X}
X
X
X/*
X *	skips the number of lines specified by n.
X */
X
Xskip(n)
Xregister int	n;
X{
X	register int	i;
X
X
X	if (n > 0) 
X	{
X		for (i = 0; i < n; ++i) 
X			prchar('\n');
X	}
X}
X
X
X
X/*
X *	spread words to justify right margin
X */
X
Xspread(p, outp, nextra, outwds)
Xunsigned char		p[];
Xregister unsigned int	outp, nextra, outwds;
X{
X	register unsigned int	i, j, nb, ne, nholes;
X
X
X	if ((nextra <= 0) || (outwds <= 1))
X		 return;
X
X	dc.sprdir = ~dc.sprdir;
X	ne = nextra;
X	nholes = outwds - 1;		/* holes between words */
X	i = outp - 1;			/* last non-blank character */
X	j = min(MAXLINE - 2, i + ne);	/* leave room for CR, LF, EOS  */
X
X	while (i < j) 
X	{
X		p[j] = p[i];
X
X		if (isspace(p[i]))
X		{
X			if (dc.sprdir == 0)
X				nb = (ne - 1)/nholes + 1;
X			else
X				nb = ne/nholes;
X
X			ne -= nb;
X			--nholes;
X
X			for (; nb > 0; --nb) 
X			{
X				--j;
X
X				if(p[i] & 0x80)
X					p[j] = ' ' | 0x80;
X				else
X					p[j] = ' ';
X			}
X		}
X
X		--i;
X		--j;
X	}
X}
X
X
X
X/*
X *	underline a line
X */
X
Xunderl(p0, p1)
Xregister unsigned char	*p0, *p1;
X{
X	register unsigned int	i, j;
X	register unsigned char	byte;
X
X	j = 0;
X
X	for (i = 0; j < MAXLINE - 1; ++i) 
X	{
X		if(isterm(p0[i]))
X			break;
X
X		byte = p0[i] & 0x7f;
X
X		if (byte >= ' ' && byte <= '~') 
X		{
X			if (isalpha(byte) || isdigit(byte) || dc.cuval > 0) 
X			{
X				p1[j++] = byte | 0x80;
X				continue;
X			}
X		}
X
X		p1[j++] = p0[i];
X	}
X
X	p1[j++] = '\n';
X	p1[j] = EOS;
X	strcpy(p0, p1);
X}
X
X
X/*
X *	compute width of character string
X */
X
Xwidth(s)
Xregister unsigned char	*s;
X{
X	register unsigned int	w;
X
X	w = 0;
X
X	while (*s != EOS) 
X	{
X		if(*s == '\b')
X			;
X		else if (!iscr(*s))
X			++w;
X
X		++s;
X	}
X
X	return (w);
X}
X
X
X
X
X
X
X/*
X *	Convert an integer into roman numerial for output
X */
X
Xstatic	unsigned char	tempbuf[25] = 0;
X
Xstruct roman
X{
X	unsigned char	rm[3];
X	unsigned int	rv;
X};
X
Xstruct roman	romtab[] =
X{
X	"M",	1000,
X	"CM",	900,
X	"D",	500,
X	"CD",	400,
X	"C",	100,
X	"XC",	90,
X	"L",	50,
X	"XL",	40,
X	"X",	10,
X	"IX",	9,
X	"V",	5,
X	"IV",	4,
X	"I",	1,
X	0,	0
X};
X
X
Xroman(value, minbuf)
Xregister unsigned int	value;
Xregister unsigned char	*minbuf;
X{
X	register int	i;
X
X
X	tempbuf[0] = 0;
X
X	for(i = 0; i < 13; ++i)
X	{
X		if(!value)
X			break;
X
X		value = romc(romtab[i].rm, romtab[i].rv, value);
X	}
X
X	if(dc.rlower)
X		makelower();
X
X	strcpy(minbuf, tempbuf);
X}
X
X
X
X
Xromc(token, max, value)
Xregister unsigned char	*token;
Xregister unsigned int	max, value;
X{
X	while(value >= max)
X	{
X		value -= max;
X		strcat(tempbuf, token);
X	}
X
X	return(value);
X}
X
X
X
Xmakelower()
X{
X	register unsigned char	*pnt = tempbuf;
X
X	while(*pnt)
X	{
X		*pnt = tolower(*pnt);
X		++pnt;
X	}
X}
X
X
X
X
X/*
X *	get the current date and time
X *
X *	NOTE:  These routines are machine dependant.
X */
X
X#include <time.h>
X#define	XTIME	struct tm
X
Xunsigned long	ITIME = 0;
Xstatic	 char	*xmod[] =
X{
X	"January",
X	"February",
X	"March",
X	"April",
X	"May",
X	"June",
X	"July",
X	"August",
X	"September",
X	"October",
X	"November",
X	"December"
X};
X
X
X
X
Xgetdate(flag)
Xunsigned int	flag;
X{
X	static	 unsigned char	dateb[30];
X	register XTIME		*tp;
X	register unsigned char	*xp;
X	extern	 XTIME		*localtime();
X
X
X
X	time(&ITIME);
X	tp = localtime(&ITIME);
X	xp = xmod[tp->tm_mon];
X	sprintf(dateb,"%s %d, 19%02d",xp,tp->tm_mday,tp->tm_year);
X
X	if(flag)
X		text(dateb);
X	else
X		return(dateb);
X}
X
X
X
Xcheckul(p)
Xregister unsigned char	*p;
X{
X	unsigned char	h[MAXLINE];
X
X
X	if (dc.ulval) 
X	{
X		underl(p, h);
X		--dc.ulval;
X	}
X
X	if (dc.cuval) 
X	{
X		underl(p, h);
X		lastflag = dc.cuval--;
X	}
X
X	if (dc.boval) 
X	{
X		bold(p, h);
X
X		if(--dc.boval == 0)
X			dc.cbold = 0;
X	}
X}
X
X
X
Xreset()
X{
X	dc.tival = dc.inval;
X	dc.rmval = dc.tmval;
X	pg.offset = pg.tofset;
X}
X
X
Xdumpdivert()
X{
X	register unsigned int	temp;
X	register unsigned char	*q;
X		 unsigned char	buff[MAXLINE];
X
X
X	if(dc.divlin)
X	{
X		temp = pg.lineno;
X		pg.lineno = 7;		/* fake out bottom checker */
X		dc.divert = 0;
X		q = divertbuf;
X
X		while(*q)
X		{
X			q = getl(q, buff);
X			putlin(buff, 0);
X		}
X
X		pg.lineno = temp + dc.divlin;
X		dc.divlin =
X		dc.divsav =
X		dc.divert = 0;
X		divpnt = divertbuf;
X		*divertbuf = 0;
X		setbot();
X	}
X}
X
X
X
Xboth()
X{
X	register int	i, j;
X
X	ofset();
X
X	if(inbuf[0])
X	{
X		i = width(inbuf);
X		j = 0;
X
X		while(inbuf[j])
X			prchar(inbuf[j++]);
X
X		inbuf[0] = 0;
X
X		if(i < dc.tival)
X			for(j = dc.tival - i; j > 0; --j)
X				prchar(' ');
X	}
X	else
X		for(j = 0; j < dc.tival; ++j)
X			prchar(' ');
X}
X
X
X
Xofset()
X{
X	register int	j;
X
X	for (j = 0; j < pg.offset; ++j)
X		prchar(' ');
X
X
X	for(j = 0; j < pg.eooset; ++j)
X		prchar(' ');
X}
X
X
X
X
X
Xclobber(h)
Xregister unsigned char	*h;
X{
X	register int	i;
X
X
X	for (i = MAXLINE - 4; ; --i)
X	{
X		if(isspace(h[i]))
X			h[i] = EOS;
X		else
X			break;
X	}
X
X	h[++i] = '\n';
X	h[++i] = EOS;
X}
X
X
X
Xblank(h)
Xregister unsigned char	*h;
X{
X	register int	i;
X
X	for (i = 0; i < MAXLINE; ++i)
X		h[i] = ' ';
X
X}
X
X
X
X
Xgetl(from, to)
Xregister unsigned char	*from, *to;
X{
X	while(*from)
X	{
X		*to++ = *from++;
X		*to = 0;
X
X		if(isterm(to[-1]))
X			return(from);
X	}
X
X	return(from);
X}
X
X
X
Xaddspace()
X{
X	if(dc.cuval || lastflag)
X		co.outbuf[co.outp++] = ' ' | 0x80;
X	else
X		co.outbuf[co.outp++] = ' ';
X}
X
X
Xchkbot()
X{
X	if(pg.lineno > pg.bottom)
X		pfoot();
X}
//go.sysin dd *
made=TRUE
if [ $made = TRUE ]; then
/bin/chmod 664 nrotxt.c
	/bin/echo -n '	'; /bin/ls -ld nrotxt.c
fi
/bin/echo 'Extracting nroindex.c'
sed 's/^X//' <<'//go.sysin dd *' >nroindex.c
X
X/*
X *	Index page processor for NRO text processor
X *
X *	Ron Light
X *	6016 Croftway Ct.
X *	Ft. Worth, Tx. 76131
X */
X
X#include <stdio.h>
X#include "nro.h"
X
X
Xextern	struct docctl	dc;
Xextern	struct page	pg;
Xextern	FILE		*pout;
Xextern	struct cout	co;
Xextern	struct macro	smac;
Xextern	struct file	file[];
Xextern	unsigned char	newext[];
Xextern	unsigned char	*divertbuf;
Xextern	unsigned char	*divpnt;
Xstatic	unsigned int	symcnt = 0;	/* index of current symbol */
Xstatic	unsigned int	symmax = 0;
Xstatic	SYM		*symbas = 0;	/* pointer to base of symbol table */
Xstatic	SYM		*symprv = 0;	/* pointer to previous symbol */
Xstatic	SYM		*symbeg = 0;	/* pointer to begin of symbols	*/
X
X
X
X
X/*
X *	Routine to check one entire line for any of the words
X *	that may be in the index table.
X */
X
Xcindex(p)
Xregister unsigned char	*p;
X{
X	register unsigned char	*q;
X	register int		i;
X	register SYM		*sp;
X		 unsigned char	buff[MAXLINE];
X		 unsigned char	wrdbuf[LNAME];
X
X	move(buff, p);
X	killcr(buff);
X	q = buff;
X
X	while((i = getwrd(q, wrdbuf)) > 0)
X	{
X		killpunc(wrdbuf);
X
X		if(sp = locate(wrdbuf, AUTO))
X			outref(sp);
X
X		q += i;
X	}
X}
X
X
X
X
X/*
X *	Routine to add one word to the index table.  If the word
X *	is already present, then add the current page number to
X *	the list.
X */
X
Xaddsym(p, flag, r)
Xregister unsigned char	*p;
Xregister unsigned int	flag, r;
X{
X	register SYM		*sp;
X		 unsigned char	buff[LNAME];
X
X
X	if(dc.indexx)
X	{
X		strncpy(buff, p, LNAME-1);
X		killcr(buff);
X
X		if(flag == AUTO)
X			oneword(buff);
X
X		if(sp = locate(buff, flag))
X		{
X			if(r)
X				outref(sp);
X		}
X		else
X			insert(buff, flag, r);
X	}
X}
X
X
X
X
X/*
X
X	locate --- locate a symbol in the symbol table
X
X	locate(name, flag)
X	char *name;
X	int  flag;
X
X	returns a pointer to the symbol if found in the table. if not
X	found, returns a null pointer. additionally sets up the index
X	of the entry in the global variable "symcnt", and the pointer
X	to the previous entry in the global variable "symprv".
X
X*/
X
X
Xstatic locate(name, flag)
Xregister unsigned char	*name;
Xregister unsigned char	flag;
X{
X	register SYM		*symcur, *symret;
X	register int		symcmp;
X
X
X	symcnt = 0;
X	symprv = SYMNUL;
X	symret = SYMNUL;
X
X	for (symcur = symbas; symcur != SYMNUL; symcur = symcur->nxtsym)
X	{
X		symcnt++;
X		symcmp = strcmp(name, symcur->name);
X
X		if (symcmp > 0)			/* not there yet */
X		{
X			symprv = symcur;	/* remember previous symbol */
X			continue;
X		}
X
X		if (symcmp < 0)			/* past it, not in table */
X			break;
X
X		symret = symcur;	/* found it */
X		break;
X	}
X
X	return(symret);
X}
X
X
X
X
X
X
X
X
X/*
X
X	insert --- insert a new entry into the symbol table
X
X	insert(name, flag, r)
X	char *name;
X	int  flag, r;
X
X	returns pointer to inserted entry, or a null pointer
X	if one of the following occurs:
X		1. asked to insert a null name.
X		2. name already exists in table.
X		3. couldn't allocate memory for entry.
X
X*/
X
X
Xstatic insert(name, flag, r)
Xregister unsigned char	*name;
Xregister unsigned int	flag, r;
X{
X	register SYM	*symcur;
X
X
X	if ((name[0] == '\0') || (locate(name, flag) != SYMNUL))
X		return(SYMNUL);
X
X
X	if(!(symcur = malloc(SYMSIZ)))		/* space for entry	*/
X		error("Can't allocate symbol space\n");
X	else
X	{
X		if(!(symcur->name = malloc(strlen(name)+1)))
X			error("Can't allocate name space\n");
X
X		strcpy(symcur->name, name);	/* put name in entry	*/
X		symcur->flag = flag;		/* auto/manual flag	*/
X		symcur->nxtref = 0;		/* no refferences yet	*/
X		++symmax;
X
X		if (symprv == SYMNUL)		/* first entry in list	*/
X		{
X			symcur->nxtsym = symbas;
X			symbas = symcur;
X		}
X		else				/* link into list	*/
X		{
X			symcur->nxtsym = symprv->nxtsym;
X			symprv->nxtsym = symcur;
X		}
X
X		symcur->nxtref = 0;
X
X		if(r)
X			outref(symcur);
X	}
X
X	return(symcur);
X}
X
X
X
X
Xstatic outref(sp)
XSYM	*sp;
X{
X	REF		*rp, *xp;
X
X
X	/* check to see if we're on the same page */
X	xp = sp->nxtref;
X
X	while(xp)
X	{
X		if(xp->ipage == pg.curpag)
X			return;
X		else if(xp->nextref == 0)
X			break;
X
X		xp = xp->nextref;
X	}
X
X	if(rp = malloc(REFSIZ))		/* allocate some space */
X	{
X		rp->ipage = pg.curpag;	/* store the page number */
X		rp->nextref = 0;	/* set end of refferences */
X	}
X	else
X		error("Can't allocate reference memory\n");
X
X	/* add refference to the linked list */
X	if(sp->nxtref)
X		xp->nextref = rp;
X	else
X		sp->nxtref = rp;
X}
X
X
X
X
X
X/*
X *	Print out the index page
X */
Xpindex()
X{
X	register	REF		*rp;
X	register	SYM		*symcur = symbas;
X			unsigned char	buffy[LNAME];
X			unsigned char	buffx[200];
X			unsigned char	h[MAXLINE];
X
X	if(!dc.indexx || !symcnt)
X		return;
X
X	dc.indexx =
X	dc.aindex = 0;
X
X
X	for(symcnt = 0; symcnt < symmax; symcnt++)
X	{
X		blank(h);
X		sprintf(buffx, "%s", symcur->name);
X		justleft(buffx, h, 0);
X		buffx[0] = 0;
X		rp = symcur->nxtref;
X
X		while(rp)
X		{
X			sprintf(buffy, "%u,", rp->ipage);
X			strcat(buffx, buffy);
X			rp = rp->nextref;
X		}
X
X		buffx[strlen(buffx) - 1] = 0;
X		justrite(buffx, h, dc.rmval - dc.inval);
X		ifill(h);
X		clobber(h);
X		put(h);
X		symcur = symcur->nxtsym;
X	}
X}
X
X
X
Xifill(pnt)
Xregister unsigned char	*pnt;
X{
X	while(*pnt)
X	{
X		if(iswhite(*pnt) && iswhite(pnt[1]) && iswhite(pnt[2]))
X			break;
X
X		++pnt;
X	}
X
X	while(*pnt && iswhite(*pnt))
X	{
X		*pnt = dc.ichr;
X		++pnt;
X	}
X}
X
X
X
Xmask(pnt)
Xregister unsigned char	*pnt;
X{
X	while(*pnt)
X	{
X		*pnt &= 0x7f;
X		++pnt;
X	}
X}
X
X
X
Xkillcr(p)
Xregister unsigned char	*p;
X{
X	register unsigned char	*pnt = p;
X
X
X	while(!isterm(*pnt))
X		++pnt;
X
X	while(pnt > p)
X	{
X		if(!isalpha(*pnt) && !isdigit(*pnt))
X			--pnt;
X		else
X			break;
X	}
X
X	*++pnt = 0;
X}
X
X
X
Xstatic oneword(pnt)
Xregister unsigned char	*pnt;
X{
X	unsigned char	buff[LNAME];
X
X	getwrd(pnt, buff);
X	strcpy(pnt, buff);
X	killpunc(pnt);
X}
X
X
X
Xstatic move(to, from)
Xregister unsigned char	*to, *from;
X{
X	register	int	i;
X
X
X	for(i = 0; i < MAXLINE; ++i)
X	{
X		if(!(*from))
X			break;
X
X		if(iscr(*from))
X			*to = ' ';
X		else if(*from == '\b')
X		{
X			++from;
X			continue;
X		}
X		else
X			*to = *from & 0x7f;
X
X		++to;
X		++from;
X	}
X
X	*to = 0;
X}
X
X
X
X
Xkillpunc(pnt)
Xregister unsigned char	*pnt;
X{
X	while(*pnt)
X	{
X		if(isalpha(*pnt) || isdigit(*pnt) || iswhite(*pnt)
X		   || *pnt == '-' || *pnt == '\'')
X			++pnt;
X		else
X			*pnt = 0;
X	}
X}
//go.sysin dd *
made=TRUE
if [ $made = TRUE ]; then
/bin/chmod 664 nroindex.c
	/bin/echo -n '	'; /bin/ls -ld nroindex.c
fi
--