diff options
author | Karl Berry <karl@freefriends.org> | 2020-02-02 22:44:20 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2020-02-02 22:44:20 +0000 |
commit | 57bf353019ba7087c6b8ab64205abb88139ba4c4 (patch) | |
tree | fd5d11df7c68334269283b00e29494e307a7b525 /Master/texmf-dist/scripts/texdoc/texdoclib-cli.tlu | |
parent | 698edf65b4e683cfffd9f8d442edd59683f48d1f (diff) |
texdoc (2feb20)
git-svn-id: svn://tug.org/texlive/trunk@53643 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/texdoc/texdoclib-cli.tlu')
-rwxr-xr-x | Master/texmf-dist/scripts/texdoc/texdoclib-cli.tlu | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/Master/texmf-dist/scripts/texdoc/texdoclib-cli.tlu b/Master/texmf-dist/scripts/texdoc/texdoclib-cli.tlu index 3de786ef2c8..95a43b7ddd9 100755 --- a/Master/texmf-dist/scripts/texdoc/texdoclib-cli.tlu +++ b/Master/texmf-dist/scripts/texdoc/texdoclib-cli.tlu @@ -4,11 +4,11 @@ -- dependencies local texdoc = { - const = require('texdoclib-const'), - util = require('texdoclib-util'), - config = require('texdoclib-config'), - search = require('texdoclib-search'), - view = require('texdoclib-view'), + const = require 'texdoclib-const', + util = require 'texdoclib-util', + config = require 'texdoclib-config', + search = require 'texdoclib-search', + view = require 'texdoclib-view', } -- shortcuts @@ -21,7 +21,7 @@ local err_print = texdoc.util.err_print -- modified Alternative GetOpt -- cf. http://lua-users.org/wiki/AlternativeGetOpt local function getopt(arg, options) - local tmp + local tmp = nil local tab = {} local saved_arg = {table.unpack(arg)} @@ -30,25 +30,36 @@ local function getopt(arg, options) table.remove(arg, 1) local x = string.find(v, '=', 1, true) if x then - table.insert(tab, {string.sub(v, 3, x-1), string.sub(v, x+1)}) + table.insert(tab, {string.sub(v, 3, x - 1), string.sub(v, x+1)}) else table.insert(tab, {string.sub(v, 3), true}) end + elseif string.sub(v, 1, 1) == '-' then table.remove(arg, 1) local y = 2 local l = string.len(v) local jopt + while (y <= l) do jopt = string.sub(v, y, y) + if string.find(options, jopt, 1, true) then if y < l then - tmp = string.sub(v, y+1) + tmp = string.sub(v, y + 1) y = l else table.remove(arg, 1) tmp = saved_arg[k + 1] end + + -- check the existence of an argument + if not tmp then + err_print('error', + 'Option -%s requires an argument.', jopt) + os.exit(C.exit_error) + end + if string.match(tmp, '^%-') then table.insert(tab, {jopt, false}) else @@ -59,6 +70,9 @@ local function getopt(arg, options) end y = y + 1 end + + else + if tmp then tmp = nil else break end end end @@ -67,7 +81,6 @@ end local function parse_options() local curr_arg - local action = true local cl_config = {} local function insert_cl_config(key, val, opt_name) @@ -87,13 +100,13 @@ local function parse_options() -- action if (curr_arg == '-h') or (curr_arg == '--help') then - action = 'help' + return true, 'help', cl_config elseif (curr_arg == '-V') or (curr_arg == '--version') then - action = 'version' + return true, 'version', cl_config elseif (curr_arg == '-f') or (curr_arg == '--files') then - action = 'files' + return true, 'files', cl_config elseif curr_arg == '--just-view' then - action = 'view' + return true, 'view', cl_config -- mode elseif (curr_arg == '-w') or (curr_arg == '--view') then @@ -117,8 +130,7 @@ local function parse_options() -- config elseif curr_arg == '-c' then - local item, value = string.match(v, '^([%a%d_]+)%s*=%s*(.+)') - insert_cl_config(item, value, curr_arg) + insert_cl_config(v, nil, curr_arg) -- debug elseif (curr_arg == '-d') or (curr_arg == '--debug') then @@ -141,7 +153,7 @@ local function parse_options() end end - return action, cl_config + return true, action, cl_config end -------------------------- process execution -------------------------- @@ -157,7 +169,7 @@ local function do_action(action) '\n\n' .. C.copyright_msg) os.exit(C.exit_ok) elseif action == 'files' then - print(C.fullname .. ' ' .. C.version) + print(texdoc.util.w32_path(C.fullname) .. ' ' .. C.version) texdoc.config.show_config_files(true) os.exit(C.exit_ok) elseif action == 'view' then @@ -189,9 +201,9 @@ end function M.exec() -- parsing command line options - local action, cl_config = parse_options() + local ok, action, cl_config = parse_options() - if not action then + if not ok then os.exit(C.exit_usage) end |