comparison liboctave/util/oct-glob.cc @ 21929:7ab7cd327257

hide fnmatch.h and glob.h headers * liboctave/wrappers/glob-wrappers.c, liboctave/wrappers/glob-wrappers.h: New files. * liboctave/wrappers/module.mk: Update. * glob-match.cc, oct-glob.cc: Use new wrapper functions.
author John W. Eaton <jwe@octave.org>
date Thu, 16 Jun 2016 13:09:54 -0400
parents ff2b9f7069c5
children 289409b2992d
comparison
equal deleted inserted replaced
21928:315f4ba604c8 21929:7ab7cd327257
25 #endif 25 #endif
26 26
27 #include <algorithm> 27 #include <algorithm>
28 #include <string> 28 #include <string>
29 29
30 #include <fnmatch.h> 30 #include "glob-wrappers.h"
31 #include <glob.h>
32 31
33 #include "oct-glob.h" 32 #include "oct-glob.h"
34 #include "file-stat.h" 33 #include "file-stat.h"
34 #include "unwind-prot.h"
35 35
36 // These functions are defined here and not in glob_match.cc so that we 36 // These functions are defined here and not in glob_match.cc so that we
37 // can include the glob.h file from gnulib, which defines glob to 37 // can include the glob.h file from gnulib, which defines glob to
38 // be rpl_glob. If we include glob.h in glob_match.cc, then it 38 // be rpl_glob. If we include glob.h in glob_match.cc, then it
39 // transforms the glob_match::glob function to be glob_match::rpl_glob, 39 // transforms the glob_match::glob function to be glob_match::rpl_glob,
57 int npat = pat.numel (); 57 int npat = pat.numel ();
58 58
59 const char *cstr = str.c_str (); 59 const char *cstr = str.c_str ();
60 60
61 for (int i = 0; i < npat; i++) 61 for (int i = 0; i < npat; i++)
62 if (::fnmatch (pat(i).c_str (), cstr, fnm_flags) != FNM_NOMATCH) 62 if (octave_fnmatch_wrapper (pat(i).c_str (), cstr, fnm_flags)
63 != octave_fnm_nomatch_wrapper ())
63 return true; 64 return true;
64 65
65 return false; 66 return false;
66 } 67 }
67 68
72 73
73 int npat = pat.numel (); 74 int npat = pat.numel ();
74 75
75 int k = 0; 76 int k = 0;
76 77
78 octave::unwind_protect frame;
79
80 void *glob_info = octave_create_glob_info_struct ();
81
82 frame.add_fcn (octave_destroy_glob_info_struct, glob_info);
83
77 for (int i = 0; i < npat; i++) 84 for (int i = 0; i < npat; i++)
78 { 85 {
79 std::string xpat = pat(i); 86 std::string xpat = pat(i);
80 87
81 if (! xpat.empty ()) 88 if (! xpat.empty ())
82 { 89 {
83 glob_t glob_info;
84
85 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \ 90 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
86 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) 91 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
87 std::replace_if (xpat.begin (), xpat.end (), 92 std::replace_if (xpat.begin (), xpat.end (),
88 std::bind2nd (std::equal_to<char> (), '\\'), 93 std::bind2nd (std::equal_to<char> (), '\\'),
89 '/'); 94 '/');
90 #endif 95 #endif
91 96
92 int err = gnulib::glob (xpat.c_str (), GLOB_NOSORT, 0, &glob_info); 97 int err = octave_glob_wrapper (xpat.c_str (),
98 octave_glob_nosort_wrapper (),
99 glob_info);
93 100
94 if (! err) 101 if (! err)
95 { 102 {
96 int n = glob_info.gl_pathc; 103 int n = octave_glob_num_matches (glob_info);
97 104
98 const char * const *matches = glob_info.gl_pathv; 105 const char * const *matches
106 = octave_glob_match_list (glob_info);
99 107
100 // FIXME: we shouldn't have to check to see if 108 // FIXME: we shouldn't have to check to see if
101 // a single match exists, but it seems that glob() won't 109 // a single match exists, but it seems that glob() won't
102 // check for us unless the pattern contains globbing 110 // check for us unless the pattern contains globbing
103 // characters. Hmm. 111 // characters. Hmm.
122 130
123 retval[k++] = tmp; 131 retval[k++] = tmp;
124 } 132 }
125 } 133 }
126 134
127 gnulib::globfree (&glob_info); 135 octave_globfree_wrapper (glob_info);
128 } 136 }
129 } 137 }
130 } 138 }
131 139
132 return retval.sort (); 140 return retval.sort ();