file-ini.lua /size: 1935 b    last modification: 2020-07-01 14:35
1
if
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
--[[ldx-- 10<p>It's more convenient to manipulate filenames (paths) in <l n='lua'/> than in 11<l n='tex'/>. These methods have counterparts at the <l n='tex'/> end.</p> 12--ldx]]
--
13 14 15
local
implement
=
interfaces
.
implement
16
local
setmacro
=
interfaces
.
setmacro
17
local
setcount
=
interfaces
.
setcount
18 19
resolvers
.
jobs
=
resolvers
.
jobs
or
{
}
20 21
local
filenametotable
=
file
.
nametotable
22
local
findtexfile
=
resolvers
.
findtexfile
23 24
local
commands_doifelse
=
commands
.
doifelse
25 26
local
function
splitfilename
(
full
)
27
local
split
=
filenametotable
(
full
)
28
local
path
=
split
.
path
29
setcount
(
"
splitoffkind
"
,
(
path
=
=
"
"
and
0
)
or
(
path
=
=
'
.
'
and
1
)
or
2
)
30
setmacro
(
"
splitofffull
"
,
full
or
"
"
)
31
setmacro
(
"
splitoffpath
"
,
path
or
"
"
)
32
setmacro
(
"
splitoffname
"
,
split
.
name
or
"
"
)
33
setmacro
(
"
splitoffbase
"
,
split
.
base
or
"
"
)
34
setmacro
(
"
splitofftype
"
,
split
.
suffix
or
"
"
)
35
end
36 37
local
function
isparentfile
(
name
)
38
return
39
name
=
=
environment
.
jobname
40
or
name
=
=
environment
.
jobname
.
.
'
.tex
'
41
or
name
=
=
environment
.
outputfilename
42
end
43 44
local
function
istexfile
(
name
)
45
local
name
=
name
and
findtexfile
(
name
)
46
return
name
~
=
"
"
and
name
47
end
48 49
implement
{
name
=
"
splitfilename
"
,
actions
=
splitfilename
,
arguments
=
"
string
"
}
50
implement
{
name
=
"
doifelseparentfile
"
,
actions
=
{
isparentfile
,
commands_doifelse
}
,
arguments
=
"
string
"
}
51
implement
{
name
=
"
doifelsepathexist
"
,
actions
=
{
lfs
.
isdir
,
commands_doifelse
}
,
arguments
=
"
string
"
}
52
implement
{
name
=
"
doifelsefileexist
"
,
actions
=
{
istexfile
,
commands_doifelse
}
,
arguments
=
"
string
"
}
53