# HG changeset patch # User jwe # Date 783786002 0 # Node ID b6b78f85743ab9b851c6667a53b38e76b9b414b7 # Parent f02ec9f8de652d5a84c303fdb9715f9b9ac2e6d0 [project @ 1994-11-02 14:20:02 by jwe] diff -r f02ec9f8de65 -r b6b78f85743a src/help.cc --- a/src/help.cc Wed Nov 02 05:19:02 1994 +0000 +++ b/src/help.cc Wed Nov 02 14:20:02 1994 +0000 @@ -439,7 +439,7 @@ do \ { \ int count; \ - char **names = global_sym_tab->list (count, 1, type); \ + char **names = global_sym_tab->list (count, 0, 0, 1, type); \ display_symtab_names (output_buf, names, count, msg); \ char **ptr = names; \ while (*ptr) \ diff -r f02ec9f8de65 -r b6b78f85743a src/load-save.cc --- a/src/load-save.cc Wed Nov 02 05:19:02 1994 +0000 +++ b/src/load-save.cc Wed Nov 02 14:20:02 1994 +0000 @@ -1356,47 +1356,59 @@ // // The data is expected to be in the following format: // -// object type bytes -// ------ ---- ----- -// magic number string 10 +// Header (one per file): +// ===================== // -// float format integer 1 +// object type bytes +// ------ ---- ----- +// magic number string 10 // -// name_length integer 4 +// float format integer 1 +// // -// name string name_length +// Data (one set for each item): +// ============================ // -// doc_length integer 4 +// object type bytes +// ------ ---- ----- +// name_length integer 4 // -// doc string doc_length +// name string name_length // -// global flag integer 1 +// doc_length integer 4 +// +// doc string doc_length // -// data type integer 1 +// global flag integer 1 // -// data: -// scalar real 8 +// data type integer 1 // -// complex scalar complex 16 +// data (one of): +// +// scalar: +// data real 8 // -// matrix: -// rows integer 4 -// columns integer 4 -// data real r*c*8 +// complex scalar: +// data complex 16 +// +// matrix: +// rows integer 4 +// columns integer 4 +// data real r*c*8 // -// complex matrix: -// rows integer 4 -// columns integer 4 -// data complex r*c*16 +// complex matrix: +// rows integer 4 +// columns integer 4 +// data complex r*c*16 // -// string: -// length int 4 -// data string length +// string: +// length int 4 +// data string length // -// range: -// base real 8 -// limit real 8 -// increment real 8 +// range: +// base real 8 +// limit real 8 +// increment real 8 // // FILENAME is used for error messages. @@ -1412,13 +1424,12 @@ doc = 0; +// We expect to fail here, at the beginning of a record, so not being +// able to read another name should not result in an error. + is.read (&name_len, 4); if (! is) - { - if (! is.eof ()) - goto data_read_error; - return 0; - } + return 0; if (swap) swap_4_bytes ((char *) &name_len); @@ -1974,8 +1985,10 @@ break; } - if (error_state || stream.eof ()) + if (error_state || stream.eof () || ! name) { + delete [] name; + delete [] doc; break; } else if (! error_state && name) @@ -2016,6 +2029,8 @@ error ("load: are you sure `%s' is an Octave data file?", orig_fname); + delete [] name; + delete [] doc; break; } diff -r f02ec9f8de65 -r b6b78f85743a src/symtab.cc --- a/src/symtab.cc Wed Nov 02 05:19:02 1994 +0000 +++ b/src/symtab.cc Wed Nov 02 14:20:02 1994 +0000 @@ -973,12 +973,26 @@ return strcmp (a->name (), b->name ()); } +static int +matches_patterns (const char *name, char **pats, int npats) +{ + while (npats-- > 0) + { + if (fnmatch (*pats, name, __FNM_FLAGS) == 0) + return 1; + + pats++; + } + + return 0; +} + // This function should probably share code with symbol_table::list. // XXX FIXME XXX symbol_record_info * -symbol_table::long_list (int& count, int sort, unsigned type, - unsigned scope) const +symbol_table::long_list (int& count, char **pats, int npats, int sort, + unsigned type, unsigned scope) const { count = 0; int n = size (); @@ -992,12 +1006,17 @@ 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++] = symbol_record_info (*ptr); - } + + char *my_name = ptr->name (); + + if ((type & my_type) && (scope & my_scope) + && (npats == 0 || matches_patterns (my_name, pats, npats))) + symbols[count++] = symbol_record_info (*ptr); + ptr = ptr->next (); } } @@ -1011,8 +1030,8 @@ } char ** -symbol_table::list (int& count, int sort, unsigned type, - unsigned scope) const +symbol_table::list (int& count, char **pats, int npats, int sort, + unsigned type, unsigned scope) const { count = 0; int n = size (); @@ -1031,7 +1050,10 @@ unsigned my_type = ptr->type (); - if ((type & my_type) && (scope & my_scope)) + char *my_name = ptr->name (); + + if ((type & my_type) && (scope & my_scope) + && (npats == 0 || matches_patterns (my_name, pats, npats))) symbols[count++] = strsave (ptr->name ()); ptr = ptr->next (); diff -r f02ec9f8de65 -r b6b78f85743a src/symtab.h --- a/src/symtab.h Wed Nov 02 05:19:02 1994 +0000 +++ b/src/symtab.h Wed Nov 02 14:20:02 1994 +0000 @@ -297,12 +297,13 @@ int size (void) const; - symbol_record_info *long_list (int& count, int sort = 0, + symbol_record_info *long_list (int& count, char **pats = 0, + int npats = 0, int sort = 0, unsigned type = SYMTAB_ALL_TYPES, unsigned scope = SYMTAB_ALL_SCOPES) const; - char **list (int& count, int sort = 0, - unsigned type = SYMTAB_ALL_TYPES, + char **list (int& count, char **pats = 0, int npats = 0, + int sort = 0, unsigned type = SYMTAB_ALL_TYPES, unsigned scope = SYMTAB_ALL_SCOPES) const; symbol_record **glob (int& count, char *pat = "*", diff -r f02ec9f8de65 -r b6b78f85743a src/variables.cc --- a/src/variables.cc Wed Nov 02 05:19:02 1994 +0000 +++ b/src/variables.cc Wed Nov 02 14:20:02 1994 +0000 @@ -967,16 +967,16 @@ } static int -maybe_list (const char *header, ostrstream& output_buf, - int show_verbose, symbol_table *sym_tab, unsigned type, - unsigned scope) +maybe_list (const char *header, char **argv, int argc, + ostrstream& output_buf, int show_verbose, symbol_table + *sym_tab, unsigned type, unsigned scope) { int count; int status = 0; if (show_verbose) { symbol_record_info *symbols; - symbols = sym_tab->long_list (count, 1, type, scope); + symbols = sym_tab->long_list (count, argv, argc, 1, type, scope); if (symbols && count > 0) { output_buf << "\n" << header << "\n\n" @@ -990,7 +990,7 @@ } else { - char **symbols = sym_tab->list (count, 1, type, scope); + char **symbols = sym_tab->list (count, argv, argc, 1, type, scope); if (symbols && count > 0) { output_buf << "\n" << header << "\n\n"; @@ -1057,9 +1057,10 @@ show_variables = 0; } - for (int i = 1; i < argc; i++) + while (--argc > 0) { argv++; + if (strcmp (*argv, "-all") == 0 || strcmp (*argv, "-a") == 0) { show_builtins++; @@ -1074,8 +1075,10 @@ show_verbose++; else if (strcmp (*argv, "-variables") == 0 || strcmp (*argv, "-v") == 0) show_variables++; + else if (*argv[0] == '-') + warning ("%s: unrecognized option `%s'", my_name, *argv); else - warning ("%s: unrecognized option `%s'", my_name, *argv); + break; } // If the user specified -l and nothing else, show variables. If @@ -1092,12 +1095,12 @@ if (show_builtins) { - pad_after += maybe_list ("*** built-in variables:", + pad_after += maybe_list ("*** built-in variables:", argv, argc, output_buf, show_verbose, global_sym_tab, symbol_def::BUILTIN_VARIABLE, SYMTAB_ALL_SCOPES); - pad_after += maybe_list ("*** built-in functions:", + pad_after += maybe_list ("*** built-in functions:", argv, argc, output_buf, show_verbose, global_sym_tab, symbol_def::BUILTIN_FUNCTION, SYMTAB_ALL_SCOPES); @@ -1106,21 +1109,21 @@ if (show_functions) { pad_after += maybe_list ("*** currently compiled functions:", - output_buf, show_verbose, global_sym_tab, - symbol_def::USER_FUNCTION, + argv, argc, output_buf, show_verbose, + global_sym_tab, symbol_def::USER_FUNCTION, SYMTAB_ALL_SCOPES); } if (show_variables) { - pad_after += maybe_list ("*** local user variables:", + pad_after += maybe_list ("*** local user variables:", argv, argc, output_buf, show_verbose, curr_sym_tab, symbol_def::USER_VARIABLE, SYMTAB_LOCAL_SCOPE); pad_after += maybe_list ("*** globally visible user variables:", - output_buf, show_verbose, curr_sym_tab, - symbol_def::USER_VARIABLE, + argv, argc, output_buf, show_verbose, + curr_sym_tab, symbol_def::USER_VARIABLE, SYMTAB_GLOBAL_SCOPE); }