# HG changeset patch # User jwe # Date 942905828 0 # Node ID d2e12e998a785e0a05d5bfe6026d0ec308bab503 # Parent c4983fc7318f3d6deb8286f697e0ebc5a7f87260 [project @ 1999-11-18 06:17:06 by jwe] diff -r c4983fc7318f -r d2e12e998a78 src/ChangeLog --- a/src/ChangeLog Thu Nov 18 05:20:52 1999 +0000 +++ b/src/ChangeLog Thu Nov 18 06:17:08 1999 +0000 @@ -1,6 +1,6 @@ 1999-11-17 John W. Eaton - * symtab.cc (symbol_record::symbol_def::type_as_string): New function. + * symtab.cc (symbol_record::type_as_string): New function. * symtab.cc (symbol_record::which): New functions. * help.cc (do_which): New functions. @@ -10,6 +10,7 @@ (builtin_help): Use them. * help.cc (do_type): New function. + (symbol_record::type): New function. (Ftype): Use them. * help.cc (print_symbol_type): Delete. diff -r c4983fc7318f -r d2e12e998a78 src/help.cc --- a/src/help.cc Thu Nov 18 05:20:52 1999 +0000 +++ b/src/help.cc Thu Nov 18 06:17:08 1999 +0000 @@ -60,7 +60,6 @@ #include "parse.h" #include "pathsearch.h" #include "procstream.h" -#include "pt-pr-code.h" #include "sighandlers.h" #include "symtab.h" #include "syswait.h" @@ -802,89 +801,7 @@ symbol_record *sym_rec = lookup_by_name (name, 0); if (sym_rec && sym_rec->is_defined ()) - { - if (sym_rec->is_user_function ()) - { - octave_value tmp = sym_rec->def (); - - octave_function *defn = tmp.function_value (); - - string fn = defn ? defn->fcn_file_name () : string (); - - if (pr_orig_txt && ! fn.empty ()) - { - ifstream fs (fn.c_str (), ios::in); - - if (fs) - { - if (pr_type_info && ! quiet) - os << name << " is the function defined from: " - << fn << "\n\n"; - - char ch; - - while (fs.get (ch)) - os << ch; - } - else - os << "unable to open `" << fn << "' for reading!\n"; - } - else - { - if (pr_type_info && ! quiet) - os << name << " is a user-defined function:\n\n"; - - tree_print_code tpc (os, "", pr_orig_txt); - - defn->accept (tpc); - } - } - - // XXX FIXME XXX -- this code should be shared with - // Fwhich. - - else if (sym_rec->is_text_function ()) - os << name << " is a built-in text-function\n"; - else if (sym_rec->is_builtin_function ()) - os << name << " is a built-in function\n"; - else if (sym_rec->is_user_variable () - || sym_rec->is_builtin_variable () - || sym_rec->is_builtin_constant ()) - { - octave_value defn = sym_rec->def (); - - int var_ok = 1; - - if (! error_state) - { - if (pr_type_info && ! quiet) - { - if (var_ok) - { - os << name; - - if (sym_rec->is_user_variable ()) - os << " is a user-defined variable\n"; - else if (sym_rec->is_builtin_variable ()) - os << " is a built-in variable\n"; - else if (sym_rec->is_builtin_constant ()) - os << " is a built-in constant\n"; - else - panic_impossible (); - } - else - os << "type: `" << name << "' has unknown type!\n"; - } - - defn.print_raw (os, true); - - if (pr_type_info) - os << "\n"; - } - } - else - error ("type: `%s' has unknown type!", name.c_str ()); - } + sym_rec->type (os, pr_type_info, quiet, pr_orig_txt); else { string ff = fcn_file_in_path (name); diff -r c4983fc7318f -r d2e12e998a78 src/symtab.cc --- a/src/symtab.cc Thu Nov 18 05:20:52 1999 +0000 +++ b/src/symtab.cc Thu Nov 18 06:17:08 1999 +0000 @@ -33,6 +33,7 @@ #include #include +#include #include "glob-match.h" #include "str-vec.h" @@ -42,6 +43,7 @@ #include "oct-lvalue.h" #include "ov.h" #include "pager.h" +#include "pt-pr-code.h" #include "symtab.h" #include "utils.h" #include "variables.h" @@ -81,6 +83,60 @@ return retval; } +void +SYMBOL_DEF::type (ostream& os, const string& name, bool pr_type_info, + bool quiet, bool pr_orig_txt) +{ + if (is_user_function ()) + { + octave_function *defn = definition.function_value (); + + string fn = defn ? defn->fcn_file_name () : string (); + + if (pr_orig_txt && ! fn.empty ()) + { + ifstream fs (fn.c_str (), ios::in); + + if (fs) + { + if (pr_type_info && ! quiet) + os << name << " is the " << type_as_string () + << " defined from: " << fn << "\n\n"; + + char ch; + + while (fs.get (ch)) + os << ch; + } + else + os << "unable to open `" << fn << "' for reading!\n"; + } + else + { + if (pr_type_info && ! quiet) + os << name << " is a " << type_as_string () << ":\n\n"; + + tree_print_code tpc (os, "", pr_orig_txt); + + defn->accept (tpc); + } + } + else if (is_user_variable () + || is_builtin_variable () + || is_builtin_constant ()) + { + if (pr_type_info && ! quiet) + os << name << " is a " << type_as_string () << "\n"; + + definition.print_raw (os, true); + + if (pr_type_info) + os << "\n"; + } + else + os << name << " is a " << type_as_string () << "\n"; +} + string SYMBOL_DEF::which (const string& name) { @@ -508,7 +564,7 @@ return sr; } else if (warn) - warning ("lookup: symbol`%s' not found", nm.c_str ()); + warning ("lookup: symbol `%s' not found", nm.c_str ()); return 0; } diff -r c4983fc7318f -r d2e12e998a78 src/symtab.h --- a/src/symtab.h Thu Nov 18 05:20:52 1999 +0000 +++ b/src/symtab.h Thu Nov 18 06:17:08 1999 +0000 @@ -143,6 +143,9 @@ string type_as_string (void) const; + void type (ostream& os, const string& name, bool pr_type_info, + bool quiet, bool pr_orig_txt); + string which (const string& name); void which (ostream& os, const string& name); @@ -317,6 +320,9 @@ string type_as_string (void) const { return definition->type_as_string (); } + void type (ostream& os, bool pr_type_info, bool quiet, bool pr_orig_txt) + { definition->type (os, name (), pr_type_info, quiet, pr_orig_txt); } + string which (void) { return definition->which (name ()); } void which (ostream& os) { definition->which (os, name ()); }