diff options
Diffstat (limited to 'Master/texmf/scripts/texdoc/config.tlu')
-rw-r--r-- | Master/texmf/scripts/texdoc/config.tlu | 218 |
1 files changed, 66 insertions, 152 deletions
diff --git a/Master/texmf/scripts/texdoc/config.tlu b/Master/texmf/scripts/texdoc/config.tlu index 1e6aa7110b3..7681425e9bb 100644 --- a/Master/texmf/scripts/texdoc/config.tlu +++ b/Master/texmf/scripts/texdoc/config.tlu @@ -1,17 +1,6 @@ --- configuration handling for texdoc ---[[ -Copyright 2008, 2009 Manuel Pégourié-Gonnard -Distributed under the terms of the GNU GPL version 3 or later. -See texdoc.tlu for details. ---]] - --- Load a private environment for this submodule (see texdoc.tlu). -local L = {} -load_env(L, { - 'os', 'kpse', 'lfs', 'io', 'setmetatable', 'print', - 'w32_path', 'confline_to_alias', 'confline_to_score', 'print_usage', - 'config', -}) +-- config.tlu: configuration handling for texdoc +-- +-- Manuel Pégourié-Gonnard, GPLv3, see texdoclib.tlu for details -------------------------- hide the config table --------------------------- @@ -44,7 +33,13 @@ function set_config_element (key, value, context) -- warn and exit if key is not a known option if not is_known then config_warn(key, nil, context, true) return end -- exit if key is already set (/!\ must test for nil, not false) - if not (config[key] == nil) then return nil end + if not (config[key] == nil) then + if context.src ~= 'def' then + deb_print('config', "Ignoring '"..key.."="..value.."' " + ..context_to_string(context)..'.') + end + return nil + end -- record the source of the setting real_set_config(key..'_src', context.src) -- detect the type of the key @@ -86,17 +81,6 @@ function set_config_element (key, value, context) else -- string real_set_config(key, value) end - -- alias_switch is depecated - if key == 'alias_switch' and context.src ~= 'def' then - err_print('warning', - 'Command-line options -a, --alias, -A, --noalias, as well as') - err_print('warning', - 'configuration item alias_switch, are deprecated') - err_print('warning', - 'and will soon be removed.') - err_print('warning', - 'Please protest on the texdoc mailing list if you need it.') - end -- special case: if we just set debug_list, print version info now if key == 'debug_list' then deb_print('version', C.fullname..' version '..C.version) @@ -152,22 +136,8 @@ function setup_config_from_cl(arg) end while arg[1] and string.match(arg[1],'^%-') do curr_arg = table.remove(arg,1) - -- special options - if (curr_arg == '-h') or (curr_arg == '--help') then - setup_config_from_files() - setup_config_from_defaults() - print_usage() - os.exit(C.exit_ok) - elseif (curr_arg == '-V') or (curr_arg == '--version') then - print (C.progname .. ' ' .. C.version ) - os.exit(C.exit_ok) - elseif (curr_arg == '-f') or (curr_arg == '--files') then - print (C.progname .. ' ' .. C.version ) - setup_config_from_files () - show_config_files (print, true) - os.exit(C.exit_ok) - -- options related to mode - elseif (curr_arg == '-w') or (curr_arg == '--view') then + -- mode + if (curr_arg == '-w') or (curr_arg == '--view') then set_config_elt('mode', 'view') elseif (curr_arg == '-m') or (curr_arg == '--mixed') then set_config_elt('mode', 'mixed') @@ -175,12 +145,6 @@ function setup_config_from_cl(arg) set_config_elt('mode', 'list') elseif (curr_arg == '-s') or (curr_arg == '--showall') then set_config_elt ('mode', 'showall') - elseif (curr_arg == '--search') then - set_config_elt ('mode', 'showall') - err_print('warning', '--search has been renamed to --showall') - err_print('warning', 'Please use the new name.') - elseif (curr_arg == '-r') or (curr_arg == '--regex') then - set_config_elt ('mode', 'regex') -- interaction elseif (curr_arg == '-I') or (curr_arg == '--nointeract') then set_config_elt('interact_switch', 'false') @@ -189,11 +153,6 @@ function setup_config_from_cl(arg) -- output format elseif (curr_arg == '-M') or (curr_arg == '--machine') then set_config_elt('machine_switch', 'true') - -- alias - elseif (curr_arg == '-A') or (curr_arg == '--noalias') then - set_config_elt('alias_switch', 'false') - elseif (curr_arg == '-a') or (curr_arg == '--alias') then - set_config_elt('alias_switch', 'true') -- debug elseif (curr_arg == '-d') or (curr_arg == '--debug') then set_config_elt('debug_list', 'all') @@ -203,60 +162,19 @@ function setup_config_from_cl(arg) elseif string.match(curr_arg, '^%-%-debug=') then local value = string.gsub(curr_arg, '^%-%-debug=', '') set_config_elt('debug_list', value) - -- quiet + -- verbosity elseif (curr_arg == '-q') or (curr_arg == '--quiet') then set_config_elt('verbosity_level', C.min_verbosity) - -- verbose - elseif string.match(curr_arg, '^%-%-verbose') then + elseif (curr_arg == '-v') or (curr_arg == '--verbose') then set_config_elt('verbosity_level', C.max_verbosity) - elseif string.match(curr_arg, '^%-v') then - local value = string.gsub(curr_arg, '^%-v=?', '') - if value == '' then - set_config_elt('verbosity_level', C.max_verbosity) - else -- compatibility syntax - err_print('warning', - 'The -v option does not accept arguments any more.') - err_print('warning', - 'Please use the new syntax -v, --verbose (without argument).') - set_config_elt('verbosity_level', value) - end - elseif string.match(curr_arg, '^%-%-verbosity') then - -- compatibility syntax - local value = string.gsub(curr_arg, '^%-%-verbosity=?', '') - err_print('warning', - '--verbosity is deprecated and will be removed soon.') - err_print('warning', - 'Please use the new syntax -v, --verbose (without argument).') - set_config_elt('verbosity_level', value) - -- extensions list (deprecated) - elseif string.match(curr_arg, '^%-e') then - local value = string.gsub(curr_arg, '^%-e=?', '') - set_config_elt('ext_list', value) - err_print('warning', - '-e is deprecated and will likely be removed soon.') - err_print('warning', - 'ext_list should be set in a configuration file instead.') - err_print('warning', - 'Please protest on the texdoc mailing list if you need this.') - elseif string.match(curr_arg, '^%-%-extensions') then - local value = string.gsub(curr_arg, '^%-%-extensions=?', '') - set_config_elt('ext_list', value) - err_print('warning', - '--extensions is deprecated and will likely be removed soon.') - err_print('warning', - 'ext_list should be set in a configuration file instead.') - err_print('warning', - 'Please protest on the texdoc mailing list if you need this.') - -- just view (undocumented option fur use with texdoctk) - elseif curr_arg == '--just-view' then - real_set_config('just_view', true) -- problem else err_print('error', "unknown option: "..curr_arg) err_print('error', C.error_msg) - os.exit(C.exit_usage) + return false end end + return true end ------------------------- config from environment -------------------------- @@ -320,20 +238,30 @@ function confline_to_config(line, file, pos) return false end --- return the list of configuration files and the index of the recommended file +-- return the list of configuration files function get_config_files () + -- get names local platform = string.match (kpse.var_value ('SELFAUTOLOC'), '.*/(.*)$') - local TEXMFHOME = kpse.var_value ('TEXMFHOME') - local TEXMFLOCAL = kpse.var_value ('TEXMFLOCAL') - local TEXMFMAIN = kpse.var_value ('TEXMFMAIN') - return { - TEXMFHOME .. '/texdoc/texdoc-'..platform..'.cnf', - TEXMFHOME .. '/texdoc/texdoc.cnf', - TEXMFHOME .. '/texdoc/texdoc-dist.cnf', - TEXMFLOCAL .. '/texdoc/texdoc-'..platform..'.cnf', - TEXMFLOCAL .. '/texdoc/texdoc.cnf', - TEXMFMAIN .. '/texdoc/texdoc.cnf', - }, 2 + local names = { + 'texdoc-'..platform..'.cnf', + 'texdoc.cnf', + 'texdoc-dist.cnf', + } + -- get dirs + local sep = (os.type == 'windows') and ';' or ':' + local texmf_texdoc = kpse.expand_path('$TEXMF/texdoc') + local dirs = texmf_texdoc:explode(sep) + -- merge them + local ret = {} + for _, dir in ipairs(dirs) do + for _, name in ipairs(names) do + local pathname = dir .. '/' .. name + if lfs.isfile(pathname) then + table.insert(ret, pathname) + end + end + end + return ret end -- the config_files table is shared by the next two functions @@ -342,15 +270,12 @@ local config_files = {} -- set config/aliases from all config files function setup_config_from_files () - local file_list, good_index = get_config_files() + local file_list = get_config_files() for i, file in ipairs (file_list) do - local found = lfs.isfile(file) - local status = found and (config.lastfile_switch - and 'disabled' or 'active') or 'absent' + local status = config.lastfile_switch and 'disabled' or 'active' config_files[i] = { path = file, status = status, - good = (i == good_index), } if status == 'active' then read_config_file (file) @@ -359,17 +284,16 @@ function setup_config_from_files () end -- now a special information function (see -f,--file option) -function show_config_files (print_fun, prefix) +function show_config_files (print_fun, verbose) + local pref = verbose and ' ' or '' print_fun("Configuration files are:") for i, file in ipairs (config_files) do - local home = prefix - and (file.good and "(*) " or " ") - or '' - print_fun (home..file.status..'\t'..w32_path(file.path)) + print_fun(pref..file.status..'\t'..w32_path(file.path)) end - if prefix then - print("(*) This is the recommended configuration file " - .. "for your personal preferences.") + if verbose then + local texmfhome = kpse.var_value('TEXMFHOME') + print_fun('Recommended file for personal settings:') + print_fun(pref..texmfhome..'/texdoc/texdoc.cnf') end end @@ -444,12 +368,9 @@ function desktop_environment_viewer() end end --- set some fall-back default values if no previous value is set -function setup_config_from_defaults() +-- set viewers from defaults (done only if necessary) +function get_default_viewers() local function set_config_ls(ls) set_config_list(ls, {src='def'}) end - local function set_config_elt(key, val) - set_config_element(key, val, {src='def'}) - end if (os.type == "windows") then set_config_ls { -- Use 'start' to get file associations. @@ -525,7 +446,15 @@ function setup_config_from_defaults() } } end - -- then various, platform independant, stuff +end + +-- set some fall-back default values if no previous value is set +function setup_config_from_defaults() + local function set_config_ls(ls) set_config_list(ls, {src='def'}) end + local function set_config_elt(key, val) + set_config_element(key, val, {src='def'}) + end + -- various, platform independant, stuff set_config_ls { mode = 'view', interact_switch = 'true', @@ -539,8 +468,6 @@ function setup_config_from_defaults() debug_list = '', max_lines = '20', } - -- must be set after mode! - set_config_elt ('alias_switch', alias_from_mode(config.mode)) -- zip-related options set_config_ls { zipext_list = '', @@ -549,32 +476,16 @@ function setup_config_from_defaults() } end --- the default value of config.alias_switch depends on the mode as follows -function alias_from_mode (mode) -- /!\ returns a string! - if (mode == 'regex') then - return 'false' - else - return 'true' - end -end - -------------------------- set all configuration --------------------------- -- populate the config and alias arrays function setup_config_and_alias(arg) -- setup config from all sources - setup_config_from_cl(arg) + local ret = setup_config_from_cl(arg) setup_config_from_env() setup_config_from_files() setup_config_from_locale() setup_config_from_defaults() - -- regex mode is deprecated - if config.mode == 'regex' then - err_print('warning', - 'Regex mode is deprecated and will likely be removed soon.') - err_print('warning', - 'Please protest on the texdoc mailing list if you need this.') - end -- machine mode implies no interaction if config.machine_switch == true then real_set_config('interact_switch', false) @@ -585,9 +496,12 @@ function setup_config_and_alias(arg) end -- we were waiting for config.debug_list to be known to do this show_config_files(function(s) deb_print('files', s) end) + -- propagated return value of _from_cl() + return ret end --- finally export a few symbols -export_symbols(L, { - 'setup_config_and_alias', -}) +return { + setup_config_and_alias = setup_config_and_alias, + get_default_viewers = get_default_viewers, + show_config_files = show_config_files, +} |