aboutsummaryrefslogtreecommitdiffstats
path: root/builtins/help.def
diff options
context:
space:
mode:
Diffstat (limited to 'builtins/help.def')
-rw-r--r--builtins/help.def134
1 files changed, 134 insertions, 0 deletions
diff --git a/builtins/help.def b/builtins/help.def
new file mode 100644
index 0000000..c9f1db8
--- /dev/null
+++ b/builtins/help.def
@@ -0,0 +1,134 @@
+This file is help.def, from which is created help.c.
+It implements the builtin "help" in Bash.
+
+Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
+
+This file is part of GNU Bash, the Bourne Again SHell.
+
+Bash is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 1, or (at your option) any later
+version.
+
+Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License along
+with Bash; see the file COPYING. If not, write to the Free Software
+Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+$PRODUCES help.c
+
+$BUILTIN help
+$FUNCTION 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 <stdio.h>
+#include "../shell.h"
+#include "../builtins.h"
+
+#if defined (USE_GLOB_LIBRARY)
+# include <glob/glob.h>
+#else
+# define FNM_NOMATCH 1
+#endif /* USE_GLOB_LIBRARY */
+
+/* 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. */
+help_builtin (list)
+ WORD_LIST *list;
+{
+ if (!list)
+ {
+ register int i, j;
+ char blurb[256];
+
+ 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");
+
+ for (i = 0; i < num_shell_builtins; 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);
+
+ }
+ if (i % 2)
+ printf ("\n");
+ }
+ else
+ {
+ int match_found = 0;
+ char *pattern = "";
+
+ if (glob_pattern_p (list->word->word))
+ {
+ printf ("Shell commands matching keyword%s `",
+ list->next ? "s" : "");
+ print_word_list (list, ", ");
+ printf ("'\n\n");
+ }
+
+ while (list)
+ {
+ register int i = 0, plen;
+ char *name;
+
+ pattern = list->word->word;
+ plen = strlen (pattern);
+
+ while (name = shell_builtins[i].name)
+ {
+ int doc_index;
+
+ QUIT;
+ if ((strncmp (pattern, name, plen) == 0) ||
+ (fnmatch (pattern, name, 0) != FNM_NOMATCH))
+ {
+ printf ("%s: %s\n", name, shell_builtins[i].short_doc);
+
+ 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++;
+ }
+ list = list->next;
+ }
+
+ if (!match_found)
+ {
+ fprintf (stderr, "No help topics match `%s'. Try `help help'.\n",
+ pattern);
+ fflush (stderr);
+ return (EXECUTION_FAILURE);
+ }
+ }
+ fflush (stdout);
+ return (EXECUTION_SUCCESS);
+}