diff options
author | Hans Hagen <pragma@wxs.nl> | 2008-01-26 02:30:00 +0100 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2008-01-26 02:30:00 +0100 |
commit | e3467ba8810e788b01d8e7ce2e16d3c8ffdd3e2a (patch) | |
tree | 151358a831d39525db303351ed5bece56b2a7524 /scripts | |
parent | 000a8c62f8ab88f17964644ce3dd3fc2720fb345 (diff) | |
download | context-e3467ba8810e788b01d8e7ce2e16d3c8ffdd3e2a.tar.gz |
stable 2008.01.26 02:30
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/lua/luatools.lua | 206 | ||||
-rw-r--r-- | scripts/context/lua/mtx-context.lua | 4 | ||||
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 160 | ||||
-rw-r--r-- | scripts/context/ruby/ctxtools.rb | 10 |
4 files changed, 347 insertions, 33 deletions
diff --git a/scripts/context/lua/luatools.lua b/scripts/context/lua/luatools.lua index 099f254e5..165221fb4 100644 --- a/scripts/context/lua/luatools.lua +++ b/scripts/context/lua/luatools.lua @@ -1036,6 +1036,14 @@ function table.count(t) return n end +function table.swapped(t) + local s = { } + for k, v in pairs(t) do + s[v] = k + end + return s +end + --~ function table.are_equal(a,b) --~ return table.serialize(a) == table.serialize(b) --~ end @@ -1446,9 +1454,12 @@ function os.resultof(command) return io.popen(command,"r"):read("*all") end ---~ if not os.exec then -- still not ok +if not os.exec then -- still not ok os.exec = os.execute ---~ end +end +if not os.spawn then -- still not ok + os.spawn = os.execute +end function os.launch(str) if os.platform == "windows" then @@ -1551,6 +1562,10 @@ function file.basename(name) return name:match("^.+[/\\](.-)$") or name end +function file.nameonly(name) + return ((name:match("^.+[/\\](.-)$") or name):gsub("%..*$","")) +end + function file.extname(name) return name:match("^.+%.([^/\\]-)$") or "" end @@ -3310,22 +3325,121 @@ function input.unexpanded_path(instance,str) return file.join_path(input.unexpanded_path_list(instance,str)) end +--~ function input.expanded_path_list(instance,str) +--~ if not str then +--~ return { } +--~ elseif instance.savelists then +--~ -- engine+progname hash +--~ str = str:gsub("%$","") +--~ if not instance.lists[str] then -- cached +--~ local lst = input.split_path(input.expansion(instance,str)) +--~ instance.lists[str] = input.aux.expanded_path(instance,lst) +--~ end +--~ return instance.lists[str] +--~ else +--~ local lst = input.split_path(input.expansion(instance,str)) +--~ return input.aux.expanded_path(instance,lst) +--~ end +--~ end + +do + local done = { } + + function input.reset_extra_path(instance) + local ep = instance.extra_paths + if not ep then + ep, done = { }, { } + instance.extra_paths = ep + elseif #ep > 0 then + instance.lists, done = { }, { } + end + end + + function input.register_extra_path(instance,paths,subpaths) + if paths and paths ~= "" then + local ep = instance.extra_paths + if not ep then + ep = { } + instance.extra_paths = ep + end + local n = #ep + if subpath and subpaths ~= "" then + for p in paths:gmatch("[^,]+") do + for s in subpaths:gmatch("[^,]+") do + local ps = p .. "/" .. s + if not done[ps] then + ep[#ep+1] = input.clean_path(ps) + done[ps] = true + end + end + end + else + for p in paths:gmatch("[^,]+") do + if not done[p] then + ep[#ep+1] = input.clean_path(p) + done[p] = true + end + end + end + if n < #ep then + instance.lists = { } + end + end + end + +end + function input.expanded_path_list(instance,str) + local function made_list(list) + local ep = instance.extra_paths + if not ep or #ep == 0 then + return list + else + local done, new = { }, { } + -- honour . .. ../.. but only when at the start + for k, v in ipairs(list) do + if not done[v] then + if v:find("^[%.%/]$") then + done[v] = true + new[#new+1] = v + else + break + end + end + end + -- first the extra paths + for k, v in ipairs(ep) do + if not done[v] then + done[v] = true + new[#new+1] = v + end + end + -- next the formal paths + for k, v in ipairs(list) do + if not done[v] then + done[v] = true + new[#new+1] = v + end + end + return new + end + end if not str then - return { } + return ep or { } elseif instance.savelists then -- engine+progname hash str = str:gsub("%$","") if not instance.lists[str] then -- cached - local lst = input.split_path(input.expansion(instance,str)) + local lst = made_list(input.split_path(input.expansion(instance,str))) instance.lists[str] = input.aux.expanded_path(instance,lst) end return instance.lists[str] else local lst = input.split_path(input.expansion(instance,str)) - return input.aux.expanded_path(instance,lst) + return made_list(input.aux.expanded_path(instance,lst)) end end + function input.expand_path(instance,str) return file.join_path(input.expanded_path_list(instance,str)) end @@ -4192,7 +4306,11 @@ end function input.clean_path(str) --~ return (((str:gsub("\\","/")):gsub("^!+","")):gsub("//+","//")) - return ((str:gsub("\\","/")):gsub("^!+","")) + if str then + return ((str:gsub("\\","/")):gsub("^!+","")) + else + return nil + end end function input.do_with_path(name,func) @@ -4282,6 +4400,76 @@ end --~ print(table.serialize(input.aux.splitpathexpr("/usr/share/texmf-{texlive,tetex}", {}))) +-- command line resolver: + +--~ print(input.resolve("abc env:tmp file:cont-en.tex path:cont-en.tex full:cont-en.tex rel:zapf/one/p-chars.tex")) + +do + + local resolvers = { } + + resolvers.environment = function(instance,str) + return input.clean_path(os.getenv(str) or os.getenv(str:upper()) or os.getenv(str:lower()) or "") + end + resolvers.relative = function(instance,str,n) + if io.exists(str) then + -- nothing + elseif io.exists("./" .. str) then + str = "./" .. str + else + local p = "../" + for i=1,n or 2 do + if io.exists(p .. str) then + str = p .. str + break + else + p = p .. "../" + end + end + end + return input.clean_path(str) + end + resolvers.locate = function(instance,str) + local fullname = input.find_given_file(instance,str) or "" + return input.clean_path((fullname ~= "" and fullname) or str) + end + resolvers.filename = function(instance,str) + local fullname = input.find_given_file(instance,str) or "" + return input.clean_path(file.basename((fullname ~= "" and fullname) or str)) + end + resolvers.pathname = function(instance,str) + local fullname = input.find_given_file(instance,str) or "" + return input.clean_path(file.dirname((fullname ~= "" and fullname) or str)) + end + + resolvers.env = resolvers.environment + resolvers.rel = resolvers.relative + resolvers.loc = resolvers.locate + resolvers.kpse = resolvers.locate + resolvers.full = resolvers.locate + resolvers.file = resolvers.filename + resolvers.path = resolvers.pathname + + function resolve(instance,str) + if type(str) == "table" then + for k, v in pairs(str) do + str[k] = resolve(instance,v) or v + end + elseif str and str ~= "" then + str = str:gsub("([a-z]+):([^ ]+)", function(method,target) + if resolvers[method] then + return resolvers[method](instance,target) + else + return method .. ":" .. target + end + end) + end + return str + end + + input.resolve = resolve + +end if not modules then modules = { } end modules ['luat-tmp'] = { @@ -5911,7 +6099,8 @@ function input.my_make_format(instance,texname) -- flags[#flags+1] = "--mkii" -- web2c error flags[#flags+1] = "--progname=" .. instance.progname else - flags[#flags+1] = "--lua=" .. string.quote(luaname) + -- flags[#flags+1] = "--lua=" .. string.quote(luaname) + flags[#flags+1] = string.quote("--lua=" .. luaname) -- flags[#flags+1] = "--progname=" .. instance.progname -- potential fallback end local bs = (environment.platform == "unix" and "\\\\") or "\\" -- todo: make a function @@ -5951,7 +6140,8 @@ function input.my_run_format(instance,name,data,more) if f then f:close() -- bug, no .fmt ! - local command = "luatex --fmt=" .. string.quote(barename) .. " --lua=" .. string.quote(luaname) .. " " .. string.quote(data) .. " " .. string.quote(more) + -- local command = "luatex --fmt=" .. string.quote(barename) .. " --lua=" .. string.quote(luaname) .. " " .. string.quote(data) .. " " .. string.quote(more) + local command = "luatex " .. string.quote("--fmt=" .. barename) .. " " .. string.quote("--lua=" .. luaname) .. " " .. string.quote(data) .. " " .. string.quote(more) input.report("running command: " .. command) os.exec(command) else diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua index fbcad1111..9ecaa7198 100644 --- a/scripts/context/lua/mtx-context.lua +++ b/scripts/context/lua/mtx-context.lua @@ -600,8 +600,6 @@ function scripts.context.ctx() scripts.context.run(ctxdata) end -input.verbose = false - banner = banner .. " | context tools " messages.help = [[ @@ -621,7 +619,7 @@ elseif environment.argument("ctx") then scripts.context.ctx() elseif environment.argument("help") then input.help(banner,messages.help) -elseif environment.filename then +elseif environment.files[1] then scripts.context.run() else input.help(banner,messages.help) diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index a52d3e882..0b6720a4e 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -1050,6 +1050,14 @@ function table.count(t) return n end +function table.swapped(t) + local s = { } + for k, v in pairs(t) do + s[v] = k + end + return s +end + --~ function table.are_equal(a,b) --~ return table.serialize(a) == table.serialize(b) --~ end @@ -1480,9 +1488,12 @@ function os.resultof(command) return io.popen(command,"r"):read("*all") end ---~ if not os.exec then -- still not ok +if not os.exec then -- still not ok os.exec = os.execute ---~ end +end +if not os.spawn then -- still not ok + os.spawn = os.execute +end function os.launch(str) if os.platform == "windows" then @@ -1565,6 +1576,10 @@ function file.basename(name) return name:match("^.+[/\\](.-)$") or name end +function file.nameonly(name) + return ((name:match("^.+[/\\](.-)$") or name):gsub("%..*$","")) +end + function file.extname(name) return name:match("^.+%.([^/\\]-)$") or "" end @@ -3411,14 +3426,20 @@ do function xml.include(xmldata,pattern,attribute,recursive,findfile) -- parse="text" (default: xml), encoding="" (todo) - pattern = pattern or 'include' - attribute = attribute or 'href' + pattern = pattern or 'include' + -- attribute = attribute or 'href' local function include(r,d,k) local ek, name = d[k], nil - if ek.at then - for a in attribute:gmatch("([^|]+)") do - name = ek.at[a] - if name then break end + if not attribute or attribute == "" then + local ekdt = ek.dt + name = (type(ekdt) == "table" and ekdt[1]) or ekdt + end + if not name then + if ek.at then + for a in (attribute or "href"):gmatch("([^|]+)") do + name = ek.at[a] + if name then break end + end end end if name then @@ -3439,6 +3460,8 @@ do else xml.empty(d,k) end + else + xml.empty(d,k) end else xml.empty(d,k) @@ -5109,22 +5132,121 @@ function input.unexpanded_path(instance,str) return file.join_path(input.unexpanded_path_list(instance,str)) end +--~ function input.expanded_path_list(instance,str) +--~ if not str then +--~ return { } +--~ elseif instance.savelists then +--~ -- engine+progname hash +--~ str = str:gsub("%$","") +--~ if not instance.lists[str] then -- cached +--~ local lst = input.split_path(input.expansion(instance,str)) +--~ instance.lists[str] = input.aux.expanded_path(instance,lst) +--~ end +--~ return instance.lists[str] +--~ else +--~ local lst = input.split_path(input.expansion(instance,str)) +--~ return input.aux.expanded_path(instance,lst) +--~ end +--~ end + +do + local done = { } + + function input.reset_extra_path(instance) + local ep = instance.extra_paths + if not ep then + ep, done = { }, { } + instance.extra_paths = ep + elseif #ep > 0 then + instance.lists, done = { }, { } + end + end + + function input.register_extra_path(instance,paths,subpaths) + if paths and paths ~= "" then + local ep = instance.extra_paths + if not ep then + ep = { } + instance.extra_paths = ep + end + local n = #ep + if subpath and subpaths ~= "" then + for p in paths:gmatch("[^,]+") do + for s in subpaths:gmatch("[^,]+") do + local ps = p .. "/" .. s + if not done[ps] then + ep[#ep+1] = input.clean_path(ps) + done[ps] = true + end + end + end + else + for p in paths:gmatch("[^,]+") do + if not done[p] then + ep[#ep+1] = input.clean_path(p) + done[p] = true + end + end + end + if n < #ep then + instance.lists = { } + end + end + end + +end + function input.expanded_path_list(instance,str) + local function made_list(list) + local ep = instance.extra_paths + if not ep or #ep == 0 then + return list + else + local done, new = { }, { } + -- honour . .. ../.. but only when at the start + for k, v in ipairs(list) do + if not done[v] then + if v:find("^[%.%/]$") then + done[v] = true + new[#new+1] = v + else + break + end + end + end + -- first the extra paths + for k, v in ipairs(ep) do + if not done[v] then + done[v] = true + new[#new+1] = v + end + end + -- next the formal paths + for k, v in ipairs(list) do + if not done[v] then + done[v] = true + new[#new+1] = v + end + end + return new + end + end if not str then - return { } + return ep or { } elseif instance.savelists then -- engine+progname hash str = str:gsub("%$","") if not instance.lists[str] then -- cached - local lst = input.split_path(input.expansion(instance,str)) + local lst = made_list(input.split_path(input.expansion(instance,str))) instance.lists[str] = input.aux.expanded_path(instance,lst) end return instance.lists[str] else local lst = input.split_path(input.expansion(instance,str)) - return input.aux.expanded_path(instance,lst) + return made_list(input.aux.expanded_path(instance,lst)) end end + function input.expand_path(instance,str) return file.join_path(input.expanded_path_list(instance,str)) end @@ -5991,7 +6113,11 @@ end function input.clean_path(str) --~ return (((str:gsub("\\","/")):gsub("^!+","")):gsub("//+","//")) - return ((str:gsub("\\","/")):gsub("^!+","")) + if str then + return ((str:gsub("\\","/")):gsub("^!+","")) + else + return nil + end end function input.do_with_path(name,func) @@ -7191,12 +7317,11 @@ function input.runners.execute_script(instance,fullname,internal) result = binary .. " " .. result end local before, after = environment.split_arguments(fullname) - -- environment.initialize_arguments(after) - -- local command = result .. " " .. environment.reconstruct_commandline(environment.original_arguments) -- bugged local command = result .. " " .. environment.reconstruct_commandline(after) input.report("") input.report("executing: " .. command) input.report("\n \n") + io.flush() local code = os.exec(command) return code == 0 end @@ -7217,11 +7342,12 @@ function input.runners.execute_program(instance,fullname) local before, after = environment.split_arguments(fullname) environment.initialize_arguments(after) fullname = fullname:gsub("^bin:","") - local command = fullname .. " " .. environment.reconstruct_commandline(environment.original_arguments) + local command = fullname .. " " .. environment.reconstruct_commandline(after) input.report("") ---~ input.report("executing: " .. command) + input.report("executing: " .. command) input.report("\n \n") - local code = os.exec(command) + io.flush() + local code = os.exec(command) -- (fullname,unpack(after)) does not work return code == 0 end end diff --git a/scripts/context/ruby/ctxtools.rb b/scripts/context/ruby/ctxtools.rb index 598bfac20..4998b21b9 100644 --- a/scripts/context/ruby/ctxtools.rb +++ b/scripts/context/ruby/ctxtools.rb @@ -1608,8 +1608,8 @@ class Commands # ghyphen.readme ghyph31.readme grphyph @@languagedata['hr' ] = [ 'ec' , ['hrhyph.tex'] ] @@languagedata['hu' ] = [ 'ec' , ['huhyphn.tex'] ] - @@languagedata['en' ] = [ 'default' , ['ushyphmax.tex'],['ushyph.tex'],['hyphen.tex'] ] - @@languagedata['us' ] = [ 'default' , ['ushyphmax.tex'],['ushyph.tex'],['hyphen.tex'] ] + @@languagedata['en' ] = [ 'default' , [['ushyphmax.tex'],['ushyph.tex'],['hyphen.tex']] ] + @@languagedata['us' ] = [ 'default' , [['ushyphmax.tex'],['ushyph.tex'],['hyphen.tex']] ] # inhyph.tex @@languagedata['is' ] = [ 'ec' , ['ishyph.tex'] ] @@languagedata['it' ] = [ 'ec' , ['ithyph.tex'] ] @@ -1617,12 +1617,12 @@ class Commands # mnhyph @@languagedata['nl' ] = [ 'ec' , ['nehyph96.tex'] ] # @@languagedata['no' ] = [ 'ec' , ['nohyphbx.tex'],['nohyphb.tex'],['nohyph2.tex'],['nohyph1.tex'],['nohyph.tex'] ] - @@languagedata['no' ] = [ 'ec' , ['asxsx.tex','nohyphbx.tex'],['nohyphb.tex'],['nohyph2.tex'],['nohyph1.tex'],['nohyph.tex'] ] - @@languagedata['agr'] = [ 'agr' , [['grahyph4.tex','oldgrhyph.tex']] ] # new, todo + @@languagedata['no' ] = [ 'ec' , [['asxsx.tex','nohyphbx.tex'],['nohyphb.tex'],['nohyph2.tex'],['nohyph1.tex'],['nohyph.tex']] ] + @@languagedata['agr'] = [ 'agr' , [['grahyph4.tex'], ['oldgrhyph.tex']] ] # new, todo @@languagedata['pl' ] = [ 'ec' , ['plhyph.tex'] ] @@languagedata['pt' ] = [ 'ec' , ['pthyph.tex'] ] @@languagedata['ro' ] = [ 'ec' , ['rohyph.tex'] ] - @@languagedata['sl' ] = [ 'ec' , ['slhyph.tex'], ['sihyph.tex'] ] + @@languagedata['sl' ] = [ 'ec' , [['slhyph.tex'], ['sihyph.tex']] ] @@languagedata['sk' ] = [ 'ec' , ['skhyphen.tex','skhyphen.ex'] ] # sorhyph.tex / upper sorbian # srhyphc.tex / cyrillic |