2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid[] = "@(#)ex_usage.c 10.13 (Berkeley) 5/3/96";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
27 #include "../common/common.h"
32 * Display help message.
34 * PUBLIC: int ex_help __P((SCR *, EXCMD *));
42 "To see the list of vi commands, enter \":viusage<CR>\"\n");
44 "To see the list of ex commands, enter \":exusage<CR>\"\n");
46 "For an ex command usage statement enter \":exusage [cmd]<CR>\"\n");
48 "For a vi key usage statement enter \":viusage [key]<CR>\"\n");
49 (void)ex_puts(sp, "To exit, enter \":q!\"\n");
54 * ex_usage -- :exusage [cmd]
55 * Display ex usage strings.
57 * PUBLIC: int ex_usage __P((SCR *, EXCMD *));
67 char *name, *p, nb[MAXCMDNAMELEN + 5];
72 if (isupper(ap->bp[0])) {
74 ap->bp[0] = tolower(ap->bp[0]);
77 for (cp = cmds; cp->name != NULL &&
78 memcmp(ap->bp, cp->name, ap->len); ++cp);
79 if (cp->name == NULL ||
80 newscreen && !F_ISSET(cp, E_NEWSCREEN)) {
82 ap->bp[0] = toupper(ap->bp[0]);
83 (void)ex_printf(sp, "The %.*s command is unknown\n",
84 (int)ap->len, ap->bp);
87 "Command: %s\n Usage: %s\n", cp->help, cp->usage);
90 * The "visual" command has two modes, one from ex,
91 * one from the vi colon line. Don't ask.
93 if (cp != &cmds[C_VISUAL_EX] &&
94 cp != &cmds[C_VISUAL_VI])
96 if (cp == &cmds[C_VISUAL_EX])
97 cp = &cmds[C_VISUAL_VI];
99 cp = &cmds[C_VISUAL_EX];
101 "Command: %s\n Usage: %s\n", cp->help, cp->usage);
105 for (cp = cmds; cp->name != NULL && !INTERRUPTED(sp); ++cp) {
107 * The ^D command has an unprintable name.
110 * We display both capital and lower-case versions of
111 * the appropriate commands -- no need to add in extra
112 * room, they're all short names.
114 if (cp == &cmds[C_SCROLL])
116 else if (F_ISSET(cp, E_NEWSCREEN)) {
118 nb[1] = toupper(cp->name[0]);
121 for (name = cp->name + 1,
122 p = nb + 4; (*p++ = *name++) != '\0';);
127 "%*s: %s\n", MAXCMDNAMELEN, name, cp->help);
137 * ex_viusage -- :viusage [key]
138 * Display vi usage strings.
140 * PUBLIC: int ex_viusage __P((SCR *, EXCMD *));
152 switch (cmdp->argc) {
154 if (cmdp->argv[0]->len != 1) {
155 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
158 key = cmdp->argv[0]->bp[0];
162 /* Special case: '[' and ']' commands. */
163 if ((key == '[' || key == ']') && cmdp->argv[0]->bp[1] != key)
166 /* Special case: ~ command. */
167 if (key == '~' && O_ISSET(sp, O_TILDEOP))
172 if (kp->usage == NULL)
173 nokey: (void)ex_printf(sp,
174 "The %s key has no current meaning\n",
178 " Key:%s%s\nUsage: %s\n",
179 isblank(*kp->help) ? "" : " ", kp->help, kp->usage);
182 for (key = 0; key <= MAXVIKEY && !INTERRUPTED(sp); ++key) {
183 /* Special case: ~ command. */
184 if (key == '~' && O_ISSET(sp, O_TILDEOP))
188 if (kp->help != NULL)
189 (void)ex_printf(sp, "%s\n", kp->help);