summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/epspdf/epspdfrc.rb
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/epspdf/epspdfrc.rb')
-rwxr-xr-xMaster/texmf-dist/scripts/epspdf/epspdfrc.rb217
1 files changed, 58 insertions, 159 deletions
diff --git a/Master/texmf-dist/scripts/epspdf/epspdfrc.rb b/Master/texmf-dist/scripts/epspdf/epspdfrc.rb
index 08bcfdb991a..06073749952 100755
--- a/Master/texmf-dist/scripts/epspdf/epspdfrc.rb
+++ b/Master/texmf-dist/scripts/epspdf/epspdfrc.rb
@@ -1,4 +1,4 @@
-EPVERSION = '0.4.3'
+EPVERSION = '0.5'
COPYRIGHT = '2006, 2008, 2009, 2010'
# epspdf conversion utility, configuration module
@@ -14,7 +14,7 @@ COPYRIGHT = '2006, 2008, 2009, 2010'
# Settings are stored in a settings hash, with some methods added
# for less unwieldy notation.
#
-# In phase 1, some programs (converters, viewers) are autodetected.
+# In phase 1, some programs (converters) are autodetected.
# In phase 2, user preferences are read from the epspdf configuration.
#
# For unix/osx, configuration info is stored in $HOME/.epspdfrc.
@@ -85,7 +85,7 @@ end
def shell_error_string ( e )
if e > 32
- returl nil
+ return nil
else
return case e
when 0 then "Out of memory or resources"
@@ -122,19 +122,22 @@ end # def
# system-dependent location of logfile
-LOGFILE = case ARCH
-when 'w32'
- "#{ENV['USERPROFILE']}\\epspdf.log"
-else
- "#{ENV['HOME']}/epspdf.log"
+epsdir = case ARCH
+ when 'w32'
+ "#{ENV['APPDATA'].gsub( /\\/, '/' )}/epspdf"
+ else
+ "#{ENV['HOME']}/.epspdf"
end
+Dir.mkdir( epsdir ) unless test( ?e, epsdir )
+# epsdir may be a regular file, or creation above may have failed
+fail("Cannot create directory #{epsdir}" ) if not test( ?d, epsdir )
+LOGFILE = "#{epsdir}/epspdf.log"
LOGFILE_OLD = LOGFILE + '.old'
+#puts LOGFILE
# system-dependent locations of saved settings
-RC_FILE = "#{ENV['HOME']}/.epspdfrc" # not used under Windows
-REG_K = 'epspdf'
-REG_KEY = 'SOFTWARE\\epspdf'
+RC_FILE = "#{epsdir}/config"
# hash of saved settings from rc file or registry
@@ -143,8 +146,7 @@ $rc_settings = {}
# test whether a string is a valid program call
# 'which' also works with explicit paths.
# 'which' returns an error for non-executable files.
-# Linux/Unix OS X: for testing existence of gs, pdftops and ps/pdf viewers
-# Mac OS X: for testing existence of gs and pdftops
+# Linux/Unix/OS X: for testing existence of gs and pdftops
# Windows: function not usable and not used
def is_a_program( s )
@@ -202,9 +204,8 @@ $settings = {
'gs_prog' => Setting.new( nil, 'auto', nil ),
#'gs_version' => Setting.new( nil, 'auto', nil ),
'pdftops_prog' => Setting.new( nil, ARCH=='w32' ? 'config' : 'auto', nil ),
- # epspdftk: viewers
- 'pdf_viewers' => Setting.new( nil, ARCH=='unix' ? 'auto' : nil, nil ),
- 'ps_viewers' => Setting.new( nil, ARCH=='unix' ? 'auto' : nil, nil ),
+ # epspdftk: viewers; epspdftk.tcl takes care of this,
+ # but their configuration is stored and retrieved by the Ruby scripts
'pdf_viewer' => Setting.new( nil, ARCH=='unix' ? 'config' : 'auto', nil ),
'ps_viewer' => Setting.new( nil, ARCH=='unix' ? 'config' : 'auto', nil ),
# epspdftk: initial dir
@@ -224,7 +225,7 @@ $settings = {
'Ignore hi-res boundingbox for pdf generation;' +
' 1=yes, empty or 0=no(default)' ),
'bb_spread' => Setting.new( '1', 'config',
- 'margin to be added to computed lores boundingbox; default 1' )
+ 'margin in points to be added to computed lores boundingbox; default 1' )
}
# Using pdftops or a hires boundingbox should be the norm, not the exception.
@@ -267,136 +268,60 @@ class << $settings
reverse_of( self['ignore_pdftops'].val )
end
- def accept_pdf_viewer( s )
- if ARCH == 'unix'
- if is_a_program( s )
- self.pdf_viewer = s
- self.pdf_viewers.unshift( s ) unless self.pdf_viewers.index( s )
- return 1
- else
- return nil
- end
- else
- return nil
- end
- end # accept_pdf_viewer
-
- def accept_ps_viewer( s )
- if ARCH == 'unix'
- if is_a_program( s )
- self.ps_viewer = s
- self.pdf_viewer = s unless \
- self.pdf_viewer and not self.pdf_viewer.empty?
- self.ps_viewers.unshift( s ) unless self.ps_viewers.index( s )
- self.pdf_viewers.push( s ) unless self.pdf_viewers.index( s )
- return 1
- else
- return nil
- end
- else
- return nil
- end
- end # accept_ps_viewer
-
# previously-configured settings into hash $rc_settings
# here no validity testing.
# we accept empty settings.
def read_settings
- if ARCH == 'w32'
- [Registry::HKEY_LOCAL_MACHINE,
- Registry::HKEY_CURRENT_USER].each { |hk|
- begin # open REG_KEY safely
- hk.open( REG_KEY ) do |ep|
- ep.each_value do |key, type, val|
- $rc_settings[ key ] = val \
- if $settings[ key ] and $settings[ key ].type == 'config'
- end # do |key, type, val|
- end # do |ep|
- rescue
- end # open REG_KEY safely
- } # each |hk|
- else
- if test( ?s, RC_FILE )
- lines = File.read( RC_FILE ).split( /\r\n?|\n/ )
- lines.each do |l|
- l = l.sub( /#.*$/, '' ) # remove trailing comments
- if l =~ /^\s*(\S+)\s*=\s*(\S(.*\S)?)\s*$/
- key, val = $1, $2
- $rc_settings[ key ] = val \
- if $settings[ key ] and $settings[ key ].type == 'config'
- elsif l =~ /^\s*(\S+)\s*=\s*$/
- key, val = $1, ''
- $rc_settings[ key ] = '' \
- if $settings[ key ] and $settings[ key ].type == 'config'
- end # if l =~
- end # do |l|
- end # if ?s
- end # if ARCH
+ if test( ?s, RC_FILE )
+ lines = File.read( RC_FILE ).split( /\r\n?|\n/ )
+ lines.each do |l|
+ l = l.sub( /#.*$/, '' ) # remove trailing comments
+ if l =~ /^\s*(\S+)\s*=\s*(\S(.*\S)?)\s*$/
+ key, val = $1, $2
+ $rc_settings[ key ] = val \
+ if $settings[ key ] and $settings[ key ].type == 'config'
+ elsif l =~ /^\s*(\S+)\s*=\s*$/
+ key, val = $1, ''
+ $rc_settings[ key ] = '' \
+ if $settings[ key ] and $settings[ key ].type == 'config'
+ end # if l =~
+ end # do |l|
+ end # if ?s
end # def
def write_settings
- if ARCH == 'w32'
- begin
- Registry::HKEY_CURRENT_USER.create(
- 'SOFTWARE', desired = Registry::KEY_ALL_ACCESS) do |reg|
- reg.create( REG_K, desired = Registry::KEY_ALL_ACCESS ) do |rk|
- $settings.each do |k, s|
- key = String.new( k )
- st = Setting.new( s.val, s.type, s.comment )
- # this copying looks kind of silly,
- # but prevents a 'modifying frozen object' error.
- if st.type == 'config'
- vl = st.val ? st.val : ''
- rk.write_s( key, vl )
- end
- end # do each
- end # do |rk|
- end # do |reg|
- rescue => er # no real error handling for now
- puts $!
- puts er.backtrace.join( $/ )
- puts 'Settings will be lost at next run'
- end
- else
- File.open( RC_FILE, 'w' ) do |f|
- f.write( "# This file will be overwritten by epspdf[tk][.rb]" \
- + $/ )
- $settings.each do |key, st|
- if st.type == 'config'
- f.write( $/ )
- f.write( '# ' + st.comment + $/ ) if st.comment
- # STDERR.puts "write setting for " + key
- # STDERR.flush
- f.write( key + " = " + ( st.val ? st.val : '' ) + $/ )
- end
- end # do |key, st|
- end # do |f|
- end # if
+ File.open( RC_FILE, 'w' ) do |f|
+ f.write( "# This file will be overwritten by epspdf.rb/epspdftk.tcl" \
+ + $/ )
+ $settings.each do |key, st|
+ if st.type == 'config'
+ f.write( $/ )
+ f.write( '# ' + st.comment + $/ ) if st.comment
+ # STDERR.puts "write setting for " + key
+ # STDERR.flush
+ f.write( key + " = " + ( st.val ? st.val : '' ) + $/ )
+ end
+ end # do |key, st|
+ end # do |f|
end # def
def get_settings
# phase 1: autodetect
- # w32: gs_prog, pdf_viewer, ps_viewer
+ # w32: gs_prog, pdftops_prog
# gs: search path; search registry settings (user and system);
# search tex installation. The first one wins.
- # viewers: check file type registry entry for valid open commands
- # unix: gs_prog, pdftops_prog, pdf_viewers, ps_viewers
+ # pdftops: search path
+ # unix: gs_prog, pdftops_prog
# osx: gs_prog, pdftops_prog
- # viewers: use Preview; don't check anything
- # unix/osx are done together, except that for osx
- # the viewers code is skipped.
+ # unix/osx are done together.
# Windows: test for TeX, because it may come with a hidden
# ghostscript. TeX may also come with pdftops.exe, but pdftops
# would then be on the searchpath and not require special treatment.
- # Later versions of Ghostscript come with several libraries built-in.
- # Hopefully, there is no harm in including too many directories
- # in GS_LIB. Better test this.
-
texbindir = ( ARCH == 'w32' ) ? find_on_path( 'tex' ) : nil
texbindir = short_name( File.dirname( texbindir ) ) if texbindir
@@ -483,28 +408,11 @@ class << $settings
when /unix|osx/
# gs
self.gs_prog = is_a_program( 'gs' ) ? 'gs' : nil
+ fail( "No ghostscript" ) unless self.gs_prog
# pdftops
self.pdftops_prog = is_a_program( 'pdftops' ) ? 'pdftops' : nil
- # viewers
- if ARCH == 'unix'
- vw = %w{ evince gpdf xpdf acroread epdfview gv gsview okular }
- vw.delete_if { |x| not is_a_program( x ) }
- vw = nil if vw.empty?
- self.pdf_viewers = vw
- self.pdf_viewer = vw ? vw[0] : nil
- if vw
- vw2 = vw.dup # copy the elements rather than the array ref
- [ 'gpdf', 'xpdf', 'acroread', 'epdfview' ].each { |pg|
- vw2.delete( pg ) if vw2.index( pg )
- }
- vw2 = nil if vw2.empty?
- self.ps_viewers = vw2
- self.ps_viewer = vw2 ? vw2[ 0 ] : nil
- end # if vw
- end # if unix
-
end # case ARCH
# built-in defaults already set during initialization of $settings
@@ -515,26 +423,17 @@ class << $settings
read_settings
- case ARCH
- when 'w32'
+ if ARCH == 'w32'
self.pdftops_prog = $rc_settings[ 'pdftops_prog' ] if
$rc_settings[ 'pdftops_prog' ] and
! $rc_settings[ 'pdftops_prog' ].empty? and
test( ?f, $rc_settings[ 'pdftops_prog' ] )
- when 'unix'
- if v = $rc_settings[ 'pdf_viewer' ] and is_a_program( v )
- self.pdf_viewer = v
- self.pdf_viewers.unshift( v ) unless self.pdf_viewers.index( v )
- end # if
- if v = $rc_settings[ 'ps_viewer' ] and is_a_program( v )
- self.ps_viewer = v
- self.ps_viewers.unshift( v ) unless self.ps_viewers.index( v )
- end # if
- if self.ps_viewers and not self.pdf_viewers
- self.pdf_viewers = self.ps_viewers.dup
- self.pdf_viewer = self.ps_viewer
- end # if
- end # case ARCH
+ end # ARCH == 'w32'
+
+ if ARCH == 'unix'
+ self.pdf_viewer = $rc_settings[ 'pdf_viewer' ] # no checks here
+ self.ps_viewer = $rc_settings[ 'ps_viewer' ]
+ end
if ( $rc_settings[ 'defaultDir' ] and
( not $rc_settings[ 'defaultDir' ].strip.empty? ) and