summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
authorManuel Pégourié-Gonnard <mpg@elzevir.fr>2008-07-15 21:07:43 +0000
committerManuel Pégourié-Gonnard <mpg@elzevir.fr>2008-07-15 21:07:43 +0000
commit3a85ece61c333a7a385c214d5cbddd6532f8a682 (patch)
treeb055f09496ddd60b234d541fbdb1a9f0c22166ad /Master
parent73c26e9e0b37ea91de30f9be5f997ed422ade33a (diff)
Add options to force (resp disable) aliases. Move parts of the code around (function definitions first, execution later) and mv the mode vairable to config.mode.
git-svn-id: svn://tug.org/texlive/trunk@9585 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rwxr-xr-xMaster/texmf/scripts/texlive/texdoc.tlu319
1 files changed, 174 insertions, 145 deletions
diff --git a/Master/texmf/scripts/texlive/texdoc.tlu b/Master/texmf/scripts/texlive/texdoc.tlu
index 4f1877d7fa3..ee8c6696f53 100755
--- a/Master/texmf/scripts/texlive/texdoc.tlu
+++ b/Master/texmf/scripts/texlive/texdoc.tlu
@@ -18,6 +18,7 @@ Public domain.]]
- initial public release
]]
+--[[ some constants ]]
progname = 'texdoc'
version = '0.31'
usage_msg = [[
@@ -25,6 +26,8 @@ Usage: texdoc -h, --help | -v, --version | [option] name(s)
-h|--help Show this help.
-V|--version Print the version of the program.
-v|--verbose Show the command being used to display the documentation.
+ -a|--alias Use the alias table.
+ -A|--noalias Don't use the alias table.
-l|--list List matching files, do not start a viewer.
-s|--search Search for name as a pattern.]]
notfound_msg = [[
@@ -53,45 +56,10 @@ function print_debug (message)
end
end
--- [[ exit codes ]]
--- 0 OK
--- 1 Usage
--- 2 No doc found for at least one arg
--- ? Should do something for viewer problems etc
-
--- must have at least one arg
-if not arg[1] then
- print (usage_msg)
- os.exit(1)
-end
--- reading and setting options
-mode = 'view'
-verbose = false
-while table.maxn(arg) > 0 and string.match(arg[1],'^%-') do
- curr_arg = table.remove(arg,1)
- if (curr_arg == '-h') or (curr_arg == '--help') then
- print (usage_msg)
- os.exit(0)
- elseif (curr_arg == '-V') or (curr_arg == '--version') then
- print (progname .. ' version: ' .. version )
- os.exit(0)
- elseif (curr_arg == '-v') or (curr_arg == '--verbose') then
- verbose = true
- elseif (curr_arg == '-l') or (curr_arg == '--list') then
- mode = 'list'
- elseif (curr_arg == '-s') or (curr_arg == '--search') then
- mode = 'search'
- end
-end
-
--- must have at least one arg left after eating up the options
-if not arg[1] then
- print (usage_msg)
- os.exit(1)
-end
+--[[ BEGIN function definitions (till the 'END' mark) ]]
---[[ function definitions ]]
+-- a general-use function
function list_iter (t)
local i = 0
local n = table.getn(t)
@@ -208,8 +176,8 @@ function recurse_tree (path)
end --function recurse_tree
--- [[ set values from config files or defaults ]]
--- also set aliases from config files while we're at it
+-- [[ function set config values from env, files, and defaults ]]
+-- same functions are used to set aliases from the conf files
config = {} -- everything is stored in this table ...
alias = {} -- ... except aliases
@@ -241,19 +209,19 @@ function set_alias (key, value)
end
end
--- first, we shall make use of some environment variables
-set_config_list {
- viewer_pdf = os.getenv ("PDFVIEWER"),
- viewer_ps = os.getenv ("PSVIEWER"),
- viewer_dvi = os.getenv ("DVIVIEWER"),
- viewer_html = os.getenv ("BROWSER"),
- viewer_txt = os.getenv ("PAGER")
-}
-
--- initialize kpathsea
-kpse.set_program_name(arg[-1], "texdoc")
+-- use environment variables if available
+function setup_config_from_env ()
+ set_config_list {
+ viewer_pdf = os.getenv ("PDFVIEWER"),
+ viewer_ps = os.getenv ("PSVIEWER"),
+ viewer_dvi = os.getenv ("DVIVIEWER"),
+ viewer_html = os.getenv ("BROWSER"),
+ viewer_txt = os.getenv ("PAGER")
+ }
+end
--- read a particular config file if it exists. Used by setup_config() only.
+-- read a particular config file if it exists.
+-- Used by setup_config_from_files () only.
function read_config_file(configfile)
if (lfs.isfile(configfile)) then -- configfile exists
local cnf=assert(io.open(configfile, 'r'))
@@ -288,7 +256,7 @@ function read_config_file(configfile)
end
-- read all config files.
-function setup_config ()
+function setup_config_from_files ()
local TEXMFHOME, TEXMFLOCAL, TEXMFMAIN
local platform, configfile, configfiles
local ext, command, default_viewer
@@ -312,7 +280,6 @@ function setup_config ()
read_config_file(configfile)
end
end
-setup_config ()
-- for default viewer on general Unix, we use a list
-- and check in the path in order to find a suitable program
@@ -336,100 +303,94 @@ function first_in_path(list)
end
-- some fall-back default values
-if (os.type == "windows") then
- -- probably Windows (or OS/2)
- -- which commands should we use for unzipping?
- set_config_list {
- viewer_dvi = '(start /wait %s) &',
- viewer_html = '(start /wait %s) &',
- viewer_pdf = '(start /wait %s) &',
- viewer_ps = '(start /wait %s) &',
- viewer_txt = '(start /wait %s) &',
- viewer_fallback='(start /wait %s) &'
- }
-else -- since we don't support msdos, if os.type is not windows, it's unix
- if (os.name == 'macosx') then
+function setup_config_from_defaults()
+ if (os.type == "windows") then
+ -- probably Windows (or OS/2)
+ -- which commands should we use for unzipping?
set_config_list {
- viewer_dvi = '(open %s)',
- viewer_html = '(open %s)',
- viewer_pdf = '(open %s)',
- viewer_ps = '(open %s)',
- viewer_txt = '(less %s)',
- viewer_fallback='(open %s)'
+ viewer_dvi = '(start /wait %s) &',
+ viewer_html = '(start /wait %s) &',
+ viewer_pdf = '(start /wait %s) &',
+ viewer_ps = '(start /wait %s) &',
+ viewer_txt = '(start /wait %s) &',
+ viewer_fallback='(start /wait %s) &'
}
- else
- set_config_list {
- viewer_dvi = first_in_path {
- {'see', '(see %s) &'},
- {'evince', '(evince %s) &'},
- {'okular', '(okular %s) &'},
- {'kdvi', '(kdvi %s) &'},
- {'xdvi', '(xdvi %s) &'}
- },
- viewer_html = first_in_path {
- {'see', '(see %s) &'},
- {'firefox', '(firefox %s) &'},
- {'mozilla', '(mozilla %s) &'},
- {'konqueror', '(konqueror %s) &'},
- {'epiphany', '(epiphany %s) &'},
- {'opera', '(opera %s) &'},
- {'w3m', '(w3m %s) &'},
- {'links', '(links %s) &'},
- {'lynx', '(lynx %s) &'}
- },
- viewer_pdf = first_in_path {
- {'see', '(see %s) &'},
- {'evince', '(evince %s) &'},
- {'okular', '(okular %s) &'},
- {'kpdf', '(kpdf %s) &'},
- {'xpdf', '(xpdf %s) &'}
- },
- viewer_ps = first_in_path {
- {'see', '(see %s) &'},
- {'evince', '(evince %s) &'},
- {'okular', '(okular %s) &'},
- {'kghostview', '(kghostview %s) &'},
- {'gv', '(gv %s) &'}
- },
- viewer_txt = first_in_path {
- {'most', '(most %s)'},
- {'less', '(less %s)'},
- {'more', '(more %s)'}
- },
- viewer_fallback = first_in_path {
- {'see', '(see %s) &'},
- {'less', '(less %s)'},
- {'more', '(more %s)'}
+ else -- since we don't support msdos, if os.type is not windows, it's unix
+ if (os.name == 'macosx') then
+ set_config_list {
+ viewer_dvi = '(open %s)',
+ viewer_html = '(open %s)',
+ viewer_pdf = '(open %s)',
+ viewer_ps = '(open %s)',
+ viewer_txt = '(less %s)',
+ viewer_fallback='(open %s)'
+ }
+ else
+ set_config_list {
+ viewer_dvi = first_in_path {
+ {'see', '(see %s) &'},
+ {'evince', '(evince %s) &'},
+ {'okular', '(okular %s) &'},
+ {'kdvi', '(kdvi %s) &'},
+ {'xdvi', '(xdvi %s) &'}
+ },
+ viewer_html = first_in_path {
+ {'see', '(see %s) &'},
+ {'firefox', '(firefox %s) &'},
+ {'mozilla', '(mozilla %s) &'},
+ {'konqueror', '(konqueror %s) &'},
+ {'epiphany', '(epiphany %s) &'},
+ {'opera', '(opera %s) &'},
+ {'w3m', '(w3m %s) &'},
+ {'links', '(links %s) &'},
+ {'lynx', '(lynx %s) &'}
+ },
+ viewer_pdf = first_in_path {
+ {'see', '(see %s) &'},
+ {'evince', '(evince %s) &'},
+ {'okular', '(okular %s) &'},
+ {'kpdf', '(kpdf %s) &'},
+ {'xpdf', '(xpdf %s) &'}
+ },
+ viewer_ps = first_in_path {
+ {'see', '(see %s) &'},
+ {'evince', '(evince %s) &'},
+ {'okular', '(okular %s) &'},
+ {'kghostview', '(kghostview %s) &'},
+ {'gv', '(gv %s) &'}
+ },
+ viewer_txt = first_in_path {
+ {'most', '(most %s)'},
+ {'less', '(less %s)'},
+ {'more', '(more %s)'}
+ },
+ viewer_fallback = first_in_path {
+ {'see', '(see %s) &'},
+ {'less', '(less %s)'},
+ {'more', '(more %s)'}
+ }
}
+ end
+ end
+ -- now a particular case for config.ext_list and zip-related stuff
+ if support_zipped then
+ set_config_element('ext_list',
+ '.pdf,.pdf.gz,.pdf.bz2, html,html.gz,html.bz2, .txt,.txt.gz,.txt.bz2,'..
+ '.dvi,.dvi.gz,.dvi.bz2, .ps,.ps.gz,.ps.bz2')
+ set_config_list {
+ unzip_gz = 'gzip -d -c ',
+ unzip_bz2 = 'bzip -d -c ',
+ rm_file = 'rm -f',
+ rm_dir = 'rmdir'
}
+ else
+ set_config_element('ext_list', '.pdf, .html, .txt, .dvi, .ps')
end
end
--- now a particular case for config.ext_list and zip-relted stuff
-if support_zipped then
- set_config_element('ext_list',
- '.pdf,.pdf.gz,.pdf.bz2, html,html.gz,html.bz2, .txt,.txt.gz,.txt.bz2,'..
- '.dvi,.dvi.gz,.dvi.bz2, .ps,.ps.gz,.ps.bz2')
- set_config_list {
- unzip_gz = 'gzip -d -c ',
- unzip_bz2 = 'bzip -d -c ',
- rm_file = 'rm -f',
- rm_dir = 'rmdir'
- }
-else
- set_config_element('ext_list', '.pdf, .html, .txt, .dvi, .ps')
-end
-
--- we want an empty string for ext at the beginning, so that it works
--- to specify the complete filename. Doesn't matter when there's one
--- more empty string, but we can easily avoid two in a row
-if not (config.ext_list[1] == '') then
- table.insert(config.ext_list,1,'')
-end
-
-- [[ functions for viewing ]]
--- prepare for viewing set viewer_replacement and viwer_ext
+-- prepare for viewing: set viewer_replacement and viwer_ext
-- may uncompress if support_zipped is set (giving the complete filename on the
-- command line is unsupported for compressed files by the way)
function prepare_viewing (ext)
@@ -500,32 +461,100 @@ function try_viewing (view_command)
return view_result
end
--- [[ the main loop ]]
+--[[ END functions definition -- execution starts below ]]
+
+--[[ exit codes ]]
+-- 0 OK
+-- 1 Usage
+-- 2 No doc found for at least one arg
+-- ? Should do something for viewer problems etc
+
+-- must have at least one arg
+if not arg[1] then
+ print (usage_msg)
+ os.exit(1)
+end
+
+--[[ options from command line ]]
+-- there is one boolean switch: verbose
+-- and config options using the config table, which means the default comes last
+-- config options are:
+-- mode ('view'* or 'list' or 'search')
+-- enable_alias ('true'* or 'false' (string, not boolean))
+verbose = false
+while table.maxn(arg) > 0 and string.match(arg[1],'^%-') do
+ curr_arg = table.remove(arg,1)
+ if (curr_arg == '-h') or (curr_arg == '--help') then
+ print (usage_msg)
+ os.exit(0)
+ elseif (curr_arg == '-V') or (curr_arg == '--version') then
+ print (progname .. ' version: ' .. version )
+ os.exit(0)
+ elseif (curr_arg == '-v') or (curr_arg == '--verbose') then
+ verbose = true
+ elseif (curr_arg == '-l') or (curr_arg == '--list') then
+ set_config_list { mode = 'list', enable_alias = 'false'}
+ elseif (curr_arg == '-s') or (curr_arg == '--search') then
+ set_config_list { mode = 'search', enable_alias = 'false'}
+ elseif (curr_arg == '-A') or (curr_arg == '--alias') then
+ set_config_element('enable_alias', 'false')
+ elseif (curr_arg == '-a') or (curr_arg == '--noalias') then
+ set_config_element('enable_alias', 'true')
+ end
+end
+-- defaults using the config table (ext_list comes later)
+set_config_list {
+ enable_alias = 'true', -- string, not boolean
+ mode = 'view',
+}
+
+-- must have at least one arg left after eating up the options
+if not arg[1] then
+ print (usage_msg)
+ os.exit(1)
+end
+
+-- initialize kpathsea
+kpse.set_program_name(arg[-1], "texdoc")
+
+-- config options from env, conf files or defaults
+setup_config_from_env ()
+setup_config_from_files ()
+setup_config_from_defaults ()
+
+-- we want an empty string for ext at the beginning, so that it works
+-- to specify the complete filename. Doesn't matter when there's one
+-- more empty string, but we can easily avoid two in a row
+if not (config.ext_list[1] == '') then
+ table.insert(config.ext_list,1,'')
+end
+
+-- the main loop over the args
exit_code = 0
for docname in list_iter (arg) do
- if alias[docname] then
+ if (alias[docname] and (config.enable_alias == 'true')) then
print ("texdoc info: "..docname.." aliased to "..alias[docname])
docname = alias[docname]
end
local docfound = false
- if (mode == 'search') then
+ if (config.mode == 'search') then
docfound = true
pattern_search(docname)
- elseif (mode == 'view') or (mode == 'list') then
+ elseif (config.mode == 'view') or (config.mode == 'list') then
for ext in list_iter(config.ext_list) do
filename = kpse.find_file(docname .. ext,
"TeX system documentation")
if filename then
docfound = true
- if (mode == 'list') then
+ if (config.mode == 'list') then
print(filename)
- else -- mode is view, is unzipping needed?
+ else -- config.mode is view, is unzipping needed?
local ok = try_viewing(prepare_viewing(ext))
if ok then break end
end -- list or view
end -- found a filename with that extension or not?
end -- for ext
- end -- if construct "case mode in"
+ end -- if construct "case config.mode in"
if not docfound then -- apologize if we didn't succeed
exit_code = 2
msg = string.gsub(notfound_msg, 'PKGNAME', docname)