home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume4 / sticky < prev    next >
Text File  |  1986-11-30  |  16KB  |  644 lines

  1. Newsgroups: mod.sources
  2. Subject: PostScript sticky label program
  3. Reply-To: liam@qmc-cs.UUCP (William Roberts)
  4. Organization: CS Dept, Queen Mary College, University of London, UK.
  5. Keywords: postscript label
  6. Approved: jpn@panda.UUCP
  7.  
  8. Mod.sources:  Volume 4, Issue 96
  9. Submitted by: talcott!seismo!mcvax!cs.qmc.ac.uk!liam
  10.  
  11. #         This is a shar archive.
  12. #         Remove everything above and including the cut line.
  13. #         Then run the rest of the file through sh.
  14. #--------cut--------cut--------cut--------cut--------cut--------
  15. #! /bin/sh
  16. #  shar:  Shell Archiver
  17. #         Run the following with /bin/sh to create:
  18. #             README
  19. #             background.test
  20. #             sticky
  21. #             sticky.1
  22. #             sticky.awk
  23. #             sticky.ps
  24. #             sticky.test
  25. # This archive created: Wed Apr 30 13:36:08 BST 1986
  26. echo shar: extracting "README" '('1719 chars')'
  27. if test -f README
  28. then
  29.     echo shar: will not overwrite existing file "README"
  30. else
  31. cat << \SHAR_EOF > README
  32. This directory contains software, example and manual page for a
  33. program which produces PostScript commands for printing address
  34. labels, conference badges etc.
  35.  
  36. I believe that this system is a good example of how to write
  37. simple X-to-PostScript filters:  essentially you do most of the
  38. programming in the PostScript prologue and do only minimal
  39. re-arrangement to input data.  In many cases the re-arrangement
  40. is so easy that you only need an awk script and/or a few other
  41. Unix tools.
  42.  
  43. The files are:
  44.  
  45. sticky.1      - the manual page. This should be comprehensive
  46.                 enough for you to run the program.
  47.  
  48. sticky.awk    - An awk(1) script that translates the input data
  49.                 into the appropriate PostScript commands.
  50.  
  51. sticky.ps     - A PostScript prologue (set of sub-routines)
  52.                 which define all the routines used by the
  53.                 output from the awk script.
  54.  
  55. sticky        - A sh(1) script which outputs sticky.ps, then
  56.                 runs the sticky.awk on its arguments.
  57.  
  58.  
  59. sticky.test   - A demonstration of the simple label features
  60.                 and the formatting capability. Type
  61.  
  62.                         sticky stick.test
  63.  
  64.                 and send the output to your PostScript printer.
  65.  
  66. background.test - A demonstration of the labels-with-backgrounds
  67.                 advanced features of the program.  Run as per
  68.                 the other .test file.
  69.  
  70.  
  71. REMARK:
  72.  
  73. The sticky command is too complicated really: I shouldn't have
  74. added to "BACKGROUND" facility to this general-purpose system.
  75. Quick, distribute it before I get second thoughts....
  76.  
  77.  
  78. William Roberts                 ARPA: liam@UK.AC.qmc.cs
  79. Queen Mary College              UUCP: liam@qmc-cs.UUCP
  80. LONDON, UK
  81. SHAR_EOF
  82. if test 1719 -ne `wc -c < README`
  83. then
  84.     echo shar: error transmitting "README" '('should be 1719 chars')'
  85. else
  86.     echo README
  87. fi
  88. fi
  89. echo shar: extracting "background.test" '('217 chars')'
  90. if test -f background.test
  91. then
  92.     echo shar: will not overwrite existing file "background.test"
  93. else
  94. cat << \SHAR_EOF > background.test
  95. FORMAT
  96. 2  HB 14 centre
  97. 14 H  14 centre
  98. 4  H  10 centre
  99.  
  100. BACKGROUND logo
  101. (blank)
  102. SPEAKER
  103. Computer Turkeysetting Conference
  104.  
  105. Anne Robbins
  106.  
  107. Bernard Matthews
  108.  
  109. William Roberts
  110.  
  111. Frances Shipsey
  112.  
  113. Angus Phillips
  114.  
  115. Ann Nursey
  116.  
  117. SHAR_EOF
  118. if test 217 -ne `wc -c < background.test`
  119. then
  120.     echo shar: error transmitting "background.test" '('should be 217 chars')'
  121. else
  122.     echo background.test
  123. fi
  124. fi
  125. echo shar: extracting "sticky" '('134 chars')'
  126. if test -f sticky
  127. then
  128.     echo shar: will not overwrite existing file "sticky"
  129. else
  130. cat << \SHAR_EOF > sticky
  131. #! /bin/sh
  132. # LaserWriter version of the "sticky" labels program
  133.  
  134. DIR=.
  135. AWK=sticky.awk
  136. PS=sticky.ps
  137.  
  138. cat $DIR/$PS; awk -f $DIR/$AWK $*
  139. SHAR_EOF
  140. if test 134 -ne `wc -c < sticky`
  141. then
  142.     echo shar: error transmitting "sticky" '('should be 134 chars')'
  143. else
  144.     echo sticky
  145. fi
  146. fi
  147. echo shar: extracting "sticky.1" '('3621 chars')'
  148. if test -f sticky.1
  149. then
  150.     echo shar: will not overwrite existing file "sticky.1"
  151. else
  152. cat << \SHAR_EOF > sticky.1
  153. .TH STICKY 1 "29 April 1982"
  154. .SH NAME
  155. sticky \- generate PostScript for address labels
  156. .SH SYNOPSIS
  157. .B sticky
  158. [
  159. .B file ....
  160. ]
  161. .SH DESCRIPTION
  162. The
  163. .I file
  164. is converted into PostScript that will print it as address
  165. labels, suitable for use with sticky label stationery (hence
  166. the name!).  Standard input will be used if
  167. .I file
  168. is ``-'' or no arguments are given.
  169. .PP
  170. Each label will have one address on it; each address is a
  171. sequence of non-blank lines from the file, terminated by a
  172. blank line or the end of the file.  Lines consisting of just
  173. the
  174. .I troff(1)
  175. directive ``.nf'' are ignored.
  176. .PP
  177. If the first line of an address is the word ``FORMAT'', the
  178. address is used as a label format description.
  179. This description consists of a number of line formats which are
  180. used for the successive lines of each subsequent address.  If
  181. an address has more lines than the current format description,
  182. the last line of the description is re-used for the extra lines
  183. (rather like the line formats in
  184. .IR tbl(1) ).
  185. Each line format has the following structure:
  186.  
  187. .I
  188. .ce
  189. gap fontcode pointsize style
  190. .ft P
  191.  
  192. .TP
  193. .I gap
  194. The gap to leave between the top of this line and the bottom of
  195. the previous line (or the top of the label) in points.  2 is a
  196. good number for this.
  197. .TP
  198. .I fontcode
  199. The
  200. .I troff(1)
  201. code for the font to use on this line (e.g. R, B, HO etc).
  202. .TP
  203. .I pointsize
  204. The pointsize of the text for this line.
  205. .TP
  206. .I style
  207. The layout style of the line; one of ``left'', ``right'' or
  208. ``centre''. The text will be aligned against the lefthand edge,
  209. the righthand edge or centred in the label respectively.
  210. .PP
  211. Addresses with a first line beginning with the word
  212. ``BACKGROUND'' are used to define a fixed part of the label.
  213. The rest of the first line is executed (as a PostScript
  214. procedure) whenever a subsequent label is printed. The rest of
  215. the address is taken to be fixed text and is printed as per the
  216. current format at the time the BACKGROUND command is issued.
  217. Subsequent changes to the format will not affect the background.
  218. An address line consisting of the just word ``(blank)'' results
  219. in a blank line in the PostScript version of the address, and
  220. is particularily useful when defining the background for
  221. labels.
  222. .SH EXAMPLES
  223. The default format is
  224. .in +0.5i
  225. .nf
  226. .ne 2
  227. FORMAT
  228. 2 R 12 left.
  229. .in
  230. A pleasing effect with the first line in large italics, a gap
  231. before the second line and subsequent lines in smaller type
  232. is given by
  233. .in +0.5i
  234. .nf
  235. .ne 4
  236. FORMAT
  237. 2 HO 14 left
  238. 4 H  12 left
  239. 2 H  12 left
  240. .fi
  241. .in
  242. Conference badges could be produced with
  243. .in +0.5i
  244. .nf
  245. .ne 4
  246. FORMAT
  247. 20 HB 15 centre
  248. 8  HO  8 centre
  249. 2  HO  8 centre
  250. .fi
  251. .in
  252. To produce conference badges with some fixed text and a logo
  253. (the ``turkey'' from the PostScript CookBook, but you could
  254. define your own!), use
  255. .in +0.5i
  256. .nf
  257. .ne 4
  258. FORMAT
  259. 2  HB 14 centre
  260. 14 H  14 centre
  261. 4  H  10 centre
  262.  
  263. .ne 4
  264. BACKGROUND logo
  265. (blank)
  266. SPEAKER
  267. Computer Turkey-Setting Conference
  268.  
  269. Mr First Speaker
  270.  
  271. Miss Second Speaker
  272.  
  273. etc....
  274. .fi
  275. .in
  276. .SH FILES
  277. .TP 2.5i
  278. /usr/local/lib/sticky/sticky.ps
  279. The PostScript prologue, including label size & layout on page.
  280. .TP
  281. /usr/local/lib/sticky/sticky.awk
  282. Awk(1) script for converting addresses to PostScript and
  283. handling the font name conversion.
  284. .SH "SEE ALSO"
  285. awk(1), troff(1), tbl(1).
  286. .SH "CUSTOMISING"
  287. The PostScript prologue can be modified to cope with specific
  288. types of label. New line formats can be added, as can
  289. additional procedures for use with the BACKGROUND facility.
  290. The safest way to do this is to copy and modify the existing
  291. routines.
  292. .SH "AUTHOR"
  293. .nf
  294. William Roberts
  295. Department of Computer Science
  296. Queen Mary College
  297. LONDON, UK
  298. .fi
  299. SHAR_EOF
  300. if test 3621 -ne `wc -c < sticky.1`
  301. then
  302.     echo shar: error transmitting "sticky.1" '('should be 3621 chars')'
  303. else
  304.     echo sticky.1
  305. fi
  306. fi
  307. echo shar: extracting "sticky.awk" '('2185 chars')'
  308. if test -f sticky.awk
  309. then
  310.     echo shar: will not overwrite existing file "sticky.awk"
  311. else
  312. cat << \SHAR_EOF > sticky.awk
  313. BEGIN   { ADDRESS = "FALSE"; FORMAT="FALSE"; BACKGROUND="FALSE"
  314.           FONTNAME["R"]  = "/Times-Roman";
  315.           FONTNAME["I"]  = "/Times-Italic";
  316.           FONTNAME["B"]  = "/Times-Bold";
  317.           FONTNAME["BI"] = "/Times-BoldItalic";
  318.           FONTNAME["H"]  = "/Helvetica";
  319.           FONTNAME["HO"] = "/Helvetica-Oblique";
  320.           FONTNAME["HB"] = "/Helvetica-Bold";
  321.           FONTNAME["HD"] = "/Helvetica-BoldOblique";
  322.           FONTNAME["C"]  = "/Courier";
  323.           FONTNAME["CO"] = "/Courier-Oblique";
  324.           FONTNAME["CB"] = "/Courier-Bold";
  325.           FONTNAME["CD"] = "/Courier-BoldOblique";
  326.         }
  327.  
  328. $1 == ".nf" \
  329.         { next }
  330.  
  331. $1 == "FORMAT" && NF == 1 \
  332.         { FORMAT = "TRUE"; printf "[\n"; next }
  333.  
  334. $1 == "BACKGROUND" \
  335.         {
  336.           printf "/BackgroundProcs {";
  337.           for(i=2; i<=NF; i++) printf "%s ", $i;
  338.           printf "} def\n[\n";
  339.           BACKGROUND = "TRUE";
  340.           next;
  341.         }
  342.  
  343. NF == 0 || ( NF == 1 && $1 == " ") \
  344.         {
  345.           if (ADDRESS == "TRUE") printf "] def DoIt\n";
  346.           ADDRESS = "FALSE";
  347.           if (FORMAT == "TRUE") printf "] define_format\n\n";
  348.           FORMAT = "FALSE";
  349.           if (BACKGROUND == "TRUE") printf "] define_background\n\n";
  350.           BACKGROUND = "FALSE";
  351.           next;
  352.         }
  353.  
  354. # Format line is: pre-line_gap  font  pointsize  line_style
  355. FORMAT == "TRUE" \
  356.         { FONT = FONTNAME[$2];
  357.           STYLE = $4; if ($4 == "center") STYLE = "centre";
  358.           printf "{ %d %s %d %s }\n", $1, FONT, $3, STYLE;
  359.           next;
  360.         }
  361.  
  362.  
  363. ADDRESS == "FALSE" && NF == 2 && $2 == "TIMES" \
  364.         {
  365.           printf "/Repeat_count %d def\n", $1;
  366.           printf "/Text [\n";
  367.           ADDRESS = "TRUE";
  368.           next;
  369.         }
  370.  
  371. ADDRESS == "FALSE" && BACKGROUND == "FALSE" \
  372.         {
  373.           printf "/Text [\n";
  374.           ADDRESS = "TRUE";
  375.         }
  376.  
  377. # all non-empty lines
  378.         {
  379.           if ($1 == "(blank)" && NF == 1 ) printf "  ()\n";
  380.           else printf "  (%s)\n", $0;
  381.         }
  382.  
  383. END     {
  384.           if (ADDRESS == "TRUE") printf "] def DoIt\n";
  385.           if (BACKGROUND == "TRUE" || FORMAT == "TRUE" ) printf "] pop\n";
  386.           printf "AllDone\n";
  387.         }
  388. SHAR_EOF
  389. if test 2185 -ne `wc -c < sticky.awk`
  390. then
  391.     echo shar: error transmitting "sticky.awk" '('should be 2185 chars')'
  392. else
  393.     echo sticky.awk
  394. fi
  395. fi
  396. echo shar: extracting "sticky.ps" '('3888 chars')'
  397. if test -f sticky.ps
  398. then
  399.     echo shar: will not overwrite existing file "sticky.ps"
  400. else
  401. cat << \SHAR_EOF > sticky.ps
  402. %!PS-ADOBE-1.0
  403. %%Pages: ?
  404. % Handle "sticky"-style labels
  405.  
  406. /mm { 2.83465 mul} def          % according to the CookBook
  407. /Label_Depth  37.3 mm def
  408. /Label_Width 104.5 mm def
  409. /Useable 0.8 def                % useable depth,width
  410.  
  411. /rows 7 def /cols 2 def
  412.  
  413. /fine_tune {3 mm -12.5 mm translate} def  % fine tune the positioning
  414.  
  415. %%%%%%%%%%%%%%%%%%%%%%%%%% PostScript Routines %%%%%%%%%%
  416. fine_tune
  417.  
  418. /Label
  419. { Label_Depth mul exch Label_Width mul exch } def
  420. /Label_Boundary
  421. { 1 0 Label rlineto  0  1 Label rlineto
  422.  -1 0 Label rlineto  0 -1 Label rlineto
  423. } def
  424. /UnUseable 1 Useable sub 2 div def
  425.  
  426. /labelrow 1 def
  427. /labelcol 1 def
  428.  
  429. /DoIt   % Argument: array of strings
  430. {
  431. Repeat_count
  432.     { gsave
  433.        labelcol 1 sub rows labelrow sub Label moveto
  434.        currentpoint translate
  435.  
  436.        gsave
  437.         Label_Boundary clippath % clip to label boundary
  438.         UnUseable Useable UnUseable add Label moveto  % Top Left of label
  439.         gsave
  440.         Background { BackgroundProcs BackDict begin PrintText end} if
  441.         grestore
  442.         PrintText
  443.        grestore
  444.  
  445.        /labelcol labelcol 1 add def       % increment column
  446.        labelcol cols gt
  447.        { /labelcol 1 def
  448.          /labelrow labelrow 1 add def       % increment row
  449.          labelrow rows gt
  450.             { showpage
  451.               /labelrow 1 def     % new page
  452.             } if
  453.        } if
  454.       grestore
  455.    } repeat
  456.    /Repeat_count 1 def        % reset multiplication count
  457. } def
  458.  
  459. /AllDone
  460. {
  461.   labelcol 1 eq labelrow 1 eq and not        % not (row=1 & col=1)
  462.   { showpage
  463.   } if       % print final page
  464. } def
  465.  
  466.  
  467. /define_format          % arg: array of {line format}
  468. { /Format exch def
  469.   /Format_max Format length 1 sub def
  470. } def
  471.  
  472. %% Local format routines:  centre, left, right
  473. %%
  474. /centre         % args: string gap font ps
  475. {
  476.   /ps exch def
  477.   findfont ps scalefont setfont 0 exch neg rmoveto
  478.   dup stringwidth pop
  479.   Label_Width Useable mul exch sub 2 div ps neg
  480.   gsave rmoveto show grestore
  481.   0 ps neg rmoveto    % go down the vertical spacing amount
  482. } def
  483. /left         % args: string gap font ps
  484. {
  485.   /ps exch def
  486.   findfont ps scalefont setfont 0 exch neg rmoveto
  487.   0 ps neg
  488.   gsave rmoveto show grestore
  489.   0 ps neg rmoveto    % go down the vertical spacing amount
  490. } def
  491. /right        % args: string gap font ps
  492. {
  493.   /ps exch def
  494.   findfont ps scalefont setfont 0 exch neg rmoveto
  495.   dup stringwidth pop
  496.   Label_Width Useable mul exch sub ps neg
  497.   gsave rmoveto show grestore
  498.   0 ps neg rmoveto    % go down the vertical spacing amount
  499. } def
  500.  
  501. %% Definitions for handling backgrounds
  502. %%
  503. /define_background      % arg: array of {text} for current format
  504. { /Background true def  % flag existence of background
  505.   BackDict /Format Format put
  506.   BackDict /Format_max Format_max put
  507.   BackDict begin
  508.     /Text exch def
  509.   end
  510. } def
  511.  
  512. %% BackgroundProc definitions
  513. %%
  514. %% logo is a silly example that prints the CookBook "turkey" in
  515. %%      one corner of the label.
  516.  
  517. /logo           % Silly example of a BackgroundProc
  518. { gsave
  519.   currentpoint translate
  520.   0 -20 translate 20 -20 scale
  521.   {1 exch sub} settransfer
  522.   24 23 1 [24 0 0 23 0 -23]
  523. {<003B00 002700 002480 0E4940
  524.   114920 14B220 3CB650 75FE88
  525.   17FF8C 175F14 1C07E2 3803C4
  526.   703182 F8EDFC B2BBC2 BB6F84
  527.   31BFC2 18EA3C 0E3E00 07FC00
  528.   03F800 1E1800 1FF800>} image
  529.   grestore
  530. } def
  531.  
  532. /PrintText
  533. { gsave
  534.    0 1 Text length 1 sub         %for i=0 to length(Text) -1
  535.    { dup Text exch get          % extract the string
  536.      exch dup Format_max gt     % still within format?
  537.      {pop Format_max} if        % re-use last format line if necessary
  538.      Format exch get
  539.      exec                       % perform the format command
  540.    } for
  541.   grestore
  542. } def
  543.  
  544. %% Default Label Format, Background & repetition count
  545.  
  546. /Repeat_count 1 def
  547. [ { 2 /Times-Roman 12 left } ] define_format
  548. /Background false def                   % no background
  549. /BackDict 15 dict def                    % dictionary for the data
  550. SHAR_EOF
  551. if test 3888 -ne `wc -c < sticky.ps`
  552. then
  553.     echo shar: error transmitting "sticky.ps" '('should be 3888 chars')'
  554. else
  555.     echo sticky.ps
  556. fi
  557. fi
  558. echo shar: extracting "sticky.test" '('868 chars')'
  559. if test -f sticky.test
  560. then
  561.     echo shar: will not overwrite existing file "sticky.test"
  562. else
  563. cat << \SHAR_EOF > sticky.test
  564. Mr David G Small
  565. High Level Hardware Ltd
  566. PO Box 170
  567. Windmill Road
  568. Oxford OX3 7BN
  569.  
  570. FORMAT
  571. 2 B 14 left
  572. 8 I 12 left
  573. 2 I 12 left
  574.  
  575. Mr Paul Farmer
  576. Syntek Ltd
  577. Fanum House
  578. 48 Leicester Square
  579. London WC2H 7BY
  580.  
  581. Mr F.J. Tucker
  582. Ernst & Whinney
  583. Beckett House
  584. 1 Lambeth Palace Road
  585. London EC1
  586.  
  587. FORMAT
  588. 2 HO 10 centre
  589. 6 HO 10 centre
  590. 2 HO 10 centre
  591.  
  592. Mr F.J. Tucker
  593. Ernst & Whinney
  594. Beckett House
  595. 1 Lambeth Palace Road
  596. London EC1
  597.  
  598. FORMAT
  599. 4 CO 12 right
  600.  
  601. Mr F.J. Tucker
  602. Ernst & Whinney
  603. Beckett House
  604. 1 Lambeth Palace Road
  605. London EC1
  606.  
  607. FORMAT
  608. 2 I 14 left
  609. 4 R 12 left
  610. 2 R 12 left
  611.  
  612. Mr David G Small
  613. High Level Hardware Ltd
  614. PO Box 170
  615. Windmill Road
  616. Oxford OX3 7BN
  617.  
  618.  
  619. Mr F.J. Tucker
  620. Ernst & Whinney
  621. Beckett House
  622. 1 Lambeth Palace Road
  623. London EC1
  624.  
  625. 3 TIMES
  626. Sue White
  627. Research Co-ordinator
  628. Department of Computer Science & Statistics
  629. Queen Mary College
  630. Mile End Road
  631. LONDON                  E1 4NS
  632.  
  633. SHAR_EOF
  634. if test 868 -ne `wc -c < sticky.test`
  635. then
  636.     echo shar: error transmitting "sticky.test" '('should be 868 chars')'
  637. else
  638.     echo sticky.test
  639. fi
  640. fi
  641. #         End of shar archive
  642. exit 0
  643.  
  644.