Mercurial > hg > octave-lyh
diff src/utils.cc @ 1781:e090f89bf2f5
[project @ 1996-01-24 08:04:14 by jwe]
author | jwe |
---|---|
date | Wed, 24 Jan 1996 08:09:03 +0000 |
parents | 3a9462b655f1 |
children | ebc1a0b2e854 |
line wrap: on
line diff
--- a/src/utils.cc +++ b/src/utils.cc @@ -60,6 +60,7 @@ #include "str-vec.h" #include "defun.h" +#include "dir-ops.h" #include "dirfns.h" #include "error.h" #include "gripes.h" @@ -71,7 +72,6 @@ #include "pager.h" #include "pathsearch.h" #include "sysdep.h" -#include "sysdir.h" #include "toplev.h" #include "unwind-prot.h" #include "user-prefs.h" @@ -315,58 +315,54 @@ } string_vector -get_fcn_file_names (int& num, const char *dir, int no_suffix) +get_fcn_file_names (const string& name, int no_suffix) { - static int num_max = 256; - string_vector retval (num_max); - int i = 0; + string_vector retval; + + dir_entry dir (name); + + if (dir) + { + string_vector tmp = dir.read (); - DIR *dirp = opendir (dir); - if (dirp) - { - struct dirent *entry; - while ((entry = readdir (dirp)) != 0) + int max_len = tmp.length (); + + retval.resize (max_len); + + int k = 0; + int i; + for (i = 0; i < max_len; i++) { - int len = NLENGTH (entry); + string entry = tmp[i]; + + int len = entry.length (); + #if defined (WITH_DYNAMIC_LINKING) if ((len > 2 - && entry->d_name[len-2] == '.' - && entry->d_name[len-1] == 'm') + && entry[len-2] == '.' && entry[len-1] == 'm') || (len > 4 - && entry->d_name[len-4] == '.' - && entry->d_name[len-3] == 'o' - && entry->d_name[len-2] == 'c' - && entry->d_name[len-1] == 't')) + && entry[len-4] == '.' && entry[len-3] == 'o' + && entry[len-2] == 'c' && entry[len-1] == 't')) #else if (len > 2 - && entry->d_name[len-2] == '.' - && entry->d_name[len-1] == 'm') + && entry[len-2] == '.' && entry[len-1] == 'm') #endif { - retval[i] = entry->d_name; if (no_suffix) { - if (retval[i][len-1] == 'm') - retval[i][len-2] = '\0'; + if (entry[len-1] == 'm') + entry.resize (len-2); else - retval[i][len-4] = '\0'; + entry.resize (len-4); } - i++; - - if (i == num_max - 1) - { - num_max += 256; - retval.resize (num_max); - } + retval[k++] = entry; } } - closedir (dirp); + + retval.resize (i); } - num = i; - retval.resize (num); - return retval; } @@ -390,13 +386,13 @@ if (elt_dir) { - int tmp_num; - string_vector names - = get_fcn_file_names (tmp_num, elt_dir, no_suffix); + string_vector names = get_fcn_file_names (elt_dir, no_suffix); + + int tmp_num = names.length (); - if (i + tmp_num >= num_max - 1) + if (i + tmp_num > num_max) { - num_max += 1024; + num_max += tmp_num; retval.resize (num_max); }