home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1163 / dvi2tty.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  23.9 KB  |  659 lines

  1. /******************************************************************************
  2.  * Marcel Mol: 1990-02-04  (UUCP: marcel@duteca.tudelft.nl)
  3.  *               First attempt to recognize symbol fonts, so bullets (in
  4.  *               itemized lists) are translated to a proper character instead
  5.  *               an awfull ligature.
  6.  *               Version 4.0.
  7.  * Marcel Mol: 1990-02-01  (UUCP: marcel@duteca.tudelft.nl)
  8.  *               Included port to VMS (off Joseph Vasallo and Seppo Rantala)
  9.  *               into latest version. Hope things still work, cannot test it ...
  10.  * Joseph Vasallo & Seppo Rantala: 1989-09-05 (Internet: rantala@tut.FI)
  11.  *         Ported to work under VAX/VMS V4.4 & VAXC V2.4 or higher.
  12.  *         Fixed bugs in using Swedish/Finnish characters.
  13.  * Marcel Mol: 1989-02-14  (UUCP: duteca!marcel)
  14.  *               Fixed check for .dvi extension.
  15.  *               Allowed more ligatures.
  16.  *               Fixed side effect bugs (2 gets as function arguments).
  17.  *               Version 3.2.
  18.  * Marcel Mol: 1989-01-19  (UUCP: duteca!marcel)
  19.  *               Changed in option handling, no change
  20.  *               in user interface (only the undocumented 
  21.  *               feature -e).
  22.  *               Version 3.1.
  23.  * Marcel Mol: 1989-01-11  (UUCP: duteca!marcel)
  24.  *               Changed some longs to ints.
  25.  *               It now also runs on MSDOS Microsoft C 5.1
  26.  *               New version: 3.0
  27.  * Marcel Mol: 1989-01-03  (UUCP: duteca!marcel)
  28.  *               Fixed a bugs concerning pager programs
  29.  *               and scanning environment variable DVI2TTY.
  30.  * Marcel Mol: 1988-10-25  (UUCP: duteca!marcel)
  31.  *        dvi2tty.c dvi2tty.h dvistuff.c commands.h
  32.  *               Converted program to C.
  33.  *               improved spacing between words/characters.
  34.  * bogart:/usr/alla/zap/dvitty/dvitty.p  1986-08-15 20:24:31,
  35.  *               Version to be sent to mod.sources ready.
  36.  * New option since last version:
  37.  *   -Fprog      Pipe output to prog. Can be used to get a different
  38.  *               pager than the default.
  39.  * bogart:/usr/alla/zap/dvitty/dvitty.p  1986-01-13 21:49:31,
  40.  *   Environment variable DVITTY is read and options can be set from it.
  41.  *   These are the currently implemented options:
  42.  *      -ofile   Write output to file, else write to stdout,
  43.  *               possibly piped through a pager if stdout is a tty.
  44.  *      -plist   Print pages whos TeX-page-number are in list.
  45.  *               List is on the form  1,3:6,8  to choose pages
  46.  *               1,3-6 and 8. TeX-nrs can be negative: -p-1:-4,4
  47.  *      -Plist   Print pages whos sequential number are in list.
  48.  *      -wn      Print the lines with width n characters, default is
  49.  *               80. Wider lines gives better results.
  50.  *      -q       Don't try to pipe to a pager.
  51.  *      -f       Try to pipe to a pager if output is a tty.
  52.  *      -Fname   Specify a pager program.                  
  53.  *               Default of -q and -f is a compile time option, a constant.
  54.  *      -l       Write '^L' instead of formfeed between pages.
  55.  *      -u       Don't try to find Scandinavian characters (they will
  56.  *               print as a:s and o:s if this option is choosen).
  57.  *      -s       Scandinavian characters printed as }{|][\.
  58.  *               Default of -s and -u is a compile time option, a constant.
  59.  * bogart:/usr/alla/zap/dvitty/dvitty.p  1986-01-10 18:51:03,
  60.  *   Argument parsing, and random access functions (external, in C)
  61.  *   and other OS-dependent stuff (in C). Removed private 'pager' &
  62.  *   tries to pipe through PAGER (environment var) or, if PAGER not
  63.  *   defined, /usr/ucb/more. Some changes for efficency.
  64.  * bogart:/usr/alla/svante/dvitty/dvitty.p  1985-07-15 20:51:00,
  65.  *   The code for processing dvi-files running on UNIX (UCB-Pascal)
  66.  *   but no argument parsing.
  67.  * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.140, 30-Mar-85 05:43:56,
  68.  *   Edit: Svante Lindahl
  69.  * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.136, 15-Jan-85 13:52:59,
  70.  *   Edit: Svante Lindahl, final Twenex version !!!??
  71.  * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.121, 14-Jan-85 03:10:22,
  72.  *   Edit: Svante Lindahl, cleaned up and fixed a lot of little things
  73.  * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.25, 15-Dec-84 05:29:56,
  74.  *   Edit: Svante Lindahl, COMND-interface, including command line scanning
  75.  * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.23, 10-Dec-84 21:24:41,
  76.  *   Edit: Svante Lindahl, added command line scanning with Rscan-JSYS
  77.  * VERA::<SVANTE-LINDAHL.DVITTY>DVITTY.PAS.48,  8-Oct-84 13:26:30,
  78.  *  Edit: Svante Lindahl, fixed switch-parsing, destroyed by earlier patches
  79.  * VERA::<SVANTE-LINDAHL.DVITTY>DVITTY.PAS.45, 29-Sep-84 18:29:53,
  80.  *  Edit: Svante Lindahl
  81.  *
  82.  * dvitty - get an ascii representation of a dvi-file, suitable for ttys
  83.  *
  84.  * This program, and any documentation for it, is copyrighted by Svante
  85.  * Lindahl. It may be copied for non-commercial use only, provided that
  86.  * any and all copyright notices are preserved.
  87.  *
  88.  * Please report any bugs and/or fixes to:
  89.  *
  90.  * UUCP: {seismo,mcvax,cernvax,diku,ukc,unido}!enea!ttds!zap
  91.  * ARPA: enea!ttds!zap@seismo.CSS.GOV
  92.  *  or   Svante_Lindahl_NADA%QZCOM.MAILNET@MIT-MULTICS.ARPA
  93.  * EAN:  zap@cs.kth.sunet
  94.  */
  95.  
  96.  
  97. #include "dvi2tty.h"
  98. #if defined(VMS)
  99. #include unixio
  100. #endif
  101.  
  102.     /*-----------------------------------------------------------------------*/
  103.     /* The following constants may be toggled before compilation to          */
  104.     /* customize the default behaviour of the program for your site.         */
  105.     /* Whichever their settings are, the defaults can be overridden at       */
  106.     /* runtime.                                                              */
  107.     /*-----------------------------------------------------------------------*/
  108.  
  109. #define DEFSCAND    FALSE     /* default is Scandinavian, toggle this if you */
  110.                               /* don't have terminals with Scand. nat. chars */
  111. #define WANTPAGER   TRUE      /* default: try to pipe through a pager (like  */
  112.                               /* more) if stdout is tty and no -o switch     */
  113. #define DEFPAGER    "/usr/bin/pg"   /* CHANGE TO YOUR LOCAL PAGER            */
  114.  
  115.     /*------------------ end of customization constants ---------------------*/
  116.  
  117. #define MAXLEN          100    /* size of char-arrays for strings            */
  118. #if defined(MSDOS) || defined(VMS)
  119. #define OPTSET      "wepPousl"   /* legal options                            */
  120. #define OPTWARG     "wepPo"      /* options with argument                    */
  121. #else
  122. #define OPTSET      "wepPousqlfF"/* legal options                            */
  123. #define OPTWARG     "wepPoF"     /* options with argument                    */
  124. #endif
  125.  
  126. /*
  127.  * USAGE CODES
  128.  */
  129.  
  130. #define wrnge  1                /* width switch arg out of range     */
  131. #define ign    2                /* ignore cause, print 'Usage:..'    */
  132. #define nan    3                /* not a number where one expected   */
  133. #define gae    4                /* garbage at end                    */
  134. #define bdlst  5                /* bad page-numberlist               */
  135. #define onef   6                /* only one dvifile allowed          */
  136. #define bdopt  7                /* bad option                        */
  137. #define onepp  8                /* only one page list allowed        */
  138. #define noarg  9                /* argument expected                 */
  139.  
  140. char *dvi2tty = "@(#) dvi2tty.c  4.0 04/02/90 M.J.E. Mol (c) 1989, 1990";
  141.  
  142. /*---------------------------------------------------------------------------*/
  143.  
  144. printlisttype * currentpage;    /* current page to print                     */
  145. printlisttype * firstpage;      /* first page selected                       */
  146. printlisttype * lastpage;       /* last page selected                        */
  147.  
  148. FILE *          DVIfile;
  149. FILE *          output;
  150. bool            outputtofile;   /* tells if output goes to file or stdout    */
  151. int             ttywidth;       /* max nr of chars per printed line          */
  152. int             espace;         /* to fake calcs with ttywidth               */
  153.  
  154. long            foo;            /* utility variable, "register"              */
  155. #if !defined(MSDOS) && !defined(VMS)
  156. bool            pager;          /* tells if output is piped to a pager       */
  157. char  *         path;           /* name of the pager to run                  */
  158. #endif
  159. char  *         progname;       /* our name                                  */
  160. int             Argc;
  161. char **         Argv;
  162. char            DVIfilename[MAXLEN];
  163. char *          OUTfilename;
  164. char            optch;          /* for option handling                       */
  165.  
  166. /*---------------------------------------------------------------------------*/
  167.  
  168. #if defined(MSDOS)
  169. void    main      (int, char **); 
  170. void    setoption (char *);
  171. void    getargs   (void);
  172. void    getpages  (int, char *);
  173. void    plcnxt    (int);
  174. void    getfname   (char *);
  175. int     getinteger(int *, int *, char *);
  176. void    usage     (int);
  177. #else
  178. char *  getenv    ();
  179. FILE *  popen     ();
  180.  
  181. void    main      (); 
  182. void    setoption ();
  183. void    getargs   ();
  184. void    getpages  ();
  185. void    plcnxt    ();
  186. void    getfname   ();
  187. int     getinteger();
  188. void    usage     ();
  189. #endif
  190.  
  191.  
  192. /****************************************************************************/
  193. /*                                                                          */
  194. /*                                 M A I N                                  */
  195. /*                                                                          */
  196. /****************************************************************************/
  197.  
  198. void main(argc, argv)
  199. int argc;
  200. char ** argv;
  201. {
  202.  
  203.     progname = *argv;
  204.     Argc = argc;
  205.     Argv = argv;
  206.  
  207.     getargs();                              /* read command line arguments   */
  208. #if defined(MSDOS)
  209.     if ((DVIfile = fopen(DVIfilename, "rb")) == NULL)
  210. #else
  211. #if defined(VMS)
  212.     if ((DVIfile = fopen(DVIfilename, "r","ctx=rec")) == NULL)
  213. #else
  214.     if ((DVIfile = fopen(DVIfilename, "r")) == NULL)
  215. #endif
  216. #endif
  217.         errorexit(filop);                   /* can't open dvifile            */
  218.  
  219.     if (outputtofile) {                     /* open the outfile, if needed   */
  220.         if ((output = fopen(OUTfilename, "w")) == NULL)
  221.             errorexit(filcr);
  222. #if !defined(MSDOS) && !defined(VMS)
  223.         pager = FALSE;
  224. #endif
  225.     }
  226.     else {
  227.         output = stdout;
  228. #if !defined(MSDOS) && !defined(VMS)
  229.         if (isatty(fileno(output)) && pager) {   /* try to pipe to a pager   */
  230.             if ((output = popen(path, "w")) == NULL) /* get pipe to pager    */
  231.                 errorexit(pipcr);                /* make output to output    */
  232.         }
  233.         else
  234.             pager = FALSE;
  235. #endif
  236.     }
  237.  
  238.     dvimain();
  239.  
  240. #if !defined(MSDOS) && !defined(VMS)
  241.     if (pager)
  242.         pclose(output);                     /* close pipe to pager            */
  243. #endif
  244.  
  245.     exit(0);
  246.  
  247. } /* main */
  248.  
  249. /*----------------------------------------------------------------------------*/
  250.  
  251. void setoption(optarg)
  252. char *optarg;
  253. {
  254.     int j = 0;
  255.     int ret;
  256.    
  257.     while (strchr(OPTSET, optch) != NULL) {
  258.         switch (optch) {
  259. #if !defined(MSDOS) && !defined(VMS)
  260.         case 'q' : pager = FALSE; break;
  261.         case 'f' : pager = TRUE; break;
  262. #endif
  263.         case 'l' : noffd = TRUE; break;
  264.         case 's' : scascii = TRUE; break;
  265.         case 'u' : scascii = FALSE; break;
  266.             case 'P' :
  267.                sequenceon = TRUE;     /* fall through */
  268.             case 'p' :
  269.                        if (pageswitchon)
  270.                            usage(onepp);
  271.                        getpages(j, optarg);
  272.                        break;
  273.             case 'w' :
  274.                if (getinteger(&ttywidth, &j, optarg))
  275.                            usage(nan);
  276.                        if (optarg[j] != '\0') 
  277.                            usage(gae);
  278.                        if ((ttywidth < 16) || (ttywidth > 132))
  279.                            usage(wrnge);
  280.                        break;
  281.             case 'e' :
  282.                if (getinteger(&espace, &j, optarg))
  283.                            usage(nan);
  284.                        if (optarg[j] != '\0') 
  285.                            usage(gae);
  286.                        break;
  287.             case 'o' :
  288.                        OUTfilename = optarg;
  289.                outputtofile = TRUE;
  290.                        j = strlen(optarg);
  291.                        break;
  292. #if !defined(MSDOS) && !defined(VMS)
  293.             case 'F' :
  294.                        pager = TRUE;
  295.                        path = optarg;
  296.                        j = strlen(optarg);
  297.                        break;
  298. #endif
  299.             default  : 
  300.                        usage(bdopt);
  301.         }
  302.         if ((optch = optarg[j]) == '\0')
  303.             break;
  304.         j++;
  305.         if ((strchr(OPTWARG, optch) != NULL) && (optarg[j]='\0')) {
  306.                 if (--Argc <= 0)
  307.                     usage(noarg);
  308.                 optarg = *++Argv;
  309.                 j = 0;
  310.             }
  311.     }
  312. } /* setoption */
  313.  
  314. /*----------------------------------------------------------------------------*/
  315.  
  316. void getargs()
  317. {
  318.     char *str, *envp;
  319.     bool DVIfound;                      /* if a dvi filename found           */
  320.  
  321.     if (Argc <= 1)
  322.         usage(ign);
  323.  
  324.     pageswitchon = FALSE;       /* show all pages                            */
  325.     sequenceon   = FALSE;       /* selected pages are TeX-numbered           */
  326.     outputtofile = FALSE;       /* write to stdout                           */
  327. #if !defined(MSDOS) && !defined(VMS)
  328.     pager        = WANTPAGER;   /* want paging, compile time option          */
  329. #endif
  330.     noffd        = FALSE;       /* print formfeed between pages              */
  331.     scascii      = DEFSCAND;    /* scandinavian, compile time option         */
  332.     ttywidth     = 80;          /* default terminal width                    */
  333.     espace       = 0;           /* to fake ttywith calcs                     */
  334.     DVIfound     = FALSE;
  335.  
  336. #if !defined(MSDOS) && !defined(VMS)
  337.     if ((path = getenv("PAGER")) == NULL)   /* find default pathname of page */
  338.             path = DEFPAGER;             /* program in case paging is wanted */
  339. #endif
  340.  
  341.     if ((envp = getenv("DVI2TTY")) != NULL) {
  342.         while (*envp == ' ')
  343.              envp++;
  344.         while (*envp) {                     /* environment var args          */
  345.             if (strchr(OPTSET, optch = *envp++) != NULL) {
  346.                 /*
  347.                  * we always pass one option, and arrange for optarg ourselfves,
  348.                  * so setoption does not mesh up Argv
  349.                  */
  350.                 if (strchr(OPTWARG, optch) != NULL) {
  351.                     while (*envp == ' ') 
  352.                         envp++;
  353.                     if (*envp == '\0')
  354.                         usage(noarg);
  355.                     str = envp;             /* str points to optarg          */
  356.                     while ((*envp != ' ') && (*envp != '\0'))
  357.                         *envp++;            /* set envp just after optarg    */
  358.                     if (*envp != '\0')
  359.                         *envp++ = '\0';     /* end optarg string             */
  360.                 }
  361.                 else
  362.                     str = "";
  363.                 setoption(str);
  364.             }
  365.             else
  366.                 usage(bdopt);
  367.             while (*envp == ' ')
  368.                  envp++;
  369.         }
  370.     }
  371.  
  372.     while (--Argc > 0) {                    /* command line args             */
  373.         str = *++Argv;
  374.         if (*str != '-') {                  /* argument is not an option     */
  375.             if (DVIfound)                   /* only one dvi file allowed     */
  376.                 usage(onef);
  377.             getfname(str);
  378.             DVIfound = TRUE;
  379.         }
  380.         else if (strchr(OPTSET, optch = *++str) != NULL) {
  381.             str++;                      /* point to rest of argument if any  */
  382.             if ((strchr(OPTWARG, optch) != NULL) && (*str == '\0')) {
  383.                 if (--Argc <= 0)
  384.                     usage(noarg);
  385.                 str = *++Argv;
  386.             }
  387.             setoption(str);
  388.         }
  389.         else
  390.             usage(bdopt);
  391.     }
  392.  
  393.     if (!DVIfound)
  394.         usage(ign);
  395.  
  396. } /* getargs */
  397.  
  398. /*---------------------------------------------------------------------------*/
  399.  
  400. void getpages(j, str)
  401. int j;
  402. char *str;
  403. {
  404.     int i, c;
  405.     int num;
  406.  
  407.     pageswitchon = TRUE;
  408.     firstpage = (printlisttype *) malloc(sizeof(printlisttype));
  409.     firstpage->all = FALSE;
  410.     firstpage->nxt = nil;
  411.     firstpage->pag = 0;
  412.     lastpage = firstpage;
  413.     currentpage = firstpage;
  414.     if (getinteger(&num, &j, str))
  415.         usage(nan);
  416.     plcnxt((int) num);
  417.     while (str[j]) {
  418.         c = str[j];
  419.         if (c == ',' || c == ':') {
  420.             j++;
  421.             if (getinteger(&num, &j, str))
  422.                 usage(nan);
  423.         }
  424.         else
  425.             break;
  426.         if (c == ',')
  427.             plcnxt(num);
  428.         else {
  429.             if (currentpage->pag < 0) {
  430.                 if (num > 0) {
  431.                     currentpage->all = TRUE;
  432.                     plcnxt(num);
  433.                 }
  434.                 else if (num < currentpage->pag)
  435.                     for (i = currentpage->pag - 1; i >= num; i--)
  436.                         plcnxt(i);
  437.                 else
  438.                     usage(bdlst);
  439.             }
  440.             else {
  441.                 if (num < currentpage->pag)
  442.                     usage(bdlst);
  443.                 for (i = currentpage->pag + 1; i <= num; i++)
  444.                     plcnxt(i);
  445.             }
  446.         }
  447.     }
  448.     if ((str[j] != ' ') && (str[j] != NULL)) {
  449.         usage(gae);
  450.     }
  451.     currentpage = firstpage;
  452.  
  453. } /* getpages */
  454.  
  455.  
  456. void plcnxt(pagnr)      /* place page-nr next in list */
  457. int pagnr;
  458. {
  459.     currentpage = lastpage;
  460.     currentpage->pag = pagnr;
  461.     lastpage = (printlisttype *) malloc(sizeof(printlisttype));
  462.     lastpage->all = FALSE;
  463.     lastpage->nxt = nil;
  464.     lastpage->pag = 0;
  465.     currentpage->nxt = lastpage;
  466.  
  467. } /* plcnxt */
  468.  
  469. /*----------------------------------------------------------------------------*/
  470.  
  471. void getfname(str)
  472. char *str;
  473. {
  474.     int   i;
  475.  
  476.     i = strlen(str);
  477.     if (i == 0)
  478.         usage(ign);
  479.     strcpy(DVIfilename, str);
  480.     if (!((i >= 5) && (str[i-1] == 'i') && (str[i-2] == 'v') &&
  481.           (str[i-3] == 'd') && (str[i-4] == '.'))) {
  482.         strcat(DVIfilename, ".dvi");
  483.     }
  484.  
  485. } /* getfname */
  486.  
  487. /*----------------------------------------------------------------------------*/
  488.  
  489. int getinteger(dest, j, str)
  490. int *dest;
  491. int *j;
  492. char *str;
  493. {
  494.     int  cum;
  495.     int  sgn;
  496.     char ch;
  497.  
  498.     ch = str[*j];
  499.     if (ch == '-') {
  500.         sgn = -1;
  501.         ch  = str[++(*j)];
  502.     }
  503.     else
  504.         sgn = 1;
  505.     if ((ch >= '0') && (ch <= '9')) {
  506.         cum = 0;
  507.         while ((ch >= '0') && (ch <= '9')) {
  508.             cum = cum*10 + ch - '0';
  509.             ch = str[++(*j)];
  510.         }
  511.         *dest = sgn * cum;
  512.         return 0;                   /* return ok */
  513.     }
  514.     return 1;                       /* return error */
  515.  
  516. }   /* getinteger */
  517.  
  518. /*----------------------------------------------------------------------------*/
  519.  
  520. void errorexit(errorcode)
  521. int errorcode;
  522. {
  523.  
  524.     fprintf(stderr, "%s: ", progname);
  525.     switch (errorcode) {
  526.         case  illop : fprintf(stderr, "Illegal op-code found: %d\n", opcode);
  527.                       break;
  528.         case  stkof : fprintf(stderr, "Stack overflow\n");
  529.                       break;
  530.         case  stkuf : fprintf(stderr, "Stack underflow\n");
  531.                       break;
  532.         case  stkrq : fprintf(stderr, "Cannot create dvi stack\n");
  533.                       break;
  534.         case  lnerq : fprintf(stderr, "Cannot allocate memory\n");
  535.                       break;
  536.         case  badid : fprintf(stderr, "Id-byte is not correct: %d\n ", opcode);
  537.                       break;
  538.         case  bdsgn : fprintf(stderr, "Bad signature: %d (not 223)\n",
  539.                                       (int) foo);
  540.                       break;
  541.         case  fwsgn : fprintf(stderr, "%d signature bytes (min. 4)\n",
  542.                                       (int) foo);
  543.                       break;
  544.         case  nopre : fprintf(stderr, "Missing preamble\n");
  545.                       break;
  546.         case  nobop : fprintf(stderr, "Missing beginning-of-page command\n");
  547.                       break;
  548.         case  nopp  : fprintf(stderr, "Missing post-post command\n");
  549.                       break;
  550.         case  bdpre : fprintf(stderr, "Preamble occured inside a page\n");
  551.                       break;
  552.         case  bdbop : fprintf(stderr, "BOP-command occured inside a page\n");
  553.                       break;
  554.         case  bdpst : fprintf(stderr, "Postamble occured before end-of-page\n");
  555.                       break;
  556.         case  bdpp  : fprintf(stderr, "Postpost occured before post-command\n");
  557.                       break;
  558.         case  nopst : fprintf(stderr, "Missing postamble\n");
  559.                       break;
  560.         case  illch : fprintf(stderr, "Character code out of range, 0..127\n");
  561.                       break;
  562.         case  filop : fprintf(stderr, "Cannot open dvifile\n");
  563.                       break;
  564.         case  filcr : fprintf(stderr, "Cannot create outfile\n");
  565.                       break;
  566. #if !defined(MSDOS) && !defined(VMS)
  567.         case  pipcr : fprintf(stderr, "Cannot create pipe to pager\n");
  568.                       break;
  569. #endif
  570.         default     : fprintf(stderr, "Unkown error code\n");
  571.                       break;
  572.     };
  573.     if (outputtofile)
  574. #if defined(VMS)
  575.         remove(OUTfilename);
  576. #else
  577.         unlink(OUTfilename);
  578. #endif
  579.     exit(errorcode);
  580.  
  581. }  /* errorexit */
  582.  
  583. /*----------------------------------------------------------------------------*/
  584.  
  585. void usage(uerr)
  586. int uerr;
  587. {
  588.  
  589.     if (uerr != ign) {
  590.         fprintf(stderr,"%s: ", progname);
  591.         switch (uerr) {
  592.             case   ign    : fprintf(stderr, "%s", Copyright);
  593.                             break;
  594.             case   wrnge  : fprintf(stderr, "width arg out of range:16-132");
  595.                             break;
  596.             case   nan    : fprintf(stderr, "numeric argument expected for option %c",
  597.                                             optch);
  598.                             break;
  599.             case   gae    : fprintf(stderr, "garbage in argument for option %c",
  600.                                             optch);
  601.                             break;
  602.             case   bdlst  : fprintf(stderr, "mal-formed list of pagenumbers");
  603.                             break;
  604.             case   onef   : fprintf(stderr, "only one infile argument allowed");
  605.                             break;
  606.             case   noarg  : fprintf(stderr, "option argument expected for option %c",
  607.                                             optch);
  608.                             break;
  609.             case   bdopt  : fprintf(stderr, "bad option %c", optch);
  610.                             break;
  611.             case   onepp  : fprintf(stderr, "only one pagelist allowed");
  612.                             break;
  613.             default       : fprintf(stderr, "unknown usage error");
  614.                             break;
  615.         }
  616.         fprintf(stderr, "\n");
  617.     }
  618.     fprintf(stderr, "Usage: %s [ options ] dvifile[.dvi]\n", progname);
  619.     fprintf(stderr, "Options are:\n");
  620.     fprintf(stderr,
  621.             " -ofile   Write output to file, else write to stdout.\n");
  622.     fprintf(stderr,
  623.             " -plist   Print pages whos TeX-page-number are in list.\n");
  624.     fprintf(stderr,
  625.             " -Plist   Print pages whos sequential number are in list.\n");
  626.     fprintf(stderr,
  627.             " -wn      Print the lines with width n characters, default 80.\n");
  628. #if !defined(MSDOS) && !defined(VMS)
  629.     fprintf(stderr, " -f       Try to pipe to a pager if output is a tty");
  630.     if (WANTPAGER)
  631.         fprintf(stderr, " (default).\n");
  632.     else
  633.         fprintf(stderr, ".\n");
  634.     fprintf(stderr, " -q       Don't try to pipe to a pager");
  635.     if (WANTPAGER)
  636.         fprintf(stderr, ".\n");
  637.     else
  638.         fprintf(stderr, " (default).\n");
  639.     fprintf(stderr, " -Fprog   Pipe output to pager prog.\n");
  640. #endif
  641.     fprintf(stderr,
  642.             " -l       Write ''^L'' instead of formfeed between pages.\n");
  643.     fprintf(stderr,
  644.             " -u       National Swedish/Finnish characters printed as aaoAAO");
  645.     if (DEFSCAND)
  646.         fprintf(stderr, ".\n");
  647.     else
  648.         fprintf(stderr, " (default).\n");
  649.     fprintf(stderr,
  650.             " -s       National Swedish/Finnish characters printed as }{|][\\");
  651.     if (DEFSCAND)
  652.         fprintf(stderr, " (default).\n");
  653.     else
  654.         fprintf(stderr, ".\n");
  655.     exit(uerr);
  656.  
  657. } /* usage */
  658.  
  659.