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[] = "$Id: ex_usage.c,v 10.16 2011/12/21 19:26:48 zy Exp $";
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 *));
37 ex_help(SCR *sp, EXCMD *cmdp)
40 "To see the list of vi commands, enter \":viusage<CR>\"\n");
42 "To see the list of ex commands, enter \":exusage<CR>\"\n");
44 "For an ex command usage statement enter \":exusage [cmd]<CR>\"\n");
46 "For a vi key usage statement enter \":viusage [key]<CR>\"\n");
47 (void)ex_puts(sp, "To exit, enter \":q!\"\n");
52 * ex_usage -- :exusage [cmd]
53 * Display ex usage strings.
55 * PUBLIC: int ex_usage __P((SCR *, EXCMD *));
58 ex_usage(SCR *sp, EXCMD *cmdp)
63 CHAR_T *name, *p, nb[MAXCMDNAMELEN + 5];
68 if (ISUPPER(ap->bp[0])) {
70 ap->bp[0] = TOLOWER(ap->bp[0]);
73 for (cp = cmds; cp->name != NULL &&
74 MEMCMP(ap->bp, cp->name, ap->len); ++cp);
75 if (cp->name == NULL ||
76 (newscreen && !F_ISSET(cp, E_NEWSCREEN))) {
78 ap->bp[0] = TOUPPER(ap->bp[0]);
79 (void)ex_printf(sp, "The "WVS" command is unknown\n",
80 (int)ap->len, ap->bp);
83 "Command: %s\n Usage: %s\n", cp->help, cp->usage);
86 * The "visual" command has two modes, one from ex,
87 * one from the vi colon line. Don't ask.
89 if (cp != &cmds[C_VISUAL_EX] &&
90 cp != &cmds[C_VISUAL_VI])
92 if (cp == &cmds[C_VISUAL_EX])
93 cp = &cmds[C_VISUAL_VI];
95 cp = &cmds[C_VISUAL_EX];
97 "Command: %s\n Usage: %s\n", cp->help, cp->usage);
101 for (cp = cmds; cp->name != NULL && !INTERRUPTED(sp); ++cp) {
103 * The ^D command has an unprintable name.
106 * We display both capital and lower-case versions of
107 * the appropriate commands -- no need to add in extra
108 * room, they're all short names.
110 if (cp == &cmds[C_SCROLL])
112 else if (F_ISSET(cp, E_NEWSCREEN)) {
114 nb[1] = TOUPPER(cp->name[0]);
117 for (name = cp->name + 1,
118 p = nb + 4; (*p++ = *name++) != '\0';);
123 WVS": %s\n", MAXCMDNAMELEN, name, cp->help);
133 * ex_viusage -- :viusage [key]
134 * Display vi usage strings.
136 * PUBLIC: int ex_viusage __P((SCR *, EXCMD *));
139 ex_viusage(SCR *sp, EXCMD *cmdp)
146 switch (cmdp->argc) {
148 if (cmdp->argv[0]->len != 1) {
149 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
152 key = cmdp->argv[0]->bp[0];
156 /* Special case: '[' and ']' commands. */
157 if ((key == '[' || key == ']') && cmdp->argv[0]->bp[1] != key)
160 /* Special case: ~ command. */
161 if (key == '~' && O_ISSET(sp, O_TILDEOP))
166 if (kp->usage == NULL)
167 nokey: (void)ex_printf(sp,
168 "The %s key has no current meaning\n",
172 " Key:%s%s\nUsage: %s\n",
173 isblank(*kp->help) ? "" : " ", kp->help, kp->usage);
176 for (key = 0; key <= MAXVIKEY && !INTERRUPTED(sp); ++key) {
177 /* Special case: ~ command. */
178 if (key == '~' && O_ISSET(sp, O_TILDEOP))
182 if (kp->help != NULL)
183 (void)ex_printf(sp, "%s\n", kp->help);