summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2006-06-09 13:05:00 +0200
committerHans Hagen <pragma@wxs.nl>2006-06-09 13:05:00 +0200
commitf9420a5dde4d6646f2e117813bd85e0bfc701d7d (patch)
tree1d04899c66f7af2bd2fcaf2082f7d4275cbc66c1 /scripts
parent6e2bc6fac8b9a5b4d29155b13d40c08c5868cd13 (diff)
downloadcontext-f9420a5dde4d6646f2e117813bd85e0bfc701d7d.tar.gz
stable 2006.06.09 13:05
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/ruby/base/ctx.rb23
-rw-r--r--scripts/context/ruby/base/tex.rb119
-rw-r--r--scripts/context/ruby/base/texutil.rb36
-rw-r--r--scripts/context/ruby/base/tool.rb2
-rw-r--r--scripts/context/ruby/ctxtools.rb17
-rw-r--r--scripts/context/ruby/rlxtools.rb4
-rw-r--r--scripts/context/ruby/texexec.rb8
-rw-r--r--scripts/context/ruby/texmfstart.rb39
8 files changed, 139 insertions, 109 deletions
diff --git a/scripts/context/ruby/base/ctx.rb b/scripts/context/ruby/base/ctx.rb
index e39751fb6..0baf5a88b 100644
--- a/scripts/context/ruby/base/ctx.rb
+++ b/scripts/context/ruby/base/ctx.rb
@@ -59,7 +59,6 @@ class CtxRunner
end
# name can be kpse:res-make.ctx
-
if not FileTest.file?(@ctxname) then
fullname, done = '', false
if @ctxname =~ /^kpse:/ then
@@ -142,7 +141,6 @@ class CtxRunner
begin
suffix = REXML::XPath.match(@xmldata.root,"/ctx:job/ctx:preprocess/@suffix").to_s
rescue
- puts $!
suffix = @@suffix
else
if suffix && suffix.empty? then suffix = @@suffix end
@@ -151,10 +149,23 @@ class CtxRunner
REXML::XPath.each(files,"ctx:file") do |pattern|
preprocessor = pattern.attributes['processor']
if preprocessor and not preprocessor.empty? then
+ begin
+ variables['old'] = @jobname
+ variables['new'] = ""
+ REXML::XPath.each(pattern,"ctx:value") do |value|
+ if name = value.attributes['name'] then
+ substititute(value,variables[name.to_s])
+ end
+ end
+ rescue
+ report('unable to resolve file pattern')
+ return
+ end
pattern = justtext(pattern)
Dir.glob(pattern).each do |oldfile|
newfile = "#{oldfile}.#{suffix}"
if File.needsupdate(oldfile,newfile) then
+ report("#{oldfile} needs preprocessing")
begin
File.delete(newfile)
rescue
@@ -222,7 +233,8 @@ class CtxRunner
log << "<?xml version='1.0' standalone='yes'?>\n\n"
log << "<ctx:preplist>\n"
@prepfiles.keys.sort.each do |prep|
- log << "\t<ctx:prepfile done='#{yes_or_no(@prepfiles[prep])}'>#{File.basename(prep)}</ctx:prepfile>\n"
+ # log << "\t<ctx:prepfile done='#{yes_or_no(@prepfiles[prep])}'>#{File.basename(prep)}</ctx:prepfile>\n"
+ log << "\t<ctx:prepfile done='#{yes_or_no(@prepfiles[prep])}'>#{prep}</ctx:prepfile>\n"
end
log << "</ctx:preplist>\n"
log.close
@@ -338,7 +350,10 @@ class CtxRunner
when 'suffix' then if str =~ /^.*\.(.*?)$/o then $1 else '' end
when 'nosuffix' then if str =~ /^(.*)\..*?$/o then $1 else str end
when 'nopath' then if str =~ /^.*[\\\/](.*?)$/o then $1 else str end
- else str
+ when 'full' then str
+ when 'complete' then str
+ when 'expand' then File.expand_path(str).gsub(/\\/,"/")
+ else str
end
end
diff --git a/scripts/context/ruby/base/tex.rb b/scripts/context/ruby/base/tex.rb
index 16544c420..c09327725 100644
--- a/scripts/context/ruby/base/tex.rb
+++ b/scripts/context/ruby/base/tex.rb
@@ -839,36 +839,10 @@ class TEX
end
end
- def makestubfile(rawname,forcexml=false)
- if tmp = openedfile(File.suffixed(rawname,'run')) then
+ def makestubfile(rawname,rawbase,forcexml=false)
+ if tmp = openedfile(File.suffixed(rawbase,'run')) then
tmp << "\\starttext\n"
if forcexml then
- # if FileTest.file?(rawname) && (xml = File.open(rawname)) then
- # xml.each do |line|
- # case line
- # when /<\?context\-directive\s+(\S+)\s+(\S+)\s+(\S+)\s*(.*?)\s*\?>/o then
- # category, key, value, rest = $1, $2, $3, $4
- # case category
- # when 'job' then
- # case key
- # when 'control' then
- # setvariable(value,if rest.empty? then true else rest end)
- # when 'mode', 'modes' then
- # tmp << "\\enablemode[#{value}]\n"
- # when 'stylefile', 'environment' then
- # tmp << "\\environment #{value}\n"
- # when 'module' then
- # tmp << "\\usemodule[#{value}]\n"
- # when 'interface' then
- # contextinterface = value
- # end
- # end
- # when /<[a-z]+/io then # beware of order, first pi test
- # break
- # end
- # end
- # xml.close
- # end
tmp << checkxmlfile(rawname)
tmp << "\\processXMLfilegrouped{#{rawname}}\n"
else
@@ -1370,11 +1344,11 @@ class TEX
takeprecautions
report("using search method '#{Kpse.searchmethod}'") if getvariable('verbose')
- rawname = getvariable('filename')
- jobname = getvariable('filename')
- suffix = getvariable('suffix')
- result = getvariable('result')
-
+ rawname = getvariable('filename')
+ jobname = getvariable('filename')
+ suffix = getvariable('suffix')
+ result = getvariable('result')
+ forcexml = getvariable('forcexml')
runonce = getvariable('once')
finalrun = getvariable('final') || (getvariable('arrange') && ! getvariable('noarrange'))
globalfile = getvariable('globalfile')
@@ -1400,7 +1374,9 @@ class TEX
PDFview.closeall if getvariable('autopdf')
- forcexml = jobsuffix.match(/^(xml|fo|fox|rlg|exa)$/io) # nil or match
+ if jobsuffix =~ /^(htm|html|xhtml|xml|fo|fox|rlg|exa)$/io then
+ forcexml = true
+ end
dummyfile = false
@@ -1417,24 +1393,31 @@ class TEX
rawname = jobname + '.' + jobsuffix
+ rawpath = File.dirname(rawname)
+ rawbase = File.basename(rawname)
+
unless FileTest.file?(rawname) then
inppath.split(',').each do |ip|
break if dummyfile = FileTest.file?(File.join(ip,rawname))
end
end
- jobsuffix = makestubfile(rawname,forcexml) if dummyfile || forcexml
+ jobsuffix = makestubfile(rawname,rawbase,forcexml) if dummyfile || forcexml
# preprocess files
unless getvariable('noctx') then
ctx = CtxRunner.new(rawname,@logger)
if getvariable('ctxfile').empty? then
- ctx.manipulate(File.suffixed(rawname,'ctx'),'jobname.ctx')
+ if rawname == rawbase then
+ ctx.manipulate(File.suffixed(rawname,'ctx'),'jobname.ctx')
+ else
+ ctx.manipulate(File.suffixed(rawname,'ctx'),File.join(rawpath,'jobname.ctx'))
+ end
else
ctx.manipulate(File.suffixed(getvariable('ctxfile'),'ctx'))
end
- ctx.savelog(File.suffixed(rawname,'ctl'))
+ ctx.savelog(File.suffixed(rawbase,'ctl'))
envs = ctx.environments
mods = ctx.modules
@@ -1465,7 +1448,7 @@ class TEX
end
result = File.suffixed(rawname,suffix) unless suffix.empty?
- pushresult(rawname,result)
+ pushresult(rawbase,result)
method = validtexmethod(validtexformat(getvariable('texformats')))
@@ -1475,16 +1458,16 @@ class TEX
when 'context' then
if getvariable('simplerun') || runonce then
- makeoptionfile(rawname,jobname,orisuffix,true,true,3,1) unless getvariable('nooptionfile')
- ok = runtex(rawname)
+ makeoptionfile(rawbase,jobname,orisuffix,true,true,3,1) unless getvariable('nooptionfile')
+ ok = runtex(if dummyfile || forcexml then rawbase else rawname end)
if ok then
- ok = runtexutil(rawname) if getvariable('texutil') || getvariable('forcetexutil')
- runbackend(rawname)
- popresult(rawname,result)
+ ok = runtexutil(rawbase) if getvariable('texutil') || getvariable('forcetexutil')
+ runbackend(rawbase)
+ popresult(rawbase,result)
end
if getvariable('keep') then
- ['top','log'].each do |suffix|
- File.silentrename(File.suffixed(rawname,suffix),File.suffixed(rawname,suffix+'.keep'))
+ ['top','log','run'].each do |suffix|
+ File.silentrename(File.suffixed(rawbase,suffix),File.suffixed(rawbase,suffix+'.keep'))
end
end
else
@@ -1492,11 +1475,11 @@ class TEX
texruns, nofruns = 0, getvariable('runs').to_i
state = FileState.new
['tub','tuo'].each do |s|
- state.register(File.suffixed(rawname,s))
+ state.register(File.suffixed(rawbase,s))
end
if getvariable('automprun') then # check this
['mprun','mpgraph'].each do |s|
- state.register(File.suffixed(rawname,s,'mp'),'randomseed')
+ state.register(File.suffixed(rawbase,s,'mp'),'randomseed')
end
end
while ! stoprunning && (texruns < nofruns) && ok do
@@ -1504,48 +1487,48 @@ class TEX
report("TeX run #{texruns}")
unless getvariable('nooptionfile') then
if texruns == nofruns then
- makeoptionfile(rawname,jobname,orisuffix,false,false,4,texruns) # last
+ makeoptionfile(rawbase,jobname,orisuffix,false,false,4,texruns) # last
elsif texruns == 1 then
- makeoptionfile(rawname,jobname,orisuffix,false,false,1,texruns) # first
+ makeoptionfile(rawbase,jobname,orisuffix,false,false,1,texruns) # first
else
- makeoptionfile(rawname,jobname,orisuffix,false,false,2,texruns) # unknown
+ makeoptionfile(rawbase,jobname,orisuffix,false,false,2,texruns) # unknown
end
end
- ok = runtex(File.suffixed(rawname,jobsuffix))
+ ok = runtex(File.suffixed(if dummyfile || forcexml then rawbase else rawname end,jobsuffix))
if ok && (nofruns > 1) then
unless getvariable('nompmode') then
- mprundone = runtexmpjob(rawname, "mpgraph")
- mprundone = runtexmpjob(rawname, "mprun")
+ mprundone = runtexmpjob(rawbase, "mpgraph")
+ mprundone = runtexmpjob(rawbase, "mprun")
end
- ok = runtexutil(rawname)
+ ok = runtexutil(rawbase)
state.update
stoprunning = state.stable?
end
end
- ok = runtexutil(rawname) if (nofruns == 1) && getvariable('texutil')
+ ok = runtexutil(rawbase) if (nofruns == 1) && getvariable('texutil')
if ok && finalrun && (nofruns > 1) then
- makeoptionfile(rawname,jobname,orisuffix,true,finalrun,4,texruns) unless getvariable('nooptionfile')
+ makeoptionfile(rawbase,jobname,orisuffix,true,finalrun,4,texruns) unless getvariable('nooptionfile')
report("final TeX run #{texruns}")
- ok = runtex(File.suffixed(rawname,jobsuffix))
+ ok = runtex(File.suffixed(if dummyfile || forcexml then rawbase else rawname end,jobsuffix))
end
if getvariable('keep') then
- ['top','log'].each do |suffix|
- File.silentrename(File.suffixed(rawname,suffix),File.suffixed(rawname,suffix+'.keep'))
+ ['top','log','run'].each do |suffix|
+ File.silentrename(File.suffixed(rawbase,suffix),File.suffixed(rawbase,suffix+'.keep'))
end
else
- File.silentrename(File.suffixed(rawname,'top'),File.suffixed(rawname,'tmp'))
+ File.silentrename(File.suffixed(rawbase,'top'),File.suffixed(rawbase,'tmp'))
end
# ['tmp','top','log'].each do |s| # previous tuo file / runtime option file / log file
- # File.silentdelete(File.suffixed(rawname,s))
+ # File.silentdelete(File.suffixed(rawbase,s))
# end
if ok then
- runbackend(rawname)
- popresult(rawname,result)
+ runbackend(rawbase)
+ popresult(rawbase,result)
end
end
- Kpse.runscript('ctxtools',rawname,'--purge') if getvariable('purge')
- Kpse.runscript('ctxtools',rawname,'--purgeall') if getvariable('purgeall')
+ Kpse.runscript('ctxtools',rawbase,'--purge') if getvariable('purge')
+ Kpse.runscript('ctxtools',rawbase,'--purgeall') if getvariable('purgeall')
when 'latex' then
@@ -1557,16 +1540,16 @@ class TEX
end
- if (dummyfile or forcexml) and FileTest.file?(rawname) then
+ if (dummyfile or forcexml) and FileTest.file?(rawbase) then
begin
- File.delete(File.suffixed(rawname,'run'))
+ File.delete(File.suffixed(rawbase,'run'))
rescue
report("unable to delete stub file")
end
end
if ok and getvariable('autopdf') then
- PDFview.open(File.suffixed(if result.empty? then rawname else result end,'pdf'))
+ PDFview.open(File.suffixed(if result.empty? then rawbase else result end,'pdf'))
end
else
diff --git a/scripts/context/ruby/base/texutil.rb b/scripts/context/ruby/base/texutil.rb
index 7b3e957e3..3d25c3e97 100644
--- a/scripts/context/ruby/base/texutil.rb
+++ b/scripts/context/ruby/base/texutil.rb
@@ -943,26 +943,30 @@ end
def loaded(filename)
begin
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)
- when /^c (.*)$/o then @plugins.reader('MyCommands', [$1])
- when /^e (.*)$/o then @plugins.reader('MyExtras', $1.splitdata)
- when /^s (.*)$/o then @plugins.reader('MySynonyms', $1.splitdata)
- when /^r (.*)$/o then @plugins.reader('MyRegisters',$1.splitdata)
- when /^p (.*)$/o then @plugins.reader('MyPlugins', $1.splitdata)
- when /^x (.*)$/o then @plugins.reader('MyKeys', $1.splitdata)
- when /^r (.*)$/o then # nothing, not handled here
- else
- # report("unknown entry #{line[0,1]} in line #{line.chomp}")
+ if FileTest.file?(tuifile) then
+ 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)
+ when /^c (.*)$/o then @plugins.reader('MyCommands', [$1])
+ when /^e (.*)$/o then @plugins.reader('MyExtras', $1.splitdata)
+ when /^s (.*)$/o then @plugins.reader('MySynonyms', $1.splitdata)
+ when /^r (.*)$/o then @plugins.reader('MyRegisters',$1.splitdata)
+ when /^p (.*)$/o then @plugins.reader('MyPlugins', $1.splitdata)
+ when /^x (.*)$/o then @plugins.reader('MyKeys', $1.splitdata)
+ when /^r (.*)$/o then # nothing, not handled here
+ else
+ # report("unknown entry #{line[0,1]} in line #{line.chomp}")
+ end
end
+ f.close
end
- f.close
+ else
+ report("unable to locate #{tuifile}")
end
rescue
- report("fatal error in parsing #{filename}")
+ report("fatal error in parsing #{tuifile}")
@filename = 'texutil'
else
@filename = filename
diff --git a/scripts/context/ruby/base/tool.rb b/scripts/context/ruby/base/tool.rb
index 7f40e773d..9f120ca11 100644
--- a/scripts/context/ruby/base/tool.rb
+++ b/scripts/context/ruby/base/tool.rb
@@ -132,7 +132,7 @@ module Tool
return old unless test(?f,old)
new = old.downcase
- new.gsub!(/[^A-Za-z0-9\-\.\\\/]/o) do # funny chars
+ new.gsub!(/[^A-Za-z0-9\_\-\.\\\/]/o) do # funny chars
'-'
end
if old =~ /[a-zA-Z]\:/o
diff --git a/scripts/context/ruby/ctxtools.rb b/scripts/context/ruby/ctxtools.rb
index 5686468f1..b1e880682 100644
--- a/scripts/context/ruby/ctxtools.rb
+++ b/scripts/context/ruby/ctxtools.rb
@@ -685,20 +685,25 @@ class Commands
else
if skiplevel == 0 then
inlocaldocument = indocument
+ inlocaldocument = false # else first line skipped when not empty
someline = str
if indocument then
ted.puts("\\stopdocumentation\n")
indocument = false
end
- if someline.empty? && indefinition then
- ted.puts("\\stopdefinition\n")
- indefinition = false
- elsif indefinition then
- ted.puts("#{someline}\n")
+ if indefinition then
+ if someline.empty? then
+ ted.puts("\\stopdefinition\n")
+ indefinition = false
+ else
+ ted.puts("#{someline}\n")
+ end
elsif ! someline.empty? then
ted.puts("\n\\startdefinition\n")
indefinition = true
- unless inlocaldocument then
+ if inlocaldocument then
+ # nothing
+ else
nofdefinitions += 1
ted.puts("#{someline}\n")
end
diff --git a/scripts/context/ruby/rlxtools.rb b/scripts/context/ruby/rlxtools.rb
index a7af5b691..1225dedb3 100644
--- a/scripts/context/ruby/rlxtools.rb
+++ b/scripts/context/ruby/rlxtools.rb
@@ -110,7 +110,7 @@ class Commands
REXML::XPath.each(localsteps,tag) do |extras|
REXML::XPath.each(extras,"rl:value") do |value|
if name = value.attributes['name'] then
- substititute(value,variables[name.to_s])
+ substititute(value,variables[name.to_s] || '')
end
end
end
@@ -202,7 +202,7 @@ class Commands
return str.strip
end
- def substititute(value,str)
+ def substititute(value,str='')
if str then
begin
if value.attributes.key?('method') then
diff --git a/scripts/context/ruby/texexec.rb b/scripts/context/ruby/texexec.rb
index 3dab3e9ce..a7b870376 100644
--- a/scripts/context/ruby/texexec.rb
+++ b/scripts/context/ruby/texexec.rb
@@ -512,10 +512,10 @@ class Commands
job.setvariable('backend','xdv')
else
case job.getvariable('texengine')
- when 'pdfetex' then job.setvariable('backend','pdftex')
- when 'luatex' then job.setvariable('backend','pdftex')
- when 'xetex' then job.setvariable('backend','xetex')
- when 'aleph' then job.setvariable('backend','dvipdfmx')
+ when 'pdfetex' then job.setvariable('backend','pdftex')
+ when 'luatex' then job.setvariable('backend','pdftex')
+ when 'xetex' then job.setvariable('backend','xetex')
+ when 'aleph' then job.setvariable('backend','dvipdfmx')
else
job.setvariable('backend','standard')
end
diff --git a/scripts/context/ruby/texmfstart.rb b/scripts/context/ruby/texmfstart.rb
index 66bab6261..22c9e36d1 100644
--- a/scripts/context/ruby/texmfstart.rb
+++ b/scripts/context/ruby/texmfstart.rb
@@ -1708,6 +1708,10 @@ def launch(filename)
end
end
+# env|environment
+# rel|relative
+# loc|locate|kpse|path|file
+
def expanded(arg) # no "other text files", too restricted
arg.gsub(/(env|environment)\:([a-zA-Z\-\_\.0-9]+)/o) do
method, original, resolved = $1, $2, ''
@@ -1718,7 +1722,20 @@ def expanded(arg) # no "other text files", too restricted
report("environment variable #{original} cannot be resolved") unless $report
original
end
- end . gsub(/(kpse|loc|file|path)\:([a-zA-Z\-\_\.0-9]+)/o) do # was: \S
+ end . gsub(/(rel|relative)\:([a-zA-Z\-\_\.0-9]+)/o) do
+ method, original, resolved = $1, $2, ''
+ ['.','..','../..'].each do |r|
+ if FileTest.file?(File.join(r,original)) then
+ resolved = File.join(r,original)
+ break
+ end
+ end
+ if resolved.empty? then
+ original
+ else
+ resolved
+ end
+ end . gsub(/(kpse|loc|locate|file|path)\:([a-zA-Z\-\_\.0-9]+)/o) do
method, original, resolved = $1, $2, ''
if $program && ! $program.empty? then
# pstrings = ["-progname=#{$program}"]
@@ -1816,8 +1833,11 @@ def runoneof(application,fullname,browserpermitted)
else
report("starting #{$filename}") unless $report
output("\n") if $report && $verbose
- applications = $applications[application]
- if applications.class == Array then
+ applications = $applications[application.downcase]
+ if ! applications then
+ output("problems with determining application type")
+ return true
+ elsif applications.class == Array then
if $report then
output([fullname,expanded($arguments)].join(' '))
return true
@@ -1858,7 +1878,7 @@ def usage
print("\n")
print("usage : texmfstart [switches] filename [optional arguments]\n")
print("\n")
- print("switches : --verbose --report --browser --direct --execute --locate --iftouched\n")
+ print("switches : --verbose --report --browser --direct --execute --locate --iftouched --ifchanged\n")
print(" --program --file --page --arguments --batch --edit --report --clear\n")
print(" --make --lmake --wmake --path --stubpath --indirect --before --after\n")
print(" --tree --autotree --environment --showenv\n")
@@ -1871,11 +1891,14 @@ def usage
print(" texmfstart --page=2 --file=showcase.pdf\n")
print(" texmfstart --program=yourtex yourscript.rb arg-1 arg-2\n")
print(" texmfstart --direct xsltproc kpse:somefile.xsl somefile.xml\n")
+ print(" texmfstart --direct ruby rel:wn-cleanup-1.rb oldfile.xml newfile.xml\n")
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 --ifchanged=somefile.dat --direct processit somefile.dat\n")
+ print(" texmfstart bin:scite kpse:texmf.cnf\n")
print(" texmfstart --exec bin:scite *.tex\n")
print(" texmfstart --edit texmf.cnf\n")
+ print(" texmfstart --edit kpse:texmf.cnf\n")
print(" texmfstart --serve\n")
print("\n")
print(" texmfstart --stubpath=/usr/local/bin [--make --remove] --verbose all\n")
@@ -2114,15 +2137,15 @@ def run(fullname)
elsif FileTest.file?(fullname) then
begin
case fullname
- when /\.(#{$scriptlist})$/ then
+ when /\.(#{$scriptlist})$/i then
return runoneof($1,fullname,false)
- when /\.(#{$documentlist})$/ then
+ when /\.(#{$documentlist})$/i then
return runoneof($1,fullname,true)
else
return runoneof('unknown',fullname,false)
end
rescue
- report("starting '#{$filename}' in program space '#{$program}' fails")
+ report("starting '#{$filename}' in program space '#{$program}' fails (#{$!})")
end
else
report("the file '#{$filename}' in program space '#{$program}' is not accessible")