summaryrefslogtreecommitdiff
path: root/tex/context/base/x-dir-05.mkiv
blob: de1d3fa5f268e028380b8dc87e4a05d3c3a35f17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%D \module
%D   [      file=x-dir-05,
%D        version=2003.05.10, % around that time -)
%D          title=\CONTEXT\ Directory Handling,
%D       subtitle=Access,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\setvariables
  [filestate]
  [name=,
   base=,
   type=,
   size=,
   permissions=,
   date=]

% \savefilestate[zip-latest][context/latest/cont-#2.zip]%

% TODO: move to module namespace

\startluacode
    local filestates = { }
    function commands.savefilestate(tag,name)
        if not filestates[tag] then
            local attr = lfs.attributes(name)
            if attr then attr.name = name end
            filestates[tag] = attr
        end
    end
    function commands.getfilestatevariable(tag,name)
        local fs = filestates[tag]
        if fs then
            local value
            if name == "base" then
                value = file.basename(fs.name)
            elseif name == "type" then
                value = file.extname(fs.name)
            elseif name == "date" then
                value = os.date("%Y-%m-%d %H:%M",fs.modification)
            else
                value = fs[name] or ""
            end
            context.sprint(tex.vrbcatcodes,value)
        end
    end
\stopluacode

\def\getfilestatevariable#1#2%
  {\ctxlua{commands.getfilestatevariable("#1","#2")}}

\def\savefilestate
  {\dodoubleargument\dosavefilestate}

\def\dosavefilestate[#1][#2]%
  {\ctxlua{commands.savefilestate("#1","#2")}%
   \setxvariables
     [#1]
     [name={#2},
      base=\getfilestatevariable{#1}{base},
      type=\getfilestatevariable{#1}{type},
      size=\getfilestatevariable{#1}{size},
      date=\getfilestatevariable{#1}{date},
      permissions=\getfilestatevariable{#1}{permissions}]}

\def\getfilestate#1% old one
  {\savefilestate[filestate][#1]}

\endinput