diff src/variables.cc @ 811:433ab56e62cd

[project @ 1994-10-14 21:58:37 by jwe]
author jwe
date Fri, 14 Oct 1994 21:59:41 +0000
parents 0acec886a912
children 4c3de23d0fb1
line wrap: on
line diff
--- a/src/variables.cc
+++ b/src/variables.cc
@@ -288,15 +288,18 @@
 
       int count = 0;
       char *ptr = s;
-      while (strstr (ptr, prefix))
+      char *next = 0;
+      while ((next = strstr (ptr, prefix)))
 	{
-	  ptr += len_prefix;
+	  ptr = next + len_prefix;
 	  count++;
 	}
 
       int grow_size = count * (len_home - len_prefix);
 
-      int len_retval = strlen (s) + grow_size;
+      int len_s = strlen (s);
+
+      int len_retval = len_s + count * grow_size;
 
       retval = new char [len_retval+1];
 
@@ -304,21 +307,23 @@
       char *p2 = p1;
       char *pdest = retval;
 
-      for (int i = 0; i < count; i++)
+// Is this really a good way to do this?
+
+      while (count >= 0)
 	{
 	  p2 = strstr (p1, prefix);
 	  
 	  if (! p2)
 	    {
-	      error ("unable to substitute OCTAVE_HOME");
-	      return retval;
+	      memcpy (pdest, p1, strlen (p1)+1);
+	      break;
 	    }
-
-	  if (p1 == p2)
+	  else if (p1 == p2)
 	    {
 	      memcpy (pdest, home, len_home);
 	      pdest += len_home;
 	      p1 += len_prefix;
+	      count--;
 	    }
 	  else
 	    {