diff options
-rwxr-xr-x | Master/texmf/scripts/texlive/texdoc.tlu | 106 |
1 files changed, 58 insertions, 48 deletions
diff --git a/Master/texmf/scripts/texlive/texdoc.tlu b/Master/texmf/scripts/texlive/texdoc.tlu index 83b96f76764..50f6e254de9 100755 --- a/Master/texmf/scripts/texlive/texdoc.tlu +++ b/Master/texmf/scripts/texlive/texdoc.tlu @@ -34,9 +34,10 @@ version = '0.4' -- make sure to update setup_config_from_cl() accordingly -- and set a default value in setup_config_from_defaults() if relevant usage_msg = [[ -Usage: texdoc -h, --help | -V, --version | [option(s)] name(s) +Usage: texdoc -h, --help | -v, --version | -f, --files | [option(s)] name(s) -h, --help Show this short help. -v, --version Print the version of the program. + -f, --files Print the name of the config files being used. -e, --extensions=L Require file extensions to be in the list L. -w, --view Use view mode: start a viewer. -m, --mixed Use mixed mode (view or list). @@ -248,17 +249,17 @@ end function real_path (fake) local code, file = string.match (fake, '^(.-):(.*)$') code = tonumber (code) - return rp_win32_hook (texdocs[code]..'/'..file) + return win32_hook (texdocs[code]..'/'..file) end -- now a special function that does nothing on Unix if os.type == "windows" then - function rp_win32_hook (path) + function win32_hook (path) local res = string.gsub (path, '/', '\\') return res -- get rid of gsub's 2nd arg end else - function rp_win32_hook (path) + function win32_hook (path) return path end end @@ -358,6 +359,9 @@ function setup_config_from_cl () elseif (curr_arg == '-v') or (curr_arg == '--version') then print (progname .. ' version: ' .. version ) os.exit(0) + elseif (curr_arg == '-f') or (curr_arg == '--files') then + print_config_files () + os.exit(0) elseif (curr_arg == '-w') or (curr_arg == '--view') then set_config_element('mode', 'view') elseif (curr_arg == '-m') or (curr_arg == '--mixed') then @@ -440,60 +444,66 @@ function complain_about_old_envvar () end end --- set config+aliases from a particular config file if it exists +-- set config+aliases from a particular config file assumed to exist function read_config_file(configfile) - if (lfs.isfile(configfile)) then -- configfile exists - local cnf = assert(io.open(configfile, 'r')) - local lineno = 0 - while true do - local key, val - local line=cnf:read('*line') - lineno = lineno + 1 - if line == nil then break end -- EOF - line = string.gsub(line, '%s*#.*$', '') -- comments begin with # - line = string.gsub(line, '%s*$', '') -- remove trailing spaces - 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, configfile, lineno) + local cnf = assert(io.open(configfile, 'r')) + local lineno = 0 + while true do + local key, val + local line=cnf:read('*line') + lineno = lineno + 1 + if line == nil then break end -- EOF + line = string.gsub(line, '%s*#.*$', '') -- comments begin with # + line = string.gsub(line, '%s*$', '') -- remove trailing spaces + 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, configfile, lineno) + else + key, val = string.match(line, '^alias%s+([%a%d_-]+)%s*=%s*(.+)') + if key and val then + set_alias(key, val) else - key, val = string.match(line, '^alias%s+([%a%d_-]+)%s*=%s*(.+)') - if key and val then - set_alias(key, val) - else - if (not string.match (line, '^%s*$')) then - err_print ('syntax error in '..configfile.. - ' at line '..lineno..'.', 'warning') - end + if (not string.match (line, '^%s*$')) then + err_print ('syntax error in '..configfile.. + ' at line '..lineno..'.', 'warning') end end end - cnf:close() end + cnf:close() +end + +-- return a table with config file and if they exist +function get_config_files () + 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') + local config_files = {} + return { + TEXMFHOME .. '/texdoc/texdoc-'..platform..'.cnf', + TEXMFHOME .. '/texdoc/texdoc.cnf', + TEXMFLOCAL .. '/texdoc/texdoc-'..platform..'.cnf', + TEXMFLOCAL .. '/texdoc/texdoc.cnf', + TEXMFMAIN .. '/texdoc/texdoc.cnf' + } end -- set config/aliases from all config files function setup_config_from_files () - local TEXMFHOME, TEXMFLOCAL, TEXMFMAIN - local platform, configfile, configfiles - local ext, command, default_viewer - -- - platform=string.match(kpse.var_value('SELFAUTOLOC'), '.*/(.*)$') - TEXMFHOME=kpse.var_value('TEXMFHOME') - TEXMFLOCAL=kpse.var_value('TEXMFLOCAL') - TEXMFMAIN=kpse.var_value('TEXMFMAIN') - -- - -- the following config files are read if they exist. - configfiles={ - TEXMFHOME ..'/texdoc/texdoc-'..platform..'.cnf', - TEXMFHOME ..'/texdoc/texdoc.cnf', - TEXMFLOCAL..'/texdoc/texdoc-'..platform..'.cnf', - TEXMFLOCAL..'/texdoc/texdoc.cnf', - TEXMFMAIN..'/texdoc/texdoc.cnf' - } - -- - for i, configfile in ipairs(configfiles) do -- process all config files - read_config_file(configfile) + for file in list (get_config_files ()) do + if lfs.isfile(file) then read_config_file (file) end + end +end + +-- now a special information function (see -f,--file option) +function print_config_files () + print "Configuration files are:" + for i, file in ipairs (get_config_files ()) do + local found = lfs.isfile(file) and "(active)" or "(not found)" + local home = (i==2) and "* " or "" -- home conffile is the 2nd + print (home..found, win32_hook(file)) end end |