Commit | Line | Data |
---|---|---|
18ae9d6b AS |
1 | /*- |
2 | * Copyright (c) 1992, 1993 | |
3 | * The Regents of the University of California. All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | */ | |
33 | ||
34 | #ifndef lint | |
35 | static char sccsid[] = "@(#)ex_usage.c 8.11 (Berkeley) 12/17/93"; | |
36 | #endif /* not lint */ | |
37 | ||
38 | #include <sys/types.h> | |
39 | #include <string.h> | |
40 | ||
41 | #include "vi.h" | |
42 | #include "excmd.h" | |
43 | #include "vcmd.h" | |
44 | ||
45 | /* | |
46 | * ex_help -- :help | |
47 | * Display help message. | |
48 | */ | |
49 | int | |
50 | ex_help(sp, ep, cmdp) | |
51 | SCR *sp; | |
52 | EXF *ep; | |
53 | EXCMDARG *cmdp; | |
54 | { | |
55 | (void)ex_printf(EXCOOKIE, | |
56 | "To see the list of vi commands, enter \":viusage<CR>\"\n"); | |
57 | (void)ex_printf(EXCOOKIE, | |
58 | "To see the list of ex commands, enter \":exusage<CR>\"\n"); | |
59 | (void)ex_printf(EXCOOKIE, | |
60 | "For an ex command usage statement enter \":exusage [cmd]<CR>\"\n"); | |
61 | (void)ex_printf(EXCOOKIE, | |
62 | "For a vi key usage statement enter \":viusage [key]<CR>\"\n"); | |
63 | (void)ex_printf(EXCOOKIE, "To exit, enter \":q!\"\n"); | |
64 | return (0); | |
65 | } | |
66 | ||
67 | /* | |
68 | * ex_usage -- :exusage [cmd] | |
69 | * Display ex usage strings. | |
70 | */ | |
71 | int | |
72 | ex_usage(sp, ep, cmdp) | |
73 | SCR *sp; | |
74 | EXF *ep; | |
75 | EXCMDARG *cmdp; | |
76 | { | |
77 | ARGS *ap; | |
78 | EXCMDLIST const *cp; | |
79 | ||
80 | switch (cmdp->argc) { | |
81 | case 1: | |
82 | ap = cmdp->argv[0]; | |
83 | for (cp = cmds; cp->name != NULL && | |
84 | memcmp(ap->bp, cp->name, ap->len); ++cp); | |
85 | if (cp->name == NULL) | |
86 | (void)ex_printf(EXCOOKIE, | |
87 | "The %.*s command is unknown.", | |
88 | (int)ap->len, ap->bp); | |
89 | else { | |
90 | (void)ex_printf(EXCOOKIE, | |
91 | "Command: %s\n Usage: %s\n", cp->help, cp->usage); | |
92 | /* | |
93 | * !!! | |
94 | * The "visual" command has two modes, one from ex, | |
95 | * one from the vi colon line. Don't ask. | |
96 | */ | |
97 | if (cp != &cmds[C_VISUAL_EX] && | |
98 | cp != &cmds[C_VISUAL_VI]) | |
99 | break; | |
100 | if (cp == &cmds[C_VISUAL_EX]) | |
101 | cp = &cmds[C_VISUAL_VI]; | |
102 | else | |
103 | cp = &cmds[C_VISUAL_EX]; | |
104 | (void)ex_printf(EXCOOKIE, | |
105 | "Command: %s\n Usage: %s\n", cp->help, cp->usage); | |
106 | } | |
107 | break; | |
108 | case 0: | |
109 | for (cp = cmds; cp->name != NULL; ++cp) | |
110 | (void)ex_printf(EXCOOKIE, | |
111 | "%*s: %s\n", MAXCMDNAMELEN, cp->name, cp->help); | |
112 | break; | |
113 | default: | |
114 | abort(); | |
115 | } | |
116 | return (0); | |
117 | } | |
118 | ||
119 | /* | |
120 | * ex_viusage -- :viusage [key] | |
121 | * Display vi usage strings. | |
122 | */ | |
123 | int | |
124 | ex_viusage(sp, ep, cmdp) | |
125 | SCR *sp; | |
126 | EXF *ep; | |
127 | EXCMDARG *cmdp; | |
128 | { | |
129 | VIKEYS const *kp; | |
130 | int key; | |
131 | ||
132 | switch (cmdp->argc) { | |
133 | case 1: | |
134 | key = cmdp->argv[0]->bp[0]; | |
135 | if (key > MAXVIKEY) | |
136 | goto nokey; | |
137 | ||
138 | /* Special case: '[' and ']' commands. */ | |
139 | if ((key == '[' || key == ']') && cmdp->argv[0]->bp[1] != key) | |
140 | goto nokey; | |
141 | ||
142 | kp = &vikeys[key]; | |
143 | if (kp->func == NULL) | |
144 | nokey: (void)ex_printf(EXCOOKIE, | |
145 | "The %s key has no current meaning", | |
146 | charname(sp, key)); | |
147 | else | |
148 | (void)ex_printf(EXCOOKIE, | |
149 | " Key:%s%s\nUsage: %s\n", | |
150 | isblank(*kp->help) ? "" : " ", kp->help, kp->usage); | |
151 | break; | |
152 | case 0: | |
153 | for (key = 0; key <= MAXVIKEY; ++key) { | |
154 | kp = &vikeys[key]; | |
155 | if (kp->help != NULL) | |
156 | (void)ex_printf(EXCOOKIE, "%s\n", kp->help); | |
157 | } | |
158 | break; | |
159 | default: | |
160 | abort(); | |
161 | } | |
162 | return (0); | |
163 | } |