1 -- --- T2-COPYRIGHT-NOTE-BEGIN ---
2 -- This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 -- T2 SDE: misc/lua/sde/desc.lua
5 -- Copyright (C) 2005 - 2006 The T2 SDE Project
6 -- Copyright (C) 2005 - 2006 Juergen "George" Sawinski
8 -- More information can be found in the files COPYING and README.
10 -- This program is free software; you can redistribute it and/or modify
11 -- it under the terms of the GNU General Public License as published by
12 -- the Free Software Foundation; version 2 of the License. A copy of the
13 -- GNU General Public License can be found in the file COPYING.
14 -- --- T2-COPYRIGHT-NOTE-END ---
17 -- - parser should also accept string as input
18 -- - implement the desc.validator
21 -- t = desc.parse(line-iterator)
22 -- Parse ".desc" file format by passing a line iterator and
23 -- return a table, where lower-case of last entry in
25 -- is the key. Example:
26 -- Parsing "[I] Title" returns `{ title = "Title" }'
28 -- package object structure
32 -- FIXME setmetatable(desc, { __call = function })
34 -- parse .desc text ; expects line iterator function as argument
36 -- no, actually it expects a FILENAME. who changed that back again ?
37 -- Please do not touch that often, because this code is used in production environment
39 function desc
.parse(iter
)
42 -- FIXME: Perhaps we'll gain some performance by not reading
45 for line
in file
:lines() do
48 _
,_
,tag,cnt
= string.find(line
, "([[][^]]*[]])[ ]+(.*)")
50 local fmt
= desc
.__format__
[tag]
52 retval
[fmt
.name
] = retval
[fmt
.name
] or {}
53 table.insert(retval
[fmt
.name
], cnt
)
61 -- similar to desc.parse, but validate the description
62 function desc
.validate(iter
)
63 local retval
= desc
.parse(iter
)
65 -- TODO implement validating
70 -- init: parse PKG-DESC-FORMAT
71 for line
in io
.open("misc/share/PKG-DESC-FORMAT"):lines() do
75 if string.match(line
, "^[[]") ~= nil then
76 -- check if tag is required
77 if string.match(line
, "([*])") ~= nil then required
=true; end
79 -- use last tag definition as name
80 for t
in string.gfind(line
,"[[]([^]]*)[]]") do tag = t
; end
81 tag = string.lower(tag)
83 -- sort into __format__
84 for t
in string.gfind(line
,"([[][^]]*[]])") do
85 desc
.__format__
[t
] = { name
= tag; required
= required
}