PROFF - Portable ROFF (4 of 5)
Ozan Yigit
oz at yetti.UUCP
Tue Jan 14 15:01:19 AEST 1986
#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# putwrd.c
# pxlex.c
# pxxparse.c
# stack.c
# This archive created: Mon Jan 13 23:54:44 1986
export PATH; PATH=/bin:$PATH
echo shar: extracting "'putwrd.c'" '(980 characters)'
if test -f 'putwrd.c'
then
echo shar: over-writing existing file "'putwrd.c'"
fi
sed 's/^X//' << \SHAR_EOF > 'putwrd.c'
X
X
X
X
X#include <stdio.h>
X#include "proff.h"
X#include "debug.h"
X
X/*
X * putwrd - put a word in outbuf; includes margin justification
X *
X */
Xputwrd(wrdbuf)
Xchar wrdbuf[];
X{
X int last, llval, extra, w;
X
Xdprintf("putwrd ");
X w = width(wrdbuf);
X last = strlen(wrdbuf) + outp; /* new end of outbuf */
X#ifdef DEBUG
Xprintf("strlen(wrdbuf) = %d\n",strlen(wrdbuf));
X#endif
X llval = rmval - tival;
X if (outw + w > llval || last >= MAXOUT) { /* too big */
X last -= outp;
X extra = llval - outw;
X#ifdef DEBUG
Xprintf("extra = %d\n",extra);
X#endif
X for ( ; outp > 0; outp--)
X if (outbuf[outp-1] == ' ')
X extra++;
X else
X break;
X if (rjust == YES) {
X spread(outbuf, outp, extra, outwds);
X if (extra > 0 && outwds > 1)
X outp += extra;
X }
X brk(); /* flush previous line */
X }
X#ifdef DEBUG
Xprintf("putwrd: last=%d w=%d outp=%d llval=%d outw=%d extra=%d\n",
X last,w,outp,llval,outw,extra);
X#endif
X strcpy(&outbuf[outp],wrdbuf);
X outp = last;
X outw += w;
X outwds++;
X}
X
SHAR_EOF
if test 980 -ne "`wc -c 'putwrd.c'`"
then
echo shar: error transmitting "'putwrd.c'" '(should have been 980 characters)'
fi
echo shar: extracting "'pxlex.c'" '(3358 characters)'
if test -f 'pxlex.c'
then
echo shar: over-writing existing file "'pxlex.c'"
fi
sed 's/^X//' << \SHAR_EOF > 'pxlex.c'
X
X
X#include <stdio.h>
X#include <math.h>
X#include <ctype.h>
X
X/* translation table for control chars */
X
Xchar c_ctrl[] = {
X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X 0, 0, 0, 0, 0, 0, 0, 0,
X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
X 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
X 23, 25, 26, 27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5,
X 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
X 20, 21, 22, 23, 24, 25, 26, 0, 0, 0, 0, 0
X };
X
X/*
X * getval - evaluate optional numeric argument
X *
X * increments i
X */
Xint
Xgetval(buf,i,argtyp)
Xchar buf[];
Xint *i;
Xint *argtyp;
X{
X int j,k;
X
X j = *i;
X k = *argtyp;
X
X skipbl(buf, &j);
X k = buf[j];
X if (k == '+' || k == '-')
X j++;
X *i = j;
X *argtyp = k;
X return(ctoi(buf,i));
X}
X
X/*
X * getarg - get the next argument from the buffer
X *
X * return values: -1 - no argument
X * n - number of chars in argument
X *
X * also handles quoted ("..") strings. If a quote is wanted
X * in the string, use "" or \". quotes are stripped.
X *
X * argument delimiters: blank, tab or comma (,).
X *
X * increments i
X *
X */
Xint
Xgetarg(buf,i,arg)
Xchar buf[];
Xint *i;
Xchar arg[];
X{
X int j,k;
X register char ch;
X
X j = *i;
X
X k = -1;
X skipbl(buf,&j);
X if (buf[j] != '\0') {
X k = 0;
X if (buf[j] == '\"') {
X j++;
X while (buf[j] != '\0') {
X if (buf[j] == '\"') {
X if (buf[j+1] == '\"') {
X arg[k++] = '\"';
X j += 2;
X }
X else
X break;
X }
X arg[k++] = buf[j++];
X }
X arg[k] = '\0';
X j++; /* skip the quote */
X /* peek next char */
X if (isalnum(buf[j]))
X error("improper argument list.");
X j++; /* skip the delimeter */
X }
X else {
X ch = buf[j];
X while (ch != ' '&&
X ch != '\t' &&
X ch != ',' &&
X ch != '\r' &&
X ch != '\n' &&
X ch != '\0') {
X arg[k++] = buf[j++];
X ch = buf[j];
X }
X arg[k] = '\0';
X if (ch != '\0') /* if non-null delimiter, skip */
X j++;
X }
X *i = j;
X }
X return(k);
X}
X
X/*
X * getpstr - get a special string to print out
X *
X */
Xgetpstr(buf,out)
Xregister char *buf;
Xregister char *out;
X{
X register int i;
X register char c, cc;
X register char *num;
X char numbuf[9];
X
X while(*buf != '\n' && *buf != '\0') {
X c = *buf;
X switch(c) {
X case ' ':
X case '\t':
X while (*buf == ' ' || *buf == '\t')
X buf++; /* skip blanks */
X break;
X case '\\':
X if (*(buf+1) != '\0') {
X *out++ = *(buf+1);
X buf += 2;
X }
X else
X buf++;
X break;
X case '^':
X if ((cc = c_ctrl[*(buf+1)]) != 0)
X *out++ = cc;
X buf += 2;
X break;
X case '\"':
X buf++; /* skip the quote */
X while (*buf != '\0') {
X if (*buf != '\"')
X *out++ = *buf++;
X else if (*(buf+1) == '\"') {
X *out++ = '\"';
X buf += 2;
X }
X else
X break;
X }
X buf++; /* skip the quote */
X break;
X case '0':
X case '1':
X case '2':
X case '3':
X case '4':
X case '5':
X case '6':
X case '7':
X case '8':
X case '9':
X num = numbuf;
X while (isdigit(*buf))
X *num++ = *buf++;
X *num = '\0';
X if ((i = atoi(numbuf)) > 256)
X error("non-ascii char value in write string.");
X else if (i > 0) /* do not output null */
X *out++ = (char) i;
X break;
X default:
X *out++ = *buf++;
X }
X }
X *out = '\0';
X}
X
SHAR_EOF
if test 3358 -ne "`wc -c 'pxlex.c'`"
then
echo shar: error transmitting "'pxlex.c'" '(should have been 3358 characters)'
fi
echo shar: extracting "'pxxparse.c'" '(9576 characters)'
if test -f 'pxxparse.c'
then
echo shar: over-writing existing file "'pxxparse.c'"
fi
sed 's/^X//' << \SHAR_EOF > 'pxxparse.c'
X#include <stdio.h>
X#include <ctype.h>
X#include "proff.h"
X#include "debug.h"
X#include "lextab.h"
X
X#define RUNOFF 1 /* recognise RUNOFF commands */
X
Xchar literal = NO; /* literal flag */
X
X/*
X * command - perform formatting command
X *
X */
Xcommand(buf)
Xchar buf[];
X{
X char token[MAXTOK], xtoken[MAXTOK], variable[MAXTOK], *defn;
X char special[MAXTOK];
X int argtyp, ct, at, spval, i, flags;
X register int val, n, rest;
X char onflag = FALSE;
X char offlag = FALSE;
X struct lexlist *xp;
X
X dovar(tbuf1,buf); /* use scratch buffer to expand variables */
X strcpy(buf,tbuf1);
X
X i = 1;
X n = getwrd(buf, &i, token); /* get the command token */
X rest = i; /* remaining string */
X ct = comtype(token, n, &defn, &flags);
X if (ct == UNKNOWN)
X return;
X if (literal && ct != ELT) { /* ignore while literal */
X put(buf);
X return;
X }
X
X#ifdef DOUBLEWORD
X if (flags == 2) { /* check for 2-word command */
X n = getwrd(buf, &i, xtoken);
X if (n == 0) {
X fprintf(stderr,"%c%s what ?\n", cchar, token);
X return;
X }
X if ((at = comtype(xtoken, n, &defn, &flags)) == UNKNOWN) {
X fprintf(stderr,"%c%s %s unknown.\n", cchar,
X token,
X xtoken);
X return;
X }
X else
X ct += at;
X }
X#endif
X
X doesc(buf, variable, MAXLINE); /* expand escapes */
X n = getarg(buf, &i, xtoken); /* first parameter*/
X argtyp = '\n'; /* defaulted ** cludge ** */
X val = 0;
X if (n > 0) {
X if (*xtoken == '+' || *xtoken == '-') {
X argtyp = *xtoken;
X val = atoi(xtoken+1);
X }
X else if (isdigit(*xtoken)) {
X argtyp = 0;
X val = atoi(xtoken);
X }
X else {
X /* check some common flags */
X if (strcmp("on",xtoken) == 0)
X onflag = TRUE;
X else if (strcmp("off",xtoken) == 0)
X offlag = TRUE;
X }
X }
X
X switch(ct) {
X
X case MACRO:
X eval(buf, defn);
X break;
X case FI:
X brk();
X fill = YES;
X break;
X case NF:
X brk();
X fill = NO;
X break;
X case BR:
X brk();
X break;
X case LS:
X set(&lsval, val, argtyp, 1, 1, HUGE);
X break;
X case CE:
X brk();
X if (onflag)
X CEon = TRUE;
X else if (offlag) {
X CEon = FALSE;
X ceval = 0; /* reset */
X }
X else
X set(&ceval, val, argtyp, 1, 0, HUGE);
X break;
X case UL:
X if (onflag) {
X ULon = TRUE;
X break;
X }
X else if (offlag) {
X ULon = FALSE;
X ulval = 0; /* reset */
X break;
X }
X else
X set(&ulval, val, argtyp, 0, 1, HUGE);
X
X if (!isdigit(*xtoken)) {
X if (strcmp("all",xtoken) == 0) {
X ulblnk = '_';
X ulval = 0;
X }
X else if (strcmp("words",xtoken) == 0) {
X ulblnk = ' ';
X ulval = 0;
X }
X }
X break;
X case BD:
X if (bolding == YES) {
X if (onflag)
X BDon = TRUE;
X else if (offlag) {
X BDon = FALSE;
X boval = 0; /* reset */
X }
X else
X set(&boval, val, argtyp, 0, 1, HUGE);
X }
X break;
X case HE:
X gettl(buf, ehead, ehlim);
X gettl(buf, ohead, ohlim);
X break;
X case FO:
X gettl(buf, efoot, eflim);
X gettl(buf, ofoot, oflim);
X break;
X case BP:
X if (paging == NO)
X break;
X brk();
X if (lineno > 0)
X space(HUGE);
X set(&curpag, val, argtyp, curpag+1, -HUGE, HUGE);
X newpag = curpag;
X break;
X case SP:
X set(&spval, val, argtyp, 1, 0, HUGE);
X space(spval);
X break;
X case IN:
X brk();
X set(&inval, val, argtyp, 0, 0, rmval-1);
X tival = inval;
X break;
X case RM:
X set(&rmval, val, argtyp, PAGEWIDTH, tival+1, HUGE);
X break;
X case TI:
X brk();
X set(&tival, val, argtyp, 0, 0, rmval);
X break;
X case LEX: /****/
X if ((xp = remove(xtoken,lextab)) != NULL) {
X if (getwrd(buf, &i, variable) != 0)
X lexinstal(variable,xp->val,xp->flag,lextab);
X }
X else
X fprintf(stderr,"%s undefined.\n",xtoken);
X break;
X case PN: /****/
X if (strcmp(xtoken,"roman") == 0)
X roman = TRUE;
X else if (strcmp(xtoken,"arabic") == 0)
X roman = FALSE;
X else
X fprintf(stderr,"%c%s does not have %s option.\n",
X cchar,token,xtoken);
X break;
X case IG: /****/
X break;
X case SET: /****/
X if (n > 0) {
X if (isdigit(*xtoken)) {
X fprintf(stderr,"illegal variable name %s\n",
X xtoken);
X break;
X }
X *variable = '\0';
X n = getarg(buf, &i, variable);
X if (n <= 0) {
X fprintf(stderr,"%s: ", xtoken);
X gets(variable);
X
X }
X if (*variable != '\0')
X install(xtoken, variable, gentab);
X }
X else
X fprintf(stderr,"%c%s needs a variable name.\n",
X cchar, token);
X break;
X case GET: /****/
X if (n > 0) {
X if (isdigit(*xtoken)) {
X fprintf(stderr,"illegal variable name %s\n",
X xtoken);
X break;
X }
X *variable = '\0';
X n = getarg(buf, &i, tbuf3); /* using temp buf3 */
X if (n > 0) {
X fprintf(stderr,"%s", tbuf3);
X gets(variable);
X
X }
X if (*variable != '\0')
X install(xtoken,variable, gentab);
X }
X else
X fprintf(stderr,"%c%s needs a variable name.\n",
X cchar, token);
X break;
X case CL: /****/
X if (argtyp == '\n') {
X clast->level = 0;
X clast->str = NULL;
X }
X else {
X skipbl(buf,&i);
X if (*(buf+i) == '\0')
X break; /* no contents line here ! */
X clast->level = val * 3; /* level * indent */
X n = i;
X while(*(buf+n) != '\n')
X n++;
X *(buf+n) = '\0'; /* destroy CR with a null */
X clast->str = strsave(buf+i);
X clast->page = curpag;
X }
X clast->nextc = (struct clist *) malloc(sizeof(struct clist));
X p_memoryus += sizeof(struct clist);
X clast = clast->nextc;
X clast->nextc = NULL;
X break;
X case PC: /****/
X brk();
X clast = chead;
X while(clast->nextc != NULL) {
X if (clast->str == NULL)
X put("\n");
X else {
X tival = (int) clast->level + inval;
X i = rmval - tival;
X docline(variable, i, clast->str, clast->page);
X put(variable);
X }
X clast = clast->nextc;
X }
X break;
X case DBO: /****/
X bolding = NO;
X break;
X case EBO: /****/
X bolding = YES;
X break;
X case AP: /****/
X autopar = YES;
X break;
X case NAP: /****/
X autopar = NO;
X break;
X case SAV: /****/
X brk();
X save();
X break;
X case RST: /****/
X brk();
X restore();
X break;
X case NPA: /****/
X paging = NO;
X savpl = plval;
X plval = HUGE;
X bottom = plval - m3val - m4val;
X break;
X case PGI: /****/
X bottom = lineno - 1; /* force end-of-page */
X brk();
X plval = savpl;
X break;
X case LTR: /****/
X brk();
X if (save()) {
X inval = 0;
X rmval = 132;
X autopar = NO;
X lsval = 0;
X fill = NO;
X literal = YES;
X }
X break;
X case ELT: /****/
X restore();
X literal = NO;
X break;
X case WR: /****/
X brk();
X getpstr(buf+rest,special);
X defn = special;
X while(*defn)
X putchar(*defn++);
X break;
X case PL:
X if (paging == NO)
X break;
X set(&plval, val, argtyp, PAGELEN,
X m1val + m2val + m3val + m4val + 1, HUGE);
X bottom = plval - m3val - m4val;
X break;
X case PO:
X set(&offset, val, argtyp, 0, 0, rmval - 1);
X break;
X case M1:
X set(&m1val, val, argtyp, 3, 0,
X plval - m2val - m3val - m4val - 1);
X break;
X case M2:
X set(&m2val, val, argtyp, 2, 0,
X plval - m1val - m3val - m4val - 1);
X break;
X case M3:
X set(&m3val, val, argtyp, 2, 0,
X plval - m1val - m2val - m4val - 1);
X bottom = plval - m3val - m4val;
X break;
X case M4:
X set(&m4val, val, argtyp, 3, 0,
X plval - m1val - m2val - m3val - 1);
X bottom = plval - m3val - m4val;
X break;
X case EH:
X gettl(buf, ehead, ehlim);
X break;
X case OH:
X gettl(buf, ohead, ohlim);
X break;
X case EF:
X gettl(buf, efoot, eflim);
X break;
X case OF:
X gettl(buf, ofoot, oflim);
X break;
X case CC:
X cchar = *xtoken;
X if (cchar == '\0' || cchar == '\n')
X cchar = '.';
X if ((lineno + val) > bottom && lineno <= bottom) {
X space(val);
X lineno = 0;
X }
X break;
X case EC:
X genesc = *xtoken;
X if (genesc == '\0' || genesc == '\n')
X genesc = '_';
X break;
X case NE:
X if ((lineno + val) > bottom && lineno <= bottom) {
X space(val);
X lineno = 0;
X }
X break;
X case BS:
X set(&bsval, val, argtyp, 1, 0, HUGE);
X break;
X case JU:
X rjust = YES;
X break;
X case NJ:
X rjust = NO;
X break;
X case SO:
X if (n <= 0)
X return;
X if (level + 1 == NFILES)
X error("? SO commands nested too deeply.");
X if ((infile[level + 1] = fopen(xtoken, "r")) != NULL) {
X level++;
X if (verbose == YES)
X#ifdef rainbow
X fprintf(stderr,"source \033[7m%s\033[0m\n",
X xtoken);
X#else
X fprintf(stderr,"source %s\n",xtoken);
X#endif
X }
X else
X fprintf(stderr,"%s: cannot open.\n",xtoken);
X break;
X case OU: /*****/
X /* skip for now. */
X break;
X
X case OE: /*****/
X /* skip for now. */
X break;
X
X case CU:
X ulblnk = '_';
X set(&ulval, val, argtyp, 0, 1, HUGE);
X break;
X case DE:
X dodef(buf, infile[level]);
X break;
X case NR:
X if (n <= 0)
X return;
X if (*xtoken < 'a' || *xtoken > 'z')
X error("invalid number register [%c].",*xtoken);
X
X val = getval(buf, &i, &argtyp);
X set(&nr[xtoken[0] - 'a'], val, argtyp, 0, -HUGE, HUGE);
X break;
X case ST:
X if (argtyp == '-')
X spval = plval;
X else
X spval = 0;
X set(&spval, val, argtyp, 0, 1, bottom);
X if (spval > lineno && lineno == 0)
X phead();
X if (spval > lineno)
X space(spval - lineno);
X break;
X case RESET: /****/
X finit();
X break;
X default:
X error("? Botch in command.");
X break;
X }
X}
X
X/*
X * comtype - decode the command type
X *
X */
Xint
Xcomtype(buf, siz, defn, flags)
Xchar buf[];
Xint siz;
Xchar **defn;
Xint *flags;
X{
X
X struct hashlist *np;
X struct lexlist *xp;
X extern struct lexlist *lexlook();
X int i,comtyp;
X char c1,c2;
X
X
X#ifdef DEBUG
X printf("comtype: %s (token)\n",token1);
X#endif
X
X if ((np = lookup(buf, macrotab)) != NULL) {
X *defn=np->def;
X return(MACRO);
X }
X comtyp = UNKNOWN;
X
X if (*buf == '#' || *buf == '!')
X return(comtyp);
X
X if ((xp = lexlook(buf,lextab)) != NULL)
X if (onlyrunoff && (xp->flag != RUNOFF)) {
X fprintf(stderr,"%c%s is not a runoff command.\n",
X cchar,buf);
X return(UNKNOWN);
X }
X else {
X comtyp = xp->val;
X *flags = xp->flag;
X }
X
X if (comtyp == UNKNOWN)
X fprintf(stderr,"unknown command %c%s\n",cchar,buf);
X return(comtyp);
X}
SHAR_EOF
if test 9576 -ne "`wc -c 'pxxparse.c'`"
then
echo shar: error transmitting "'pxxparse.c'" '(should have been 9576 characters)'
fi
echo shar: extracting "'stack.c'" '(1911 characters)'
if test -f 'stack.c'
then
echo shar: over-writing existing file "'stack.c'"
fi
sed 's/^X//' << \SHAR_EOF > 'stack.c'
X
X
X#include <stdio.h>
X#include "proff.h"
X
Xstruct _proffitem {
X int Xinval;
X int Xrmval;
X int Xoffset;
X int Xlsval;
X int Xplval;
X int Xm1val;
X int Xm2val;
X int Xm3val;
X int Xm4val;
X int Xfill;
X int Xrjust;
X
X char Xcchar;
X char Xgenesc;
X char Xroman;
X char Xbolding;
X char Xpaging;
X char Xautopar;
X
X struct _proffitem *prev;
X};
X
Xstatic struct
X_proffitem *head = NULL;
Xstatic struct
X_proffitem *top = NULL;
X
X
Xchar *pusherr = "save: stack overflow.\n";
Xchar *poperr = "restore: stack underflow.\n";
X
X/*
X * save - save proff parameters
X *
X */
Xsave()
X{
X struct _proffitem *sp;
X char *malloc();
X
X if ((sp = (struct _proffitem *) malloc(sizeof(*sp))) == NULL) {
X fprintf(stderr,pusherr);
X return(FALSE);
X }
X else {
X p_memoryus += sizeof(struct _proffitem);
X if (head == NULL) { /* first element in stack */
X head = sp;
X top = NULL;
X }
X
X sp->Xinval = inval;
X sp->Xrmval = rmval;
X sp->Xoffset= offset;
X sp->Xlsval = lsval;
X sp->Xplval = plval;
X sp->Xm1val = m1val;
X sp->Xm2val = m2val;
X sp->Xm3val = m3val;
X sp->Xm4val = m4val;
X sp->Xfill = fill;
X sp->Xrjust = rjust;
X sp->Xcchar = cchar;
X sp->Xgenesc= genesc;
X sp->Xroman = roman;
X sp->Xbolding = bolding;
X sp->Xpaging = paging;
X sp->Xautopar = autopar;
X
X sp->prev = top;
X top = sp;
X }
X return(TRUE);
X}
X
Xrestore()
X{
X struct _proffitem *sp;
X
X if (top != NULL) {
X
X inval = top->Xinval;
X rmval = top->Xrmval;
X offset= top->Xoffset;
X lsval = top->Xlsval;
X plval = top->Xplval;
X m1val = top->Xm1val;
X m2val = top->Xm2val;
X m3val = top->Xm3val;
X m4val = top->Xm4val;
X fill = top->Xfill;
X rjust = top->Xrjust;
X cchar = top->Xcchar;
X genesc= top->Xgenesc;
X roman = top->Xroman;
X bolding = top->Xbolding;
X paging = top->Xpaging;
X autopar = top->Xautopar;
X
X sp = top->prev;
X free(top);
X p_memoryus -= sizeof(struct _proffitem);
X if ((top = sp) == NULL)
X head = NULL;
X }
X else
X fprintf(stderr,poperr);
X}
SHAR_EOF
if test 1911 -ne "`wc -c 'stack.c'`"
then
echo shar: error transmitting "'stack.c'" '(should have been 1911 characters)'
fi
# End of shell archive
exit 0
--
Usenet: [decvax|allegra|linus|ihnp4]!utzoo!yetti!oz
Bitnet: oz@[yusol|yuyetti]
In the beginning, there was Word all right, except
it wasn't fixed number of bits.
More information about the Comp.sources.unix
mailing list