diff options
author | Hans Hagen <pragma@wxs.nl> | 2008-03-24 23:24:00 +0100 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2008-03-24 23:24:00 +0100 |
commit | 55bcf0e607bb8af553581e74293687ed635bf877 (patch) | |
tree | 328adc5c0c28d46fd49369999d0b160c3d7582f8 /scripts | |
parent | 3bcf8de3c62348cb5526ddb37b3f4ea0f3d1df4f (diff) | |
download | context-55bcf0e607bb8af553581e74293687ed635bf877.tar.gz |
stable 2008.03.24 23:24
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/lua/luatools.lua | 88 | ||||
-rw-r--r-- | scripts/context/lua/mtx-update.lua | 1 | ||||
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 201 | ||||
-rw-r--r-- | scripts/context/ruby/base/tex.rb | 4 |
4 files changed, 213 insertions, 81 deletions
diff --git a/scripts/context/lua/luatools.lua b/scripts/context/lua/luatools.lua index 80291325c..2d146149e 100644 --- a/scripts/context/lua/luatools.lua +++ b/scripts/context/lua/luatools.lua @@ -1098,6 +1098,24 @@ function table.hexed(t,seperator) return table.concat(tt,seperator or " ") end +function table.reverse_hash(h) + local r = { } + for k,v in pairs(h) do + r[v] = (k:gsub(" ","")):lower() + end + return r +end + +function table.reverse(t) + local tt = { } + if #t > 0 then + for i=#t,1,-1 do + tt[#tt+1] = t[i] + end + end + return tt +end + -- filename : l-io.lua -- comment : split off from luat-lib @@ -1835,6 +1853,7 @@ if lfs then do if ok and type(scanner) == "function" then if not path:find("/$") then path = path .. '/' end for name in scanner do +print(name) local full = path .. name local mode = attributes(full,'mode') if mode == 'file' then @@ -1950,23 +1969,28 @@ if lfs then do end local first, middle, last local drive = false - first, last = str:match("^(//)/*(.-)$") + first, middle, last = str:match("^(//)(//*)(.*)$") if first then - middle, last = str:match("([^/]+)/+(.-)$") - if middle then - pth = "//" .. middle - else - pth = "//" .. last - last = "" - end + -- empty network path == local path else - first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$") + first, last = str:match("^(//)/*(.-)$") if first then - pth, drive = first .. middle, true + middle, last = str:match("([^/]+)/+(.-)$") + if middle then + pth = "//" .. middle + else + pth = "//" .. last + last = "" + end else - middle, last = str:match("^(/*)(.-)$") - if not middle then - last = str + first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$") + if first then + pth, drive = first .. middle, true + else + middle, last = str:match("^(/*)(.-)$") + if not middle then + last = str + end end end end @@ -1998,17 +2022,38 @@ if lfs then do --~ print(dir.mkdirs("a/bbb//ccc/")) function dir.expand_name(str) - local first, last = str:match("^(//)/*(.*)$") + local first, nothing, last = str:match("^(//)(//*)(.*)$") + if first then + first = lfs.currentdir() .. "/" + first = first:gsub("\\","/") + end + if not first then + first, last = str:match("^(//)/*(.*)$") + end if not first then first, last = str:match("^([a-zA-Z]:)(.*)$") + if first and not last:find("^/") then + local d = lfs.currentdir() + if lfs.chdir(first) then + first = lfs.currentdir() + first = first:gsub("\\","/") + end + lfs.chdir(d) + end end if not first then - first, last = lfs.currentdir() .. "/", str + first, last = lfs.currentdir(), str first = first:gsub("\\","/") end last = last:gsub("//","/") last = last:gsub("/%./","/") - return first .. last + last = last:gsub("^/*","") + first = first:gsub("/*$","") + if last == "" then + return first + else + return first .. "/" .. last + end end else @@ -4129,7 +4174,7 @@ function input.aux.find_file(instance,filename) -- todo : plugin (scanners, chec end -- this is actually 'other text files' or 'any' or 'whatever' local filelist = input.aux.collect_files(instance,wantedfiles) - local lf = filelist and filelist[1] + local fl = filelist and filelist[1] if fl then filename = fl[3] result[#result+1] = filename @@ -4890,9 +4935,10 @@ end -- here we use the cache for format loading (texconfig.[formatname|jobname]) -if tex and texconfig and texconfig.formatname and texconfig.formatname == "" then - if not texconfig.luaname then texconfig.luaname = "cont-en.lua" end - texconfig.formatname = caches.setpath(instance,"format") .. "/" .. texconfig.luaname:gsub("%.lu.$",".fmt") +--~ if tex and texconfig and texconfig.formatname and texconfig.formatname == "" then +if tex and texconfig and (not texconfig.formatname or texconfig.formatname == "") and texmf.instance then + if not texconfig.luaname then texconfig.luaname = "cont-en.lua" end -- or luc + texconfig.formatname = caches.setpath(texmf.instance,"formats") .. "/" .. texconfig.luaname:gsub("%.lu.$",".fmt") end --[[ldx-- @@ -5673,7 +5719,7 @@ if texconfig and not texlua then do ws("graphics processing time - %s seconds (n=%s) (including tex)", input.loadtime(figures), figures.n or "?") end if metapost then - ws("metapost processing time - %s seconds (+ loading: %s seconds)", input.loadtime(metapost), input.loadtime(mplib)) + ws("metapost processing time - %s seconds (loading: %s seconds, execution: %s seconds, n: %s)", input.loadtime(metapost), input.loadtime(mplib), input.loadtime(metapost.exectime), metapost.n) end if status.luastate_bytes then ws("current memory usage - %s bytes", status.luastate_bytes) diff --git a/scripts/context/lua/mtx-update.lua b/scripts/context/lua/mtx-update.lua index d2630f95c..4908db4da 100644 --- a/scripts/context/lua/mtx-update.lua +++ b/scripts/context/lua/mtx-update.lua @@ -127,6 +127,7 @@ scripts.update.platforms = { ["win32"] = "mswin", ["win"] = "mswin", ["linux"] = "linux", + ["freebsd"] = "freebsd", ["linux-32"] = "linux", ["linux-64"] = "linux-64", ["osx"] = "osx-intel", diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 9a9a68d38..aa78a553e 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -1112,6 +1112,24 @@ function table.hexed(t,seperator) return table.concat(tt,seperator or " ") end +function table.reverse_hash(h) + local r = { } + for k,v in pairs(h) do + r[v] = (k:gsub(" ","")):lower() + end + return r +end + +function table.reverse(t) + local tt = { } + if #t > 0 then + for i=#t,1,-1 do + tt[#tt+1] = t[i] + end + end + return tt +end + -- filename : l-io.lua -- comment : split off from luat-lib @@ -1736,18 +1754,68 @@ dir = { } if lfs then do +--~ local attributes = lfs.attributes +--~ local walkdir = lfs.dir +--~ +--~ local function glob_pattern(path,patt,recurse,action) +--~ local ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe +--~ if ok and type(scanner) == "function" then +--~ if not path:find("/$") then path = path .. '/' end +--~ for name in scanner do +--~ local full = path .. name +--~ local mode = attributes(full,'mode') +--~ if mode == 'file' then +--~ if name:find(patt) then +--~ action(full) +--~ end +--~ elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then +--~ glob_pattern(full,patt,recurse,action) +--~ end +--~ end +--~ end +--~ end +--~ +--~ dir.glob_pattern = glob_pattern +--~ +--~ local function glob(pattern, action) +--~ local t = { } +--~ local action = action or function(name) t[#t+1] = name end +--~ local path, patt = pattern:match("^(.*)/*%*%*/*(.-)$") +--~ local recurse = path and patt +--~ if not recurse then +--~ path, patt = pattern:match("^(.*)/(.-)$") +--~ if not (path and patt) then +--~ path, patt = '.', pattern +--~ end +--~ end +--~ patt = patt:gsub("([%.%-%+])", "%%%1") +--~ patt = patt:gsub("%*", ".*") +--~ patt = patt:gsub("%?", ".") +--~ patt = "^" .. patt .. "$" +--~ -- print('path: ' .. path .. ' | pattern: ' .. patt .. ' | recurse: ' .. tostring(recurse)) +--~ glob_pattern(path,patt,recurse,action) +--~ return t +--~ end +--~ +--~ dir.glob = glob + local attributes = lfs.attributes local walkdir = lfs.dir local function glob_pattern(path,patt,recurse,action) - local ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe + local ok, scanner + if path == "/" then + ok, scanner = xpcall(function() return walkdir(path..".") end, function() end) -- kepler safe + else + ok, scanner = xpcall(function() return walkdir(path) end, function() end) -- kepler safe + end if ok and type(scanner) == "function" then if not path:find("/$") then path = path .. '/' end for name in scanner do local full = path .. name local mode = attributes(full,'mode') if mode == 'file' then - if name:find(patt) then + if full:find(patt) then action(full) end elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then @@ -1761,29 +1829,36 @@ if lfs then do local function glob(pattern, action) local t = { } - local action = action or function(name) table.insert(t,name) end - local path, patt = pattern:match("^(.*)/*%*%*/*(.-)$") - local recurse = path and patt - if not recurse then - path, patt = pattern:match("^(.*)/(.-)$") - if not (path and patt) then - path, patt = '.', pattern - end - end - patt = patt:gsub("([%.%-%+])", "%%%1") - patt = patt:gsub("%*", ".*") - patt = patt:gsub("%?", ".") - patt = "^" .. patt .. "$" - -- print('path: ' .. path .. ' | pattern: ' .. patt .. ' | recurse: ' .. tostring(recurse)) + local path, rest, patt, recurse + local action = action or function(name) t[#t+1] = name end + local pattern = pattern:gsub("^%*%*","./**") + local pattern = pattern:gsub("/%*/","/**/") + path, rest = pattern:match("^(/)(.-)$") + if path then + path = path + else + path, rest = pattern:match("^([^/]*)/(.-)$") + end + patt = rest:gsub("([%.%-%+])", "%%%1") + patt = patt:gsub("%*", "[^/]*") + patt = patt:gsub("%?", "[^/]") + patt = patt:gsub("%[%^/%]%*%[%^/%]%*", ".*") + if path == "" then path = "." end + -- print(pattern, path, patt) + recurse = patt:find("%.%*/") glob_pattern(path,patt,recurse,action) return t end dir.glob = glob - -- todo: speedup + --~ list = dir.glob("**/*.tif") + --~ list = dir.glob("/**/*.tif") + --~ list = dir.glob("./**/*.tif") + --~ list = dir.glob("oeps/**/*.tif") + --~ list = dir.glob("/oeps/**/*.tif") - local function globfiles(path,recurse,func,files) + local function globfiles(path,recurse,func,files) -- func == pattern or function if type(func) == "string" then local s = func -- alas, we need this indirect way func = function(name) return name:find(s) end @@ -1825,23 +1900,6 @@ if lfs then do --~ mkdirs(".","/a/b/c") --~ mkdirs("a","b","c") ---~ function dir.mkdirs(...) ---~ local pth, err, lst = "", false, table.concat({...},"/") ---~ for _, s in ipairs(lst:split("/")) do ---~ if pth == "" then ---~ pth = (s == "" and "/") or s ---~ else ---~ pth = pth .. "/" .. s ---~ end ---~ if s == "" then ---~ -- can be network path ---~ elseif not lfs.isdir(pth) then ---~ lfs.mkdir(pth) ---~ end ---~ end ---~ return pth, not err ---~ end - local make_indeed = true -- false if string.find(os.getenv("PATH"),";") then @@ -1859,23 +1917,28 @@ if lfs then do end local first, middle, last local drive = false - first, last = str:match("^(//)/*(.-)$") + first, middle, last = str:match("^(//)(//*)(.*)$") if first then - middle, last = str:match("([^/]+)/+(.-)$") - if middle then - pth = "//" .. middle - else - pth = "//" .. last - last = "" - end + -- empty network path == local path else - first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$") + first, last = str:match("^(//)/*(.-)$") if first then - pth, drive = first .. middle, true + middle, last = str:match("([^/]+)/+(.-)$") + if middle then + pth = "//" .. middle + else + pth = "//" .. last + last = "" + end else - middle, last = str:match("^(/*)(.-)$") - if not middle then - last = str + first, middle, last = str:match("^([a-zA-Z]:)(/*)(.-)$") + if first then + pth, drive = first .. middle, true + else + middle, last = str:match("^(/*)(.-)$") + if not middle then + last = str + end end end end @@ -1907,17 +1970,38 @@ if lfs then do --~ print(dir.mkdirs("a/bbb//ccc/")) function dir.expand_name(str) - local first, last = str:match("^(//)/*(.*)$") + local first, nothing, last = str:match("^(//)(//*)(.*)$") + if first then + first = lfs.currentdir() .. "/" + first = first:gsub("\\","/") + end + if not first then + first, last = str:match("^(//)/*(.*)$") + end if not first then first, last = str:match("^([a-zA-Z]:)(.*)$") + if first and not last:find("^/") then + local d = lfs.currentdir() + if lfs.chdir(first) then + first = lfs.currentdir() + first = first:gsub("\\","/") + end + lfs.chdir(d) + end end if not first then - first, last = lfs.currentdir() .. "/", str + first, last = lfs.currentdir(), str first = first:gsub("\\","/") end last = last:gsub("//","/") last = last:gsub("/%./","/") - return first .. last + last = last:gsub("^/*","") + first = first:gsub("/*$","") + if last == "" then + return first + else + return first .. "/" .. last + end end else @@ -3072,7 +3156,7 @@ do end else if (command == 16 or command == 12) and index == 1 then -- initial ---~ wildcard = true + -- wildcard = true wildcard = command == 16 -- ok? index = index + 1 action = pattern[index] @@ -3178,8 +3262,8 @@ do if matched then -- combine tg test and at test if index == #pattern then if handle(root,rootdt,root.ri or k) then return false end - if wildcard and multiple then ---~ if wildcard or multiple then +--~ if wildcard and multiple then +if wildcard or multiple then if not traverse(e,pattern,handle,reverse,index,root,true) then return false end end else @@ -5842,7 +5926,7 @@ function input.aux.find_file(instance,filename) -- todo : plugin (scanners, chec end -- this is actually 'other text files' or 'any' or 'whatever' local filelist = input.aux.collect_files(instance,wantedfiles) - local lf = filelist and filelist[1] + local fl = filelist and filelist[1] if fl then filename = fl[3] result[#result+1] = filename @@ -6603,9 +6687,10 @@ end -- here we use the cache for format loading (texconfig.[formatname|jobname]) -if tex and texconfig and texconfig.formatname and texconfig.formatname == "" then - if not texconfig.luaname then texconfig.luaname = "cont-en.lua" end - texconfig.formatname = caches.setpath(instance,"format") .. "/" .. texconfig.luaname:gsub("%.lu.$",".fmt") +--~ if tex and texconfig and texconfig.formatname and texconfig.formatname == "" then +if tex and texconfig and (not texconfig.formatname or texconfig.formatname == "") and texmf.instance then + if not texconfig.luaname then texconfig.luaname = "cont-en.lua" end -- or luc + texconfig.formatname = caches.setpath(texmf.instance,"formats") .. "/" .. texconfig.luaname:gsub("%.lu.$",".fmt") end --[[ldx-- diff --git a/scripts/context/ruby/base/tex.rb b/scripts/context/ruby/base/tex.rb index 02683bd60..bf2f92547 100644 --- a/scripts/context/ruby/base/tex.rb +++ b/scripts/context/ruby/base/tex.rb @@ -577,7 +577,7 @@ class TEX if data = (IO.readlines(@@luafiles) rescue nil) then report("compiling lua files (using #{File.expand_path(@@luafiles)})") begin - Dir.makedirs(@@luatarget) rescue false + File.makedirs(@@luatarget) rescue false data.each do |line| luafile = line.chomp lucfile = File.basename(luafile).gsub(/\..*?$/,'') + ".luc" @@ -2057,7 +2057,7 @@ end setvariable('mp.line','') setvariable('mp.error','') if mpdata = File.silentread(mpname) then - mpdata.gsub!(/^\#.*\n/o,'') + mpdata.gsub!(/^\%.*\n/o,'') File.silentrename(mpname,mpcopy) texfound = mergebe || (mpdata =~ /btex .*? etex/mo) if mp = openedfile(mpname) then |