diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/lua/mtx-convert.lua | 87 | ||||
-rw-r--r-- | scripts/context/lua/mtx-fonts.lua | 1 | ||||
-rw-r--r-- | scripts/context/lua/mtx-update.lua | 2 | ||||
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 121 | ||||
-rw-r--r-- | scripts/context/stubs/mswin/mtxrun.lua | 121 | ||||
-rwxr-xr-x | scripts/context/stubs/unix/mtxrun | 121 |
6 files changed, 281 insertions, 172 deletions
diff --git a/scripts/context/lua/mtx-convert.lua b/scripts/context/lua/mtx-convert.lua index 0c5c01bbf..b4e6e010b 100644 --- a/scripts/context/lua/mtx-convert.lua +++ b/scripts/context/lua/mtx-convert.lua @@ -23,16 +23,27 @@ local application = logs.application { helpinfo = helpinfo, } +local format, find = string.format, string.find +local concat = table.concat + local report = application.report -graphics = graphics or { } -graphics.converters = graphics.converters or { } +scripts = scripts or { } +scripts.convert = scripts.convert or { } +local convert = scripts.convert +convert.converters = convert.converters or { } +local converters = convert.converters + +local gsprogram = (os.type == "windows" and "gswin32c") or "gs" +local gstemplate_eps = "%s -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dEPSCrop -dNOPAUSE -dSAFER -dNOCACHE -dBATCH -dAutoRotatePages=/None -dProcessColorModel=/DeviceCMYK -sOutputFile=%s %s -c quit" +local gstemplate_ps = "%s -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dNOPAUSE -dSAFER -dNOCACHE -dBATCH -dAutoRotatePages=/None -dProcessColorModel=/DeviceCMYK -sOutputFile=%s %s -c quit" -local gsprogram = (os.type == "windows" and "gswin32c") or "gs" -local gstemplate = "%s -q -sDEVICE=pdfwrite -dEPSCrop -dNOPAUSE -dNOCACHE -dBATCH -dAutoRotatePages=/None -dProcessColorModel=/DeviceCMYK -sOutputFile=%s %s -c quit" +function converters.eps(oldname,newname) + return format(gstemplate_eps,gsprogram,newname,oldname) +end -function graphics.converters.eps(oldname,newname) - return gstemplate:format(gsprogram,newname,oldname) +function converters.ps(oldname,newname) + return format(gstemplate_ps,gsprogram,newname,oldname) end local improgram = "convert" @@ -42,21 +53,21 @@ local imtemplate = { high = "%s -quality 100 -compress zip %s pdf:%s", } -function graphics.converters.jpg(oldname,newname) +function converters.jpg(oldname,newname) local ea = environment.arguments local quality = (ea.high and 'high') or (ea.medium and 'medium') or (ea.low and 'low') or 'high' - return imtemplate[quality]:format(improgram,oldname,newname) + return format(imtemplate[quality],improgram,oldname,newname) end -graphics.converters.gif = graphics.converters.jpg -graphics.converters.tif = graphics.converters.jpg -graphics.converters.tiff = graphics.converters.jpg -graphics.converters.png = graphics.converters.jpg +converters.gif = converters.jpg +converters.tif = converters.jpg +converters.tiff = converters.jpg +converters.png = converters.jpg -local function convert(kind,oldname,newname) - if graphics.converters[kind] then -- extra test +function converters.convertgraphic(kind,oldname,newname) + if converters[kind] then -- extra test local tmpname = file.replacesuffix(newname,"tmp") - local command = graphics.converters[kind](oldname,tmpname) + local command = converters[kind](oldname,tmpname) report("command: %s",command) io.flush() os.spawn(command) @@ -68,58 +79,62 @@ local function convert(kind,oldname,newname) end end -function graphics.converters.convertpath(inputpath,outputpath) +function converters.convertpath(inputpath,outputpath) inputpath = inputpath or "." outputpath = outputpath or "." for name in lfs.dir(inputpath) do local suffix = file.extname(name) - if name:find("%.$") then + if find(name,"%.$") then -- skip . and .. - elseif graphics.converters[suffix] then + elseif converters[suffix] then local oldname = file.join(inputpath,name) local newname = file.join(outputpath,file.replacesuffix(name,"pdf")) local et = lfs.attributes(oldname,"modification") local pt = lfs.attributes(newname,"modification") if not pt or et > pt then dir.mkdirs(outputpath) - convert(suffix,oldname,newname) + converters.convertgraphic(suffix,oldname,newname) end elseif lfs.isdir(inputpath .. "/".. name) then - graphics.converters.convertpath(inputpath .. "/".. name,outputpath .. "/".. name) + converters.convertpath(inputpath .. "/".. name,outputpath .. "/".. name) end end end -function graphics.converters.convertfile(oldname) +function converters.convertfile(oldname) local suffix = file.extname(oldname) - if graphics.converters[suffix] then - local newname = file.replacesuffix(name,"pdf") + if converters[suffix] then + local newname = file.replacesuffix(oldname,"pdf") if oldname == newname then -- todo: downsample, crop etc elseif environment.argument("force") then - convert(suffix,oldname,newname) + converters.convertgraphic(suffix,oldname,newname) else local et = lfs.attributes(oldname,"modification") local pt = lfs.attributes(newname,"modification") if not pt or et > pt then - convert(suffix,oldname,newname) + converters.convertgraphic(suffix,oldname,newname) end end end end -scripts = scripts or { } -scripts.convert = scripts.convert or { } +if environment.ownscript then + -- stand alone +else + report(application.banner) + return convert +end -scripts.convert.delay = 5 * 60 -- 5 minutes +convert.delay = 5 * 60 -- 5 minutes -function scripts.convert.convertall() +function convert.convertall() local watch = environment.arguments.watch or false - local delay = environment.arguments.delay or scripts.convert.delay + local delay = environment.arguments.delay or convert.delay local input = environment.arguments.inputpath or "." local output = environment.arguments.outputpath or "." while true do - graphics.converters.convertpath(input, output) + converters.convertpath(input, output) if watch then os.sleep(delay) else @@ -128,17 +143,17 @@ function scripts.convert.convertall() end end -function scripts.convert.convertgiven() +function convert.convertgiven() local files = environment.files for i=1,#files do - graphics.converters.convertfile(files[i]) + converters.convertfile(files[i]) end end -if environment.argument("convertall") then - scripts.convert.convertall() +if environment.arguments.convertall then + convert.convertall() elseif environment.files[1] then - scripts.convert.convertgiven() + convert.convertgiven() else application.help() end diff --git a/scripts/context/lua/mtx-fonts.lua b/scripts/context/lua/mtx-fonts.lua index 90fa1b03e..c5b458c14 100644 --- a/scripts/context/lua/mtx-fonts.lua +++ b/scripts/context/lua/mtx-fonts.lua @@ -8,6 +8,7 @@ if not modules then modules = { } end modules ['mtx-fonts'] = { local helpinfo = [[ --save save open type font in raw table +--unpack save a tma file in a more readale format --reload generate new font database --reload --simple generate 'luatex-fonts-names.lua' (not for context!) diff --git a/scripts/context/lua/mtx-update.lua b/scripts/context/lua/mtx-update.lua index 2b8c06f0a..cb12b99ce 100644 --- a/scripts/context/lua/mtx-update.lua +++ b/scripts/context/lua/mtx-update.lua @@ -344,7 +344,7 @@ function scripts.update.synchronize() destination = gsub(destination,"\\","/") archive = gsub(archive,"<version>",version) if osplatform == "windows" or osplatform == "mswin" then - destination = gsub(destination,"([a-zA-Z]):/", "/cygdrive/%1/") + destination = gsub(destination,"([a-zA-Z]):/", "/cygdrive/%1/") -- ^ end individual[#individual+1] = { archive, destination } end diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index fc4e81d1c..6ac5a5ce5 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -1112,6 +1112,9 @@ if not modules then modules = { } end modules ['l-lpeg'] = { license = "see context related readme files" } + +-- a new lpeg fails on a #(1-P(":")) test and really needs a + P(-1) + local lpeg = require("lpeg") -- tracing (only used when we encounter a problem in integration of lpeg in luatex) @@ -1148,7 +1151,7 @@ patterns.alwaysmatched = alwaysmatched local digit, sign = R('09'), S('+-') local cr, lf, crlf = P("\r"), P("\n"), P("\r\n") -local newline = crlf + cr + lf +local newline = crlf + S("\r\n") -- cr + lf local escaped = P("\\") * anything local squote = P("'") local dquote = P('"') @@ -1668,8 +1671,6 @@ function lpeg.append(list,pp,delayed) end - - end -- of closure do -- create closure to overcome 200 locals limit @@ -7425,18 +7426,15 @@ alternative.</p> function xml.checkbom(root) -- can be made faster if root.ri then - local dt, found = root.dt, false + local dt = root.dt for k=1,#dt do local v = dt[k] if type(v) == "table" and v.special and v.tg == "@pi@" and find(v.dt[1],"xml.*version=") then - found = true - break + return end end - if not found then - insert(dt, 1, { special=true, ns="", tg="@pi@", dt = { "xml version='1.0' standalone='yes'"} } ) - insert(dt, 2, "\n" ) - end + insert(dt, 1, { special=true, ns="", tg="@pi@", dt = { "xml version='1.0' standalone='yes'"} } ) + insert(dt, 2, "\n" ) end end @@ -8547,7 +8545,10 @@ local special_1 = P("*") * Cc(register_auto_descendant) * Cc(register_all_nodes local special_2 = P("/") * Cc(register_auto_self) local special_3 = P("") * Cc(register_auto_self) -local pathparser = Ct { "patterns", -- can be made a bit faster by moving pattern outside +local no_nextcolon = P(-1) + #(1-P(":")) -- newer lpeg needs the P(-1) +local no_nextlparent = P(-1) + #(1-P("(")) -- newer lpeg needs the P(-1) + +local pathparser = Ct { "patterns", -- can be made a bit faster by moving some patterns outside patterns = spaces * V("protocol") * spaces * ( ( V("special") * spaces * P(-1) ) + @@ -8576,10 +8577,8 @@ local pathparser = Ct { "patterns", -- can be made a bit faster by moving patter shortcuts = V("shortcuts_a") * (spaces * "/" * spaces * V("shortcuts_a"))^0, s_descendant_or_self = (P("***/") + P("/")) * Cc(register_descendant_or_self), --- *** is a bonus - -- s_descendant_or_self = P("/") * Cc(register_descendant_or_self), s_descendant = P("**") * Cc(register_descendant), - s_child = P("*") * #(1-P(":")) * Cc(register_child ), --- s_child = P("*") * #(P("/")+P(-1)) * Cc(register_child ), + s_child = P("*") * no_nextcolon * Cc(register_child ), s_parent = P("..") * Cc(register_parent ), s_self = P("." ) * Cc(register_self ), s_root = P("^^") * Cc(register_root ), @@ -8606,13 +8605,13 @@ local pathparser = Ct { "patterns", -- can be made a bit faster by moving patter expressions = expression / register_expression, letters = R("az")^1, - name = (1-lpeg.S("/[]()|:*!"))^1, + name = (1-lpeg.S("/[]()|:*!"))^1, -- make inline negate = P("!") * Cc(false), nodefunction = V("negate") + P("not") * Cc(false) + Cc(true), nodetest = V("negate") + Cc(true), nodename = (V("negate") + Cc(true)) * spaces * ((V("wildnodename") * P(":") * V("wildnodename")) + (Cc(false) * V("wildnodename"))), - wildnodename = (C(V("name")) + P("*") * Cc(false)) * #(1-P("(")), + wildnodename = (C(V("name")) + P("*") * Cc(false)) * no_nextlparent, nodeset = spaces * Ct(V("nodename") * (spaces * P("|") * spaces * V("nodename"))^0) * spaces, finalizer = (Cb("protocol") * P("/")^-1 * C(V("name")) * arguments * P(-1)) / register_finalizer, @@ -10522,41 +10521,73 @@ end -- {a,b,c/{p,q/{x,y,z},w}v,d/{p,q,r}} -- {$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c} -local cleanup = lpeg.replacer { - { "!" , "" }, - { "\\" , "/" }, -} - -local homedir +-- local cleanup = lpeg.replacer { +-- { "!" , "" }, +-- { "\\" , "/" }, +-- } +-- +-- local homedir +-- +-- function resolvers.cleanpath(str) -- tricky, maybe only simple paths +-- if not homedir then +-- homedir = lpegmatch(cleanup,environment.homedir or "") +-- if homedir == char(127) or homedir == "" or not lfs.isdir(homedir) then +-- if trace_expansions then +-- report_expansions("no home dir set, ignoring dependent paths") +-- end +-- function resolvers.cleanpath(str) +-- if find(str,"~") then +-- return "" -- special case +-- else +-- return str and lpegmatch(cleanup,str) +-- end +-- end +-- else +-- cleanup = lpeg.replacer { +-- { "!" , "" }, +-- { "\\" , "/" }, +-- { "~" , homedir }, +-- } +-- function resolvers.cleanpath(str) +-- return str and lpegmatch(cleanup,str) +-- end +-- end +-- end +-- return resolvers.cleanpath(str) +-- end -function resolvers.cleanpath(str) - if not homedir then - homedir = lpegmatch(cleanup,environment.homedir or "") - if homedir == char(127) or homedir == "" or not lfs.isdir(homedir) then - if trace_expansions then - report_expansions("no home dir set, ignoring dependent paths") - end - function resolvers.cleanpath(str) - if find(str,"~") then - return "" -- special case - else - return str and lpegmatch(cleanup,str) - end - end - else - cleanup = lpeg.replacer { - { "!" , "" }, - { "\\" , "/" }, - { "~" , homedir }, - } - function resolvers.cleanpath(str) - return str and lpegmatch(cleanup,str) +function resolvers.cleanpath(str) -- tricky, maybe only simple paths + local doslashes = (P("\\")/"/" + 1)^0 + local donegation = (P("!") /"" )^0 + local homedir = lpegmatch(Cs(donegation * doslashes),environment.homedir or "") + if homedir == "~" or homedir == "" or not lfs.isdir(homedir) then + if trace_expansions then + report_expansions("no home dir set, ignoring dependent paths") + end + function resolvers.cleanpath(str) + if not str or find(str,"~") then + return "" -- special case + else + return lpegmatch(cleanup,str) end end + else + local dohome = ((P("~")+P("$HOME"))/homedir)^0 + local cleanup = Cs(donegation * dohome * doslashes) + function resolvers.cleanpath(str) + return str and lpegmatch(cleanup,str) or "" + end end return resolvers.cleanpath(str) end +-- print(resolvers.cleanpath("")) +-- print(resolvers.cleanpath("!")) +-- print(resolvers.cleanpath("~")) +-- print(resolvers.cleanpath("~/test")) +-- print(resolvers.cleanpath("!~/test")) +-- print(resolvers.cleanpath("~/test~test")) + -- This one strips quotes and funny tokens. local expandhome = P("~") / "$HOME" -- environment.homedir @@ -13338,7 +13369,7 @@ end prefixes.filename = function(str) local fullname = findgivenfile(str) or "" - return cleanpath(file.basename((fullname ~= "" and fullname) or str)) + return cleanpath(file.basename((fullname ~= "" and fullname) or str)) -- no cleanpath needed here end prefixes.pathname = function(str) diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index fc4e81d1c..6ac5a5ce5 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -1112,6 +1112,9 @@ if not modules then modules = { } end modules ['l-lpeg'] = { license = "see context related readme files" } + +-- a new lpeg fails on a #(1-P(":")) test and really needs a + P(-1) + local lpeg = require("lpeg") -- tracing (only used when we encounter a problem in integration of lpeg in luatex) @@ -1148,7 +1151,7 @@ patterns.alwaysmatched = alwaysmatched local digit, sign = R('09'), S('+-') local cr, lf, crlf = P("\r"), P("\n"), P("\r\n") -local newline = crlf + cr + lf +local newline = crlf + S("\r\n") -- cr + lf local escaped = P("\\") * anything local squote = P("'") local dquote = P('"') @@ -1668,8 +1671,6 @@ function lpeg.append(list,pp,delayed) end - - end -- of closure do -- create closure to overcome 200 locals limit @@ -7425,18 +7426,15 @@ alternative.</p> function xml.checkbom(root) -- can be made faster if root.ri then - local dt, found = root.dt, false + local dt = root.dt for k=1,#dt do local v = dt[k] if type(v) == "table" and v.special and v.tg == "@pi@" and find(v.dt[1],"xml.*version=") then - found = true - break + return end end - if not found then - insert(dt, 1, { special=true, ns="", tg="@pi@", dt = { "xml version='1.0' standalone='yes'"} } ) - insert(dt, 2, "\n" ) - end + insert(dt, 1, { special=true, ns="", tg="@pi@", dt = { "xml version='1.0' standalone='yes'"} } ) + insert(dt, 2, "\n" ) end end @@ -8547,7 +8545,10 @@ local special_1 = P("*") * Cc(register_auto_descendant) * Cc(register_all_nodes local special_2 = P("/") * Cc(register_auto_self) local special_3 = P("") * Cc(register_auto_self) -local pathparser = Ct { "patterns", -- can be made a bit faster by moving pattern outside +local no_nextcolon = P(-1) + #(1-P(":")) -- newer lpeg needs the P(-1) +local no_nextlparent = P(-1) + #(1-P("(")) -- newer lpeg needs the P(-1) + +local pathparser = Ct { "patterns", -- can be made a bit faster by moving some patterns outside patterns = spaces * V("protocol") * spaces * ( ( V("special") * spaces * P(-1) ) + @@ -8576,10 +8577,8 @@ local pathparser = Ct { "patterns", -- can be made a bit faster by moving patter shortcuts = V("shortcuts_a") * (spaces * "/" * spaces * V("shortcuts_a"))^0, s_descendant_or_self = (P("***/") + P("/")) * Cc(register_descendant_or_self), --- *** is a bonus - -- s_descendant_or_self = P("/") * Cc(register_descendant_or_self), s_descendant = P("**") * Cc(register_descendant), - s_child = P("*") * #(1-P(":")) * Cc(register_child ), --- s_child = P("*") * #(P("/")+P(-1)) * Cc(register_child ), + s_child = P("*") * no_nextcolon * Cc(register_child ), s_parent = P("..") * Cc(register_parent ), s_self = P("." ) * Cc(register_self ), s_root = P("^^") * Cc(register_root ), @@ -8606,13 +8605,13 @@ local pathparser = Ct { "patterns", -- can be made a bit faster by moving patter expressions = expression / register_expression, letters = R("az")^1, - name = (1-lpeg.S("/[]()|:*!"))^1, + name = (1-lpeg.S("/[]()|:*!"))^1, -- make inline negate = P("!") * Cc(false), nodefunction = V("negate") + P("not") * Cc(false) + Cc(true), nodetest = V("negate") + Cc(true), nodename = (V("negate") + Cc(true)) * spaces * ((V("wildnodename") * P(":") * V("wildnodename")) + (Cc(false) * V("wildnodename"))), - wildnodename = (C(V("name")) + P("*") * Cc(false)) * #(1-P("(")), + wildnodename = (C(V("name")) + P("*") * Cc(false)) * no_nextlparent, nodeset = spaces * Ct(V("nodename") * (spaces * P("|") * spaces * V("nodename"))^0) * spaces, finalizer = (Cb("protocol") * P("/")^-1 * C(V("name")) * arguments * P(-1)) / register_finalizer, @@ -10522,41 +10521,73 @@ end -- {a,b,c/{p,q/{x,y,z},w}v,d/{p,q,r}} -- {$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c} -local cleanup = lpeg.replacer { - { "!" , "" }, - { "\\" , "/" }, -} - -local homedir +-- local cleanup = lpeg.replacer { +-- { "!" , "" }, +-- { "\\" , "/" }, +-- } +-- +-- local homedir +-- +-- function resolvers.cleanpath(str) -- tricky, maybe only simple paths +-- if not homedir then +-- homedir = lpegmatch(cleanup,environment.homedir or "") +-- if homedir == char(127) or homedir == "" or not lfs.isdir(homedir) then +-- if trace_expansions then +-- report_expansions("no home dir set, ignoring dependent paths") +-- end +-- function resolvers.cleanpath(str) +-- if find(str,"~") then +-- return "" -- special case +-- else +-- return str and lpegmatch(cleanup,str) +-- end +-- end +-- else +-- cleanup = lpeg.replacer { +-- { "!" , "" }, +-- { "\\" , "/" }, +-- { "~" , homedir }, +-- } +-- function resolvers.cleanpath(str) +-- return str and lpegmatch(cleanup,str) +-- end +-- end +-- end +-- return resolvers.cleanpath(str) +-- end -function resolvers.cleanpath(str) - if not homedir then - homedir = lpegmatch(cleanup,environment.homedir or "") - if homedir == char(127) or homedir == "" or not lfs.isdir(homedir) then - if trace_expansions then - report_expansions("no home dir set, ignoring dependent paths") - end - function resolvers.cleanpath(str) - if find(str,"~") then - return "" -- special case - else - return str and lpegmatch(cleanup,str) - end - end - else - cleanup = lpeg.replacer { - { "!" , "" }, - { "\\" , "/" }, - { "~" , homedir }, - } - function resolvers.cleanpath(str) - return str and lpegmatch(cleanup,str) +function resolvers.cleanpath(str) -- tricky, maybe only simple paths + local doslashes = (P("\\")/"/" + 1)^0 + local donegation = (P("!") /"" )^0 + local homedir = lpegmatch(Cs(donegation * doslashes),environment.homedir or "") + if homedir == "~" or homedir == "" or not lfs.isdir(homedir) then + if trace_expansions then + report_expansions("no home dir set, ignoring dependent paths") + end + function resolvers.cleanpath(str) + if not str or find(str,"~") then + return "" -- special case + else + return lpegmatch(cleanup,str) end end + else + local dohome = ((P("~")+P("$HOME"))/homedir)^0 + local cleanup = Cs(donegation * dohome * doslashes) + function resolvers.cleanpath(str) + return str and lpegmatch(cleanup,str) or "" + end end return resolvers.cleanpath(str) end +-- print(resolvers.cleanpath("")) +-- print(resolvers.cleanpath("!")) +-- print(resolvers.cleanpath("~")) +-- print(resolvers.cleanpath("~/test")) +-- print(resolvers.cleanpath("!~/test")) +-- print(resolvers.cleanpath("~/test~test")) + -- This one strips quotes and funny tokens. local expandhome = P("~") / "$HOME" -- environment.homedir @@ -13338,7 +13369,7 @@ end prefixes.filename = function(str) local fullname = findgivenfile(str) or "" - return cleanpath(file.basename((fullname ~= "" and fullname) or str)) + return cleanpath(file.basename((fullname ~= "" and fullname) or str)) -- no cleanpath needed here end prefixes.pathname = function(str) diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index fc4e81d1c..6ac5a5ce5 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -1112,6 +1112,9 @@ if not modules then modules = { } end modules ['l-lpeg'] = { license = "see context related readme files" } + +-- a new lpeg fails on a #(1-P(":")) test and really needs a + P(-1) + local lpeg = require("lpeg") -- tracing (only used when we encounter a problem in integration of lpeg in luatex) @@ -1148,7 +1151,7 @@ patterns.alwaysmatched = alwaysmatched local digit, sign = R('09'), S('+-') local cr, lf, crlf = P("\r"), P("\n"), P("\r\n") -local newline = crlf + cr + lf +local newline = crlf + S("\r\n") -- cr + lf local escaped = P("\\") * anything local squote = P("'") local dquote = P('"') @@ -1668,8 +1671,6 @@ function lpeg.append(list,pp,delayed) end - - end -- of closure do -- create closure to overcome 200 locals limit @@ -7425,18 +7426,15 @@ alternative.</p> function xml.checkbom(root) -- can be made faster if root.ri then - local dt, found = root.dt, false + local dt = root.dt for k=1,#dt do local v = dt[k] if type(v) == "table" and v.special and v.tg == "@pi@" and find(v.dt[1],"xml.*version=") then - found = true - break + return end end - if not found then - insert(dt, 1, { special=true, ns="", tg="@pi@", dt = { "xml version='1.0' standalone='yes'"} } ) - insert(dt, 2, "\n" ) - end + insert(dt, 1, { special=true, ns="", tg="@pi@", dt = { "xml version='1.0' standalone='yes'"} } ) + insert(dt, 2, "\n" ) end end @@ -8547,7 +8545,10 @@ local special_1 = P("*") * Cc(register_auto_descendant) * Cc(register_all_nodes local special_2 = P("/") * Cc(register_auto_self) local special_3 = P("") * Cc(register_auto_self) -local pathparser = Ct { "patterns", -- can be made a bit faster by moving pattern outside +local no_nextcolon = P(-1) + #(1-P(":")) -- newer lpeg needs the P(-1) +local no_nextlparent = P(-1) + #(1-P("(")) -- newer lpeg needs the P(-1) + +local pathparser = Ct { "patterns", -- can be made a bit faster by moving some patterns outside patterns = spaces * V("protocol") * spaces * ( ( V("special") * spaces * P(-1) ) + @@ -8576,10 +8577,8 @@ local pathparser = Ct { "patterns", -- can be made a bit faster by moving patter shortcuts = V("shortcuts_a") * (spaces * "/" * spaces * V("shortcuts_a"))^0, s_descendant_or_self = (P("***/") + P("/")) * Cc(register_descendant_or_self), --- *** is a bonus - -- s_descendant_or_self = P("/") * Cc(register_descendant_or_self), s_descendant = P("**") * Cc(register_descendant), - s_child = P("*") * #(1-P(":")) * Cc(register_child ), --- s_child = P("*") * #(P("/")+P(-1)) * Cc(register_child ), + s_child = P("*") * no_nextcolon * Cc(register_child ), s_parent = P("..") * Cc(register_parent ), s_self = P("." ) * Cc(register_self ), s_root = P("^^") * Cc(register_root ), @@ -8606,13 +8605,13 @@ local pathparser = Ct { "patterns", -- can be made a bit faster by moving patter expressions = expression / register_expression, letters = R("az")^1, - name = (1-lpeg.S("/[]()|:*!"))^1, + name = (1-lpeg.S("/[]()|:*!"))^1, -- make inline negate = P("!") * Cc(false), nodefunction = V("negate") + P("not") * Cc(false) + Cc(true), nodetest = V("negate") + Cc(true), nodename = (V("negate") + Cc(true)) * spaces * ((V("wildnodename") * P(":") * V("wildnodename")) + (Cc(false) * V("wildnodename"))), - wildnodename = (C(V("name")) + P("*") * Cc(false)) * #(1-P("(")), + wildnodename = (C(V("name")) + P("*") * Cc(false)) * no_nextlparent, nodeset = spaces * Ct(V("nodename") * (spaces * P("|") * spaces * V("nodename"))^0) * spaces, finalizer = (Cb("protocol") * P("/")^-1 * C(V("name")) * arguments * P(-1)) / register_finalizer, @@ -10522,41 +10521,73 @@ end -- {a,b,c/{p,q/{x,y,z},w}v,d/{p,q,r}} -- {$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c} -local cleanup = lpeg.replacer { - { "!" , "" }, - { "\\" , "/" }, -} - -local homedir +-- local cleanup = lpeg.replacer { +-- { "!" , "" }, +-- { "\\" , "/" }, +-- } +-- +-- local homedir +-- +-- function resolvers.cleanpath(str) -- tricky, maybe only simple paths +-- if not homedir then +-- homedir = lpegmatch(cleanup,environment.homedir or "") +-- if homedir == char(127) or homedir == "" or not lfs.isdir(homedir) then +-- if trace_expansions then +-- report_expansions("no home dir set, ignoring dependent paths") +-- end +-- function resolvers.cleanpath(str) +-- if find(str,"~") then +-- return "" -- special case +-- else +-- return str and lpegmatch(cleanup,str) +-- end +-- end +-- else +-- cleanup = lpeg.replacer { +-- { "!" , "" }, +-- { "\\" , "/" }, +-- { "~" , homedir }, +-- } +-- function resolvers.cleanpath(str) +-- return str and lpegmatch(cleanup,str) +-- end +-- end +-- end +-- return resolvers.cleanpath(str) +-- end -function resolvers.cleanpath(str) - if not homedir then - homedir = lpegmatch(cleanup,environment.homedir or "") - if homedir == char(127) or homedir == "" or not lfs.isdir(homedir) then - if trace_expansions then - report_expansions("no home dir set, ignoring dependent paths") - end - function resolvers.cleanpath(str) - if find(str,"~") then - return "" -- special case - else - return str and lpegmatch(cleanup,str) - end - end - else - cleanup = lpeg.replacer { - { "!" , "" }, - { "\\" , "/" }, - { "~" , homedir }, - } - function resolvers.cleanpath(str) - return str and lpegmatch(cleanup,str) +function resolvers.cleanpath(str) -- tricky, maybe only simple paths + local doslashes = (P("\\")/"/" + 1)^0 + local donegation = (P("!") /"" )^0 + local homedir = lpegmatch(Cs(donegation * doslashes),environment.homedir or "") + if homedir == "~" or homedir == "" or not lfs.isdir(homedir) then + if trace_expansions then + report_expansions("no home dir set, ignoring dependent paths") + end + function resolvers.cleanpath(str) + if not str or find(str,"~") then + return "" -- special case + else + return lpegmatch(cleanup,str) end end + else + local dohome = ((P("~")+P("$HOME"))/homedir)^0 + local cleanup = Cs(donegation * dohome * doslashes) + function resolvers.cleanpath(str) + return str and lpegmatch(cleanup,str) or "" + end end return resolvers.cleanpath(str) end +-- print(resolvers.cleanpath("")) +-- print(resolvers.cleanpath("!")) +-- print(resolvers.cleanpath("~")) +-- print(resolvers.cleanpath("~/test")) +-- print(resolvers.cleanpath("!~/test")) +-- print(resolvers.cleanpath("~/test~test")) + -- This one strips quotes and funny tokens. local expandhome = P("~") / "$HOME" -- environment.homedir @@ -13338,7 +13369,7 @@ end prefixes.filename = function(str) local fullname = findgivenfile(str) or "" - return cleanpath(file.basename((fullname ~= "" and fullname) or str)) + return cleanpath(file.basename((fullname ~= "" and fullname) or str)) -- no cleanpath needed here end prefixes.pathname = function(str) |