diff options
author | Marius <mariausol@gmail.com> | 2012-05-22 02:40:13 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2012-05-22 02:40:13 +0300 |
commit | ffb360b52944514197aa47313c26816cd2fb7a7e (patch) | |
tree | af46811e825bb977838cd2db44646879f281b752 /scripts | |
parent | 3821b4213bf250551cfa122313ae2c56f9923533 (diff) | |
download | context-ffb360b52944514197aa47313c26816cd2fb7a7e.tar.gz |
beta 2012.05.22 01:22
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/lua/mtx-context.lua | 93 | ||||
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 74 | ||||
-rw-r--r-- | scripts/context/ruby/base/tex.rb | 65 | ||||
-rw-r--r-- | scripts/context/stubs/mswin/mtxrun.lua | 74 | ||||
-rw-r--r-- | scripts/context/stubs/unix/mtxrun | 74 |
5 files changed, 308 insertions, 72 deletions
diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua index 305236509..f1138979e 100644 --- a/scripts/context/lua/mtx-context.lua +++ b/scripts/context/lua/mtx-context.lua @@ -621,6 +621,10 @@ scripts.context.aftersuffixes = { "pdf", "tuo", "tuc", "log" } +scripts.context.errorsuffixes = { + "log" +} + scripts.context.interfaces = { en = "cont-en", uk = "cont-uk", @@ -710,6 +714,56 @@ function scripts.context.closepdf(name,method) pdfview.close(file.replacesuffix(name,"pdf")) end +local function push_result_purge(oldbase,newbase) + for _, suffix in next, scripts.context.aftersuffixes do + local oldname = file.addsuffix(oldbase,suffix) + local newname = file.addsuffix(newbase,suffix) + os.remove(newname) + os.remove(oldname) + end +end + +local function push_result_keep(oldbase,newbase) + for _, suffix in next, scripts.context.beforesuffixes do + local oldname = file.addsuffix(oldbase,suffix) + local newname = file.addsuffix(newbase,suffix) + local tmpname = "keep-"..oldname + os.remove(tmpname) + os.rename(oldname,tmpname) + os.remove(oldname) + os.rename(newname,oldname) + end +end + +local function save_result_error(oldbase,newbase) + for _, suffix in next, scripts.context.errorsuffixes do + local oldname = file.addsuffix(oldbase,suffix) + local newname = file.addsuffix(newbase,suffix) + os.remove(newname) -- to be sure + os.rename(oldname,newname) + end +end + +local function save_result_purge(oldbase,newbase) + for _, suffix in next, scripts.context.aftersuffixes do + local oldname = file.addsuffix(oldbase,suffix) + local newname = file.addsuffix(newbase,suffix) + os.remove(newname) -- to be sure + os.rename(oldname,newname) + end +end + +local function save_result_keep(oldbase,newbase) + for _, suffix in next, scripts.context.aftersuffixes do + local oldname = file.addsuffix(oldbase,suffix) + local newname = file.addsuffix(newbase,suffix) + local tmpname = "keep-"..oldname + os.remove(newname) + os.rename(oldname,newname) + os.rename(tmpname,oldname) + end +end + function scripts.context.run(ctxdata,filename) -- filename overloads environment.files local files = (filename and { filename }) or environment.files @@ -812,22 +866,9 @@ function scripts.context.run(ctxdata,filename) newbase = file.removesuffix(resultname) if oldbase ~= newbase then if environment.argument("purgeresult") then - for _, suffix in next, scripts.context.aftersuffixes do - local oldname = file.addsuffix(oldbase,suffix) - local newname = file.addsuffix(newbase,suffix) - os.remove(newname) - os.remove(oldname) - end + push_result_purge(oldbase,newbase) else - for _, suffix in next, scripts.context.beforesuffixes do - local oldname = file.addsuffix(oldbase,suffix) - local newname = file.addsuffix(newbase,suffix) - local tmpname = "keep-"..oldname - os.remove(tmpname) - os.rename(oldname,tmpname) - os.remove(oldname) - os.rename(newname,oldname) - end + push_result_keep(oldbase,newbase) end else resultname = nil @@ -928,10 +969,16 @@ function scripts.context.run(ctxdata,filename) --~ end if not returncode then report("fatal error: no return code, message: %s",errorstring or "?") + if resultname then + save_result_error(oldbase,newbase) + end os.exit(1) break elseif returncode > 0 then report("fatal error: return code: %s",returncode or "?") + if resultname then + save_result_error(oldbase,newbase) + end os.exit(returncode) break else @@ -972,21 +1019,9 @@ function scripts.context.run(ctxdata,filename) if environment.argument("purgeresult") then -- so, if there is no result then we don't get the old one, but -- related files (log etc) are still there for tracing purposes - for _, suffix in next, scripts.context.aftersuffixes do - local oldname = file.addsuffix(oldbase,suffix) - local newname = file.addsuffix(newbase,suffix) - os.remove(newname) -- to be sure - os.rename(oldname,newname) - end + save_result_purge(oldbase,newbase) else - for _, suffix in next, scripts.context.aftersuffixes do - local oldname = file.addsuffix(oldbase,suffix) - local newname = file.addsuffix(newbase,suffix) - local tmpname = "keep-"..oldname - os.remove(newname) - os.rename(oldname,newname) - os.rename(tmpname,oldname) - end + save_result_keep(oldbase,newbase) end report("result renamed to: %s",newbase) end diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 335c4fcb9..a8bbca885 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -8112,7 +8112,7 @@ xml.tocdata(e,"error") </typing> --ldx]]-- -function xml.tocdata(e,wrapper) +function xml.tocdata(e,wrapper) -- a few more in the aux module local whatever = type(e) == "table" and xmltostring(e.dt) or e or "" if wrapper then whatever = format("<%s>%s</%s>",wrapper,whatever,wrapper) @@ -10095,6 +10095,36 @@ function xml.cdatatotext(e) end end +-- local x = xml.convert("<x><a>1<b>2</b>3</a></x>") +-- xml.texttocdata(xml.first(x,"a")) +-- print(x) -- <x><![CDATA[1<b>2</b>3]]></x> + +function xml.texttocdata(e) -- could be a finalizer + local dt = e.dt + local s = xml.tostring(dt) -- no shortcut? + e.tg = "@cd@" + e.special = true + e.ns = "" + e.rn = "" + e.dt = { s } + e.at = nil +end + +-- local x = xml.convert("<x><a>1<b>2</b>3</a></x>") +-- xml.tocdata(xml.first(x,"a")) +-- print(x) -- <x><![CDATA[<a>1<b>2</b>3</a>]]></x> + +function xml.elementtocdata(e) -- could be a finalizer + local dt = e.dt + local s = xml.tostring(e) -- no shortcut? + e.tg = "@cd@" + e.special = true + e.ns = "" + e.rn = "" + e.dt = { s } + e.at = nil +end + xml.builtinentities = table.tohash { "amp", "quot", "apos", "lt", "gt" } -- used often so share local entities = characters and characters.entities or nil @@ -10242,7 +10272,7 @@ if not modules then modules = { } end modules ['lxml-xml'] = { } local concat = table.concat -local find = string.find +local find, lower, upper = string.find, string.lower, string.upper local xml = xml @@ -10639,6 +10669,46 @@ function xml.textonly(e) -- no pattern return concat(textonly(e,{})) end +-- + +-- local x = xml.convert("<x><a x='+'>1<B>2</B>3</a></x>") +-- xml.filter(x,"**/lowerall()") print(x) +-- xml.filter(x,"**/upperall()") print(x) + +function finalizers.lowerall(collected) + for c=1,#collected do + local e = collected[c] + if not e.special then + e.tg = lower(e.tg) + local eat = e.at + if eat then + local t = { } + for k,v in next, eat do + t[lower(k)] = v + end + e.at = t + end + end + end +end + +function finalizers.upperall(collected) + for c=1,#collected do + local e = collected[c] + if not e.special then + e.tg = upper(e.tg) + local eat = e.at + if eat then + local t = { } + for k,v in next, eat do + t[upper(k)] = v + end + e.at = t + end + end + end +end + end -- of closure diff --git a/scripts/context/ruby/base/tex.rb b/scripts/context/ruby/base/tex.rb index 2184447ce..8f5683985 100644 --- a/scripts/context/ruby/base/tex.rb +++ b/scripts/context/ruby/base/tex.rb @@ -74,7 +74,6 @@ class TEX @@backends = Hash.new @@mappaths = Hash.new @@runoptions = Hash.new - @@tcxflag = Hash.new @@draftoptions = Hash.new @@synctexcoptions = Hash.new @@texformats = Hash.new @@ -86,18 +85,18 @@ class TEX @@mpsprocstr = Hash.new @@texmethods = Hash.new @@mpsmethods = Hash.new - @@pdftex = 'pdftex' # new default, pdfetex is gone + @@pdftex = 'pdftex' @@platformslash = if System.unix? then "\\\\" else "\\" end - ['tex','etex','pdftex','pdfetex','standard'] .each do |e| @@texengines[e] = 'pdftex' end + ['tex','etex','pdftex','standard'] .each do |e| @@texengines[e] = 'pdftex' end ['aleph','omega'] .each do |e| @@texengines[e] = 'aleph' end ['xetex'] .each do |e| @@texengines[e] = 'xetex' end ['petex'] .each do |e| @@texengines[e] = 'petex' end ['metapost','mpost', 'standard'] .each do |e| @@mpsengines[e] = 'mpost' end - ['pdfetex','pdftex','pdf','pdftex','standard'] .each do |b| @@backends[b] = 'pdftex' end + ['pdftex','pdf','pdftex','standard'] .each do |b| @@backends[b] = 'pdftex' end ['dvipdfmx','dvipdfm','dpx','dpm'] .each do |b| @@backends[b] = 'dvipdfmx' end ['xetex','xtx'] .each do |b| @@backends[b] = 'xetex' end ['petex'] .each do |b| @@backends[b] = 'dvipdfmx' end @@ -108,7 +107,7 @@ class TEX ['xdv','xdv2pdf'] .each do |b| @@backends[b] = 'xdv2pdf' end ['tex','standard'] .each do |b| @@mappaths[b] = 'dvips' end - ['pdftex','pdfetex'] .each do |b| @@mappaths[b] = 'pdftex' end + ['pdftex'] .each do |b| @@mappaths[b] = 'pdftex' end ['aleph','omega','xetex','petex'] .each do |b| @@mappaths[b] = 'dvipdfmx' end ['dvipdfm', 'dvipdfmx', 'xdvipdfmx'] .each do |b| @@mappaths[b] = 'dvipdfmx' end ['xdv','xdv2pdf'] .each do |b| @@mappaths[b] = 'dvips' end @@ -131,8 +130,7 @@ class TEX ['plain','mpost'] .each do |f| @@mpsformats[f] = 'mpost' end ['metafun','context','standard'] .each do |f| @@mpsformats[f] = 'metafun' end - ['pdftex','pdfetex','aleph','omega','petex', - 'xetex'] .each do |p| @@prognames[p] = 'context' end + ['pdftex','aleph','omega','petex','xetex'] .each do |p| @@prognames[p] = 'context' end ['mpost'] .each do |p| @@prognames[p] = 'metafun' end ['latex','pdflatex'] .each do |p| @@prognames[p] = 'latex' end @@ -159,21 +157,13 @@ class TEX @@runoptions['aleph'] = ['--8bit'] @@runoptions['mpost'] = ['--8bit'] - @@runoptions['pdfetex'] = ['--8bit'] # obsolete - @@runoptions['pdftex'] = ['--8bit'] # pdftex is now pdfetex + @@runoptions['pdftex'] = ['--8bit'] # @@runoptions['petex'] = [] @@runoptions['xetex'] = ['--8bit','-output-driver="xdvipdfmx -E -d 4 -V 5"'] @@draftoptions['pdftex'] = ['--draftmode'] @@synctexcoptions['pdftex'] = ['--synctex=1'] @@synctexcoptions['xetex'] = ['--synctex=1'] - @@tcxflag['aleph'] = true - @@tcxflag['mpost'] = false - @@tcxflag['pdfetex'] = true - @@tcxflag['pdftex'] = true - @@tcxflag['petex'] = false - @@tcxflag['xetex'] = false - @@mainbooleanvars = [ 'batchmode', 'nonstopmode', 'fast', 'final', 'paranoid', 'notparanoid', 'nobanner', 'once', 'allpatterns', 'draft', @@ -423,7 +413,7 @@ class TEX def prefixed(format,engine) # format case engine - when /etex|pdftex|pdfetex|aleph|xetex/io then + when /etex|pdftex|aleph|xetex/io then "*#{format}" else format @@ -540,18 +530,21 @@ class TEX "--ini" end end - def tcxflag(engine) - if @@tcxflag[engine] then - file = "natural.tcx" - if Kpse.miktex? then - "-tcx=#{file}" - else - "-translate-file=#{file}" - end - else - "" - end - end + + # # obsolete + # + # def tcxflag(engine) + # if @@tcxflag[engine] then + # file = "natural.tcx" + # if Kpse.miktex? then + # "-tcx=#{file}" + # else + # "-translate-file=#{file}" + # end + # else + # "" + # end + # end def filestate(file) File.mtime(file).strftime("%d/%m/%Y %H:%M:%S") @@ -618,7 +611,7 @@ class TEX texformats.each do |texformat| report("generating tex format #{texformat}") progname = validprogname([getvariable('progname'),texformat,texengine]) - runcommand([quoted(texengine),prognameflag(progname),iniflag,tcxflag(texengine),prefixed(texformat,texengine),texmakeextras(texformat)]) + runcommand([quoted(texengine),prognameflag(progname),iniflag,prefixed(texformat,texengine),texmakeextras(texformat)]) end else report("unable to make format due to lack of permissions") @@ -643,7 +636,6 @@ class TEX mpsformats.each do |mpsformat| report("generating mps format #{mpsformat}") progname = validprogname([getvariable('progname'),mpsformat,mpsengine]) - # if not runcommand([quoted(mpsengine),prognameflag(progname),iniflag,tcxflag(mpsengine),runoptions(mpsengine),mpsformat,mpsmakeextras(mpsformat)]) then if not runcommand([quoted(mpsengine),prognameflag(progname),iniflag,runoptions(mpsengine),mpsformat,mpsmakeextras(mpsformat)]) then setvariable('error','no format made') end @@ -717,7 +709,7 @@ class TEX f.close if FileTest.file?(tempfilename('tex')) then format = File.basename(name) - engine = if name =~ /(pdftex|pdfetex|aleph|xetex)[\/\\]#{format}/ then $1 else '' end + engine = if name =~ /(pdftex|aleph|xetex)[\/\\]#{format}/ then $1 else '' end if engine.empty? then engineflag = "" else @@ -816,14 +808,14 @@ class TEX end end - private # will become baee/context + private # will become base/context @@preamblekeys = [ ['tex','texengine'], ['engine','texengine'], ['program','texengine'], - ['translate','tcxfilter'], - ['tcx','tcxfilter'], + # ['translate','tcxfilter'], + # ['tcx','tcxfilter'], ['output','backend'], ['mode','mode'], ['ctx','ctxfile'], @@ -1503,7 +1495,7 @@ end if texengine && texformat then fixbackendvars(@@mappaths[texengine]) progname = validprogname([getvariable('progname'),texformat,texengine]) - runcommand([quoted(texengine),prognameflag(progname),formatflag(texengine,texformat),tcxflag(texengine),runoptions(texengine),filename,texprocextras(texformat)]) + runcommand([quoted(texengine),prognameflag(progname),formatflag(texengine,texformat),runoptions(texengine),filename,texprocextras(texformat)]) else false end @@ -1517,7 +1509,6 @@ end ENV["MPXCOMMAND"] = "0" unless mpx progname = validprogname([getvariable('progname'),mpsformat,mpsengine]) mpname.gsub!(/\.mp$/,"") # temp bug in mp - # runcommand([quoted(mpsengine),prognameflag(progname),formatflag(mpsengine,mpsformat),tcxflag(mpsengine),runoptions(mpsengine),mpname,mpsprocextras(mpsformat)]) runcommand([quoted(mpsengine),prognameflag(progname),formatflag(mpsengine,mpsformat),runoptions(mpsengine),mpname,mpsprocextras(mpsformat)]) true else diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 335c4fcb9..a8bbca885 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -8112,7 +8112,7 @@ xml.tocdata(e,"error") </typing> --ldx]]-- -function xml.tocdata(e,wrapper) +function xml.tocdata(e,wrapper) -- a few more in the aux module local whatever = type(e) == "table" and xmltostring(e.dt) or e or "" if wrapper then whatever = format("<%s>%s</%s>",wrapper,whatever,wrapper) @@ -10095,6 +10095,36 @@ function xml.cdatatotext(e) end end +-- local x = xml.convert("<x><a>1<b>2</b>3</a></x>") +-- xml.texttocdata(xml.first(x,"a")) +-- print(x) -- <x><![CDATA[1<b>2</b>3]]></x> + +function xml.texttocdata(e) -- could be a finalizer + local dt = e.dt + local s = xml.tostring(dt) -- no shortcut? + e.tg = "@cd@" + e.special = true + e.ns = "" + e.rn = "" + e.dt = { s } + e.at = nil +end + +-- local x = xml.convert("<x><a>1<b>2</b>3</a></x>") +-- xml.tocdata(xml.first(x,"a")) +-- print(x) -- <x><![CDATA[<a>1<b>2</b>3</a>]]></x> + +function xml.elementtocdata(e) -- could be a finalizer + local dt = e.dt + local s = xml.tostring(e) -- no shortcut? + e.tg = "@cd@" + e.special = true + e.ns = "" + e.rn = "" + e.dt = { s } + e.at = nil +end + xml.builtinentities = table.tohash { "amp", "quot", "apos", "lt", "gt" } -- used often so share local entities = characters and characters.entities or nil @@ -10242,7 +10272,7 @@ if not modules then modules = { } end modules ['lxml-xml'] = { } local concat = table.concat -local find = string.find +local find, lower, upper = string.find, string.lower, string.upper local xml = xml @@ -10639,6 +10669,46 @@ function xml.textonly(e) -- no pattern return concat(textonly(e,{})) end +-- + +-- local x = xml.convert("<x><a x='+'>1<B>2</B>3</a></x>") +-- xml.filter(x,"**/lowerall()") print(x) +-- xml.filter(x,"**/upperall()") print(x) + +function finalizers.lowerall(collected) + for c=1,#collected do + local e = collected[c] + if not e.special then + e.tg = lower(e.tg) + local eat = e.at + if eat then + local t = { } + for k,v in next, eat do + t[lower(k)] = v + end + e.at = t + end + end + end +end + +function finalizers.upperall(collected) + for c=1,#collected do + local e = collected[c] + if not e.special then + e.tg = upper(e.tg) + local eat = e.at + if eat then + local t = { } + for k,v in next, eat do + t[upper(k)] = v + end + e.at = t + end + end + end +end + end -- of closure diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 335c4fcb9..a8bbca885 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -8112,7 +8112,7 @@ xml.tocdata(e,"error") </typing> --ldx]]-- -function xml.tocdata(e,wrapper) +function xml.tocdata(e,wrapper) -- a few more in the aux module local whatever = type(e) == "table" and xmltostring(e.dt) or e or "" if wrapper then whatever = format("<%s>%s</%s>",wrapper,whatever,wrapper) @@ -10095,6 +10095,36 @@ function xml.cdatatotext(e) end end +-- local x = xml.convert("<x><a>1<b>2</b>3</a></x>") +-- xml.texttocdata(xml.first(x,"a")) +-- print(x) -- <x><![CDATA[1<b>2</b>3]]></x> + +function xml.texttocdata(e) -- could be a finalizer + local dt = e.dt + local s = xml.tostring(dt) -- no shortcut? + e.tg = "@cd@" + e.special = true + e.ns = "" + e.rn = "" + e.dt = { s } + e.at = nil +end + +-- local x = xml.convert("<x><a>1<b>2</b>3</a></x>") +-- xml.tocdata(xml.first(x,"a")) +-- print(x) -- <x><![CDATA[<a>1<b>2</b>3</a>]]></x> + +function xml.elementtocdata(e) -- could be a finalizer + local dt = e.dt + local s = xml.tostring(e) -- no shortcut? + e.tg = "@cd@" + e.special = true + e.ns = "" + e.rn = "" + e.dt = { s } + e.at = nil +end + xml.builtinentities = table.tohash { "amp", "quot", "apos", "lt", "gt" } -- used often so share local entities = characters and characters.entities or nil @@ -10242,7 +10272,7 @@ if not modules then modules = { } end modules ['lxml-xml'] = { } local concat = table.concat -local find = string.find +local find, lower, upper = string.find, string.lower, string.upper local xml = xml @@ -10639,6 +10669,46 @@ function xml.textonly(e) -- no pattern return concat(textonly(e,{})) end +-- + +-- local x = xml.convert("<x><a x='+'>1<B>2</B>3</a></x>") +-- xml.filter(x,"**/lowerall()") print(x) +-- xml.filter(x,"**/upperall()") print(x) + +function finalizers.lowerall(collected) + for c=1,#collected do + local e = collected[c] + if not e.special then + e.tg = lower(e.tg) + local eat = e.at + if eat then + local t = { } + for k,v in next, eat do + t[lower(k)] = v + end + e.at = t + end + end + end +end + +function finalizers.upperall(collected) + for c=1,#collected do + local e = collected[c] + if not e.special then + e.tg = upper(e.tg) + local eat = e.at + if eat then + local t = { } + for k,v in next, eat do + t[upper(k)] = v + end + e.at = t + end + end + end +end + end -- of closure |