home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1454 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  4.9 KB

  1. From: jv@mh.nl (Johan Vromans)
  2. Newsgroups: comp.lang.perl,alt.sources
  3. Subject: PostScript to troff converter for Perl Reference Guide
  4. Message-ID: <JV.90Jun13102616@squirrel.mh.nl>
  5. Date: 13 Jun 90 16:26:16 GMT
  6. X-Checksum-Snefru: 0ec8fdec 0428230e f908f43e b8760a7d
  7.  
  8. This perl program translates the PostScript output for the Perl
  9. Reference Guide to troff. It may be useful for other things as well.
  10.  
  11. NOTE:    This program was sent to me by Barry Friedman
  12.     <uunet!chekov!friedman>. You should contact him for details
  13.     and remarks. I'm only passing it through.
  14.  
  15. Submitted-by: Barry Friedman <uunet!chekov!friedman>
  16. Archive-name: tguide/part01
  17.  
  18. ---- Cut Here and unpack ----
  19. #!/bin/sh
  20. # This is tguide, a shell archive (shar 3.24)
  21. # made 06/13/1990 08:19 UTC by jv@squirrel.mh.nl
  22. # Source directory /u/jv/reftf
  23. #
  24. # existing files WILL be overwritten
  25. #
  26. # This shar contains:
  27. # length  mode       name
  28. # ------ ---------- ------------------------------------------
  29. #   3160 -rwxrwxrwx tguide
  30. #
  31. if touch 2>&1 | fgrep '[-amc]' > /dev/null
  32.  then TOUCH=touch
  33.  else TOUCH=true
  34. fi
  35. # ============= tguide ==============
  36. echo "x - extracting tguide (Text)"
  37. sed 's/^X//' << 'SHAR_EOF' > tguide &&
  38. X#!/utils/bin/perl
  39. X$em='\\\\(em';  #  em dash
  40. X$dg='\\\\(dg';  #  dagger
  41. X#   scale and page position factors
  42. X$hscale=3;
  43. X$vscale=2.7;
  44. X$hcorr=250;
  45. X$vcorr=120;
  46. X
  47. X#  this sequence works with Eroff, don't know about others
  48. Xprint q|\X'code="\e033&l2S"'\c|,"\n";  #  laserjet 2000 control sequence
  49. X
  50. Xprint ".po 0\n";
  51. Xprint ".in 0\n";
  52. X
  53. Xwhile (<>) {
  54. X
  55. X    #-------------------------------------------------
  56. X    # Skip a lot of useless stuff
  57. X    #-------------------------------------------------
  58. X
  59. X    if ( /^%%/ ) { # comments skipped
  60. X        next;
  61. X    }
  62. X
  63. X    if ( / gr$/ ) {  
  64. X        #?
  65. X        next;
  66. X    }
  67. X
  68. X    if ( / lw$/ ) {  
  69. X        #?
  70. X        next;
  71. X    }
  72. X
  73. X    if ( / lin$/ ) {  
  74. X        #?
  75. X        next;
  76. X    }
  77. X
  78. X    if ( / setTxMode$/ ) {  
  79. X        #?
  80. X        next;
  81. X    }
  82. X
  83. X    if ( / pen$/ ) {  
  84. X        #?
  85. X        next;
  86. X    }
  87. X
  88. X    if ( /\)kp$/ ) {  
  89. X        #frame ?
  90. X        next;
  91. X    }
  92. X
  93. X    if ( / xl$/ ) {  
  94. X        #frame ?
  95. X        next;
  96. X    }
  97. X
  98. X    if ( / fr$/ ) {  
  99. X        #frame ?
  100. X        next;
  101. X    }
  102. X
  103. X    if ( /bu fc$/ ) {
  104. X        next;
  105. X    }
  106. X
  107. X    if ( /fs$/ ) {
  108. X        next;
  109. X    }
  110. X
  111. X    if ( /bn$/ ) {
  112. X        next;
  113. X    }
  114. X    #-------------------------------------------------
  115. X    # Now for some real work
  116. X    #-------------------------------------------------
  117. X
  118. X    if ( /^move1$/ ) {  # output page NOTE: Eroff 2-up landscape handles
  119. X                                            # this automatically  - otherwise toggle a correction
  120. X                                            # factor to be added to horizontal position
  121. X        #move to left side of page
  122. X        next;
  123. X    }
  124. X
  125. X    if ( /^move2$/ ) {  # output page
  126. X        #move to right side of page
  127. X        next;
  128. X    }
  129. X
  130. X    if ( /^op$/ ) {  # output page
  131. X        print ".bp\n";
  132. X        next;
  133. X    }
  134. X
  135. X    #-------------------------------------------------
  136. X    # Font Changes
  137. X    #-------------------------------------------------
  138. X
  139. X    if ( /Helvetica fnt/ ) {
  140. X        print "'ft H\n";
  141. X        next;
  142. X    }
  143. X
  144. X    if ( /Times-Bold fnt/ ) {
  145. X        print ".ft B\n";
  146. X        next;
  147. X    }
  148. X
  149. X    if ( /Times-Italic fnt/ ) {
  150. X        print ".ft I\n";
  151. X        next;
  152. X    }
  153. X    if ( /Times-Roman fnt/ ) {
  154. X        print ".ft R\n";
  155. X        next;
  156. X    }
  157. X    #-------------------------------------------------
  158. X    # Size translations (from 2up guide 
  159. X    #-------------------------------------------------
  160. X    if ( /(\d+) fz/ ) {
  161. X        $sz = $1;
  162. X        if ($sz == 24) { $sz = 18; } 
  163. X        elsif ($sz == 18) { $sz = 12; } 
  164. X        elsif ($sz == 14) { $sz = 10; } 
  165. X        elsif ($sz == 12) { $sz = 8; } 
  166. X        elsif ($sz == 10) { $sz = 8; } 
  167. X
  168. X        print ".ps $sz\n";
  169. X        $vs = $sz+2;
  170. X        print ".vs $vs\n";
  171. X        next;
  172. X    }
  173. X    #-------------------------------------------------
  174. X    # Positioning
  175. X    #-------------------------------------------------
  176. X    if ( /(-*\d+) (-*\d+) gm$/ ) {
  177. X        $v= $1; # vertical pos
  178. X        $h= $2; # horiz. pos
  179. X        if ($1 < 0 || $2 < 0 ) {
  180. X            next;
  181. X        }
  182. X        $sc_v = int($v * $vscale) - $vcorr;
  183. X        print ".br\n";
  184. X        print ".sp |$sc_v","u\n";
  185. X        $sc_h = int($h * $hscale) - $hcorr;
  186. X        print "\\h\'|$sc_h","u\'\\c\n";
  187. X        next;
  188. X    }
  189. X    #-------------------------------------------------
  190. X    # Text translations
  191. X    #-------------------------------------------------
  192. X    if ( /[(](.*)[)].*show$/ ) {
  193. X        $ln = $1;
  194. X        $ln =~ s/\\240/$dg/g; 
  195. X        $ln =~ s/\\253/'/g; 
  196. X        $ln =~ s/\\311/.../g; 
  197. X        $ln =~ s/\\312/\\|/g; 
  198. X        $ln =~ s/\\322/``/g; 
  199. X        $ln =~ s/\\323/''/g; 
  200. X        $ln =~ s/\\325/'/g; 
  201. X        $ln =~ s/\\32./$em/g; 
  202. X
  203. X        $ln =~ s/\\\(/\(/g;
  204. X        $ln =~ s/\\\)/\)/g;
  205. X        # guard column 1 of output
  206. X        if ( $ln =~ /^[.'" ]/ ) {
  207. X            $ln = "\\&" . $ln;
  208. X        }
  209. X        print "$ln\n";
  210. X        next;
  211. X    }
  212. X    print STDERR "?: $_\n";  # Anything I missed
  213. X}
  214. SHAR_EOF
  215. $TOUCH -am 0531181990 tguide &&
  216. chmod 0777 tguide ||
  217. echo "restore of tguide failed"
  218. set `wc -c tguide`;Wc_c=$1
  219. if test "$Wc_c" != "3160"; then
  220.     echo original size 3160, current size $Wc_c
  221. fi
  222. exit 0
  223. --
  224. Johan Vromans                       jv@mh.nl via internet backbones
  225. Multihouse Automatisering bv               uucp: ..!{uunet,hp4nl}!mh.nl!jv
  226. Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62944/62500
  227. ------------------------ "Arms are made for hugging" -------------------------
  228.