home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume2 / split-1.1 / part01 next >
Encoding:
Internet Message Format  |  1991-08-07  |  19.1 KB

  1. From: richard@gryphon.CTS.COM (Richard Sexton)
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i064: split -- V1.1
  4. Message-ID: <7467@ncoast.UUCP>
  5. Date: 5 Mar 88 22:12:23 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. Comp.sources.misc: Volume 2, Issue 64
  9. Submitted-By: "Richard Sexton" <richard@gryphon.CTS.COM>
  10. Archive-Name: split-1.1/part01
  11.  
  12. After a humbling lesson in argument passing, here is a fixed
  13. up version of split.
  14.  
  15. This one should work on Apollos and Suns.
  16.  
  17. Usage:
  18.  
  19. split file  --  makes file.ps from fil
  20.  
  21. split -ifile -oblat.ps   --  makes blat.ps from file
  22.  
  23. split file1 file2 file3 -fCourier  -- makes file1.ps, file3.ps, file3.ps in 
  24.                                       the courier font.
  25.  
  26. Note that you can go "split files switches" or "split switches files"
  27.  
  28. The -i and -o switches are mostly for you PC guys who cant handle filenames
  29. like this.that.and.the.other, as the program wants to just stuff a .ps
  30. on the end.
  31.  
  32. Let me know if there are any problems.
  33.  
  34. =============== snip ========== snipity snip =========== snip ============
  35.  
  36. #include "stdio.h"
  37.  
  38. /*  split.c  28-feb-88
  39.  
  40.     Copyright 1988 Richard John Sexton
  41.     All rights reserved 
  42.  
  43.     Permission to use all or part of this program without fee is
  44.     granted provided that it is not used or distributed for direct
  45.     commercial gain, the above copyright notice appears, and
  46.     notice is given that use is by permission of Richard J. Sexton
  47.  
  48.         richard@gryphon.CTS.COM
  49.         rutgers!marque!gryphon!richard
  50. */
  51.  
  52.  
  53. #define _toupper(x) ((x)&0x5f)
  54.  
  55. #define CR 10
  56. #define LF 13
  57.  
  58. #define TRUE 1
  59. #define FALSE 0
  60.  
  61. #define TOP_MARGIN_DEFAULT 25
  62. #define BOTTOM_MARGIN_DEFAULT 25
  63.  
  64. #define POINTS_ACROSS ((85 * 72) / 10)
  65. #define POINTS_DOWN ((110 * 72) / 10)
  66.  
  67. FILE *in, *out;
  68. unsigned char *fword, swarray [26], fontname[256] = "Helvetica";
  69. unsigned long swvalues [26];
  70. short i, fontsize, pt_row_cntr, lines, linecntr, col_nbr, nbr_cols, xpos;
  71. short  ypos, yils, page_nbr, colums = 1, rotate = 0, maxx, maxy, temp1;
  72. short temp2, switch_num, border_value, lm_offset, title;
  73. short top_margin, bottom_margin;
  74. short nbr_copies = 1;
  75. short infsw;
  76. unsigned char title_text[256] ="", outfilename[1081] = "", infilename[1081] = "";
  77.  
  78. char *sploptstr = "123b:c:f:h:i:l:n:o:p:r:t:";
  79.  
  80. int    opterr = 1;
  81. int    optind = 1;
  82. int filind = 1;
  83. int    optopt;
  84. int fillo, filhi, filenum;
  85. int saved = 1;
  86.  
  87. char *optarg, saved_c;
  88.  
  89. main (argc, argv)
  90. short argc;
  91. unsigned char *argv[];
  92.    {
  93.    unsigned short ctemp;
  94.    unsigned char c, *s, *d;
  95.  
  96.  
  97.    printf ("\n   Split V1.1  Copyright 1988 by Richard J. Sexton.  All rights reserved.\n   Never to be sold.\n\n");
  98.   
  99.    init_data (); 
  100.  
  101.    /* Get values of switches, if any */
  102.  
  103.    if (argc == 1)
  104.       {
  105.       print_help ('\0', argv);    /* no files or switches, print help */
  106.       exit (0);
  107.       }
  108.  
  109.     infsw = 0;                /* assume we got no input files */
  110.  
  111.     set_optind (argc, argv);
  112.  
  113.     pass_switches (argc, argv);
  114.  
  115.     if (argc == optind)
  116.         {
  117.         fillo = 1; filhi = saved;   /* files came first, then switches */
  118.         }
  119.     else
  120.         {
  121.         fillo = optind; filhi = argc;  /* switches came first, then files */
  122.         }
  123.  
  124. /* main loop */
  125.  
  126.     filenum = fillo;
  127.  
  128.     do {
  129.  
  130.     reinit_data ();
  131.  
  132.     if (*infilename == '\0')
  133.         {
  134.         scopy (argv[filenum] + infsw, infilename);
  135.         }
  136.  
  137.    if (!lines) 
  138.       {
  139.       lines = (rotate ? 500 : 675) / (((fontsize ? fontsize : 10) * 3) / 2);
  140.       }
  141.  
  142.    in = fopen (infilename, "r");
  143.  
  144.  
  145.     if (!(*outfilename))
  146.         {
  147.            d = outfilename;
  148.            s = infilename;
  149.  
  150.            for (;*s;)
  151.               {
  152.               *d++ = *s++;
  153.            }
  154.  
  155.         scopy (".ps", d);
  156.         }
  157.  
  158.    out = fopen (outfilename, "w");
  159.  
  160.    if (in == 0)  {printf ("(%s): Can't open file '%s' for input.\n", argv[0], infilename); exit(1);}
  161.    if (out == 0) {printf ("(%s): Can't open %s.ps for output.\n", argv[0], outfilename); exit (2);}
  162.  
  163.    printf ("\n%s --> %s\n", infilename, outfilename);
  164.  
  165.    /* Insert stupid Adobe header */
  166.  
  167.    fprintf (out, "%%!PS-Adobe-1.0\n");
  168.    fprintf (out, "%%Creator: The program '%s'\n", argv[0]);
  169.    fprintf (out, "%%Title: %s\n", outfilename);
  170.    fprintf (out, "%%Pages: (atend)\n");
  171.    fprintf (out, "%%DocumentFonts: (atend)\n");
  172.    fprintf (out, "%%EndComments\n\n");
  173.  
  174.    fprintf (out, "/yline %d def\n/xline %d def\n/%s findfont %d scalefont setfont\n/yils %d def\n",
  175.    (rotate ? (-lm_offset) : 725), lm_offset, fontname, fontsize, fontsize + (fontsize / 2));
  176.  
  177.    /* Define clipping path(s) */
  178.  
  179.    for (i = 0; i < nbr_cols; i++)
  180.       {
  181.       temp1 = lm_offset + (((maxx - 110) / (nbr_cols)) * i);
  182.  
  183.       temp2 = lm_offset + (((maxx - 110) / (nbr_cols)) * (i + 1));
  184.       temp2 -= 6;
  185.  
  186.       fprintf (out, "/clippath%d { newpath %d 999 moveto %d -999 lineto",
  187.       i, temp1, temp1);
  188.  
  189.       fprintf (out, " %d -999 lineto %d 999 lineto closepath} def\n",
  190.       temp2, temp2);
  191.       }
  192.  
  193.    fprintf (out, "/nl {/yline yline yils sub def xline yline moveto show } def\n");
  194.    fprintf (out, "/move {moveto} def\n/draw {lineto} def\n");
  195.  
  196.    if (rotate)
  197.       {
  198.       fprintf (out, "90 rotate\n");
  199.       }
  200.  
  201.    fprintf (out, "gsave\nclippath0 clip\n");
  202.  
  203.    fprintf (out, "%%EndProlog\n%%Page 0 1\n");
  204.  
  205.    fprintf (out, "\n(");
  206.  
  207.    while ((c = getc (in)) != 0xff)
  208.       {
  209.       if ((c == CR) || (c == LF))
  210.          {
  211.          /* Hit a CR or LF, move to a new line */
  212.          /* If your files have CR LF then you have a problem */
  213.          /* Mine don't */
  214.  
  215.          fprintf (out, ") nl");
  216.          pt_row_cntr -= yils;
  217.          linecntr++;
  218.  
  219.          if (((lines == 0) && (pt_row_cntr <= 150)) ||
  220.             ((lines) && (linecntr == lines)))
  221.             {
  222.             colum_break ();
  223.             pt_row_cntr = maxy;
  224.             linecntr = 0;
  225.             }
  226.  
  227.          fprintf (out, "\n(");
  228.          }
  229.       else
  230.          {
  231.          /* Output a line of text */
  232.  
  233.          if (c == '/' || c == '\\' 
  234.          ||  c == '(' || c == ')'
  235.          ||  c == '[' || c == ']'
  236.          ||  c == '{' || c == '}')
  237.             {
  238.             fprintf (out, "\\");
  239.             }
  240.          fprintf (out, "%c", c);
  241.          }
  242.       }
  243.  
  244.    fprintf (out, ")\n/yline yline yils sub def\nxline yline moveto\nshow\n");
  245.  
  246.    draw_border ();
  247.    draw_title ();
  248.  
  249.     for (i = 0; i < nbr_copies; i++)  fprintf (out, "copypage\n");
  250.  
  251.    fprintf (" erasepage grestore\n");
  252.  
  253.    fprintf (out, "%%Trailer\n%%DocumentFonts: %s", fontname);
  254.  
  255.    if ((strcmp (fontname, "Helvetica") != NULL) && title)
  256.     {
  257.     fprintf (out, ", Helvetica");
  258.     }
  259.  
  260.    fprintf (out, "\n%%Pages: %d\n", page_nbr);
  261.  
  262.    fclose (out);
  263.    fclose (in);
  264.  
  265.    printf ("%d page%s printed.\n\n", page_nbr, (page_nbr == 1 ? "" : "s"));
  266.  
  267.    *infilename = '\0';
  268.    *outfilename = '\0';
  269.  
  270.  
  271.     if (infsw == 2) {filenum--; infsw = 0;}
  272.  
  273.    } while (++filenum < filhi);
  274.  
  275.   }
  276.  
  277. /******************** Local support routines ***************************/
  278.  
  279. scopy (s, d)
  280. unsigned char *s, *d;
  281.    {
  282.    while (*s) *d++ = *s++; *d = 0;
  283.    }
  284.  
  285. colum_break ()
  286.    {
  287.    if (col_nbr++ >= nbr_cols - 1)
  288.       {
  289.       page_break ();
  290.       col_nbr = 0;
  291.       }
  292.    else
  293.       {
  294.       xpos = lm_offset + (((maxx - 110) / (nbr_cols)) * col_nbr);  /*  used to be nbr_cols + 1 */
  295.  
  296.       ypos = rotate ? (-lm_offset) : 725;
  297.       fprintf (out, "/yline %d def\n/xline %d def\n", ypos, xpos);
  298.       }
  299.    fprintf (out, "grestore gsave\nclippath%d clip\n", col_nbr);
  300.    }
  301.  
  302. page_break()
  303.    {
  304.    draw_border ();
  305.    draw_title ();
  306.  
  307.    for (i = 0; i < nbr_copies; i++) fprintf (out, "\ncopypage\n");
  308.  
  309.    fprintf (out, "erasepage\n%%Page %d %d\n", page_nbr - 1, page_nbr);
  310.    if (rotate) fprintf (out, "90 rotate");
  311.  
  312.    xpos = lm_offset; ypos = (rotate ? (-lm_offset) : 725);
  313.    fprintf (out, "/yline %d def\n/xline %d def\n", ypos, xpos);
  314.    col_nbr = 0;
  315.    page_nbr++;
  316.    }
  317.  
  318. init_data ()
  319.    {
  320.    register unsigned short i;
  321.  
  322.    fontsize = 10;             /* Set default font size */
  323.    yils = 15;                 /* Y InterLine Spacing = fontsize * 1.5 */
  324.    pt_row_cntr = POINTS_DOWN;         /* Start counter (in points) at T.O.P - 725 */
  325.    col_nbr = 0;
  326.    saved_c = '\0';
  327.    nbr_cols = 1;
  328.    linecntr = 0;
  329.    page_nbr = 1;
  330.    border_value = 0;
  331.    lines = 0;
  332.    switch_num = -1;
  333.    lm_offset = 45;             /* Left margin offset */
  334.    title = 0;                  /* default to no title */
  335.  
  336.    top_margin = TOP_MARGIN_DEFAULT;
  337.    bottom_margin = BOTTOM_MARGIN_DEFAULT;
  338.  
  339.    maxx = POINTS_ACROSS; maxy = POINTS_DOWN;
  340.    }
  341.  
  342. reinit_data ()
  343.    {
  344.    register unsigned short i;
  345.  
  346.    pt_row_cntr = POINTS_DOWN;         /* Start counter (in points) at T.O.P - 725 */
  347.    col_nbr = 0;
  348.    linecntr = 0;
  349.    lines = 0;
  350.    lm_offset = 45;             /* Left margin offset */
  351.    page_nbr = 1;
  352.    }
  353.  
  354. /* 
  355.  * printhelp
  356.  *
  357.  * takes a char, and if its binary zero, displays general
  358.  * help message, else it's assumed to be a character and
  359.  * displays the help screen for that charater.
  360.  *
  361.  */
  362.  
  363. print_help (helpqual,argv)
  364. unsigned char helpqual;
  365. char **argv;
  366.    {
  367.    switch (toupper (helpqual))
  368.       {
  369.       case 0:
  370.          {
  371.          printf ("\n Usage:   '%s -ifile',  output goes to 'file.ps'.\n\n", argv[0], argv[0]);
  372.          printf ("\n Options are:\n");
  373.          printf ("    -bn    Draw border around text, format 'n'\n");
  374.          printf ("    -cn    Set text in 'n' colums across\n");
  375.          printf ("    -fname Set text in font 'name'\n");
  376.          printf ("    -h[s]  '%s -h' gets help. '%s -hs' gets help about subject 's'.\n", argv[0], argv[0]);
  377.          printf ("    -ifile Input file name.\n");
  378.          printf ("    -ln    Limit text to 'n' lines per column\n");
  379.          printf ("    -n     Print 'n' copies\n");
  380.          printf ("    -ofile Output file name.\n");
  381.          printf ("    -rn    rendering orientation 'n'. n = l for landscape, p for portrait\n");
  382.          printf ("    -pn    Set text 'n' points tall\n");
  383.          printf ("    -n     Use predefined format n:\n");
  384.          printf ("\n         1 = portrait, 2 columns of 6pt Helvetica\n");
  385.          printf ("         2 = landscape, 2 columns of 6pt Helvetica\n");
  386.          printf ("         3 = landscape, 1 column, 18pt Times Roman\n\n");
  387.          printf ("    -ttext Print title = text and page # on every page\n");
  388.          printf ("\nThe default output format is portrait, 10pt Helvetica\n");
  389.          break;
  390.          }
  391.  
  392.       case 'B':
  393.          {
  394.            printf ("\n                         ** Border formats **\n\n");
  395.            printf ("       The qualifier for the -b switch is a number 0 - 127.\n");
  396.            printf ("       -b0 draws a box around the whole page.\n\n");
  397.            printf ("       The individual lines are binary encoded as follows:\n\n");
  398.  /*border shit */          printf ("              1 = left border line          2 = top line\n");
  399.            printf ("              4 = right border line         8 = bottom line\n");
  400.            printf ("             16 = middle line (does not connect with top and bottom\n");
  401.            printf ("             32 = middle connecting line (top)\n");
  402.            printf ("             64 = middle connecting line (bottom)\n\n");
  403.            printf ("       These last two connect the middle line to the top and bottom and\n");
  404.            printf ("       draw a small cross where they intersect to aid registration.\n\n");
  405.            printf ("       These numbers can be used alone or added together. For example:\n\n");
  406.            printf ("       -b16 would draw a line between columns\n");
  407.            printf ("       -b15 would draw the four lines forming a box around the column(s)\n");
  408.            printf ("        (15 = 8 + 4 + 2 + 1)\n");
  409.          break;
  410.  
  411.          }
  412.  
  413.       case 'C':
  414.          {
  415.          break;
  416.          }
  417.  
  418.       case 'F':
  419.          {
  420.          break;
  421.          }
  422.  
  423.       case 'H':
  424.          {
  425.          break;
  426.          }
  427.  
  428.       case 'L':
  429.          {
  430.          break;
  431.          }
  432.  
  433.       case 'N':
  434.          {
  435.          break;
  436.          }
  437.  
  438.       case 'O':
  439.          {
  440.          break;
  441.          }
  442.  
  443.       case 'P':
  444.          {
  445.          }
  446.  
  447.       }      /* End switch */
  448.   exit (0);
  449.    }
  450.  
  451. /*   pass_switches - pass command line switches for split
  452.  
  453. **  options:
  454. **
  455. **        -b         
  456. **        -c    
  457. **        -f
  458. **        -l
  459. **        -n
  460. **        -o
  461. **        -p
  462. */
  463.  
  464. pass_switches (argc, argv)
  465. int argc;
  466. char **argv;
  467.     {
  468.     register unsigned c;
  469.  
  470. /*
  471. **  Process command line arguments
  472. */
  473.     while ((c = getopt(argc, argv, sploptstr)) != EOF) {
  474.  
  475.         switch ( c ) {
  476.  
  477.         case 'b':
  478.             {
  479.             /* box stuff. */
  480.  
  481.             if (*optarg)
  482.                 {
  483.                 border_value = atoi (optarg);
  484.                 if (border_value < 1 || border_value > 256)
  485.                     {
  486.                     border_value = 15; /* default to box */
  487.                     }
  488.                 }
  489.             break;
  490.             }
  491.  
  492.         case NULL:
  493.             {
  494.             printf ("Oh shit!\n");
  495.             break;
  496.             }
  497.  
  498.         case 'c':
  499.             {
  500.  
  501.             /* colums, number of */
  502.  
  503.             if (*optarg)
  504.                 {
  505.                 nbr_cols = atoi (optarg);
  506.                 if (nbr_cols < 1 || nbr_cols > 256)
  507.                     {
  508.                     nbr_cols = 15; /* default to box */
  509.                     }
  510.                 }
  511.             break;
  512.             }
  513.         
  514.         case 'f':
  515.             {
  516.  
  517.             /* fontname */
  518.  
  519.             (void) strcopy (fontname, optarg);
  520.             break;
  521.             }
  522.  
  523.  
  524.         case 'h':
  525.             {
  526.             char tc;
  527.  
  528.             /* help */
  529.  
  530.             if (tc = *optarg)
  531.                 {
  532.                 print_help (tc,argv);
  533.                 }    
  534.             break;
  535.             }
  536.  
  537.  
  538.         case 'i':
  539.             {
  540.  
  541.             /* input file name */
  542.  
  543.             (void) strcopy (infilename, optarg);
  544.             infsw = 2;
  545.             break;
  546.             }
  547.  
  548.         
  549.         case 'o':
  550.             {
  551.  
  552.             /* output file name */
  553.  
  554.             (void) strcopy (outfilename, optarg);
  555.             break;
  556.             }
  557.  
  558.  
  559.         case 'r':
  560.             {
  561.  
  562.             /* rendering orientation. -rp = portrait mode, -rl = landscape mode */
  563.  
  564.             register char tc;
  565.  
  566.             tc = *optarg;
  567.  
  568.             if (tc = *optarg)
  569.                 {
  570.                 if (toupper (tc) == 'P')
  571.                     {
  572.                     set_rotate (0);
  573.                     }
  574.                 else
  575.                     {
  576.                     if (toupper (tc) == 'L')
  577.                         {
  578.                         set_rotate (1);
  579.                         }
  580.                     }
  581.                 }
  582.             
  583.             break;
  584.             }
  585.             
  586.  
  587.         case 'l':
  588.             {
  589.  
  590.             /* number of lines per column */
  591.  
  592.             if (*optarg) lines = atoi (optarg);
  593.             break;
  594.             }
  595.  
  596.         case 'n':
  597.             {
  598.  
  599.             /* number of copies */
  600.  
  601.             if (*optarg) nbr_copies = atoi (optarg);
  602.             break;
  603.             }
  604.  
  605.  
  606.         case 'p':
  607.             {
  608.  
  609.             /* point size */
  610.  
  611.             if (*optarg) fontsize = atoi (optarg);
  612.             break;
  613.             }
  614.  
  615.         case 't':
  616.             {
  617.  
  618.             /* Title */
  619.  
  620.             if (*optarg) scopy (optarg, title_text);
  621.             title = 1;
  622.             break;
  623.             }
  624.  
  625.  
  626.          case '1':
  627.             {
  628.             fontsize = 6; nbr_cols = 2;
  629.             break;
  630.             }
  631.  
  632.           case '2':
  633.             {
  634.             set_rotate (1);
  635.             fontsize = 6; nbr_cols = 2;
  636.             break;
  637.             }
  638.  
  639.          case '3':
  640.             {
  641.             fontsize = 18;
  642.             scopy ("Times-Roman", fontname);
  643.             break;
  644.             }
  645.  
  646.         case '?':
  647.             {
  648.  
  649.             /* getopt error'd */
  650.  
  651.             break;
  652.             }
  653.  
  654.         default:
  655.             {
  656.             printf ("%s: valid flags are %s\n", argv[0], sploptstr);
  657.             exit (0);
  658.             }
  659.  
  660.         }   /* end switch */
  661.     }    /* end while */
  662.  
  663.     }  /* end pass_switches */
  664.  
  665.  
  666. set_rotate (num)
  667. short num;
  668.    {
  669.    short t;
  670.  
  671.    if (num != rotate)
  672.       {
  673.       t = maxx; maxx = maxy; maxy = t;
  674.       pt_row_cntr = maxy;
  675.       rotate ^= 1;
  676.       }
  677.    }
  678.  
  679. draw_border ()
  680.    {
  681.    short tx1, ty1, tx2, ty2;
  682.  
  683.     if (border_value)
  684.       {
  685.       tx1 = 40; ty1 = rotate ? (-lm_offset) : 760;
  686.       tx2 = rotate ? 750 : 580; ty2 = rotate ? (-580) : 35;
  687.  
  688.       fprintf (out, "\ngrestore gsave newpath\n");
  689.       fprintf (out, "%d %d move ", tx1, ty1);
  690.  
  691.       /* Draw */
  692.  
  693.       if (border_value & 1)
  694.          {
  695.          fprintf (out, "%d %d draw ", tx1, ty2);
  696.          }
  697.       else
  698.          {
  699.          fprintf (out, "%d %d move ", tx1, ty2);
  700.          }
  701.  
  702.       if (border_value & 8)
  703.          {
  704.          fprintf (out, "%d %d draw ", tx2, ty2);
  705.          }
  706.       else
  707.          {
  708.          fprintf (out, "%d %d move ", tx2, ty2);
  709.          }
  710.  
  711.       if (border_value & 4)
  712.          {
  713.          fprintf (out, "%d %d draw ", tx2, ty1);
  714.          }
  715.       else
  716.          {
  717.          fprintf (out, "%d %d move ", tx2, ty1);
  718.          }
  719.  
  720.       if (border_value & 2)
  721.          {
  722.          fprintf (out, "%d %d draw ", tx1, ty1);
  723.          }
  724.       else
  725.          {
  726.          fprintf (out, "%d %d move ", tx1, ty1);
  727.          }
  728.  
  729.       fprintf (out, "\nclosepath\n");
  730.  
  731.       if (border_value & (16 + 32))
  732.          {
  733.          short tempx, indx;
  734.  
  735.          for (indx = 0; indx < nbr_cols - 1; indx++)
  736.             {
  737.             tempx = lm_offset + (((maxx - 110) / (nbr_cols)) * (indx + 1));
  738.             tempx -= 6;  /* Bump over a bit */
  739.  
  740.             if (border_value & 16)
  741.                {
  742.                fprintf (out, "%d %d move %d %d draw\n",
  743.                tempx, ty1 - 20, tempx, ty2 + 20);    
  744.                }
  745.  
  746.             if (border_value & 32)
  747.                {printf ("32\n");
  748.                fprintf (out, "%d %d move %d %d draw\n",
  749.                        tempx, ty1, tempx, ty1 - 20);
  750.                fprintf (out, "%d %d move %d %d draw\n",
  751.                        tempx - 20, ty1, tempx + 20, ty1);
  752.  
  753.                fprintf (out, "%d %d move %d %d draw\n",
  754.                        tempx, ty2, tempx, ty2 + 20);
  755.                fprintf (out, "%d %d move %d %d draw\n",
  756.                        tempx - 20, ty2, tempx + 20, ty2);
  757.                }
  758.             }
  759.          }
  760.       fprintf (out, "stroke\n");
  761.       }
  762.    }
  763.  
  764.  
  765. draw_title ()
  766.    {
  767.    if (title)
  768.       {
  769.       fprintf (out, "\ngrestore gsave\n"); 
  770.       if (strcmp ("Helvetica", fontname) != NULL)
  771.          {
  772.          fprintf (out, "/Helvetica findfont 12 scalefont setfont\n");
  773.          }
  774.  
  775.       if (rotate)
  776.          {
  777.          fprintf (out, "40 -593 move (%s) show\n", title_text);
  778.          fprintf (out, "600 -593 move (Page %d) show\n", page_nbr);
  779.          }
  780.       else
  781.          {
  782.          fprintf (out, "40 20 move (%s) show\n", title_text);
  783.          fprintf (out, "400 20 move (Page %d) show\n", page_nbr);
  784.          }
  785.  
  786.       if (strcmp ("Helvetica", fontname) != NULL)
  787.          {
  788.          fprintf (out, "/%s findfont %d scalefont setfont\n", fontname, fontsize);
  789.          }
  790.       }
  791.    }
  792.  
  793.    
  794. /*
  795. **    based on: @(#)getopt.c    2.5 (smail) 9/15/87
  796. */
  797.  
  798. int getopt(argc, argv, opts)
  799. int    argc;
  800. char    **argv, *opts;
  801. {
  802.     extern char *strchr();
  803.     static int sp = 1;
  804.     register int c;
  805.     register char *cp;
  806.  
  807.     if(sp == 1)
  808.         if(optind >= argc ||
  809.            argv[optind][0] != '-' || argv[optind][1] == '\0')
  810.             return(EOF);
  811.         else if(strcmp(argv[optind], "--") == NULL) {
  812.             optind++;
  813.             return(EOF);
  814.         }
  815.     saved_c = optopt = c = argv[optind][sp];
  816.  
  817.  
  818.     if(c == ':' || (cp=strchr(opts, c)) == (char *)NULL) {
  819.         printf ("(%s) illegal option -- '%c'\n", argv[0], c);
  820.         if(argv[optind][++sp] == '\0') {
  821.             optind++;
  822.             sp = 1;
  823.         }
  824.         return('?');
  825.     }
  826.  
  827.     if(*++cp == ':') {
  828.         if(argv[optind][sp+1] != '\0')
  829.             optarg = &argv[optind++][sp+1];
  830.         else if(++optind >= argc) {
  831.             sp = 1;
  832.             if (c == 'h') {
  833.                 print_help ('\0', argv);
  834.                 }
  835.             else {
  836.                   printf("(%s) %c option requires an argument.\n", argv[0], c);
  837.                   }
  838.             return('?');
  839.         } else {
  840.             optarg = argv[optind++];
  841.           }
  842.         sp = 1;
  843.     } else {
  844.         if(argv[optind][++sp] == '\0') {
  845.             sp = 1;
  846.             optind++;
  847.         }
  848.         optarg = NULL;
  849.     }
  850.  
  851.     return(c);
  852. }
  853.  
  854. get_file_name (argv)
  855. char **argv;
  856.     {
  857.     char *ptr;
  858.     }
  859.  
  860. strcopy (d, s)
  861. char *s, *d;
  862.     {
  863.     while (*s) *d++ = *s++;
  864.     *d = '\0';
  865.     }
  866.  
  867. set_optind (argc, argv)
  868. int argc;
  869. char **argv;
  870.     {
  871.     static int i;
  872.  
  873.     /* First find the first option (argument with a dash) */
  874.  
  875.     for (i = 1; i < argc; i++)
  876.         {
  877.         if (argv[i][0] == '-')
  878.             {
  879.             optind = i;
  880.             i = argc + 1;
  881.             saved = optind;
  882.             }
  883.         }
  884.     
  885.     for (i = 1; i < argc; i++)
  886.         {
  887.         if (argv[i][0] != '-')
  888.             {
  889.             filind = i;
  890.             i = argc + 1;
  891.             }
  892.         }
  893.     }
  894.  
  895.  
  896. printit (a, b, c, d, argv)
  897. int a, b, c, d;
  898. char **argv;
  899.     {
  900.     int i;
  901.  
  902.     printf ("\n\nFiles = ");
  903.  
  904.     for (i = a; i < b; i++)
  905.         {
  906.         printf ("  %s", argv[i]);
  907.         }
  908.     
  909.     printf ("\nswitches = ");
  910.  
  911.     for (i = c; i < d; i++)
  912.         {
  913.         printf ("  %s", argv[i]);
  914.         }
  915.  
  916.     printf ("\n");
  917.     }
  918.  
  919.  
  920. ================= congratulations ! ============= you got the whole thing ======
  921.  
  922.  
  923.  
  924. thats it.
  925.  
  926.  
  927. -- 
  928.     "Each morning when I wake up to rise, I'm living in a dreamland" 
  929.                           richard@gryphon.CTS.COM 
  930.    {ihnp4!scgvaxd!cadovax, rutgers!marque, codas!ddsw1} gryphon!richard
  931.