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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
#! /usr/bin/env texlua
-- texlive/tlpdb.tlu
-- $Id$
--
-- Copyright (C) 2008 Norbert Preining
-- This file is licensed under the GNU General Public License version 2
-- or any later version.
--
-- TODO: tag evaluation of docfiles lines ...
--
-- providing the tlpdb as a lua table
--
-- format
-- tlpobj = tlpdb[packagename]
-- tlpobj.name string
-- tlpobj.revision string
-- tlpobj.category string
-- tlpobj.shortdesc string
-- tlpobj.longdesc string
-- tlpobj.catalogue string
-- tlpobj.cataloguedata table indexed by various catalogue values
-- tlpobj.containersize string
-- tlpobj.srccontainersize string
-- tlpobj.doccontainersize string
-- tlpobj.containerchecksum string
-- tlpobj.srccontainerchecksum string
-- tlpobj.doccontainerchecksum string
-- tlpobj.binfiles table indexed by archs giving table indexed by numbers
-- tlpobj.binsize table indexed by archs giving strings
-- tlpobj.docfiles = table indexed by numbers
-- tlpobj.docfiledata[docfile][tag] = value
-- tlpobj.docsize string
-- tlpobj.srcfiles = table indexed by numbers
-- tlpobj.srcsize string
-- tlpobj.runfiles = table indexed by numbers
-- tlpobj.runsize string
-- tlpobj.depend = table indexed by numbers
-- tlpobj.execute = table of strings indexed by numbers
-- tlpobj.postaction = table of strings indexed by numbers
-- tlpobj.relocated = boolean
--
--*-Lua-*-
function read_tlpdb(root)
local fn = root..'/tlpkg/texlive.tlpdb'
if (lfs.isfile(fn)) then -- tlpdb exists
local lineno = 0 -- current line number
local errline = '' -- current line
local function die(msg)
io.stderr:write(msg..' in '..fn..' at line '..tostring(lineno)
..'\n>>'..errline..'<<\n')
-- for now, exit, but this is bad behaviour if we want to be used
-- as a library. FIXME.
os.exit(1)
end
local started = false
local lastcmd = ""
local arch
local size
local tlpobj = {}
local name
local tlpdb = {}
for line in io.lines(fn) do
lineno = lineno + 1
errline = line
if string.match(line, '^%s*$') then
if started then
-- we have encountered an empty line while creating a tlpobj, so
-- stop that tlpobj, add it to the tlpdb, and restart
--tlpdb[name] = tlpobj
tlpdb[name] = tlpobj
tlpobj = {}
--print ("adding "..name.." to tlpdb")
started = false
end
else
if string.match(line, '^ ') then
if lastcmd == 'runfiles' or
lastcmd == 'binfiles' or
lastcmd == 'docfiles' or
lastcmd == 'srcfiles' or
lastcmd == 'execute' or
lastcmd == 'depend' then
line = string.gsub(line, '^ ', lastcmd.."continued ")
else
die('Continuation of '..lastcmd..' not allowed')
end
end
local first
local rest
first, rest = string.match(line,'^(%S+)%s*(.*)%s*$')
--print ("DEBUG: line = "..line)
--print ("DEBUG: first = "..first)
lastcmd = first
if first == "name" then
tlpobj.name = rest
name = rest
started = true
elseif first == "revision" then
tlpobj.revision = rest
elseif first == "category" then
tlpobj.category = rest
elseif first == "shortdesc" then
tlpobj.shortdesc = rest
elseif first == "catalogue" then
tlpobj.catalogue = rest
elseif string.match(first,'^catalogue%-') then
--local data = string.match(first,'^catalogue-(.*)$')
local cdata = string.gsub(first,'^catalogue%-', '')
--print("DEBUG: cdata = "..cdata..", first = "..first)
if not(tlpobj.cataloguedata) then
tlpobj.cataloguedata = {}
end
tlpobj.cataloguedata[cdata] = rest
elseif first == "containersize" then
tlpobj.containersize = rest
elseif first == "srccontainersize" then
tlpobj.srccontainersize = rest
elseif first == "doccontainersize" then
tlpobj.doccontainersize = rest
elseif first == "containerchecksum" then
tlpobj.containerchecksum = rest
elseif first == "srccontainerchecksum" then
tlpobj.srccontainerchecksum = rest
elseif first == "doccontainerchecksum" then
tlpobj.doccontainerchecksum = rest
elseif first == "runfiles" then
local rsize = string.match(rest,'size=([0-9]*)')
if (rsize) then
tlpobj.runsize = rsize
else
if #rest > 0 then
die('Unknown tag')
end
end
elseif first == "docfiles" then
local dsize = string.match(rest,'size=([0-9]*)')
if (dsize) then
tlpobj.docsize = dsize
else
if #rest > 0 then
die('Unknown tag')
end
end
elseif first == "srcfiles" then
local ssize = string.match(rest,'size=([0-9]*)')
if (ssize) then
tlpobj.srcsize = ssize
else
if #rest > 0 then
die('Unknown tag')
end
end
elseif first == "binfiles" then
arch = ""
local barch
local bsize
for aaa in string.gmatch(rest,'%S+') do
if string.match(aaa,'^arch=(%S*)$') then
barch = string.match(aaa,'^arch=(%S*)$')
elseif string.match(aaa,'^size=(%S*)$') then
bsize = string.match(aaa,'^size=(%S*)$')
else
die('Unknown tag')
end
end
if barch and bsize then
if not(tlpobj.binsize) then
tlpobj.binsize = {}
end
tlpobj.binsize[barch] = bsize
arch = barch
else
die('Incomplete binfile tags ')
end
elseif first == "runfilescontinued" then
if not(tlpobj.runfiles) then
tlpobj.runfiles = {}
end
table.insert(tlpobj.runfiles,rest)
lastcmd = "runfiles"
elseif first == "docfilescontinued" then
local dfile,tags = string.match(rest,'^(%S+)%s*(.*)%s*$')
if not(tlpobj.docfiles) then
tlpobj.docfiles = {}
end
table.insert(tlpobj.docfiles,dfile)
for aaa,bbb in string.gmatch(tags,'(%S+)=(%b"")') do
if not(tlpobj.docfiledata) then
tlpobj.docfiledata = {}
end
if aaa == "details" or aaa == "language" then
if not(tlpobj.docfiledata[dfile]) then
tlpobj.docfiledata[dfile] = {}
end
tlpobj.docfiledata[dfile][aaa] = bbb
else
die('Unknown docfile tag')
end
end
lastcmd = "docfiles"
elseif first == "srcfilescontinued" then
if not(tlpobj.srcfiles) then
tlpobj.srcfiles = {}
end
table.insert(tlpobj.srcfiles,rest)
lastcmd = "srcfiles"
elseif first == "binfilescontinued" then
if not(tlpobj.binfiles) then
tlpobj.binfiles = {}
end
if not(tlpobj.binfiles[arch]) then
tlpobj.binfiles[arch] = {}
end
table.insert(tlpobj.binfiles[arch],rest)
lastcmd = "binfiles"
elseif first == "depend" then
if not(tlpobj.depend) then
tlpobj.depend = {}
end
table.insert(tlpobj.depend,rest)
elseif first == "longdesc" then
if tlpobj.longdesc then
tlpobj.longdesc = tlpobj.longdesc.." "..rest
else
tlpobj.longdesc = rest
end
elseif first == "execute" then
if not(tlpobj.execute) then
tlpobj.execute = {}
end
table.insert(tlpobj.execute,rest)
elseif first == 'postaction' then
tlpobj.postaction = tlpobj.postaction or {}
table.insert(tlpobj.postaction, rest)
elseif first == 'relocated' then
-- don't even try to validate the value
tlpobj.relocated = (rest == '1')
else
die('Unknown directive')
end
if not(first) then
die('Missing directive')
end
end
end
return tlpdb
else
print (fn..' not found.')
end
end
-- Local Variables:
-- lua-indent-level: 2
-- tab-width: 2
-- indent-tabs-mode: nil
-- End:
-- vim:set tabstop=2 shiftwidth=2 expandtab: #
|