Mercurial > octave
annotate liboctave/util/oct-glob.cc @ 29539:b51ba0fdd513
Windows: Fix using glob patterns with non-ASCII characters.
* liboctave/util/oct-glob.cc (windows_glob): Use Unicode API for checking file
existance on Windows.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sat, 17 Apr 2021 12:21:35 +0200 |
parents | 7854d5752dd2 |
children | aef11bb4e6d1 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 // Copyright (C) 2010-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
27 # include "config.h" |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #endif |
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 |
10345
33b012d39dce
Convert between back and forward slashes before and after calling glob.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10314
diff
changeset
|
30 #include <algorithm> |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include <string> |
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
33 #include "glob-wrappers.h" |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 |
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 #include "oct-glob.h" |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
36 #include "file-ops.h" |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include "file-stat.h" |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
38 #include "unwind-prot.h" |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
40 #if defined (OCTAVE_USE_WINDOWS_API) |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
41 # include <windows.h> |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
42 # include <shlwapi.h> |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
43 # include <wchar.h> |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
44 |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
45 # include "lo-sysdep.h" |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
46 #endif |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
47 |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 // These functions are defined here and not in glob_match.cc so that we |
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 // can include the glob.h file from gnulib, which defines glob to |
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 // be rpl_glob. If we include glob.h in glob_match.cc, then it |
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 // transforms the glob_match::glob function to be glob_match::rpl_glob, |
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 // which is not what we want... |
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 |
21734
11af9c03400c
write namespace keyword and name on same line in C++ files
John W. Eaton <jwe@octave.org>
parents:
21726
diff
changeset
|
54 namespace octave |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 { |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
56 static bool |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
57 single_match_exists (const std::string& file) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
58 { |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
59 sys::file_stat s (file); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
60 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
61 return s.exists (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
62 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
63 |
21734
11af9c03400c
write namespace keyword and name on same line in C++ files
John W. Eaton <jwe@octave.org>
parents:
21726
diff
changeset
|
64 namespace sys |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
65 { |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
66 bool |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
67 fnmatch (const string_vector& pat, const std::string& str, int fnm_flags) |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
68 { |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
69 int npat = pat.numel (); |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
71 const char *cstr = str.c_str (); |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
73 for (int i = 0; i < npat; i++) |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
74 if (octave_fnmatch_wrapper (pat(i).c_str (), cstr, fnm_flags) |
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
75 != octave_fnm_nomatch_wrapper ()) |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
76 return true; |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
77 |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
78 return false; |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
79 } |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
81 string_vector |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
82 glob (const string_vector& pat) |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
83 { |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
84 string_vector retval; |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
85 |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
86 int npat = pat.numel (); |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
87 |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
88 int k = 0; |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
90 void *glob_info = octave_create_glob_info_struct (); |
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
91 |
28857
43ad651cf5a0
eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents:
28851
diff
changeset
|
92 unwind_action cleanup_glob_info_struct |
28851
1ac5a76ae91d
use [=] capture default specification where possible
John W. Eaton <jwe@octave.org>
parents:
28850
diff
changeset
|
93 ([=] () { octave_destroy_glob_info_struct (glob_info); }); |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
94 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
95 for (int i = 0; i < npat; i++) |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
96 { |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
97 std::string xpat = pat(i); |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
98 |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
99 if (! xpat.empty ()) |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
100 { |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22155
diff
changeset
|
101 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \ |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
102 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
103 std::replace_if (xpat.begin (), xpat.end (), |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
104 std::bind2nd (std::equal_to<char> (), '\\'), |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
105 '/'); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
106 #endif |
10345
33b012d39dce
Convert between back and forward slashes before and after calling glob.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10314
diff
changeset
|
107 |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
108 int err = octave_glob_wrapper (xpat.c_str (), |
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
109 octave_glob_nosort_wrapper (), |
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
110 glob_info); |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
112 if (! err) |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
113 { |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
114 int n = octave_glob_num_matches (glob_info); |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
116 const char * const *matches |
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
117 = octave_glob_match_list (glob_info); |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
119 // FIXME: we shouldn't have to check to see if |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
120 // a single match exists, but it seems that glob() won't |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
121 // check for us unless the pattern contains globbing |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
122 // characters. Hmm. |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
124 if (n > 1 |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
125 || (n == 1 |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
126 && single_match_exists (std::string (matches[0])))) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
127 { |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
128 retval.resize (k+n); |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
129 |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
130 for (int j = 0; j < n; j++) |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
131 { |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
132 std::string tmp = matches[j]; |
10345
33b012d39dce
Convert between back and forward slashes before and after calling glob.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10314
diff
changeset
|
133 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
134 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \ |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
135 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM) |
21761 | 136 std::replace_if (tmp.begin (), tmp.end (), |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
137 std::bind2nd (std::equal_to<char> (), |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
138 '/'), |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
139 '\\'); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
140 #endif |
10345
33b012d39dce
Convert between back and forward slashes before and after calling glob.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10314
diff
changeset
|
141 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
142 retval[k++] = tmp; |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
143 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
144 } |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
145 |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
146 octave_globfree_wrapper (glob_info); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10138
diff
changeset
|
147 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10138
diff
changeset
|
148 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10138
diff
changeset
|
149 } |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
150 |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
151 return retval.sort (); |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
152 } |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
153 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
154 #if defined (OCTAVE_USE_WINDOWS_API) |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
155 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
156 static void |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
157 find_files (std::list<std::string>& dirlist, const std::string& dir, |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
158 const std::string& pat, std::string& file) |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
159 { |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
160 // remove leading file separators |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
161 while (file.length () > 1 && sys::file_ops::is_dir_sep (file[0])) |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
162 file = file.substr (1, std::string::npos); |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
163 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
164 // find first file in directory that matches pattern in PAT |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
165 std::wstring wpat = u8_to_wstring (sys::file_ops::concat (dir, pat)); |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
166 _WIN32_FIND_DATAW ffd; |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
167 HANDLE h_find = FindFirstFileW (wpat.c_str (), &ffd); |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
168 // ignore any error |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
169 if (h_find == INVALID_HANDLE_VALUE) |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
170 return; |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
171 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
172 unwind_action close_h_find ([=] () { FindClose (h_find); }); |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
173 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
174 // find all files that match pattern |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
175 do |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
176 { |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
177 std::string found_dir = u8_from_wstring (ffd.cFileName); |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
178 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
179 if (file.empty ()) |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
180 { |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
181 if (found_dir.compare (".") && found_dir.compare ("..")) |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
182 dirlist.push_back (sys::file_ops::concat (dir, found_dir)); |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
183 } |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
184 else |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
185 { |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
186 // get next component of path (or file name) |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
187 size_t sep_pos |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
188 = file.find_first_of (sys::file_ops::dir_sep_chars ()); |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
189 std::string pat_str = file.substr (0, sep_pos); |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
190 std::string file_str = (sep_pos != std::string::npos |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
191 && file.length () > sep_pos+1) |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
192 ? file.substr (sep_pos+1) : ""; |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
193 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
194 // call this function recursively with next path component in PAT |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
195 find_files (dirlist, sys::file_ops::concat (dir, found_dir), |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
196 pat_str, file_str); |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
197 } |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
198 } |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
199 while (FindNextFileW (h_find, &ffd) != 0); |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
200 } |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
201 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
202 #endif |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
203 |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
204 // Glob like Windows "dir". Treat only * and ? as wildcards, |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
205 // and "*.*" matches filenames even if they do not contain ".". |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
206 string_vector |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
207 windows_glob (const string_vector& pat) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
208 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
209 string_vector retval; |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
210 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
211 int npat = pat.numel (); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
212 |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
213 #if defined (OCTAVE_USE_WINDOWS_API) |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
214 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
215 std::list<std::string> dirlist; |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
216 |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
217 for (int i = 0; i < npat; i++) |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
218 { |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
219 std::string xpat = pat(i); |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
220 if (xpat.empty ()) |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
221 continue; |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
222 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
223 // separate component until first dir separator |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
224 size_t sep_pos |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
225 = xpat.find_first_of (sys::file_ops::dir_sep_chars ()); |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
226 std::string file = (sep_pos != std::string::npos |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
227 && xpat.length () > sep_pos+1) |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
228 ? xpat.substr (sep_pos+1) : ""; |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
229 xpat = xpat.substr (0, sep_pos); |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
230 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
231 std::string dir = ""; |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
232 |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
233 if ((sep_pos == 2 || xpat.length () == 2) && xpat[1] == ':') |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
234 { |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
235 // include disc root with first file or folder |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
236 |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
237 // remove leading file separators in path without disc root |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
238 while (file.length () > 1 && sys::file_ops::is_dir_sep (file[0])) |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
239 file = file.substr (1, std::string::npos); |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
240 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
241 sep_pos = file.find_first_of (sys::file_ops::dir_sep_chars ()); |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
242 dir = xpat; |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
243 xpat = file.substr (0, sep_pos); |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
244 file = (sep_pos != std::string::npos |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
245 && file.length () > sep_pos+1) |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
246 ? file.substr (sep_pos+1) : ""; |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
247 if (xpat.empty ()) |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
248 { |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
249 // don't glob if input is only disc root |
29539
b51ba0fdd513
Windows: Fix using glob patterns with non-ASCII characters.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
250 std::wstring wpat = u8_to_wstring (pat(i)); |
b51ba0fdd513
Windows: Fix using glob patterns with non-ASCII characters.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
251 if (PathFileExistsW (wpat.c_str ())) |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
252 { |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
253 if (sys::file_ops::is_dir_sep (pat(i).back ())) |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
254 dirlist.push_back (dir + |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
255 sys::file_ops::dir_sep_char ()); |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
256 else |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
257 dirlist.push_back (dir); |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
258 } |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
259 continue; |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
260 } |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
261 } |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
262 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
263 find_files (dirlist, dir, xpat, file); |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
264 } |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
265 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
266 retval = string_vector (dirlist); |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
267 |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
268 #else |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
269 |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
270 int k = 0; |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
271 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
272 void *glob_info = octave_create_glob_info_struct (); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
273 |
28857
43ad651cf5a0
eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents:
28851
diff
changeset
|
274 unwind_action cleanup_glob_info_struct |
28851
1ac5a76ae91d
use [=] capture default specification where possible
John W. Eaton <jwe@octave.org>
parents:
28850
diff
changeset
|
275 ([=] () { octave_destroy_glob_info_struct (glob_info); }); |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
276 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
277 for (int i = 0; i < npat; i++) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
278 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
279 std::string xpat = pat(i); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
280 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
281 if (! xpat.empty ()) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
282 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
283 std::string escaped; |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
284 escaped.reserve (xpat.length ()); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
285 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
286 for (size_t j = 0; j < xpat.length (); j++) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
287 { |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
288 # if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \ |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
289 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
290 if (xpat[j] == '\\') |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22155
diff
changeset
|
291 escaped += '/'; |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
292 else |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
293 # endif |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
294 { |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
295 if (xpat[j] == ']' || xpat[j] == '[') |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
296 escaped += '\\'; |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
297 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
298 escaped += xpat[j]; |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
299 } |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
300 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
301 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
302 // Replace trailing "*.*" by "*". |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
303 int len = escaped.length (); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
304 if (len >= 3 && escaped.substr (len - 3) == "*.*") |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
305 escaped = escaped.substr (0, len - 2); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
306 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
307 int err = octave_glob_wrapper (escaped.c_str (), |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
308 octave_glob_nosort_wrapper (), |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
309 glob_info); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
310 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
311 if (! err) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
312 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
313 int n = octave_glob_num_matches (glob_info); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
314 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
315 const char * const *matches |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
316 = octave_glob_match_list (glob_info); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
317 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
318 // FIXME: we shouldn't have to check to see if |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
319 // a single match exists, but it seems that glob() won't |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
320 // check for us unless the pattern contains globbing |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
321 // characters. Hmm. |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
322 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
323 if (n > 1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
324 || (n == 1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
325 && single_match_exists (std::string (matches[0])))) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
326 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
327 retval.resize (k + n); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
328 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
329 for (int j = 0; j < n; j++) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
330 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
331 std::string tmp = matches[j]; |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
332 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
333 std::string unescaped; |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
334 unescaped.reserve (tmp.length ()); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
335 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
336 for (size_t m = 0; m < tmp.length (); m++) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
337 { |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
338 # if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \ |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
339 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
340 if (tmp[m] == '/') |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22155
diff
changeset
|
341 unescaped += '\\'; |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
342 else |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
343 # endif |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
344 { |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
345 if (tmp[m] == '\\' |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
346 && ++m == tmp.length ()) |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
347 break; |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
348 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
349 unescaped += tmp[m]; |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
350 } |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
351 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
352 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
353 retval[k++] = unescaped; |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
354 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
355 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
356 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
357 octave_globfree_wrapper (glob_info); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
358 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
359 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
360 } |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
361 #endif |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
362 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
363 return retval.sort (); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
364 } |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
365 } |
10138
805a83ecd3da
avoid conflict between glob.h definition of glob and glob_match::glob function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
366 } |