diff liboctave/pathsearch.cc @ 4390:c378263ef911

[project @ 2003-04-25 21:05:06 by jwe]
author jwe
date Fri, 25 Apr 2003 21:05:06 +0000
parents 7d48a8fba1d4
children dd108fa566fa
line wrap: on
line diff
--- a/liboctave/pathsearch.cc
+++ b/liboctave/pathsearch.cc
@@ -69,9 +69,9 @@
 
 	      for (dir = *elt_dirs; dir; dir = STR_LLIST_NEXT (*dir))
 		{
-		  char *elt_dir = STR_LLIST (*dir);
+		  const std::string elt_dir = STR_LLIST (*dir);
 
-		  if (elt_dir)
+		  if (! elt_dir.empty ())
 		    {
 		      if (count == nmax)
 			nmax *= 2;
@@ -93,143 +93,27 @@
 std::string
 dir_path::find_first (const std::string& nm)
 {
-  std::string retval;
-
-  if (initialized)
-    {
-      char *tmp = kpse_path_search (p.c_str (), nm.c_str (), true);
-
-      if (tmp)
-	{
-	  retval = tmp;
-	  free (tmp);
-	}
-    }
-
-  return retval;
-}
-
-static string_vector
-make_retval (char **tmp)
-{
-  string_vector retval;
-
-  if (tmp)
-    {
-      int count = 0;
-      char **ptr = tmp;
-      while (*ptr++)
-	count++;
-
-      retval.resize (count);
-
-      for (int i = 0; i < count; i++)
-	retval[i] = tmp[i];
-    }
-
-  return retval;
-}
-
-static void
-free_c_array (char **tmp)
-{
-  if (tmp)
-    {
-      char **ptr = tmp;
-
-      while (char *elt = *ptr++)
-	if (elt)
-	  free (elt);
-
-      free (tmp);
-    }
+  return initialized ? kpse_path_search (p, nm, true) : std::string ();
 }
 
 string_vector
 dir_path::find_all (const std::string& nm)
 {
-  string_vector retval;
-
-  if (initialized)
-    {
-      char **tmp = kpse_all_path_search (p.c_str (), nm.c_str ());
-
-      retval = make_retval (tmp);
-
-      free_c_array (tmp);
-    }
-
-  return retval;
-}
-
-static const char **
-make_c_names (const string_vector& names)
-{
-  int len = names.length ();
-
-  const char **c_names = new const char *[len+1];
-
-  for (int i = 0; i < len; i++)
-    c_names[i] = strsave (names[i].c_str ());
-
-  c_names[len] = 0;
-
-  return c_names;
-}
-
-static void
-delete_c_names (const char **c_names)
-{
-  const char **p = c_names;
-
-  while (const char *elt = *p++)
-    delete [] elt;
-
-  delete [] c_names;
+  return initialized ? kpse_all_path_search (p, nm) : string_vector ();
 }
 
 std::string
 dir_path::find_first_of (const string_vector& names)
 {
-  std::string retval;
-
-  if (initialized)
-    {
-      const char **c_names = make_c_names (names);
-
-      char *tmp = kpse_path_find_first_of (p.c_str (), c_names, true);
-
-      delete_c_names (c_names);
-
-      if (tmp)
-	{
-	  retval = tmp;
-	  free (tmp);
-	}
-    }
-
-  return retval;
+  return initialized
+    ? kpse_path_find_first_of (p, names, true) : std::string ();
 }
 
 string_vector
 dir_path::find_all_first_of (const string_vector& names)
 {
-  string_vector retval;
-
-  if (initialized)
-    {
-      const char **c_names = make_c_names (names);
-
-      char **tmp = kpse_all_path_find_first_of (p.c_str (), c_names);
-
-      delete_c_names (c_names);
-
-      retval = make_retval (tmp);
-
-      free_c_array (tmp);
-    }
-
-  return retval;
+  return initialized
+    ? kpse_all_path_find_first_of (p, names) : string_vector ();
 }
 
 void