3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
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
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
...
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
local default_mode = {
['render:format'] = 'html';
['html:gen-styles'] = true;
}
local function
main(input, output, log, mode, suggestions, vars)
local doc = ct.parse(input.stream, input.src, mode)
input.stream:close()
if mode['parse:show-tree'] then
log:write(ss.dump(doc))
end
-- the document has now had a chance to give its say; if it hasn't specified
-- any modes of its own, we now merge in the 'weak modes' (suggestions)
................................................................................
['mode-set'] = 1;
['mode-clear'] = 1;
mode = 2;
['mode-set-weak'] = 1;
['mode-clear-weak'] = 1;
['mode-weak'] = 2;
}
return param_opts[o] or 0
end
local optmap = {
o = 'out';
l = 'log';
d = 'define';
V = 'version';
h = 'help';
y = 'mode-set', Y = 'mode-set-weak';
n = 'mode-clear', N = 'mode-clear-weak';
m = 'mode', M = 'mode-weak';
}
local checkmodekey = function(key)
if not key:match '[^:]+:.+' then
ct.exns.cli('invalid mode key %s', key):throw()
end
return key
end
................................................................................
mode = function(key,value) mode[checkmodekey(key)] = value end;
['mode-set'] = function(key) mode[checkmodekey(key)] = true end;
['mode-clear'] = function(key) mode[checkmodekey(key)] = false end;
['mode-weak'] = function(key,value) suggestions[checkmodekey(key)] = value end;
['mode-set-weak'] = function(key) suggestions[checkmodekey(key)] = true end;
['mode-clear-weak'] = function(key) suggestions[checkmodekey(key)] = false end;
['version'] = function()
outp:write(ct.info:about())
if next(ct.ext.loaded) then
outp:write('\nactive extensions:\n')
for k,v in pairs(ct.ext.loaded) do
outp:write(string.format(' * %s', v.id ..
(v.version and (' ' .. v.version:string()) or '')))
................................................................................
keepParsing = false
else
local longopt = v:match '^%-%-(.+)$'
if keepParsing and longopt then
execLongOpt(longopt)
else
if keepParsing and v:sub(1,1) == '-' then
for c,p in ss.str.enc.utf8.each(v:sub(2)) do
if optmap[c] then
execLongOpt(optmap[c])
else
ct.exns.cli('switch -%s unrecognized', c):throw()
end
end
else
................................................................................
if args[1] and args[1] ~= '' then
local file = io.open(args[1], "rb")
if not file then error('unable to load file ' .. args[1]) end
input.stream = file
input.src.file = args[1]
end
return main(input, outp, log, mode, suggestions, vars)
end
local ok, e = pcall(entry_cli)
-- local ok, e = true, entry_cli()
if not ok then
local str = 'translation failure'
if ss.exn.is(e) then
str = e.kind.desc
end
local color = false
if log:seek() == nil then
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
<
>
>
>
>
>
|
|
|
|
|
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
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
...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
...
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
...
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
local default_mode = {
['render:format'] = 'html';
['html:gen-styles'] = true;
}
local function
main(input, output, log, mode, suggestions, vars, extrule)
local doc = ct.parse(input.stream, input.src, mode, function(c)
c.doc.ext = extrule
end)
input.stream:close()
if mode['parse:show-tree'] then
log:write(ss.dump(doc))
end
-- the document has now had a chance to give its say; if it hasn't specified
-- any modes of its own, we now merge in the 'weak modes' (suggestions)
................................................................................
['mode-set'] = 1;
['mode-clear'] = 1;
mode = 2;
['mode-set-weak'] = 1;
['mode-clear-weak'] = 1;
['mode-weak'] = 2;
['use'] = 1;
['inhibit'] = 1;
['need'] = 1;
['load'] = 1;
['enc'] = 1;
}
return param_opts[o] or 0
end
local optmap = {
o = 'out';
l = 'log';
d = 'define';
V = 'version';
h = 'help';
y = 'mode-set', Y = 'mode-set-weak';
n = 'mode-clear', N = 'mode-clear-weak';
m = 'mode', M = 'mode-weak';
L = 'load',
u = 'use', i = 'inhibit', r = 'require';
e = 'enc';
}
local extrule = {use={},inhibit={},need={}}
local checkmodekey = function(key)
if not key:match '[^:]+:.+' then
ct.exns.cli('invalid mode key %s', key):throw()
end
return key
end
................................................................................
mode = function(key,value) mode[checkmodekey(key)] = value end;
['mode-set'] = function(key) mode[checkmodekey(key)] = true end;
['mode-clear'] = function(key) mode[checkmodekey(key)] = false end;
['mode-weak'] = function(key,value) suggestions[checkmodekey(key)] = value end;
['mode-set-weak'] = function(key) suggestions[checkmodekey(key)] = true end;
['mode-clear-weak'] = function(key) suggestions[checkmodekey(key)] = false end;
['use' ] = function(ext) extrule.use [ext] = true end;
['inhibit'] = function(ext) extrule.inhibit[ext] = true end;
['require'] = function(ext) extrule.need [ext] = true end;
['load'] = function(extpath) end;
['enc'] = function(enc) end;
['version'] = function()
outp:write(ct.info:about())
if next(ct.ext.loaded) then
outp:write('\nactive extensions:\n')
for k,v in pairs(ct.ext.loaded) do
outp:write(string.format(' * %s', v.id ..
(v.version and (' ' .. v.version:string()) or '')))
................................................................................
keepParsing = false
else
local longopt = v:match '^%-%-(.+)$'
if keepParsing and longopt then
execLongOpt(longopt)
else
if keepParsing and v:sub(1,1) == '-' then
for c,p in ss.str.each(ss.str.enc.utf8, v:sub(2)) do
if optmap[c] then
execLongOpt(optmap[c])
else
ct.exns.cli('switch -%s unrecognized', c):throw()
end
end
else
................................................................................
if args[1] and args[1] ~= '' then
local file = io.open(args[1], "rb")
if not file then error('unable to load file ' .. args[1]) end
input.stream = file
input.src.file = args[1]
end
return main(input, outp, log, mode, suggestions, vars, extrule)
end
-- local ok, e = pcall(entry_cli)
local ok, e = true, entry_cli()
if not ok then
local str = 'translation failure'
if ss.exn.is(e) then
str = e.kind.desc
end
local color = false
if log:seek() == nil then
|