Mercurial > octave
diff src/symtab.cc @ 605:4f65175911a6
[project @ 1994-08-13 20:10:39 by jwe]
author | jwe |
---|---|
date | Sat, 13 Aug 1994 20:10:39 +0000 |
parents | 4057f845c1ee |
children | 8e4e7e5f307e |
line wrap: on
line diff
--- a/src/symtab.cc Sat Aug 13 20:10:39 1994 +0000 +++ b/src/symtab.cc Sat Aug 13 20:10:39 1994 +0000 @@ -37,6 +37,11 @@ #include "tree-expr.h" #include "tree-const.h" +extern "C" +{ +#include "fnmatch.h" +} + /* * Variables and functions. */ @@ -194,12 +199,6 @@ } int -symbol_def::save (ostream& os, int mark_as_global, int precision) -{ - return definition->save (os, mark_as_global, precision); -} - -int maybe_delete (symbol_def *def) { int count = 0; @@ -521,30 +520,6 @@ } int -symbol_record::save (ostream& os, int mark_as_global, int precision) -{ - int status = -1; - -// This is a kludge, but hey, it doesn't make sense to save them -// anyway, does it? Even if it did, we would just have trouble trying -// to read NaN and Inf on lots of systems anyway... -// -// Should we also save the help string? Maybe someday. - - if (is_read_only ()) - warning ("save: sorry, can't save read-only variable `%s'", nm); - else if (is_function ()) - warning ("save: sorry, can't save function `%s'", nm); - else if (is_defined ()) - { - os << "# name: " << nm << "\n"; - status = definition->save (os, mark_as_global, precision); - } - - return status; -} - -int symbol_record::clear (void) { int count = 0; @@ -988,37 +963,6 @@ } int -symbol_table::save (ostream& os, int mark_as_global, int precision) -{ - int status = 0; - int count; - char **names = list (count, 1, symbol_def::USER_VARIABLE); - char **ptr = names; - if (ptr) - { - while (*ptr) - { - if (save (os, *ptr, mark_as_global, precision)) - status++; - delete [] *ptr++; - } - delete [] names; - } - return status; -} - -int -symbol_table::save (ostream& os, const char *name, int mark_as_global, - int precision) -{ - int status = 0; - symbol_record *sr = lookup (name, 0, 0); - if (sr) - status = sr->save (os, mark_as_global, precision); - return status; -} - -int symbol_table::size (void) const { int count = 0; @@ -1099,10 +1043,14 @@ while (ptr) { assert (count < n); + unsigned my_scope = ptr->is_linked_to_global () + 1; // Tricky... + unsigned my_type = ptr->type (); + if ((type & my_type) && (scope & my_scope)) symbols[count++] = strsave (ptr->name ()); + ptr = ptr->next (); } } @@ -1115,6 +1063,41 @@ return symbols; } +symbol_record ** +symbol_table::glob (int& count, char *pat, unsigned type, + unsigned scope) const +{ + count = 0; + int n = size (); + if (n == 0) + return 0; + + symbol_record **symbols = new symbol_record * [n+1]; + for (int i = 0; i < HASH_TABLE_SIZE; i++) + { + symbol_record *ptr = table[i].next (); + while (ptr) + { + assert (count < n); + + unsigned my_scope = ptr->is_linked_to_global () + 1; // Tricky... + + unsigned my_type = ptr->type (); + + if ((type & my_type) && (scope & my_scope) + && fnmatch (pat, ptr->name (), __FNM_FLAGS) == 0) + { + symbols[count++] = ptr; + } + + ptr = ptr->next (); + } + } + symbols[count] = 0; + + return symbols; +} + void symbol_table::push_context (void) {