#!/usr/unsupported/bin/perl

$filename = $ARGV[0];
$fsize = $ARGV[1];
$fnamenum = $ARGV[2];
$problem_chars = '([()%])';

if ($filename eq "-help") {die "Usage: enscript.perl filename fontsize fontnumber";}

open(RAWDATA, $filename) || die "Can't open $filename";
open(OUTFILE, ">&STDOUT") || die "Can't open STDOUT";

print OUTFILE while(<DATA>);

if ($fnamenum == 0) {print OUTFILE "\n$fsize tr\n\n";}
	else {print OUTFILE "\n$fsize /Courier gofont\n\n";}

while (<RAWDATA>) {
	chop;
	s/\\/\\134/g;
        s/$problem_chars/sprintf('\\0%o', ord($1))/ego;
	print OUTFILE "($_) GO\n";
}

print OUTFILE "\n\nshowpage\n";
close OUTFILE || die "Could not close $filename";
__END__
%!
%Copyright 1991 Dave Cho  All Rights Reserved
%Permission is given to freely distribute and modify this product so long
%as it is done without charge and so long as this Copyright text remains in
%place.
%Certain designs inherent may be copyrighted elsewhere.
%Dave Cho 1991
%7.7 8.5 div   10.1 11 div scale  % for gs
/inch {72 mul} def
/cm {72 mul 2.54 div} def
/yline {8 inch} def
% the following are the parameters you might want to change:
/sp {14 neg} def % number of points between returns
/cp {4.25 inch} def % where rcenter centers around
/lm {0.5 inch} def % left margin
/tablen {2 inch} def % distance between tab stops
/tabpos {0} def % initial tab position
%/shiftover {} def
/shiftflag 0 def
/shiftover {shiftflag 0 eq 
	{5.5 inch 0 translate /shiftflag 1 def}
	{showpage 0 11 inch translate -90 rotate /shiftflag 0 def} ifelse
/yline 8 inch def 0 yline moveto enter
} def

% don't mess with these:
/stringheight {/stringfoobar exch def gsave
newpath 0 0 moveto  stringfoobar false charpath  flattenpath pathbbox
exch pop 3 -1 roll pop  exch sub  grestore} def
/sqr {dup mul} def
/center   % stack: x y str
{dup stringwidth -2 div 4 -1 roll add exch
   -2 div 4 -1 roll add exch moveto show} def
/enter {lm currentpoint exch pop moveto 0 sp rmoveto
	/yline {currentpoint exch pop} def
	/tabpos lm def
	yline 0.5 inch le {shiftover} if} def
/return {show enter} def
/rcenter {currentpoint exch pop cp exch 3 -1 roll  center enter} def
/tab {tabpos tablen add /tabnew exch def tabnew currentpoint
   exch pop moveto /tabpos tabnew def} def
/tabpos {lm} def
/stab {show tab} def
/blam { show currentpoint pop /xorig exch def /xfin {tablen lm add} def
(.) stringwidth pop /dotlen exch def xfin xorig sub dotlen div /foo exch def
/t {1} def 1 t foo {pop (.) show} for} def
/rm {7.5 inch} def
/right {currentpoint exch pop rm exch moveto dup stringwidth pop neg
0 rmoveto} def
/mark1 {currentpoint /ymark1 exch def /xmark1 exch def} def
/mark2 {currentpoint /ymark2 exch def /xmark2 exch def} def
/gofont {/fname exch def /fsize exch def fname findfont fsize scalefont
	setfont /sp {fsize -1.1 mul} def } def
/tb {/Times-Bold gofont} def
/tr {/Times-Roman gofont} def
/ti {/Times-Italic gofont} def
/tbi {/Times-BoldItalic gofont} def
/really {/wanted fsize def
/do-really {
(A) stringheight  wanted lt 
  {fsize 1 add fname gofont do-really} if
} def
do-really
} def
%%Trailer

/wordbreak ( ) def
% the following needs to be the Code Std converted from octal into decimal
/wordbreaknum 32 def
							    
/GOblah {/proc exch def	/linelength exch def /textstring exch def
    /breaklen wordbreak stringwidth pop def /curlen 0 def
    /lastwordbreak 0 def /startchar 0 def /restoftext textstring def
    { restoftext wordbreak search {/nextword exch def pop
	 /restoftext exch def /wordlen nextword stringwidth pop def
	 curlen wordlen add linelength lt
	   { /curlen curlen wordlen add breaklen add def }
	   { textstring startchar lastwordbreak startchar sub
	     getinterval proc /startchar lastwordbreak def
	     /curlen wordlen breaklen add def } ifelse
	 /lastwordbreak lastwordbreak nextword length add 1 add def}
	{ pop exit } ifelse } loop
    /lastchar textstring length def textstring startchar lastchar
      startchar sub getinterval
	dup stringwidth pop linelength lt {proc}
	{/overstring exch def
	/curlen 0 def /lastwordbreak textstring length 1 sub def
	/curpos 0 def
	overstring {wordbreaknum eq {/lastwordbreak curpos def} if
		/curpos curpos 1 add def} forall
	overstring 0 lastwordbreak 1 add getinterval
	  dup stringwidth pop linelength lt {proc
		overstring dup length lastwordbreak sub 1 sub lastwordbreak
		1 add exch getinterval proc}
	    {pop %ok, it's stupid
		/curlen 0 def /curpos 0 def /origpos 0 def
		/tempoverstring overstring length string def
		0 1 overstring length 1 sub {/curpos exch def curpos dup
		  overstring exch 1 getinterval dup stringwidth pop
		  curlen add /curlen exch def
		  tempoverstring 3 1 roll putinterval
		  curlen linelength ge {
			tempoverstring origpos curpos origpos sub 1 add
			  getinterval proc
			/origpos curpos 1 add def
			/curlen 0 def
			/tempoverstring overstring length string def
			} if
		} for
		tempoverstring origpos curpos origpos sub 1 add
		  getinterval proc
	    } ifelse
	} ifelse
} def

%the 4.5 inch is the length of the horz line
/GO {4.5 inch {/gostring exch def  gostring () ne
 {gostring lm yline moveto return} if } GOblah} def

0 11 inch translate -90 rotate
