diff options
Diffstat (limited to 'Master/texmf-dist/scripts/context/ruby/base/kpse.rb')
-rw-r--r-- | Master/texmf-dist/scripts/context/ruby/base/kpse.rb | 93 |
1 files changed, 73 insertions, 20 deletions
diff --git a/Master/texmf-dist/scripts/context/ruby/base/kpse.rb b/Master/texmf-dist/scripts/context/ruby/base/kpse.rb index dc4898ffc58..b0321672fc1 100644 --- a/Master/texmf-dist/scripts/context/ruby/base/kpse.rb +++ b/Master/texmf-dist/scripts/context/ruby/base/kpse.rb @@ -18,6 +18,26 @@ require 'rbconfig' # # miktex has mem|fmt|base paths +class String + + def split_path + if self =~ /\;/o || self =~ /^[a-z]\:/io then + self.split(";") + else + self.split(":") + end + end + +end + +class Array + + def join_path + self.join(File::PATH_SEPARATOR) + end + +end + module Kpse @@located = Hash.new @@ -32,11 +52,21 @@ module Kpse @@crossover = true @@mswindows = Config::CONFIG['host_os'] =~ /mswin/ - @@distribution = 'miktex' if ENV['PATH'] =~ /miktex[\\\/]bin/o + # @@distribution = 'miktex' if ENV['PATH'] =~ /miktex[\\\/]bin/o - @@usekpserunner = false || ENV['KPSEFAST'] == 'yes' + if ENV['PATH'] =~ /(.*?)miktex[\\\/]bin/i then + @@distribution = 'miktex' unless $1 =~ /(texmf\-mswin[\/\\]bin|bin[\/\\]win32)/i + end + + @@re_true = /yes|on|true|1/i - require 'base/tool' if @@usekpserunner + if (ENV['KPSEFAST'] =~ @@re_true) || (ENV['CTXMINIMAL'] =~ @@re_true) then + @@usekpserunner = true + require 'base/kpsefast' + require 'base/kpserunner' + else + @@usekpserunner = false + end if @@crossover then ENV.keys.each do |k| @@ -113,12 +143,10 @@ module Kpse begin if @@problems then results = '' + elsif @@usekpserunner then + results = KpseRunner.kpsewhich(arguments).chomp else - if @@usekpserunner then - results = KpseRunner.kpsewhich(arguments).chomp - else - results = `kpsewhich #{arguments}`.chomp - end + results = `kpsewhich #{arguments}`.chomp end rescue puts "unable to run kpsewhich" if @@tracing @@ -132,7 +160,7 @@ module Kpse # maybe we should check for writeability unless @@paths.key?('formatpaths') then begin - setpath('formatpaths',run("--show-path=fmt").gsub(/\\/,'/').split(File::PATH_SEPARATOR)) + setpath('formatpaths',run("--show-path=fmt").gsub(/\\/,'/').split_path) rescue setpath('formatpaths',[]) end @@ -189,30 +217,51 @@ module Kpse end # locate writable path if ! formatpath.empty? then - formatpath.split(File::PATH_SEPARATOR).each do |fp| - fp.gsub!(/\\/,'/') + formatpaths, done = formatpath.split_path, false + formatpaths.collect! do |fp| + fp.gsub!(/\\/o,'/') + fp.gsub!(/\/\/$/o,'/') # remove funny patterns - fp.sub!(/^!!/,'') - fp.sub!(/\/+$/,'') - fp.sub!(/unsetengine/,if enginepath then engine else '' end) - if ! fp.empty? && (fp != '.') then - # strip (possible engine) and test for writeability - fpp = fp.sub(/#{engine}\/*$/,'') + fp.sub!(/^!!/o,'') + fp.sub!(/\/+$/o,'') + fp.sub!(/(unsetengine|unset)/o,if enginepath then engine else '' end) + fp + end + formatpaths.delete_if do |fp| + fp.empty? || fp == '.' + end + # the engine path may not yet be present, find first writable + formatpaths.each do |fp| + # strip (possible engine) and test for writeability + fpp = fp.sub(/#{engine}\/*$/o,'') + if FileTest.directory?(fpp) && FileTest.writable?(fpp) then + # use this path + formatpath, done = fp.dup, true + break + end + end + unless done then + formatpaths.each do |fp| + fpp = fp.sub(/#{engine}\/*$/o,'') + File.makedirs(fpp) rescue false # maybe we don't have an path yet if FileTest.directory?(fpp) && FileTest.writable?(fpp) then # use this path - formatpath = fp.dup + formatpath, done = fp.dup, true break end end end + unless done then + formatpath = '.' + end end # needed ! - begin File.makedirs(formatpath) ; rescue ; end ; + File.makedirs(formatpath) rescue false # fall back to current path formatpath = '.' if formatpath.empty? || ! FileTest.writable?(formatpath) # append engine but prevent duplicates formatpath = File.join(formatpath.sub(/\/*#{engine}\/*$/,''), engine) if enginepath - begin File.makedirs(formatpath) ; rescue ; end ; + File.makedirs(formatpath) rescue false setpath(engine,formatpath) # ENV['engine'] = savedengine end @@ -283,6 +332,10 @@ module Kpse `#{cmd}` end + def Kpse.searchmethod + if @@usekpserunner then 'kpsefast' else 'kpsewhich' end + end + private def Kpse.setvariable(key,value) |