changeset 21726:f05a00e611ff

use namespace for glob and fnmatch wrapper functions * oct-glob.h, oct-glob.cc: Put fnmatch and glob in octave::sys namespace. (octave_fnmatch, octave_glob): Now deprecated aliases for functions in octave::sys namespace. * glob-match.cc: Use new names. * oct-conf-post.in.h, mk-octave-config-h.sh: Define OCTAVE_USE_DEPRECATED_FUNCTIONS.
author John W. Eaton <jwe@octave.org>
date Wed, 18 May 2016 15:17:00 -0400
parents 78e0b187904b
children e0da98857c19
files build-aux/mk-octave-config-h.sh liboctave/util/glob-match.cc liboctave/util/oct-glob.cc liboctave/util/oct-glob.h oct-conf-post.in.h
diffstat 5 files changed, 96 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/build-aux/mk-octave-config-h.sh	Wed May 18 11:00:58 2016 -0700
+++ b/build-aux/mk-octave-config-h.sh	Wed May 18 15:17:00 2016 -0400
@@ -116,6 +116,8 @@
 /* #  undef HAVE_OCTAVE_UNUSED_ATTR */
 #endif
 
+#define OCTAVE_USE_DEPRECATED_FUNCTIONS 1
+
 #if defined (__cplusplus)
 template <typename T>
 static inline void
--- a/liboctave/util/glob-match.cc	Wed May 18 11:00:58 2016 -0700
+++ b/liboctave/util/glob-match.cc	Wed May 18 15:17:00 2016 -0400
@@ -32,13 +32,13 @@
 bool
 glob_match::match (const std::string& str) const
 {
-  return octave_fnmatch (pat, str, fnmatch_flags);
+  return octave::sys::fnmatch (pat, str, fnmatch_flags);
 }
 
 string_vector
 glob_match::glob (void) const
 {
-  return octave_glob (pat);
+  return octave::sys::glob (pat);
 }
 
 int
--- a/liboctave/util/oct-glob.cc	Wed May 18 11:00:58 2016 -0700
+++ b/liboctave/util/oct-glob.cc	Wed May 18 15:17:00 2016 -0400
@@ -47,84 +47,91 @@
   return s.exists ();
 }
 
-bool
-octave_fnmatch (const string_vector& pat, const std::string& str,
-                int fnmatch_flags)
-{
-  int npat = pat.numel ();
-
-  const char *cstr = str.c_str ();
-
-  for (int i = 0; i < npat; i++)
-    if (fnmatch (pat(i).c_str (), cstr, fnmatch_flags) != FNM_NOMATCH)
-      return true;
-
-  return false;
-}
-
-string_vector
-octave_glob (const string_vector& pat)
+namespace
+octave
 {
-  string_vector retval;
-
-  int npat = pat.numel ();
+  namespace
+  sys
+  {
+    bool
+    fnmatch (const string_vector& pat, const std::string& str, int fnm_flags)
+    {
+      int npat = pat.numel ();
 
-  int k = 0;
+      const char *cstr = str.c_str ();
 
-  for (int i = 0; i < npat; i++)
-    {
-      std::string xpat = pat(i);
+      for (int i = 0; i < npat; i++)
+        if (::fnmatch (pat(i).c_str (), cstr, fnm_flags) != FNM_NOMATCH)
+          return true;
+
+      return false;
+    }
 
-      if (! xpat.empty ())
-        {
-          glob_t glob_info;
+    string_vector
+    glob (const string_vector& pat)
+    {
+      string_vector retval;
+
+      int npat = pat.numel ();
+
+      int k = 0;
 
-#if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
-    && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
-          std::replace_if (xpat.begin (), xpat.end (),
-                           std::bind2nd (std::equal_to<char> (), '\\'),
-                           '/');
+      for (int i = 0; i < npat; i++)
+        {
+          std::string xpat = pat(i);
+
+          if (! xpat.empty ())
+            {
+              glob_t glob_info;
+
+#if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
+     && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
+              std::replace_if (xpat.begin (), xpat.end (),
+                               std::bind2nd (std::equal_to<char> (), '\\'),
+                               '/');
 #endif
 
-          int err = gnulib::glob (xpat.c_str (), GLOB_NOSORT, 0, &glob_info);
+              int err = gnulib::glob (xpat.c_str (), GLOB_NOSORT, 0, &glob_info);
 
-          if (! err)
-            {
-              int n = glob_info.gl_pathc;
+              if (! err)
+                {
+                  int n = glob_info.gl_pathc;
 
-              const char * const *matches = glob_info.gl_pathv;
+                  const char * const *matches = glob_info.gl_pathv;
 
-              // FIXME: we shouldn't have to check to see if
-              // a single match exists, but it seems that glob() won't
-              // check for us unless the pattern contains globbing
-              // characters.  Hmm.
+                  // FIXME: we shouldn't have to check to see if
+                  // a single match exists, but it seems that glob() won't
+                  // check for us unless the pattern contains globbing
+                  // characters.  Hmm.
 
-              if (n > 1
-                  || (n == 1
-                      && single_match_exists (std::string (matches[0]))))
-                {
-                  retval.resize (k+n);
-
-                  for (int j = 0; j < n; j++)
+                  if (n > 1
+                      || (n == 1
+                          && single_match_exists (std::string (matches[0]))))
                     {
-                      std::string tmp = matches[j];
+                      retval.resize (k+n);
+
+                      for (int j = 0; j < n; j++)
+                        {
+                          std::string tmp = matches[j];
 
-#if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
-                      && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
-                      std::replace_if (tmp.begin (), tmp.end (),
-                                       std::bind2nd (std::equal_to<char> (),
-                                                     '/'),
-                                       '\\');
+#if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM)    \
+  && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
+`                          std::replace_if (tmp.begin (), tmp.end (),
+                                           std::bind2nd (std::equal_to<char> (),
+                                                         '/'),
+                                           '\\');
 #endif
 
-                      retval[k++] = tmp;
+                          retval[k++] = tmp;
+                        }
                     }
+
+                  gnulib::globfree (&glob_info);
                 }
-
-              gnulib::globfree (&glob_info);
             }
         }
+
+      return retval.sort ();
     }
-
-  return retval.sort ();
+  }
 }
--- a/liboctave/util/oct-glob.h	Wed May 18 11:00:58 2016 -0700
+++ b/liboctave/util/oct-glob.h	Wed May 18 15:17:00 2016 -0400
@@ -27,11 +27,29 @@
 
 #include "str-vec.h"
 
-extern bool
-octave_fnmatch (const string_vector& pat, const std::string& str,
-                int fnmatch_flags);
+namespace
+octave
+{
+  namespace
+  sys
+  {
+    extern bool
+    fnmatch (const string_vector& pat, const std::string& str,
+             int fnmatch_flags);
 
-extern string_vector
-octave_glob (const string_vector&);
+    extern string_vector
+    glob (const string_vector&);
+  }
+}
+
+#if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
+
+OCTAVE_DEPRECATED ("use octave::sys::fnmatch instead")
+const auto octave_fnmatch = octave::sys::fnmatch;
+
+OCTAVE_DEPRECATED ("use octave::sys::glob instead")
+const auto octave_glob = octave::sys::glob;
 
 #endif
+
+#endif
--- a/oct-conf-post.in.h	Wed May 18 11:00:58 2016 -0700
+++ b/oct-conf-post.in.h	Wed May 18 15:17:00 2016 -0400
@@ -54,6 +54,8 @@
 #  define OCTAVE_UNUSED
 #endif
 
+#define OCTAVE_USE_DEPRECATED_FUNCTIONS 1
+
 #if defined (__cplusplus)
 template <typename T>
 static inline void