home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 304_01 / roff5.h < prev    next >
Text File  |  1990-02-14  |  11KB  |  348 lines

  1. /********************************************************/
  2. /*         ROFF5, Version 2.00            */
  3. /*    (c) 1983,4,8,9 by Ernest E. Bergmann        */
  4. /*    730 Seneca Street, Bethlehem, Pa. 18015        */
  5. /*                            */
  6. /* Permission is hereby granted for all commercial and    */
  7. /* non-commercial reproduction and distribution of this    */
  8. /* material provided this notice is included.        */
  9. /********************************************************/
  10. #define    VERSION 2
  11. #define subVERSION 00
  12. #include "\turboc\include\stdio.h"
  13. #include "\turboc\include\string.h"
  14. #define NULL 0
  15. #define TRUE 1
  16. #define FALSE 0
  17. #define ERR -1
  18. #define ERROR (0)
  19. #define CPMEOF 26
  20.  
  21. #define MAXLINE 512
  22.  
  23. /* send error messages to console while in DIO */
  24. #define STKSIZ        3
  25. #define HUGE        135    /* generally large number */
  26. #define LSZ        255    /* line buffer size*/
  27. #define    COMMAND        '.'    /* all commands starts with this */
  28.  
  29. #define    NO_VAL        -32760    /* returned when no argument w/commad */
  30. #define WE_HAVE_A_WORD   1       /* returned by getwrd func. */
  31. #define    NO        0
  32. #define    YES        1
  33. #define UNDERLINE    '\137'
  34. #define    CR        0x0D
  35. #define BACKSPACE    '\b'
  36. #define NUMSIGN        '#'    /* for title strings */
  37. #define NEWLINE        '\n'
  38. #define TAB        '\t'
  39. #define BLANK        ' '
  40. #define FORMF        0x0C    /* formfeed for printer */
  41. #define SQUOTE        0x27    /* single quote */
  42. #define DQUOTE        0x22    /* double quote */
  43. #define CNTLZ        26    /* ^Z=MS-DOS EOF char */
  44. #define TRANSLATE 2    /* May 23, 1983*/
  45. #define BLACK 1
  46. #define WHITE 0
  47. #define CONTROL -1
  48. #define SENTINEL -2
  49. #define HTAB    -3
  50. #define SOH    -5
  51. #define OTHERS -4
  52. #define XCHAR '-'
  53. #define UCHAR '_'
  54.  
  55. /* defaults for global parameters */
  56. #define CZSUB_DEF    154    /* ^Z substitute default */
  57. #define FI_DEF        1
  58. #define    LS_DEF        1
  59. #define    TI_DEF        0
  60. #define    CE_DEF        1
  61. #define    UL_DEF        -1
  62. #define M1_DEF        2
  63. #define M2_DEF        2
  64. #define M3_DEF        2
  65. #define M4_DEF        2
  66. #define PL_DEF        66
  67. #define FF_DEF        YES    /* .ff defaults to "on" */
  68. #define FF_INI        NO    /* initial setting*/
  69. #define SC_INI        BLANK
  70. #define TF_DEF        '~'    /*translation flag default*/
  71. #define CF_DEF        '^'    /*Dec 4*/
  72. #define IC_DEF        '\\'
  73. #define EV_INI        0
  74. #define CW_DEF        12    /* 12/120" */
  75. #define JU_INI        YES    /*right justification*/
  76. #define REGDEF         1    /*default for register var.*/
  77.                 /*when .rg has no numeric arg*/
  78.  
  79.  
  80. #define    REVSCROLL    FALSE
  81. #define CANBS        FALSE
  82. #define BELL    '\007'
  83.  
  84. typedef enum
  85. {IF,        /*"if" conditional */
  86.  IE,        /* start of "if-else" conditional */
  87.  EL,        /* "else" part of conditional */
  88.  LEFT,        /* for ".{" */
  89.  RIGHT,        /* for ".}" */
  90.  UNKNOWN,    /* returned if doesn't recg. command */
  91.  FI,        /* fill lines */
  92.  TI,        /* temporary indent */
  93.  BP,        /* begin page  */
  94.  BR,        /* causes break */
  95.  CE,        /* center line(s) */
  96.  LS,        /* line spacing */
  97.  NF,        /* no fill */
  98.  PL,        /* set page length */
  99.  SP,        /* add blank line(s) */
  100.  ST,        /* stop(pause) at page start?*/
  101.  FO,        /* footer title */
  102.  HE,        /* header title */
  103.  M1,        /* top margin */
  104.  M2,        /* second top margin */
  105.  M3,        /* first bottom margin */
  106.  M4,        /* bottom-most margin       */
  107.  IG,        /* "ignore";comments*/
  108.  DOTDOT,    /* ".." comment */
  109.  NE,        /* "need";Nov 7,82*/
  110.  FF,        /* "formfeed";Nov 10*/
  111.  SC,        /* "space character"*/
  112.  EH,        /* "even headers"*/
  113.  OH,        /* "odd headers"*/
  114.  EF,        /* "even footers"*/
  115.  OF,        /* "odd footers"*/
  116.  AB,        /* "abort"*/
  117.  TF,        /* "translation flag" */
  118.  CF,        /* "control flag char"*/
  119.  IC,        /* insert character */
  120.  OU,        /* output */
  121.  AD,        /* adjust (justify)*/
  122.  NA,        /* do Not Adjust */
  123.  FR,        /* fractional spacing,code*/
  124.  DS,        /*define string*/
  125.  DE,        /*define macro*/
  126.  AM,        /*append macro*/
  127.  NR,        /*Number Register*/
  128.  DI,        /*diversion*/
  129.  DA,        /* " append*/
  130.  SO,        /*"source", include*/
  131.  OT,        /* Output Translation */
  132.  TM,        /*msg to terminal (stderr)*/
  133.  BJ,        /*break with right justification of current line*/
  134.  AF,           /*"assign format" to register*/
  135.  CZ,        /* ^Z substitute character */
  136.  RL,         /* Ruler Line tab spec similar to Wordstar */
  137.  EV,        /* environment switching */
  138.  RM,        /* remove a definition */
  139.  RN,        /* rename a definition */
  140.  PM,        /*print list of macros */
  141.  MC,        /*margin character*/
  142.  NM,        /*numbers in margin*/
  143.  NN,        /*suspend .NM*/
  144.  PC,        /*page number character*/
  145.  PO,        /*page offset*/
  146.  LC,        /*Leader expansion Character*/
  147.  TC,        /*Tab expansion Character*/
  148.  WH,        /* WHen page trap */
  149.  CH,        /* Change page trap */
  150.  IT,        /* Input Trap */
  151.  EM,        /* End Macro trap */
  152.  DT,        /* Diversion Trap */
  153.  TL,        /* 3 part TitLe */
  154.  GO        /* (advance printer only) to absolute location */
  155. } CMD;
  156.  
  157. typedef struct
  158.     {char typ;
  159.      char fill;
  160.      int minwidth;
  161.     }
  162. FORMAT;
  163.  
  164. typedef struct
  165. {void *link;
  166.  char ident[1]; /*indefinitely long, terminated by '\0' */
  167.  /* followed by integer, string, or pointer to structure */
  168. } ENTRY;  /*can be serched by find2()*/
  169. typedef struct
  170. {void *link;
  171.  char ident[2]; /*="\177"*/
  172.  int dl; /*width*/
  173.  int dn; /*# lines*/
  174.  int dt; /*trap postion*/
  175.  char dtname[LSZ];
  176. } DENTRY;
  177. extern
  178. ENTRY    SLINK,    /* string substitution table */ /*insert(), showit()*/
  179.     MLINK, /* macro and diversion substitution table */
  180.         /*minsert(),showm(),macq()*/
  181.         /*SLINK,MLINK table entries are following ident string
  182.             with second string used as replacement*/
  183.     RLINK;    /* register substitution table;
  184.            ident string followed by int*/ /*showr(),regist()*/
  185.  
  186. /* typical addition of new entries consists of:
  187.     entry *pe;
  188.     char  *pc;
  189.     char buff[?];
  190.     unsigned siz;
  191.     ENTRY *where;
  192.     pe = buff;
  193.     pe->link = ?LINK.link;
  194.     pc = &pe.ident;
  195.     pc++ = stpcpy(pc, NAME);
  196.         Now pc points to where info should be placed;
  197.     Compute actual siz;
  198.     if (NULL==(where=(ENTRY *)malloc(siz)))
  199.     {fprintf(stderr,"ERROR MESSAGE cannot malloc\n");
  200.      exit();
  201.     }
  202.     ?LINK.link = (ENTRY *)memcpy(where,buff,siz);
  203. */
  204. extern int
  205.  INPUTlns,    /*count of all lines from input*/
  206.  INTRAP,    /* 0 if no input trap pending; counts down if pos. */
  207.  PAGESTOP,
  208.  JUSTIFY, DOTJ,
  209.  FFEED,
  210.  FIRSTPAGE,LASTPAGE,/*for selectively printing output*/
  211.  SUPPRESS,/*if true,no output is passed by putchar()*/
  212.  
  213.  
  214.  FILL,        /* boolean for filled lines or not */
  215.  LSVAL[STKSIZ+1],
  216.  TIVAL,    /* temporary indent -> default  0 */
  217.  INVAL,    /* indent margin */
  218.  RMVAL,    /* right margin */
  219.  CEVAL,    /* set equal to number of lines to be centered    */
  220.  TFVAL[STKSIZ+1], /* default is 0 */
  221.  SPVAL;    /* blank lines to be spaced down */
  222. extern int
  223.  CURPAG,    /* current output page number; init = 0 */
  224.  NEWPAG;    /* next output page number; init = 1 */
  225. extern FORMAT PAGFMT; /*format for printing page numbers*/
  226. extern int
  227.  VLINENO,    /* virtual (intended) line advances on page,
  228.             see vadv()*/
  229.  FVLINENO,    /* + line fraction */
  230.  PLINENO,    /* printer's actual line advances on page,
  231.             see padv()*/
  232.  FPLINENO,    /* + line fraction */
  233.  PLVAL[STKSIZ+1],
  234.  M1VAL[STKSIZ+1],
  235.  M2VAL[STKSIZ+1],
  236.  M3VAL[STKSIZ+1],
  237.  M4VAL[STKSIZ+1],
  238.  TRAPLOC,    /* location of next page trap in lines */
  239.  FOOTLOC,    /* location of start of page footer */
  240.  SCVAL[STKSIZ+1],
  241.  SENTENCE,    /* Nov 20*/
  242.  CFVAL[STKSIZ+1],
  243.  ICVAL[STKSIZ+1],
  244.  EVVAL[STKSIZ+1];
  245.  
  246. extern int
  247.  LCVAL,        /* for .lc */
  248.  TCVAL;        /* for .tc */
  249. extern char
  250.  ITstring[LSZ],    /* for input trap */
  251.  EMstring[LSZ], /* for End Macro trap */
  252.  *TRAPNAM,    /* for pagetrapping, used with TRAPLOC */
  253.  LINE[ LSZ ], *LIN ,    /*input line buffer */
  254.  EHEAD[ LSZ ],*EH2,*EH3,    /* even header title */
  255.  OHEAD[ LSZ ],*OH2,*OH3,    /* odd header title */
  256.  EFOOT[ LSZ ],*EF2,*EF3,    /* even footer title */
  257.  OFOOT[ LSZ ],*OF2,*OF3,    /* even footer title */
  258.  RULER[ LSZ ];    /* similar to WordStar, keeps track of tabs */
  259. extern int CZSUB;        /* ^Z substitution character */
  260.  
  261. extern FILE *ifp, *ofp;
  262. /*following added for buffered and formatted output:  */
  263. extern char OUTBUF2[LSZ];    /*for line to be output in fancy fmt*/
  264. extern int BPOS,CP,PP;        /*buffer,column,printer positions*/
  265. extern char XBUF[LSZ];        /*strikout buffer*/
  266. extern int XF,XCOL;        /* " flag and column */
  267. extern char UBUF[LSZ];        /*underline buffer*/
  268. extern int UF,UCOL;        /* " flag and column */
  269. extern int FIRST;            /*flag for first pass*/
  270. extern char DBUF[LSZ];        /*double strike buffer*/
  271. extern int
  272.  dotO,        /* .o page offset */
  273.  DPOS,
  274.  OCNT,
  275.  MCNT,
  276.  BLKCNT,
  277.  DIR,                /* for "spreading" of lines    */
  278.  OUTWRDS,            /* no. words in OUTBUF, init = 0 */
  279.  OUTW,                /*current display width of OUTBUF*/
  280.  OUTPOS,                /* =strlen(OUTBUF) */
  281.  WTOP,LTOP,OUTTOP,    /*zero|negative;levels of subscripts*/
  282.  WBOT,LBOT,OUTBOT,    /*zero|positive;levels of subscripts*/
  283.  OLDLN,                /*position of previous main line*/
  284.  OLDBOT,                /*OUTBOT for previous line;reset
  285.                             each page*/
  286.  FRQ,FRVAL;            /* fractional line?, what fraction size*/
  287. #define BBSIZ0    2000
  288. extern int BBSIZ;
  289. extern char
  290.  OUTBUF[ LSZ ],        /*lines to be filled collected here */
  291.  GPWBUF[ LSZ ],        /*the word buffer used by getwrd->putwrd*/
  292.  *FRSTRING,         /* ^ to code for fractional spacing*/
  293.  *WHSTRING,            /* ^ to code for whole line spacing*/
  294.  *CPTR[128-' '],    /*pointer table for print control*/
  295.  *TPTR[128-' '],    /*pointer table for translation strings
  296.                               for char; initialize to null */
  297.  KEYBD,                /*boolean & prompt for keyboard input*/
  298.  KLINE[MAXLINE],    /*keyboard line input buffer*/
  299.  *KPTR,                /*pointer for above*/
  300.  *BACKBUF,            /* used as BACKBUF[] */
  301.  BACKBUF0[BBSIZ0];
  302. extern int BINP;            /*position in above;init to 0*/
  303.  
  304. #define FMAX 4       /* # of additional files open */
  305. #define FNAMSIZ    60   /* limit of filename length */
  306. typedef struct
  307.     {FILE *IFP;
  308.      char FNAME[FNAMSIZ];
  309.      int nlines;
  310.      int bbsiz;
  311.      int binp;
  312.      char *backbuf;
  313.      }
  314. FILEF;
  315. extern FILEF FSTACK[FMAX];
  316. extern int    FPTR;
  317. extern int
  318.  XF2,UF2,MCNT2;
  319. #define NUMENV 4    /* defines number of possible environments */
  320. #define ARGLIM 10
  321. typedef struct
  322. { int dollar;
  323.   char *arg[ARGLIM];
  324.   char tokens[LSZ];
  325. } ARGs;
  326.  
  327. #include "\turboc\roff5.fnc"
  328.  
  329. /*in preparation for new diversion capabilities: */
  330. extern int DIVERTING;    /* TRUE/FALSE */
  331. extern int DLINES;    /* no of lines in last or current div*/
  332. extern int DWIDTH;    /* max OUTW in last or current diversion*/
  333. extern char DNAME[FNAMSIZ]; /*name of current or last diversion*/
  334. extern char Dbuff[]; /* accumulation buffer for diversion*/
  335. extern unsigned Dsiz;    /* number of bytes in DBUFF */
  336. extern char *Dpc2;    /* char pointer within DBUFF */
  337. extern ENTRY *Dprev, *Dnext, *Dpe;
  338. extern DENTRY *Dstats; /*init by dappend; updated by enddiv() */
  339.  
  340. /* for .nm, .nn */
  341. extern int
  342. NUMBERING,    /* T/F */
  343. NNVAL,        /* nonumbering counter */
  344. LN,        /* line number for NUMBERING */
  345. LNMOD,        /* NUMBERING modulus */
  346. LNI,        /* LN indent from offset */
  347. LNST;        /* LN space from text */
  348.