home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume12 / psf2 / part04 / psbanner.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-19  |  6.9 KB  |  314 lines

  1. /* ta=4 */
  2. /****************************************************************************
  3. *                p s b a n n e r . c        v 2.0                                *
  4. *                                                                            *
  5. *    Print a banner page on a postscript printer for Xenix 2.2.3                *
  6. *                                                                            *
  7. *    The generated print stream is NOT minimally conforming as per Red Book.    *
  8. *                                                                            *
  9. *    Tony Field.       tony@ajfcal                                              *
  10. ****************************************************************************/
  11.  
  12. #include <stdio.h>
  13. #include "patchlevel.h"
  14.  
  15.  
  16. /*    setup paper dimensions                                    */
  17.  
  18. typedef struct                     /*    measurement in point                    */
  19. {    char    paper_name[60];        /*    name of paper size (for command line)    */
  20.     char    paper_tray[200];    /*    postscript operator to select this tray    */
  21.     int        width;                /*    portrait point width of paper            */
  22.     int        height;                /*    portrait point height of paper            */
  23.     int        lx, ly, ux, uy;
  24. } measure;
  25.  
  26. measure    *p;        /*    working set of parameters  (points to something below)     */
  27.  
  28.                 /*    standard paper sizes in portrait layout.                 */
  29.  
  30. measure    page_types[30] =
  31. {            {     "letter",
  32.                 "statusdict begin lettertray end",
  33.                   612,   792,    18,    15,   593,   777
  34.             },
  35.             {     "legal",
  36.                 "statusdict begin legaltray end",
  37.                   612,  1008,    18,    15,   593,   993
  38.             },
  39.             {    "a4",
  40.                 "statusdict begin a4tray end",
  41.                   595,   842,    18,    15,   578,   827
  42.             },
  43.             {    "b5",
  44.                 "statusdict begin b5tray end",
  45.                   516,   729,    18,    15,   497,   712
  46.             },
  47.             {    "",            /* end of paper list */
  48.                 "",
  49.                  0, 0,  0,  0, 0, 0
  50.             }
  51. };
  52.  
  53. char    slots[4][100] = 
  54. {            "statusdict begin 1 setpapertray end",
  55.             "statusdict begin 2 setpapertray end",
  56.             "",
  57.             ""
  58. } ;
  59. int        nslots = 2;
  60.  
  61. int    X_INDENT    = 30;        /*    points                        */
  62. int Y_INDENT    = 30;
  63. int    BIG_POINT    = 60;        /* changes to point size automatically scale    */
  64. int MED_POINT    = 35;        /* the printout.                                */
  65. int    SMALL_POINT    = 15;
  66. int    UX, UY, DX, DY, MAX_X, MAX_Y;
  67.  
  68. /*    The following arguments are received in the command line
  69.     argvp[9] and argv[10] may be page size and paper tray specifications.
  70. */
  71.  
  72. #define    Userid        argv[1]
  73. #define    Name        argv[2]
  74. #define    Requestid    argv[3]
  75. #define    Printer        argv[4]
  76. #define    Options        argv[5]
  77. #define    Date        argv[6]
  78. #define    Machineid    argv[7]
  79. #define    Title        argv[8]
  80.  
  81. main (argc, argv)
  82. int        argc;
  83. char    *argv[];
  84. {    int        x, y, c, i, set_paper_tray, set_paper_bin;
  85.     char    line[200];
  86.     FILE    *pdef;
  87.     
  88.     if ((pdef = fopen (PDEF, "r")) != NULL)
  89.     {    nslots = 0;
  90.         fgets (line, 199, pdef);
  91.         for (i = 0;  i < 25;  i++)
  92.         {    if (fgets (line, 199, pdef) == NULL)
  93.                 break;
  94.             trim (line);
  95.             if (strncmp (line, "*fonts", 6) == 0)
  96.                 break;
  97.             strcpy (page_types[i].paper_name, line);
  98.             if (fgets (page_types[i].paper_tray, 199, pdef) == NULL)
  99.                 bad_file();
  100.             trim (page_types[i].paper_tray);
  101.             if (fgets (line, 100, pdef) == NULL)
  102.                 bad_file();
  103.             trim (line);
  104.             sscanf (line, "%d%d%d%d%d%d",
  105.                 &page_types[i].width,
  106.                 &page_types[i].height,
  107.                 &page_types[i].lx,
  108.                 &page_types[i].ly,
  109.                 &page_types[i].ux,
  110.                 &page_types[i].uy);
  111.  
  112.         }
  113.         page_types[i].paper_name[0] = '\0';
  114.  
  115.         while (fgets (line, 199, pdef) != NULL)
  116.         {    if (strncmp (line, "*slots", 6) == 0)
  117.             {    while (fgets (line, 90, pdef) != NULL)
  118.                 {    trim (line);
  119.                     if (strncmp (line, "*eof", 4) == 0)
  120.                         break;
  121.                     if (*line)
  122.                     {    strcpy (slots[nslots], line);
  123.                         if (++nslots > 3)
  124.                             break;
  125.                     }
  126.                 }
  127.             }
  128.         }
  129.         fclose (pdef);
  130.     }
  131.     
  132.     MAX_X = page_types[0].width;
  133.     MAX_Y = page_types[0].height;
  134.     set_paper_bin = 0;
  135.     set_paper_tray = -1;
  136.     
  137.     for (i = 9;  i < argc;  i++)
  138.     {    c = argv[i][1];
  139.         switch (c)
  140.         {
  141.         case 'b':
  142.             if ((set_paper_bin = atoi (argv[i+1])) > nslots)
  143.             {    fprintf (stderr, "paper bin greater than %d\n", nslots);
  144.                 exit (1);
  145.             }
  146.             i++;
  147.             break;
  148.  
  149.         case 'g':
  150.             for (set_paper_tray = 0;  page_types[set_paper_tray].paper_name[0];  set_paper_tray++)
  151.             {    if (compare (argv[i+1], page_types[set_paper_tray].paper_name) == 0)
  152.                 {    MAX_X = page_types[set_paper_tray].width;
  153.                     MAX_Y = page_types[set_paper_tray].height;
  154.                     break;
  155.                 }
  156.             }
  157.             if (page_types[set_paper_tray].paper_name[0] == '\0')
  158.             {    fprintf (stderr, "Invalid paper size\n");
  159.                 exit (1);
  160.             }
  161.             i++;
  162.             break;
  163.  
  164.         default: ;
  165.         }
  166.     }
  167.  
  168.     UX    =    X_INDENT;
  169.     UY    =    (MAX_Y - Y_INDENT);
  170.     DX    =    (MAX_X - 2 * X_INDENT);
  171.     DY    =    (BIG_POINT * 3);
  172.  
  173.     /*    center text used for userid and job title print  */
  174.     
  175.     send ("%!\n");
  176.     send ("/ctext {     % center text:   string x y dx\n");
  177.     send ("   2 div\n");
  178.     send ("   /Dx exch def\n");
  179.     send ("   /Yv exch def\n");
  180.     send ("   /Xv exch def\n");
  181.     send ("   dup stringwidth pop\n");
  182.     send ("   2 div\n");
  183.     send ("   Dx exch sub\n");
  184.     send ("   Xv add\n");
  185.     send ("   Yv moveto\n");
  186.     send ("   show\n");
  187.     send ("} def\n");
  188.     send ("%%EndProlog\n");
  189.  
  190.     send ("%%Page: ? 1\n");
  191.     if (set_paper_bin)
  192.         printf ("%s\n", slots[set_paper_bin-1]);
  193.  
  194.     if (set_paper_tray >= 0)
  195.         printf ("%s\n", page_types[set_paper_tray].paper_tray);
  196.         
  197.     send ("/pg save def\n");
  198.  
  199.     /*    draw a box for the userid */
  200.     
  201.     printf ("newpath\n");
  202.     printf ("%d %d moveto\n", UX,UY);
  203.     printf ("%d %d rlineto\n", DX, 0);
  204.     printf ("%d %d rlineto\n", 0, -DY);
  205.     printf ("%d %d rlineto\n", -DX, 0);
  206.     printf ("closepath\n");
  207.     printf ("4 setlinewidth\n");
  208.     printf ("stroke\n");
  209.  
  210.     /*    center the userid and the job title */
  211.     
  212.     y = UY - DY / 2 - BIG_POINT / 2;
  213.     printf ("/Helvetica-BoldOblique findfont %d scalefont setfont\n", BIG_POINT);
  214.     printf ("(%s) %d %d %d ctext\n", Userid, X_INDENT, y, DX);
  215.  
  216.     y = UY - (DY + MED_POINT * 3);
  217.     printf ("/Helvetica-Bold findfont %d scalefont setfont\n", MED_POINT);
  218.     printf ("(%s) %d %d %d ctext\n", Title, X_INDENT, y, DX);
  219.  
  220.     /*    print other banner page parameters */
  221.     
  222.     x = X_INDENT;
  223.     y -= (MED_POINT * 2);
  224.     printf ("%d %d moveto\n", x,y);    
  225.     sendnormal ("User:       ");
  226.     sendbold (Name);
  227.  
  228.     y -= SMALL_POINT + (SMALL_POINT / 2);
  229.     printf ("%d %d moveto\n", x,y);    
  230.     sendnormal ("Request ID: ");
  231.     sendbold (Requestid);
  232.     
  233.     y -= SMALL_POINT + (SMALL_POINT / 2);
  234.     printf ("%d %d moveto\n", x,y);    
  235.     sendnormal ("Printer ID: ");
  236.     sendbold (Printer);
  237.     
  238.     y -= SMALL_POINT + (SMALL_POINT / 2);
  239.     printf ("%d %d moveto\n", x,y);    
  240.     sendnormal ("Options:    ");
  241.     sendbold (Options);
  242.     
  243.     y -= SMALL_POINT + (SMALL_POINT / 2);
  244.     printf ("%d %d moveto\n", x,y);    
  245.     sendnormal ("Date:       ");
  246.     sendbold (Date);
  247.     
  248.     y -= SMALL_POINT + (SMALL_POINT / 2);
  249.     printf ("%d %d moveto\n", x,y);    
  250.     sendnormal ("Machine:    ");
  251.     sendbold (Machineid);
  252.  
  253.     send ("showpage pg restore\n");
  254.     send ("%%Trailer\n");    
  255.     exit (0);
  256. }
  257.  
  258. send (s)
  259. char    *s;
  260. {
  261.     while (*s)
  262.         putchar (*s++);
  263. }
  264.  
  265. sendnormal (s)
  266. char     *s;
  267. {
  268.     printf ("/Courier findfont %d scalefont setfont\n", SMALL_POINT);
  269.     send ("(");
  270.     send (s);
  271.     send (")show\n");
  272. }
  273.  
  274. sendbold (s)
  275. char     *s;
  276. {
  277.     printf ("/Helvetica-Bold findfont %d scalefont setfont\n", SMALL_POINT);
  278.     send ("(");
  279.     send (s);
  280.     send (")show\n");
  281. }
  282.  
  283. trim (s)
  284. char    *s;
  285. {
  286.     while (*s)
  287.     {    if (*s < ' ')
  288.         {    *s = 0;
  289.             break;
  290.         }
  291.         s++;
  292.     }
  293. }
  294.  
  295. bad_file()
  296. {
  297.     fprintf (stderr, "Bad %s file\n", PDEF);
  298.     exit (1);
  299. }
  300.  
  301. compare (a,b)
  302. char    *a, *b;
  303. {    int    aa, bb;
  304.  
  305.     while (*a  &&  *b)
  306.     {    aa = *a++;
  307.         bb = *b++;
  308.         if (toupper (aa)  !=  toupper (bb))
  309.             return (aa - bb);
  310.     }
  311.     return (0);
  312. }
  313.  
  314.