Attached is a patch to make pdfjam read /etc/papersize with the same effect
as explicit options --letterpaper --a4paper etc. The patch looks big because I had to relocate the error_exit() function higher up in the script so it could be called
by the new code (which is only a few lines).

Note - I can't include the patch in the body of this email because thunderbird sometimes
corrupts white space even in plain-text emails (ugh).

-Jim Avera

--- pdfjam.ORIG 2012-04-27 15:08:51.071415912 -0700
+++ pdfjam      2012-04-27 16:01:45.323560907 -0700
@@ -136,10 +136,36 @@
 ##
 #########################################################################
 ##
+##  ERROR CODES
+##
+E_USAGE=64           #  command line usage error
+E_DATAERR=65         #  data format error
+E_NOINPUT=66         #  cannot open input
+E_UNAVAILABLE=69     #  service unavailable
+E_SOFTWARE=70        #  internal software error
+E_CANTCREATE=73      #  can't create (user) output file
+E_CONFIG=78          #  configuration error
+##
+##  Define a function to print an error message and exit:
+##
+error_exit () {
+    if (test -r "$PDFJAM_MESSAGES_FILE")
+    then cat "$PDFJAM_MESSAGES_FILE" >&2
+    else printf "$messages" 1>&2
+    fi
+    printf "  pdfjam ERROR: %s\n" "$1" 1>&2 ;
+    exit "$2" ;
+}
+##
+#########################################################################
+##
 ##  CONFIGURATION
 ##
+##  First, the default paper size is read from /etc/papersize if it exists.
+##  Then pdfjam native config files.
+##
 ##  THESE SETTINGS WILL BE OVER-RIDDEN by any found in configuration
-##  files.  By default such files are found at any or all of
+##  files.  By default native config files are found at any or all of
 ##     /etc/pdfjam.conf
 ##     /usr/share/etc/pdfjam.conf
 ##     /usr/local/share/pdfjam.conf
@@ -148,7 +174,7 @@
 ##  (And they are read in that order; if a setting is made more than
 ##  once, the last one prevails.)
 ##
-##  An example configuration file can be found at
+##  An example native configuration file can be found at
 ##     http://go.warwick.ac.uk/pdfjam
 ##
 ##  The path searched for site-wide configuration files can be changed
@@ -204,11 +230,17 @@
 then
     if test "$PDFJAM_CALL_NUMBER" = 0   ## not a secondary call to pdfjam
     then
+       PDFJAM_CONFIG=""
+       prattle "Reading any site-wide or user-specific defaults..."
+       if test -s /etc/papersize ; then
+           change="paper=`cat /etc/papersize`paper" \
+             || error_exit "Can't read /etc/papersize" $E_UNAVAILABLE
+           comment="## From /etc/papersize:"
+           PDFJAM_CONFIG="$PDFJAM_CONFIG$comment$newline$change$newline"
+       fi
        configFiles=`printf "%s" "$configpath" | \
            sed 's/:/\/pdfjam.conf:/g; s/$/\/pdfjam.conf/'`
        configFiles="${configFiles}:$HOME/.pdfjam.conf"
-       PDFJAM_CONFIG=""
-       prattle "Reading any site-wide or user-specific defaults..."
        IFS=':'
        for d in $configFiles
        do
@@ -421,29 +453,6 @@
 ##
 #########################################################################
 ##
-##  ERROR CODES
-##
-E_USAGE=64           #  command line usage error
-E_DATAERR=65         #  data format error
-E_NOINPUT=66         #  cannot open input
-E_UNAVAILABLE=69     #  service unavailable
-E_SOFTWARE=70        #  internal software error
-E_CANTCREATE=73      #  can't create (user) output file
-E_CONFIG=78          #  configuration error
-##
-##  Define a function to print an error message and exit:
-##
-error_exit () {
-    if (test -r "$PDFJAM_MESSAGES_FILE")
-    then cat "$PDFJAM_MESSAGES_FILE" >&2
-    else printf "$messages" 1>&2
-    fi
-    printf "  pdfjam ERROR: %s\n" "$1" 1>&2 ;
-    exit "$2" ;
-}
-##
-#########################################################################
-##
 ##  READ AND PROCESS THE ARGUMENTS
 ##
 ##  In case of NO argument supplied, mention 'pdfjam --help':

Reply via email to