summaryrefslogtreecommitdiff
path: root/Master/texmf/scripts
diff options
context:
space:
mode:
authorManuel Pégourié-Gonnard <mpg@elzevir.fr>2008-07-29 00:11:22 +0000
committerManuel Pégourié-Gonnard <mpg@elzevir.fr>2008-07-29 00:11:22 +0000
commitdf4a62a2045d0e17bd4fb670691e2785f0ba7f0b (patch)
treef68f8880177dabab1be7db3e11bda5cb87128c59 /Master/texmf/scripts
parentdc0ce3c0c5831ad7081a0329abeb473cbf257fdc (diff)
rework boolean config values
git-svn-id: svn://tug.org/texlive/trunk@9857 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf/scripts')
-rwxr-xr-xMaster/texmf/scripts/texlive/texdoc.tlu60
1 files changed, 34 insertions, 26 deletions
diff --git a/Master/texmf/scripts/texlive/texdoc.tlu b/Master/texmf/scripts/texlive/texdoc.tlu
index cfc64747680..9836755c76e 100755
--- a/Master/texmf/scripts/texlive/texdoc.tlu
+++ b/Master/texmf/scripts/texlive/texdoc.tlu
@@ -87,9 +87,6 @@ end
-- BEGIN kpse-like
--- temporary, will be an option soon
-no_regex = true
-
-- get global texdocs, do_recurse and must_have_lsr lists from kpse's $TEXDOCS
function get_texdocs ()
local sep = (os.type == 'window') and ';' or ':'
@@ -252,8 +249,9 @@ end
-- functions to set config values and aliases
---------------------------------------------
--- set a value without overwriting if already set
-function set_config_element (key, value)
+-- set a value without overwriting if already set and
+-- using to special types: *_list and *_switch
+function set_config_element (key, value, file, line)
if config[key] == nil then
if string.match(key, '_list$') then
-- this is actually a coma-separeted list of values
@@ -263,6 +261,20 @@ function set_config_element (key, value)
values[i] = string.gsub(j, '^%s*', '')
end
config[key] = values
+ elseif string.find (key, '_switch$') then
+ local val = string.lower(value)
+ if val == 'true' then
+ config[key] = true
+ elseif val == 'false' then
+ config[key] = false
+ else
+ io.write ('texdoc warning: illegal value '..value..' for '
+ ..key)
+ if file and line then
+ io.write ('\nin '..file..' line '..line)
+ end
+ io.write ('. Skipping.\n')
+ end
else
config[key] = value
end
@@ -296,7 +308,7 @@ function setup_config_from_cl ()
print (progname .. ' version: ' .. version )
os.exit(0)
elseif (curr_arg == '-v') or (curr_arg == '--verbose') then
- verbose = true
+ set_config_element('verbose_switch', 'true')
elseif (curr_arg == '-w') or (curr_arg == '--view') then
set_config_element('mode', 'view')
elseif (curr_arg == '-m') or (curr_arg == '--mixed') then
@@ -308,13 +320,13 @@ function setup_config_from_cl ()
elseif (curr_arg == '-r') or (curr_arg == '--regex') then
set_config_element ('mode', 'regex')
elseif (curr_arg == '-I') or (curr_arg == '--nointeractive') then
- set_config_element('interactive', 'false')
+ set_config_element('interactive_switch', 'false')
elseif (curr_arg == '-i') or (curr_arg == '--interactive') then
- set_config_element('interactive', 'true')
+ set_config_element('interactive_switch', 'true')
elseif (curr_arg == '-A') or (curr_arg == '--noalias') then
- set_config_element('enable_alias', 'false')
+ set_config_element('alias_switch', 'false')
elseif (curr_arg == '-a') or (curr_arg == '--alias') then
- set_config_element('enable_alias', 'true')
+ set_config_element('alias_switch', 'true')
elseif string.match(curr_arg, '^-e') then
set_config_element('ext_list',
string.gsub(curr_arg, '^-e=?', ''))
@@ -327,7 +339,7 @@ function setup_config_from_cl ()
end
end
--- the default value af config.enable_alias depends on the mode as follows
+-- the default value af config.alias_switch depends on the mode as follows
function alias_from_mode (mode)
if (mode == 'view') or (mode == 'mixed') or (mode == 'list') then
return 'true'
@@ -362,7 +374,7 @@ function read_config_file(configfile)
line = string.gsub(line, '^%s*', '') -- remove leading spaces
key, val=string.match(line, '^([%a%d_]+)%s*=%s*(.+)')
if key and val then
- set_config_element(key, val)
+ set_config_element(key, val, configfile, lineno)
else
key, val = string.match(line, '^alias%s+([%a%d_-]+)%s*=%s*(.+)')
if key and val then
@@ -490,12 +502,12 @@ function setup_config_from_defaults()
end
-- then various stuff
set_config_list {
- mode = 'view',
- verbose = 'false',
- interactive = 'true',
+ mode = 'view',
+ verbose_switch = 'false',
+ interactive_switch = 'true',
}
-- must be set after mode!
- set_config_element ('enable_alias', alias_from_mode(config.mode))
+ set_config_element ('alias_switch', alias_from_mode(config.mode))
-- now a particular case for config.ext_list and zip-related stuff
-- Note: removed texdoc_formats/zip_formats, gives simpler & generic code
if support_zipped then
@@ -576,7 +588,7 @@ function try_viewing (view_command, viewer_replacement)
else
view_command = view_command..' "'..viewer_replacement..'"'
end
- if verbose then
+ if config.verbose_switch then
print(view_command)
end
view_result = os.execute(view_command)
@@ -640,7 +652,7 @@ function display_table (t, offset)
offset = offset or 0
table.sort(t, file_order)
for i, val in ipairs (t) do
- if interactive then
+ if config.interactive_switch then
print (i+offset, real_path(val))
else
print (real_path(val))
@@ -653,7 +665,7 @@ function print_menu (files, comp)
comp = comp or {}
max_lines = tonumber (config.max_lines) or 20
local f = #files
- if interactive then
+ if config.interactive_switch then
local n = f + #comp
if n > max_lines then
io.write (n, " results. Display them all? (y/N) ")
@@ -663,7 +675,7 @@ function print_menu (files, comp)
end
display_table (files)
display_table (comp, f)
- if interactive then
+ if config.interactive_switch then
io.write ("Please enter the number of the file to view, ",
"anything else to skip: ")
local num = tonumber(io.read('*line'))
@@ -725,17 +737,13 @@ setup_config_from_env ()
setup_config_from_files ()
setup_config_from_defaults ()
--- shortcuts for boolean config option (not very nice, but)
-enable_alias = (config.enable_alias == 'true')
-verbose = (config.verbose == 'true')
-interactive = (config.interactive == 'true')
-
-- the main loop over the args
------------------------------
exit_code = 0
+no_regex = true
for docname in list (arg) do
- if enable_alias and alias[docname] then
+ if config.alias_switch and alias[docname] then
print ("texdoc info: "..docname.." aliased to "..alias[docname])
docname = alias[docname]
end