the script used to extract a release
[nvi.git] / ex / ex_usage.c
blobc5afb26c63ec55aa37c8ea2f7cffeb74132b0fdd
1 /*-
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.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: ex_usage.c,v 10.12 1996/05/03 08:58:49 bostic Exp $ (Berkeley) $Date: 1996/05/03 08:58:49 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
20 #include <bitstring.h>
21 #include <ctype.h>
22 #include <limits.h>
23 #include <stdio.h>
24 #include <string.h>
26 #include "../common/common.h"
27 #include "../vi/vi.h"
30 * ex_help -- :help
31 * Display help message.
33 * PUBLIC: int ex_help __P((SCR *, EXCMD *));
35 int
36 ex_help(sp, cmdp)
37 SCR *sp;
38 EXCMD *cmdp;
40 (void)ex_puts(sp,
41 "To see the list of vi commands, enter \":viusage<CR>\"\n");
42 (void)ex_puts(sp,
43 "To see the list of ex commands, enter \":exusage<CR>\"\n");
44 (void)ex_puts(sp,
45 "For an ex command usage statement enter \":exusage [cmd]<CR>\"\n");
46 (void)ex_puts(sp,
47 "For a vi key usage statement enter \":viusage [key]<CR>\"\n");
48 (void)ex_puts(sp, "To exit, enter \":q!\"\n");
49 return (0);
53 * ex_usage -- :exusage [cmd]
54 * Display ex usage strings.
56 * PUBLIC: int ex_usage __P((SCR *, EXCMD *));
58 int
59 ex_usage(sp, cmdp)
60 SCR *sp;
61 EXCMD *cmdp;
63 ARGS *ap;
64 EXCMDLIST const *cp;
65 int newscreen;
66 char *name, *p, nb[MAXCMDNAMELEN + 5];
68 switch (cmdp->argc) {
69 case 1:
70 ap = cmdp->argv[0];
71 if (isupper(ap->bp[0])) {
72 newscreen = 1;
73 ap->bp[0] = tolower(ap->bp[0]);
74 } else
75 newscreen = 0;
76 for (cp = cmds; cp->name != NULL &&
77 memcmp(ap->bp, cp->name, ap->len); ++cp);
78 if (cp->name == NULL ||
79 newscreen && !F_ISSET(cp, E_NEWSCREEN)) {
80 if (newscreen)
81 ap->bp[0] = toupper(ap->bp[0]);
82 (void)ex_printf(sp, "The %.*s command is unknown\n",
83 (int)ap->len, ap->bp);
84 } else {
85 (void)ex_printf(sp,
86 "Command: %s\n Usage: %s\n", cp->help, cp->usage);
88 * !!!
89 * The "visual" command has two modes, one from ex,
90 * one from the vi colon line. Don't ask.
92 if (cp != &cmds[C_VISUAL_EX] &&
93 cp != &cmds[C_VISUAL_VI])
94 break;
95 if (cp == &cmds[C_VISUAL_EX])
96 cp = &cmds[C_VISUAL_VI];
97 else
98 cp = &cmds[C_VISUAL_EX];
99 (void)ex_printf(sp,
100 "Command: %s\n Usage: %s\n", cp->help, cp->usage);
102 break;
103 case 0:
104 for (cp = cmds; cp->name != NULL && !INTERRUPTED(sp); ++cp) {
106 * The ^D command has an unprintable name.
108 * XXX
109 * We display both capital and lower-case versions of
110 * the appropriate commands -- no need to add in extra
111 * room, they're all short names.
113 if (cp == &cmds[C_SCROLL])
114 name = "^D";
115 else if (F_ISSET(cp, E_NEWSCREEN)) {
116 nb[0] = '[';
117 nb[1] = toupper(cp->name[0]);
118 nb[2] = cp->name[0];
119 nb[3] = ']';
120 for (name = cp->name + 1,
121 p = nb + 4; (*p++ = *name++) != '\0';);
122 name = nb;
123 } else
124 name = cp->name;
125 (void)ex_printf(sp,
126 "%*s: %s\n", MAXCMDNAMELEN, name, cp->help);
128 break;
129 default:
130 abort();
132 return (0);
136 * ex_viusage -- :viusage [key]
137 * Display vi usage strings.
139 * PUBLIC: int ex_viusage __P((SCR *, EXCMD *));
142 ex_viusage(sp, cmdp)
143 SCR *sp;
144 EXCMD *cmdp;
146 GS *gp;
147 VIKEYS const *kp;
148 int key;
150 gp = sp->gp;
151 switch (cmdp->argc) {
152 case 1:
153 if (cmdp->argv[0]->len != 1) {
154 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
155 return (1);
157 key = cmdp->argv[0]->bp[0];
158 if (key > MAXVIKEY)
159 goto nokey;
161 /* Special case: '[' and ']' commands. */
162 if ((key == '[' || key == ']') && cmdp->argv[0]->bp[1] != key)
163 goto nokey;
165 /* Special case: ~ command. */
166 if (key == '~' && O_ISSET(sp, O_TILDEOP))
167 kp = &tmotion;
168 else
169 kp = &vikeys[key];
171 if (kp->usage == NULL)
172 nokey: (void)ex_printf(sp,
173 "The %s key has no current meaning\n",
174 KEY_NAME(sp, key));
175 else
176 (void)ex_printf(sp,
177 " Key:%s%s\nUsage: %s\n",
178 isblank(*kp->help) ? "" : " ", kp->help, kp->usage);
179 break;
180 case 0:
181 for (key = 0; key <= MAXVIKEY && !INTERRUPTED(sp); ++key) {
182 /* Special case: ~ command. */
183 if (key == '~' && O_ISSET(sp, O_TILDEOP))
184 kp = &tmotion;
185 else
186 kp = &vikeys[key];
187 if (kp->help != NULL)
188 (void)ex_printf(sp, "%s\n", kp->help);
190 break;
191 default:
192 abort();
194 return (0);