update to 1.01
[nvi.git] / ex / ex_usage.c
blobce74eab2f319181f9a48a6cf2d986d10ba238b93
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: ex_usage.c,v 8.11 1993/12/17 13:43:59 bostic Exp $ (Berkeley) $Date: 1993/12/17 13:43:59 $";
10 #endif /* not lint */
12 #include <sys/types.h>
13 #include <string.h>
15 #include "vi.h"
16 #include "excmd.h"
17 #include "vcmd.h"
20 * ex_help -- :help
21 * Display help message.
23 int
24 ex_help(sp, ep, cmdp)
25 SCR *sp;
26 EXF *ep;
27 EXCMDARG *cmdp;
29 (void)ex_printf(EXCOOKIE,
30 "To see the list of vi commands, enter \":viusage<CR>\"\n");
31 (void)ex_printf(EXCOOKIE,
32 "To see the list of ex commands, enter \":exusage<CR>\"\n");
33 (void)ex_printf(EXCOOKIE,
34 "For an ex command usage statement enter \":exusage [cmd]<CR>\"\n");
35 (void)ex_printf(EXCOOKIE,
36 "For a vi key usage statement enter \":viusage [key]<CR>\"\n");
37 (void)ex_printf(EXCOOKIE, "To exit, enter \":q!\"\n");
38 return (0);
42 * ex_usage -- :exusage [cmd]
43 * Display ex usage strings.
45 int
46 ex_usage(sp, ep, cmdp)
47 SCR *sp;
48 EXF *ep;
49 EXCMDARG *cmdp;
51 ARGS *ap;
52 EXCMDLIST const *cp;
54 switch (cmdp->argc) {
55 case 1:
56 ap = cmdp->argv[0];
57 for (cp = cmds; cp->name != NULL &&
58 memcmp(ap->bp, cp->name, ap->len); ++cp);
59 if (cp->name == NULL)
60 (void)ex_printf(EXCOOKIE,
61 "The %.*s command is unknown.",
62 (int)ap->len, ap->bp);
63 else {
64 (void)ex_printf(EXCOOKIE,
65 "Command: %s\n Usage: %s\n", cp->help, cp->usage);
67 * !!!
68 * The "visual" command has two modes, one from ex,
69 * one from the vi colon line. Don't ask.
71 if (cp != &cmds[C_VISUAL_EX] &&
72 cp != &cmds[C_VISUAL_VI])
73 break;
74 if (cp == &cmds[C_VISUAL_EX])
75 cp = &cmds[C_VISUAL_VI];
76 else
77 cp = &cmds[C_VISUAL_EX];
78 (void)ex_printf(EXCOOKIE,
79 "Command: %s\n Usage: %s\n", cp->help, cp->usage);
81 break;
82 case 0:
83 for (cp = cmds; cp->name != NULL; ++cp)
84 (void)ex_printf(EXCOOKIE,
85 "%*s: %s\n", MAXCMDNAMELEN, cp->name, cp->help);
86 break;
87 default:
88 abort();
90 return (0);
94 * ex_viusage -- :viusage [key]
95 * Display vi usage strings.
97 int
98 ex_viusage(sp, ep, cmdp)
99 SCR *sp;
100 EXF *ep;
101 EXCMDARG *cmdp;
103 VIKEYS const *kp;
104 int key;
106 switch (cmdp->argc) {
107 case 1:
108 key = cmdp->argv[0]->bp[0];
109 if (key > MAXVIKEY)
110 goto nokey;
112 /* Special case: '[' and ']' commands. */
113 if ((key == '[' || key == ']') && cmdp->argv[0]->bp[1] != key)
114 goto nokey;
116 kp = &vikeys[key];
117 if (kp->func == NULL)
118 nokey: (void)ex_printf(EXCOOKIE,
119 "The %s key has no current meaning",
120 charname(sp, key));
121 else
122 (void)ex_printf(EXCOOKIE,
123 " Key:%s%s\nUsage: %s\n",
124 isblank(*kp->help) ? "" : " ", kp->help, kp->usage);
125 break;
126 case 0:
127 for (key = 0; key <= MAXVIKEY; ++key) {
128 kp = &vikeys[key];
129 if (kp->help != NULL)
130 (void)ex_printf(EXCOOKIE, "%s\n", kp->help);
132 break;
133 default:
134 abort();
136 return (0);