Unnamed Fossil Project

Check-in [5e0dd8d9d5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Zaciname!
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5e0dd8d9d5284b6530414ab9e517b0eafe6fdb03
User & Date: Yasha 2014-03-16 14:18:54
Context
2014-04-21
15:54
Pridany dalsi casti. check-in: 55525ed0a6 user: Yasha tags: trunk
2014-03-16
14:18
Zaciname! check-in: 5e0dd8d9d5 user: Yasha tags: trunk
14:17
initial empty check-in check-in: f10db920de user: Yasha tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added lib/cmdline.lua.















































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
-- started: 2008-04-12 by Shmuel Zeigerman
-- license: public domain

local ipairs,pairs,setfenv,tonumber,loadstring,type =
  ipairs,pairs,setfenv,tonumber,loadstring,type
local tinsert, tconcat = table.insert, table.concat
module(...)

local function commonerror (msg)
  return nil, ("[cmdline]: " .. msg)
end

local function argerror (msg, numarg)
  msg = msg and (": " .. msg) or ""
  return nil, ("[cmdline]: bad argument #" .. numarg .. msg)
end

local function iderror (numarg)
  return argerror("ID not valid", numarg)
end

local function idcheck (id)
  return id:match("^[%a_][%w_]*$") and true
end

--[[------------------------------------------------------------------------
Syntax:
  t_out = getparam(t_in [,options] [,params])

Parameters:
  t_in:   table - list of string arguments to be processed in order
          (usually it is the `arg' table created by the Lua interpreter).

     * if an argument begins with $, the $ is skipped and the rest is inserted
       into the array part of the output table.

     * if an argument begins with -, the rest is a sequence of variables
       (separated by commas or semicolons) that are all set to true;
            example: -var1,var2  --> var1,var2 = true,true

     * if an argument begins with !, the rest is a Lua chunk;
            example: !a=(40+3)*5;b=20;name="John";window={w=600,h=480}

     * if an argument contains =, then it is an assignment in the form
       var1,...=value (no space is allowed around the =)
         * if value begins with $, the $ is skipped, the rest is a string
                 example: var1,var2=$         --> var1,var2 = "",""
                 example: var1,var2=$125      --> var1,var2 = "125","125"
                 example: var1,var2=$$125     --> var1,var2 = "$125","$125"
         * if value is convertible to number, it is a number
                 example: var1,var2=125       --> var1,var2 = 125,125
         * otherwise it is a string
                 example: name=John           --> name = "John"

     * if an argument neither begins with one of the special characters (-,!,$),
       nor contains =, it is inserted as is into the array part of the output
       table.

  options (optional): a list of names of all command-line options and parameters
     permitted in the application; used to check that each found option
     is valid; no checks are done if not supplied.

  params (optional): a list of names of all command-line parameters required
     by the application; used to check that each required parameter is present;
     no checks are done if not supplied.

Returns:
  On success: the output table, e.g. { [1]="./myfile.txt", name="John", age=40 }
  On error: nil followed by error message string.

--]]------------------------------------------------------------------------
function getparam (t_in, options, params)
  local t_out = {}
  for i,v in ipairs(t_in) do
    local prefix, command = v:sub(1,1), v:sub(2)
    if prefix == "$" then
      tinsert(t_out, command)
    elseif prefix == "-" then
      for id in command:gmatch"[^,;]+" do
        if not idcheck(id) then return iderror(i) end
        t_out[id] = true
      end
    elseif prefix == "!" then
      local f, err = loadstring(command)
      if not f then return argerror(err, i) end
      setfenv(f, t_out)()
    elseif v:find("=") then
      local ids, val = v:match("^([^=]+)%=(.*)") -- no space around =
      if not ids then return argerror("invalid assignment syntax", i) end
      val = val:sub(1,1)=="$" and val:sub(2) or tonumber(val) or val
      for id in ids:gmatch"[^,;]+" do
        if not idcheck(id) then return iderror(i) end
        t_out[id] = val
      end
    else
      tinsert(t_out, v)
    end
  end
  if options then
    local lookup, unknown = {}, {}
    for _,v in ipairs(options) do lookup[v] = true end
    for k,_ in pairs(t_out) do
      if lookup[k]==nil and type(k)=="string" then tinsert(unknown, k) end
    end
    if #unknown > 0 then
      return commonerror("unknown options: " .. tconcat(unknown, ", "))
    end
  end
  if params then
    local missing = {}
    for _,v in ipairs(params) do
      if t_out[v]==nil then tinsert(missing, v) end
    end
    if #missing > 0 then
      return commonerror("missing parameters: " .. tconcat(missing, ", "))
    end
  end
  return t_out
end

Added lib/format/kockopes/html.lua.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
local tags = {}

tags['<mode>'] = 'simple'

-- tags.p = 

return tags

Added lib/serpent.lua.

































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
local n, v = "serpent", 0.272 -- (C) 2012-13 Paul Kulchenko; MIT License
local c, d = "Paul Kulchenko", "Lua serializer and pretty printer"
local snum = {[tostring(1/0)]='1/0 --[[math.huge]]',[tostring(-1/0)]='-1/0 --[[-math.huge]]',[tostring(0/0)]='0/0'}
local badtype = {thread = true, userdata = true, cdata = true}
local keyword, globals, G = {}, {}, (_G or _ENV)
for _,k in ipairs({'and', 'break', 'do', 'else', 'elseif', 'end', 'false',
	'for', 'function', 'goto', 'if', 'in', 'local', 'nil', 'not', 'or', 'repeat',
	'return', 'then', 'true', 'until', 'while'}) do keyword[k] = true end
for k,v in pairs(G) do globals[v] = k end -- build func to name mapping
for _,g in ipairs({'coroutine', 'debug', 'io', 'math', 'string', 'table', 'os'}) do
	for k,v in pairs(G[g] or {}) do globals[v] = g..'.'..k end end

local function s(t, opts)
	local name, indent, fatal, maxnum = opts.name, opts.indent, opts.fatal, opts.maxnum
	local sparse, custom, huge = opts.sparse, opts.custom, not opts.nohuge
	local space, maxl = (opts.compact and '' or ' '), (opts.maxlevel or math.huge)
	local iname, comm = '_'..(name or ''), opts.comment and (tonumber(opts.comment) or math.huge)
	local seen, sref, syms, symn = {}, {'local '..iname..'={}'}, {}, 0
	local function gensym(val) return '_'..(tostring(tostring(val)):gsub("[^%w]",""):gsub("(%d%w+)",
		-- tostring(val) is needed because __tostring may return a non-string value
		function(s) if not syms[s] then symn = symn+1; syms[s] = symn end return syms[s] end)) end
	local function safestr(s) return type(s) == "number" and (huge and snum[tostring(s)] or s)
			or type(s) ~= "string" and tostring(s) -- escape NEWLINE/010 and EOF/026
			or ("%q"):format(s):gsub("\010","n"):gsub("\026","\\026") end
	local function comment(s,l) return comm and (l or 0) < comm and ' --[['..tostring(s)..']]' or '' end
	local function globerr(s,l) return globals[s] and globals[s]..comment(s,l) or not fatal
			and safestr(select(2, pcall(tostring, s))) or error("Can't serialize "..tostring(s)) end
	local function safename(path, name) -- generates foo.bar, foo[3], or foo['b a r']
		local n = name == nil and '' or name
		local plain = type(n) == "string" and n:match("^[%l%u_][%w_]*$") and not keyword[n]
		local safe = plain and n or '['..safestr(n)..']'
		return (path or '')..(plain and path and '.' or '')..safe, safe end
	local alphanumsort = type(opts.sortkeys) == 'function' and opts.sortkeys or function(k, o, n) -- k=keys, o=originaltable, n=padding
		local maxn, to = tonumber(n) or 12, {number = 'a', string = 'b'}
		local function padnum(d) return ("%0"..maxn.."d"):format(d) end
		table.sort(k, function(a,b)
		-- sort numeric keys first: k[key] is not nil for numerical keys
			return (k[a] ~= nil and 0 or to[type(a)] or 'z')..(tostring(a):gsub("%d+",padnum))
					< (k[b] ~= nil and 0 or to[type(b)] or 'z')..(tostring(b):gsub("%d+",padnum)) end) end
	local function val2str(t, name, indent, insref, path, plainindex, level)
		local ttype, level, mt = type(t), (level or 0), getmetatable(t)
		local spath, sname = safename(path, name)
		local tag = plainindex and
				((type(name) == "number") and '' or name..space..'='..space) or
				(name ~= nil and sname..space..'='..space or '')
		if seen[t] then -- already seen this element
			sref[#sref+1] = spath..space..'='..space..seen[t]
			return tag..'nil'..comment('ref', level) end
		if type(mt) == 'table' and (mt.__serialize or mt.__tostring) then -- knows how to serialize itself
			seen[t] = insref or spath
			if mt.__serialize then t = mt.__serialize(t) else t = tostring(t) end
			ttype = type(t) end -- new value falls through to be serialized
		if ttype == "table" then
			if level >= maxl then return tag..'{}'..comment('max', level) end
			seen[t] = insref or spath
			if next(t) == nil then return tag..'{}'..comment(t, level) end -- table empty
			local maxn, o, out = math.min(#t, maxnum or #t), {}, {}
			for key = 1, maxn do o[key] = key end
			if not maxnum or #o < maxnum then
				local n = #o -- n = n + 1; o[n] is much faster than o[#o+1] on large tables
				for key in pairs(t) do if o[key] ~= key then n = n + 1; o[n] = key end end end
			if maxnum and #o > maxnum then o[maxnum+1] = nil end
			if opts.sortkeys and #o > maxn then alphanumsort(o, t, opts.sortkeys) end
			local sparse = sparse and #o > maxn -- disable sparsness if only numeric keys (shorter output)
			for n, key in ipairs(o) do
				local value, ktype, plainindex = t[key], type(key), n <= maxn and not sparse
				if opts.valignore and opts.valignore[value] -- skip ignored values; do nothing
						or opts.keyallow and not opts.keyallow[key]
						or opts.valtypeignore and opts.valtypeignore[type(value)] -- skipping ignored value types
						or sparse and value == nil then -- skipping nils; do nothing
				elseif ktype == 'table' or ktype == 'function' or badtype[ktype] then
					if not seen[key] and not globals[key] then
						sref[#sref+1] = 'placeholder'
						local sname = safename(iname, gensym(key)) -- iname is table for local variables
						sref[#sref] = val2str(key,sname,indent,sname,iname,true) end
					sref[#sref+1] = 'placeholder'
					local path = seen[t]..'['..(seen[key] or globals[key] or gensym(key))..']'
					sref[#sref] = path..space..'='..space..(seen[value] or val2str(value,nil,indent,path))
				else
					out[#out+1] = val2str(value,key,indent,insref,seen[t],plainindex,level+1)
				end
			end
			local prefix = string.rep(indent or '', level)
			local head = indent and '{\n'..prefix..indent or '{'
			local body = table.concat(out, ','..(indent and '\n'..prefix..indent or space))
			local tail = indent and "\n"..prefix..'}' or '}'
			return (custom and custom(tag,head,body,tail) or tag..head..body..tail)..comment(t, level)
		elseif badtype[ttype] then
			seen[t] = insref or spath
			return tag..globerr(t, level)
		elseif ttype == 'function' then
			seen[t] = insref or spath
			local ok, res = pcall(string.dump, t)
			local func = ok and ((opts.nocode and "function() --[[..skipped..]] end" or
					"((loadstring or load)("..safestr(res)..",'@serialized'))")..comment(t, level))
			return tag..(func or globerr(t, level))
		else return tag..safestr(t) end -- handle all other types
	end
	local sepr = indent and "\n" or ";"..space
	local body = val2str(t, name, indent) -- this call also populates sref
	local tail = #sref>1 and table.concat(sref, sepr)..sepr or ''
	local warn = opts.comment and #sref>1 and space.."--[[incomplete output with shared/self-references skipped]]" or ''
	return not name and body..warn or "do local "..body..sepr..tail.."return "..name..sepr.."end"
end

local function deserialize(data, opts)
	local f, res = (loadstring or load)('return '..data)
	if not f then f, res = (loadstring or load)(data) end
	if not f then return f, res end
	if opts and opts.safe == false then return pcall(f) end

	local count, thread = 0, coroutine.running()
	local h, m, c = debug.gethook(thread)
	debug.sethook(function (e, l) count = count + 1
	if count >= 3 then error("cannot call functions") end
	end, "c")
	local res = {pcall(f)}
	count = 0 -- set again, otherwise it's tripped on the next sethook
	debug.sethook(thread, h, m, c)
	return (table.unpack or unpack)(res)
end

local function merge(a, b) if b then for k,v in pairs(b) do a[k] = v end end; return a; end
return { _NAME = n, _COPYRIGHT = c, _DESCRIPTION = d, _VERSION = v, serialize = s,
	load = deserialize,
	dump = function(a, opts) return s(a, merge({name = '_', compact = true, sparse = true}, opts)) end,
	line = function(a, opts) return s(a, merge({sortkeys = true, comment = true}, opts)) end,
	block = function(a, opts) return s(a, merge({indent = ' ', sortkeys = true, comment = true}, opts)) end }

Added lib/slaxdom.lua.



































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
-- Optional parser that creates a flat DOM from parsing
local SLAXML = require 'slaxml'
function SLAXML:dom(xml,opts)
	if not opts then opts={} end
	local rich = not opts.simple
	local push, pop = table.insert, table.remove
	local stack = {}
	local doc = { type="document", name="#doc", kids={} }
	local current = doc
	local builder = SLAXML:parser{
		startElement = function(name,nsURI)
			local el = { type="element", name=name, kids={}, el=rich and {} or nil, attr={}, nsURI=nsURI, parent=rich and current or nil }
			if current==doc then
				if doc.root then error(("Encountered element '%s' when the document already has a root '%s' element"):format(name,doc.root.name)) end
				doc.root = el
			end
			push(current.kids,el)
			if current.el then push(current.el,el) end
			current = el
			push(stack,el)
		end,
		attribute = function(name,value,nsURI)
			if not current or current.type~="element" then error(("Encountered an attribute %s=%s but I wasn't inside an element"):format(name,value)) end
			local attr = {type='attribute',name=name,nsURI=nsURI,value=value,parent=rich and current or nil}
			if rich then current.attr[name] = value end
			push(current.attr,attr)
		end,
		closeElement = function(name)
			if current.name~=name or current.type~="element" then error(("Received a close element notification for '%s' but was inside a '%s' %s"):format(name,current.name,current.type)) end
			pop(stack)
			current = stack[#stack]
		end,
		text = function(value)
			if current.type~='document' then
				if current.type~="element" then error(("Received a text notification '%s' but was inside a %s"):format(value,current.type)) end
				push(current.kids,{type='text',name='#text',value=value,parent=rich and current or nil})
			end
		end,
		comment = function(value)
			push(current.kids,{type='comment',name='#comment',value=value,parent=rich and current or nil})
		end,
		pi = function(name,value)
			push(current.kids,{type='pi',name=name,value=value,parent=rich and current or nil})
		end
	}
	builder:parse(xml,opts)
	return doc
end
return SLAXML

Added lib/slaxml.lua.



































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
--[=====================================================================[
v0.5.3 Copyright © 2013 Gavin Kistner <!@phrogz.net>; MIT Licensed
See http://github.com/Phrogz/SLAXML for details.
--]=====================================================================]
local SLAXML = {
	VERSION = "0.5.3",
	_call = {
		pi = function(target,content)
			print(string.format("<?%s %s?>",target,content))
		end,
		comment = function(content)
			print(string.format("<!-- %s -->",content))
		end,
		startElement = function(name,nsURI)
			print(string.format("<%s%s>",name,nsURI and (" ("..nsURI..")") or ""))
		end,
		attribute = function(name,value,nsURI)
			print(string.format(" %s=%q%s",name,value,nsURI and (" ("..nsURI..")") or ""))
		end,
		text = function(text)
			print(string.format(" text: %q",text))
		end,
		closeElement = function(name,nsURI)
			print(string.format("</%s>",name))
		end,
	}
}

function SLAXML:parser(callbacks)
	return { _call=callbacks or self._call, parse=SLAXML.parse }
end

function SLAXML:parse(xml,options)
	if not options then options = { stripWhitespace=false } end

	-- Cache references for maximum speed
	local find, sub, gsub, char, push, pop = string.find, string.sub, string.gsub, string.char, table.insert, table.remove
	local first, last, match1, match2, match3, pos2, nsURI
	local unpack = unpack or table.unpack
	local pos = 1
	local state = "text"
	local textStart = 1
	local currentElement={}
	local currentAttributes={}
	local currentAttributeCt
	local nsStack = {}

	local entityMap = { ["lt"]="<", ["gt"]=">", ["amp"]="&", ["quot"]='"', ["apos"]="'" }
	local entitySwap = function(orig,n,s) return entityMap[s] or n=="#" and char(s) or orig end
	local function unescape(str) return gsub( str, '(&(#?)([%d%a]+);)', entitySwap ) end
	local anyElement = false

	local function finishText()
		if first>textStart and self._call.text then
			local text = sub(xml,textStart,first-1)
			if options.stripWhitespace then
				text = gsub(text,'^%s+','')
				text = gsub(text,'%s+$','')
				if #text==0 then text=nil end
			end
			if text then self._call.text(unescape(text)) end
		end
	end

	local function findPI()
		first, last, match1, match2 = find( xml, '^<%?([:%a_][:%w_.-]*) ?(.-)%?>', pos )
		if first then
			finishText()
			if self._call.pi then self._call.pi(match1,match2) end
			pos = last+1
			textStart = pos
			return true
		end
	end

	local function findComment()
		first, last, match1 = find( xml, '^<!%-%-(.-)%-%->', pos )
		if first then
			finishText()
			if self._call.comment then self._call.comment(match1) end
			pos = last+1
			textStart = pos
			return true
		end
	end

	local function nsForPrefix(prefix)
		if prefix=='xml' then return 'http://www.w3.org/XML/1998/namespace' end -- http://www.w3.org/TR/xml-names/#ns-decl
		for i=#nsStack,1,-1 do if nsStack[i][prefix] then return nsStack[i][prefix] end end
		error(("Cannot find namespace for prefix %s"):format(prefix))
	end

	local function startElement()
		anyElement = true
		first, last, match1 = find( xml, '^<([%a_][%w_.-]*)', pos )
		if first then
			currentElement[2] = nil
			finishText()
			pos = last+1
			first,last,match2 = find(xml, '^:([%a_][%w_.-]*)', pos )
			if first then
				currentElement[1] = match2
				currentElement[2] = nsForPrefix(match1)
				match1 = match2
				pos = last+1
			else
				currentElement[1] = match1
				for i=#nsStack,1,-1 do if nsStack[i]['!'] then currentElement[2] = nsStack[i]['!']; break end end
			end
			currentAttributeCt = 0
			push(nsStack,{})
			return true
		end
	end

	local function findAttribute()
		first, last, match1 = find( xml, '^%s+([:%a_][:%w_.-]*)%s*=%s*', pos )
		if first then
			pos2 = last+1
			first, last, match2 = find( xml, '^"([^<"]*)"', pos2 ) -- FIXME: disallow non-entity ampersands
			if first then
				pos = last+1
				match2 = unescape(match2)
			else
				first, last, match2 = find( xml, "^'([^<']*)'", pos2 ) -- FIXME: disallow non-entity ampersands
				if first then
					pos = last+1
					match2 = unescape(match2)
				end
			end
		end
		if match1 and match2 then
			local currentAttribute = {match1,match2}
			local prefix,name = string.match(match1,'^([^:]+):([^:]+)$')
			if prefix then
				if prefix=='xmlns' then
					nsStack[#nsStack][name] = match2
				else
					currentAttribute[1] = name
					currentAttribute[3] = nsForPrefix(prefix)
				end
			else
				if match1=='xmlns' then
					nsStack[#nsStack]['!'] = match2
					currentElement[2] = match2
				end
			end
			currentAttributeCt = currentAttributeCt + 1
			currentAttributes[currentAttributeCt] = currentAttribute
			return true
		end
	end

	local function findCDATA()
		first, last, match1 = find( xml, '^<!%[CDATA%[(.-)%]%]>', pos )
		if first then
			finishText()
			if self._call.text then self._call.text(match1) end
			pos = last+1
			textStart = pos
			return true
		end
	end

	local function closeElement()
		first, last, match1 = find( xml, '^%s*(/?)>', pos )
		if first then
			state = "text"
			pos = last+1
			textStart = pos

			if self._call.startElement then self._call.startElement(unpack(currentElement)) end
			if self._call.attribute then for i=1,currentAttributeCt do self._call.attribute(unpack(currentAttributes[i])) end end

			if match1=="/" then
				pop(nsStack)
				if self._call.closeElement then self._call.closeElement(unpack(currentElement)) end
			end
			return true
		end
	end

	local function findElementClose()
		first, last, match1, match2 = find( xml, '^</([%a_][%w_.-]*)%s*>', pos )
		if first then
			nsURI = nil
			for i=#nsStack,1,-1 do if nsStack[i]['!'] then nsURI = nsStack[i]['!']; break end end
		else
			first, last, match2, match1 = find( xml, '^</([%a_][%w_.-]*):([%a_][%w_.-]*)%s*>', pos )
			if first then nsURI = nsForPrefix(match2) end
		end
		if first then
			finishText()
			if self._call.closeElement then self._call.closeElement(match1,nsURI) end
			pos = last+1
			textStart = pos
			pop(nsStack)
			return true
		end
	end

	while pos<#xml do
		if state=="text" then
			if not (findPI() or findComment() or findCDATA() or findElementClose()) then
				if startElement() then
					state = "attributes"
				else
					first, last = find( xml, '^[^<]+', pos )
					pos = (first and last or pos) + 1
				end
			end
		elseif state=="attributes" then
			if not findAttribute() then
				if not closeElement() then
					error("Was in an element and couldn't find attributes or the close.")
				end
			end
		end
	end

	if not anyElement then error("Parsing did not discover any elements") end
	if #nsStack > 0 then error("Parsing ended with unclosed elements") end
end

return SLAXML

Added lib/xmlcodec.lua.













































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
-- Severak XML codec
local xmlcodec = {}
local slaxml = require 'slaxml'
local push = table.insert
local pop = table.remove
local current = {}

local function last(t)
	if #t>0 then
		return t[#t]
	else
		return nil
	end
end

local parser = slaxml:parser{
	startElement = function(name,nsURI)
		local elem = {[0]=name }
		if current.elem then
			push(current.elem, elem) -- add children if we have parent
		end
		current.elem = elem
		push(current.stack, elem) -- push elem for reuse
		if not current.root then
			current.root = elem
		end
	end,
	attribute = function(name,value,nsURI)
		current.elem[name] = value
	end,
	closeElement = function(name)
		pop(current.stack)
		current.elem = last(current.stack) -- set parent elem as current
	end,
	text = function(value)
		push(current.elem or {}, value)
	end,
	comment = function(value)
		-- push(current.kids,{type='comment',name='#comment',value=value,parent=rich and current or nil})
	end,
	pi = function(name,value)
		-- push(current.kids,{type='pi',name=name,value=value,parent=rich and current or nil})
	end
}

function xmlcodec.parse(txt)
	current.elem = nil
	current.root = nil
	current.stack = {}
	parser:parse(txt, {stripWhitespace=true})
	return current.root
end

return xmlcodec

Added svidoc.bat.









>
>
>
>
1
2
3
4
@echo off
SET svidir=%~dp0
SET LUA_PATH=%svidir%lib\?.lua;;
%svidir%bin\lua52 %svidir%svidoc.lua %*

Added svidoc.lua.





































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
local cmdline = require 'cmdline'
local xmlcodec = require 'xmlcodec'
local serpent = require 'serpent'

local function check_args(args)
	-- todo
end

local fmt_proto = {
	['<mode>'] = 'simple',
	['<start>'] = function() end,
	['<stop>'] = function() end,
	['<text>'] = function(text) 
		return text
	end,
	['<unknown>'] = function(name) 
		error(string.format('Unknown tag "%s" found!', name or '<unknown>'))
	end
}

local fmt_mt = {__index = fmt_proto}

local function load_format(name)
	local ok, fmt = pcall(require, 'format.'..name)
	if not ok then
		error(string.format('Format "%s" nenalezen!\n\n%s', name, fmt))
	end
	return setmetatable(fmt, fmt_mt)
end

local push = table.insert

local function process_node(node, tags, output)
	local ret = nil
	print(tags.ok)
	local mode = tags['<mode>']
	if type(node)=='table' then
		local tagname = node[0] or '<???>'
		local def = tags[tagname]
		if not def then
			tags['<unknown>'](tagname, node)
		else
			if type(def)=='table' then
				-- todo
			elseif type(def)=='function' then
				-- todo
			elseif type(def)=='string' then
				-- todo
			end
		end
	elseif type(node)=='string' then
		ret = tags['<text>'](node)
		if mode=='simple' then
			push(output, ret)
		end
	end
end

-- local function process_xml(xml, tags, args)
-- 	local push = table.insert
-- end

local function main(arg)
	local args = cmdline.getparam(arg)
	if not args.f then
		error('Zadejte nazev formatu! (f=xxx)')
	end
	local fmt = load_format(args.f)
	if not args.i then
		error('Zadejte nazev vstupniho souboru! (i=xxx)')
	end
	local xmlf = io.open(args.i)
	if not xmlf then
		error(string.format('Vstupni soubor "%s" nenalezen!', args.i))
	end
	local xml = xmlcodec.parse(xmlf:read('*a'))
	local out = {}
	process_node(xml, fmt, out)
	print(table.concat(out))
end

main(arg)