file-syn.lua /size: 1927 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
file-syn
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to file-syn.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 10
environment
.
filesynonyms
=
environment
.
filesynonyms
or
{
}
11
local
filesynonyms
=
environment
.
filesynonyms
12 13
local
settings_to_array
=
utilities
.
parsers
.
settings_to_array
14
local
findfile
=
resolvers
.
findfile
15 16
local
implement
=
interfaces
.
implement
17 18
storage
.
register
(
"
environment/filesynonyms
"
,
filesynonyms
,
"
environment.filesynonyms
"
)
19 20
local
function
truefilename
(
name
)
21
local
realname
=
filesynonyms
[
name
]
or
name
22
if
realname
~
=
name
then
23
return
truefilename
(
realname
)
24
else
25
return
realname
26
end
27
end
28 29
environment
.
truefilename
=
truefilename
30 31
function
environment
.
definefilesynonym
(
name
,
realname
)
32
local
names
=
settings_to_array
(
name
)
33
for
i
=
1
,
#
names
do
34
local
name
=
names
[
i
]
35
local
synonym
=
filesynonyms
[
name
]
36
if
synonym
then
37
interfaces
.
showmessage
(
"
files
"
,
1
,
{
name
or
"
?
"
,
realname
or
"
?
"
,
synonym
or
"
?
"
}
)
38
end
39
filesynonyms
[
name
]
=
realname
40
end
41
end
42 43
function
environment
.
definefilefallback
(
name
,
alternatives
)
44
local
names
=
settings_to_array
(
alternatives
)
45
for
i
=
1
,
#
names
do
46
local
realname
=
findfile
(
names
[
i
]
)
47
if
realname
~
=
"
"
then
48
filesynonyms
[
name
]
=
realname
49
break
50
end
51
end
52
end
53 54
implement
{
55
name
=
"
truefilename
"
,
56
actions
=
{
truefilename
,
context
}
,
57
arguments
=
"
string
"
58
}
59 60
implement
{
61
name
=
"
definefilesynonym
"
,
62
actions
=
environment
.
definefilesynonym
,
63
arguments
=
"
2 strings
"
64
}
65 66
implement
{
67
name
=
"
definefilefallback
"
,
68
actions
=
environment
,
definefilefallback
,
69
arguments
=
"
2 strings
"
70
}
71