星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

gslp.ps 19KB

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