Mercurial > hg > octave-avbm
changeset 2247:108d848901b4
[project @ 1996-05-22 07:39:29 by jwe]
author | jwe |
---|---|
date | Wed, 22 May 1996 07:39:29 +0000 |
parents | a6791c6486fa |
children | 2e4be59df9f9 |
files | src/input.cc |
diffstat | 1 files changed, 21 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/src/input.cc +++ b/src/input.cc @@ -635,13 +635,11 @@ return rl_instream; } -// XXX FIXME XXX -- this should return a string_vector. - -static const char ** +static string_vector generate_struct_completions (const char *text, char *& prefix, char *& hint) { - const char **names = 0; + string_vector names; assert (text); @@ -677,8 +675,6 @@ if (def && def->is_map ()) { - string_vector tmp_names; - if (elts && *elts) { octave_value ult = def->lookup_map_element (elts, 0, 1); @@ -686,23 +682,13 @@ if (ult.is_map ()) { Octave_map m = ult.map_value (); - tmp_names = m.make_name_list (); + names = m.make_name_list (); } } else { Octave_map m = def->map_value (); - tmp_names = m.make_name_list (); - } - - int n = tmp_names.length (); - - if (n > 0) - { - names = new const char * [n+1]; - for (int i = 0; i < n; i++) - names[i] = strsave (tmp_names[i].c_str ()); - names[n] = 0; + names = m.make_name_list (); } } } @@ -713,32 +699,19 @@ } // XXX FIXME XXX -- make this generate file names when appropriate. -// XXX FIXME XXX -- this should return a string_vector. -static const char ** +static string_vector generate_possible_completions (const char *text, char *& prefix, char *& hint) { - const char **names = 0; + string_vector names; prefix = 0; if (text && *text && *text != '.' && strrchr (text, '.')) names = generate_struct_completions (text, prefix, hint); else - { - string_vector tmp_names = make_name_list (); - - int n = tmp_names.length (); - - if (n > 0) - { - names = new const char * [n+1]; - for (int i = 0; i < n; i++) - names[i] = strsave (tmp_names[i].c_str ()); - names[n] = 0; - } - } + names = make_name_list (); return names; } @@ -804,7 +777,8 @@ static int hint_len = 0; static int list_index = 0; - static const char **name_list = 0; + static int list_length = 0; + static string_vector name_list; static int matches = 0; @@ -812,18 +786,6 @@ { list_index = 0; - if (name_list) - { - const char **ptr = name_list; - - while (ptr && *ptr) - delete [] *ptr++; - - delete [] name_list; - - name_list = 0; - } - delete [] prefix; prefix = 0; @@ -840,22 +802,24 @@ hint_len = strlen (hint); matches = 0; - if (name_list) - { - int i = 0; - while (name_list[i]) - if (strncmp (name_list[i++], hint, hint_len) == 0) - matches++; - } + + list_length = name_list.length (); + + for (int i = 0; i < list_length; i++) + if (name_list[i].compare (hint, 0, hint_len)) + matches++; } - if (name_list && matches) + if (list_length > 0 && matches > 0) { const char *name; - while ((name = name_list[list_index]) != 0) + while (list_index < list_length) { + name = name_list[list_index].c_str (); + list_index++; + if (strncmp (name, hint, hint_len) == 0) { int len = 2 + prefix_len + strlen (name); @@ -873,8 +837,7 @@ if (matches == 1 && looks_like_struct (buf)) rl_completion_append_character = '.'; else - rl_completion_append_character - = Vcompletion_append_char; + rl_completion_append_character = Vcompletion_append_char; return buf; }