Mercurial > hg > octave-terminal
changeset 542:682393bf54f7
[project @ 1994-07-22 04:41:52 by jwe]
author | jwe |
---|---|
date | Fri, 22 Jul 1994 04:44:45 +0000 |
parents | a8d5d1072d99 |
children | b15c1fafec84 |
files | src/file-io.cc src/help.cc src/help.h src/octave.cc src/pr-output.cc src/sysdep.cc src/variables.cc |
diffstat | 7 files changed, 109 insertions(+), 226 deletions(-) [+] |
line wrap: on
line diff
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -44,6 +44,7 @@ #include "octave-hist.h" #include "tree-const.h" #include "error.h" +#include "help.h" #include "utils.h" #include "pager.h" #include "defun.h"
--- a/src/help.cc +++ b/src/help.cc @@ -292,9 +292,42 @@ return keywords; } +void +additional_help_message (ostrstream& output_buf) +{ + output_buf + << "\n" + << "Additional help for builtin functions, operators, and variables\n" + << "is available in the on-line version of the manual.\n" + << "\n" + << "Use the command `help -i <topic>' to search the manual index.\n"; +} + +void +print_usage (const char *string, int just_usage) +{ + ostrstream output_buf; + + symbol_record *sym_rec = global_sym_tab->lookup (string, 0, 0); + if (sym_rec) + { + char *h = sym_rec->help (); + if (h && *h) + { + output_buf << "\n*** " << string << ":\n\n" + << h << "\n"; + + if (! just_usage) + additional_help_message (output_buf); + output_buf << ends; + maybe_page_output (output_buf); + } + } +} + static void -help_syms_list (ostrstream& output_buf, help_list *list, - const char *desc) +display_names_from_help_list (ostrstream& output_buf, help_list *list, + const char *desc) { int count = 0; char **symbols = names (list, count); @@ -305,26 +338,51 @@ } static void +display_symtab_names (ostrstream& output_buf, char **names, + int count, const char *desc) +{ + output_buf << "\n*** " << desc << ":\n\n"; + if (names && count > 0) + list_in_columns (output_buf, names); +} + +static void simple_help (void) { ostrstream output_buf; - help_syms_list (output_buf, operator_help (), "operators"); + display_names_from_help_list (output_buf, operator_help (), + "operators"); - help_syms_list (output_buf, keyword_help (), "reserved words"); - - help_syms_list (output_buf, builtin_text_functions_help (), - "text functions (these names are also reserved)"); + display_names_from_help_list (output_buf, keyword_help (), + "reserved words"); - help_syms_list (output_buf, builtin_mapper_functions_help (), - "mapper functions"); +#ifdef LIST_SYMBOLS +#undef LIST_SYMBOLS +#endif +#define LIST_SYMBOLS(type, msg) \ + do \ + { \ + int count; \ + char **names = global_sym_tab->list (count, 1, type); \ + display_symtab_names (output_buf, names, count, msg); \ + char **ptr = names; \ + while (*ptr) \ + delete [] *ptr++; \ + delete [] names; \ + } \ + while (0) - help_syms_list (output_buf, builtin_general_functions_help (), - "general functions"); +// XXX FIXME XXX -- is this distinction needed? + LIST_SYMBOLS (symbol_def::TEXT_FUNCTION, + "text functions (these names are also reserved)"); - help_syms_list (output_buf, builtin_variables_help (), - "builtin variables"); - + LIST_SYMBOLS (symbol_def::MAPPER_FUNCTION, "mapper functions"); + + LIST_SYMBOLS (symbol_def::BUILTIN_FUNCTION, "general functions"); + + LIST_SYMBOLS (symbol_def::BUILTIN_VARIABLE, "builtin variables"); + // Also need to list variables and currently compiled functions from // the symbol table, if there are any. @@ -416,6 +474,31 @@ return status; } +int +help_from_list (ostrstream& output_buf, const help_list *list, + const char *string, int usage) +{ + char *name; + while ((name = list->name) != 0) + { + if (strcmp (name, string) == 0) + { + if (usage) + output_buf << "\nusage: "; + else + { + output_buf << "\n*** " << string << ":\n\n"; + } + + output_buf << list->help << "\n"; + + return 1; + } + list++; + } + return 0; +} + DEFUN_TEXT ("help", Fhelp, Shelp, -1, 1, "help [-i] [topic ...]\n\ \n\
--- a/src/help.h +++ b/src/help.h @@ -24,6 +24,8 @@ #if !defined (octave_help_h) #define octave_help_h 1 +class ostrstream; + typedef struct help_list { char *name; @@ -34,6 +36,12 @@ extern help_list *operator_help (void); extern help_list *keyword_help (void); +extern int help_from_list (ostrstream& output_buf, + const help_list *list, const char *string, + int usage); + +extern void print_usage (const char *s, int just_usage = 0); + #endif /*
--- a/src/octave.cc +++ b/src/octave.cc @@ -56,6 +56,7 @@ #include "input.h" #include "pager.h" #include "lex.h" +#include "help.h" #include "octave.h" #include "parse.h" #include "unwind-prot.h"
--- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -42,6 +42,7 @@ #include "pr-output.h" #include "mappers.h" #include "pager.h" +#include "help.h" #include "error.h" #include "utils.h" #include "defun.h"
--- a/src/sysdep.cc +++ b/src/sysdep.cc @@ -36,6 +36,7 @@ #include "tree-const.h" #include "octave.h" +#include "help.h" #include "input.h" #include "utils.h" #include "oct-obj.h"
--- a/src/variables.cc +++ b/src/variables.cc @@ -772,218 +772,6 @@ return (sr && sr->is_text_function ()); } -/* - * Help stuff. - */ -help_list * -builtin_mapper_functions_help (void) -{ -#if 0 - int count = 0; - builtin_mapper_functions *mfptr; - - mfptr = mapper_functions; - while (mfptr->name) - { - count++; - mfptr++; - } - - if (count == 0) - return 0; - - help_list *hl = new help_list [count+1]; - - int i = 0; - mfptr = mapper_functions; - while (mfptr->name) - { - hl[i].name = mfptr->name; - hl[i].help = mfptr->help_string; - i++; - mfptr++; - } - - hl[count].name = 0; - hl[count].help = 0; - - return hl; -#endif - - return 0; -} - -help_list * -builtin_general_functions_help (void) -{ -#if 0 - int count = 0; - builtin_general_functions *gfptr; - - gfptr = general_functions; - while (gfptr->name) - { - count++; - gfptr++; - } - - if (count == 0) - return 0; - - help_list *hl = new help_list [count+1]; - - int i = 0; - gfptr = general_functions; - while (gfptr->name) - { - hl[i].name = gfptr->name; - hl[i].help = gfptr->help_string; - i++; - gfptr++; - } - - hl[count].name = 0; - hl[count].help = 0; - - return hl; -#endif - - return 0; -} - -help_list * -builtin_text_functions_help (void) -{ -#if 0 - int count = 0; - builtin_text_functions *tfptr; - - tfptr = text_functions; - while (tfptr->name) - { - count++; - tfptr++; - } - - if (count == 0) - return 0; - - help_list *hl = new help_list [count+1]; - - int i = 0; - tfptr = text_functions; - while (tfptr->name) - { - hl[i].name = tfptr->name; - hl[i].help = tfptr->help_string; - i++; - tfptr++; - } - - hl[count].name = 0; - hl[count].help = 0; - - return hl; -#endif - - return 0; -} - -help_list * -builtin_variables_help (void) -{ -#if 0 - int count = 0; - - builtin_string_variables *svptr; - - svptr = string_variables; - while (svptr->name) - { - count++; - svptr++; - } - - if (count == 0) - return 0; - - help_list *hl = new help_list [count+1]; - - int i = 0; - svptr = string_variables; - while (svptr->name) - { - hl[i].name = svptr->name; - hl[i].help = svptr->help_string; - i++; - svptr++; - } - - hl[count].name = 0; - hl[count].help = 0; - - return hl; -#endif - - return 0; -} - -int -help_from_list (ostrstream& output_buf, const help_list *list, - const char *string, int usage) -{ - char *name; - while ((name = list->name) != 0) - { - if (strcmp (name, string) == 0) - { - if (usage) - output_buf << "\nusage: "; - else - { - output_buf << "\n*** " << string << ":\n\n"; - } - - output_buf << list->help << "\n"; - - return 1; - } - list++; - } - return 0; -} - -void -additional_help_message (ostrstream& output_buf) -{ - output_buf - << "\n" - << "Additional help for builtin functions, operators, and variables\n" - << "is available in the on-line version of the manual.\n" - << "\n" - << "Use the command `help -i <topic>' to search the manual index.\n"; -} - -void -print_usage (const char *string, int just_usage) -{ - ostrstream output_buf; - - help_list *gf_help_list = builtin_general_functions_help (); - help_list *tf_help_list = builtin_text_functions_help (); - help_list *mf_help_list = builtin_mapper_functions_help (); - - if (help_from_list (output_buf, gf_help_list, string, 1) - || help_from_list (output_buf, tf_help_list, string, 1) - || help_from_list (output_buf, mf_help_list, string, 1)) - { - if (! just_usage) - additional_help_message (output_buf); - output_buf << ends; - maybe_page_output (output_buf); - } -} - void install_builtin_variables (void) {