#!/bin/csh -f
onintr EXINT
set colmax='75'
###Request option###
l1:
set opt=P
echo -n "Option print, postscript, tidy, list (p,ps,t,l) [p]: "
set temp=$<
if ($temp != "") set opt=$temp
set opt=`echo $opt |tr ptls PTLS`
l2:
if ($opt !~ P* && $opt !~ T* && $opt !~ L*) then
   echo "**Invalid option must be p, ps, t or l**"
   goto l1
endif
###Request filename###
l3:
echo -n "Filename: "
set temp=$<
if ($temp == "") exit 101
set fnam=$temp
l4:
if (-e $fnam == 0) then
   echo "**File $fnam does not exist**"
   goto l3
endif
set help=""
echo -n "Is this a help file [n]: "
set temp=$<
if ($temp =~ Y* || $temp =~ y*) then
   set help='HP'
   set colmax='72'
endif
###Underline character###
set ul='^'
echo -n "Underline character [^]: "
set temp=$<
if ($temp != "") set ul=$temp
###Paging###
if ($opt !~ T*) then
   set pag=0
   echo -n "Page numbering required (y/n) [y]: "
   set temp=$<
   if ($temp != "") then
      set temp=`echo $temp |tr yn YN`
      if ($temp =~ N*) set pag=-1
   else
      echo -n "Start page number [1]: "
      set temp=$<
      if ($temp != "") then
         @ pag = $temp - 1
      endif
   endif
endif
####Postscript####
if ($opt =~ PS*) then
   echo -n "File name for Postscript file: "
   set psfil=$<
   echo "9 83 2 57 0 150 80 0 0 0 $pag" >$$.tmp
   echo "PR PS UL$ul OV" 'BO~' "$help" >>$$.tmp
   echo "   " >>$$.tmp
   echo "0" >>$$.tmp
   setenv TEXTIN $fnam
   setenv PROUT $psfil
   onintr clrup0
   /pxbin/tidytext <$$.tmp
   clrup0:
   onintr -
   /bin/rm $$.tmp
   exit 101
endif
####Print####
if ($opt =~ P*) then
   echo "9 83 2 57 0 150 80 0 0 0 $pag" >$$.tmp
   echo "PR UL$ul OV" 'BO~' "$help" >>$$.tmp
   echo "   " >>$$.tmp
   echo "0" >>$$.tmp
   setenv TEXTIN $fnam
   setenv PROUT $$.lis
   onintr clrup1
   /pxbin/tidytext <$$.tmp
   asa $$.lis | lpr -J $fnam
   clrup1:
   onintr -
   /bin/rm $$.tmp  $$.lis
   exit 101
####Tidy file####
else if ($opt =~ T*) then
   echo "1 $colmax 2 57 60 150 80 0 0 0 0" >$$.tmp
   echo "PR WF UL$ul" 'BO~' "$help" >>$$.tmp
   echo "   " >>$$.tmp
   echo "0" >>$$.tmp
   echo "Renaming original file as $fnam.bak"
   onintr clrup2
   mv $fnam $fnam.bak
   setenv TEXTIN $fnam.bak
   setenv TEXTOUT $fnam
   setenv PROUT $$.lis
   /pxbin/tidytext <$$.tmp
   cat $$.lis
   onintr clrup3
   echo "Remove backup file (y/n) [n]: "
   set temp=$<
   if ($temp != "") then
      set temp=`echo $temp |tr yn YN`
      if ($temp =~ Y*) /bin/rm $fnam.bak
   endif
   goto clrup3
   clrup2:
   onintr -
   /bin/rm $fnam
   mv $fnam.bak $fnam
   clrup3:
   onintr -
   /bin/rm $$.tmp $$.lis
   exit 101
####List on terminal
else if ($opt =~ L*) then
   echo "1 75 2 57 60 150 80 0 0 0 $pag" >$$.tmp
   echo "PR UL$ul" 'BO~' "$help">>$$.tmp
   echo "   " >>$$.tmp
   echo "0" >>$$.tmp
   setenv TEXTIN $fnam
   setenv PROUT $$.lis
   onintr clrup4
   /pxbin/tidytext <$$.tmp
   more $$.lis
   clrup4:
   onintr -
   /bin/rm $$.tmp $$.lis
   exit 101
endif
EXINT:
exit 99
