summaryrefslogtreecommitdiff
path: root/support/texdoc/script/texdoclib-cli.tlu
diff options
context:
space:
mode:
Diffstat (limited to 'support/texdoc/script/texdoclib-cli.tlu')
-rw-r--r--support/texdoc/script/texdoclib-cli.tlu32
1 files changed, 18 insertions, 14 deletions
diff --git a/support/texdoc/script/texdoclib-cli.tlu b/support/texdoc/script/texdoclib-cli.tlu
index 5eddc8f7f5..79c202600d 100644
--- a/support/texdoc/script/texdoclib-cli.tlu
+++ b/support/texdoc/script/texdoclib-cli.tlu
@@ -21,32 +21,36 @@ local err_print = texdoc.util.err_print
-- modified Alternative GetOpt
-- cf. http://lua-users.org/wiki/AlternativeGetOpt
local function getopt(arg, options)
- local tmp = nil
+ local tmp
local tab = {}
local saved_arg = {table.unpack(arg)}
for k, v in ipairs(saved_arg) do
- if string.sub(v, 1, 2) == '--' then
+ if v:sub(1, 2) == '--' then
table.remove(arg, 1)
- local x = string.find(v, '=', 1, true)
+ if v == '--' then -- terminate parsing
+ break
+ end
+
+ local x = v:find('=', 1, true)
if x then
- table.insert(tab, {string.sub(v, 3, x - 1), string.sub(v, x+1)})
+ table.insert(tab, {v:sub(3, x - 1), v:sub(x+1)})
else
- table.insert(tab, {string.sub(v, 3), true})
+ table.insert(tab, {v:sub(3), true})
end
- elseif string.sub(v, 1, 1) == '-' then
+ elseif v:sub(1, 1) == '-' then
table.remove(arg, 1)
local y = 2
- local l = string.len(v)
+ local l = v:len()
local jopt
while (y <= l) do
- jopt = string.sub(v, y, y)
+ jopt = v:sub(y, y)
- if string.find(options, jopt, 1, true) then
+ if options:find(jopt, 1, true) then
if y < l then
- tmp = string.sub(v, y + 1)
+ tmp = v:sub(y + 1)
y = l
else
table.remove(arg, 1)
@@ -60,7 +64,7 @@ local function getopt(arg, options)
os.exit(C.exit_error)
end
- if string.match(tmp, '^%-') then
+ if tmp:match('^%-') then
table.insert(tab, {jopt, false})
else
table.insert(tab, {jopt, tmp})
@@ -102,14 +106,14 @@ local function parse_options()
end
for i, o in ipairs(C.options) do
- if k == o["short"] or k == o["long"] then
+ if k == o['short'] or k == o['long'] then
k = i
break
end
end
option = C.options[k]
- if option['group'] == 'action' then
+ if option ~= nil and option['group'] == 'action' then
if option['long'] == 'just-view' then
return true, 'view', cl_config
elseif option['long'] == 'print-completion' then
@@ -117,7 +121,7 @@ local function parse_options()
else
return true, option['long'], cl_config
end
- elseif option['group'] then
+ elseif option~=nil and option['group'] then
if option['type'] == 'boolean' then
option['action'](cl_config, curr_arg)
elseif option['type'] == 'string' then