texlive[44391] Master/texmf-dist/scripts/texdoc: viewer environment,

commits+karl at tug.org commits+karl at tug.org
Wed May 17 20:11:11 CEST 2017


Revision: 44391
          http://tug.org/svn/texlive?view=revision&revision=44391
Author:   karl
Date:     2017-05-17 20:11:11 +0200 (Wed, 17 May 2017)
Log Message:
-----------
viewer environment, version 2.017

Modified Paths:
--------------
    trunk/Master/texmf-dist/scripts/texdoc/constants.tlu
    trunk/Master/texmf-dist/scripts/texdoc/functions.tlu
    trunk/Master/texmf-dist/scripts/texdoc/view.tlu

Modified: trunk/Master/texmf-dist/scripts/texdoc/constants.tlu
===================================================================
--- trunk/Master/texmf-dist/scripts/texdoc/constants.tlu	2017-05-17 08:57:42 UTC (rev 44390)
+++ trunk/Master/texmf-dist/scripts/texdoc/constants.tlu	2017-05-17 18:11:11 UTC (rev 44391)
@@ -1,6 +1,7 @@
+-- $Id: constants.tlu 13 2017-05-17 18:09:11Z karl $
 -- constants.tlu: global "constants" for texdoc.
 --
--- Manuel Pégourié-Gonnard, GPLv3, see texdoclib.tlu for details
+-- Manuel Pégourié-Gonnard, GPLv3+, see texdoclib.tlu for details
 
 -- use an empty environment that will become texdoc_env.C (see EOF)
 local constants = {}
@@ -20,7 +21,7 @@
 -- progname and version
 fullname    = kpse.find_file('texdoc/texdoclib', 'lua')
 progname    = 'texdoc'
-version     = '0.85'
+version     = '2.017'
 
 -- make sure to update setup_config_from_cl() accordingly
 -- and set a default value in setup_config_from_defaults() if relevant
@@ -48,13 +49,17 @@
   -v, --verbose         Print additional information (eg, viewer command).
   -d, --debug[=list]    Activate debug output (restricted to list).
 
-Environment: PAGER, BROWSER, PDFVIEWER, PSVIEWER, DVIVIEWER.
+Environment variables: PAGER, BROWSER, PDFVIEWER, PSVIEWER, DVIVIEWER,
+and texdoc_* of each.
+
 Files: <texmf>/texdoc/texdoc.cnf, see output of the --files option.
-Report bugs to <texdoc at tug.org>.
-Full manual available via `texdoc texdoc'.]]
+Full manual available via `texdoc texdoc'.
 
+Please report bugs to <texdoc at tug.org>.
+]]
+
 copyright_msg = [[
-Copyright (C) 2008-2013 Manuel P'egouri'e-Gonnard.
+Copyright 2008-2017 Manuel P'egouri'e-Gonnard.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
 This is free software: you are free to change and redistribute it.]]
 
@@ -91,6 +96,7 @@
 
 error_msg = [[
 Try `texdoc --help' for a short help, `texdoc texdoc' for the user manual.]]
+
 notfound_msg = [[
 Sorry, no documentation found for PKGNAME.
 If you are unsure about the name, try searching CTAN's TeX catalogue at
@@ -102,7 +108,7 @@
     warning = 2,
     info    = 3,
 }
-min_verbosity='0'
+min_verbosity='0'  -- (nothing at all)
 max_verbosity='3'
 def_verbosity='2'
 

Modified: trunk/Master/texmf-dist/scripts/texdoc/functions.tlu
===================================================================
--- trunk/Master/texmf-dist/scripts/texdoc/functions.tlu	2017-05-17 08:57:42 UTC (rev 44390)
+++ trunk/Master/texmf-dist/scripts/texdoc/functions.tlu	2017-05-17 18:11:11 UTC (rev 44391)
@@ -1,6 +1,7 @@
+-- $Id: functions.tlu 12 2017-05-17 18:07:47Z karl $
 -- functions.tlu: general-use functions for texdoc
 --
--- Manuel Pégourié-Gonnard, GPLv3, see texdoclib.tlu for details
+-- Manuel Pégourié-Gonnard, GPLv3+, see texdoclib.tlu for details
 
 -- change '/' to '\' on windows
 -- Use: internal representation of files always use forward slashes.
@@ -26,7 +27,7 @@
     end
 end
 
--- generic error display function (see the error_priority constant)
+-- generic error display function (see the err_priority constant)
 function err_print (lvl, msg)
     -- be careful: maybe config.verbosity_level is not set yet
     local verbosity_level = config.verbosity_level or tonumber(C.def_verbosity)

Modified: trunk/Master/texmf-dist/scripts/texdoc/view.tlu
===================================================================
--- trunk/Master/texmf-dist/scripts/texdoc/view.tlu	2017-05-17 08:57:42 UTC (rev 44390)
+++ trunk/Master/texmf-dist/scripts/texdoc/view.tlu	2017-05-17 18:11:11 UTC (rev 44391)
@@ -81,6 +81,7 @@
     else
         view_command = view_command..' '..viewer_replacement
     end
+
     -- try to catch problems with missing DISPLAY on Unix
     if os.type == 'unix' and not (os.name == 'macosx')
             and os.getenv('DISPLAY') == nil then
@@ -90,13 +91,44 @@
         "Try --list to list results instead of displaying them.")
     end
     err_print('info', 'View command: '..view_command)
+     
+    -- See long comment below this function for the LC_CTYPE story.
+    -- We only want to reset the environment if we have the value
+    -- to reset it to. In older versions of luatex, status.lc_* will be nil.
+    local env_lc_ctype = status.lc_ctype
+    local luatex_lc_ctype = os.setlocale(nil, 'ctype')
+    if (env_lc_ctype) then
+      err_print('info', "Setting environment LC_CTYPE to: "..env_lc_ctype)
+      os.setenv("LC_CTYPE", env_lc_ctype)
+    end
+
+    -- the big casino: run the external command.
     if not os.execute(view_command) then
-        err_print('error', "Failed to execute '"..view_command.."'")
+        err_print('error', "Failed to execute: "..view_command)
         return false
     end
+    
+    -- reset back to "C" (should always be C and always happen, but in case...)
+    if (luatex_lc_ctype) then
+      os.setenv("LC_CTYPE", luatex_lc_ctype)
+    end
+
     return true
 end
 
+-- Explanation of locale madness:
+-- LuaTeX resets LC_CTYPE, LC_COLLATE, LC_NUMERIC to "C". That is good for
+-- inside luatex, but when we run an external program, if the user's
+-- environment is something else, we want to switch back to it. As of
+-- TL 2017 LuaTeX, we can inspect the user's locale with status.lc_ctype, etc.
+-- 
+-- For texdoc purposes, what matters is LC_CTYPE (so we don't bother with
+-- the others). For example, with the less pager, when LC_CTYPE=C,
+-- non-ASCII bytes are displayed as "<xx>", where xx is the two hex
+-- digits for the byte.
+-- 
+-- See <texdoc-dev-source>/tools/Makefile for a standalone test case.
+
 -----------------------------   display results   -----------------------------
 
 -- print a list of docfile objects (see search.tlu) as a menu



More information about the tex-live-commits mailing list