xref: /minix3/external/bsd/less/dist/command.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*	$NetBSD: command.c,v 1.5 2013/09/04 19:44:21 tron Exp $	*/
2f7cf2976SLionel Sambuc 
3f7cf2976SLionel Sambuc /*
4*84d9c625SLionel Sambuc  * Copyright (C) 1984-2012  Mark Nudelman
5f7cf2976SLionel Sambuc  *
6f7cf2976SLionel Sambuc  * You may distribute under the terms of either the GNU General Public
7f7cf2976SLionel Sambuc  * License or the Less License, as specified in the README file.
8f7cf2976SLionel Sambuc  *
9*84d9c625SLionel Sambuc  * For more information, see the README file.
10f7cf2976SLionel Sambuc  */
11f7cf2976SLionel Sambuc 
12f7cf2976SLionel Sambuc 
13f7cf2976SLionel Sambuc /*
14f7cf2976SLionel Sambuc  * User-level command processor.
15f7cf2976SLionel Sambuc  */
16f7cf2976SLionel Sambuc 
17f7cf2976SLionel Sambuc #include "less.h"
18f7cf2976SLionel Sambuc #if MSDOS_COMPILER==WIN32C
19f7cf2976SLionel Sambuc #include <windows.h>
20f7cf2976SLionel Sambuc #endif
21f7cf2976SLionel Sambuc #include "position.h"
22f7cf2976SLionel Sambuc #include "option.h"
23f7cf2976SLionel Sambuc #include "cmd.h"
24f7cf2976SLionel Sambuc 
25f7cf2976SLionel Sambuc extern int erase_char, erase2_char, kill_char;
26f7cf2976SLionel Sambuc extern int sigs;
27f7cf2976SLionel Sambuc extern int quit_if_one_screen;
28f7cf2976SLionel Sambuc extern int squished;
29f7cf2976SLionel Sambuc extern int sc_width;
30f7cf2976SLionel Sambuc extern int sc_height;
31f7cf2976SLionel Sambuc extern int swindow;
32f7cf2976SLionel Sambuc extern int jump_sline;
33f7cf2976SLionel Sambuc extern int quitting;
34f7cf2976SLionel Sambuc extern int wscroll;
35f7cf2976SLionel Sambuc extern int top_scroll;
36f7cf2976SLionel Sambuc extern int ignore_eoi;
37f7cf2976SLionel Sambuc extern int secure;
38f7cf2976SLionel Sambuc extern int hshift;
39f7cf2976SLionel Sambuc extern int show_attn;
40*84d9c625SLionel Sambuc extern POSITION highest_hilite;
41f7cf2976SLionel Sambuc extern char *every_first_cmd;
42f7cf2976SLionel Sambuc extern char *curr_altfilename;
43f7cf2976SLionel Sambuc extern char version[];
44f7cf2976SLionel Sambuc extern struct scrpos initial_scrpos;
45f7cf2976SLionel Sambuc extern IFILE curr_ifile;
46f7cf2976SLionel Sambuc extern void constant *ml_search;
47f7cf2976SLionel Sambuc extern void * constant ml_examine;
48f7cf2976SLionel Sambuc #if SHELL_ESCAPE || PIPEC
49f7cf2976SLionel Sambuc extern void * constant ml_shell;
50f7cf2976SLionel Sambuc #endif
51f7cf2976SLionel Sambuc #if EDITOR
52f7cf2976SLionel Sambuc extern char *editor;
53f7cf2976SLionel Sambuc extern char *editproto;
54f7cf2976SLionel Sambuc #endif
55f7cf2976SLionel Sambuc extern int screen_trashed;	/* The screen has been overwritten */
56f7cf2976SLionel Sambuc extern int shift_count;
57f7cf2976SLionel Sambuc extern int oldbot;
58f7cf2976SLionel Sambuc extern int forw_prompt;
59f7cf2976SLionel Sambuc extern int be_helpful;
60f7cf2976SLionel Sambuc extern int more_mode;
61f7cf2976SLionel Sambuc 
62f7cf2976SLionel Sambuc static int helpprompt;
63f7cf2976SLionel Sambuc 
64f7cf2976SLionel Sambuc #if SHELL_ESCAPE
65f7cf2976SLionel Sambuc static char *shellcmd = NULL;	/* For holding last shell command for "!!" */
66f7cf2976SLionel Sambuc #endif
67f7cf2976SLionel Sambuc static int mca;			/* The multicharacter command (action) */
68f7cf2976SLionel Sambuc static int search_type;		/* The previous type of search */
69f7cf2976SLionel Sambuc static LINENUM number;		/* The number typed by the user */
70f7cf2976SLionel Sambuc static long fraction;		/* The fractional part of the number */
71f7cf2976SLionel Sambuc static struct loption *curropt;
72f7cf2976SLionel Sambuc static int opt_lower;
73f7cf2976SLionel Sambuc static int optflag;
74f7cf2976SLionel Sambuc static int optgetname;
75f7cf2976SLionel Sambuc static POSITION bottompos;
76f7cf2976SLionel Sambuc static int save_hshift;
77f7cf2976SLionel Sambuc #if PIPEC
78f7cf2976SLionel Sambuc static char pipec;
79f7cf2976SLionel Sambuc #endif
80f7cf2976SLionel Sambuc 
81f7cf2976SLionel Sambuc struct ungot {
82f7cf2976SLionel Sambuc 	struct ungot *ug_next;
83f7cf2976SLionel Sambuc 	char ug_char;
84f7cf2976SLionel Sambuc };
85f7cf2976SLionel Sambuc static struct ungot* ungot = NULL;
86f7cf2976SLionel Sambuc static int unget_end = 0;
87f7cf2976SLionel Sambuc 
88f7cf2976SLionel Sambuc static void multi_search();
89f7cf2976SLionel Sambuc 
90f7cf2976SLionel Sambuc /*
91f7cf2976SLionel Sambuc  * Move the cursor to start of prompt line before executing a command.
92f7cf2976SLionel Sambuc  * This looks nicer if the command takes a long time before
93f7cf2976SLionel Sambuc  * updating the screen.
94f7cf2976SLionel Sambuc  */
95f7cf2976SLionel Sambuc 	static void
cmd_exec()96f7cf2976SLionel Sambuc cmd_exec()
97f7cf2976SLionel Sambuc {
98f7cf2976SLionel Sambuc #if HILITE_SEARCH
99f7cf2976SLionel Sambuc 	clear_attn();
100f7cf2976SLionel Sambuc #endif
101f7cf2976SLionel Sambuc 	clear_bot();
102f7cf2976SLionel Sambuc 	flush();
103f7cf2976SLionel Sambuc }
104f7cf2976SLionel Sambuc 
105f7cf2976SLionel Sambuc /*
106f7cf2976SLionel Sambuc  * Set up the display to start a new multi-character command.
107f7cf2976SLionel Sambuc  */
108f7cf2976SLionel Sambuc 	static void
start_mca(action,prompt,mlist,cmdflags)109f7cf2976SLionel Sambuc start_mca(action, prompt, mlist, cmdflags)
110f7cf2976SLionel Sambuc 	int action;
111*84d9c625SLionel Sambuc 	constant char *prompt;
112*84d9c625SLionel Sambuc 	constant void *mlist;
113f7cf2976SLionel Sambuc 	int cmdflags;
114f7cf2976SLionel Sambuc {
115f7cf2976SLionel Sambuc 	mca = action;
116f7cf2976SLionel Sambuc 	clear_bot();
117f7cf2976SLionel Sambuc 	clear_cmd();
118f7cf2976SLionel Sambuc 	cmd_putstr(prompt);
119f7cf2976SLionel Sambuc 	set_mlist(mlist, cmdflags);
120f7cf2976SLionel Sambuc }
121f7cf2976SLionel Sambuc 
122f7cf2976SLionel Sambuc 	public int
in_mca()123f7cf2976SLionel Sambuc in_mca()
124f7cf2976SLionel Sambuc {
125f7cf2976SLionel Sambuc 	return (mca != 0 && mca != A_PREFIX);
126f7cf2976SLionel Sambuc }
127f7cf2976SLionel Sambuc 
128f7cf2976SLionel Sambuc /*
129f7cf2976SLionel Sambuc  * Set up the display to start a new search command.
130f7cf2976SLionel Sambuc  */
131f7cf2976SLionel Sambuc 	static void
mca_search()132f7cf2976SLionel Sambuc mca_search()
133f7cf2976SLionel Sambuc {
134f7cf2976SLionel Sambuc #if HILITE_SEARCH
135f7cf2976SLionel Sambuc 	if (search_type & SRCH_FILTER)
136f7cf2976SLionel Sambuc 		mca = A_FILTER;
137f7cf2976SLionel Sambuc 	else
138f7cf2976SLionel Sambuc #endif
139f7cf2976SLionel Sambuc 	if (search_type & SRCH_FORW)
140f7cf2976SLionel Sambuc 		mca = A_F_SEARCH;
141f7cf2976SLionel Sambuc 	else
142f7cf2976SLionel Sambuc 		mca = A_B_SEARCH;
143f7cf2976SLionel Sambuc 
144f7cf2976SLionel Sambuc 	clear_bot();
145f7cf2976SLionel Sambuc 	clear_cmd();
146f7cf2976SLionel Sambuc 
147f7cf2976SLionel Sambuc 	if (search_type & SRCH_NO_MATCH)
148f7cf2976SLionel Sambuc 		cmd_putstr("Non-match ");
149f7cf2976SLionel Sambuc 	if (search_type & SRCH_FIRST_FILE)
150f7cf2976SLionel Sambuc 		cmd_putstr("First-file ");
151f7cf2976SLionel Sambuc 	if (search_type & SRCH_PAST_EOF)
152f7cf2976SLionel Sambuc 		cmd_putstr("EOF-ignore ");
153f7cf2976SLionel Sambuc 	if (search_type & SRCH_NO_MOVE)
154f7cf2976SLionel Sambuc 		cmd_putstr("Keep-pos ");
155f7cf2976SLionel Sambuc 	if (search_type & SRCH_NO_REGEX)
156f7cf2976SLionel Sambuc 		cmd_putstr("Regex-off ");
157f7cf2976SLionel Sambuc 
158f7cf2976SLionel Sambuc #if HILITE_SEARCH
159f7cf2976SLionel Sambuc 	if (search_type & SRCH_FILTER)
160f7cf2976SLionel Sambuc 		cmd_putstr("&/");
161f7cf2976SLionel Sambuc 	else
162f7cf2976SLionel Sambuc #endif
163f7cf2976SLionel Sambuc 	if (search_type & SRCH_FORW)
164f7cf2976SLionel Sambuc 		cmd_putstr("/");
165f7cf2976SLionel Sambuc 	else
166f7cf2976SLionel Sambuc 		cmd_putstr("?");
167f7cf2976SLionel Sambuc 	set_mlist(ml_search, 0);
168f7cf2976SLionel Sambuc }
169f7cf2976SLionel Sambuc 
170f7cf2976SLionel Sambuc /*
171f7cf2976SLionel Sambuc  * Set up the display to start a new toggle-option command.
172f7cf2976SLionel Sambuc  */
173f7cf2976SLionel Sambuc 	static void
mca_opt_toggle()174f7cf2976SLionel Sambuc mca_opt_toggle()
175f7cf2976SLionel Sambuc {
176f7cf2976SLionel Sambuc 	int no_prompt;
177f7cf2976SLionel Sambuc 	int flag;
178f7cf2976SLionel Sambuc 	char *dash;
179f7cf2976SLionel Sambuc 
180f7cf2976SLionel Sambuc 	no_prompt = (optflag & OPT_NO_PROMPT);
181f7cf2976SLionel Sambuc 	flag = (optflag & ~OPT_NO_PROMPT);
182f7cf2976SLionel Sambuc 	dash = (flag == OPT_NO_TOGGLE) ? "_" : "-";
183f7cf2976SLionel Sambuc 
184f7cf2976SLionel Sambuc 	mca = A_OPT_TOGGLE;
185f7cf2976SLionel Sambuc 	clear_bot();
186f7cf2976SLionel Sambuc 	clear_cmd();
187f7cf2976SLionel Sambuc 	cmd_putstr(dash);
188f7cf2976SLionel Sambuc 	if (optgetname)
189f7cf2976SLionel Sambuc 		cmd_putstr(dash);
190f7cf2976SLionel Sambuc 	if (no_prompt)
191f7cf2976SLionel Sambuc 		cmd_putstr("(P)");
192f7cf2976SLionel Sambuc 	switch (flag)
193f7cf2976SLionel Sambuc 	{
194f7cf2976SLionel Sambuc 	case OPT_UNSET:
195f7cf2976SLionel Sambuc 		cmd_putstr("+");
196f7cf2976SLionel Sambuc 		break;
197f7cf2976SLionel Sambuc 	case OPT_SET:
198f7cf2976SLionel Sambuc 		cmd_putstr("!");
199f7cf2976SLionel Sambuc 		break;
200f7cf2976SLionel Sambuc 	}
201f7cf2976SLionel Sambuc 	set_mlist(NULL, 0);
202f7cf2976SLionel Sambuc }
203f7cf2976SLionel Sambuc 
204f7cf2976SLionel Sambuc /*
205f7cf2976SLionel Sambuc  * Execute a multicharacter command.
206f7cf2976SLionel Sambuc  */
207f7cf2976SLionel Sambuc 	static void
exec_mca()208f7cf2976SLionel Sambuc exec_mca()
209f7cf2976SLionel Sambuc {
210f7cf2976SLionel Sambuc 	register char *cbuf;
211f7cf2976SLionel Sambuc 
212f7cf2976SLionel Sambuc 	cmd_exec();
213f7cf2976SLionel Sambuc 	cbuf = get_cmdbuf();
214f7cf2976SLionel Sambuc 
215f7cf2976SLionel Sambuc 	switch (mca)
216f7cf2976SLionel Sambuc 	{
217f7cf2976SLionel Sambuc 	case A_F_SEARCH:
218f7cf2976SLionel Sambuc 	case A_B_SEARCH:
219f7cf2976SLionel Sambuc 		multi_search(cbuf, (int) number);
220f7cf2976SLionel Sambuc 		break;
221f7cf2976SLionel Sambuc #if HILITE_SEARCH
222f7cf2976SLionel Sambuc 	case A_FILTER:
223f7cf2976SLionel Sambuc 		search_type ^= SRCH_NO_MATCH;
224f7cf2976SLionel Sambuc 		set_filter_pattern(cbuf, search_type);
225f7cf2976SLionel Sambuc 		break;
226f7cf2976SLionel Sambuc #endif
227f7cf2976SLionel Sambuc 	case A_FIRSTCMD:
228f7cf2976SLionel Sambuc 		/*
229f7cf2976SLionel Sambuc 		 * Skip leading spaces or + signs in the string.
230f7cf2976SLionel Sambuc 		 */
231f7cf2976SLionel Sambuc 		while (*cbuf == '+' || *cbuf == ' ')
232f7cf2976SLionel Sambuc 			cbuf++;
233f7cf2976SLionel Sambuc 		if (every_first_cmd != NULL)
234f7cf2976SLionel Sambuc 			free(every_first_cmd);
235f7cf2976SLionel Sambuc 		if (*cbuf == '\0')
236f7cf2976SLionel Sambuc 			every_first_cmd = NULL;
237f7cf2976SLionel Sambuc 		else
238f7cf2976SLionel Sambuc 			every_first_cmd = save(cbuf);
239f7cf2976SLionel Sambuc 		break;
240f7cf2976SLionel Sambuc 	case A_OPT_TOGGLE:
241f7cf2976SLionel Sambuc 		toggle_option(curropt, opt_lower, cbuf, optflag);
242f7cf2976SLionel Sambuc 		curropt = NULL;
243f7cf2976SLionel Sambuc 		break;
244f7cf2976SLionel Sambuc 	case A_F_BRACKET:
245f7cf2976SLionel Sambuc 		match_brac(cbuf[0], cbuf[1], 1, (int) number);
246f7cf2976SLionel Sambuc 		break;
247f7cf2976SLionel Sambuc 	case A_B_BRACKET:
248f7cf2976SLionel Sambuc 		match_brac(cbuf[1], cbuf[0], 0, (int) number);
249f7cf2976SLionel Sambuc 		break;
250f7cf2976SLionel Sambuc #if EXAMINE
251f7cf2976SLionel Sambuc 	case A_EXAMINE:
252f7cf2976SLionel Sambuc 		if (secure)
253f7cf2976SLionel Sambuc 			break;
254f7cf2976SLionel Sambuc 		edit_list(cbuf);
255f7cf2976SLionel Sambuc #if TAGS
256f7cf2976SLionel Sambuc 		/* If tag structure is loaded then clean it up. */
257f7cf2976SLionel Sambuc 		cleantags();
258f7cf2976SLionel Sambuc #endif
259f7cf2976SLionel Sambuc 		break;
260f7cf2976SLionel Sambuc #endif
261f7cf2976SLionel Sambuc #if SHELL_ESCAPE
262f7cf2976SLionel Sambuc 	case A_SHELL:
263f7cf2976SLionel Sambuc 		/*
264f7cf2976SLionel Sambuc 		 * !! just uses whatever is in shellcmd.
265f7cf2976SLionel Sambuc 		 * Otherwise, copy cmdbuf to shellcmd,
266f7cf2976SLionel Sambuc 		 * expanding any special characters ("%" or "#").
267f7cf2976SLionel Sambuc 		 */
268f7cf2976SLionel Sambuc 		if (*cbuf != '!')
269f7cf2976SLionel Sambuc 		{
270f7cf2976SLionel Sambuc 			if (shellcmd != NULL)
271f7cf2976SLionel Sambuc 				free(shellcmd);
272f7cf2976SLionel Sambuc 			shellcmd = fexpand(cbuf);
273f7cf2976SLionel Sambuc 		}
274f7cf2976SLionel Sambuc 
275f7cf2976SLionel Sambuc 		if (secure)
276f7cf2976SLionel Sambuc 			break;
277f7cf2976SLionel Sambuc 		if (shellcmd == NULL)
278f7cf2976SLionel Sambuc 			lsystem("", "!done");
279f7cf2976SLionel Sambuc 		else
280f7cf2976SLionel Sambuc 			lsystem(shellcmd, "!done");
281f7cf2976SLionel Sambuc 		break;
282f7cf2976SLionel Sambuc #endif
283f7cf2976SLionel Sambuc #if PIPEC
284f7cf2976SLionel Sambuc 	case A_PIPE:
285f7cf2976SLionel Sambuc 		if (secure)
286f7cf2976SLionel Sambuc 			break;
287f7cf2976SLionel Sambuc 		(void) pipe_mark(pipec, cbuf);
288f7cf2976SLionel Sambuc 		error("|done", NULL_PARG);
289f7cf2976SLionel Sambuc 		break;
290f7cf2976SLionel Sambuc #endif
291f7cf2976SLionel Sambuc 	}
292f7cf2976SLionel Sambuc }
293f7cf2976SLionel Sambuc 
294f7cf2976SLionel Sambuc /*
295f7cf2976SLionel Sambuc  * Is a character an erase or kill char?
296f7cf2976SLionel Sambuc  */
297f7cf2976SLionel Sambuc 	static int
is_erase_char(c)298f7cf2976SLionel Sambuc is_erase_char(c)
299f7cf2976SLionel Sambuc 	int c;
300f7cf2976SLionel Sambuc {
301f7cf2976SLionel Sambuc 	return (c == erase_char || c == erase2_char || c == kill_char);
302f7cf2976SLionel Sambuc }
303f7cf2976SLionel Sambuc 
304f7cf2976SLionel Sambuc /*
305f7cf2976SLionel Sambuc  * Handle the first char of an option (after the initial dash).
306f7cf2976SLionel Sambuc  */
307f7cf2976SLionel Sambuc 	static int
mca_opt_first_char(c)308f7cf2976SLionel Sambuc mca_opt_first_char(c)
309f7cf2976SLionel Sambuc     int c;
310f7cf2976SLionel Sambuc {
311f7cf2976SLionel Sambuc 	int flag = (optflag & ~OPT_NO_PROMPT);
312f7cf2976SLionel Sambuc 	if (flag == OPT_NO_TOGGLE)
313f7cf2976SLionel Sambuc 	{
314f7cf2976SLionel Sambuc 		switch (c)
315f7cf2976SLionel Sambuc 		{
316f7cf2976SLionel Sambuc 		case '_':
317f7cf2976SLionel Sambuc 			/* "__" = long option name. */
318f7cf2976SLionel Sambuc 			optgetname = TRUE;
319f7cf2976SLionel Sambuc 			mca_opt_toggle();
320f7cf2976SLionel Sambuc 			return (MCA_MORE);
321f7cf2976SLionel Sambuc 		}
322f7cf2976SLionel Sambuc 	} else
323f7cf2976SLionel Sambuc 	{
324f7cf2976SLionel Sambuc 		switch (c)
325f7cf2976SLionel Sambuc 		{
326f7cf2976SLionel Sambuc 		case '+':
327f7cf2976SLionel Sambuc 			/* "-+" = UNSET. */
328f7cf2976SLionel Sambuc 			optflag = (flag == OPT_UNSET) ?
329f7cf2976SLionel Sambuc 				OPT_TOGGLE : OPT_UNSET;
330f7cf2976SLionel Sambuc 			mca_opt_toggle();
331f7cf2976SLionel Sambuc 			return (MCA_MORE);
332f7cf2976SLionel Sambuc 		case '!':
333f7cf2976SLionel Sambuc 			/* "-!" = SET */
334f7cf2976SLionel Sambuc 			optflag = (flag == OPT_SET) ?
335f7cf2976SLionel Sambuc 				OPT_TOGGLE : OPT_SET;
336f7cf2976SLionel Sambuc 			mca_opt_toggle();
337f7cf2976SLionel Sambuc 			return (MCA_MORE);
338f7cf2976SLionel Sambuc 		case CONTROL('P'):
339f7cf2976SLionel Sambuc 			optflag ^= OPT_NO_PROMPT;
340f7cf2976SLionel Sambuc 			mca_opt_toggle();
341f7cf2976SLionel Sambuc 			return (MCA_MORE);
342f7cf2976SLionel Sambuc 		case '-':
343f7cf2976SLionel Sambuc 			/* "--" = long option name. */
344f7cf2976SLionel Sambuc 			optgetname = TRUE;
345f7cf2976SLionel Sambuc 			mca_opt_toggle();
346f7cf2976SLionel Sambuc 			return (MCA_MORE);
347f7cf2976SLionel Sambuc 		}
348f7cf2976SLionel Sambuc 	}
349f7cf2976SLionel Sambuc 	/* Char was not handled here. */
350f7cf2976SLionel Sambuc 	return (NO_MCA);
351f7cf2976SLionel Sambuc }
352f7cf2976SLionel Sambuc 
353f7cf2976SLionel Sambuc /*
354f7cf2976SLionel Sambuc  * Add a char to a long option name.
355f7cf2976SLionel Sambuc  * See if we've got a match for an option name yet.
356f7cf2976SLionel Sambuc  * If so, display the complete name and stop
357f7cf2976SLionel Sambuc  * accepting chars until user hits RETURN.
358f7cf2976SLionel Sambuc  */
359f7cf2976SLionel Sambuc 	static int
mca_opt_nonfirst_char(c)360f7cf2976SLionel Sambuc mca_opt_nonfirst_char(c)
361f7cf2976SLionel Sambuc 	int c;
362f7cf2976SLionel Sambuc {
363f7cf2976SLionel Sambuc 	char *p;
364f7cf2976SLionel Sambuc 	char *oname;
365f7cf2976SLionel Sambuc 
366f7cf2976SLionel Sambuc 	if (curropt != NULL)
367f7cf2976SLionel Sambuc 	{
368f7cf2976SLionel Sambuc 		/*
369f7cf2976SLionel Sambuc 		 * Already have a match for the name.
370f7cf2976SLionel Sambuc 		 * Don't accept anything but erase/kill.
371f7cf2976SLionel Sambuc 		 */
372f7cf2976SLionel Sambuc 		if (is_erase_char(c))
373f7cf2976SLionel Sambuc 			return (MCA_DONE);
374f7cf2976SLionel Sambuc 		return (MCA_MORE);
375f7cf2976SLionel Sambuc 	}
376f7cf2976SLionel Sambuc 	/*
377f7cf2976SLionel Sambuc 	 * Add char to cmd buffer and try to match
378f7cf2976SLionel Sambuc 	 * the option name.
379f7cf2976SLionel Sambuc 	 */
380f7cf2976SLionel Sambuc 	if (cmd_char(c) == CC_QUIT)
381f7cf2976SLionel Sambuc 		return (MCA_DONE);
382f7cf2976SLionel Sambuc 	p = get_cmdbuf();
383f7cf2976SLionel Sambuc 	opt_lower = ASCII_IS_LOWER(p[0]);
384f7cf2976SLionel Sambuc 	curropt = findopt_name(&p, &oname, NULL);
385f7cf2976SLionel Sambuc 	if (curropt != NULL)
386f7cf2976SLionel Sambuc 	{
387f7cf2976SLionel Sambuc 		/*
388f7cf2976SLionel Sambuc 		 * Got a match.
389f7cf2976SLionel Sambuc 		 * Remember the option and
390f7cf2976SLionel Sambuc 		 * display the full option name.
391f7cf2976SLionel Sambuc 		 */
392f7cf2976SLionel Sambuc 		cmd_reset();
393f7cf2976SLionel Sambuc 		mca_opt_toggle();
394f7cf2976SLionel Sambuc 		for (p = oname;  *p != '\0';  p++)
395f7cf2976SLionel Sambuc 		{
396f7cf2976SLionel Sambuc 			c = *p;
397f7cf2976SLionel Sambuc 			if (!opt_lower && ASCII_IS_LOWER(c))
398f7cf2976SLionel Sambuc 				c = ASCII_TO_UPPER(c);
399f7cf2976SLionel Sambuc 			if (cmd_char(c) != CC_OK)
400f7cf2976SLionel Sambuc 				return (MCA_DONE);
401f7cf2976SLionel Sambuc 		}
402f7cf2976SLionel Sambuc 	}
403f7cf2976SLionel Sambuc 	return (MCA_MORE);
404f7cf2976SLionel Sambuc }
405f7cf2976SLionel Sambuc 
406f7cf2976SLionel Sambuc /*
407f7cf2976SLionel Sambuc  * Handle a char of an option toggle command.
408f7cf2976SLionel Sambuc  */
409f7cf2976SLionel Sambuc 	static int
mca_opt_char(c)410f7cf2976SLionel Sambuc mca_opt_char(c)
411f7cf2976SLionel Sambuc 	int c;
412f7cf2976SLionel Sambuc {
413f7cf2976SLionel Sambuc 	PARG parg;
414f7cf2976SLionel Sambuc 
415f7cf2976SLionel Sambuc 	/*
416f7cf2976SLionel Sambuc 	 * This may be a short option (single char),
417f7cf2976SLionel Sambuc 	 * or one char of a long option name,
418f7cf2976SLionel Sambuc 	 * or one char of the option parameter.
419f7cf2976SLionel Sambuc 	 */
420f7cf2976SLionel Sambuc 	if (curropt == NULL && len_cmdbuf() == 0)
421f7cf2976SLionel Sambuc 	{
422f7cf2976SLionel Sambuc 		int ret = mca_opt_first_char(c);
423f7cf2976SLionel Sambuc 		if (ret != NO_MCA)
424f7cf2976SLionel Sambuc 			return (ret);
425f7cf2976SLionel Sambuc 	}
426f7cf2976SLionel Sambuc 	if (optgetname)
427f7cf2976SLionel Sambuc 	{
428f7cf2976SLionel Sambuc 		/* We're getting a long option name.  */
429f7cf2976SLionel Sambuc 		if (c != '\n' && c != '\r')
430f7cf2976SLionel Sambuc 			return (mca_opt_nonfirst_char(c));
431f7cf2976SLionel Sambuc 		if (curropt == NULL)
432f7cf2976SLionel Sambuc 		{
433f7cf2976SLionel Sambuc 			parg.p_string = get_cmdbuf();
434f7cf2976SLionel Sambuc 			error("There is no --%s option", &parg);
435f7cf2976SLionel Sambuc 			return (MCA_DONE);
436f7cf2976SLionel Sambuc 		}
437f7cf2976SLionel Sambuc 		optgetname = FALSE;
438f7cf2976SLionel Sambuc 		cmd_reset();
439f7cf2976SLionel Sambuc 	} else
440f7cf2976SLionel Sambuc 	{
441f7cf2976SLionel Sambuc 		if (is_erase_char(c))
442f7cf2976SLionel Sambuc 			return (NO_MCA);
443f7cf2976SLionel Sambuc 		if (curropt != NULL)
444f7cf2976SLionel Sambuc 			/* We're getting the option parameter. */
445f7cf2976SLionel Sambuc 			return (NO_MCA);
446f7cf2976SLionel Sambuc 		curropt = findopt(c);
447f7cf2976SLionel Sambuc 		if (curropt == NULL)
448f7cf2976SLionel Sambuc 		{
449f7cf2976SLionel Sambuc 			parg.p_string = propt(c);
450f7cf2976SLionel Sambuc 			error("There is no %s option", &parg);
451f7cf2976SLionel Sambuc 			return (MCA_DONE);
452f7cf2976SLionel Sambuc 		}
453f7cf2976SLionel Sambuc 	}
454f7cf2976SLionel Sambuc 	/*
455f7cf2976SLionel Sambuc 	 * If the option which was entered does not take a
456f7cf2976SLionel Sambuc 	 * parameter, toggle the option immediately,
457f7cf2976SLionel Sambuc 	 * so user doesn't have to hit RETURN.
458f7cf2976SLionel Sambuc 	 */
459f7cf2976SLionel Sambuc 	if ((optflag & ~OPT_NO_PROMPT) != OPT_TOGGLE ||
460f7cf2976SLionel Sambuc 	    !opt_has_param(curropt))
461f7cf2976SLionel Sambuc 	{
462f7cf2976SLionel Sambuc 		toggle_option(curropt, ASCII_IS_LOWER(c), "", optflag);
463f7cf2976SLionel Sambuc 		return (MCA_DONE);
464f7cf2976SLionel Sambuc 	}
465f7cf2976SLionel Sambuc 	/*
466f7cf2976SLionel Sambuc 	 * Display a prompt appropriate for the option parameter.
467f7cf2976SLionel Sambuc 	 */
468f7cf2976SLionel Sambuc 	start_mca(A_OPT_TOGGLE, opt_prompt(curropt), (void*)NULL, 0);
469f7cf2976SLionel Sambuc 	return (MCA_MORE);
470f7cf2976SLionel Sambuc }
471f7cf2976SLionel Sambuc 
472f7cf2976SLionel Sambuc /*
473f7cf2976SLionel Sambuc  * Handle a char of a search command.
474f7cf2976SLionel Sambuc  */
475f7cf2976SLionel Sambuc 	static int
mca_search_char(c)476f7cf2976SLionel Sambuc mca_search_char(c)
477f7cf2976SLionel Sambuc 	int c;
478f7cf2976SLionel Sambuc {
479f7cf2976SLionel Sambuc 	int flag = 0;
480f7cf2976SLionel Sambuc 
481f7cf2976SLionel Sambuc 	/*
482f7cf2976SLionel Sambuc 	 * Certain characters as the first char of
483f7cf2976SLionel Sambuc 	 * the pattern have special meaning:
484f7cf2976SLionel Sambuc 	 *	!  Toggle the NO_MATCH flag
485f7cf2976SLionel Sambuc 	 *	*  Toggle the PAST_EOF flag (less extension)
486f7cf2976SLionel Sambuc 	 *	@  Toggle the FIRST_FILE flag (less extension)
487f7cf2976SLionel Sambuc 	 */
488f7cf2976SLionel Sambuc 	if (len_cmdbuf() > 0)
489f7cf2976SLionel Sambuc 		return (NO_MCA);
490f7cf2976SLionel Sambuc 
491f7cf2976SLionel Sambuc 	switch (c)
492f7cf2976SLionel Sambuc 	{
493f7cf2976SLionel Sambuc 	case '*':
494f7cf2976SLionel Sambuc 		if (more_mode)
495f7cf2976SLionel Sambuc 			break;
496f7cf2976SLionel Sambuc 	case CONTROL('E'): /* ignore END of file */
497f7cf2976SLionel Sambuc 		if (mca != A_FILTER)
498f7cf2976SLionel Sambuc 			flag = SRCH_PAST_EOF;
499f7cf2976SLionel Sambuc 		break;
500f7cf2976SLionel Sambuc 	case '@':
501f7cf2976SLionel Sambuc 		if (more_mode)
502f7cf2976SLionel Sambuc 			break;
503f7cf2976SLionel Sambuc 	case CONTROL('F'): /* FIRST file */
504f7cf2976SLionel Sambuc 		if (mca != A_FILTER)
505f7cf2976SLionel Sambuc 			flag = SRCH_FIRST_FILE;
506f7cf2976SLionel Sambuc 		break;
507f7cf2976SLionel Sambuc 	case CONTROL('K'): /* KEEP position */
508f7cf2976SLionel Sambuc 		if (mca != A_FILTER)
509f7cf2976SLionel Sambuc 			flag = SRCH_NO_MOVE;
510f7cf2976SLionel Sambuc 		break;
511f7cf2976SLionel Sambuc 	case CONTROL('R'): /* Don't use REGULAR EXPRESSIONS */
512f7cf2976SLionel Sambuc 		flag = SRCH_NO_REGEX;
513f7cf2976SLionel Sambuc 		break;
514f7cf2976SLionel Sambuc 	case CONTROL('N'): /* NOT match */
515f7cf2976SLionel Sambuc 	case '!':
516f7cf2976SLionel Sambuc 		flag = SRCH_NO_MATCH;
517f7cf2976SLionel Sambuc 		break;
518f7cf2976SLionel Sambuc 	}
519f7cf2976SLionel Sambuc 
520f7cf2976SLionel Sambuc 	if (flag != 0)
521f7cf2976SLionel Sambuc 	{
522f7cf2976SLionel Sambuc 		search_type ^= flag;
523f7cf2976SLionel Sambuc 		mca_search();
524f7cf2976SLionel Sambuc 		return (MCA_MORE);
525f7cf2976SLionel Sambuc 	}
526f7cf2976SLionel Sambuc 	return (NO_MCA);
527f7cf2976SLionel Sambuc }
528f7cf2976SLionel Sambuc 
529f7cf2976SLionel Sambuc /*
530f7cf2976SLionel Sambuc  * Handle a character of a multi-character command.
531f7cf2976SLionel Sambuc  */
532f7cf2976SLionel Sambuc 	static int
mca_char(c)533f7cf2976SLionel Sambuc mca_char(c)
534f7cf2976SLionel Sambuc 	int c;
535f7cf2976SLionel Sambuc {
536f7cf2976SLionel Sambuc 	int ret;
537f7cf2976SLionel Sambuc 
538f7cf2976SLionel Sambuc 	switch (mca)
539f7cf2976SLionel Sambuc 	{
540f7cf2976SLionel Sambuc 	case 0:
541f7cf2976SLionel Sambuc 		/*
542f7cf2976SLionel Sambuc 		 * We're not in a multicharacter command.
543f7cf2976SLionel Sambuc 		 */
544f7cf2976SLionel Sambuc 		return (NO_MCA);
545f7cf2976SLionel Sambuc 
546f7cf2976SLionel Sambuc 	case A_PREFIX:
547f7cf2976SLionel Sambuc 		/*
548f7cf2976SLionel Sambuc 		 * In the prefix of a command.
549f7cf2976SLionel Sambuc 		 * This not considered a multichar command
550f7cf2976SLionel Sambuc 		 * (even tho it uses cmdbuf, etc.).
551f7cf2976SLionel Sambuc 		 * It is handled in the commands() switch.
552f7cf2976SLionel Sambuc 		 */
553f7cf2976SLionel Sambuc 		return (NO_MCA);
554f7cf2976SLionel Sambuc 
555f7cf2976SLionel Sambuc 	case A_DIGIT:
556f7cf2976SLionel Sambuc 		/*
557f7cf2976SLionel Sambuc 		 * Entering digits of a number.
558f7cf2976SLionel Sambuc 		 * Terminated by a non-digit.
559f7cf2976SLionel Sambuc 		 */
560f7cf2976SLionel Sambuc 		if (!((c >= '0' && c <= '9') || c == '.') &&
561f7cf2976SLionel Sambuc 		  editchar(c, EC_PEEK|EC_NOHISTORY|EC_NOCOMPLETE|EC_NORIGHTLEFT) == A_INVALID)
562f7cf2976SLionel Sambuc 		{
563f7cf2976SLionel Sambuc 			/*
564f7cf2976SLionel Sambuc 			 * Not part of the number.
565f7cf2976SLionel Sambuc 			 * End the number and treat this char
566f7cf2976SLionel Sambuc 			 * as a normal command character.
567f7cf2976SLionel Sambuc 			 */
568f7cf2976SLionel Sambuc 			number = cmd_int(&fraction);
569f7cf2976SLionel Sambuc 			mca = 0;
570f7cf2976SLionel Sambuc 			cmd_accept();
571f7cf2976SLionel Sambuc 			return (NO_MCA);
572f7cf2976SLionel Sambuc 		}
573f7cf2976SLionel Sambuc 		break;
574f7cf2976SLionel Sambuc 
575f7cf2976SLionel Sambuc 	case A_OPT_TOGGLE:
576f7cf2976SLionel Sambuc 		ret = mca_opt_char(c);
577f7cf2976SLionel Sambuc 		if (ret != NO_MCA)
578f7cf2976SLionel Sambuc 			return (ret);
579f7cf2976SLionel Sambuc 		break;
580f7cf2976SLionel Sambuc 
581f7cf2976SLionel Sambuc 	case A_F_SEARCH:
582f7cf2976SLionel Sambuc 	case A_B_SEARCH:
583f7cf2976SLionel Sambuc 	case A_FILTER:
584f7cf2976SLionel Sambuc 		ret = mca_search_char(c);
585f7cf2976SLionel Sambuc 		if (ret != NO_MCA)
586f7cf2976SLionel Sambuc 			return (ret);
587f7cf2976SLionel Sambuc 		break;
588f7cf2976SLionel Sambuc 
589f7cf2976SLionel Sambuc 	default:
590f7cf2976SLionel Sambuc 		/* Other multicharacter command. */
591f7cf2976SLionel Sambuc 		break;
592f7cf2976SLionel Sambuc 	}
593f7cf2976SLionel Sambuc 
594f7cf2976SLionel Sambuc 	/*
595f7cf2976SLionel Sambuc 	 * The multichar command is terminated by a newline.
596f7cf2976SLionel Sambuc 	 */
597f7cf2976SLionel Sambuc 	if (c == '\n' || c == '\r')
598f7cf2976SLionel Sambuc 	{
599f7cf2976SLionel Sambuc 		/*
600f7cf2976SLionel Sambuc 		 * Execute the command.
601f7cf2976SLionel Sambuc 		 */
602f7cf2976SLionel Sambuc 		exec_mca();
603f7cf2976SLionel Sambuc 		return (MCA_DONE);
604f7cf2976SLionel Sambuc 	}
605f7cf2976SLionel Sambuc 
606f7cf2976SLionel Sambuc 	/*
607f7cf2976SLionel Sambuc 	 * Append the char to the command buffer.
608f7cf2976SLionel Sambuc 	 */
609f7cf2976SLionel Sambuc 	if (cmd_char(c) == CC_QUIT)
610f7cf2976SLionel Sambuc 		/*
611f7cf2976SLionel Sambuc 		 * Abort the multi-char command.
612f7cf2976SLionel Sambuc 		 */
613f7cf2976SLionel Sambuc 		return (MCA_DONE);
614f7cf2976SLionel Sambuc 
615f7cf2976SLionel Sambuc 	if ((mca == A_F_BRACKET || mca == A_B_BRACKET) && len_cmdbuf() >= 2)
616f7cf2976SLionel Sambuc 	{
617f7cf2976SLionel Sambuc 		/*
618f7cf2976SLionel Sambuc 		 * Special case for the bracket-matching commands.
619f7cf2976SLionel Sambuc 		 * Execute the command after getting exactly two
620f7cf2976SLionel Sambuc 		 * characters from the user.
621f7cf2976SLionel Sambuc 		 */
622f7cf2976SLionel Sambuc 		exec_mca();
623f7cf2976SLionel Sambuc 		return (MCA_DONE);
624f7cf2976SLionel Sambuc 	}
625f7cf2976SLionel Sambuc 
626f7cf2976SLionel Sambuc 	/*
627f7cf2976SLionel Sambuc 	 * Need another character.
628f7cf2976SLionel Sambuc 	 */
629f7cf2976SLionel Sambuc 	return (MCA_MORE);
630f7cf2976SLionel Sambuc }
631f7cf2976SLionel Sambuc 
632f7cf2976SLionel Sambuc /*
633f7cf2976SLionel Sambuc  * Discard any buffered file data.
634f7cf2976SLionel Sambuc  */
635f7cf2976SLionel Sambuc 	static void
clear_buffers()636f7cf2976SLionel Sambuc clear_buffers()
637f7cf2976SLionel Sambuc {
638f7cf2976SLionel Sambuc 	if (!(ch_getflags() & CH_CANSEEK))
639f7cf2976SLionel Sambuc 		return;
640f7cf2976SLionel Sambuc 	ch_flush();
641f7cf2976SLionel Sambuc 	clr_linenum();
642f7cf2976SLionel Sambuc #if HILITE_SEARCH
643f7cf2976SLionel Sambuc 	clr_hilite();
644f7cf2976SLionel Sambuc #endif
645f7cf2976SLionel Sambuc }
646f7cf2976SLionel Sambuc 
647f7cf2976SLionel Sambuc /*
648f7cf2976SLionel Sambuc  * Make sure the screen is displayed.
649f7cf2976SLionel Sambuc  */
650f7cf2976SLionel Sambuc 	static void
make_display()651f7cf2976SLionel Sambuc make_display()
652f7cf2976SLionel Sambuc {
653f7cf2976SLionel Sambuc 	/*
654f7cf2976SLionel Sambuc 	 * If nothing is displayed yet, display starting from initial_scrpos.
655f7cf2976SLionel Sambuc 	 */
656f7cf2976SLionel Sambuc 	if (empty_screen())
657f7cf2976SLionel Sambuc 	{
658f7cf2976SLionel Sambuc 		if (initial_scrpos.pos == NULL_POSITION)
659f7cf2976SLionel Sambuc 			/*
660f7cf2976SLionel Sambuc 			 * {{ Maybe this should be:
661f7cf2976SLionel Sambuc 			 *    jump_loc(ch_zero(), jump_sline);
662f7cf2976SLionel Sambuc 			 *    but this behavior seems rather unexpected
663f7cf2976SLionel Sambuc 			 *    on the first screen. }}
664f7cf2976SLionel Sambuc 			 */
665f7cf2976SLionel Sambuc 			jump_loc(ch_zero(), 1);
666f7cf2976SLionel Sambuc 		else
667f7cf2976SLionel Sambuc 			jump_loc(initial_scrpos.pos, initial_scrpos.ln);
668f7cf2976SLionel Sambuc 	} else if (screen_trashed)
669f7cf2976SLionel Sambuc 	{
670f7cf2976SLionel Sambuc 		int save_top_scroll = top_scroll;
671f7cf2976SLionel Sambuc 		int save_ignore_eoi = ignore_eoi;
672f7cf2976SLionel Sambuc 		top_scroll = 1;
673f7cf2976SLionel Sambuc 		ignore_eoi = 0;
674f7cf2976SLionel Sambuc 		if (screen_trashed == 2)
675f7cf2976SLionel Sambuc 		{
676f7cf2976SLionel Sambuc 			/* Special case used by ignore_eoi: re-open the input file
677f7cf2976SLionel Sambuc 			 * and jump to the end of the file. */
678f7cf2976SLionel Sambuc 			reopen_curr_ifile();
679f7cf2976SLionel Sambuc 			jump_forw();
680f7cf2976SLionel Sambuc 		}
681f7cf2976SLionel Sambuc 		repaint();
682f7cf2976SLionel Sambuc 		top_scroll = save_top_scroll;
683f7cf2976SLionel Sambuc 		ignore_eoi = save_ignore_eoi;
684f7cf2976SLionel Sambuc 	}
685f7cf2976SLionel Sambuc }
686f7cf2976SLionel Sambuc 
687f7cf2976SLionel Sambuc /*
688f7cf2976SLionel Sambuc  * Display the appropriate prompt.
689f7cf2976SLionel Sambuc  */
690f7cf2976SLionel Sambuc 	static void
prompt()691f7cf2976SLionel Sambuc prompt()
692f7cf2976SLionel Sambuc {
693*84d9c625SLionel Sambuc 	register constant char *p;
694f7cf2976SLionel Sambuc 
695f7cf2976SLionel Sambuc 	if (ungot != NULL)
696f7cf2976SLionel Sambuc 	{
697f7cf2976SLionel Sambuc 		/*
698f7cf2976SLionel Sambuc 		 * No prompt necessary if commands are from
699f7cf2976SLionel Sambuc 		 * ungotten chars rather than from the user.
700f7cf2976SLionel Sambuc 		 */
701f7cf2976SLionel Sambuc 		return;
702f7cf2976SLionel Sambuc 	}
703f7cf2976SLionel Sambuc 
704f7cf2976SLionel Sambuc 	/*
705f7cf2976SLionel Sambuc 	 * Make sure the screen is displayed.
706f7cf2976SLionel Sambuc 	 */
707f7cf2976SLionel Sambuc 	make_display();
708f7cf2976SLionel Sambuc 	bottompos = position(BOTTOM_PLUS_ONE);
709f7cf2976SLionel Sambuc 
710f7cf2976SLionel Sambuc 	/*
711f7cf2976SLionel Sambuc 	 * If we've hit EOF on the last file and the -E flag is set, quit.
712f7cf2976SLionel Sambuc 	 */
713f7cf2976SLionel Sambuc 	if (get_quit_at_eof() == OPT_ONPLUS &&
714f7cf2976SLionel Sambuc 	    eof_displayed() && !(ch_getflags() & CH_HELPFILE) &&
715f7cf2976SLionel Sambuc 	    next_ifile(curr_ifile) == NULL_IFILE)
716f7cf2976SLionel Sambuc 		quit(QUIT_OK);
717f7cf2976SLionel Sambuc 
718f7cf2976SLionel Sambuc 	/*
719f7cf2976SLionel Sambuc 	 * If the entire file is displayed and the -F flag is set, quit.
720f7cf2976SLionel Sambuc 	 */
721f7cf2976SLionel Sambuc 	if (quit_if_one_screen &&
722f7cf2976SLionel Sambuc 	    entire_file_displayed() && !(ch_getflags() & CH_HELPFILE) &&
723f7cf2976SLionel Sambuc 	    next_ifile(curr_ifile) == NULL_IFILE)
724f7cf2976SLionel Sambuc 		quit(QUIT_OK);
725f7cf2976SLionel Sambuc 
726f7cf2976SLionel Sambuc #if MSDOS_COMPILER==WIN32C
727f7cf2976SLionel Sambuc 	/*
728f7cf2976SLionel Sambuc 	 * In Win32, display the file name in the window title.
729f7cf2976SLionel Sambuc 	 */
730f7cf2976SLionel Sambuc 	if (!(ch_getflags() & CH_HELPFILE))
731f7cf2976SLionel Sambuc 		SetConsoleTitle(pr_expand("Less?f - %f.", 0));
732f7cf2976SLionel Sambuc #endif
733f7cf2976SLionel Sambuc 	/*
734f7cf2976SLionel Sambuc 	 * Select the proper prompt and display it.
735f7cf2976SLionel Sambuc 	 */
736f7cf2976SLionel Sambuc 	/*
737f7cf2976SLionel Sambuc 	 * If the previous action was a forward movement,
738f7cf2976SLionel Sambuc 	 * don't clear the bottom line of the display;
739f7cf2976SLionel Sambuc 	 * just print the prompt since the forward movement guarantees
740f7cf2976SLionel Sambuc 	 * that we're in the right position to display the prompt.
741f7cf2976SLionel Sambuc 	 * Clearing the line could cause a problem: for example, if the last
742f7cf2976SLionel Sambuc 	 * line displayed ended at the right screen edge without a newline,
743f7cf2976SLionel Sambuc 	 * then clearing would clear the last displayed line rather than
744f7cf2976SLionel Sambuc 	 * the prompt line.
745f7cf2976SLionel Sambuc 	 */
746f7cf2976SLionel Sambuc 	if (!forw_prompt)
747f7cf2976SLionel Sambuc 		clear_bot();
748f7cf2976SLionel Sambuc 	clear_cmd();
749f7cf2976SLionel Sambuc 	forw_prompt = 0;
750f7cf2976SLionel Sambuc 	if (helpprompt) {
751f7cf2976SLionel Sambuc 		at_enter(AT_STANDOUT);
752f7cf2976SLionel Sambuc 		putstr("[Press 'h' for instructions.]");
753f7cf2976SLionel Sambuc 		at_exit();
754f7cf2976SLionel Sambuc 		helpprompt = 0;
755f7cf2976SLionel Sambuc 	} else {
756f7cf2976SLionel Sambuc 		p = pr_string();
757f7cf2976SLionel Sambuc 		if (is_filtering())
758f7cf2976SLionel Sambuc 			putstr("& ");
759f7cf2976SLionel Sambuc 		if (p == NULL || *p == '\0')
760f7cf2976SLionel Sambuc 			putchr(':');
761f7cf2976SLionel Sambuc 		else
762f7cf2976SLionel Sambuc 		{
763f7cf2976SLionel Sambuc 			at_enter(AT_STANDOUT);
764f7cf2976SLionel Sambuc 			putstr(p);
765f7cf2976SLionel Sambuc 			at_exit();
766f7cf2976SLionel Sambuc 		}
767f7cf2976SLionel Sambuc 	}
768f7cf2976SLionel Sambuc 	clear_eol();
769f7cf2976SLionel Sambuc }
770f7cf2976SLionel Sambuc 
771f7cf2976SLionel Sambuc /*
772f7cf2976SLionel Sambuc  * Display the less version message.
773f7cf2976SLionel Sambuc  */
774f7cf2976SLionel Sambuc 	public void
dispversion()775f7cf2976SLionel Sambuc dispversion()
776f7cf2976SLionel Sambuc {
777f7cf2976SLionel Sambuc 	PARG parg;
778f7cf2976SLionel Sambuc 
779f7cf2976SLionel Sambuc 	parg.p_string = version;
780f7cf2976SLionel Sambuc 	error("less %s", &parg);
781f7cf2976SLionel Sambuc }
782f7cf2976SLionel Sambuc 
783f7cf2976SLionel Sambuc /*
784f7cf2976SLionel Sambuc  * Get command character.
785f7cf2976SLionel Sambuc  * The character normally comes from the keyboard,
786f7cf2976SLionel Sambuc  * but may come from ungotten characters
787f7cf2976SLionel Sambuc  * (characters previously given to ungetcc or ungetsc).
788f7cf2976SLionel Sambuc  */
789f7cf2976SLionel Sambuc 	public int
getcc()790f7cf2976SLionel Sambuc getcc()
791f7cf2976SLionel Sambuc {
792f7cf2976SLionel Sambuc 	if (unget_end)
793f7cf2976SLionel Sambuc 	{
794f7cf2976SLionel Sambuc 		/*
795f7cf2976SLionel Sambuc 		 * We have just run out of ungotten chars.
796f7cf2976SLionel Sambuc 		 */
797f7cf2976SLionel Sambuc 		unget_end = 0;
798f7cf2976SLionel Sambuc 		if (len_cmdbuf() == 0 || !empty_screen())
799f7cf2976SLionel Sambuc 			return (getchr());
800f7cf2976SLionel Sambuc 		/*
801f7cf2976SLionel Sambuc 		 * Command is incomplete, so try to complete it.
802f7cf2976SLionel Sambuc 		 */
803f7cf2976SLionel Sambuc 		switch (mca)
804f7cf2976SLionel Sambuc 		{
805f7cf2976SLionel Sambuc 		case A_DIGIT:
806f7cf2976SLionel Sambuc 			/*
807f7cf2976SLionel Sambuc 			 * We have a number but no command.  Treat as #g.
808f7cf2976SLionel Sambuc 			 */
809f7cf2976SLionel Sambuc 			return ('g');
810f7cf2976SLionel Sambuc 
811f7cf2976SLionel Sambuc 		case A_F_SEARCH:
812f7cf2976SLionel Sambuc 		case A_B_SEARCH:
813f7cf2976SLionel Sambuc 			/*
814f7cf2976SLionel Sambuc 			 * We have "/string" but no newline.  Add the \n.
815f7cf2976SLionel Sambuc 			 */
816f7cf2976SLionel Sambuc 			return ('\n');
817f7cf2976SLionel Sambuc 
818f7cf2976SLionel Sambuc 		default:
819f7cf2976SLionel Sambuc 			/*
820f7cf2976SLionel Sambuc 			 * Some other incomplete command.  Let user complete it.
821f7cf2976SLionel Sambuc 			 */
822f7cf2976SLionel Sambuc 			return (getchr());
823f7cf2976SLionel Sambuc 		}
824f7cf2976SLionel Sambuc 	}
825f7cf2976SLionel Sambuc 
826f7cf2976SLionel Sambuc 	if (ungot == NULL)
827f7cf2976SLionel Sambuc 	{
828f7cf2976SLionel Sambuc 		/*
829f7cf2976SLionel Sambuc 		 * Normal case: no ungotten chars, so get one from the user.
830f7cf2976SLionel Sambuc 		 */
831f7cf2976SLionel Sambuc 		return (getchr());
832f7cf2976SLionel Sambuc 	}
833f7cf2976SLionel Sambuc 
834f7cf2976SLionel Sambuc 	/*
835f7cf2976SLionel Sambuc 	 * Return the next ungotten char.
836f7cf2976SLionel Sambuc 	 */
837f7cf2976SLionel Sambuc 	{
838f7cf2976SLionel Sambuc 		struct ungot *ug = ungot;
839f7cf2976SLionel Sambuc 		char c = ug->ug_char;
840f7cf2976SLionel Sambuc 		ungot = ug->ug_next;
841f7cf2976SLionel Sambuc 		free(ug);
842f7cf2976SLionel Sambuc 		unget_end = (ungot == NULL);
843f7cf2976SLionel Sambuc 		return (c);
844f7cf2976SLionel Sambuc 	}
845f7cf2976SLionel Sambuc }
846f7cf2976SLionel Sambuc 
847f7cf2976SLionel Sambuc /*
848f7cf2976SLionel Sambuc  * "Unget" a command character.
849f7cf2976SLionel Sambuc  * The next getcc() will return this character.
850f7cf2976SLionel Sambuc  */
851f7cf2976SLionel Sambuc 	public void
ungetcc(c)852f7cf2976SLionel Sambuc ungetcc(c)
853f7cf2976SLionel Sambuc 	int c;
854f7cf2976SLionel Sambuc {
855f7cf2976SLionel Sambuc 	struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot));
856f7cf2976SLionel Sambuc 
857f7cf2976SLionel Sambuc 	ug->ug_char = c;
858f7cf2976SLionel Sambuc 	ug->ug_next = ungot;
859f7cf2976SLionel Sambuc 	ungot = ug;
860f7cf2976SLionel Sambuc 	unget_end = 0;
861f7cf2976SLionel Sambuc }
862f7cf2976SLionel Sambuc 
863f7cf2976SLionel Sambuc /*
864f7cf2976SLionel Sambuc  * Unget a whole string of command characters.
865f7cf2976SLionel Sambuc  * The next sequence of getcc()'s will return this string.
866f7cf2976SLionel Sambuc  */
867f7cf2976SLionel Sambuc 	public void
ungetsc(s)868f7cf2976SLionel Sambuc ungetsc(s)
869f7cf2976SLionel Sambuc 	char *s;
870f7cf2976SLionel Sambuc {
871f7cf2976SLionel Sambuc 	register char *p;
872f7cf2976SLionel Sambuc 
873f7cf2976SLionel Sambuc 	for (p = s + strlen(s) - 1;  p >= s;  p--)
874f7cf2976SLionel Sambuc 		ungetcc(*p);
875f7cf2976SLionel Sambuc }
876f7cf2976SLionel Sambuc 
877f7cf2976SLionel Sambuc /*
878f7cf2976SLionel Sambuc  * Search for a pattern, possibly in multiple files.
879f7cf2976SLionel Sambuc  * If SRCH_FIRST_FILE is set, begin searching at the first file.
880f7cf2976SLionel Sambuc  * If SRCH_PAST_EOF is set, continue the search thru multiple files.
881f7cf2976SLionel Sambuc  */
882f7cf2976SLionel Sambuc 	static void
multi_search(pattern,n)883f7cf2976SLionel Sambuc multi_search(pattern, n)
884f7cf2976SLionel Sambuc 	char *pattern;
885f7cf2976SLionel Sambuc 	int n;
886f7cf2976SLionel Sambuc {
887f7cf2976SLionel Sambuc 	register int nomore;
888f7cf2976SLionel Sambuc 	IFILE save_ifile;
889f7cf2976SLionel Sambuc 	int changed_file;
890f7cf2976SLionel Sambuc 
891f7cf2976SLionel Sambuc 	changed_file = 0;
892f7cf2976SLionel Sambuc 	save_ifile = save_curr_ifile();
893f7cf2976SLionel Sambuc 
894f7cf2976SLionel Sambuc 	if (search_type & SRCH_FIRST_FILE)
895f7cf2976SLionel Sambuc 	{
896f7cf2976SLionel Sambuc 		/*
897f7cf2976SLionel Sambuc 		 * Start at the first (or last) file
898f7cf2976SLionel Sambuc 		 * in the command line list.
899f7cf2976SLionel Sambuc 		 */
900f7cf2976SLionel Sambuc 		if (search_type & SRCH_FORW)
901f7cf2976SLionel Sambuc 			nomore = edit_first();
902f7cf2976SLionel Sambuc 		else
903f7cf2976SLionel Sambuc 			nomore = edit_last();
904f7cf2976SLionel Sambuc 		if (nomore)
905f7cf2976SLionel Sambuc 		{
906f7cf2976SLionel Sambuc 			unsave_ifile(save_ifile);
907f7cf2976SLionel Sambuc 			return;
908f7cf2976SLionel Sambuc 		}
909f7cf2976SLionel Sambuc 		changed_file = 1;
910f7cf2976SLionel Sambuc 		search_type &= ~SRCH_FIRST_FILE;
911f7cf2976SLionel Sambuc 	}
912f7cf2976SLionel Sambuc 
913f7cf2976SLionel Sambuc 	for (;;)
914f7cf2976SLionel Sambuc 	{
915f7cf2976SLionel Sambuc 		n = search(search_type, pattern, n);
916f7cf2976SLionel Sambuc 		/*
917f7cf2976SLionel Sambuc 		 * The SRCH_NO_MOVE flag doesn't "stick": it gets cleared
918f7cf2976SLionel Sambuc 		 * after being used once.  This allows "n" to work after
919f7cf2976SLionel Sambuc 		 * using a /@@ search.
920f7cf2976SLionel Sambuc 		 */
921f7cf2976SLionel Sambuc 		search_type &= ~SRCH_NO_MOVE;
922f7cf2976SLionel Sambuc 		if (n == 0)
923f7cf2976SLionel Sambuc 		{
924f7cf2976SLionel Sambuc 			/*
925f7cf2976SLionel Sambuc 			 * Found it.
926f7cf2976SLionel Sambuc 			 */
927f7cf2976SLionel Sambuc 			unsave_ifile(save_ifile);
928f7cf2976SLionel Sambuc 			return;
929f7cf2976SLionel Sambuc 		}
930f7cf2976SLionel Sambuc 
931f7cf2976SLionel Sambuc 		if (n < 0)
932f7cf2976SLionel Sambuc 			/*
933f7cf2976SLionel Sambuc 			 * Some kind of error in the search.
934f7cf2976SLionel Sambuc 			 * Error message has been printed by search().
935f7cf2976SLionel Sambuc 			 */
936f7cf2976SLionel Sambuc 			break;
937f7cf2976SLionel Sambuc 
938f7cf2976SLionel Sambuc 		if ((search_type & SRCH_PAST_EOF) == 0)
939f7cf2976SLionel Sambuc 			/*
940f7cf2976SLionel Sambuc 			 * We didn't find a match, but we're
941f7cf2976SLionel Sambuc 			 * supposed to search only one file.
942f7cf2976SLionel Sambuc 			 */
943f7cf2976SLionel Sambuc 			break;
944f7cf2976SLionel Sambuc 		/*
945f7cf2976SLionel Sambuc 		 * Move on to the next file.
946f7cf2976SLionel Sambuc 		 */
947f7cf2976SLionel Sambuc 		if (search_type & SRCH_FORW)
948f7cf2976SLionel Sambuc 			nomore = edit_next(1);
949f7cf2976SLionel Sambuc 		else
950f7cf2976SLionel Sambuc 			nomore = edit_prev(1);
951f7cf2976SLionel Sambuc 		if (nomore)
952f7cf2976SLionel Sambuc 			break;
953f7cf2976SLionel Sambuc 		changed_file = 1;
954f7cf2976SLionel Sambuc 	}
955f7cf2976SLionel Sambuc 
956f7cf2976SLionel Sambuc 	/*
957f7cf2976SLionel Sambuc 	 * Didn't find it.
958f7cf2976SLionel Sambuc 	 * Print an error message if we haven't already.
959f7cf2976SLionel Sambuc 	 */
960f7cf2976SLionel Sambuc 	if (n > 0)
961f7cf2976SLionel Sambuc 		error("Pattern not found", NULL_PARG);
962f7cf2976SLionel Sambuc 
963f7cf2976SLionel Sambuc 	if (changed_file)
964f7cf2976SLionel Sambuc 	{
965f7cf2976SLionel Sambuc 		/*
966f7cf2976SLionel Sambuc 		 * Restore the file we were originally viewing.
967f7cf2976SLionel Sambuc 		 */
968f7cf2976SLionel Sambuc 		reedit_ifile(save_ifile);
969f7cf2976SLionel Sambuc 	} else
970f7cf2976SLionel Sambuc 	{
971f7cf2976SLionel Sambuc 		unsave_ifile(save_ifile);
972f7cf2976SLionel Sambuc 	}
973f7cf2976SLionel Sambuc }
974f7cf2976SLionel Sambuc 
975f7cf2976SLionel Sambuc /*
976*84d9c625SLionel Sambuc  * Forward forever, or until a highlighted line appears.
977*84d9c625SLionel Sambuc  */
978*84d9c625SLionel Sambuc 	static int
forw_loop(until_hilite)979*84d9c625SLionel Sambuc forw_loop(until_hilite)
980*84d9c625SLionel Sambuc 	int until_hilite;
981*84d9c625SLionel Sambuc {
982*84d9c625SLionel Sambuc 	POSITION curr_len;
983*84d9c625SLionel Sambuc 
984*84d9c625SLionel Sambuc 	if (ch_getflags() & CH_HELPFILE)
985*84d9c625SLionel Sambuc 		return (A_NOACTION);
986*84d9c625SLionel Sambuc 
987*84d9c625SLionel Sambuc 	cmd_exec();
988*84d9c625SLionel Sambuc 	jump_forw();
989*84d9c625SLionel Sambuc 	curr_len = ch_length();
990*84d9c625SLionel Sambuc 	highest_hilite = until_hilite ? curr_len : NULL_POSITION;
991*84d9c625SLionel Sambuc 	ignore_eoi = 1;
992*84d9c625SLionel Sambuc 	while (!sigs)
993*84d9c625SLionel Sambuc 	{
994*84d9c625SLionel Sambuc 		if (until_hilite && highest_hilite > curr_len)
995*84d9c625SLionel Sambuc 		{
996*84d9c625SLionel Sambuc 			bell();
997*84d9c625SLionel Sambuc 			break;
998*84d9c625SLionel Sambuc 		}
999*84d9c625SLionel Sambuc 		make_display();
1000*84d9c625SLionel Sambuc 		forward(1, 0, 0);
1001*84d9c625SLionel Sambuc 	}
1002*84d9c625SLionel Sambuc 	ignore_eoi = 0;
1003*84d9c625SLionel Sambuc 	ch_set_eof();
1004*84d9c625SLionel Sambuc 
1005*84d9c625SLionel Sambuc 	/*
1006*84d9c625SLionel Sambuc 	 * This gets us back in "F mode" after processing
1007*84d9c625SLionel Sambuc 	 * a non-abort signal (e.g. window-change).
1008*84d9c625SLionel Sambuc 	 */
1009*84d9c625SLionel Sambuc 	if (sigs && !ABORT_SIGS())
1010*84d9c625SLionel Sambuc 		return (until_hilite ? A_F_UNTIL_HILITE : A_F_FOREVER);
1011*84d9c625SLionel Sambuc 
1012*84d9c625SLionel Sambuc 	return (A_NOACTION);
1013*84d9c625SLionel Sambuc }
1014*84d9c625SLionel Sambuc 
1015*84d9c625SLionel Sambuc /*
1016f7cf2976SLionel Sambuc  * Main command processor.
1017f7cf2976SLionel Sambuc  * Accept and execute commands until a quit command.
1018f7cf2976SLionel Sambuc  */
1019f7cf2976SLionel Sambuc 	public void
commands()1020f7cf2976SLionel Sambuc commands()
1021f7cf2976SLionel Sambuc {
1022f7cf2976SLionel Sambuc 	register int c;
1023f7cf2976SLionel Sambuc 	register int action;
1024f7cf2976SLionel Sambuc 	register char *cbuf;
1025f7cf2976SLionel Sambuc 	int newaction;
1026f7cf2976SLionel Sambuc 	int save_search_type;
1027f7cf2976SLionel Sambuc 	char *extra;
1028f7cf2976SLionel Sambuc 	char tbuf[2];
1029f7cf2976SLionel Sambuc 	PARG parg;
1030f7cf2976SLionel Sambuc 	IFILE old_ifile;
1031f7cf2976SLionel Sambuc 	IFILE new_ifile;
1032f7cf2976SLionel Sambuc 	char *tagfile;
1033*84d9c625SLionel Sambuc 	int until_hilite = 0;
1034f7cf2976SLionel Sambuc 
1035f7cf2976SLionel Sambuc 	search_type = SRCH_FORW;
1036f7cf2976SLionel Sambuc 	wscroll = (sc_height + 1) / 2;
1037f7cf2976SLionel Sambuc 	newaction = A_NOACTION;
1038f7cf2976SLionel Sambuc 
1039f7cf2976SLionel Sambuc 	for (;;)
1040f7cf2976SLionel Sambuc 	{
1041f7cf2976SLionel Sambuc 		mca = 0;
1042f7cf2976SLionel Sambuc 		cmd_accept();
1043f7cf2976SLionel Sambuc 		number = 0;
1044f7cf2976SLionel Sambuc 		curropt = NULL;
1045f7cf2976SLionel Sambuc 
1046f7cf2976SLionel Sambuc 		/*
1047f7cf2976SLionel Sambuc 		 * See if any signals need processing.
1048f7cf2976SLionel Sambuc 		 */
1049f7cf2976SLionel Sambuc 		if (sigs)
1050f7cf2976SLionel Sambuc 		{
1051f7cf2976SLionel Sambuc 			psignals();
1052f7cf2976SLionel Sambuc 			if (quitting)
1053f7cf2976SLionel Sambuc 				quit(QUIT_SAVED_STATUS);
1054f7cf2976SLionel Sambuc 		}
1055f7cf2976SLionel Sambuc 
1056f7cf2976SLionel Sambuc 		/*
1057f7cf2976SLionel Sambuc 		 * See if window size changed, for systems that don't
1058f7cf2976SLionel Sambuc 		 * generate SIGWINCH.
1059f7cf2976SLionel Sambuc 		 */
1060f7cf2976SLionel Sambuc 		check_winch();
1061f7cf2976SLionel Sambuc 
1062f7cf2976SLionel Sambuc 		/*
1063f7cf2976SLionel Sambuc 		 * Display prompt and accept a character.
1064f7cf2976SLionel Sambuc 		 */
1065f7cf2976SLionel Sambuc 		cmd_reset();
1066f7cf2976SLionel Sambuc 		prompt();
1067f7cf2976SLionel Sambuc 		if (sigs)
1068f7cf2976SLionel Sambuc 			continue;
1069f7cf2976SLionel Sambuc 		if (newaction == A_NOACTION)
1070f7cf2976SLionel Sambuc 			c = getcc();
1071f7cf2976SLionel Sambuc 
1072f7cf2976SLionel Sambuc 	again:
1073f7cf2976SLionel Sambuc 		if (sigs)
1074f7cf2976SLionel Sambuc 			continue;
1075f7cf2976SLionel Sambuc 
1076f7cf2976SLionel Sambuc 		if (newaction != A_NOACTION)
1077f7cf2976SLionel Sambuc 		{
1078f7cf2976SLionel Sambuc 			action = newaction;
1079f7cf2976SLionel Sambuc 			newaction = A_NOACTION;
1080f7cf2976SLionel Sambuc 		} else
1081f7cf2976SLionel Sambuc 		{
1082f7cf2976SLionel Sambuc 			/*
1083f7cf2976SLionel Sambuc 			 * If we are in a multicharacter command, call mca_char.
1084f7cf2976SLionel Sambuc 			 * Otherwise we call fcmd_decode to determine the
1085f7cf2976SLionel Sambuc 			 * action to be performed.
1086f7cf2976SLionel Sambuc 			 */
1087f7cf2976SLionel Sambuc 			if (mca)
1088f7cf2976SLionel Sambuc 				switch (mca_char(c))
1089f7cf2976SLionel Sambuc 				{
1090f7cf2976SLionel Sambuc 				case MCA_MORE:
1091f7cf2976SLionel Sambuc 					/*
1092f7cf2976SLionel Sambuc 					 * Need another character.
1093f7cf2976SLionel Sambuc 					 */
1094f7cf2976SLionel Sambuc 					c = getcc();
1095f7cf2976SLionel Sambuc 					goto again;
1096f7cf2976SLionel Sambuc 				case MCA_DONE:
1097f7cf2976SLionel Sambuc 					/*
1098f7cf2976SLionel Sambuc 					 * Command has been handled by mca_char.
1099f7cf2976SLionel Sambuc 					 * Start clean with a prompt.
1100f7cf2976SLionel Sambuc 					 */
1101f7cf2976SLionel Sambuc 					continue;
1102f7cf2976SLionel Sambuc 				case NO_MCA:
1103f7cf2976SLionel Sambuc 					/*
1104f7cf2976SLionel Sambuc 					 * Not a multi-char command
1105f7cf2976SLionel Sambuc 					 * (at least, not anymore).
1106f7cf2976SLionel Sambuc 					 */
1107f7cf2976SLionel Sambuc 					break;
1108f7cf2976SLionel Sambuc 				}
1109f7cf2976SLionel Sambuc 
1110f7cf2976SLionel Sambuc 			/*
1111f7cf2976SLionel Sambuc 			 * Decode the command character and decide what to do.
1112f7cf2976SLionel Sambuc 			 */
1113f7cf2976SLionel Sambuc 			if (mca)
1114f7cf2976SLionel Sambuc 			{
1115f7cf2976SLionel Sambuc 				/*
1116f7cf2976SLionel Sambuc 				 * We're in a multichar command.
1117f7cf2976SLionel Sambuc 				 * Add the character to the command buffer
1118f7cf2976SLionel Sambuc 				 * and display it on the screen.
1119f7cf2976SLionel Sambuc 				 * If the user backspaces past the start
1120f7cf2976SLionel Sambuc 				 * of the line, abort the command.
1121f7cf2976SLionel Sambuc 				 */
1122f7cf2976SLionel Sambuc 				if (cmd_char(c) == CC_QUIT || len_cmdbuf() == 0)
1123f7cf2976SLionel Sambuc 					continue;
1124f7cf2976SLionel Sambuc 				cbuf = get_cmdbuf();
1125f7cf2976SLionel Sambuc 			} else
1126f7cf2976SLionel Sambuc 			{
1127f7cf2976SLionel Sambuc 				/*
1128f7cf2976SLionel Sambuc 				 * Don't use cmd_char if we're starting fresh
1129f7cf2976SLionel Sambuc 				 * at the beginning of a command, because we
1130f7cf2976SLionel Sambuc 				 * don't want to echo the command until we know
1131f7cf2976SLionel Sambuc 				 * it is a multichar command.  We also don't
1132f7cf2976SLionel Sambuc 				 * want erase_char/kill_char to be treated
1133f7cf2976SLionel Sambuc 				 * as line editing characters.
1134f7cf2976SLionel Sambuc 				 */
1135f7cf2976SLionel Sambuc 				tbuf[0] = c;
1136f7cf2976SLionel Sambuc 				tbuf[1] = '\0';
1137f7cf2976SLionel Sambuc 				cbuf = tbuf;
1138f7cf2976SLionel Sambuc 			}
1139f7cf2976SLionel Sambuc 			extra = NULL;
1140f7cf2976SLionel Sambuc 			action = fcmd_decode(cbuf, &extra);
1141f7cf2976SLionel Sambuc 			/*
1142f7cf2976SLionel Sambuc 			 * If an "extra" string was returned,
1143f7cf2976SLionel Sambuc 			 * process it as a string of command characters.
1144f7cf2976SLionel Sambuc 			 */
1145f7cf2976SLionel Sambuc 			if (extra != NULL)
1146f7cf2976SLionel Sambuc 				ungetsc(extra);
1147f7cf2976SLionel Sambuc 		}
1148f7cf2976SLionel Sambuc 		/*
1149f7cf2976SLionel Sambuc 		 * Clear the cmdbuf string.
1150f7cf2976SLionel Sambuc 		 * (But not if we're in the prefix of a command,
1151f7cf2976SLionel Sambuc 		 * because the partial command string is kept there.)
1152f7cf2976SLionel Sambuc 		 */
1153f7cf2976SLionel Sambuc 		if (action != A_PREFIX)
1154f7cf2976SLionel Sambuc 			cmd_reset();
1155f7cf2976SLionel Sambuc 
1156f7cf2976SLionel Sambuc 		switch (action)
1157f7cf2976SLionel Sambuc 		{
1158f7cf2976SLionel Sambuc 		case A_DIGIT:
1159f7cf2976SLionel Sambuc 			/*
1160f7cf2976SLionel Sambuc 			 * First digit of a number.
1161f7cf2976SLionel Sambuc 			 */
1162f7cf2976SLionel Sambuc 			start_mca(A_DIGIT, ":", (void*)NULL, CF_QUIT_ON_ERASE);
1163f7cf2976SLionel Sambuc 			goto again;
1164f7cf2976SLionel Sambuc 
1165f7cf2976SLionel Sambuc 		case A_F_WINDOW:
1166f7cf2976SLionel Sambuc 			/*
1167f7cf2976SLionel Sambuc 			 * Forward one window (and set the window size).
1168f7cf2976SLionel Sambuc 			 */
1169f7cf2976SLionel Sambuc 			if (number > 0)
1170f7cf2976SLionel Sambuc 				swindow = (int) number;
1171f7cf2976SLionel Sambuc 			/* FALLTHRU */
1172f7cf2976SLionel Sambuc 		case A_F_SCREEN:
1173f7cf2976SLionel Sambuc 			/*
1174f7cf2976SLionel Sambuc 			 * Forward one screen.
1175f7cf2976SLionel Sambuc 			 */
1176f7cf2976SLionel Sambuc 			if (number <= 0)
1177f7cf2976SLionel Sambuc 				number = get_swindow();
1178f7cf2976SLionel Sambuc 			cmd_exec();
1179f7cf2976SLionel Sambuc 			if (show_attn)
1180f7cf2976SLionel Sambuc 				set_attnpos(bottompos);
1181f7cf2976SLionel Sambuc 			forward((int) number, 0, 1);
1182f7cf2976SLionel Sambuc 			break;
1183f7cf2976SLionel Sambuc 
1184f7cf2976SLionel Sambuc 		case A_B_WINDOW:
1185f7cf2976SLionel Sambuc 			/*
1186f7cf2976SLionel Sambuc 			 * Backward one window (and set the window size).
1187f7cf2976SLionel Sambuc 			 */
1188f7cf2976SLionel Sambuc 			if (number > 0)
1189f7cf2976SLionel Sambuc 				swindow = (int) number;
1190f7cf2976SLionel Sambuc 			/* FALLTHRU */
1191f7cf2976SLionel Sambuc 		case A_B_SCREEN:
1192f7cf2976SLionel Sambuc 			/*
1193f7cf2976SLionel Sambuc 			 * Backward one screen.
1194f7cf2976SLionel Sambuc 			 */
1195f7cf2976SLionel Sambuc 			if (number <= 0)
1196f7cf2976SLionel Sambuc 				number = get_swindow();
1197f7cf2976SLionel Sambuc 			cmd_exec();
1198f7cf2976SLionel Sambuc 			backward((int) number, 0, 1);
1199f7cf2976SLionel Sambuc 			break;
1200f7cf2976SLionel Sambuc 
1201f7cf2976SLionel Sambuc 		case A_F_LINE:
1202f7cf2976SLionel Sambuc 			/*
1203f7cf2976SLionel Sambuc 			 * Forward N (default 1) line.
1204f7cf2976SLionel Sambuc 			 */
1205f7cf2976SLionel Sambuc 			if (number <= 0)
1206f7cf2976SLionel Sambuc 				number = 1;
1207f7cf2976SLionel Sambuc 			cmd_exec();
1208f7cf2976SLionel Sambuc 			if (show_attn == OPT_ONPLUS && number > 1)
1209f7cf2976SLionel Sambuc 				set_attnpos(bottompos);
1210f7cf2976SLionel Sambuc 			forward((int) number, 0, 0);
1211f7cf2976SLionel Sambuc 			break;
1212f7cf2976SLionel Sambuc 
1213f7cf2976SLionel Sambuc 		case A_B_LINE:
1214f7cf2976SLionel Sambuc 			/*
1215f7cf2976SLionel Sambuc 			 * Backward N (default 1) line.
1216f7cf2976SLionel Sambuc 			 */
1217f7cf2976SLionel Sambuc 			if (number <= 0)
1218f7cf2976SLionel Sambuc 				number = 1;
1219f7cf2976SLionel Sambuc 			cmd_exec();
1220f7cf2976SLionel Sambuc 			backward((int) number, 0, 0);
1221f7cf2976SLionel Sambuc 			break;
1222f7cf2976SLionel Sambuc 
1223f7cf2976SLionel Sambuc 		case A_FF_LINE:
1224f7cf2976SLionel Sambuc 			/*
1225f7cf2976SLionel Sambuc 			 * Force forward N (default 1) line.
1226f7cf2976SLionel Sambuc 			 */
1227f7cf2976SLionel Sambuc 			if (number <= 0)
1228f7cf2976SLionel Sambuc 				number = 1;
1229f7cf2976SLionel Sambuc 			cmd_exec();
1230f7cf2976SLionel Sambuc 			if (show_attn == OPT_ONPLUS && number > 1)
1231f7cf2976SLionel Sambuc 				set_attnpos(bottompos);
1232f7cf2976SLionel Sambuc 			forward((int) number, 1, 0);
1233f7cf2976SLionel Sambuc 			break;
1234f7cf2976SLionel Sambuc 
1235f7cf2976SLionel Sambuc 		case A_BF_LINE:
1236f7cf2976SLionel Sambuc 			/*
1237f7cf2976SLionel Sambuc 			 * Force backward N (default 1) line.
1238f7cf2976SLionel Sambuc 			 */
1239f7cf2976SLionel Sambuc 			if (number <= 0)
1240f7cf2976SLionel Sambuc 				number = 1;
1241f7cf2976SLionel Sambuc 			cmd_exec();
1242f7cf2976SLionel Sambuc 			backward((int) number, 1, 0);
1243f7cf2976SLionel Sambuc 			break;
1244f7cf2976SLionel Sambuc 
1245f7cf2976SLionel Sambuc 		case A_FF_SCREEN:
1246f7cf2976SLionel Sambuc 			/*
1247f7cf2976SLionel Sambuc 			 * Force forward one screen.
1248f7cf2976SLionel Sambuc 			 */
1249f7cf2976SLionel Sambuc 			if (number <= 0)
1250f7cf2976SLionel Sambuc 				number = get_swindow();
1251f7cf2976SLionel Sambuc 			cmd_exec();
1252f7cf2976SLionel Sambuc 			if (show_attn == OPT_ONPLUS)
1253f7cf2976SLionel Sambuc 				set_attnpos(bottompos);
1254f7cf2976SLionel Sambuc 			forward((int) number, 1, 0);
1255f7cf2976SLionel Sambuc 			break;
1256f7cf2976SLionel Sambuc 
1257f7cf2976SLionel Sambuc 		case A_F_FOREVER:
1258f7cf2976SLionel Sambuc 			/*
1259f7cf2976SLionel Sambuc 			 * Forward forever, ignoring EOF.
1260f7cf2976SLionel Sambuc 			 */
1261*84d9c625SLionel Sambuc 			newaction = forw_loop(0);
1262f7cf2976SLionel Sambuc 			break;
1263*84d9c625SLionel Sambuc 
1264*84d9c625SLionel Sambuc 		case A_F_UNTIL_HILITE:
1265*84d9c625SLionel Sambuc 			newaction = forw_loop(1);
1266f7cf2976SLionel Sambuc 			break;
1267f7cf2976SLionel Sambuc 
1268f7cf2976SLionel Sambuc 		case A_F_SCROLL:
1269f7cf2976SLionel Sambuc 			/*
1270f7cf2976SLionel Sambuc 			 * Forward N lines
1271f7cf2976SLionel Sambuc 			 * (default same as last 'd' or 'u' command).
1272f7cf2976SLionel Sambuc 			 */
1273f7cf2976SLionel Sambuc 			if (number > 0)
1274f7cf2976SLionel Sambuc 				wscroll = (int) number;
1275f7cf2976SLionel Sambuc 			cmd_exec();
1276f7cf2976SLionel Sambuc 			if (show_attn == OPT_ONPLUS)
1277f7cf2976SLionel Sambuc 				set_attnpos(bottompos);
1278f7cf2976SLionel Sambuc 			forward(wscroll, 0, 0);
1279f7cf2976SLionel Sambuc 			break;
1280f7cf2976SLionel Sambuc 
1281f7cf2976SLionel Sambuc 		case A_B_SCROLL:
1282f7cf2976SLionel Sambuc 			/*
1283f7cf2976SLionel Sambuc 			 * Forward N lines
1284f7cf2976SLionel Sambuc 			 * (default same as last 'd' or 'u' command).
1285f7cf2976SLionel Sambuc 			 */
1286f7cf2976SLionel Sambuc 			if (number > 0)
1287f7cf2976SLionel Sambuc 				wscroll = (int) number;
1288f7cf2976SLionel Sambuc 			cmd_exec();
1289f7cf2976SLionel Sambuc 			backward(wscroll, 0, 0);
1290f7cf2976SLionel Sambuc 			break;
1291f7cf2976SLionel Sambuc 
1292f7cf2976SLionel Sambuc 		case A_FREPAINT:
1293f7cf2976SLionel Sambuc 			/*
1294f7cf2976SLionel Sambuc 			 * Flush buffers, then repaint screen.
1295f7cf2976SLionel Sambuc 			 * Don't flush the buffers on a pipe!
1296f7cf2976SLionel Sambuc 			 */
1297f7cf2976SLionel Sambuc 			clear_buffers();
1298f7cf2976SLionel Sambuc 			/* FALLTHRU */
1299f7cf2976SLionel Sambuc 		case A_REPAINT:
1300f7cf2976SLionel Sambuc 			/*
1301f7cf2976SLionel Sambuc 			 * Repaint screen.
1302f7cf2976SLionel Sambuc 			 */
1303f7cf2976SLionel Sambuc 			cmd_exec();
1304f7cf2976SLionel Sambuc 			repaint();
1305f7cf2976SLionel Sambuc 			break;
1306f7cf2976SLionel Sambuc 
1307f7cf2976SLionel Sambuc 		case A_GOLINE:
1308f7cf2976SLionel Sambuc 			/*
1309f7cf2976SLionel Sambuc 			 * Go to line N, default beginning of file.
1310f7cf2976SLionel Sambuc 			 */
1311f7cf2976SLionel Sambuc 			if (number <= 0)
1312f7cf2976SLionel Sambuc 				number = 1;
1313f7cf2976SLionel Sambuc 			cmd_exec();
1314f7cf2976SLionel Sambuc 			jump_back(number);
1315f7cf2976SLionel Sambuc 			break;
1316f7cf2976SLionel Sambuc 
1317f7cf2976SLionel Sambuc 		case A_PERCENT:
1318f7cf2976SLionel Sambuc 			/*
1319f7cf2976SLionel Sambuc 			 * Go to a specified percentage into the file.
1320f7cf2976SLionel Sambuc 			 */
1321f7cf2976SLionel Sambuc 			if (number < 0)
1322f7cf2976SLionel Sambuc 			{
1323f7cf2976SLionel Sambuc 				number = 0;
1324f7cf2976SLionel Sambuc 				fraction = 0;
1325f7cf2976SLionel Sambuc 			}
1326f7cf2976SLionel Sambuc 			if (number > 100)
1327f7cf2976SLionel Sambuc 			{
1328f7cf2976SLionel Sambuc 				number = 100;
1329f7cf2976SLionel Sambuc 				fraction = 0;
1330f7cf2976SLionel Sambuc 			}
1331f7cf2976SLionel Sambuc 			cmd_exec();
1332f7cf2976SLionel Sambuc 			jump_percent((int) number, fraction);
1333f7cf2976SLionel Sambuc 			break;
1334f7cf2976SLionel Sambuc 
1335f7cf2976SLionel Sambuc 		case A_GOEND:
1336f7cf2976SLionel Sambuc 			/*
1337f7cf2976SLionel Sambuc 			 * Go to line N, default end of file.
1338f7cf2976SLionel Sambuc 			 */
1339f7cf2976SLionel Sambuc 			cmd_exec();
1340f7cf2976SLionel Sambuc 			if (number <= 0)
1341f7cf2976SLionel Sambuc 				jump_forw();
1342f7cf2976SLionel Sambuc 			else
1343f7cf2976SLionel Sambuc 				jump_back(number);
1344f7cf2976SLionel Sambuc 			break;
1345f7cf2976SLionel Sambuc 
1346f7cf2976SLionel Sambuc 		case A_GOPOS:
1347f7cf2976SLionel Sambuc 			/*
1348f7cf2976SLionel Sambuc 			 * Go to a specified byte position in the file.
1349f7cf2976SLionel Sambuc 			 */
1350f7cf2976SLionel Sambuc 			cmd_exec();
1351f7cf2976SLionel Sambuc 			if (number < 0)
1352f7cf2976SLionel Sambuc 				number = 0;
1353f7cf2976SLionel Sambuc 			jump_line_loc((POSITION) number, jump_sline);
1354f7cf2976SLionel Sambuc 			break;
1355f7cf2976SLionel Sambuc 
1356f7cf2976SLionel Sambuc 		case A_STAT:
1357f7cf2976SLionel Sambuc 			/*
1358f7cf2976SLionel Sambuc 			 * Print file name, etc.
1359f7cf2976SLionel Sambuc 			 */
1360f7cf2976SLionel Sambuc 			if (ch_getflags() & CH_HELPFILE)
1361f7cf2976SLionel Sambuc 				break;
1362f7cf2976SLionel Sambuc 			cmd_exec();
1363f7cf2976SLionel Sambuc 			parg.p_string = eq_message();
1364f7cf2976SLionel Sambuc 			error("%s", &parg);
1365f7cf2976SLionel Sambuc 			break;
1366f7cf2976SLionel Sambuc 
1367f7cf2976SLionel Sambuc 		case A_VERSION:
1368f7cf2976SLionel Sambuc 			/*
1369f7cf2976SLionel Sambuc 			 * Print version number, without the "@(#)".
1370f7cf2976SLionel Sambuc 			 */
1371f7cf2976SLionel Sambuc 			cmd_exec();
1372f7cf2976SLionel Sambuc 			dispversion();
1373f7cf2976SLionel Sambuc 			break;
1374f7cf2976SLionel Sambuc 
1375f7cf2976SLionel Sambuc 		case A_QUIT:
1376f7cf2976SLionel Sambuc 			/*
1377f7cf2976SLionel Sambuc 			 * Exit.
1378f7cf2976SLionel Sambuc 			 */
1379f7cf2976SLionel Sambuc 			if (curr_ifile != NULL_IFILE &&
1380f7cf2976SLionel Sambuc 			    ch_getflags() & CH_HELPFILE)
1381f7cf2976SLionel Sambuc 			{
1382f7cf2976SLionel Sambuc 				/*
1383f7cf2976SLionel Sambuc 				 * Quit while viewing the help file
1384f7cf2976SLionel Sambuc 				 * just means return to viewing the
1385f7cf2976SLionel Sambuc 				 * previous file.
1386f7cf2976SLionel Sambuc 				 */
1387f7cf2976SLionel Sambuc 				hshift = save_hshift;
1388f7cf2976SLionel Sambuc 				if (edit_prev(1) == 0)
1389f7cf2976SLionel Sambuc 					break;
1390f7cf2976SLionel Sambuc 			}
1391f7cf2976SLionel Sambuc 			if (extra != NULL)
1392f7cf2976SLionel Sambuc 				quit(*extra);
1393f7cf2976SLionel Sambuc 			quit(QUIT_OK);
1394f7cf2976SLionel Sambuc 			break;
1395f7cf2976SLionel Sambuc 
1396f7cf2976SLionel Sambuc /*
1397f7cf2976SLionel Sambuc  * Define abbreviation for a commonly used sequence below.
1398f7cf2976SLionel Sambuc  */
1399f7cf2976SLionel Sambuc #define	DO_SEARCH() \
1400f7cf2976SLionel Sambuc 			if (number <= 0) number = 1;	\
1401f7cf2976SLionel Sambuc 			mca_search();			\
1402f7cf2976SLionel Sambuc 			cmd_exec();			\
1403f7cf2976SLionel Sambuc 			multi_search((char *)NULL, (int) number);
1404f7cf2976SLionel Sambuc 
1405f7cf2976SLionel Sambuc 
1406f7cf2976SLionel Sambuc 		case A_F_SEARCH:
1407f7cf2976SLionel Sambuc 			/*
1408f7cf2976SLionel Sambuc 			 * Search forward for a pattern.
1409f7cf2976SLionel Sambuc 			 * Get the first char of the pattern.
1410f7cf2976SLionel Sambuc 			 */
1411f7cf2976SLionel Sambuc 			search_type = SRCH_FORW;
1412f7cf2976SLionel Sambuc 			if (number <= 0)
1413f7cf2976SLionel Sambuc 				number = 1;
1414f7cf2976SLionel Sambuc 			mca_search();
1415f7cf2976SLionel Sambuc 			c = getcc();
1416f7cf2976SLionel Sambuc 			goto again;
1417f7cf2976SLionel Sambuc 
1418f7cf2976SLionel Sambuc 		case A_B_SEARCH:
1419f7cf2976SLionel Sambuc 			/*
1420f7cf2976SLionel Sambuc 			 * Search backward for a pattern.
1421f7cf2976SLionel Sambuc 			 * Get the first char of the pattern.
1422f7cf2976SLionel Sambuc 			 */
1423f7cf2976SLionel Sambuc 			search_type = SRCH_BACK;
1424f7cf2976SLionel Sambuc 			if (number <= 0)
1425f7cf2976SLionel Sambuc 				number = 1;
1426f7cf2976SLionel Sambuc 			mca_search();
1427f7cf2976SLionel Sambuc 			c = getcc();
1428f7cf2976SLionel Sambuc 			goto again;
1429f7cf2976SLionel Sambuc 
1430f7cf2976SLionel Sambuc 		case A_FILTER:
1431f7cf2976SLionel Sambuc #if HILITE_SEARCH
1432f7cf2976SLionel Sambuc 			search_type = SRCH_FORW | SRCH_FILTER;
1433f7cf2976SLionel Sambuc 			mca_search();
1434f7cf2976SLionel Sambuc 			c = getcc();
1435f7cf2976SLionel Sambuc 			goto again;
1436f7cf2976SLionel Sambuc #else
1437f7cf2976SLionel Sambuc 			error("Command not available", NULL_PARG);
1438f7cf2976SLionel Sambuc 			break;
1439f7cf2976SLionel Sambuc #endif
1440f7cf2976SLionel Sambuc 
1441f7cf2976SLionel Sambuc 		case A_AGAIN_SEARCH:
1442f7cf2976SLionel Sambuc 			/*
1443f7cf2976SLionel Sambuc 			 * Repeat previous search.
1444f7cf2976SLionel Sambuc 			 */
1445f7cf2976SLionel Sambuc 			DO_SEARCH();
1446f7cf2976SLionel Sambuc 			break;
1447f7cf2976SLionel Sambuc 
1448f7cf2976SLionel Sambuc 		case A_T_AGAIN_SEARCH:
1449f7cf2976SLionel Sambuc 			/*
1450f7cf2976SLionel Sambuc 			 * Repeat previous search, multiple files.
1451f7cf2976SLionel Sambuc 			 */
1452f7cf2976SLionel Sambuc 			search_type |= SRCH_PAST_EOF;
1453f7cf2976SLionel Sambuc 			DO_SEARCH();
1454f7cf2976SLionel Sambuc 			break;
1455f7cf2976SLionel Sambuc 
1456f7cf2976SLionel Sambuc 		case A_REVERSE_SEARCH:
1457f7cf2976SLionel Sambuc 			/*
1458f7cf2976SLionel Sambuc 			 * Repeat previous search, in reverse direction.
1459f7cf2976SLionel Sambuc 			 */
1460f7cf2976SLionel Sambuc 			save_search_type = search_type;
1461f7cf2976SLionel Sambuc 			search_type = SRCH_REVERSE(search_type);
1462f7cf2976SLionel Sambuc 			DO_SEARCH();
1463f7cf2976SLionel Sambuc 			search_type = save_search_type;
1464f7cf2976SLionel Sambuc 			break;
1465f7cf2976SLionel Sambuc 
1466f7cf2976SLionel Sambuc 		case A_T_REVERSE_SEARCH:
1467f7cf2976SLionel Sambuc 			/*
1468f7cf2976SLionel Sambuc 			 * Repeat previous search,
1469f7cf2976SLionel Sambuc 			 * multiple files in reverse direction.
1470f7cf2976SLionel Sambuc 			 */
1471f7cf2976SLionel Sambuc 			save_search_type = search_type;
1472f7cf2976SLionel Sambuc 			search_type = SRCH_REVERSE(search_type);
1473f7cf2976SLionel Sambuc 			search_type |= SRCH_PAST_EOF;
1474f7cf2976SLionel Sambuc 			DO_SEARCH();
1475f7cf2976SLionel Sambuc 			search_type = save_search_type;
1476f7cf2976SLionel Sambuc 			break;
1477f7cf2976SLionel Sambuc 
1478f7cf2976SLionel Sambuc 		case A_UNDO_SEARCH:
1479f7cf2976SLionel Sambuc 			undo_search();
1480f7cf2976SLionel Sambuc 			break;
1481f7cf2976SLionel Sambuc 
1482f7cf2976SLionel Sambuc 		case A_HELP:
1483f7cf2976SLionel Sambuc 			/*
1484f7cf2976SLionel Sambuc 			 * Help.
1485f7cf2976SLionel Sambuc 			 */
1486f7cf2976SLionel Sambuc 			if (ch_getflags() & CH_HELPFILE)
1487f7cf2976SLionel Sambuc 				break;
1488f7cf2976SLionel Sambuc 			cmd_exec();
1489f7cf2976SLionel Sambuc 			save_hshift = hshift;
1490f7cf2976SLionel Sambuc 			hshift = 0;
1491f7cf2976SLionel Sambuc 			(void) edit(FAKE_HELPFILE);
1492f7cf2976SLionel Sambuc 			break;
1493f7cf2976SLionel Sambuc 
1494f7cf2976SLionel Sambuc 		case A_EXAMINE:
1495f7cf2976SLionel Sambuc #if EXAMINE
1496f7cf2976SLionel Sambuc 			/*
1497f7cf2976SLionel Sambuc 			 * Edit a new file.  Get the filename.
1498f7cf2976SLionel Sambuc 			 */
1499f7cf2976SLionel Sambuc 			if (secure)
1500f7cf2976SLionel Sambuc 			{
1501f7cf2976SLionel Sambuc 				error("Command not available", NULL_PARG);
1502f7cf2976SLionel Sambuc 				break;
1503f7cf2976SLionel Sambuc 			}
1504f7cf2976SLionel Sambuc 			start_mca(A_EXAMINE, "Examine: ", ml_examine, 0);
1505f7cf2976SLionel Sambuc 			c = getcc();
1506f7cf2976SLionel Sambuc 			goto again;
1507f7cf2976SLionel Sambuc #else
1508f7cf2976SLionel Sambuc 			error("Command not available", NULL_PARG);
1509f7cf2976SLionel Sambuc 			break;
1510f7cf2976SLionel Sambuc #endif
1511f7cf2976SLionel Sambuc 
1512f7cf2976SLionel Sambuc 		case A_VISUAL:
1513f7cf2976SLionel Sambuc 			/*
1514f7cf2976SLionel Sambuc 			 * Invoke an editor on the input file.
1515f7cf2976SLionel Sambuc 			 */
1516f7cf2976SLionel Sambuc #if EDITOR
1517f7cf2976SLionel Sambuc 			if (secure)
1518f7cf2976SLionel Sambuc 			{
1519f7cf2976SLionel Sambuc 				error("Command not available", NULL_PARG);
1520f7cf2976SLionel Sambuc 				break;
1521f7cf2976SLionel Sambuc 			}
1522f7cf2976SLionel Sambuc 			if (ch_getflags() & CH_HELPFILE)
1523f7cf2976SLionel Sambuc 				break;
1524f7cf2976SLionel Sambuc 			if (strcmp(get_filename(curr_ifile), "-") == 0)
1525f7cf2976SLionel Sambuc 			{
1526f7cf2976SLionel Sambuc 				error("Cannot edit standard input", NULL_PARG);
1527f7cf2976SLionel Sambuc 				break;
1528f7cf2976SLionel Sambuc 			}
1529f7cf2976SLionel Sambuc 			if (curr_altfilename != NULL)
1530f7cf2976SLionel Sambuc 			{
1531f7cf2976SLionel Sambuc 				error("WARNING: This file was viewed via LESSOPEN",
1532f7cf2976SLionel Sambuc 					NULL_PARG);
1533f7cf2976SLionel Sambuc 			}
1534f7cf2976SLionel Sambuc 			start_mca(A_SHELL, "!", ml_shell, 0);
1535f7cf2976SLionel Sambuc 			/*
1536f7cf2976SLionel Sambuc 			 * Expand the editor prototype string
1537f7cf2976SLionel Sambuc 			 * and pass it to the system to execute.
1538f7cf2976SLionel Sambuc 			 * (Make sure the screen is displayed so the
1539f7cf2976SLionel Sambuc 			 * expansion of "+%lm" works.)
1540f7cf2976SLionel Sambuc 			 */
1541f7cf2976SLionel Sambuc 			make_display();
1542f7cf2976SLionel Sambuc 			cmd_exec();
1543f7cf2976SLionel Sambuc 			lsystem(pr_expand(editproto, 0), (char*)NULL);
1544f7cf2976SLionel Sambuc 			break;
1545f7cf2976SLionel Sambuc #else
1546f7cf2976SLionel Sambuc 			error("Command not available", NULL_PARG);
1547f7cf2976SLionel Sambuc 			break;
1548f7cf2976SLionel Sambuc #endif
1549f7cf2976SLionel Sambuc 
1550f7cf2976SLionel Sambuc 		case A_NEXT_FILE:
1551f7cf2976SLionel Sambuc 			/*
1552f7cf2976SLionel Sambuc 			 * Examine next file.
1553f7cf2976SLionel Sambuc 			 */
1554f7cf2976SLionel Sambuc #if TAGS
1555f7cf2976SLionel Sambuc 			if (ntags())
1556f7cf2976SLionel Sambuc 			{
1557f7cf2976SLionel Sambuc 				error("No next file", NULL_PARG);
1558f7cf2976SLionel Sambuc 				break;
1559f7cf2976SLionel Sambuc 			}
1560f7cf2976SLionel Sambuc #endif
1561f7cf2976SLionel Sambuc 			if (number <= 0)
1562f7cf2976SLionel Sambuc 				number = 1;
1563f7cf2976SLionel Sambuc 			if (edit_next((int) number))
1564f7cf2976SLionel Sambuc 			{
1565f7cf2976SLionel Sambuc 				if (get_quit_at_eof() && eof_displayed() &&
1566f7cf2976SLionel Sambuc 				    !(ch_getflags() & CH_HELPFILE))
1567f7cf2976SLionel Sambuc 					quit(QUIT_OK);
1568f7cf2976SLionel Sambuc 				parg.p_string = (number > 1) ? "(N-th) " : "";
1569f7cf2976SLionel Sambuc 				error("No %snext file", &parg);
1570f7cf2976SLionel Sambuc 			}
1571f7cf2976SLionel Sambuc 			break;
1572f7cf2976SLionel Sambuc 
1573f7cf2976SLionel Sambuc 		case A_PREV_FILE:
1574f7cf2976SLionel Sambuc 			/*
1575f7cf2976SLionel Sambuc 			 * Examine previous file.
1576f7cf2976SLionel Sambuc 			 */
1577f7cf2976SLionel Sambuc #if TAGS
1578f7cf2976SLionel Sambuc 			if (ntags())
1579f7cf2976SLionel Sambuc 			{
1580f7cf2976SLionel Sambuc 				error("No previous file", NULL_PARG);
1581f7cf2976SLionel Sambuc 				break;
1582f7cf2976SLionel Sambuc 			}
1583f7cf2976SLionel Sambuc #endif
1584f7cf2976SLionel Sambuc 			if (number <= 0)
1585f7cf2976SLionel Sambuc 				number = 1;
1586f7cf2976SLionel Sambuc 			if (edit_prev((int) number))
1587f7cf2976SLionel Sambuc 			{
1588f7cf2976SLionel Sambuc 				parg.p_string = (number > 1) ? "(N-th) " : "";
1589f7cf2976SLionel Sambuc 				error("No %sprevious file", &parg);
1590f7cf2976SLionel Sambuc 			}
1591f7cf2976SLionel Sambuc 			break;
1592f7cf2976SLionel Sambuc 
1593f7cf2976SLionel Sambuc 		case A_NEXT_TAG:
1594f7cf2976SLionel Sambuc #if TAGS
1595f7cf2976SLionel Sambuc 			if (number <= 0)
1596f7cf2976SLionel Sambuc 				number = 1;
1597f7cf2976SLionel Sambuc 			tagfile = nexttag((int) number);
1598f7cf2976SLionel Sambuc 			if (tagfile == NULL)
1599f7cf2976SLionel Sambuc 			{
1600f7cf2976SLionel Sambuc 				error("No next tag", NULL_PARG);
1601f7cf2976SLionel Sambuc 				break;
1602f7cf2976SLionel Sambuc 			}
1603f7cf2976SLionel Sambuc 			if (edit(tagfile) == 0)
1604f7cf2976SLionel Sambuc 			{
1605f7cf2976SLionel Sambuc 				POSITION pos = tagsearch();
1606f7cf2976SLionel Sambuc 				if (pos != NULL_POSITION)
1607f7cf2976SLionel Sambuc 					jump_loc(pos, jump_sline);
1608f7cf2976SLionel Sambuc 			}
1609f7cf2976SLionel Sambuc #else
1610f7cf2976SLionel Sambuc 			error("Command not available", NULL_PARG);
1611f7cf2976SLionel Sambuc #endif
1612f7cf2976SLionel Sambuc 			break;
1613f7cf2976SLionel Sambuc 
1614f7cf2976SLionel Sambuc 		case A_PREV_TAG:
1615f7cf2976SLionel Sambuc #if TAGS
1616f7cf2976SLionel Sambuc 			if (number <= 0)
1617f7cf2976SLionel Sambuc 				number = 1;
1618f7cf2976SLionel Sambuc 			tagfile = prevtag((int) number);
1619f7cf2976SLionel Sambuc 			if (tagfile == NULL)
1620f7cf2976SLionel Sambuc 			{
1621f7cf2976SLionel Sambuc 				error("No previous tag", NULL_PARG);
1622f7cf2976SLionel Sambuc 				break;
1623f7cf2976SLionel Sambuc 			}
1624f7cf2976SLionel Sambuc 			if (edit(tagfile) == 0)
1625f7cf2976SLionel Sambuc 			{
1626f7cf2976SLionel Sambuc 				POSITION pos = tagsearch();
1627f7cf2976SLionel Sambuc 				if (pos != NULL_POSITION)
1628f7cf2976SLionel Sambuc 					jump_loc(pos, jump_sline);
1629f7cf2976SLionel Sambuc 			}
1630f7cf2976SLionel Sambuc #else
1631f7cf2976SLionel Sambuc 			error("Command not available", NULL_PARG);
1632f7cf2976SLionel Sambuc #endif
1633f7cf2976SLionel Sambuc 			break;
1634f7cf2976SLionel Sambuc 
1635f7cf2976SLionel Sambuc 		case A_INDEX_FILE:
1636f7cf2976SLionel Sambuc 			/*
1637f7cf2976SLionel Sambuc 			 * Examine a particular file.
1638f7cf2976SLionel Sambuc 			 */
1639f7cf2976SLionel Sambuc 			if (number <= 0)
1640f7cf2976SLionel Sambuc 				number = 1;
1641f7cf2976SLionel Sambuc 			if (edit_index((int) number))
1642f7cf2976SLionel Sambuc 				error("No such file", NULL_PARG);
1643f7cf2976SLionel Sambuc 			break;
1644f7cf2976SLionel Sambuc 
1645f7cf2976SLionel Sambuc 		case A_REMOVE_FILE:
1646f7cf2976SLionel Sambuc 			if (ch_getflags() & CH_HELPFILE)
1647f7cf2976SLionel Sambuc 				break;
1648f7cf2976SLionel Sambuc 			old_ifile = curr_ifile;
1649f7cf2976SLionel Sambuc 			new_ifile = getoff_ifile(curr_ifile);
1650f7cf2976SLionel Sambuc 			if (new_ifile == NULL_IFILE)
1651f7cf2976SLionel Sambuc 			{
1652f7cf2976SLionel Sambuc 				bell();
1653f7cf2976SLionel Sambuc 				break;
1654f7cf2976SLionel Sambuc 			}
1655f7cf2976SLionel Sambuc 			if (edit_ifile(new_ifile) != 0)
1656f7cf2976SLionel Sambuc 			{
1657f7cf2976SLionel Sambuc 				reedit_ifile(old_ifile);
1658f7cf2976SLionel Sambuc 				break;
1659f7cf2976SLionel Sambuc 			}
1660f7cf2976SLionel Sambuc 			del_ifile(old_ifile);
1661f7cf2976SLionel Sambuc 			break;
1662f7cf2976SLionel Sambuc 
1663f7cf2976SLionel Sambuc 		case A_OPT_TOGGLE:
1664f7cf2976SLionel Sambuc 			optflag = OPT_TOGGLE;
1665f7cf2976SLionel Sambuc 			optgetname = FALSE;
1666f7cf2976SLionel Sambuc 			mca_opt_toggle();
1667f7cf2976SLionel Sambuc 			c = getcc();
1668f7cf2976SLionel Sambuc 			goto again;
1669f7cf2976SLionel Sambuc 
1670f7cf2976SLionel Sambuc 		case A_DISP_OPTION:
1671f7cf2976SLionel Sambuc 			/*
1672f7cf2976SLionel Sambuc 			 * Report a flag setting.
1673f7cf2976SLionel Sambuc 			 */
1674f7cf2976SLionel Sambuc 			optflag = OPT_NO_TOGGLE;
1675f7cf2976SLionel Sambuc 			optgetname = FALSE;
1676f7cf2976SLionel Sambuc 			mca_opt_toggle();
1677f7cf2976SLionel Sambuc 			c = getcc();
1678f7cf2976SLionel Sambuc 			goto again;
1679f7cf2976SLionel Sambuc 
1680f7cf2976SLionel Sambuc 		case A_FIRSTCMD:
1681f7cf2976SLionel Sambuc 			/*
1682f7cf2976SLionel Sambuc 			 * Set an initial command for new files.
1683f7cf2976SLionel Sambuc 			 */
1684f7cf2976SLionel Sambuc 			start_mca(A_FIRSTCMD, "+", (void*)NULL, 0);
1685f7cf2976SLionel Sambuc 			c = getcc();
1686f7cf2976SLionel Sambuc 			goto again;
1687f7cf2976SLionel Sambuc 
1688f7cf2976SLionel Sambuc 		case A_SHELL:
1689f7cf2976SLionel Sambuc 			/*
1690f7cf2976SLionel Sambuc 			 * Shell escape.
1691f7cf2976SLionel Sambuc 			 */
1692f7cf2976SLionel Sambuc #if SHELL_ESCAPE
1693f7cf2976SLionel Sambuc 			if (secure)
1694f7cf2976SLionel Sambuc 			{
1695f7cf2976SLionel Sambuc 				error("Command not available", NULL_PARG);
1696f7cf2976SLionel Sambuc 				break;
1697f7cf2976SLionel Sambuc 			}
1698f7cf2976SLionel Sambuc 			start_mca(A_SHELL, "!", ml_shell, 0);
1699f7cf2976SLionel Sambuc 			c = getcc();
1700f7cf2976SLionel Sambuc 			goto again;
1701f7cf2976SLionel Sambuc #else
1702f7cf2976SLionel Sambuc 			error("Command not available", NULL_PARG);
1703f7cf2976SLionel Sambuc 			break;
1704f7cf2976SLionel Sambuc #endif
1705f7cf2976SLionel Sambuc 
1706f7cf2976SLionel Sambuc 		case A_SETMARK:
1707f7cf2976SLionel Sambuc 			/*
1708f7cf2976SLionel Sambuc 			 * Set a mark.
1709f7cf2976SLionel Sambuc 			 */
1710f7cf2976SLionel Sambuc 			if (ch_getflags() & CH_HELPFILE)
1711f7cf2976SLionel Sambuc 				break;
1712f7cf2976SLionel Sambuc 			start_mca(A_SETMARK, "mark: ", (void*)NULL, 0);
1713f7cf2976SLionel Sambuc 			c = getcc();
1714f7cf2976SLionel Sambuc 			if (c == erase_char || c == erase2_char ||
1715f7cf2976SLionel Sambuc 			    c == kill_char || c == '\n' || c == '\r')
1716f7cf2976SLionel Sambuc 				break;
1717f7cf2976SLionel Sambuc 			setmark(c);
1718f7cf2976SLionel Sambuc 			break;
1719f7cf2976SLionel Sambuc 
1720f7cf2976SLionel Sambuc 		case A_GOMARK:
1721f7cf2976SLionel Sambuc 			/*
1722f7cf2976SLionel Sambuc 			 * Go to a mark.
1723f7cf2976SLionel Sambuc 			 */
1724f7cf2976SLionel Sambuc 			start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0);
1725f7cf2976SLionel Sambuc 			c = getcc();
1726f7cf2976SLionel Sambuc 			if (c == erase_char || c == erase2_char ||
1727f7cf2976SLionel Sambuc 			    c == kill_char || c == '\n' || c == '\r')
1728f7cf2976SLionel Sambuc 				break;
1729f7cf2976SLionel Sambuc 			cmd_exec();
1730f7cf2976SLionel Sambuc 			gomark(c);
1731f7cf2976SLionel Sambuc 			break;
1732f7cf2976SLionel Sambuc 
1733f7cf2976SLionel Sambuc 		case A_PIPE:
1734f7cf2976SLionel Sambuc #if PIPEC
1735f7cf2976SLionel Sambuc 			if (secure)
1736f7cf2976SLionel Sambuc 			{
1737f7cf2976SLionel Sambuc 				error("Command not available", NULL_PARG);
1738f7cf2976SLionel Sambuc 				break;
1739f7cf2976SLionel Sambuc 			}
1740f7cf2976SLionel Sambuc 			start_mca(A_PIPE, "|mark: ", (void*)NULL, 0);
1741f7cf2976SLionel Sambuc 			c = getcc();
1742f7cf2976SLionel Sambuc 			if (c == erase_char || c == erase2_char || c == kill_char)
1743f7cf2976SLionel Sambuc 				break;
1744f7cf2976SLionel Sambuc 			if (c == '\n' || c == '\r')
1745f7cf2976SLionel Sambuc 				c = '.';
1746f7cf2976SLionel Sambuc 			if (badmark(c))
1747f7cf2976SLionel Sambuc 				break;
1748f7cf2976SLionel Sambuc 			pipec = c;
1749f7cf2976SLionel Sambuc 			start_mca(A_PIPE, "!", ml_shell, 0);
1750f7cf2976SLionel Sambuc 			c = getcc();
1751f7cf2976SLionel Sambuc 			goto again;
1752f7cf2976SLionel Sambuc #else
1753f7cf2976SLionel Sambuc 			error("Command not available", NULL_PARG);
1754f7cf2976SLionel Sambuc 			break;
1755f7cf2976SLionel Sambuc #endif
1756f7cf2976SLionel Sambuc 
1757f7cf2976SLionel Sambuc 		case A_B_BRACKET:
1758f7cf2976SLionel Sambuc 		case A_F_BRACKET:
1759f7cf2976SLionel Sambuc 			start_mca(action, "Brackets: ", (void*)NULL, 0);
1760f7cf2976SLionel Sambuc 			c = getcc();
1761f7cf2976SLionel Sambuc 			goto again;
1762f7cf2976SLionel Sambuc 
1763f7cf2976SLionel Sambuc 		case A_LSHIFT:
1764f7cf2976SLionel Sambuc 			if (number > 0)
1765f7cf2976SLionel Sambuc 				shift_count = number;
1766f7cf2976SLionel Sambuc 			else
1767f7cf2976SLionel Sambuc 				number = (shift_count > 0) ?
1768f7cf2976SLionel Sambuc 					shift_count : sc_width / 2;
1769f7cf2976SLionel Sambuc 			if (number > hshift)
1770f7cf2976SLionel Sambuc 				number = hshift;
1771f7cf2976SLionel Sambuc 			hshift -= number;
1772f7cf2976SLionel Sambuc 			screen_trashed = 1;
1773f7cf2976SLionel Sambuc 			break;
1774f7cf2976SLionel Sambuc 
1775f7cf2976SLionel Sambuc 		case A_RSHIFT:
1776f7cf2976SLionel Sambuc 			if (number > 0)
1777f7cf2976SLionel Sambuc 				shift_count = number;
1778f7cf2976SLionel Sambuc 			else
1779f7cf2976SLionel Sambuc 				number = (shift_count > 0) ?
1780f7cf2976SLionel Sambuc 					shift_count : sc_width / 2;
1781f7cf2976SLionel Sambuc 			hshift += number;
1782f7cf2976SLionel Sambuc 			screen_trashed = 1;
1783f7cf2976SLionel Sambuc 			break;
1784f7cf2976SLionel Sambuc 
1785f7cf2976SLionel Sambuc 		case A_PREFIX:
1786f7cf2976SLionel Sambuc 			/*
1787f7cf2976SLionel Sambuc 			 * The command is incomplete (more chars are needed).
1788f7cf2976SLionel Sambuc 			 * Display the current char, so the user knows
1789f7cf2976SLionel Sambuc 			 * what's going on, and get another character.
1790f7cf2976SLionel Sambuc 			 */
1791f7cf2976SLionel Sambuc 			if (mca != A_PREFIX)
1792f7cf2976SLionel Sambuc 			{
1793f7cf2976SLionel Sambuc 				cmd_reset();
1794f7cf2976SLionel Sambuc 				start_mca(A_PREFIX, " ", (void*)NULL,
1795f7cf2976SLionel Sambuc 					CF_QUIT_ON_ERASE);
1796f7cf2976SLionel Sambuc 				(void) cmd_char(c);
1797f7cf2976SLionel Sambuc 			}
1798f7cf2976SLionel Sambuc 			c = getcc();
1799f7cf2976SLionel Sambuc 			goto again;
1800f7cf2976SLionel Sambuc 
1801f7cf2976SLionel Sambuc 		case A_NOACTION:
1802f7cf2976SLionel Sambuc 			break;
1803f7cf2976SLionel Sambuc 
1804f7cf2976SLionel Sambuc 		default:
1805f7cf2976SLionel Sambuc 			if (be_helpful)
1806f7cf2976SLionel Sambuc 				helpprompt = 1;
1807f7cf2976SLionel Sambuc 			else
1808f7cf2976SLionel Sambuc 				bell();
1809f7cf2976SLionel Sambuc 			break;
1810f7cf2976SLionel Sambuc 		}
1811f7cf2976SLionel Sambuc 	}
1812f7cf2976SLionel Sambuc }
1813