home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / a2ps < prev    next >
Text File  |  1990-06-30  |  13KB  |  430 lines

  1.  
  2. #!/bin/sh
  3. # shar: Shell Archiver
  4. # Execute the following text with /bin/sh to create the file(s):
  5. #    a2ps.1
  6. #    a2ps
  7. # This archive created: Thu Jun 28 14:40:28 1990
  8. # Wrapped by: Gisle Aas (Norwegain Computing Centre, Oslo, Norway)
  9. sed 's/^X//' << \SHAR_EOF > a2ps.1
  10. X.TH A2PS 1 "June 1990"
  11. X.SH NAME
  12. Xa2ps \- convert ISO Latin1 text to PostScript
  13. X.SH SYNOPSIS
  14. X.B a2ps
  15. X[
  16. X.B \-nlrth23
  17. X] [
  18. X.B \-b
  19. X.I "text"
  20. X] [
  21. X.B \-s
  22. X.I size
  23. X] [
  24. X.I filename
  25. X\&.\|.\|.
  26. X]
  27. X.SH DESCRIPTION
  28. XThe
  29. X.B a2ps
  30. Xprogram is used to print simple
  31. Xtext files (e.g. program listings) on a PostScript\*R device. 
  32. XThe name
  33. X.B a2ps
  34. Xused to stand for ascii-to-postscript, but the program
  35. Xis designed to handle the whole
  36. XISO Latin1 character set.
  37. XEfforts have been made to ensure that 
  38. X.B a2ps
  39. Xproduces good looking and effective PostScript code.
  40. XThe output conforms to Adobe's
  41. Xdocument structuring conventions (version 2.1). The 
  42. X.B a2ps 
  43. Xprogram
  44. Xassumes that the page format on the output device is A4.
  45. XThe meaning of form feed (^L) characters in the input stream is understood.
  46. X.PP
  47. XThe
  48. X.B a2ps
  49. Xprogram is written in
  50. X.I perl.
  51. XSo if there is something you don't like about how
  52. X.B a2ps
  53. Xworks, you can easily fix it youself.
  54. X.SH OPTIONS
  55. X.TP 5
  56. X.B \-n
  57. Xuse the norwegian version of ISO 646 (7-bit ascii) to encode the text.
  58. XNorwegian letters will replace the left/right braces, left/right
  59. Xbrackets, backslash and horisontal bar characters.
  60. X.TP 5
  61. X.B \-l
  62. Xproduces linenumbers on each 5'th line. Nice for program listings.
  63. X.TP 5
  64. X.B \-t
  65. Xtruncate lines that are to long. The default is to wrap
  66. Xlong lines so that they continue on the next line on the printed output.
  67. X.TP 5
  68. X.B \-r
  69. Xrotate the output page 90 degrees. This is also called
  70. X.I landscape
  71. Xmode.
  72. X.TP 5
  73. X.B \-h
  74. Xsuppress generation of page headers.
  75. X.TP 5
  76. X.B \-2
  77. Xuse two column format.
  78. X.TP 5
  79. X.B \-3
  80. Xuse three column format (not supported).
  81. X.TP 5
  82. X.BI \-b " text"
  83. Xthe 
  84. X.I text
  85. Xparameter replaces the default text in the header of the pages.
  86. XThe default text is the filename of the file to be printed. There is no
  87. Xdefault if the filtered text comes from standard input.
  88. X.TP 5
  89. X.BI \-s " size"
  90. Xspecifies a new font size for the body text. The default is 10 point.
  91. X.SH EXAMPLES
  92. XTo print files on a PostScript printer:
  93. X.nf
  94. X    a2ps -l *.[ch] | lpr
  95. X.fi
  96. X.PP
  97. XTo find out how many pages a2ps will produce for a given file:
  98. X.nf
  99. X    a2ps file.txt | tail -1
  100. X.fi
  101. X.PP
  102. XOur printer stacks the pages the wrong way. To fix it try:
  103. X.nf
  104. X    cat file.txt | a2ps -b "some text" | psrev | lpr
  105. X.fi
  106. X.SH SEE ALSO
  107. X.BR perl (1),
  108. X.BR enscript (1),
  109. X.BR psrev (1),
  110. X.BR ISO8859 (7),
  111. X.BR PostScript (7)
  112. X.SH BUGS
  113. XIf some of the specified
  114. X.I files
  115. Xdoes not exist,
  116. X.B a2ps
  117. Xget confused about what to put in the header.
  118. XThere is no easy way to change the margins or the fonts that
  119. X.B a2ps
  120. Xinsist on using.
  121. XThe
  122. X.B a2ps
  123. Xfilter ought to understand the meaning of the backspace character. It is used
  124. Xto produce boldfaced and underlined text by programs like 
  125. X.BR nroff (1).
  126. XPerhaps
  127. X.B a2ps
  128. Xshould be made to reject input which looks like garbage (binary files).
  129. X.SH AUTHOR
  130. XGisle Aas, Norwegain Computing Centre (NR), Oslo, Norway.
  131. X<Gisle.Aas@nr.no>
  132. SHAR_EOF
  133. if test 2839 -ne "`wc -c a2ps.1`"
  134. then
  135. echo shar: error transmitting a2ps.1 '(should have been 2839 characters)'
  136. fi
  137. sed 's/^X//' << \SHAR_EOF > a2ps
  138. X#!/local/boeygen/bin/perl
  139. X# "a2ps" text to PostScript filter written in perl by Gisle Aas, NCC 1990
  140. X# version 1.1
  141. X#
  142. X# Efforts have been made to produce nice and effective PostScript. The
  143. X# output conforms to Adobe's document structuring conventions version-2.1.
  144. X# 
  145. X# Whish list:  (this may become a feature some time)
  146. X#     Line number on the last line (in addition to each 5th line)
  147. X#     Marking (by some funny char) truncation and wrapping of lines
  148. X#     Faster execution (rewrite the hole thing in C?)
  149. X#     Parsing of backspace to produce bold and underlined fonts.
  150. X
  151. X# Some configuration constants, meassured in points (1/72 inch)
  152. Xsub a4_top        { 841; }
  153. Xsub a4_right_edge { 595; }
  154. X
  155. X# The next few entries are from the AFM file for Adobe's font Courier
  156. Xsub cour_char_width     { 600; }   # The width of each char in 1000x1000 square
  157. X#sub underline_position  { -82; }   # Where underline goes relative to baseline
  158. X#sub underline_thickness {  40; }   # and it's thickness
  159. X
  160. X# Parse command line for options and flags
  161. Xdo 'getopts.pl';
  162. Xunless (&Getopts('nrth12s:b:l')) {
  163. X   print STDERR "Usage: a2ps [-<options>] [file]...\n";
  164. X   print STDERR "Options: -n       norwegian 7bit-ascii encoding\n";
  165. X   print STDERR "         -l       print with line numbers\n";
  166. X   print STDERR "         -r       rotated, landscape orientation\n";
  167. X   print STDERR "         -t       truncate long lines, " . 
  168. X                                  "default is to wrap lines\n";
  169. X   print STDERR "         -b\"text\" replaces the text in the page header\n";
  170. X   print STDERR "         -h       no page headers\n";
  171. X   print STDERR "         -2       set text in two columns\n";
  172. X   print STDERR "         -s<size> select new text fontsize, default 10pt\n";
  173. X   exit(1);
  174. X}
  175. X
  176. X# Set default values, some based on command line options
  177. X$left_margin  = 80;
  178. X$right_margin = 40;
  179. X$tb_margin    = 45;
  180. X$font         = "Courier";
  181. X$font_size    = 10;        $font_size = $opt_s if ($opt_s > 0);
  182. X$header_font  = "Helvetica-Bold";
  183. X$header_font_size = 12;
  184. X$line_number_font = "Helvetica";
  185. X$line_number_size = 5;
  186. X
  187. X$line_height = $font_size * 1.08;
  188. X$no_columns = defined($opt_2) ? 2 : 1;
  189. X$col_separation = 30;
  190. X$sep_bars = '';                 # false
  191. X$landscape = defined($opt_r);
  192. X$header_height = 30;
  193. X$show_header = !defined($opt_h);
  194. X$wrap_lines = !defined($opt_t);
  195. X$truncate_lines = !$wrap_lines; # don't change this
  196. X$norsk_ascii = defined($opt_n);
  197. X
  198. X# Some initial values
  199. X$opt_b = &ps_string($opt_b) if ($opt_b);
  200. X$form_feed = ''; # false;
  201. X$page_no  = 0;
  202. X$line_no = 0;
  203. Xif ($landscape) {
  204. X    $top = &a4_right_edge;
  205. X    $right_edge = &a4_top;
  206. X    $left_margin = $right_margin; # this is a dirty one
  207. X} else {
  208. X    $top = &a4_top;
  209. X    $right_edge = &a4_right_edge;
  210. X}
  211. X$home_pos = $top - $tb_margin - ($show_header ? $header_height : 0);
  212. X$col_width = ($right_edge - $left_margin - $right_margin
  213. X              - ($no_columns - 1) * $col_separation) / $no_columns;
  214. X$char_width = &cour_char_width * $font_size / 1000;
  215. X$chars_per_line = int ($col_width / $char_width + 1);
  216. X
  217. X&prolog;
  218. X
  219. X$cur_pos = -1;
  220. X$cur_col = 100;
  221. X$file_name = &ps_string($ARGV[0]);
  222. XLINES:
  223. Xwhile (<>) {
  224. X   chop;
  225. X   $line_no++;
  226. X   if (ord == 014) {        # form feed
  227. X       s/.//;    # chop off first char
  228. X       $cur_pos = -1; 
  229. X       next LINES if (length == 0);
  230. X   }
  231. X   while (s/\t/' ' x (8 - length($`) % 8)/e) {}   # expand tabs
  232. X   do {
  233. X      if ($cur_pos < $tb_margin) {
  234. X          $cur_pos = $home_pos;
  235. X          if ($cur_col < $no_columns) {
  236. X              $cur_col++;
  237. X          } else {
  238. X              $cur_col = 1;
  239. X              &new_page;
  240. X          }
  241. X      }
  242. X      $text = substr($_,0,$chars_per_line);
  243. X      $_ = $truncate_lines ? '' : substr($_,$chars_per_line,10000);
  244. X      if ($text =~ s/^ +//) {            # suppress leading blanks
  245. X          $indent = $char_width * length($&);
  246. X      } else {
  247. X          $indent = 0;
  248. X      }
  249. X      # Make suitable as a postscript string
  250. X      $text =~ s/[\\\(\)]/\\$&/g;
  251. X      $text =~ s/[\000-\037\177-\377]/sprintf("\\%03o",ord($&))/ge;
  252. X      # Calculate position
  253. X      $x = $left_margin + ($cur_col - 1) * ($col_width + $col_separation);
  254. X      $cur_pos -= $line_height;
  255. X      printf "(%s)%.1f %.1f S\n", $text, $x + $indent, $cur_pos 
  256. X             if (length($text));
  257. X      if ($opt_l && ($line_no % 5) == 0) { # print line numbers
  258. X          print "F2 SF ";
  259. X          printf "($line_no) dup stringwidth pop neg %.1f add %.1f M show ",
  260. X                  $x - 10, $cur_pos;
  261. X          print "F1 SF\n";
  262. X      }
  263. X      if (eof) {
  264. X         $file_name = &ps_string($ARGV[0]);
  265. X         $cur_pos = -1;  # will force a new column next time
  266. X         $cur_col = 100; # will force a new page next time
  267. X         $line_no = 0;
  268. X      }
  269. X   } while (length($_));
  270. X}
  271. X&end_page;
  272. Xprint "%%Trailer\n";
  273. Xprint "%%Pages: $page_no\n";
  274. X
  275. X#--end of main-------------------------------------------------------
  276. X
  277. X
  278. Xsub prolog {
  279. X   local($user) = getlogin || "(unknown)";
  280. X   local($sec,$min,$hour,$mday,$mon,$year) = localtime;
  281. X   $date = sprintf("(%d. %s %d) (%2d:%02d)",$mday,
  282. X                    ('Januar','Februar','Mars','April','Mai','Juni',
  283. X                     'Juli','August','Oktober','November','Desember')[$mon],
  284. X                     $year+1900, $hour,$min);
  285. X#   open(LOG,">>/home/boeygen/aas/.a2ps-log");
  286. X#   print LOG "$user, $date\n";
  287. X#   close(LOG);
  288. X
  289. X   print "%!PS-Adobe-2.0\n";
  290. X   print "%%Title: @ARGV\n" if (@ARGV);
  291. X   print <<"EOT";
  292. X%%Creator: a2ps, Text to PostScript filter in perl, (C) 1990 Gisle Aas, NCC
  293. X%%CreationDate: $date
  294. X%%For: $user
  295. X%%Pages: (atend)
  296. X%%DocumentFonts: $font
  297. XEOT
  298. X   print "%%+ $line_number_font\n" if ($opt_l);
  299. X   print "%%+ $header_font\n" if ($show_header);
  300. X   print <<"EOT";
  301. X%%EndComments
  302. X/S{moveto show}bind def
  303. X/M{moveto}bind def
  304. X/L{lineto}bind def
  305. X/SF{setfont}bind def
  306. X%%BeginProcSet: reencode 1.0 0
  307. X/RE { %def
  308. X   findfont begin
  309. X   currentdict dup length dict begin
  310. X        { %forall
  311. X             1 index/FID ne {def} {pop pop} ifelse
  312. X         } forall
  313. X         /FontName exch def dup length 0 ne { %if
  314. X            /Encoding Encoding 256 array copy def
  315. X            0 exch { %forall
  316. X                dup type /nametype eq { %ifelse
  317. X                    Encoding 2 index 2 index put
  318. X                    pop 1 add
  319. X                 }{%else
  320. X                    exch pop
  321. X                 } ifelse
  322. X          } forall
  323. X       } if pop
  324. X    currentdict dup end end
  325. X    /FontName get exch definefont pop
  326. X} bind def
  327. X%%EndProcSet: reencode 1.0 0
  328. X%%EndProlog
  329. X%%BeginSetup
  330. X0.15 setlinewidth
  331. XEOT
  332. X   if ($norsk_ascii) {
  333. X      print "[8#133 /AE/Oslash/Aring 8#173 /ae/oslash/aring] dup\n";
  334. X      print "/Body-Font/$font RE\n";
  335. X      print "/Header-Font/$header_font RE\n" if ($show_header);
  336. X   } else {
  337. X      print "ISOLatin1Encoding /Body-Font/$font RE\n";
  338. X      print "ISOLatin1Encoding /Header-Font/$header_font RE\n"
  339. X         if ($show_header);
  340. X   }
  341. X   print "/F1/Body-Font findfont $font_size scalefont def\n";
  342. X   print "/F2/$line_number_font findfont $line_number_size scalefont def\n"
  343. X        if ($opt_l);
  344. X   print "/F3/Header-Font findfont $header_font_size scalefont def\n"
  345. X        if ($show_header);
  346. X   print "F1 SF\n";
  347. X   if ($landscape) {
  348. X      printf "90 rotate 0 -%d translate %% landscape mode\n",&a4_right_edge;
  349. X   }
  350. X   print "%%EndSetup\n";
  351. X}
  352. X
  353. X
  354. X
  355. Xsub new_page {
  356. X   &end_page unless ($page_no == 0);
  357. X   $page_no++;
  358. X   print "%%Page: $page_no $page_no\n";
  359. X   print "/my_save save def\n";
  360. X   if ($show_header) {
  361. X      # First print a box
  362. X      local($llx,$lly,$urx,$ury) = ($left_margin - 10,
  363. X            $top - $tb_margin - $header_font_size * 1.3,
  364. X            $right_edge - $right_margin + 10, $top - $tb_margin);
  365. X      printf "%.1f %.1f M %.1f %.1f L %.1f %.1f L ",
  366. X             $llx,$lly, $urx,$lly, $urx, $ury;
  367. X      printf "%.1f %.1f L closepath \n",$llx,$ury;
  368. X      print  "gsave .95 setgray fill grestore stroke\n";
  369. X      # Then the banner or the filename
  370. X      print "F3 SF\n";
  371. X      if ($opt_b) {
  372. X         printf "($opt_b)%.1f %.1f S\n",
  373. X                $left_margin,$top - $tb_margin - $header_font_size;
  374. X      }
  375. X      elsif ($file_name) {
  376. X         printf "(%s)%.1f %.1f S\n", $file_name, 
  377. X                      $left_margin,
  378. X                      $top - $tb_margin - $header_font_size;
  379. X      }
  380. X      # Then print page number
  381. X      printf "%.1f %.1f M($page_no)dup stringwidth pop neg 0 rmoveto show\n",
  382. X                 $right_edge - $right_margin, 
  383. X                 $top - $tb_margin - $header_font_size;
  384. X      print  "F1 SF\n";
  385. X   }
  386. X   if ($sep_bars) {
  387. X      print "% Some postscript code to draw horizontal bars.\n";
  388. X      print "% Not implemented yet\n";
  389. X   }
  390. X}
  391. X
  392. Xsub end_page {
  393. X   unless ($page_no == 0) {
  394. X      print "showpage\n";
  395. X      print "my_save restore\n";
  396. X   }
  397. X}
  398. X
  399. Xsub ps_string
  400. X{
  401. X   # Prepare text for printing
  402. X   local($_) = shift;
  403. X   s/[\\\(\)]/\\$&/g;
  404. X   s/[\001-\037\177-\377]/sprintf("\\%03o",ord($&))/ge;
  405. X   $_;    # return string
  406. X}
  407. X
  408. X
  409. X
  410. X
  411. X# This is interpreted by the GnuEmacs text editor.
  412. X# Local Variables:
  413. X# mode: C
  414. X# eval: (message "Text to PostScript filter written in perl by Gisle Aas")
  415. X# End:
  416. SHAR_EOF
  417. if test 8974 -ne "`wc -c a2ps`"
  418. then
  419. echo shar: error transmitting a2ps '(should have been 8974 characters)'
  420. fi
  421. #    End of shell archive
  422. exit 0
  423. --
  424. Gisle Aas               |  snail: Boks 114 Blindern, N-0314 Oslo, Norway
  425. Norsk Regnesentral      |  X.400: G=Gisle;S=Aas;O=nr;P=uninett;C=no
  426. voice: +47-2-453561     |  inet:  Gisle.Aas@nr.no
  427.  
  428.  
  429.  
  430.