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.12 1996/05/03 08:58:49 bostic Exp $ (Berkeley) $Date: 1996/05/03 08:58:49 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
26 #include "../common/common.h"
31 * Display help message.
33 * PUBLIC: int ex_help __P((SCR *, EXCMD *));
41 "To see the list of vi commands, enter \":viusage<CR>\"\n");
43 "To see the list of ex commands, enter \":exusage<CR>\"\n");
45 "For an ex command usage statement enter \":exusage [cmd]<CR>\"\n");
47 "For a vi key usage statement enter \":viusage [key]<CR>\"\n");
48 (void)ex_puts(sp
, "To exit, enter \":q!\"\n");
53 * ex_usage -- :exusage [cmd]
54 * Display ex usage strings.
56 * PUBLIC: int ex_usage __P((SCR *, EXCMD *));
66 char *name
, *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
)) {
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
);
86 "Command: %s\n Usage: %s\n", cp
->help
, cp
->usage
);
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
])
95 if (cp
== &cmds
[C_VISUAL_EX
])
96 cp
= &cmds
[C_VISUAL_VI
];
98 cp
= &cmds
[C_VISUAL_EX
];
100 "Command: %s\n Usage: %s\n", cp
->help
, cp
->usage
);
104 for (cp
= cmds
; cp
->name
!= NULL
&& !INTERRUPTED(sp
); ++cp
) {
106 * The ^D command has an unprintable name.
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
])
115 else if (F_ISSET(cp
, E_NEWSCREEN
)) {
117 nb
[1] = toupper(cp
->name
[0]);
120 for (name
= cp
->name
+ 1,
121 p
= nb
+ 4; (*p
++ = *name
++) != '\0';);
126 "%*s: %s\n", MAXCMDNAMELEN
, name
, cp
->help
);
136 * ex_viusage -- :viusage [key]
137 * Display vi usage strings.
139 * PUBLIC: int ex_viusage __P((SCR *, EXCMD *));
151 switch (cmdp
->argc
) {
153 if (cmdp
->argv
[0]->len
!= 1) {
154 ex_emsg(sp
, cmdp
->cmd
->usage
, EXM_USAGE
);
157 key
= cmdp
->argv
[0]->bp
[0];
161 /* Special case: '[' and ']' commands. */
162 if ((key
== '[' || key
== ']') && cmdp
->argv
[0]->bp
[1] != key
)
165 /* Special case: ~ command. */
166 if (key
== '~' && O_ISSET(sp
, O_TILDEOP
))
171 if (kp
->usage
== NULL
)
172 nokey
: (void)ex_printf(sp
,
173 "The %s key has no current meaning\n",
177 " Key:%s%s\nUsage: %s\n",
178 isblank(*kp
->help
) ? "" : " ", kp
->help
, kp
->usage
);
181 for (key
= 0; key
<= MAXVIKEY
&& !INTERRUPTED(sp
); ++key
) {
182 /* Special case: ~ command. */
183 if (key
== '~' && O_ISSET(sp
, O_TILDEOP
))
187 if (kp
->help
!= NULL
)
188 (void)ex_printf(sp
, "%s\n", kp
->help
);