changeset 1792:e6d79e281f7d

[project @ 1996-01-26 02:33:22 by jwe]
author jwe
date Fri, 26 Jan 1996 02:35:42 +0000
parents 96a5948e7294
children 0193a3d7a121
files src/load-save.cc src/octave.cc src/symtab.cc src/variables.cc
diffstat 4 files changed, 60 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/load-save.cc
+++ b/src/load-save.cc
@@ -36,8 +36,7 @@
 #include <fstream.h>
 #include <strstream.h>
 
-#include "fnmatch.h"
-
+#include "oct-glob.h"
 #include "str-vec.h"
 
 #include "defun.h"
@@ -1984,11 +1983,12 @@
 
 static int
 matches_patterns (const string_vector& patterns, int pat_idx,
-		  int num_pat, char *name)
+		  int num_pat, const string& name)
 {
   for (int i = pat_idx; i < num_pat; i++)
     {
-      if (fnmatch (patterns[i].c_str (), name, __FNM_FLAGS) == 0)
+      glob_match pattern (patterns[i]);
+      if (pattern.match (name))
 	return 1;
     }
   return 0;
--- a/src/octave.cc
+++ b/src/octave.cc
@@ -81,6 +81,15 @@
 #define atexit on_exit
 #endif
 
+// Don't redefine the variables if glibc already has.
+#ifndef HAVE_PROGRAM_INVOCATION_NAME
+char *program_invocation_name;
+char *program_invocation_short_name;
+#else
+extern char *program_invocation_name;
+extern char *program_invocation_short_name;
+#endif
+
 // This is from readline's paren.c:
 extern int rl_blink_matching_paren;
 
@@ -166,6 +175,15 @@
 static void
 initialize_globals (const string& name)
 {
+  // Kpathsea needs this.
+
+#ifndef HAVE_PROGRAM_INVOCATION_NAME
+  program_invocation_name = strsave (name.c_str ());
+  program_invocation_short_name = strrchr (program_invocation_name, '/');
+  if (! program_invocation_short_name)
+    program_invocation_short_name = program_invocation_name;
+#endif
+
   raw_prog_name = name;
   size_t pos = raw_prog_name.rfind ('/');
   if (pos == NPOS)
@@ -200,6 +218,32 @@
   editor = default_editor ();
 }
 
+static void
+initialize_pathsearch (void)
+{
+  // This may seem odd, but doing it this way means that we don't have
+  // to modify the kpathsea library...
+
+  char *odb = getenv ("OCTAVE_DB_DIR");
+
+  if (odb)
+    oct_putenv ("TEXMF", odb);
+  else
+    {
+      char *oh = getenv ("OCTAVE_HOME");
+
+      if (oh)
+	{
+	  int len = strlen (oh) + 12;
+	  char *putenv_val = new char [len];
+	  sprintf (putenv_val, "%s/lib/octave", oh);
+	  oct_putenv ("TEXMF", putenv_val);
+	}
+      else  
+	oct_putenv ("TEXMF", OCTAVE_DATADIR "/octave");
+    }
+}
+
 // Initialize by reading startup files.
 
 static void
@@ -355,7 +399,7 @@
 
   initialize_globals (argv[0]);
 
-  initialize_pathsearch (argv[0]);
+  initialize_pathsearch ();
 
   int optc;
   while ((optc = getopt_long (argc, argv, short_opts, long_opts, 0)) != EOF)
--- a/src/symtab.cc
+++ b/src/symtab.cc
@@ -29,8 +29,7 @@
 #include <config.h>
 #endif
 
-#include "fnmatch.h"
-
+#include "oct-glob.h"
 #include "str-vec.h"
 
 #include "error.h"
@@ -988,7 +987,8 @@
 {
   for (int i = 0; i < npats; i++)
     {
-      if (fnmatch (pats[i].c_str (), name.c_str (), __FNM_FLAGS) == 0)
+      glob_match pattern (pats[i]);
+      if (pattern.match (name))
 	return 1;
     }
 
@@ -1099,10 +1099,10 @@
 
 	  unsigned my_type = ptr->type ();
 
-	  string tmp = ptr->name ();
+	  glob_match pattern (pat);
 
 	  if ((type & my_type) && (scope & my_scope)
-	      && fnmatch (pat.c_str (), tmp.c_str (), __FNM_FLAGS) == 0)
+	      && pattern.match (ptr->name ()))
 	    {
 	      symbols[count++] = ptr;
 	    }
--- a/src/variables.cc
+++ b/src/variables.cc
@@ -40,8 +40,8 @@
 
 #include <readline/readline.h>
 
-#include "fnmatch.h"
-
+#include "file-ops.h"
+#include "oct-glob.h"
 #include "str-vec.h"
 
 #include "defaults.h"
@@ -49,7 +49,6 @@
 #include "dirfns.h"
 #include "dynamic-ld.h"
 #include "error.h"
-#include "file-ops.h"
 #include "help.h"
 #include "input.h"
 #include "lex.h"
@@ -1925,13 +1924,13 @@
 
 	  if (! patstr.empty ())
 	    {
-	      const char *pat = patstr.c_str ();
+	      glob_match pattern (patstr);
 
 	      int i;
 	      for (i = 0; i < lcount; i++)
 		{
 		  string nm = lvars[i];
-		  int match = (fnmatch (pat, nm.c_str (), __FNM_FLAGS) == 0);
+		  int match = pattern.match (nm);
 		  if ((exclusive && ! match) || (! exclusive && match))
 		    curr_sym_tab->clear (nm);
 		}
@@ -1940,7 +1939,7 @@
 	      for (i = 0; i < gcount; i++)
 		{
 		  string nm = gvars[i];
-		  int match = (fnmatch (pat, nm.c_str (), __FNM_FLAGS) == 0);
+		  int match = pattern.match (nm);
 		  if ((exclusive && ! match) || (! exclusive && match))
 		    {
 		      count = curr_sym_tab->clear (nm);
@@ -1952,7 +1951,7 @@
 	      for (i = 0; i < fcount; i++)
 		{
 		  string nm = fcns[i];
-		  int match = (fnmatch (pat, nm.c_str (), __FNM_FLAGS) == 0);
+		  int match = pattern.match (nm);
 		  if ((exclusive && ! match) || (! exclusive && match))
 		    {
 		      count = curr_sym_tab->clear (nm);