diff options
author | Jari Aalto <jari.aalto@cante.net> | 1996-12-23 17:02:34 +0000 |
---|---|---|
committer | Jari Aalto <jari.aalto@cante.net> | 2009-09-12 16:46:49 +0000 |
commit | ccc6cda312fea9f0468ee65b8f368e9653e1380b (patch) | |
tree | b059878adcfd876c4acb8030deda1eeb918c7e75 /builtins/help.def | |
parent | 726f63884db0132f01745f1fb4465e6621088ccf (diff) | |
download | android_external_bash-ccc6cda312fea9f0468ee65b8f368e9653e1380b.tar.gz android_external_bash-ccc6cda312fea9f0468ee65b8f368e9653e1380b.tar.bz2 android_external_bash-ccc6cda312fea9f0468ee65b8f368e9653e1380b.zip |
Imported from ../bash-2.0.tar.gz.
Diffstat (limited to 'builtins/help.def')
-rw-r--r-- | builtins/help.def | 165 |
1 files changed, 92 insertions, 73 deletions
diff --git a/builtins/help.def b/builtins/help.def index c9f1db8..e5e82d5 100644 --- a/builtins/help.def +++ b/builtins/help.def @@ -23,112 +23,131 @@ $PRODUCES help.c $BUILTIN help $FUNCTION help_builtin +$DEPENDS_ON HELP_BUILTIN $SHORT_DOC help [pattern ...] Display helpful information about builtin commands. If PATTERN is specified, gives detailed help on all commands matching PATTERN, otherwise a list of the builtins is printed. $END +#include <config.h> + +#if defined (HELP_BUILTIN) #include <stdio.h> + +#if defined (HAVE_UNISTD_H) +# include <unistd.h> +#endif + #include "../shell.h" #include "../builtins.h" +#include "bashgetopt.h" + +#include <glob/fnmatch.h> +#include <glob/glob.h> -#if defined (USE_GLOB_LIBRARY) -# include <glob/glob.h> -#else -# define FNM_NOMATCH 1 -#endif /* USE_GLOB_LIBRARY */ +static void show_builtin_command_help (); /* Print out a list of the known functions in the shell, and what they do. If LIST is supplied, print out the list which matches for each pattern specified. */ +int help_builtin (list) WORD_LIST *list; { - if (!list) - { - register int i, j; - char blurb[256]; + register int i, j; + char *pattern, *name; + int plen, match_found; - show_shell_version (); - printf ( -"Shell commands that are defined internally. Type `help' to see this list.\n\ -Type `help name' to find out more about the function `name'.\n\ -Use `info bash' to find out more about the shell in general.\n\ -\n\ -A star (*) next to a name means that the command is disabled.\n\ -\n"); + if (list == 0) + { + show_shell_version (0); + show_builtin_command_help (); + return (EXECUTION_SUCCESS); + } - for (i = 0; i < num_shell_builtins; i++) + /* Placeholder for future options. */ + reset_internal_getopt (); + while ((i = internal_getopt (list, "")) != -1) + { + switch (i) { - QUIT; - sprintf (blurb, "%c%s", - (shell_builtins[i].flags & BUILTIN_ENABLED) ? ' ' : '*', - shell_builtins[i].short_doc); - - blurb[35] = '\0'; - printf ("%s", blurb); - - if (i % 2) - printf ("\n"); - else - for (j = strlen (blurb); j < 35; j++) - putc (' ', stdout); - + default: + builtin_usage (); + return (EX_USAGE); } - if (i % 2) - printf ("\n"); } - else - { - int match_found = 0; - char *pattern = ""; + list = loptend; - if (glob_pattern_p (list->word->word)) - { - printf ("Shell commands matching keyword%s `", - list->next ? "s" : ""); - print_word_list (list, ", "); - printf ("'\n\n"); - } + /* We should consider making `help bash' do something. */ - while (list) - { - register int i = 0, plen; - char *name; + if (glob_pattern_p (list->word->word)) + { + printf ("Shell commands matching keyword%s `", list->next ? "s" : ""); + print_word_list (list, ", "); + printf ("'\n\n"); + } - pattern = list->word->word; - plen = strlen (pattern); + for (match_found = 0, pattern = ""; list; list = list->next) + { + pattern = list->word->word; + plen = strlen (pattern); - while (name = shell_builtins[i].name) + for (i = 0; name = shell_builtins[i].name; i++) + { + QUIT; + if ((strncmp (pattern, name, plen) == 0) || + (fnmatch (pattern, name, 0) != FNM_NOMATCH)) { - int doc_index; + printf ("%s: %s\n", name, shell_builtins[i].short_doc); - QUIT; - if ((strncmp (pattern, name, plen) == 0) || - (fnmatch (pattern, name, 0) != FNM_NOMATCH)) - { - printf ("%s: %s\n", name, shell_builtins[i].short_doc); + for (j = 0; shell_builtins[i].long_doc[j]; j++) + printf (" %s\n", shell_builtins[i].long_doc[j]); - for (doc_index = 0; - shell_builtins[i].long_doc[doc_index]; doc_index++) - printf (" %s\n", shell_builtins[i].long_doc[doc_index]); - - match_found++; - } - i++; + match_found++; } - list = list->next; } + } - if (!match_found) - { - fprintf (stderr, "No help topics match `%s'. Try `help help'.\n", - pattern); - fflush (stderr); - return (EXECUTION_FAILURE); - } + if (match_found == 0) + { + builtin_error ("no help topics match `%s'. Try `help help'.", pattern); + return (EXECUTION_FAILURE); } + fflush (stdout); return (EXECUTION_SUCCESS); } + +static void +show_builtin_command_help () +{ + int i, j; + char blurb[36]; + + printf ( +"These shell commands are defined internally. Type `help' to see this list.\n\ +Type `help name' to find out more about the function `name'.\n\ +Use `info bash' to find out more about the shell in general.\n\ +\n\ +A star (*) next to a name means that the command is disabled.\n\ +\n"); + + for (i = 0; i < num_shell_builtins; i++) + { + QUIT; + blurb[0] = (shell_builtins[i].flags & BUILTIN_ENABLED) ? ' ' : '*'; + strncpy (blurb + 1, shell_builtins[i].short_doc, 34); + blurb[35] = '\0'; + printf ("%s", blurb); + + if (i % 2) + printf ("\n"); + else + for (j = strlen (blurb); j < 35; j++) + putc (' ', stdout); + } + if (i % 2) + printf ("\n"); +} +#endif /* HELP_BUILTIN */ |