Subject: papersize support ghostscript?
To: None <tech-pkg@netbsd.org>
From: Jeremy C. Reed <reed@reedmedia.net>
List: tech-pkg
Date: 05/08/2002 21:15:21
I upgraded ghostscript today. And for some reason, my printing started
using A4 (instead of letter). (I can't remember if I hard-coded that long
ago.) Anyways, it was an easy workaround to use -sPAPERSIZE with my gs
wrapper.

I made a patch for papersize package to support ghostscript.

 $ getpapersize
 a2ps has default papersize: A4
 ghostscript has default papersize: (unknown)
 $ setpapersize letter ghostscript
 Set ghostscript package default paper size to Letter in
 /usr/pkg/share/ghostscript/6.01vflib/lib/gs_init.ps
 $ getpapersize
 a2ps has default papersize: A4
 ghostscript has default papersize: letter

I am looking at /usr/pkg/share/ghostscript/6.01vflib/lib/gs_init.ps.
It says the default is letter. The alternative a4 line is commented out.

The package build has:
.if defined(PAPERSIZE) && (${PAPERSIZE} == "A4" || ${PAPERSIZE} == "a4")
CFLAGS+=                -DA4
.endif

And I see that A4 is set in mk/bsd.pkg.defaults.mk so was built that way.

It looks like some of the patches hard-code A4 also.

Wouldn't it be easier to use the gs_init.ps file?

Also, how should I figure out location of gs_init.ps (because
${GS_VERS}vflib may change)?

My patch for papersize below my signature. Please share your comments.

By the way, setpapersize(1) should:
- check for success before overwriting current configs;
- probably should use some mktemp for temp files;
- only output that it was Set if really set.
And getpapersize(1) should say unknown if unknown.

   Jeremy C. Reed
   http://www.reedmedia.net/


diff -u orig/getpapersize /usr/pkgsrc/print/papersize/files/getpapersize
--- orig/getpapersize	Wed May  8 18:59:08 2002
+++ /usr/pkgsrc/print/papersize/files/getpapersize	Wed May  8 21:05:12 2002
@@ -6,7 +6,7 @@
 #

 if [ $# -eq 0 ]; then
-	pkgs="a2ps ddd enscript magicfilter psutils";
+	pkgs="a2ps ddd enscript ghostscript magicfilter psutils";
 else
 	pkgs=$@
 fi
@@ -33,6 +33,18 @@
 		if [ -e $f ]; then
 			echo -n "$1 has default papersize: "
 			awk '/^DefaultMedia:.*/ { gsub(".*:", "", $0); print $0; }' $f
+		fi
+		;;
+	ghostscript)
+		f=`ls @localbase@/share/ghostscript/*/lib/gs_init.ps 2>/dev/null | tail -1`
+		if [ -e $f ]; then
+			echo -n "$1 has default papersize: "
+			gssize=`sed -n -e '/^% Optionally choose a default paper size other than U.S. letter.$/N' -e 's/^% Optionally.*\n[[:space:]]*(\(.*\)) \/PAPERSIZE where.*$/\1/p' $f`
+			if [ -z "$gssize" ] ; then
+				echo "(unknown)"
+			else
+				echo $gssize
+			fi
 		fi
 		;;
 	magicfilter)
diff -u orig/getpapersize.1 /usr/pkgsrc/print/papersize/files/getpapersize.1
--- orig/getpapersize.1	Wed May  8 18:59:08 2002
+++ /usr/pkgsrc/print/papersize/files/getpapersize.1	Wed May  8 19:08:45 2002
@@ -12,8 +12,8 @@
 The
 .Nm
 utility shows the default paper size for a number of packages.
-At the present time, these are the a2ps, ddd, enscript, magicfilter
-and psutils packages.
+At the present time, these are the a2ps, ddd, enscript, ghostscript,
+magicfilter, and psutils packages.
 If no package argument is given, all packages are assumed.
 The
 .Xr setpapersize 1
diff -u orig/setpapersize /usr/pkgsrc/print/papersize/files/setpapersize
--- orig/setpapersize	Wed May  8 18:59:08 2002
+++ /usr/pkgsrc/print/papersize/files/setpapersize	Wed May  8 21:05:12 2002
@@ -37,7 +37,7 @@
 lowpaper=`echo $papersize | tr '[A-Z]' '[a-z]'`

 if [ $# -eq 0 ]; then
-	pkgs="a2ps ddd enscript magicfilter psutils";
+	pkgs="a2ps ddd enscript ghostscript magicfilter psutils";
 else
 	pkgs=$@
 fi
@@ -67,6 +67,14 @@
 			mv $enscriptfile $enscriptfile.old
 			sed -e 's|^DefaultMedia:.*|DefaultMedia: '$papersize'|' $enscriptfile.old > $enscriptfile && rm $enscriptfile.old
 			echo "Set $1 package default paper size to $papersize in $enscriptfile"
+		fi
+		;;
+	ghostscript)
+		ghostscriptfile=`ls @localbase@/share/ghostscript/*/lib/gs_init.ps 2>/dev/null | tail -1`
+		if [ -e $ghostscriptfile ]; then
+			mv $ghostscriptfile $ghostscriptfile.old
+			sed -e '/^% Optionally choose a default paper size other than U.S. letter.$/N' -e 's/^\(% Optionally.*\n\)[%[:space:]]*(.*\() \/PAPERSIZE where.*\)$/\1('$lowpaper'\2/' $ghostscriptfile.old > $ghostscriptfile && rm $ghostscriptfile.old
+			echo "Set $1 package default paper size to $papersize in $ghostscriptfile"
 		fi
 		;;
 	magicfilter)
diff -u orig/setpapersize.1 /usr/pkgsrc/print/papersize/files/setpapersize.1
--- orig/setpapersize.1	Wed May  8 18:59:08 2002
+++ /usr/pkgsrc/print/papersize/files/setpapersize.1	Wed May  8 19:08:45 2002
@@ -13,8 +13,8 @@
 The
 .Nm
 utility sets the default paper size for a number of packages.
-At the present time, these are the a2ps, ddd, enscript, magicfilter
-and psutils packages.
+At the present time, these are the a2ps, ddd, enscript, ghostscript,
+magicfilter and psutils packages.
 If no package argument is given, all packages are assumed.
 The
 .Ar PAPERSIZE