1998-01-09 11:03:16 +03:00
|
|
|
/* $NetBSD: ex_usage.c,v 1.7 1998/01/09 08:08:09 perry Exp $ */
|
|
|
|
|
1994-01-24 08:52:58 +03:00
|
|
|
/*-
|
1994-03-28 08:28:20 +04:00
|
|
|
* Copyright (c) 1992, 1993, 1994
|
1994-01-24 08:52:58 +03:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
1996-05-20 07:47:00 +04:00
|
|
|
* Copyright (c) 1992, 1993, 1994, 1995, 1996
|
|
|
|
* Keith Bostic. All rights reserved.
|
1994-01-24 08:52:58 +03:00
|
|
|
*
|
1996-05-20 07:47:00 +04:00
|
|
|
* See the LICENSE file for redistribution information.
|
1994-01-24 08:52:58 +03:00
|
|
|
*/
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
1994-01-24 08:52:58 +03:00
|
|
|
#ifndef lint
|
1996-05-20 07:47:00 +04:00
|
|
|
static const char sccsid[] = "@(#)ex_usage.c 10.13 (Berkeley) 5/3/96";
|
1994-01-24 08:52:58 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
1994-03-28 08:28:20 +04:00
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <bitstring.h>
|
1996-05-20 07:47:00 +04:00
|
|
|
#include <ctype.h>
|
1994-03-28 08:28:20 +04:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
1996-05-20 07:47:00 +04:00
|
|
|
#include <stdlib.h>
|
1994-01-24 08:52:58 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
#include "../common/common.h"
|
|
|
|
#include "../vi/vi.h"
|
1994-01-24 08:52:58 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ex_help -- :help
|
|
|
|
* Display help message.
|
1996-05-20 07:47:00 +04:00
|
|
|
*
|
|
|
|
* PUBLIC: int ex_help __P((SCR *, EXCMD *));
|
1994-01-24 08:52:58 +03:00
|
|
|
*/
|
|
|
|
int
|
1996-05-20 07:47:00 +04:00
|
|
|
ex_help(sp, cmdp)
|
1994-01-24 08:52:58 +03:00
|
|
|
SCR *sp;
|
1996-05-20 07:47:00 +04:00
|
|
|
EXCMD *cmdp;
|
1994-01-24 08:52:58 +03:00
|
|
|
{
|
1996-05-20 07:47:00 +04:00
|
|
|
(void)ex_puts(sp,
|
1994-01-24 08:52:58 +03:00
|
|
|
"To see the list of vi commands, enter \":viusage<CR>\"\n");
|
1996-05-20 07:47:00 +04:00
|
|
|
(void)ex_puts(sp,
|
1994-01-24 08:52:58 +03:00
|
|
|
"To see the list of ex commands, enter \":exusage<CR>\"\n");
|
1996-05-20 07:47:00 +04:00
|
|
|
(void)ex_puts(sp,
|
1994-01-24 08:52:58 +03:00
|
|
|
"For an ex command usage statement enter \":exusage [cmd]<CR>\"\n");
|
1996-05-20 07:47:00 +04:00
|
|
|
(void)ex_puts(sp,
|
1994-01-24 08:52:58 +03:00
|
|
|
"For a vi key usage statement enter \":viusage [key]<CR>\"\n");
|
1996-05-20 07:47:00 +04:00
|
|
|
(void)ex_puts(sp, "To exit, enter \":q!\"\n");
|
1994-01-24 08:52:58 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ex_usage -- :exusage [cmd]
|
|
|
|
* Display ex usage strings.
|
1996-05-20 07:47:00 +04:00
|
|
|
*
|
|
|
|
* PUBLIC: int ex_usage __P((SCR *, EXCMD *));
|
1994-01-24 08:52:58 +03:00
|
|
|
*/
|
|
|
|
int
|
1996-05-20 07:47:00 +04:00
|
|
|
ex_usage(sp, cmdp)
|
1994-01-24 08:52:58 +03:00
|
|
|
SCR *sp;
|
1996-05-20 07:47:00 +04:00
|
|
|
EXCMD *cmdp;
|
1994-01-24 08:52:58 +03:00
|
|
|
{
|
|
|
|
ARGS *ap;
|
|
|
|
EXCMDLIST const *cp;
|
1996-05-20 07:47:00 +04:00
|
|
|
int newscreen;
|
|
|
|
char *name, *p, nb[MAXCMDNAMELEN + 5];
|
1994-03-28 08:28:20 +04:00
|
|
|
|
1994-01-24 08:52:58 +03:00
|
|
|
switch (cmdp->argc) {
|
|
|
|
case 1:
|
|
|
|
ap = cmdp->argv[0];
|
1996-05-20 07:47:00 +04:00
|
|
|
if (isupper(ap->bp[0])) {
|
|
|
|
newscreen = 1;
|
|
|
|
ap->bp[0] = tolower(ap->bp[0]);
|
|
|
|
} else
|
|
|
|
newscreen = 0;
|
1994-01-24 08:52:58 +03:00
|
|
|
for (cp = cmds; cp->name != NULL &&
|
|
|
|
memcmp(ap->bp, cp->name, ap->len); ++cp);
|
1996-05-20 07:47:00 +04:00
|
|
|
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",
|
1994-01-24 08:52:58 +03:00
|
|
|
(int)ap->len, ap->bp);
|
1996-05-20 07:47:00 +04:00
|
|
|
} else {
|
|
|
|
(void)ex_printf(sp,
|
1994-01-24 08:52:58 +03:00
|
|
|
"Command: %s\n Usage: %s\n", cp->help, cp->usage);
|
|
|
|
/*
|
|
|
|
* !!!
|
|
|
|
* The "visual" command has two modes, one from ex,
|
|
|
|
* one from the vi colon line. Don't ask.
|
|
|
|
*/
|
|
|
|
if (cp != &cmds[C_VISUAL_EX] &&
|
|
|
|
cp != &cmds[C_VISUAL_VI])
|
|
|
|
break;
|
|
|
|
if (cp == &cmds[C_VISUAL_EX])
|
|
|
|
cp = &cmds[C_VISUAL_VI];
|
|
|
|
else
|
|
|
|
cp = &cmds[C_VISUAL_EX];
|
1996-05-20 07:47:00 +04:00
|
|
|
(void)ex_printf(sp,
|
1994-01-24 08:52:58 +03:00
|
|
|
"Command: %s\n Usage: %s\n", cp->help, cp->usage);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0:
|
1996-05-20 07:47:00 +04:00
|
|
|
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.
|
|
|
|
*/
|
1994-03-28 08:28:20 +04:00
|
|
|
if (cp == &cmds[C_SCROLL])
|
|
|
|
name = "^D";
|
1996-05-20 07:47:00 +04:00
|
|
|
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
|
1994-03-28 08:28:20 +04:00
|
|
|
name = cp->name;
|
1996-05-20 07:47:00 +04:00
|
|
|
(void)ex_printf(sp,
|
1994-03-28 08:28:20 +04:00
|
|
|
"%*s: %s\n", MAXCMDNAMELEN, name, cp->help);
|
|
|
|
}
|
1994-01-24 08:52:58 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ex_viusage -- :viusage [key]
|
|
|
|
* Display vi usage strings.
|
1996-05-20 07:47:00 +04:00
|
|
|
*
|
|
|
|
* PUBLIC: int ex_viusage __P((SCR *, EXCMD *));
|
1994-01-24 08:52:58 +03:00
|
|
|
*/
|
|
|
|
int
|
1996-05-20 07:47:00 +04:00
|
|
|
ex_viusage(sp, cmdp)
|
1994-01-24 08:52:58 +03:00
|
|
|
SCR *sp;
|
1996-05-20 07:47:00 +04:00
|
|
|
EXCMD *cmdp;
|
1994-01-24 08:52:58 +03:00
|
|
|
{
|
1996-05-20 07:47:00 +04:00
|
|
|
GS *gp;
|
1994-01-24 08:52:58 +03:00
|
|
|
VIKEYS const *kp;
|
|
|
|
int key;
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
gp = sp->gp;
|
1994-01-24 08:52:58 +03:00
|
|
|
switch (cmdp->argc) {
|
|
|
|
case 1:
|
1994-08-17 20:35:35 +04:00
|
|
|
if (cmdp->argv[0]->len != 1) {
|
1996-05-20 07:47:00 +04:00
|
|
|
ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
|
1994-08-17 20:35:35 +04:00
|
|
|
return (1);
|
|
|
|
}
|
1994-01-24 08:52:58 +03:00
|
|
|
key = cmdp->argv[0]->bp[0];
|
|
|
|
if (key > MAXVIKEY)
|
|
|
|
goto nokey;
|
|
|
|
|
|
|
|
/* Special case: '[' and ']' commands. */
|
|
|
|
if ((key == '[' || key == ']') && cmdp->argv[0]->bp[1] != key)
|
|
|
|
goto nokey;
|
|
|
|
|
1994-08-17 20:35:35 +04:00
|
|
|
/* Special case: ~ command. */
|
|
|
|
if (key == '~' && O_ISSET(sp, O_TILDEOP))
|
|
|
|
kp = &tmotion;
|
|
|
|
else
|
|
|
|
kp = &vikeys[key];
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
if (kp->usage == NULL)
|
|
|
|
nokey: (void)ex_printf(sp,
|
|
|
|
"The %s key has no current meaning\n",
|
1994-08-17 20:35:35 +04:00
|
|
|
KEY_NAME(sp, key));
|
1994-01-24 08:52:58 +03:00
|
|
|
else
|
1996-05-20 07:47:00 +04:00
|
|
|
(void)ex_printf(sp,
|
1994-01-24 08:52:58 +03:00
|
|
|
" Key:%s%s\nUsage: %s\n",
|
|
|
|
isblank(*kp->help) ? "" : " ", kp->help, kp->usage);
|
|
|
|
break;
|
|
|
|
case 0:
|
1996-05-20 07:47:00 +04:00
|
|
|
for (key = 0; key <= MAXVIKEY && !INTERRUPTED(sp); ++key) {
|
1994-08-17 20:35:35 +04:00
|
|
|
/* Special case: ~ command. */
|
|
|
|
if (key == '~' && O_ISSET(sp, O_TILDEOP))
|
|
|
|
kp = &tmotion;
|
|
|
|
else
|
|
|
|
kp = &vikeys[key];
|
1994-01-24 08:52:58 +03:00
|
|
|
if (kp->help != NULL)
|
1996-05-20 07:47:00 +04:00
|
|
|
(void)ex_printf(sp, "%s\n", kp->help);
|
1994-01-24 08:52:58 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|