diff options
author | Context Git Mirror Bot <phg42.2a@gmail.com> | 2016-01-12 17:15:07 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2016-01-12 17:15:07 +0100 |
commit | 8d8d528d2ad52599f11250cfc567fea4f37f2a8b (patch) | |
tree | 94286bc131ef7d994f9432febaf03fe23d10eef8 /tex/context/base/mkiv/core-sys.lua | |
parent | f5aed2e51223c36c84c5f25a6cad238b2af59087 (diff) | |
download | context-8d8d528d2ad52599f11250cfc567fea4f37f2a8b.tar.gz |
2016-01-12 16:26:00
Diffstat (limited to 'tex/context/base/mkiv/core-sys.lua')
-rw-r--r-- | tex/context/base/mkiv/core-sys.lua | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/core-sys.lua b/tex/context/base/mkiv/core-sys.lua new file mode 100644 index 000000000..f688a1454 --- /dev/null +++ b/tex/context/base/mkiv/core-sys.lua @@ -0,0 +1,90 @@ +if not modules then modules = { } end modules ['core-sys'] = { + version = 1.001, + comment = "companion to core-sys.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local lower, format, gsub = string.lower, string.format, string.gsub +local suffixonly, basename, removesuffix = file.suffix, file.basename, file.removesuffix + +local environment = environment +local context = context +local implement = interfaces.implement + +local report_files = logs.reporter("system","files") + +function environment.initializefilenames() + + local arguments = environment.arguments + + local jobname = arguments.jobname or tex.jobname + local fulljobname = arguments.fulljobname or jobname + local inputfilename = arguments.input or fulljobname + local outputfilename = arguments.result or removesuffix(jobname) + + local inputfilename = suffixonly(inputfilename) == "tex" and removesuffix(inputfilename) or inputfilename or "" + + local filename = fulljobname + local suffix = suffixonly(filename) + + local filename = ctxrunner.resolve(filename) -- in case we're prepped + + local jobfilename = jobname or inputfilename or tex.jobname or "" + local inputfilename = inputfilename or "" + + local jobfilebase = basename(jobfilename) + local inputfilebase = basename(inputfilename) + + -- jobfilename = gsub(jobfilename, "^./","") + -- inputfilename = gsub(inputfilename,"^./","") + + environment.jobfilename = jobfilebase + environment.jobfilesuffix = lower(suffixonly(jobfilebase)) + + environment.inputfilename = inputfilename -- so here we keep e.g. ./ or explicit paths + environment.inputfilebarename = removesuffix(inputfilebase) + environment.inputfilesuffix = lower(suffixonly(inputfilebase)) + + environment.outputfilename = outputfilename or environment.inputfilebarename or "" + + environment.filename = filename + environment.suffix = suffix + + report_files("jobname %a, input %a, result %a",jobfilename,inputfilename,outputfilename) + + function environment.initializefilenames() end +end + +-- we could set a macro (but will that work when we're expanding? needs testing!) + +implement { name = "operatingsystem", actions = function() context(os.platform) end } +implement { name = "jobfilename", actions = function() context(environment.jobfilename) end } +implement { name = "jobfilesuffix", actions = function() context(environment.jobfilesuffix) end } +implement { name = "inputfilebarename", actions = function() context(environment.inputfilebarename) end } +implement { name = "inputfilerealsuffix", actions = function() context(environment.inputfilerealsuffix) end } +implement { name = "inputfilesuffix", actions = function() context(environment.inputfilesuffix) end } +implement { name = "inputfilename", actions = function() context(environment.inputfilename) end } +implement { name = "outputfilename", actions = function() context(environment.outputfilename) end } + +statistics.register("result saved in file", function() + -- suffix will be fetched from backend + local outputfilename = environment.outputfilename or environment.jobname or tex.jobname or "<unset>" + if (tex.pdfoutput or tex.outputmode) > 0 then + return format("%s.%s, compresslevel %s, objectcompresslevel %s",outputfilename,"pdf", + tex.pdfcompresslevel or pdf.getcompresslevel(), + tex.pdfobjcompresslevel or pdf.getobjcompresslevel() + ) + else + return format("%s.%s",outputfilename,"dvi") -- hard to imagine + end +end) + +implement { + name = "systemlog", + arguments = { "string", "string", "string" }, + actions = function(whereto,category,text) + logs.system(whereto,"context",tex.jobname,category,text) + end, +} |