file-ini.lua /size: 1852 b    last modification: 2023-12-21 09:44
1if not modules then modules = { } end modules ['file-ini'] = {
2    version   = 1.001,
3    comment   = "companion to file-ini.mkvi",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9-- It's more convenient to manipulate filenames (paths) in Lua than in TeX. These
10-- methods have counterparts at the TeX end.
11
12local implement       = interfaces.implement
13local setmacro        = interfaces.setmacro
14local setcount        = interfaces.setcount
15
16resolvers.jobs        = resolvers.jobs or { }
17
18local filenametotable = file.nametotable
19local findtexfile     = resolvers.findtexfile
20
21local ctx_doifelse    = commands.doifelse
22
23local function splitfilename(full)
24    local split = filenametotable(full)
25    local path  = split.path
26    setcount("splitoffkind",(path == "" and 0) or (path == '.' and 1) or 2)
27    setmacro("splitofffull",full or "")
28    setmacro("splitoffpath",path or "")
29    setmacro("splitoffname",split.name or "")
30    setmacro("splitoffbase",split.base or "")
31    setmacro("splitofftype",split.suffix or "")
32end
33
34local function isparentfile(name)
35    return
36        name == environment.jobname
37     or name == environment.jobname .. '.tex'
38     or name == environment.outputfilename
39end
40
41local function istexfile(name)
42    local name = name and findtexfile(name)
43    return name ~= "" and name
44end
45
46implement { name = "splitfilename",      actions = splitfilename,                  arguments = "string" }
47implement { name = "doifelseparentfile", actions = { isparentfile, ctx_doifelse }, arguments = "string" }
48implement { name = "doifelsepathexist",  actions = { lfs.isdir,    ctx_doifelse }, arguments = "string" }
49implement { name = "doifelsefileexist",  actions = { istexfile,    ctx_doifelse }, arguments = "string" }
50