texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[5508] info_add_extension


From: Gavin D. Smith
Subject: [5508] info_add_extension
Date: Fri, 02 May 2014 12:43:50 +0000

Revision: 5508
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5508
Author:   gavin
Date:     2014-05-02 12:43:49 +0000 (Fri, 02 May 2014)
Log Message:
-----------
info_add_extension

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/Makefile.am
    trunk/info/filesys.c

Added Paths:
-----------
    trunk/info/t/split.sh

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-05-02 09:11:19 UTC (rev 5507)
+++ trunk/ChangeLog     2014-05-02 12:43:49 UTC (rev 5508)
@@ -1,5 +1,14 @@
 2014-05-02  Gavin Smith  <address@hidden>
 
+       * info/filesys.c (info_add_extension): Loop trying various file
+       extensions moved from info_file_find_next_in_path.
+       (info_find_fullpath): Account for null struct stat argument.  Check
+       case when path is not absolute, but contains intermediate
+       subdirectories.
+       * info/t/split.sh: New test.
+
+2014-05-02  Gavin Smith  <address@hidden>
+
        * info/session.c (info_set_node_of_window): Argument
        'remember' removed.  All callers updated.
        (begin_multiple_window_info_session): Don't call

Modified: trunk/info/Makefile.am
===================================================================
--- trunk/info/Makefile.am      2014-05-02 09:11:19 UTC (rev 5507)
+++ trunk/info/Makefile.am      2014-05-02 12:43:49 UTC (rev 5508)
@@ -93,6 +93,7 @@
        t/file-node.sh \
        t/file-nodes.sh \
        t/no-file.sh \
+       t/split.sh \
        t/dir.sh \
        t/dir-file.sh \
        t/dir-nondir.sh \

Modified: trunk/info/filesys.c
===================================================================
--- trunk/info/filesys.c        2014-05-02 09:11:19 UTC (rev 5507)
+++ trunk/info/filesys.c        2014-05-02 12:43:49 UTC (rev 5508)
@@ -27,11 +27,9 @@
 
 /* Local to this file. */
 static char *info_file_in_path (char *filename, char *path, struct stat 
*finfo);
-static char *lookup_info_filename (char *filename);
-static char *info_add_extension (char *fname, struct stat *finfo);
+static char *info_add_extension (char *dirname, char *fname,
+                                 struct stat *finfo);
 
-static void remember_info_filename (char *filename, char *expansion);
-
 static char *filesys_read_compressed (char *pathname, size_t *filesize);
 
 /* Given a chunk of text and its length, convert all CRLF pairs at the
@@ -50,6 +48,7 @@
 } COMPRESSION_ALIST;
 
 static char *info_suffixes[] = {
+  "",
   ".info",
   "-info",
   "/index",
@@ -59,7 +58,6 @@
   ".in",        /* for .inz, .igz etc. */
   ".i",
 #endif
-  "",
   NULL
 };
 
@@ -93,9 +91,13 @@
 info_find_fullpath (char *partial, struct stat *finfo)
 {
   char *fullpath = 0;
+  struct stat dummy;
 
   debug(1, (_("looking for file \"%s\""), partial));
 
+  if (!finfo)
+    finfo = &dummy;
+
   filesys_error_number = 0;
 
   if (!partial || !*partial)
@@ -106,23 +108,25 @@
   /* If path is absolute already, see if it needs an extension. */
   if (IS_ABSOLUTE (partial))
     {
-      fullpath = info_add_extension (partial, finfo);
+      fullpath = info_add_extension (0, partial, finfo);
     }
 
   /* Tilde expansion.  FIXME: Not needed, because done by shell. */
   else if (partial[0] == '~')
     {
       partial = tilde_expand_word (partial);
-      fullpath = info_add_extension (partial, finfo);
+      fullpath = info_add_extension (0, partial, finfo);
     }
 
-  /* If filename begins with "./" or "../", view it relative to
-     current directory. */
-  else if (partial[0] == '.'
+  /* If filename begins with "./" or "../", or if there are intermediate
+     directories, interpret it as relative to current directory.  This may
+     be from the command line, or in the subfiles table of a split file. */
+  else if ((partial[0] == '.'
            && (IS_SLASH (partial[1])
                || (partial[1] == '.' && IS_SLASH (partial[2]))))
+          || strchr (partial, '/'))
     {
-      fullpath = info_add_extension (partial, finfo);
+      fullpath = info_add_extension (0, partial, finfo);
 #if 0
       /* Don't limit paths to 1023 bytes, and don't ask for
          1024 bytes when it isn't needed. 
@@ -163,8 +167,7 @@
 info_file_find_next_in_path (char *filename, char *path, int *diridx,
                              struct stat *finfo)
 {
-  char *temp_dirname;
-  int statable;
+  char *dirname;
   struct stat dummy;
 
   /* Used for output of fstat in case the caller doesn't care about
@@ -177,111 +180,120 @@
   if (!*filename || STREQ (filename, ".") || STREQ (filename, ".."))
     return NULL;
 
-  while ((temp_dirname = extract_colon_unit (path, diridx)))
+  while ((dirname = extract_colon_unit (path, diridx)))
     {
-      register int i, pre_suffix_length;
-      char *temp;
+      char *with_extension = 0;
 
-      debug(1, (_("looking for file %s in %s"), filename, temp_dirname));
+      debug(1, (_("looking for file %s in %s"), filename, dirname));
+
       /* Expand a leading tilde if one is present. */
-      if (*temp_dirname == '~')
+      if (*dirname == '~')
         {
-          char *expanded_dirname = tilde_expand_word (temp_dirname);
-          free (temp_dirname);
-          temp_dirname = expanded_dirname;
+          char *expanded_dirname = tilde_expand_word (dirname);
+          free (dirname);
+          dirname = expanded_dirname;
         }
 
-      temp = xmalloc (30 + strlen (temp_dirname) + strlen (filename));
-      strcpy (temp, temp_dirname);
-      if (!IS_SLASH (temp[(strlen (temp)) - 1]))
-        strcat (temp, "/");
-      strcat (temp, filename);
+      with_extension = info_add_extension (dirname, filename, finfo);
+      free (dirname);
 
-      pre_suffix_length = strlen (temp);
+      if (with_extension)
+        return with_extension;
+    }
+  return NULL;
+}
 
-      free (temp_dirname);
+static char *
+info_file_in_path (char *filename, char *path, struct stat *finfo)
+{
+  int i = 0;
+  return info_file_find_next_in_path (filename, path, &i, finfo);
+}
 
-      for (i = 0; info_suffixes[i]; i++)
+/* Look for a file called FILENAME in a directory called DIRNAME, adding file
+   extensions if necessary.  FILENAME can be an absolute path or a path
+   relative to the current directory, in which case DIRNAME should be
+   null.  Return it as a new string; otherwise return a NULL pointer. */
+static char *
+info_add_extension (char *dirname, char *filename, struct stat *finfo)
+{
+  char *try_filename;
+  register int i, pre_suffix_length = 0;
+
+  if (dirname)
+    pre_suffix_length += strlen (dirname);
+
+  pre_suffix_length += strlen (filename);
+
+  try_filename = xmalloc (pre_suffix_length + 30);
+  try_filename[0] = '\0';
+
+  if (dirname)
+    {
+      strcpy (try_filename, dirname);
+      if (!IS_SLASH (try_filename[(strlen (try_filename)) - 1]))
         {
-          strcpy (temp + pre_suffix_length, info_suffixes[i]);
+          strcat (try_filename, "/");
+          pre_suffix_length++;
+        }
+    }
 
-          statable = (stat (temp, finfo) == 0);
+  strcat (try_filename, filename);
 
-          /* If we have found a regular file, then use that.  Else, if we
-             have found a directory, look in that directory for this file. */
-          if (statable)
-            {
-              if (S_ISREG (finfo->st_mode))
-                {
-                 debug(1, (_("found file %s"), temp));
-                  return temp;
-                }
-              else if (S_ISDIR (finfo->st_mode))
-                {
-                  char *newpath, *filename_only, *newtemp;
+  for (i = 0; info_suffixes[i]; i++)
+    {
+      int statable;
 
-                  newpath = xstrdup (temp);
-                  filename_only = filename_non_directory (filename);
-                  newtemp = info_file_in_path (filename_only, newpath, finfo);
+      strcpy (try_filename + pre_suffix_length, info_suffixes[i]);
+      statable = (stat (try_filename, finfo) == 0);
 
-                  free (newpath);
-                  if (newtemp)
-                    {
-                      free (temp);
-                     debug(1, (_("found file %s"), newtemp));
-                      return newtemp;
-                    }
-                }
+      /* If we have found a regular file, then use that.  Else, if we
+         have found a directory, look in that directory for this file. */
+      if (statable)
+        {
+          if (S_ISREG (finfo->st_mode))
+            {
+              debug(1, (_("found file %s"), try_filename));
+              return try_filename;
             }
-          else
+          else if (S_ISDIR (finfo->st_mode))
             {
-              /* Add various compression suffixes to the name to see if
-                 the file is present in compressed format. */
-              register int j, pre_compress_suffix_length;
+              char *newpath, *new_filename;
 
-              pre_compress_suffix_length = strlen (temp);
+              newpath = xstrdup (try_filename);
+              new_filename = info_file_in_path (filename, newpath, finfo);
 
-              for (j = 0; compress_suffixes[j].suffix; j++)
+              free (newpath);
+              if (new_filename)
                 {
-                  strcpy (temp + pre_compress_suffix_length,
-                          compress_suffixes[j].suffix);
-
-                  statable = (stat (temp, finfo) == 0);
-                  if (statable && (S_ISREG (finfo->st_mode)))
-                   {
-                     debug(1, (_("found file %s"), temp));
-                     return temp;
-                   }
+                  free (try_filename);
+                  debug(1, (_("found file %s"), new_filename));
+                  return new_filename;
                 }
             }
         }
-      free (temp);
-    }
-  return NULL;
-}
+      else
+        {
+          /* Add various compression suffixes to the name to see if
+             the file is present in compressed format. */
+          register int j, pre_compress_suffix_length;
 
-static char *
-info_file_in_path (char *filename, char *path, struct stat *finfo)
-{
-  int i = 0;
-  return info_file_find_next_in_path (filename, path, &i, finfo);
-}
+          pre_compress_suffix_length = strlen (try_filename);
 
-/* Look for a file with a path of FNAME, adding file extensions if necessary.
-   FNAME must contain directory elements.  Return it as a new string; otherwise
-   return a NULL pointer.  We do it by taking the file name apart
-   into its directory and basename parts, and calling info_file_in_path.*/
-static char *
-info_add_extension (char *fname, struct stat *finfo)
-{
-  char *containing_dir = xstrdup (fname);
-  char *base = filename_non_directory (containing_dir);
+          for (j = 0; compress_suffixes[j].suffix; j++)
+            {
+              strcpy (try_filename + pre_compress_suffix_length,
+                      compress_suffixes[j].suffix);
 
-  if (base > containing_dir)
-    base[-1] = '\0';
-
-  return info_file_in_path (filename_non_directory (fname), containing_dir,
-                            finfo);
+              statable = (stat (try_filename, finfo) == 0);
+              if (statable && (S_ISREG (finfo->st_mode)))
+                {
+                  debug(1, (_("found file %s"), try_filename));
+                  return try_filename;
+                }
+            }
+        }
+    }
 }
 
 /* Given a string containing units of information separated by the

Added: trunk/info/t/split.sh
===================================================================
--- trunk/info/t/split.sh                               (rev 0)
+++ trunk/info/t/split.sh       2014-05-02 12:43:49 UTC (rev 5508)
@@ -0,0 +1,21 @@
+#!/bin/sh
+# Copyright (C) 2014 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. t/Init-test.inc
+
+# Load a split file
+
+$GINFO -f split | grep '^File: split.info,'


Property changes on: trunk/info/t/split.sh
___________________________________________________________________
Added: svn:executable
   + *




reply via email to

[Prev in Thread] Current Thread [Next in Thread]