Mercurial > octave
annotate liboctave/util/oct-glob.cc @ 31605:e88a07dec498 stable
maint: Use macros to begin/end C++ namespaces.
* oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE,
OCTAVE_END_NAMESPACE) that can be used to start/end a namespace.
* mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc,
__dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc,
__ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc,
__magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc,
auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h,
besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc,
colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc,
defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc,
display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc,
ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h,
event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc,
fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc,
ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc,
getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc,
gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc,
graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc,
help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h,
interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h,
inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc,
latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc,
ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h,
mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc,
oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h,
oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h,
oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h,
oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy,
ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc,
pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc,
qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h,
sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc,
sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h,
stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc,
symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h,
symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h,
text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc,
toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc,
url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc,
variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h,
__delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc,
audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh,
mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc,
cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h,
cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h,
cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc,
ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc,
ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h,
ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc,
ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h,
ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc,
op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc,
op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc,
op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc,
op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc,
op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc,
op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc,
op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc,
op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc,
op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc,
op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc,
op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc,
op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc,
op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc,
op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc,
op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h,
anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h,
comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc,
oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h,
pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h,
pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h,
pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h,
pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h,
pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc,
pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc,
pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc,
pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc,
pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc,
pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc,
pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h,
pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h,
range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc,
chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h,
lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h,
oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h,
oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc,
qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc,
randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc,
sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc,
child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc,
file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h,
mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h,
oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc,
oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h,
base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h,
file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc,
lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h,
oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h,
oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h,
oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h,
pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h,
url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 01 Dec 2022 14:23:45 -0800 |
parents | d33af4594440 |
children | aac27ad79be6 |
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 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
3 // Copyright (C) 2010-2022 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 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31065
diff
changeset
|
54 OCTAVE_BEGIN_NAMESPACE(octave) |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31065
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 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31065
diff
changeset
|
64 OCTAVE_BEGIN_NAMESPACE(sys) |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31065
diff
changeset
|
65 |
21726
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)) |
31027
72786e150001
oct-glob.cc: Fix yet another typo in 8475b51b990c.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31016
diff
changeset
|
103 std::replace (xpat.begin (), xpat.end (), '\\', '/'); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
104 #endif |
10345
33b012d39dce
Convert between back and forward slashes before and after calling glob.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10314
diff
changeset
|
105 |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
106 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
|
107 octave_glob_nosort_wrapper (), |
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
108 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
|
109 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
110 if (! err) |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
111 { |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
112 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
|
113 |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
114 const char * const *matches |
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
115 = 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
|
116 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
117 // 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
|
118 // 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
|
119 // 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
|
120 // 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
|
121 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
122 if (n > 1 |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
123 || (n == 1 |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
124 && 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
|
125 { |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
126 retval.resize (k+n); |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
127 |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
128 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
|
129 { |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
130 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
|
131 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
132 #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
|
133 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM) |
31016
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
134 std::replace (tmp.begin (), tmp.end (), '/', '\\'); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
135 #endif |
10345
33b012d39dce
Convert between back and forward slashes before and after calling glob.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10314
diff
changeset
|
136 |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
137 retval[k++] = tmp; |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
138 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
139 } |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
140 |
21929
7ab7cd327257
hide fnmatch.h and glob.h headers
John W. Eaton <jwe@octave.org>
parents:
21761
diff
changeset
|
141 octave_globfree_wrapper (glob_info); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10138
diff
changeset
|
142 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10138
diff
changeset
|
143 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10138
diff
changeset
|
144 } |
21726
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
145 |
f05a00e611ff
use namespace for glob and fnmatch wrapper functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
146 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
|
147 } |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
148 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
149 #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
|
150 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
151 static void |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
152 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
|
153 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
|
154 { |
31016
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
155 // remove leading file separators |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
156 bool is_file_empty = file.empty (); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
157 while (! file.empty () && sys::file_ops::is_dir_sep (file[0])) |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
158 file = file.substr (1, std::string::npos); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
159 |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
160 bool is_trailing_file_sep = ! is_file_empty && file.empty (); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
161 |
30979
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
162 if (! pat.compare (".") || ! pat.compare ("..")) |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
163 { |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
164 // shortcut for trivial patterns that would expand to a folder name |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
165 |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
166 // get next component of path (or file name) |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
167 std::size_t sep_pos |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
168 = file.find_first_of (sys::file_ops::dir_sep_chars ()); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
169 std::string pat_str = file.substr (0, sep_pos); |
31016
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
170 std::string file_str = (sep_pos != std::string::npos) |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
171 ? file.substr (sep_pos) : ""; |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
172 |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
173 // Original pattern ends with "." or "..". Take it as we have it. |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
174 if (pat_str.empty ()) |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
175 { |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
176 if (is_trailing_file_sep) |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
177 pat_str = sys::file_ops::dir_sep_char (); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
178 dirlist.push_back (sys::file_ops::concat (dir, pat) + pat_str); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
179 return; |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
180 } |
30979
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
181 |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
182 // call this function recursively with next path component in PAT |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
183 find_files (dirlist, sys::file_ops::concat (dir, pat), |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
184 pat_str, file_str); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
185 return; |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
186 } |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
187 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
188 // 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
|
189 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
|
190 _WIN32_FIND_DATAW ffd; |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
191 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
|
192 // ignore any error |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
193 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
|
194 return; |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
195 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
196 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
|
197 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
198 // 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
|
199 do |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
200 { |
31016
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
201 // must be directory if pattern continues |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
202 if (! (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
203 && (! file.empty () || is_trailing_file_sep)) |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
204 continue; |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
205 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
206 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
|
207 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
208 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
|
209 { |
30979
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
210 // Don't include "." and ".." in matches. |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
211 if (found_dir.compare (".") && found_dir.compare ("..")) |
31016
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
212 { |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
213 if (is_trailing_file_sep) |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
214 found_dir += sys::file_ops::dir_sep_char (); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
215 dirlist.push_back (sys::file_ops::concat (dir, found_dir)); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
216 } |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
217 } |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
218 else |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
219 { |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
220 // get next component of path (or file name) |
29572
aef11bb4e6d1
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29539
diff
changeset
|
221 std::size_t sep_pos |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
222 = 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
|
223 std::string pat_str = file.substr (0, sep_pos); |
31016
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
224 std::string file_str = (sep_pos != std::string::npos) |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
225 ? file.substr (sep_pos) : ""; |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
226 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
227 // 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
|
228 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
|
229 pat_str, file_str); |
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 } |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
232 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
|
233 } |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
234 |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
235 #endif |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
236 |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
237 // 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
|
238 // 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
|
239 string_vector |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
240 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
|
241 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
242 string_vector retval; |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
243 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
244 int npat = pat.numel (); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
245 |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
246 #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
|
247 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
248 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
|
249 |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
250 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
|
251 { |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
252 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
|
253 if (xpat.empty ()) |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
254 continue; |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
255 |
31065
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
256 std::string dir = ""; |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
257 |
31016
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
258 // separate component until first file separator |
29572
aef11bb4e6d1
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29539
diff
changeset
|
259 std::size_t sep_pos |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
260 = xpat.find_first_of (sys::file_ops::dir_sep_chars ()); |
31065
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
261 |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
262 // handle UNC paths |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
263 if (sep_pos == 0 && xpat.length () > 1 |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
264 && sys::file_ops::is_dir_sep (xpat[1])) |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
265 { |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
266 // start pattern with a file, i.e., "\\SERVER\share\file" |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
267 sep_pos = xpat.find_first_of (sys::file_ops::dir_sep_chars (), 2); |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
268 if (sep_pos != std::string::npos) |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
269 sep_pos = xpat.find_first_of (sys::file_ops::dir_sep_chars (), |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
270 sep_pos + 1); |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
271 if (sep_pos != std::string::npos) |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
272 { |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
273 dir = xpat.substr(0, sep_pos); |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
274 xpat = xpat.substr (sep_pos+1); |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
275 sep_pos = xpat.find_first_of (sys::file_ops::dir_sep_chars ()); |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
276 } |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
277 } |
d33af4594440
__wglob__: Handle patterns with UNC paths on Windows (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31027
diff
changeset
|
278 |
31016
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
279 std::string file = (sep_pos != std::string::npos) |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
280 ? xpat.substr (sep_pos) : ""; |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
281 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
|
282 |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
283 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
|
284 { |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
285 // 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
|
286 |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
287 // 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
|
288 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
|
289 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
|
290 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
291 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
|
292 dir = xpat; |
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
293 xpat = file.substr (0, sep_pos); |
31016
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
294 file = (sep_pos != std::string::npos) |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
295 ? file.substr (sep_pos) : ""; |
29073
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
296 if (xpat.empty ()) |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
297 { |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
298 // 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
|
299 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
|
300 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
|
301 { |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 else |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
306 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
|
307 } |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
308 continue; |
f39e75f35e48
__wglob__: Fix some issues with native implementation on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28898
diff
changeset
|
309 } |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
310 } |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
311 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
312 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
|
313 } |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
314 |
28898
caf577e7ef43
__wglob__: Fix for argument containing directory (bug #59252).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28869
diff
changeset
|
315 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
|
316 |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
317 #else |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
318 |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
319 int k = 0; |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
320 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
321 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
|
322 |
28857
43ad651cf5a0
eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents:
28851
diff
changeset
|
323 unwind_action cleanup_glob_info_struct |
28851
1ac5a76ae91d
use [=] capture default specification where possible
John W. Eaton <jwe@octave.org>
parents:
28850
diff
changeset
|
324 ([=] () { 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
|
325 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
326 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
|
327 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
328 std::string xpat = pat(i); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
329 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
330 if (! xpat.empty ()) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
331 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
332 std::string escaped; |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
333 escaped.reserve (xpat.length ()); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
334 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
335 for (std::size_t j = 0; j < xpat.length (); j++) |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
336 { |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
337 # 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
|
338 && ! 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
|
339 if (xpat[j] == '\\') |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22155
diff
changeset
|
340 escaped += '/'; |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
341 else |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
342 # endif |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
343 { |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
344 if (xpat[j] == ']' || xpat[j] == '[') |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
345 escaped += '\\'; |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
346 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
347 escaped += xpat[j]; |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
348 } |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
349 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
350 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
351 // Replace trailing "*.*" by "*". |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
352 int len = escaped.length (); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
353 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
|
354 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
|
355 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
356 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
|
357 octave_glob_nosort_wrapper (), |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
358 glob_info); |
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 if (! err) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
361 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
362 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
|
363 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
364 const char * const *matches |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
365 = 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
|
366 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
367 // 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
|
368 // 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
|
369 // 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
|
370 // characters. Hmm. |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
371 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
372 if (n > 1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
373 || (n == 1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
374 && 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
|
375 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
376 retval.resize (k + n); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
377 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
378 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
|
379 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
380 std::string tmp = matches[j]; |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
381 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
382 std::string unescaped; |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
383 unescaped.reserve (tmp.length ()); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
384 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
385 for (std::size_t m = 0; m < tmp.length (); m++) |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
386 { |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
387 # 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
|
388 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
389 if (tmp[m] == '/') |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22155
diff
changeset
|
390 unescaped += '\\'; |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
391 else |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
392 # endif |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
393 { |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
394 if (tmp[m] == '\\' |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
395 && ++m == tmp.length ()) |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
396 break; |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
397 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
398 unescaped += tmp[m]; |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
399 } |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
400 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
401 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
402 retval[k++] = unescaped; |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
403 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
404 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
405 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
406 octave_globfree_wrapper (glob_info); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
407 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
408 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
409 } |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
410 #endif |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
411 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
412 return retval.sort (); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21929
diff
changeset
|
413 } |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31065
diff
changeset
|
414 |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31065
diff
changeset
|
415 OCTAVE_END_NAMESPACE(sys) |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31065
diff
changeset
|
416 OCTAVE_END_NAMESPACE(octave) |