[net.micro.atari16] Scribble-->Proff

RDROYA01@ULKYVX.BITNET (Robert Royar) (10/14/86)

#       This is a shell archive.
#       Remove everything above and including the cut line.
#       Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:    Shell Archiver
#       Run the following text with /bin/sh to create:
#       readme
#       scribe.h
#       scribe.c
#       scribe.mac
# This archive created: Mon Oct 13 21:03:36 1986
sed 's/^x//' << \SHAR_EOF > readme
xScribe-->Proff v. 2
x
xThis is an update of my preliminary posting and includes a number of
xenhancements.  The program now supports "devices" via the @device() command.
xThere is an array of structures in device.c that can be edited to add more
xdevices (only Brother/Diablo daisy wheel printers are fully supported).  The
xfile var.c includes the dynamic memory allocator, lookup, and installation
xfor the string, value, and index commands.  The chapter and section commands
xalso use the variable table maintained by the routines in var.c.
x
xTwo new commands in device.c allow you to modify the pitch and line height
xon your printer, assuming it has minimum horizontal and vertical movement
xstrings.  They take integers as arguments in the style of WordStar (i.e.
x@pitch(10) sets your printer to 12 pitch, and @height(8) sets the line
xheight to 6 lines per inch.  The @sub(text) command creates a subscript out
xof 'text' and @super(text) superscripts the text.  If your printer is
xdefined as a DEVPLN (see scribe.h) these commands turn into null strings.
xIf, on the other hand, you have a DEVFNCY, the program will insert the
xcontrol codes that you have defined for your printer for the commands (and
xthe @u() @b() commands).
x
xCaveats:
x
xSince device.c has the actual ASCII printer codes in it, you may need
xto device.c to repair any mailer changes.
x
xUsing the @u() and @b() commands changes your line length in such a way that
xproff can no longer justify the line fully.  That's why this program forces
xproff to default to .nj rather than .ju.
x
xCurrently the index command simply writes the indexed word to a file with
xthe name infilename.NDX and does nothing more.  This is as far as the
xpreprocessor can go because it doesn't know about proff's final page
xnumbers.
x
xThe @enumerate() command does not always format the enumerated environment
xas desired; it indents the paragraph by one character.
x
xWhile the @need() command always gets through, proff disregards it at times.
x
xThe size of a single environment is limited to 32K simply because I was too
xlazy to figure out a dynamic allocation function for lines.  It just uses a
xgiant static array, much larger than most should need.  But forgetting to
xclose an environment can lead to overwriting a buffer if your file is large
xenough (probably about 30K or so).  I've used it on 50K texts without
xproblem, but I'm rather religious about fences since GNU_EMACS understands
x@environment{} names.
x
xChapter, section, and string variable values are stored in static arrays
xinside a circularly linked list of variable structures.  Values are limited
xto 255 characters, but no checking is done.  Labels are limited to 31
xcharacters.
x
xThis is a one pass preprocessor.  Environments can be nested, but string
xvariables cannot contain references to other variables.  Example
x@string(name="Neil") @string(atarirep=name) "The Atari rep is
x@value(atarirep)" will not work as expected.
x
xThe @include(file) command does not really include the file; it just tells
xproff to do so.  If the included file also contains directives for this
xprogram, it will need to be processed before proff includes it.
x
xThe argv parser creates an outfilename based on the infilename.  Example if
xoutfile == FILE.MSS, the program will write out a file FILE.PRF to the same
xdrive and directory.  If the @index() commands shows up, the file FILE.NDX
xwill be created.  The program only uses four files because it frees up the
xstandard I/O files to use putchar(), getchar(), etc.  for I/O.
x
xIt also looks into the STREAM structure, so if you have a braindamaged
xcompiler that doesn't let you find stdout->ptr you'll have to repair
xlastchar in envir.c.
x
xComing attractions:
x
x@case{atarirep,
x
xNeil, "Write this out to the file."
x
xJohn, "But don't write this."
x
xNULL, "[]".
x
xelse, "Got no name for atarirep."}
x
x@style(linewidth 39 pica) Style commands aren't too useful if you can't use
xpicas, micas, and ems.
x
x@time(GMT) (i.e. insert time using GMT standard.  This assumes you've set
xthe default time and the formatter time flag with the @style(time EST).)
x
x@note(Make this a fottnote, endnote, or inline note)  Endnote and inline are
xeasy, but footnote is real hard.
x
xI hope someone finds this program useful.
x
xRobert Royar
x
xrdroya01@ulkyvx.bitnet
x
SHAR_EOF
sed 's/^x//' << \SHAR_EOF > scribe.h
x/* Header for scribe modules */
x#include <stdio.h>
x
x#define MAXTEXT 32768  /* an array to hold environment for text */
x#define DEFLFT 0       /* default left margin */
x#define DEFRHT 65      /* default right margin */
x#define DEFSPC 1       /* default line spacing */
x#define DEFPRN "plain" /* default printer name */
x#define DEFFIL ".nj\n.ap"      /* default fill parameters */
x#define DEFPGL 66      /* default page length */
x#define DEVPLN 1       /* our output device is plain */
x#define DEVFNCY 0      /* our output device is fancy */
x#define VARNUM 2       /* the variable is a number */
x#define VARSTR 1       /* the variable is a string */
x#define VARNDX         0       /* the variable is indexed  */
x#define NVARTBL        128     /* static arrays for variables */
x
xextern int pglen;      /* current page length */
xextern int rghmrg;     /* current right margin */
xextern int lftmrg;     /* current left margin */
xextern int lspcng;     /* current line spacing */
xextern int pmrg;       /* current paragraph margin (.ti) */
x
x/* variables mostly assigned in var.c */
x
xextern char curvlbl[32];       /* current variable label       */
xextern char cursval[256];      /* value of string or index variable */
xextern int curnval;            /* current int variable */
xextern int pagenum;            /* useless page number var for later */
xextern int chapnum;            /* chapter variable for @chapter() */
xextern int sectnum;
xextern char title[256];
xextern char chaptitle[256];
xextern char secttitle[256];
x
xextern char text[MAXTEXT];
xextern int fence;
xextern char command[15];
xextern unsigned int txtind;
xextern int ndxfile;
xextern FILE *ndxfp;
xextern char ofname[80];
xextern char ifname[80];
xextern char *strcat(), *strcpy(), *rindex();
xextern FILE *fopen(), *freopen();
x
x/* printer strings assigned in device.c */
x
xextern char prnname[15];
xextern char bdon[15];
xextern char bdoff[15];
xextern char ulon[15];
xextern char uloff[15];
xextern char pinit[15];
xextern char preset[15];
xextern char ptch[15];
xextern char lhght[15];
xextern int  devflag;   /* type of current output device */
x
x/* structure used by var.c functions to create and maintain a variables'
x * list.
x */
x
xtypedef struct VARTBL  {
x       struct  VARTBL  *v_fp;
x       struct  VARTBL  *v_bp;
x       char    label[32];
x       char    svalue[256];
x       int     nvalue;
x       int     type;
x}      VARTBL;
x
xextern VARTBL  *valloc(), *getvar();
SHAR_EOF
sed 's/^x//' << \SHAR_EOF > scribe.c
x/* scribe.c preprocessor for proff to convert scribble files to proff */
x
x#include "scribe.h"
x#include <ctype.h>
x
xint pglen = DEFPGL;    /* current page length */
xint rghmrg = DEFRHT;   /* current right margin */
xint lftmrg = DEFLFT;   /* current left margin */
xint lspcng = DEFSPC;   /* current line spacing */
xint pmrg = DEFLFT;     /* current paragraph margin (.ti) */
x
xchar command[15];      /* current command name */
xint fence;             /* expected terminating fence for current env. */
xunsigned int txtind;   /* index to current place in text array */
xchar text[MAXTEXT];    /* an array to hold all the text you want */
xchar ofname[80];
xchar ifname[80];
x
xmain(argc,argv)
xint argc;
xchar *argv[];
x{
x
x       register int c;
x
x       fprintf(stderr,"Scribble --> Proff %c 1986\n\n",0xbd);
x       if (argc < 2) {
x               fprintf(stderr,"usage: SCRIBE infile\n");
x               exit(1);
x       }
x       makename(argv[1]);
x       if (freopen(ifname,"r",stdin) != stdin) {
x               fprintf(stderr,"SCRIBE cannot read from file %s\n",ifname);
x               exit(1);
x       }
x       if (freopen(ofname,"w",stdout) != stdout) {
x               fprintf(stderr,"SCRIBE cannot write to file %s\n",ofname);
x               exit(1);
x       }
x       initdef();
x       initvar();
x       fprintf(stderr,"Formatting: %s\nOutput : %s\nDevice: %s\n",
x       ifname,ofname,prnname);
x       while ((c=getchar())!=EOF) {
x               if (c == '@')   {
x                       fence = getcmd(TRUE);
x                       execute(TRUE);
x               }
x               else
x                       putchar(c);
x       }
x       if (ndxfile == YES)
x               fclose(ndxfp);
x       exit(0);
x}
x
xmakename(name)
xchar name[];
x{
x       char *ptr;
x
x       strcpy(ifname,name);
x       strcpy(ofname,name);
x       if ((ptr = rindex(ofname, '.')) != NULL)
x               ptr[0] = '\0';
x       strcat(ofname,".PRF");
x       return;
x}
x
xinitdef()
x{
x       printf(".po %d\n.rm %d\n.ls %d\n.pl %d\n",lftmrg,rghmrg,lspcng,pglen);
x       puts(DEFFIL);
x       strcpy(prnname,DEFPRN);
x       setdvc(TRUE);
x       return;
x}
x
xgetcmd(f)
xint f;
x{
x       register int c;
x       register int i;
x       i = 0;
x
x       switch (f)
x               {
x               case TRUE:      {
x                               while ((c=getchar())!=EOF)
x                                       if (isalpha(c)){
x                                               command[i++] = c;
x                                       }
x                                       else
x                                               break;
x                               command[i] = '\0';
x                               break;
x                       }
x               case FALSE:     {
x                               while ((c=text[++txtind]))
x                                       if (isalpha(c)){
x                                               command[i++] = c;
x                                       }
x                                       else {
x                                               ++txtind;
x                                               break;
x                                       }
x                               command[i] = '\0';
x                               break;
x                       }
x               default:        c = -1; break;  /* basic error */
x               }
x       /* return closing fence */
x       if (c == (int)'[')
x               return((int)']');
x       else if (c == (int)'(')
x               return((int)')');
x       else if (c == (int)'{')
x               return((int)'}');
x       else if (c == (int)'<')
x               return((int)'>');
x       else
x               return(-1);     /* error */
x}
x
xgettext()
x{
x       register int c;
x
x       txtind = 0;     /* reset index */
x
x       while ((c=getchar())!=EOF) {
x               if (c == fence)
x                       break;
x               text[txtind++] = c;
x       }
x       text[txtind] = '\0';
x       txtind = 0;     /* reset counter for next function */
x       return(c);      /* c == closing fence */
x}
x
xerror()
x{
x       fprintf(stderr,"\nEnvironment not closed : %s\n", command);
x       return;
x}
x
xfatal()
x{
x       fprintf(stderr,"Fatal error in style command.\nCannot parse:\n%s",text);
x       exit(1);
x}
x
SHAR_EOF
sed 's/^x//' << \SHAR_EOF > scribe.mac
x.! ----------- macros ----------
x.! sect - produce a bold section header and
x.! enter a contents line. First parameter
x.! is indent level for contents line.
x.define sect
x.sp
x.cl $1 $2 $3 $4 $5 $6 $7 $8 $9
x$2 $3 $4 $5 $6 $7 $8 $9
x.en
x.!
x.! macros to create a point-form lists.
x.!------------
x.define list
x.br
x.ls 1
x.in +6
x.en
x.!------------
x.define item
x.br
x.ls 1
x.ti -3
x$1
x.en
x.!------------
x.define nolist
x.in -6
x.ls 2
x.en
x.!------------
SHAR_EOF
#       End of shell archive
exit 0
%NONAME-W-NOMSG, Message number 00000000
%SYSTEM-F-NOLOGNAM, no logical name match

RDROYA01@ULKYVX.BITNET (Robert Royar) (10/14/86)

#       This is a shell archive.
#       Remove everything above and including the cut line.
#       Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:    Shell Archiver
#       Run the following text with /bin/sh to create:
#       envir.c
#       device.c
# This archive created: Mon Oct 13 21:04:59 1986
sed 's/^x//' << \SHAR_EOF > envir.c
x/* envir.c  major and minor environments for scribble -> proff preprocessor */
x
x#include "scribe.h"
x
xstyle(f)
xint f;
x{
x       char stylstr[512];
x       register int i;
x       register int c;
x       int myfence;
x
x       i = 0;
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence) {
x                       error();
x                       fatal();
x                       }
x       while ((c=text[txtind]) != myfence)
x               stylstr[i++] = text[txtind++];
x       ++txtind;
x       stylstr[i] = '\0';
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       printf("@style(%s)\n",stylstr);
x       return(TRUE);
x}
x
xsp(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0': fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       fputs(".sp",stdout);
x       while ((c=text[txtind]) != myfence)
x               fputc(text[txtind++],stdout);
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       return(TRUE);
x}
x
xux(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0': fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".ul all\n.ul on",stdout);
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               fputc(text[txtind++],stdout);
x       }
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".ul off");
x       return(TRUE);
x}
x
xinclude(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0': fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       fputs(".source ",stdout);
x       while ((c=text[txtind]) != myfence)
x               fputc(text[txtind++],stdout);
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       return(TRUE);
x}
x
xvrbate(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0': fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".save\n.nap\n.nf\n.ls 1");
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               fputc(text[txtind++],stdout);
x       }
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".restore");
x       return(TRUE);
x}
x
xenumer(f)
xint f;
x{
x       register int c;
x       int myfence;
x       register int i;
x
x       i = 1;
x       myfence = (f == TRUE ? '\0': fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       fputs(".save\n.list\n.item 1.",stdout);
x       if (text[txtind] != '\n')
x               putchar('\n');
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               fputc(text[txtind++],stdout);
x               if (lastchar(stdout) == '\n' && text[txtind] == '\n')
x                       printf(".item %d.",++i);
x       }
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".nolist\n.restore");
x       return(TRUE);
x}
x
xquote(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".save\n.in +5\n.rm -5\n.ls 1");
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               fputc(text[txtind++],stdout);
x       }
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".restore"); /* turn it off */
x       return(TRUE);
x}
x
xitemz(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0': fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       fputs(".save\n.list\n.br\n.item -  ",stdout);
x       if (text[txtind] != '\n')
x               putchar('\n');
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               fputc(text[txtind++],stdout);
x               if (lastchar(stdout) == '\n' && text[txtind] == '\n')
x                       fputs(".item - ",stdout);
x       }
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".nolist\n.restore");
x       return(TRUE);
x}
x
xundent(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0': fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".in +5\n.ti -5");
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               fputc(text[txtind++],stdout);
x               if (lastchar(stdout) == '\n' && text[txtind] == '\n')
x                       fputs(".ti -5",stdout);
x       }
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".in -5");
x       return(TRUE);
x}
x
xunbound(f)
xint f;
x{
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       printf(".%s\n",command); /* turn on command */
x       return(TRUE);
x}
x
xsubh(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".ul all\n.sp 2\n.ul on");
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               fputc(text[txtind++],stdout);
x       }
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".ul off\n.sp 2");
x       return(TRUE);
x}
x
xhead(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(".sp 4\n.ce on");
x       puts(bdon);
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               fputc(text[txtind++],stdout);
x       }
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       puts(bdoff);
x       puts(".ce off\n.sp 2");
x       return(TRUE);
x}
x
xnewpage()
x{
x       putchar('\n');
x       puts(".bp");
x       return(TRUE);
x}
x
xchapter(f)
xint f;
x{
x       register int i;
x       register int c;
x       int myfence;
x       i = 0;
x
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               chaptitle[i++] = text[txtind++];
x       }
x       chaptitle[i] = '\0';
x       ++txtind;
x       printf("\n.bp\n.sp 4\n.ce on\n%s\n.cl 0 %d %s\n%s\n%s\n.sp 4\n.ce off\n"
,
x       bdon,chapnum,chaptitle,chaptitle,bdoff);
x       strcpy(curvlbl,"chapter");
x       strcpy(cursval,chaptitle);
x       putvar(VARSTR);
x       sectnum = 1;
x       ++chapnum;
x       return(TRUE);
x}
x
xsection(f)
xint f;
x{
x       register int i;
x       register int c;
x       int myfence;
x       i = 0;
x
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               secttitle[i++] = text[txtind++];
x       }
x       secttitle[i] = '\0';
x       ++txtind;
x       printf("\n.sp 2\n%s\n.cl 1 %d.%d %s\n%d.%d %s\n%s\n.sp 2\n",
x       ulon,chapnum-1,sectnum,secttitle,chapnum-1,sectnum,secttitle,uloff);
x       strcpy(curvlbl,"section");
x       strcpy(cursval,secttitle);
x       putvar(VARSTR);
x       sectnum++;
x       return(TRUE);
x}
x
xhe(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       fputs(".he ",stdout);
x       while ((c=text[txtind]) != myfence)
x               fputc(text[txtind++],stdout);
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       return(TRUE);
x}
x
xfo(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       fputs(".so ",stdout);
x       while ((c=text[txtind]) != myfence)
x               fputc(text[txtind++],stdout);
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       return(TRUE);
x}
x
xneed(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       fputs(".need ",stdout);
x       while ((c=text[txtind]) != myfence)
x               fputc(text[txtind++],stdout);
x       ++txtind;
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       return(TRUE);
x}
x
xcomment(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       while ((c=text[++txtind]) != myfence);
x       return(TRUE);
x}
x
xlastchar(fp)
xFILE *fp;
x{
x       register char c;
x       register char *optr;
x
x       optr = fp->_ptr;
x       c = *--optr;
x       return(c);
x}
SHAR_EOF
sed 's/^x//' << \SHAR_EOF > device.c
x/* device.c  printer tables to allow the @device() directive and direct
x * printer control.
x */
x
x#include "scribe.h"
x
x/* printer strings for device support */
x
xchar prnname[15];
xchar bdon[15];
xchar bdoff[15];
xchar ulon[15];
xchar uloff[15];
xchar hlfdn[15];
xchar hlfup[15];
xchar pinit[15];
xchar preset[15];
xchar ptch[15];
xchar lhght[15];
xint devflag;
x
xtypedef struct {
x       char prnname[15];
x       char bdon[15];
x       char bdoff[15];
x       char ulon[15];
x       char uloff[15];
x       char hlfdn[15];
x       char hlfup[15];
x       char init[15];
x       char reset[15];
x       char ptch[15];
x       char lhght[15];
x       int devflag;
x}DVCTAB;
x
xDVCTAB devtab[] = {
x       /* vanilla */
x       "plain",
x       ".bd on",".bd off",".ul on",".ul off",
x       "","",
x       "",".bp",
x       "","",DEVPLN,
x
x       /* Brother HR-15,25,35 */
x       "Brother",
x       "W","&","E","R",
x       "U","D",
x       ".wr 27 13 80",".wr 27 13 80",
x       "","",DEVFNCY,
x
x       /* QUME */
x       "Qume",
x       "W","&","E","R",
x       "U","D",
x       ".wr 27 13 50",".wr 27 15 50",
x       "","",DEVFNCY,
x
x       /* Prowriter Jr. */
x       "Prowriter",
x       "E","F","-","-",
x       "T","S\0",
x       "@","@",
x       "","",DEVFNCY,
x
x       /* Epson LX-80 */
x       "LX-80",
x       "E","F","-","-",
x       "T","S\0",
x       "@","@",
x       "","",DEVFNCY,
x
x       /* Epson RX-80 */
x       "RX-80",
x       "E","F","-","-",
x       "T","S\0",
x       "@","@",
x       "","",DEVFNCY,
x
x       /* Atari */
x       "Atari",
x       "E","F","-","-",
x       "T","S\0",
x       "@","@",
x       "","",DEVFNCY
x
x       /* coming soon */
x       /* FILE */
x       /* CON: */
x};
x
x#define NDEVTAB (sizeof(devtab)/sizeof(devtab[0]))
x
xsetdvc(f)
xint f;
x{
x       register DVCTAB *dtp;
x
x       dtp = &devtab[0];
x       while (dtp < &devtab[NDEVTAB]) {
x               if (strcmp(dtp->prnname,prnname)==0) {
x                       strcpy(bdon,dtp->bdon);
x                       strcpy(bdoff,dtp->bdoff);
x                       strcpy(ulon,dtp->ulon);
x                       strcpy(uloff,dtp->uloff);
x                       strcpy(hlfdn,dtp->hlfdn);
x                       strcpy(hlfup,dtp->hlfup);
x                       strcpy(pinit,dtp->init);
x                       strcpy(preset,dtp->reset);
x                       strcpy(ptch,dtp->ptch);
x                       strcpy(lhght,dtp->lhght);
x                       devflag = dtp->devflag;
x                       return(f);
x               }
x               ++dtp;
x       }
x       fprintf(stderr,"Device %s is not defined, using %s\n",prnname,DEFPRN);
x       strcpy(prnname,DEFPRN);
x       setdvc(f);
x       return(f);
x}
x
xdevice(f)
xint f;
x{
x       register int i;
x       register int c;
x       int myfence;
x
x       i = 0;
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (lastchar(stdout) != '\n')
x               putchar('\n');
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               prnname[i++] = text[txtind++];
x       }
x       prnname[i] = '\0';
x       ++txtind;
x       setdvc(f);
x       fprintf(stderr,"%cNow formatting for device %s\r",0x07,prnname);
x       return(TRUE);
x}
x
xheight(f)
xint f;
x{
x       char hstr[15];
x       register int i;
x       register int c;
x       int myfence;
x       int ascstr;
x
x       i = 0;
x       myfence = (f == TRUE ? '\0' : fence);
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       while ((c=text[txtind]) != myfence)
x               hstr[i++] = text[txtind++];
x       hstr[i] = '\0';
x       ++txtind;
x       ascstr = atoi(hstr);
x       if (devflag == DEVFNCY) {
x               fputs(lhght,stdout);
x               putchar(ascstr);
x       }
x       return(TRUE);
x}
x
xpitch(f)
xint f;
x{
x       char pstr[15];
x       register int i;
x       register int c;
x       int myfence;
x       int ascstr;
x
x       i = 0;
x       myfence = (f == TRUE ? '\0' : fence);
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       while ((c=text[txtind]) != myfence)
x               pstr[i++] = text[txtind++];
x       pstr[i] = '\0';
x       ++txtind;
x       ascstr = atoi(pstr);
x       if (devflag == DEVFNCY) {
x               fputs(ptch,stdout);
x               putchar(ascstr);
x       }
x       return(TRUE);
x}
x
xu(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0': fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (devflag == DEVPLN)
x               if (lastchar(stdout) != '\n')
x                       putchar('\n');
x       fputs(ulon,stdout);
x       if (devflag == DEVPLN)
x               putchar('\n');
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               fputc(text[txtind++],stdout);
x       }
x       ++txtind;
x       if (devflag == DEVPLN)
x               if (lastchar(stdout) != '\n')
x                       putchar('\n');
x       fputs(uloff,stdout);
x       if (devflag == DEVPLN)
x               putchar('\n');
x       return(TRUE);
x}
x
xbold(f)
xint f;
x{
x       register int c;
x       int myfence;
x       int nowrt = FALSE;
x
x       myfence = (f == TRUE ? '\0': fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (devflag == DEVPLN)
x               if (lastchar(stdout) != '\n')
x                       putchar('\n');
x       fputs(bdon,stdout);
x       if (devflag == DEVPLN)
x               putchar('\n');
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               fputc(text[txtind++],stdout);
x       }
x       ++txtind;
x       if (devflag == DEVPLN)
x               if (lastchar(stdout) != '\n')
x                       putchar('\n');
x       fputs(bdoff,stdout);
x       if (devflag == DEVPLN)
x               putchar('\n');
x       return(TRUE);
x}
x
xsuper(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0': fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (devflag == DEVPLN)
x               if (lastchar(stdout) != '\n')
x                       putchar('\n');
x       fputs(hlfup,stdout);
x       if (devflag == DEVPLN)
x               putchar('\n');
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               fputc(text[txtind++],stdout);
x       }
x       ++txtind;
x       if (devflag == DEVPLN)
x               if (lastchar(stdout) != '\n')
x                       putchar('\n');
x       fputs(hlfdn,stdout);
x       if (devflag == DEVPLN)
x               putchar('\n');
x       return(TRUE);
x}
x
xsub(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0': fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       if (devflag == DEVPLN)
x               if (lastchar(stdout) != '\n')
x                       putchar('\n');
x       fputs(hlfdn,stdout);
x       if (devflag == DEVPLN)
x               putchar('\n');
x       while ((c=text[txtind]) != myfence) {
x               if (c == '@') {
x                       fence=getcmd(FALSE);
x                       execute(FALSE);
x               }
x               fputc(text[txtind++],stdout);
x       }
x       ++txtind;
x       if (devflag == DEVPLN)
x               if (lastchar(stdout) != '\n')
x                       putchar('\n');
x       fputs(hlfup,stdout);
x       if (devflag == DEVPLN)
x               putchar('\n');
x       return(TRUE);
x}
x
xreset(f)
xint f;
x{
x       register int c;
x       int myfence;
x
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       while ((c=text[++txtind]) != myfence);
x       puts(preset);
x       return(TRUE);
x}
SHAR_EOF
#       End of shell archive
exit 0
%NONAME-W-NOMSG, Message number 00000000

RDROYA01@ULKYVX.BITNET (Robert Royar) (10/14/86)

#       This is a shell archive.
#       Remove everything above and including the cut line.
#       Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:    Shell Archiver
#       Run the following text with /bin/sh to create:
#       keytab.c
#       var.c
#       lnk.
# This archive created: Mon Oct 13 21:06:08 1986
sed 's/^x//' << \SHAR_EOF > keytab.c
x/* keytab.c main key table for environment command lookup.  Edit this file
x * to add or delete recognized command names.  All table lookup is based
x * on D. G. Conroy's original MicroEmacs execute() function.
x */
x
x#include "scribe.h"
x
xtypedef struct {
x       char name[15];
x       int (*keyfunc)();
x}ENVTAB;
x
xextern int enumer;
xextern int quote;
xextern int vrbate;
xextern int itemz;
xextern int ux;
xextern int u;
xextern int bold;
xextern int sp;
xextern int newpage;
xextern int he;
xextern int fo;
xextern int style;
xextern int head;
xextern int subh;
xextern int chapter;
xextern int include;
xextern int need;
xextern int comment;
xextern int undent;
xextern int super;
xextern int sub;
xextern int reset;
xextern int ndex;
xextern int string;
xextern int value;
xextern int section;
x
xENVTAB envtab[] = {
x       "enumerate",    &enumer,
x       "quotation",    &quote,
x       "verbatim",     &vrbate,
x       "itemize",      &itemz,
x       "ux",           &ux,
x       "u",            &u,
x       "i",            &u,
x       "b",            &bold,
x       "blankspace",   &sp,
x       "newpage",      &newpage,
x       "pageheading",  &he,
x       "pagefooting",  &fo,
x       "style",        &style,
x       "heading",      &head,
x       "subheading",   &subh,
x       "chapter",      &chapter,
x       "include",      &include,
x       "need",         &need,
x       "undent",       &undent,
x       "device",       &device,
x       "pitch",        &pitch,
x       "height",       &height,
x       "super",        &super,
x       "sub",          &sub,
x       "reset",        &reset,
x       "index",        &ndex,
x       "string",       &string,
x       "value",        &value,
x       "section",      &section,
x       "comment",      &comment
x};
x
x#define NENVTAB (sizeof(envtab)/sizeof(envtab[0]))
x
xexecute(f)
xint f;
x{
x       register ENVTAB *etp;
x       int status;
x
x       etp = &envtab[0];
x       while (etp < &envtab[NENVTAB]) {
x               if (strcmp(etp->name,command)==0) {
x                       status = (*etp->keyfunc)(f);
x                       return(status);
x               }
x               ++etp;
x       }
x       fprintf(stderr,"no code table for: %s\n",command);
x       return(unbound(f));     /* just set it up as a proff command */
x}
SHAR_EOF
sed 's/^x//' << \SHAR_EOF > var.c
x/* var.c functions to assign and retrieve variables in text.  Also the index
x * function is in this section.
x */
x
x#include "scribe.h"
x#include <ctype.h>
x
x#define        NBLOCK  16
x
xint ndxfile    = NO;   /* we don't yet have an index filed opened */
xchar curvlbl[32];      /* current variable label       */
xchar cursval[256];     /* value of string or index variable */
xint curnval;           /* current int variable value */
xint pagenum=1;         /* useless page number var for later */
xint chapnum=1;         /* chapter variable for @chapter() */
xint sectnum=1;         /* section variable for @section() */
xchar title[256];
xchar chaptitle[256];
xchar secttitle[256];
xextern FILE *fopen();
xFILE *ndxfp;
xextern char *malloc();
xVARTBL *vheadp;        /* variable table header pointer */
xVARTBL *curvp;         /* current variable table pointer */
x
x/* start up the variables table at the root */
x
xinitvar(f)
xint f;
x{
x       strcpy(&curvlbl[0],"ROOTNODE");
x       strcpy(&cursval[0],"");
x       vheadp = valloc(0);
x       vheadp->v_fp = vheadp;
x       vheadp->v_bp = NULL;
x       strcpy(vheadp->label,&curvlbl[0]);
x       strcpy(vheadp->svalue,&cursval[0]);
x       vheadp->type=VARSTR;
x       curvp = vheadp;
x       return(f);
x}
x
x/* put a, possibly preallocated, variable into the table */
x
xputvar(f)
xint f;         /* f == type of variable */
x{
x       register VARTBL *vtp;
x
x       /* perhaps we've already defined this variable */
x       if ((vtp=getvar(FALSE))==(VARTBL *)NULL) {
x               vtp = valloc(); /* no, then allocate space */
x               if (curvp == vheadp) {  /* special case first time after init */
x                       vtp->v_fp = vheadp;
x                       vtp->v_bp = vheadp;
x                       vheadp->v_fp = vtp;
x               }
x               else {
x                       vtp->v_fp = vheadp;
x                       vtp->v_bp = curvp;
x                       curvp->v_fp = vtp;
x               }
x               curvp = vtp;
x       }
x       if (f == VARSTR) {
x               strcpy(vtp->label,curvlbl);
x               strcpy(vtp->svalue,cursval);
x               vtp->type=VARSTR;
x       }
x       else if (f == VARNUM) {
x               strcpy(vtp->label,curvlbl);
x               vtp->nvalue=curnval;
x               vtp->type=VARNUM;
x       }
x       else if (f == VARNDX) {
x               strcpy(vtp->label,curvlbl);
x               strcpy(vtp->svalue,cursval);
x               vtp->type=VARNDX;
x       }
x       else {
x               fprintf(stderr,"Bad argument to putvar(): %d\n",f);
x               return(FALSE);
x       }
x       return(TRUE);
x}
x
xVARTBL *
xgetvar(f)
xint f;         /* f==TRUE really get var; f==FALSE just return pointer */
x{
x       VARTBL *vtp;
x
x       vtp = curvp;
x
x       while (vtp->v_bp != NULL) {
x               if (strcmp(vtp->label,curvlbl)==0) {
x                       if (f == FALSE)
x                               return(vtp);
x                       if (vtp->type == VARSTR) {
x                               strcpy(cursval,vtp->svalue);
x                               return(vtp);
x                       }
x                       else if (vtp->type == VARNUM) {
x                               curnval = vtp->nvalue;
x                               return(vtp);
x                       }
x                       else if (vtp->type == VARNDX)
x                               return(vtp);
x                       else {
x                               fprintf(stderr,"Bad argument to getvar(): %d\n",
f);
x                               return((VARTBL *)NULL);
x                       }
x               }
x               vtp = vtp->v_bp;
x       }
x       return((VARTBL *) NULL);
x}
x
xVARTBL
x*valloc()
x{
x        register VARTBL   *vp;
x        register int    size;
x
x        size = (NBLOCK-1) & ~(NBLOCK-1);
x        if (size == 0)
x                size = NBLOCK;
x        if ((vp=(VARTBL *)malloc(sizeof(VARTBL)+size)) == NULL) {
x                fprintf(stderr,"Fatal Error: out of space in variable table\n")
;
x                exit(1);
x       }
x        return (vp);
x}
x
xndex(f)                /* not index() because that name is taken */
xint f;
x{
x       register int i;
x       register int c;
x       int myfence;
x       i = 0;
x
x       if (ndxfile == NO)
x               mkndxf();
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       while ((c=text[txtind]) != myfence)
x               cursval[i++] = text[txtind++];
x       cursval[i] = '\0';
x       ++txtind;
x       strcpy(curvlbl,"NDXVAR");
x       putvar(VARNDX);
x       fputs(cursval,ndxfp);
x       fputc('\n',ndxfp);
x       return(TRUE);
x}
x
xmkndxf()
x{
x       char *ptr;
x       char ndxname[80];
x
x       strcpy(ndxname,ifname);
x       if ((ptr = rindex(ndxname, '.')) != NULL)
x               ptr[0] = '\0';
x       strcat(ndxname,".NDX");
x       if ((ndxfp=fopen(ndxname, "w")) == NULL) {
x               fprintf(stderr,"Fatal Error: scribe cannot open %s for writing\n
");
x               exit(1);
x       }
x       ndxfile = YES;
x       return;
x}
x
xstring(f)
xint f;
x{
x       register int i;
x       register int c;
x       int myfence;
x
x       i = 0;
x
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       while ((c=text[txtind]) != '=') {
x               if (isspace(c)) {
x                       txtind++;
x                       continue;       /* skip blanks */
x               }
x               else if (c == myfence) {
x                       fprintf(stderr,"Improper assignment to string\n");
x                       return(FALSE);
x               }
x               else
x                       curvlbl[i++] = text[txtind++];
x       }
x       curvlbl[i] = '\0';
x       i = 0;
x       txtind++;
x       while (text[txtind] != myfence)
x               cursval[i++] = text[txtind++];
x       cursval[i] = '\0';
x       ++txtind;
x       putvar(VARSTR);
x       return(TRUE);
x}
x
xvalue(f)
xint f;
x{
x       register int i;
x       register int c;
x       int myfence;
x
x       i = 0;
x
x       myfence = (f == TRUE ? '\0' : fence);
x
x       if (f == TRUE)
x               if (gettext() != fence)
x                       error();
x       while ((c=text[txtind]) != myfence) {
x               if (isspace(c)) {
x                       txtind++;
x                       continue;       /* skip blanks */
x               }
x               else
x                       curvlbl[i++] = text[txtind++];
x       }
x       curvlbl[i] = '\0';
x       ++txtind;
x       if (getvar(TRUE)!= (VARTBL *)NULL) {
x               i = 0;
x               while (c=cursval[i++])
x                       if (c != '\"')
x                               putchar(c);
x       }
x       else {
x               fprintf(stderr,"@VALUE: variable not found '%s'\n",curvlbl);
x               return(FALSE);
x       }
x       return(TRUE);
x}
x
SHAR_EOF
sed 's/^x//' << \SHAR_EOF > lnk.
xscribe.68k=gemstart,scribe,keytab,var,device,envir,gemlib[in[_nofloat]]
x
SHAR_EOF
#       End of shell archive
exit 0
%NONAME-W-NOMSG, Message number 00000000