texlive[49400] Build/source/texk/kpathsea: have kpsewhich --var-value

commits+karl at tug.org commits+karl at tug.org
Thu Dec 13 18:23:11 CET 2018


Revision: 49400
          http://tug.org/svn/texlive?view=revision&revision=49400
Author:   karl
Date:     2018-12-13 18:23:10 +0100 (Thu, 13 Dec 2018)
Log Message:
-----------
have kpsewhich --var-value expand braces too; also, recognize eithe ; or : regardless of the current system when parsing elements from a path (https://github.com/TeX-Live/texlive-source/issues/3)

Modified Paths:
--------------
    trunk/Build/source/texk/kpathsea/ChangeLog
    trunk/Build/source/texk/kpathsea/NEWS
    trunk/Build/source/texk/kpathsea/c-pathch.h
    trunk/Build/source/texk/kpathsea/doc/kpathsea.info
    trunk/Build/source/texk/kpathsea/doc/kpathsea.texi
    trunk/Build/source/texk/kpathsea/kpsewhich.c
    trunk/Build/source/texk/kpathsea/path-elt.c
    trunk/Build/source/texk/kpathsea/pathsearch.h

Modified: trunk/Build/source/texk/kpathsea/ChangeLog
===================================================================
--- trunk/Build/source/texk/kpathsea/ChangeLog	2018-12-13 01:23:20 UTC (rev 49399)
+++ trunk/Build/source/texk/kpathsea/ChangeLog	2018-12-13 17:23:10 UTC (rev 49400)
@@ -1,5 +1,22 @@
 2018-12-12  Karl Berry  <karl at freefriends.org>
 
+	* c-pathch.h (IS_KPSE_SEP): new macro to check for either : or ;
+	regardless of the current system.
+	* path-elt.c (element): use it when extracting the path elements,
+	so that we'll get ~ expansion on Unix in, e.g.,
+	    env FOO='/;~' ./kpsewhich --expand-braces='$FOO'
+	* kpsewhich.c (main): call kpathsea_brace_expand on the result
+	from kpathsea_var_value, so that we'll get ~ expansion in, e.g.,
+	    env FOO='/:~' ./kpsewhich --var-value=FOO
+	Original report from e-kwsm (E Kawashima),
+	https://github.com/TeX-Live/texlive-source/issues/3
+	
+	* NEWS,
+	* doc/kpathsea.texi (Auxiliary tasks): document that -var-value
+	now does brace expansion.
+
+2018-12-12  Karl Berry  <karl at freefriends.org>
+
 	* expand.h,
 	* pathsearch.h,
 	* cnf.c: doc fixes.

Modified: trunk/Build/source/texk/kpathsea/NEWS
===================================================================
--- trunk/Build/source/texk/kpathsea/NEWS	2018-12-13 01:23:20 UTC (rev 49399)
+++ trunk/Build/source/texk/kpathsea/NEWS	2018-12-13 17:23:10 UTC (rev 49400)
@@ -1,6 +1,13 @@
 $Id$
 This file records noteworthy changes.  (Public domain.)
 
+6.3.1 (for TeX Live 2019)
+* kpsewhich --var-value does brace expansion as well as variable and
+  tilde expansion.
+* The kpathsea_path_search() and related functions always recognize either
+  common path separator (: or ;) when splitting paths into elements.
+  (Before, there were some unusual contexts where this did not happen.)
+
 6.3.0 (for TeX Live 2018, 14 April 2018)
 * New configuration value texmf_casefold_search to fall back to
   case-insensitive search in non-system directories if there is no exact

Modified: trunk/Build/source/texk/kpathsea/c-pathch.h
===================================================================
--- trunk/Build/source/texk/kpathsea/c-pathch.h	2018-12-13 01:23:20 UTC (rev 49399)
+++ trunk/Build/source/texk/kpathsea/c-pathch.h	2018-12-13 17:23:10 UTC (rev 49400)
@@ -1,7 +1,7 @@
 /* c-pathch.h: define the characters which separate components of
    filenames and environment variable paths.
 
-   Copyright 1992, 1993, 1995, 1997, 2008 Karl Berry.
+   Copyright 1992, 1993, 1995, 1997, 2008, 2018 Karl Berry.
    Copyright 1997, 1999, 2001, 2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -97,4 +97,13 @@
 #define IS_ENV_SEP(ch) ((ch) == ENV_SEP)
 #endif
 
+/* Because paths in Kpathsea cnf files are system-independent, allowing
+   use of either ; or : regardless of the current system, sometimes we
+   need to check for either of the possible path separators.  */
+#ifndef IS_KPSE_SEP
+#define IS_KPSE_SEP(ch) ((ch) == ':' || (ch) == ';')
+/* In principle we should do it differently on VMS and VMCMS,
+   but I'm guessing no one is compiling current kpathsea sources there.  */
+#endif
+
 #endif /* not C_PATHCH_H */

Modified: trunk/Build/source/texk/kpathsea/doc/kpathsea.info
===================================================================
--- trunk/Build/source/texk/kpathsea/doc/kpathsea.info	2018-12-13 01:23:20 UTC (rev 49399)
+++ trunk/Build/source/texk/kpathsea/doc/kpathsea.info	2018-12-13 17:23:10 UTC (rev 49400)
@@ -37,7 +37,7 @@
 ****************
 
 This manual documents the Kpathsea library for path searching.  It
-corresponds to version 6.3.0, released in July 2018.
+corresponds to version 6.3.0, released in December 2018.
 
 * Menu:
 
@@ -62,7 +62,7 @@
 **************
 
 This manual corresponds to version 6.3.0 of the Kpathsea library,
-released in July 2018.
+released in December 2018.
 
    The library's fundamental purpose is to return a filename from a list
 of directories specified by the user, similar to what shells do when
@@ -725,7 +725,7 @@
      foo/{1,2}/baz
 
 expands to 'foo/1/baz:foo/2/baz'.  ':' is the path separator on the
-current system; e.g., on a DOS system, it's ';'.
+current system; e.g., on a Windows system, it's ';'.
 
    Braces can be nested; for example, 'x{A,B{1,2}}y' expands to
 'xAy:xB1y:xB2y'.
@@ -738,7 +738,7 @@
 assigning a brace list to '$TEXMF', as mentioned in 'texmf.in'.
 
    You can also use the path separator instead of the comma.  The last
-example could have been written 'x{A:B}{1:2}y'.
+example could have been written 'x{A:B}{1:2}y' (on Unix).
 
    Brace expansion is implemented in the source file
 'kpathsea/expand.c'.
@@ -1425,8 +1425,8 @@
      Set debugging options to NUM.  *Note Debugging::.
 
 '--expand-braces=STRING'
-     Output variable and brace expansion of STRING.  *Note Path
-     expansion::.
+     Output variable, tilde, and brace expansion of STRING, which is
+     assumed to be a single path element.  *Note Path expansion::.
 
 '--expand-path=STRING'
      Output the complete expansion of STRING, with each element
@@ -1444,12 +1444,12 @@
           =>
 
      For one-shot uses of an arbitrary (not built in to Kpathsea) path,
-     see '--path' (*note Path searching options::)
+     see '--path' (*note Path searching options::).
 
 '--expand-var=STRING'
-     Output the variable and tilde expansion of STRING the 'mktex...'
-     scripts run 'kpsewhich --expand-var='$TEXMF'' to find the root of
-     the TeX system hierarchy.  *Note Path expansion::.
+     Output the variable and tilde expansion of STRING.  For example,
+     with the usual 'texmf.cnf', 'kpsewhich --expand-var='$TEXMF''
+     returns the TeX system hierarchy root(s).  *Note Path expansion::.
 
 '--help-formats'
      Output information about each supported format (*note Supported
@@ -1471,9 +1471,10 @@
 
 '--var-value=VARIABLE'
      Outputs the value of VARIABLE (a simple identifier like 'TEXMF',
-     with no '$' or other constructs), expanding '$' (*note Variable
-     expansion:: and '~' (*note Tilde expansion::) constructs, but not
-     performing other expansions.
+     with no '$' or other constructs), expanding '{...}' (*note Brace
+     expansion::), '$' (*note Variable expansion::) and '~' (*note Tilde
+     expansion::) constructs, considered as strings, but not looking on
+     the filesystem.
 
 
 File: kpathsea.info,  Node: Standard options,  Prev: Auxiliary tasks,  Up: Invoking kpsewhich
@@ -2911,9 +2912,6 @@
 passed, problems may lurk.  Optimization occasionally causes trouble in
 programs other than TeX and Metafont themselves, too.
 
-   Insufficient swap space may also cause core dumps or other erratic
-behavior.
-
    For a workaround, if you enabled any optimization flags, it's best to
 omit optimization entirely.  In any case, the way to find the facts is
 to run the program under the debugger and see where it's failing.
@@ -2926,8 +2924,7 @@
    To report compiler bugs effectively requires perseverance and
 perspicacity: you must find the miscompiled line, and that usually
 involves delving backwards in time from the point of error, checking
-through TeX's (or whatever program's) data structures.  Things are not
-helped by all-too-common bugs in the debugger itself.  Good luck.
+through TeX's (or whatever program's) data structures.  Good luck.
 
 
 File: kpathsea.info,  Node: Index,  Prev: Reporting bugs,  Up: Top
@@ -3195,7 +3192,7 @@
 * compiler bugs:                         TeX or Metafont failing.
                                                               (line   6)
 * compiler bugs, finding:                TeX or Metafont failing.
-                                                              (line  24)
+                                                              (line  21)
 * conditions for use:                    Introduction.        (line  32)
 * config files:                          Config files.        (line   6)
 * config files, for Kpathsea-using programs: Calling sequence.
@@ -3360,7 +3357,7 @@
 * glyphlist.txt:                         Specially-recognized files.
                                                               (line  25)
 * GNU C compiler bugs:                   TeX or Metafont failing.
-                                                              (line  19)
+                                                              (line  16)
 * GNU General Public License:            Introduction.        (line  32)
 * group-writable directories:            Security.            (line  40)
 * GSFTOPK_DEBUG (128):                   Debugging.           (line  88)
@@ -3535,7 +3532,7 @@
 * OPENTYPEFONTS:                         Supported file formats.
                                                               (line 145)
 * optimization caveat:                   TeX or Metafont failing.
-                                                              (line  15)
+                                                              (line  12)
 * options for debugging:                 Debugging.           (line   6)
 * OTPINPUTS:                             Supported file formats.
                                                               (line 151)
@@ -3669,7 +3666,7 @@
 * symbolic links, and ls-R:              ls-R.                (line  38)
 * symlinks, resolving:                   Calling sequence.    (line  31)
 * system C compiler bugs:                TeX or Metafont failing.
-                                                              (line  19)
+                                                              (line  16)
 * system-dependent casefolding behavior: Casefolding rationale.
                                                               (line   6)
 * T1FONTS:                               Supported file formats.
@@ -3847,61 +3844,61 @@
 
 Tag Table:
 Node: Top1480
-Node: Introduction2259
-Node: History4328
-Node: unixtex.ftp8924
-Node: Security10349
-Node: TeX directory structure12853
-Node: Path searching16901
-Node: Searching overview17628
-Node: Path sources21447
-Node: Config files22538
-Node: Path expansion26465
-Node: Default expansion27418
-Node: Variable expansion29488
-Node: Tilde expansion30889
-Node: Brace expansion31869
-Node: KPSE_DOT expansion32794
-Node: Subdirectory expansion33307
-Node: Casefolding search35661
-Node: Casefolding rationale36430
-Node: Casefolding examples37769
-Node: Filename database42819
-Node: ls-R43877
-Node: Filename aliases46772
-Node: Database format47950
-Node: Invoking kpsewhich48963
-Node: Path searching options49918
-Node: Specially-recognized files58437
-Node: Auxiliary tasks59792
-Node: Standard options62131
-Node: TeX support62487
-Node: Supported file formats63841
-Node: File lookup71506
-Node: Glyph lookup73255
-Node: Basic glyph lookup74379
-Node: Fontmap75259
-Node: Fallback font77788
-Node: Suppressing warnings78700
-Node: mktex scripts79827
-Node: mktex configuration81042
-Node: mktex script names86845
-Node: mktex script arguments88231
-Node: Programming89110
-Node: Programming overview89683
-Node: Calling sequence92544
-Node: Program-specific files99076
-Node: Programming with config files100099
-Node: Reporting bugs101411
-Node: Bug checklist102089
-Node: Mailing lists105561
-Node: Debugging106236
-Node: Logging111313
-Node: Common problems113180
-Node: Unable to find files113657
-Node: Slow path searching116067
-Node: Unable to generate fonts117442
-Node: TeX or Metafont failing119913
+Node: Introduction2263
+Node: History4336
+Node: unixtex.ftp8932
+Node: Security10357
+Node: TeX directory structure12861
+Node: Path searching16909
+Node: Searching overview17636
+Node: Path sources21455
+Node: Config files22546
+Node: Path expansion26473
+Node: Default expansion27426
+Node: Variable expansion29496
+Node: Tilde expansion30897
+Node: Brace expansion31877
+Node: KPSE_DOT expansion32816
+Node: Subdirectory expansion33329
+Node: Casefolding search35683
+Node: Casefolding rationale36452
+Node: Casefolding examples37791
+Node: Filename database42841
+Node: ls-R43899
+Node: Filename aliases46794
+Node: Database format47972
+Node: Invoking kpsewhich48985
+Node: Path searching options49940
+Node: Specially-recognized files58459
+Node: Auxiliary tasks59814
+Node: Standard options62282
+Node: TeX support62638
+Node: Supported file formats63992
+Node: File lookup71657
+Node: Glyph lookup73406
+Node: Basic glyph lookup74530
+Node: Fontmap75410
+Node: Fallback font77939
+Node: Suppressing warnings78851
+Node: mktex scripts79978
+Node: mktex configuration81193
+Node: mktex script names86996
+Node: mktex script arguments88382
+Node: Programming89261
+Node: Programming overview89834
+Node: Calling sequence92695
+Node: Program-specific files99227
+Node: Programming with config files100250
+Node: Reporting bugs101562
+Node: Bug checklist102240
+Node: Mailing lists105712
+Node: Debugging106387
+Node: Logging111464
+Node: Common problems113331
+Node: Unable to find files113808
+Node: Slow path searching116218
+Node: Unable to generate fonts117593
+Node: TeX or Metafont failing120064
 Node: Index121266
 
 End Tag Table

Modified: trunk/Build/source/texk/kpathsea/doc/kpathsea.texi
===================================================================
--- trunk/Build/source/texk/kpathsea/doc/kpathsea.texi	2018-12-13 01:23:20 UTC (rev 49399)
+++ trunk/Build/source/texk/kpathsea/doc/kpathsea.texi	2018-12-13 17:23:10 UTC (rev 49400)
@@ -3,7 +3,7 @@
 @settitle Kpathsea: A library for path searching
 
 @set version 6.3.0
- at set month-year July 2018
+ at set month-year December 2018
 
 @copying
 This file documents the Kpathsea library for path searching.
@@ -919,7 +919,7 @@
 @end example
 
 @noindent expands to @samp{foo/1/baz:foo/2/baz}.  @samp{:} is the path
-separator on the current system; e.g., on a DOS system, it's @samp{;}.
+separator on the current system; e.g., on a Windows system, it's @samp{;}.
 
 Braces can be nested; for example, @samp{x@{A,B@{1,2@}@}y} expands to
 @samp{xAy:xB1y:xB2y}.
@@ -934,7 +934,7 @@
 @file{texmf.in}.
 
 You can also use the path separator instead of the comma.  The last
-example could have been written @samp{x@{A:B@}@{1:2@}y}.
+example could have been written @samp{x@{A:B@}@{1:2@}y} (on Unix).
 
 
 @flindex expand.c
@@ -1769,8 +1769,8 @@
 
 @item --expand-braces=@var{string}
 @opindex --expand-braces=@var{string}
-Output variable and brace expansion of @var{string}.  @xref{Path
-expansion}.
+Output variable, tilde, and brace expansion of @var{string}, which is
+assumed to be a single path element.  @xref{Path expansion}.
 
 @item --expand-path=@var{string}
 @opindex --expand-path=@var{string}
@@ -1791,14 +1791,14 @@
 @end example
 
 For one-shot uses of an arbitrary (not built in to Kpathsea) path, see
- at samp{--path} (@pxref{Path searching options})
+ at samp{--path} (@pxref{Path searching options}).
 
 @item --expand-var=@var{string}
 @opindex --expand-var=@var{string}
-Output the variable and tilde expansion of @var{string}
-the @samp{mktex at dots{}} scripts run @samp{kpsewhich
---expand-var='$TEXMF'} to find the root of the @TeX{} system
-hierarchy.  @xref{Path expansion}.
+Output the variable and tilde expansion of @var{string}. For example,
+with the usual @file{texmf.cnf}, @samp{kpsewhich
+--expand-var='$TEXMF'} returns the @TeX{} system hierarchy root(s).
+ at xref{Path expansion}.
 
 @item --help-formats
 @opindex --help-formats
@@ -1826,8 +1826,9 @@
 @opindex --var-value=@var{variable}
 Outputs the value of @var{variable} (a simple identifier like
 @samp{TEXMF}, with no @samp{$} or other constructs), expanding
- at samp{$} (@pxref{Variable expansion} and @samp{~} (@pxref{Tilde
-expansion}) constructs, but not performing other expansions.
+ at samp{@{...@}} (@pxref{Brace expansion}), @samp{$} (@pxref{Variable
+expansion}) and @samp{~} (@pxref{Tilde expansion}) constructs,
+considered as strings, but not looking on the filesystem.
 
 @end table
 
@@ -3790,9 +3791,6 @@
 passed, problems may lurk.  Optimization occasionally causes trouble in
 programs other than @TeX{} and Metafont themselves, too.
 
-Insufficient swap space may also cause core dumps or other erratic
-behavior.
-
 @cindex optimization caveat
 For a workaround, if you enabled any optimization flags, it's best to
 omit optimization entirely.  In any case, the way to find the facts is
@@ -3809,8 +3807,7 @@
 To report compiler bugs effectively requires perseverance and
 perspicacity: you must find the miscompiled line, and that usually
 involves delving backwards in time from the point of error, checking
-through @TeX{}'s (or whatever program's) data structures.  Things are
-not helped by all-too-common bugs in the debugger itself.  Good luck.
+through @TeX{}'s (or whatever program's) data structures.  Good luck.
 
 
 @node Index

Modified: trunk/Build/source/texk/kpathsea/kpsewhich.c
===================================================================
--- trunk/Build/source/texk/kpathsea/kpsewhich.c	2018-12-13 01:23:20 UTC (rev 49399)
+++ trunk/Build/source/texk/kpathsea/kpsewhich.c	2018-12-13 17:23:10 UTC (rev 49400)
@@ -493,7 +493,7 @@
 -show-path=TYPE        output search path for file type TYPE\n\
                          (list shown by -help-formats).\n\
 -subdir=STRING         only output matches whose directory ends with STRING.\n\
--var-value=STRING      output the value of variable $STRING.\n\
+-var-value=STRING      output the expanded value of variable $STRING.\n\
 -version               display version information number and exit.\n \
 "
 
@@ -824,7 +824,7 @@
       }
       puts (kpse->format_info[user_format].path);
     } else {
-      WARNING1 ("kpsewhich: Unknown file type, cannot show path:",
+      WARNING1 ("kpsewhich: Unknown file type, cannot show path: ",
                 path_to_show);
     }
   }
@@ -836,6 +836,12 @@
       unfound++;
       value = "";
     }
+    /* It is helpful for users to output the fully-expanded (as a
+       string, no filesystem checks) value. We can't call brace_expand
+       as part of kpathsea_var_value, though, because unfortunately it
+       is not reentrant. We use var_value in lots of places in the
+       source, and it clobbers the static buffer in the kpse structure.  */
+    value = kpathsea_brace_expand (kpse, value);
     puts (value);
   }
 

Modified: trunk/Build/source/texk/kpathsea/path-elt.c
===================================================================
--- trunk/Build/source/texk/kpathsea/path-elt.c	2018-12-13 01:23:20 UTC (rev 49399)
+++ trunk/Build/source/texk/kpathsea/path-elt.c	2018-12-13 17:23:10 UTC (rev 49400)
@@ -1,6 +1,6 @@
 /* path-elt.c: return the stuff between colons.
 
-   Copyright 1993, 1996 2008, 2016 Karl Berry.
+   Copyright 1993, 1996, 2008, 2016, 2018 Karl Berry.
    Copyright 1997, 2001, 2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -28,7 +28,7 @@
    thus, we parse the same path over and over, on every lookup.  If that
    turns out to be a significant lose, it can be fixed, but I'm guessing
    disk accesses overwhelm everything else.  If ENV_P is true, use
-   IS_ENV_SEP; else use IS_DIR_SEP.  */
+   IS_KPSE_SEP; else use IS_DIR_SEP.  */
 
 static string
 element (kpathsea kpse, const_string passed_path,  boolean env_p)
@@ -49,10 +49,16 @@
   assert (kpse->path);
   p = kpse->path;
 
-  /* Find the next colon not enclosed by braces (or the end of the path).  */
+  /* Find the next path separator not enclosed by braces (or the end of
+     the path).  Here we want to check for either : or ; because we might
+     be called with the ;-using paths from the default texmf.cnf, e.g.,
+     with kpsewhich --expand-braces or kpsewhich --var-value, while on a
+     Unix system. Otherwise, the path elements are not parsed and thus ~
+     expansion (for example), does not happen except on the first element.
+     https://github.com/TeX-Live/texlive-source/issues/3 */
   brace_level = 0;
-  while (*p != 0  && !(brace_level == 0
-                       && (env_p ? IS_ENV_SEP (*p) : IS_DIR_SEP (*p)))) {
+  while (*p != 0 && !(brace_level == 0
+                      && (env_p ? IS_KPSE_SEP (*p) : IS_DIR_SEP (*p)))) {
     if (*p == '{') ++brace_level;
     else if (*p == '}') --brace_level;
 #if defined(WIN32)

Modified: trunk/Build/source/texk/kpathsea/pathsearch.h
===================================================================
--- trunk/Build/source/texk/kpathsea/pathsearch.h	2018-12-13 01:23:20 UTC (rev 49399)
+++ trunk/Build/source/texk/kpathsea/pathsearch.h	2018-12-13 17:23:10 UTC (rev 49400)
@@ -1,7 +1,7 @@
 /* pathsearch.h: mostly-generic path searching.
 
    Copyright 1993, 1994, 1996, 1997, 2007, 2008, 2009, 2011, 2012,
-   2014 Karl Berry.
+   2014, 2018 Karl Berry.
    Copyright 1999-2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -36,7 +36,7 @@
 #ifdef MAKE_KPSE_DLL /* libkpathsea internal only */
 
 /* If PATH is non-null, return its first element (as defined by
-   IS_ENV_SEP).  If it's NULL, return the next element in the previous
+   IS_KPSE_SEP).  If it's NULL, return the next element in the previous
    path, a la strtok.  Leading, trailing, or doubled colons result in
    the empty string.  When at the end of PATH, return NULL.  In any
    case, return a pointer to an area that may be overwritten on
@@ -47,10 +47,9 @@
    IS_DIR_SEP).  Uses same area as `kpathsea_path_element'.  */
 extern string kpathsea_filename_component (kpathsea kpse, const_string path);
 
-/*
-  This function may rewrite its argument to avoid bugs when calling
-  stat() or equivalent under Win32.  Also, it returns the index after
-  which the program should start to look for expandable constructs. */
+/* This function may rewrite its argument to avoid bugs when calling
+   stat() or equivalent under Windows.  Also, it returns the index after
+   which the program should start to look for expandable constructs. */
 extern unsigned kpathsea_normalize_path (kpathsea kpse, string elt);
 
 /* Given a path element ELT, return a pointer to a NULL-terminated list
@@ -61,8 +60,7 @@
    It's up to the caller to expand ELT.  This is because this routine is
    most likely only useful to be called from `kpathsea_path_search', which
    has already assumed expansion has been done.  */
-extern str_llist_type *kpathsea_element_dirs (kpathsea kpse,
-                                                      string elt);
+extern str_llist_type *kpathsea_element_dirs (kpathsea kpse, string elt);
 
 #endif /* MAKE_KPSE_DLL */
 



More information about the tex-live-commits mailing list