1 /* $NetBSD: ex_usage.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
13 #include <sys/cdefs.h>
16 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 ";
19 __RCSID("$NetBSD: ex_usage.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
22 #include <sys/types.h>
23 #include <sys/queue.h>
26 #include <bitstring.h>
33 #include "../common/common.h"
38 * Display help message.
40 * PUBLIC: int ex_help __P((SCR *, EXCMD *));
43 ex_help(SCR
*sp
, EXCMD
*cmdp
)
46 "To see the list of vi commands, enter \":viusage<CR>\"\n");
48 "To see the list of ex commands, enter \":exusage<CR>\"\n");
50 "For an ex command usage statement enter \":exusage [cmd]<CR>\"\n");
52 "For a vi key usage statement enter \":viusage [key]<CR>\"\n");
53 (void)ex_puts(sp
, "To exit, enter \":q!\"\n");
58 * ex_usage -- :exusage [cmd]
59 * Display ex usage strings.
61 * PUBLIC: int ex_usage __P((SCR *, EXCMD *));
64 ex_usage(SCR
*sp
, EXCMD
*cmdp
)
69 CHAR_T
*p
, nb
[MAXCMDNAMELEN
+ 5];
75 if (ISUPPER((UCHAR_T
)ap
->bp
[0])) {
77 ap
->bp
[0] = TOLOWER((UCHAR_T
)ap
->bp
[0]);
80 for (cp
= cmds
; cp
->name
!= NULL
&&
81 memcmp(ap
->bp
, cp
->name
, ap
->len
); ++cp
);
82 if (cp
->name
== NULL
||
83 (newscreen
&& !F_ISSET(cp
, E_NEWSCREEN
))) {
88 ap
->bp
[0] = TOUPPER((UCHAR_T
)ap
->bp
[0]);
90 INT2CHAR(sp
, ap
->bp
, ap
->len
+ 1, nstr
, nlen
);
91 (void)ex_printf(sp
, "The %.*s command is unknown\n",
95 "Command: %s\n Usage: %s\n", cp
->help
, cp
->usage
);
98 * The "visual" command has two modes, one from ex,
99 * one from the vi colon line. Don't ask.
101 if (cp
!= &cmds
[C_VISUAL_EX
] &&
102 cp
!= &cmds
[C_VISUAL_VI
])
104 if (cp
== &cmds
[C_VISUAL_EX
])
105 cp
= &cmds
[C_VISUAL_VI
];
107 cp
= &cmds
[C_VISUAL_EX
];
109 "Command: %s\n Usage: %s\n", cp
->help
, cp
->usage
);
113 for (cp
= cmds
; cp
->name
!= NULL
&& !INTERRUPTED(sp
); ++cp
) {
115 * The ^D command has an unprintable name.
118 * We display both capital and lower-case versions of
119 * the appropriate commands -- no need to add in extra
120 * room, they're all short names.
122 if (cp
== &cmds
[C_SCROLL
])
124 else if (F_ISSET(cp
, E_NEWSCREEN
)) {
126 nb
[1] = TOUPPER((UCHAR_T
)cp
->name
[0]);
129 for (name
= cp
->name
+ 1,
130 p
= nb
+ 4; (*p
++ = *name
++) != '\0';);
135 WVS
": %s\n", MAXCMDNAMELEN
, name
, cp
->help
);
145 * ex_viusage -- :viusage [key]
146 * Display vi usage strings.
148 * PUBLIC: int ex_viusage __P((SCR *, EXCMD *));
151 ex_viusage(SCR
*sp
, EXCMD
*cmdp
)
156 switch (cmdp
->argc
) {
158 if (cmdp
->argv
[0]->len
!= 1) {
159 ex_emsg(sp
, cmdp
->cmd
->usage
, EXM_USAGE
);
162 key
= cmdp
->argv
[0]->bp
[0];
166 /* Special case: '[' and ']' commands. */
167 if ((key
== '[' || key
== ']') && cmdp
->argv
[0]->bp
[1] != key
)
170 /* Special case: ~ command. */
171 if (key
== '~' && O_ISSET(sp
, O_TILDEOP
))
176 if (kp
->usage
== NULL
)
177 nokey
: (void)ex_printf(sp
,
178 "The %s key has no current meaning\n",
182 " Key:%s%s\nUsage: %s\n",
183 isblank((unsigned char)*kp
->help
) ? "" : " ", kp
->help
, kp
->usage
);
186 for (key
= 0; key
<= MAXVIKEY
&& !INTERRUPTED(sp
); ++key
) {
187 /* Special case: ~ command. */
188 if (key
== '~' && O_ISSET(sp
, O_TILDEOP
))
192 if (kp
->help
!= NULL
)
193 (void)ex_printf(sp
, "%s\n", kp
->help
);