Subject: enhancements to the psview script

From: [email-masked] (Craig Leres)
Date: Sat, 11 Jul 87 01:46:47 EDT

Date: 10 Jul 87 04:03:45 GMT
From: [email-masked]  (Craig Leres)
Subject: enhancements to the psview script
To: [email-masked]

Last time I did PostScript previewing, I wasn't very happy with
the supplied psview script so I did some hacking on it. A context
diff between it and the psview that is on the 1.0 beta follows. My
version uses psh instead of say, has legal and portrait flags, and
allows you to specify multiple input files. But the most important
feature as far as previewing goes is that it rereads the input
files on a screen redraw. This way, you can make changes to your
PostScript source(s) and quickly see them (assuming they are
syntactically correct).

		Craig
------

*** psview	Thu Jul  9 20:44:08 1987
--- /usr/NeWS/bin/psview	Mon Mar 16 10:10:44 1987
***************
*** 1,7 ****
  #! /bin/csh -f
  #
- # @(#) $Header: psview,v 1.3 87/07/09 20:43:47 leres Exp $ (LBL)
- #
  # NeWS is a product of Sun Microsystems, Inc. and is provided for
  # unrestricted use provided that this legend is included on all tape
  # media and as a part of the software program in whole or part.  Users
--- 1,5 ----
***************
*** 44,114 ****
  #	on top of each other.
  #   o	NeWS does not support outline fonts, or dash patterns yet.
  #   o	Assumes a syntactically valid PostScript file.
- #
- # Flags:
- #
- #	-p portrait mode
- #	-l legal size
- #
- # 26May87: Rewrote to use psh instead of say, to accept multiple file
- #          arguments and to reread users input files on window refresh.
- #          Added portrait and legal size flags. -leres
- #
- #

! top:
!     if ($#argv > 0) then
! 	if ($argv[1] == "-p") then
! 	    set portrait
! 	    shift
! 	    goto top
! 	endif
! 	if ($argv[1] == "-l") then
! 	    set legal
! 	    shift
! 	    goto top
! 	endif
!     endif
!
!     if ( $#argv < 1 ) then
! 	echo "usage: $argv[0]:t [-pl] ps_filename ..."
  	exit 1
      endif

!     set temp=/tmp/psview.$$

!     cat > $temp << 'EOF'
! #! /usr/NeWS/bin/psh
  % definitions to figure out page aspect ratio
  /inch { 72 mul } def		% LaserWriter PostScript coordinates are
  				% 72 points per inch
! 'EOF'
!
!     set page_width=8.5
!     set page_height=11
!     if ($?legal) set page_height=14
!     if ($?portrait) then
! 	set x=$page_height
! 	set page_height=$page_width
! 	set page_width=$x
!     endif
!
!     echo "/page_width $page_width inch def" >>$temp
!     echo "/page_height $page_height inch def" >>$temp
!
!     cat >> $temp << 'EOF'
  /page_aspect page_height page_width div def	% page aspect ratio
  /can_width null def		% placeholders so they don't go in window dict
  /can_height null def

- % Load in a file, if it exists.
- /LoadFile {
-     { dup (r) file } stopped not {
- 	cvx exch
- 	pop
- 	exec clear true
-     } if
- } def

  /PSPaint {			% This procedure sets up the canvas to look
  				% like a letter-sized page,
--- 42,74 ----
  #	on top of each other.
  #   o	NeWS does not support outline fonts, or dash patterns yet.
  #   o	Assumes a syntactically valid PostScript file.

! if ( $#argv > 1) then
!     set progname="$0"
!     echo "usage: $progname:t PS_filename"
!     exit 1
! else if ( $#argv == 1 ) then
!     set inputfile="$argv[1]"
!     if ( $inputfile != "-" && ! -r $inputfile ) then
! 	echo ${inputfile}: No such file or directory
  	exit 1
      endif
+ else
+     set inputfile="-"
+ endif

! set temp=/tmp/psview$$

! cat > $temp << 'EOF'
  % definitions to figure out page aspect ratio
  /inch { 72 mul } def		% LaserWriter PostScript coordinates are
  				% 72 points per inch
! /page_width 8.5 inch def	% letter size; change these for A4 or legal
! /page_height 11 inch def
  /page_aspect page_height page_width div def	% page aspect ratio
  /can_width null def		% placeholders so they don't go in window dict
  /can_height null def

  /PSPaint {			% This procedure sets up the canvas to look
  				% like a letter-sized page,
***************
*** 139,168 ****
      0 0 lineto
      fill			% fill page area with white
      grestore
-
  'EOF'

!     if ($?portrait) then
! 	echo "0 8.5 inch translate" >>$temp
! 	echo "-90 rotate" >>$temp
!     endif

! loop:
!     set arg="$argv[1]"
!     set head=$arg:h
!     set tail=$arg:t
!     if ( $arg == $head ) set head=$cwd
!     set file={$head}/{$tail}
!     if ( ! -r $file ) then
! 	echo ${arg}: No such file or directory
! 	exit 1
!     endif
!     echo "    ($file) LoadFile pop" >>$temp
!     shift
!     if ( $#argv > 0 ) goto loop
!
! cat >> $temp << 'EOF'
!
  } def				% end of PSPaint procedure

  /win {				% create a window
--- 99,110 ----
      0 0 lineto
      fill			% fill page area with white
      grestore
  'EOF'

! # ??? should the client code also be run in a gsave/grestore???
! cat $inputfile >> $temp

! cat << 'EOF' >> $temp
  } def				% end of PSPaint procedure

  /win {				% create a window
***************
*** 172,178 ****
  } makewindowfromuser
  'EOF'

!     chmod u+x $temp
!     $temp
!     rm $temp
!     exit
--- 114,118 ----
  } makewindowfromuser
  'EOF'

! #   tell `say` not to make the window itself
! say -P " " -w -W < $temp; rm -f $temp &