home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume26 / pstext / part01 / pstext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-25  |  17.5 KB  |  650 lines

  1. /* 
  2.   pstext 1.3
  3.   by Dan Judd
  4.      St. Olaf College
  5.      11/29/89
  6.  
  7.   updated with several minor bug fixes 12/14/90 Dan Judd
  8.   added -v flag and -x[rlp] and -y[tbp] flags 2/26/91 Dan Judd
  9.   added -T flag 6/24/91 Dan Judd
  10.      
  11.   This program takes plain ascii text and converts it to Postscript.
  12.   It takes a few options.
  13.   [-p ] prints portrait mode 1 page (default)
  14.   [-l ] prints landscape mode 1 page
  15.   [-ld ] dual landscape mode 2 pages per page
  16.   [-d ] dual portrait mode, prints 2 pages per page
  17.   [-n number] number of lines per page
  18.   [-t tabstring ] use a different tabstring size (00000000 default)
  19.   [-f fontname ] use a different font (Courier default)
  20.   [-s pointsize ] use a different point size (12 default)
  21.   [-i pointoffset ] offset pointoffset points from normal (0 default)
  22.   [-cy] turn font checking on (default)
  23.   [-c] turn font checking on
  24.   [-cn] turn font checking off
  25.   [-x value] set x left margin to value 
  26.   [-xl value] set x left margin to value (18 default)
  27.   [-xr value] set x right margin to value (14 default)
  28.   [-xp value] set x page size to value (612 default)
  29.   [-y value] set y top margin to value
  30.   [-yt value] set y top margin to value (8 default)
  31.   [-yb value] set y bottom margin to value (13 default)
  32.   [-yp value] set y page size to value (792 default)
  33.   [-v] print version and quit
  34.   [-T printertype ] set defaults for printertype later flags modify this
  35.  
  36.   Margin values are based on 8 1/2 X 11 inch paper from an Apple
  37.   LaserWriter other printers may vary. To change defaults see
  38.   defines below.
  39.  
  40.   It handles tabs and backspaces in an intelligent way in any font.
  41.  
  42.   Copyright Dan Judd 1989
  43.   This program is freely redistributable, but may not be sold.
  44.   send bug fixes to danjudd@cps.msu.edu
  45.  */
  46.  
  47. #include <stdio.h>
  48. #include <strings.h>
  49. #include <ctype.h>
  50. #define TRUE 1
  51. #define FALSE 0
  52. #define DFLT_PTSIZE 12
  53. #define DFLT_FONT "Courier"
  54. #define DFLT_TABSTRING "00000000"
  55. #define INDENT 0
  56. #define DFLT_STYLE 1
  57. #define DFLT_LINES 0
  58. #define CHECKFONT TRUE
  59. #define XRMARGIN 14
  60. #define XLMARGIN 18
  61. #define XPAGE 612
  62. #define YPAGE 792
  63. #define YTMARGIN 8
  64. #define YBMARGIN 13
  65.  
  66. static char version[] = "pstext version 1.3";
  67.  
  68.  /*
  69.    getfile(fpin,fpout)
  70.     FILE *fpin,fpout;
  71.    Read in text from a file and output appropriate postscript
  72.   */
  73. int getfile(fpin,fpout)
  74.   FILE *fpin,*fpout;
  75.   {
  76.    int ch;
  77.  
  78.    fprintf(fpout,"(");
  79.    while ((ch = getc(fpin))!=EOF) {
  80.    if(isprint(ch)) {
  81.     switch (ch ) {
  82.      case '(':
  83.      case ')':
  84.      case '\\':
  85.         fprintf(fpout,"\\%c",ch);
  86.         break;
  87.      default:    fprintf(fpout,"%c",ch);
  88.         break;
  89.      }
  90.    }
  91.   else {
  92.     switch (ch ) {
  93.      case '\n':    fprintf(fpout,")s\n(");
  94.         break;
  95.      case '\t':    fprintf(fpout,")S\nht (");
  96.         break;
  97.      case '\b':    fprintf(fpout,")S\nbs(");
  98.         break;
  99.      case '\r':    fprintf(fpout,")S\ncr(");
  100.         break;
  101.      case '\f':    fprintf(fpout,")S\nnp(");
  102.         break;
  103.      default:
  104.         break;
  105.         }
  106.       }
  107.    }
  108.  /* send trailer */
  109.  fprintf(fpout,")s\nnp\n");
  110.  return(0);
  111.  }
  112.  /*
  113.     Prints the header of Postscript commands that define
  114.     the various procedures used. Yes it takes a lot of arguements,
  115.     yes that makes it ugly, but is it uglier than using globals?
  116.     I think not.
  117.   */
  118. int printhead(fp,font,size,style,numlines,tabstring,indent,checkfont,
  119.     xrmargin, xlmargin,xpage,ypage,ytmargin,ybmargin,version)
  120.  FILE *fp;
  121.  char *font;
  122.  double size;
  123.  int style;
  124.  int numlines;
  125.  char *tabstring;
  126.  int indent;
  127.  int checkfont;
  128.  int xrmargin;
  129.  int xlmargin;
  130.  int xpage;
  131.  int ypage;
  132.  int ytmargin;
  133.  int ybmargin;
  134.  char *version;
  135.  {
  136.   fprintf(fp,"%%! PS - Adobe\n");
  137.   fprintf(fp,"%% Created by %s by Dan Judd\n",version);
  138.   fprintf(fp,"/PAGE_STYLE %d def\n",style);
  139.   fprintf(fp,"/NUM_LINES %d def\n",numlines);
  140.   fprintf(fp,"/FONT (%s) cvn def\n",font);
  141.   fprintf(fp,"/FONT_SIZE %lf def\n",size);
  142.   fprintf(fp,"%%check if font exists\n");
  143.  
  144. /* this is vaguely device depenent, FontDirectory is standard, but */
  145. /* the Next uses SharedFontDirectory instead. The program won't crash,*/
  146. /* but the only font you can use is Courier. Blech. */
  147. /* if this is a problem just define CHECKFONT as FALSE early in the program*/
  148.   if (checkfont) {
  149.   fprintf(fp,"FontDirectory FONT known not { /FONT (Courier) cvn def} if\n");
  150.    }
  151.   fprintf(fp,"%%misc hardware defs\n");
  152.   if (style > 2) {
  153.     fprintf(fp,"/XLMARGIN %d def\n",xlmargin);
  154.     }
  155.    else
  156.     {
  157.     fprintf(fp,"/XLMARGIN %d def\n",(indent + xlmargin));
  158.     }
  159.   fprintf(fp,"/XRMARGIN %d def\n",xrmargin);
  160.   fprintf(fp,"/XPAGE %d def\n",xpage);
  161.   fprintf(fp,"/YPAGE %d def\n",ypage);
  162.   fprintf(fp,"/YTMARGIN %d def\n",ytmargin);
  163.   if (style < 3) {
  164.     fprintf(fp,"/YBMARGIN %d def\n",ybmargin);
  165.     }
  166.    else
  167.     {
  168.     fprintf(fp,"/YBMARGIN %d def\n",(indent + ybmargin));
  169.     }
  170.   fprintf(fp,"/PAGENUM 1 def\n");
  171.   fprintf(fp,"%%\n");
  172.   fprintf(fp,"%%short defs to save space\n");
  173.   fprintf(fp,"%%\n");
  174.   fprintf(fp,"/bd {bind def} bind def\n");
  175.   fprintf(fp,"/m {moveto} bd\n");
  176.   fprintf(fp,"/l {lineto}bd\n");
  177.   fprintf(fp,"/gs {gsave}bd\n");
  178.   fprintf(fp,"/gr {grestore}bd\n");
  179.   fprintf(fp,"/tr {translate} bd\n");
  180.   fprintf(fp,"/rt {rotate} bd\n");
  181.   fprintf(fp,"%%\n");
  182.   fprintf(fp,"%%Set up vars and np depending on PAGE_STYLE\n");
  183.   fprintf(fp,"%%\n");
  184.   fprintf(fp,"%% Style 1\n");
  185.   fprintf(fp,"1 PAGE_STYLE eq {\n");
  186.   fprintf(fp,"    /PAGES_PER_SHEET 1 def\n");
  187.   fprintf(fp,"    /sp {/SAVEOBJ save def} def\n");
  188.   fprintf(fp,"    /np { showpage SAVEOBJ restore sp bp } bd\n");
  189.   fprintf(fp,"    } if\n");
  190.   fprintf(fp,"%% Style 2\n");
  191.   fprintf(fp,"2 PAGE_STYLE eq {\n");
  192.   fprintf(fp,"    /PAGES_PER_SHEET 2 def\n");
  193.   fprintf(fp,"    /sp {/SAVEOBJ save def gs XPAGE 2 div dup 0 m YPAGE l stroke\n");
  194.   fprintf(fp,"        newpath 0 0 m 0 YPAGE l XPAGE 2 div XRMARGIN sub dup\n");
  195.   fprintf(fp,"        YPAGE l 0 l 0 0 l clip\n");
  196.   fprintf(fp,"        } bd\n");
  197.   fprintf(fp,"    /np { /PAGENUM 1 PAGENUM add def\n");
  198.   fprintf(fp,"        PAGENUM PAGES_PER_SHEET\n");
  199.   fprintf(fp,"        gt {gr showpage SAVEOBJ restore sp /PAGENUM 1 def }\n");
  200.   fprintf(fp,"        {gr gs XPAGE 2 div 0 tr} ifelse\n");
  201.   fprintf(fp,"        bp\n");
  202.   fprintf(fp,"        } bd\n");
  203.   fprintf(fp,"    } if\n");
  204.   fprintf(fp,"%% Style 3\n");
  205.   fprintf(fp,"3 PAGE_STYLE eq {\n");
  206.   /* define if you want double page landscape mode to have fonts */
  207.   /* proportional to single page portrait */
  208. #ifdef LANDPROP
  209.   fprintf(fp,"    /FONT_SIZE FONT_SIZE .642 mul def\n");
  210. #endif
  211.   fprintf(fp,"    /TMP XPAGE def\n");
  212.   fprintf(fp,"    /XPAGE YPAGE def\n");
  213.   fprintf(fp,"    /YPAGE TMP def\n");
  214.   fprintf(fp,"    /TMP XRMARGIN def\n");
  215.   fprintf(fp,"    /XRMARGIN YTMARGIN def\n");
  216.   fprintf(fp,"    /YTMARGIN TMP def\n");
  217.   fprintf(fp,"    /TMP XLMARGIN def\n");
  218.   fprintf(fp,"    /XLMARGIN YBMARGIN def\n");
  219.   fprintf(fp,"    /YBMARGIN TMP def\n");
  220.   fprintf(fp,"    /PAGES_PER_SHEET 2 def\n");
  221.   fprintf(fp,"    /sp {/SAVEOBJ save def gs 0 XPAGE tr -90 rt\n");
  222.   fprintf(fp,"        XPAGE 2 div dup 0 moveto YPAGE l stroke\n");
  223.   fprintf(fp,"        newpath 0 0 m 0 YPAGE l XPAGE 2 div XRMARGIN sub dup\n");
  224.   fprintf(fp,"        YPAGE l 0 l 0 0 l clip\n");
  225.   fprintf(fp,"        } bd\n");
  226.   fprintf(fp,"    /np { /PAGENUM 1 PAGENUM add def\n");
  227.   fprintf(fp,"        PAGENUM PAGES_PER_SHEET\n");
  228.   fprintf(fp,"        gt {gr showpage SAVEOBJ restore sp /PAGENUM 1 def }\n");
  229.   fprintf(fp,"        {gr gs 0 XPAGE 2 div tr -90 rt } ifelse\n");
  230.   fprintf(fp,"        bp\n");
  231.   fprintf(fp,"        } bd\n");
  232.   fprintf(fp,"    } if\n");
  233.   fprintf(fp,"%% Style 4\n");
  234.   fprintf(fp,"4 PAGE_STYLE eq {\n");
  235.   fprintf(fp,"    /TMP XPAGE def\n");
  236.   fprintf(fp,"    /XPAGE YPAGE def\n");
  237.   fprintf(fp,"    /YPAGE TMP def\n");
  238.   fprintf(fp,"    /TMP XRMARGIN def\n");
  239.   fprintf(fp,"    /XRMARGIN YTMARGIN def\n");
  240.   fprintf(fp,"    /YTMARGIN TMP def\n");
  241.   fprintf(fp,"    /TMP XLMARGIN def\n");
  242.   fprintf(fp,"    /XLMARGIN YBMARGIN def\n");
  243.   fprintf(fp,"    /YBMARGIN TMP def\n");
  244.   fprintf(fp,"    /PAGES_PER_SHEET 1 def\n");
  245.   fprintf(fp,"    /sp {/SAVEOBJ save def gs 0 XPAGE tr -90 rt\n");
  246.   fprintf(fp,"        } bd\n");
  247.   fprintf(fp,"    /np { gr showpage SAVEOBJ restore sp bp} bd\n");
  248.   fprintf(fp,"    } if\n");
  249.   fprintf(fp,"%%\n");
  250.   fprintf(fp,"%%set up fonts\n");
  251.   fprintf(fp,"%%\n");
  252.   fprintf(fp,"NUM_LINES 1 ge {FONT findfont 1 scalefont setfont\n");
  253.   fprintf(fp,"    /FONT_UPPER currentfont /FontBBox get 3 get 0 exch\n");
  254.   fprintf(fp,"    currentfont /FontMatrix get transform exch pop def\n");
  255.   fprintf(fp,"    /FONT_LOWER currentfont /FontBBox get 1 get 0 exch\n");
  256.   fprintf(fp,"    currentfont /FontMatrix get transform exch pop def\n");
  257.   fprintf(fp,"    /FONT_HT  FONT_UPPER FONT_LOWER  sub def\n");
  258.   fprintf(fp,"    /FONT_SIZE YPAGE YBMARGIN sub YTMARGIN sub 1 sub\n");
  259.   fprintf(fp,"    NUM_LINES div FONT_HT 1 gt  {FONT_HT div } if def\n");
  260.   fprintf(fp,"    } if\n");
  261.   fprintf(fp,"\n");
  262.   fprintf(fp,"FONT findfont FONT_SIZE scalefont setfont\n");
  263.   fprintf(fp,"\n");
  264.   fprintf(fp,"%%get height of font set tolerances\n");
  265.   fprintf(fp,"    /FONT_UPPER currentfont /FontBBox get 3 get 0 exch\n");
  266.   fprintf(fp,"    currentfont /FontMatrix get transform exch pop def\n");
  267.   fprintf(fp,"    /FONT_LOWER currentfont /FontBBox get 1 get 0 exch\n");
  268.   fprintf(fp,"    currentfont /FontMatrix get transform exch pop def\n");
  269.   fprintf(fp,"    /FONT_HT  FONT_UPPER FONT_LOWER sub def\n");
  270.   fprintf(fp,"    FONT_HT 0 eq {/FONT_HT FONT_SIZE def } if\n");
  271.   fprintf(fp,"    /FONT_MOVE FONT_SIZE FONT_HT gt {FONT_SIZE def} {FONT_HT def} ifelse\n");
  272.   fprintf(fp,"/FONT_TOL FONT_HT YBMARGIN add def\n");
  273.   fprintf(fp,"%%\n");
  274.   fprintf(fp,"%%Routines common to all page styles\n");
  275.   fprintf(fp,"%%\n");
  276.   fprintf(fp,"/bp { XLMARGIN YPAGE YTMARGIN sub FONT_UPPER sub m\n");
  277.   fprintf(fp,"    } bd\n");
  278.   fprintf(fp,"/s { show  currentpoint exch pop dup FONT_TOL\n");
  279.   fprintf(fp,"    gt {FONT_MOVE sub XLMARGIN  exch m} {np} ifelse}  bd\n");
  280.   fprintf(fp,"/S {show} bd\n");
  281.   fprintf(fp,"/OFFSET (_) stringwidth pop neg def\n");
  282.   fprintf(fp,"/bs { OFFSET 0 rmoveto } bd\n");
  283.   fprintf(fp,"/bs {XLMARGIN currentpoint pop OFFSET add lt {OFFSET 0 rmoveto}\n");
  284.   fprintf(fp,"{XLMARGIN currentpoint exch pop m}ifelse} bd\n");
  285.   fprintf(fp,"/TABLEN (%s) stringwidth pop def\n",tabstring);
  286.  
  287. /* Multiple tabs in succession don't always work due to floating point
  288.  * math routing.  On the QMS PS-410, more than two tabs in succession
  289.  * caused the procedure to hang at the second tab spot because the
  290.  * calculation of (curpoint - XLMARGIN)/TABLEN was always less than 2.
  291.  * Add one percent of the tabwidth to the current point before calculating
  292.  * the next tab position to force it over the edge.  This won't affect
  293.  * regular tabs since this (and any other remainder) is discarded by the
  294.  * 'cvi' function.
  295.  */
  296.   fprintf(fp,"/ht {currentpoint exch TABLEN .01 mul add XLMARGIN sub TABLEN div \n");
  297.   fprintf(fp,"    cvi 1 add TABLEN mul XLMARGIN add exch m}bd\n");
  298.   fprintf(fp,"/cr {currentpoint XLMARGIN exch m pop} bd\n");
  299.   fprintf(fp,"/lp {gr 1 PAGENUM ne {showpage}if} bd\n");
  300.   fprintf(fp,"%%\n");
  301.   fprintf(fp,"%%begin data et al\n");
  302.   fprintf(fp,"%%\n");
  303.   fprintf(fp,"sp\n");
  304.   fprintf(fp,"bp\n");
  305.   return(0);
  306.  }
  307.  
  308. /*
  309.  * setupdevice - sets up defaults for a given printer type,
  310.  *   returns 0 if printer type set ok.
  311.  *   returns 1 if unknown printer type 
  312.  */
  313.  
  314. int setupdevice(type,checkfont,xrmargin,xlmargin,xpage,ypage,ytmargin,ybmargin)
  315.  char *type; /* printer type */
  316.  int *checkfont;
  317.  int *xrmargin;
  318.  int *xlmargin;
  319.  int *xpage;
  320.  int *ypage;
  321.  int *ytmargin;
  322.  int *ybmargin;
  323.  {
  324.   char tmptype[256];
  325.   int tmpi;
  326.  
  327.   for (tmpi = 0; type[tmpi] != '\0'; tmpi++) {
  328.      if ( isupper(type[tmpi] )) {
  329.     tmptype[tmpi] = tolower(type[tmpi]);
  330.     }
  331.        else {
  332.     tmptype[tmpi] = type[tmpi];
  333.     }
  334.       }
  335.  
  336.   if (strcmp (tmptype, "alwnt") == 0 || strcmp (tmptype, "alwntx") == 0) 
  337.     {
  338.     *checkfont = TRUE;
  339.     *xrmargin = 14;
  340.     *xlmargin = 18;
  341.     *xpage = 612;
  342.     *ypage = 792;
  343.     *ytmargin = 8;
  344.     *ybmargin = 13;
  345.     return (0);
  346.     }
  347.  
  348.   if (strcmp (tmptype, "next") == 0) 
  349.     {
  350.     *checkfont = FALSE;
  351.     *xrmargin = 9;
  352.     *xlmargin = 11;
  353.     *xpage = 612;
  354.     *ypage = 792;
  355.     *ytmargin = 10;
  356.     *ybmargin = 10;
  357.     return (0);
  358.     }
  359.  
  360.   if (strcmp (tmptype, "hpiii") == 0 ) 
  361.     {
  362.     *checkfont = TRUE;
  363.     *xrmargin = 18;
  364.     *xlmargin = 18;
  365.     *xpage = 612;
  366.     *ypage = 792;
  367.     *ytmargin = 18;
  368.     *ybmargin = 18;
  369.     return (0);
  370.     }
  371.    return (1);
  372.  }
  373.  
  374. /*
  375.  * main program 
  376.  * args parsed, initial values set.
  377.  */
  378. main(argc,argv)
  379. int argc;
  380. char *argv[];
  381. {
  382.  double ptsize = DFLT_PTSIZE;
  383.  char *font;
  384.  char *tabstring;
  385.  int style = DFLT_STYLE;
  386.  int numlines = DFLT_LINES;
  387.  int indent = INDENT;
  388.  FILE *fpout = stdout;
  389.  FILE *fpin = stdin;
  390.  short badflag = FALSE;
  391.  int checkfont = CHECKFONT;
  392.  int xrmargin = XRMARGIN;
  393.  int xlmargin = XLMARGIN;
  394.  int xpage = XPAGE;
  395.  int ypage = YPAGE;
  396.  int ytmargin = YTMARGIN;
  397.  int ybmargin = YBMARGIN;
  398.  char *type; /* printer type */
  399.  char ch; /* tmp character holder */
  400.  int tmpint; /* tmp integer holder */
  401.  char *progname;
  402.  double atof();
  403.  
  404.  font = (char *) malloc(sizeof(DFLT_FONT));
  405.  strcpy(font,DFLT_FONT);
  406.  tabstring = (char *) malloc(sizeof(DFLT_TABSTRING));
  407.  strcpy(tabstring,DFLT_TABSTRING);
  408.  /* parse args */
  409.  progname =  *argv++;
  410.  
  411.  while ((--argc > 0)&&(*argv[0]=='-')) {
  412.    switch(*++argv[0]) {
  413.     
  414.     case 'l':    if(*++argv[0]=='d') {
  415.           style = 3;
  416.           }
  417.          else {
  418.           style = 4;
  419.           };
  420.         break;
  421.     case 'p':    style = 1;
  422.         break;
  423.     case 'd':    style = 2;
  424.         break;
  425.     case '\0':    argc = 1;    /* read only standard input */
  426.         break;
  427.     case 'f':    if (*++argv[0] != '\0'){
  428.           font =  *argv;
  429.          }
  430.         else
  431.          if (--argc) {
  432.           font =  *++argv;
  433.           }
  434.          else {
  435.           badflag = TRUE;
  436.           }
  437.         break;
  438.     case 't':    if (*++argv[0] !='\0'){
  439.           tabstring =  *argv;
  440.          }
  441.         else
  442.          if (--argc) {
  443.           tabstring =  *++argv;
  444.           }
  445.          else {
  446.           badflag = TRUE;
  447.           }
  448.         break;
  449.  
  450.     case 'T':    if (*++argv[0] !='\0'){
  451.           type =  *argv;
  452.          }
  453.         else
  454.          if (--argc) {
  455.           type =  *++argv;
  456.           }
  457.          else {
  458.           badflag = TRUE;
  459.           }
  460.         if ( setupdevice(type, &checkfont, &xrmargin, &xlmargin,
  461.              &xpage, &ypage, &ytmargin, &ybmargin) != 0 ) {
  462.            fprintf(stderr,"Unknown printer type: %s \n",type);
  463.            badflag = TRUE;
  464.            }
  465.  
  466.         break;
  467.     case 'n':    if (*++argv[0] !='\0'){
  468.           if((numlines = atof(*argv)) <= 0){
  469.             fprintf(stderr,"specify a line number 1 or more\n");
  470.             badflag = TRUE;
  471.             }
  472.         }
  473.         else
  474.         if (--argc) {
  475.           if((numlines = atof(*++argv)) <= 0){
  476.             fprintf(stderr,"specify a line number 1 or more\n");
  477.             badflag = TRUE;
  478.             }
  479.           }
  480.          else {
  481.           badflag = TRUE;
  482.           }
  483.         break;
  484.     case 'i':    if (*++argv[0] !='\0'){
  485.           if((indent = atof(*argv)) <= 0){
  486.             fprintf(stderr,"specify a point offset of 1 or more\n");
  487.             badflag = TRUE;
  488.             }
  489.         }
  490.         else
  491.         if (--argc) {
  492.           if((indent = atof(*++argv)) <= 0){
  493.             fprintf(stderr,"specify a point offset of 1 or more\n");
  494.             badflag = TRUE;
  495.             }
  496.           }
  497.          else {
  498.           badflag = TRUE;
  499.           }
  500.         break;
  501.     case 's':    if (*++argv[0] !='\0'){
  502.           if((ptsize = atof(*argv)) <= 0){
  503.             fprintf(stderr,"specify a point size greater than 0\n");
  504.             badflag = TRUE;
  505.             }
  506.         }
  507.         else
  508.         if (--argc) {
  509.           if((ptsize = atof(*++argv)) <= 0){
  510.             fprintf(stderr,"specify a point size greater than 0\n");
  511.             badflag = TRUE;
  512.             }
  513.           }
  514.          else {
  515.           badflag = TRUE;
  516.           }
  517.         break;
  518.     case 'c':    if(*++argv[0]=='n') {
  519.           checkfont = FALSE;
  520.           }
  521.          else {
  522.           checkfont = TRUE;
  523.           };
  524.         break;
  525.     case 'x':    ch = *++argv[0];
  526.         switch (ch) {
  527.           case '\0':
  528.           case 'r':
  529.           case 'l':
  530.           case 'p':
  531.                    if (*++argv[0] !='\0'){
  532.                  if((tmpint = atof(*argv)) < 0){
  533.                    fprintf(stderr,"specify value greater than 0\n");
  534.                    badflag = TRUE;
  535.                      }
  536.                      }
  537.                 else
  538.                if (--argc) {
  539.                  if((tmpint = atof(*++argv)) < 0){
  540.                     fprintf(stderr,"specify value greater than 0\n");
  541.                     badflag = TRUE;
  542.                    }
  543.                  }
  544.                 else {
  545.                  badflag = TRUE;
  546.                  }
  547.                 break;
  548.                default:    badflag = TRUE;
  549.                    fprintf(stderr,"bad case %c with x flag\n",ch);
  550.                 break;
  551.             }
  552.         if (! badflag) {
  553.           switch (ch) {
  554.             case '\0':
  555.             case 'l':   xlmargin = tmpint;
  556.                 break;
  557.             case 'r':   xrmargin = tmpint;
  558.                 break;
  559.             case 'p':   xpage = tmpint;
  560.                 break;
  561.             }
  562.               }
  563.            
  564.         break;
  565.  
  566.     case 'y':    ch = *++argv[0];
  567.         switch (ch) {
  568.           case '\0':
  569.           case 't':
  570.           case 'b':
  571.           case 'p':
  572.                    if (*++argv[0] !='\0'){
  573.                  if((tmpint = atof(*argv)) < 0){
  574.                    fprintf(stderr,"specify value greater than 0\n");
  575.                    badflag = TRUE;
  576.                      }
  577.                      }
  578.                 else
  579.                if (--argc) {
  580.                  if((tmpint = atof(*++argv)) < 0){
  581.                     fprintf(stderr,"specify value greater than 0\n");
  582.                     badflag = TRUE;
  583.                    }
  584.                  }
  585.                 else {
  586.                  badflag = TRUE;
  587.                  }
  588.                 break;
  589.                default:    badflag = TRUE;
  590.                    fprintf(stderr,"bad case %c with y flag\n",ch);
  591.                 break;
  592.             }
  593.         if (! badflag) {
  594.           switch (ch) {
  595.             case '\0':
  596.             case 't':   ytmargin = tmpint;
  597.                 break;
  598.             case 'b':   ybmargin = tmpint;
  599.                 break;
  600.             case 'p':   ypage = tmpint;
  601.                 break;
  602.             }
  603.               }
  604.            
  605.         break;
  606.  
  607.     case 'v':    fprintf(stdout,"%s\n",version);
  608.         return(0);
  609.         break;
  610.     default:    badflag = TRUE;
  611.         break;
  612.  
  613.     }
  614. if(badflag) {
  615.  fprintf(stderr,"Usage: %s [-p] [-l] [-ld] [-d] [-n lines ] [-t ",progname);
  616.  fprintf(stderr,"tabstring] [-f fontname] [-s pointsize] [-i point offset]");
  617.  fprintf(stderr," [-T printertype ] ");
  618.  fprintf(stderr,"[-c[yn] [-x[rlp] size] [-y[btp] size] [file1 ... ]\n");
  619.  return(1);
  620.   }
  621.     *argv++;
  622.     }
  623.  
  624.  /* set up postscript header */
  625.  
  626.  printhead(fpout,font,ptsize,style,numlines,tabstring,indent,checkfont,
  627.     xrmargin, xlmargin,xpage,ypage,ytmargin,ybmargin,version);
  628.  /* read files */
  629.  if (argc <=0) {
  630.    getfile(stdin,fpout);
  631.    }
  632.   else {
  633.    while(argc--!=0) {
  634.     if((fpin = fopen(*argv,"r"))!=NULL) {
  635.       getfile(fpin,fpout);
  636.       fclose(fpin);
  637.       *argv++;
  638.       }
  639.      else{
  640.       fprintf(stderr,"Unable to open file %s\n",*argv);
  641.       fprintf(fpout,"\nlp\n");
  642.       return(1);
  643.       }
  644.     }
  645.   }
  646.  /* makesure showpage is done so last page prints */
  647.  fprintf(fpout,"\nlp\n");
  648.  return(0);
  649.  }
  650.