diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/ruby/base/exa.rb | 406 | ||||
-rw-r--r-- | scripts/context/ruby/base/tex.rb | 293 | ||||
-rw-r--r-- | scripts/context/ruby/base/texutil.rb | 2 | ||||
-rw-r--r-- | scripts/context/ruby/texmfstart.rb | 95 |
4 files changed, 631 insertions, 165 deletions
diff --git a/scripts/context/ruby/base/exa.rb b/scripts/context/ruby/base/exa.rb new file mode 100644 index 000000000..fdc5b5093 --- /dev/null +++ b/scripts/context/ruby/base/exa.rb @@ -0,0 +1,406 @@ +# \setuplayout[width=3cm] +# +# tex.setup.setuplayout.width.[integer|real|dimension|string|key] +# tex.[mp]var.whatever.width.[integer|real|dimension|string|key] + +require 'ftools' +require 'md5' + +# this can become a lua thing + +# no .*? but 0-9a-z\:\. because other too slow (and greedy) + +class Hash + + def subset(pattern) + h = Hash.new + r = /^#{pattern.gsub('.','\.')}/ + self.keys.each do |k| + h[k] = self[k].dup if k =~ r + end + return h + end + +end + +module ExaEncrypt + + def ExaEncrypt.encrypt_base(logger, oldfilename, newfilename) + if FileTest.file?(oldfilename) then + logger.report("checking #{oldfilename}") if logger + if data = IO.read(oldfilename) then + done = false + # cfg file: + # + # banner : exa configuration file + # user : domain, name = password, projectlist + # + if data =~ /^\s*banner\s*\:\s*exa\s*configuration\s*file/ then + data.gsub!(/^(\s*user\s*\:\s*.+?\s*\,\s*.+?\s*\=\s*)(.+?)(\s*\,\s*.+\s*)$/) do + pre, password, post = $1, $2, $3 + unless password =~ /MD5:/i then + done = true + password = "MD5:" + MD5.new(password).hexdigest.upcase + end + "#{pre}#{password}#{post}" + end + else + data.gsub!(/<exa:password([^>]*?)>(.*?)<\/exa:password>/mois) do + attributes, password = $1, $2 + unless password =~ /^([0-9A-F][0-9A-F])+$/ then + done = true + password = MD5.new(password).hexdigest.upcase + attributes = " encryption='md5'#{attributes}" + end + "<exa:password#{attributes}>#{password}</exa:password>" + end + end + begin + File.open(newfilename,'w') do |f| + f.puts(data) + end + rescue + logger.report("#{newfilename} cannot be written") if logger + else + logger.report("#{oldfilename} encrypted into #{newfilename}") if done and logger + end + end + end + end + +end + +module ExaModes + + @@modefile = 'examodes.tex' + + @@request = /(<exa:request.*?)(>.*?<\/exa:request>)/mo + @@redone = /<exa:request[^>]*?texified=([\'\"])yes\1.*?>/mo + @@reload = /<(exa:variable)([^>]+?label\=)([\"\'])([0-9A-Za-z\-\.\:]+?)(\3[^\/]*?)>(.*?)<(\/exa:variable)>/mo + @@recalc = /<(exa:variable)([^>]+?label\=)([\"\'])([0-9A-Za-z\-\.\:]+?)([\.\:]calcmath)(\3[^\/]*?)>(.*?)<(\/exa:variable)>/mo + @@rename = /<(exa:variable)([^>]+?label\=)([\"\'])([0-9A-Za-z\-\.\:]+?)(\3[^\/]*?)>(.*?)<(\/exa:variable)>/mo + @@refile = /<(exa:filename|exa:filelist)>(.*?)<(\/\1)>/mo + + def ExaModes.cleanup_request(logger,filename='request.exa',modefile=@@modefile) + begin File.delete(filename+'.raw') ; rescue ; end + begin File.delete(modefile) ; rescue ; end + if FileTest.file?(filename) then + data, done = nil, false + begin + data = IO.read(filename) + rescue + data = nil + end + if data =~ @@request and data !~ @@redone then + data.gsub!(@@rename) do + done = true + '<' + $1 + $2 + $3 + $4 + $5 + '>' + + texifiedstr($4,$6) + + '<' + $7 + '>' + end + data.gsub!(@@refile) do + done = true + '<' + $1 + '>' + + cleanpath($2) + + '<' + $3 + '>' + end + data.gsub!(@@recalc) do + done = true + '<' + $1 + $2 + $3 + $4 + ":raw" + $6 + '>' + $7 + '<' + $8 + '>' + + '<' + $1 + $2 + $3 + $4 + $6 + '>' + + calculatortexmath($7,false) + + '<' + $8 + '>' + end + if done then + data.gsub!(@@request) do + $1 + " texified='yes'" + $2 + end + begin File.copy(filename, filename+'.raw') ; rescue ; end + begin + logger.report("rewriting #{filename}") if logger + File.open(filename,'w') do |f| + f.puts(data) + end + rescue + logger.report("#{filename} cannot be rewritten") if logger + end + end + else + logger.report("#{filename} is already ok") if logger + end + @variables = Hash.new + data.scan(@@reload) do + @variables[$4] = $5 + end + vars = @variables.subset('data.tex.var') + mpvars = @variables.subset('data.tex.mpvar') + modes = @variables.subset('data.tex.mode') + setups = @variables.subset('data.tex.setup') + if not (modes.empty? and setups.empty? and vars.empty? and mpvars.empty?) then + begin + File.open(modefile,'w') do |mod| + logger.report("saving modes and setups in #{modefile}") if logger + if not modes.empty? then + for key in modes.keys do + k = key.dup + k.gsub!(/\./,'-') + mod.puts("\\enablemode[#{k}-#{modes[key]}]\n") + if modes[key] =~ /(on|yes|start)/o then # ! ! ! ! ! + mod.puts("\\enablemode[#{k}]\n") + end + end + mod.puts("\n\\readfile{cont-mod}{}{}\n") + end + if not setups.empty? then + for key in setups.keys + if key =~ /^(.+?)\.(.+?)\.(.+?)$/o then + command, key, type, value = $1, $2, $3, setups[key] + value = cleanedup(key,type,value) + mod.puts("\\#{$1}[#{key}=#{value}]\n") + elsif key =~ /^(.+?)\.(.+?)$/o then + command, type, value = $1, $2, setups[key] + mod.puts("\\#{$1}[#{value}]\n") + end + end + end + savevaroptions(vars, 'setvariables', mod) + savevaroptions(mpvars,'setMPvariables',mod) + end + rescue + logger.report("#{modefile} cannot be saved") if logger + end + else + logger.report("#{modefile} is not created") if logger + end + end + end + + private + + def ExaModes.autoparenthesis(str) + if str =~ /[\+\-]/o then '[1]' + str + '[1]' else str end + end + + def ExaModes.cleanedup(key,type,value) + if type == 'dimension' then + unless value =~ /(cm|mm|in|bp|sp|pt|dd|em|ex)/o + value + 'pt' + else + value + end + elsif type == 'calcmath' then + '{' + calculatortexmath(value,true) + '}' + elsif type =~ /^filename|filelist$/ or key =~ /^filename|filelist$/ then + cleanpath(value) + else + value + end + end + + def ExaModes.cleanpath(str) + (str ||'').gsub(/\\/o,'/') + end + + def ExaModes.texifiedstr(key,val) + case key + when 'filename' then + cleanpath(val) + when 'filelist' then + cleanpath(val) + else + val + end + end + + def ExaModes.savevaroptions(vars,setvariables,mod) + if not vars.empty? then + for key in vars.keys do + # var.whatever.width.dimension.value + if key =~ /^(.+?)\.(.+?)\.(.+?)$/o then + tag, key, type, value = $1, $2, $3, vars[key] + value = cleanedup(key,type,value) + mod.puts("\\#{setvariables}[#{tag}][#{key}=#{value}]\n") + elsif key =~ /^(.+?)\.(.+?)$/o then + tag, key, value = $1, $2, vars[key] + mod.puts("\\#{setvariables}[#{tag}][#{key}=#{value}]\n") + end + end + end + end + + def ExaModes.calculatortexmath(str,tx=true) + if tx then + bdisp, edisp = "\\displaymath\{", "\}" + binln, einln = "\\inlinemath\{" , "\}" + egraf = "\\endgraf" + else + bdisp, edisp = "<displaytexmath>", "</displaytexmath>" + binln, einln = "<inlinetexmath>" , "</inlinetexmath>" + egraf = "<p/>" + end + str.gsub!(/\n\s*\n+/mois, "\\ENDGRAF ") + str.gsub!(/(\[\[)\s*(.*?)\s*(\]\])/mos) do + $1 + docalculatortexmath($2) + $3 + end + str.gsub!(/(\\ENDGRAF)+\s*(\[\[)\s*(.*?)\s*(\]\])/mois) do + $1 + bdisp + $3 + edisp + end + str.gsub!(/(\[\[)\s*(.*?)\s*(\]\])/o) do + binln + $2 + einln + end + str.gsub!(/\\ENDGRAF/mos, egraf) + str + end + + def ExaModes.docalculatortexmath(str) + str.gsub!(/\n/o) { ' ' } + str.gsub!(/\s+/o) { ' ' } + str.gsub!(/>/o) { '>' } + str.gsub!(/</o) { '<' } + str.gsub!(/&.*?;/o) { } + level = 0 + str.gsub!(/([\(\)])/o) do |chr| + if chr == '(' then + level = level + 1 + chr = '[' + level.to_s + ']' + elsif chr == ')' then + chr = '[' + level.to_s + ']' + level = level - 1 + end + chr + end + # ...E... + loop do + break unless str.gsub!(/([\d\.]+)E([\-\+]{0,1}[\d\.]+)/o) do + "\{\\SCINOT\{#{$1}\}\{#{$2}\}\}" + end + end + # ^-.. + loop do + break unless str.gsub!(/\^([\-\+]*\d+)/o) do + "\^\{#{$1}\}" + end + end + # ^(...) + loop do + break unless str.gsub!(/\^(\[\d+\])(.*?)\1/o) do + "\^\{#{$2}\}" + end + end + # 1/x^2 + loop do + break unless str.gsub!(/([\d\w\.]+)\/([\d\w\.]+)\^([\d\w\.]+)/o) do + "@\{#{$1}\}\{#{$2}\^\{#{$3}\}\}" + end + end + # int(a,b,c) + loop do + break unless str.gsub!(/(int|sum|prod)(\[\d+\])(.*?),(.*?),(.*?)\2/o) do + "\\#{$1.upcase}\^\{#{$4}\}\_\{#{$5}\}\{#{autoparenthesis($3)}\}" + end + end + # int(a,b) + loop do + break unless str.gsub!(/(int|sum|prod)(\[\d+\])(.*?),(.*?)\2/o) do + "\\#{$1.upcase}\_\{#{$4}\}\{#{autoparenthesis($3)}\}" + end + end + # int(a) + loop do + break unless str.gsub!(/(int|sum|prod)(\[\d+\])(.*?)\2/o) do + "\\#{$1.upcase}\{#{autoparenthesis($3)}\}" + end + end + # sin(x) => {\sin(x)} + loop do + break unless str.gsub!(/(median|min|max|round|sqrt|sin|cos|tan|sinh|cosh|tanh|ln|log)\s*(\[\d+\])(.*?)\2/o) do + "\{\\#{$1.upcase}\{#{$2}#{$3}#{$2}\}\}" + end + end + # mean + str.gsub!(/(mean)(\[\d+\])(.*?)\2/o) do + "\{\\OVERLINE\{#{$3}\}\}" + end + # sin x => {\sin(x)} + # ... + # (1+x)/(1+x) => \frac{1+x}{1+x} + loop do + break unless str.gsub!(/(\[\d+\])(.*?)\1\/(\[\d+\])(.*?)\3/o) do + "@\{#{$2}\}\{#{$4}\}" + end + end + # (1+x)/x => \frac{1+x}{x} + loop do + break unless str.gsub!(/(\[\d+\])(.*?)\1\/([a-zA-Z0-9]+)/o) do + "@\{#{$2}\}\{#{$3}\}" + end + end + # 1/(1+x) => \frac{1}{1+x} + loop do + break unless str.gsub!(/([a-zA-Z0-9]+)\/(\[\d+\])(.*?)\2/o) do + "@\{#{$1}\}\{#{$3}\}" + end + end + # 1/x => \frac{1}{x} + loop do + break unless str.gsub!(/([a-zA-Z0-9]+)\/([a-zA-Z0-9]+)/o) do + "@\{#{$1}\}\{#{$2}\}" + end + end + # + str.gsub!(/\@/o) do + "\\FRAC " + end + str.gsub!(/\*/o) do + " " + end + str.gsub!(/\<\=/o) do + "\\LE " + end + str.gsub!(/\>\=/o) do + "\\GE " + end + str.gsub!(/\=/o) do + "\\EQ " + end + str.gsub!(/\</o) do + "\\LT " + end + str.gsub!(/\>/) do + "\\GT " + end + str.gsub!(/(D)(\[\d+\])(.*?)\2/o) do + "\{\\FRAC\{\\MBOX{d}\}\{\\MBOX{d}x\}\{#{$2}#{$3}#{$2}\}\}" + end + str.gsub!(/(exp)(\[\d+\])(.*?)\2/o) do + "\{e^\{#{$3}\}\}" + end + str.gsub!(/(abs)(\[\d+\])(.*?)\2/o) do + "\{\\left\|#{$3}\\right\|\}" + end + str.gsub!(/D([x|y])/o) do + "\\FRAC\{\{\\rm d\}#{$1}\}\{\{\\rm d\}x\}" + end + str.gsub!(/D([f|g])(\[\d+\])(.*?)\2/o) do + "\{\\rm #{$1}\}'#{$2}#{$3}#{$2}" + end + str.gsub!(/([f|g])(\[\d+\])(.*?)\2/o) do + "\{\\rm #{$1}\}#{$2}#{$3}#{$2}" + end + str.gsub!(/(pi|inf)/io) do + "\\#{$1} " + end + loop do + break unless str.gsub!(/(\[\d+?\])(.*?)\1/o) do + "\\left(#{$2}\\right)" + end + end + str.gsub!(/\\([A-Z]+?)([\s\{\^\_\\])/io) do + "\\#{$1.downcase}#{$2}" + end + str + end + +end + +# ExaModes.cleanup_request() diff --git a/scripts/context/ruby/base/tex.rb b/scripts/context/ruby/base/tex.rb index ea909aabc..481d0eb12 100644 --- a/scripts/context/ruby/base/tex.rb +++ b/scripts/context/ruby/base/tex.rb @@ -128,7 +128,7 @@ class TEX 'mpyforce', 'forcempy', 'forcetexutil', 'texutil', 'globalfile', 'autopath', - 'purge', 'purgeall', 'autopdf', 'xpdf', 'simplerun', 'verbose', + 'purge', 'purgeall', 'keep', 'autopdf', 'xpdf', 'simplerun', 'verbose', 'nooptionfile' ] @@stringvars = [ @@ -847,148 +847,157 @@ class TEX end def deleteoptionfile(rawname) - begin - File.delete(File.suffixed(rawname,'top')) - rescue + ['top','top.keep'].each do |suffix| + begin + File.delete(File.suffixed(rawname,suffix)) + rescue + end end end def makeoptionfile(rawname, jobname, jobsuffix, finalrun, fastdisabled, kindofrun) - # jobsuffix = orisuffix - if topname = File.suffixed(rawname,'top') and opt = File.open(topname,'w') then - # local handies - opt << "\% #{topname}\n" - opt << "\\unprotect\n" - opt << "\\setupsystem[\\c!n=#{kindofrun}]\n" - opt << "\\def\\MPOSTformatswitch\{#{prognameflag('metafun')} #{formatflag('mpost')}=\}\n" - if getvariable('batchmode') then - opt << "\\batchmode\n" - end - if getvariable('nonstopmode') then - opt << "\\nonstopmode\n" - end - if getvariable('paranoid') then - opt << "\\def\\maxreadlevel{1}\n" - end - if (str = File.unixfied(getvariable('modefile'))) && ! str.empty? then - opt << "\\readlocfile{#{str}}{}{}\n" - end - if (str = File.unixfied(getvariable('result'))) && ! str.empty? then - opt << "\\setupsystem[file=#{str}]\n" - elsif (str = getvariable('suffix')) && ! str.empty? then - opt << "\\setupsystem[file=#{jobname}.#{str}]\n" - end - opt << "\\setupsystem[\\c!type=#{Tool.ruby_platform()}]\n" - if (str = File.unixfied(getvariable('path'))) && ! str.empty? then - opt << "\\usepath[#{str}]\n" unless str.empty? - end - if (str = getvariable('mainlanguage').downcase) && ! str.empty? && ! str.standard? then - opt << "\\setuplanguage[#{str}]\n" - end - if str = validbackend(getvariable('backend')) then - opt << "\\setupoutput[#{str}]\n" - end - if getvariable('color') then - opt << "\\setupcolors[\\c!state=\\v!start]\n" - end - if getvariable('nompmode') || getvariable('nomprun') || getvariable('automprun') then - opt << "\\runMPgraphicsfalse\n" - end - if getvariable('fast') && ! getvariable('fastdisabled') then - opt << "\\fastmode\n" - end - if getvariable('silentmode') then - opt << "\\silentmode\n" - end - if (str = getvariable('separation')) && ! str.empty? then - opt << "\\setupcolors[\\c!split=#{str}]\n" - end - if (str = getvariable('setuppath')) && ! str.empty? then - opt << "\\setupsystem[\\c!directory=\{#{str}\}]\n" - end - if (str = getvariable('paperformat')) && ! str.empty? && ! str.standard? then - if str =~ /^([a-z]+\d+)([a-z]+\d+)$/io then # A5A4 A4A3 A2A1 ... - opt << "\\setuppapersize[#{$1.upcase}][#{$2.upcase}]\n" - else # ...*... - pf = str.upcase.split(/[x\*]/o) - pf << pf[0] if pd.size == 1 - opt << "\\setuppapersize[#{pf[0]}][#{pf[1]}]\n" + begin + # jobsuffix = orisuffix + if topname = File.suffixed(rawname,'top') and opt = File.open(topname,'w') then + report("writing option file #{topname}") + # local handies + opt << "\% #{topname}\n" + opt << "\\unprotect\n" + opt << "\\setupsystem[\\c!n=#{kindofrun}]\n" + opt << "\\def\\MPOSTformatswitch\{#{prognameflag('metafun')} #{formatflag('mpost')}=\}\n" + if getvariable('batchmode') then + opt << "\\batchmode\n" end - end - if (str = getvariable('background')) && ! str.empty? then - opt << "\\defineoverlay[whatever][{\\externalfigure[#{str}][\\c!factor=\\v!max]}]\n" - opt << "\\setupbackgrounds[\\v!page][\\c!background=whatever]\n" - end - if getvariable('centerpage') then - opt << "\\setuplayout[\\c!location=\\v!middle,\\c!marking=\\v!on]\n" - end - if getvariable('nomapfiles') then - opt << "\\disablemapfiles\n" - end - if getvariable('noarrange') then - opt << "\\setuparranging[\\v!disable]\n" - elsif getvariable('arrange') then - arrangement = Array.new - if finalrun then - arrangement << "\\v!doublesided" unless getvariable('noduplex') - case getvariable('printformat') - when '' then arrangement << "\\v!normal" - when /.*up/oi then arrangement << "\\v!rotated" - when /.*down/oi then arrangement << ["2DOWN","\\v!rotated"] - when /.*side/oi then arrangement << ["2SIDE","\\v!rotated"] + if getvariable('nonstopmode') then + opt << "\\nonstopmode\n" + end + if getvariable('paranoid') then + opt << "\\def\\maxreadlevel{1}\n" + end + if (str = File.unixfied(getvariable('modefile'))) && ! str.empty? then + opt << "\\readlocfile{#{str}}{}{}\n" + end + if (str = File.unixfied(getvariable('result'))) && ! str.empty? then + opt << "\\setupsystem[file=#{str}]\n" + elsif (str = getvariable('suffix')) && ! str.empty? then + opt << "\\setupsystem[file=#{jobname}.#{str}]\n" + end + opt << "\\setupsystem[\\c!type=#{Tool.ruby_platform()}]\n" + if (str = File.unixfied(getvariable('path'))) && ! str.empty? then + opt << "\\usepath[#{str}]\n" unless str.empty? + end + if (str = getvariable('mainlanguage').downcase) && ! str.empty? && ! str.standard? then + opt << "\\setuplanguage[#{str}]\n" + end + if str = validbackend(getvariable('backend')) then + opt << "\\setupoutput[#{str}]\n" + end + if getvariable('color') then + opt << "\\setupcolors[\\c!state=\\v!start]\n" + end + if getvariable('nompmode') || getvariable('nomprun') || getvariable('automprun') then + opt << "\\runMPgraphicsfalse\n" + end + if getvariable('fast') && ! getvariable('fastdisabled') then + opt << "\\fastmode\n" + end + if getvariable('silentmode') then + opt << "\\silentmode\n" + end + if (str = getvariable('separation')) && ! str.empty? then + opt << "\\setupcolors[\\c!split=#{str}]\n" + end + if (str = getvariable('setuppath')) && ! str.empty? then + opt << "\\setupsystem[\\c!directory=\{#{str}\}]\n" + end + if (str = getvariable('paperformat')) && ! str.empty? && ! str.standard? then + if str =~ /^([a-z]+\d+)([a-z]+\d+)$/io then # A5A4 A4A3 A2A1 ... + opt << "\\setuppapersize[#{$1.upcase}][#{$2.upcase}]\n" + else # ...*... + pf = str.upcase.split(/[x\*]/o) + pf << pf[0] if pd.size == 1 + opt << "\\setuppapersize[#{pf[0]}][#{pf[1]}]\n" end - else - arrangement << "\\v!disable" end - opt << "\\setuparranging[#{arrangement.flatten.join(',')}]\n" if arrangement.size > 0 - end - # we handle both "--mode" and "--modes", else "--mode" is - # mapped onto "--modefile" - if (str = getvariable('modes')) && ! str.empty? then - opt << "\\enablemode[#{str}]\n" - end - if (str = getvariable('mode')) && ! str.empty? then - opt << "\\enablemode[#{str}]\n" - end - if (str = getvariable('arguments')) && ! str.empty? then - opt << "\\setupenv[#{str}]\n" - end - if (str = getvariable('randomseed')) && ! str.empty? then - opt << "\\setupsystem[\\c!random=#{str}]\n" - end - if (str = getvariable('input')) && ! str.empty? then - opt << "\\setupsystem[inputfile=#{str}]\n" - else - opt << "\\setupsystem[inputfile=#{rawname}]\n" - end - if (str = getvariable('pages')) && ! str.empty? then - if str.downcase == 'odd' then - opt << "\\chardef\\whichpagetoshipout=1\n" - elsif str.downcase == 'even' then - opt << "\\chardef\\whichpagetoshipout=2\n" + if (str = getvariable('background')) && ! str.empty? then + opt << "\\defineoverlay[whatever][{\\externalfigure[#{str}][\\c!factor=\\v!max]}]\n" + opt << "\\setupbackgrounds[\\v!page][\\c!background=whatever]\n" + end + if getvariable('centerpage') then + opt << "\\setuplayout[\\c!location=\\v!middle,\\c!marking=\\v!on]\n" + end + if getvariable('nomapfiles') then + opt << "\\disablemapfiles\n" + end + if getvariable('noarrange') then + opt << "\\setuparranging[\\v!disable]\n" + elsif getvariable('arrange') then + arrangement = Array.new + if finalrun then + arrangement << "\\v!doublesided" unless getvariable('noduplex') + case getvariable('printformat') + when '' then arrangement << "\\v!normal" + when /.*up/oi then arrangement << "\\v!rotated" + when /.*down/oi then arrangement << ["2DOWN","\\v!rotated"] + when /.*side/oi then arrangement << ["2SIDE","\\v!rotated"] + end + else + arrangement << "\\v!disable" + end + opt << "\\setuparranging[#{arrangement.flatten.join(',')}]\n" if arrangement.size > 0 + end + # we handle both "--mode" and "--modes", else "--mode" is + # mapped onto "--modefile" + if (str = getvariable('modes')) && ! str.empty? then + opt << "\\enablemode[#{str}]\n" + end + if (str = getvariable('mode')) && ! str.empty? then + opt << "\\enablemode[#{str}]\n" + end + if (str = getvariable('arguments')) && ! str.empty? then + opt << "\\setupenv[#{str}]\n" + end + if (str = getvariable('randomseed')) && ! str.empty? then + opt << "\\setupsystem[\\c!random=#{str}]\n" + end + if (str = getvariable('input')) && ! str.empty? then + opt << "\\setupsystem[inputfile=#{str}]\n" else - pagelist = Array.new - str.split(/\,/).each do |page| - pagerange = page.split(/(\:|\.\.)/o ) - if pagerange.size > 1 then - pagerange.first.to_i.upto(pagerange.last.to_i) do |p| - pagelist << p.to_s + opt << "\\setupsystem[inputfile=#{rawname}]\n" + end + if (str = getvariable('pages')) && ! str.empty? then + if str.downcase == 'odd' then + opt << "\\chardef\\whichpagetoshipout=1\n" + elsif str.downcase == 'even' then + opt << "\\chardef\\whichpagetoshipout=2\n" + else + pagelist = Array.new + str.split(/\,/).each do |page| + pagerange = page.split(/(\:|\.\.)/o ) + if pagerange.size > 1 then + pagerange.first.to_i.upto(pagerange.last.to_i) do |p| + pagelist << p.to_s + end + else + pagelist << page end - else - pagelist << page end + opt << "\\def\\pagestoshipout\{pagelist.join(',')\}\n"; end - opt << "\\def\\pagestoshipout\{pagelist.join(',')\}\n"; end + opt << "\\protect\n"; + begin getvariable('filters' ).split(',').uniq.each do |f| opt << "\\useXMLfilter[#{f}]\n" end ; rescue ; end + begin getvariable('usemodules' ).split(',').uniq.each do |m| opt << "\\usemodule[#{m}]\n" end ; rescue ; end + begin getvariable('environments').split(',').uniq.each do |e| opt << "\\environment #{e}\n" end ; rescue ; end + # this will become: + # begin getvariable('environments').split(',').uniq.each do |e| opt << "\\useenvironment[#{e}]\n" end ; rescue ; end + opt << "\\endinput\n" + opt.close + else + report("unable to write option file #{topname}") end - opt << "\\protect\n"; - begin getvariable('filters' ).split(',').uniq.each do |f| opt << "\\useXMLfilter[#{f}]\n" end ; rescue ; end - begin getvariable('usemodules' ).split(',').uniq.each do |m| opt << "\\usemodule[#{m}]\n" end ; rescue ; end - begin getvariable('environments').split(',').uniq.each do |e| opt << "\\environment #{e}\n" end ; rescue ; end - # this will become: - # begin getvariable('environments').split(',').uniq.each do |e| opt << "\\useenvironment[#{e}]\n" end ; rescue ; end - opt << "\\endinput\n" - opt.close + rescue + report("fatal error in writing option file #{topname}") end end @@ -1009,6 +1018,7 @@ class TEX if ENV.key?('SHELL_ESCAPE') && (ENV['SHELL_ESCAPE'] == 'f') then setvariable('automprun',true) end + done = false ['TXRESOURCES','MPRESOURCES','MFRESOURCES'].each do |res| [getvariable('runpath'),getvariable('path')].each do |pat| unless pat.empty? then @@ -1017,8 +1027,10 @@ class TEX else ENV[res] = pat end + report("setting #{res} to #{ENV[res]}") unless done end end + done = true end end @@ -1282,8 +1294,11 @@ class TEX runbackend(rawname) popresult(rawname,result) end - File.silentdelete(File.suffixed(rawname,'tmp')) - File.silentrename(File.suffixed(rawname,'top'),File.suffixed(rawname,'tmp')) + if getvariable('keep') then + ['top','log'].each do |suffix| + File.silentrename(File.suffixed(rawname,suffix),File.suffixed(rawname,suffix+'.keep')) + end + end else mprundone, ok, stoprunning = false, true, false texruns, nofruns = 0, getvariable('runs').to_i @@ -1321,10 +1336,16 @@ class TEX report("final TeX run #{texruns}") ok = runtex(File.suffixed(rawname,jobsuffix)) end - ['tmp','top'].each do |s| # previous tuo file / runtime option file - File.silentdelete(File.suffixed(rawname,s)) + if getvariable('keep') then + ['top','log'].each do |suffix| + File.silentrename(File.suffixed(rawname,suffix),File.suffixed(rawname,suffix+'.keep')) + end + else + File.silentrename(File.suffixed(rawname,'top'),File.suffixed(rawname,'tmp')) end - File.silentrename(File.suffixed(rawname,'top'),File.suffixed(rawname,'tmp')) + # ['tmp','top','log'].each do |s| # previous tuo file / runtime option file / log file + # File.silentdelete(File.suffixed(rawname,s)) + # end if ok then runbackend(rawname) popresult(rawname,result) @@ -1422,7 +1443,7 @@ class TEX end f.close end - File.silentrename(mpfile,"mptrace.tmp") + File.silentrename(mpfile,mpfile+'.keep') File.silentrename(mpcopy, mpfile) end end diff --git a/scripts/context/ruby/base/texutil.rb b/scripts/context/ruby/base/texutil.rb index e05e88cdc..2c57702de 100644 --- a/scripts/context/ruby/base/texutil.rb +++ b/scripts/context/ruby/base/texutil.rb @@ -372,7 +372,7 @@ class TeXUtil def MyExtras::processor(logger) @@programs.each do |p| - cmd = "texmfstart #{@@programs[p.to_i]}" + cmd = @@programs[p.to_i] logger.report("running #{cmd}") system(cmd) end diff --git a/scripts/context/ruby/texmfstart.rb b/scripts/context/ruby/texmfstart.rb index 4bea5e979..8c22d7d4a 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.7.1 - 2003/2005 +# version : 1.8.3 - 2003/2006 # author : Hans Hagen # # project : ConTeXt / eXaMpLe @@ -36,13 +36,11 @@ require "rbconfig" $mswindows = Config::CONFIG['host_os'] =~ /mswin/ $separator = File::PATH_SEPARATOR -$version = "1.7.1" +$version = "1.8.3" if $mswindows then - require "win32ole" require "Win32API" - end exit if defined?(REQUIRE2LIB) @@ -97,7 +95,9 @@ $makelist = [ 'xmltools', 'textools', 'mpstools', - 'tmftools' + 'tmftools', + 'exatools', + 'runtools' ] if ENV['TEXMFSTART_MODE'] = 'experimental' then @@ -388,22 +388,22 @@ def runoneof(application,fullname,browserpermitted) end def report(str) - $stderr.puts(str) if $verbose + $stdout.puts(str) if $verbose end def output(str) - $stderr.puts(str) + $stdout.puts(str) end def usage - print "version : #{$version} - 2003/2005 - www.pragma-ade.com\n" + print "version : #{$version} - 2003/2006 - www.pragma-ade.com\n" print("\n") print("usage : texmfstart [switches] filename [optional arguments]\n") print("\n") 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\n") + print(" --tree --autotree --showenv\n") print("\n") print("example : texmfstart pstopdf.rb cow.eps\n") print(" texmfstart --locate examplex.rb\n") @@ -560,9 +560,10 @@ def find(filename,program) paths = ENV['PATH'].split($separator) suffixlist.each do |s| paths.each do |p| - report("checking #{p} for suffix #{s}") - if FileTest.file?(File.join(p,"#{filename}.#{s}")) then - fullname = File.join(p,"#{filename}.#{s}") + suffixedname = "#{filename}.#{s}" + report("checking #{p} for #{filename}") + if FileTest.file?(File.join(p,suffixedname)) then + fullname = File.join(p,suffixedname) return shortpathname(fullname) if register(filename,fullname) end end @@ -696,13 +697,15 @@ def make(filename,windows=false,linux=false) if windows && f = open(basename+'.bat','w') then f.binmode f.write("@echo off\015\012") - f.write("#{program} #{filename} %*\015\012") + # f.write("#{program} #{filename} %*\015\012") + f.write("#{program} %~n0 %*\015\012") f.close report("windows stub '#{basename}.bat' made") elsif linux && f = open(basename,'w') then f.binmode f.write("#!/bin/sh\012") f.write("#{program} #{filename} $@\012") + # f.write("#{program} `basename $0` $@\012") f.close report("unix stub '#{basename}' made") end @@ -736,8 +739,8 @@ def process(&block) end def checktree(tree) - unless tree.empty? then - begin + begin + unless tree.empty? then setuptex = File.join(tree,'setuptex.tmf') if FileTest.file?(setuptex) then report('') @@ -753,28 +756,57 @@ def checktree(tree) 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("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 + case line.chomp when /^[\#\%]/ then # comment - when /^(.*?)\s+\=\s+(.*)\s*$/ then - k, v = $1, $2 - ENV[k] = v.gsub(/\%(.*?)\%/) do - ENV[$1] || '' + 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 - report("user set : #{k} => #{ENV[k]}") end end else report("no setup file '#{setuptex}'") end - rescue end + rescue + # maybe tree is empty or boolean (no arg given) + end +end + +def show_environment + if $showenv then + keys = ENV.keys.sort + size = 0 + keys.each do |k| + size = k.size if k.size > size + end + report('') + keys.each do |k| + report("#{k.rjust(size)} => #{ENV[k]}") + end + report('') end end @@ -793,12 +825,12 @@ def execute(arguments) $page = $directives['page'] || 0 $browser = $directives['browser'] || false $report = $directives['report'] || false - $verbose = $directives['verbose'] || (ENV['_CTX_VERBOSE_'] =~ /(y|yes|t|true|on)/io) || 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'] || '') else '' end + $autotree = if $directives['autotree'] then (ENV['TEXMFSTART_TREE'] || ENV['TEXMFSTARTTREE'] || '') else '' end $path = $directives['path'] || '' $tree = $directives['tree'] || $autotree || '' @@ -818,6 +850,11 @@ def execute(arguments) $crossover = false if $directives['clear'] + $showenv = $directives['showenv'] || false + $verbose = true if $showenv + + $verbose = true if (ENV['_CTX_VERBOSE_'] =~ /(y|yes|t|true|on)/io) && ! $locate && ! $report + ENV['_CTX_VERBOSE_'] = 'yes' if $verbose if $openoffice then @@ -841,11 +878,13 @@ def execute(arguments) if $help || ! $filename || $filename.empty? then usage checktree($tree) + 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) + show_environment() if $make then if $filename == 'all' then makelist = $makelist |