diff options
Diffstat (limited to 'tex')
-rw-r--r-- | tex/context/base/bibl-bib.lua | 10 | ||||
-rw-r--r-- | tex/context/base/core-mis.mkiv | 2 | ||||
-rw-r--r-- | tex/context/base/data-bin.lua | 6 | ||||
-rw-r--r-- | tex/context/base/data-res.lua | 1 | ||||
-rw-r--r-- | tex/context/base/data-tex.lua | 4 | ||||
-rw-r--r-- | tex/context/base/grph-fig.mkiv | 92 | ||||
-rw-r--r-- | tex/context/base/grph-inc.lua | 155 | ||||
-rw-r--r-- | tex/context/base/grph-inc.mkiv | 5 | ||||
-rw-r--r-- | tex/context/base/l-file.lua | 46 | ||||
-rw-r--r-- | tex/context/base/lxml-lpt.lua | 7 | ||||
-rw-r--r-- | tex/generic/context/luatex-fonts-merged.lua | 48 |
11 files changed, 313 insertions, 63 deletions
diff --git a/tex/context/base/bibl-bib.lua b/tex/context/base/bibl-bib.lua index 2df2f9507..efc68fe59 100644 --- a/tex/context/base/bibl-bib.lua +++ b/tex/context/base/bibl-bib.lua @@ -16,6 +16,8 @@ local lower, format, gsub = string.lower, string.format, string.gsub local next = next local lpegmatch = lpeg.match +local trace_bibxml = false trackers.register("publications.bibxml", function(v) trace_bibtex = v end) + bibtex = bibtex or { } bibtex.size = 0 @@ -109,7 +111,13 @@ end function bibtex.load(session,filename) local filename = resolvers.find_file(filename,"bib") if filename ~= "" then - bibtex.convert(session,io.loaddata(filename) or "") + local data = io.loaddata(filename) or "" + if data == "" then + logs.report("publications","empty file '%s', no conversion to xml",filename) + elseif trace_bibxml then + logs.report("publications","converting file '%s' to xml",filename) + end + bibtex.convert(session,data) end end diff --git a/tex/context/base/core-mis.mkiv b/tex/context/base/core-mis.mkiv index f742dab47..0babb77f1 100644 --- a/tex/context/base/core-mis.mkiv +++ b/tex/context/base/core-mis.mkiv @@ -1736,6 +1736,8 @@ % todo: \startcombination \startcomb \stopcomb ... +% needs to be mkiv'd + \newcount\horcombination % counter \newcount\totcombination diff --git a/tex/context/base/data-bin.lua b/tex/context/base/data-bin.lua index 7bfdc7efe..5e4397a54 100644 --- a/tex/context/base/data-bin.lua +++ b/tex/context/base/data-bin.lua @@ -10,15 +10,15 @@ local finders, openers, loaders = resolvers.finders, resolvers.openers, resolver local unpack = unpack or table.unpack function resolvers.findbinfile(filename, filetype) - return resolvers.methodhandler('finders',file.collapse_path(filename), filetype) + return resolvers.methodhandler('finders',filename, filetype) end function resolvers.openbinfile(filename) - return resolvers.methodhandler('loaders',file.collapse_path(filename)) + return resolvers.methodhandler('loaders',filename) end function resolvers.loadbinfile(filename, filetype) - local fname = resolvers.findbinfile(file.collapse_path(filename), filetype) + local fname = resolvers.methodhandler('finders',filename, filetype) if fname and fname ~= "" then return resolvers.openbinfile(fname) else diff --git a/tex/context/base/data-res.lua b/tex/context/base/data-res.lua index 5cc74ad5b..83d78e066 100644 --- a/tex/context/base/data-res.lua +++ b/tex/context/base/data-res.lua @@ -2025,6 +2025,7 @@ function table.sequenced(t,sep) -- temp here end function resolvers.methodhandler(what, filename, filetype) -- ... + filename = file.collapse_path(filename) local specification = (type(filename) == "string" and resolvers.splitmethod(filename)) or filename -- no or { }, let it bomb local scheme = specification.scheme if resolvers[what][scheme] then diff --git a/tex/context/base/data-tex.lua b/tex/context/base/data-tex.lua index 5798ba9f3..8f31bb258 100644 --- a/tex/context/base/data-tex.lua +++ b/tex/context/base/data-tex.lua @@ -202,11 +202,11 @@ function loaders.tex(filename) end function resolvers.findtexfile(filename, filetype) - return resolvers.methodhandler('finders',file.collapse_path(filename), filetype) + return resolvers.methodhandler('finders',filename, filetype) end function resolvers.opentexfile(filename) - return resolvers.methodhandler('openers',file.collapse_path(filename)) + return resolvers.methodhandler('openers',filename) end function resolvers.openfile(filename) diff --git a/tex/context/base/grph-fig.mkiv b/tex/context/base/grph-fig.mkiv index 80dbefafd..5761f6081 100644 --- a/tex/context/base/grph-fig.mkiv +++ b/tex/context/base/grph-fig.mkiv @@ -130,19 +130,99 @@ \def\useexternalfigure {\doquadrupleempty\douseexternalfigure} +% \def\douseexternalfigure[#1][#2][#3][#4]% +% {\doifelsenothing{#1} +% {\doifsomething{#2} +% {\doifassignmentelse{#3} +% {\setvalue{\??ef\??ef#2}{\doplaceexternalfigure[#2][#2][#3][#4]}} +% {\setvalue{\??ef\??ef#2}{\doplaceexternalfigure[#2][#2][][#4]}}}} +% {\doifelsenothing{#2} +% {\doifassignmentelse{#3} +% {\setvalue{\??ef\??ef#1}{\doplaceexternalfigure[#1][#1][][#3]}} +% {\setvalue{\??ef\??ef#1}{\doplaceexternalfigure[#1][#1][#3][#4]}}} +% {\doifassignmentelse{#3} +% {\setvalue{\??ef\??ef#1}{\doplaceexternalfigure[#1][#2][][#3]}} +% {\setvalue{\??ef\??ef#1}{\doplaceexternalfigure[#1][#2][#3][#4]}}}}} + \def\douseexternalfigure[#1][#2][#3][#4]% {\doifelsenothing{#1} {\doifsomething{#2} {\doifassignmentelse{#3} - {\setvalue{\??ef\??ef#2}{\doplaceexternalfigure[#2][#2][#3][#4]}} - {\setvalue{\??ef\??ef#2}{\doplaceexternalfigure[#2][#2][][#4]}}}} + {\dodouseexternalfigure{#2}{#2}{#3}{#4}} + {\dodouseexternalfigure{#2}{#2}{}{#4}}}} {\doifelsenothing{#2} {\doifassignmentelse{#3} - {\setvalue{\??ef\??ef#1}{\doplaceexternalfigure[#1][#1][][#3]}} - {\setvalue{\??ef\??ef#1}{\doplaceexternalfigure[#1][#1][#3][#4]}}} + {\dodouseexternalfigure{#1}{#1}{}{#3}} + {\dodouseexternalfigure{#1}{#1}{#3}{#4}}} {\doifassignmentelse{#3} - {\setvalue{\??ef\??ef#1}{\doplaceexternalfigure[#1][#2][][#3]}} - {\setvalue{\??ef\??ef#1}{\doplaceexternalfigure[#1][#2][#3][#4]}}}}} + {\dodouseexternalfigure{#1}{#2}{}{#3}} + {\dodouseexternalfigure{#1}{#2}{#3}{#4}}}}} + +\def\dodouseexternalfigure#1#2#3#4% + {\setvalue{\??ef\??ef#1}{\doplaceexternalfigure[#1][#2][#3][#4]}% + \doanalyseexternalfigurecollection[#2][#4]} + +\newconditional\inexternalfigurecollection +\newdimen\xexternalfigurecollectionminwidth +\newdimen\xexternalfigurecollectionmaxwidth +\newdimen\xexternalfigurecollectionminheight +\newdimen\xexternalfigurecollectionmaxheight + +\def\doanalyseexternalfigurecollection[#1][#2]% + {\ifconditional\inexternalfigurecollection + \setfalse\inexternalfigurecollection + \getfiguredimensions[#1][#2]% + \settrue\inexternalfigurecollection + \scratchdimen\naturalfigurewidth + \ifdim\scratchdimen>\xexternalfigurecollectionmaxwidth \xexternalfigurecollectionmaxwidth \scratchdimen \fi + \ifdim\scratchdimen<\xexternalfigurecollectionminwidth \xexternalfigurecollectionminwidth \scratchdimen \fi + \scratchdimen\naturalfigureheight + \ifdim\scratchdimen>\xexternalfigurecollectionmaxheight \xexternalfigurecollectionmaxheight\scratchdimen \fi + \ifdim\scratchdimen<\xexternalfigurecollectionminheight \xexternalfigurecollectionminheight\scratchdimen \fi + \fi} + +\def\startexternalfigurecollection[#1]% + {\begingroup + \def\currentexternalfigurecollection{#1}% + \settrue\inexternalfigurecollection + \xexternalfigurecollectionminwidth \maxdimen + \xexternalfigurecollectionmaxwidth \zeropoint + \xexternalfigurecollectionminheight\maxdimen + \xexternalfigurecollectionmaxheight\zeropoint} + +\def\stopexternalfigurecollection + {\setxvalue{\??ef:c:\currentexternalfigurecollection:\c!minwidth }{\the\xexternalfigurecollectionminwidth }% + \setxvalue{\??ef:c:\currentexternalfigurecollection:\c!maxwidth }{\the\xexternalfigurecollectionmaxwidth }% + \setxvalue{\??ef:c:\currentexternalfigurecollection:\c!minheight}{\the\xexternalfigurecollectionminheight}% + \setxvalue{\??ef:c:\currentexternalfigurecollection:\c!maxheight}{\the\xexternalfigurecollectionmaxheight}% + \endgroup} + +\def\externalfigurecollectionparameter#1#2% + {\csname\ifcsname\??ef:c:#1:#2\endcsname\??ef:c:#1:#2\else\s!empty\fi\endcsname} + +\def\externalfigurecollectionminwidth #1{\externalfigurecollectionparameter{#1}\c!minwidth } +\def\externalfigurecollectionmaxwidth #1{\externalfigurecollectionparameter{#1}\c!maxwidth } +\def\externalfigurecollectionminheight#1{\externalfigurecollectionparameter{#1}\c!minheight} +\def\externalfigurecollectionmaxheight#1{\externalfigurecollectionparameter{#1}\c!maxheight} + +\let\efcparameter\externalfigurecollectionparameter +\let\efcminwidth \externalfigurecollectionminwidth +\let\efcmaxwidth \externalfigurecollectionmaxwidth +\let\efcminheight\externalfigurecollectionminheight +\let\efcmaxheight\externalfigurecollectionmaxheight + +% \startexternalfigurecollection[name] +% \useexternalfigure[cow] [cow.pdf] +% \useexternalfigure[mill][mill.png] +% \stopexternalfigurecollection +% \starttext +% \bTABLE +% \bTR +% \bTD \externalfigure[cow] [height=\externalfigurecollectionmaxheight{name}] \eTD +% \bTD \externalfigure[mill][height=\externalfigurecollectionmaxheight{name}] \eTD +% \eTR +% \eTABLE +% \stoptext \def\dosetefparameters#1#2#3% parent_id use_settings current_settings {\doifelsenothing{#1} % inherit from parent diff --git a/tex/context/base/grph-inc.lua b/tex/context/base/grph-inc.lua index b90a938bb..b984f9877 100644 --- a/tex/context/base/grph-inc.lua +++ b/tex/context/base/grph-inc.lua @@ -43,9 +43,10 @@ local concat = table.concat local ctxcatcodes = tex.ctxcatcodes local variables = interfaces.variables -local trace_figures = false trackers.register("figures.locating", function(v) trace_figures = v end) -local trace_bases = false trackers.register("figures.bases", function(v) trace_bases = v end) -local trace_programs = false trackers.register("figures.programs", function(v) trace_programs = v end) +local trace_figures = false trackers.register("figures.locating", function(v) trace_figures = v end) +local trace_bases = false trackers.register("figures.bases", function(v) trace_bases = v end) +local trace_programs = false trackers.register("figures.programs", function(v) trace_programs = v end) +local trace_conversion = false trackers.register("figures.conversion", function(v) trace_conversion = v end) --- some extra img functions --- @@ -85,13 +86,13 @@ end --- -figures = figures or { } -figures.loaded = figures.loaded or { } -figures.used = figures.used or { } -figures.found = figures.found or { } -figures.suffixes = figures.suffixes or { } -figures.patterns = figures.patterns or { } -figures.boxnumber = figures.boxid or 0 +figures = figures or { } +figures.loaded = figures.loaded or { } +figures.used = figures.used or { } +figures.found = figures.found or { } +figures.suffixes = figures.suffixes or { } +figures.patterns = figures.patterns or { } +figures.boxnumber = figures.boxnumber or 0 figures.defaultsearch = true figures.defaultwidth = 0 figures.defaultheight = 0 @@ -271,7 +272,10 @@ do end function figures.push(request) - statistics.starttiming(figures) + local ncs = #callstack + 1 + if ncs == 1 then + statistics.starttiming(figures) + end local figuredata = figures.new() if request then local iv = interfaces.variables @@ -290,13 +294,16 @@ do -- request.height = (h and h > 0) or false table.merge(figuredata.request,request) end - callstack[#callstack+1] = figuredata + callstack[ncs] = figuredata return figuredata end function figures.pop() - figuredata = callstack[#callstack] - callstack[#callstack] = nil - statistics.stoptiming(figures) + local ncs = #callstack + figuredata = callstack[ncs] + callstack[ncs] = nil + if ncs == 1 then + statistics.stoptiming(figures) + end end -- maybe move texsprint to tex function figures.get(category,tag,default) @@ -317,19 +324,48 @@ do end +local defaultformat = "pdf" +local defaultprefix = "m_k_v_i_" + local function register(askedname,specification) if specification then local format = specification.format if format then - local converter = figures.converters[format] + local conversion = specification.conversion + if conversion == "" then + conversion = nil + end + local newformat = conversion + if not newformat or newformat == "" then + newformat = defaultformat + end + local converter = (newformat ~= format) and figures.converters[format] + if trace_conversion then + logs.report("figures","checking conversion of '%s': old format '%s', new format '%s', conversion '%s'", + askedname,format,newformat,conversion or "default") + end + if converter then + if converter[newformat] then + converter = converter[newformat] + else + newformat = defaultformat + if converter[newformat] then + converter = converter[newformat] + else + newformat = defaultformat + end + end + end if converter then local oldname = specification.fullname - local newformat = "pdf" -- todo, other target than pdf local newpath = file.dirname(oldname) - local newbase = file.replacesuffix(file.basename(oldname),newformat) + local oldbase = file.basename(oldname) + local newbase = file.replacesuffix(oldbase,newformat) local fc = specification.cache or figures.cachepaths.path if fc and fc ~= "" and fc ~= "." then newpath = fc + else + newbase = defaultprefix .. newbase end local subpath = specification.subpath or figures.cachepaths.subpath if subpath and subpath ~= "" and subpath ~= "." then @@ -341,10 +377,19 @@ local function register(askedname,specification) end local newname = file.join(newpath,newbase) dir.makedirs(newpath) + oldname = dir.expand_name(oldname) + newname = dir.expand_name(newname) local oldtime = lfs.attributes(oldname,'modification') or 0 local newtime = lfs.attributes(newname,'modification') or 0 if oldtime > newtime then + if trace_conversion then + logs.report("figures","converting '%s' from '%s' to '%s'",askedname,format,newformat) + end converter(oldname,newname) + else + if trace_conversion then + logs.report("figures","no need to convert '%s' from '%s' to '%s'",askedname,format,newformat) + end end if io.exists(newname) then specification.foundname = oldname @@ -379,7 +424,7 @@ local function register(askedname,specification) specification = { } end specification.foundname = specification.foundname or specification.fullname - figures.found[askedname] = specification + figures.found[askedname .. "->" .. (specification.conversion or "default")] = specification return specification end @@ -387,7 +432,7 @@ local resolve_too = true local function locate(request) -- name, format, cache local askedname = resolvers.clean_path(request.name) - local foundname = figures.found[askedname] + local foundname = figures.found[askedname .. "->" .. (request.conversion or "default")] if foundname then return foundname end @@ -404,6 +449,7 @@ local function locate(request) -- name, format, cache local askedbase = file.basename(askedname) local askedformat = (request.format ~= "" and request.format ~= "unknown" and request.format) or file.extname(askedname) or "" local askedcache = request.cache + local askedconversion = request.conversion if askedformat ~= "" then if trace_figures then commands.writestatus("figures","strategy: forced format") @@ -427,6 +473,7 @@ local function locate(request) -- name, format, cache format = format, cache = askedcache, foundname = foundname, + conversion = askedconversion, }) end end @@ -438,6 +485,7 @@ local function locate(request) -- name, format, cache fullname = askedname, format = askedformat, cache = askedcache, + conversion = askedconversion, }) end else @@ -452,6 +500,7 @@ local function locate(request) -- name, format, cache fullname = check, format = askedformat, cache = askedcache, + conversion = askedconversion, }) end end @@ -463,6 +512,7 @@ local function locate(request) -- name, format, cache fullname = check, format = askedformat, cache = askedcache, + conversion = askedconversion, }) end end @@ -481,6 +531,7 @@ local function locate(request) -- name, format, cache fullname = check, format = format, cache = askedcache, + conversion = askedconversion, }) end end @@ -508,6 +559,7 @@ local function locate(request) -- name, format, cache fullname = check, format = format, cache = askedcache, + conversion = askedconversion, }) end end @@ -528,6 +580,7 @@ local function locate(request) -- name, format, cache fullname = check, format = format, cache = askedcache, + conversion = askedconversion, }) end end @@ -548,6 +601,7 @@ local function locate(request) -- name, format, cache fullname = check, format = format, cache = askedcache, + conversion = askedconversion, }) end end @@ -655,7 +709,11 @@ end function figures.checkers.generic(data) local dr, du, ds = data.request, data.used, data.status local name, page, size, color = du.fullname or "unknown generic", du.page or dr.page, dr.size or "crop", dr.color or "natural" - local hash = name .. "->" .. page .. "->" .. size .. "->" .. color + local conversion = dr.conversion + if not conversion or conversion == "" then + conversion = "unknown" + end + local hash = name .. "->" .. page .. "->" .. size .. "->" .. color .. "->" .. conversion local figure = figures.loaded[hash] if figure == nil then figure = img.new { filename = name, page = page, pagebox = dr.size } @@ -664,6 +722,13 @@ function figures.checkers.generic(data) local f, d = backends.codeinjections.setfigurealternative(data,figure) figure, data = f or figure, d or data figures.loaded[hash] = figure + if trace_conversion then + logs.report("figures","new graphic, hash: %s",hash) + end + else + if trace_conversion then + logs.report("figures","existing graphic, hash: %s",hash) + end end if figure then du.width = figure.width @@ -808,7 +873,7 @@ end local function runprogram(...) local command = format(...) - if trace_programs then + if trace_conversion or trace_programs then logs.report("figures","running %s",command) end os.spawn(command) @@ -816,6 +881,9 @@ end -- -- -- eps -- -- -- +local epsconverter = { } +figures.converters.eps = epsconverter + figures.programs.gs = { options = { "-dAutoRotatePages=/None", @@ -825,7 +893,7 @@ figures.programs.gs = { command = (os.type == "windows" and "gswin32") or "gs" } -function figures.converters.eps(oldname,newname) +function epsconverter.pdf(oldname,newname) local gs = figures.programs.gs runprogram ( '%s -q -sDEVICE=pdfwrite -dNOPAUSE -dNOCACHE -dBATCH %s -sOutputFile="%s" "%s" -c quit', @@ -833,31 +901,51 @@ function figures.converters.eps(oldname,newname) ) end +epsconverter.default = epsconverter.pdf + -- -- -- svg -- -- -- +local svgconverter = { } +figures.converters.svg = svgconverter +figures.converters.svgz = svgconverter + +-- inkscape on windows only works with complete paths + figures.programs.inkscape = { + options = { + "--export-dpi=600" + }, command = "inkscape" } -function figures.converters.svg(oldname,newname) - -- inkscape on windows only works with complete paths +function svgconverter.pdf(oldname,newname) local inkscape = figures.programs.inkscape - oldname, newname = dir.expand_name(oldname), dir.expand_name(newname) runprogram ( '%s "%s" --export-pdf="%s" %s', inkscape.command, oldname, newname, makeoptions(inkscape.options) ) end -figures.converters.svgz = figures.converters.svg +function svgconverter.png(oldname,newname) + local inkscape = figures.programs.inkscape + runprogram ( + '%s "%s" --export-png="%s" %s', + inkscape.command, oldname, newname, makeoptions(inkscape.options) + ) +end + +svgconverter.default = svgconverter.pdf -- -- -- gif -- -- -- +local gifconverter = { } +figures.converters.gif = gifconverter + figures.programs.convert = { command = "convert" -- imagemagick } -function figures.converters.gif(oldname,newname) +function gifconverter.pdf(oldname,newname) local convert = figures.programs.convert runprogram ( "convert %s %s", @@ -865,14 +953,11 @@ function figures.converters.gif(oldname,newname) ) end --- -- -- lowres -- -- -- +gifconverter.default = gifconverter.pdf ---~ function figures.converters.pdf(oldname,newname) ---~ local outputpath = file.dirname(newname) ---~ local outputbase = file.basename(newname) ---~ local command = format("mtxrun bin:pstopdf --method=4 --outputpath=%s %s",outputpath,oldname) ---~ os.spawn(command) ---~ end +-- todo: lowres + +-- -- -- bases -- -- -- figures.bases = { } figures.bases.list = { } -- index => { basename, fullname, xmlroot } diff --git a/tex/context/base/grph-inc.mkiv b/tex/context/base/grph-inc.mkiv index 6961262d0..e28a289ab 100644 --- a/tex/context/base/grph-inc.mkiv +++ b/tex/context/base/grph-inc.mkiv @@ -212,6 +212,10 @@ \newconditional\testexternalfigureonly +% \enabletrackers[figures.conversion] +% \externalfigure[demo.svg] +% \externalfigure[demo.svg][conversion=png] + \def\calculateexternalfigure[#1][#2][#3][#4][#5][#6]% \cmd label filename parent_id preset current {\dontcomplain \restorecatcodes @@ -235,6 +239,7 @@ controls="\@@efcontrols", preview="\@@efpreview", display="\@@efdisplay", + conversion="\@@efconversion", color="\internalspotcolorparent\@@efcolor", % hack is needed ["repeat"]="\@@efrepeat", width="\@@efwidth", % can be crap diff --git a/tex/context/base/l-file.lua b/tex/context/base/l-file.lua index 87ae6e7fe..2064fcdd1 100644 --- a/tex/context/base/l-file.lua +++ b/tex/context/base/l-file.lua @@ -11,7 +11,7 @@ if not modules then modules = { } end modules ['l-file'] = { file = file or { } local concat = table.concat -local find, gmatch, match, gsub, sub = string.find, string.gmatch, string.match, string.gsub, string.sub +local find, gmatch, match, gsub, sub, char = string.find, string.gmatch, string.match, string.gsub, string.sub, string.char local lpegmatch = lpeg.match function file.removesuffix(filename) @@ -48,14 +48,33 @@ end file.suffix = file.extname ---~ print(file.join("x/","/y")) ---~ print(file.join("http://","/y")) ---~ print(file.join("http://a","/y")) ---~ print(file.join("http:///a","/y")) ---~ print(file.join("//nas-1","/y")) +--~ function file.join(...) +--~ local pth = concat({...},"/") +--~ pth = gsub(pth,"\\","/") +--~ local a, b = match(pth,"^(.*://)(.*)$") +--~ if a and b then +--~ return a .. gsub(b,"//+","/") +--~ end +--~ a, b = match(pth,"^(//)(.*)$") +--~ if a and b then +--~ return a .. gsub(b,"//+","/") +--~ end +--~ return (gsub(pth,"//+","/")) +--~ end + +local trick_1 = char(1) +local trick_2 = "^" .. trick_1 .. "/+" function file.join(...) - local pth = concat({...},"/") + local lst = { ... } + local a, b = lst[1], lst[2] + if a == "" then + lst[1] = trick_1 + elseif b and find(a,"^/+$") and find(b,"^/") then + lst[1] = "" + lst[2] = gsub(b,"^/+","") + end + local pth = concat(lst,"/") pth = gsub(pth,"\\","/") local a, b = match(pth,"^(.*://)(.*)$") if a and b then @@ -65,9 +84,20 @@ function file.join(...) if a and b then return a .. gsub(b,"//+","/") end + pth = gsub(pth,trick_2,"") return (gsub(pth,"//+","/")) end +--~ print(file.join("//","/y")) +--~ print(file.join("/","/y")) +--~ print(file.join("","/y")) +--~ print(file.join("/x/","/y")) +--~ print(file.join("x/","/y")) +--~ print(file.join("http://","/y")) +--~ print(file.join("http://a","/y")) +--~ print(file.join("http:///a","/y")) +--~ print(file.join("//nas-1","/y")) + function file.iswritable(name) local a = lfs.attributes(name) or lfs.attributes(file.dirname(name,".")) return a and sub(a.permissions,2,2) == "w" @@ -106,6 +136,8 @@ function file.join_path(tab) return concat(tab,io.pathseparator) -- can have trailing // end +-- we can hash them weakly + function file.collapse_path(str) if find(str,"/") then str = gsub(str,"/%./","/") diff --git a/tex/context/base/lxml-lpt.lua b/tex/context/base/lxml-lpt.lua index 8381cc221..04808c70f 100644 --- a/tex/context/base/lxml-lpt.lua +++ b/tex/context/base/lxml-lpt.lua @@ -609,8 +609,13 @@ local register_initial_child = { kind = "axis", axis = "initial-child" local register_all_nodes = { kind = "nodes", nodetest = true, nodes = { true, false, false } } +local skip = { } + local function errorrunner_e(str,cnv) - logs.report("lpath","error in expression: %s => %s",str,cnv) + if not skip[str] then + logs.report("lpath","error in expression: %s => %s",str,cnv) + skip[str] = cnv or str + end return false end local function errorrunner_f(str,arg) diff --git a/tex/generic/context/luatex-fonts-merged.lua b/tex/generic/context/luatex-fonts-merged.lua index 69446a8e6..f6683650a 100644 --- a/tex/generic/context/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/texmf/tex/generic/context/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/texmf/tex/generic/context/luatex-fonts.lua --- merge date : 02/08/10 19:47:32 +-- merge date : 02/09/10 18:25:39 do -- begin closure to overcome local limits and interference @@ -1447,7 +1447,7 @@ if not modules then modules = { } end modules ['l-file'] = { file = file or { } local concat = table.concat -local find, gmatch, match, gsub, sub = string.find, string.gmatch, string.match, string.gsub, string.sub +local find, gmatch, match, gsub, sub, char = string.find, string.gmatch, string.match, string.gsub, string.sub, string.char local lpegmatch = lpeg.match function file.removesuffix(filename) @@ -1484,14 +1484,33 @@ end file.suffix = file.extname ---~ print(file.join("x/","/y")) ---~ print(file.join("http://","/y")) ---~ print(file.join("http://a","/y")) ---~ print(file.join("http:///a","/y")) ---~ print(file.join("//nas-1","/y")) +--~ function file.join(...) +--~ local pth = concat({...},"/") +--~ pth = gsub(pth,"\\","/") +--~ local a, b = match(pth,"^(.*://)(.*)$") +--~ if a and b then +--~ return a .. gsub(b,"//+","/") +--~ end +--~ a, b = match(pth,"^(//)(.*)$") +--~ if a and b then +--~ return a .. gsub(b,"//+","/") +--~ end +--~ return (gsub(pth,"//+","/")) +--~ end + +local trick_1 = char(1) +local trick_2 = "^" .. trick_1 .. "/+" function file.join(...) - local pth = concat({...},"/") + local lst = { ... } + local a, b = lst[1], lst[2] + if a == "" then + lst[1] = trick_1 + elseif b and find(a,"^/+$") and find(b,"^/") then + lst[1] = "" + lst[2] = gsub(b,"^/+","") + end + local pth = concat(lst,"/") pth = gsub(pth,"\\","/") local a, b = match(pth,"^(.*://)(.*)$") if a and b then @@ -1501,9 +1520,20 @@ function file.join(...) if a and b then return a .. gsub(b,"//+","/") end + pth = gsub(pth,trick_2,"") return (gsub(pth,"//+","/")) end +--~ print(file.join("//","/y")) +--~ print(file.join("/","/y")) +--~ print(file.join("","/y")) +--~ print(file.join("/x/","/y")) +--~ print(file.join("x/","/y")) +--~ print(file.join("http://","/y")) +--~ print(file.join("http://a","/y")) +--~ print(file.join("http:///a","/y")) +--~ print(file.join("//nas-1","/y")) + function file.iswritable(name) local a = lfs.attributes(name) or lfs.attributes(file.dirname(name,".")) return a and sub(a.permissions,2,2) == "w" @@ -1542,6 +1572,8 @@ function file.join_path(tab) return concat(tab,io.pathseparator) -- can have trailing // end +-- we can hash them weakly + function file.collapse_path(str) if find(str,"/") then str = gsub(str,"/%./","/") |