evan@csli.STANFORD.EDU (Evan Kirshenbaum) (05/26/88)
Ok, folk, the initial response has been sufficient to warrant posting
the code to the net. To install, simply run the following through sh,
and change the definition of 'dir' in a2ps to point to the directory
where the other files are kept. To use, just say
a2ps file1 file2 ...
This produces output suitable for piping through lpr to a PostScript
printer.
The program consists of a csh script, a sed file, an awk file and a ps
prolog. It requires that expand(1) be present in the path. It has
been run on a Sun-4 running 4.2bsd and HP-Bobcats running HP/UX.
I've got a number of improvements in mind, and I would appreciate any
suggestions (and bugs reports) anyone has. I will probably post a
spiffier version in a coupe of weeks, but this has served me well for
quite some time.
Enjoy
---
Evan Kirshenbaum
Stanford University
evan@csli.Stanford.EDU
...!ucbvax!csli.stanford.edu!evan
If you think my opinions represent this university,
you haven't been on campus recently!
--Cut-Here----Cut-Here----Cut-Here----Cut-Here----Cut-Here----Cut-Here--
#! /bin/sh
: This is a shar archive. Extract with sh, not csh.
echo x - a2ps
cat > a2ps << '5982!Funky!Stuff!'
#!/bin/csh
# File: csli:/user/evan/bin/a2ps
# Created: Wed May 25 11:32:18 1988 by evan@csli (Evan Kirshenbaum)
# Version: 1.0(1)
# Description: Convert files from ascii to PostScript.
# Usage: a2ps file1 file2 ...
# Writes to standard output (I generally pipe through
# lpr). Files are prepared for printing landscape, two to
# a page, boxed. Header for each page has the format:
# Print-Time File-Name Page-Number
# where page-number starts at 1 for each file. Each
# sheet in the batch is also numbered in the lower
# right-hand corner.
#
# Customizability will be included soon.
#
# Requires 'expand' (change tabs to spaces) in the search
# path.
#
# When installing, change the definition of 'dir' to the
# directory where the a2ps.* files are kept.
#
# Edit History:
set dir= (~evan/bin)
cat $dir/a2ps.ps
date +"/date (%d %h 19%y %r) def"
echo "startdoc"
foreach f ($*)
echo "($f) newfile"
cat $f | expand |sed -f $dir/a2ps.sed | awk -f $dir/a2ps.awk
end
echo "cleanup"
5982!Funky!Stuff!
echo x - a2ps.sed
cat > a2ps.sed << '5982!Funky!Stuff!'
# File: csli:/user/evan/bin/a2ps.sed
# Created: Wed May 25 11:24:07 1988 by evan@csli (Evan Kirshenbaum)
# Version: 1.0(1)
# Description: sed filter for a2ps ascii to PostScript conversion
# program. Puts backslashes before all parens and
# backslashes to allow the line to be included directly
# in a postscript string.
#
# Edit History:
s/[\\()]/\\&/g
5982!Funky!Stuff!
echo x - a2ps.awk
cat > a2ps.awk << '5982!Funky!Stuff!'
# File: csli:/user/evan/bin/a2ps.awk
# Created: Wed May 25 11:26:39 1988 by evan@csli (Evan Kirshenbaum)
# Version: 1.0(1)
# Description: awk filter for a2ps ascii to PostScript conversion
# program. Breaks pages every 66 lines or when a line
# begins with '\f'.
#
# Edit History:
BEGIN {line=0; print "startpage"}
(line>65 || $0~/^/) {line=0; print "endpage startpage"}
$0~/^ *$/ {next}
{print "(" $0 ") s"; line++}
END {print "endpage"}
5982!Funky!Stuff!
echo x - a2ps.ps
cat > a2ps.ps << '5982!Funky!Stuff!'
%! PostScript Source Code
% File: csli:/user/evan/bin/a2ps.ps
% Created: Wed May 25 11:22:04 1988 by evan@csli (Evan Kirshenbaum)
% Version: 1.0(1)
% Description: PostScript prolog for a2ps ascii to PostScript program.
%
% Edit History:
/xdef {exch def} def
/inch {72 mul} def
/getfont {exch findfont exch scalefont} def
/filenamesize 12 def
/filenamefont /Helvetica-Bold filenamesize getfont def
/linesperpage 66 def
/datesize filenamesize 2 sub def
/datefont /Helvetica datesize getfont def
/headersize filenamesize 4 add def
/bodysize 6.8 def
/bodyfont /Courier bodysize getfont def
/sidemargin 4 def
/topmargin 4 def
/pagewidth
bodyfont setfont (0) stringwidth pop 80 mul sidemargin dup add add
def
/pageheight
bodysize linesperpage mul topmargin dup add add headersize add
def
/uppery 8.5 inch pageheight add 2 div def
/upperx [ 11 inch pagewidth 2 mul sub 3 div
dup 2 mul pagewidth add ] def
/pnum ( ) def
/endpage
{ pageside 1 eq
{ /pageside 0 def
numberpage
copypage erasepage
/sheet sheet 1 add def }
{ /pageside 1 def }
ifelse
/pagenum pagenum 1 add def
} def
/numberpage
{ 11 inch upperx 0 get sub sidemargin add
8.5 inch uppery sub headersize sub moveto
datefont setfont
sheet pnum cvs show
} def
/newfile
{ /filename xdef
/pagenum 1 def
} def
/cleanup
{ pageside 1 eq
{numberpage showpage} if
} def
/startdoc
{ 8.5 inch 0 inch translate
90 rotate
/pageside 0 def
/sheet 1 def
} def
/startpage
{ printheader
printborder
upperx pageside get sidemargin add
uppery topmargin sub bodysize sub headersize sub moveto
bodyfont setfont
} def
/s { gsave
show
grestore
0 bodysize neg rmoveto
} def
/printheader
{ upperx pageside get uppery headersize sub 1 add moveto
datefont setfont
gsave
sidemargin 2 rmoveto date show
grestore
gsave
/pnum pagenum pnum cvs def
pagewidth sidemargin sub pnum stringwidth pop sub
(Page ) stringwidth pop sub 3 rmoveto
(Page ) show pnum show
grestore
gsave
filenamefont setfont
pagewidth filename stringwidth pop sub 2 div 2 rmoveto
filename show
grestore
} def
/printborder
{ upperx pageside get uppery moveto
gsave
pagewidth 0 rlineto
0 pageheight neg rlineto
pagewidth neg 0 rlineto
closepath stroke
grestore
0 headersize neg rmoveto pagewidth 0 rlineto stroke
} def
5982!Funky!Stuff!