changeset 266:818be8915438

[project @ 1994-01-03 23:06:07 by jwe]
author jwe
date Mon, 03 Jan 1994 23:07:25 +0000
parents 221a5fa8bf01
children 12010b8263ca
files src/Makefile.in src/t-builtins.cc
diffstat 2 files changed, 75 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.in	Mon Jan 03 22:08:53 1994 +0000
+++ b/src/Makefile.in	Mon Jan 03 23:07:25 1994 +0000
@@ -63,8 +63,8 @@
 	f-det.h f-eig.h f-expm.h f-fft.h f-fsolve.h f-fsqp.h f-givens.h \
 	f-hess.h f-ifft.h f-inv.h f-lpsolve.h f-lsode.h f-lu.h \
 	f-npsol.h f-qpsol.h f-qr.h f-quad.h f-qzval.h f-rand.h \
-	f-schur.h f-svd.h f-syl.h file-io.h g-builtins.h getopt.h \
-	gripes.h help.h idx-vector.h input.h lex.h mappers.h \
+	f-schur.h f-svd.h f-syl.h file-io.h fnmatch.h g-builtins.h \
+	getopt.h gripes.h help.h idx-vector.h input.h lex.h mappers.h \
 	missing-math.h octave.h octave-hist.h pager.h parse.h \
 	pr-output.h procstream.h sighandlers.h statdefs.h symtab.h \
 	sysdep.h t-builtins.h token.h tree-base.h tree-const.h tree.h \
@@ -76,14 +76,14 @@
 	f-expm.cc f-fft.cc f-fsolve.cc f-fsqp.cc f-givens.cc \
 	f-hess.cc f-ifft.cc f-inv.cc f-lpsolve.cc f-lsode.cc f-lu.cc \
 	f-npsol.cc f-qpsol.cc f-qr.cc f-quad.cc f-qzval.cc f-rand.cc \
-	f-schur.cc f-svd.cc f-syl.cc file-io.cc	g-builtins.cc \
-	getopt.c getopt1.c gripes.cc help.cc idx-vector.cc input.cc \
-	lex.l mappers.cc octave.cc octave-hist.cc pager.cc parse.y \
-	pr-output.cc procstream.cc sighandlers.cc symtab.cc \
-	sysdep.cc t-builtins.cc tc-assign.cc tc-extras.cc \
-	tc-index.cc tc-inlines.cc token.cc tree.cc tree-const.cc \
-	tree-plot.cc unwind-prot.cc user-prefs.cc utils.cc \
-	variables.cc xdiv.cc xpow.cc SLStack.cc
+	f-schur.cc f-svd.cc f-syl.cc file-io.cc	fnmatch.c \
+	g-builtins.cc getopt.c getopt1.c gripes.cc help.cc \
+	idx-vector.cc input.cc lex.l mappers.cc octave.cc \
+	octave-hist.cc pager.cc parse.y pr-output.cc procstream.cc \
+	sighandlers.cc symtab.cc sysdep.cc t-builtins.cc tc-assign.cc \
+	tc-extras.cc tc-index.cc tc-inlines.cc token.cc tree.cc \
+	tree-const.cc tree-plot.cc unwind-prot.cc user-prefs.cc \
+	utils.cc variables.cc xdiv.cc xpow.cc SLStack.cc
 
 DEP_SOURCES_2 = $(patsubst %.l, %.cc, $(SOURCES))
 DEP_SOURCES_1 = $(patsubst %.y, %.cc, $(DEP_SOURCES_2))
@@ -96,13 +96,13 @@
 	f-npsol.o f-qpsol.o f-qr.o f-quad.o f-qzval.o f-rand.o \
 	f-schur.o f-svd.o f-syl.o 
 
-OBJECTS = arith-ops.o builtins.o error.o file-io.o g-builtins.o \
-	getopt.o getopt1.o gripes.o help.o idx-vector.o input.o \
-	lex.o mappers.o octave.o octave-hist.o pager.o parse.o \
-	pr-output.o procstream.o sighandlers.o symtab.o sysdep.o \
-	t-builtins.o tc-assign.o tc-extras.o tc-index.o token.o \
-	tree.o tree-const.o tree-plot.o unwind-prot.o user-prefs.o \
-	utils.o variables.o xdiv.o xpow.o SLStack.o \
+OBJECTS = arith-ops.o builtins.o error.o file-io.o fnmatch.o \
+	g-builtins.o getopt.o getopt1.o gripes.o help.o idx-vector.o \
+	input.o lex.o mappers.o octave.o octave-hist.o pager.o \
+	parse.o pr-output.o procstream.o sighandlers.o symtab.o \
+	sysdep.o t-builtins.o tc-assign.o tc-extras.o tc-index.o \
+	token.o tree.o tree-const.o tree-plot.o unwind-prot.o \
+	user-prefs.o utils.o variables.o xdiv.o xpow.o SLStack.o \
 	@DYNAMIC_LD_OBJ@
 
 OCTAVE_LIBS = ../liboctave.a ../libcruft.a ../libinfo.a \
--- a/src/t-builtins.cc	Mon Jan 03 22:08:53 1994 +0000
+++ b/src/t-builtins.cc	Mon Jan 03 23:07:25 1994 +0000
@@ -31,6 +31,10 @@
 GNU ls, print_many_per_line, copyright (C) 1985, 1988, 1990, 1991 Free
 Software Foundation, Inc.
 
+The function glob_pattern_p was taken from the file glob.c distributed
+with GNU Bash, the Bourne Again SHell, copyright (C) 1985, 1988, 1989
+Free Software Foundation, Inc.
+
 */
 
 #ifdef HAVE_CONFIG_H
@@ -51,7 +55,6 @@
 #include <time.h>
 #include <errno.h>
 #include <signal.h>
-#include <String.h>
 
 #include "procstream.h"
 
@@ -72,6 +75,11 @@
 #include "tree.h"
 #include "help.h"
 
+extern "C"
+{
+#include "fnmatch.h"
+}
+
 // May need replacement for this on some machines.
 extern "C"
 {
@@ -278,21 +286,17 @@
 	  argv++;
 	  if (*argv != (char *) NULL)
 	    {
-	      Regex rx (*argv);
-
 	      int i;
 	      for (i = 0; i < lcount; i++)
 		{
-		  String nm (lvars[i]);
-		  if (nm.matches (rx))
+		  if (fnmatch (*argv, lvars[i], __FNM_FLAGS) == 0)
 		    curr_sym_tab->clear (lvars[i]);
 		}
 
 	      int count;
 	      for (i = 0; i < gcount; i++)
 		{
-		  String nm (gvars[i]);
-		  if (nm.matches (rx))
+		  if (fnmatch (*argv, gvars[i], __FNM_FLAGS) == 0)
 		    {
 		      count = curr_sym_tab->clear (gvars[i]);
 		      if (count > 0)
@@ -302,8 +306,7 @@
 
 	      for (i = 0; i < fcount; i++)
 		{
-		  String nm (fcns[i]);
-		  if (nm.matches (rx))
+		  if (fnmatch (*argv, fcns[i], __FNM_FLAGS) == 0)
 		    {
 		      count = curr_sym_tab->clear (fcns[i]);
 		      if (count > 0)
@@ -813,6 +816,45 @@
 }
 
 /*
+ * Return nonzero if PATTERN has any special globbing chars in it.
+ */
+static int
+glob_pattern_p (char *pattern)
+{
+  char *p = pattern;
+  char c;
+  int open = 0;
+
+  while ((c = *p++) != '\0')
+    {
+      switch (c)
+	{
+	case '?':
+	case '*':
+	  return 1;
+
+	case '[':	// Only accept an open brace if there is a close
+	  open++;	// brace to match it.  Bracket expressions must be
+	  continue;	// complete, according to Posix.2
+
+	case ']':
+	  if (open)
+	    return 1;
+	  continue;
+	  
+	case '\\':
+	  if (*p++ == '\0')
+	    return 0;
+
+	default:
+	  continue;
+	}
+    }
+
+  return 0;
+}
+
+/*
  * Write variables to an output stream.
  */
 tree_constant
@@ -837,6 +879,11 @@
 // tree_constant (string)?
       stream = cout;
     }
+  else if (argc == 1 && glob_pattern_p (*argv)) // Guard against things
+    {						// like `save a*',
+      print_usage ("save");			// which are probably
+      return retval;				// mistakes...
+    }
   else
     {
       char *fname = tilde_expand (*argv);
@@ -871,14 +918,12 @@
 	  int count;
 	  char **lvars = curr_sym_tab->list (count, 0,
 					     symbol_def::USER_VARIABLE);
-	  Regex rx (*argv);
 
 	  int saved_or_error = 0;
 	  int i;
 	  for (i = 0; i < count; i++)
 	    {
-	      String nm (lvars[i]);
-	      if (nm.matches (rx)
+	      if (fnmatch (*argv, lvars[i], __FNM_FLAGS) == 0
 		  && curr_sym_tab->save (stream, lvars[i]) != 0)
 		saved_or_error++;
 	    }
@@ -888,8 +933,7 @@
 
 	  for (i = 0; i < count; i++)
 	    {
-	      String nm (bvars[i]);
-	      if (nm.matches (rx)
+	      if (fnmatch (*argv, bvars[i], __FNM_FLAGS) == 0
 		  && global_sym_tab->save (stream, bvars[i]) != 0)
 		saved_or_error++;
 	    }