1 /* $NetBSD: ex_usage.c,v 1.3 2009/11/14 23:40:11 christos Exp $ */
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.
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";
18 #include <sys/types.h>
19 #include <sys/queue.h>
22 #include <bitstring.h>
29 #include "../common/common.h"
34 * Display help message.
36 * PUBLIC: int ex_help __P((SCR *, EXCMD *));
39 ex_help(SCR
*sp
, EXCMD
*cmdp
)
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 *));
60 ex_usage(SCR
*sp
, EXCMD
*cmdp
)
65 CHAR_T
*p
, nb
[MAXCMDNAMELEN
+ 5];
71 if (ISUPPER(ap
->bp
[0])) {
73 ap
->bp
[0] = TOLOWER(ap
->bp
[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
))) {
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",
91 "Command: %s\n Usage: %s\n", cp
->help
, cp
->usage
);
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
])
100 if (cp
== &cmds
[C_VISUAL_EX
])
101 cp
= &cmds
[C_VISUAL_VI
];
103 cp
= &cmds
[C_VISUAL_EX
];
105 "Command: %s\n Usage: %s\n", cp
->help
, cp
->usage
);
109 for (cp
= cmds
; cp
->name
!= NULL
&& !INTERRUPTED(sp
); ++cp
) {
111 * The ^D command has an unprintable name.
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
])
120 else if (F_ISSET(cp
, E_NEWSCREEN
)) {
122 nb
[1] = TOUPPER(cp
->name
[0]);
125 for (name
= cp
->name
+ 1,
126 p
= nb
+ 4; (*p
++ = *name
++) != '\0';);
131 WVS
": %s\n", MAXCMDNAMELEN
, name
, cp
->help
);
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
)
154 switch (cmdp
->argc
) {
156 if (cmdp
->argv
[0]->len
!= 1) {
157 ex_emsg(sp
, cmdp
->cmd
->usage
, EXM_USAGE
);
160 key
= cmdp
->argv
[0]->bp
[0];
164 /* Special case: '[' and ']' commands. */
165 if ((key
== '[' || key
== ']') && cmdp
->argv
[0]->bp
[1] != key
)
168 /* Special case: ~ command. */
169 if (key
== '~' && O_ISSET(sp
, O_TILDEOP
))
174 if (kp
->usage
== NULL
)
175 nokey
: (void)ex_printf(sp
,
176 "The %s key has no current meaning\n",
180 " Key:%s%s\nUsage: %s\n",
181 isblank(*kp
->help
) ? "" : " ", kp
->help
, kp
->usage
);
184 for (key
= 0; key
<= MAXVIKEY
&& !INTERRUPTED(sp
); ++key
) {
185 /* Special case: ~ command. */
186 if (key
== '~' && O_ISSET(sp
, O_TILDEOP
))
190 if (kp
->help
!= NULL
)
191 (void)ex_printf(sp
, "%s\n", kp
->help
);