From dfbbcbbdb6e3a3681b7c853ac5e213c1933b385c Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Mon, 20 Mar 2006 10:19:00 +0100 Subject: stable 2006.03.20 10:19 --- scripts/context/perl/texutil.pl | 28 +- scripts/context/ruby/base/kpse.rb | 9 +- scripts/context/ruby/base/kpsedirect.rb | 30 +++ scripts/context/ruby/base/kpsefast.rb | 436 ++++++++++++++++---------------- scripts/context/ruby/base/kpseremote.rb | 104 ++++++++ scripts/context/ruby/base/kpserunner.rb | 87 +++++++ scripts/context/ruby/base/switch.rb | 24 +- scripts/context/ruby/base/system.rb | 2 +- scripts/context/ruby/base/tex.rb | 117 +++++---- scripts/context/ruby/base/texutil.rb | 5 +- scripts/context/ruby/base/variables.rb | 87 +++++++ scripts/context/ruby/ctxtools.rb | 391 ++++++++++++++++++++++++++-- scripts/context/ruby/newtexexec.rb | 2 +- scripts/context/ruby/runtools.rb | 2 +- scripts/context/ruby/texmfstart.rb | 283 ++++++++++++++------- scripts/context/ruby/tmftools.rb | 61 ++++- 16 files changed, 1255 insertions(+), 413 deletions(-) create mode 100644 scripts/context/ruby/base/kpsedirect.rb create mode 100644 scripts/context/ruby/base/kpseremote.rb create mode 100644 scripts/context/ruby/base/kpserunner.rb (limited to 'scripts') diff --git a/scripts/context/perl/texutil.pl b/scripts/context/perl/texutil.pl index 0a0d29753..a20a7f6aa 100644 --- a/scripts/context/perl/texutil.pl +++ b/scripts/context/perl/texutil.pl @@ -44,7 +44,7 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $ #D binary version, like scanning illustrations other than \EPS. #D I would suggest to keep an eye on the version number: -$Program = "TeXUtil 9.0.0 - ConTeXt / PRAGMA ADE 1992-2004" ; +$Program = "TeXUtil 9.0.1 - ConTeXt / PRAGMA ADE 1992-2006" ; #D By the way, this is my first \PERL\ script, which means #D that it will be improved as soon as I find new and/or more @@ -54,6 +54,11 @@ $Program = "TeXUtil 9.0.0 - ConTeXt / PRAGMA ADE 1992-2004" ; #D users in english as well as some other languages. One can #D set his favourite language by saying something like: +#D This one has a real old date, 1992. This is because it is +#D a converted modula program that was used in the very early +#D days of our \TEX\ history (macros for proper inclusion of +#D graphics were among the first thatwe wrote). + #D \starttypen #D perl texutil.pl --int=de --fig *.eps *.tif *.pdf *.png *.jpg #D \stoptypen @@ -823,7 +828,7 @@ sub InitializeKeys { my $filename = $ARGV[0] ; return unless (open(TEX,"$filename.tex")) ; for ($i=0;$i<=255;$i++) - { @Filter[$i] = $i } + { $Filter[$i] = $i } if ($TcXPath eq '') { foreach (@paths) { my $p = checked_path($_) . 'kpsewhich' ; @@ -848,7 +853,7 @@ sub InitializeKeys { Report ("LoadedFilter", $Translation) ; while () { if (/^(\d+)\s*(\d+)/) - { @Filter[$2] = $1 } } + { $Filter[$2] = $1 } } close (ASC) } elsif ($TcXPath ne '') { Report ("WrongFilterPath", $TcXPath) } @@ -861,7 +866,7 @@ sub HandleKey { ++$SortN ; $RestOfLine =~ s/\{(.*)\}/$1/o ; my ($lan, $enc, $str, $chr, $map, $alf) = split(/\}\s*\{/, $RestOfLine) ; - if ($str =~ /^(\d+)/) { $str = ''.chr(@Filter[$1]) } + if ($str =~ /^(\d+)/) { $str = ''.chr($Filter[$1]) } $map = chr(ord($MAP[$i])+128) ; $STR[$SortN] = $str ; $CHR[$SortN] = $chr ; @@ -1279,8 +1284,8 @@ sub HandleRegister # the } { makes sure that local {} is ok # if ($Key eq "") { $Key = SanitizedString($Entry) } - if ($SortMethod ne '') - { $ProcessHigh = 0 } + # if ($SortMethod ne '') + # { $ProcessHigh = 0 } if ($ProcessHigh) { $Key = HighConverted($Key) } $KeyTag = substr $Key, 0, 1 ; @@ -2075,7 +2080,7 @@ sub SaveFigurePresets { $Figures[$NOfFigures] .= ",t=\{$FTit\}" } if ($FCre) { $Figures[$NOfFigures] .= ",c=\{$FCre\}" } - $Figures[$NOfFigures] .= ",s=$FSiz]\n" } } + $Figures[$NOfFigures] .= ",s=$FSiz]" } } #D The \EPS\ to \PDF\ conversion pipe to \GHOSTSCRIPT\ is #D inspired by a script posted by Sebastian Ratz at the @@ -2580,8 +2585,10 @@ sub FlushFigures open ( TUF, ">$OutputFile" ) ; print TUF "%\n" . "% $Program / Figures\n" . "%\n" ; print TUF "\\thisisfigureversion\{1996.06.01\}\n" . "%\n" ; + # a joins is nicer for ($n=1 ; $n<=$NOfFigures ; ++$n) - { print TUF $Figures[$n] } + { print TUF "$Figures[$n]%\n" } + print TUF "\\endinput"; close (TUF) ; if ($NOfFigures) { Report("OutputFile", $OutputFile ) } @@ -2772,7 +2779,9 @@ if ($PurgeAllFiles) { push @forsuresuffixes, @texnonesuffixes ; @texnonesuffixes = [] } sub PurgeFiles # no my in foreach - { my $pattern = $ARGV[0] ; my $strippedname, $basename ; + { my $pattern = $ARGV[0] ; + my $strippedname ; + my $basename ; my @files = () ; if ($pattern eq '') { $pattern = "*.*" ; @@ -2895,7 +2904,6 @@ elsif ($PurgeFiles ) { PurgeFiles } elsif ($PurgeAllFiles ) { PurgeFiles } elsif ($AnalyzeFile ) { AnalyzeFile } elsif ($FilterPages ) { FilterPages } -elsif ($SciteApi ) { GenerateSciteApi } elsif ($ProcessHelp ) { ShowHelpInfo } # redundant else { ShowHelpInfo } diff --git a/scripts/context/ruby/base/kpse.rb b/scripts/context/ruby/base/kpse.rb index adeaacbe1..d05600b8f 100644 --- a/scripts/context/ruby/base/kpse.rb +++ b/scripts/context/ruby/base/kpse.rb @@ -43,6 +43,7 @@ module Kpse else @@usekpserunner = true require 'base/kpsefast' + require 'base/kpserunner' end if @@crossover then @@ -120,12 +121,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 diff --git a/scripts/context/ruby/base/kpsedirect.rb b/scripts/context/ruby/base/kpsedirect.rb new file mode 100644 index 000000000..d38e892b1 --- /dev/null +++ b/scripts/context/ruby/base/kpsedirect.rb @@ -0,0 +1,30 @@ +class KpseDirect + + attr_accessor :progname, :format, :engine + + def initialize + @progname = '' + @format = '' + @engine = '' + end + + def expand_path(str) + `kpsewhich -expand-path=#{str}`.chomp + end + + def expand_var(str) + `kpsewhich -expand-var=#{str}`.chomp + end + + def find_file(str) + `kpsewhich #{_progname_} #{_format_} #{str}`.chomp + end + + def _progname_ + if @progname.empty? then '' else "-progname=#{@progname}" end + end + def _format_ + if @format.empty? then '' else "-format=\"#{@format}\"" end + end + +end diff --git a/scripts/context/ruby/base/kpsefast.rb b/scripts/context/ruby/base/kpsefast.rb index 52ab28d0f..231c6221c 100644 --- a/scripts/context/ruby/base/kpsefast.rb +++ b/scripts/context/ruby/base/kpsefast.rb @@ -37,7 +37,49 @@ class File end -class KPSEFAST +module KpseUtil + + @@texmfcnf = 'texmf.cnf' + + def KpseUtil::identify + ownpath = File.expand_path($0) + if ownpath.gsub!(/texmf.*?$/o, '') then + ENV['SELFAUTOPARENT'] = ownpath + else + ENV['SELFAUTOPARENT'] = '.' + end + filenames = Array.new + if ENV['TEXMFCNF'] and not ENV['TEXMFCNF'].empty? then + ENV['TEXMFCNF'].split(File::PATH_SEPARATOR).each do |path| + filenames << File.join(path,@@texmfcnf) + end + elsif ENV['SELFAUTOPARENT'] == '.' then + filenames << File.join('.',@@texmfcnf) + else + ['texmf-local','texmf'].each do |tree| + filenames << File.join(ENV['SELFAUTOPARENT'],tree,'web2c',@@texmfcnf) + end + end + loop do + busy = false + filenames.collect! do |f| + f.gsub(/\$([a-zA-Z0-9\_\-]*)/o) do + busy = true + ENV[$1] || ("$#{$1}") + end + end + break unless busy + end + return filenames + end + + def KpseUtil::environment + Hash.new.merge(ENV) + end + +end + +class KpseFast # formats are an incredible inconsistent mess @@ -45,6 +87,8 @@ class KPSEFAST @@formats = Hash.new @@suffixmap = Hash.new + @@texmfcnf = 'texmf.cnf' + @@suffixes['gf'] = ['.gf'] # todo @@suffixes['pk'] = ['.pk'] # todo @@suffixes['tfm'] = ['.tfm'] @@ -121,7 +165,7 @@ class KPSEFAST @@formats['bst'] = '' @@formats['cnf'] = '' @@formats['ls-R'] = '' - @@formats['fmt'] = '' + @@formats['fmt'] = 'TEXFORMATS' @@formats['map'] = 'TEXFONTMAPS' @@formats['mem'] = 'MPMEMS' @@formats['mf'] = 'MFINPUTS' @@ -170,27 +214,41 @@ class KPSEFAST @@cacheversion = '1' def initialize - @rootpath = '' - @treepath = '' - @progname = 'kpsewhich' - @engine = 'pdfetex' - @variables = Hash.new - @expansions = Hash.new - @files = Hash.new - @found = Hash.new - @kpsevars = Hash.new - @lsrfiles = Array.new - @cnffiles = Array.new - @verbose = true - @remember = true - @scandisk = true - @diskcache = true - @renewcache = false - @isolate = false - - @diskcache = false - @cachepath = nil - @cachefile = 'tmftools.log' + @rootpath = '' + @treepath = '' + @progname = 'kpsewhich' + @engine = 'pdfetex' + @variables = Hash.new + @expansions = Hash.new + @files = Hash.new + @found = Hash.new + @kpsevars = Hash.new + @lsrfiles = Array.new + @cnffiles = Array.new + @verbose = true + @remember = true + @scandisk = true + @diskcache = true + @renewcache = false + @isolate = false + + @diskcache = false + @cachepath = nil + @cachefile = 'tmftools.log' + + @environment = ENV + end + + def set(key,value) + case key + when 'progname' then @progname = value + when 'engine' then @engine = value + when 'format' then @format = value + end + end + + def push_environment(env) + @environment = env end # {$SELFAUTOLOC,$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,}/web2c} @@ -201,36 +259,41 @@ class KPSEFAST # # 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 + def load_cnf(filenames=nil) + unless filenames then + ownpath = File.expand_path($0) + if ownpath.gsub!(/texmf.*?$/o, '') then + @environment['SELFAUTOPARENT'] = ownpath + else + @environment['SELFAUTOPARENT'] = '.' + end + unless @treepath.empty? then + unless @rootpath.empty? then + @treepath = @treepath.split(',').collect do |p| File.join(@rootpath,p) end.join(',') + end + @environment['TEXMF'] = @treepath + @environment['TEXMFCNF'] = File.join(@treepath.split(',').first,'texmf/web2c') + end unless @rootpath.empty? then - @treepath = @treepath.split(',').collect do |p| File.join(@rootpath,p) end.join(',') + @environment['TEXMFCNF'] = File.join(@rootpath,'texmf/web2c') + @environment['SELFAUTOPARENT'] = @rootpath + @isolate = true end - ENV['TEXMF'] = @treepath - ENV['TEXMFCNF'] = File.join(@treepath.split(',').first,'texmf/web2c') - end - unless @rootpath.empty? then - ENV['TEXMFCNF'] = File.join(@rootpath,'texmf/web2c') - ENV['SELFAUTOPARENT'] = @rootpath - @isolate = true - end - 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') + filenames = Array.new + if @environment['TEXMFCNF'] and not @environment['TEXMFCNF'].empty? then + @environment['TEXMFCNF'].split(File::PATH_SEPARATOR).each do |path| + filenames << File.join(path,@@texmfcnf) + end + elsif @environment['SELFAUTOPARENT'] == '.' then + filenames << File.join('.',@@texmfcnf) + else + ['texmf-local','texmf'].each do |tree| + filenames << File.join(@environment['SELFAUTOPARENT'],tree,'web2c',@@texmfcnf) + end end end # /texmf/web2c/texmf.cnf + filenames = _expanded_path_(filenames) @rootpath = filenames.first 3.times do @rootpath = File.dirname(@rootpath) @@ -280,9 +343,9 @@ class KPSEFAST @files = Hash.new if @diskcache then ['HOME','TEMP','TMP','TMPDIR'].each do |key| - if ENV[key] then - if FileTest.directory?(ENV[key]) then - @cachepath = ENV[key] + if @environment[key] then + if FileTest.directory?(@environment[key]) then + @cachepath = @environment[key] @cachefile = [@rootpath.gsub(/[^A-Z0-9]/io, '-').gsub(/\-+/,'-'),File.basename(@cachefile)].join('-') break end @@ -342,14 +405,14 @@ class KPSEFAST def expand_variables @expansions = Hash.new if @isolate then - @variables['TEXMFCNF'] = ENV['TEXMFCNF'].dup - @variables['SELFAUTOPARENT'] = ENV['SELFAUTOPARENT'].dup + @variables['TEXMFCNF'] = @environment['TEXMFCNF'].dup + @variables['SELFAUTOPARENT'] = @environment['SELFAUTOPARENT'].dup else - ENV.keys.each do |e| + @environment.keys.each do |e| if e =~ /^([a-zA-Z]+)\_(.*)\s*$/o then - @expansions["#{$1}.#{$2}"] = ENV[e].dup + @expansions["#{$1}.#{$2}"] = (@environment[e] ||'').dup else - @expansions[e] = ENV[e].dup + @expansions[e] = (@environment[e] ||'').dup end end end @@ -465,7 +528,8 @@ class KPSEFAST end end pathlist = pathlist.uniq.collect do |path| - p = path.gsub(/^\/+/o) do '' end + p = path + # p.gsub(/^\/+/o) do '' end # p.gsub!(/(.)\/\/(.)/o) do "#{$1}/#{$2}" end # p.gsub!(/\/\/+$/o) do '//' end p.gsub!(/\/\/+/o) do '//' end @@ -485,8 +549,8 @@ class KPSEFAST end def var_of_format_or_suffix(str) - if @@formats.key?(@format) then - @@formats[@format] + if @@formats.key?(str) then + @@formats[str] elsif @@suffixmap.key?(File.extname(str)) then # extname includes . @@formats[@@suffixmap[File.extname(str)]] # extname includes . else @@ -496,7 +560,7 @@ class KPSEFAST end -class KPSEFAST +class KpseFast # test things @@ -543,7 +607,7 @@ class KPSEFAST end -class KPSEFAST +class KpseFast # kpse stuff @@ -560,7 +624,8 @@ class KPSEFAST end def show_path(str) # output search path for file type NAME - expanded_path(var_of_format(str)).join(File::PATH_SEPARATOR) + # expanded_path(var_of_format(str)).join(File::PATH_SEPARATOR) + expanded_path(str).join(File::PATH_SEPARATOR) end def var_value(str) # output the value of variable $STRING. @@ -569,97 +634,117 @@ class KPSEFAST end -class KPSEFAST +class KpseFast + + def _is_cnf_?(filename) + filename == File.basename((@cnffiles.first rescue @@texmfcnf)) + end def find_file(filename) - find_files(filename,true) + if _is_cnf_?(filename) then + @cnffiles.first rescue '' + else + [find_files(filename,true)].flatten.first || '' + end end def find_files(filename,first=false) - if @remember then - stamp = "#{filename}--#{@format}--#{@engine}--#{@progname}" - return @found[stamp] if @found.key?(stamp) - end - pathlist = expanded_path(filename) - result = [] - filelist = if @files.key?(filename) then @files[filename].uniq else nil end - done = false - pathlist.each do |path| - doscan = if path =~ /^\!\!/o then false else true end - recurse = if path =~ /\/\/$/o then true else false end - pathname = path.dup - pathname.gsub!(/^\!+/o, '') + if _is_cnf_?(filename) then + result = @cnffiles.dup + else + if @remember then + # stamp = "#{filename}--#{@format}--#{@engine}--#{@progname}" + stamp = "#{filename}--#{@engine}--#{@progname}" + return @found[stamp] if @found.key?(stamp) + end + pathlist = expanded_path(filename) + result = [] + filelist = if @files.key?(filename) then @files[filename].uniq else nil end done = false - if not done and filelist then - # checking for exact match - if filelist.include?(pathname) then - result << pathname + if pathlist.size == 0 then + if FileTest.file?(filename) then done = true + result << '.' end - if not done and recurse then - # checking for fuzzy // - pathname.gsub!(/\/+$/o, '/.*') - # pathname.gsub!(/\/\//o,'/[\/]*/') - pathname.gsub!(/\/\//o,'/.*?/') - re = /^#{pathname}/ - filelist.each do |f| - if re =~ f then - result << f # duplicates will be filtered later + else + pathlist.each do |path| + doscan = if path =~ /^\!\!/o then false else true end + recurse = if path =~ /\/\/$/o then true else false end + pathname = path.dup + pathname.gsub!(/^\!+/o, '') + done = false + if not done and filelist then + # checking for exact match + if filelist.include?(pathname) then + result << pathname + done = true + end + if not done and recurse then + # checking for fuzzy // + pathname.gsub!(/\/+$/o, '/.*') + # pathname.gsub!(/\/\//o,'/[\/]*/') + pathname.gsub!(/\/\//o,'/.*?/') + re = /^#{pathname}/ + filelist.each do |f| + if re =~ f then + result << f # duplicates will be filtered later + done = true + end + break if done + end + end + end + if not done and doscan then + # checking for path itself + pname = pathname.sub(/\.\*$/,'') + if not pname =~ /\*/o and FileTest.file?(File.join(pname,filename)) then + result << pname done = true end - break if done end + break if done and first end end - if not done and doscan then - # checking for path itself - pname = pathname.sub(/\.\*$/,'') - if not pname =~ /\*/o and FileTest.file?(File.join(pname,filename)) then - result << pname - done = true - end - end - break if done and first - end - if not done and @scandisk then - pathlist.each do |path| - pathname = path.dup - unless pathname.gsub!(/^\!+/o, '') then # !! prevents scan - recurse = pathname.gsub!(/\/+$/o, '') - complex = pathname.gsub!(/\/\//o,'/*/') - if recurse then - if complex then - if ok = File.glob_file("#{pathname}/**/#{filename}") then + if not done and @scandisk then + pathlist.each do |path| + pathname = path.dup + unless pathname.gsub!(/^\!+/o, '') then # !! prevents scan + recurse = pathname.gsub!(/\/+$/o, '') + complex = pathname.gsub!(/\/\//o,'/*/') + if recurse then + if complex then + if ok = File.glob_file("#{pathname}/**/#{filename}") then + result << File.dirname(ok) + done = true + end + elsif ok = File.locate_file(pathname,filename) then result << File.dirname(ok) done = true end - elsif ok = File.locate_file(pathname,filename) then - result << File.dirname(ok) - done = true - end - elsif complex then - if ok = File.glob_file("#{pathname}/#{filename}") then - result << File.dirname(ok) + elsif complex then + if ok = File.glob_file("#{pathname}/#{filename}") then + result << File.dirname(ok) + done = true + end + elsif FileTest.file?(File.join(pathname,filename)) then + result << pathname done = true end - elsif FileTest.file?(File.join(pathname,filename)) then - result << pathname - done = true + break if done and first end - break if done and first end end + result = result.uniq.collect do |pathname| + File.join(pathname,filename) + end + @found[stamp] = result if @remember end - result = result.uniq.collect do |pathname| - File.join(pathname,filename) - end - @found[stamp] = result if @remember return result # redundant end end -class KPSEFAST +class KpseFast class FileData attr_accessor :tag, :name, :size, :date @@ -673,12 +758,9 @@ class KPSEFAST end def report case @tag - when 1 - "deleted | #{@size.to_s.rjust(8)} | #{@date.strftime('%m/%d/%Y %I:%M')} | #{@name}" - when 2 - "present | #{@size.to_s.rjust(8)} | #{@date.strftime('%m/%d/%Y %I:%M')} | #{@name}" - when 3 - "obsolete | #{' '*8} | #{' '*16} | #{@name}" + when 1 then "deleted | #{@size.to_s.rjust(8)} | #{@date.strftime('%m/%d/%Y %I:%M')} | #{@name}" + when 2 then "present | #{@size.to_s.rjust(8)} | #{@date.strftime('%m/%d/%Y %I:%M')} | #{@name}" + when 3 then "obsolete | #{' '*8} | #{' '*16} | #{@name}" end end end @@ -769,88 +851,16 @@ 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(' ','') - end - arg = arg.split(/\s+/o) - arg.collect! do |a| - a.gsub('',' ') - 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 -if false then + # k = KpseFast.new # (root) + # k.set_test_patterns + # k.load_cnf + # k.expand_variables + # k.load_lsr - k = KPSEFAST.new # (root) - k.set_test_patterns - k.load_cnf - k.expand_variables - k.load_lsr + # k.show_test_patterns - k.show_test_patterns # puts k.list_variables # puts k.list_expansions # k.list_lsr @@ -876,6 +886,6 @@ if false then # puts "expand value $TEXINPUTS.context" # puts k.var_value("$TEXINPUTS.context") - exit + # exit -end +# end diff --git a/scripts/context/ruby/base/kpseremote.rb b/scripts/context/ruby/base/kpseremote.rb new file mode 100644 index 000000000..f5a72b712 --- /dev/null +++ b/scripts/context/ruby/base/kpseremote.rb @@ -0,0 +1,104 @@ +require 'base/kpsefast' + +class KpseRemote + + case ENV['KPSEMETHOD'] + when /soap/o then require 'base/kpse/soap' + when /drb/o then require 'base/kpse/drb' + else require 'base/kpse/drb' + end + + @@port = ENV['KPSEPORT'] || 7000 + + def KpseRemote::available? + ENV['KPSEMETHOD'] && ENV['KPSEPORT'] + end + + def KpseRemote::start_server(port=nil) + kpse = KpseServer.new(port || @@port) + kpse.start + end + + def KpseRemote::start_client(port=nil) # keeps object in server + kpseclient = KpseClient.new(port || @@port) + kpseclient.start + kpse = kpseclient.object + tree = kpse.choose(KpseUtil::identify, KpseUtil::environment) + [kpse, tree] + end + + def KpseRemote::fetch(port=nil) # no need for defining methods but slower, send whole object + kpseclient = KpseClient.new(port || @@port) + kpseclient.start + kpseclient.object.fetch(KpseUtil::identify, KpseUtil::environment) rescue nil + end + + def initialize(port=nil) + begin + @kpse, @tree = KpseRemote::start_client(port) + rescue + @kpse, @tree = nil, nil + end + end + + def progname=(value) + @kpse.set(@tree,'progname',value) + end + def format=(value) + @kpse.set(@tree,'format',value) + end + def engine=(value) + @kpse.set(@tree,'engine',value) + end + + def progname + @kpse.get(@tree,'progname') + end + def format + @kpse.get(@tree,'format') + end + def engine + @kpse.get(@tree,'engine') + end + + def load + @kpse.load(KpseUtil::identify, KpseUtil::environment) + end + def okay? + @kpse && @tree + end + def set(key,value) + @kpse.set(@tree,key,value) + end + def load_cnf + @kpse.load_cnf(@tree) + end + def load_lsr + @kpse.load_lsr(@tree) + end + def expand_variables + @kpse.expand_variables(@tree) + end + def expand_braces(str) + @kpse.expand_braces(@tree,str) + end + def expand_path(str) + @kpse.expand_path(@tree,str) + end + def expand_var(str) + @kpse.expand_var(@tree,str) + end + def show_path(str) + @kpse.show_path(@tree,str) + end + def var_value(str) + @kpse.var_value(@tree,str) + end + def find_file(filename) + @kpse.find_file(@tree,filename) + end + def find_files(filename,first=false) + @kpse.find_files(@tree,filename,first) + end + +end diff --git a/scripts/context/ruby/base/kpserunner.rb b/scripts/context/ruby/base/kpserunner.rb new file mode 100644 index 000000000..cfc2ad4fb --- /dev/null +++ b/scripts/context/ruby/base/kpserunner.rb @@ -0,0 +1,87 @@ +require 'base/kpsefast' + +module KpseRunner + + @@kpse = nil + + def KpseRunner.kpsewhich(arg='') + options, arguments = split_args(arg) + unless @@kpse then + if ENV['KPSEMETHOD'] && ENV['KPSEPORT'] then + require 'base/kpseremote' + @@kpse = KpseRemote.new + else + @@kpse = nil + end + if @@kpse && @@kpse.okay? then + @@kpse.progname = options['progname'] || '' + @@kpse.engine = options['engine'] || '' + @@kpse.format = options['format'] || '' + else + require 'base/kpsefast' + @@kpse = KpseFast.new + @@kpse.load_cnf + @@kpse.progname = options['progname'] || '' + @@kpse.engine = options['engine'] || '' + @@kpse.format = options['format'] || '' + @@kpse.expand_variables + @@kpse.load_lsr + end + 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(' ','') + end + arg = arg.split(/\s+/o) + arg.collect! do |a| + a.gsub('',' ') + 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 diff --git a/scripts/context/ruby/base/switch.rb b/scripts/context/ruby/base/switch.rb index 64d518bd4..160b50aba 100644 --- a/scripts/context/ruby/base/switch.rb +++ b/scripts/context/ruby/base/switch.rb @@ -493,15 +493,21 @@ class CommandLine unless foundkey then @registered.each do |option, shortcut, kind| n = 0 - if option =~ /^#{key}/i then - case n - when 0 - foundkey, foundkind = option, kind - n = 1 - when 1 - # ambiguous matches, like --fix => --fixme --fixyou - foundkey, foundkind = nil, nil - break + begin + re = /^#{key}/i + rescue + key = key.inspect.sub(/^\"(.*)\"$/) do $1 end + re = /^#{key}/i + ensure + if option =~ re then + case n + when 0 + foundkey, foundkind, n = option, kind, 1 + when 1 + # ambiguous matches, like --fix => --fixme --fixyou + foundkey, foundkind = nil, nil + break + end end end end diff --git a/scripts/context/ruby/base/system.rb b/scripts/context/ruby/base/system.rb index ed8c2756e..50173a72d 100644 --- a/scripts/context/ruby/base/system.rb +++ b/scripts/context/ruby/base/system.rb @@ -74,7 +74,7 @@ module System end program = program + ' ' + arguments if ! arguments.empty? program.gsub!(/\s+/io, ' ') - program.gsub!(/(\.\/)+/io, '') + #program.gsub!(/(\/\.\/)+/io, '/') program.gsub!(/\\/io, '/') return program end diff --git a/scripts/context/ruby/base/tex.rb b/scripts/context/ruby/base/tex.rb index 481d0eb12..1aee93fb1 100644 --- a/scripts/context/ruby/base/tex.rb +++ b/scripts/context/ruby/base/tex.rb @@ -129,7 +129,7 @@ class TEX 'forcetexutil', 'texutil', 'globalfile', 'autopath', 'purge', 'purgeall', 'keep', 'autopdf', 'xpdf', 'simplerun', 'verbose', - 'nooptionfile' + 'nooptionfile', 'nobackend' ] @@stringvars = [ 'modefile', 'result', 'suffix', 'response', 'path', @@ -223,6 +223,7 @@ class TEX if ! name || name.empty? then name = [booleanvars,stringvars,standardvars,knownvars] end + str = '' # allocate [name].flatten.each do |n| if str = getvariable(n) then unless (str.class == String) && str.empty? then @@ -855,7 +856,7 @@ class TEX end end - def makeoptionfile(rawname, jobname, jobsuffix, finalrun, fastdisabled, kindofrun) + def makeoptionfile(rawname, jobname, jobsuffix, finalrun, fastdisabled, kindofrun, currentrun=1) begin # jobsuffix = orisuffix if topname = File.suffixed(rawname,'top') and opt = File.open(topname,'w') then @@ -863,7 +864,7 @@ class TEX # local handies opt << "\% #{topname}\n" opt << "\\unprotect\n" - opt << "\\setupsystem[\\c!n=#{kindofrun}]\n" + opt << "\\setupsystem[\\c!n=#{kindofrun},\\c!m=#{currentrun}]\n" opt << "\\def\\MPOSTformatswitch\{#{prognameflag('metafun')} #{formatflag('mpost')}=\}\n" if getvariable('batchmode') then opt << "\\batchmode\n" @@ -973,7 +974,7 @@ class TEX else pagelist = Array.new str.split(/\,/).each do |page| - pagerange = page.split(/(\:|\.\.)/o ) + pagerange = page.split(/\D+/o) if pagerange.size > 1 then pagerange.first.to_i.upto(pagerange.last.to_i) do |p| pagelist << p.to_s @@ -1050,12 +1051,13 @@ class TEX end end - def runmp(filename) + def runmp(filename,mpx=false) mpsengine = validmpsengine(getvariable('mpsengine')) mpsformat = validmpsformat(getarrayvariable('mpsformats').first) progname = validprogname(getvariable('progname')) if mpsengine && mpsformat && progname then command = [quoted(mpsengine),prognameflag(progname),formatflag(mpsengine,mpsformat),runoptions(mpsengine),filename,mpsprocextras(mpsformat)].join(' ') + ENV["MPXCOMMAND"] = "0" unless mpx report(command) if getvariable('verbose') system(command) else @@ -1150,30 +1152,32 @@ class TEX end def runbackend(rawname) - case validbackend(getvariable('backend')) - when 'dvipdfmx' then - fixbackendvars('dvipdfm') - system("dvipdfmx -d 4 #{File.unsuffixed(rawname)}") - when 'xetex' then - fixbackendvars('xetex') - system("xdv2pdf #{File.suffixed(rawname,'xdv')}") - when 'dvips' then - fixbackendvars('dvips') - mapfiles = '' - begin - if tuifile = File.suffixed(rawname,'tui') and FileTest.file?(tuifile) then - IO.read(tuifile).scan(/^c \\usedmapfile\{.\}\{(.*?)\}\s*$/o) do - mapfiles += "-u +#{$1} " ; + unless getvariable('nobackend') then + case validbackend(getvariable('backend')) + when 'dvipdfmx' then + fixbackendvars('dvipdfm') + system("dvipdfmx -d 4 #{File.unsuffixed(rawname)}") + when 'xetex' then + fixbackendvars('xetex') + system("xdv2pdf #{File.suffixed(rawname,'xdv')}") + when 'dvips' then + fixbackendvars('dvips') + mapfiles = '' + begin + if tuifile = File.suffixed(rawname,'tui') and FileTest.file?(tuifile) then + IO.read(tuifile).scan(/^c \\usedmapfile\{.\}\{(.*?)\}\s*$/o) do + mapfiles += "-u +#{$1} " ; + end end + rescue + mapfiles = '' end - rescue - mapfiles = '' - end - system("dvips #{mapfiles} #{File.unsuffixed(rawname)}") - when 'pdftex' then - # no need for postprocessing - else - report("no postprocessing needed") + system("dvips #{mapfiles} #{File.unsuffixed(rawname)}") + when 'pdftex' then + # no need for postprocessing + else + report("no postprocessing needed") + end end end @@ -1287,7 +1291,7 @@ class TEX when 'context' then if getvariable('simplerun') || runonce then - makeoptionfile(rawname,jobname,orisuffix,true,true,3) unless getvariable('nooptionfile') + makeoptionfile(rawname,jobname,orisuffix,true,true,3,1) unless getvariable('nooptionfile') ok = runtex(rawname) if ok then ok = runtexutil(rawname) if getvariable('texutil') || getvariable('forcetexutil') @@ -1314,10 +1318,14 @@ class TEX while ! stoprunning && (texruns < nofruns) && ok do texruns += 1 report("TeX run #{texruns}") - if texruns == 1 then - makeoptionfile(rawname,jobname,orisuffix,false,false,1) unless getvariable('nooptionfile') - else - makeoptionfile(rawname,jobname,orisuffix,false,false,2) unless getvariable('nooptionfile') + unless getvariable('nooptionfile') then + if texruns == nofruns then + makeoptionfile(rawname,jobname,orisuffix,false,false,4,texruns) # last + elsif texruns == 1 then + makeoptionfile(rawname,jobname,orisuffix,false,false,1,texruns) # first + else + makeoptionfile(rawname,jobname,orisuffix,false,false,2,texruns) # unknown + end end ok = runtex(File.suffixed(rawname,jobsuffix)) if ok && (nofruns > 1) then @@ -1332,7 +1340,7 @@ class TEX end ok = runtexutil(rawname) if (nofruns == 1) && getvariable('texutil') if ok && finalrun && (nofruns > 1) then - makeoptionfile(rawname,jobname,orisuffix,true,finalrun,4) unless getvariable('nooptionfile') + makeoptionfile(rawname,jobname,orisuffix,true,finalrun,4,texruns) unless getvariable('nooptionfile') report("final TeX run #{texruns}") ok = runtex(File.suffixed(rawname,jobsuffix)) end @@ -1394,7 +1402,7 @@ class TEX if mpdata = File.silentread(mpfile) then mpdata.gsub!(/^\#.*\n/o,'') File.silentrename(mpfile,mpcopy) - texfound = mergebe || mpdata =~ /btex .*? etex/o + texfound = mergebe || mpdata =~ /btex .*? etex/mo if mp = openedfile(mpfile) then mpdata.gsub!(/(btex.*?)\;(.*?etex)/o) do "#{$1}@@@#{$2}" end # mpdata.gsub!(/(\".*?)\;(.*?\")/o) do "#{$1}@@@#{$2}" end @@ -1408,14 +1416,16 @@ class TEX mpdata.gsub!(/beginfig\s*\((\d+)\)\s*\;(.*?)endfig\s*\;/o) do n, str = $1, $2 if str =~ /(.*?)(verbatimtex.*?etex)\s*\;(.*)/o then - "beginfig(#{n})\;\n$1$2\;\n#{mpbetex(n)}\n$3\;endfig\;\n" + "beginfig(#{n})\;\n#{$1}#{$2}\;\n#{mpbetex(n)}\n#{$3}\;endfig\;\n" else "beginfig(#{n})\;\n#{mpbetex(n)}\n#{str}\;endfig\;\n" end end end + mpdata.gsub!(/\n+/mo, "\n") + mpdata.gsub!(/^\s*\;\s*\n/o, "") unless mpdata =~ /beginfig\s*\(\s*0\s*\)/o then - mp << mpbetex[0] if mpbetex.key?(0) + mp << mpbetex['0'] if mpbetex.key?('0') end mp << mpdata # ?? mp << "\n" @@ -1443,7 +1453,7 @@ class TEX end f.close end - File.silentrename(mpfile,mpfile+'.keep') + File.silentrename(mpfile, mpfile+'.keep') File.silentrename(mpcopy, mpfile) end end @@ -1456,13 +1466,26 @@ class TEX mptex = File.suffixed(mpname,'temp','tex') mpdvi = File.suffixed(mpname,'temp','dvi') mplog = File.suffixed(mpname,'temp','log') - mpmpx = File.suffixed(mpname,'temp','mpx') + mpmpx = File.suffixed(mpname,'mpx') ok = system("mpto #{mpname} > #{mptex}") if ok && File.appended(mptex, "\\end\n") then - if context then - ok = RunConTeXtFile(mptex) + if localjob = TEX.new(@logger) then + localjob.setvariable('files',mptex) + localjob.setvariable('backend','dvips') + localjob.setvariable('engine',getvariable('engine')) unless getvariable('engine').empty? + localjob.setvariable('once',true) + localjob.setvariable('nobackend',true) + if context then + localjob.setvariable('texformats',[getvariable('interface')]) unless getvariable('interface').empty? + elsif getvariable('interface').empty? then + localjob.setvariable('texformats',['plain']) + else + localjob.setvariable('texformats',[getvariable('interface')]) + end + localjob.processtex + ok = true # todo else - ok = RunSomeTeXFile(mptex) + ok = false end ok = ok && FileTest.file?(mpdvi) && system("dvitomp #{mpdvi} #{mpmpx}") [mptex,mpdvi,mplog].each do |mpfil| @@ -1508,18 +1531,22 @@ class TEX if File.atleast?(mpname,10) && (mp = File.silentopen(mpname)) then labels = Hash.new while str = mp.gets do - t = if str =~ /%\s*setup\s*:\s*(.*)/o then $1 else '' end - if str =~ /%\s*figure\s*(\d+)\s*:\s*(.*)/o then + t = if str =~ /^%\s*setup\s*:\s*(.*)$/o then $1 else '' end + if str =~ /^%\s*figure\s*(\d+)\s*:\s*(.*)$/o then labels[$1] = labels[$1] || '' unless t.empty? then labels[$1] += "#{t}\n" t = '' end - labels[$1] += "$2\n" + labels[$1] += "#{$2}\n" end end mp.close - return labels if labels.size>0 + if labels.size>0 then + return labels + else + return nil + end end return nil end diff --git a/scripts/context/ruby/base/texutil.rb b/scripts/context/ruby/base/texutil.rb index 2c57702de..12337c643 100644 --- a/scripts/context/ruby/base/texutil.rb +++ b/scripts/context/ruby/base/texutil.rb @@ -823,8 +823,9 @@ class TeXUtil def loaded(filename) begin - report("parsing file #{filename}") - if f = open(File.suffixed(filename,'tui')) then + tuifile = File.suffixed(filename,'tui') + report("parsing file #{tuifile}") + if f = open(tuifile) then f.each do |line| case line.chomp when /^f (.*)$/o then @plugins.reader('MyFiles', $1.splitdata) diff --git a/scripts/context/ruby/base/variables.rb b/scripts/context/ruby/base/variables.rb index 5cbc5ba53..403b57716 100644 --- a/scripts/context/ruby/base/variables.rb +++ b/scripts/context/ruby/base/variables.rb @@ -12,6 +12,89 @@ require 'base/tool' +class Hash + + def nothing?(id) + ! self[id] || self[id].empty? + end + + def subset(pattern) + h = Hash.new + p = pattern.gsub(/([\.\:\-])/) do "\\#{$1}" end + r = /^#{p}/ + self.keys.each do |k| + h[k] = self[k].dup if k =~ r + end + return h + end + +end + +class ExtendedHash < Hash + + @@re_var_a = /\%(.*?)\%/ + @@re_var_b = /\$\((.*?)\)/ + + def set(key,value='',resolve=true) + if value then + self[key] = if resolve then resolved(value.to_s) else value.to_s end + else + self[key] = '' + end + end + + def replace(key,value='') + self[key] = value if self?(key) + end + + def get(key,default='') + if self.key?(key) then self[key] else default end + end + + def true?(key) + self[key] =~ /^(yes|on|true|enable|enabled|y|start)$/io rescue false + end + + def resolved(str) + begin + str.to_s.gsub(@@re_var_a) do + self[$1] || '' + end.gsub(@@re_var_b) do + self[$1] || '' + end + rescue + str.to_s rescue '' + end + end + + def check(key,default='') + if self.key?(key) then + if self[key].empty? then self[key] = (default || '') end + else + self[key] = (default || '') + end + end + + def checked(key,default='') + if self.key?(key) then + if self[key].empty? then default else self[key] end + else + default + end + end + + def empty?(key) + self[key].empty? + end + + # def downcase(key) + # self[key].downcase! + # end + +end + +# the next one is obsolete so we need to replace things + module Variables def setvariable(key,value='') @@ -26,6 +109,10 @@ module Variables if @variables.key?(key) then @variables[key] else default end end + def truevariable(key) + @variables[key] =~ /^(yes|on|true)$/io rescue false + end + def checkedvariable(str,default='') if @variables.key?(key) then if @variables[key].empty? then default else @variables[key] end diff --git a/scripts/context/ruby/ctxtools.rb b/scripts/context/ruby/ctxtools.rb index 4c47d643e..a768264d9 100644 --- a/scripts/context/ruby/ctxtools.rb +++ b/scripts/context/ruby/ctxtools.rb @@ -15,7 +15,7 @@ # todo: move scite here # -# todo: move kpse call to kpse class/module +# todo: move kpse call to kpse class/module, faster and better banner = ['CtxTools', 'version 1.3.1', '2004/2006', 'PRAGMA ADE/POD'] @@ -1528,33 +1528,386 @@ class Commands end -logger = Logger.new(banner.shift) -commandline = CommandLine.new +class TexDeps + + @@cs_tex = %q/ + above abovedisplayshortskip abovedisplayskip + abovewithdelims accent adjdemerits advance afterassignment + aftergroup atop atopwithdelims + badness baselineskip batchmode begingroup + belowdisplayshortskip belowdisplayskip binoppenalty botmark + box boxmaxdepth brokenpenalty + catcode char chardef cleaders closein closeout clubpenalty + copy count countdef cr crcr csname + day deadcycles def defaulthyphenchar defaultskewchar + delcode delimiter delimiterfactor delimeters + delimitershortfall delimeters dimen dimendef discretionary + displayindent displaylimits displaystyle + displaywidowpenalty displaywidth divide + doublehyphendemerits dp dump + edef else emergencystretch end endcsname endgroup endinput + endlinechar eqno errhelp errmessage errorcontextlines + errorstopmode escapechar everycr everydisplay everyhbox + everyjob everymath everypar everyvbox exhyphenpenalty + expandafter + fam fi finalhyphendemerits firstmark floatingpenalty font + fontdimen fontname futurelet + gdef global group globaldefs + halign hangafter hangindent hbadness hbox hfil horizontal + hfill horizontal hfilneg hfuzz hoffset holdinginserts hrule + hsize hskip hss horizontal ht hyphenation hyphenchar + hyphenpenalty hyphen + if ifcase ifcat ifdim ifeof iffalse ifhbox ifhmode ifinner + ifmmode ifnum ifodd iftrue ifvbox ifvmode ifvoid ifx + ignorespaces immediate indent input inputlineno input + insert insertpenalties interlinepenalty + jobname + kern + language lastbox lastkern lastpenalty lastskip lccode + leaders left lefthyphenmin leftskip leqno let limits + linepenalty line lineskip lineskiplimit long looseness + lower lowercase + mag mark mathaccent mathbin mathchar mathchardef mathchoice + mathclose mathcode mathinner mathop mathopen mathord + mathpunct mathrel mathsurround maxdeadcycles maxdepth + meaning medmuskip message mkern month moveleft moveright + mskip multiply muskip muskipdef + newlinechar noalign noboundary noexpand noindent nolimits + nonscript scriptscript nonstopmode nulldelimiterspace + nullfont number + omit openin openout or outer output outputpenalty over + overfullrule overline overwithdelims + pagedepth pagefilllstretch pagefillstretch pagefilstretch + pagegoal pageshrink pagestretch pagetotal par parfillskip + parindent parshape parskip patterns pausing penalty + postdisplaypenalty predisplaypenalty predisplaysize + pretolerance prevdepth prevgraf + radical raise read relax relpenalty right righthyphenmin + rightskip romannumeral + scriptfont scriptscriptfont scriptscriptstyle scriptspace + scriptstyle scrollmode setbox setlanguage sfcode shipout + show showbox showboxbreadth showboxdepth showlists showthe + skewchar skip skipdef spacefactor spaceskip span special + splitbotmark splitfirstmark splitmaxdepth splittopskip + string + tabskip textfont textstyle the thickmuskip thinmuskip time + toks toksdef tolerance topmark topskip tracingcommands + tracinglostchars tracingmacros tracingonline tracingoutput + tracingpages tracingparagraphs tracingrestores tracingstats + uccode uchyph underline unhbox unhcopy unkern unpenalty + unskip unvbox unvcopy uppercase + vadjust valign vbadness vbox vcenter vfil vfill vfilneg + vfuzz voffset vrule vsize vskip vsplit vss vtop + wd widowpenalty write + xdef xleaders xspaceskip + year + /.split + + @@cs_etex = %q/ + beginL beginR botmarks + clubpenalties currentgrouplevel currentgrouptype + currentifbranch currentiflevel currentiftype + detokenize dimexpr displaywidowpenalties + endL endR eTeXrevision eTeXversion everyeof + firstmarks fontchardp fontcharht fontcharic fontcharwd + glueexpr glueshrink glueshrinkorder gluestretch + gluestretchorder gluetomu + ifcsname ifdefined iffontchar interactionmode + interactionmode interlinepenalties + lastlinefit lastnodetype + marks topmarks middle muexpr mutoglue + numexpr + pagediscards parshapedimen parshapeindent parshapelength + predisplaydirection + savinghyphcodes savingvdiscards scantokens showgroups + showifs showtokens splitdiscards splitfirstmarks + TeXXeTstate tracingassigns tracinggroups tracingifs + tracingnesting tracingscantokens + unexpanded unless + widowpenalties + /.split + + @@cs_pdftex = %q/ + pdfadjustspacing pdfannot pdfavoidoverfull + pdfcatalog pdfcompresslevel + pdfdecimaldigits pdfdest pdfdestmargin + pdfendlink pdfendthread + pdffontattr pdffontexpand pdffontname pdffontobjnum pdffontsize + pdfhorigin + pdfimageresolution pdfincludechars pdfinfo + pdflastannot pdflastdemerits pdflastobj + pdflastvbreakpenalty pdflastxform pdflastximage + pdflastximagepages pdflastxpos pdflastypos + pdflinesnapx pdflinesnapy pdflinkmargin pdfliteral + pdfmapfile pdfmaxpenalty pdfminpenalty pdfmovechars + pdfnames + pdfobj pdfoptionpdfminorversion pdfoutline pdfoutput + pdfpageattr pdfpageheight pdfpageresources pdfpagesattr + pdfpagewidth pdfpkresolution pdfprotrudechars + pdfrefobj pdfrefxform pdfrefximage + pdfsavepos pdfsnaprefpoint pdfsnapx pdfsnapy pdfstartlink + pdfstartthread + pdftexrevision pdftexversion pdfthread pdfthreadmargin + pdfuniqueresname + pdfvorigin + pdfxform pdfximage + /.split + + @@cs_omega = %q/ + odelimiter omathaccent omathchar oradical omathchardef omathcode odelcode + leftghost rightghost + charwd charht chardp charit + localleftbox localrightbox + localinterlinepenalty localbrokenpenalty + pagedir bodydir pardir textdir mathdir + boxdir nextfakemath + pagewidth pageheight pagerightoffset pagebottomoffset + nullocp nullocplist ocp externalocp ocplist pushocplist popocplist clearocplists ocptracelevel + addbeforeocplist addafterocplist removebeforeocplist removeafterocplist + OmegaVersion + InputTranslation OutputTranslation DefaultInputTranslation DefaultOutputTranslation + noInputTranslation noOutputTranslation + InputMode OutputMode DefaultInputMode DefaultOutputMode + noInputMode noOutputMode noDefaultInputMode noDefaultOutputMode + /.split + + @@cs_plain = %q/ + TeX + bgroup egroup endgraf space empty null + newcount newdimen newskip newmuskip newbox newtoks newhelp newread newwrite newfam newlanguage newinsert newif + maxdimen magstephalf magstep + frenchspacing nonfrenchspacing normalbaselines obeylines obeyspaces raggedright ttraggedright + thinspace negthinspace enspace enskip quad qquad + smallskip medskip bigskip removelastskip topglue vglue hglue + break nobreak allowbreak filbreak goodbreak smallbreak medbreak bigbreak + line leftline rightline centerline rlap llap underbar strutbox strut + cases matrix pmatrix bordermatrix eqalign displaylines eqalignno leqalignno + pageno folio tracingall showhyphens fmtname fmtversion + hphantom vphantom phantom smash + /.split + + @@cs_eplain = %q/ + eTeX + newmarks grouptype interactionmode nodetype iftype + tracingall loggingall tracingnone + /.split + + # let's ignore \dimendef etc + + @@primitives_def = "def|edef|xdef|gdef|let|newcount|newdimen|newskip|newbox|newtoks|newmarks|chardef|mathchardef|newconditional" + + @@cs_global = [@@cs_tex,@@cs_etex,@@cs_pdftex,@@cs_omega].sort.flatten + @@types = [['invalid','*'],['okay','='],['forward','>'],['backward','<'],['unknown','?']] + + def initialize(logger=nil) + @cs_local = Hash.new + @cs_new = Hash.new + @cs_defd = Hash.new + @cs_used = Hash.new + @filename = 'context.tex' + @files = Array.new # keep load order ! + @compact = false + @logger = logger + end -commandline.registeraction('touchcontextfile', 'update context version') -commandline.registeraction('contextversion', 'report context version') + def load(filename='context.tex',omitlist=['mult-com.tex']) + begin + @filename = filename + File.open(filename) do |f| + f.each do |line| + if line =~ /^\\input\s+(\S+)\s*/o then + @files.push($1) unless omitlist.include?(File.basename($1)) + end + end + end + rescue + @files = Array.new + end + end -commandline.registeraction('jeditinterface', 'generate jedit syntax files [--pipe]') -commandline.registeraction('bbeditinterface', 'generate bbedit syntax files [--pipe]') -commandline.registeraction('sciteinterface', 'generate scite syntax files [--pipe]') -commandline.registeraction('rawinterface', 'generate raw syntax files [--pipe]') + def analyze + @files.each do |filename| + if f = File.open(filename) then + @logger.report("loading #{filename}") if @logger + defs, uses, n = 0, 0, 0 + f.each do |line| + n += 1 + case line + when /^%/ + # skip + when /\\newif\s*\\if([a-zA-Z@\?\!]+)/ then + pushdef(filename,n,"if:#{$1}") + when /\\([a-zA-Z@\?\!]+)(true|false)/ then + pushuse(filename,n,"if:#{$1}") + when /^\s*\\(#{@primitives_def})\\([a-zA-Z@\?\!]{3,})/o + pushdef(filename,n,$2) + when /\\([a-zA-Z@\?\!]{3,})/o + pushuse(filename,n,$1) + end + end + f.close + end + end + end -commandline.registeraction('translateinterface', 'generate interface files (xml) [nl de ..]') -commandline.registeraction('purgefiles', 'remove temporary files [--all --recurse] [basename]') + def feedback(compact=false) + begin + outputfile = File.basename(@filename).sub(/\.tex$/,'')+'.dep' + File.open(outputfile,'w') do |f| + @compact = compact + @logger.report("saving analysis in #{outputfile}") if @logger + list, len = @cs_local.keys.sort, 0 + if @compact then + list.each do |cs| + if cs.length > len then len = cs.length end + end + len += 1 + else + f.puts "\n" + f.puts "\n" + end + list.each do |cs| + if @cs_new.key?(cs) then + if @cs_new[cs] == @cs_local[cs] then + f.puts some_struc(cs,len,1,some_str(@cs_new,@cs_defd,cs)) + elsif @cs_new[cs].first == @cs_local[cs].first then + f.puts some_struc(cs,len,2,some_str(@cs_new,@cs_defd,cs),some_str(@cs_local,@cs_used,cs)) + else + f.puts some_struc(cs,len,3,some_str(@cs_new,@cs_defd,cs),some_str(@cs_local,@cs_used,cs)) + end + else + f.puts some_struc(cs,len,4,some_str(@cs_local,@cs_used,cs)) + end + end + if @compact then + # nothing + else + "\n" unless @compact + end + end + rescue + end + end -commandline.registeraction('documentation', 'generate documentation [--type=] [filename]') + private -commandline.registeraction('filterpages') # no help, hidden temporary feature -commandline.registeraction('purgeallfiles') # no help, compatibility feature + def some_struc(cs,len,type=1,defstr='',usestr='') + if @compact then + "#{cs.ljust(len)} #{@@types[type][1]} #{defstr} #{usestr}" + else + "\n" + + if defstr.empty? then " \n" else " \n#{defstr} <\defined>\n" end + + if usestr.empty? then " \n" else " #{usestr}\n <\used>\n" end + + "\n" + end + end -commandline.registeraction('patternfiles', 'generate pattern files [--all --xml --utf8] [languagecode]') + def some_str(files, lines, cs) + return '' unless files[cs] + if @compact then + str = '[ ' + files[cs].each do |c| + str += c + str += " (#{lines[cs][c].join(' ')}) " if lines[cs][c] + str += ' ' + end + str += ']' + str.gsub(/ +/, ' ') + else + str = '' + files[cs].each do |c| + if lines[cs][c] then + str += " \n" + str += " " + lines[cs][c].each do |l| + # str += " \n" + str += "" + end + str += "\n" + str += " \n" + else + str += " \n" + end + end + str + end + end + + def pushdef(filename,n,cs) + unless @cs_new.key?(cs) then + @cs_new[cs] = Array.new + @cs_defd[cs] = Hash.new unless @cs_defd.key?(cs) + end + @cs_defd[cs][filename] = Array.new unless @cs_defd[cs][filename] + @cs_new[cs].push(filename) unless @cs_new[cs].include?(filename) + @cs_defd[cs][filename] << n + end + + def pushuse(filename,n,cs) + unless @@cs_global.include?(cs.to_s) then + unless @cs_local[cs] then + @cs_local[cs] = Array.new + @cs_used[cs] = Hash.new unless @cs_used.key?(cs) + end + @cs_used[cs][filename] = Array.new unless @cs_used[cs][filename] + @cs_local[cs].push(filename) unless @cs_local[cs].include?(filename) + @cs_used[cs][filename] << n + end + end + +end + +class Commands + + include CommandBase + + def dependencies + + filename = if @commandline.arguments.empty? then 'context.tex' else @commandline.arguments.first end + compact = @commandline.option('compact') + + ['progname=context',''].each do |progname| + unless FileTest.file?(filename) then + name = `kpsewhich #{progname} #{filename}`.chomp + if FileTest.file?(name) then + filename = name + break + end + end + end -commandline.registeraction('dpxmapfiles', 'convert pdftex mapfiles to dvipdfmx [--force] [texmfroot]') -commandline.registeraction('listentities', 'create doctype entity definition from enco-uc.tex') + if FileTest.file?(filename) && deps = TexDeps.new(logger) then + deps.load + deps.analyze + deps.feedback(compact) + else + report("unknown file #{filename}") + end -commandline.registeraction('brandfiles', 'add context copyright notice [--force]') + end + +end -commandline.registeraction('platformize', 'replace line-endings [--recurse --force] [pattern]') +logger = Logger.new(banner.shift) +commandline = CommandLine.new + +commandline.registeraction('touchcontextfile' , 'update context version') +commandline.registeraction('contextversion' , 'report context version') +commandline.registeraction('jeditinterface' , 'generate jedit syntax files [--pipe]') +commandline.registeraction('bbeditinterface' , 'generate bbedit syntax files [--pipe]') +commandline.registeraction('sciteinterface' , 'generate scite syntax files [--pipe]') +commandline.registeraction('rawinterface' , 'generate raw syntax files [--pipe]') +commandline.registeraction('translateinterface', 'generate interface files (xml) [nl de ..]') +commandline.registeraction('purgefiles' , 'remove temporary files [--all --recurse] [basename]') +commandline.registeraction('documentation' , 'generate documentation [--type=] [filename]') +commandline.registeraction('filterpages' ) # no help, hidden temporary feature +commandline.registeraction('purgeallfiles' ) # no help, compatibility feature +commandline.registeraction('patternfiles' , 'generate pattern files [--all --xml --utf8] [languagecode]') +commandline.registeraction('dpxmapfiles' , 'convert pdftex mapfiles to dvipdfmx [--force] [texmfroot]') +commandline.registeraction('listentities' , 'create doctype entity definition from enco-uc.tex') +commandline.registeraction('brandfiles' , 'add context copyright notice [--force]') +commandline.registeraction('platformize' , 'replace line-endings [--recurse --force] [pattern]') +commandline.registeraction('dependencies' , 'analyze depedencies witin context [--compact] [rootfile]') commandline.registervalue('type','') diff --git a/scripts/context/ruby/newtexexec.rb b/scripts/context/ruby/newtexexec.rb index 86780e742..564205d2e 100644 --- a/scripts/context/ruby/newtexexec.rb +++ b/scripts/context/ruby/newtexexec.rb @@ -1,4 +1,4 @@ -banner = ['TeXExec', 'version 6.1.1', '1997-2006', 'PRAGMA ADE/POD'] +banner = ['TeXExec', 'version 6.1.2', '1997-2006', 'PRAGMA ADE/POD'] unless defined? ownpath ownpath = $0.sub(/[\\\/][a-z0-9\-]*?\.rb/i,'') diff --git a/scripts/context/ruby/runtools.rb b/scripts/context/ruby/runtools.rb index f554057f6..9f6fd3328 100644 --- a/scripts/context/ruby/runtools.rb +++ b/scripts/context/ruby/runtools.rb @@ -456,7 +456,7 @@ class Job end end else - error("no setup file '#{setuptex}'") + warning("no setup file '#{setuptex}', tree not initialized") # no error end rescue warning("error in setup: #{$!}") diff --git a/scripts/context/ruby/texmfstart.rb b/scripts/context/ruby/texmfstart.rb index 8c22d7d4a..dfc9b1a26 100644 --- a/scripts/context/ruby/texmfstart.rb +++ b/scripts/context/ruby/texmfstart.rb @@ -2,7 +2,7 @@ # program : texmfstart # copyright : PRAGMA Advanced Document Engineering -# version : 1.8.3 - 2003/2006 +# version : 1.8.5 - 2003/2006 # author : Hans Hagen # # project : ConTeXt / eXaMpLe @@ -32,11 +32,16 @@ $ownpath = File.expand_path(File.dirname($0)) unless defined? $ownpath +$: << $ownpath + require "rbconfig" +require 'base/kpseremote' +require 'base/kpsedirect' + $mswindows = Config::CONFIG['host_os'] =~ /mswin/ $separator = File::PATH_SEPARATOR -$version = "1.8.3" +$version = "1.8.5" if $mswindows then require "win32ole" @@ -80,6 +85,9 @@ $predefined['mpstools'] = 'mpstools.rb' $predefined['exatools'] = 'exatools.rb' $predefined['xmltools'] = 'xmltools.rb' +$predefined['newpstopdf'] = 'newpstopdf.rb' +$predefined['newtexexec'] = 'newtexexec.rb' + $makelist = [ # context 'texexec', @@ -132,6 +140,25 @@ end $applications['htm'] = $applications['html'] $applications['eps'] = $applications['ps'] +$kpse = nil + +def check_kpse + if $kpse then + # already done + elsif KpseRemote::available? then + $kpse = KpseRemote.new + if $kpse.okay? then + puts("using remote kpse") if $verbose + else + $kpse = KpseDirect.new + puts("forcing direct kpse") if $verbose + end + else + $kpse = KpseDirect.new + puts("using direct kpse") if $verbose + end +end + if $mswindows then GetShortPathName = Win32API.new('kernel32', 'GetShortPathName', ['P','P','N'], 'N') @@ -274,9 +301,11 @@ def expanded(arg) # no "other text files", too restricted end . gsub(/(kpse|loc|file|path)\:([a-zA-Z\-\_\.0-9]+)/o) do # was: \S method, original, resolved = $1, $2, '' if $program && ! $program.empty? then - pstrings = ["-progname=#{$program}"] + # pstrings = ["-progname=#{$program}"] +pstrings = [$program] else - pstrings = ['','progname=context'] + # pstrings = ['','-progname=context'] +pstrings = ['','context'] end # auto suffix with texinputs as fall back if ENV["_CTX_K_V_#{original}_"] then @@ -284,22 +313,31 @@ def expanded(arg) # no "other text files", too restricted report("environment provides #{original} as #{resolved}") unless $report resolved else + check_kpse pstrings.each do |pstr| if resolved.empty? then - command = "kpsewhich #{pstr} #{original}" - report("running #{command}") + # command = "kpsewhich #{pstr} #{original}" + # report("running #{command}") + report("locating '#{original}' in program space '#{pstr}'") begin - resolved = `#{command}`.chomp + # resolved = `#{command}`.chomp + $kpse.progname = pstr + $kpse.format = '' + resolved = $kpse.find_file(original) rescue resolved = '' end end # elsewhere in the tree if resolved.empty? then - command = "kpsewhich #{pstr} -format=\"other text files\" #{original}" - report("running #{command}") + # command = "kpsewhich #{pstr} -format=\"other text files\" #{original}" + # report("running #{command}") + report("locating '#{original}' in program space '#{pstr}' using format 'other text files'") begin - resolved = `#{command}`.chomp + # resolved = `#{command}`.chomp + $kpse.progname = pstr + $kpse.format = 'other text files' + resolved = $kpse.find_file(original) rescue resolved = '' end @@ -403,7 +441,7 @@ def usage print("switches : --verbose --report --browser --direct --execute --locate --iftouched\n") print(" --program --file --page --arguments --batch --edit --report --clear\n") print(" --make --lmake --wmake --path --stubpath --indirect --before --after\n") - print(" --tree --autotree --showenv\n") + print(" --tree --autotree --environment --showenv\n") print("\n") print("example : texmfstart pstopdf.rb cow.eps\n") print(" texmfstart --locate examplex.rb\n") @@ -416,10 +454,11 @@ def usage print(" texmfstart bin:xsltproc env:somepreset path:somefile.xsl somefile.xml\n") print(" texmfstart --iftouched=normal,lowres downsample.rb normal lowres\n") print(" texmfstart texmfstart bin:scite kpse:texmf.cnf\n") - print(" texmfstart texmfstart --exec bin:scite *.tex\n") - print(" texmfstart texmfstart --edit texmf.cnf\n") - print(" texmfstart texmfstart --stubpath=/usr/local/bin --make texexec\n") - print(" texmfstart texmfstart --stubpath=auto --make all\n") + print(" texmfstart --exec bin:scite *.tex\n") + print(" texmfstart --edit texmf.cnf\n") + print(" texmfstart --stubpath=/usr/local/bin --make texexec\n") + print(" texmfstart --stubpath=auto --make all\n") + print(" texmfstart --serve\n") end # somehow registration does not work out (at least not under windows) @@ -491,13 +530,16 @@ def find(filename,program) end # now we consult environment settings fullname = nil + check_kpse + $kpse.progname = program suffixlist.each do |suffix| begin break unless $suffixinputs[suffix] environment = ENV[$suffixinputs[suffix]] || ENV[$suffixinputs[suffix]+".#{$program}"] if ! environment || environment.empty? then begin - environment = `kpsewhich -expand-path=\$#{$suffixinputs[suffix]}`.chomp + # environment = `kpsewhich -expand-path=\$#{$suffixinputs[suffix]}`.chomp + environment = $kpse.expand_path("\$#{$suffixinputs[suffix]}") rescue environment = nil else @@ -536,7 +578,9 @@ def find(filename,program) if suffix =~ /(#{$scriptlist})/ then begin report("using 'kpsewhich' to locate '#{filename}' in suffix space '#{suffix}' (1)") - fullname = `kpsewhich -progname=#{program} -format=texmfscripts #{filename}.#{suffix}`.chomp + # fullname = `kpsewhich -progname=#{program} -format=texmfscripts #{filename}.#{suffix}`.chomp + $kpse.format = 'texmfscripts' + fullname = $kpse.find_file("#{filename}.#{suffix}") rescue report("kpsewhich cannot locate '#{filename}' in suffix space '#{suffix}' (1)") fullname = nil @@ -547,7 +591,9 @@ def find(filename,program) # old TDS location: .../texmf/context/... begin report("using 'kpsewhich' to locate '#{filename}' in suffix space '#{suffix}' (2)") - fullname = `kpsewhich -progname=#{program} -format="other text files" #{filename}.#{suffix}`.chomp + # fullname = `kpsewhich -progname=#{program} -format="other text files" #{filename}.#{suffix}`.chomp + $kpse.format = 'other text files' + fullname = $kpse.find_file("#{filename}.#{suffix}") rescue report("kpsewhich cannot locate '#{filename}' in suffix space '#{suffix}' (2)") fullname = nil @@ -572,7 +618,8 @@ def find(filename,program) if (suffixlist.length == 1) && (suffixlist.first =~ /(#{$documentlist})/) then report("aggressively locating '#{filename}' in document trees") begin - texroot = `kpsewhich -expand-var=$SELFAUTOPARENT`.chomp + # texroot = `kpsewhich -expand-var=$SELFAUTOPARENT`.chomp + texroot = $kpse.expand_var("$SELFAUTOPARENT") rescue texroot = '' else @@ -593,7 +640,8 @@ def find(filename,program) end report("aggressively locating '#{filename}' in tex trees") begin - textrees = `kpsewhich -expand-var=$TEXMF`.chomp + # textrees = `kpsewhich -expand-var=$TEXMF`.chomp + textrees = $kpse.expand_var("$TEXMF") rescue textrees = '' end @@ -719,7 +767,6 @@ def make(filename,windows=false,linux=false) end def process(&block) - if $iftouched then files = $directives['iftouched'].split(',') oldname, newname = files[0], files[1] @@ -735,57 +782,74 @@ def process(&block) else yield end +end +def checkenvironment(tree) + report('') + ENV['TMP'] = ENV['TMP'] || ENV['TEMP'] || ENV['TMPDIR'] || ENV['HOME'] + case RUBY_PLATFORM + when /(mswin|bccwin|mingw|cygwin)/i then ENV['TEXOS'] = ENV['TEXOS'] || 'texmf-mswin' + when /(linux)/i then ENV['TEXOS'] = ENV['TEXOS'] || 'texmf-linux' + when /(darwin|rhapsody|nextstep)/i then ENV['TEXOS'] = ENV['TEXOS'] || 'texmf-macosx' + # when /(netbsd|unix)/i then # todo + else # todo + end + ENV['TEXOS'] = "#{ENV['TEXOS'].sub(/^[\\\/]*/, '').sub(/[\\\/]*$/, '')}" + ENV['TEXPATH'] = tree.sub(/\/+$/,'') # + '/' + ENV['TEXMFOS'] = "#{ENV['TEXPATH']}/#{ENV['TEXOS']}" + report('') + report("preset : TEXPATH => #{ENV['TEXPATH']}") + report("preset : TEXOS => #{ENV['TEXOS']}") + report("preset : TEXMFOS => #{ENV['TEXMFOS']}") + report("preset : TMP => #{ENV['TMP']}") + report('') +end + +def loadfile(filename) + begin + IO.readlines(filename).each do |line| + case line.chomp + when /^[\#\%]/ then + # comment + when /^(.*?)\s*(\>|\=|\<)\s*(.*)\s*$/ then + # = assign | > prepend | < append + key, how, value = $1, $2, $3 + begin + # $SAFE = 0 + value.gsub!(/\%(.*?)\%/) do + ENV[$1] || '' + end + # value.gsub!(/\;/,$separator) if key =~ /PATH/i then + case how + when '=', '<<' then ENV[key] = value + when '?', '??' then ENV[key] = ENV[key] || value + when '<', '+=' then ENV[key] = (ENV[key] || '') + $separator + value + when '>', '=+' then ENV[key] = value + $separator + (ENV[key] ||'') + end + rescue + report("user set failed : #{key} (#{$!})") + else + report("user set : #{key} => #{ENV[key]}") + end + end + end + rescue + report("error in reading file '#{filename}'") + end end -def checktree(tree) +def loadtree(tree) begin unless tree.empty? then - setuptex = File.join(tree,'setuptex.tmf') + if File.directory?(tree) then + setuptex = File.join(tree,'setuptex.tmf') + else + setuptex = tree.dup + end if FileTest.file?(setuptex) then - report('') - report("tex tree : #{setuptex}") - ENV['TEXPATH'] = tree.sub(/\/+$/,'') # + '/' - ENV['TMP'] = ENV['TMP'] || ENV['TEMP'] || ENV['TMPDIR'] || ENV['HOME'] - case RUBY_PLATFORM - when /(mswin|bccwin|mingw|cygwin)/i then ENV['TEXOS'] = ENV['TEXOS'] || 'texmf-mswin' - when /(linux)/i then ENV['TEXOS'] = ENV['TEXOS'] || 'texmf-linux' - when /(darwin|rhapsody|nextstep)/i then ENV['TEXOS'] = ENV['TEXOS'] || 'texmf-macosx' - # when /(netbsd|unix)/i then # todo - else # todo - end - ENV['TEXMFOS'] = "#{ENV['TEXPATH']}/#{ENV['TEXOS']}" - report('') - report("preset : TEXPATH => #{ENV['TEXPATH']}") - report("preset : TEXOS => #{ENV['TEXOS']}") - report("preset : TEXMFOS => #{ENV['TEXMFOS']}") - report("preset : TMP => #{ENV['TMP']}") - report('') - IO.readlines(File.join(tree,'setuptex.tmf')).each do |line| - case line.chomp - when /^[\#\%]/ then - # comment - when /^(.*?)\s*(\>|\=|\<)\s*(.*)\s*$/ then - # = assign | > prepend | < append - key, how, value = $1, $2, $3 - begin - # $SAFE = 0 - value.gsub!(/\%(.*?)\%/) do - ENV[$1] || '' - end - # value.gsub!(/\;/,$separator) if key =~ /PATH/i then - case how - when '=' then ENV[key] = value - when '<' then ENV[key] = (ENV[key] ||'') + $separator + value - when '>' then ENV[key] = value + $separator + (ENV[key] ||'') - end - rescue - report("user set failed : #{key} (#{$!})") - else - report("user set : #{key} => #{ENV[key]}") - end - end - end + report("tex tree definition: #{setuptex}") + checkenvironment(File.dirname(setuptex)) + loadfile(setuptex) else report("no setup file '#{setuptex}'") end @@ -795,6 +859,22 @@ def checktree(tree) end end +def loadenvironment(environment) + begin + unless environment.empty? then + filename = if $path.empty? then environment else File.expand_path(File.join($path,environment)) end + if FileTest.file?(filename) then + report("environment : #{environment}") + loadfile(filename) + else + report("no environment file '#{environment}'") + end + end + rescue + report("problem while loading '#{environment}'") + end +end + def show_environment if $showenv then keys = ENV.keys.sort @@ -816,43 +896,46 @@ def execute(arguments) $directives = hashed(arguments) - $help = $directives['help'] || false - $batch = $directives['batch'] || false - $filename = $directives['file'] || '' - $program = $directives['program'] || 'context' - $direct = $directives['direct'] || false - $edit = $directives['edit'] || false - $page = $directives['page'] || 0 - $browser = $directives['browser'] || false - $report = $directives['report'] || false - $verbose = $directives['verbose'] || false - $arguments = $directives['arguments'] || '' - $execute = $directives['execute'] || $directives['exec'] || false - $locate = $directives['locate'] || false + $help = $directives['help'] || false + $batch = $directives['batch'] || false + $filename = $directives['file'] || '' + $program = $directives['program'] || 'context' + $direct = $directives['direct'] || false + $edit = $directives['edit'] || false + $page = $directives['page'] || 0 + $browser = $directives['browser'] || false + $report = $directives['report'] || false + $verbose = $directives['verbose'] || false + $arguments = $directives['arguments'] || '' + $execute = $directives['execute'] || $directives['exec'] || false + $locate = $directives['locate'] || false $autotree = if $directives['autotree'] then (ENV['TEXMFSTART_TREE'] || ENV['TEXMFSTARTTREE'] || '') else '' end - $path = $directives['path'] || '' - $tree = $directives['tree'] || $autotree || '' + $path = $directives['path'] || '' + $tree = $directives['tree'] || $autotree || '' + $environment = $directives['environment'] || '' - $make = $directives['make'] || false - $unix = $directives['unix'] || false - $windows = $directives['windows'] || false - $stubpath = $directives['stubpath'] || '' - $indirect = $directives['indirect'] || false + $make = $directives['make'] || false + $unix = $directives['unix'] || false + $windows = $directives['windows'] || false + $stubpath = $directives['stubpath'] || '' + $indirect = $directives['indirect'] || false - $before = $directives['before'] || '' - $after = $directives['after'] || '' + $before = $directives['before'] || '' + $after = $directives['after'] || '' - $iftouched = $directives['iftouched'] || false + $iftouched = $directives['iftouched'] || false - $openoffice = $directives['oo'] || false + $openoffice = $directives['oo'] || false $crossover = false if $directives['clear'] - $showenv = $directives['showenv'] || false + $showenv = $directives['showenv'] || false $verbose = true if $showenv + $serve = $directives['serve'] || false + $verbose = true if (ENV['_CTX_VERBOSE_'] =~ /(y|yes|t|true|on)/io) && ! $locate && ! $report ENV['_CTX_VERBOSE_'] = 'yes' if $verbose @@ -875,15 +958,27 @@ def execute(arguments) end end - if $help || ! $filename || $filename.empty? then + if $serve then + if ENV['KPSEMETHOD'] && ENV['KPSEPORT'] then + require 'base/kpseremote' + begin + KpseRemote::start_server + rescue + end + else + usage + end + elsif $help || ! $filename || $filename.empty? then usage - checktree($tree) + loadtree($tree) + loadenvironment($environment) show_environment() elsif $batch && $filename && ! $filename.empty? then # todo, take commands from file and avoid multiple starts and checks else report("texmfstart version #{$version}") - checktree($tree) + loadtree($tree) + loadenvironment($environment) show_environment() if $make then if $filename == 'all' then diff --git a/scripts/context/ruby/tmftools.rb b/scripts/context/ruby/tmftools.rb index d125c5cae..56935b452 100644 --- a/scripts/context/ruby/tmftools.rb +++ b/scripts/context/ruby/tmftools.rb @@ -21,10 +21,11 @@ # tmftools --analyze > kpsewhat.log # tmftools --analyze --strict > kpsewhat.log # tmftools --analyze --delete --force "texmf-local/fonts/.*/somename" +# tmftools --serve # the real thing -banner = ['TMFTools', 'version 1.0.0 (experimental, no help yet)', '2005', 'PRAGMA ADE/POD'] +banner = ['TMFTools', 'version 1.1.0 (experimental, no help yet)', '2005/2006', 'PRAGMA ADE/POD'] unless defined? ownpath ownpath = $0.sub(/[\\\/][a-z0-9\-]*?\.rb/i,'') @@ -33,27 +34,58 @@ end require 'base/switch' require 'base/logger' -require 'base/kpsefast' class Commands include CommandBase def init_kpse - k = KPSEFAST.new - k.rootpath = @commandline.option('rootpath') - k.treepath = @commandline.option('treepath') - k.progname = @commandline.option('progname') - k.engine = @commandline.option('engine') - k.format = @commandline.option('format') - k.diskcache = @commandline.option('diskcache') - k.renewcache = @commandline.option('renewcache') - k.load_cnf - k.expand_variables - k.load_lsr + # require 'base/kpseremote' + # if KpseRemote::available? then + if ENV['KPSEMETHOD'] && ENV['KPSEPORT'] then + require 'base/kpseremote' + k = KpseRemote.new + else + k = nil + end + if k && k.okay? then + k.progname = @commandline.option('progname') + k.engine = @commandline.option('engine') + k.format = @commandline.option('format') + else + require 'base/kpsefast' + k = KpseFast.new + k.rootpath = @commandline.option('rootpath') + k.treepath = @commandline.option('treepath') + k.progname = @commandline.option('progname') + k.engine = @commandline.option('engine') + k.format = @commandline.option('format') + k.diskcache = @commandline.option('diskcache') + k.renewcache = @commandline.option('renewcache') + k.load_cnf + k.expand_variables + k.load_lsr + end return k end + def serve + if ENV['KPSEMETHOD'] && ENV['KPSEPORT'] then + require 'base/kpseremote' + begin + KpseRemote::start_server + rescue + end + end + end + + def reload + begin + init_kpse.load + rescue + end + end + def main if option = @commandline.option('expand-braces') and not option.empty? then puts init_kpse.expand_braces(option) @@ -128,6 +160,9 @@ commandline.registerflag('verbose') commandline.registeraction('help') commandline.registeraction('version') +commandline.registeraction('reload') +commandline.registeraction('serve') + commandline.expand Commands.new(commandline,logger,banner).send(commandline.action || 'main') -- cgit v1.2.3