texlive[46468] Build/source/texk/kpathsea: doc fixes, code formatting

commits+karl at tug.org commits+karl at tug.org
Sun Jan 28 01:16:44 CET 2018


Revision: 46468
          http://tug.org/svn/texlive?view=revision&revision=46468
Author:   karl
Date:     2018-01-28 01:16:43 +0100 (Sun, 28 Jan 2018)
Log Message:
-----------
doc fixes, code formatting

Modified Paths:
--------------
    trunk/Build/source/texk/kpathsea/ChangeLog
    trunk/Build/source/texk/kpathsea/readable.c
    trunk/Build/source/texk/kpathsea/readable.h

Modified: trunk/Build/source/texk/kpathsea/ChangeLog
===================================================================
--- trunk/Build/source/texk/kpathsea/ChangeLog	2018-01-28 00:08:31 UTC (rev 46467)
+++ trunk/Build/source/texk/kpathsea/ChangeLog	2018-01-28 00:16:43 UTC (rev 46468)
@@ -1,5 +1,9 @@
 2018-01-27  Karl Berry  <karl at freefriends.org>
 
+	* readable.h: doc fixes.
+	* readable.c (READABLE): take (ignored) kpse arg in macro, so:
+	(kpathsea_readable_file): we can avoid #ifdefs in body.
+
 	* str-list.c (str_list_concat_elements): reformat for consistency.
 
 	* str-list.h (STR_LIST_EMPTY, STR_LIST_FIRST_ELT): new macros.

Modified: trunk/Build/source/texk/kpathsea/readable.c
===================================================================
--- trunk/Build/source/texk/kpathsea/readable.c	2018-01-28 00:08:31 UTC (rev 46467)
+++ trunk/Build/source/texk/kpathsea/readable.c	2018-01-28 00:16:43 UTC (rev 46468)
@@ -43,28 +43,28 @@
   wchar_t *fnw;
   fnw = get_wstring_from_mbstring(kpse->File_system_codepage, fn, fnw=NULL);
   if ((st = GetFileAttributesW(fnw)) != 0xFFFFFFFF) {
-      /* succeeded */
-      errno = 0;
+    /* succeeded */
+    errno = 0;
   } else {
-      switch(GetLastError()) {
-      case ERROR_BUFFER_OVERFLOW:
-          errno = ENAMETOOLONG;
-          break;
-      case ERROR_ACCESS_DENIED:
-          errno = EACCES;
-          break;
-      default :
-          errno = EIO;          /* meaningless, will make ret=NULL later */
-          break;
-      }
+    switch(GetLastError()) {
+    case ERROR_BUFFER_OVERFLOW:
+      errno = ENAMETOOLONG;
+      break;
+    case ERROR_ACCESS_DENIED:
+      errno = EACCES;
+      break;
+    default :
+      errno = EIO;          /* meaningless, will make ret=NULL later */
+      break;
+    }
   }
-  if(fnw) free(fnw);
-  return ((st != 0xFFFFFFFF) &&
-                  !(st & FILE_ATTRIBUTE_DIRECTORY));
+  if (fnw)
+    free (fnw);
+  return ((st != 0xFFFFFFFF) && !(st & FILE_ATTRIBUTE_DIRECTORY));
 }
-#else
+#else /* not __DJGPP__ and not WIN32 */
 #define READABLE(kpse, fn, st) \
- (access ((fn), R_OK) == 0 && stat (fn, &(st)) == 0 && !S_ISDIR ((st).st_mode))
+ (access((fn), R_OK) == 0 && stat((fn), &(st)) == 0 && !S_ISDIR ((st).st_mode))
 #endif
 
 

@@ -83,52 +83,55 @@
 
   kpathsea_normalize_path (kpse, name);
   if (READABLE (kpse, name, st)) {
-      return name;
+    return name;
 
 #ifdef ENAMETOOLONG
   } else if (errno == ENAMETOOLONG) {
-      /* Truncate any too-long components in NAME.  */
-      unsigned c_len = 0;        /* Length of current component.  */
-      char *s = name;            /* Position in current component.  */
-      char *t = name;            /* End of allowed length.  */
-      
-      for (; *s; s++) {
-          if (c_len <= NAME_MAX)
-              t = s;
+    /* Truncate any too-long components in NAME.  */
+    unsigned c_len = 0;        /* Length of current component.  */
+    char *s = name;            /* Position in current component.  */
+    char *t = name;            /* End of allowed length.  */
+
+    for (; *s; s++) {
+      if (c_len <= NAME_MAX) {
+        t = s;
+      }
 #if defined(WIN32)
-          if (kpathsea_IS_KANJI (kpse, s)) {
-              s++;
-              c_len += 2;
-              continue;
-          }
+      if (kpathsea_IS_KANJI (kpse, s)) {
+        s++;
+        c_len += 2;
+        continue;
+      }
 #endif /* WIN32 */
-          if (IS_DIR_SEP (*s) || IS_DEVICE_SEP (*s)) {
-              if (c_len > NAME_MAX) {
-                  /* Truncate if past the max for a component.  */
-                  memmove (t, s, strlen (s) + 1);
-                  s = t;
-              }
-              /* At a directory delimiter, reset component length.  */
-              c_len = 0;
-          } else
-              c_len++;
+      if (IS_DIR_SEP (*s) || IS_DEVICE_SEP (*s)) {
+        if (c_len > NAME_MAX) {
+          /* Truncate if past the max for a component.  */
+          memmove (t, s, strlen (s) + 1);
+          s = t;
+        }
+        /* At a directory delimiter, reset component length.  */
+        c_len = 0;
+      } else {
+        c_len++;
       }
-      if (c_len > NAME_MAX)
-          /* Truncate if past the max for last component.  */
-          *t = 0;
+    }
+    if (c_len > NAME_MAX) {
+      /* Truncate if past the max for last component.  */
+      *t = 0;
+    }
 
-      /* Perhaps some other error will occur with the truncated name, so
-         let's call access again.  */
-      if (READABLE (kpse, name, st)) /* Success.  */
-          return name;
+    /* Perhaps some other error will occur with the truncated name, so
+       let's call access again.  */
+    if (READABLE (kpse, name, st)) /* Success.  */
+      return name;
 #endif /* ENAMETOOLONG */
 
   } else { /* Some other error.  */
-      if (errno == EACCES) { /* Maybe warn them if permissions are bad.  */
-          if (!kpathsea_tex_hush (kpse, "readable")) {
-              perror (name);
-          }
+    if (errno == EACCES) { /* Maybe warn them if permissions are bad.  */
+      if (!kpathsea_tex_hush (kpse, "readable")) {
+        perror (name);
       }
+    }
   }
 
   return NULL;
@@ -139,6 +142,6 @@
 string
 kpse_readable_file (string name)
 {
-    return kpathsea_readable_file (kpse_def, name);
+  return kpathsea_readable_file (kpse_def, name);
 }
 #endif

Modified: trunk/Build/source/texk/kpathsea/readable.h
===================================================================
--- trunk/Build/source/texk/kpathsea/readable.h	2018-01-28 00:08:31 UTC (rev 46467)
+++ trunk/Build/source/texk/kpathsea/readable.h	2018-01-28 00:16:43 UTC (rev 46468)
@@ -1,6 +1,6 @@
 /* readable.h: is a file readable?
 
-   Copyright 1993, 2008, 2009 Karl Berry.
+   Copyright 1993, 2008, 2009, 2018 Karl Berry.
    Copyright 1999, 2005 Olaf Weber.
 
    This library is free software; you can redistribute it and/or
@@ -26,10 +26,10 @@
 extern "C" {
 #endif
 
-/* If NAME is readable and is a regular file, return it.  If the error is
-   ENAMETOOLONG, truncate any too-long path components, and if the
-   result is a readable file, return that.  Otherwise return NULL.  */
-
+/* If NAME is readable and is a regular file, return it (as is).  If the
+   error is ENAMETOOLONG, truncate any too-long path components, and if
+   the result is a readable file, return that (in the same memory, since
+   it only got shorter).  Otherwise return NULL.  */
 extern KPSEDLL string kpathsea_readable_file (kpathsea kpse, string name);
 
 #if defined (KPSE_COMPAT_API)



More information about the tex-live-commits mailing list