Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / nvi / ex / ex_usage.c
blob2e2514d7cd29737c19876c09d24a6ab7e39d6d39
1 /* $NetBSD: ex_usage.c,v 1.3 2009/11/14 23:40:11 christos Exp $ */
3 /*-
4 * Copyright (c) 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1992, 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
12 #include "config.h"
14 #ifndef lint
15 static const char sccsid[] = "Id: ex_usage.c,v 10.15 2001/06/25 15:19:21 skimo Exp (Berkeley) Date: 2001/06/25 15:19:21";
16 #endif /* not lint */
18 #include <sys/types.h>
19 #include <sys/queue.h>
20 #include <sys/time.h>
22 #include <bitstring.h>
23 #include <ctype.h>
24 #include <limits.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
29 #include "../common/common.h"
30 #include "../vi/vi.h"
33 * ex_help -- :help
34 * Display help message.
36 * PUBLIC: int ex_help __P((SCR *, EXCMD *));
38 int
39 ex_help(SCR *sp, EXCMD *cmdp)
41 (void)ex_puts(sp,
42 "To see the list of vi commands, enter \":viusage<CR>\"\n");
43 (void)ex_puts(sp,
44 "To see the list of ex commands, enter \":exusage<CR>\"\n");
45 (void)ex_puts(sp,
46 "For an ex command usage statement enter \":exusage [cmd]<CR>\"\n");
47 (void)ex_puts(sp,
48 "For a vi key usage statement enter \":viusage [key]<CR>\"\n");
49 (void)ex_puts(sp, "To exit, enter \":q!\"\n");
50 return (0);
54 * ex_usage -- :exusage [cmd]
55 * Display ex usage strings.
57 * PUBLIC: int ex_usage __P((SCR *, EXCMD *));
59 int
60 ex_usage(SCR *sp, EXCMD *cmdp)
62 ARGS *ap;
63 EXCMDLIST const *cp;
64 int newscreen;
65 CHAR_T *p, nb[MAXCMDNAMELEN + 5];
66 const CHAR_T *name;
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 const char *nstr;
81 size_t nlen;
83 if (newscreen)
84 ap->bp[0] = TOUPPER(ap->bp[0]);
86 INT2CHAR(sp, ap->bp, ap->len + 1, nstr, nlen);
87 (void)ex_printf(sp, "The %.*s command is unknown\n",
88 (int)ap->len, nstr);
89 } else {
90 (void)ex_printf(sp,
91 "Command: %s\n Usage: %s\n", cp->help, cp->usage);
93 * !!!
94 * The "visual" command has two modes, one from ex,
95 * one from the vi colon line. Don't ask.
97 if (cp != &cmds[C_VISUAL_EX] &&
98 cp != &cmds[C_VISUAL_VI])
99 break;
100 if (cp == &cmds[C_VISUAL_EX])
101 cp = &cmds[C_VISUAL_VI];
102 else
103 cp = &cmds[C_VISUAL_EX];
104 (void)ex_printf(sp,
105 "Command: %s\n Usage: %s\n", cp->help, cp->usage);
107 break;
108 case 0:
109 for (cp = cmds; cp->name != NULL && !INTERRUPTED(sp); ++cp) {
111 * The ^D command has an unprintable name.
113 * XXX
114 * We display both capital and lower-case versions of
115 * the appropriate commands -- no need to add in extra
116 * room, they're all short names.
118 if (cp == &cmds[C_SCROLL])
119 name = L("^D");
120 else if (F_ISSET(cp, E_NEWSCREEN)) {
121 nb[0] = L('[');
122 nb[1] = TOUPPER(cp->name[0]);
123 nb[2] = cp->name[0];
124 nb[3] = L(']');
125 for (name = cp->name + 1,
126 p = nb + 4; (*p++ = *name++) != '\0';);
127 name = nb;
128 } else
129 name = cp->name;
130 (void)ex_printf(sp,
131 WVS": %s\n", MAXCMDNAMELEN, name, cp->help);
133 break;
134 default:
135 abort();
137 return (0);
141 * ex_viusage -- :viusage [key]
142 * Display vi usage strings.
144 * PUBLIC: int ex_viusage __P((SCR *, EXCMD *));
147 ex_viusage(SCR *sp, EXCMD *cmdp)
149 GS *gp;
150 VIKEYS const *kp;
151 int key;
153 gp = sp->gp;
154 switch (cmdp->argc) {
155 case 1:
156 if (cmdp->argv[0]->len != 1) {
157 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
158 return (1);
160 key = cmdp->argv[0]->bp[0];
161 if (key > MAXVIKEY)
162 goto nokey;
164 /* Special case: '[' and ']' commands. */
165 if ((key == '[' || key == ']') && cmdp->argv[0]->bp[1] != key)
166 goto nokey;
168 /* Special case: ~ command. */
169 if (key == '~' && O_ISSET(sp, O_TILDEOP))
170 kp = &tmotion;
171 else
172 kp = &vikeys[key];
174 if (kp->usage == NULL)
175 nokey: (void)ex_printf(sp,
176 "The %s key has no current meaning\n",
177 KEY_NAME(sp, key));
178 else
179 (void)ex_printf(sp,
180 " Key:%s%s\nUsage: %s\n",
181 isblank(*kp->help) ? "" : " ", kp->help, kp->usage);
182 break;
183 case 0:
184 for (key = 0; key <= MAXVIKEY && !INTERRUPTED(sp); ++key) {
185 /* Special case: ~ command. */
186 if (key == '~' && O_ISSET(sp, O_TILDEOP))
187 kp = &tmotion;
188 else
189 kp = &vikeys[key];
190 if (kp->help != NULL)
191 (void)ex_printf(sp, "%s\n", kp->help);
193 break;
194 default:
195 abort();
197 return (0);