:
#	@(#) text2post 1.3 90/03/07 
#
#	Copyright (C) The Santa Cruz Operation, 1989, 1990.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, and should be treated as Confidential.
#
# Description	Convert files from ascii to PostScript.  
# Usage		reads stdin, out to stdout
# Options	-port: prints in portrait mode
# Options	-land: prints in landscape 1 page  mode
# Options	-land2: prints in landscape 2 page  mode
#
# This program generates a list of sums for all the files
# in the distribution tree.
#
# Created       26 Dec 1989     mikeeb
# Modified      06 Mar 1990     mikeeb
#				modified to work with SCO UNIX 3.2.2
#
# MODE can be	land2 for 2 page landscape mode
#               port for portrait mode
#               land for 1 page landscape mode

port_head()
{
cat << !!END!!OF!!PS!!PROLOGUE!!
%!
save
36.0000 36.0000 translate
/width 540.0000 def
/height 720.0000 def
/deltaY 10.8000 def
/margin 36.0000 def
/indent 36.0000 def
/charWidth 5.4000 def
/Home { /y height deltaY sub def 0 y moveto } def
/Down { /y y deltaY sub def 0 y moveto } def
/Line { show Down } def
/Page { showpage restore save Home } def
/Courier findfont 9 scalefont setfont
save Home
!!END!!OF!!PS!!PROLOGUE!!
}

# Define current date and time and start document

# Process each file on the command line, take standard input
# if there is no arguments on the command line
port_proc()
{
cat - | sed 's/	/        /g' | sed 's/[\\()]/\\&/g' \
    | awk 'BEGIN { line=0 }
	(line>65)	{ line=0; print "Page" }
	$0~/^/		{ print "Page"; line=0 ; next }
				{ print "(" $0 ") Line"; line++ }
	END			{print "showpage restore"}'
echo "restore"
}

land_head()
{
cat << !!END!!OF!!PS!!PROLOGUE!!
%!
save
90 rotate 0 -612.0000 translate
36.0000 36.0000 translate
/width 720.0000 def
/height 540.0000 def
/deltaY 12.0000 def
/margin 36.0000 def
/indent 36.0000 def
/charWidth 6.0000 def
/Home { /y height deltaY sub def 0 y moveto } def
/Down { /y y deltaY sub def 0 y moveto } def
/Line { show Down } def
/Page { showpage restore save Home } def
/Courier findfont 10 scalefont setfont
save Home
!!END!!OF!!PS!!PROLOGUE!!
}

# Define current date and time and start document

# Process each file on the command line, take standard input
# if there is no arguments on the command line
land_proc()
{
cat - | sed 's/	/        /g' | sed 's/[\\()]/\\&/g' \
    | awk 'BEGIN { line=0 }
	(line>42)		{ line=0; print "Page" }
	$0~/^/		{ print "Page"; line=0 ; next }
				{ print "(" $0 ") Line"; line++ }
	END			{print "showpage restore"}'
echo "restore"
}

land2_head()
{
cat << !!END!!OF!!PS!!PROLOGUE!!
%!
save
/xdef {exch def} bind def
/inch {72 mul} bind def
/getfont {exch findfont exch scalefont} bind 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

/pnumbuf 10 string 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
    } bind def
/numberpage
    { 11 inch upperx 0 get sub sidemargin add
      8.5 inch uppery sub headersize sub moveto
      datefont setfont
      sheet pnumbuf cvs show
    } bind def
/newfile
    { /filename xdef
      /pagenum 1 def 
    } bind def
/cleanup
    { pageside 1 eq
      {numberpage showpage} if
    } bind def
/startdoc
    { 8.5 inch 0 inch translate
      90 rotate 
      /pageside 0 def
      /sheet 1 def
    } bind def
/startpage
    { printheader
      printborder
      upperx pageside get sidemargin add
      uppery topmargin sub bodysize sub headersize sub moveto
      bodyfont setfont
    } bind def
/s  { gsave
        show
      grestore
      0 bodysize neg rmoveto
    } bind def
/printheader
    { upperx pageside get uppery headersize sub 1 add moveto
      datefont setfont
      gsave
        sidemargin 2 rmoveto date show
      grestore
      gsave
	/pnum pagenum pnumbuf 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
    } bind 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
    } bind def
!!END!!OF!!PS!!PROLOGUE!!
}

land2_proc()
{
# Define current date and time and start document
date +"/date (%d %h 19%y  %r) def"
echo "startdoc"

# Process each file on the command line, take standard input
# if there is no arguments on the command line
i=-
echo "( ) newfile"
cat $i | sed 's/	/        /g' | sed 's/[\\()]/\\&/g' \
    | awk 'BEGIN		{ line=0; print "startpage" }
	(line>65 || $0~/^/)	{ line=0; print "endpage startpage" }
	$0~/^ *$/		{ next }
				{ print "(" $0 ") s"; line++ }
	END			{print "endpage"}'
echo "cleanup"
echo "restore"
}

#main
#process MODE
if [ $MODE ];then
	case "$MODE" in
	land)	land_head
		land_proc
		;;
	land2)	land2_head
		land2_proc
		;;
	port)	port_head
		port_proc
		;;
	esac
else
	port_head
	port_proc
fi

exit 0
