texlive[41557] Build/source/texk/kpathsea: kpathsea: Eliminate global

commits+kakuto at tug.org commits+kakuto at tug.org
Tue Jun 28 12:20:13 CEST 2016


Revision: 41557
          http://tug.org/svn/texlive?view=revision&revision=41557
Author:   kakuto
Date:     2016-06-28 12:20:13 +0200 (Tue, 28 Jun 2016)
Log Message:
-----------
kpathsea: Eliminate global and static variables (w32 only)

Modified Paths:
--------------
    trunk/Build/source/texk/kpathsea/ChangeLog
    trunk/Build/source/texk/kpathsea/config.h
    trunk/Build/source/texk/kpathsea/db.c
    trunk/Build/source/texk/kpathsea/elt-dirs.c
    trunk/Build/source/texk/kpathsea/expand.c
    trunk/Build/source/texk/kpathsea/find-suffix.c
    trunk/Build/source/texk/kpathsea/hash.c
    trunk/Build/source/texk/kpathsea/knj.c
    trunk/Build/source/texk/kpathsea/knj.h
    trunk/Build/source/texk/kpathsea/kpsewhich.c
    trunk/Build/source/texk/kpathsea/make-suffix.c
    trunk/Build/source/texk/kpathsea/path-elt.c
    trunk/Build/source/texk/kpathsea/progname.c
    trunk/Build/source/texk/kpathsea/readable.c
    trunk/Build/source/texk/kpathsea/tilde.c
    trunk/Build/source/texk/kpathsea/types.h
    trunk/Build/source/texk/kpathsea/variable.c
    trunk/Build/source/texk/kpathsea/win32lib.c
    trunk/Build/source/texk/kpathsea/win32lib.h
    trunk/Build/source/texk/kpathsea/xbasename.c
    trunk/Build/source/texk/kpathsea/xdirname.c
    trunk/Build/source/texk/kpathsea/xdirtest.c
    trunk/Build/source/texk/kpathsea/xgetcwd.c

Modified: trunk/Build/source/texk/kpathsea/ChangeLog
===================================================================
--- trunk/Build/source/texk/kpathsea/ChangeLog	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/ChangeLog	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,3 +1,11 @@
+2016-06-28  Akira Kakuto  <kakuto at fuk.kindai.ac.jp>
+
+	* config.h, db.c, elt-dirs.c, expand.c, find-suffix.c, hash.c, knj.c,
+	knj.h, kpsewhich.c, make-suffix.c, path-elt.c, progname.c, readable.c,
+	tilde.c, types.h, variable.c, win32lib.c, win32lib.h, xbasename.c,
+	xdirname.c, xdirtest.c, xgetcwd.c: Eliminate global and static
+	variables (w32 only).
+
 2016-05-28  Akira Kakuto  <kakuto at fuk.kindai.ac.jp>
 
 	* tex-file.c: Fix a bug that TEXMFOUTPUT does not work (w32 only).

Modified: trunk/Build/source/texk/kpathsea/config.h
===================================================================
--- trunk/Build/source/texk/kpathsea/config.h	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/config.h	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,7 +1,7 @@
 /* config.h: master configuration file, included first by all compilable
    source files (not headers).
 
-   Copyright 1993, 1995, 1996, 1997, 2008, 2010, 2011 Karl Berry.
+   Copyright 1993, 1995, 1996, 1997, 2008, 2010, 2011, 2016 Karl Berry.
    Copyright 2000, 2003, 2004, 2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -95,12 +95,13 @@
   but before "lib.h". FP.
 */
 #if defined (WIN32) || defined (_WIN32)
-#include <kpathsea/knj.h>
 #ifdef __MINGW32__
 #include <kpathsea/mingw32.h>
 #else
 #include <kpathsea/win32lib.h>
 #endif
+#include <kpathsea/types.h>
+#include <kpathsea/knj.h>
 #endif
 
 #if defined(WIN32) || defined(WRAP_SNPRINTF)

Modified: trunk/Build/source/texk/kpathsea/db.c
===================================================================
--- trunk/Build/source/texk/kpathsea/db.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/db.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* db.c: an external database to avoid filesystem lookups.
 
-   Copyright 1994, 1995, 1996, 1997, 2008, 2009, 2011, 2012, 2014 Karl Berry.
+   Copyright 1994, 1995, 1996, 1997, 2008, 2009, 2011, 2012, 2014, 2016 Karl Berry.
    Copyright 1997-2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -106,7 +106,7 @@
 
 #if defined(WIN32)
       for (pp = line; *pp; pp++) {
-        if (IS_KANJI(pp))
+        if (kpathsea_IS_KANJI(kpse, pp))
           pp++;
         else
           *pp = TRANSFORM(*pp);

Modified: trunk/Build/source/texk/kpathsea/elt-dirs.c
===================================================================
--- trunk/Build/source/texk/kpathsea/elt-dirs.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/elt-dirs.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* elt-dirs.c: Translate a path element to its corresponding director{y,ies}.
 
-   Copyright 1993, 1994, 1995, 1996, 1997, 2008, 2009, 2010, 2011 Karl Berry.
+   Copyright 1993, 1994, 1995, 1996, 1997, 2008, 2009, 2010, 2011, 2016 Karl Berry.
    Copyright 1997, 1998, 1999, 2000, 2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -133,7 +133,7 @@
 #if defined (WIN32)
   strcpy(dirname, FN_STRING(name));
   strcat(dirname, "/*.*");         /* "*.*" or "*" -- seems equivalent. */
-  get_wstring_from_fsyscp(dirname, dirnamew);
+  get_wstring_from_mbstring(kpse->File_system_codepage, dirname, dirnamew);
   hnd = FindFirstFileW(dirnamew, &find_file_data);
 
   if (hnd == INVALID_HANDLE_VALUE) {
@@ -158,7 +158,7 @@
       int links;
 
       /* Construct the potential subdirectory name.  */
-      potname = get_fsyscp_from_wstring(find_file_data.cFileName, potname=NULL);
+      potname = get_mbstring_from_wstring(kpse->File_system_codepage, find_file_data.cFileName, potname=NULL);
       fn_str_grow (&name, potname);
       free(potname);
 
@@ -368,7 +368,7 @@
   for (i = 0; elt[i]; i++) {
     if (elt[i] == '\\')
       elt[i] = '/';
-    else if (IS_KANJI(elt + i))
+    else if (kpathsea_IS_KANJI(kpse, elt + i))
       i++;
   }
 #endif

Modified: trunk/Build/source/texk/kpathsea/expand.c
===================================================================
--- trunk/Build/source/texk/kpathsea/expand.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/expand.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,7 +1,7 @@
 /* expand.c: general expansion.
 
    Copyright 1993, 1994, 1995, 1996, 1997, 2005, 2008, 2009, 2011,
-             2012 Karl Berry.
+             2012, 2016 Karl Berry.
    Copyright 1997-2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -226,7 +226,7 @@
   for (p = zpath; *p; p++)
     if (*p == '\\')
       *p = '/';
-    else if (IS_KANJI(p))
+    else if (kpathsea_IS_KANJI(kpse, p))
       p++;
 
   ypath = zpath;
@@ -343,7 +343,7 @@
                 for (p+=2; *p!='}';++p);
         }
 #if defined(WIN32)
-        else if (IS_KANJI(p))
+        else if (kpathsea_IS_KANJI(kpse, p))
             p++;
 #endif
     }

Modified: trunk/Build/source/texk/kpathsea/find-suffix.c
===================================================================
--- trunk/Build/source/texk/kpathsea/find-suffix.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/find-suffix.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* find-suffix.c: return the stuff after a dot.
 
-   Copyright 1992, 1993, 1995, 2008, 2011 Karl Berry.
+   Copyright 1992, 1993, 1995, 2008, 2011, 2016 Karl Berry.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -47,10 +47,6 @@
   for (p = dot_pos + 1; *p; p++) {
     if (IS_DIR_SEP (*p))
       return NULL;
-#if defined(WIN32)
-    else if (IS_KANJI(p))
-      p++;
-#endif
   }
 
   return dot_pos + 1;

Modified: trunk/Build/source/texk/kpathsea/hash.c
===================================================================
--- trunk/Build/source/texk/kpathsea/hash.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/hash.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* hash.c: hash table operations.
 
-   Copyright 1994-2000, 2002, 2005, 2008, 2012
+   Copyright 1994-2000, 2002, 2005, 2008, 2012, 2016
    Karl Berry & Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -35,7 +35,7 @@
   /* Our keys aren't often anagrams of each other, so no point in
      weighting the characters.  */
   while (*key != 0)
-#if defined(WIN32)
+#if defined (WIN32) && defined (KPSE_COMPAT_API)
     if (IS_KANJI(key)) {
       n = (n + n + (unsigned)(*key++)) % table.size;
       n = (n + n + (unsigned)(*key++)) % table.size;

Modified: trunk/Build/source/texk/kpathsea/knj.c
===================================================================
--- trunk/Build/source/texk/kpathsea/knj.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/knj.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -20,38 +20,17 @@
 #include <kpathsea/debug.h>
 #include <wchar.h>
 
-int is_cp932_system, file_system_codepage;
-
-int isknj(int c)
+static int
+is_include_space(const char *s)
 {
-  c &= 0xff;
-  switch (is_cp932_system) {
-  case 932:
-    return((c>=0x81 && c<=0x9f) || (c>=0xe0 && c<=0xfc));
-  case 936:
-    return(c>=0x81 && c<=0xfe);
-  case 950:
-    return((c>=0xa1 && c<=0xc6) || (c>=0xc9 && c<=0xf9));
-  default:
-    return(0);
-  }
+    char *p;
+    p = strchr(s, ' ');
+    if(p) return 1;
+    p = strchr(s, '\t');
+    if(p) return 1;
+    return 0;
 }
 
-int isknj2(int c)
-{
-  c &= 0xff;
-  switch (is_cp932_system) {
-  case 932:
-    return(c>=0x40 && c<=0xfc && c!=0x7f);
-  case 936:
-    return(c>=0x40 && c<=0xfe && c!=0x7f);
-  case 950:
-    return((c>=0x40 && c<=0x7e) || (c>=0xa1 && c<=0xfe));
-  default:
-    return(0);
-  }
-}
-
 /*
   Get wide string from multibyte string.
 */
@@ -96,27 +75,55 @@
   return mbstr;
 }
 
+int
+kpathsea_isknj(kpathsea kpse, int c)
+{
+  c &= 0xff;
+  switch (kpse->Is_cp932_system) {
+  case 932:
+    return((c>=0x81 && c<=0x9f) || (c>=0xe0 && c<=0xfc));
+  case 936:
+    return(c>=0x81 && c<=0xfe);
+  case 950:
+    return((c>=0xa1 && c<=0xc6) || (c>=0xc9 && c<=0xf9));
+  default:
+    return(0);
+  }
+}
+
+int
+kpathsea_isknj2(kpathsea kpse, int c)
+{
+  c &= 0xff;
+  switch (kpse->Is_cp932_system) {
+  case 932:
+    return(c>=0x40 && c<=0xfc && c!=0x7f);
+  case 936:
+    return(c>=0x40 && c<=0xfe && c!=0x7f);
+  case 950:
+    return((c>=0x40 && c<=0x7e) || (c>=0xa1 && c<=0xfe));
+  default:
+    return(0);
+  }
+}
+
 /*
   xfopen by file system codepage
 */
 FILE *
-fsyscp_xfopen (const char *filename, const char *mode)
+kpathsea_fsyscp_xfopen (kpathsea kpse, const char *filename, const char *mode)
 {
     FILE *f;
     wchar_t *fnamew, modew[4];
     int i;
-#if defined (KPSE_COMPAT_API)
-    kpathsea kpse;
-#endif
+
     assert(filename && mode);
 
-    fnamew = get_wstring_from_fsyscp(filename, fnamew=NULL);
+    fnamew = get_wstring_from_mbstring(kpse->File_system_codepage, filename, fnamew=NULL);
     for(i=0; (modew[i]=(wchar_t)mode[i]); i++) {} /* mode[i] must be ASCII */
     f = _wfopen(fnamew, modew);
     if (f == NULL)
         FATAL_PERROR(filename);
-#if defined (KPSE_COMPAT_API)
-    kpse = kpse_def;
     if (KPATHSEA_DEBUG_P (KPSE_DEBUG_FOPEN)) {
         DEBUGF_START ();
         fprintf (stderr, "fsyscp_xfopen(%s [", filename);
@@ -128,7 +135,6 @@
 #endif
         DEBUGF_END ();
     }
-#endif
     free(fnamew);
 
     return f;
@@ -138,22 +144,18 @@
   fopen by file system codepage
 */
 FILE *
-fsyscp_fopen (const char *filename, const char *mode)
+kpathsea_fsyscp_fopen (kpathsea kpse, const char *filename, const char *mode)
 {
     FILE *f;
     wchar_t *fnamew, modew[4];
     int i;
-#if defined (KPSE_COMPAT_API)
-    kpathsea kpse;
-#endif
+
     assert(filename && mode);
 
-    fnamew = get_wstring_from_fsyscp(filename, fnamew=NULL);
+    fnamew = get_wstring_from_mbstring(kpse->File_system_codepage, filename, fnamew=NULL);
     for(i=0; (modew[i]=(wchar_t)mode[i]); i++) {} /* mode[i] must be ASCII */
     f = _wfopen(fnamew, modew);
-#if defined (KPSE_COMPAT_API)
     if (f != NULL) {
-        kpse = kpse_def;
         if (KPATHSEA_DEBUG_P (KPSE_DEBUG_FOPEN)) {
             DEBUGF_START ();
             fprintf (stderr, "fsyscp_fopen(%s [", filename);
@@ -166,35 +168,19 @@
             DEBUGF_END ();
         }
     }
-#endif
     free(fnamew);
 
     return f;
 }
 
-/*
-  popen by file system codepage
-*/
-static int
-is_include_space(const char *s)
-{
-    char *p;
-    p = strchr(s, ' ');
-    if(p) return 1;
-    p = strchr(s, '\t');
-    if(p) return 1;
-    return 0;
-}
 
 FILE *
-fsyscp_popen (const char *command, const char *mode)
+kpathsea_fsyscp_popen (kpathsea kpse, const char *command, const char *mode)
 {
     FILE *f;
     wchar_t *commandw, modew[4];
     int i;
-#if defined (KPSE_COMPAT_API)
-    kpathsea kpse;
-#endif
+
     assert(command && mode);
 
     if (is_include_space (command)) {
@@ -208,16 +194,15 @@
             *q++ = *p++;
         *q++ = '\"';
         *q = '\0';
-        commandw = get_wstring_from_fsyscp(command2, commandw=NULL);
+        commandw = get_wstring_from_mbstring(kpse->File_system_codepage,command2, commandw=NULL);
         free (command2);
     } else {
-        commandw = get_wstring_from_fsyscp(command, commandw=NULL);
+        commandw = get_wstring_from_mbstring(kpse->File_system_codepage,command, commandw=NULL);
     }
     for(i=0; (modew[i]=(wchar_t)mode[i]); i++) {} /* mode[i] must be ASCII */
     f = _wpopen(commandw, modew);
-#if defined (KPSE_COMPAT_API)
+
     if (f != NULL) {
-        kpse = kpse_def;
         if (KPATHSEA_DEBUG_P (KPSE_DEBUG_FOPEN)) {
             DEBUGF_START ();
             fprintf (stderr, "fsyscp_popen(%s [", command);
@@ -230,7 +215,7 @@
             DEBUGF_END ();
         }
     }
-#endif
+
     free (commandw);
 /* We use always binary mode on Windows */
     if(f) _setmode (fileno (f), _O_BINARY);
@@ -239,7 +224,7 @@
 }
 
 int
-get_command_line_args_utf8 (const_string enc, int *p_ac, char ***p_av)
+kpathsea_get_command_line_args_utf8 (kpathsea kpse, const_string enc, int *p_ac, char ***p_av)
 {
     int argc;
     string *argv;
@@ -258,8 +243,8 @@
       HANDLE hStderr;
       hStderr = GetStdHandle( STD_ERROR_HANDLE );
 #endif /* DEBUG */
-      file_system_codepage = CP_UTF8;
-      is_cp932_system = 0;
+      kpse->File_system_codepage = CP_UTF8;
+      kpse->Is_cp932_system = 0;
       argvw = CommandLineToArgvW(GetCommandLineW(), &argcw);
       argc = argcw;
       argv = xmalloc(sizeof(char *)*(argcw+1));
@@ -275,7 +260,7 @@
       argv[argcw] = NULL;
       *p_ac = argc;
       *p_av = argv;
-      return file_system_codepage;
+      return kpse->File_system_codepage;
     } else {
       return 0;
     }
@@ -285,7 +270,7 @@
   spawnvp by file system codepage
 */
 int
-fsyscp_spawnvp (int mode, const char *command, const char* const *argv)
+kpathsea_fsyscp_spawnvp (kpathsea kpse, int mode, const char *command, const char* const *argv)
 {
     int ret;
     wchar_t *commandw, **argvw, **pw;
@@ -296,11 +281,11 @@
     for (i = 0, p = argv; *p; p++)
       i++;
     argvw = xcalloc (i + 3, sizeof (wchar_t *));
-    commandw = get_wstring_from_fsyscp(command, commandw=NULL);
+    commandw = get_wstring_from_mbstring(kpse->File_system_codepage, command, commandw=NULL);
     p = argv;
     pw = argvw;
     while (*p) {
-      *pw = get_wstring_from_fsyscp(*p, *pw=NULL);
+      *pw = get_wstring_from_mbstring(kpse->File_system_codepage, *p, *pw=NULL);
       p++;
       pw++;
     }
@@ -323,7 +308,7 @@
   system by file system codepage
 */
 int
-fsyscp_system (const char *cmd)
+kpathsea_fsyscp_system (kpathsea kpse, const char *cmd)
 {
     const char *p;
     char  *q;
@@ -353,7 +338,7 @@
       *q++ = '"';
     *q = '\0';
     av[3] = NULL;
-    ret = fsyscp_spawnvp (_P_WAIT, av[0], (const char* const*) av);
+    ret = kpathsea_fsyscp_spawnvp (kpse, _P_WAIT, av[0], (const char* const*) av);
     free (av[0]);
     free (av[1]);
     free (av[2]);
@@ -360,10 +345,8 @@
     return ret;
 }
 
-static int getc_len;
-static int getc_buff[4];
-
-int win32_getc(FILE *fp)
+int
+kpathsea_win32_getc(kpathsea kpse, FILE *fp)
 {
     const int fd = fileno(fp);
     HANDLE hStdin;
@@ -371,17 +354,16 @@
     wchar_t wc[3];
     char mbc[5];
     int j;
-    static wchar_t wcbuf = L'\0';
 
-    if (!(fd == fileno(stdin) && _isatty(fd) && file_system_codepage == CP_UTF8))
+    if (!(fd == fileno(stdin) && _isatty(fd) && kpse->File_system_codepage == CP_UTF8))
         return getc(fp);
 
-    if (getc_len == 0)
+    if (kpse->getc_len == 0)
     {
         hStdin = GetStdHandle(STD_INPUT_HANDLE);
-        if (wcbuf) {
-            wc[0] = wcbuf;
-            wcbuf = L'\0';
+        if (kpse->wcbuf) {
+            wc[0] = kpse->wcbuf;
+            kpse->wcbuf = L'\0';
         }
         else if (ReadConsoleW(hStdin, wc, 1, &ret, NULL) == 0)
             return EOF;
@@ -391,7 +373,7 @@
             if (0xdc00<=wc[1] && wc[1]<0xe000) {
                 wc[2]=L'\0';
             } else {
-                wcbuf=wc[1];
+                kpse->wcbuf=wc[1];
                 wc[0]=0xfffd;    /* illegal surrogate pair */
                 wc[1]=L'\0';
             }
@@ -404,21 +386,22 @@
         get_utf8_from_wstring(wc,mbc);
         j=strlen(mbc)-1;
         while(j>=0) {
-            getc_buff[getc_len++]=(int)mbc[j--];
+            kpse->getc_buff[kpse->getc_len++]=(int)mbc[j--];
         }
     }
-    return getc_buff[--getc_len];
+    return kpse->getc_buff[--kpse->getc_len];
 }
 
-int win32_ungetc(int c, FILE *fp)
+int
+kpathsea_win32_ungetc(kpathsea kpse, int c, FILE *fp)
 {
     const int fd = fileno(fp);
 
-    if (!(fd == fileno(stdin) && _isatty(fd) && file_system_codepage == CP_UTF8))
+    if (!(fd == fileno(stdin) && _isatty(fd) && kpse->File_system_codepage == CP_UTF8))
         return ungetc(c, fp);
 
-    assert(getc_len < 4);
-    return getc_buff[getc_len++] = c;
+    assert(kpse->getc_len < 4);
+    return kpse->getc_buff[kpse->getc_len++] = c;
 }
 
 static int __win32_fputs(const char *str, HANDLE hStdout)
@@ -437,13 +420,14 @@
     return ret;
 }
 
-int win32_fputs(const char *str, FILE *fp)
+int
+kpathsea_win32_fputs(kpathsea kpse, const char *str, FILE *fp)
 {
     const int fd = fileno(fp);
     HANDLE hStdout;
 
     if (!((fd == fileno(stdout) || fd == fileno(stderr)) && _isatty(fd)
-        && file_system_codepage == CP_UTF8))
+        && kpse->File_system_codepage == CP_UTF8))
         return fputs(str, fp);
 
     hStdout = (fd == fileno(stdout)) ?
@@ -454,7 +438,8 @@
 
 #define MAX_PROMPT_STR_SIZE 8192
 
-int win32_vfprintf(FILE *fp, const char *format, va_list argp)
+int
+kpathsea_win32_vfprintf(kpathsea kpse, FILE *fp, const char *format, va_list argp)
 {
     const int fd = fileno(fp);
     HANDLE hStdout;
@@ -462,7 +447,7 @@
     int ret;
 
     if (!((fd == fileno(stdout) || fd == fileno(stderr)) && _isatty(fd)
-        && file_system_codepage == CP_UTF8))
+        && kpse->File_system_codepage == CP_UTF8))
         return vfprintf(fp, format, argp);
 
     hStdout = (fd == fileno(stdout)) ?
@@ -475,25 +460,25 @@
     return ret;
 }
 
-int win32_puts(const char *str)
+int
+kpathsea_win32_puts(kpathsea kpse, const char *str)
 {
-    if (win32_fputs(str, stdout)==EOF) {
+    if (kpathsea_win32_fputs(kpse, str, stdout)==EOF) {
         return EOF;
     }
     return puts("");
 }
 
-int win32_putc(int c, FILE *fp)
+int
+kpathsea_win32_putc(kpathsea kpse, int c, FILE *fp)
 {
     const int fd = fileno(fp);
     HANDLE hStdout;
     DWORD ret;
     wchar_t wstr[3];
-    static int len = 0;
-    static char buff[5], *str;
 
     if (!((fd == fileno(stdout) || fd == fileno(stderr)) && _isatty(fd)
-        && file_system_codepage == CP_UTF8))
+        && kpse->File_system_codepage == CP_UTF8))
         return putc(c, fp);
 
     hStdout = (fd == fileno(stdout)) ?
@@ -502,31 +487,158 @@
     c &= 0xff;
 
     if (c < 0x80) {
-        str = buff;
-        len = 1;
+        kpse->st_str = kpse->st_buff;
+        kpse->st_len = 1;
     }
     if (c < 0xc0) { /* ASCII or trailer */
-        *str++ = c;
-        len--;
-        if (len == 0) {
-            *str = '\0';
-            get_wstring_from_utf8(buff, wstr);
+        *(kpse->st_str)++ = c;
+        kpse->st_len--;
+        if (kpse->st_len == 0) {
+            *(kpse->st_str) = '\0';
+            get_wstring_from_utf8(kpse->st_buff, wstr);
             if (WriteConsoleW(hStdout, wstr, wcslen(wstr), &ret, NULL) == 0) {
-                len = 0;
+                kpse->st_len = 0;
                 return EOF;
             }
         }
-        else if (len < 0) return EOF;
+        else if (kpse->st_len < 0) return EOF;
         return c;
     }
-    else if (c < 0xc2) { len = 0; return EOF; }  /* illegal */
-    else if (c < 0xe0) len = 2;
-    else if (c < 0xf0) len = 3;
-    else if (c < 0xf5) len = 4;
-    else { len = 0; return EOF; }
+    else if (c < 0xc2) { kpse->st_len = 0; return EOF; }  /* illegal */
+    else if (c < 0xe0) kpse->st_len = 2;
+    else if (c < 0xf0) kpse->st_len = 3;
+    else if (c < 0xf5) kpse->st_len = 4;
+    else { kpse->st_len = 0; return EOF; }
 
-    str = buff;
-    *str++ = c;
-    len--;
+    kpse->st_str = kpse->st_buff;
+    *(kpse->st_str)++ = c;
+    kpse->st_len--;
     return c;
 }
+
+int
+kpathsea_IS_KANJI(kpathsea kpse, char *p)
+{
+  int ret;
+
+  ret = kpse->Is_cp932_system && kpathsea_isknj(kpse, *(p)) &&
+        kpathsea_isknj2(kpse, *(p+1));
+  return ret;
+}
+
+char *
+kpathsea_get_fsyscp_from_wstring(kpathsea kpse, const wchar_t *w,char *mb)
+{
+  return get_mbstring_from_wstring(kpse->File_system_codepage, w, mb);
+}
+
+wchar_t *
+kpathsea_get_wstring_from_fsyscp(kpathsea kpse, const char *mb,wchar_t *w)
+{
+  return get_wstring_from_mbstring(kpse->File_system_codepage, mb, w);
+}
+
+#if defined (KPSE_COMPAT_API)
+
+int
+isknj(int c)
+{
+  return kpathsea_isknj(kpse_def, c);
+}
+
+int
+isknj2(int c)
+{
+  return kpathsea_isknj2(kpse_def, c);
+}
+
+FILE *
+fsyscp_xfopen (const char *filename, const char *mode)
+{
+  return kpathsea_fsyscp_xfopen (kpse_def, filename, mode);
+}
+
+FILE *
+fsyscp_fopen (const char *filename, const char *mode)
+{
+  return kpathsea_fsyscp_fopen (kpse_def, filename, mode);
+}
+
+FILE *
+fsyscp_popen (const char *command, const char *mode)
+{
+  return kpathsea_fsyscp_popen (kpse_def, command, mode);
+}
+
+int
+get_command_line_args_utf8 (const_string enc, int *p_ac, char ***p_av)
+{
+  return kpathsea_get_command_line_args_utf8 (kpse_def, enc, p_ac, p_av);
+}
+
+int
+fsyscp_spawnvp (int mode, const char *command, const char* const *argv)
+{
+  return kpathsea_fsyscp_spawnvp (kpse_def, mode, command, argv);
+}
+
+int
+fsyscp_system (const char *cmd)
+{
+  return kpathsea_fsyscp_system (kpse_def, cmd);
+}
+
+int
+win32_getc(FILE *fp)
+{
+  return kpathsea_win32_getc(kpse_def, fp);
+}
+
+int
+win32_ungetc(int c, FILE *fp)
+{
+  return kpathsea_win32_ungetc(kpse_def, c, fp);
+}
+
+int
+win32_fputs(const char *str, FILE *fp)
+{
+  return kpathsea_win32_fputs(kpse_def, str, fp);
+}
+
+int
+win32_vfprintf(FILE *fp, const char *format, va_list argp)
+{
+  return kpathsea_win32_vfprintf(kpse_def, fp, format, argp);
+}
+
+int
+win32_puts(const char *str)
+{
+  return kpathsea_win32_puts(kpse_def, str);
+}
+
+int
+win32_putc(int c, FILE *fp)
+{
+  return kpathsea_win32_putc(kpse_def, c, fp);
+}
+
+int
+IS_KANJI(char *p)
+{
+  return kpathsea_IS_KANJI(kpse_def, p);
+}
+
+char *
+get_fsyscp_from_wstring(const wchar_t *w,char *mb)
+{
+  return kpathsea_get_fsyscp_from_wstring(kpse_def, w, mb);
+}
+
+wchar_t *
+get_wstring_from_fsyscp(const char *mb,wchar_t *w)
+{
+  return kpathsea_get_wstring_from_fsyscp(kpse_def, mb, w);
+}
+#endif

Modified: trunk/Build/source/texk/kpathsea/knj.h
===================================================================
--- trunk/Build/source/texk/kpathsea/knj.h	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/knj.h	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* knj.h: check for 2-Byte Kanji (CP 932, SJIS) codes.
 
-   Copyright 2010, 2014 Akira Kakuto.
+   Copyright 2010, 2014, 2016 Akira Kakuto.
    Copyright 2013, 2014 TANAKA Takuji.
 
    This library is free software; you can redistribute it and/or
@@ -23,14 +23,32 @@
 extern "C" {
 #endif
 
-extern KPSEDLL int is_cp932_system;
-extern KPSEDLL int file_system_codepage;
+extern KPSEDLL wchar_t* get_wstring_from_mbstring(int cp, const char *mbstr, wchar_t *wstr);
+extern KPSEDLL char* get_mbstring_from_wstring(int cp, const wchar_t *wstr, char *mbstr);
+extern KPSEDLL int kpathsea_isknj(kpathsea kpse, int c);
+extern KPSEDLL int kpathsea_isknj2(kpathsea kpse, int c);
+extern KPSEDLL FILE* kpathsea_fsyscp_xfopen(kpathsea kpse, const char *filename, const char *mode);
+extern KPSEDLL FILE* kpathsea_fsyscp_fopen(kpathsea kpse, const char *filename, const char *mode);
+extern KPSEDLL FILE* kpathsea_fsyscp_popen(kpathsea kpse, const char *command, const char *mode);
+extern KPSEDLL int kpathsea_fsyscp_spawnvp(kpathsea kpse, int mode, const char *command, const char* const *argv);
+extern KPSEDLL int kpathsea_fsyscp_system(kpathsea kpse, const char *cmd);
+extern KPSEDLL int kpathsea_get_command_line_args_utf8(kpathsea kpse, const char *enc, int *p_ac, char ***p_av);
+extern KPSEDLL int kpathsea_win32_getc(kpathsea kpse, FILE *fp);
+extern KPSEDLL int kpathsea_win32_ungetc(kpathsea kpse, int c, FILE *fp);
+extern KPSEDLL int kpathsea_win32_fputs(kpathsea kpse, const char *str, FILE *fp);
+extern KPSEDLL int kpathsea_win32_puts(kpathsea kpse, const char *str);
+extern KPSEDLL int kpathsea_win32_vfprintf(kpathsea kpse, FILE *fp, const char *format, va_list argp);
+extern KPSEDLL int kpathsea_win32_putc(kpathsea kpse, int c, FILE *fp);
+extern KPSEDLL int kpathsea_IS_KANJI(kpathsea kpse, char *p);
+extern KPSEDLL char *kpathsea_get_fsyscp_from_wstring(kpathsea kpse, const wchar_t *w,char *mb);
+extern KPSEDLL wchar_t *kpathsea_get_wstring_from_fsyscp(kpathsea kpse, const char *mb,wchar_t *w);
 
+#if defined (KPSE_COMPAT_API)
+#define is_cp932_system kpse_def->Is_cp932_system
+#define file_system_codepage kpse_def->File_system_codepage
+
 extern KPSEDLL int isknj(int c);
 extern KPSEDLL int isknj2(int c);
-
-extern KPSEDLL wchar_t* get_wstring_from_mbstring(int cp, const char *mbstr, wchar_t *wstr);
-extern KPSEDLL char* get_mbstring_from_wstring(int cp, const wchar_t *wstr, char *mbstr);
 extern KPSEDLL FILE* fsyscp_xfopen(const char *filename, const char *mode);
 extern KPSEDLL FILE* fsyscp_fopen(const char *filename, const char *mode);
 extern KPSEDLL FILE* fsyscp_popen(const char *command, const char *mode);
@@ -43,21 +61,17 @@
 extern KPSEDLL int win32_puts(const char *str);
 extern KPSEDLL int win32_vfprintf(FILE *fp, const char *format, va_list argp);
 extern KPSEDLL int win32_putc(int c, FILE *fp);
-
+extern KPSEDLL int IS_KANJI(char *p);
+extern KPSEDLL char *get_fsyscp_from_wstring(const wchar_t *w,char *mb);
+extern KPSEDLL wchar_t *get_wstring_from_fsyscp(const char *mb,wchar_t *w);
+#endif
 #ifdef __cplusplus
 }
 #endif
 
-/* True if P points to a 2-Byte Kanji (CP 932, SJIS) code.  */
-#define IS_KANJI(p) is_cp932_system && isknj(*(p)) && isknj2(*(p+1))
-
 /* Get wide string from multibyte string in UTF-8 */
 #define get_wstring_from_utf8(mb,w) get_wstring_from_mbstring(CP_UTF8,mb,w)
 /* Get multibyte string in UTF-8 from wide string */
 #define get_utf8_from_wstring(w,mb) get_mbstring_from_wstring(CP_UTF8,w,mb)
-/* Get wide string from multibyte string in file system codepage */
-#define get_wstring_from_fsyscp(mb,w) get_wstring_from_mbstring(file_system_codepage,mb,w)
-/* Get multibyte string in file system codepage from wide string */
-#define get_fsyscp_from_wstring(w,mb) get_mbstring_from_wstring(file_system_codepage,w,mb)
 
 #endif /* not KPATHSEA_KNJ_H */

Modified: trunk/Build/source/texk/kpathsea/kpsewhich.c
===================================================================
--- trunk/Build/source/texk/kpathsea/kpsewhich.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/kpsewhich.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -30,13 +30,6 @@
 #include <kpathsea/variable.h>
 #include <kpathsea/version.h>
 
-#ifdef WIN32
-#undef fputs
-#undef puts
-#define fputs win32_fputs
-#define puts  win32_puts
-#endif
-
 /* For variable and path expansion.  (-expand-var, -expand-path,
    -show-path) */
 string var_to_expand = NULL;
@@ -272,14 +265,14 @@
    We don't reallocate the actual strings, just the list elements.
    Perhaps later we will implement wildcards or // or something.  */
 
+#if defined(WIN32)
 static string *
-subdir_match (str_list_type subdirs,  string *matches)
+kpathsea_subdir_match (kpathsea kpse, str_list_type subdirs,  string *matches)
 {
   string *ret = XTALLOC1 (string);
   unsigned len = 1;
   unsigned e;
   unsigned m;
-#if defined(WIN32)
   string p;
 
   for (e = 0; e < STR_LIST_LENGTH (subdirs); e++) {
@@ -286,11 +279,10 @@
     for (p = STR_LIST_ELT (subdirs, e); *p; p++) {
       if (*p == '\\')
         *p = '/';
-      else if (IS_KANJI(p))
+      else if (kpathsea_IS_KANJI(kpse, p))
         p++;
     }
   }
-#endif
 
   for (m = 0; matches[m]; m++) {
     unsigned loc;
@@ -322,7 +314,46 @@
   return ret;
 }
 
+#else /* WIN32 */
+static string *
+subdir_match (str_list_type subdirs,  string *matches)
+{
+  string *ret = XTALLOC1 (string);
+  unsigned len = 1;
+  unsigned e;
+  unsigned m;
 
+  for (m = 0; matches[m]; m++) {
+    unsigned loc;
+    string s = xstrdup (matches[m]);
+    for (loc = strlen (s); loc > 0 && !IS_DIR_SEP_CH (s[loc-1]); loc--)
+      ;
+    while (loc > 0 && IS_DIR_SEP_CH (s[loc-1])) {
+      loc--;
+    }
+    s[loc] = 0;  /* wipe out basename */
+
+    for (e = 0; e < STR_LIST_LENGTH (subdirs); e++) {
+      string subdir = STR_LIST_ELT (subdirs, e);
+      unsigned subdir_len = strlen (subdir);
+      while (subdir_len > 0 && IS_DIR_SEP_CH (subdir[subdir_len-1])) {
+        subdir_len--;
+        subdir[subdir_len] = 0; /* remove trailing slashes from subdir spec */
+      }
+      if (FILESTRCASEEQ (subdir, s + loc - subdir_len)) {
+        /* matched, save this one.  */
+        XRETALLOC (ret, len + 1, string);
+        ret[len-1] = matches[m];
+        len++;
+      }
+    }
+    free (s);
+  }
+  ret[len-1] = NULL;
+  return ret;
+}
+#endif /* WIN32 */
+
 

 /* Look up a single filename NAME.  Return 0 if success, 1 if failure.  */
 
@@ -395,7 +426,11 @@
 
   /* Filter by subdirectories, if specified.  */
   if (STR_LIST_LENGTH (subdir_paths) > 0) {
+#if defined(WIN32)
+    string *new_list = kpathsea_subdir_match (kpse, subdir_paths, ret_list);
+#else
     string *new_list = subdir_match (subdir_paths, ret_list);
+#endif /* WIN32 */
     free (ret_list);
     ret_list = new_list;
   }
@@ -403,7 +438,11 @@
   /* Print output.  */
   if (ret_list) {
     for (i = 0; ret_list[i]; i++)
+#ifdef WIN32
+      kpathsea_win32_puts (kpse, ret_list[i]);
+#else
       puts (ret_list[i]);
+#endif
     /* Save whether we found anything */
     ret = ret_list[0];
     free (ret_list);
@@ -452,10 +491,19 @@
 help_message (kpathsea kpse, string *argv)
 {
   printf ("Usage: %s [OPTION]... [FILENAME]...\n", argv[0]);
+#ifdef WIN32
+  kpathsea_win32_fputs (kpse, USAGE, stdout);
+#else
   fputs (USAGE, stdout);
+#endif
   putchar ('\n');
+#ifdef WIN32
+  kpathsea_win32_fputs (kpse, kpathsea_bug_address, stdout);
+  kpathsea_win32_fputs (kpse, "Kpathsea home page: http://tug.org/kpathsea/\n", stdout);
+#else
   fputs (kpathsea_bug_address, stdout);
   fputs ("Kpathsea home page: http://tug.org/kpathsea/\n", stdout);
+#endif
   exit (0);
 }
 
@@ -467,8 +515,13 @@
   /* Have to set this for init_format to work.  */
   kpathsea_set_program_name (kpse, argv[0], progname);
 
+#ifdef WIN32
+  kpathsea_win32_puts (kpse, kpathsea_version_string); 
+  kpathsea_win32_puts (kpse, "\nRecognized Kpathsea format names and their (abbreviations) and suffixes:");
+#else
   puts (kpathsea_version_string); 
   puts ("\nRecognized Kpathsea format names and their (abbreviations) and suffixes:");
+#endif
   for (f = 0; f < kpse_last_format; f++) {
     const_string *ext;
 
@@ -493,7 +546,11 @@
     putchar (':');
     for (ext = kpse->format_info[f].suffix; ext && *ext; ext++) {
       putchar (' ');
+#ifdef WIN32
+      kpathsea_win32_fputs (kpse, *ext, stdout);
+#else
       fputs (*ext, stdout);
+#endif
     }
 
     if (kpse->format_info[f].alt_suffix) {
@@ -502,7 +559,11 @@
     }
     for (ext = kpse->format_info[f].alt_suffix; ext && *ext; ext++) {
       putchar (' ');
+#ifdef WIN32
+      kpathsea_win32_fputs (kpse, *ext, stdout);
+#else
       fputs (*ext, stdout);
+#endif
     }
 
     printf ("  [variables: %s]\n", envvar_list);
@@ -511,8 +572,13 @@
             kpse->format_info[f].path_source, kpse->format_info[f].raw_path);
   }
 
+#ifdef WIN32
+  kpathsea_win32_fputs (kpse, "\nTo see paths after expansion, use --show-path=FMT.\n\n", stdout);
+  kpathsea_win32_fputs (kpse, kpathsea_bug_address, stdout);
+#else
   fputs ("\nTo see paths after expansion, use --show-path=FMT.\n\n", stdout);
   fputs (kpathsea_bug_address, stdout);
+#endif
   exit (0);
 }
 
@@ -630,11 +696,19 @@
       var_to_value = optarg;
 
     } else if (ARGUMENT_IS ("version")) {
+#ifdef WIN32
+      kpathsea_win32_puts (kpse, kpathsea_version_string);
+      kpathsea_win32_puts (kpse, "Copyright 2016 Karl Berry & Olaf Weber.\n\
+License LGPLv2.1+: GNU Lesser GPL version 2.1 or later <http://gnu.org/licenses/lgpl.html>\n\
+This is free software: you are free to change and redistribute it.\n\
+There is NO WARRANTY, to the extent permitted by law.\n");
+#else
       puts (kpathsea_version_string);
       puts ("Copyright 2016 Karl Berry & Olaf Weber.\n\
 License LGPLv2.1+: GNU Lesser GPL version 2.1 or later <http://gnu.org/licenses/lgpl.html>\n\
 This is free software: you are free to change and redistribute it.\n\
 There is NO WARRANTY, to the extent permitted by law.\n");
+#endif
       exit (0);
     }
 
@@ -644,7 +718,11 @@
   if (user_path && user_format_string) {
     fprintf (stderr, "-path (%s) and -format (%s) are mutually exclusive.\n",
              user_path, user_format_string);
+#ifdef WIN32
+    kpathsea_win32_fputs (kpse, "Try `kpsewhich --help' for more information.\n", stderr);
+#else
     fputs ("Try `kpsewhich --help' for more information.\n", stderr);
+#endif
     exit (1);
   }
 
@@ -652,8 +730,13 @@
       && !var_to_expand && !braces_to_expand && !path_to_expand
       && !path_to_show && !var_to_value
       && !safe_in_name && !safe_out_name) {
+#ifdef WIN32
+    kpathsea_win32_fputs (kpse, "Missing argument. Try `kpsewhich --help' for more information.\n",
+           stderr);
+#else
     fputs ("Missing argument. Try `kpsewhich --help' for more information.\n",
            stderr);
+#endif
     exit (1);
   }
 }
@@ -720,7 +803,7 @@
       enc = "utf-8";
     else
       enc = kpathsea_var_value (kpse, "command_line_encoding");
-    if (get_command_line_args_utf8(enc, &ac, &av)) {
+    if (kpathsea_get_command_line_args_utf8(kpse, enc, &ac, &av)) {
       optind = 0;
       read_command_line (kpse, ac, av);
       argv = av;
@@ -735,15 +818,27 @@
 
   /* Variable expansion.  */
   if (var_to_expand)
+#ifdef WIN32
+    kpathsea_win32_puts (kpse, kpathsea_var_expand (kpse, var_to_expand));
+#else
     puts (kpathsea_var_expand (kpse, var_to_expand));
+#endif
 
   /* Brace expansion. */
   if (braces_to_expand)
+#ifdef WIN32
+    kpathsea_win32_puts (kpse, kpathsea_brace_expand (kpse, braces_to_expand));
+#else
     puts (kpathsea_brace_expand (kpse, braces_to_expand));
+#endif
 
   /* Path expansion. */
   if (path_to_expand)
+#ifdef WIN32
+    kpathsea_win32_puts (kpse, kpathsea_path_expand (kpse, path_to_expand));
+#else
     puts (kpathsea_path_expand (kpse, path_to_expand));
+#endif
 
   /* Show a search path. */
   if (path_to_show) {
@@ -750,7 +845,11 @@
     if (user_format != kpse_last_format) {
       if (!kpse->format_info[user_format].type) /* needed if arg was numeric */
         kpathsea_init_format (kpse, user_format);
+#ifdef WIN32
+      kpathsea_win32_puts (kpse, kpse->format_info[user_format].path);
+#else
       puts (kpse->format_info[user_format].path);
+#endif
     } else {
       WARNING ("kpsewhich: Cannot show path for unknown file type");
     }
@@ -763,7 +862,11 @@
       unfound++;
       value = "";
     }
+#ifdef WIN32
+    kpathsea_win32_puts (kpse, value);
+#else
     puts (value);
+#endif
   }
 
   if (safe_in_name) {

Modified: trunk/Build/source/texk/kpathsea/make-suffix.c
===================================================================
--- trunk/Build/source/texk/kpathsea/make-suffix.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/make-suffix.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* make-suffix.c: unconditionally add a filename suffix.
 
-   Copyright 1992, 1993, 1995, 2008, 2011 Karl Berry.
+   Copyright 1992, 1993, 1995, 2008, 2011, 2016 Karl Berry.
    Copyright 2001, 2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -38,7 +38,7 @@
         dot_pos = NULL;
         break;
       }
-#if defined(WIN32)
+#if defined(WIN32) && defined(KPSE_COMPAT_API)
       else if (IS_KANJI(p))
         p++;
 #endif
@@ -59,8 +59,10 @@
   for (q = new_s; *q; q++) {
     if (*q == '\\')
       *q = '/';
+#if defined(KPSE_COMPAT_API)
     else if (IS_KANJI(q))
       q++;
+#endif
   }
 #endif
 

Modified: trunk/Build/source/texk/kpathsea/path-elt.c
===================================================================
--- trunk/Build/source/texk/kpathsea/path-elt.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/path-elt.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* path-elt.c: return the stuff between colons.
 
-   Copyright 1993, 1996 2008 Karl Berry.
+   Copyright 1993, 1996 2008, 2016 Karl Berry.
    Copyright 1997, 2001, 2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -56,7 +56,7 @@
     if (*p == '{') ++brace_level;
     else if (*p == '}') --brace_level;
 #if defined(WIN32)
-    else if (IS_KANJI(p))
+    else if (kpathsea_IS_KANJI(kpse, p))
         p++;
 #endif
     p++;

Modified: trunk/Build/source/texk/kpathsea/progname.c
===================================================================
--- trunk/Build/source/texk/kpathsea/progname.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/progname.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* progname.c: the executable name we were invoked as; general initialization.
 
-   Copyright 1994, 1996, 1997, 2008-2013 Karl Berry.
+   Copyright 1994, 1996, 1997, 2008-2013, 2016 Karl Berry.
    Copyright 1998-2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -501,14 +501,14 @@
   }
 
 #if defined(WIN32)
-  if (!file_system_codepage)
-    file_system_codepage = AreFileApisANSI() ? GetACP() : GetOEMCP();
-  cp = file_system_codepage;
+  if (!kpse->File_system_codepage)
+    kpse->File_system_codepage = AreFileApisANSI() ? GetACP() : GetOEMCP();
+  cp = kpse->File_system_codepage;
   if (cp == 932 || cp == 936 || cp == 950) {
-    is_cp932_system = cp;
+    kpse->Is_cp932_system = cp;
   }
   else
-    is_cp932_system = 0;
+    kpse->Is_cp932_system = 0;
 
 #if defined(__MINGW32__)
   /* Set various info about user. Among many things,
@@ -585,7 +585,7 @@
     for (fp = path; fp && *fp; fp++)
         if (IS_DIR_SEP(*fp)) *fp = DIR_SEP;
 #else /* !__MINGW32__ */
-    if (getlongpath(path, short_path, PATH_MAX) == 0)
+    if (kpathsea_getlongpath(kpse, path, short_path, PATH_MAX) == 0)
         FATAL1("Can't get long name for %s.\n", short_path);
     if ((hnd = FindFirstFile(short_path, &ffd)) == INVALID_HANDLE_VALUE)
         FATAL1("The following path points to an invalid file : %s\n", path);

Modified: trunk/Build/source/texk/kpathsea/readable.c
===================================================================
--- trunk/Build/source/texk/kpathsea/readable.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/readable.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* readable.c: check if a filename is a readable non-directory file.
 
-   Copyright 1993, 1995, 1996, 2008, 2011, 2012 Karl Berry.
+   Copyright 1993, 1995, 1996, 2008, 2011, 2012, 2016 Karl Berry.
    Copyright 1998, 1999, 2000, 2001, 2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -38,10 +38,10 @@
 #elif defined (WIN32)
 /* st must be an unsigned int under Windows */
 static boolean
-READABLE(const_string fn, unsigned int st)
+READABLE(kpathsea kpse, const_string fn, unsigned int st)
 {
   wchar_t *fnw;
-  fnw = get_wstring_from_fsyscp(fn, fnw=NULL);
+  fnw = get_wstring_from_mbstring(kpse->File_system_codepage, fn, fnw=NULL);
   if ((st = GetFileAttributesW(fnw)) != 0xFFFFFFFF) {
       /* succeeded */
       errno = 0;
@@ -82,7 +82,11 @@
 #endif
 
   kpathsea_normalize_path (kpse, name);
+#ifdef WIN32
+  if (READABLE (kpse, name, st)) {
+#else
   if (READABLE (name, st)) {
+#endif
       return name;
 #ifdef ENAMETOOLONG
   } else if (errno == ENAMETOOLONG) {
@@ -95,7 +99,7 @@
           if (c_len <= NAME_MAX)
               t = s;
 #if defined(WIN32)
-          if (IS_KANJI (s)) {
+          if (kpathsea_IS_KANJI (kpse, s)) {
               s++;
               c_len += 2;
               continue;
@@ -118,7 +122,11 @@
 
       /* Perhaps some other error will occur with the truncated name, so
          let's call access again.  */
+#ifdef WIN32
+      if (READABLE (kpse, name, st)) /* Success.  */
+#else
       if (READABLE (name, st)) /* Success.  */
+#endif
           return name;
 #endif /* ENAMETOOLONG */
   } else { /* Some other error.  */

Modified: trunk/Build/source/texk/kpathsea/tilde.c
===================================================================
--- trunk/Build/source/texk/kpathsea/tilde.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/tilde.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,7 +1,7 @@
 /* tilde.c: expand user's home directories.
 
     Copyright 1997, 1998, 2005, Olaf Weber.
-    Copyright 1993, 1995, 1996, 1997, 2008, 2011 Karl Berry.
+    Copyright 1993, 1995, 1996, 1997, 2008, 2011, 2016 Karl Berry.
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
@@ -88,7 +88,7 @@
       c = 2;
       while (!IS_DIR_SEP (name[c]) && name[c] != 0) {  /* find user name */
 #if defined(WIN32)
-        if (IS_KANJI(name+c))
+        if (kpathsea_IS_KANJI(kpse, name+c))
           c++;
 #endif
         c++;
@@ -130,7 +130,7 @@
       for (q = home; *q; q++) {
         if (IS_DIR_SEP (*q) && q[1] == 0)
           c++;
-        else if (IS_KANJI(q))
+        else if (kpathsea_IS_KANJI(kpse, q))
           q++;
       }
 #else
@@ -146,7 +146,7 @@
   for (p = expansion; *p; p++) {
     if (*p == '\\')
       *p = '/'; 
-    else if (IS_KANJI(p))
+    else if (kpathsea_IS_KANJI(kpse, p))
       p++;
   }
 #endif

Modified: trunk/Build/source/texk/kpathsea/types.h
===================================================================
--- trunk/Build/source/texk/kpathsea/types.h	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/types.h	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* types.h: general types for kpathsea.
 
-   Copyright 1993, 1995, 1996, 2005, 2008-2014 Karl Berry.
+   Copyright 1993, 1995, 1996, 2005, 2008-2014, 2016 Karl Berry.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -292,6 +292,16 @@
     struct passwd the_passwd;
     int __system_allow_multiple_cmds;
 #endif /* WIN32 && !__MINGW32__ */
+#if defined(WIN32)
+    int Is_cp932_system;
+    int File_system_codepage;
+    int getc_len;
+    int getc_buff[4];
+    wchar_t wcbuf;
+    int st_len;
+    char st_buff[5];
+    char *st_str;
+#endif
 } kpathsea_instance;
 
 /* these come from kpathsea.c */

Modified: trunk/Build/source/texk/kpathsea/variable.c
===================================================================
--- trunk/Build/source/texk/kpathsea/variable.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/variable.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* variable.c: variable expansion.
 
-    Copyright 1993, 1994, 1995, 1996, 2008, 2009, 2011, 2012 Karl Berry.
+    Copyright 1993, 1994, 1995, 1996, 2008, 2009, 2011, 2012, 2016 Karl Berry.
     Copyright 1997, 1999, 2001, 2002, 2005 Olaf Weber.
 
     This library is free software; you can redistribute it and/or
@@ -222,7 +222,7 @@
 
         while (*var_end && !IS_VAR_END_DELIMITER (*var_end)) {
 #if defined(WIN32)
-          if (IS_KANJI(var_end))
+          if (kpathsea_IS_KANJI(kpse, var_end))
             var_end++;
 #endif
           var_end++;

Modified: trunk/Build/source/texk/kpathsea/win32lib.c
===================================================================
--- trunk/Build/source/texk/kpathsea/win32lib.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/win32lib.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -172,7 +172,7 @@
                1 if succeeded
 */
 
-int getlongpath(char *buff, char *input, int len)
+int kpathsea_getlongpath(kpathsea kpse, char *buff, char *input, int len)
 {
    HANDLE hnd;
    WIN32_FIND_DATA ffd;
@@ -202,7 +202,7 @@
       p += 2;
       r += 2;
       while(*p != '\\' && *p) {
-         if (IS_KANJI(p)) {
+         if (kpathsea_IS_KANJI(kpse, p)) {
             cnt++;
             if(cnt > len) return 0;
             *r++ = *p++;
@@ -216,7 +216,7 @@
       *r++ = '/';
       if(*p) p++;
       while(*p != '\\' && *p) {
-         if (IS_KANJI(p)) {
+         if (kpathsea_IS_KANJI(kpse, p)) {
             cnt++;
             if(cnt > len) return 0;
             *r++ = *p++;
@@ -244,7 +244,7 @@
    }
 
    for( ; *p; p++) {
-      if(IS_KANJI(p)) {
+      if(kpathsea_IS_KANJI(kpse, p)) {
          p++;
          continue;
       }
@@ -292,7 +292,7 @@
 /* Sync'ed with Emacs 19.34.6 by Marc Paquette <marcpa at cam.org> */
 /* Adapted to fpTeX 0.4 by Fabrice Popineau <Fabrice.Popineau at supelec.fr> */
 
-char * get_home_directory()
+char * kpathsea_get_home_directory(kpathsea kpse)
 {
   char *p;
   char *home = getenv("HOME");
@@ -301,7 +301,7 @@
   if(home) {
     home = xstrdup(home);
     for(p = home; *p; p++) {
-      if(IS_KANJI(p)) {
+      if(kpathsea_IS_KANJI(kpse, p)) {
         p++;
         continue;
       }
@@ -360,7 +360,7 @@
 
    /* Ensure HOME and SHELL are defined. */
 
-   home = get_home_directory();
+   home = kpathsea_get_home_directory(kpse);
    if (home) {
       putenv(concat("HOME=", home));
    }
@@ -381,7 +381,7 @@
    }
 
    /* Set dir and shell from environment variables. */
-   strcpy (kpse->the_passwd.pw_dir, get_home_directory());
+   strcpy (kpse->the_passwd.pw_dir, kpathsea_get_home_directory(kpse));
    strcpy (kpse->the_passwd.pw_shell, getenv ("SHELL"));
 }
 
@@ -424,6 +424,16 @@
 }
 
 #if defined (KPSE_COMPAT_API)
+int getlongpath(char *buff, char *input, int len)
+{
+  return kpathsea_getlongpath(kpse_def, buff, input, len);
+}
+
+char * get_home_directory(void)
+{
+  return kpathsea_get_home_directory(kpse_def);
+}
+
 int 
 getuid (void) 
 { 

Modified: trunk/Build/source/texk/kpathsea/win32lib.h
===================================================================
--- trunk/Build/source/texk/kpathsea/win32lib.h	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/win32lib.h	2016-06-28 10:20:13 UTC (rev 41557)
@@ -275,8 +275,13 @@
 extern KPSEDLL int system(const char * cmd);
 
 extern KPSEDLL void texlive_gs_init(void);
+extern KPSEDLL int kpathsea_getlongpath (kpathsea kpse, char *output, char *input, int len);
+extern KPSEDLL char *kpathsea_get_home_directory (kpathsea kpse);
+
+#if defined (KPSE_COMPAT_API)
 extern KPSEDLL int getlongpath (char *output, char *input, int len);
 extern KPSEDLL char *get_home_directory (void);
+#endif
 
 #define off_t __int64
 #define xfseeko xfseek64

Modified: trunk/Build/source/texk/kpathsea/xbasename.c
===================================================================
--- trunk/Build/source/texk/kpathsea/xbasename.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/xbasename.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* xbasename.c: return the last element in a path.
 
-   Copyright 1992, 1994, 1995, 1996, 2008, 2011 Karl Berry.
+   Copyright 1992, 1994, 1995, 1996, 2008, 2011, 2016 Karl Berry.
    Copyright 2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -38,13 +38,13 @@
         unsigned limit;
 
         for (limit = 2; name[limit] && !IS_DIR_SEP (name[limit]); limit++)
-#if defined(WIN32)
+#if defined(WIN32) && defined (KPSE_COMPAT_API)
             if (IS_KANJI(name+limit)) limit++
 #endif
             ;
         if (name[limit++] && name[limit] && !IS_DIR_SEP (name[limit])) {
             for (; name[limit] && !IS_DIR_SEP (name[limit]); limit++)
-#if defined(WIN32)
+#if defined(WIN32) && defined (KPSE_COMPAT_API)
                 if (IS_KANJI(name+limit)) limit++
 #endif
                 ;
@@ -57,7 +57,7 @@
     for (p = base; *p; p++) {
         if (IS_DIR_SEP(*p))
             base = p + 1;
-#if defined(WIN32)
+#if defined(WIN32) && defined (KPSE_COMPAT_API)
         else if (IS_KANJI(p))
             p++;
 #endif

Modified: trunk/Build/source/texk/kpathsea/xdirname.c
===================================================================
--- trunk/Build/source/texk/kpathsea/xdirname.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/xdirname.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* xdirname.c: return the directory part of a path.
 
-   Copyright 1999, 2008, 2011 Karl Berry.
+   Copyright 1999, 2008, 2011, 2016 Karl Berry.
    Copyright 2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -43,13 +43,13 @@
         limit = 2;
     } else if (IS_UNC_NAME(name)) {
         for (limit = 2; name[limit] && !IS_DIR_SEP (name[limit]); limit++)
-#if defined(WIN32)
+#if defined(WIN32) && defined(KPSE_COMPAT_API)
             if (IS_KANJI(name+limit)) limit++
 #endif
             ;
         if (name[limit++] && name[limit] && !IS_DIR_SEP (name[limit])) {
             for (; name[limit] && !IS_DIR_SEP (name[limit]); limit++)
-#if defined(WIN32)
+#if defined(WIN32) && defined(KPSE_COMPAT_API)
                 if (IS_KANJI(name+limit)) limit++
 #endif
                 ;
@@ -68,7 +68,10 @@
             for (i++; IS_DIR_SEP (name[i]); i++)
                 ;
             loc = i + 1;
-        } else if (IS_KANJI(name+i)) i++;
+        }
+#if defined (KPSE_COMPAT_API)
+        else if (IS_KANJI(name+i)) i++;
+#endif
     }
 #else
     for (loc = strlen (name); loc > limit && !IS_DIR_SEP (name[loc-1]); loc--)
@@ -107,8 +110,10 @@
     for (p = ret; *p; p++) {
         if (*p == '\\')
             *p = '/';
+#if defined (KPSE_COMPAT_API)
         else if (IS_KANJI(p))
             p++;
+#endif
     }
 #endif
 

Modified: trunk/Build/source/texk/kpathsea/xdirtest.c
===================================================================
--- trunk/Build/source/texk/kpathsea/xdirtest.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/xdirtest.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -3,6 +3,7 @@
    Copyright 1999 Karl Berry.
    Copyright 2005 Olaf Weber.
    Copyright 2011 Peter Breitenlohner.
+   Copyright 2016 Akira Kakuto.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -100,10 +101,10 @@
 }
 
 static void
-do_kanji (void) {
+do_kanji (kpathsea kpse) {
     const char **p;
 
-    printf("\nAssuming CP %s 932\n", is_cp932_system ? "is" : "is not");
+    printf("\nAssuming CP %s 932\n", kpse->Is_cp932_system ? "is" : "is not");
 
     for (p = ktab; *p; p++) {
         char *q = to_kanji(*p);
@@ -117,18 +118,18 @@
 }
 
 static void
-kanji_test(void) {
-    int save_cp932 = is_cp932_system;
+kanji_test(kpathsea kpse) {
+    int save_cp932 = kpse->Is_cp932_system;
 
     printf("\nTesting 2-Byte Kanji (CP 932, SJIS) codes with 'K' representing 0x81\n");
 
-    is_cp932_system = 932;	/* pretend CP is 932 */
-    do_kanji();
+    kpse->Is_cp932_system = 932;	/* pretend CP is 932 */
+    do_kanji(kpse);
 
-    is_cp932_system = 0;	/* pretend CP is not 932 */
-    do_kanji();
+    kpse->Is_cp932_system = 0;	/* pretend CP is not 932 */
+    do_kanji(kpse);
 
-    is_cp932_system = save_cp932;
+    kpse->Is_cp932_system = save_cp932;
 }
 #endif
 
@@ -150,7 +151,7 @@
     }
 
 #if defined (WIN32)
-    kanji_test();
+    kanji_test(kpse);
 #endif
 
     return 0;

Modified: trunk/Build/source/texk/kpathsea/xgetcwd.c
===================================================================
--- trunk/Build/source/texk/kpathsea/xgetcwd.c	2016-06-28 01:14:58 UTC (rev 41556)
+++ trunk/Build/source/texk/kpathsea/xgetcwd.c	2016-06-28 10:20:13 UTC (rev 41557)
@@ -1,6 +1,6 @@
 /* xgetcwd.c: a from-scratch version of getwd.  Ideas from tcsh 5.20 source.
 
-   Copyright 1992, 1994, 1996, 2008, 2011 Karl Berry.
+   Copyright 1992, 1994, 1996, 2008, 2011, 2016 Karl Berry.
    Copyright 2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -61,8 +61,10 @@
     for (pp = path; *pp; pp++) {
         if (*pp == '\\')
             *pp = '/';
+#if defined (KPSE_COMPAT_API)
         else if (IS_KANJI(pp))
             pp++;
+#endif
     }
 #endif
 



More information about the tex-live-commits mailing list