home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / GhostScript / !GhostScr / 6_01 / lib / gslp.ps < prev    next >
Text File  |  2000-03-09  |  20KB  |  697 lines

  1. %    Copyright (C) 1991, 1995, 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % $Id: gslp.ps,v 1.1 2000/03/09 08:40:40 lpd Exp $
  16. % gslp.ps - format and print text
  17.  
  18. % This utility provides functionality approximately equivalent to the Unix
  19. % `enscript' program.  It prints plain text files using a single font.
  20. % It currently handles tabs and formfeeds, but not backspaces.
  21. % It will line-wrap when using fixed-pitch fonts.
  22. % It will also do kerning and width adjustment.
  23. % Standard switches implemented:
  24. %    -12BclqRr -b<header> -f<font> -F<hfont> -L<lines> -p<outfile>
  25. % Sun switches implemented:
  26. %    -T<n>    set tab width
  27. % Switches ignored:
  28. %    -GghKkmow -# -C -d -J -n -P -S -s -t -v
  29. % Switches added:
  30. %    --add-to-space <units>
  31. %        add the given number of 1/72" units to the width of each
  32. %        space (may be negative)
  33. %    --add-to-width <units>
  34. %        add the given number of 1/72" units to the width of each
  35. %        character (may be negative)
  36. %    --columns <n>
  37. %        print in <n> columns
  38. %    --detect
  39. %        treat the file as PostScript if it starts with %!
  40. %    --first-page <n>
  41. %        start printing at page <n>
  42. %    --kern <file.afm>
  43. %        kern using information from the given .AFM file
  44. %    --last-page <n>
  45. %        stop printing after page <n>
  46. %    --(heading|footing)-(left|center|right) <string>
  47. %        set the heading/footing fields; use -B first to clear
  48. %    --margin-(top|bottom|left|right) <inches>
  49. %        set a margin
  50. %    --no-eject-(file|formfeed)
  51. %        end-of-file/FF only starts a new column, not a new sheet
  52. %    --spacing <n>
  53. %        use double (n=2), triple (n=3), etc. spacing
  54. % Also, the string %# in a heading or footing is replaced with the page #.
  55. /PageNumberString (%#) def
  56.  
  57. /lpdict 150 dict def
  58. lpdict begin
  59.  
  60. % build iso-latin-1 version of a font
  61. /font-to-iso-latin-1 {    % <font> font-to-iso-latin-1 <font>
  62.     %% reencode for iso latin1; from the 2nd edition red book, sec 5.6.1
  63.     dup length dict begin {1 index /FID ne {def} {pop pop} ifelse} forall
  64.     /Encoding ISOLatin1Encoding def currentdict end
  65.     dup /FontName get 80 string cvs (-ISOLatin1) concatstrings cvn 
  66.     exch definefont
  67. } def
  68.  
  69. /find-latin-font {    % <name> find-latin-font <font>
  70.   findfont font-to-iso-latin-1
  71. } def
  72.  
  73. % Define the initial values of the printing parameters.
  74.  
  75. /AddToSpace 0 def
  76. /AddToWidth 0 def
  77. /BodyFont null def        % use default
  78.   /defaultBodyFontPortrait
  79.     /Courier find-latin-font 10 scalefont def
  80.   /defaultBodyFontLandscape
  81.     /Courier find-latin-font 7 scalefont def
  82.   /defaultBodyFont
  83.     { Landscape { defaultBodyFontLandscape } { defaultBodyFontPortrait } ifelse } def
  84. /Columns 1 def
  85. /DetectFileType false def
  86. /EjectEOF true def
  87. /EjectFF true def
  88. /Footers false def
  89. /FootingLeft () def
  90. /FootingCenter () def
  91. /FootingRight () def
  92. /Headers true def
  93. /HeadingLeft () def
  94. /HeadingCenter () def
  95. /HeadingRight (page ) PageNumberString concatstrings def
  96. /HeadingFont null def        % use default
  97.   /defaultHeadingFont
  98.     /Courier-Bold find-latin-font 10 scalefont def
  99. /Kern 0 dict def        % no kerning
  100. /Landscape false def
  101. /MarginBottom 36 def        % 1/2"
  102. /MarginLeft 36 def        % 1/2"
  103. /MarginRight 36 def        % 1/2"
  104. /MarginTop 36 def        % 1/2"
  105. /MaxLines 9999 def        % max lines per page
  106. /Noisy true def            % i.e., not quiet
  107. /OutFile null def        % null = write directly to device
  108. /PageFirst 1 def
  109. /PageLast 99999 def
  110. /Spacing 1 def
  111. /Tab 8 def
  112. /Truncate false def        % wrap long lines, don't truncate
  113.  
  114. % When writing to a file, we want to write out PostScript;
  115. % when writing to the printer, we want to execute it;
  116. % some commands should be executed regardless.
  117. % lpexec provides for all this.
  118.  
  119. /lpdef {    % <name> <value> lpdef -
  120.   /def 2 true lpexec
  121. } def
  122.  
  123. /lpexec {    % <arg1> ... <argn> </op> <n> <do_always> lpexec -
  124.   OutFile null eq {
  125.     pop 1 add true
  126.   } {
  127.     /t exch def 1 add /n exch def cvx
  128.     n -1 roll dup wo
  129.     n 1 sub { n -1 roll dup wosp } repeat
  130.     (\n) ws n t
  131.   } ifelse
  132.     { pop load exec }
  133.     { { pop } repeat }
  134.   ifelse
  135. } def
  136.  
  137. /lpmoveto {    % <x> <y> lpmoveto -
  138.     % Round the coordinates for smaller output.
  139.   2 {
  140.     exch 100 mul round 100 div
  141.     dup dup cvi eq { cvi } if
  142.   } repeat
  143.   1 index X eq { neg exch pop /V 1 } { neg /M 2 } ifelse true lpexec
  144. } def
  145. /lpshow {    % <string> lpshow -
  146.   dup length 0 ne {
  147.     addspace 0 ne {
  148.       addspace 0 32 
  149.       addwidth 0 ne {
  150.     addwidth 0 6 -1 roll /awidthshow 6 true lpexec
  151.       } {
  152.     4 -1 roll /widthshow 4 true lpexec
  153.       } ifelse
  154.     } {
  155.       addwidth 0 ne {
  156.     addwidth 0 3 -1 roll /ashow 3 true lpexec
  157.       } {
  158.     OutFile null ne {
  159.       dup dup length =string length gt {
  160.         /show 1 false lpexec
  161.       } {
  162.         (S ) ws ws (\n) ws
  163.       } ifelse
  164.     } if show 
  165.       } ifelse
  166.     } ifelse
  167.   } {
  168.     pop
  169.   } ifelse
  170. } def
  171. /lpsetmyfont {
  172.   dup load setfont
  173.    OutFile null ne { cvx /setfont 1 false lpexec } { pop } ifelse
  174. } def
  175.  
  176. % Define some utility procedures.
  177.  
  178. /banner        % ypos left center right
  179.  { /HFont lpsetmyfont
  180.    /addspace 0 def /addwidth 0 def
  181.    /pairkern 0 dict def
  182.    3 -1 roll bannerstring pop 0 4 index pwidth showline2 pop
  183.    exch bannerstring pwidth exch sub 2 div 3 index pwidth showline2 pop
  184.    bannerstring
  185.         % Prevent the last character of the heading from grazing
  186.         % the right margin.
  187.         % ****** WHY DOES IT REQUIRE SO MUCH PADDING? ******
  188.    ( ) stringwidth pop 2 mul add
  189.    pwidth exch sub
  190.    3 -1 roll pwidth showline2 pop
  191.  } def
  192.  
  193. /bannerstring    % string -> string width
  194.   { PageNumberString search
  195.      { exch pop pindex 4 string cvs concatstrings exch concatstrings
  196.      }
  197.     if dup stringwidth pop
  198.   } def
  199.  
  200. /beginpage
  201.  { /lindex 0 def
  202.    /skipping pindex PageFirst ge pindex PageLast le and not def
  203.    pagex pagey Landscape {/BL} {/B} ifelse 2 true lpexec
  204.    /pagesave exch def
  205.    skipping { nulldevice   /OutFile null def } if
  206.    Headers
  207.     { lheight hdescent add
  208.       HeadingLeft HeadingCenter HeadingRight banner
  209.     } if
  210.    /BFont lpsetmyfont
  211.    /pairkern Kern def
  212.    /addspace AddToSpace def /addwidth AddToWidth def
  213.    pairkern length 0 ne {
  214.      /addspace AddToSpace lpdef /addwidth AddToWidth lpdef
  215.    } if
  216.  } def
  217.  
  218. /endpage {
  219.   lindex 0 ne {
  220.     Footers {
  221.       topskip plength sub hdescent add
  222.       FootingLeft FootingCenter FootingRight banner
  223.     } if
  224.     /E
  225.   } {
  226.     /restore
  227.   } ifelse
  228.   pagesave exch 0 true lpexec
  229.   /pindex pindex 1 add def
  230. } def
  231.  
  232. /endcolumn
  233.  { lindex colines 1 sub add colines idiv colines mul
  234.    dup llength ge { pop endpage beginpage } { /lindex exch def } ifelse
  235.  } def
  236.  
  237. /fontheight    % <font> fontheight <ascent> <height>
  238.  { gsave setfont
  239.    newpath 0 0 moveto
  240.    (|^_j) false charpath
  241.    pathbbox exch pop dup 2 index sub 4 -2 roll pop pop
  242.    grestore exch 1.25 mul exch 1.25 mul
  243.  } def
  244.  
  245. /wdict {
  246.   dup length wosp ( dict\n) ws
  247.   { (dup) ws exch wosp wosp ( put\n) ws } forall
  248. } def
  249. /wosp { ( ) ws wo } def
  250. /wo {
  251.   dup type /dicttype eq { wdict } { OutFile exch write==only } ifelse
  252. } def
  253. /ws {
  254.   OutFile exch writestring
  255. } def
  256.  
  257. /outfont {        % <name> <font> outfont -
  258.   OutFile null ne {
  259.     exch wo
  260.     dup /FontName get 
  261.     dup wosp (-ISOLatin1) ws wosp ( RE) ws
  262.     /FontMatrix get 0 get 1000 mul round cvi wosp
  263.     ( scalefont def\n) ws
  264.   } {
  265.     pop pop
  266.   }ifelse
  267. } def
  268.  
  269. /StringFF (\f) def
  270. /CharFF StringFF 0 get def
  271. /StringTAB (\t) def
  272. /CharTAB StringTAB 0 get def
  273.  
  274. /showline        % line -> leftover_line (handles \f)
  275.  {  { showline1 dup length 0 eq { exit } if
  276.       dup 0 get CharFF ne { exit } if
  277.       EjectFF { endpage beginpage } { endcolumn } ifelse
  278.       skip1
  279.     }
  280.    loop
  281.  } def
  282.  
  283. /showline1        % line -> leftover_line (handles page break)
  284.  { lindex llength eq { endpage beginpage } if
  285.    lindex colines idiv cowidth mul        % x
  286.    lindex colines mod 1 add lheight mul neg fascent sub    % y
  287.    1 index cowidth add
  288.    showline2
  289.    /lindex lindex 1 add def
  290.  } def
  291.  
  292. /setxy {
  293.   /ty exch def /tx exch def
  294. } def
  295.  
  296. /showline2 {    % string x y xlimit -> leftover_string (handles tabs)
  297.   2 index exch 5 2 roll setxy {
  298.         % Stack: xinit xlimit string
  299.     showline3 dup length 0 eq { exit } if
  300.     dup 0 get CharTAB ne { exit } if
  301.     tx 3 index sub tabwx div
  302.       0.05 add ceiling tabwx mul 3 index add ty setxy
  303.     skip1
  304.     tx 2 index ge { exit } if
  305.   } loop exch pop exch pop
  306. } def
  307.  
  308. /showline3 {    % xlimit string -> xlimit leftover_string
  309.         % (finds line break / tab / formfeed)
  310.   1 index tx sub
  311.     cwx div 0.1 add cvi 0 max 1 index length min
  312.   1 index 0 3 -1 roll getinterval
  313.     % look for \f or \t
  314.   StringFF search { exch pop exch pop } if
  315.   StringTAB search { exch pop exch pop } if
  316.   dup length 0 ne {
  317.     tx ty lpmoveto
  318.     dup pairkern length 0 eq {
  319.       lpshow
  320.     } {
  321.       { kproc } exch /kshow 2 true lpexec
  322.     } ifelse
  323.     currentpoint setxy
  324.   } if
  325.   length dup 2 index length exch sub getinterval
  326. } def
  327.  
  328. /kproc {    % <char1> <char2> kproc -
  329.   pairkern currentfont /Encoding get 3 index get
  330.   2 copy known {
  331.     get currentfont /Encoding get 2 index get
  332.     2 copy known {
  333.       get currentfont /FontMatrix get 0 get mul
  334.     } {
  335.       pop pop 0
  336.     } ifelse
  337.   } {
  338.     pop pop 0
  339.   } ifelse
  340.   addwidth add 2 index 32 eq { addspace add } if
  341.   dup 0 eq { pop } { 0 rmoveto } ifelse
  342.   pop pop
  343. } def
  344.  
  345. /skip1
  346.  { dup length 1 sub 1 exch getinterval
  347.  } def
  348.  
  349. /e== {        % <object> e== - -- print an object to stderr
  350.   (%stderr) (w) file dup 3 -1 roll write==only flushfile
  351. } def
  352.  
  353. /eprint {    % <string> eprint - -- print a string to stderr
  354.   (%stderr) (w) file dup 3 -1 roll writestring flushfile
  355. } def
  356.  
  357. % Read kerning information from a .AFM file.
  358.  
  359. /readkern {    % <afmfile> readkern <pairkerndict>
  360.   /mfilename 1 index def
  361.   (r) file /mfile exch def
  362.   mfile =string readline pop
  363.   (StartFontMetrics ) anchorsearch {
  364.     pop pop
  365.     /kdict 256 dict def
  366.     { mfile =string readline pop
  367.       (EndFontMetrics) anchorsearch { pop pop exit } if
  368.       (KPX ) anchorsearch {
  369.     pop token pop cvlit /char1 exch def
  370.     token pop cvlit /char2 exch def
  371.     token pop /kern exch def pop
  372.     kdict char1 .knownget not {
  373.       5 dict kdict char1 2 index .growput
  374.     } if
  375.     char2 kern .growput
  376.       } {
  377.     pop
  378.       } ifelse
  379.     } loop kdict
  380.   } {
  381.     pop
  382.     mfilename eprint ( does not begin with StartFontMetrics.\n) eprint
  383.     0 dict
  384.   } ifelse
  385.   mfile closefile
  386. } def
  387.  
  388. % The main printing procedure
  389.  
  390. /doFirst true def
  391. /prevBFont null def
  392. /prevHFont null def
  393.  
  394. /lpfirst {    % - lpfirst -
  395. % Define some abbreviating procedures.
  396.   /B {save 3 1 roll translate /X 0 def} lpdef
  397.   /BL {save 3 1 roll 90 rotate translate /X 0 def} lpdef
  398.   /E {showpage restore} lpdef
  399.   /V {neg X exch moveto} lpdef
  400.   /M {/X 2 index def neg moveto} lpdef
  401.   /S {currentfile =string readline pop show} lpdef
  402.   /RE {        % <isoname> <fontname> RE <font>
  403.     findfont
  404.     %% reencode for iso latin1; from the 2nd edition red book, sec 5.6.1
  405.     dup length dict begin {1 index /FID ne {def} {pop pop} ifelse} forall
  406.     /Encoding ISOLatin1Encoding def currentdict end
  407.     definefont
  408.   } lpdef
  409. } def
  410.  
  411. /lp {        % file initial_chars ->
  412.   /lpline exch def
  413.   /lpfile exch def
  414.  
  415.   doFirst { lpfirst /doFirst false def } if
  416.  
  417. % Initialize the device and fonts.
  418.   /BFont
  419.     BodyFont null eq { defaultBodyFont } { BodyFont } ifelse def
  420.   BFont prevBFont ne {
  421.     /BFont BFont outfont
  422.     /prevBFont BFont def
  423.   } if
  424.   Headers Footers or {
  425.     /HFont
  426.       HeadingFont null eq { defaultHeadingFont } { HeadingFont } ifelse def
  427.     HFont prevHFont ne {
  428.       /HFont HFont outfont
  429.       /prevHFont HFont def
  430.     } if
  431.   } if
  432.   save
  433.  
  434. % Get the layout parameters.
  435.    clippath
  436.    gsave    % for possible rotation
  437.    Landscape { 90 rotate } if
  438.    BFont setfont ( ) stringwidth pop /cwx exch def
  439.      cwx Tab mul /tabwx exch def
  440.    BFont fontheight /fheight exch def /fascent exch def
  441.    Headers Footers or { HFont fontheight } { 0 0 } ifelse
  442.      /hheight exch def /hascent exch def
  443.      /hdescent hheight hascent sub def
  444.    fheight Spacing mul /lheight exch def
  445.    Headers { hheight lheight add } { 0 } ifelse
  446.      /topskip exch def
  447.    Footers { hheight lheight add } { 0 } ifelse
  448.      /botskip exch def
  449.    /pskip topskip botskip add def
  450.     % Translate the page so that (0,0) corresponds to
  451.     % the top of the topmost body line.
  452.    pathbbox
  453.      2 index sub MarginBottom MarginTop add sub /plength exch def
  454.      2 index sub MarginLeft MarginRight add sub /pwidth exch def
  455.      pwidth Columns div /cowidth exch def
  456.      exch MarginLeft add
  457.      exch MarginBottom add plength add topskip sub
  458.      /pagey exch def /pagex exch def
  459.    plength pskip sub lheight div cvi MaxLines min
  460.      dup /colines exch def
  461.      Columns mul /llength exch def
  462.    grestore
  463.    OutFile null ne { nulldevice } if
  464.  
  465. % Print layout
  466.    Noisy
  467.     { (Page height = ) eprint llength e==
  468.       (.\n) eprint flush
  469.     } if
  470.  
  471. % Write the kerning table, if relevant.
  472.    OutFile null ne Kern length 0 ne and {
  473.      (/kproc) ws /kproc load wosp ( def\n) ws
  474.      (/pairkern) ws Kern wosp ( def\n) ws
  475.    } if
  476.  
  477. % Disable stack recording so we can use stopped with readline.
  478.    $error /recordstacks false put
  479.  
  480. % Initialize for the first page.
  481.    /lbuf 1000 string def
  482.    /pindex 1 def
  483.    beginpage
  484.  
  485. % Iterate through the file.
  486.    lpline
  487.     { dup length /pos exch def
  488.       lbuf exch 0 exch putinterval
  489.        { lpfile lbuf pos lbuf length pos sub getinterval readline } stopped
  490.        {    % Filled the line before a CR or EOF.
  491.          exch pop showline
  492.        }
  493.        {    % Reached CR and/or EOF first.
  494.          exch length pos add lbuf exch 0 exch getinterval
  495.      1 index { showline } if        % omit final empty line
  496.       { dup length 0 eq Truncate or { pop () exit } if
  497.         showline
  498.       }
  499.      loop
  500.      exch not { exit } if
  501.        }
  502.       ifelse
  503.     } loop
  504.    pop
  505.  
  506. % Wrap up.
  507. %**************** WHY IS THIS COMMENTED OUT? ****************
  508. %   EjectEOF { endpage } { endcolumn } ifelse
  509.    endpage
  510.    restore
  511.  
  512. } def
  513.  
  514. end
  515.  
  516. % Usage: <file> lp
  517. %   prints <file> using the current parameter settings.
  518. % Usage: [ <arg1> ... <argn> ] lpcommand
  519. %   interprets args like a command line.
  520.  
  521. /lp { save   lpdict begin () lp end   restore } def
  522.  
  523. lpdict begin
  524.  
  525. /splitfn        % (FontNNN) -> <font>
  526.  { dup /arg exch def length
  527.     { dup 0 le { exit } if
  528.       dup 1 sub arg exch get dup 48 ge exch 59 le and not { exit } if
  529.       1 sub
  530.     } loop
  531.    arg exch 0 exch getinterval dup cvn find-latin-font
  532.    exch arg exch anchorsearch pop pop cvr scalefont
  533.  } def
  534.  
  535. % Parse the command line switches.
  536.  
  537. /doswitch    % argn ... arg1 (-?) restofswitch ->
  538.  { exch dup cvn lpdict exch known
  539.     { cvn load exec }
  540.     { exch pop (Unknown switch: ) eprint eprint (\n) eprint }
  541.    ifelse
  542.  } def
  543.  
  544. /more        % argn ... arg1 restofswitch ->
  545.  { dup length 0 ne
  546.     { (- ) dup 1 3 index 0 get put
  547.       exch dup length 1 sub 1 exch getinterval
  548.       doswitch
  549.     }
  550.     { pop
  551.     }
  552.    ifelse
  553.  } def
  554.  
  555. /-- { (--) exch concatstrings
  556.       dup cvn lpdict exch known
  557.        { cvn load exec }
  558.        { (Unknown switch: ) eprint eprint (\n) eprint }
  559.       ifelse
  560.     } def
  561. /--add-to-space { cvr /AddToSpace exch def } def
  562. /--add-to-width { cvr /AddToWidth exch def } def
  563. /--columns { cvi 1 max /Columns exch def } def
  564. /--detect { /DetectFileType true def } def
  565. /--first-page { cvi /PageFirst exch def } def
  566. /--footing-center { /FootingCenter exch def   /Footers true def } def
  567. /--footing-left { /FootingLeft exch def   /Footers true def } def
  568. /--footing-right { /FootingRight exch def   /Footers true def} def
  569. /--heading-center { /HeadingCenter exch def   /Headers true def } def
  570. /--heading-left { /HeadingLeft exch def   /Headers true def } def
  571. /--heading-right { /HeadingRight exch def   /Headers true def } def
  572. /--kern { readkern /Kern exch def } def
  573. /--last-page { cvi /PageLast exch def } def
  574. /--margin-bottom { cvr 72.0 mul /MarginBottom exch def } def
  575. /--margin-left { cvr 72.0 mul /MarginLeft exch def } def
  576. /--margin-right { cvr 72.0 mul /MarginRight exch def } def
  577. /--margin-top { cvr 72.0 mul /MarginTop exch def } def
  578. /--no-eject-file { /EjectEOF false def } def
  579. /--no-eject-formfeed { /EjectFF false def } def
  580. /--spacing { cvr /Spacing exch def } def
  581.  
  582. /-# { pop } def        % ignore
  583. /-+ { -- } def
  584. (-1)cvn { /Columns 1 def   more } def
  585. (-2)cvn { /Columns 2 def   more } def
  586. /-b { /HeadingLeft exch def   /HeadingCenter () def   /HeadingRight PageNumberString def
  587.       /Headers true def
  588.       /break true def
  589.     } def
  590. /-B { /HeadingLeft () def   /HeadingCenter () def   /HeadingRight () def
  591.       /Headers false def
  592.       /FootingLeft () def   /FootingCenter () def   /FootingRight () def
  593.       /Footers false def
  594.       /break true def
  595.       more
  596.     } def
  597. /-C { pop } def        % ignore
  598. /-c { /Truncate true def   more } def
  599. /-d { pop } def        % ignore
  600. /-f { splitfn /BodyFont exch def } def
  601. /-F { splitfn /HeadingFont exch def } def
  602. /-G { more } def    % ignore
  603. /-g { more } def    % ignore
  604. /-h { more } def    % ignore
  605. /-J { pop } def        % ignore
  606. /-K { more } def    % ignore
  607. /-k { more } def    % ignore
  608. /-l { 66 -L -B } def
  609. /-L { cvi /MaxLines exch def } def
  610. /-m { more } def    % ignore
  611. /-n { pop } def        % ignore
  612. /-o { more } def    % ignore
  613. /-p { (w) file /OutFile exch def   OutFile (%!\n) writestring } def
  614. /-P { pop } def        % ignore
  615. /-q { /Noisy false def   more } def
  616. /-r { /Landscape true def   more } def
  617. /-R { /Landscape false def   more } def
  618. /-S { pop } def        % ignore
  619. /-s { pop } def        % ignore
  620. /-T { cvi /Tab exch def } def
  621. /-v { pop } def        % ignore
  622. /-w { more } def    % ignore
  623.  
  624. /lp1        % filename ->
  625.  { break not { dup /HeadingLeft exch def } if
  626.    Noisy
  627.     { (Printing ) eprint dup eprint (\n) eprint 
  628.     } if
  629.    (r) file
  630.         % If requested, check for a PostScript file.
  631.    DetectFileType
  632.     { dup 2 string readstring pop dup (%!) eq
  633.        {    % Yes, it's a PostScript file.
  634.          pop dup 80 string readline pop pop cvx exec
  635.        }
  636.        { lp
  637.        }
  638.       ifelse
  639.     }
  640.     { () lp
  641.     }
  642.    ifelse
  643.  } bind def
  644.  
  645. /lpcstring 100 string def
  646.  
  647. end
  648.  
  649. /lpcommand        % <[arg1 ... argn]> lpcommand <any_printed>
  650.  {    % Push the commands on the stack in reverse order
  651.    mark exch
  652.    dup length 1 sub -1 0 { 1 index exch get exch } for pop
  653.    lpdict begin
  654.    /any false def
  655.    /break false def
  656.     { dup mark eq { pop exit } if
  657.       dup length 2 ge { dup 0 get (-) 0 get eq } { false } ifelse
  658.        { dup 0 2 getinterval
  659.          exch dup length 2 sub 2 exch getinterval
  660.      doswitch
  661.        }
  662.        { dup  /matched false def
  663.           { /matched true def   /any true def   lp1 } lpcstring filenameforall
  664.      matched { pop } { lp1 } ifelse        % let the error happen
  665.        }
  666.       ifelse
  667.     } loop
  668.    OutFile null ne
  669.     { OutFile (%stdout) (w) file ne { OutFile closefile } if
  670.       /OutFile null def
  671.     } if
  672.    any
  673.    end
  674.  } def
  675.  
  676. [ shellarguments
  677.  { ] dup length 0 ne { lpcommand } { false } ifelse not
  678.     { (%stderr) (w) file
  679.       [ (Usage: )
  680.     /PROGNAME where { pop PROGNAME } { (gslp) } ifelse
  681.     ( [-12BclqRr] [-b<header>] [-f<font>] [-F<hfont>]\n)
  682.     (        [-L<lines>] [-p<outfile>] [-T<tabwidth>]\n)
  683.     (        [--add-to-(space|width) <units>] [--columns <n>]\n)
  684.     (        [--detect] [--first-page <page#>] [--last-page <page#>]\n)
  685.     (        [--(heading|footing)-(left|right|center) <string>]\n)
  686.     (        [--kern <afmfile>] [--margin-(top|bottom|left|right) <inches>]\n)
  687.     (        [--no-eject-(file|formfeed)] [--spacing <n>] file1 ... filen\n)
  688.       ] { 2 copy writestring pop } forall dup flushfile closefile
  689.     }
  690.    if
  691.  }
  692.  { pop }
  693. ifelse
  694.