diff options
Diffstat (limited to 'scripts')
30 files changed, 2775 insertions, 2417 deletions
diff --git a/scripts/context/lua/mtx-babel.lua b/scripts/context/lua/mtx-babel.lua index 7e08633cf..120e49092 100644 --- a/scripts/context/lua/mtx-babel.lua +++ b/scripts/context/lua/mtx-babel.lua @@ -8,6 +8,20 @@ if not modules then modules = { } end modules ['mtx-babel'] = { -- data tables by Thomas A. Schmitz +local helpinfo = [[ +--language=string conversion language (e.g. greek) +--structure=string obey given structure (e.g. 'document', default: 'context') +--convert convert babel codes into utf +]] + +local application = logs.application { + name = "mtx-babel", + banner = "Babel Input To UTF Conversion 1.20", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.babel = scripts.babel or { } @@ -387,22 +401,22 @@ do local structure = environment.argument("structure") or "document" converter = converter[structure] if converter then - logs.simple("converting '%s' using language '%s' with structure '%s'", filename, language, structure) + report("converting '%s' using language '%s' with structure '%s'", filename, language, structure) data = converter:match(data) local newfilename = filename .. ".utf" io.savedata(newfilename, data) - logs.simple("converted data saved in '%s'", newfilename) + report("converted data saved in '%s'", newfilename) else - logs.simple("unknown structure '%s' language '%s'", structure, language) + report("unknown structure '%s' language '%s'", structure, language) end else - logs.simple("no converter for language '%s'", language) + report("no converter for language '%s'", language) end else - logs.simple("provide language") + report("provide language") end else - logs.simple("no data in '%s'",filename) + report("no data in '%s'",filename) end end end @@ -415,16 +429,8 @@ do end -logs.extendbanner("Babel Input To UTF Conversion 1.20") - -messages.help = [[ ---language=string conversion language (e.g. greek) ---structure=string obey given structure (e.g. 'document', default: 'context') ---convert convert babel codes into utf -]] - if environment.argument("convert") then scripts.babel.convert(environment.files[1] or "") else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-base.lua b/scripts/context/lua/mtx-base.lua index 99a478b1e..ab5bfe18a 100644 --- a/scripts/context/lua/mtx-base.lua +++ b/scripts/context/lua/mtx-base.lua @@ -6,35 +6,7 @@ if not modules then modules = { } end modules ['mtx-base'] = { license = "see context related readme files" } -logs.extendbanner("ConTeXt TDS Management Tool 1.35 (aka luatools)") - --- private option --noluc for testing errors in the stub - -local instance = resolvers.instance - -local pattern = environment.arguments["pattern"] or nil -local fileformat = environment.arguments["format"] or "" -- nil ? -local allresults = environment.arguments["all"] or false -local trace = environment.arguments["trace"] - -if type(pattern) == 'boolean' then - logs.simple("invalid pattern specification") - pattern = nil -end - -if trace then - resolvers.settrace(trace) -- move to mtxrun ? -end - -runners = runners or { } -messages = messages or { } - -messages.no_ini_file = [[ -There is no lua initialization file found. It may be that you have -to regenerate the file database using "mtxrun --generate". -]] - -messages.help = [[ +local helpinfo = [[ --generate generate file database --variables show configuration variables --configurations show configuration order @@ -55,6 +27,32 @@ messages.help = [[ --trackers=list enable given trackers ]] +local application = logs.application { + name = "mtx-base", + banner = "ConTeXt TDS Management Tool 1.35 (aka luatools)", + helpinfo = helpinfo, +} + +local report = application.report + +-- private option --noluc for testing errors in the stub + +local instance = resolvers.instance + +local pattern = environment.arguments["pattern"] or nil +local fileformat = environment.arguments["format"] or "" -- nil ? +local allresults = environment.arguments["all"] or false +local trace = environment.arguments["trace"] + +if type(pattern) == 'boolean' then + report("invalid pattern specification") + pattern = nil +end + +if trace then + resolvers.settrace(trace) -- move to mtxrun ? +end + if environment.arguments["find-file"] then resolvers.load() if pattern then @@ -91,7 +89,7 @@ elseif environment.arguments["var-value"] or environment.arguments["show-value"] resolvers.dowithfilesandreport(resolvers.variable, environment.files) elseif environment.arguments["format-path"] then resolvers.load() - logs.simple(caches.getwritablepath("format")) + report(caches.getwritablepath("format")) elseif pattern then -- brrr resolvers.load() resolvers.dowithfilesandreport(resolvers.findfiles, { pattern }, fileformat, allresults) @@ -110,7 +108,7 @@ elseif environment.arguments["configurations"] or environment.arguments["show-co resolvers.load("nofiles") resolvers.listers.configurations() elseif environment.arguments["help"] or (environment.files[1]=='help') or (#environment.files==0) then - logs.help(messages.help) + application.help() elseif environment.files[1] == 'texmfcnf.lua' then resolvers.load("nofiles") resolvers.listers.configurations() diff --git a/scripts/context/lua/mtx-cache.lua b/scripts/context/lua/mtx-cache.lua index a6985d3bc..08202bbf8 100644 --- a/scripts/context/lua/mtx-cache.lua +++ b/scripts/context/lua/mtx-cache.lua @@ -6,6 +6,22 @@ if not modules then modules = { } end modules ['mtx-cache'] = { license = "see context related readme files" } +local helpinfo = [[ +--purge remove not used files +--erase completely remove cache +--list show cache + +--all all (not yet implemented) +]] + +local application = logs.application { + name = "mtx-cache", + banner = "ConTeXt & MetaTeX Cache Management 0.10", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.cache = scripts.cache or { } @@ -27,18 +43,18 @@ local function collect(path) end local function list(banner,path,tmas,tmcs,rest) - logs.report("cache",string.format("%s: %s",banner,path)) - logs.report() - logs.report("cache",string.format("tma : %4i",#tmas)) - logs.report("cache",string.format("tmc : %4i",#tmcs)) - logs.report("cache",string.format("rest : %4i",#rest)) - logs.report("cache",string.format("total : %4i",#tmas+#tmcs+#rest)) - logs.report() + report("%s: %s",banner,path) + report() + report("tma : %4i",#tmas) + report("tmc : %4i",#tmcs) + report("rest : %4i",#rest) + report("total : %4i",#tmas+#tmcs+#rest) + report() end local function purge(banner,path,list,all) - logs.report("cache",string.format("%s: %s",banner,path)) - logs.report() + report("%s: %s",banner,path) + report() local n = 0 for i=1,#list do local filename = list[i] @@ -58,8 +74,8 @@ local function purge(banner,path,list,all) end end end - logs.report("cache",string.format("removed tma files : %i",n)) - logs.report() + report("removed tma files : %i",n) + report() end function scripts.cache.purge() @@ -92,16 +108,6 @@ function scripts.cache.list() end end -logs.extendbanner("ConTeXt & MetaTeX Cache Management 0.10") - -messages.help = [[ ---purge remove not used files ---erase completely remove cache ---list show cache - ---all all (not yet implemented) -]] - if environment.argument("purge") then scripts.cache.purge() elseif environment.argument("erase") then @@ -109,5 +115,5 @@ elseif environment.argument("erase") then elseif environment.argument("list") then scripts.cache.list() else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-chars.lua b/scripts/context/lua/mtx-chars.lua index d356bb5bb..dc760c4e7 100644 --- a/scripts/context/lua/mtx-chars.lua +++ b/scripts/context/lua/mtx-chars.lua @@ -6,6 +6,20 @@ if not modules then modules = { } end modules ['mtx-chars'] = { license = "see context related readme files" } +local helpinfo = [[ +--stix convert stix table to math table +--xtx generate xetx-*.tex (used by xetex) +--pdf generate pdfr-def.tex (used by pdftex) +]] + +local application = logs.application { + name = "mtx-chars", + banner = "MkII Character Table Generators 0.10", + helpinfo = helpinfo, +} + +local report = application.report + local format, concat, utfchar, upper = string.format, table.concat, unicode.utf8.char, string.upper scripts = scripts or { } @@ -24,13 +38,13 @@ scripts.chars = scripts.chars or { } --~ --~ function scripts.chars.stixtomkiv(inname,outname) --~ if inname == "" then ---~ logs.report("aquiring math data","invalid datafilename") +--~ report("aquiring math data, invalid datafilename") --~ end --~ local f = io.open(inname) --~ if not f then ---~ logs.report("aquiring math data","invalid datafile") +--~ report("aquiring math data, invalid datafile") --~ else ---~ logs.report("aquiring math data","processing " .. inname) +--~ report("aquiring math data, processing %s",inname) --~ if not outname or outname == "" then --~ outname = "char-mth.lua" --~ end @@ -72,9 +86,9 @@ scripts.chars = scripts.chars or { } --~ end --~ if not valid then --~ g:write("\t-- The data file is corrupt, invalid or maybe the format has changed.\n") ---~ logs.report("aquiring math data","problems with data table") +--~ report("aquiring math data, problems with data table") --~ else ---~ logs.report("aquiring math data","table saved in " .. outname) +--~ report("aquiring math data, table saved in %s",outname) --~ end --~ g:write("}\n") --~ g:close() @@ -83,7 +97,7 @@ scripts.chars = scripts.chars or { } --~ end function scripts.chars.stixtomkiv(inname,outname) - logs.report("we no longer use this options but use our own tables instead") + report("we no longer use this options but use our own tables instead") end local banner_pdf_1 = [[ @@ -185,7 +199,7 @@ function scripts.chars.makeencoutf() local function open(name,banner) local f = io.open(name,'w') if f then - logs.simple("writing '%s'",name) + report("writing '%s'",name) f:write(format(banner_utf_module,name)) f:write(banner) f:write() @@ -307,14 +321,6 @@ function scripts.chars.makeencoutf() end end -logs.extendbanner("MkII Character Table Generators 0.10") - -messages.help = [[ ---stix convert stix table to math table ---xtx generate xetx-*.tex (used by xetex) ---pdf generate pdfr-def.tex (used by pdftex) -]] - if environment.argument("stix") then local inname = environment.files[1] or "" local outname = environment.files[2] or "" @@ -324,5 +330,5 @@ elseif environment.argument("xtx") then elseif environment.argument("pdf") then scripts.chars.makepdfr() else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-check.lua b/scripts/context/lua/mtx-check.lua index 7704d86ae..e0ab3b882 100644 --- a/scripts/context/lua/mtx-check.lua +++ b/scripts/context/lua/mtx-check.lua @@ -6,6 +6,18 @@ if not modules then modules = { } end modules ['mtx-check'] = { license = "see context related readme files" } +local helpinfo = [[ +--convert check tex file for errors +]] + +local application = logs.application { + name = "mtx-check", + banner = "Basic ConTeXt Syntax Checking 0.10", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.checker = scripts.checker or { } @@ -123,17 +135,13 @@ function scripts.checker.check(filename) end end -logs.extendbanner("Basic ConTeXt Syntax Checking 0.10") - -messages.help = [[ ---convert check tex file for errors -]] - if environment.argument("check") then scripts.checker.check(environment.files[1]) elseif environment.argument("help") then - logs.help(messages.help) + application.help() elseif environment.files[1] then scripts.checker.check(environment.files[1]) +else + application.help() end diff --git a/scripts/context/lua/mtx-colors.lua b/scripts/context/lua/mtx-colors.lua index e5338a32b..ee825a42c 100644 --- a/scripts/context/lua/mtx-colors.lua +++ b/scripts/context/lua/mtx-colors.lua @@ -8,6 +8,22 @@ if not modules then modules = { } end modules ['mtx-colors'] = { -- todo: fc-cache -v en check dirs, or better is: fc-cat -v | grep Directory +local helpinfo = [[ +--table show icc table + +example: + +mtxrun --script color --table somename +]] + +local application = logs.application { + name = "mtx-cache", + banner = "ConTeXt Color Management 0.10", + helpinfo = helpinfo, +} + +local report = application.report + if not fontloader then fontloader = fontforge end dofile(resolvers.findfile("colo-icc.lua","tex")) @@ -21,31 +37,21 @@ function scripts.colors.table() for i=1,#files do local profile, okay, message = colors.iccprofile(files[i]) if not okay then - logs.simple(message) + report(message) else - logs.simple(table.serialize(profile,"profile")) + report(table.serialize(profile,"profile")) end end else - logs.simple("no file(s) given" ) + report("no file(s) given" ) end end -logs.extendbanner("ConTeXt Color Management 0.1") - -messages.help = [[ ---table show icc table - -example: - -mtxrun --script color --table somename -]] - --~ local track = environment.argument("track") --~ if track then trackers.enable(track) end if environment.argument("table") then scripts.colors.table() else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua index e3082e825..b8ca6a11e 100644 --- a/scripts/context/lua/mtx-context.lua +++ b/scripts/context/lua/mtx-context.lua @@ -6,6 +6,88 @@ if not modules then modules = { } end modules ['mtx-context'] = { license = "see context related readme files" } +local basicinfo = [[ +--run process (one or more) files (default action) +--make create context formats + +--ctx=name use ctx file (process management specification) +--interface use specified user interface (default: en) + +--autopdf close pdf file in viewer and start pdf viewer afterwards +--purge(all) purge files either or not after a run (--pattern=...) + +--usemodule=list load the given module or style, normally part o fthe distribution +--environment=list load the given environment file first (document styles) +--mode=list enable given the modes (conditional processing in styles) +--path=list also consult the given paths when files are looked for +--arguments=list set variables that can be consulted during a run (key/value pairs) +--randomseed=number set the randomseed +--result=name rename the resulting output to the given name +--trackers=list set tracker variables (show list with --showtrackers) +--directives=list set directive variables (show list with --showdirectives) +--silent=list disable logcatgories (show list with --showlogcategories) +--purgeresult purge result file before run + +--forcexml force xml stub (optional flag: --mkii) +--forcecld force cld (context lua document) stub + +--arrange run extra imposition pass, given that the style sets up imposition +--noarrange ignore imposition specifications in the style + +--once only run once (no multipass data file is produced) +--batchmode run without stopping and don't show messages on the console +--nonstopmode run without stopping + +--generate generate file database etc. (as luatools does) +--paranoid don't descend to .. and ../.. +--version report installed context version + +--expert expert options +]] + +-- filter=list is kind of obsolete +-- color is obsolete for mkiv, always on +-- separation is obsolete for mkiv, no longer available +-- output is currently obsolete for mkiv +-- setuppath=list must check +-- modefile=name must check +-- input=name load the given inputfile (must check) + +local expertinfo = [[ +expert options: + +--touch update context version number (remake needed afterwards, also provide --expert) +--nostats omit runtime statistics at the end of the run +--update update context from website (not to be confused with contextgarden) +--profile profile job (use: mtxrun --script profile --analyze) +--timing generate timing and statistics overview +--tracefiles show some extra info when locating files (at the tex end) + +--extra=name process extra (mtx-context-<name> in distribution) +--extras show extras +]] + +local specialinfo = [[ +special options: + +--pdftex process file with texexec using pdftex +--xetex process file with texexec using xetex + +--pipe don't check for file and enter scroll mode (--dummyfile=whatever.tmp) +]] + +local application = logs.application { + name = "mtx-context", + banner = "ConTeXt Process Management 0.52", + helpinfo = { + basic = basicinfo, + extra = extrainfo, + expert = expertinfo, + } +} + +local report = application.report + scripts = scripts or { } scripts.context = scripts.context or { } @@ -118,13 +200,13 @@ do elseif ctxdata.ctxname then ctlname = file.replacesuffix(ctxdata.ctxname,'ctl') else - logs.simple("invalid ctl name: %s",ctlname or "?") + report("invalid ctl name: %s",ctlname or "?") return end end local prepfiles = ctxdata.prepfiles if prepfiles and next(prepfiles) then - logs.simple("saving logdata in: %s",ctlname) + report("saving logdata in: %s",ctlname) f = io.open(ctlname,'w') if f then f:write("<?xml version='1.0' standalone='yes'?>\n\n") @@ -138,7 +220,7 @@ do f:close() end else - logs.simple("nothing prepared, no ctl file saved") + report("nothing prepared, no ctl file saved") os.remove(ctlname) end end @@ -173,8 +255,8 @@ do ctxdata.jobname = file.addsuffix(ctxdata.jobname,'tex') ctxdata.ctxname = file.addsuffix(ctxdata.ctxname,'ctx') - logs.simple("jobname: %s",ctxdata.jobname) - logs.simple("ctxname: %s",ctxdata.ctxname) + report("jobname: %s",ctxdata.jobname) + report("ctxname: %s",ctxdata.ctxname) -- mtxrun should resolve kpse: and file: @@ -225,7 +307,7 @@ do local messages = ctxdata.messages for i=1,#messages do - logs.simple("ctx comment: %s", xml.tostring(messages[i])) + report("ctx comment: %s", xml.tostring(messages[i])) end for r, d, k in xml.elements(ctxdata.xmldata,"ctx:value[@name='job']") do @@ -318,11 +400,11 @@ do -- potential optimization: when mtxrun run internal command = xml.content(command) command = ctxrunner.justtext(command) - logs.simple("command: %s",command) + report("command: %s",command) local result = os.spawn(command) or 0 -- somehow we get the wrong return value if result > 0 then - logs.simple("error, return code: %s",result) + report("error, return code: %s",result) end if ctxdata.runlocal then oldfile = file.basename(oldfile) @@ -333,11 +415,11 @@ do file.syncmtimes(oldfile,newfile) ctxdata.prepfiles[oldfile] = true else - logs.simple("error, check target location of new file: %s", newfile) + report("error, check target location of new file: %s", newfile) ctxdata.prepfiles[oldfile] = false end else - logs.simple("old file needs no preprocessing") + report("old file needs no preprocessing") ctxdata.prepfiles[oldfile] = lfs.isfile(newfile) end end @@ -447,10 +529,15 @@ function scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,curr -- setalways("%% feedback and basic job control") if type(environment.argument("trackers")) == "string" then - setvalue ("trackers" , "\\enabletrackers[%s]") + setvalue("trackers" , "\\enabletrackers[%s]") end if type(environment.argument("directives")) == "string" then - setvalue ("directives", "\\enabledirectives[%s]") + setvalue("directives", "\\enabledirectives[%s]") + end + if type(environment.argument("silent")) == "string" then + setvalue("silent", "\\enabledirectives[logs.blocked={%s}]") + elseif environment.argument("silent") then + setvalue("silent", "\\enabledirectives[logs.blocked=*]") -- maybe \silentmode end setfixed ("timing" , "\\usemodule[timing]") setfixed ("batchmode" , "\\batchmode") @@ -490,7 +577,7 @@ function scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,curr setalways("%% options (not that important)") -- setalways("\\startsetups *runtime:options") - setvalue ('output' , "\\setupoutput[%s]", scripts.context.backends, 'pdftex') + setvalue ('output' , "\\setupoutput[%s]", scripts.context.backends, 'pdf') setfixed ("color" , "\\setupcolors[\\c!state=\\v!start]") setvalue ("separation" , "\\setupcolors[\\c!split=%s]") setfixed ("noarrange" , "\\setuparranging[\\v!disable]") @@ -640,7 +727,7 @@ local pdfview -- delayed loading function scripts.context.openpdf(name,method) pdfview = pdfview or dofile(resolvers.findfile("l-pdfview.lua","tex")) pdfview.setmethod(method) - logs.simple(pdfview.status()) + report(pdfview.status()) pdfview.open(file.replacesuffix(name,"pdf")) end @@ -669,7 +756,7 @@ function scripts.context.run(ctxdata,filename) local formatfile, scriptfile = resolvers.locateformat(formatname) -- this catches the command line if not formatfile or not scriptfile then - logs.simple("warning: no format found, forcing remake (commandline driven)") + report("warning: no format found, forcing remake (commandline driven)") scripts.context.make(formatname) formatfile, scriptfile = resolvers.locateformat(formatname) end @@ -716,7 +803,7 @@ function scripts.context.run(ctxdata,filename) end -- this catches the command line if not formatfile or not scriptfile then - logs.simple("warning: no format found, forcing remake (source driven)") + report("warning: no format found, forcing remake (source driven)") scripts.context.make(formatname) formatfile, scriptfile = resolvers.locateformat(formatname) end @@ -785,7 +872,7 @@ function scripts.context.run(ctxdata,filename) -- local okay = statistics.checkfmtstatus(formatfile) if okay ~= true then - logs.simple("warning: %s, forcing remake",tostring(okay)) + report("warning: %s, forcing remake",tostring(okay)) scripts.context.make(formatname) end -- @@ -794,7 +881,7 @@ function scripts.context.run(ctxdata,filename) flags[#flags+1] = "--interaction=batchmode" end if environment.argument("synctex") then - logs.simple("warning: syntex is enabled") -- can add upto 5% runtime + report("warning: syntex is enabled") -- can add upto 5% runtime flags[#flags+1] = "--synctex=1" end flags[#flags+1] = "--fmt=" .. string.quote(formatfile) @@ -809,22 +896,22 @@ function scripts.context.run(ctxdata,filename) -- 1:first run, 2:successive run, 3:once, 4:last of maxruns local kindofrun = (once and 3) or (i==1 and 1) or (i==maxnofruns and 4) or 2 scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,i,false) -- kindofrun, currentrun, final - logs.simple("run %s: %s",i,command) + report("run %s: %s",i,command) local returncode, errorstring = os.spawn(command) --~ if returncode == 3 then --~ scripts.context.make(formatname) --~ returncode, errorstring = os.spawn(command) --~ if returncode == 3 then - --~ logs.simple("ks: return code 3, message: %s",errorstring or "?") + --~ report("ks: return code 3, message: %s",errorstring or "?") --~ os.exit(1) --~ end --~ end if not returncode then - logs.simple("fatal error: no return code, message: %s",errorstring or "?") + report("fatal error: no return code, message: %s",errorstring or "?") os.exit(1) break elseif returncode > 0 then - logs.simple("fatal error: return code: %s",returncode or "?") + report("fatal error: return code: %s",returncode or "?") os.exit(returncode) break else @@ -842,13 +929,13 @@ function scripts.context.run(ctxdata,filename) if arrange then local kindofrun = 3 scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,i,true) -- kindofrun, currentrun, final - logs.simple("arrange run: %s",command) + report("arrange run: %s",command) local returncode, errorstring = os.spawn(command) if not returncode then - logs.simple("fatal error: no return code, message: %s",errorstring or "?") + report("fatal error: no return code, message: %s",errorstring or "?") os.exit(1) elseif returncode > 0 then - logs.simple("fatal error: return code: %s",returncode or "?") + report("fatal error: return code: %s",returncode or "?") os.exit(returncode) end end @@ -881,7 +968,7 @@ function scripts.context.run(ctxdata,filename) os.rename(tmpname,oldname) end end - logs.simple("result renamed to: %s",newbase) + report("result renamed to: %s",newbase) end -- if environment.argument("purge") then @@ -896,18 +983,18 @@ function scripts.context.run(ctxdata,filename) end -- if environment.argument("timing") then - logs.line() - logs.simple("you can process (timing) statistics with:",jobname) - logs.line() - logs.simple("context --extra=timing '%s'",jobname) - logs.simple("mtxrun --script timing --xhtml [--launch --remove] '%s'",jobname) - logs.line() + report() + report("you can process (timing) statistics with:",jobname) + report() + report("context --extra=timing '%s'",jobname) + report("mtxrun --script timing --xhtml [--launch --remove] '%s'",jobname) + report() end else if formatname then - logs.simple("error, no format found with name: %s, skipping",formatname) + report("error, no format found with name: %s, skipping",formatname) else - logs.simple("error, no format found (provide formatname or interface)") + report("error, no format found (provide formatname or interface)") end break end @@ -915,9 +1002,9 @@ function scripts.context.run(ctxdata,filename) end else if formatname then - logs.simple("error, no format found with name: %s, aborting",formatname) + report("error, no format found with name: %s, aborting",formatname) else - logs.simple("error, no format found (provide formatname or interface)") + report("error, no format found (provide formatname or interface)") end end end @@ -931,14 +1018,14 @@ function scripts.context.pipe() local formatname = scripts.context.interfaces[interface] or "cont-en" local formatfile, scriptfile = resolvers.locateformat(formatname) if not formatfile or not scriptfile then - logs.simple("warning: no format found, forcing remake (commandline driven)") + report("warning: no format found, forcing remake (commandline driven)") scripts.context.make(formatname) formatfile, scriptfile = resolvers.locateformat(formatname) end if formatfile and scriptfile then local okay = statistics.checkfmtstatus(formatfile) if okay ~= true then - logs.simple("warning: %s, forcing remake",tostring(okay)) + report("warning: %s, forcing remake",tostring(okay)) scripts.context.make(formatname) end local flags = { @@ -950,12 +1037,12 @@ function scripts.context.pipe() local filename = environment.argument("dummyfile") or "" if filename == "" then filename = "\\relax" - logs.simple("entering scrollmode, end job with \\end") + report("entering scrollmode, end job with \\end") else filename = file.addsuffix(filename,"tmp") io.savedata(filename,"\\relax") scripts.context.multipass.makeoptionfile(filename,{ flags = flags },3,1,false) -- kindofrun, currentrun, final - logs.simple("entering scrollmode using '%s' with optionfile, end job with \\end",filename) + report("entering scrollmode using '%s' with optionfile, end job with \\end",filename) end local command = string.format("luatex %s %s", table.concat(flags," "), string.quote(filename)) os.spawn(command) @@ -967,9 +1054,9 @@ function scripts.context.pipe() end else if formatname then - logs.simple("error, no format found with name: %s, aborting",formatname) + report("error, no format found with name: %s, aborting",formatname) else - logs.simple("error, no format found (provide formatname or interface)") + report("error, no format found (provide formatname or interface)") end end end @@ -979,7 +1066,7 @@ local make_mkiv_format = environment.make_format local function make_mkii_format(name,engine) if environment.argument(engine) then local command = string.format("mtxrun texexec.rb --make --%s %s",name,engine) - logs.simple("running command: %s",command) + report("running command: %s",command) os.spawn(command) end end @@ -1051,7 +1138,7 @@ function scripts.context.metapost() dofile(resolvers.findfile("mlib-run.lua")) loaded = true commands = commands or { } - commands.writestatus = logs.report + commands.writestatus = report -- no longer needed end local formatname = environment.argument("format") or "metafun" if formatname == "" or type(format) == "boolean" then @@ -1079,20 +1166,20 @@ end function scripts.context.version() local name = resolvers.findfile("context.mkiv") if name ~= "" then - logs.simple("main context file: %s",name) + report("main context file: %s",name) local data = io.loaddata(name) if data then local version = data:match("\\edef\\contextversion{(.-)}") if version then - logs.simple("current version: %s",version) + report("current version: %s",version) else - logs.simple("context version: unknown, no timestamp found") + report("context version: unknown, no timestamp found") end else - logs.simple("context version: unknown, load error") + report("context version: unknown, load error") end else - logs.simple("main context file: unknown, 'context.mkiv' not found") + report("main context file: unknown, 'context.mkiv' not found") end end @@ -1157,7 +1244,7 @@ function scripts.context.purge_job(jobname,all,mkiitoo) end end if #deleted > 0 then - logs.simple("purged files: %s", table.concat(deleted,", ")) + report("purged files: %s", table.concat(deleted,", ")) end end end @@ -1187,7 +1274,7 @@ function scripts.context.purge(all,pattern,mkiitoo) end end if #deleted > 0 then - logs.simple("purged files: %s", table.concat(deleted,", ")) + report("purged files: %s", table.concat(deleted,", ")) end end @@ -1215,12 +1302,12 @@ end local function touchfiles(suffix) local done, oldversion, newversion, foundname = touch(file.addsuffix("context",suffix),"(\\edef\\contextversion{)(.-)(})") if done then - logs.simple("old version : %s", oldversion) - logs.simple("new version : %s", newversion) - logs.simple("touched file: %s", foundname) + report("old version : %s", oldversion) + report("new version : %s", newversion) + report("touched file: %s", foundname) local ok, _, _, foundname = touch(file.addsuffix("cont-new",suffix), "(\\newcontextversion{)(.-)(})") if ok then - logs.simple("touched file: %s", foundname) + report("touched file: %s", foundname) end end end @@ -1237,26 +1324,21 @@ end function scripts.context.extras(pattern) local found = resolvers.findfile("context.mkiv") if found == "" then - logs.simple("unknown extra: %s", extra) + report("unknown extra: %s", extra) else pattern = file.join(dir.expandname(file.dirname(found)),string.format("mtx-context-%s.tex",pattern or "*")) local list = dir.glob(pattern) - if not extra or extra == "" then - logs.extendbanner("extras") - else - logs.extendbanner(extra) - end for i=1,#list do local v = list[i] local data = io.loaddata(v) or "" data = string.match(data,"begin help(.-)end help") if data then - local h = { string.format("extra: %s (%s)",string.gsub(v,"^.*mtx%-context%-(.-)%.tex$","%1"),v) } + report() + report(string.format("extra: %s (%s)",string.gsub(v,"^.*mtx%-context%-(.-)%.tex$","%1"),v)) for s in string.gmatch(data,"%% *(.-)[\n\r]") do - h[#h+1] = s + report(s) end - h[#h+1] = "" - logs.help(table.concat(h,"\n"),"nomoreinfo") + report() end end end @@ -1277,7 +1359,7 @@ function scripts.context.extra() scripts.context.extras() return else - logs.simple("processing extra: %s", foundextra) + report("processing extra: %s", foundextra) end environment.setargument("purgeall",true) local result = environment.setargument("result") or "" @@ -1294,17 +1376,24 @@ end -- todo: we need to do a dummy run function scripts.context.trackers() - environment.files = { resolvers.findfile("m-trackers.tex") } + environment.files = { resolvers.findfile("m-trackers.mkiv") } scripts.context.multipass.nofruns = 1 + environment.setargument("purgeall",true) scripts.context.run() - -- maybe filter from log end function scripts.context.directives() - environment.files = { resolvers.findfile("m-directives.tex") } + environment.files = { resolvers.findfile("m-directives.mkiv") } scripts.context.multipass.nofruns = 1 + environment.setargument("purgeall",true) + scripts.context.run() +end + +function scripts.context.logcategories() + environment.files = { resolvers.findfile("m-logcategories.mkiv") } + scripts.context.multipass.nofruns = 1 + environment.setargument("purgeall",true) scripts.context.run() - -- maybe filter from log end function scripts.context.timed(action) @@ -1332,12 +1421,12 @@ function scripts.context.update() local http = require("socket.http") local basepath = resolvers.findfile("context.mkiv") or "" if basepath == "" then - logs.simple("quiting, no 'context.mkiv' found") + report("quiting, no 'context.mkiv' found") return end local basetree = basepath.match(basepath,"^(.-)tex/context/base/context.mkiv$") or "" if basetree == "" then - logs.simple("quiting, no proper tds structure (%s)",basepath) + report("quiting, no proper tds structure (%s)",basepath) return end local function is_okay(basetree) @@ -1351,19 +1440,19 @@ function scripts.context.update() end local okay = is_okay(basetree) if not okay then - logs.simple("quiting, tree '%s' is protected",okay) + report("quiting, tree '%s' is protected",okay) return else - logs.simple("updating tree '%s'",okay) + report("updating tree '%s'",okay) end if not lfs.chdir(basetree) then - logs.simple("quiting, unable to change to '%s'",okay) + report("quiting, unable to change to '%s'",okay) return end - logs.simple("fetching '%s'",mainzip) + report("fetching '%s'",mainzip) local latest = http.request(mainzip) if not latest then - logs.simple("context tree '%s' can be updated, use --force",okay) + report("context tree '%s' can be updated, use --force",okay) return end io.savedata("cont-tmf.zip",latest) @@ -1374,12 +1463,12 @@ function scripts.context.update() -- variant 2 local zipfile = zip.open(zipname) if not zipfile then - logs.simple("quiting, unable to open '%s'",zipname) + report("quiting, unable to open '%s'",zipname) return end local newfile = zip.loaddata(zipfile,"tex/context/base/context.mkiv") if not newfile then - logs.simple("quiting, unable to open '%s'","context.mkiv") + report("quiting, unable to open '%s'","context.mkiv") return end local oldfile = io.loaddata(resolvers.findfile("context.mkiv")) or "" @@ -1388,23 +1477,23 @@ function scripts.context.update() local year, month, day, hour, minute = str:match("\\edef\\contextversion{(%d+)%.(%d+)%.(%d+) *(%d+)%:(%d+)}") if year and minute then local time = os.time { year=year,month=month,day=day,hour=hour,minute=minute} - logs.simple("%s version: %s (%s)",what,version,time) + report("%s version: %s (%s)",what,version,time) return time else - logs.simple("%s version: %s (unknown)",what,version) + report("%s version: %s (unknown)",what,version) return nil end end local oldversion = versiontonumber("old",oldfile) local newversion = versiontonumber("new",newfile) if not oldversion or not newversion then - logs.simple("quiting, version cannot be determined") + report("quiting, version cannot be determined") return elseif oldversion == newversion then - logs.simple("quiting, your current version is up-to-date") + report("quiting, your current version is up-to-date") return elseif oldversion > newversion then - logs.simple("quiting, your current version is newer") + report("quiting, your current version is newer") return end for k in zipfile:files() do @@ -1417,7 +1506,7 @@ function scripts.context.update() if force then io.savedata(filename,data) end - logs.simple(filename) + report(filename) end end end @@ -1427,13 +1516,13 @@ function scripts.context.update() local newscript = "./scripts/context/lua/" .. scriptname local data = io.loaddata(newscript) or "" if data ~= "" then - logs.simple("replacing script '%s' by '%s'",oldscript,newscript) + report("replacing script '%s' by '%s'",oldscript,newscript) if force then io.savedata(oldscript,data) end end else - logs.simple("keeping script '%s'",oldscript) + report("keeping script '%s'",oldscript) end end if force then @@ -1441,83 +1530,12 @@ function scripts.context.update() end end if force then - logs.simple("context tree '%s' has been updated",okay) + report("context tree '%s' has been updated",okay) else - logs.simple("context tree '%s' can been updated (use --force)",okay) + report("context tree '%s' can been updated (use --force)",okay) end end -logs.extendbanner("ConTeXt Process Management 0.51") - -messages.help = [[ ---run process (one or more) files (default action) ---make create context formats - ---ctx=name use ctx file (process management specification) ---interface use specified user interface (default: en) - ---autopdf close pdf file in viewer and start pdf viewer afterwards ---purge(all) purge files either or not after a run (--pattern=...) - ---usemodule=list load the given module or style, normally part o fthe distribution ---environment=list load the given environment file first (document styles) ---mode=list enable given the modes (conditional processing in styles) ---path=list also consult the given paths when files are looked for ---arguments=list set variables that can be consulted during a run (key/value pairs) ---randomseed=number set the randomseed ---result=name rename the resulting output to the given name ---trackers=list show/set tracker variables ---directives=list show/set directive variables ---purgeresult purge result file before run - ---forcexml force xml stub (optional flag: --mkii) ---forcecld force cld (context lua document) stub - ---arrange run extra imposition pass, given that the style sets up imposition ---noarrange ignore imposition specifications in the style - ---once only run once (no multipass data file is produced) ---batchmode run without stopping and don't show messages on the console ---nonstopmode run without stopping - ---generate generate file database etc. (as luatools does) ---paranoid don't descend to .. and ../.. ---version report installed context version - ---expert expert options -]] - --- filter=list is kind of obsolete --- color is obsolete for mkiv, always on --- separation is obsolete for mkiv, no longer available --- output is currently obsolete for mkiv --- setuppath=list must check --- modefile=name must check --- input=name load the given inputfile (must check) - -messages.expert = [[ -expert options: - ---touch update context version number (remake needed afterwards, also provide --expert) ---nostats omit runtime statistics at the end of the run ---update update context from website (not to be confused with contextgarden) ---profile profile job (use: mtxrun --script profile --analyze) ---timing generate timing and statistics overview ---tracefiles show some extra info when locating files (at the tex end) - ---extra=name process extra (mtx-context-<name> in distribution) ---extras show extras -]] - -messages.special = [[ -special options: - ---pdftex process file with texexec using pdftex ---xetex process file with texexec using xetex - ---pipe don't check for file and enter scroll mode (--dummyfile=whatever.tmp) -]] - if environment.argument("once") then scripts.context.multipass.nofruns = 1 elseif environment.argument("runs") then @@ -1546,7 +1564,7 @@ elseif environment.argument("touch") then elseif environment.argument("update") then scripts.context.update() elseif environment.argument("expert") then - logs.help(table.concat({ messages.expert, messages.special },"\n")) + application.help("expert", "special") elseif environment.argument("extras") then scripts.context.extras() elseif environment.argument("extra") then @@ -1555,12 +1573,14 @@ elseif environment.argument("help") then if environment.files[1] == "extras" then scripts.context.extras() else - logs.help(messages.help) + application.help("basic") end -elseif environment.argument("trackers") and type(environment.argument("trackers")) == "boolean" then +elseif environment.argument("showtrackers") or environment.argument("trackers") == true then scripts.context.trackers() -elseif environment.argument("directives") and type(environment.argument("directives")) == "boolean" then +elseif environment.argument("showdirectives") or environment.argument("directives") == true then scripts.context.directives() +elseif environment.argument("showlogcategories") then + scripts.context.logcategories() elseif environment.argument("track") and type(environment.argument("track")) == "boolean" then -- for old times sake, will go scripts.context.trackers() elseif environment.files[1] then @@ -1575,7 +1595,7 @@ elseif environment.argument("purgeall") then -- only when no filename given, supports --pattern scripts.context.purge(true) else - logs.help(messages.help) + application.help("basic") end if environment.argument("profile") then diff --git a/scripts/context/lua/mtx-convert.lua b/scripts/context/lua/mtx-convert.lua index 448a1b6ca..0c5c01bbf 100644 --- a/scripts/context/lua/mtx-convert.lua +++ b/scripts/context/lua/mtx-convert.lua @@ -8,6 +8,23 @@ if not modules then modules = { } end modules ['mtx-convert'] = { -- todo: eps and svg +local helpinfo = [[ +--convertall convert all graphics on path +--inputpath=string original graphics path +--outputpath=string converted graphics path +--watch watch folders +--force force conversion (even if older) +--delay time between sweeps +]] + +local application = logs.application { + name = "mtx-convert", + banner = "ConTeXT Graphic Conversion Helpers 0.10", + helpinfo = helpinfo, +} + +local report = application.report + graphics = graphics or { } graphics.converters = graphics.converters or { } @@ -40,7 +57,7 @@ local function convert(kind,oldname,newname) if graphics.converters[kind] then -- extra test local tmpname = file.replacesuffix(newname,"tmp") local command = graphics.converters[kind](oldname,tmpname) - logs.simple("command: %s",command) + report("command: %s",command) io.flush() os.spawn(command) os.remove(newname) @@ -118,22 +135,10 @@ function scripts.convert.convertgiven() end end - -logs.extendbanner("ConTeXT Graphic Conversion Helpers 0.10") - -messages.help = [[ ---convertall convert all graphics on path ---inputpath=string original graphics path ---outputpath=string converted graphics path ---watch watch folders ---force force conversion (even if older) ---delay time between sweeps -]] - if environment.argument("convertall") then scripts.convert.convertall() elseif environment.files[1] then scripts.convert.convertgiven() else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-fonts.lua b/scripts/context/lua/mtx-fonts.lua index b42627c95..b1e5f2dde 100644 --- a/scripts/context/lua/mtx-fonts.lua +++ b/scripts/context/lua/mtx-fonts.lua @@ -6,6 +6,49 @@ if not modules then modules = { } end modules ['mtx-fonts'] = { license = "see context related readme files" } +local helpinfo = [[ +--save save open type font in raw table + +--reload generate new font database +--reload --simple generate 'luatex-fonts-names.lua' (not for context!) + +--list --name list installed fonts, filter by name [--pattern] +--list --spec list installed fonts, filter by spec [--filter] +--list --file list installed fonts, filter by file [--pattern] + +--pattern=str filter files using pattern +--filter=list key-value pairs +--all show all found instances +--info give more details +--track=list enable trackers +--statistics some info about the database + +examples of searches: + +mtxrun --script font --list somename (== --pattern=*somename*) + +mtxrun --script font --list --name somename +mtxrun --script font --list --name --pattern=*somename* + +mtxrun --script font --list --spec somename +mtxrun --script font --list --spec somename-bold-italic +mtxrun --script font --list --spec --pattern=*somename* +mtxrun --script font --list --spec --filter="fontname=somename" +mtxrun --script font --list --spec --filter="familyname=somename,weight=bold,style=italic,width=condensed" +mtxrun --script font --list --spec --filter="familyname=crap*,weight=bold,style=italic" + +mtxrun --script font --list --file somename +mtxrun --script font --list --file --pattern=*somename* +]] + +local application = logs.application { + name = "mtx-fonts", + banner = "ConTeXt Font Database Management 0.21", + helpinfo = helpinfo, +} + +local report = application.report + -- todo: fc-cache -v en check dirs, or better is: fc-cat -v | grep Directory if not fontloader then fontloader = fontforge end @@ -31,29 +74,29 @@ function fonts.names.statistics() return table.sequenced(n) end - logs.simple("cache uuid : %s", data.cache_uuid) - logs.simple("cache version : %s", data.cache_version) - logs.simple("number of trees : %s", #data.datastate) - logs.simpleline() - logs.simple("number of fonts : %s", statistics.fonts or 0) - logs.simple("used files : %s", statistics.readfiles or 0) - logs.simple("skipped files : %s", statistics.skippedfiles or 0) - logs.simple("duplicate files : %s", statistics.duplicatefiles or 0) - logs.simple("specifications : %s", #data.specifications) - logs.simple("families : %s", table.count(data.families)) - logs.simpleline() - logs.simple("mappings : %s", counted(data.mappings)) - logs.simple("fallbacks : %s", counted(data.fallbacks)) - logs.simpleline() - logs.simple("used styles : %s", table.sequenced(statistics.used_styles)) - logs.simple("used variants : %s", table.sequenced(statistics.used_variants)) - logs.simple("used weights : %s", table.sequenced(statistics.used_weights)) - logs.simple("used widths : %s", table.sequenced(statistics.used_widths)) - logs.simpleline() - logs.simple("found styles : %s", table.sequenced(statistics.styles)) - logs.simple("found variants : %s", table.sequenced(statistics.variants)) - logs.simple("found weights : %s", table.sequenced(statistics.weights)) - logs.simple("found widths : %s", table.sequenced(statistics.widths)) + report("cache uuid : %s", data.cache_uuid) + report("cache version : %s", data.cache_version) + report("number of trees : %s", #data.datastate) + report() + report("number of fonts : %s", statistics.fonts or 0) + report("used files : %s", statistics.readfiles or 0) + report("skipped files : %s", statistics.skippedfiles or 0) + report("duplicate files : %s", statistics.duplicatefiles or 0) + report("specifications : %s", #data.specifications) + report("families : %s", table.count(data.families)) + report() + report("mappings : %s", counted(data.mappings)) + report("fallbacks : %s", counted(data.fallbacks)) + report() + report("used styles : %s", table.sequenced(statistics.used_styles)) + report("used variants : %s", table.sequenced(statistics.used_variants)) + report("used weights : %s", table.sequenced(statistics.used_weights)) + report("used widths : %s", table.sequenced(statistics.used_widths)) + report() + report("found styles : %s", table.sequenced(statistics.styles)) + report("found variants : %s", table.sequenced(statistics.variants)) + report("found weights : %s", table.sequenced(statistics.weights)) + report("found widths : %s", table.sequenced(statistics.widths)) end @@ -63,7 +106,7 @@ function fonts.names.simple() local name = "luatex-fonts-names.lua" fonts.names.filters.list = simplelist fonts.names.version = simpleversion -- this number is the same as in font-dum.lua - logs.report("fontnames","generating font database for 'luatex-fonts' version %s",fonts.names.version) + report("generating font database for 'luatex-fonts' version %s",fonts.names.version) fonts.names.identify(true) local data = fonts.names.data if data then @@ -80,12 +123,12 @@ function fonts.names.simple() simplemappings[tag] = { s.rawname, s.filename, s.subfont } end end - logs.report("fontnames","saving names in '%s'",name) + report("saving names in '%s'",name) io.savedata(name,table.serialize(simplified,true)) local data = io.loaddata(resolvers.findfile("font-dum.lua","tex")) local dummy = string.match(data,"fonts%.names%.version%s*=%s*([%d%.]+)") if tonumber(dummy) ~= simpleversion then - logs.report("fontnames","warning: version number %s in 'font-dum' does not match database version number %s",dummy or "?",simpleversion) + report("warning: version number %s in 'font-dum' does not match database version number %s",dummy or "?",simpleversion) end elseif lfs.isfile(name) then os.remove(name) @@ -117,28 +160,29 @@ local function fontweight(fw) end local function showfeatures(tag,specification) - logs.simple("mapping : %s",tag) - logs.simple("fontname: %s",specification.fontname) - logs.simple("fullname: %s",specification.fullname) - logs.simple("filename: %s",specification.filename) - logs.simple("family : %s",specification.familyname or "<nofamily>") - logs.simple("weight : %s",specification.weight or "<noweight>") - logs.simple("style : %s",specification.style or "<nostyle>") - logs.simple("width : %s",specification.width or "<nowidth>") - logs.simple("variant : %s",specification.variant or "<novariant>") - logs.simple("subfont : %s",subfont(specification.subfont)) - logs.simple("fweight : %s",fontweight(specification.fontweight)) + report() + report("mapping : %s",tag) + report("fontname: %s",specification.fontname) + report("fullname: %s",specification.fullname) + report("filename: %s",specification.filename) + report("family : %s",specification.familyname or "<nofamily>") + report("weight : %s",specification.weight or "<noweight>") + report("style : %s",specification.style or "<nostyle>") + report("width : %s",specification.width or "<nowidth>") + report("variant : %s",specification.variant or "<novariant>") + report("subfont : %s",subfont(specification.subfont)) + report("fweight : %s",fontweight(specification.fontweight)) -- maybe more local features = fonts.get_features(specification.filename,specification.format) if features then for what, v in table.sortedhash(features) do local data = features[what] if data and next(data) then - logs.simple() - logs.simple("%s features:",what) - logs.simple() - logs.simple("feature script languages") - logs.simple() + report() + report("%s features:",what) + report() + report("feature script languages") + report() for f,ff in table.sortedhash(data) do local done = false for s, ss in table.sortedhash(ff) do @@ -149,24 +193,22 @@ local function showfeatures(tag,specification) else done = true end - logs.simple("% -8s % -8s % -8s",f,s,table.concat(table.sortedkeys(ss), " ")) -- todo: padd 4 + report("% -8s % -8s % -8s",f,s,table.concat(table.sortedkeys(ss), " ")) -- todo: padd 4 end end end end else - logs.simple() - logs.simple("no features") - logs.simple() + report("no features") end - logs.reportline() + report() end local function reloadbase(reload) if reload then - logs.simple("fontnames, reloading font database") + report("fontnames, reloading font database") names.load(true) - logs.simple("fontnames, done\n\n") + report("fontnames, done\n\n") end end @@ -245,17 +287,17 @@ function scripts.fonts.list() --~ mtxrun --script font --list --name --pattern=*somename* list_matches(fonts.names.list(string.topattern(pattern,true),reload,all),info) elseif filter then - logs.report("fontnames","not supported: --list --name --filter",name) + report("not supported: --list --name --filter",name) elseif given then --~ mtxrun --script font --list --name somename list_matches(fonts.names.list(given,reload,all),info) else - logs.report("fontnames","not supported: --list --name <no specification>",name) + report("not supported: --list --name <no specification>",name) end elseif environment.argument("spec") then if pattern then --~ mtxrun --script font --list --spec --pattern=*somename* - logs.report("fontnames","not supported: --list --spec --pattern",name) + report("not supported: --list --spec --pattern",name) elseif filter then --~ mtxrun --script font --list --spec --filter="fontname=somename" list_specifications(fonts.names.getlookups(filter),info) @@ -263,19 +305,19 @@ function scripts.fonts.list() --~ mtxrun --script font --list --spec somename list_specifications(fonts.names.collectspec(given,reload,all),info) else - logs.report("fontnames","not supported: --list --spec <no specification>",name) + report("not supported: --list --spec <no specification>",name) end elseif environment.argument("file") then if pattern then --~ mtxrun --script font --list --file --pattern=*somename* list_specifications(fonts.names.collectfiles(string.topattern(pattern,true),reload,all),info) elseif filter then - logs.report("fontnames","not supported: --list --spec",name) + report("not supported: --list --spec",name) elseif given then --~ mtxrun --script font --list --file somename list_specifications(fonts.names.collectfiles(given,reload,all),info) else - logs.report("fontnames","not supported: --list --file <no specification>",name) + report("not supported: --list --file <no specification>",name) end elseif pattern then --~ mtxrun --script font --list --pattern=*somename* @@ -287,7 +329,7 @@ function scripts.fonts.list() pattern = "*" list_matches(fonts.names.list(string.topattern(pattern,true),reload,all),info) else - logs.report("fontnames","not supported: --list <no specification>",name) + report("not supported: --list <no specification>",name) end end @@ -298,7 +340,7 @@ function scripts.fonts.save() local function save(savename,fontblob) if fontblob then savename = savename:lower() .. ".lua" - logs.simple("fontsave, saving data in %s",savename) + report("fontsave, saving data in %s",savename) table.tofile(savename,fontloader.to_table(fontblob),"return") fontloader.close(fontblob) end @@ -310,7 +352,7 @@ function scripts.fonts.save() if suffix == 'ttf' or suffix == 'otf' or suffix == 'ttc' or suffix == "dfont" then local fontinfo = fontloader.info(filename) if fontinfo then - logs.simple("font: %s located as %s",name,filename) + report("font: %s located as %s",name,filename) if fontinfo[1] then for k=1,#fontinfo do local v = fontinfo[k] @@ -320,56 +362,19 @@ function scripts.fonts.save() save(fontinfo.fullname,fontloader.open(filename)) end else - logs.simple("font: %s cannot be read",filename) + report("font: %s cannot be read",filename) end else - logs.simple("font: %s not saved",filename) + report("font: %s not saved",filename) end else - logs.simple("font: %s not found",name) + report("font: %s not found",name) end else - logs.simple("font: no name given") + report("font: no name given") end end -logs.extendbanner("ConTeXt Font Database Management 0.21") - -messages.help = [[ ---save save open type font in raw table - ---reload generate new font database ---reload --simple generate 'luatex-fonts-names.lua' (not for context!) - ---list --name list installed fonts, filter by name [--pattern] ---list --spec list installed fonts, filter by spec [--filter] ---list --file list installed fonts, filter by file [--pattern] - ---pattern=str filter files using pattern ---filter=list key-value pairs ---all show all found instances ---info give more details ---track=list enable trackers ---statistics some info about the database - -examples of searches: - -mtxrun --script font --list somename (== --pattern=*somename*) - -mtxrun --script font --list --name somename -mtxrun --script font --list --name --pattern=*somename* - -mtxrun --script font --list --spec somename -mtxrun --script font --list --spec somename-bold-italic -mtxrun --script font --list --spec --pattern=*somename* -mtxrun --script font --list --spec --filter="fontname=somename" -mtxrun --script font --list --spec --filter="familyname=somename,weight=bold,style=italic,width=condensed" -mtxrun --script font --list --spec --filter="familyname=crap*,weight=bold,style=italic" - -mtxrun --script font --list --file somename -mtxrun --script font --list --file --pattern=*somename* -]] - local track = environment.argument("track") if track then trackers.enable(track) end @@ -388,5 +393,5 @@ elseif environment.argument("save") then elseif environment.argument("statistics") then fonts.names.statistics() else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-grep.lua b/scripts/context/lua/mtx-grep.lua index 98378f92b..963422c68 100644 --- a/scripts/context/lua/mtx-grep.lua +++ b/scripts/context/lua/mtx-grep.lua @@ -6,11 +6,25 @@ if not modules then modules = { } end modules ['mtx-babel'] = { license = "see context related readme files" } +local helpinfo = [[ +--pattern search for pattern (optional) +--count count matches only +--nocomment skip lines that start with %% or # + +patterns are lua patterns and need to be escaped accordingly +]] + +local application = logs.application { + name = "mtx-grep", + banner = "Simple Grepper 0.10", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.grep = scripts.grep or { } -logs.extendbanner("Simple Grepper 0.10") - local find, format = string.find, string.format local cr = lpeg.P("\r") @@ -94,14 +108,6 @@ function scripts.grep.find(pattern, files, offset) end end -messages.help = [[ ---pattern search for pattern (optional) ---count count matches only ---nocomment skip lines that start with %% or # - -patterns are lua patterns and need to be escaped accordingly -]] - local pattern = environment.argument("pattern") local files = environment.files and #environment.files > 0 and environment.files @@ -110,5 +116,5 @@ if pattern and files then elseif files then scripts.grep.find(files[1], files, 2) else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-interface.lua b/scripts/context/lua/mtx-interface.lua index bee6a7da1..91ae16ce3 100644 --- a/scripts/context/lua/mtx-interface.lua +++ b/scripts/context/lua/mtx-interface.lua @@ -10,6 +10,36 @@ local concat, sort, insert = table.concat, table.sort, table.insert local gsub, format, gmatch, find = string.gsub, string.format, string.gmatch, string.find local utfchar, utfgsub = utf.char, utf.gsub +local helpinfo = [[ +--interfaces generate context interface files +--messages generate context message files +--labels generate context label files + +--context equals --interfaces --messages --languages + +--scite generate scite interface +--bbedit generate bbedit interface files +--jedit generate jedit interface files +--textpad generate textpad interface files +--text create text files for commands and environments +--raw report commands to the console +--check generate check file + +--toutf replace named characters by utf +--preprocess preprocess mkvi files to tex files [force,suffix] + +--suffix use given suffix for output files +--force force action even when in doubt +]] + +local application = logs.application { + name = "mtx-interface", + banner = "ConTeXt Interface Related Goodies 0.13", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.interface = scripts.interface or { } @@ -64,7 +94,7 @@ end function flushers.raw(interface,commands) for i=1,#commands do - logs.simple(commands[i]) + report(commands[i]) end end @@ -73,12 +103,12 @@ local textpadcreator = "mtx-interface-textpad.lua" function flushers.text(interface,commands,environments) local c, cname = { }, format("context-commands-%s.txt",interface) local e, ename = { }, format("context-environments-%s.txt",interface) - logs.simple("saving '%s'",cname) + report("saving '%s'",cname) for i=1,#commands do c[#c+1] = format("\\%s",commands[i]) end io.savedata(cname,concat(c,"\n")) - logs.simple("saving '%s'",ename) + report("saving '%s'",ename) for i=1,#environments do e[#e+1] = format("\\start%s",environments[i]) e[#e+1] = format("\\stop%s", environments[i]) @@ -92,7 +122,7 @@ function flushers.textpad(interface,commands,environments) -- plugin, this is a rewrite of a file provided by Lukas Prochazka -- local function merge(templatedata,destinationdata,categories) - logs.simple("loading '%s'",templatedata) + report("loading '%s'",templatedata) local data = io.loaddata(templatedata) local done = 0 for i=1,#categories do @@ -103,25 +133,25 @@ function flushers.textpad(interface,commands,environments) local found = resolvers.findfile(filename) or "" local blob = found ~= "" and io.loaddata(found) or "" if blob == "" then - logs.simple("category: %s, filename: %s, not found",category,filename) + report("category: %s, filename: %s, not found",category,filename) else done = done + 1 - logs.simple("category: %s, filename: %s, merged",category,filename) + report("category: %s, filename: %s, merged",category,filename) end return format("; category: %s\n; filename: %s\n%s\n\n",category,filename,blob) end) end if done > 0 then - logs.simple("saving '%s' (%s files merged)",destinationdata,done) + report("saving '%s' (%s files merged)",destinationdata,done) io.savedata(destinationdata,data) else - logs.simple("skipping '%s' (no files merged)",destinationdata) + report("skipping '%s' (no files merged)",destinationdata) end end local templatename = "textpad-context-template.txt" local templatedata = resolvers.findfile(templatename) or "" if templatedata == "" then - logs.simple("unable to locate template '%s'",templatename) + report("unable to locate template '%s'",templatename) else merge(templatedata, "context.syn", { "tex commands","context commands" }) if environment.argument("textpad") == "latex" then @@ -152,13 +182,13 @@ function scripts.interface.editor(editor,split,forcedinterfaces) end local xmlfile = resolvers.findfile("cont-en.xml") or "" if xmlfile == "" then - logs.simple("unable to locate cont-en.xml") + report("unable to locate cont-en.xml") end for i=1,#interfaces do local interface = interfaces[i] local keyfile = resolvers.findfile(format("keys-%s.xml",interface)) or "" if keyfile == "" then - logs.simple("unable to locate keys-*.xml") + report("unable to locate keys-*.xml") else local commands = { } local mappings = { } @@ -243,7 +273,7 @@ function scripts.interface.interfaces() local v = t[key] local value = v[language] or v["en"] if not value then - logs.simple("warning, no value for key '%s' for language '%s'",key,language) + report("warning, no value for key '%s' for language '%s'",key,language) else local value = t[key][language] or t[key].en texresult[#texresult+1] = format("\\setinterface%s{%s}{%s}",tag,key,value) @@ -281,9 +311,9 @@ function scripts.interface.interfaces() local texfilename = format("mult-%s.mkii",language) local xmlfilename = format("keys-%s.xml",language) io.savedata(texfilename,concat(texresult,"\n")) - logs.simple("saving interface definitions '%s'",texfilename) + report("saving interface definitions '%s'",texfilename) io.savedata(xmlfilename,concat(xmlresult,"\n")) - logs.simple("saving interface translations '%s'",xmlfilename) + report("saving interface translations '%s'",xmlfilename) if language ~= "en" and xmldata ~= "" then local newdata = xmldata:gsub("(<cd:interface.*language=.)en(.)","%1"..language.."%2",1) newdata = replace(newdata, 'cd:string', 'value', interface.commands, interface.elements, language) @@ -294,7 +324,7 @@ function scripts.interface.interfaces() newdata = replace(newdata, 'cd:inherit', 'name', interface.commands, interface.elements, language) local xmlfilename = format("cont-%s.xml",language) io.savedata(xmlfilename,newdata) - logs.simple("saving interface specification '%s'",xmlfilename) + report("saving interface specification '%s'",xmlfilename) end end end @@ -309,42 +339,42 @@ function scripts.interface.preprocess() local oldname = environment.files[i] local newname = file.replacesuffix(oldname,newsuffix) if oldname == newname then - logs.simple("skipping '%s' because old and new name are the same",oldname) + report("skipping '%s' because old and new name are the same",oldname) elseif io.exists(newname) and not force then - logs.simple("skipping '%s' because new file exists, use --force",oldname) + report("skipping '%s' because new file exists, use --force",oldname) else - logs.simple("processing '%s' into '%s'",oldname,newname) + report("processing '%s' into '%s'",oldname,newname) io.savedata(newname,resolvers.macros.preprocessed(io.loaddata(oldname))) end end end -function scripts.interface.messages() - local filename = resolvers.findfile(environment.files[1] or "mult-mes.lua") or "" - if filename ~= "" then - local messages = dofile(filename) - logs.simple("messages for * loaded from '%s'",filename) - logs.simple() - for i=1,#messageinterfaces do - local interface = messageinterfaces[i] - local texresult = { } - for category, data in next, messages do - for tag, message in next, data do - if tag ~= "files" then - local msg = message[interface] or message["all"] or message["en"] - if msg then - texresult[#texresult+1] = format("\\setinterfacemessage{%s}{%s}{%s}",category,tag,msg) - end - end - end - end - texresult[#texresult+1] = format("%%\n\\endinput") - local interfacefile = format("mult-m%s.mkii",interface) - io.savedata(interfacefile,concat(texresult,"\n")) - logs.simple("messages for '%s' saved in '%s'",interface,interfacefile) - end - end -end +-- function scripts.interface.messages() +-- local filename = resolvers.findfile(environment.files[1] or "mult-mes.lua") or "" +-- if filename ~= "" then +-- local messages = dofile(filename) +-- report("messages for * loaded from '%s'",filename) +-- report() +-- for i=1,#messageinterfaces do +-- local interface = messageinterfaces[i] +-- local texresult = { } +-- for category, data in next, messages do +-- for tag, message in next, data do +-- if tag ~= "files" then +-- local msg = message[interface] or message["all"] or message["en"] +-- if msg then +-- texresult[#texresult+1] = format("\\setinterfacemessage{%s}{%s}{%s}",category,tag,msg) +-- end +-- end +-- end +-- end +-- texresult[#texresult+1] = format("%%\n\\endinput") +-- local interfacefile = format("mult-m%s.mkii",interface) +-- io.savedata(interfacefile,concat(texresult,"\n")) +-- report("messages for '%s' saved in '%s'",interface,interfacefile) +-- end +-- end +-- end function scripts.interface.toutf() local filename = environment.files[1] @@ -363,7 +393,7 @@ function scripts.interface.toutf() contextnames.aumlaut = contextnames.adiaeresis contextnames.Aumlaut = contextnames.Adiaeresis end - logs.simple("loading '%s'",filename) + report("loading '%s'",filename) local str = io.loaddata(filename) or "" local done = { } str = gsub(str,"(\\)([a-zA-Z][a-zA-Z][a-zA-Z]+)(%s*)", function(b,s,a) @@ -378,129 +408,99 @@ function scripts.interface.toutf() end) for k, v in table.sortedpairs(done) do if v > 0 then - logs.simple("+ %5i : %s => %s",v,k,contextnames[k]) + report("+ %5i : %s => %s",v,k,contextnames[k]) else - logs.simple("- %5i : %s",-v,k,contextnames[k]) + report("- %5i : %s",-v,k,contextnames[k]) end end filename = filename .. ".toutf" - logs.simple("saving '%s'",filename) + report("saving '%s'",filename) io.savedata(filename,str) end end -function scripts.interface.labels() - require("char-def.lua") - require("lang-txt.lua") - local interfaces = require("mult-def.lua") - local variables = interfaces.variables - local contextnames = { } - for unicode, data in next, characters.data do - local contextname = data.contextname - if contextname then - contextnames[utfchar(unicode)] = "\\" .. contextname .. " " - end - end - contextnames["i"] = nil - contextnames["'"] = nil - contextnames["\\"] = nil - local function flush(f,kind,what,expand,namespace,prefix) - local whatdata = languages.data.labels[what] - f:write("\n") - f:write(format("%% %s => %s\n",what,kind)) - for tag, data in table.sortedpairs(whatdata) do - if not data.hidden then - f:write("\n") - for language, text in table.sortedpairs(data.labels) do - if text ~= "" then - if expand then - text = utfgsub(text,".",contextnames) - text = gsub(text," ", "\ ") - end - if namespace and namespace[tag] then - tag = prefix .. tag - end - if find(text,",") then - text = "{" .. text .. "}" - end - - if text == "" then - -- skip - else - if type(text) == "table" then - f:write(format("\\setup%stext[\\s!%s][%s={{%s},}]\n",kind,language,tag,text)) - else - f:write(format("\\setup%stext[\\s!%s][%s={{%s},{%s}}]\n",kind,language,tag,text[1],text[2])) - end - end - - end - end - end - end - end - function flushall(txtname,expand) - local f = io.open(txtname,"w") - if f then - logs.simple("saving '%s'",txtname) - f:write("% this file is auto-generated, don't edit this file\n") - flush(f,"head","titles",expand,variables,"\\v!") - flush(f,"label","texts",expand,variables,"\\v!") - flush(f,"mathlabel","functions",expand) - flush(f,"taglabel","tags",expand) - f:write("\n") - f:write("\\endinput\n") - f:close() - end - end - flushall("lang-txt.mkii",true) - flushall("lang-txt.mkiv",false) -end - -function scripts.interface.labels() - -- maybe supported one day -end - -logs.extendbanner("ConTeXt Interface Related Goodies 0.13") - -messages.help = [[ ---interfaces generate context interface files ---messages generate context message files ---labels generate context label files - ---context equals --interfaces --messages --languages - ---scite generate scite interface ---bbedit generate bbedit interface files ---jedit generate jedit interface files ---textpad generate textpad interface files ---text create text files for commands and environments ---raw report commands to the console ---check generate check file - ---toutf replace named characters by utf ---preprocess preprocess mkvi files to tex files [force,suffix] - ---suffix use given suffix for output files ---force force action even when in doubt -]] +-- function scripts.interface.labels() +-- require("char-def.lua") +-- require("lang-txt.lua") +-- local interfaces = require("mult-def.lua") +-- local variables = interfaces.variables +-- local contextnames = { } +-- for unicode, data in next, characters.data do +-- local contextname = data.contextname +-- if contextname then +-- contextnames[utfchar(unicode)] = "\\" .. contextname .. " " +-- end +-- end +-- contextnames["i"] = nil +-- contextnames["'"] = nil +-- contextnames["\\"] = nil +-- local function flush(f,kind,what,expand,namespace,prefix) +-- local whatdata = languages.data.labels[what] +-- f:write("\n") +-- f:write(format("%% %s => %s\n",what,kind)) +-- for tag, data in table.sortedpairs(whatdata) do +-- if not data.hidden then +-- f:write("\n") +-- for language, text in table.sortedpairs(data.labels) do +-- if text ~= "" then +-- if expand then +-- text = utfgsub(text,".",contextnames) +-- text = gsub(text," ", "\ ") +-- end +-- if namespace and namespace[tag] then +-- tag = prefix .. tag +-- end +-- if find(text,",") then +-- text = "{" .. text .. "}" +-- end +-- if text == "" then +-- -- skip +-- else +-- if type(text) == "table" then +-- f:write(format("\\setup%stext[\\s!%s][%s={{%s},}]\n",kind,language,tag,text)) +-- else +-- f:write(format("\\setup%stext[\\s!%s][%s={{%s},{%s}}]\n",kind,language,tag,text[1],text[2])) +-- end +-- end +-- end +-- end +-- end +-- end +-- end +-- function flushall(txtname,expand) +-- local f = io.open(txtname,"w") +-- if f then +-- report("saving '%s'",txtname) +-- f:write("% this file is auto-generated, don't edit this file\n") +-- flush(f,"head","titles",expand,variables,"\\v!") +-- flush(f,"label","texts",expand,variables,"\\v!") +-- flush(f,"mathlabel","functions",expand) +-- flush(f,"taglabel","tags",expand) +-- f:write("\n") +-- f:write("\\endinput\n") +-- f:close() +-- end +-- end +-- flushall("lang-txt.mkii",true) +-- flushall("lang-txt.mkiv",false) +-- end local ea = environment.argument if ea("context") then scripts.interface.interfaces() - scripts.interface.messages() - scripts.interface.labels() + -- scripts.interface.messages() + -- scripts.interface.labels() elseif ea("interfaces") or ea("messages") or ea("labels") then if ea("interfaces") then scripts.interface.interfaces() end - if ea("messages") then - scripts.interface.messages() - end - if ea("labels") then - scripts.interface.labels() - end + -- if ea("messages") then + -- scripts.interface.messages() + -- end + -- if ea("labels") then + -- scripts.interface.labels() + -- end elseif ea("preprocess") then scripts.interface.preprocess() elseif ea("toutf") then @@ -527,5 +527,5 @@ elseif ea("scite") or ea("bbedit") or ea("jedit") or ea("textpad") or ea("text") scripts.interface.editor("raw") end else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-metapost.lua b/scripts/context/lua/mtx-metapost.lua index 9bdd1260f..3b9ed6ff1 100644 --- a/scripts/context/lua/mtx-metapost.lua +++ b/scripts/context/lua/mtx-metapost.lua @@ -6,6 +6,30 @@ if not modules then modules = { } end modules ['mtx-metapost'] = { -- this was m license = "see context related readme files" } +local helpinfo = [[ +--rawmp raw metapost run +--metafun use metafun instead of plain +--latex force --tex=latex +--texexec force texexec usage (mkii) +--split split single result file into pages + +intended usage: + +mtxrun --script metapost yourfile.mp +mtxrun --script metapost --split yourfile.mp +mtxrun --script metapost yourfile.123 myfile.mps + +other usage resembles mptopdf.pl +]] + +local application = logs.application { + name = "mtx-metapost", + banner = "MetaPost to PDF processor 0.10", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.mptopdf = scripts.mptopdf or { } scripts.mptopdf.aux = scripts.mptopdf.aux or { } @@ -67,23 +91,23 @@ local function do_convert_all(filename) end end if #report > 0 then - logs.simple("number of converted files: %i", #report) - logs.simple("") + report("number of converted files: %i", #report) + report() for i=1,#report do local r = report[i] - logs.simple("%s => %s", r[1], r[2]) + report("%s => %s", r[1], r[2]) end else - logs.simple("no files are converted for '%s'",filename) + report("no files are converted for '%s'",filename) end end local function do_convert_one(filename) local resultname = do_convert(filename) if resultname then - logs.simple("%s => %s", filename,resultname) + report("%s => %s", filename,resultname) else - logs.simple("no result for '%s'",filename) + report("no result for '%s'",filename) end end @@ -121,7 +145,7 @@ function scripts.mptopdf.convertall() command, convert = format("context --result=%s --purge --once %s",file.nameonly(filename),tempname), false end end - logs.simple("running: %s\n",command) + report("running: %s",command) local done = os.execute(command) if done then if convert then @@ -131,41 +155,23 @@ function scripts.mptopdf.convertall() -- already pdf, maybe optionally split end else - logs.simple("error while processing mp file '%s'", filename) + report("error while processing mp file '%s'", filename) end else do_convert_one(filename) end end else - logs.simple("no files match to process") + report("no files match to process") end end -logs.extendbanner("MetaPost to PDF processor 0.10") - -messages.help = [[ ---rawmp raw metapost run ---metafun use metafun instead of plain ---latex force --tex=latex ---texexec force texexec usage (mkii) ---split split single result file into pages - -intended usage: - -mtxrun --script metapost yourfile.mp -mtxrun --script metapost --split yourfile.mp -mtxrun --script metapost yourfile.123 myfile.mps - -other usage resembles mptopdf.pl -]] - if environment.files[1] then scripts.mptopdf.convertall() else if not environment.arguments.help then - logs.simple("provide MP output file (or pattern)") - logs.simple("") + report("provide MP output file (or pattern)") + report() end - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-metatex.lua b/scripts/context/lua/mtx-metatex.lua index c5865b808..0b66d59ef 100644 --- a/scripts/context/lua/mtx-metatex.lua +++ b/scripts/context/lua/mtx-metatex.lua @@ -8,6 +8,19 @@ if not modules then modules = { } end modules ['mtx-metatex'] = { -- future versions will deal with specific variants of metatex +local helpinfo = [[ +--run process (one or more) files (default action) +--make create metatex format(s) +]] + +local application = logs.application { + name = "mtx-metatex", + banner = "MetaTeX Process Management 0.10", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.metatex = scripts.metatex or { } @@ -24,12 +37,12 @@ function scripts.metatex.run(ctxdata,filename) if formatfile and scriptfile then local command = string.format("luatex --fmt=%s --lua=%s %s", string.quote(formatfile), string.quote(scriptfile), string.quote(filename)) - logs.simple("running command: %s",command) + report("running command: %s",command) os.spawn(command) elseif formatname then - logs.simple("error, no format found with name: %s",formatname) + report("error, no format found with name: %s",formatname) else - logs.simple("error, no format found (provide formatname or interface)") + report("error, no format found (provide formatname or interface)") end end end @@ -38,13 +51,6 @@ function scripts.metatex.timed(action) statistics.timed(action) end -logs.extendbanner("MetaTeX Process Management 0.10") - -messages.help = [[ ---run process (one or more) files (default action) ---make create metatex format(s) -]] - if environment.argument("run") then scripts.metatex.timed(scripts.metatex.run) elseif environment.argument("make") then @@ -54,5 +60,5 @@ elseif environment.argument("help") then elseif environment.files[1] then scripts.metatex.timed(scripts.metatex.run) else - logs.help(messages.help,false) + application.help() end diff --git a/scripts/context/lua/mtx-modules.lua b/scripts/context/lua/mtx-modules.lua index 632aa0f68..8f3ab89cf 100644 --- a/scripts/context/lua/mtx-modules.lua +++ b/scripts/context/lua/mtx-modules.lua @@ -9,6 +9,20 @@ if not modules then modules = { } end modules ['mtx-modules'] = { scripts = scripts or { } scripts.modules = scripts.modules or { } +local helpinfo = [[ +--convert convert source files (tex, mkii, mkiv, mp) to 'ted' files +--process process source files (tex, mkii, mkiv, mp) to 'pdf' files +--prep use original name with suffix 'prep' appended +]] + +local application = logs.application { + name = "mtx-modules", + banner = "ConTeXt Module Documentation Generators 1.00", + helpinfo = helpinfo, +} + +local report = application.report + -- Documentation can be woven into a source file. This script can generates -- a file with the documentation and source fragments properly tagged. The -- documentation is included as comment: @@ -39,15 +53,15 @@ local find, format, sub, is_empty, strip = string.find, string.format, string.su local function source_to_ted(inpname,outname,filetype) local inp = io.open(inpname) if not inp then - logs.simple("unable to open '%s'",inpname) + report("unable to open '%s'",inpname) return end local out = io.open(outname,"w") if not out then - logs.simple("unable to open '%s'",outname) + report("unable to open '%s'",outname) return end - logs.simple("converting '%s' to '%s'",inpname,outname) + report("converting '%s' to '%s'",inpname,outname) local skiplevel, indocument, indefinition = 0, false, false out:write(format("\\startmodule[type=%s]\n",filetype or file.suffix(inpname))) for line in inp:lines() do @@ -143,25 +157,16 @@ function scripts.modules.process(runtex) end for i=1,#processed do local name = processed[i] - logs.simple("modules","processed: %s",name) + report("modules","processed: %s",name) end end -- context --ctx=m-modules.ctx xxx.mkiv - -logs.extendbanner("ConTeXt Module Documentation Generators 1.00") - -messages.help = [[ ---convert convert source files (tex, mkii, mkiv, mp) to 'ted' files ---process process source files (tex, mkii, mkiv, mp) to 'pdf' files ---prep use original name with suffix 'prep' appended -]] - if environment.argument("process") then scripts.modules.process(true) elseif environment.argument("convert") then scripts.modules.process(false) else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-package.lua b/scripts/context/lua/mtx-package.lua index 5269eb34c..294ef4f28 100644 --- a/scripts/context/lua/mtx-package.lua +++ b/scripts/context/lua/mtx-package.lua @@ -8,6 +8,18 @@ if not modules then modules = { } end modules ['mtx-package'] = { local format, gsub, gmatch = string.format, string.gsub, string.gmatch +local helpinfo = [[ +--merge merge 'loadmodule' into merge file +]] + +local application = logs.application { + name = "mtx-package", + banner = "Distribution Related Goodies 0.10", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } messages = messages or { } scripts.package = scripts.package or { } @@ -16,14 +28,14 @@ function scripts.package.merge_luatex_files(name,strip) local oldname = resolvers.findfile(name) or "" oldname = file.replacesuffix(oldname,"lua") if oldname == "" then - logs.simple("missing '%s'",name) + report("missing '%s'",name) else local newname = file.removesuffix(oldname) .. "-merged.lua" local data = io.loaddata(oldname) or "" if data == "" then - logs.simple("missing '%s'",newname) + report("missing '%s'",newname) else - logs.simple("loading '%s'",oldname) + report("loading '%s'",oldname) local collected = { } collected[#collected+1] = format("-- merged file : %s\n",newname) collected[#collected+1] = format("-- parent file : %s\n",oldname) @@ -33,9 +45,9 @@ function scripts.package.merge_luatex_files(name,strip) if file.basename(lib) ~= file.basename(newname) then local fullname = resolvers.findfile(lib) or "" if fullname == "" then - logs.simple("missing '%s'",lib) + report("missing '%s'",lib) else - logs.simple("fetching '%s'",fullname) + report("fetching '%s'",fullname) local data = io.loaddata(fullname) if strip then data = gsub(data,"%-%-%[%[ldx%-%-.-%-%-%ldx%]%]%-%-[\n\r]*","") @@ -49,20 +61,14 @@ function scripts.package.merge_luatex_files(name,strip) end end end - logs.simple("saving '%s'",newname) + report("saving '%s'",newname) io.savedata(newname,table.concat(collected)) end end end -logs.extendbanner("Distribution Related Goodies 0.10") - -messages.help = [[ ---merge merge 'loadmodule' into merge file -]] - if environment.argument("merge") then scripts.package.merge_luatex_files(environment.files[1] or "") else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-patterns.lua b/scripts/context/lua/mtx-patterns.lua index cb5717c58..bbf475133 100644 --- a/scripts/context/lua/mtx-patterns.lua +++ b/scripts/context/lua/mtx-patterns.lua @@ -11,10 +11,31 @@ local byte, char = utf.byte, utf.char local addsuffix = file.addsuffix local lpegmatch, validutf8 = lpeg.match, lpeg.patterns.validutf8 +local helpinfo = [[ +--convert generate context language files (mnemonic driven, if not given then all) +--check check pattern file (or those used by context when no file given) +--path source path where hyph-foo.tex files are stored +--destination destination path + +examples of usage: + +mtxrun --script pattern --check hyph-*.tex +mtxrun --script pattern --check --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns +mtxrun --script pattern --convert --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns/tex --destination=e:/tmp/patterns +mtxrun --script pattern --convert --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns/txt --destination=e:/tmp/patterns +]] + +local application = logs.application { + name = "mtx-patterns", + banner = "ConTeXt Pattern File Management 0.20", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.patterns = scripts.patterns or { } - local permitted_characters = table.tohash { 0x0009, -- tab 0x0027, -- apostrofe @@ -138,11 +159,11 @@ function scripts.patterns.load(path,name,mnemonic,ignored) local splitpatternsold, splithyphenationsold = { }, { } local usedpatterncharacters, usedhyphenationcharacters = { }, { } if lfs.isfile(patfile) then - logs.simple("using txt files %s.[hyp|pat|lic].txt",name) + report("using txt files %s.[hyp|pat|lic].txt",name) comment, patterns, hyphenations = io.loaddata(licfile) or "", io.loaddata(patfile) or "", io.loaddata(hypfile) or "" hypfile, patfile, licfile = hypfile, patfile, licfile elseif lfs.isfile(texfile) then - logs.simple("using tex file %s.txt",name) + report("using tex file %s.txt",name) local data = io.loaddata(texfile) or "" if data ~= "" then data = gsub(data,"([\n\r])\\input ([^ \n\r]+)", function(previous,subname) @@ -150,7 +171,7 @@ function scripts.patterns.load(path,name,mnemonic,ignored) local subfull = file.join(file.dirname(texfile),subname) local subdata = io.loaddata(subfull) or "" if subdata == "" then - logs.simple("no subfile %s",subname) + report("no subfile %s",subname) end return previous .. subdata end) @@ -179,7 +200,7 @@ function scripts.patterns.load(path,name,mnemonic,ignored) local line = splitdata[i] if find(line,"%%") then splitdata[i] = gsub(line,"%%.*$","") - logs.simple("removing comment: %s",line) + report("removing comment: %s",line) end end end @@ -195,7 +216,7 @@ function scripts.patterns.load(path,name,mnemonic,ignored) local line = splitdata[i] if find(line,"\\") then splitdata[i] = "" - logs.simple("removing line with command: %s",line) + report("removing line with command: %s",line) end end end @@ -211,7 +232,7 @@ function scripts.patterns.load(path,name,mnemonic,ignored) local ok = lpegmatch(validutf8,line) if not ok then splitdata[i] = "" - logs.simple("removing line with invalid utf: %s",line) + report("removing line with invalid utf: %s",line) end end -- check for commands being used in comments @@ -235,7 +256,7 @@ function scripts.patterns.load(path,name,mnemonic,ignored) else local cdb = cd[b] if not cdb then - logs.simple("no entry in chardata for character %s (0x%04X)",char(b),b) + report("no entry in chardata for character %s (0x%04X)",char(b),b) else local ct = cd[b].category if ct == "lu" or ct == "ll" then @@ -243,7 +264,7 @@ function scripts.patterns.load(path,name,mnemonic,ignored) elseif ct == "nd" then -- number else - logs.simple("removing line with suspected utf character %s (0x%04X), category %s: %s",char(b),b,ct,line) + report("removing line with suspected utf character %s (0x%04X), category %s: %s",char(b),b,ct,line) splitdata[i] = "" break end @@ -256,7 +277,7 @@ function scripts.patterns.load(path,name,mnemonic,ignored) usedpatterncharacters = check(splitpatternsnew,byte(".")) usedhyphenationcharacters = check(splithyphenationsnew,byte("-")) for k, v in next, stripped do - logs.simple("entries that contain character %s (0x%04X) have been omitted",char(k),k) + report("entries that contain character %s (0x%04X) have been omitted",char(k),k) end end if okay then @@ -287,11 +308,11 @@ function scripts.patterns.load(path,name,mnemonic,ignored) for i=1,#what do local line = what[i] if p and lpegmatch(p,line) then - logs.simple("discarding conflicting pattern: %s",line) + report("discarding conflicting pattern: %s",line) else -- we can speed this up by testing for replacements in the string local l = lpegmatch(r,line) if l ~= line then - logs.simple("sanitizing pattern: %s -> %s (for old patterns)",line,l) + report("sanitizing pattern: %s -> %s (for old patterns)",line,l) end result[#result+1] = l end @@ -313,7 +334,7 @@ function scripts.patterns.load(path,name,mnemonic,ignored) -- discard elseif used[line] then -- discard - logs.simple("discarding duplicate pattern: %s",line) + repo("discarding duplicate pattern: %s",line) else used[line] = true collected[#collected+1] = line @@ -327,7 +348,7 @@ function scripts.patterns.load(path,name,mnemonic,ignored) splithyphenationsold = check(hyphenations,splithyphenationsold,hypfile) end if not okay then - logs.simple("no valid file %s.*",name) + report("no valid file %s.*",name) end return okay, splitpatternsnew, splithyphenationsnew, splitpatternsold, splithyphenationsold, comment, stripset, usedpatterncharacters, usedhyphenationcharacters end @@ -335,7 +356,7 @@ end function scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenationsnew,patternsold,hyphenationsold,comment,stripped,pused,hused,ignored) local nofpatternsnew, nofhyphenationsnew = #patternsnew, #hyphenationsnew local nofpatternsold, nofhyphenationsold = #patternsold, #hyphenationsold - logs.simple("language %s has %s old and %s new patterns and %s old and %s new exceptions",mnemonic,nofpatternsold,nofpatternsnew,nofhyphenationsold,nofhyphenationsnew) + report("language %s has %s old and %s new patterns and %s old and %s new exceptions",mnemonic,nofpatternsold,nofpatternsnew,nofhyphenationsold,nofhyphenationsnew) if mnemonic ~= "??" then local pu = concat(table.sortedkeys(pused), " ") local hu = concat(table.sortedkeys(hused), " ") @@ -347,7 +368,7 @@ function scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenation local topline = "% generated by mtxrun --script pattern --convert" local banner = "% for comment and copyright, see " .. rmefile - logs.simple("saving language data for %s",mnemonic) + report("saving language data for %s",mnemonic) if not comment or comment == "" then comment = "% no comment" end if not type(destination) == "string" then destination = "." end @@ -426,12 +447,12 @@ function scripts.patterns.check() for k, v in next, scripts.patterns.list do local mnemonic, name, ignored = v[1], v[2], v[4] if not only or only[mnemonic] then - logs.simple("checking language %s, file %s", mnemonic, name) + report("checking language %s, file %s", mnemonic, name) local okay = scripts.patterns.load(path,name,mnemonic,ignored) if not okay then - logs.simple("there are errors that need to be fixed") + report("there are errors that need to be fixed") end - logs.simple("") + report() end end end @@ -439,11 +460,11 @@ end function scripts.patterns.convert() local path = environment.argument("path") or "." if path == "" then - logs.simple("provide sourcepath using --path ") + report("provide sourcepath using --path ") else local destination = environment.argument("destination") or "." if path == destination then - logs.simple("source path and destination path should differ (use --path and/or --destination)") + resport("source path and destination path should differ (use --path and/or --destination)") else local files = environment.files local only = false @@ -453,36 +474,20 @@ function scripts.patterns.convert() for k, v in next, scripts.patterns.list do local mnemonic, name, ignored = v[1], v[2], v[4] if not only or only[mnemonic] then - logs.simple("converting language %s, file %s", mnemonic, name) + report("converting language %s, file %s", mnemonic, name) local okay, patternsnew, hyphenationsnew, patternsold, hyphenationsold, comment, stripped, pused, hused = scripts.patterns.load(path,name,mnemonic,ignored) if okay then scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenationsnew,patternsold,hyphenationsold,comment,stripped,pused,hused,ignored) else - logs.simple("convertion aborted due to error(s)") + report("convertion aborted due to error(s)") end - logs.simple("") + report() end end end end end -logs.extendbanner("ConTeXt Pattern File Management 0.20") - -messages.help = [[ ---convert generate context language files (mnemonic driven, if not given then all) ---check check pattern file (or those used by context when no file given) ---path source path where hyph-foo.tex files are stored ---destination destination path - -examples of usage: - -mtxrun --script pattern --check hyph-*.tex -mtxrun --script pattern --check --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns -mtxrun --script pattern --convert --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns/tex --destination=e:/tmp/patterns -mtxrun --script pattern --convert --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns/txt --destination=e:/tmp/patterns -]] - if environment.argument("check") then scripts.patterns.prepare() scripts.patterns.check() @@ -490,7 +495,7 @@ elseif environment.argument("convert") then scripts.patterns.prepare() scripts.patterns.convert() else - logs.help(messages.help) + application.help() end -- mtxrun --script pattern --check hyph-*.tex diff --git a/scripts/context/lua/mtx-profile.lua b/scripts/context/lua/mtx-profile.lua index d78e3457a..74e1d1538 100644 --- a/scripts/context/lua/mtx-profile.lua +++ b/scripts/context/lua/mtx-profile.lua @@ -11,6 +11,19 @@ if not modules then modules = { } end modules ['mtx-profile'] = { local match, format, find = string.match, string.format, string.find +local helpinfo = [[ +--analyze analyze lua calls +--trace analyze tex calls +]] + +local application = logs.application { + name = "mtx-cache", + banner = "ConTeXt MkIV LuaTeX Profiler 1.00", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.profiler = scripts.profiler or { } @@ -54,7 +67,7 @@ function scripts.profiler.analyze(filename) f:close() print("") local loaded = { } - local sortedtable.sortedkeys(times) + sortedtable.sortedkeys(times) for i=1,#sorted do local filename = sorted[i] local functions = times[filename] @@ -154,17 +167,10 @@ end --~ scripts.profiler.analyze("t:/manuals/mk/mk-fonts-profile.lua") --~ scripts.profiler.analyze("t:/manuals/mk/mk-introduction-profile.lua") -logs.extendbanner("ConTeXt MkIV LuaTeX Profiler 1.00") - -messages.help = [[ ---analyze analyze lua calls ---trace analyze tex calls -]] - if environment.argument("analyze") then scripts.profiler.analyze(environment.files[1] or "luatex-profile.log") elseif environment.argument("trace") then scripts.profiler.analyze(environment.files[1] or "temp.log") else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-scite.lua b/scripts/context/lua/mtx-scite.lua index 068e4ecf5..0ac09b017 100644 --- a/scripts/context/lua/mtx-scite.lua +++ b/scripts/context/lua/mtx-scite.lua @@ -9,6 +9,19 @@ if not modules then modules = { } end modules ['mtx-scite'] = { -- todo: append to global properties else order of loading problem -- linux problem ... files are under root protection so we need --install +local helpinfo = [[ +--start [--verbose] start scite +--test report what will happen +]] + +local application = logs.application { + name = "mtx-scite", + banner = "Scite Startup Script 1.00", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.scite = scripts.scite or { } @@ -42,11 +55,11 @@ function scripts.scite.start(indeed) end end if not datapath or datapath == "" then - logs.simple("invalid datapath, maybe you need to regenerate the file database") + report("invalid datapath, maybe you need to regenerate the file database") return false end if not binpaths or #binpaths == 0 then - logs.simple("invalid binpath") + report("invalid binpath") return false end for i=1,#binpaths do @@ -57,7 +70,7 @@ function scripts.scite.start(indeed) end end if not fullname then - logs.simple("unable to locate %s",workname) + report("unable to locate %s",workname) return false end local properties = dir.glob(file.join(datapath,"*.properties")) @@ -65,7 +78,7 @@ function scripts.scite.start(indeed) local extrafont = resolvers.findfile(screenfont,"truetype font") or "" local pragmafound = dir.glob(file.join(datapath,"pragma.properties")) if userpath == "" then - logs.simple("unable to figure out userpath") + report("unable to figure out userpath") return false end local verbose = environment.argument("verbose") @@ -120,47 +133,40 @@ function scripts.scite.start(indeed) end end if not indeed or verbose then - logs.simple("used signal: %s", usedsignal) - logs.simple("data path : %s", datapath) - logs.simple("full name : %s", fullname) - logs.simple("user path : %s", userpath) - logs.simple("extra font : %s", extrafont) + report("used signal: %s", usedsignal) + report("data path : %s", datapath) + report("full name : %s", fullname) + report("user path : %s", userpath) + report("extra font : %s", extrafont) end if #logdata > 0 then - logs.simple("") + report("") for k=1,#logdata do local v = logdata[k] - logs.simple(v[1],v[2]) + report(v[1],v[2]) end end if indeed then if #tobecopied > 0 then - logs.simple("warning : copying updated files") + report("warning : copying updated files") for i=1,#tobecopied do local what = tobecopied[i] - logs.simple("copying : '%s' => '%s'",what[1],what[2]) + report("copying : '%s' => '%s'",what[1],what[2]) file.copy(what[1],what[2]) end end if propfiledone then - logs.simple("saving : '%s'",userpropfile) + report("saving : '%s'",userpropfile) io.savedata(fullpropfile,userpropdata) end os.launch(fullname) end end -logs.extendbanner("Scite Startup Script 1.00") - -messages.help = [[ ---start [--verbose] start scite ---test report what will happen -]] - if environment.argument("start") then scripts.scite.start(true) elseif environment.argument("test") then scripts.scite.start() else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-server-ctx-fonttest.lua b/scripts/context/lua/mtx-server-ctx-fonttest.lua index d2f11ca95..9bea14561 100644 --- a/scripts/context/lua/mtx-server-ctx-fonttest.lua +++ b/scripts/context/lua/mtx-server-ctx-fonttest.lua @@ -15,6 +15,8 @@ dofile(resolvers.findfile("font-mis.lua","tex")) local format, gsub, concat, match, find = string.format, string.gsub, table.concat, string.match, string.find +local report = logs.new("ctx-fonttest") + local sample_line = "This is a sample line!" local tempname = "mtx-server-ctx-fonttest-temp" local temppath = caches.setfirstwritablefile("temp","mtx-server-ctx-fonttest") @@ -150,20 +152,20 @@ local cache = { } local function showfeatures(f) if f then - logs.simple("processing font '%s'",f) + report("processing font '%s'",f) local features = cache[f] if features == nil then features = fonts.get_features(resolvers.findfile(f)) if not features then - logs.simple("building cache for '%s'",f) + report("building cache for '%s'",f) io.savedata(file.join(temppath,file.addsuffix(tempname,"tex")),format(process_templates.cache,f,f)) os.execute(format("mtxrun --path=%s --script context --once --batchmode %s",temppath,tempname)) features = fonts.get_features(f) end cache[f] = features or false - logs.simple("caching info of '%s'",f) + report("caching info of '%s'",f) else - logs.simple("using cached info of '%s'",f) + report("using cached info of '%s'",f) end if features then local scr, lan, fea, rev = { }, { }, { }, { } @@ -294,7 +296,7 @@ local function get_specification(name) end local function edit_font(currentfont,detail,tempname) - logs.simple("entering edit mode for '%s'",currentfont) + report("entering edit mode for '%s'",currentfont) local specification = get_specification(currentfont) if specification then local htmldata = showfeatures(specification.filename) @@ -374,7 +376,7 @@ local function process_font(currentfont,detail) -- maybe just fontname end local sample = string.strip(detail.sampletext or "") if sample == "" then sample = sample_line end - logs.simple("sample text: %s",sample) + report("sample text: %s",sample) io.savedata(file.join(temppath,file.addsuffix(tempname,"tex")),format(variant,concat(features,","),currentfont,sample)) os.execute(format("mtxrun --path=%s --script context --once --batchmode %s",temppath,tempname)) return edit_font(currentfont,detail,tempname) @@ -497,7 +499,7 @@ local function loadbase() if storage == "" then storage = { } else - logs.simple("loading '%s'",datafile) + report("loading '%s'",datafile) storage = loadstring(storage) storage = (storage and storage()) or { } end @@ -527,14 +529,14 @@ end local function savebase(storage,name) local datafile = file.join(basepath,basename) - logs.simple("saving '%s' in '%s'",name or "data",datafile) + report("saving '%s' in '%s'",name or "data",datafile) io.savedata(datafile,table.serialize(storage,true)) end local function deletestored(detail,currentfont,name) local storage = loadbase() if storage and name and storage[name] then - logs.simple("deleting '%s' from base",name) + report("deleting '%s' from base",name) storage[name] = nil savebase(storage) end @@ -610,7 +612,7 @@ end function extras.reload() local command = "mtxrun --script font --reload" - logs.simple("run command: %s",command) + report("run command: %s",command) os.execute(command) return do_extras() end @@ -679,7 +681,7 @@ function doit(configuration,filename,hashed) variables.javascripts = "" variables.javascriptinit = "" - logs.simple("action: %s",action or "no action") + report("action: %s",action or "no action") local result @@ -722,7 +724,7 @@ function doit(configuration,filename,hashed) result = { content = lmx.convert('context-fonttest.lmx',false,variables) } - logs.simple("time spent on page: %0.03f seconds",os.clock()-start) + report("time spent on page: %0.03f seconds",os.clock()-start) return result diff --git a/scripts/context/lua/mtx-server-ctx-help.lua b/scripts/context/lua/mtx-server-ctx-help.lua index 5ee0c7d43..eb07a244b 100644 --- a/scripts/context/lua/mtx-server-ctx-help.lua +++ b/scripts/context/lua/mtx-server-ctx-help.lua @@ -17,6 +17,8 @@ dofile(resolvers.findfile("trac-lmx.lua","tex")) local format = string.format local concat = table.concat +local report = logs.new("ctx-help") + -- -- -- make this a module: cont-xx.lua document = document or { } @@ -591,7 +593,7 @@ local function doit(configuration,filename,hashed) lastmode = tonumber(detail.mode or lastmode) or 1 if lastinterface then - logs.simple("checking interface: %s",lastinterface) + report("checking interface: %s",lastinterface) document.setups.load(format("cont-%s.xml",lastinterface)) end @@ -657,7 +659,7 @@ local function doit(configuration,filename,hashed) local content = lmx.convert('context-help.lmx',false,variables) - logs.simple("time spent on page: %0.03f seconds",os.clock()-start) + report("time spent on page: %0.03f seconds",os.clock()-start) return { content = content } end diff --git a/scripts/context/lua/mtx-server.lua b/scripts/context/lua/mtx-server.lua index 4fe0a6ac8..4547877b5 100644 --- a/scripts/context/lua/mtx-server.lua +++ b/scripts/context/lua/mtx-server.lua @@ -6,6 +6,23 @@ if not modules then modules = { } end modules ['mtx-server'] = { license = "see context related readme files" } +local helpinfo = [[ +--start start server +--port port to listen to +--root server root +--scripts scripts sub path +--index index file +--auto start on own path +]] + +local application = logs.application { + name = "mtx-server", + banner = "Simple Webserver For Helpers 0.10", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.webserver = scripts.webserver or { } @@ -127,7 +144,7 @@ local handlers = { } local function errormessage(client,configuration,n) local data = format("<head><title>%s %s</title></head><html><h2>%s %s</h2></html>",n,messages[n],n,messages[n]) - logs.simple("handling error %s: %s",n,messages[n]) + report("handling error %s: %s",n,messages[n]) handlers.generic(client,configuration,data,nil,true) end @@ -136,7 +153,7 @@ local validpaths, registered = { }, { } function scripts.webserver.registerpath(name) if not registered[name] then local cleanname = string.gsub(name,"%.%.","deleted-parent") - logs.simple("registering path '%s'",cleanname) + report("registering path '%s'",cleanname) validpaths[#validpaths+1] = cleanname registered[name] = true end @@ -145,7 +162,7 @@ end function handlers.generic(client,configuration,data,suffix,iscontent) if not iscontent then local name = data - logs.simple("requested file '%s'",name) + report("requested file '%s'",name) local fullname = file.join(configuration.root,name) data = io.loaddata(fullname) or "" if data == "" then @@ -153,12 +170,12 @@ function handlers.generic(client,configuration,data,suffix,iscontent) local fullname = file.join(validpaths[n],name) data = io.loaddata(fullname) or "" if data ~= "" then - logs.simple("sending generic file '%s'",fullname) + report("sending generic file '%s'",fullname) break end end else - logs.simple("sending generic file '%s'",fullname) + report("sending generic file '%s'",fullname) end end if data and data ~= "" then @@ -192,18 +209,18 @@ function handlers.lua(client,configuration,filename,suffix,iscontent,hashed) -- -- todo: split url in components, see l-url; rather trivial local result, keep = loaded[filename], false if result then - logs.simple("reusing script: %s",filename) + report("reusing script: %s",filename) else - logs.simple("locating script: %s",filename) + report("locating script: %s",filename) if lfs.isfile(filename) then - logs.simple("loading script: %s",filename) + report("loading script: %s",filename) result = loadfile(filename) - logs.simple("return type: %s",type(result)) + report("return type: %s",type(result)) if result and type(result) == "function" then -- result() should return a table { [type=,] [length=,] content= }, function or string result, keep = result() if keep then - logs.simple("saving script: %s",type(result)) + report("saving script: %s",type(result)) loaded[filename] = result end end @@ -277,11 +294,11 @@ function scripts.webserver.run(configuration) configuration.scripts = dir.expandname(file.join(configuration.root or ".",configuration.scripts or ".")) end -- so far for checks - logs.simple("running at port: %s",configuration.port) - logs.simple("document root: %s",configuration.root or resolvers.ownpath) - logs.simple("main index file: %s",configuration.index) - logs.simple("scripts subpath: %s",configuration.scripts) - logs.simple("context services: http://localhost:%s/mtx-server-ctx-startup.lua",configuration.port) + report("running at port: %s",configuration.port) + report("document root: %s",configuration.root or resolvers.ownpath) + report("main index file: %s",configuration.index) + report("scripts subpath: %s",configuration.scripts) + report("context services: http://localhost:%s/mtx-server-ctx-startup.lua",configuration.port) local server = assert(socket.bind("*", configuration.port)) --~ local reading = { server } while true do -- no multiple clients @@ -295,7 +312,7 @@ function scripts.webserver.run(configuration) errormessage(client,configuration,404) else local from = client:getpeername() - logs.simple("request from: %s",tostring(from)) + report("request from: %s",tostring(from)) local fullurl = request:match("GET (.+) HTTP/.*$") -- todo: more clever fullurl = socket.url.unescape(fullurl) local hashed = url.hashed(fullurl) @@ -304,18 +321,18 @@ function scripts.webserver.run(configuration) --~ table.print(hashed) if filename then filename = socket.url.unescape(filename) - logs.simple("requested action: %s",filename) + report("requested action: %s",filename) if filename:find("%.%.") then filename = nil -- invalid path end if filename == nil or filename == "" or filename == "/" then filename = configuration.index - logs.simple("invalid filename, forcing: %s",filename) + report("invalid filename, forcing: %s",filename) end local suffix = file.extname(filename) local action = handlers[suffix] or handlers.generic if action then - logs.simple("performing action: %s",filename) + report("performing action: %s",filename) action(client,configuration,filename,suffix,false,hashed) -- filename and no content else errormessage(client,configuration,404) @@ -325,21 +342,10 @@ function scripts.webserver.run(configuration) end end client:close() - logs.simple("time spent with client: %0.03f seconds",os.clock()-start) + report("time spent with client: %0.03f seconds",os.clock()-start) end end -logs.extendbanner("Simple Webserver For Helpers 0.10") - -messages.help = [[ ---start start server ---port port to listen to ---root server root ---scripts scripts sub path ---index index file ---auto start on own path -]] - if environment.argument("auto") then local path = resolvers.findfile("mtx-server.lua") or "." scripts.webserver.run { @@ -355,7 +361,7 @@ elseif environment.argument("start") then scripts = environment.argument("scripts"), } else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-texworks.lua b/scripts/context/lua/mtx-texworks.lua index 38a162c0e..33e56df46 100644 --- a/scripts/context/lua/mtx-texworks.lua +++ b/scripts/context/lua/mtx-texworks.lua @@ -6,6 +6,19 @@ if not modules then modules = { } end modules ['mtx-texworks'] = { license = "see context related readme files" } +local helpinfo = [[ +--start [--verbose] start texworks +--test report what will happen +]] + +local application = logs.application { + name = "mtx-texworks", + banner = "TeXworks Startup Script 1.00", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.texworks = scripts.texworks or { } @@ -49,11 +62,11 @@ function scripts.texworks.start(indeed) end end if datapath == "" then - logs.simple("invalid datapath, maybe you need to regenerate the file database") + report("invalid datapath, maybe you need to regenerate the file database") return false end if not binpaths or #binpaths == 0 then - logs.simple("invalid binpath") + report("invalid binpath") return false end for i=1,#binpaths do @@ -64,7 +77,7 @@ function scripts.texworks.start(indeed) end end if not fullname then - logs.simple("unable to locate %s",workname) + report("unable to locate %s",workname) return false end for i=1,#texworkspaths do @@ -73,27 +86,20 @@ function scripts.texworks.start(indeed) os.setenv("TW_INIPATH",datapath) os.setenv("TW_LIBPATH",datapath) if not indeed or environment.argument("verbose") then - logs.simple("used signal: %s", usedsignal) - logs.simple("data path : %s", datapath) - logs.simple("full name : %s", fullname) - logs.simple("set paths : TW_INIPATH TW_LIBPATH") + report("used signal: %s", usedsignal) + report("data path : %s", datapath) + report("full name : %s", fullname) + report("set paths : TW_INIPATH TW_LIBPATH") end if indeed then os.launch(fullname) end end -logs.extendbanner("TeXworks Startup Script 1.00") - -messages.help = [[ ---start [--verbose] start texworks ---test report what will happen -]] - if environment.argument("start") then scripts.texworks.start(true) elseif environment.argument("test") then scripts.texworks.start() else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-timing.lua b/scripts/context/lua/mtx-timing.lua index ee658f461..03100e991 100644 --- a/scripts/context/lua/mtx-timing.lua +++ b/scripts/context/lua/mtx-timing.lua @@ -8,6 +8,20 @@ if not modules then modules = { } end modules ['mtx-timing'] = { local format, gsub, concat = string.format, string.gsub, table.concat +local helpinfo = [[ +--xhtml make xhtml file +--launch launch after conversion +--remove remove after launching +]] + +local application = logs.application { + name = "mtx-timing", + banner = "ConTeXt Timing Tools 0.10", + helpinfo = helpinfo, +} + +local report = application.report + dofile(resolvers.findfile("trac-tim.lua","tex")) dofile(resolvers.findfile("trac-lmx.lua","tex")) @@ -57,6 +71,8 @@ local directrun = true local what = { "parameters", "nodes" } +plugins = plugins or { } -- brrr, will become moduledata as well + function plugins.progress.make_svg(filename,other) local metadata, menudata, c = { }, { }, 0 metadata[#metadata+1] = 'outputformat := "svg" ;' @@ -76,7 +92,7 @@ function plugins.progress.make_svg(filename,other) if directrun then dofile(resolvers.findfile("mlib-run.lua","tex")) commands = commands or { } - commands.writestatus = logs.report + commands.writestatus = report local result = metapost.directrun("metafun","timing data","svg",true,metadata) return menudata, result else @@ -167,9 +183,9 @@ scripts.timings = scripts.timings or { } function scripts.timings.xhtml(filename) if filename == "" then - logs.simple("provide filename") + report("provide filename") elseif not plugins.progress.valid_file(filename) then - logs.simple("first run context again with the --timing option") + report("first run context again with the --timing option") else local basename = file.removesuffix(filename) local launch = environment.argument("launch") @@ -178,16 +194,8 @@ function scripts.timings.xhtml(filename) end end -logs.extendbanner("ConTeXt Timing Tools 0.10",true) - -messages.help = [[ ---xhtml make xhtml file ---launch launch after conversion ---remove remove after launching -]] - if environment.argument("xhtml") then scripts.timings.xhtml(environment.files[1] or "") else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-tools.lua b/scripts/context/lua/mtx-tools.lua index 92c13886a..905b3aa85 100644 --- a/scripts/context/lua/mtx-tools.lua +++ b/scripts/context/lua/mtx-tools.lua @@ -8,6 +8,33 @@ if not modules then modules = { } end modules ['mtx-tools'] = { local find, format, sub, rep, gsub, lower = string.find, string.format, string.sub, string.rep, string.gsub, string.lower +local helpinfo = [[ +--disarmutfbomb remove utf bomb if present + --force remove indeed + +--dirtoxml glob directory into xml + --pattern glob pattern (default: *) + --url url attribute (no processing) + --root the root of the globbed path (default: .) + --output output filename (console by default) + --recurse recurse into subdirecories + --stripname take pathpart of given pattern + --longname set name attributes to full path name + +--downcase + --pattern glob pattern (default: *) + --recurse recurse into subdirecories + --force downcase indeed +]] + +local application = logs.application { + name = "mtx-tools", + banner = "Some File Related Goodies 1.01", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.tools = scripts.tools or { } @@ -23,24 +50,24 @@ function scripts.tools.disarmutfbomb() if not data then -- just skip elseif find(data,bomb_1) then - logs.simple("file '%s' has a 2 character utf bomb",name) + report("file '%s' has a 2 character utf bomb",name) if force then io.savedata(name,(gsub(data,bomb_1,""))) end done = true elseif find(data,bomb_2) then - logs.simple("file '%s' has a 3 character utf bomb",name) + report("file '%s' has a 3 character utf bomb",name) if force then io.savedata(name,(gsub(data,bomb_2,""))) end done = true else - -- logs.simple("file '%s' has no utf bomb",name) + -- report("file '%s' has no utf bomb",name) end end end if done and not force then - logs.simple("use --force to do a real disarming") + report("use --force to do a real disarming") end end @@ -63,12 +90,12 @@ function scripts.tools.downcase() end) if n > 0 then if force then - logs.simple("%s files renamed",n) + report("%s files renamed",n) else - logs.simple("use --force to do a real rename (%s files involved)",n) + report("use --force to do a real rename (%s files involved)",n) end else - logs.simple("nothing to do") + report("nothing to do") end end @@ -111,7 +138,7 @@ function scripts.tools.dirtoxml() end if not pattern or pattern == "" then - logs.report('provide --pattern=') + report('provide --pattern=') return end @@ -144,27 +171,6 @@ function scripts.tools.dirtoxml() end -logs.extendbanner("Some File Related Goodies 1.01") - -messages.help = [[ ---disarmutfbomb remove utf bomb if present - --force remove indeed - ---dirtoxml glob directory into xml - --pattern glob pattern (default: *) - --url url attribute (no processing) - --root the root of the globbed path (default: .) - --output output filename (console by default) - --recurse recurse into subdirecories - --stripname take pathpart of given pattern - --longname set name attributes to full path name - ---downcase - --pattern glob pattern (default: *) - --recurse recurse into subdirecories - --force downcase indeed -]] - if environment.argument("disarmutfbomb") then scripts.tools.disarmutfbomb() elseif environment.argument("dirtoxml") then @@ -172,5 +178,5 @@ elseif environment.argument("dirtoxml") then elseif environment.argument("downcase") then scripts.tools.downcase() else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtx-unzip.lua b/scripts/context/lua/mtx-unzip.lua index 85a4b9e7b..645863426 100644 --- a/scripts/context/lua/mtx-unzip.lua +++ b/scripts/context/lua/mtx-unzip.lua @@ -10,21 +10,23 @@ if not modules then modules = { } end modules ['mtx-unzip'] = { local format = string.format -logs.extendbanner("Simple Unzipper 0.10") - -messages.help = [[ +local helpinfo = [[ --list list files in archive --junk flatten unzipped directory structure --extract extract files ]] +local application = logs.application { + name = "mtx-unzip", + banner = "Simple Unzipper 0.10", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.unzipper = scripts.unzipper or { } -function scripts.unzipper.help() - logs.help(messages.help) -end - function scripts.unzipper.opened() local filename = environment.files[1] if filename and filename ~= "" then @@ -34,7 +36,7 @@ function scripts.unzipper.opened() return zipfile end end - logs.report("unzip", "no zip file: " .. filename) + report("no zip file: %s",filename) return false end @@ -104,11 +106,11 @@ function scripts.unzipper.extract() end if environment.arguments["h"] or environment.arguments["help"] then - scripts.unzipper.help() + application.help() elseif environment.arguments["l"] or environment.arguments["list"] then scripts.unzipper.list(zipfile) elseif environment.files[1] then -- implicit --extract scripts.unzipper.extract(zipfile) else - scripts.unzipper.help() + application.help() end diff --git a/scripts/context/lua/mtx-update.lua b/scripts/context/lua/mtx-update.lua index 708565910..750c74886 100644 --- a/scripts/context/lua/mtx-update.lua +++ b/scripts/context/lua/mtx-update.lua @@ -11,6 +11,32 @@ if not modules then modules = { } end modules ['mtx-update'] = { -- Together with Arthur Reutenauer she made sure that it worked well on all -- platforms that matter. +local helpinfo = [[ +--platform=string platform (windows, linux, linux-64, osx-intel, osx-ppc, linux-ppc) +--server=string repository url (rsync://contextgarden.net) +--module=string repository url (minimals) +--repository=string specify version (current, experimental) +--context=string specify version (current, latest, beta, yyyy.mm.dd) +--rsync=string rsync binary (rsync) +--texroot=string installation directory (not guessed for the moment) +--engine=string tex engine (luatex, pdftex, xetex) +--extras=string extra modules (can be list or 'all') +--goodies=string extra binaries (like scite and texworks) +--force instead of a dryrun, do the real thing +--update update minimal tree +--make also make formats and generate file databases +--keep don't delete unused or obsolete files +--state update tree using saved state +]] + +local application = logs.application { + name = "mtx-update", + banner = "ConTeXt Minimals Updater 0.22", + helpinfo = helpinfo, +} + +local report = application.report + local format, concat, gmatch, gsub = string.format, table.concat, string.gmatch, string.gsub scripts = scripts or { } @@ -159,10 +185,10 @@ function scripts.update.run(str) -- (texlua sets luatex as the engine, we need to reset that or to fix texexec :) os.setenv("engine",nil) if environment.argument("force") then - logs.report("run", str) + report("run, %s",str) os.execute(str) else - logs.report("dry run", str) + report("dry run, %s",str) end end @@ -176,7 +202,7 @@ end function scripts.update.synchronize() - logs.report("update","start") + report("update, start") local texroot = scripts.update.fullpath(states.get("paths.root")) local engines = states.get('engines') or { } @@ -350,7 +376,7 @@ function scripts.update.synchronize() deleteflags = states.get("rsync.flags.delete") end command = format("%s %s %s %s %s'%s' '%s'", bin, normalflags, deleteflags, dryrunflags, url, archives, destination) - --logs.report("mtx update", format("running command: %s",command)) + -- report("running command: %s",command) if not fetched[command] then scripts.update.run(command,true) fetched[command] = command @@ -370,7 +396,7 @@ function scripts.update.synchronize() else command = format("%s -tgo --chmod=a+x %s/texmf-context/scripts/context/lua/%s.lua %s/texmf-%s/bin/%s", bin, texroot, script, texroot, platform, script) end - logs.report("mtx update", format("updating %s for %s: %s", script, platform, command)) + report("updating %s for %s: %s", script, platform, command) scripts.update.run(command) end end @@ -382,10 +408,10 @@ function scripts.update.synchronize() end else - logs.report("mtx update", format("no valid texroot: %s",texroot)) + report("no valid texroot: %s",texroot) end if not force then - logs.report("update", "use --force to really update files") + report("use --force to really update files") end resolvers.load_tree(texroot) -- else we operate in the wrong tree @@ -395,7 +421,7 @@ function scripts.update.synchronize() -- update filename database for luatex scripts.update.run(format('mtxrun --tree="%s" --generate',texroot)) - logs.report("update","done") + report("update, done") end function table.fromhash(t) @@ -409,7 +435,7 @@ end -- make the ConTeXt formats function scripts.update.make() - logs.report("make","start") + report("make, start") local force = environment.argument("force") local texroot = scripts.update.fullpath(states.get("paths.root")) @@ -451,33 +477,13 @@ function scripts.update.make() scripts.update.run(format('mtxrun --tree="%s" --script texexec --make --all %s',texroot,formatlist)) end if not force then - logs.report("make", "use --force to really make formats") + report("make, use --force to really make formats") end scripts.update.run(format('mtxrun --tree="%s" --direct mktexlsr',texroot)) scripts.update.run(format('mtxrun --tree="%s" --generate',texroot)) - logs.report("make","done") + report("make, done") end -logs.extendbanner("ConTeXt Minimals Updater 0.21") - -messages.help = [[ ---platform=string platform (windows, linux, linux-64, osx-intel, osx-ppc, linux-ppc) ---server=string repository url (rsync://contextgarden.net) ---module=string repository url (minimals) ---repository=string specify version (current, experimental) ---context=string specify version (current, latest, beta, yyyy.mm.dd) ---rsync=string rsync binary (rsync) ---texroot=string installation directory (not guessed for the moment) ---engine=string tex engine (luatex, pdftex, xetex) ---extras=string extra modules (can be list or 'all') ---goodies=string extra binaries (like scite and texworks) ---force instead of a dryrun, do the real thing ---update update minimal tree ---make also make formats and generate file databases ---keep don't delete unused or obsolete files ---state update tree using saved state -]] - scripts.savestate = true if scripts.savestate then @@ -544,7 +550,8 @@ if scripts.savestate then states.set("goodies." .. r, true) end - logs.report("state","loaded") + report("state, loaded") + report() end @@ -562,7 +569,7 @@ if environment.argument("update") then elseif environment.argument("make") then scripts.update.make() else - logs.help(messages.help) + application.help() end if scripts.savestate then @@ -570,6 +577,6 @@ if scripts.savestate then states.set("info.runtime",tonumber(statistics.elapsedtime(states))) if environment.argument("force") then states.save() - logs.report("state","saved") + report("state","saved") end end diff --git a/scripts/context/lua/mtx-watch.lua b/scripts/context/lua/mtx-watch.lua index 617d73f90..5bd0ad5f4 100644 --- a/scripts/context/lua/mtx-watch.lua +++ b/scripts/context/lua/mtx-watch.lua @@ -6,6 +6,25 @@ if not modules then modules = { } end modules ['mtx-watch'] = { license = "see context related readme files" } +local helpinfo = [[ +--logpath optional path for log files +--watch watch given path [--delay] +--pipe use pipe instead of execute +--delay delay between sweeps +--automachine replace /machine/ in path /<servername>/ +--collect condense log files +--cleanup=delay remove files in given path [--force] +--showlog show log data +]] + +local application = logs.application { + name = "mtx-watch", + banner = "ConTeXt Request Watchdog 1.00", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.watch = scripts.watch or { } @@ -92,7 +111,7 @@ function scripts.watch.watch() end end for i=1,#paths do - logs.report("watch", "watching path ".. paths[i]) + report("watching path %s",paths[i]) end local function process() local done = false @@ -107,7 +126,7 @@ function scripts.watch.watch() local ok, joblog = pcall(dofile,name) if ok and joblog then if joblog.status == "processing" then - logs.report("watch",format("aborted job, %s added to queue",name)) + report("aborted job, %s added to queue",name) joblog.status = "queued" io.savedata(name, table.serialize(joblog,true)) elseif joblog.status == "queued" then @@ -124,7 +143,7 @@ function scripts.watch.watch() joblog.status = "processing" joblog.runtime = clock() io.savedata(name, table.serialize(joblog,true)) - logs.report("watch",format("running: %s", command)) + report("running: %s", command) local newpath = file.dirname(name) io.flush() local result = "" @@ -141,7 +160,7 @@ function scripts.watch.watch() scripts.watch.save_exa_modes(joblog,ctmname) if pipe then result = os.resultof(command) else result = os.spawn(command) end end - logs.report("watch",format("return value: %s", result)) + report("return value: %s", result) done = true local path, base = replacements.outputpath, file.basename(replacements.filename) joblog.runtime = clock() - joblog.runtime @@ -162,7 +181,7 @@ function scripts.watch.watch() if logpath and logpath ~= "" then local name = file.join(logpath,os.uuid() .. ".lua") io.savedata(name, table.serialize(joblog,true)) - logs.report("watch", "saving joblog in " .. name) + report("saving joblog in %s",name) end end end @@ -175,7 +194,7 @@ function scripts.watch.watch() --~ if not done then --~ n = n + 1 --~ if n >= 10 then ---~ logs.report("watch", format("run time: %i seconds, memory usage: %0.3g MB", difftime(time(),start), (status.luastate_bytes/1024)/1000)) +--~ report("run time: %i seconds, memory usage: %0.3g MB", difftime(time(),start), (status.luastate_bytes/1024)/1000) --~ n = 0 --~ end --~ os.sleep(delay) @@ -187,7 +206,7 @@ function scripts.watch.watch() if not done then n = n + 1 if n >= 10 then - logs.report("watch", format("run time: %i seconds, memory usage: %0.3g MB", difftime(time(),start), (status.luastate_bytes/1024)/1000)) + report("run time: %i seconds, memory usage: %0.3g MB", difftime(time(),start), (status.luastate_bytes/1024)/1000) n = 0 end local ttime = 0 @@ -222,7 +241,7 @@ function scripts.watch.watch() local filetime = lfs.attributes(name,"modification") local delta = difftime(currenttime,filetime) if delta > cleanupdelay then - -- logs.report("watch",format("cleaning up '%s'",name)) + -- report("cleaning up '%s'",name) os.remove(name) end end @@ -248,7 +267,7 @@ function scripts.watch.watch() end end else - logs.report("watch", "no paths to watch") + report("no paths to watch") end end @@ -282,7 +301,7 @@ function scripts.watch.save_logs(collection,path) -- play safe local check = dofile(filename) for k,v in next, check do if not collection[k] then - logs.error("watch", "error in saving file") + report("error in saving file") os.remove(filename) return false end @@ -326,7 +345,7 @@ function scripts.watch.show_logs(path) -- removes duplicates local v = sorted[k] local c = collection[v] local f, s, r, n = c.filename or "?", c.status or "?", c.runtime or 0, c.size or 0 - logs.report("watch", format("%s %s %3i %8i %s",string.padd(f,max," "),string.padd(s,10," "),r,n,v)) + report("%s %s %3i %8i %s",string.padd(f,max," "),string.padd(s,10," "),r,n,v) end end @@ -335,11 +354,11 @@ function scripts.watch.cleanup_stale_files() -- removes duplicates local delay = tonumber(environment.argument("cleanup")) local force = environment.argument("force") if not path or path == "." then - logs.report("watch","provide qualified path") + report("provide qualified path") elseif not delay then - logs.report("watch","missing --cleanup=delay") + report("missing --cleanup=delay") else - logs.report("watch","dryrun, use --force for real cleanup") + report("dryrun, use --force for real cleanup") local files = dir.glob(file.join(path,"*")) local rtime = time() for i=1,#files do @@ -347,7 +366,7 @@ function scripts.watch.cleanup_stale_files() -- removes duplicates local mtime = lfs.attributes(name,"modification") local delta = difftime(rtime,mtime) if delta > delay then - logs.report("watch",format("cleaning up '%s'",name)) + report("cleaning up '%s'",name) if force then os.remove(name) end @@ -356,19 +375,6 @@ function scripts.watch.cleanup_stale_files() -- removes duplicates end end -logs.extendbanner("ConTeXt Request Watchdog 1.00") - -messages.help = [[ ---logpath optional path for log files ---watch watch given path [--delay] ---pipe use pipe instead of execute ---delay delay between sweeps ---automachine replace /machine/ in path /<servername>/ ---collect condense log files ---cleanup=delay remove files in given path [--force] ---showlog show log data -]] - if environment.argument("watch") then scripts.watch.watch() elseif environment.argument("collect") then @@ -378,5 +384,5 @@ elseif environment.argument("cleanup") then elseif environment.argument("showlog") then scripts.watch.show_logs() else - logs.help(messages.help) + application.help() end diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 31d7d9b0f..afc472d1c 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -8,7 +8,6 @@ if not modules then modules = { } end modules ['mtxrun'] = { license = "see context related readme files" } - -- one can make a stub: -- -- #!/bin/sh @@ -132,11 +131,7 @@ local simple_escapes = { } function string.escapedpattern(str,simple) - if simple then - return (gsub(str,".",simple_escapes)) - else - return (gsub(str,".",patterns_escapes)) - end + return (gsub(str,".",simple and simple_escapes or patterns_escapes)) end function string.topattern(str,lowercase,strict) @@ -556,11 +551,7 @@ local p = Cs((S("-.+*%()[]") / patterns_escapes + anything)^0) local s = Cs((S("-.+*%()[]") / simple_escapes + anything)^0) function string.escapedpattern(str,simple) - if simple then - return match(s,str) - else - return match(p,str) - end + return match(simple and s or p,str) end -- utf extensies @@ -3826,7 +3817,7 @@ local type, next = type, next utilities = utilities or {} utilities.merger = utilities.merger or { } -- maybe mergers -utilities.report = utilities.report or print +utilities.report = logs and logs.new("system") or print local merger = utilities.merger @@ -3964,7 +3955,7 @@ if not modules then modules = { } end modules ['util-lua'] = { utilities = utilities or {} utilities.lua = utilities.lua or { } -utilities.report = utilities.report or print +utilities.report = logs and logs.new("system") or print function utilities.lua.compile(luafile,lucfile,cleanup,strip) -- defaults: cleanup=false strip=true utilities.report("lua: compiling %s into %s",luafile,lucfile) @@ -4577,19 +4568,21 @@ function statistics.show(reporter) end end - -local template, nn = nil, 0 -- we only calcute it once +local template, report_statistics, nn = nil, nil, 0 -- we only calcute it once function statistics.showjobstat(tag,data,n) - if type(data) == "table" then + if not logs then + -- sorry + elseif type(data) == "table" then for i=1,#data do statistics.showjobstat(tag,data[i],n) end else if not template or n > nn then - template, n = format("%%-%ss: %%-%ss - %%s",15,n), nn + template, n = format("%%-%ss - %%s",n), nn + report_statistics = logs.new("mkiv lua stats") end - write_nl(format(template,"mkiv lua stats",tag,data)) + report_statistics(format(template,tag,data)) end end @@ -4610,7 +4603,7 @@ function statistics.runtime() end function statistics.timed(action,report) - report = report or logs.simple + report = report or logs.new("system") starttiming("run") action() stoptiming("run") @@ -4664,14 +4657,10 @@ local data = { } -- maybe just local local trace_initialize = false -- only for testing during development -local function report(a,b,...) - texio.write_nl(format("%-16s> %s",a,format(b,...))) -end - function setters.initialize(filename,name,values) -- filename only for diagnostics - local data = data[name] - if data then - data = data.data + local setter = data[name] + if setter then + local data = data.data if data then for key, value in next, values do -- key = gsub(key,"_",".") @@ -4680,7 +4669,7 @@ function setters.initialize(filename,name,values) -- filename only for diagnosti if functions then if #functions > 0 and not functions.value then if trace_initialize then - report(name,"executing %s (%s -> %s)",key,filename,tostring(value)) + setter.report("executing %s (%s -> %s)",key,filename,tostring(value)) end for i=1,#functions do functions[i](value) @@ -4688,7 +4677,7 @@ function setters.initialize(filename,name,values) -- filename only for diagnosti functions.value = value else if trace_initialize then - report(name,"skipping %s (%s -> %s)",key,filename,tostring(value)) + setter.report("skipping %s (%s -> %s)",key,filename,tostring(value)) end end else @@ -4697,7 +4686,7 @@ function setters.initialize(filename,name,values) -- filename only for diagnosti functions = { default = value } data[key] = functions if trace_initialize then - report(name,"storing %s (%s -> %s)",key,filename,tostring(value)) + setter.report("storing %s (%s -> %s)",key,filename,tostring(value)) end end end @@ -4724,10 +4713,11 @@ local function set(t,what,newvalue) else value = is_boolean(value,value) end + w = escapedpattern(w,true) for name, functions in next, data do if done[name] then -- prevent recursion due to wildcards - elseif find(name,escapedpattern(w,true)) then + elseif find(name,w) then done[name] = true for i=1,#functions do functions[i](value) @@ -4769,7 +4759,7 @@ function setters.register(t,what,...) functions = { } data[what] = functions if trace_initialize then - report(t.name,"defining %s",what) + t.report("defining %s",what) end end local default = functions.default -- can be set from cnf file @@ -4777,7 +4767,7 @@ function setters.register(t,what,...) local typ = type(fnc) if typ == "string" then if trace_initialize then - report(t.name,"coupling %s to %s",what,fnc) + t.report("coupling %s to %s",what,fnc) end local s = fnc -- else wrong reference fnc = function(value) set(t,s,value) end @@ -4831,9 +4821,9 @@ function setters.list(t) -- pattern end function setters.show(t) - commands.writestatus("","") - local list = setters.list(t) local category = t.name + local list = setters.list(t) + t.report() for k=1,#list do local name = list[k] local functions = t.data[name] @@ -4841,10 +4831,10 @@ function setters.show(t) local value, default, modules = functions.value, functions.default, #functions value = value == nil and "unset" or tostring(value) default = default == nil and "unset" or tostring(default) - commands.writestatus(category,format("%-30s modules: %2i default: %5s value: %5s",name,modules,default,value)) + t.report("%-30s modules: %2i default: %6s value: %6s",name,modules,default,value) end end - commands.writestatus("","") + t.report() end -- we could have used a bit of oo and the trackers:enable syntax but @@ -4854,57 +4844,62 @@ end local enable, disable, register, list, show = setters.enable, setters.disable, setters.register, setters.list, setters.show +local function report(setter,...) + local report = logs and logs.report + if report then + report(setter.name,...) + else -- fallback, as this module is loaded before the logger + write_nl(format("%-16s: %s\n",setter.name,format(...))) + end +end + function setters.new(name) - local t -- we need to access it in t - t = { + local setter -- we need to access it in setter itself + setter = { data = allocate(), -- indexed, but also default and value fields name = name, - enable = function(...) enable (t,...) end, - disable = function(...) disable (t,...) end, - register = function(...) register(t,...) end, - list = function(...) list (t,...) end, - show = function(...) show (t,...) end, + report = function(...) report (setter,...) end, + enable = function(...) enable (setter,...) end, + disable = function(...) disable (setter,...) end, + register = function(...) register(setter,...) end, + list = function(...) list (setter,...) end, + show = function(...) show (setter,...) end, } - data[name] = t - return t + data[name] = setter + return setter end trackers = setters.new("trackers") directives = setters.new("directives") experiments = setters.new("experiments") -local t_enable, t_disable = trackers .enable, trackers .disable -local d_enable, d_disable = directives .enable, directives .disable -local e_enable, e_disable = experiments.enable, experiments.disable +local t_enable, t_disable, t_report = trackers .enable, trackers .disable, trackers .report +local d_enable, d_disable, d_report = directives .enable, directives .disable, directives .report +local e_enable, e_disable, e_report = experiments.enable, experiments.disable, experiments.report -- nice trick: we overload two of the directives related functions with variants that -- do tracing (itself using a tracker) .. proof of concept -local function report(...) -- messy .. chicken or egg - local p = (commands and commands.writestatus) or (logs and logs.report) - if p then p(...) end -end - local trace_directives = false local trace_directives = false trackers.register("system.directives", function(v) trace_directives = v end) local trace_experiments = false local trace_experiments = false trackers.register("system.experiments", function(v) trace_experiments = v end) function directives.enable(...) - report("directives","enabling: %s",concat({...}," ")) + d_report("enabling: %s",concat({...}," ")) d_enable(...) end function directives.disable(...) - report("directives","disabling: %s",concat({...}," ")) + d_report("disabling: %s",concat({...}," ")) d_disable(...) end function experiments.enable(...) - report("experiments","enabling: %s",concat({...}," ")) + e_report("enabling: %s",concat({...}," ")) e_enable(...) end function experiments.disable(...) - report("experiments","disabling: %s",concat({...}," ")) + e_report("disabling: %s",concat({...}," ")) e_disable(...) end @@ -4967,20 +4962,19 @@ if not modules then modules = { } end modules ['trac-log'] = { license = "see context related readme files" } --- xml logging is only usefull in normal runs, not in ini mode --- it looks like some tex logging (like filenames) is broken (no longer --- interceoted at the tex end so the xml variant is not that useable now) +-- todo: less categories, more subcategories (e.g. nodes) local write_nl, write = texio and texio.write_nl or print, texio and texio.write or io.write -local format, gmatch = string.format, string.gmatch +local format, gmatch, find = string.format, string.gmatch, string.find +local concat = table.concat +local escapedpattern = string.escapedpattern local texcount = tex and tex.count +local next, type = next, type --[[ldx-- -<p>This is a prelude to a more extensive logging module. For the sake -of parsing log files, in addition to the standard logging we will -provide an <l n='xml'/> structured file. Actually, any logging that -is hooked into callbacks will be \XML\ by default.</p> +<p>This is a prelude to a more extensive logging module. We no longer +provide <l n='xml'/> based logging a sparsing is relatively easy anyway.</p> --ldx]]-- logs = logs or { } @@ -4998,96 +4992,239 @@ webpage : http://www.pragma-ade.nl / http://tex.aanhet.net wiki : http://contextgarden.net ]] -local functions = { - 'report', 'status', 'start', 'stop', 'push', 'pop', 'line', 'direct', - 'start_run', 'stop_run', - 'start_page_number', 'stop_page_number', - 'report_output_pages', 'report_output_log', - 'report_tex_stat', 'report_job_stat', - 'show_open', 'show_close', 'show_load', - 'dummy', -} +-- local functions = { +-- 'report', 'status', 'start', 'stop', 'line', 'direct', +-- 'start_run', 'stop_run', +-- 'start_page_number', 'stop_page_number', +-- 'report_output_pages', 'report_output_log', +-- 'report_tex_stat', 'report_job_stat', +-- 'show_open', 'show_close', 'show_load', +-- 'dummy', +-- } -local method = "nop" +-- basic loggers -function logs.setmethod(newmethod) - method = newmethod - -- a direct copy might be faster but let's try this for a while - setmetatable(logs, { __index = logs[method] }) -end +local function ignore() end -function logs.getmethod() - return method -end +setmetatable(logs, { __index = function(t,k) t[k] = ignore ; return ignore end }) --- installer +-- local separator = (tex and (tex.jobname or tex.formatname)) and ">" or "|" -local data = { } +local report, subreport -function logs.new(category) - local logger = data[category] - if not logger then - logger = function(...) - logs.report(category,...) +if tex and tex.jobname or tex.formatname then + + report = function(a,b,c,...) + if c then + write_nl(format("%-15s > %s\n",a,format(b,c,...))) + elseif b then + write_nl(format("%-15s > %s\n",a,b)) + elseif a then + write_nl(format("%-15s >\n", a)) + else + write_nl("\n") end - data[category] = logger end - return logger -end + subreport = function(a,sub,b,c,...) + if c then + write_nl(format("%-15s > %s > %s\n",a,sub,format(b,c,...))) + elseif b then + write_nl(format("%-15s > %s > %s\n",a,sub,b)) + elseif a then + write_nl(format("%-15s > %s >\n", a,sub)) + else + write_nl("\n") + end + end --- nop logging (maybe use __call instead) - -local noplog = { } logs.nop = noplog setmetatable(logs, { __index = noplog }) +else -for i=1,#functions do - noplog[functions[i]] = function() end -end + report = function(a,b,c,...) + if c then + write_nl(format("%-15s | %s",a,format(b,c,...))) + elseif b then + write_nl(format("%-15s | %s",a,b)) + elseif a then + write_nl(format("%-15s |", a)) + else + write_nl("") + end + end --- tex logging + subreport = function(a,sub,b,c,...) + if c then + write_nl(format("%-15s | %s | %s",a,sub,format(b,c,...))) + elseif b then + write_nl(format("%-15s | %s | %s",a,sub,b)) + elseif a then + write_nl(format("%-15s | %s |", a,sub)) + else + write_nl("") + end + end -local texlog = { } logs.tex = texlog setmetatable(texlog, { __index = noplog }) +end -function texlog.report(a,b,c,...) +function logs.status(a,b,c,...) -- at the tex end if c then - write_nl(format("%-16s> %s\n",a,format(b,c,...))) + write_nl(format("%-15s : %s\n",a,format(b,c,...))) elseif b then - write_nl(format("%-16s> %s\n",a,b)) + write_nl(format("%-15s : %s\n",a,b)) -- b can have %'s + elseif a then + write_nl(format("%-15s :\n", a)) else - write_nl(format("%-16s>\n",a)) + write_nl("\n") end end -function texlog.status(a,b,c,...) - if c then - write_nl(format("%-16s: %s\n",a,format(b,c,...))) - elseif b then - write_nl(format("%-16s: %s\n",a,b)) -- b can have %'s - else - write_nl(format("%-16s:>\n",a)) +logs.report = report +logs.subreport = subreport + +-- installer + +-- todo: renew (un) locks when a new one is added and wildcard + +local data, states = { }, nil + +function logs.reporter(category,subcategory) + local logger = data[category] + if not logger then + local state = false + if states == true then + state = true + elseif type(states) == "table" then + for c, _ in next, states do + if find(category,c) then + state = true + break + end + end + end + logger = { + reporters = { }, + state = state, + } + data[category] = logger + end + local reporter = logger.reporters[subcategory or "default"] + if not reporter then + if subcategory then + reporter = function(...) + if not logger.state then + subreport(category,subcategory,...) + end + end + logger.reporters[subcategory] = reporter + else + local tag = category + reporter = function(...) + if not logger.state then + report(category,...) + end + end + logger.reporters.default = reporter + end end + return reporter end -function texlog.line(fmt,...) -- new - if fmt then - write_nl(format(fmt,...)) +logs.new = logs.reporter + +local function doset(category,value) + if category == true then + -- lock all + category, value = "*", true + elseif category == false then + -- unlock all + category, value = "*", false + elseif value == nil then + -- lock selective + value = true + end + if category == "*" then + states = value + for k, v in next, data do + v.state = value + end else - write_nl("") + states = utilities.parsers.settings_to_hash(category) + for c, _ in next, states do + if data[c] then + v.state = value + else + c = escapedpattern(c,true) + for k, v in next, data do + if find(k,c) then + v.state = value + end + end + end + end + end +end + +function logs.disable(category,value) + doset(category,value == nil and true or value) +end + +function logs.enable(category) + doset(category,false) +end + +function logs.categories() + return table.sortedkeys(data) +end + +function logs.show() + local n, c, s, max = 0, 0, 0, 0 + for category, v in table.sortedpairs(data) do + n = n + 1 + local state = v.state + local reporters = v.reporters + local nc = #category + if nc > c then + c = nc + end + for subcategory, _ in next, reporters do + local ns = #subcategory + if ns > c then + s = ns + end + local m = nc + ns + if m > max then + max = m + end + end + local subcategories = concat(table.sortedkeys(reporters),", ") + if state == true then + state = "disabled" + elseif state == false then + state = "enabled" + else + state = "unknown" + end + -- no new here + report("logging","category: '%s', subcategories: '%s', state: '%s'",category,subcategories,state) end + report("logging","categories: %s, max category: %s, max subcategory: %s, max combined: %s",n,c,s,max) end +directives.register("logs.blocked", function(v) + doset(v,true) +end) +-- tex specific loggers (might move elsewhere) +local report_pages = logs.reporter("pages") -- not needed but saves checking when we grep for it local real, user, sub -function texlog.start_page_number() +function logs.start_page_number() real, user, sub = texcount.realpageno, texcount.userpageno, texcount.subpageno end -local report_pages = logs.new("pages") -- not needed but saves checking when we grep for it - -function texlog.stop_page_number() +function logs.stop_page_number() if real > 0 then if user > 0 then if sub > 0 then @@ -5104,176 +5241,98 @@ function texlog.stop_page_number() io.flush() end -texlog.report_job_stat = statistics and statistics.showjobstat +logs.report_job_stat = statistics and statistics.showjobstat --- xml logging +local report_files = logs.reporter("files") -local xmllog = { } logs.xml = xmllog setmetatable(xmllog, { __index = noplog }) +local nesting = 0 +local verbose = false -function xmllog.report(category,fmt,s,...) -- new - if s then - write_nl(format("<r category='%s'>%s</r>",category,format(fmt,s,...))) - elseif fmt then - write_nl(format("<r category='%s'>%s</r>",category,fmt)) - else - write_nl(format("<r category='%s'/>",category)) +function logs.show_open(name) + if verbose then + nesting = nesting + 1 + report_files("level %s, opening %s",nesting,name) end end -function xmllog.status(category,fmt,s,...) - if s then - write_nl(format("<s category='%s'>%s</r>",category,format(fmt,s,...))) - elseif fmt then - write_nl(format("<s category='%s'>%s</r>",category,fmt)) - else - write_nl(format("<s category='%s'/>",category)) +function logs.show_close(name) + if verbose then + report_files("level %s, closing %s",nesting,name) + nesting = nesting - 1 end end -function xmllog.line(fmt,...) -- new - if fmt then - write_nl(format("<r>%s</r>",format(fmt,...))) - else - write_nl("<r/>") +function logs.show_load(name) + if verbose then + report_files("level %s, loading %s",nesting+1,name) end end -function xmllog.start() write_nl("<%s>" ) end -function xmllog.stop () write_nl("</%s>") end -function xmllog.push () write_nl("<!-- ") end -function xmllog.pop () write_nl(" -->" ) end - -function xmllog.start_run() - write_nl("<?xml version='1.0' standalone='yes'?>") - write_nl("<job>") -- xmlns='www.pragma-ade.com/luatex/schemas/context-job.rng' - write_nl("") -end - -function xmllog.stop_run() - write_nl("</job>") -end - -function xmllog.start_page_number() - write_nl(format("<p real='%s' page='%s' sub='%s'", texcount.realpageno, texcount.userpageno, texcount.subpageno)) -end - -function xmllog.stop_page_number() - write("/>") - write_nl("") -end +-- there may be scripts out there using this: -function xmllog.report_output_pages(p,b) - write_nl(format("<v k='pages' v='%s'/>", p)) - write_nl(format("<v k='bytes' v='%s'/>", b)) - write_nl("") -end - -function xmllog.report_output_log() - -- nothing -end +local simple = logs.reporter("comment") -function xmllog.report_tex_stat(k,v) - write_nl("log","<v k='"..k.."'>"..tostring(v).."</v>") -end - -local nesting = 0 - -function xmllog.show_open(name) - nesting = nesting + 1 - write_nl(format("<f l='%s' n='%s'>",nesting,name)) -end +logs.simple = simple +logs.simpleline = simple -function xmllog.show_close(name) - write("</f> ") - nesting = nesting - 1 -end - -function xmllog.show_load(name) - write_nl(format("<f l='%s' n='%s'/>",nesting+1,name)) -end - --- initialization - -if tex and (tex.jobname or tex.formatname) then - -- todo: this can be set in mtxrun ... or maybe we should just forget about this alternative format - if (os.getenv("mtx.directives.logmethod") or os.getenv("mtx_directives_logmethod")) == "xml" then - logs.setmethod('xml') - else - logs.setmethod('tex') - end -else - logs.setmethod('nop') -end +-- obsolete --- logging in runners -> these are actually the nop loggers +function logs.setprogram () end -- obsolete +function logs.extendbanner() end -- obsolete +function logs.reportlines () end -- obsolete +function logs.reportbanner() end -- obsolete +function logs.reportline () end -- obsolete +function logs.simplelines () end -- obsolete +function logs.help () end -- obsolete -local name, banner = 'report', 'context' +-- applications -function noplog.report(category,fmt,...) -- todo: fmt,s - if fmt then - write_nl(format("%s | %s: %s",name,category,format(fmt,...))) - elseif category then - write_nl(format("%s | %s",name,category)) - else - write_nl(format("%s |",name)) +local function reportlines(t,str) + if str then + for line in gmatch(str,"(.-)[\n\r]") do + t.report(line) + end end end -noplog.status = noplog.report -- just to be sure, never used - -function noplog.simple(fmt,...) -- todo: fmt,s - if fmt then - write_nl(format("%s | %s",name,format(fmt,...))) - else - write_nl(format("%s |",name)) +local function reportbanner(t) + local banner = t.banner + if banner then + t.report(banner) + t.report() end end -if utilities then - utilities.report = function(...) logs.simple(...) end -end - -function logs.setprogram(newname,newbanner) - name, banner = newname, newbanner -end - -function logs.extendbanner(newbanner) - banner = banner .. " | ".. newbanner -end - -function logs.reportlines(str) -- todo: <lines></lines> - for line in gmatch(str,"(.-)[\n\r]") do - logs.report(line) +local function reporthelp(t,...) + local helpinfo = t.helpinfo + if type(helpinfo) == "string" then + reportlines(t,helpinfo) + elseif type(helpinfo) == "table" then + local tags = { ... } + for i=1,#tags do + reportlines(t,t.helpinfo[tags[i]]) + if i < #tags then + t.report() + end + end end end -function logs.reportline() -- for scripts too - logs.report() -end - -function logs.simpleline() - logs.report() +local function reportinfo(t) + t.report() + reportlines(t,moreinfo) end -function logs.simplelines(str) -- todo: <lines></lines> - for line in gmatch(str,"(.-)[\n\r]") do - logs.simple(line) - end +function logs.application(t) + t.name = t.name or "unknown" + t.banner = t.banner + t.report = logs.reporter(t.name) + t.help = function(...) reportbanner(t) ; reporthelp(t,...) ; reportinfo(t) end + t.identify = function() reportbanner(t) end + return t end -function logs.reportbanner() -- for scripts too - logs.report(banner) -end - -function logs.help(message,option) - logs.reportbanner() - logs.reportline() - logs.reportlines(message) - if option ~= "nomoreinfo" then - logs.reportline() - logs.reportlines(moreinfo) - end -end +-- somewhat special -- logging to a file @@ -5281,7 +5340,7 @@ end function logs.system(whereto,process,jobname,category,...) local message = format("%s %s => %s => %s => %s\r",os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)) for i=1,10 do - local f = io.open(whereto,"a") + local f = io.open(whereto,"a") -- we can consider keepint the file open if f then f:write(message) f:close() @@ -5292,30 +5351,24 @@ function logs.system(whereto,process,jobname,category,...) end end --- bonus - -function logs.fatal(where,...) - logs.report(where,"fatal error: %s, aborting now",format(...)) - os.exit() -end - +local report_system = logs.reporter("system","logs") function logs.obsolete(old,new) local o = loadstring("return " .. new)() if type(o) == "function" then return function(...) - logs.report("system","function %s is obsolete, use %s",old,new) + report_system("function %s is obsolete, use %s",old,new) loadstring(old .. "=" .. new .. " return ".. old)()(...) end elseif type(o) == "table" then local t, m = { }, { } m.__index = function(t,k) - logs.report("system","table %s is obsolete, use %s",old,new) + report_system("table %s is obsolete, use %s",old,new) m.__index, m.__newindex = o, o return o[k] end m.__newindex = function(t,k,v) - logs.report("system","table %s is obsolete, use %s",old,new) + report_system("table %s is obsolete, use %s",old,new) m.__index, m.__newindex = o, o o[k] = v end @@ -5327,6 +5380,10 @@ function logs.obsolete(old,new) end end +if utilities then + utilities.report = report_system +end + if tex and tex.error then function logs.texerrormessage(...) -- for the moment we put this function here tex.error(format(...), { }) @@ -5361,7 +5418,7 @@ local getmetatable, setmetatable, rawset, type = getmetatable, setmetatable, raw local trace_namespaces = false trackers.register("system.namespaces", function(v) trace_namespaces = v end) -local report_system = logs.new("system") +local report_system = logs.new("system","protection") namespaces = namespaces or { } local namespaces = namespaces @@ -5530,7 +5587,7 @@ if not modules then modules = { } end modules ['luat-env'] = { local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_lua = logs.new("resolvers","lua") local allocate, mark = utilities.storage.allocate, utilities.storage.mark @@ -5754,14 +5811,14 @@ function environment.luafilechunk(filename,silent) -- used for loading lua bytec if fullname and fullname ~= "" then local data = environment.loadedluacode(fullname) if trace_locating then - report_resolvers("loading file %s%s", fullname, not data and " failed" or "") + report_lua("loading file %s%s", fullname, not data and " failed" or "") elseif not silent then texio.write("<",data and "+ " or "- ",fullname,">") end return data else if trace_locating then - report_resolvers("unknown file %s", filename) + report_lua("unknown file %s", filename) end return nil end @@ -5781,7 +5838,7 @@ function environment.loadluafile(filename, version) local fullname = (lucname and environment.luafile(lucname)) or "" if fullname ~= "" then if trace_locating then - report_resolvers("loading %s", fullname) + report_lua("loading %s", fullname) end chunk = loadfile(fullname) -- this way we don't need a file exists check end @@ -5799,7 +5856,7 @@ function environment.loadluafile(filename, version) return true else if trace_locating then - report_resolvers("version mismatch for %s: lua=%s, luc=%s", filename, v, version) + report_lua("version mismatch for %s: lua=%s, luc=%s", filename, v, version) end environment.loadluafile(filename) end @@ -5810,12 +5867,12 @@ function environment.loadluafile(filename, version) fullname = (luaname and environment.luafile(luaname)) or "" if fullname ~= "" then if trace_locating then - report_resolvers("loading %s", fullname) + report_lua("loading %s", fullname) end chunk = loadfile(fullname) -- this way we don't need a file exists check if not chunk then if trace_locating then - report_resolvers("unknown file %s", filename) + report_lua("unknown file %s", filename) end else assert(chunk)() @@ -5844,7 +5901,7 @@ if not modules then modules = { } end modules ['lxml-tab'] = { local trace_entities = false trackers.register("xml.entities", function(v) trace_entities = v end) -local report_xml = logs.new("xml") +local report_xml = logs and logs.new("xml","core") or function(...) print(format(...)) end --[[ldx-- <p>The parser used here is inspired by the variant discussed in the lua book, but @@ -6518,7 +6575,7 @@ function xml.is_valid(root) return root and not root.error end -xml.errorhandler = (logs and logs.report) or (input and logs.report) or print +xml.errorhandler = report --[[ldx-- <p>We cannot load an <l n='lpeg'/> from a filehandle so we need to load @@ -7069,7 +7126,7 @@ local trace_lpath = false if trackers then trackers.register("xml.path", local trace_lparse = false if trackers then trackers.register("xml.parse", function(v) trace_lparse = v end) end local trace_lprofile = false if trackers then trackers.register("xml.profile", function(v) trace_lpath = v trace_lparse = v trace_lprofile = v end) end -local report_lpath = logs.new("lpath") +local report_lpath = logs.new("xml","lpath") --[[ldx-- <p>We've now arrived at an interesting part: accessing the tree using a subset @@ -7951,9 +8008,9 @@ local function traced_apply(list,parsed,nofparsed,order) if trace_lparse then lshow(parsed) end - report_lpath("collecting : %s",parsed.pattern) - report_lpath(" root tags : %s",tagstostring(list)) - report_lpath(" order : %s",order or "unset") + report_lpath("collecting: %s",parsed.pattern) + report_lpath("root tags : %s",tagstostring(list)) + report_lpath("order : %s",order or "unset") local collected = list for i=1,nofparsed do local pi = parsed[i] @@ -9224,7 +9281,7 @@ local trace_locating = false trackers.register("resolvers.locating", functi local trace_detail = false trackers.register("resolvers.details", function(v) trace_detail = v end) local trace_expansions = false trackers.register("resolvers.expansions", function(v) trace_expansions = v end) -local report_resolvers = logs.new("resolvers") +local report_initialization = logs.new("resolvers","initialization") local ostype, osname, ossetenv, osgetenv = os.type, os.name, os.setenv, os.getenv @@ -9245,7 +9302,7 @@ kpse = { original = kpse } setmetatable(kpse, { __index = function(kp,name) - report_resolvers("fatal error: kpse library is accessed (key: %s)",name) + report_initialization("fatal error: kpse library is accessed (key: %s)",name) os.exit() end } ) @@ -9329,13 +9386,13 @@ do if lfs.chdir(p) then local pp = lfs.currentdir() if trace_locating and p ~= pp then - report_resolvers("following symlink '%s' to '%s'",p,pp) + report_initialization("following symlink '%s' to '%s'",p,pp) end ownpath = pp lfs.chdir(olddir) else if trace_locating then - report_resolvers("unable to check path '%s'",p) + report_initialization("unable to check path '%s'",p) end ownpath = p end @@ -9346,9 +9403,9 @@ do end if not ownpath or ownpath == "" then ownpath = "." - report_resolvers("forcing fallback ownpath .") + report_initialization("forcing fallback ownpath .") elseif trace_locating then - report_resolvers("using ownpath '%s'",ownpath) + report_initialization("using ownpath '%s'",ownpath) end end @@ -9375,7 +9432,7 @@ do ossetenv('SELFAUTODIR', file.collapsepath(ownpath .. "/..")) ossetenv('SELFAUTOPARENT', file.collapsepath(ownpath .. "/../..")) else - report_resolvers("error: unable to locate ownpath") + report_initialization("error: unable to locate ownpath") os.exit() end @@ -9461,7 +9518,7 @@ local collapsepath = file.collapsepath local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) local trace_expansions = false trackers.register("resolvers.expansions", function(v) trace_expansions = v end) -local report_resolvers = logs.new("resolvers") +local report_expansions = logs.new("resolvers","expansions") local resolvers = resolvers @@ -9524,7 +9581,7 @@ local replacer_1 = lpeg.replacer { { ",}", ",@}" }, { "{,", "{@," }, } local function splitpathexpr(str, newlist, validate) -- I couldn't resist lpegging it (nice exercise). if trace_expansions then - report_resolvers("expanding variable '%s'",str) + report_expansions("expanding variable '%s'",str) end local t, ok, done = newlist or { }, false, false local n = #t @@ -9550,7 +9607,7 @@ local function splitpathexpr(str, newlist, validate) -- I couldn't resist lpeggi end if trace_expansions then for k=1,#t do - report_resolvers("% 4i: %s",k,t[k]) + report_expansions("% 4i: %s",k,t[k]) end end return t @@ -9585,7 +9642,7 @@ function resolvers.cleanpath(str) homedir = lpegmatch(cleanup,environment.homedir or "") if homedir == string.char(127) or homedir == "" or not lfs.isdir(homedir) then if trace_expansions then - report_resolvers("no home dir set, ignoring dependent paths") + report_expansions("no home dir set, ignoring dependent paths") end function resolvers.cleanpath(str) if find(str,"~") then @@ -9655,9 +9712,9 @@ local function splitconfigurationpath(str) -- beware, this can be either a path end end if trace_expansions then - report_resolvers("splitting path specification '%s'",str) + report_expansions("splitting path specification '%s'",str) for k=1,noffound do - report_resolvers("% 4i: %s",k,found[k]) + report_expansions("% 4i: %s",k,found[k]) end end cache[str] = found @@ -9742,7 +9799,7 @@ end function resolvers.scanfiles(path,branch) if trace_locating then - report_resolvers("scanning path '%s', branch '%s'",path, branch or path) + report_expansions("scanning path '%s', branch '%s'",path, branch or path) end local realpath = resolvers.resolve(path) -- no shortcut local files, n, m, r = scan({ },realpath .. '/',"",0,0,0) @@ -9751,7 +9808,7 @@ function resolvers.scanfiles(path,branch) files.__directories__ = m files.__remappings__ = r if trace_locating then - report_resolvers("%s files found on %s directories with %s uppercase remappings",n,m,r) + report_expansions("%s files found on %s directories with %s uppercase remappings",n,m,r) end return files end @@ -10080,8 +10137,8 @@ local mkdirs, isdir = dir.mkdirs, lfs.isdir local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end) -local report_cache = logs.new("cache") -local report_resolvers = logs.new("resolvers") +local report_caches = logs.new("resolvers","caches") +local report_resolvers = logs.new("resolvers","caching") local resolvers = resolvers @@ -10141,7 +10198,7 @@ local function identify() if not caches.ask or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then mkdirs(cachepath) if isdir(cachepath) and file.is_writable(cachepath) then - report_cache("created: %s",cachepath) + report_caches("created: %s",cachepath) writable = cachepath readables[#readables+1] = cachepath end @@ -10175,10 +10232,10 @@ local function identify() -- Some extra checking. If we have no writable or readable path then we simply -- quit. if not writable then - report_cache("fatal error: there is no valid writable cache path defined") + report_caches("fatal error: there is no valid writable cache path defined") os.exit() elseif #readables == 0 then - report_cache("fatal error: there is no valid readable cache path defined") + report_caches("fatal error: there is no valid readable cache path defined") os.exit() end -- why here @@ -10200,9 +10257,9 @@ local function identify() -- end if trace_cache then for i=1,#readables do - report_cache("using readable path '%s' (order %s)",readables[i],i) + report_caches("using readable path '%s' (order %s)",readables[i],i) end - report_cache("using writable path '%s'",writable) + report_caches("using writable path '%s'",writable) end identify = function() return writable, readables @@ -10237,7 +10294,7 @@ function caches.hashed(tree) tree = lower(tree) local hash = md5.hex(tree) if trace_cache or trace_locating then - report_cache("hashing tree %s, hash %s",tree,hash) + report_caches("hashing tree %s, hash %s",tree,hash) end return hash end @@ -10463,7 +10520,7 @@ trackers.register("resolvers.locating", function(v) trace_methods = v end) trackers.register("resolvers.methods", function(v) trace_methods = v end) -local report_resolvers = logs.new("resolvers") +local report_methods = logs.new("resolvers","methods") local allocate = utilities.storage.allocate @@ -10505,41 +10562,41 @@ local function methodhandler(what,first,...) -- filename can be nil or false local resolver = namespace and namespace[scheme] if resolver then if trace_methods then - report_resolvers("resolver: method=%s, how=%s, scheme=%s, argument=%s",what,how,scheme,first) + report_methods("resolver: method=%s, how=%s, scheme=%s, argument=%s",what,how,scheme,first) end return resolver(specification,...) else resolver = namespace.default or namespace.file if resolver then if trace_methods then - report_resolvers("resolver: method=%s, how=%s, default, argument=%s",what,how,first) + report_methods("resolver: method=%s, how=%s, default, argument=%s",what,how,first) end return resolver(specification,...) elseif trace_methods then - report_resolvers("resolver: method=%s, how=%s, no handler",what,how) + report_methods("resolver: method=%s, how=%s, no handler",what,how) end end elseif how == "tag" then local resolver = namespace and namespace[first] if resolver then if trace_methods then - report_resolvers("resolver: method=%s, how=%s, tag=%s",what,how,first) + report_methods("resolver: method=%s, how=%s, tag=%s",what,how,first) end return resolver(...) else resolver = namespace.default or namespace.file if resolver then if trace_methods then - report_resolvers("resolver: method=%s, how=%s, default",what,how) + report_methods("resolver: method=%s, how=%s, default",what,how) end return resolver(...) elseif trace_methods then - report_resolvers("resolver: method=%s, how=%s, unknown",what,how) + report_methods("resolver: method=%s, how=%s, unknown",what,how) end end end else - report_resolvers("resolver: method=%s, unknown",what) + report_methods("resolver: method=%s, unknown",what) end end @@ -10610,7 +10667,7 @@ local trace_locating = false trackers.register("resolvers.locating", functi local trace_detail = false trackers.register("resolvers.details", function(v) trace_detail = v end) local trace_expansions = false trackers.register("resolvers.expansions", function(v) trace_expansions = v end) -local report_resolvers = logs.new("resolvers") +local report_resolving = logs.new("resolvers","resolving") local resolvers = resolvers @@ -10712,7 +10769,7 @@ end function resolvers.newinstance() -- todo: all vars will become lowercase and alphanum only if trace_locating then - report_resolvers("creating instance") + report_resolving("creating instance") end local environment, variables, expansions, order = allocate(), allocate(), allocate(), allocate() @@ -10830,9 +10887,9 @@ local function reportcriticalvariables() for i=1,#resolvers.criticalvars do local k = resolvers.criticalvars[i] local v = resolvers.getenv(k) or "unknown" -- this one will not resolve ! - report_resolvers("variable '%s' set to '%s'",k,v) + report_resolving("variable '%s' set to '%s'",k,v) end - report_resolvers() + report_resolving() end reportcriticalvariables = function() end end @@ -10856,17 +10913,17 @@ local function identify_configuration_files() if lfs.isfile(realname) then specification[#specification+1] = filename if trace_locating then - report_resolvers("found configuration file '%s'",realname) + report_resolving("found configuration file '%s'",realname) end elseif trace_locating then - report_resolvers("unknown configuration file '%s'",realname) + report_resolving("unknown configuration file '%s'",realname) end end if trace_locating then - report_resolvers() + report_resolving() end elseif trace_locating then - report_resolvers("configuration files already identified") + report_resolving("configuration files already identified") end end @@ -10886,8 +10943,8 @@ local function load_configuration_files() data = data and data.content if data then if trace_locating then - report_resolvers("loading configuration file '%s'",filename) - report_resolvers() + report_resolving("loading configuration file '%s'",filename) + report_resolving() end local variables = data.variables or { } local warning = false @@ -10897,7 +10954,7 @@ local function load_configuration_files() initializesetter(filename,k,v) elseif variables[k] == nil then if trace_locating and not warning then - report_resolvers("variables like '%s' in configuration file '%s' should move to the 'variables' subtable", + report_resolving("variables like '%s' in configuration file '%s' should move to the 'variables' subtable", k,resolvers.resolve(filename)) warning = true end @@ -10910,7 +10967,7 @@ local function load_configuration_files() local cnfspec = variables["TEXMFCNF"] if cnfspec then if trace_locating then - report_resolvers("reloading configuration due to TEXMF redefinition") + report_resolving("reloading configuration due to TEXMF redefinition") end -- we push the value into the main environment (osenv) so -- that it takes precedence over the default one and therefore @@ -10929,13 +10986,13 @@ local function load_configuration_files() else if trace_locating then - report_resolvers("skipping configuration file '%s' (no content)",filename) + report_resolving("skipping configuration file '%s' (no content)",filename) end setups[pathname] = { } instance.loaderror = true end elseif trace_locating then - report_resolvers("skipping configuration file '%s' (no file)",filename) + report_resolving("skipping configuration file '%s' (no file)",filename) end instance.order[#instance.order+1] = instance.setups[pathname] if instance.loaderror then @@ -10943,7 +11000,7 @@ local function load_configuration_files() end end elseif trace_locating then - report_resolvers("warning: no lua configuration files found") + report_resolving("warning: no lua configuration files found") end end @@ -10979,19 +11036,19 @@ local function locate_file_databases() end if trace_locating then if runtime then - report_resolvers("locating list of '%s' (runtime)",path) + report_resolving("locating list of '%s' (runtime)",path) else - report_resolvers("locating list of '%s' (cached)",path) + report_resolving("locating list of '%s' (cached)",path) end end methodhandler('locators',stripped) end end if trace_locating then - report_resolvers() + report_resolving() end elseif trace_locating then - report_resolvers("no texmf paths are defined (using TEXMF)") + report_resolving("no texmf paths are defined (using TEXMF)") end end @@ -11002,7 +11059,7 @@ local function generate_file_databases() methodhandler('generators',hash.name) end if trace_locating then - report_resolvers() + report_resolving() end end @@ -11014,11 +11071,11 @@ local function save_file_databases() -- will become cachers local content = instance.files[cachename] caches.collapsecontent(content) if trace_locating then - report_resolvers("saving tree '%s'",cachename) + report_resolving("saving tree '%s'",cachename) end caches.savecontent(cachename,"files",content) elseif trace_locating then - report_resolvers("not saving runtime tree '%s'",cachename) + report_resolving("not saving runtime tree '%s'",cachename) end end end @@ -11043,7 +11100,7 @@ function resolvers.appendhash(type,name,cache) -- safeguard ... tricky as it's actually a bug when seen twice if not instance.hashed[name] then if trace_locating then - report_resolvers("hash '%s' appended",name) + report_resolving("hash '%s' appended",name) end insert(instance.hashes, { type = type, name = name, cache = cache } ) instance.hashed[name] = cache @@ -11054,7 +11111,7 @@ function resolvers.prependhash(type,name,cache) -- safeguard ... tricky as it's actually a bug when seen twice if not instance.hashed[name] then if trace_locating then - report_resolvers("hash '%s' prepended",name) + report_resolving("hash '%s' prepended",name) end insert(instance.hashes, 1, { type = type, name = name, cache = cache } ) instance.hashed[name] = cache @@ -11287,9 +11344,9 @@ function isreadable(name) local readable = lfs.isfile(name) -- not file.is_readable(name) asit can be a dir if trace_detail then if readable then - report_resolvers("file '%s' is readable",name) + report_resolving("file '%s' is readable",name) else - report_resolvers("file '%s' is not readable", name) + report_resolving("file '%s' is not readable", name) end end return readable @@ -11303,7 +11360,7 @@ local function collect_files(names) for k=1,#names do local fname = names[k] if trace_detail then - report_resolvers("checking name '%s'",fname) + report_resolving("checking name '%s'",fname) end local bname = filebasename(fname) local dname = filedirname(fname) @@ -11319,7 +11376,7 @@ local function collect_files(names) local files = blobpath and instance.files[blobpath] if files then if trace_detail then - report_resolvers("deep checking '%s' (%s)",blobpath,bname) + report_resolving("deep checking '%s' (%s)",blobpath,bname) end local blobfile = files[bname] if not blobfile then @@ -11339,7 +11396,7 @@ local function collect_files(names) local search = filejoin(blobroot,blobfile,bname) local result = methodhandler('concatinators',hash.type,blobroot,blobfile,bname) if trace_detail then - report_resolvers("match: kind '%s', search '%s', result '%s'",kind,search,result) + report_resolving("match: kind '%s', search '%s', result '%s'",kind,search,result) end noffiles = noffiles + 1 filelist[noffiles] = { kind, search, result } @@ -11353,7 +11410,7 @@ local function collect_files(names) local search = filejoin(blobroot,vv,bname) local result = methodhandler('concatinators',hash.type,blobroot,vv,bname) if trace_detail then - report_resolvers("match: kind '%s', search '%s', result '%s'",kind,search,result) + report_resolving("match: kind '%s', search '%s', result '%s'",kind,search,result) end noffiles = noffiles + 1 filelist[noffiles] = { kind, search, result } @@ -11362,7 +11419,7 @@ local function collect_files(names) end end elseif trace_locating then - report_resolvers("no match in '%s' (%s)",blobpath,bname) + report_resolving("no match in '%s' (%s)",blobpath,bname) end end end @@ -11403,7 +11460,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : stamp = filename .. "--" .. askedformat if instance.found[stamp] then if trace_locating then - report_resolvers("remembered file '%s'",filename) + report_resolving("remembered file '%s'",filename) end resolvers.registerintrees(filename) -- for tracing used files return instance.found[stamp] @@ -11412,7 +11469,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : if not dangerous[askedformat] then if isreadable(filename) then if trace_detail then - report_resolvers("file '%s' found directly",filename) + report_resolving("file '%s' found directly",filename) end if stamp then instance.found[stamp] = { filename } @@ -11422,13 +11479,13 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : end if find(filename,'%*') then if trace_locating then - report_resolvers("checking wildcard '%s'", filename) + report_resolving("checking wildcard '%s'", filename) end result = resolvers.findwildcardfiles(filename) -- we can use th elocal elseif file.is_qualified_path(filename) then if isreadable(filename) then if trace_locating then - report_resolvers("qualified name '%s'", filename) + report_resolving("qualified name '%s'", filename) end result = { filename } else @@ -11441,7 +11498,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : forcedname = filename .. "." .. s if isreadable(forcedname) then if trace_locating then - report_resolvers("no suffix, forcing format filetype '%s'", s) + report_resolving("no suffix, forcing format filetype '%s'", s) end result, ok = { forcedname }, true break @@ -11494,7 +11551,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : -- end end if not ok and trace_locating then - report_resolvers("qualified name '%s'", filename) + report_resolving("qualified name '%s'", filename) end end else @@ -11513,13 +11570,13 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : wantedfiles[#wantedfiles+1] = forcedname filetype = resolvers.formatofsuffix(forcedname) if trace_locating then - report_resolvers("forcing filetype '%s'",filetype) + report_resolving("forcing filetype '%s'",filetype) end end else filetype = resolvers.formatofsuffix(filename) if trace_locating then - report_resolvers("using suffix based filetype '%s'",filetype) + report_resolving("using suffix based filetype '%s'",filetype) end end else @@ -11533,7 +11590,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : end filetype = askedformat if trace_locating then - report_resolvers("using given filetype '%s'",filetype) + report_resolving("using given filetype '%s'",filetype) end end local typespec = resolvers.variableofformat(filetype) @@ -11541,7 +11598,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : if not pathlist or #pathlist == 0 then -- no pathlist, access check only / todo == wildcard if trace_detail then - report_resolvers("checking filename '%s', filetype '%s', wanted files '%s'",filename, filetype or '?',concat(wantedfiles," | ")) + report_resolving("checking filename '%s', filetype '%s', wanted files '%s'",filename, filetype or '?',concat(wantedfiles," | ")) end for k=1,#wantedfiles do local fname = wantedfiles[k] @@ -11569,7 +11626,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : end end if trace_detail then - report_resolvers("checking filename '%s'",filename) + report_resolving("checking filename '%s'",filename) end for k=1,#pathlist do local path = pathlist[k] @@ -11581,7 +11638,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : -- compare list entries with permitted pattern -- /xx /xx// local expression = makepathexpression(pathname) if trace_detail then - report_resolvers("using pattern '%s' for path '%s'",expression,pathname) + report_resolving("using pattern '%s' for path '%s'",expression,pathname) end for k=1,#filelist do local fl = filelist[k] @@ -11593,16 +11650,16 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : done = true if allresults then if trace_detail then - report_resolvers("match to '%s' in hash for file '%s' and path '%s', continue scanning",expression,f,d) + report_resolving("match to '%s' in hash for file '%s' and path '%s', continue scanning",expression,f,d) end else if trace_detail then - report_resolvers("match to '%s' in hash for file '%s' and path '%s', quit scanning",expression,f,d) + report_resolving("match to '%s' in hash for file '%s' and path '%s', quit scanning",expression,f,d) end break end elseif trace_detail then - report_resolvers("no match to '%s' in hash for file '%s' and path '%s'",expression,f,d) + report_resolving("no match to '%s' in hash for file '%s' and path '%s'",expression,f,d) end end end @@ -11619,7 +11676,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : local fname = filejoin(ppname,w) if isreadable(fname) then if trace_detail then - report_resolvers("found '%s' by scanning",fname) + report_resolving("found '%s' by scanning",fname) end result[#result+1] = fname done = true @@ -11824,7 +11881,7 @@ end local function report(str) if trace_locating then - report_resolvers(str) -- has already verbose + report_resolving(str) -- has already verbose else print(str) end @@ -12219,7 +12276,7 @@ if not modules then modules = { } end modules ['data-fil'] = { local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_files = logs.new("resolvers","files") local resolvers = resolvers @@ -12233,11 +12290,11 @@ function locators.file(specification) local realname = resolvers.resolve(name) -- no shortcut if realname and realname ~= '' and lfs.isdir(realname) then if trace_locating then - report_resolvers("file locator '%s' found as '%s'",name,realname) + report_files("file locator '%s' found as '%s'",name,realname) end resolvers.appendhash('file',name,true) -- cache elseif trace_locating then - report_resolvers("file locator '%s' not found",name) + report_files("file locator '%s' not found",name) end end @@ -12260,12 +12317,12 @@ function finders.file(specification,filetype) local foundname = resolvers.findfile(filename,filetype) if foundname and foundname ~= "" then if trace_locating then - report_resolvers("file finder: '%s' found",filename) + report_files("file finder: '%s' found",filename) end return foundname else if trace_locating then - report_resolvers("file finder: %s' not found",filename) + report_files("file finder: %s' not found",filename) end return finders.notfound() end @@ -12286,13 +12343,13 @@ function openers.file(specification,filetype) local f = io.open(filename,"r") if f then if trace_locating then - report_resolvers("file opener, '%s' opened",filename) + report_files("file opener, '%s' opened",filename) end return openers.helpers.textopener("file",filename,f) end end if trace_locating then - report_resolvers("file opener, '%s' not found",filename) + report_files("file opener, '%s' not found",filename) end return openers.notfound() end @@ -12304,7 +12361,7 @@ function loaders.file(specification,filetype) if f then logs.show_load(filename) if trace_locating then - report_resolvers("file loader, '%s' loaded",filename) + report_files("file loader, '%s' loaded",filename) end local s = f:read("*a") if checkgarbage then @@ -12317,7 +12374,7 @@ function loaders.file(specification,filetype) end end if trace_locating then - report_resolvers("file loader, '%s' not found",filename) + report_files("file loader, '%s' not found",filename) end return loaders.notfound() end @@ -12358,11 +12415,11 @@ containers = containers or { } local containers = containers containers.usecache = true -local report_cache = logs.new("cache") +local report_containers = logs.new("resolvers","containers") local function report(container,tag,name) if trace_cache or trace_containers then - report_cache("container: %s, tag: %s, name: %s",container.subcategory,tag,name or 'invalid') + report_containers("container: %s, tag: %s, name: %s",container.subcategory,tag,name or 'invalid') end end @@ -12480,7 +12537,7 @@ local format, lower, gsub, find = string.format, string.lower, string.gsub, stri local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_mounts = logs.new("resolvers","mounts") local resolvers = resolvers @@ -12505,7 +12562,7 @@ function resolvers.automount(usecache) -- skip elseif find(line,"^zip://") then if trace_locating then - report_resolvers("mounting %s",line) + report_mounts("mounting %s",line) end table.insert(resolvers.automounted,line) resolvers.usezipfile(line) @@ -12585,7 +12642,7 @@ local format, find, match = string.format, string.find, string.match local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_zip = logs.new("resolvers","zip") -- zip:///oeps.zip?name=bla/bla.tex -- zip:///oeps.zip?tree=tex/texmf-local @@ -12638,9 +12695,9 @@ function resolvers.locators.zip(specification) local zipfile = archive and archive ~= "" and zip.openarchive(archive) -- tricky, could be in to be initialized tree if trace_locating then if zipfile then - report_resolvers("zip locator, archive '%s' found",archive) + report_zip("locator, archive '%s' found",archive) else - report_resolvers("zip locator, archive '%s' not found",archive) + report_zip("locator, archive '%s' not found",archive) end end end @@ -12648,7 +12705,7 @@ end function resolvers.hashers.zip(specification) local archive = specification.filename if trace_locating then - report_resolvers("loading zip file '%s'",archive) + report_zip("loading file '%s'",archive) end resolvers.usezipfile(specification.original) end @@ -12671,25 +12728,25 @@ function resolvers.finders.zip(specification) local zfile = zip.openarchive(archive) if zfile then if trace_locating then - report_resolvers("zip finder, archive '%s' found",archive) + report_zip("finder, archive '%s' found",archive) end local dfile = zfile:open(queryname) if dfile then dfile = zfile:close() if trace_locating then - report_resolvers("zip finder, file '%s' found",queryname) + report_zip("finder, file '%s' found",queryname) end return specification.original elseif trace_locating then - report_resolvers("zip finder, file '%s' not found",queryname) + report_zip("finder, file '%s' not found",queryname) end elseif trace_locating then - report_resolvers("zip finder, unknown archive '%s'",archive) + report_zip("finder, unknown archive '%s'",archive) end end end if trace_locating then - report_resolvers("zip finder, '%s' not found",original) + report_zip("finder, '%s' not found",original) end return resolvers.finders.notfound() end @@ -12704,24 +12761,24 @@ function resolvers.openers.zip(specification) local zfile = zip.openarchive(archive) if zfile then if trace_locating then - report_resolvers("zip opener, archive '%s' opened",archive) + report_zip("opener, archive '%s' opened",archive) end local dfile = zfile:open(queryname) if dfile then if trace_locating then - report_resolvers("zip opener, file '%s' found",queryname) + report_zip("opener, file '%s' found",queryname) end return resolvers.openers.helpers.textopener('zip',original,dfile) elseif trace_locating then - report_resolvers("zip opener, file '%s' not found",queryname) + report_zip("opener, file '%s' not found",queryname) end elseif trace_locating then - report_resolvers("zip opener, unknown archive '%s'",archive) + report_zip("opener, unknown archive '%s'",archive) end end end if trace_locating then - report_resolvers("zip opener, '%s' not found",original) + report_zip("opener, '%s' not found",original) end return resolvers.openers.notfound() end @@ -12736,27 +12793,27 @@ function resolvers.loaders.zip(specification) local zfile = zip.openarchive(archive) if zfile then if trace_locating then - report_resolvers("zip loader, archive '%s' opened",archive) + report_zip("loader, archive '%s' opened",archive) end local dfile = zfile:open(queryname) if dfile then logs.show_load(original) if trace_locating then - report_resolvers("zip loader, file '%s' loaded",original) + report_zip("loader, file '%s' loaded",original) end local s = dfile:read("*all") dfile:close() return true, s, #s elseif trace_locating then - report_resolvers("zip loader, file '%s' not found",queryname) + report_zip("loader, file '%s' not found",queryname) end elseif trace_locating then - report_resolvers("zip loader, unknown archive '%s'",archive) + report_zip("loader, unknown archive '%s'",archive) end end end if trace_locating then - report_resolvers("zip loader, '%s' not found",original) + report_zip("loader, '%s' not found",original) end return resolvers.openers.notfound() end @@ -12772,7 +12829,7 @@ function resolvers.usezipfile(archive) if z then local tree = url.query(specification.query).tree or "" if trace_locating then - report_resolvers("zip registering, registering archive '%s'",archive) + report_zip("registering, registering archive '%s'",archive) end statistics.starttiming(resolvers.instance) resolvers.prependhash('zip',archive) @@ -12781,10 +12838,10 @@ function resolvers.usezipfile(archive) instance.files[archive] = resolvers.registerzipfile(z,tree) statistics.stoptiming(resolvers.instance) elseif trace_locating then - report_resolvers("zip registering, unknown archive '%s'",archive) + report_zip("registering, unknown archive '%s'",archive) end elseif trace_locating then - report_resolvers("zip registering, '%s' not found",archive) + report_zip("registering, '%s' not found",archive) end end @@ -12796,7 +12853,7 @@ function resolvers.registerzipfile(z,tree) filter = format("^%s/(.+)/(.-)$",tree) end if trace_locating then - report_resolvers("zip registering, using filter '%s'",filter) + report_zip("registering, using filter '%s'",filter) end local register, n = resolvers.registerfile, 0 for i in z:files() do @@ -12813,7 +12870,7 @@ function resolvers.registerzipfile(z,tree) n = n + 1 end end - report_resolvers("zip registering, %s files registered",n) + report_zip("registering, %s files registered",n) return files end @@ -12836,7 +12893,7 @@ local find, gsub, format = string.find, string.gsub, string.format local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_trees = logs.new("resolvers","trees") local resolvers = resolvers @@ -12874,18 +12931,18 @@ function resolvers.locators.tree(specification) local name = specification.filename if name ~= '' and lfs.isdir(name) then if trace_locating then - report_resolvers("tree locator '%s' found",name) + report_trees("locator '%s' found",name) end resolvers.appendhash('tree',name,false) -- don't cache elseif trace_locating then - report_resolvers("tree locator '%s' not found",name) + report_trees("locator '%s' not found",name) end end function resolvers.hashers.tree(specification) local name = specification.filename if trace_locating then - report_resolvers("analysing tree '%s'",name) + report_trees("analysing '%s'",name) end resolvers.methodhandler("hashers",name) end @@ -12981,7 +13038,7 @@ if not modules then modules = { } end modules ['data-lua'] = { local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_libraries = logs.new("resolvers","libraries") local gsub, insert = string.gsub, table.insert local unpack = unpack or table.unpack @@ -13013,7 +13070,7 @@ local function thepath(...) local t = { ... } t[#t+1] = "?.lua" local path = file.join(unpack(t)) if trace_locating then - report_resolvers("! appending '%s' to 'package.path'",path) + report_libraries("! appending '%s' to 'package.path'",path) end return path end @@ -13035,11 +13092,11 @@ local function loaded(libpaths,name,simple) local libpath = libpaths[i] local resolved = gsub(libpath,"%?",simple) if trace_locating then -- more detail - report_resolvers("! checking for '%s' on 'package.path': '%s' => '%s'",simple,libpath,resolved) + report_libraries("! checking for '%s' on 'package.path': '%s' => '%s'",simple,libpath,resolved) end if file.is_readable(resolved) then if trace_locating then - report_resolvers("! lib '%s' located via 'package.path': '%s'",name,resolved) + report_libraries("! lib '%s' located via 'package.path': '%s'",name,resolved) end return loadfile(resolved) end @@ -13048,17 +13105,17 @@ end package.loaders[2] = function(name) -- was [#package.loaders+1] if trace_locating then -- mode detail - report_resolvers("! locating '%s'",name) + report_libraries("! locating '%s'",name) end for i=1,#libformats do local format = libformats[i] local resolved = resolvers.findfile(name,format) or "" if trace_locating then -- mode detail - report_resolvers("! checking for '%s' using 'libformat path': '%s'",name,format) + report_libraries("! checking for '%s' using 'libformat path': '%s'",name,format) end if resolved ~= "" then if trace_locating then - report_resolvers("! lib '%s' located via environment: '%s'",name,resolved) + report_libraries("! lib '%s' located via environment: '%s'",name,resolved) end return loadfile(resolved) end @@ -13081,11 +13138,11 @@ package.loaders[2] = function(name) -- was [#package.loaders+1] local path = paths[p] local resolved = file.join(path,libname) if trace_locating then -- mode detail - report_resolvers("! checking for '%s' using 'clibformat path': '%s'",libname,path) + report_libraries("! checking for '%s' using 'clibformat path': '%s'",libname,path) end if file.is_readable(resolved) then if trace_locating then - report_resolvers("! lib '%s' located via 'clibformat': '%s'",libname,resolved) + report_libraries("! lib '%s' located via 'clibformat': '%s'",libname,resolved) end return package.loadlib(resolved,name) end @@ -13095,28 +13152,28 @@ package.loaders[2] = function(name) -- was [#package.loaders+1] local libpath = clibpaths[i] local resolved = gsub(libpath,"?",simple) if trace_locating then -- more detail - report_resolvers("! checking for '%s' on 'package.cpath': '%s'",simple,libpath) + report_libraries("! checking for '%s' on 'package.cpath': '%s'",simple,libpath) end if file.is_readable(resolved) then if trace_locating then - report_resolvers("! lib '%s' located via 'package.cpath': '%s'",name,resolved) + report_libraries("! lib '%s' located via 'package.cpath': '%s'",name,resolved) end return package.loadlib(resolved,name) end end -- just in case the distribution is messed up if trace_loading then -- more detail - report_resolvers("! checking for '%s' using 'luatexlibs': '%s'",name) + report_libraries("! checking for '%s' using 'luatexlibs': '%s'",name) end local resolved = resolvers.findfile(file.basename(name),'luatexlibs') or "" if resolved ~= "" then if trace_locating then - report_resolvers("! lib '%s' located by basename via environment: '%s'",name,resolved) + report_libraries("! lib '%s' located by basename via environment: '%s'",name,resolved) end return loadfile(resolved) end if trace_locating then - report_resolvers('? unable to locate lib: %s',name) + report_libraries('? unable to locate lib: %s',name) end -- return "unable to locate " .. name end @@ -13153,48 +13210,48 @@ local trace_locating = false trackers.register("resolvers.locating", function(v local resolvers = resolvers -local report_resolvers = logs.new("resolvers") +local report_scripts = logs.new("resolvers","scripts") function resolvers.updatescript(oldname,newname) -- oldname -> own.name, not per se a suffix local scriptpath = "scripts/context/lua" newname = file.addsuffix(newname,"lua") local oldscript = resolvers.cleanpath(oldname) if trace_locating then - report_resolvers("to be replaced old script %s", oldscript) + report_scripts("to be replaced old script %s", oldscript) end local newscripts = resolvers.findfiles(newname) or { } if #newscripts == 0 then if trace_locating then - report_resolvers("unable to locate new script") + report_scripts("unable to locate new script") end else for i=1,#newscripts do local newscript = resolvers.cleanpath(newscripts[i]) if trace_locating then - report_resolvers("checking new script %s", newscript) + report_scripts("checking new script %s", newscript) end if oldscript == newscript then if trace_locating then - report_resolvers("old and new script are the same") + report_scripts("old and new script are the same") end elseif not find(newscript,scriptpath) then if trace_locating then - report_resolvers("new script should come from %s",scriptpath) + report_scripts("new script should come from %s",scriptpath) end elseif not (find(oldscript,file.removesuffix(newname).."$") or find(oldscript,newname.."$")) then if trace_locating then - report_resolvers("invalid new script name") + report_scripts("invalid new script name") end else local newdata = io.loaddata(newscript) if newdata then if trace_locating then - report_resolvers("old script content replaced by new content") + report_scripts("old script content replaced by new content") end io.savedata(oldscript,newdata) break elseif trace_locating then - report_resolvers("unable to load new script") + report_scripts("unable to load new script") end end end @@ -13216,6 +13273,8 @@ if not modules then modules = { } end modules ['data-tmf'] = { local resolvers = resolvers +local report_tds = logs.new("resolvers","tds") + -- = << -- ? ?? -- < += @@ -13236,11 +13295,11 @@ function resolvers.load_tree(tree,resolve) local newpath = file.join(newtree,"bin") if not lfs.isdir(newtree) then - logs.simple("no '%s' under tree %s",texos,tree) + report_tds("no '%s' under tree %s",texos,tree) os.exit() end if not lfs.isdir(newpath) then - logs.simple("no '%s/bin' under tree %s",texos,tree) + report_tds("no '%s/bin' under tree %s",texos,tree) os.exit() end @@ -13264,9 +13323,9 @@ function resolvers.load_tree(tree,resolve) setenv('TEXMFCNF', resolvers.luacnfspec, not resolve) setenv("PATH", newpath .. io.pathseparator .. getenv("PATH")) - logs.simple("changing from root '%s' to '%s'",oldroot,newroot) - logs.simple("prepending '%s' to binary path",newpath) - logs.simple() + report_tds("changing from root '%s' to '%s'",oldroot,newroot) + report_tds("prepending '%s' to binary path",newpath) + report_tds() end end @@ -13291,6 +13350,8 @@ resolvers.listers = resolvers.listers or { } local resolvers = resolvers +local report_lists = logs.new("resolvers","lists") + local function tabstr(str) if type(str) == 'table' then return concat(str," | ") @@ -13319,11 +13380,11 @@ function resolvers.listers.variables(pattern) local exp = table.fastcopy(expansions) for key, value in table.sortedpairs(configured) do if key ~= "" and (pattern == "" or find(upper(key),pattern)) then - logs.simple(key) - logs.simple(" env: %s",tabstr(rawget(environment,key)) or "unset") - logs.simple(" var: %s",tabstr(configured[key]) or "unset") - logs.simple(" exp: %s",tabstr(expansions[key]) or "unset") - logs.simple(" res: %s",resolvers.resolve(expansions[key]) or "unset") + report_lists(key) + report_lists(" env: %s",tabstr(rawget(environment,key)) or "unset") + report_lists(" var: %s",tabstr(configured[key]) or "unset") + report_lists(" exp: %s",tabstr(expansions[key]) or "unset") + report_lists(" res: %s",resolvers.resolve(expansions[key]) or "unset") end end instance.environment = table.fastcopy(env) @@ -13477,6 +13538,8 @@ if not modules then modules = { } end modules ['luat-fmt'] = { local format = string.format +local report_format = logs.new("resolvers","formats") + -- helper for mtxrun local quoted = string.quoted @@ -13501,7 +13564,7 @@ function environment.make_format(name) if path ~= "" then lfs.chdir(path) end - logs.simple("format path: %s",lfs.currentdir()) + report_format("format path: %s",lfs.currentdir()) -- check source file local texsourcename = file.addsuffix(name,"mkiv") local fulltexsourcename = resolvers.findfile(texsourcename,"tex") or "" @@ -13510,11 +13573,11 @@ function environment.make_format(name) fulltexsourcename = resolvers.findfile(texsourcename,"tex") or "" end if fulltexsourcename == "" then - logs.simple("no tex source file with name: %s (mkiv or tex)",name) + report_format("no tex source file with name: %s (mkiv or tex)",name) lfs.chdir(olddir) return else - logs.simple("using tex source file: %s",fulltexsourcename) + report_format("using tex source file: %s",fulltexsourcename) end local texsourcepath = dir.expandname(file.dirname(fulltexsourcename)) -- really needed -- check specification @@ -13525,7 +13588,7 @@ function environment.make_format(name) fullspecificationname = resolvers.findfile(specificationname,"tex") or "" end if fullspecificationname == "" then - logs.simple("unknown stub specification: %s",specificationname) + report_format("unknown stub specification: %s",specificationname) lfs.chdir(olddir) return end @@ -13536,39 +13599,39 @@ function environment.make_format(name) if type(usedlualibs) == "string" then usedluastub = file.join(file.dirname(fullspecificationname),usedlualibs) elseif type(usedlualibs) == "table" then - logs.simple("using stub specification: %s",fullspecificationname) + report_format("using stub specification: %s",fullspecificationname) local texbasename = file.basename(name) local luastubname = file.addsuffix(texbasename,"lua") local lucstubname = file.addsuffix(texbasename,"luc") -- pack libraries in stub - logs.simple("creating initialization file: %s",luastubname) + report_format("creating initialization file: %s",luastubname) utilities.merger.selfcreate(usedlualibs,specificationpath,luastubname) -- compile stub file (does not save that much as we don't use this stub at startup any more) local strip = resolvers.booleanvariable("LUACSTRIP", true) if utilities.lua.compile(luastubname,lucstubname) and lfs.isfile(lucstubname) then - logs.simple("using compiled initialization file: %s",lucstubname) + report_format("using compiled initialization file: %s",lucstubname) usedluastub = lucstubname else - logs.simple("using uncompiled initialization file: %s",luastubname) + report_format("using uncompiled initialization file: %s",luastubname) usedluastub = luastubname end else - logs.simple("invalid stub specification: %s",fullspecificationname) + report_format("invalid stub specification: %s",fullspecificationname) lfs.chdir(olddir) return end -- generate format local command = format("luatex --ini %s --lua=%s %s %sdump",primaryflags(),quoted(usedluastub),quoted(fulltexsourcename),os.platform == "unix" and "\\\\" or "\\") - logs.simple("running command: %s\n",command) + report_format("running command: %s\n",command) os.spawn(command) -- remove related mem files local pattern = file.removesuffix(file.basename(usedluastub)).."-*.mem" - -- logs.simple("removing related mplib format with pattern '%s'", pattern) + -- report_format("removing related mplib format with pattern '%s'", pattern) local mp = dir.glob(pattern) if mp then for i=1,#mp do local name = mp[i] - logs.simple("removing related mplib format %s", file.basename(name)) + report_format("removing related mplib format %s", file.basename(name)) os.remove(name) end end @@ -13585,7 +13648,7 @@ function environment.run_format(name,data,more) end fmtname = resolvers.cleanpath(fmtname) if fmtname == "" then - logs.simple("no format with name: %s",name) + report_format("no format with name: %s",name) else local barename = file.removesuffix(name) -- expanded name local luaname = file.addsuffix(barename,"luc") @@ -13593,11 +13656,11 @@ function environment.run_format(name,data,more) luaname = file.addsuffix(barename,"lua") end if not lfs.isfile(luaname) then - logs.simple("using format name: %s",fmtname) - logs.simple("no luc/lua with name: %s",barename) + report_format("using format name: %s",fmtname) + report_format("no luc/lua with name: %s",barename) else local command = format("luatex %s --fmt=%s --lua=%s %s %s",primaryflags(),quoted(barename),quoted(luaname),quoted(data),more ~= "" and quoted(more) or "") - logs.simple("running command: %s",command) + report_format("running command: %s",command) os.spawn(command) end end @@ -13750,8 +13813,6 @@ if not resolvers then os.exit() end -logs.setprogram('MTXrun',"TDS Runner Tool 1.30") - if environment.arguments["verbose"] then trackers.enable("resolvers.locating") end @@ -13764,10 +13825,7 @@ if trackspec then trackers.enable(trackspec) end -runners = runners or { } -- global -messages = messages or { } - -messages.help = [[ +local helpinfo = [[ --script run an mtx script (lua prefered method) (--noquotes), no script gives list --execute run a script or program (texmfstart method) (--noquotes) --resolve resolve prefixed arguments @@ -13819,6 +13877,19 @@ messages.help = [[ --pattern=str filter variables ]] +local application = logs.application { + name = "mtxrun", + banner = "ConTeXt TDS Runner Tool 1.30", + helpinfo = helpinfo, +} + +local report = application.report + +local verbose = environment.argument("verbose") + +messages = messages or { } -- for the mo + +runners = runners or { } -- global runners.applications = { ["lua"] = "luatex --luaonly", @@ -13872,17 +13943,16 @@ end function runners.prepare() local checkname = environment.argument("ifchanged") - local verbose = environment.argument("verbose") if type(checkname) == "string" and checkname ~= "" then local oldchecksum = file.loadchecksum(checkname) local newchecksum = file.checksum(checkname) if oldchecksum == newchecksum then if verbose then - logs.simple("file '%s' is unchanged",checkname) + report("file '%s' is unchanged",checkname) end return "skip" elseif verbose then - logs.simple("file '%s' is changed, processing started",checkname) + report("file '%s' is changed, processing started",checkname) end file.savechecksum(checkname) end @@ -13892,17 +13962,17 @@ function runners.prepare() if oldname and newname and oldname ~= "" and newname ~= "" then if not file.needs_updating(oldname,newname) then if verbose then - logs.simple("file '%s' and '%s' have same age",oldname,newname) + report("file '%s' and '%s' have same age",oldname,newname) end return "skip" elseif verbose then - logs.simple("file '%s' is older than '%s'",oldname,newname) + report("file '%s' is older than '%s'",oldname,newname) end end end local runpath = environment.argument("path") if type(runpath) == "string" and not lfs.chdir(runpath) then - logs.simple("unable to change to path '%s'",runpath) + report("unable to change to path '%s'",runpath) return "error" end runners.prepare = function() end @@ -13961,11 +14031,11 @@ function runners.execute_script(fullname,internal,nosplit) result = binary .. " " .. result end local command = result .. " " .. environment.reconstructcommandline(environment.arguments_after,noquote) - if logs.verbose then - logs.simpleline() - logs.simple("executing: %s",command) - logs.simpleline() - logs.simpleline() + if verbose then + report() + report("executing: %s",command) + report() + report() io.flush() end -- no os.exec because otherwise we get the wrong return value @@ -13980,9 +14050,9 @@ function runners.execute_script(fullname,internal,nosplit) return false end end - logs.simpleline() - logs.simple("This script needs '%s' which seems not to be installed.",binary) - logs.simpleline() + report() + report("This script needs '%s' which seems not to be installed.",binary) + report() end return false end @@ -14007,10 +14077,10 @@ function runners.execute_program(fullname) environment.initializearguments(after) fullname = fullname:gsub("^bin:","") local command = fullname .. " " .. (environment.reconstructcommandline(after or "",noquote) or "") - logs.simpleline() - logs.simple("executing: %s",command) - logs.simpleline() - logs.simpleline() + report() + report("executing: %s",command) + report() + report() io.flush() local code = os.exec(command) -- (fullname,unpack(after)) does not work / maybe spawn return code == 0 @@ -14042,18 +14112,18 @@ function runners.handle_stubs(create) if create then if windows then io.savedata(file.join(stubpath,base..".bat"),string.format(windows_stub,name)) - logs.simple("windows stub for '%s' created",base) + report("windows stub for '%s' created",base) end if unix then io.savedata(file.join(stubpath,base),string.format(unix_stub,name)) - logs.simple("unix stub for '%s' created",base) + report("unix stub for '%s' created",base) end else if windows and (os.remove(file.join(stubpath,base..'.bat')) or os.remove(file.join(stubpath,base..'.cmd'))) then - logs.simple("windows stub for '%s' removed", base) + report("windows stub for '%s' removed", base) end if unix and (os.remove(file.join(stubpath,base)) or os.remove(file.join(stubpath,base..'.sh'))) then - logs.simple("unix stub for '%s' removed",base) + report("unix stub for '%s' removed",base) end end end @@ -14078,12 +14148,12 @@ function runners.locate_platform() end function runners.report_location(result) - if logs.verbose then - logs.simpleline() + if verbose then + reportline() if result and result ~= "" then - logs.simple(result) + report(result) else - logs.simple("not found") + report("not found") end else io.write(result) @@ -14095,11 +14165,11 @@ function runners.edit_script(filename) -- we assume that gvim is present on most local rest = resolvers.resolve(filename) if rest ~= "" then local command = editor .. " " .. rest - if logs.verbose then - logs.simpleline() - logs.simple("starting editor: %s",command) - logs.simple_line() - logs.simple_line() + if verbose then + report() + report("starting editor: %s",command) + report() + report() end os.launch(command) end @@ -14148,7 +14218,7 @@ function runners.launch_file(filename) pattern = filename end if not pattern or pattern == "" then - logs.simple("provide name or --pattern=") + report("provide name or --pattern=") else local t = resolvers.findfiles(pattern) if not t or #t == 0 then @@ -14160,15 +14230,15 @@ function runners.launch_file(filename) if t and #t > 0 then if environment.arguments["all"] then for _, v in pairs(t) do - logs.simple("launching %s", v) + report("launching %s", v) resolvers.launch(v) end else - logs.simple("launching %s", t[1]) + report("launching %s", t[1]) resolvers.launch(t[1]) end else - logs.simple("no match for %s", pattern) + report("no match for %s", pattern) end end end @@ -14239,7 +14309,7 @@ function runners.execute_ctx_script(filename,...) local fullname = runners.find_mtx_script(filename) or "" if file.extname(fullname) == "cld" then -- handy in editors where we force --autopdf - logs.simple("running cld script: %s",filename) + report("running cld script: %s",filename) table.insert(arguments,1,fullname) table.insert(arguments,"--autopdf") fullname = runners.find_mtx_script("context") or "" @@ -14270,8 +14340,8 @@ function runners.execute_ctx_script(filename,...) runners.load_script_session(loadname) end filename = environment.files[1] - if logs.verbose then - logs.simple("using script: %s\n",fullname) + if verbose then + report("using script: %s\n",fullname) end environment.ownscript = fullname dofile(fullname) @@ -14306,24 +14376,23 @@ function runners.execute_ctx_script(filename,...) end end if #valid > 0 then - logs.reportbanner() - logs.reportline() - logs.simple("no script name given, known scripts:") - logs.simple() + application.identify() + report("no script name given, known scripts:") + report() for k=1,#valid do local v = valid[k] - logs.simple("%-12s %4s %s",v[1],v[2],v[3]) + report("%-12s %4s %s",v[1],v[2],v[3]) end end else - logs.simple("no script name given") + report("no script name given") end else filename = file.addsuffix(filename,"lua") if file.is_qualified_path(filename) then - logs.simple("unknown script '%s'",filename) + report("unknown script '%s'",filename) else - logs.simple("unknown script '%s' or 'mtx-%s'",filename,filename) + report("unknown script '%s' or 'mtx-%s'",filename,filename) end end return false @@ -14331,9 +14400,9 @@ function runners.execute_ctx_script(filename,...) end function runners.prefixes() - logs.reportbanner() - logs.reportline() - logs.simple(table.concat(resolvers.allprefixes(true)," ")) + application.identify() + report() + report(table.concat(resolvers.allprefixes(true)," ")) end function runners.timedrun(filename) -- just for me @@ -14385,7 +14454,7 @@ if environment.argument("usekpse") or environment.argument("forcekpse") or is_mk local t = os.clock() local k = kpse.original.new("luatex",progname) local dummy = k:find_file("mtxrun.lua") -- so that we're initialized - logs.simple("kpse fallback with progname '%s' initialized in %s seconds",progname,os.clock()-t) + report("kpse fallback with progname '%s' initialized in %s seconds",progname,os.clock()-t) kpse_initialized = function() return k end return k end @@ -14432,11 +14501,11 @@ else function runners.loadbase(...) if not resolvers.load(...) then - logs.simple("forcing cache reload") + report("forcing cache reload") instance.renewcache = true trackers.enable("resolvers.locating") if not resolvers.load(...) then - logs.simple("the resolver databases are not present or outdated") + report("the resolver databases are not present or outdated") end end end @@ -14595,8 +14664,8 @@ elseif environment.argument("find-path") then resolvers.load() local path = resolvers.findpath(filename, instance.my_format) - if logs.verbose then - logs.simple(path) + if verbose then + report(path) else print(path) end @@ -14651,7 +14720,7 @@ elseif environment.argument("format-path") then -- luatools: runners.execute_ctx_script("mtx-base","--format-path",filename) resolvers.load() - logs.simple(caches.getwritablepath("format")) + report(caches.getwritablepath("format")) elseif environment.argument("pattern") then @@ -14695,7 +14764,7 @@ elseif environment.argument("help") and filename=='base' then elseif environment.argument("help") or filename=='help' or filename == "" then - logs.help(messages.help) + application.help() elseif filename:find("^bin:") then @@ -14729,9 +14798,9 @@ else end -if logs.verbose then - logs.simpleline() - logs.simple("runtime: %0.3f seconds",os.runtime()) +if verbose then + report() + report("runtime: %0.3f seconds",os.runtime()) end if os.type ~= "windows" then diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 31d7d9b0f..afc472d1c 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -8,7 +8,6 @@ if not modules then modules = { } end modules ['mtxrun'] = { license = "see context related readme files" } - -- one can make a stub: -- -- #!/bin/sh @@ -132,11 +131,7 @@ local simple_escapes = { } function string.escapedpattern(str,simple) - if simple then - return (gsub(str,".",simple_escapes)) - else - return (gsub(str,".",patterns_escapes)) - end + return (gsub(str,".",simple and simple_escapes or patterns_escapes)) end function string.topattern(str,lowercase,strict) @@ -556,11 +551,7 @@ local p = Cs((S("-.+*%()[]") / patterns_escapes + anything)^0) local s = Cs((S("-.+*%()[]") / simple_escapes + anything)^0) function string.escapedpattern(str,simple) - if simple then - return match(s,str) - else - return match(p,str) - end + return match(simple and s or p,str) end -- utf extensies @@ -3826,7 +3817,7 @@ local type, next = type, next utilities = utilities or {} utilities.merger = utilities.merger or { } -- maybe mergers -utilities.report = utilities.report or print +utilities.report = logs and logs.new("system") or print local merger = utilities.merger @@ -3964,7 +3955,7 @@ if not modules then modules = { } end modules ['util-lua'] = { utilities = utilities or {} utilities.lua = utilities.lua or { } -utilities.report = utilities.report or print +utilities.report = logs and logs.new("system") or print function utilities.lua.compile(luafile,lucfile,cleanup,strip) -- defaults: cleanup=false strip=true utilities.report("lua: compiling %s into %s",luafile,lucfile) @@ -4577,19 +4568,21 @@ function statistics.show(reporter) end end - -local template, nn = nil, 0 -- we only calcute it once +local template, report_statistics, nn = nil, nil, 0 -- we only calcute it once function statistics.showjobstat(tag,data,n) - if type(data) == "table" then + if not logs then + -- sorry + elseif type(data) == "table" then for i=1,#data do statistics.showjobstat(tag,data[i],n) end else if not template or n > nn then - template, n = format("%%-%ss: %%-%ss - %%s",15,n), nn + template, n = format("%%-%ss - %%s",n), nn + report_statistics = logs.new("mkiv lua stats") end - write_nl(format(template,"mkiv lua stats",tag,data)) + report_statistics(format(template,tag,data)) end end @@ -4610,7 +4603,7 @@ function statistics.runtime() end function statistics.timed(action,report) - report = report or logs.simple + report = report or logs.new("system") starttiming("run") action() stoptiming("run") @@ -4664,14 +4657,10 @@ local data = { } -- maybe just local local trace_initialize = false -- only for testing during development -local function report(a,b,...) - texio.write_nl(format("%-16s> %s",a,format(b,...))) -end - function setters.initialize(filename,name,values) -- filename only for diagnostics - local data = data[name] - if data then - data = data.data + local setter = data[name] + if setter then + local data = data.data if data then for key, value in next, values do -- key = gsub(key,"_",".") @@ -4680,7 +4669,7 @@ function setters.initialize(filename,name,values) -- filename only for diagnosti if functions then if #functions > 0 and not functions.value then if trace_initialize then - report(name,"executing %s (%s -> %s)",key,filename,tostring(value)) + setter.report("executing %s (%s -> %s)",key,filename,tostring(value)) end for i=1,#functions do functions[i](value) @@ -4688,7 +4677,7 @@ function setters.initialize(filename,name,values) -- filename only for diagnosti functions.value = value else if trace_initialize then - report(name,"skipping %s (%s -> %s)",key,filename,tostring(value)) + setter.report("skipping %s (%s -> %s)",key,filename,tostring(value)) end end else @@ -4697,7 +4686,7 @@ function setters.initialize(filename,name,values) -- filename only for diagnosti functions = { default = value } data[key] = functions if trace_initialize then - report(name,"storing %s (%s -> %s)",key,filename,tostring(value)) + setter.report("storing %s (%s -> %s)",key,filename,tostring(value)) end end end @@ -4724,10 +4713,11 @@ local function set(t,what,newvalue) else value = is_boolean(value,value) end + w = escapedpattern(w,true) for name, functions in next, data do if done[name] then -- prevent recursion due to wildcards - elseif find(name,escapedpattern(w,true)) then + elseif find(name,w) then done[name] = true for i=1,#functions do functions[i](value) @@ -4769,7 +4759,7 @@ function setters.register(t,what,...) functions = { } data[what] = functions if trace_initialize then - report(t.name,"defining %s",what) + t.report("defining %s",what) end end local default = functions.default -- can be set from cnf file @@ -4777,7 +4767,7 @@ function setters.register(t,what,...) local typ = type(fnc) if typ == "string" then if trace_initialize then - report(t.name,"coupling %s to %s",what,fnc) + t.report("coupling %s to %s",what,fnc) end local s = fnc -- else wrong reference fnc = function(value) set(t,s,value) end @@ -4831,9 +4821,9 @@ function setters.list(t) -- pattern end function setters.show(t) - commands.writestatus("","") - local list = setters.list(t) local category = t.name + local list = setters.list(t) + t.report() for k=1,#list do local name = list[k] local functions = t.data[name] @@ -4841,10 +4831,10 @@ function setters.show(t) local value, default, modules = functions.value, functions.default, #functions value = value == nil and "unset" or tostring(value) default = default == nil and "unset" or tostring(default) - commands.writestatus(category,format("%-30s modules: %2i default: %5s value: %5s",name,modules,default,value)) + t.report("%-30s modules: %2i default: %6s value: %6s",name,modules,default,value) end end - commands.writestatus("","") + t.report() end -- we could have used a bit of oo and the trackers:enable syntax but @@ -4854,57 +4844,62 @@ end local enable, disable, register, list, show = setters.enable, setters.disable, setters.register, setters.list, setters.show +local function report(setter,...) + local report = logs and logs.report + if report then + report(setter.name,...) + else -- fallback, as this module is loaded before the logger + write_nl(format("%-16s: %s\n",setter.name,format(...))) + end +end + function setters.new(name) - local t -- we need to access it in t - t = { + local setter -- we need to access it in setter itself + setter = { data = allocate(), -- indexed, but also default and value fields name = name, - enable = function(...) enable (t,...) end, - disable = function(...) disable (t,...) end, - register = function(...) register(t,...) end, - list = function(...) list (t,...) end, - show = function(...) show (t,...) end, + report = function(...) report (setter,...) end, + enable = function(...) enable (setter,...) end, + disable = function(...) disable (setter,...) end, + register = function(...) register(setter,...) end, + list = function(...) list (setter,...) end, + show = function(...) show (setter,...) end, } - data[name] = t - return t + data[name] = setter + return setter end trackers = setters.new("trackers") directives = setters.new("directives") experiments = setters.new("experiments") -local t_enable, t_disable = trackers .enable, trackers .disable -local d_enable, d_disable = directives .enable, directives .disable -local e_enable, e_disable = experiments.enable, experiments.disable +local t_enable, t_disable, t_report = trackers .enable, trackers .disable, trackers .report +local d_enable, d_disable, d_report = directives .enable, directives .disable, directives .report +local e_enable, e_disable, e_report = experiments.enable, experiments.disable, experiments.report -- nice trick: we overload two of the directives related functions with variants that -- do tracing (itself using a tracker) .. proof of concept -local function report(...) -- messy .. chicken or egg - local p = (commands and commands.writestatus) or (logs and logs.report) - if p then p(...) end -end - local trace_directives = false local trace_directives = false trackers.register("system.directives", function(v) trace_directives = v end) local trace_experiments = false local trace_experiments = false trackers.register("system.experiments", function(v) trace_experiments = v end) function directives.enable(...) - report("directives","enabling: %s",concat({...}," ")) + d_report("enabling: %s",concat({...}," ")) d_enable(...) end function directives.disable(...) - report("directives","disabling: %s",concat({...}," ")) + d_report("disabling: %s",concat({...}," ")) d_disable(...) end function experiments.enable(...) - report("experiments","enabling: %s",concat({...}," ")) + e_report("enabling: %s",concat({...}," ")) e_enable(...) end function experiments.disable(...) - report("experiments","disabling: %s",concat({...}," ")) + e_report("disabling: %s",concat({...}," ")) e_disable(...) end @@ -4967,20 +4962,19 @@ if not modules then modules = { } end modules ['trac-log'] = { license = "see context related readme files" } --- xml logging is only usefull in normal runs, not in ini mode --- it looks like some tex logging (like filenames) is broken (no longer --- interceoted at the tex end so the xml variant is not that useable now) +-- todo: less categories, more subcategories (e.g. nodes) local write_nl, write = texio and texio.write_nl or print, texio and texio.write or io.write -local format, gmatch = string.format, string.gmatch +local format, gmatch, find = string.format, string.gmatch, string.find +local concat = table.concat +local escapedpattern = string.escapedpattern local texcount = tex and tex.count +local next, type = next, type --[[ldx-- -<p>This is a prelude to a more extensive logging module. For the sake -of parsing log files, in addition to the standard logging we will -provide an <l n='xml'/> structured file. Actually, any logging that -is hooked into callbacks will be \XML\ by default.</p> +<p>This is a prelude to a more extensive logging module. We no longer +provide <l n='xml'/> based logging a sparsing is relatively easy anyway.</p> --ldx]]-- logs = logs or { } @@ -4998,96 +4992,239 @@ webpage : http://www.pragma-ade.nl / http://tex.aanhet.net wiki : http://contextgarden.net ]] -local functions = { - 'report', 'status', 'start', 'stop', 'push', 'pop', 'line', 'direct', - 'start_run', 'stop_run', - 'start_page_number', 'stop_page_number', - 'report_output_pages', 'report_output_log', - 'report_tex_stat', 'report_job_stat', - 'show_open', 'show_close', 'show_load', - 'dummy', -} +-- local functions = { +-- 'report', 'status', 'start', 'stop', 'line', 'direct', +-- 'start_run', 'stop_run', +-- 'start_page_number', 'stop_page_number', +-- 'report_output_pages', 'report_output_log', +-- 'report_tex_stat', 'report_job_stat', +-- 'show_open', 'show_close', 'show_load', +-- 'dummy', +-- } -local method = "nop" +-- basic loggers -function logs.setmethod(newmethod) - method = newmethod - -- a direct copy might be faster but let's try this for a while - setmetatable(logs, { __index = logs[method] }) -end +local function ignore() end -function logs.getmethod() - return method -end +setmetatable(logs, { __index = function(t,k) t[k] = ignore ; return ignore end }) --- installer +-- local separator = (tex and (tex.jobname or tex.formatname)) and ">" or "|" -local data = { } +local report, subreport -function logs.new(category) - local logger = data[category] - if not logger then - logger = function(...) - logs.report(category,...) +if tex and tex.jobname or tex.formatname then + + report = function(a,b,c,...) + if c then + write_nl(format("%-15s > %s\n",a,format(b,c,...))) + elseif b then + write_nl(format("%-15s > %s\n",a,b)) + elseif a then + write_nl(format("%-15s >\n", a)) + else + write_nl("\n") end - data[category] = logger end - return logger -end + subreport = function(a,sub,b,c,...) + if c then + write_nl(format("%-15s > %s > %s\n",a,sub,format(b,c,...))) + elseif b then + write_nl(format("%-15s > %s > %s\n",a,sub,b)) + elseif a then + write_nl(format("%-15s > %s >\n", a,sub)) + else + write_nl("\n") + end + end --- nop logging (maybe use __call instead) - -local noplog = { } logs.nop = noplog setmetatable(logs, { __index = noplog }) +else -for i=1,#functions do - noplog[functions[i]] = function() end -end + report = function(a,b,c,...) + if c then + write_nl(format("%-15s | %s",a,format(b,c,...))) + elseif b then + write_nl(format("%-15s | %s",a,b)) + elseif a then + write_nl(format("%-15s |", a)) + else + write_nl("") + end + end --- tex logging + subreport = function(a,sub,b,c,...) + if c then + write_nl(format("%-15s | %s | %s",a,sub,format(b,c,...))) + elseif b then + write_nl(format("%-15s | %s | %s",a,sub,b)) + elseif a then + write_nl(format("%-15s | %s |", a,sub)) + else + write_nl("") + end + end -local texlog = { } logs.tex = texlog setmetatable(texlog, { __index = noplog }) +end -function texlog.report(a,b,c,...) +function logs.status(a,b,c,...) -- at the tex end if c then - write_nl(format("%-16s> %s\n",a,format(b,c,...))) + write_nl(format("%-15s : %s\n",a,format(b,c,...))) elseif b then - write_nl(format("%-16s> %s\n",a,b)) + write_nl(format("%-15s : %s\n",a,b)) -- b can have %'s + elseif a then + write_nl(format("%-15s :\n", a)) else - write_nl(format("%-16s>\n",a)) + write_nl("\n") end end -function texlog.status(a,b,c,...) - if c then - write_nl(format("%-16s: %s\n",a,format(b,c,...))) - elseif b then - write_nl(format("%-16s: %s\n",a,b)) -- b can have %'s - else - write_nl(format("%-16s:>\n",a)) +logs.report = report +logs.subreport = subreport + +-- installer + +-- todo: renew (un) locks when a new one is added and wildcard + +local data, states = { }, nil + +function logs.reporter(category,subcategory) + local logger = data[category] + if not logger then + local state = false + if states == true then + state = true + elseif type(states) == "table" then + for c, _ in next, states do + if find(category,c) then + state = true + break + end + end + end + logger = { + reporters = { }, + state = state, + } + data[category] = logger + end + local reporter = logger.reporters[subcategory or "default"] + if not reporter then + if subcategory then + reporter = function(...) + if not logger.state then + subreport(category,subcategory,...) + end + end + logger.reporters[subcategory] = reporter + else + local tag = category + reporter = function(...) + if not logger.state then + report(category,...) + end + end + logger.reporters.default = reporter + end end + return reporter end -function texlog.line(fmt,...) -- new - if fmt then - write_nl(format(fmt,...)) +logs.new = logs.reporter + +local function doset(category,value) + if category == true then + -- lock all + category, value = "*", true + elseif category == false then + -- unlock all + category, value = "*", false + elseif value == nil then + -- lock selective + value = true + end + if category == "*" then + states = value + for k, v in next, data do + v.state = value + end else - write_nl("") + states = utilities.parsers.settings_to_hash(category) + for c, _ in next, states do + if data[c] then + v.state = value + else + c = escapedpattern(c,true) + for k, v in next, data do + if find(k,c) then + v.state = value + end + end + end + end + end +end + +function logs.disable(category,value) + doset(category,value == nil and true or value) +end + +function logs.enable(category) + doset(category,false) +end + +function logs.categories() + return table.sortedkeys(data) +end + +function logs.show() + local n, c, s, max = 0, 0, 0, 0 + for category, v in table.sortedpairs(data) do + n = n + 1 + local state = v.state + local reporters = v.reporters + local nc = #category + if nc > c then + c = nc + end + for subcategory, _ in next, reporters do + local ns = #subcategory + if ns > c then + s = ns + end + local m = nc + ns + if m > max then + max = m + end + end + local subcategories = concat(table.sortedkeys(reporters),", ") + if state == true then + state = "disabled" + elseif state == false then + state = "enabled" + else + state = "unknown" + end + -- no new here + report("logging","category: '%s', subcategories: '%s', state: '%s'",category,subcategories,state) end + report("logging","categories: %s, max category: %s, max subcategory: %s, max combined: %s",n,c,s,max) end +directives.register("logs.blocked", function(v) + doset(v,true) +end) +-- tex specific loggers (might move elsewhere) +local report_pages = logs.reporter("pages") -- not needed but saves checking when we grep for it local real, user, sub -function texlog.start_page_number() +function logs.start_page_number() real, user, sub = texcount.realpageno, texcount.userpageno, texcount.subpageno end -local report_pages = logs.new("pages") -- not needed but saves checking when we grep for it - -function texlog.stop_page_number() +function logs.stop_page_number() if real > 0 then if user > 0 then if sub > 0 then @@ -5104,176 +5241,98 @@ function texlog.stop_page_number() io.flush() end -texlog.report_job_stat = statistics and statistics.showjobstat +logs.report_job_stat = statistics and statistics.showjobstat --- xml logging +local report_files = logs.reporter("files") -local xmllog = { } logs.xml = xmllog setmetatable(xmllog, { __index = noplog }) +local nesting = 0 +local verbose = false -function xmllog.report(category,fmt,s,...) -- new - if s then - write_nl(format("<r category='%s'>%s</r>",category,format(fmt,s,...))) - elseif fmt then - write_nl(format("<r category='%s'>%s</r>",category,fmt)) - else - write_nl(format("<r category='%s'/>",category)) +function logs.show_open(name) + if verbose then + nesting = nesting + 1 + report_files("level %s, opening %s",nesting,name) end end -function xmllog.status(category,fmt,s,...) - if s then - write_nl(format("<s category='%s'>%s</r>",category,format(fmt,s,...))) - elseif fmt then - write_nl(format("<s category='%s'>%s</r>",category,fmt)) - else - write_nl(format("<s category='%s'/>",category)) +function logs.show_close(name) + if verbose then + report_files("level %s, closing %s",nesting,name) + nesting = nesting - 1 end end -function xmllog.line(fmt,...) -- new - if fmt then - write_nl(format("<r>%s</r>",format(fmt,...))) - else - write_nl("<r/>") +function logs.show_load(name) + if verbose then + report_files("level %s, loading %s",nesting+1,name) end end -function xmllog.start() write_nl("<%s>" ) end -function xmllog.stop () write_nl("</%s>") end -function xmllog.push () write_nl("<!-- ") end -function xmllog.pop () write_nl(" -->" ) end - -function xmllog.start_run() - write_nl("<?xml version='1.0' standalone='yes'?>") - write_nl("<job>") -- xmlns='www.pragma-ade.com/luatex/schemas/context-job.rng' - write_nl("") -end - -function xmllog.stop_run() - write_nl("</job>") -end - -function xmllog.start_page_number() - write_nl(format("<p real='%s' page='%s' sub='%s'", texcount.realpageno, texcount.userpageno, texcount.subpageno)) -end - -function xmllog.stop_page_number() - write("/>") - write_nl("") -end +-- there may be scripts out there using this: -function xmllog.report_output_pages(p,b) - write_nl(format("<v k='pages' v='%s'/>", p)) - write_nl(format("<v k='bytes' v='%s'/>", b)) - write_nl("") -end - -function xmllog.report_output_log() - -- nothing -end +local simple = logs.reporter("comment") -function xmllog.report_tex_stat(k,v) - write_nl("log","<v k='"..k.."'>"..tostring(v).."</v>") -end - -local nesting = 0 - -function xmllog.show_open(name) - nesting = nesting + 1 - write_nl(format("<f l='%s' n='%s'>",nesting,name)) -end +logs.simple = simple +logs.simpleline = simple -function xmllog.show_close(name) - write("</f> ") - nesting = nesting - 1 -end - -function xmllog.show_load(name) - write_nl(format("<f l='%s' n='%s'/>",nesting+1,name)) -end - --- initialization - -if tex and (tex.jobname or tex.formatname) then - -- todo: this can be set in mtxrun ... or maybe we should just forget about this alternative format - if (os.getenv("mtx.directives.logmethod") or os.getenv("mtx_directives_logmethod")) == "xml" then - logs.setmethod('xml') - else - logs.setmethod('tex') - end -else - logs.setmethod('nop') -end +-- obsolete --- logging in runners -> these are actually the nop loggers +function logs.setprogram () end -- obsolete +function logs.extendbanner() end -- obsolete +function logs.reportlines () end -- obsolete +function logs.reportbanner() end -- obsolete +function logs.reportline () end -- obsolete +function logs.simplelines () end -- obsolete +function logs.help () end -- obsolete -local name, banner = 'report', 'context' +-- applications -function noplog.report(category,fmt,...) -- todo: fmt,s - if fmt then - write_nl(format("%s | %s: %s",name,category,format(fmt,...))) - elseif category then - write_nl(format("%s | %s",name,category)) - else - write_nl(format("%s |",name)) +local function reportlines(t,str) + if str then + for line in gmatch(str,"(.-)[\n\r]") do + t.report(line) + end end end -noplog.status = noplog.report -- just to be sure, never used - -function noplog.simple(fmt,...) -- todo: fmt,s - if fmt then - write_nl(format("%s | %s",name,format(fmt,...))) - else - write_nl(format("%s |",name)) +local function reportbanner(t) + local banner = t.banner + if banner then + t.report(banner) + t.report() end end -if utilities then - utilities.report = function(...) logs.simple(...) end -end - -function logs.setprogram(newname,newbanner) - name, banner = newname, newbanner -end - -function logs.extendbanner(newbanner) - banner = banner .. " | ".. newbanner -end - -function logs.reportlines(str) -- todo: <lines></lines> - for line in gmatch(str,"(.-)[\n\r]") do - logs.report(line) +local function reporthelp(t,...) + local helpinfo = t.helpinfo + if type(helpinfo) == "string" then + reportlines(t,helpinfo) + elseif type(helpinfo) == "table" then + local tags = { ... } + for i=1,#tags do + reportlines(t,t.helpinfo[tags[i]]) + if i < #tags then + t.report() + end + end end end -function logs.reportline() -- for scripts too - logs.report() -end - -function logs.simpleline() - logs.report() +local function reportinfo(t) + t.report() + reportlines(t,moreinfo) end -function logs.simplelines(str) -- todo: <lines></lines> - for line in gmatch(str,"(.-)[\n\r]") do - logs.simple(line) - end +function logs.application(t) + t.name = t.name or "unknown" + t.banner = t.banner + t.report = logs.reporter(t.name) + t.help = function(...) reportbanner(t) ; reporthelp(t,...) ; reportinfo(t) end + t.identify = function() reportbanner(t) end + return t end -function logs.reportbanner() -- for scripts too - logs.report(banner) -end - -function logs.help(message,option) - logs.reportbanner() - logs.reportline() - logs.reportlines(message) - if option ~= "nomoreinfo" then - logs.reportline() - logs.reportlines(moreinfo) - end -end +-- somewhat special -- logging to a file @@ -5281,7 +5340,7 @@ end function logs.system(whereto,process,jobname,category,...) local message = format("%s %s => %s => %s => %s\r",os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)) for i=1,10 do - local f = io.open(whereto,"a") + local f = io.open(whereto,"a") -- we can consider keepint the file open if f then f:write(message) f:close() @@ -5292,30 +5351,24 @@ function logs.system(whereto,process,jobname,category,...) end end --- bonus - -function logs.fatal(where,...) - logs.report(where,"fatal error: %s, aborting now",format(...)) - os.exit() -end - +local report_system = logs.reporter("system","logs") function logs.obsolete(old,new) local o = loadstring("return " .. new)() if type(o) == "function" then return function(...) - logs.report("system","function %s is obsolete, use %s",old,new) + report_system("function %s is obsolete, use %s",old,new) loadstring(old .. "=" .. new .. " return ".. old)()(...) end elseif type(o) == "table" then local t, m = { }, { } m.__index = function(t,k) - logs.report("system","table %s is obsolete, use %s",old,new) + report_system("table %s is obsolete, use %s",old,new) m.__index, m.__newindex = o, o return o[k] end m.__newindex = function(t,k,v) - logs.report("system","table %s is obsolete, use %s",old,new) + report_system("table %s is obsolete, use %s",old,new) m.__index, m.__newindex = o, o o[k] = v end @@ -5327,6 +5380,10 @@ function logs.obsolete(old,new) end end +if utilities then + utilities.report = report_system +end + if tex and tex.error then function logs.texerrormessage(...) -- for the moment we put this function here tex.error(format(...), { }) @@ -5361,7 +5418,7 @@ local getmetatable, setmetatable, rawset, type = getmetatable, setmetatable, raw local trace_namespaces = false trackers.register("system.namespaces", function(v) trace_namespaces = v end) -local report_system = logs.new("system") +local report_system = logs.new("system","protection") namespaces = namespaces or { } local namespaces = namespaces @@ -5530,7 +5587,7 @@ if not modules then modules = { } end modules ['luat-env'] = { local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_lua = logs.new("resolvers","lua") local allocate, mark = utilities.storage.allocate, utilities.storage.mark @@ -5754,14 +5811,14 @@ function environment.luafilechunk(filename,silent) -- used for loading lua bytec if fullname and fullname ~= "" then local data = environment.loadedluacode(fullname) if trace_locating then - report_resolvers("loading file %s%s", fullname, not data and " failed" or "") + report_lua("loading file %s%s", fullname, not data and " failed" or "") elseif not silent then texio.write("<",data and "+ " or "- ",fullname,">") end return data else if trace_locating then - report_resolvers("unknown file %s", filename) + report_lua("unknown file %s", filename) end return nil end @@ -5781,7 +5838,7 @@ function environment.loadluafile(filename, version) local fullname = (lucname and environment.luafile(lucname)) or "" if fullname ~= "" then if trace_locating then - report_resolvers("loading %s", fullname) + report_lua("loading %s", fullname) end chunk = loadfile(fullname) -- this way we don't need a file exists check end @@ -5799,7 +5856,7 @@ function environment.loadluafile(filename, version) return true else if trace_locating then - report_resolvers("version mismatch for %s: lua=%s, luc=%s", filename, v, version) + report_lua("version mismatch for %s: lua=%s, luc=%s", filename, v, version) end environment.loadluafile(filename) end @@ -5810,12 +5867,12 @@ function environment.loadluafile(filename, version) fullname = (luaname and environment.luafile(luaname)) or "" if fullname ~= "" then if trace_locating then - report_resolvers("loading %s", fullname) + report_lua("loading %s", fullname) end chunk = loadfile(fullname) -- this way we don't need a file exists check if not chunk then if trace_locating then - report_resolvers("unknown file %s", filename) + report_lua("unknown file %s", filename) end else assert(chunk)() @@ -5844,7 +5901,7 @@ if not modules then modules = { } end modules ['lxml-tab'] = { local trace_entities = false trackers.register("xml.entities", function(v) trace_entities = v end) -local report_xml = logs.new("xml") +local report_xml = logs and logs.new("xml","core") or function(...) print(format(...)) end --[[ldx-- <p>The parser used here is inspired by the variant discussed in the lua book, but @@ -6518,7 +6575,7 @@ function xml.is_valid(root) return root and not root.error end -xml.errorhandler = (logs and logs.report) or (input and logs.report) or print +xml.errorhandler = report --[[ldx-- <p>We cannot load an <l n='lpeg'/> from a filehandle so we need to load @@ -7069,7 +7126,7 @@ local trace_lpath = false if trackers then trackers.register("xml.path", local trace_lparse = false if trackers then trackers.register("xml.parse", function(v) trace_lparse = v end) end local trace_lprofile = false if trackers then trackers.register("xml.profile", function(v) trace_lpath = v trace_lparse = v trace_lprofile = v end) end -local report_lpath = logs.new("lpath") +local report_lpath = logs.new("xml","lpath") --[[ldx-- <p>We've now arrived at an interesting part: accessing the tree using a subset @@ -7951,9 +8008,9 @@ local function traced_apply(list,parsed,nofparsed,order) if trace_lparse then lshow(parsed) end - report_lpath("collecting : %s",parsed.pattern) - report_lpath(" root tags : %s",tagstostring(list)) - report_lpath(" order : %s",order or "unset") + report_lpath("collecting: %s",parsed.pattern) + report_lpath("root tags : %s",tagstostring(list)) + report_lpath("order : %s",order or "unset") local collected = list for i=1,nofparsed do local pi = parsed[i] @@ -9224,7 +9281,7 @@ local trace_locating = false trackers.register("resolvers.locating", functi local trace_detail = false trackers.register("resolvers.details", function(v) trace_detail = v end) local trace_expansions = false trackers.register("resolvers.expansions", function(v) trace_expansions = v end) -local report_resolvers = logs.new("resolvers") +local report_initialization = logs.new("resolvers","initialization") local ostype, osname, ossetenv, osgetenv = os.type, os.name, os.setenv, os.getenv @@ -9245,7 +9302,7 @@ kpse = { original = kpse } setmetatable(kpse, { __index = function(kp,name) - report_resolvers("fatal error: kpse library is accessed (key: %s)",name) + report_initialization("fatal error: kpse library is accessed (key: %s)",name) os.exit() end } ) @@ -9329,13 +9386,13 @@ do if lfs.chdir(p) then local pp = lfs.currentdir() if trace_locating and p ~= pp then - report_resolvers("following symlink '%s' to '%s'",p,pp) + report_initialization("following symlink '%s' to '%s'",p,pp) end ownpath = pp lfs.chdir(olddir) else if trace_locating then - report_resolvers("unable to check path '%s'",p) + report_initialization("unable to check path '%s'",p) end ownpath = p end @@ -9346,9 +9403,9 @@ do end if not ownpath or ownpath == "" then ownpath = "." - report_resolvers("forcing fallback ownpath .") + report_initialization("forcing fallback ownpath .") elseif trace_locating then - report_resolvers("using ownpath '%s'",ownpath) + report_initialization("using ownpath '%s'",ownpath) end end @@ -9375,7 +9432,7 @@ do ossetenv('SELFAUTODIR', file.collapsepath(ownpath .. "/..")) ossetenv('SELFAUTOPARENT', file.collapsepath(ownpath .. "/../..")) else - report_resolvers("error: unable to locate ownpath") + report_initialization("error: unable to locate ownpath") os.exit() end @@ -9461,7 +9518,7 @@ local collapsepath = file.collapsepath local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) local trace_expansions = false trackers.register("resolvers.expansions", function(v) trace_expansions = v end) -local report_resolvers = logs.new("resolvers") +local report_expansions = logs.new("resolvers","expansions") local resolvers = resolvers @@ -9524,7 +9581,7 @@ local replacer_1 = lpeg.replacer { { ",}", ",@}" }, { "{,", "{@," }, } local function splitpathexpr(str, newlist, validate) -- I couldn't resist lpegging it (nice exercise). if trace_expansions then - report_resolvers("expanding variable '%s'",str) + report_expansions("expanding variable '%s'",str) end local t, ok, done = newlist or { }, false, false local n = #t @@ -9550,7 +9607,7 @@ local function splitpathexpr(str, newlist, validate) -- I couldn't resist lpeggi end if trace_expansions then for k=1,#t do - report_resolvers("% 4i: %s",k,t[k]) + report_expansions("% 4i: %s",k,t[k]) end end return t @@ -9585,7 +9642,7 @@ function resolvers.cleanpath(str) homedir = lpegmatch(cleanup,environment.homedir or "") if homedir == string.char(127) or homedir == "" or not lfs.isdir(homedir) then if trace_expansions then - report_resolvers("no home dir set, ignoring dependent paths") + report_expansions("no home dir set, ignoring dependent paths") end function resolvers.cleanpath(str) if find(str,"~") then @@ -9655,9 +9712,9 @@ local function splitconfigurationpath(str) -- beware, this can be either a path end end if trace_expansions then - report_resolvers("splitting path specification '%s'",str) + report_expansions("splitting path specification '%s'",str) for k=1,noffound do - report_resolvers("% 4i: %s",k,found[k]) + report_expansions("% 4i: %s",k,found[k]) end end cache[str] = found @@ -9742,7 +9799,7 @@ end function resolvers.scanfiles(path,branch) if trace_locating then - report_resolvers("scanning path '%s', branch '%s'",path, branch or path) + report_expansions("scanning path '%s', branch '%s'",path, branch or path) end local realpath = resolvers.resolve(path) -- no shortcut local files, n, m, r = scan({ },realpath .. '/',"",0,0,0) @@ -9751,7 +9808,7 @@ function resolvers.scanfiles(path,branch) files.__directories__ = m files.__remappings__ = r if trace_locating then - report_resolvers("%s files found on %s directories with %s uppercase remappings",n,m,r) + report_expansions("%s files found on %s directories with %s uppercase remappings",n,m,r) end return files end @@ -10080,8 +10137,8 @@ local mkdirs, isdir = dir.mkdirs, lfs.isdir local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end) -local report_cache = logs.new("cache") -local report_resolvers = logs.new("resolvers") +local report_caches = logs.new("resolvers","caches") +local report_resolvers = logs.new("resolvers","caching") local resolvers = resolvers @@ -10141,7 +10198,7 @@ local function identify() if not caches.ask or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then mkdirs(cachepath) if isdir(cachepath) and file.is_writable(cachepath) then - report_cache("created: %s",cachepath) + report_caches("created: %s",cachepath) writable = cachepath readables[#readables+1] = cachepath end @@ -10175,10 +10232,10 @@ local function identify() -- Some extra checking. If we have no writable or readable path then we simply -- quit. if not writable then - report_cache("fatal error: there is no valid writable cache path defined") + report_caches("fatal error: there is no valid writable cache path defined") os.exit() elseif #readables == 0 then - report_cache("fatal error: there is no valid readable cache path defined") + report_caches("fatal error: there is no valid readable cache path defined") os.exit() end -- why here @@ -10200,9 +10257,9 @@ local function identify() -- end if trace_cache then for i=1,#readables do - report_cache("using readable path '%s' (order %s)",readables[i],i) + report_caches("using readable path '%s' (order %s)",readables[i],i) end - report_cache("using writable path '%s'",writable) + report_caches("using writable path '%s'",writable) end identify = function() return writable, readables @@ -10237,7 +10294,7 @@ function caches.hashed(tree) tree = lower(tree) local hash = md5.hex(tree) if trace_cache or trace_locating then - report_cache("hashing tree %s, hash %s",tree,hash) + report_caches("hashing tree %s, hash %s",tree,hash) end return hash end @@ -10463,7 +10520,7 @@ trackers.register("resolvers.locating", function(v) trace_methods = v end) trackers.register("resolvers.methods", function(v) trace_methods = v end) -local report_resolvers = logs.new("resolvers") +local report_methods = logs.new("resolvers","methods") local allocate = utilities.storage.allocate @@ -10505,41 +10562,41 @@ local function methodhandler(what,first,...) -- filename can be nil or false local resolver = namespace and namespace[scheme] if resolver then if trace_methods then - report_resolvers("resolver: method=%s, how=%s, scheme=%s, argument=%s",what,how,scheme,first) + report_methods("resolver: method=%s, how=%s, scheme=%s, argument=%s",what,how,scheme,first) end return resolver(specification,...) else resolver = namespace.default or namespace.file if resolver then if trace_methods then - report_resolvers("resolver: method=%s, how=%s, default, argument=%s",what,how,first) + report_methods("resolver: method=%s, how=%s, default, argument=%s",what,how,first) end return resolver(specification,...) elseif trace_methods then - report_resolvers("resolver: method=%s, how=%s, no handler",what,how) + report_methods("resolver: method=%s, how=%s, no handler",what,how) end end elseif how == "tag" then local resolver = namespace and namespace[first] if resolver then if trace_methods then - report_resolvers("resolver: method=%s, how=%s, tag=%s",what,how,first) + report_methods("resolver: method=%s, how=%s, tag=%s",what,how,first) end return resolver(...) else resolver = namespace.default or namespace.file if resolver then if trace_methods then - report_resolvers("resolver: method=%s, how=%s, default",what,how) + report_methods("resolver: method=%s, how=%s, default",what,how) end return resolver(...) elseif trace_methods then - report_resolvers("resolver: method=%s, how=%s, unknown",what,how) + report_methods("resolver: method=%s, how=%s, unknown",what,how) end end end else - report_resolvers("resolver: method=%s, unknown",what) + report_methods("resolver: method=%s, unknown",what) end end @@ -10610,7 +10667,7 @@ local trace_locating = false trackers.register("resolvers.locating", functi local trace_detail = false trackers.register("resolvers.details", function(v) trace_detail = v end) local trace_expansions = false trackers.register("resolvers.expansions", function(v) trace_expansions = v end) -local report_resolvers = logs.new("resolvers") +local report_resolving = logs.new("resolvers","resolving") local resolvers = resolvers @@ -10712,7 +10769,7 @@ end function resolvers.newinstance() -- todo: all vars will become lowercase and alphanum only if trace_locating then - report_resolvers("creating instance") + report_resolving("creating instance") end local environment, variables, expansions, order = allocate(), allocate(), allocate(), allocate() @@ -10830,9 +10887,9 @@ local function reportcriticalvariables() for i=1,#resolvers.criticalvars do local k = resolvers.criticalvars[i] local v = resolvers.getenv(k) or "unknown" -- this one will not resolve ! - report_resolvers("variable '%s' set to '%s'",k,v) + report_resolving("variable '%s' set to '%s'",k,v) end - report_resolvers() + report_resolving() end reportcriticalvariables = function() end end @@ -10856,17 +10913,17 @@ local function identify_configuration_files() if lfs.isfile(realname) then specification[#specification+1] = filename if trace_locating then - report_resolvers("found configuration file '%s'",realname) + report_resolving("found configuration file '%s'",realname) end elseif trace_locating then - report_resolvers("unknown configuration file '%s'",realname) + report_resolving("unknown configuration file '%s'",realname) end end if trace_locating then - report_resolvers() + report_resolving() end elseif trace_locating then - report_resolvers("configuration files already identified") + report_resolving("configuration files already identified") end end @@ -10886,8 +10943,8 @@ local function load_configuration_files() data = data and data.content if data then if trace_locating then - report_resolvers("loading configuration file '%s'",filename) - report_resolvers() + report_resolving("loading configuration file '%s'",filename) + report_resolving() end local variables = data.variables or { } local warning = false @@ -10897,7 +10954,7 @@ local function load_configuration_files() initializesetter(filename,k,v) elseif variables[k] == nil then if trace_locating and not warning then - report_resolvers("variables like '%s' in configuration file '%s' should move to the 'variables' subtable", + report_resolving("variables like '%s' in configuration file '%s' should move to the 'variables' subtable", k,resolvers.resolve(filename)) warning = true end @@ -10910,7 +10967,7 @@ local function load_configuration_files() local cnfspec = variables["TEXMFCNF"] if cnfspec then if trace_locating then - report_resolvers("reloading configuration due to TEXMF redefinition") + report_resolving("reloading configuration due to TEXMF redefinition") end -- we push the value into the main environment (osenv) so -- that it takes precedence over the default one and therefore @@ -10929,13 +10986,13 @@ local function load_configuration_files() else if trace_locating then - report_resolvers("skipping configuration file '%s' (no content)",filename) + report_resolving("skipping configuration file '%s' (no content)",filename) end setups[pathname] = { } instance.loaderror = true end elseif trace_locating then - report_resolvers("skipping configuration file '%s' (no file)",filename) + report_resolving("skipping configuration file '%s' (no file)",filename) end instance.order[#instance.order+1] = instance.setups[pathname] if instance.loaderror then @@ -10943,7 +11000,7 @@ local function load_configuration_files() end end elseif trace_locating then - report_resolvers("warning: no lua configuration files found") + report_resolving("warning: no lua configuration files found") end end @@ -10979,19 +11036,19 @@ local function locate_file_databases() end if trace_locating then if runtime then - report_resolvers("locating list of '%s' (runtime)",path) + report_resolving("locating list of '%s' (runtime)",path) else - report_resolvers("locating list of '%s' (cached)",path) + report_resolving("locating list of '%s' (cached)",path) end end methodhandler('locators',stripped) end end if trace_locating then - report_resolvers() + report_resolving() end elseif trace_locating then - report_resolvers("no texmf paths are defined (using TEXMF)") + report_resolving("no texmf paths are defined (using TEXMF)") end end @@ -11002,7 +11059,7 @@ local function generate_file_databases() methodhandler('generators',hash.name) end if trace_locating then - report_resolvers() + report_resolving() end end @@ -11014,11 +11071,11 @@ local function save_file_databases() -- will become cachers local content = instance.files[cachename] caches.collapsecontent(content) if trace_locating then - report_resolvers("saving tree '%s'",cachename) + report_resolving("saving tree '%s'",cachename) end caches.savecontent(cachename,"files",content) elseif trace_locating then - report_resolvers("not saving runtime tree '%s'",cachename) + report_resolving("not saving runtime tree '%s'",cachename) end end end @@ -11043,7 +11100,7 @@ function resolvers.appendhash(type,name,cache) -- safeguard ... tricky as it's actually a bug when seen twice if not instance.hashed[name] then if trace_locating then - report_resolvers("hash '%s' appended",name) + report_resolving("hash '%s' appended",name) end insert(instance.hashes, { type = type, name = name, cache = cache } ) instance.hashed[name] = cache @@ -11054,7 +11111,7 @@ function resolvers.prependhash(type,name,cache) -- safeguard ... tricky as it's actually a bug when seen twice if not instance.hashed[name] then if trace_locating then - report_resolvers("hash '%s' prepended",name) + report_resolving("hash '%s' prepended",name) end insert(instance.hashes, 1, { type = type, name = name, cache = cache } ) instance.hashed[name] = cache @@ -11287,9 +11344,9 @@ function isreadable(name) local readable = lfs.isfile(name) -- not file.is_readable(name) asit can be a dir if trace_detail then if readable then - report_resolvers("file '%s' is readable",name) + report_resolving("file '%s' is readable",name) else - report_resolvers("file '%s' is not readable", name) + report_resolving("file '%s' is not readable", name) end end return readable @@ -11303,7 +11360,7 @@ local function collect_files(names) for k=1,#names do local fname = names[k] if trace_detail then - report_resolvers("checking name '%s'",fname) + report_resolving("checking name '%s'",fname) end local bname = filebasename(fname) local dname = filedirname(fname) @@ -11319,7 +11376,7 @@ local function collect_files(names) local files = blobpath and instance.files[blobpath] if files then if trace_detail then - report_resolvers("deep checking '%s' (%s)",blobpath,bname) + report_resolving("deep checking '%s' (%s)",blobpath,bname) end local blobfile = files[bname] if not blobfile then @@ -11339,7 +11396,7 @@ local function collect_files(names) local search = filejoin(blobroot,blobfile,bname) local result = methodhandler('concatinators',hash.type,blobroot,blobfile,bname) if trace_detail then - report_resolvers("match: kind '%s', search '%s', result '%s'",kind,search,result) + report_resolving("match: kind '%s', search '%s', result '%s'",kind,search,result) end noffiles = noffiles + 1 filelist[noffiles] = { kind, search, result } @@ -11353,7 +11410,7 @@ local function collect_files(names) local search = filejoin(blobroot,vv,bname) local result = methodhandler('concatinators',hash.type,blobroot,vv,bname) if trace_detail then - report_resolvers("match: kind '%s', search '%s', result '%s'",kind,search,result) + report_resolving("match: kind '%s', search '%s', result '%s'",kind,search,result) end noffiles = noffiles + 1 filelist[noffiles] = { kind, search, result } @@ -11362,7 +11419,7 @@ local function collect_files(names) end end elseif trace_locating then - report_resolvers("no match in '%s' (%s)",blobpath,bname) + report_resolving("no match in '%s' (%s)",blobpath,bname) end end end @@ -11403,7 +11460,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : stamp = filename .. "--" .. askedformat if instance.found[stamp] then if trace_locating then - report_resolvers("remembered file '%s'",filename) + report_resolving("remembered file '%s'",filename) end resolvers.registerintrees(filename) -- for tracing used files return instance.found[stamp] @@ -11412,7 +11469,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : if not dangerous[askedformat] then if isreadable(filename) then if trace_detail then - report_resolvers("file '%s' found directly",filename) + report_resolving("file '%s' found directly",filename) end if stamp then instance.found[stamp] = { filename } @@ -11422,13 +11479,13 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : end if find(filename,'%*') then if trace_locating then - report_resolvers("checking wildcard '%s'", filename) + report_resolving("checking wildcard '%s'", filename) end result = resolvers.findwildcardfiles(filename) -- we can use th elocal elseif file.is_qualified_path(filename) then if isreadable(filename) then if trace_locating then - report_resolvers("qualified name '%s'", filename) + report_resolving("qualified name '%s'", filename) end result = { filename } else @@ -11441,7 +11498,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : forcedname = filename .. "." .. s if isreadable(forcedname) then if trace_locating then - report_resolvers("no suffix, forcing format filetype '%s'", s) + report_resolving("no suffix, forcing format filetype '%s'", s) end result, ok = { forcedname }, true break @@ -11494,7 +11551,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : -- end end if not ok and trace_locating then - report_resolvers("qualified name '%s'", filename) + report_resolving("qualified name '%s'", filename) end end else @@ -11513,13 +11570,13 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : wantedfiles[#wantedfiles+1] = forcedname filetype = resolvers.formatofsuffix(forcedname) if trace_locating then - report_resolvers("forcing filetype '%s'",filetype) + report_resolving("forcing filetype '%s'",filetype) end end else filetype = resolvers.formatofsuffix(filename) if trace_locating then - report_resolvers("using suffix based filetype '%s'",filetype) + report_resolving("using suffix based filetype '%s'",filetype) end end else @@ -11533,7 +11590,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : end filetype = askedformat if trace_locating then - report_resolvers("using given filetype '%s'",filetype) + report_resolving("using given filetype '%s'",filetype) end end local typespec = resolvers.variableofformat(filetype) @@ -11541,7 +11598,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : if not pathlist or #pathlist == 0 then -- no pathlist, access check only / todo == wildcard if trace_detail then - report_resolvers("checking filename '%s', filetype '%s', wanted files '%s'",filename, filetype or '?',concat(wantedfiles," | ")) + report_resolving("checking filename '%s', filetype '%s', wanted files '%s'",filename, filetype or '?',concat(wantedfiles," | ")) end for k=1,#wantedfiles do local fname = wantedfiles[k] @@ -11569,7 +11626,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : end end if trace_detail then - report_resolvers("checking filename '%s'",filename) + report_resolving("checking filename '%s'",filename) end for k=1,#pathlist do local path = pathlist[k] @@ -11581,7 +11638,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : -- compare list entries with permitted pattern -- /xx /xx// local expression = makepathexpression(pathname) if trace_detail then - report_resolvers("using pattern '%s' for path '%s'",expression,pathname) + report_resolving("using pattern '%s' for path '%s'",expression,pathname) end for k=1,#filelist do local fl = filelist[k] @@ -11593,16 +11650,16 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : done = true if allresults then if trace_detail then - report_resolvers("match to '%s' in hash for file '%s' and path '%s', continue scanning",expression,f,d) + report_resolving("match to '%s' in hash for file '%s' and path '%s', continue scanning",expression,f,d) end else if trace_detail then - report_resolvers("match to '%s' in hash for file '%s' and path '%s', quit scanning",expression,f,d) + report_resolving("match to '%s' in hash for file '%s' and path '%s', quit scanning",expression,f,d) end break end elseif trace_detail then - report_resolvers("no match to '%s' in hash for file '%s' and path '%s'",expression,f,d) + report_resolving("no match to '%s' in hash for file '%s' and path '%s'",expression,f,d) end end end @@ -11619,7 +11676,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : local fname = filejoin(ppname,w) if isreadable(fname) then if trace_detail then - report_resolvers("found '%s' by scanning",fname) + report_resolving("found '%s' by scanning",fname) end result[#result+1] = fname done = true @@ -11824,7 +11881,7 @@ end local function report(str) if trace_locating then - report_resolvers(str) -- has already verbose + report_resolving(str) -- has already verbose else print(str) end @@ -12219,7 +12276,7 @@ if not modules then modules = { } end modules ['data-fil'] = { local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_files = logs.new("resolvers","files") local resolvers = resolvers @@ -12233,11 +12290,11 @@ function locators.file(specification) local realname = resolvers.resolve(name) -- no shortcut if realname and realname ~= '' and lfs.isdir(realname) then if trace_locating then - report_resolvers("file locator '%s' found as '%s'",name,realname) + report_files("file locator '%s' found as '%s'",name,realname) end resolvers.appendhash('file',name,true) -- cache elseif trace_locating then - report_resolvers("file locator '%s' not found",name) + report_files("file locator '%s' not found",name) end end @@ -12260,12 +12317,12 @@ function finders.file(specification,filetype) local foundname = resolvers.findfile(filename,filetype) if foundname and foundname ~= "" then if trace_locating then - report_resolvers("file finder: '%s' found",filename) + report_files("file finder: '%s' found",filename) end return foundname else if trace_locating then - report_resolvers("file finder: %s' not found",filename) + report_files("file finder: %s' not found",filename) end return finders.notfound() end @@ -12286,13 +12343,13 @@ function openers.file(specification,filetype) local f = io.open(filename,"r") if f then if trace_locating then - report_resolvers("file opener, '%s' opened",filename) + report_files("file opener, '%s' opened",filename) end return openers.helpers.textopener("file",filename,f) end end if trace_locating then - report_resolvers("file opener, '%s' not found",filename) + report_files("file opener, '%s' not found",filename) end return openers.notfound() end @@ -12304,7 +12361,7 @@ function loaders.file(specification,filetype) if f then logs.show_load(filename) if trace_locating then - report_resolvers("file loader, '%s' loaded",filename) + report_files("file loader, '%s' loaded",filename) end local s = f:read("*a") if checkgarbage then @@ -12317,7 +12374,7 @@ function loaders.file(specification,filetype) end end if trace_locating then - report_resolvers("file loader, '%s' not found",filename) + report_files("file loader, '%s' not found",filename) end return loaders.notfound() end @@ -12358,11 +12415,11 @@ containers = containers or { } local containers = containers containers.usecache = true -local report_cache = logs.new("cache") +local report_containers = logs.new("resolvers","containers") local function report(container,tag,name) if trace_cache or trace_containers then - report_cache("container: %s, tag: %s, name: %s",container.subcategory,tag,name or 'invalid') + report_containers("container: %s, tag: %s, name: %s",container.subcategory,tag,name or 'invalid') end end @@ -12480,7 +12537,7 @@ local format, lower, gsub, find = string.format, string.lower, string.gsub, stri local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_mounts = logs.new("resolvers","mounts") local resolvers = resolvers @@ -12505,7 +12562,7 @@ function resolvers.automount(usecache) -- skip elseif find(line,"^zip://") then if trace_locating then - report_resolvers("mounting %s",line) + report_mounts("mounting %s",line) end table.insert(resolvers.automounted,line) resolvers.usezipfile(line) @@ -12585,7 +12642,7 @@ local format, find, match = string.format, string.find, string.match local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_zip = logs.new("resolvers","zip") -- zip:///oeps.zip?name=bla/bla.tex -- zip:///oeps.zip?tree=tex/texmf-local @@ -12638,9 +12695,9 @@ function resolvers.locators.zip(specification) local zipfile = archive and archive ~= "" and zip.openarchive(archive) -- tricky, could be in to be initialized tree if trace_locating then if zipfile then - report_resolvers("zip locator, archive '%s' found",archive) + report_zip("locator, archive '%s' found",archive) else - report_resolvers("zip locator, archive '%s' not found",archive) + report_zip("locator, archive '%s' not found",archive) end end end @@ -12648,7 +12705,7 @@ end function resolvers.hashers.zip(specification) local archive = specification.filename if trace_locating then - report_resolvers("loading zip file '%s'",archive) + report_zip("loading file '%s'",archive) end resolvers.usezipfile(specification.original) end @@ -12671,25 +12728,25 @@ function resolvers.finders.zip(specification) local zfile = zip.openarchive(archive) if zfile then if trace_locating then - report_resolvers("zip finder, archive '%s' found",archive) + report_zip("finder, archive '%s' found",archive) end local dfile = zfile:open(queryname) if dfile then dfile = zfile:close() if trace_locating then - report_resolvers("zip finder, file '%s' found",queryname) + report_zip("finder, file '%s' found",queryname) end return specification.original elseif trace_locating then - report_resolvers("zip finder, file '%s' not found",queryname) + report_zip("finder, file '%s' not found",queryname) end elseif trace_locating then - report_resolvers("zip finder, unknown archive '%s'",archive) + report_zip("finder, unknown archive '%s'",archive) end end end if trace_locating then - report_resolvers("zip finder, '%s' not found",original) + report_zip("finder, '%s' not found",original) end return resolvers.finders.notfound() end @@ -12704,24 +12761,24 @@ function resolvers.openers.zip(specification) local zfile = zip.openarchive(archive) if zfile then if trace_locating then - report_resolvers("zip opener, archive '%s' opened",archive) + report_zip("opener, archive '%s' opened",archive) end local dfile = zfile:open(queryname) if dfile then if trace_locating then - report_resolvers("zip opener, file '%s' found",queryname) + report_zip("opener, file '%s' found",queryname) end return resolvers.openers.helpers.textopener('zip',original,dfile) elseif trace_locating then - report_resolvers("zip opener, file '%s' not found",queryname) + report_zip("opener, file '%s' not found",queryname) end elseif trace_locating then - report_resolvers("zip opener, unknown archive '%s'",archive) + report_zip("opener, unknown archive '%s'",archive) end end end if trace_locating then - report_resolvers("zip opener, '%s' not found",original) + report_zip("opener, '%s' not found",original) end return resolvers.openers.notfound() end @@ -12736,27 +12793,27 @@ function resolvers.loaders.zip(specification) local zfile = zip.openarchive(archive) if zfile then if trace_locating then - report_resolvers("zip loader, archive '%s' opened",archive) + report_zip("loader, archive '%s' opened",archive) end local dfile = zfile:open(queryname) if dfile then logs.show_load(original) if trace_locating then - report_resolvers("zip loader, file '%s' loaded",original) + report_zip("loader, file '%s' loaded",original) end local s = dfile:read("*all") dfile:close() return true, s, #s elseif trace_locating then - report_resolvers("zip loader, file '%s' not found",queryname) + report_zip("loader, file '%s' not found",queryname) end elseif trace_locating then - report_resolvers("zip loader, unknown archive '%s'",archive) + report_zip("loader, unknown archive '%s'",archive) end end end if trace_locating then - report_resolvers("zip loader, '%s' not found",original) + report_zip("loader, '%s' not found",original) end return resolvers.openers.notfound() end @@ -12772,7 +12829,7 @@ function resolvers.usezipfile(archive) if z then local tree = url.query(specification.query).tree or "" if trace_locating then - report_resolvers("zip registering, registering archive '%s'",archive) + report_zip("registering, registering archive '%s'",archive) end statistics.starttiming(resolvers.instance) resolvers.prependhash('zip',archive) @@ -12781,10 +12838,10 @@ function resolvers.usezipfile(archive) instance.files[archive] = resolvers.registerzipfile(z,tree) statistics.stoptiming(resolvers.instance) elseif trace_locating then - report_resolvers("zip registering, unknown archive '%s'",archive) + report_zip("registering, unknown archive '%s'",archive) end elseif trace_locating then - report_resolvers("zip registering, '%s' not found",archive) + report_zip("registering, '%s' not found",archive) end end @@ -12796,7 +12853,7 @@ function resolvers.registerzipfile(z,tree) filter = format("^%s/(.+)/(.-)$",tree) end if trace_locating then - report_resolvers("zip registering, using filter '%s'",filter) + report_zip("registering, using filter '%s'",filter) end local register, n = resolvers.registerfile, 0 for i in z:files() do @@ -12813,7 +12870,7 @@ function resolvers.registerzipfile(z,tree) n = n + 1 end end - report_resolvers("zip registering, %s files registered",n) + report_zip("registering, %s files registered",n) return files end @@ -12836,7 +12893,7 @@ local find, gsub, format = string.find, string.gsub, string.format local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_trees = logs.new("resolvers","trees") local resolvers = resolvers @@ -12874,18 +12931,18 @@ function resolvers.locators.tree(specification) local name = specification.filename if name ~= '' and lfs.isdir(name) then if trace_locating then - report_resolvers("tree locator '%s' found",name) + report_trees("locator '%s' found",name) end resolvers.appendhash('tree',name,false) -- don't cache elseif trace_locating then - report_resolvers("tree locator '%s' not found",name) + report_trees("locator '%s' not found",name) end end function resolvers.hashers.tree(specification) local name = specification.filename if trace_locating then - report_resolvers("analysing tree '%s'",name) + report_trees("analysing '%s'",name) end resolvers.methodhandler("hashers",name) end @@ -12981,7 +13038,7 @@ if not modules then modules = { } end modules ['data-lua'] = { local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_libraries = logs.new("resolvers","libraries") local gsub, insert = string.gsub, table.insert local unpack = unpack or table.unpack @@ -13013,7 +13070,7 @@ local function thepath(...) local t = { ... } t[#t+1] = "?.lua" local path = file.join(unpack(t)) if trace_locating then - report_resolvers("! appending '%s' to 'package.path'",path) + report_libraries("! appending '%s' to 'package.path'",path) end return path end @@ -13035,11 +13092,11 @@ local function loaded(libpaths,name,simple) local libpath = libpaths[i] local resolved = gsub(libpath,"%?",simple) if trace_locating then -- more detail - report_resolvers("! checking for '%s' on 'package.path': '%s' => '%s'",simple,libpath,resolved) + report_libraries("! checking for '%s' on 'package.path': '%s' => '%s'",simple,libpath,resolved) end if file.is_readable(resolved) then if trace_locating then - report_resolvers("! lib '%s' located via 'package.path': '%s'",name,resolved) + report_libraries("! lib '%s' located via 'package.path': '%s'",name,resolved) end return loadfile(resolved) end @@ -13048,17 +13105,17 @@ end package.loaders[2] = function(name) -- was [#package.loaders+1] if trace_locating then -- mode detail - report_resolvers("! locating '%s'",name) + report_libraries("! locating '%s'",name) end for i=1,#libformats do local format = libformats[i] local resolved = resolvers.findfile(name,format) or "" if trace_locating then -- mode detail - report_resolvers("! checking for '%s' using 'libformat path': '%s'",name,format) + report_libraries("! checking for '%s' using 'libformat path': '%s'",name,format) end if resolved ~= "" then if trace_locating then - report_resolvers("! lib '%s' located via environment: '%s'",name,resolved) + report_libraries("! lib '%s' located via environment: '%s'",name,resolved) end return loadfile(resolved) end @@ -13081,11 +13138,11 @@ package.loaders[2] = function(name) -- was [#package.loaders+1] local path = paths[p] local resolved = file.join(path,libname) if trace_locating then -- mode detail - report_resolvers("! checking for '%s' using 'clibformat path': '%s'",libname,path) + report_libraries("! checking for '%s' using 'clibformat path': '%s'",libname,path) end if file.is_readable(resolved) then if trace_locating then - report_resolvers("! lib '%s' located via 'clibformat': '%s'",libname,resolved) + report_libraries("! lib '%s' located via 'clibformat': '%s'",libname,resolved) end return package.loadlib(resolved,name) end @@ -13095,28 +13152,28 @@ package.loaders[2] = function(name) -- was [#package.loaders+1] local libpath = clibpaths[i] local resolved = gsub(libpath,"?",simple) if trace_locating then -- more detail - report_resolvers("! checking for '%s' on 'package.cpath': '%s'",simple,libpath) + report_libraries("! checking for '%s' on 'package.cpath': '%s'",simple,libpath) end if file.is_readable(resolved) then if trace_locating then - report_resolvers("! lib '%s' located via 'package.cpath': '%s'",name,resolved) + report_libraries("! lib '%s' located via 'package.cpath': '%s'",name,resolved) end return package.loadlib(resolved,name) end end -- just in case the distribution is messed up if trace_loading then -- more detail - report_resolvers("! checking for '%s' using 'luatexlibs': '%s'",name) + report_libraries("! checking for '%s' using 'luatexlibs': '%s'",name) end local resolved = resolvers.findfile(file.basename(name),'luatexlibs') or "" if resolved ~= "" then if trace_locating then - report_resolvers("! lib '%s' located by basename via environment: '%s'",name,resolved) + report_libraries("! lib '%s' located by basename via environment: '%s'",name,resolved) end return loadfile(resolved) end if trace_locating then - report_resolvers('? unable to locate lib: %s',name) + report_libraries('? unable to locate lib: %s',name) end -- return "unable to locate " .. name end @@ -13153,48 +13210,48 @@ local trace_locating = false trackers.register("resolvers.locating", function(v local resolvers = resolvers -local report_resolvers = logs.new("resolvers") +local report_scripts = logs.new("resolvers","scripts") function resolvers.updatescript(oldname,newname) -- oldname -> own.name, not per se a suffix local scriptpath = "scripts/context/lua" newname = file.addsuffix(newname,"lua") local oldscript = resolvers.cleanpath(oldname) if trace_locating then - report_resolvers("to be replaced old script %s", oldscript) + report_scripts("to be replaced old script %s", oldscript) end local newscripts = resolvers.findfiles(newname) or { } if #newscripts == 0 then if trace_locating then - report_resolvers("unable to locate new script") + report_scripts("unable to locate new script") end else for i=1,#newscripts do local newscript = resolvers.cleanpath(newscripts[i]) if trace_locating then - report_resolvers("checking new script %s", newscript) + report_scripts("checking new script %s", newscript) end if oldscript == newscript then if trace_locating then - report_resolvers("old and new script are the same") + report_scripts("old and new script are the same") end elseif not find(newscript,scriptpath) then if trace_locating then - report_resolvers("new script should come from %s",scriptpath) + report_scripts("new script should come from %s",scriptpath) end elseif not (find(oldscript,file.removesuffix(newname).."$") or find(oldscript,newname.."$")) then if trace_locating then - report_resolvers("invalid new script name") + report_scripts("invalid new script name") end else local newdata = io.loaddata(newscript) if newdata then if trace_locating then - report_resolvers("old script content replaced by new content") + report_scripts("old script content replaced by new content") end io.savedata(oldscript,newdata) break elseif trace_locating then - report_resolvers("unable to load new script") + report_scripts("unable to load new script") end end end @@ -13216,6 +13273,8 @@ if not modules then modules = { } end modules ['data-tmf'] = { local resolvers = resolvers +local report_tds = logs.new("resolvers","tds") + -- = << -- ? ?? -- < += @@ -13236,11 +13295,11 @@ function resolvers.load_tree(tree,resolve) local newpath = file.join(newtree,"bin") if not lfs.isdir(newtree) then - logs.simple("no '%s' under tree %s",texos,tree) + report_tds("no '%s' under tree %s",texos,tree) os.exit() end if not lfs.isdir(newpath) then - logs.simple("no '%s/bin' under tree %s",texos,tree) + report_tds("no '%s/bin' under tree %s",texos,tree) os.exit() end @@ -13264,9 +13323,9 @@ function resolvers.load_tree(tree,resolve) setenv('TEXMFCNF', resolvers.luacnfspec, not resolve) setenv("PATH", newpath .. io.pathseparator .. getenv("PATH")) - logs.simple("changing from root '%s' to '%s'",oldroot,newroot) - logs.simple("prepending '%s' to binary path",newpath) - logs.simple() + report_tds("changing from root '%s' to '%s'",oldroot,newroot) + report_tds("prepending '%s' to binary path",newpath) + report_tds() end end @@ -13291,6 +13350,8 @@ resolvers.listers = resolvers.listers or { } local resolvers = resolvers +local report_lists = logs.new("resolvers","lists") + local function tabstr(str) if type(str) == 'table' then return concat(str," | ") @@ -13319,11 +13380,11 @@ function resolvers.listers.variables(pattern) local exp = table.fastcopy(expansions) for key, value in table.sortedpairs(configured) do if key ~= "" and (pattern == "" or find(upper(key),pattern)) then - logs.simple(key) - logs.simple(" env: %s",tabstr(rawget(environment,key)) or "unset") - logs.simple(" var: %s",tabstr(configured[key]) or "unset") - logs.simple(" exp: %s",tabstr(expansions[key]) or "unset") - logs.simple(" res: %s",resolvers.resolve(expansions[key]) or "unset") + report_lists(key) + report_lists(" env: %s",tabstr(rawget(environment,key)) or "unset") + report_lists(" var: %s",tabstr(configured[key]) or "unset") + report_lists(" exp: %s",tabstr(expansions[key]) or "unset") + report_lists(" res: %s",resolvers.resolve(expansions[key]) or "unset") end end instance.environment = table.fastcopy(env) @@ -13477,6 +13538,8 @@ if not modules then modules = { } end modules ['luat-fmt'] = { local format = string.format +local report_format = logs.new("resolvers","formats") + -- helper for mtxrun local quoted = string.quoted @@ -13501,7 +13564,7 @@ function environment.make_format(name) if path ~= "" then lfs.chdir(path) end - logs.simple("format path: %s",lfs.currentdir()) + report_format("format path: %s",lfs.currentdir()) -- check source file local texsourcename = file.addsuffix(name,"mkiv") local fulltexsourcename = resolvers.findfile(texsourcename,"tex") or "" @@ -13510,11 +13573,11 @@ function environment.make_format(name) fulltexsourcename = resolvers.findfile(texsourcename,"tex") or "" end if fulltexsourcename == "" then - logs.simple("no tex source file with name: %s (mkiv or tex)",name) + report_format("no tex source file with name: %s (mkiv or tex)",name) lfs.chdir(olddir) return else - logs.simple("using tex source file: %s",fulltexsourcename) + report_format("using tex source file: %s",fulltexsourcename) end local texsourcepath = dir.expandname(file.dirname(fulltexsourcename)) -- really needed -- check specification @@ -13525,7 +13588,7 @@ function environment.make_format(name) fullspecificationname = resolvers.findfile(specificationname,"tex") or "" end if fullspecificationname == "" then - logs.simple("unknown stub specification: %s",specificationname) + report_format("unknown stub specification: %s",specificationname) lfs.chdir(olddir) return end @@ -13536,39 +13599,39 @@ function environment.make_format(name) if type(usedlualibs) == "string" then usedluastub = file.join(file.dirname(fullspecificationname),usedlualibs) elseif type(usedlualibs) == "table" then - logs.simple("using stub specification: %s",fullspecificationname) + report_format("using stub specification: %s",fullspecificationname) local texbasename = file.basename(name) local luastubname = file.addsuffix(texbasename,"lua") local lucstubname = file.addsuffix(texbasename,"luc") -- pack libraries in stub - logs.simple("creating initialization file: %s",luastubname) + report_format("creating initialization file: %s",luastubname) utilities.merger.selfcreate(usedlualibs,specificationpath,luastubname) -- compile stub file (does not save that much as we don't use this stub at startup any more) local strip = resolvers.booleanvariable("LUACSTRIP", true) if utilities.lua.compile(luastubname,lucstubname) and lfs.isfile(lucstubname) then - logs.simple("using compiled initialization file: %s",lucstubname) + report_format("using compiled initialization file: %s",lucstubname) usedluastub = lucstubname else - logs.simple("using uncompiled initialization file: %s",luastubname) + report_format("using uncompiled initialization file: %s",luastubname) usedluastub = luastubname end else - logs.simple("invalid stub specification: %s",fullspecificationname) + report_format("invalid stub specification: %s",fullspecificationname) lfs.chdir(olddir) return end -- generate format local command = format("luatex --ini %s --lua=%s %s %sdump",primaryflags(),quoted(usedluastub),quoted(fulltexsourcename),os.platform == "unix" and "\\\\" or "\\") - logs.simple("running command: %s\n",command) + report_format("running command: %s\n",command) os.spawn(command) -- remove related mem files local pattern = file.removesuffix(file.basename(usedluastub)).."-*.mem" - -- logs.simple("removing related mplib format with pattern '%s'", pattern) + -- report_format("removing related mplib format with pattern '%s'", pattern) local mp = dir.glob(pattern) if mp then for i=1,#mp do local name = mp[i] - logs.simple("removing related mplib format %s", file.basename(name)) + report_format("removing related mplib format %s", file.basename(name)) os.remove(name) end end @@ -13585,7 +13648,7 @@ function environment.run_format(name,data,more) end fmtname = resolvers.cleanpath(fmtname) if fmtname == "" then - logs.simple("no format with name: %s",name) + report_format("no format with name: %s",name) else local barename = file.removesuffix(name) -- expanded name local luaname = file.addsuffix(barename,"luc") @@ -13593,11 +13656,11 @@ function environment.run_format(name,data,more) luaname = file.addsuffix(barename,"lua") end if not lfs.isfile(luaname) then - logs.simple("using format name: %s",fmtname) - logs.simple("no luc/lua with name: %s",barename) + report_format("using format name: %s",fmtname) + report_format("no luc/lua with name: %s",barename) else local command = format("luatex %s --fmt=%s --lua=%s %s %s",primaryflags(),quoted(barename),quoted(luaname),quoted(data),more ~= "" and quoted(more) or "") - logs.simple("running command: %s",command) + report_format("running command: %s",command) os.spawn(command) end end @@ -13750,8 +13813,6 @@ if not resolvers then os.exit() end -logs.setprogram('MTXrun',"TDS Runner Tool 1.30") - if environment.arguments["verbose"] then trackers.enable("resolvers.locating") end @@ -13764,10 +13825,7 @@ if trackspec then trackers.enable(trackspec) end -runners = runners or { } -- global -messages = messages or { } - -messages.help = [[ +local helpinfo = [[ --script run an mtx script (lua prefered method) (--noquotes), no script gives list --execute run a script or program (texmfstart method) (--noquotes) --resolve resolve prefixed arguments @@ -13819,6 +13877,19 @@ messages.help = [[ --pattern=str filter variables ]] +local application = logs.application { + name = "mtxrun", + banner = "ConTeXt TDS Runner Tool 1.30", + helpinfo = helpinfo, +} + +local report = application.report + +local verbose = environment.argument("verbose") + +messages = messages or { } -- for the mo + +runners = runners or { } -- global runners.applications = { ["lua"] = "luatex --luaonly", @@ -13872,17 +13943,16 @@ end function runners.prepare() local checkname = environment.argument("ifchanged") - local verbose = environment.argument("verbose") if type(checkname) == "string" and checkname ~= "" then local oldchecksum = file.loadchecksum(checkname) local newchecksum = file.checksum(checkname) if oldchecksum == newchecksum then if verbose then - logs.simple("file '%s' is unchanged",checkname) + report("file '%s' is unchanged",checkname) end return "skip" elseif verbose then - logs.simple("file '%s' is changed, processing started",checkname) + report("file '%s' is changed, processing started",checkname) end file.savechecksum(checkname) end @@ -13892,17 +13962,17 @@ function runners.prepare() if oldname and newname and oldname ~= "" and newname ~= "" then if not file.needs_updating(oldname,newname) then if verbose then - logs.simple("file '%s' and '%s' have same age",oldname,newname) + report("file '%s' and '%s' have same age",oldname,newname) end return "skip" elseif verbose then - logs.simple("file '%s' is older than '%s'",oldname,newname) + report("file '%s' is older than '%s'",oldname,newname) end end end local runpath = environment.argument("path") if type(runpath) == "string" and not lfs.chdir(runpath) then - logs.simple("unable to change to path '%s'",runpath) + report("unable to change to path '%s'",runpath) return "error" end runners.prepare = function() end @@ -13961,11 +14031,11 @@ function runners.execute_script(fullname,internal,nosplit) result = binary .. " " .. result end local command = result .. " " .. environment.reconstructcommandline(environment.arguments_after,noquote) - if logs.verbose then - logs.simpleline() - logs.simple("executing: %s",command) - logs.simpleline() - logs.simpleline() + if verbose then + report() + report("executing: %s",command) + report() + report() io.flush() end -- no os.exec because otherwise we get the wrong return value @@ -13980,9 +14050,9 @@ function runners.execute_script(fullname,internal,nosplit) return false end end - logs.simpleline() - logs.simple("This script needs '%s' which seems not to be installed.",binary) - logs.simpleline() + report() + report("This script needs '%s' which seems not to be installed.",binary) + report() end return false end @@ -14007,10 +14077,10 @@ function runners.execute_program(fullname) environment.initializearguments(after) fullname = fullname:gsub("^bin:","") local command = fullname .. " " .. (environment.reconstructcommandline(after or "",noquote) or "") - logs.simpleline() - logs.simple("executing: %s",command) - logs.simpleline() - logs.simpleline() + report() + report("executing: %s",command) + report() + report() io.flush() local code = os.exec(command) -- (fullname,unpack(after)) does not work / maybe spawn return code == 0 @@ -14042,18 +14112,18 @@ function runners.handle_stubs(create) if create then if windows then io.savedata(file.join(stubpath,base..".bat"),string.format(windows_stub,name)) - logs.simple("windows stub for '%s' created",base) + report("windows stub for '%s' created",base) end if unix then io.savedata(file.join(stubpath,base),string.format(unix_stub,name)) - logs.simple("unix stub for '%s' created",base) + report("unix stub for '%s' created",base) end else if windows and (os.remove(file.join(stubpath,base..'.bat')) or os.remove(file.join(stubpath,base..'.cmd'))) then - logs.simple("windows stub for '%s' removed", base) + report("windows stub for '%s' removed", base) end if unix and (os.remove(file.join(stubpath,base)) or os.remove(file.join(stubpath,base..'.sh'))) then - logs.simple("unix stub for '%s' removed",base) + report("unix stub for '%s' removed",base) end end end @@ -14078,12 +14148,12 @@ function runners.locate_platform() end function runners.report_location(result) - if logs.verbose then - logs.simpleline() + if verbose then + reportline() if result and result ~= "" then - logs.simple(result) + report(result) else - logs.simple("not found") + report("not found") end else io.write(result) @@ -14095,11 +14165,11 @@ function runners.edit_script(filename) -- we assume that gvim is present on most local rest = resolvers.resolve(filename) if rest ~= "" then local command = editor .. " " .. rest - if logs.verbose then - logs.simpleline() - logs.simple("starting editor: %s",command) - logs.simple_line() - logs.simple_line() + if verbose then + report() + report("starting editor: %s",command) + report() + report() end os.launch(command) end @@ -14148,7 +14218,7 @@ function runners.launch_file(filename) pattern = filename end if not pattern or pattern == "" then - logs.simple("provide name or --pattern=") + report("provide name or --pattern=") else local t = resolvers.findfiles(pattern) if not t or #t == 0 then @@ -14160,15 +14230,15 @@ function runners.launch_file(filename) if t and #t > 0 then if environment.arguments["all"] then for _, v in pairs(t) do - logs.simple("launching %s", v) + report("launching %s", v) resolvers.launch(v) end else - logs.simple("launching %s", t[1]) + report("launching %s", t[1]) resolvers.launch(t[1]) end else - logs.simple("no match for %s", pattern) + report("no match for %s", pattern) end end end @@ -14239,7 +14309,7 @@ function runners.execute_ctx_script(filename,...) local fullname = runners.find_mtx_script(filename) or "" if file.extname(fullname) == "cld" then -- handy in editors where we force --autopdf - logs.simple("running cld script: %s",filename) + report("running cld script: %s",filename) table.insert(arguments,1,fullname) table.insert(arguments,"--autopdf") fullname = runners.find_mtx_script("context") or "" @@ -14270,8 +14340,8 @@ function runners.execute_ctx_script(filename,...) runners.load_script_session(loadname) end filename = environment.files[1] - if logs.verbose then - logs.simple("using script: %s\n",fullname) + if verbose then + report("using script: %s\n",fullname) end environment.ownscript = fullname dofile(fullname) @@ -14306,24 +14376,23 @@ function runners.execute_ctx_script(filename,...) end end if #valid > 0 then - logs.reportbanner() - logs.reportline() - logs.simple("no script name given, known scripts:") - logs.simple() + application.identify() + report("no script name given, known scripts:") + report() for k=1,#valid do local v = valid[k] - logs.simple("%-12s %4s %s",v[1],v[2],v[3]) + report("%-12s %4s %s",v[1],v[2],v[3]) end end else - logs.simple("no script name given") + report("no script name given") end else filename = file.addsuffix(filename,"lua") if file.is_qualified_path(filename) then - logs.simple("unknown script '%s'",filename) + report("unknown script '%s'",filename) else - logs.simple("unknown script '%s' or 'mtx-%s'",filename,filename) + report("unknown script '%s' or 'mtx-%s'",filename,filename) end end return false @@ -14331,9 +14400,9 @@ function runners.execute_ctx_script(filename,...) end function runners.prefixes() - logs.reportbanner() - logs.reportline() - logs.simple(table.concat(resolvers.allprefixes(true)," ")) + application.identify() + report() + report(table.concat(resolvers.allprefixes(true)," ")) end function runners.timedrun(filename) -- just for me @@ -14385,7 +14454,7 @@ if environment.argument("usekpse") or environment.argument("forcekpse") or is_mk local t = os.clock() local k = kpse.original.new("luatex",progname) local dummy = k:find_file("mtxrun.lua") -- so that we're initialized - logs.simple("kpse fallback with progname '%s' initialized in %s seconds",progname,os.clock()-t) + report("kpse fallback with progname '%s' initialized in %s seconds",progname,os.clock()-t) kpse_initialized = function() return k end return k end @@ -14432,11 +14501,11 @@ else function runners.loadbase(...) if not resolvers.load(...) then - logs.simple("forcing cache reload") + report("forcing cache reload") instance.renewcache = true trackers.enable("resolvers.locating") if not resolvers.load(...) then - logs.simple("the resolver databases are not present or outdated") + report("the resolver databases are not present or outdated") end end end @@ -14595,8 +14664,8 @@ elseif environment.argument("find-path") then resolvers.load() local path = resolvers.findpath(filename, instance.my_format) - if logs.verbose then - logs.simple(path) + if verbose then + report(path) else print(path) end @@ -14651,7 +14720,7 @@ elseif environment.argument("format-path") then -- luatools: runners.execute_ctx_script("mtx-base","--format-path",filename) resolvers.load() - logs.simple(caches.getwritablepath("format")) + report(caches.getwritablepath("format")) elseif environment.argument("pattern") then @@ -14695,7 +14764,7 @@ elseif environment.argument("help") and filename=='base' then elseif environment.argument("help") or filename=='help' or filename == "" then - logs.help(messages.help) + application.help() elseif filename:find("^bin:") then @@ -14729,9 +14798,9 @@ else end -if logs.verbose then - logs.simpleline() - logs.simple("runtime: %0.3f seconds",os.runtime()) +if verbose then + report() + report("runtime: %0.3f seconds",os.runtime()) end if os.type ~= "windows" then diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 31d7d9b0f..afc472d1c 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -8,7 +8,6 @@ if not modules then modules = { } end modules ['mtxrun'] = { license = "see context related readme files" } - -- one can make a stub: -- -- #!/bin/sh @@ -132,11 +131,7 @@ local simple_escapes = { } function string.escapedpattern(str,simple) - if simple then - return (gsub(str,".",simple_escapes)) - else - return (gsub(str,".",patterns_escapes)) - end + return (gsub(str,".",simple and simple_escapes or patterns_escapes)) end function string.topattern(str,lowercase,strict) @@ -556,11 +551,7 @@ local p = Cs((S("-.+*%()[]") / patterns_escapes + anything)^0) local s = Cs((S("-.+*%()[]") / simple_escapes + anything)^0) function string.escapedpattern(str,simple) - if simple then - return match(s,str) - else - return match(p,str) - end + return match(simple and s or p,str) end -- utf extensies @@ -3826,7 +3817,7 @@ local type, next = type, next utilities = utilities or {} utilities.merger = utilities.merger or { } -- maybe mergers -utilities.report = utilities.report or print +utilities.report = logs and logs.new("system") or print local merger = utilities.merger @@ -3964,7 +3955,7 @@ if not modules then modules = { } end modules ['util-lua'] = { utilities = utilities or {} utilities.lua = utilities.lua or { } -utilities.report = utilities.report or print +utilities.report = logs and logs.new("system") or print function utilities.lua.compile(luafile,lucfile,cleanup,strip) -- defaults: cleanup=false strip=true utilities.report("lua: compiling %s into %s",luafile,lucfile) @@ -4577,19 +4568,21 @@ function statistics.show(reporter) end end - -local template, nn = nil, 0 -- we only calcute it once +local template, report_statistics, nn = nil, nil, 0 -- we only calcute it once function statistics.showjobstat(tag,data,n) - if type(data) == "table" then + if not logs then + -- sorry + elseif type(data) == "table" then for i=1,#data do statistics.showjobstat(tag,data[i],n) end else if not template or n > nn then - template, n = format("%%-%ss: %%-%ss - %%s",15,n), nn + template, n = format("%%-%ss - %%s",n), nn + report_statistics = logs.new("mkiv lua stats") end - write_nl(format(template,"mkiv lua stats",tag,data)) + report_statistics(format(template,tag,data)) end end @@ -4610,7 +4603,7 @@ function statistics.runtime() end function statistics.timed(action,report) - report = report or logs.simple + report = report or logs.new("system") starttiming("run") action() stoptiming("run") @@ -4664,14 +4657,10 @@ local data = { } -- maybe just local local trace_initialize = false -- only for testing during development -local function report(a,b,...) - texio.write_nl(format("%-16s> %s",a,format(b,...))) -end - function setters.initialize(filename,name,values) -- filename only for diagnostics - local data = data[name] - if data then - data = data.data + local setter = data[name] + if setter then + local data = data.data if data then for key, value in next, values do -- key = gsub(key,"_",".") @@ -4680,7 +4669,7 @@ function setters.initialize(filename,name,values) -- filename only for diagnosti if functions then if #functions > 0 and not functions.value then if trace_initialize then - report(name,"executing %s (%s -> %s)",key,filename,tostring(value)) + setter.report("executing %s (%s -> %s)",key,filename,tostring(value)) end for i=1,#functions do functions[i](value) @@ -4688,7 +4677,7 @@ function setters.initialize(filename,name,values) -- filename only for diagnosti functions.value = value else if trace_initialize then - report(name,"skipping %s (%s -> %s)",key,filename,tostring(value)) + setter.report("skipping %s (%s -> %s)",key,filename,tostring(value)) end end else @@ -4697,7 +4686,7 @@ function setters.initialize(filename,name,values) -- filename only for diagnosti functions = { default = value } data[key] = functions if trace_initialize then - report(name,"storing %s (%s -> %s)",key,filename,tostring(value)) + setter.report("storing %s (%s -> %s)",key,filename,tostring(value)) end end end @@ -4724,10 +4713,11 @@ local function set(t,what,newvalue) else value = is_boolean(value,value) end + w = escapedpattern(w,true) for name, functions in next, data do if done[name] then -- prevent recursion due to wildcards - elseif find(name,escapedpattern(w,true)) then + elseif find(name,w) then done[name] = true for i=1,#functions do functions[i](value) @@ -4769,7 +4759,7 @@ function setters.register(t,what,...) functions = { } data[what] = functions if trace_initialize then - report(t.name,"defining %s",what) + t.report("defining %s",what) end end local default = functions.default -- can be set from cnf file @@ -4777,7 +4767,7 @@ function setters.register(t,what,...) local typ = type(fnc) if typ == "string" then if trace_initialize then - report(t.name,"coupling %s to %s",what,fnc) + t.report("coupling %s to %s",what,fnc) end local s = fnc -- else wrong reference fnc = function(value) set(t,s,value) end @@ -4831,9 +4821,9 @@ function setters.list(t) -- pattern end function setters.show(t) - commands.writestatus("","") - local list = setters.list(t) local category = t.name + local list = setters.list(t) + t.report() for k=1,#list do local name = list[k] local functions = t.data[name] @@ -4841,10 +4831,10 @@ function setters.show(t) local value, default, modules = functions.value, functions.default, #functions value = value == nil and "unset" or tostring(value) default = default == nil and "unset" or tostring(default) - commands.writestatus(category,format("%-30s modules: %2i default: %5s value: %5s",name,modules,default,value)) + t.report("%-30s modules: %2i default: %6s value: %6s",name,modules,default,value) end end - commands.writestatus("","") + t.report() end -- we could have used a bit of oo and the trackers:enable syntax but @@ -4854,57 +4844,62 @@ end local enable, disable, register, list, show = setters.enable, setters.disable, setters.register, setters.list, setters.show +local function report(setter,...) + local report = logs and logs.report + if report then + report(setter.name,...) + else -- fallback, as this module is loaded before the logger + write_nl(format("%-16s: %s\n",setter.name,format(...))) + end +end + function setters.new(name) - local t -- we need to access it in t - t = { + local setter -- we need to access it in setter itself + setter = { data = allocate(), -- indexed, but also default and value fields name = name, - enable = function(...) enable (t,...) end, - disable = function(...) disable (t,...) end, - register = function(...) register(t,...) end, - list = function(...) list (t,...) end, - show = function(...) show (t,...) end, + report = function(...) report (setter,...) end, + enable = function(...) enable (setter,...) end, + disable = function(...) disable (setter,...) end, + register = function(...) register(setter,...) end, + list = function(...) list (setter,...) end, + show = function(...) show (setter,...) end, } - data[name] = t - return t + data[name] = setter + return setter end trackers = setters.new("trackers") directives = setters.new("directives") experiments = setters.new("experiments") -local t_enable, t_disable = trackers .enable, trackers .disable -local d_enable, d_disable = directives .enable, directives .disable -local e_enable, e_disable = experiments.enable, experiments.disable +local t_enable, t_disable, t_report = trackers .enable, trackers .disable, trackers .report +local d_enable, d_disable, d_report = directives .enable, directives .disable, directives .report +local e_enable, e_disable, e_report = experiments.enable, experiments.disable, experiments.report -- nice trick: we overload two of the directives related functions with variants that -- do tracing (itself using a tracker) .. proof of concept -local function report(...) -- messy .. chicken or egg - local p = (commands and commands.writestatus) or (logs and logs.report) - if p then p(...) end -end - local trace_directives = false local trace_directives = false trackers.register("system.directives", function(v) trace_directives = v end) local trace_experiments = false local trace_experiments = false trackers.register("system.experiments", function(v) trace_experiments = v end) function directives.enable(...) - report("directives","enabling: %s",concat({...}," ")) + d_report("enabling: %s",concat({...}," ")) d_enable(...) end function directives.disable(...) - report("directives","disabling: %s",concat({...}," ")) + d_report("disabling: %s",concat({...}," ")) d_disable(...) end function experiments.enable(...) - report("experiments","enabling: %s",concat({...}," ")) + e_report("enabling: %s",concat({...}," ")) e_enable(...) end function experiments.disable(...) - report("experiments","disabling: %s",concat({...}," ")) + e_report("disabling: %s",concat({...}," ")) e_disable(...) end @@ -4967,20 +4962,19 @@ if not modules then modules = { } end modules ['trac-log'] = { license = "see context related readme files" } --- xml logging is only usefull in normal runs, not in ini mode --- it looks like some tex logging (like filenames) is broken (no longer --- interceoted at the tex end so the xml variant is not that useable now) +-- todo: less categories, more subcategories (e.g. nodes) local write_nl, write = texio and texio.write_nl or print, texio and texio.write or io.write -local format, gmatch = string.format, string.gmatch +local format, gmatch, find = string.format, string.gmatch, string.find +local concat = table.concat +local escapedpattern = string.escapedpattern local texcount = tex and tex.count +local next, type = next, type --[[ldx-- -<p>This is a prelude to a more extensive logging module. For the sake -of parsing log files, in addition to the standard logging we will -provide an <l n='xml'/> structured file. Actually, any logging that -is hooked into callbacks will be \XML\ by default.</p> +<p>This is a prelude to a more extensive logging module. We no longer +provide <l n='xml'/> based logging a sparsing is relatively easy anyway.</p> --ldx]]-- logs = logs or { } @@ -4998,96 +4992,239 @@ webpage : http://www.pragma-ade.nl / http://tex.aanhet.net wiki : http://contextgarden.net ]] -local functions = { - 'report', 'status', 'start', 'stop', 'push', 'pop', 'line', 'direct', - 'start_run', 'stop_run', - 'start_page_number', 'stop_page_number', - 'report_output_pages', 'report_output_log', - 'report_tex_stat', 'report_job_stat', - 'show_open', 'show_close', 'show_load', - 'dummy', -} +-- local functions = { +-- 'report', 'status', 'start', 'stop', 'line', 'direct', +-- 'start_run', 'stop_run', +-- 'start_page_number', 'stop_page_number', +-- 'report_output_pages', 'report_output_log', +-- 'report_tex_stat', 'report_job_stat', +-- 'show_open', 'show_close', 'show_load', +-- 'dummy', +-- } -local method = "nop" +-- basic loggers -function logs.setmethod(newmethod) - method = newmethod - -- a direct copy might be faster but let's try this for a while - setmetatable(logs, { __index = logs[method] }) -end +local function ignore() end -function logs.getmethod() - return method -end +setmetatable(logs, { __index = function(t,k) t[k] = ignore ; return ignore end }) --- installer +-- local separator = (tex and (tex.jobname or tex.formatname)) and ">" or "|" -local data = { } +local report, subreport -function logs.new(category) - local logger = data[category] - if not logger then - logger = function(...) - logs.report(category,...) +if tex and tex.jobname or tex.formatname then + + report = function(a,b,c,...) + if c then + write_nl(format("%-15s > %s\n",a,format(b,c,...))) + elseif b then + write_nl(format("%-15s > %s\n",a,b)) + elseif a then + write_nl(format("%-15s >\n", a)) + else + write_nl("\n") end - data[category] = logger end - return logger -end + subreport = function(a,sub,b,c,...) + if c then + write_nl(format("%-15s > %s > %s\n",a,sub,format(b,c,...))) + elseif b then + write_nl(format("%-15s > %s > %s\n",a,sub,b)) + elseif a then + write_nl(format("%-15s > %s >\n", a,sub)) + else + write_nl("\n") + end + end --- nop logging (maybe use __call instead) - -local noplog = { } logs.nop = noplog setmetatable(logs, { __index = noplog }) +else -for i=1,#functions do - noplog[functions[i]] = function() end -end + report = function(a,b,c,...) + if c then + write_nl(format("%-15s | %s",a,format(b,c,...))) + elseif b then + write_nl(format("%-15s | %s",a,b)) + elseif a then + write_nl(format("%-15s |", a)) + else + write_nl("") + end + end --- tex logging + subreport = function(a,sub,b,c,...) + if c then + write_nl(format("%-15s | %s | %s",a,sub,format(b,c,...))) + elseif b then + write_nl(format("%-15s | %s | %s",a,sub,b)) + elseif a then + write_nl(format("%-15s | %s |", a,sub)) + else + write_nl("") + end + end -local texlog = { } logs.tex = texlog setmetatable(texlog, { __index = noplog }) +end -function texlog.report(a,b,c,...) +function logs.status(a,b,c,...) -- at the tex end if c then - write_nl(format("%-16s> %s\n",a,format(b,c,...))) + write_nl(format("%-15s : %s\n",a,format(b,c,...))) elseif b then - write_nl(format("%-16s> %s\n",a,b)) + write_nl(format("%-15s : %s\n",a,b)) -- b can have %'s + elseif a then + write_nl(format("%-15s :\n", a)) else - write_nl(format("%-16s>\n",a)) + write_nl("\n") end end -function texlog.status(a,b,c,...) - if c then - write_nl(format("%-16s: %s\n",a,format(b,c,...))) - elseif b then - write_nl(format("%-16s: %s\n",a,b)) -- b can have %'s - else - write_nl(format("%-16s:>\n",a)) +logs.report = report +logs.subreport = subreport + +-- installer + +-- todo: renew (un) locks when a new one is added and wildcard + +local data, states = { }, nil + +function logs.reporter(category,subcategory) + local logger = data[category] + if not logger then + local state = false + if states == true then + state = true + elseif type(states) == "table" then + for c, _ in next, states do + if find(category,c) then + state = true + break + end + end + end + logger = { + reporters = { }, + state = state, + } + data[category] = logger + end + local reporter = logger.reporters[subcategory or "default"] + if not reporter then + if subcategory then + reporter = function(...) + if not logger.state then + subreport(category,subcategory,...) + end + end + logger.reporters[subcategory] = reporter + else + local tag = category + reporter = function(...) + if not logger.state then + report(category,...) + end + end + logger.reporters.default = reporter + end end + return reporter end -function texlog.line(fmt,...) -- new - if fmt then - write_nl(format(fmt,...)) +logs.new = logs.reporter + +local function doset(category,value) + if category == true then + -- lock all + category, value = "*", true + elseif category == false then + -- unlock all + category, value = "*", false + elseif value == nil then + -- lock selective + value = true + end + if category == "*" then + states = value + for k, v in next, data do + v.state = value + end else - write_nl("") + states = utilities.parsers.settings_to_hash(category) + for c, _ in next, states do + if data[c] then + v.state = value + else + c = escapedpattern(c,true) + for k, v in next, data do + if find(k,c) then + v.state = value + end + end + end + end + end +end + +function logs.disable(category,value) + doset(category,value == nil and true or value) +end + +function logs.enable(category) + doset(category,false) +end + +function logs.categories() + return table.sortedkeys(data) +end + +function logs.show() + local n, c, s, max = 0, 0, 0, 0 + for category, v in table.sortedpairs(data) do + n = n + 1 + local state = v.state + local reporters = v.reporters + local nc = #category + if nc > c then + c = nc + end + for subcategory, _ in next, reporters do + local ns = #subcategory + if ns > c then + s = ns + end + local m = nc + ns + if m > max then + max = m + end + end + local subcategories = concat(table.sortedkeys(reporters),", ") + if state == true then + state = "disabled" + elseif state == false then + state = "enabled" + else + state = "unknown" + end + -- no new here + report("logging","category: '%s', subcategories: '%s', state: '%s'",category,subcategories,state) end + report("logging","categories: %s, max category: %s, max subcategory: %s, max combined: %s",n,c,s,max) end +directives.register("logs.blocked", function(v) + doset(v,true) +end) +-- tex specific loggers (might move elsewhere) +local report_pages = logs.reporter("pages") -- not needed but saves checking when we grep for it local real, user, sub -function texlog.start_page_number() +function logs.start_page_number() real, user, sub = texcount.realpageno, texcount.userpageno, texcount.subpageno end -local report_pages = logs.new("pages") -- not needed but saves checking when we grep for it - -function texlog.stop_page_number() +function logs.stop_page_number() if real > 0 then if user > 0 then if sub > 0 then @@ -5104,176 +5241,98 @@ function texlog.stop_page_number() io.flush() end -texlog.report_job_stat = statistics and statistics.showjobstat +logs.report_job_stat = statistics and statistics.showjobstat --- xml logging +local report_files = logs.reporter("files") -local xmllog = { } logs.xml = xmllog setmetatable(xmllog, { __index = noplog }) +local nesting = 0 +local verbose = false -function xmllog.report(category,fmt,s,...) -- new - if s then - write_nl(format("<r category='%s'>%s</r>",category,format(fmt,s,...))) - elseif fmt then - write_nl(format("<r category='%s'>%s</r>",category,fmt)) - else - write_nl(format("<r category='%s'/>",category)) +function logs.show_open(name) + if verbose then + nesting = nesting + 1 + report_files("level %s, opening %s",nesting,name) end end -function xmllog.status(category,fmt,s,...) - if s then - write_nl(format("<s category='%s'>%s</r>",category,format(fmt,s,...))) - elseif fmt then - write_nl(format("<s category='%s'>%s</r>",category,fmt)) - else - write_nl(format("<s category='%s'/>",category)) +function logs.show_close(name) + if verbose then + report_files("level %s, closing %s",nesting,name) + nesting = nesting - 1 end end -function xmllog.line(fmt,...) -- new - if fmt then - write_nl(format("<r>%s</r>",format(fmt,...))) - else - write_nl("<r/>") +function logs.show_load(name) + if verbose then + report_files("level %s, loading %s",nesting+1,name) end end -function xmllog.start() write_nl("<%s>" ) end -function xmllog.stop () write_nl("</%s>") end -function xmllog.push () write_nl("<!-- ") end -function xmllog.pop () write_nl(" -->" ) end - -function xmllog.start_run() - write_nl("<?xml version='1.0' standalone='yes'?>") - write_nl("<job>") -- xmlns='www.pragma-ade.com/luatex/schemas/context-job.rng' - write_nl("") -end - -function xmllog.stop_run() - write_nl("</job>") -end - -function xmllog.start_page_number() - write_nl(format("<p real='%s' page='%s' sub='%s'", texcount.realpageno, texcount.userpageno, texcount.subpageno)) -end - -function xmllog.stop_page_number() - write("/>") - write_nl("") -end +-- there may be scripts out there using this: -function xmllog.report_output_pages(p,b) - write_nl(format("<v k='pages' v='%s'/>", p)) - write_nl(format("<v k='bytes' v='%s'/>", b)) - write_nl("") -end - -function xmllog.report_output_log() - -- nothing -end +local simple = logs.reporter("comment") -function xmllog.report_tex_stat(k,v) - write_nl("log","<v k='"..k.."'>"..tostring(v).."</v>") -end - -local nesting = 0 - -function xmllog.show_open(name) - nesting = nesting + 1 - write_nl(format("<f l='%s' n='%s'>",nesting,name)) -end +logs.simple = simple +logs.simpleline = simple -function xmllog.show_close(name) - write("</f> ") - nesting = nesting - 1 -end - -function xmllog.show_load(name) - write_nl(format("<f l='%s' n='%s'/>",nesting+1,name)) -end - --- initialization - -if tex and (tex.jobname or tex.formatname) then - -- todo: this can be set in mtxrun ... or maybe we should just forget about this alternative format - if (os.getenv("mtx.directives.logmethod") or os.getenv("mtx_directives_logmethod")) == "xml" then - logs.setmethod('xml') - else - logs.setmethod('tex') - end -else - logs.setmethod('nop') -end +-- obsolete --- logging in runners -> these are actually the nop loggers +function logs.setprogram () end -- obsolete +function logs.extendbanner() end -- obsolete +function logs.reportlines () end -- obsolete +function logs.reportbanner() end -- obsolete +function logs.reportline () end -- obsolete +function logs.simplelines () end -- obsolete +function logs.help () end -- obsolete -local name, banner = 'report', 'context' +-- applications -function noplog.report(category,fmt,...) -- todo: fmt,s - if fmt then - write_nl(format("%s | %s: %s",name,category,format(fmt,...))) - elseif category then - write_nl(format("%s | %s",name,category)) - else - write_nl(format("%s |",name)) +local function reportlines(t,str) + if str then + for line in gmatch(str,"(.-)[\n\r]") do + t.report(line) + end end end -noplog.status = noplog.report -- just to be sure, never used - -function noplog.simple(fmt,...) -- todo: fmt,s - if fmt then - write_nl(format("%s | %s",name,format(fmt,...))) - else - write_nl(format("%s |",name)) +local function reportbanner(t) + local banner = t.banner + if banner then + t.report(banner) + t.report() end end -if utilities then - utilities.report = function(...) logs.simple(...) end -end - -function logs.setprogram(newname,newbanner) - name, banner = newname, newbanner -end - -function logs.extendbanner(newbanner) - banner = banner .. " | ".. newbanner -end - -function logs.reportlines(str) -- todo: <lines></lines> - for line in gmatch(str,"(.-)[\n\r]") do - logs.report(line) +local function reporthelp(t,...) + local helpinfo = t.helpinfo + if type(helpinfo) == "string" then + reportlines(t,helpinfo) + elseif type(helpinfo) == "table" then + local tags = { ... } + for i=1,#tags do + reportlines(t,t.helpinfo[tags[i]]) + if i < #tags then + t.report() + end + end end end -function logs.reportline() -- for scripts too - logs.report() -end - -function logs.simpleline() - logs.report() +local function reportinfo(t) + t.report() + reportlines(t,moreinfo) end -function logs.simplelines(str) -- todo: <lines></lines> - for line in gmatch(str,"(.-)[\n\r]") do - logs.simple(line) - end +function logs.application(t) + t.name = t.name or "unknown" + t.banner = t.banner + t.report = logs.reporter(t.name) + t.help = function(...) reportbanner(t) ; reporthelp(t,...) ; reportinfo(t) end + t.identify = function() reportbanner(t) end + return t end -function logs.reportbanner() -- for scripts too - logs.report(banner) -end - -function logs.help(message,option) - logs.reportbanner() - logs.reportline() - logs.reportlines(message) - if option ~= "nomoreinfo" then - logs.reportline() - logs.reportlines(moreinfo) - end -end +-- somewhat special -- logging to a file @@ -5281,7 +5340,7 @@ end function logs.system(whereto,process,jobname,category,...) local message = format("%s %s => %s => %s => %s\r",os.date("%d/%m/%y %H:%m:%S"),process,jobname,category,format(...)) for i=1,10 do - local f = io.open(whereto,"a") + local f = io.open(whereto,"a") -- we can consider keepint the file open if f then f:write(message) f:close() @@ -5292,30 +5351,24 @@ function logs.system(whereto,process,jobname,category,...) end end --- bonus - -function logs.fatal(where,...) - logs.report(where,"fatal error: %s, aborting now",format(...)) - os.exit() -end - +local report_system = logs.reporter("system","logs") function logs.obsolete(old,new) local o = loadstring("return " .. new)() if type(o) == "function" then return function(...) - logs.report("system","function %s is obsolete, use %s",old,new) + report_system("function %s is obsolete, use %s",old,new) loadstring(old .. "=" .. new .. " return ".. old)()(...) end elseif type(o) == "table" then local t, m = { }, { } m.__index = function(t,k) - logs.report("system","table %s is obsolete, use %s",old,new) + report_system("table %s is obsolete, use %s",old,new) m.__index, m.__newindex = o, o return o[k] end m.__newindex = function(t,k,v) - logs.report("system","table %s is obsolete, use %s",old,new) + report_system("table %s is obsolete, use %s",old,new) m.__index, m.__newindex = o, o o[k] = v end @@ -5327,6 +5380,10 @@ function logs.obsolete(old,new) end end +if utilities then + utilities.report = report_system +end + if tex and tex.error then function logs.texerrormessage(...) -- for the moment we put this function here tex.error(format(...), { }) @@ -5361,7 +5418,7 @@ local getmetatable, setmetatable, rawset, type = getmetatable, setmetatable, raw local trace_namespaces = false trackers.register("system.namespaces", function(v) trace_namespaces = v end) -local report_system = logs.new("system") +local report_system = logs.new("system","protection") namespaces = namespaces or { } local namespaces = namespaces @@ -5530,7 +5587,7 @@ if not modules then modules = { } end modules ['luat-env'] = { local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_lua = logs.new("resolvers","lua") local allocate, mark = utilities.storage.allocate, utilities.storage.mark @@ -5754,14 +5811,14 @@ function environment.luafilechunk(filename,silent) -- used for loading lua bytec if fullname and fullname ~= "" then local data = environment.loadedluacode(fullname) if trace_locating then - report_resolvers("loading file %s%s", fullname, not data and " failed" or "") + report_lua("loading file %s%s", fullname, not data and " failed" or "") elseif not silent then texio.write("<",data and "+ " or "- ",fullname,">") end return data else if trace_locating then - report_resolvers("unknown file %s", filename) + report_lua("unknown file %s", filename) end return nil end @@ -5781,7 +5838,7 @@ function environment.loadluafile(filename, version) local fullname = (lucname and environment.luafile(lucname)) or "" if fullname ~= "" then if trace_locating then - report_resolvers("loading %s", fullname) + report_lua("loading %s", fullname) end chunk = loadfile(fullname) -- this way we don't need a file exists check end @@ -5799,7 +5856,7 @@ function environment.loadluafile(filename, version) return true else if trace_locating then - report_resolvers("version mismatch for %s: lua=%s, luc=%s", filename, v, version) + report_lua("version mismatch for %s: lua=%s, luc=%s", filename, v, version) end environment.loadluafile(filename) end @@ -5810,12 +5867,12 @@ function environment.loadluafile(filename, version) fullname = (luaname and environment.luafile(luaname)) or "" if fullname ~= "" then if trace_locating then - report_resolvers("loading %s", fullname) + report_lua("loading %s", fullname) end chunk = loadfile(fullname) -- this way we don't need a file exists check if not chunk then if trace_locating then - report_resolvers("unknown file %s", filename) + report_lua("unknown file %s", filename) end else assert(chunk)() @@ -5844,7 +5901,7 @@ if not modules then modules = { } end modules ['lxml-tab'] = { local trace_entities = false trackers.register("xml.entities", function(v) trace_entities = v end) -local report_xml = logs.new("xml") +local report_xml = logs and logs.new("xml","core") or function(...) print(format(...)) end --[[ldx-- <p>The parser used here is inspired by the variant discussed in the lua book, but @@ -6518,7 +6575,7 @@ function xml.is_valid(root) return root and not root.error end -xml.errorhandler = (logs and logs.report) or (input and logs.report) or print +xml.errorhandler = report --[[ldx-- <p>We cannot load an <l n='lpeg'/> from a filehandle so we need to load @@ -7069,7 +7126,7 @@ local trace_lpath = false if trackers then trackers.register("xml.path", local trace_lparse = false if trackers then trackers.register("xml.parse", function(v) trace_lparse = v end) end local trace_lprofile = false if trackers then trackers.register("xml.profile", function(v) trace_lpath = v trace_lparse = v trace_lprofile = v end) end -local report_lpath = logs.new("lpath") +local report_lpath = logs.new("xml","lpath") --[[ldx-- <p>We've now arrived at an interesting part: accessing the tree using a subset @@ -7951,9 +8008,9 @@ local function traced_apply(list,parsed,nofparsed,order) if trace_lparse then lshow(parsed) end - report_lpath("collecting : %s",parsed.pattern) - report_lpath(" root tags : %s",tagstostring(list)) - report_lpath(" order : %s",order or "unset") + report_lpath("collecting: %s",parsed.pattern) + report_lpath("root tags : %s",tagstostring(list)) + report_lpath("order : %s",order or "unset") local collected = list for i=1,nofparsed do local pi = parsed[i] @@ -9224,7 +9281,7 @@ local trace_locating = false trackers.register("resolvers.locating", functi local trace_detail = false trackers.register("resolvers.details", function(v) trace_detail = v end) local trace_expansions = false trackers.register("resolvers.expansions", function(v) trace_expansions = v end) -local report_resolvers = logs.new("resolvers") +local report_initialization = logs.new("resolvers","initialization") local ostype, osname, ossetenv, osgetenv = os.type, os.name, os.setenv, os.getenv @@ -9245,7 +9302,7 @@ kpse = { original = kpse } setmetatable(kpse, { __index = function(kp,name) - report_resolvers("fatal error: kpse library is accessed (key: %s)",name) + report_initialization("fatal error: kpse library is accessed (key: %s)",name) os.exit() end } ) @@ -9329,13 +9386,13 @@ do if lfs.chdir(p) then local pp = lfs.currentdir() if trace_locating and p ~= pp then - report_resolvers("following symlink '%s' to '%s'",p,pp) + report_initialization("following symlink '%s' to '%s'",p,pp) end ownpath = pp lfs.chdir(olddir) else if trace_locating then - report_resolvers("unable to check path '%s'",p) + report_initialization("unable to check path '%s'",p) end ownpath = p end @@ -9346,9 +9403,9 @@ do end if not ownpath or ownpath == "" then ownpath = "." - report_resolvers("forcing fallback ownpath .") + report_initialization("forcing fallback ownpath .") elseif trace_locating then - report_resolvers("using ownpath '%s'",ownpath) + report_initialization("using ownpath '%s'",ownpath) end end @@ -9375,7 +9432,7 @@ do ossetenv('SELFAUTODIR', file.collapsepath(ownpath .. "/..")) ossetenv('SELFAUTOPARENT', file.collapsepath(ownpath .. "/../..")) else - report_resolvers("error: unable to locate ownpath") + report_initialization("error: unable to locate ownpath") os.exit() end @@ -9461,7 +9518,7 @@ local collapsepath = file.collapsepath local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) local trace_expansions = false trackers.register("resolvers.expansions", function(v) trace_expansions = v end) -local report_resolvers = logs.new("resolvers") +local report_expansions = logs.new("resolvers","expansions") local resolvers = resolvers @@ -9524,7 +9581,7 @@ local replacer_1 = lpeg.replacer { { ",}", ",@}" }, { "{,", "{@," }, } local function splitpathexpr(str, newlist, validate) -- I couldn't resist lpegging it (nice exercise). if trace_expansions then - report_resolvers("expanding variable '%s'",str) + report_expansions("expanding variable '%s'",str) end local t, ok, done = newlist or { }, false, false local n = #t @@ -9550,7 +9607,7 @@ local function splitpathexpr(str, newlist, validate) -- I couldn't resist lpeggi end if trace_expansions then for k=1,#t do - report_resolvers("% 4i: %s",k,t[k]) + report_expansions("% 4i: %s",k,t[k]) end end return t @@ -9585,7 +9642,7 @@ function resolvers.cleanpath(str) homedir = lpegmatch(cleanup,environment.homedir or "") if homedir == string.char(127) or homedir == "" or not lfs.isdir(homedir) then if trace_expansions then - report_resolvers("no home dir set, ignoring dependent paths") + report_expansions("no home dir set, ignoring dependent paths") end function resolvers.cleanpath(str) if find(str,"~") then @@ -9655,9 +9712,9 @@ local function splitconfigurationpath(str) -- beware, this can be either a path end end if trace_expansions then - report_resolvers("splitting path specification '%s'",str) + report_expansions("splitting path specification '%s'",str) for k=1,noffound do - report_resolvers("% 4i: %s",k,found[k]) + report_expansions("% 4i: %s",k,found[k]) end end cache[str] = found @@ -9742,7 +9799,7 @@ end function resolvers.scanfiles(path,branch) if trace_locating then - report_resolvers("scanning path '%s', branch '%s'",path, branch or path) + report_expansions("scanning path '%s', branch '%s'",path, branch or path) end local realpath = resolvers.resolve(path) -- no shortcut local files, n, m, r = scan({ },realpath .. '/',"",0,0,0) @@ -9751,7 +9808,7 @@ function resolvers.scanfiles(path,branch) files.__directories__ = m files.__remappings__ = r if trace_locating then - report_resolvers("%s files found on %s directories with %s uppercase remappings",n,m,r) + report_expansions("%s files found on %s directories with %s uppercase remappings",n,m,r) end return files end @@ -10080,8 +10137,8 @@ local mkdirs, isdir = dir.mkdirs, lfs.isdir local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end) -local report_cache = logs.new("cache") -local report_resolvers = logs.new("resolvers") +local report_caches = logs.new("resolvers","caches") +local report_resolvers = logs.new("resolvers","caching") local resolvers = resolvers @@ -10141,7 +10198,7 @@ local function identify() if not caches.ask or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then mkdirs(cachepath) if isdir(cachepath) and file.is_writable(cachepath) then - report_cache("created: %s",cachepath) + report_caches("created: %s",cachepath) writable = cachepath readables[#readables+1] = cachepath end @@ -10175,10 +10232,10 @@ local function identify() -- Some extra checking. If we have no writable or readable path then we simply -- quit. if not writable then - report_cache("fatal error: there is no valid writable cache path defined") + report_caches("fatal error: there is no valid writable cache path defined") os.exit() elseif #readables == 0 then - report_cache("fatal error: there is no valid readable cache path defined") + report_caches("fatal error: there is no valid readable cache path defined") os.exit() end -- why here @@ -10200,9 +10257,9 @@ local function identify() -- end if trace_cache then for i=1,#readables do - report_cache("using readable path '%s' (order %s)",readables[i],i) + report_caches("using readable path '%s' (order %s)",readables[i],i) end - report_cache("using writable path '%s'",writable) + report_caches("using writable path '%s'",writable) end identify = function() return writable, readables @@ -10237,7 +10294,7 @@ function caches.hashed(tree) tree = lower(tree) local hash = md5.hex(tree) if trace_cache or trace_locating then - report_cache("hashing tree %s, hash %s",tree,hash) + report_caches("hashing tree %s, hash %s",tree,hash) end return hash end @@ -10463,7 +10520,7 @@ trackers.register("resolvers.locating", function(v) trace_methods = v end) trackers.register("resolvers.methods", function(v) trace_methods = v end) -local report_resolvers = logs.new("resolvers") +local report_methods = logs.new("resolvers","methods") local allocate = utilities.storage.allocate @@ -10505,41 +10562,41 @@ local function methodhandler(what,first,...) -- filename can be nil or false local resolver = namespace and namespace[scheme] if resolver then if trace_methods then - report_resolvers("resolver: method=%s, how=%s, scheme=%s, argument=%s",what,how,scheme,first) + report_methods("resolver: method=%s, how=%s, scheme=%s, argument=%s",what,how,scheme,first) end return resolver(specification,...) else resolver = namespace.default or namespace.file if resolver then if trace_methods then - report_resolvers("resolver: method=%s, how=%s, default, argument=%s",what,how,first) + report_methods("resolver: method=%s, how=%s, default, argument=%s",what,how,first) end return resolver(specification,...) elseif trace_methods then - report_resolvers("resolver: method=%s, how=%s, no handler",what,how) + report_methods("resolver: method=%s, how=%s, no handler",what,how) end end elseif how == "tag" then local resolver = namespace and namespace[first] if resolver then if trace_methods then - report_resolvers("resolver: method=%s, how=%s, tag=%s",what,how,first) + report_methods("resolver: method=%s, how=%s, tag=%s",what,how,first) end return resolver(...) else resolver = namespace.default or namespace.file if resolver then if trace_methods then - report_resolvers("resolver: method=%s, how=%s, default",what,how) + report_methods("resolver: method=%s, how=%s, default",what,how) end return resolver(...) elseif trace_methods then - report_resolvers("resolver: method=%s, how=%s, unknown",what,how) + report_methods("resolver: method=%s, how=%s, unknown",what,how) end end end else - report_resolvers("resolver: method=%s, unknown",what) + report_methods("resolver: method=%s, unknown",what) end end @@ -10610,7 +10667,7 @@ local trace_locating = false trackers.register("resolvers.locating", functi local trace_detail = false trackers.register("resolvers.details", function(v) trace_detail = v end) local trace_expansions = false trackers.register("resolvers.expansions", function(v) trace_expansions = v end) -local report_resolvers = logs.new("resolvers") +local report_resolving = logs.new("resolvers","resolving") local resolvers = resolvers @@ -10712,7 +10769,7 @@ end function resolvers.newinstance() -- todo: all vars will become lowercase and alphanum only if trace_locating then - report_resolvers("creating instance") + report_resolving("creating instance") end local environment, variables, expansions, order = allocate(), allocate(), allocate(), allocate() @@ -10830,9 +10887,9 @@ local function reportcriticalvariables() for i=1,#resolvers.criticalvars do local k = resolvers.criticalvars[i] local v = resolvers.getenv(k) or "unknown" -- this one will not resolve ! - report_resolvers("variable '%s' set to '%s'",k,v) + report_resolving("variable '%s' set to '%s'",k,v) end - report_resolvers() + report_resolving() end reportcriticalvariables = function() end end @@ -10856,17 +10913,17 @@ local function identify_configuration_files() if lfs.isfile(realname) then specification[#specification+1] = filename if trace_locating then - report_resolvers("found configuration file '%s'",realname) + report_resolving("found configuration file '%s'",realname) end elseif trace_locating then - report_resolvers("unknown configuration file '%s'",realname) + report_resolving("unknown configuration file '%s'",realname) end end if trace_locating then - report_resolvers() + report_resolving() end elseif trace_locating then - report_resolvers("configuration files already identified") + report_resolving("configuration files already identified") end end @@ -10886,8 +10943,8 @@ local function load_configuration_files() data = data and data.content if data then if trace_locating then - report_resolvers("loading configuration file '%s'",filename) - report_resolvers() + report_resolving("loading configuration file '%s'",filename) + report_resolving() end local variables = data.variables or { } local warning = false @@ -10897,7 +10954,7 @@ local function load_configuration_files() initializesetter(filename,k,v) elseif variables[k] == nil then if trace_locating and not warning then - report_resolvers("variables like '%s' in configuration file '%s' should move to the 'variables' subtable", + report_resolving("variables like '%s' in configuration file '%s' should move to the 'variables' subtable", k,resolvers.resolve(filename)) warning = true end @@ -10910,7 +10967,7 @@ local function load_configuration_files() local cnfspec = variables["TEXMFCNF"] if cnfspec then if trace_locating then - report_resolvers("reloading configuration due to TEXMF redefinition") + report_resolving("reloading configuration due to TEXMF redefinition") end -- we push the value into the main environment (osenv) so -- that it takes precedence over the default one and therefore @@ -10929,13 +10986,13 @@ local function load_configuration_files() else if trace_locating then - report_resolvers("skipping configuration file '%s' (no content)",filename) + report_resolving("skipping configuration file '%s' (no content)",filename) end setups[pathname] = { } instance.loaderror = true end elseif trace_locating then - report_resolvers("skipping configuration file '%s' (no file)",filename) + report_resolving("skipping configuration file '%s' (no file)",filename) end instance.order[#instance.order+1] = instance.setups[pathname] if instance.loaderror then @@ -10943,7 +11000,7 @@ local function load_configuration_files() end end elseif trace_locating then - report_resolvers("warning: no lua configuration files found") + report_resolving("warning: no lua configuration files found") end end @@ -10979,19 +11036,19 @@ local function locate_file_databases() end if trace_locating then if runtime then - report_resolvers("locating list of '%s' (runtime)",path) + report_resolving("locating list of '%s' (runtime)",path) else - report_resolvers("locating list of '%s' (cached)",path) + report_resolving("locating list of '%s' (cached)",path) end end methodhandler('locators',stripped) end end if trace_locating then - report_resolvers() + report_resolving() end elseif trace_locating then - report_resolvers("no texmf paths are defined (using TEXMF)") + report_resolving("no texmf paths are defined (using TEXMF)") end end @@ -11002,7 +11059,7 @@ local function generate_file_databases() methodhandler('generators',hash.name) end if trace_locating then - report_resolvers() + report_resolving() end end @@ -11014,11 +11071,11 @@ local function save_file_databases() -- will become cachers local content = instance.files[cachename] caches.collapsecontent(content) if trace_locating then - report_resolvers("saving tree '%s'",cachename) + report_resolving("saving tree '%s'",cachename) end caches.savecontent(cachename,"files",content) elseif trace_locating then - report_resolvers("not saving runtime tree '%s'",cachename) + report_resolving("not saving runtime tree '%s'",cachename) end end end @@ -11043,7 +11100,7 @@ function resolvers.appendhash(type,name,cache) -- safeguard ... tricky as it's actually a bug when seen twice if not instance.hashed[name] then if trace_locating then - report_resolvers("hash '%s' appended",name) + report_resolving("hash '%s' appended",name) end insert(instance.hashes, { type = type, name = name, cache = cache } ) instance.hashed[name] = cache @@ -11054,7 +11111,7 @@ function resolvers.prependhash(type,name,cache) -- safeguard ... tricky as it's actually a bug when seen twice if not instance.hashed[name] then if trace_locating then - report_resolvers("hash '%s' prepended",name) + report_resolving("hash '%s' prepended",name) end insert(instance.hashes, 1, { type = type, name = name, cache = cache } ) instance.hashed[name] = cache @@ -11287,9 +11344,9 @@ function isreadable(name) local readable = lfs.isfile(name) -- not file.is_readable(name) asit can be a dir if trace_detail then if readable then - report_resolvers("file '%s' is readable",name) + report_resolving("file '%s' is readable",name) else - report_resolvers("file '%s' is not readable", name) + report_resolving("file '%s' is not readable", name) end end return readable @@ -11303,7 +11360,7 @@ local function collect_files(names) for k=1,#names do local fname = names[k] if trace_detail then - report_resolvers("checking name '%s'",fname) + report_resolving("checking name '%s'",fname) end local bname = filebasename(fname) local dname = filedirname(fname) @@ -11319,7 +11376,7 @@ local function collect_files(names) local files = blobpath and instance.files[blobpath] if files then if trace_detail then - report_resolvers("deep checking '%s' (%s)",blobpath,bname) + report_resolving("deep checking '%s' (%s)",blobpath,bname) end local blobfile = files[bname] if not blobfile then @@ -11339,7 +11396,7 @@ local function collect_files(names) local search = filejoin(blobroot,blobfile,bname) local result = methodhandler('concatinators',hash.type,blobroot,blobfile,bname) if trace_detail then - report_resolvers("match: kind '%s', search '%s', result '%s'",kind,search,result) + report_resolving("match: kind '%s', search '%s', result '%s'",kind,search,result) end noffiles = noffiles + 1 filelist[noffiles] = { kind, search, result } @@ -11353,7 +11410,7 @@ local function collect_files(names) local search = filejoin(blobroot,vv,bname) local result = methodhandler('concatinators',hash.type,blobroot,vv,bname) if trace_detail then - report_resolvers("match: kind '%s', search '%s', result '%s'",kind,search,result) + report_resolving("match: kind '%s', search '%s', result '%s'",kind,search,result) end noffiles = noffiles + 1 filelist[noffiles] = { kind, search, result } @@ -11362,7 +11419,7 @@ local function collect_files(names) end end elseif trace_locating then - report_resolvers("no match in '%s' (%s)",blobpath,bname) + report_resolving("no match in '%s' (%s)",blobpath,bname) end end end @@ -11403,7 +11460,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : stamp = filename .. "--" .. askedformat if instance.found[stamp] then if trace_locating then - report_resolvers("remembered file '%s'",filename) + report_resolving("remembered file '%s'",filename) end resolvers.registerintrees(filename) -- for tracing used files return instance.found[stamp] @@ -11412,7 +11469,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : if not dangerous[askedformat] then if isreadable(filename) then if trace_detail then - report_resolvers("file '%s' found directly",filename) + report_resolving("file '%s' found directly",filename) end if stamp then instance.found[stamp] = { filename } @@ -11422,13 +11479,13 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : end if find(filename,'%*') then if trace_locating then - report_resolvers("checking wildcard '%s'", filename) + report_resolving("checking wildcard '%s'", filename) end result = resolvers.findwildcardfiles(filename) -- we can use th elocal elseif file.is_qualified_path(filename) then if isreadable(filename) then if trace_locating then - report_resolvers("qualified name '%s'", filename) + report_resolving("qualified name '%s'", filename) end result = { filename } else @@ -11441,7 +11498,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : forcedname = filename .. "." .. s if isreadable(forcedname) then if trace_locating then - report_resolvers("no suffix, forcing format filetype '%s'", s) + report_resolving("no suffix, forcing format filetype '%s'", s) end result, ok = { forcedname }, true break @@ -11494,7 +11551,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : -- end end if not ok and trace_locating then - report_resolvers("qualified name '%s'", filename) + report_resolving("qualified name '%s'", filename) end end else @@ -11513,13 +11570,13 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : wantedfiles[#wantedfiles+1] = forcedname filetype = resolvers.formatofsuffix(forcedname) if trace_locating then - report_resolvers("forcing filetype '%s'",filetype) + report_resolving("forcing filetype '%s'",filetype) end end else filetype = resolvers.formatofsuffix(filename) if trace_locating then - report_resolvers("using suffix based filetype '%s'",filetype) + report_resolving("using suffix based filetype '%s'",filetype) end end else @@ -11533,7 +11590,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : end filetype = askedformat if trace_locating then - report_resolvers("using given filetype '%s'",filetype) + report_resolving("using given filetype '%s'",filetype) end end local typespec = resolvers.variableofformat(filetype) @@ -11541,7 +11598,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : if not pathlist or #pathlist == 0 then -- no pathlist, access check only / todo == wildcard if trace_detail then - report_resolvers("checking filename '%s', filetype '%s', wanted files '%s'",filename, filetype or '?',concat(wantedfiles," | ")) + report_resolving("checking filename '%s', filetype '%s', wanted files '%s'",filename, filetype or '?',concat(wantedfiles," | ")) end for k=1,#wantedfiles do local fname = wantedfiles[k] @@ -11569,7 +11626,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : end end if trace_detail then - report_resolvers("checking filename '%s'",filename) + report_resolving("checking filename '%s'",filename) end for k=1,#pathlist do local path = pathlist[k] @@ -11581,7 +11638,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : -- compare list entries with permitted pattern -- /xx /xx// local expression = makepathexpression(pathname) if trace_detail then - report_resolvers("using pattern '%s' for path '%s'",expression,pathname) + report_resolving("using pattern '%s' for path '%s'",expression,pathname) end for k=1,#filelist do local fl = filelist[k] @@ -11593,16 +11650,16 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : done = true if allresults then if trace_detail then - report_resolvers("match to '%s' in hash for file '%s' and path '%s', continue scanning",expression,f,d) + report_resolving("match to '%s' in hash for file '%s' and path '%s', continue scanning",expression,f,d) end else if trace_detail then - report_resolvers("match to '%s' in hash for file '%s' and path '%s', quit scanning",expression,f,d) + report_resolving("match to '%s' in hash for file '%s' and path '%s', quit scanning",expression,f,d) end break end elseif trace_detail then - report_resolvers("no match to '%s' in hash for file '%s' and path '%s'",expression,f,d) + report_resolving("no match to '%s' in hash for file '%s' and path '%s'",expression,f,d) end end end @@ -11619,7 +11676,7 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo : local fname = filejoin(ppname,w) if isreadable(fname) then if trace_detail then - report_resolvers("found '%s' by scanning",fname) + report_resolving("found '%s' by scanning",fname) end result[#result+1] = fname done = true @@ -11824,7 +11881,7 @@ end local function report(str) if trace_locating then - report_resolvers(str) -- has already verbose + report_resolving(str) -- has already verbose else print(str) end @@ -12219,7 +12276,7 @@ if not modules then modules = { } end modules ['data-fil'] = { local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_files = logs.new("resolvers","files") local resolvers = resolvers @@ -12233,11 +12290,11 @@ function locators.file(specification) local realname = resolvers.resolve(name) -- no shortcut if realname and realname ~= '' and lfs.isdir(realname) then if trace_locating then - report_resolvers("file locator '%s' found as '%s'",name,realname) + report_files("file locator '%s' found as '%s'",name,realname) end resolvers.appendhash('file',name,true) -- cache elseif trace_locating then - report_resolvers("file locator '%s' not found",name) + report_files("file locator '%s' not found",name) end end @@ -12260,12 +12317,12 @@ function finders.file(specification,filetype) local foundname = resolvers.findfile(filename,filetype) if foundname and foundname ~= "" then if trace_locating then - report_resolvers("file finder: '%s' found",filename) + report_files("file finder: '%s' found",filename) end return foundname else if trace_locating then - report_resolvers("file finder: %s' not found",filename) + report_files("file finder: %s' not found",filename) end return finders.notfound() end @@ -12286,13 +12343,13 @@ function openers.file(specification,filetype) local f = io.open(filename,"r") if f then if trace_locating then - report_resolvers("file opener, '%s' opened",filename) + report_files("file opener, '%s' opened",filename) end return openers.helpers.textopener("file",filename,f) end end if trace_locating then - report_resolvers("file opener, '%s' not found",filename) + report_files("file opener, '%s' not found",filename) end return openers.notfound() end @@ -12304,7 +12361,7 @@ function loaders.file(specification,filetype) if f then logs.show_load(filename) if trace_locating then - report_resolvers("file loader, '%s' loaded",filename) + report_files("file loader, '%s' loaded",filename) end local s = f:read("*a") if checkgarbage then @@ -12317,7 +12374,7 @@ function loaders.file(specification,filetype) end end if trace_locating then - report_resolvers("file loader, '%s' not found",filename) + report_files("file loader, '%s' not found",filename) end return loaders.notfound() end @@ -12358,11 +12415,11 @@ containers = containers or { } local containers = containers containers.usecache = true -local report_cache = logs.new("cache") +local report_containers = logs.new("resolvers","containers") local function report(container,tag,name) if trace_cache or trace_containers then - report_cache("container: %s, tag: %s, name: %s",container.subcategory,tag,name or 'invalid') + report_containers("container: %s, tag: %s, name: %s",container.subcategory,tag,name or 'invalid') end end @@ -12480,7 +12537,7 @@ local format, lower, gsub, find = string.format, string.lower, string.gsub, stri local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_mounts = logs.new("resolvers","mounts") local resolvers = resolvers @@ -12505,7 +12562,7 @@ function resolvers.automount(usecache) -- skip elseif find(line,"^zip://") then if trace_locating then - report_resolvers("mounting %s",line) + report_mounts("mounting %s",line) end table.insert(resolvers.automounted,line) resolvers.usezipfile(line) @@ -12585,7 +12642,7 @@ local format, find, match = string.format, string.find, string.match local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_zip = logs.new("resolvers","zip") -- zip:///oeps.zip?name=bla/bla.tex -- zip:///oeps.zip?tree=tex/texmf-local @@ -12638,9 +12695,9 @@ function resolvers.locators.zip(specification) local zipfile = archive and archive ~= "" and zip.openarchive(archive) -- tricky, could be in to be initialized tree if trace_locating then if zipfile then - report_resolvers("zip locator, archive '%s' found",archive) + report_zip("locator, archive '%s' found",archive) else - report_resolvers("zip locator, archive '%s' not found",archive) + report_zip("locator, archive '%s' not found",archive) end end end @@ -12648,7 +12705,7 @@ end function resolvers.hashers.zip(specification) local archive = specification.filename if trace_locating then - report_resolvers("loading zip file '%s'",archive) + report_zip("loading file '%s'",archive) end resolvers.usezipfile(specification.original) end @@ -12671,25 +12728,25 @@ function resolvers.finders.zip(specification) local zfile = zip.openarchive(archive) if zfile then if trace_locating then - report_resolvers("zip finder, archive '%s' found",archive) + report_zip("finder, archive '%s' found",archive) end local dfile = zfile:open(queryname) if dfile then dfile = zfile:close() if trace_locating then - report_resolvers("zip finder, file '%s' found",queryname) + report_zip("finder, file '%s' found",queryname) end return specification.original elseif trace_locating then - report_resolvers("zip finder, file '%s' not found",queryname) + report_zip("finder, file '%s' not found",queryname) end elseif trace_locating then - report_resolvers("zip finder, unknown archive '%s'",archive) + report_zip("finder, unknown archive '%s'",archive) end end end if trace_locating then - report_resolvers("zip finder, '%s' not found",original) + report_zip("finder, '%s' not found",original) end return resolvers.finders.notfound() end @@ -12704,24 +12761,24 @@ function resolvers.openers.zip(specification) local zfile = zip.openarchive(archive) if zfile then if trace_locating then - report_resolvers("zip opener, archive '%s' opened",archive) + report_zip("opener, archive '%s' opened",archive) end local dfile = zfile:open(queryname) if dfile then if trace_locating then - report_resolvers("zip opener, file '%s' found",queryname) + report_zip("opener, file '%s' found",queryname) end return resolvers.openers.helpers.textopener('zip',original,dfile) elseif trace_locating then - report_resolvers("zip opener, file '%s' not found",queryname) + report_zip("opener, file '%s' not found",queryname) end elseif trace_locating then - report_resolvers("zip opener, unknown archive '%s'",archive) + report_zip("opener, unknown archive '%s'",archive) end end end if trace_locating then - report_resolvers("zip opener, '%s' not found",original) + report_zip("opener, '%s' not found",original) end return resolvers.openers.notfound() end @@ -12736,27 +12793,27 @@ function resolvers.loaders.zip(specification) local zfile = zip.openarchive(archive) if zfile then if trace_locating then - report_resolvers("zip loader, archive '%s' opened",archive) + report_zip("loader, archive '%s' opened",archive) end local dfile = zfile:open(queryname) if dfile then logs.show_load(original) if trace_locating then - report_resolvers("zip loader, file '%s' loaded",original) + report_zip("loader, file '%s' loaded",original) end local s = dfile:read("*all") dfile:close() return true, s, #s elseif trace_locating then - report_resolvers("zip loader, file '%s' not found",queryname) + report_zip("loader, file '%s' not found",queryname) end elseif trace_locating then - report_resolvers("zip loader, unknown archive '%s'",archive) + report_zip("loader, unknown archive '%s'",archive) end end end if trace_locating then - report_resolvers("zip loader, '%s' not found",original) + report_zip("loader, '%s' not found",original) end return resolvers.openers.notfound() end @@ -12772,7 +12829,7 @@ function resolvers.usezipfile(archive) if z then local tree = url.query(specification.query).tree or "" if trace_locating then - report_resolvers("zip registering, registering archive '%s'",archive) + report_zip("registering, registering archive '%s'",archive) end statistics.starttiming(resolvers.instance) resolvers.prependhash('zip',archive) @@ -12781,10 +12838,10 @@ function resolvers.usezipfile(archive) instance.files[archive] = resolvers.registerzipfile(z,tree) statistics.stoptiming(resolvers.instance) elseif trace_locating then - report_resolvers("zip registering, unknown archive '%s'",archive) + report_zip("registering, unknown archive '%s'",archive) end elseif trace_locating then - report_resolvers("zip registering, '%s' not found",archive) + report_zip("registering, '%s' not found",archive) end end @@ -12796,7 +12853,7 @@ function resolvers.registerzipfile(z,tree) filter = format("^%s/(.+)/(.-)$",tree) end if trace_locating then - report_resolvers("zip registering, using filter '%s'",filter) + report_zip("registering, using filter '%s'",filter) end local register, n = resolvers.registerfile, 0 for i in z:files() do @@ -12813,7 +12870,7 @@ function resolvers.registerzipfile(z,tree) n = n + 1 end end - report_resolvers("zip registering, %s files registered",n) + report_zip("registering, %s files registered",n) return files end @@ -12836,7 +12893,7 @@ local find, gsub, format = string.find, string.gsub, string.format local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_trees = logs.new("resolvers","trees") local resolvers = resolvers @@ -12874,18 +12931,18 @@ function resolvers.locators.tree(specification) local name = specification.filename if name ~= '' and lfs.isdir(name) then if trace_locating then - report_resolvers("tree locator '%s' found",name) + report_trees("locator '%s' found",name) end resolvers.appendhash('tree',name,false) -- don't cache elseif trace_locating then - report_resolvers("tree locator '%s' not found",name) + report_trees("locator '%s' not found",name) end end function resolvers.hashers.tree(specification) local name = specification.filename if trace_locating then - report_resolvers("analysing tree '%s'",name) + report_trees("analysing '%s'",name) end resolvers.methodhandler("hashers",name) end @@ -12981,7 +13038,7 @@ if not modules then modules = { } end modules ['data-lua'] = { local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end) -local report_resolvers = logs.new("resolvers") +local report_libraries = logs.new("resolvers","libraries") local gsub, insert = string.gsub, table.insert local unpack = unpack or table.unpack @@ -13013,7 +13070,7 @@ local function thepath(...) local t = { ... } t[#t+1] = "?.lua" local path = file.join(unpack(t)) if trace_locating then - report_resolvers("! appending '%s' to 'package.path'",path) + report_libraries("! appending '%s' to 'package.path'",path) end return path end @@ -13035,11 +13092,11 @@ local function loaded(libpaths,name,simple) local libpath = libpaths[i] local resolved = gsub(libpath,"%?",simple) if trace_locating then -- more detail - report_resolvers("! checking for '%s' on 'package.path': '%s' => '%s'",simple,libpath,resolved) + report_libraries("! checking for '%s' on 'package.path': '%s' => '%s'",simple,libpath,resolved) end if file.is_readable(resolved) then if trace_locating then - report_resolvers("! lib '%s' located via 'package.path': '%s'",name,resolved) + report_libraries("! lib '%s' located via 'package.path': '%s'",name,resolved) end return loadfile(resolved) end @@ -13048,17 +13105,17 @@ end package.loaders[2] = function(name) -- was [#package.loaders+1] if trace_locating then -- mode detail - report_resolvers("! locating '%s'",name) + report_libraries("! locating '%s'",name) end for i=1,#libformats do local format = libformats[i] local resolved = resolvers.findfile(name,format) or "" if trace_locating then -- mode detail - report_resolvers("! checking for '%s' using 'libformat path': '%s'",name,format) + report_libraries("! checking for '%s' using 'libformat path': '%s'",name,format) end if resolved ~= "" then if trace_locating then - report_resolvers("! lib '%s' located via environment: '%s'",name,resolved) + report_libraries("! lib '%s' located via environment: '%s'",name,resolved) end return loadfile(resolved) end @@ -13081,11 +13138,11 @@ package.loaders[2] = function(name) -- was [#package.loaders+1] local path = paths[p] local resolved = file.join(path,libname) if trace_locating then -- mode detail - report_resolvers("! checking for '%s' using 'clibformat path': '%s'",libname,path) + report_libraries("! checking for '%s' using 'clibformat path': '%s'",libname,path) end if file.is_readable(resolved) then if trace_locating then - report_resolvers("! lib '%s' located via 'clibformat': '%s'",libname,resolved) + report_libraries("! lib '%s' located via 'clibformat': '%s'",libname,resolved) end return package.loadlib(resolved,name) end @@ -13095,28 +13152,28 @@ package.loaders[2] = function(name) -- was [#package.loaders+1] local libpath = clibpaths[i] local resolved = gsub(libpath,"?",simple) if trace_locating then -- more detail - report_resolvers("! checking for '%s' on 'package.cpath': '%s'",simple,libpath) + report_libraries("! checking for '%s' on 'package.cpath': '%s'",simple,libpath) end if file.is_readable(resolved) then if trace_locating then - report_resolvers("! lib '%s' located via 'package.cpath': '%s'",name,resolved) + report_libraries("! lib '%s' located via 'package.cpath': '%s'",name,resolved) end return package.loadlib(resolved,name) end end -- just in case the distribution is messed up if trace_loading then -- more detail - report_resolvers("! checking for '%s' using 'luatexlibs': '%s'",name) + report_libraries("! checking for '%s' using 'luatexlibs': '%s'",name) end local resolved = resolvers.findfile(file.basename(name),'luatexlibs') or "" if resolved ~= "" then if trace_locating then - report_resolvers("! lib '%s' located by basename via environment: '%s'",name,resolved) + report_libraries("! lib '%s' located by basename via environment: '%s'",name,resolved) end return loadfile(resolved) end if trace_locating then - report_resolvers('? unable to locate lib: %s',name) + report_libraries('? unable to locate lib: %s',name) end -- return "unable to locate " .. name end @@ -13153,48 +13210,48 @@ local trace_locating = false trackers.register("resolvers.locating", function(v local resolvers = resolvers -local report_resolvers = logs.new("resolvers") +local report_scripts = logs.new("resolvers","scripts") function resolvers.updatescript(oldname,newname) -- oldname -> own.name, not per se a suffix local scriptpath = "scripts/context/lua" newname = file.addsuffix(newname,"lua") local oldscript = resolvers.cleanpath(oldname) if trace_locating then - report_resolvers("to be replaced old script %s", oldscript) + report_scripts("to be replaced old script %s", oldscript) end local newscripts = resolvers.findfiles(newname) or { } if #newscripts == 0 then if trace_locating then - report_resolvers("unable to locate new script") + report_scripts("unable to locate new script") end else for i=1,#newscripts do local newscript = resolvers.cleanpath(newscripts[i]) if trace_locating then - report_resolvers("checking new script %s", newscript) + report_scripts("checking new script %s", newscript) end if oldscript == newscript then if trace_locating then - report_resolvers("old and new script are the same") + report_scripts("old and new script are the same") end elseif not find(newscript,scriptpath) then if trace_locating then - report_resolvers("new script should come from %s",scriptpath) + report_scripts("new script should come from %s",scriptpath) end elseif not (find(oldscript,file.removesuffix(newname).."$") or find(oldscript,newname.."$")) then if trace_locating then - report_resolvers("invalid new script name") + report_scripts("invalid new script name") end else local newdata = io.loaddata(newscript) if newdata then if trace_locating then - report_resolvers("old script content replaced by new content") + report_scripts("old script content replaced by new content") end io.savedata(oldscript,newdata) break elseif trace_locating then - report_resolvers("unable to load new script") + report_scripts("unable to load new script") end end end @@ -13216,6 +13273,8 @@ if not modules then modules = { } end modules ['data-tmf'] = { local resolvers = resolvers +local report_tds = logs.new("resolvers","tds") + -- = << -- ? ?? -- < += @@ -13236,11 +13295,11 @@ function resolvers.load_tree(tree,resolve) local newpath = file.join(newtree,"bin") if not lfs.isdir(newtree) then - logs.simple("no '%s' under tree %s",texos,tree) + report_tds("no '%s' under tree %s",texos,tree) os.exit() end if not lfs.isdir(newpath) then - logs.simple("no '%s/bin' under tree %s",texos,tree) + report_tds("no '%s/bin' under tree %s",texos,tree) os.exit() end @@ -13264,9 +13323,9 @@ function resolvers.load_tree(tree,resolve) setenv('TEXMFCNF', resolvers.luacnfspec, not resolve) setenv("PATH", newpath .. io.pathseparator .. getenv("PATH")) - logs.simple("changing from root '%s' to '%s'",oldroot,newroot) - logs.simple("prepending '%s' to binary path",newpath) - logs.simple() + report_tds("changing from root '%s' to '%s'",oldroot,newroot) + report_tds("prepending '%s' to binary path",newpath) + report_tds() end end @@ -13291,6 +13350,8 @@ resolvers.listers = resolvers.listers or { } local resolvers = resolvers +local report_lists = logs.new("resolvers","lists") + local function tabstr(str) if type(str) == 'table' then return concat(str," | ") @@ -13319,11 +13380,11 @@ function resolvers.listers.variables(pattern) local exp = table.fastcopy(expansions) for key, value in table.sortedpairs(configured) do if key ~= "" and (pattern == "" or find(upper(key),pattern)) then - logs.simple(key) - logs.simple(" env: %s",tabstr(rawget(environment,key)) or "unset") - logs.simple(" var: %s",tabstr(configured[key]) or "unset") - logs.simple(" exp: %s",tabstr(expansions[key]) or "unset") - logs.simple(" res: %s",resolvers.resolve(expansions[key]) or "unset") + report_lists(key) + report_lists(" env: %s",tabstr(rawget(environment,key)) or "unset") + report_lists(" var: %s",tabstr(configured[key]) or "unset") + report_lists(" exp: %s",tabstr(expansions[key]) or "unset") + report_lists(" res: %s",resolvers.resolve(expansions[key]) or "unset") end end instance.environment = table.fastcopy(env) @@ -13477,6 +13538,8 @@ if not modules then modules = { } end modules ['luat-fmt'] = { local format = string.format +local report_format = logs.new("resolvers","formats") + -- helper for mtxrun local quoted = string.quoted @@ -13501,7 +13564,7 @@ function environment.make_format(name) if path ~= "" then lfs.chdir(path) end - logs.simple("format path: %s",lfs.currentdir()) + report_format("format path: %s",lfs.currentdir()) -- check source file local texsourcename = file.addsuffix(name,"mkiv") local fulltexsourcename = resolvers.findfile(texsourcename,"tex") or "" @@ -13510,11 +13573,11 @@ function environment.make_format(name) fulltexsourcename = resolvers.findfile(texsourcename,"tex") or "" end if fulltexsourcename == "" then - logs.simple("no tex source file with name: %s (mkiv or tex)",name) + report_format("no tex source file with name: %s (mkiv or tex)",name) lfs.chdir(olddir) return else - logs.simple("using tex source file: %s",fulltexsourcename) + report_format("using tex source file: %s",fulltexsourcename) end local texsourcepath = dir.expandname(file.dirname(fulltexsourcename)) -- really needed -- check specification @@ -13525,7 +13588,7 @@ function environment.make_format(name) fullspecificationname = resolvers.findfile(specificationname,"tex") or "" end if fullspecificationname == "" then - logs.simple("unknown stub specification: %s",specificationname) + report_format("unknown stub specification: %s",specificationname) lfs.chdir(olddir) return end @@ -13536,39 +13599,39 @@ function environment.make_format(name) if type(usedlualibs) == "string" then usedluastub = file.join(file.dirname(fullspecificationname),usedlualibs) elseif type(usedlualibs) == "table" then - logs.simple("using stub specification: %s",fullspecificationname) + report_format("using stub specification: %s",fullspecificationname) local texbasename = file.basename(name) local luastubname = file.addsuffix(texbasename,"lua") local lucstubname = file.addsuffix(texbasename,"luc") -- pack libraries in stub - logs.simple("creating initialization file: %s",luastubname) + report_format("creating initialization file: %s",luastubname) utilities.merger.selfcreate(usedlualibs,specificationpath,luastubname) -- compile stub file (does not save that much as we don't use this stub at startup any more) local strip = resolvers.booleanvariable("LUACSTRIP", true) if utilities.lua.compile(luastubname,lucstubname) and lfs.isfile(lucstubname) then - logs.simple("using compiled initialization file: %s",lucstubname) + report_format("using compiled initialization file: %s",lucstubname) usedluastub = lucstubname else - logs.simple("using uncompiled initialization file: %s",luastubname) + report_format("using uncompiled initialization file: %s",luastubname) usedluastub = luastubname end else - logs.simple("invalid stub specification: %s",fullspecificationname) + report_format("invalid stub specification: %s",fullspecificationname) lfs.chdir(olddir) return end -- generate format local command = format("luatex --ini %s --lua=%s %s %sdump",primaryflags(),quoted(usedluastub),quoted(fulltexsourcename),os.platform == "unix" and "\\\\" or "\\") - logs.simple("running command: %s\n",command) + report_format("running command: %s\n",command) os.spawn(command) -- remove related mem files local pattern = file.removesuffix(file.basename(usedluastub)).."-*.mem" - -- logs.simple("removing related mplib format with pattern '%s'", pattern) + -- report_format("removing related mplib format with pattern '%s'", pattern) local mp = dir.glob(pattern) if mp then for i=1,#mp do local name = mp[i] - logs.simple("removing related mplib format %s", file.basename(name)) + report_format("removing related mplib format %s", file.basename(name)) os.remove(name) end end @@ -13585,7 +13648,7 @@ function environment.run_format(name,data,more) end fmtname = resolvers.cleanpath(fmtname) if fmtname == "" then - logs.simple("no format with name: %s",name) + report_format("no format with name: %s",name) else local barename = file.removesuffix(name) -- expanded name local luaname = file.addsuffix(barename,"luc") @@ -13593,11 +13656,11 @@ function environment.run_format(name,data,more) luaname = file.addsuffix(barename,"lua") end if not lfs.isfile(luaname) then - logs.simple("using format name: %s",fmtname) - logs.simple("no luc/lua with name: %s",barename) + report_format("using format name: %s",fmtname) + report_format("no luc/lua with name: %s",barename) else local command = format("luatex %s --fmt=%s --lua=%s %s %s",primaryflags(),quoted(barename),quoted(luaname),quoted(data),more ~= "" and quoted(more) or "") - logs.simple("running command: %s",command) + report_format("running command: %s",command) os.spawn(command) end end @@ -13750,8 +13813,6 @@ if not resolvers then os.exit() end -logs.setprogram('MTXrun',"TDS Runner Tool 1.30") - if environment.arguments["verbose"] then trackers.enable("resolvers.locating") end @@ -13764,10 +13825,7 @@ if trackspec then trackers.enable(trackspec) end -runners = runners or { } -- global -messages = messages or { } - -messages.help = [[ +local helpinfo = [[ --script run an mtx script (lua prefered method) (--noquotes), no script gives list --execute run a script or program (texmfstart method) (--noquotes) --resolve resolve prefixed arguments @@ -13819,6 +13877,19 @@ messages.help = [[ --pattern=str filter variables ]] +local application = logs.application { + name = "mtxrun", + banner = "ConTeXt TDS Runner Tool 1.30", + helpinfo = helpinfo, +} + +local report = application.report + +local verbose = environment.argument("verbose") + +messages = messages or { } -- for the mo + +runners = runners or { } -- global runners.applications = { ["lua"] = "luatex --luaonly", @@ -13872,17 +13943,16 @@ end function runners.prepare() local checkname = environment.argument("ifchanged") - local verbose = environment.argument("verbose") if type(checkname) == "string" and checkname ~= "" then local oldchecksum = file.loadchecksum(checkname) local newchecksum = file.checksum(checkname) if oldchecksum == newchecksum then if verbose then - logs.simple("file '%s' is unchanged",checkname) + report("file '%s' is unchanged",checkname) end return "skip" elseif verbose then - logs.simple("file '%s' is changed, processing started",checkname) + report("file '%s' is changed, processing started",checkname) end file.savechecksum(checkname) end @@ -13892,17 +13962,17 @@ function runners.prepare() if oldname and newname and oldname ~= "" and newname ~= "" then if not file.needs_updating(oldname,newname) then if verbose then - logs.simple("file '%s' and '%s' have same age",oldname,newname) + report("file '%s' and '%s' have same age",oldname,newname) end return "skip" elseif verbose then - logs.simple("file '%s' is older than '%s'",oldname,newname) + report("file '%s' is older than '%s'",oldname,newname) end end end local runpath = environment.argument("path") if type(runpath) == "string" and not lfs.chdir(runpath) then - logs.simple("unable to change to path '%s'",runpath) + report("unable to change to path '%s'",runpath) return "error" end runners.prepare = function() end @@ -13961,11 +14031,11 @@ function runners.execute_script(fullname,internal,nosplit) result = binary .. " " .. result end local command = result .. " " .. environment.reconstructcommandline(environment.arguments_after,noquote) - if logs.verbose then - logs.simpleline() - logs.simple("executing: %s",command) - logs.simpleline() - logs.simpleline() + if verbose then + report() + report("executing: %s",command) + report() + report() io.flush() end -- no os.exec because otherwise we get the wrong return value @@ -13980,9 +14050,9 @@ function runners.execute_script(fullname,internal,nosplit) return false end end - logs.simpleline() - logs.simple("This script needs '%s' which seems not to be installed.",binary) - logs.simpleline() + report() + report("This script needs '%s' which seems not to be installed.",binary) + report() end return false end @@ -14007,10 +14077,10 @@ function runners.execute_program(fullname) environment.initializearguments(after) fullname = fullname:gsub("^bin:","") local command = fullname .. " " .. (environment.reconstructcommandline(after or "",noquote) or "") - logs.simpleline() - logs.simple("executing: %s",command) - logs.simpleline() - logs.simpleline() + report() + report("executing: %s",command) + report() + report() io.flush() local code = os.exec(command) -- (fullname,unpack(after)) does not work / maybe spawn return code == 0 @@ -14042,18 +14112,18 @@ function runners.handle_stubs(create) if create then if windows then io.savedata(file.join(stubpath,base..".bat"),string.format(windows_stub,name)) - logs.simple("windows stub for '%s' created",base) + report("windows stub for '%s' created",base) end if unix then io.savedata(file.join(stubpath,base),string.format(unix_stub,name)) - logs.simple("unix stub for '%s' created",base) + report("unix stub for '%s' created",base) end else if windows and (os.remove(file.join(stubpath,base..'.bat')) or os.remove(file.join(stubpath,base..'.cmd'))) then - logs.simple("windows stub for '%s' removed", base) + report("windows stub for '%s' removed", base) end if unix and (os.remove(file.join(stubpath,base)) or os.remove(file.join(stubpath,base..'.sh'))) then - logs.simple("unix stub for '%s' removed",base) + report("unix stub for '%s' removed",base) end end end @@ -14078,12 +14148,12 @@ function runners.locate_platform() end function runners.report_location(result) - if logs.verbose then - logs.simpleline() + if verbose then + reportline() if result and result ~= "" then - logs.simple(result) + report(result) else - logs.simple("not found") + report("not found") end else io.write(result) @@ -14095,11 +14165,11 @@ function runners.edit_script(filename) -- we assume that gvim is present on most local rest = resolvers.resolve(filename) if rest ~= "" then local command = editor .. " " .. rest - if logs.verbose then - logs.simpleline() - logs.simple("starting editor: %s",command) - logs.simple_line() - logs.simple_line() + if verbose then + report() + report("starting editor: %s",command) + report() + report() end os.launch(command) end @@ -14148,7 +14218,7 @@ function runners.launch_file(filename) pattern = filename end if not pattern or pattern == "" then - logs.simple("provide name or --pattern=") + report("provide name or --pattern=") else local t = resolvers.findfiles(pattern) if not t or #t == 0 then @@ -14160,15 +14230,15 @@ function runners.launch_file(filename) if t and #t > 0 then if environment.arguments["all"] then for _, v in pairs(t) do - logs.simple("launching %s", v) + report("launching %s", v) resolvers.launch(v) end else - logs.simple("launching %s", t[1]) + report("launching %s", t[1]) resolvers.launch(t[1]) end else - logs.simple("no match for %s", pattern) + report("no match for %s", pattern) end end end @@ -14239,7 +14309,7 @@ function runners.execute_ctx_script(filename,...) local fullname = runners.find_mtx_script(filename) or "" if file.extname(fullname) == "cld" then -- handy in editors where we force --autopdf - logs.simple("running cld script: %s",filename) + report("running cld script: %s",filename) table.insert(arguments,1,fullname) table.insert(arguments,"--autopdf") fullname = runners.find_mtx_script("context") or "" @@ -14270,8 +14340,8 @@ function runners.execute_ctx_script(filename,...) runners.load_script_session(loadname) end filename = environment.files[1] - if logs.verbose then - logs.simple("using script: %s\n",fullname) + if verbose then + report("using script: %s\n",fullname) end environment.ownscript = fullname dofile(fullname) @@ -14306,24 +14376,23 @@ function runners.execute_ctx_script(filename,...) end end if #valid > 0 then - logs.reportbanner() - logs.reportline() - logs.simple("no script name given, known scripts:") - logs.simple() + application.identify() + report("no script name given, known scripts:") + report() for k=1,#valid do local v = valid[k] - logs.simple("%-12s %4s %s",v[1],v[2],v[3]) + report("%-12s %4s %s",v[1],v[2],v[3]) end end else - logs.simple("no script name given") + report("no script name given") end else filename = file.addsuffix(filename,"lua") if file.is_qualified_path(filename) then - logs.simple("unknown script '%s'",filename) + report("unknown script '%s'",filename) else - logs.simple("unknown script '%s' or 'mtx-%s'",filename,filename) + report("unknown script '%s' or 'mtx-%s'",filename,filename) end end return false @@ -14331,9 +14400,9 @@ function runners.execute_ctx_script(filename,...) end function runners.prefixes() - logs.reportbanner() - logs.reportline() - logs.simple(table.concat(resolvers.allprefixes(true)," ")) + application.identify() + report() + report(table.concat(resolvers.allprefixes(true)," ")) end function runners.timedrun(filename) -- just for me @@ -14385,7 +14454,7 @@ if environment.argument("usekpse") or environment.argument("forcekpse") or is_mk local t = os.clock() local k = kpse.original.new("luatex",progname) local dummy = k:find_file("mtxrun.lua") -- so that we're initialized - logs.simple("kpse fallback with progname '%s' initialized in %s seconds",progname,os.clock()-t) + report("kpse fallback with progname '%s' initialized in %s seconds",progname,os.clock()-t) kpse_initialized = function() return k end return k end @@ -14432,11 +14501,11 @@ else function runners.loadbase(...) if not resolvers.load(...) then - logs.simple("forcing cache reload") + report("forcing cache reload") instance.renewcache = true trackers.enable("resolvers.locating") if not resolvers.load(...) then - logs.simple("the resolver databases are not present or outdated") + report("the resolver databases are not present or outdated") end end end @@ -14595,8 +14664,8 @@ elseif environment.argument("find-path") then resolvers.load() local path = resolvers.findpath(filename, instance.my_format) - if logs.verbose then - logs.simple(path) + if verbose then + report(path) else print(path) end @@ -14651,7 +14720,7 @@ elseif environment.argument("format-path") then -- luatools: runners.execute_ctx_script("mtx-base","--format-path",filename) resolvers.load() - logs.simple(caches.getwritablepath("format")) + report(caches.getwritablepath("format")) elseif environment.argument("pattern") then @@ -14695,7 +14764,7 @@ elseif environment.argument("help") and filename=='base' then elseif environment.argument("help") or filename=='help' or filename == "" then - logs.help(messages.help) + application.help() elseif filename:find("^bin:") then @@ -14729,9 +14798,9 @@ else end -if logs.verbose then - logs.simpleline() - logs.simple("runtime: %0.3f seconds",os.runtime()) +if verbose then + report() + report("runtime: %0.3f seconds",os.runtime()) end if os.type ~= "windows" then |