summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2005-08-19 00:00:00 +0200
committerHans Hagen <pragma@wxs.nl>2005-08-19 00:00:00 +0200
commit762d1d411dbef0c303d28c3c2db2df4065648747 (patch)
treeff26a98539a470fba370715f71008fc22b5375f1 /scripts
parentf8482bca2d7d031de38b8c751aadf5e2523f1a52 (diff)
downloadcontext-762d1d411dbef0c303d28c3c2db2df4065648747.tar.gz
stable 2005.08.19
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/ruby/base/kpse.rb38
-rw-r--r--scripts/context/ruby/base/kpsefast.rb107
-rw-r--r--scripts/context/ruby/base/texutil.rb32
-rw-r--r--scripts/context/ruby/ctxtools.rb9
4 files changed, 151 insertions, 35 deletions
diff --git a/scripts/context/ruby/base/kpse.rb b/scripts/context/ruby/base/kpse.rb
index 3c3cc21df..dc4898ffc 100644
--- a/scripts/context/ruby/base/kpse.rb
+++ b/scripts/context/ruby/base/kpse.rb
@@ -20,19 +20,23 @@ require 'rbconfig'
module Kpse
- @@located = Hash.new
- @@paths = Hash.new
- @@scripts = Hash.new
- @@formats = ['tex','texmfscripts','other text files']
- @@progname = 'context'
- @@ownpath = $0.sub(/[\\\/][a-z0-9\-]*?\.rb/i,'')
- @@problems = false
- @@tracing = false
- @@distribution = 'web2c'
- @@crossover = true
- @@mswindows = Config::CONFIG['host_os'] =~ /mswin/
-
- @@distribution = 'miktex' if ENV['PATH'] =~ /miktex[\\\/]bin/o
+ @@located = Hash.new
+ @@paths = Hash.new
+ @@scripts = Hash.new
+ @@formats = ['tex','texmfscripts','other text files']
+ @@progname = 'context'
+ @@ownpath = $0.sub(/[\\\/][a-z0-9\-]*?\.rb/i,'')
+ @@problems = false
+ @@tracing = false
+ @@distribution = 'web2c'
+ @@crossover = true
+ @@mswindows = Config::CONFIG['host_os'] =~ /mswin/
+
+ @@distribution = 'miktex' if ENV['PATH'] =~ /miktex[\\\/]bin/o
+
+ @@usekpserunner = false || ENV['KPSEFAST'] == 'yes'
+
+ require 'base/tool' if @@usekpserunner
if @@crossover then
ENV.keys.each do |k|
@@ -101,7 +105,7 @@ module Kpse
end
def Kpse.which
- Kpse.Kpsewhich
+ Kpse.kpsewhich
end
def Kpse.run(arguments)
@@ -110,7 +114,11 @@ module Kpse
if @@problems then
results = ''
else
- results = `kpsewhich #{arguments}`.chomp
+ if @@usekpserunner then
+ results = KpseRunner.kpsewhich(arguments).chomp
+ else
+ results = `kpsewhich #{arguments}`.chomp
+ end
end
rescue
puts "unable to run kpsewhich" if @@tracing
diff --git a/scripts/context/ruby/base/kpsefast.rb b/scripts/context/ruby/base/kpsefast.rb
index a519a6be6..e0204cf13 100644
--- a/scripts/context/ruby/base/kpsefast.rb
+++ b/scripts/context/ruby/base/kpsefast.rb
@@ -180,6 +180,7 @@ class KPSEFAST
@found = Hash.new
@kpsevars = Hash.new
@lsrfiles = Array.new
+ @cnffiles = Array.new
@verbose = true
@remember = true
@scandisk = true
@@ -192,7 +193,21 @@ class KPSEFAST
@cachefile = 'tmftools.log'
end
+ # {$SELFAUTOLOC,$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,}/web2c}
+ #
+ # $SELFAUTOLOC : /usr/tex/bin/platform
+ # $SELFAUTODIR : /usr/tex/bin
+ # $SELFAUTOPARENT : /usr/tex
+ #
+ # since we live in scriptpath we need a slightly different method
+
def load_cnf
+ ownpath = File.expand_path($0)
+ if ownpath.gsub!(/texmf.*?$/o, '') then
+ ENV['SELFAUTOPARENT'] = ownpath
+ else
+ ENV['SELFAUTOPARENT'] = '.'
+ end
unless @treepath.empty? then
unless @rootpath.empty? then
@treepath = @treepath.split(',').collect do |p| File.join(@rootpath,p) end.join(',')
@@ -205,7 +220,16 @@ class KPSEFAST
ENV['SELFAUTOPARENT'] = @rootpath
@isolate = true
end
- filenames = [File.join(ENV['TEXMFCNF'] || '.','texmf.cnf')]
+ filenames = Array.new
+ if ENV['TEXMFCNF'] and not ENV['TEXMFCNF'].empty? then
+ filenames << File.join(ENV['TEXMFCNF'],'texmf.cnf')
+ elsif ENV['SELFAUTOPARENT'] == '.' then
+ filenames << File.join('.','texmf.cnf')
+ else
+ ['texmf-local','texmf'].each do |tree|
+ filenames << File.join(ENV['SELFAUTOPARENT'],tree,'web2c','texmf.cnf')
+ end
+ end
# <root>/texmf/web2c/texmf.cnf
@rootpath = filenames.first
3.times do
@@ -216,6 +240,7 @@ class KPSEFAST
end
filenames.each do |fname|
if FileTest.file?(fname) and f = File.open(fname) then
+ @cnffiles << fname
while line = f.gets do
loop do
# concatenate lines ending with \
@@ -659,9 +684,10 @@ class KPSEFAST
end
def analyze_files(filter='',strict=false,sort='',delete=false)
- puts("command = #{ARGV.join(' ')}")
- puts("files = #{@files.size}")
- puts("filter = #{filter}")
+ puts("command line = #{ARGV.join(' ')}")
+ puts("number of files = #{@files.size}")
+ puts("filter pattern = #{filter}")
+ puts("loaded cnf files = #{@cnffiles.join(' ')}")
puts('')
if filter.gsub!(/^not:/,'') then
def the_same(filter,filename)
@@ -737,6 +763,79 @@ class KPSEFAST
end
+module KpseRunner
+
+ @@kpse = nil
+
+ def KpseRunner.kpsewhich(arg='')
+ options, arguments = split_args(arg)
+ unless @@kpse then
+ @@kpse = KPSEFAST.new
+ @@kpse.load_cnf
+ @@kpse.progname = options['progname'] || ''
+ @@kpse.engine = options['engine'] || ''
+ @@kpse.format = options['format'] || ''
+ @@kpse.expand_variables
+ @@kpse.load_lsr
+ else
+ @@kpse.progname = options['progname'] || ''
+ @@kpse.engine = options['engine'] || ''
+ @@kpse.format = options['format'] || ''
+ @@kpse.expand_variables
+ end
+ if option = options['expand-braces'] and not option.empty? then
+ @@kpse.expand_braces(option)
+ elsif option = options['expand-path'] and not option.empty? then
+ @@kpse.expand_path(option)
+ elsif option = options['expand-var'] and not option.empty? then
+ @@kpse.expand_var(option)
+ elsif option = options['show-path'] and not option.empty? then
+ @@kpse.show_path(option)
+ elsif option = options['var-value'] and not option.empty? then
+ @@kpse.expand_var(option)
+ elsif arguments.size > 0 then
+ files = Array.new
+ arguments.each do |option|
+ if file = @@kpse.find_file(option) and not file.empty? then
+ files << file
+ end
+ end
+ files.join("\n")
+ else
+ ''
+ end
+ end
+
+ def KpseRunner.kpsereset
+ @@kpse = nil
+ end
+
+ private
+
+ def KpseRunner.split_args(arg)
+ vars, args = Hash.new, Array.new
+ arg.gsub!(/([\"\'])(.*?)\1/o) do
+ $2.gsub(' ','<space/>')
+ end
+ arg = arg.split(/\s+/o)
+ arg.collect! do |a|
+ a.gsub('<space/>',' ')
+ end
+ arg.each do |a|
+ if a =~ /^(.*?)\=(.*?)$/o then
+ k, v = $1, $2
+ vars[k.sub(/^\-+/,'')] = v
+ else
+ args << a
+ end
+ end
+ # puts vars.inspect
+ # puts args.inspect
+ return vars, args
+ end
+
+end
+
if false then
k = KPSEFAST.new # (root)
diff --git a/scripts/context/ruby/base/texutil.rb b/scripts/context/ruby/base/texutil.rb
index 47c613474..c279bcc97 100644
--- a/scripts/context/ruby/base/texutil.rb
+++ b/scripts/context/ruby/base/texutil.rb
@@ -172,10 +172,14 @@ class TeXUtil
end
def prepare
- @rexa = /(#{@rep.keys.join('|')})/o
+ if @rep.size > 0 then
+ @rexa = /(#{@rep.keys.join('|')})/ # o
+ else
+ @rexa = nil
+ end
if @map.size > 0 then
# watch out, order of match matters
- @rexb = /(\\[a-zA-Z]+|#{@map.keys.join('|')}|.)\s*/o
+ @rexb = /(\\[a-zA-Z]+|#{@map.keys.join('|')}|.)\s*/ # o
else
@rexb = /(\\[a-zA-Z]+|.)\s*/o
end
@@ -186,17 +190,21 @@ class TeXUtil
s.gsub!(/(\d+)/o) do
$1.rjust(10,'a') # rest is b .. k
end
- s.gsub!(@rexa) do
- @rep[$1.escaped]
+ if @rexa then
+ s.gsub!(@rexa) do
+ @rep[$1.escaped]
+ end
end
- s.gsub!(@rexb) do
- token = $1.sub(/\\/o, '')
- if @exp.key?(token) then
- @exp[token].ljust(@max,' ')
- elsif @map.key?(token) then
- @map[token].ljust(@max,' ')
- else
- ''
+ if @rexb then
+ s.gsub!(@rexb) do
+ token = $1.sub(/\\/o, '')
+ if @exp.key?(token) then
+ @exp[token].ljust(@max,' ')
+ elsif @map.key?(token) then
+ @map[token].ljust(@max,' ')
+ else
+ ''
+ end
end
end
s
diff --git a/scripts/context/ruby/ctxtools.rb b/scripts/context/ruby/ctxtools.rb
index 44bf85b5b..75720d8b8 100644
--- a/scripts/context/ruby/ctxtools.rb
+++ b/scripts/context/ruby/ctxtools.rb
@@ -1251,12 +1251,13 @@ class Commands
if line =~ /^[\%\#]+/mo then
''
else
- encoding = if line =~ /([a-z0-9\-]+)\.enc/io then $1 else '' end
- fontfile = if line =~ /([a-z0-9\-]+)\.(pfb|ttf)/io then $1 else nil end
- metrics = if line =~ /^([a-z0-9\-]+)[\s\<]+/io then $1 else nil end
+ encoding = if line =~ /([a-z0-9\-]+)\.enc/io then $1 else '' end
+ fontfile = if line =~ /([a-z0-9\-]+)\.(pfb|ttf)/io then $1 else nil end
+ metrics = if line =~ /^([a-z0-9\-]+)[\s\<]+/io then $1 else nil end
+ slant = if line =~ /\"([\d\.]+)\s+SlantFont\"/io then "-s #{$1}" else '' end
if metrics && encoding && fontfile then
n += 1
- "#{metrics} #{encoding} #{fontfile}"
+ "#{metrics} #{encoding} #{fontfile} #{slant}"
else
''
end