summaryrefslogtreecommitdiff
path: root/usr.bin/vi/ex/ex_usage.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-05-22 11:37:15 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-05-22 11:37:15 +0000
commit0157a77a51c5e35e093ae03581f66dea010edcc8 (patch)
tree5e8bd32aa4d2b5ed37b7cf3ad26e8bdfc7f20a04 /usr.bin/vi/ex/ex_usage.c
parent806021be093ad00ce2022a532c0f4cc99b0065ac (diff)
new vi
Diffstat (limited to 'usr.bin/vi/ex/ex_usage.c')
-rw-r--r--usr.bin/vi/ex/ex_usage.c141
1 files changed, 70 insertions, 71 deletions
diff --git a/usr.bin/vi/ex/ex_usage.c b/usr.bin/vi/ex/ex_usage.c
index 424b79bb5a4..cddf7a6643c 100644
--- a/usr.bin/vi/ex/ex_usage.c
+++ b/usr.bin/vi/ex/ex_usage.c
@@ -1,38 +1,16 @@
/*-
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1992, 1993, 1994, 1995, 1996
+ * Keith Bostic. All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * See the LICENSE file for redistribution information.
*/
+#include "config.h"
+
#ifndef lint
-static char sccsid[] = "@(#)ex_usage.c 8.21 (Berkeley) 8/17/94";
+static const char sccsid[] = "@(#)ex_usage.c 10.13 (Berkeley) 5/3/96";
#endif /* not lint */
#include <sys/types.h>
@@ -40,67 +18,72 @@ static char sccsid[] = "@(#)ex_usage.c 8.21 (Berkeley) 8/17/94";
#include <sys/time.h>
#include <bitstring.h>
+#include <ctype.h>
#include <limits.h>
-#include <signal.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-#include "vi.h"
-#include "excmd.h"
-#include "../vi/vcmd.h"
+#include "../common/common.h"
+#include "../vi/vi.h"
/*
* ex_help -- :help
* Display help message.
+ *
+ * PUBLIC: int ex_help __P((SCR *, EXCMD *));
*/
int
-ex_help(sp, ep, cmdp)
+ex_help(sp, cmdp)
SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
+ EXCMD *cmdp;
{
- (void)ex_printf(EXCOOKIE,
+ (void)ex_puts(sp,
"To see the list of vi commands, enter \":viusage<CR>\"\n");
- (void)ex_printf(EXCOOKIE,
+ (void)ex_puts(sp,
"To see the list of ex commands, enter \":exusage<CR>\"\n");
- (void)ex_printf(EXCOOKIE,
+ (void)ex_puts(sp,
"For an ex command usage statement enter \":exusage [cmd]<CR>\"\n");
- (void)ex_printf(EXCOOKIE,
+ (void)ex_puts(sp,
"For a vi key usage statement enter \":viusage [key]<CR>\"\n");
- (void)ex_printf(EXCOOKIE, "To exit, enter \":q!\"\n");
+ (void)ex_puts(sp, "To exit, enter \":q!\"\n");
return (0);
}
/*
* ex_usage -- :exusage [cmd]
* Display ex usage strings.
+ *
+ * PUBLIC: int ex_usage __P((SCR *, EXCMD *));
*/
int
-ex_usage(sp, ep, cmdp)
+ex_usage(sp, cmdp)
SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
+ EXCMD *cmdp;
{
ARGS *ap;
EXCMDLIST const *cp;
- char *name;
+ int newscreen;
+ char *name, *p, nb[MAXCMDNAMELEN + 5];
switch (cmdp->argc) {
case 1:
ap = cmdp->argv[0];
+ if (isupper(ap->bp[0])) {
+ newscreen = 1;
+ ap->bp[0] = tolower(ap->bp[0]);
+ } else
+ newscreen = 0;
for (cp = cmds; cp->name != NULL &&
memcmp(ap->bp, cp->name, ap->len); ++cp);
- if (cp->name == NULL)
- (void)ex_printf(EXCOOKIE,
- "The %.*s command is unknown",
+ if (cp->name == NULL ||
+ newscreen && !F_ISSET(cp, E_NEWSCREEN)) {
+ if (newscreen)
+ ap->bp[0] = toupper(ap->bp[0]);
+ (void)ex_printf(sp, "The %.*s command is unknown\n",
(int)ap->len, ap->bp);
- else {
- (void)ex_printf(EXCOOKIE,
+ } else {
+ (void)ex_printf(sp,
"Command: %s\n Usage: %s\n", cp->help, cp->usage);
/*
* !!!
@@ -114,19 +97,33 @@ ex_usage(sp, ep, cmdp)
cp = &cmds[C_VISUAL_VI];
else
cp = &cmds[C_VISUAL_EX];
- (void)ex_printf(EXCOOKIE,
+ (void)ex_printf(sp,
"Command: %s\n Usage: %s\n", cp->help, cp->usage);
}
break;
case 0:
- F_SET(sp, S_INTERRUPTIBLE);
- for (cp = cmds; cp->name != NULL; ++cp) {
- /* The ^D command has an unprintable name. */
+ for (cp = cmds; cp->name != NULL && !INTERRUPTED(sp); ++cp) {
+ /*
+ * The ^D command has an unprintable name.
+ *
+ * XXX
+ * We display both capital and lower-case versions of
+ * the appropriate commands -- no need to add in extra
+ * room, they're all short names.
+ */
if (cp == &cmds[C_SCROLL])
name = "^D";
- else
+ else if (F_ISSET(cp, E_NEWSCREEN)) {
+ nb[0] = '[';
+ nb[1] = toupper(cp->name[0]);
+ nb[2] = cp->name[0];
+ nb[3] = ']';
+ for (name = cp->name + 1,
+ p = nb + 4; (*p++ = *name++) != '\0';);
+ name = nb;
+ } else
name = cp->name;
- (void)ex_printf(EXCOOKIE,
+ (void)ex_printf(sp,
"%*s: %s\n", MAXCMDNAMELEN, name, cp->help);
}
break;
@@ -139,20 +136,23 @@ ex_usage(sp, ep, cmdp)
/*
* ex_viusage -- :viusage [key]
* Display vi usage strings.
+ *
+ * PUBLIC: int ex_viusage __P((SCR *, EXCMD *));
*/
int
-ex_viusage(sp, ep, cmdp)
+ex_viusage(sp, cmdp)
SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
+ EXCMD *cmdp;
{
+ GS *gp;
VIKEYS const *kp;
int key;
+ gp = sp->gp;
switch (cmdp->argc) {
case 1:
if (cmdp->argv[0]->len != 1) {
- msgq(sp, M_ERR, "Usage: %s", cmdp->cmd->usage);
+ ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
return (1);
}
key = cmdp->argv[0]->bp[0];
@@ -169,25 +169,24 @@ ex_viusage(sp, ep, cmdp)
else
kp = &vikeys[key];
- if (kp->func == NULL)
-nokey: (void)ex_printf(EXCOOKIE,
- "The %s key has no current meaning",
+ if (kp->usage == NULL)
+nokey: (void)ex_printf(sp,
+ "The %s key has no current meaning\n",
KEY_NAME(sp, key));
else
- (void)ex_printf(EXCOOKIE,
+ (void)ex_printf(sp,
" Key:%s%s\nUsage: %s\n",
isblank(*kp->help) ? "" : " ", kp->help, kp->usage);
break;
case 0:
- F_SET(sp, S_INTERRUPTIBLE);
- for (key = 0; key <= MAXVIKEY; ++key) {
+ for (key = 0; key <= MAXVIKEY && !INTERRUPTED(sp); ++key) {
/* Special case: ~ command. */
if (key == '~' && O_ISSET(sp, O_TILDEOP))
kp = &tmotion;
else
kp = &vikeys[key];
if (kp->help != NULL)
- (void)ex_printf(EXCOOKIE, "%s\n", kp->help);
+ (void)ex_printf(sp, "%s\n", kp->help);
}
break;
default: