changeset 19119:f506de9089e8

Deprecate fnmatch function. * NEWS: Announce deprecation. * scripts/deprecated/fnmatch.m: m-file to replace C++ function and issue deprecated warning. * scripts/deprecated/module.mk: Add fnmatch.m to build system. * dirfns.cc: Rename fnmatch to __fnmatch__ internal version. Switch DEFUNX to DEFUN. * test/system.tst: Remove fnmatch tests
author Rik <rik@octave.org>
date Sat, 20 Sep 2014 21:17:43 -0700
parents 9c5a17d5fc19
children 3fb075f5140f
files NEWS libinterp/corefcn/dirfns.cc scripts/deprecated/fnmatch.m scripts/deprecated/module.mk test/system.tst
diffstat 5 files changed, 56 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Sat Sep 20 20:31:16 2014 -0700
+++ b/NEWS	Sat Sep 20 21:17:43 2014 -0700
@@ -96,6 +96,7 @@
       find_dir_in_path   | dir_in_loadpath
       finite             | isfinite
       fmod               | rem
+      fnmatch            | glob or regexp
       nfields            | numfields
       syl                | sylvester
       usage              | print_usage
--- a/libinterp/corefcn/dirfns.cc	Sat Sep 20 20:31:16 2014 -0700
+++ b/libinterp/corefcn/dirfns.cc	Sat Sep 20 21:17:43 2014 -0700
@@ -608,7 +608,7 @@
         [2,1] = file2\n\
       @}\n\
 @end example\n\
-@seealso{ls, dir, readdir, what, fnmatch}\n\
+@seealso{ls, dir, readdir, what}\n\
 @end deftypefn")
 {
   octave_value retval;
@@ -664,7 +664,7 @@
 %! assert (result3, {"file1"; "file2"});
 */
 
-DEFUNX ("fnmatch", Ffnmatch, args, ,
+DEFUN (__fnmatch__, args, ,
         "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} fnmatch (@var{pattern}, @var{string})\n\
 Return true or false for each element of @var{string} that matches any of\n\
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/deprecated/fnmatch.m	Sat Sep 20 21:17:43 2014 -0700
@@ -0,0 +1,52 @@
+## Copyright (C) 2014 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Built-in Function} {} fnmatch (@var{pattern}, @var{string})
+##
+## @code{fnmatch} is deprecated and will be removed in Octave version 4.6.
+## Please use @code{glob} or @code{regexp} in all new code.
+##
+## Return true or false for each element of @var{string} that matches any of
+## the elements of the string array @var{pattern}, using the rules of
+## filename pattern matching.  For example:
+## 
+## @example
+## @group
+## fnmatch (\"a*b\", @{\"ab\"; \"axyzb\"; \"xyzab\"@})
+##      @result{} [ 1; 1; 0 ]
+## @end group
+## @end example
+## @seealso{glob, regexp}
+## @end deftypefn
+
+## Deprecated in version 4.2
+
+function retval = fnmatch (varargin)
+
+  persistent warned = false;
+  if (! warned)
+    warned = true;
+    warning ("Octave:deprecated-function",
+             "fnmatch is obsolete and will be removed from a future version of Octave, please use glob or regexp instead");
+  endif
+
+  retval = __fnmatch__ (varargin{:});
+
+endfunction
+
--- a/scripts/deprecated/module.mk	Sat Sep 20 20:31:16 2014 -0700
+++ b/scripts/deprecated/module.mk	Sat Sep 20 21:17:43 2014 -0700
@@ -5,6 +5,7 @@
   deprecated/find_dir_in_path.m \
   deprecated/finite.m \
   deprecated/fmod.m \
+  deprecated/fnmatch.m \
   deprecated/isstr.m \
   deprecated/nfields.m \
   deprecated/strmatch.m \
--- a/test/system.tst	Sat Sep 20 20:31:16 2014 -0700
+++ b/test/system.tst	Sat Sep 20 21:17:43 2014 -0700
@@ -185,17 +185,6 @@
 %!error <Invalid call to glob> glob ()
 %!error <Invalid call to glob> glob ("foo", 1)
 
-%!test
-%! string_fill_char = char (0);
-%! assert ((fnmatch ("a*a", {"aba"; "xxxba"; "aa"}) == [1; 0; 1]
-%! && fnmatch ({"a*a"; "b*b"}, "bob")
-%! && fnmatch ("x[0-5]*", {"x1"; "x6"}) == [1; 0]
-%! && fnmatch ("x[0-5]*", {"x1"; "x6"; "x001"}) == [1; 0; 1]
-%! && fnmatch ("x???y", {"xabcy"; "xy"}) == [1; 0]));
-
-%!error <Invalid call to fnmatch> fnmatch ()
-%!error <Invalid call to fnmatch> fnmatch ("foo", "bar", 3)
-
 %!assert (ischar (file_in_path (path (), "date.m")))
 
 %!error <invalid option> file_in_path ("foo", "bar", 1)