home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gslp.ps < prev    next >
Text File  |  2003-12-13  |  20KB  |  695 lines

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