xref: /csrg-svn/usr.bin/more/command.c (revision 62131)
135209Sbostic /*
235209Sbostic  * Copyright (c) 1988 Mark Nudleman
3*62131Sbostic  * Copyright (c) 1988, 1993
4*62131Sbostic  *	The Regents of the University of California.  All rights reserved.
535209Sbostic  *
642742Sbostic  * %sccs.include.redist.c%
735209Sbostic  */
835209Sbostic 
935209Sbostic #ifndef lint
10*62131Sbostic static char sccsid[] = "@(#)command.c	8.1 (Berkeley) 06/06/93";
1135209Sbostic #endif /* not lint */
1235209Sbostic 
1336251Sbostic #include <sys/param.h>
1436251Sbostic #include <stdio.h>
1536251Sbostic #include <ctype.h>
1636251Sbostic #include <less.h>
1737919Sbostic #include "pathnames.h"
1835209Sbostic 
1935209Sbostic #define	NO_MCA		0
2035209Sbostic #define	MCA_DONE	1
2135209Sbostic #define	MCA_MORE	2
2235209Sbostic 
2336251Sbostic extern int erase_char, kill_char, werase_char;
2435209Sbostic extern int ispipe;
2535209Sbostic extern int sigs;
2635209Sbostic extern int quit_at_eof;
2735209Sbostic extern int hit_eof;
2835209Sbostic extern int sc_width;
2935209Sbostic extern int sc_height;
3035209Sbostic extern int sc_window;
3135209Sbostic extern int curr_ac;
3235209Sbostic extern int ac;
3335209Sbostic extern int quitting;
3435209Sbostic extern int scroll;
3535209Sbostic extern int screen_trashed;	/* The screen has been overwritten */
3635209Sbostic 
3735209Sbostic static char cmdbuf[120];	/* Buffer for holding a multi-char command */
3835209Sbostic static char *cp;		/* Pointer into cmdbuf */
3935209Sbostic static int cmd_col;		/* Current column of the multi-char command */
4036251Sbostic static int longprompt;		/* if stat command instead of prompt */
4135209Sbostic static int mca;			/* The multicharacter command (action) */
4235209Sbostic static int last_mca;		/* The previous mca */
4335209Sbostic static int number;		/* The number typed by the user */
4435209Sbostic static int wsearch;		/* Search for matches (1) or non-matches (0) */
4535209Sbostic 
4636299Sbostic #define	CMD_RESET	cp = cmdbuf	/* reset command buffer to empty */
4736299Sbostic #define	CMD_EXEC	lower_left(); flush()
4835209Sbostic 
4936299Sbostic /* backspace in command buffer. */
5036251Sbostic static
cmd_erase()5135209Sbostic cmd_erase()
5235209Sbostic {
5336299Sbostic 	/*
5436299Sbostic 	 * backspace past beginning of the string: this usually means
5536299Sbostic 	 * abort the command.
5636299Sbostic 	 */
5735209Sbostic 	if (cp == cmdbuf)
5836251Sbostic 		return(1);
5935209Sbostic 
6036299Sbostic 	/* erase an extra character, for the carat. */
6136251Sbostic 	if (CONTROL_CHAR(*--cp)) {
6235209Sbostic 		backspace();
6336251Sbostic 		--cmd_col;
6435209Sbostic 	}
6536299Sbostic 
6635209Sbostic 	backspace();
6736251Sbostic 	--cmd_col;
6836251Sbostic 	return(0);
6935209Sbostic }
7035209Sbostic 
7136299Sbostic /* set up the display to start a new multi-character command. */
start_mca(action,prompt)7235209Sbostic start_mca(action, prompt)
7335209Sbostic 	int action;
7435209Sbostic 	char *prompt;
7535209Sbostic {
7635209Sbostic 	lower_left();
7735209Sbostic 	clear_eol();
7835209Sbostic 	putstr(prompt);
7935209Sbostic 	cmd_col = strlen(prompt);
8035209Sbostic 	mca = action;
8135209Sbostic }
8235209Sbostic 
8335209Sbostic /*
8436299Sbostic  * process a single character of a multi-character command, such as
8535209Sbostic  * a number, or the pattern of a search command.
8635209Sbostic  */
8736251Sbostic static
cmd_char(c)8835209Sbostic cmd_char(c)
8935209Sbostic 	int c;
9035209Sbostic {
9135209Sbostic 	if (c == erase_char)
9236251Sbostic 		return(cmd_erase());
9336251Sbostic 	/* in this order, in case werase == erase_char */
9436251Sbostic 	if (c == werase_char) {
9536251Sbostic 		if (cp > cmdbuf) {
9636251Sbostic 			while (isspace(cp[-1]) && !cmd_erase());
9736251Sbostic 			while (!isspace(cp[-1]) && !cmd_erase());
9836251Sbostic 			while (isspace(cp[-1]) && !cmd_erase());
9936251Sbostic 		}
10036251Sbostic 		return(cp == cmdbuf);
10136251Sbostic 	}
10236251Sbostic 	if (c == kill_char) {
10336251Sbostic 		while (!cmd_erase());
10436251Sbostic 		return(1);
10536251Sbostic 	}
10636251Sbostic 	/*
10736251Sbostic 	 * No room in the command buffer, or no room on the screen;
10836251Sbostic 	 * {{ Could get fancy here; maybe shift the displayed line
10936251Sbostic 	 * and make room for more chars, like ksh. }}
11036251Sbostic 	 */
11136251Sbostic 	if (cp >= &cmdbuf[sizeof(cmdbuf)-1] || cmd_col >= sc_width-3)
11235209Sbostic 		bell();
11336251Sbostic 	else {
11435209Sbostic 		*cp++ = c;
11536251Sbostic 		if (CONTROL_CHAR(c)) {
11635209Sbostic 			putchr('^');
11735209Sbostic 			cmd_col++;
11836251Sbostic 			c = CARAT_CHAR(c);
11935209Sbostic 		}
12035209Sbostic 		putchr(c);
12135209Sbostic 		cmd_col++;
12235209Sbostic 	}
12336251Sbostic 	return(0);
12435209Sbostic }
12535209Sbostic 
prompt()12635209Sbostic prompt()
12735209Sbostic {
12836482Sbostic 	extern int linenums, short_file;
12936272Sbostic 	extern char *current_name, *firstsearch, *next_name;
13036251Sbostic 	off_t len, pos, ch_length(), position(), forw_line();
13136251Sbostic 	char pbuf[40];
13235209Sbostic 
13335209Sbostic 	/*
13436251Sbostic 	 * if nothing is displayed yet, display starting from line 1;
13536251Sbostic 	 * if search string provided, go there instead.
13635209Sbostic 	 */
13736251Sbostic 	if (position(TOP) == NULL_POSITION) {
13836251Sbostic 		if (forw_line((off_t)0) == NULL_POSITION)
13936251Sbostic 			return(0);
14036251Sbostic 		if (!firstsearch || !search(1, firstsearch, 1, 1))
14136251Sbostic 			jump_back(1);
14236251Sbostic 	}
14335209Sbostic 	else if (screen_trashed)
14435209Sbostic 		repaint();
14535209Sbostic 
14636251Sbostic 	/* if no -e flag and we've hit EOF on the last file, quit. */
14736482Sbostic 	if ((!quit_at_eof || short_file) && hit_eof && curr_ac + 1 >= ac)
14835209Sbostic 		quit();
14935209Sbostic 
15036251Sbostic 	/* select the proper prompt and display it. */
15135209Sbostic 	lower_left();
15235209Sbostic 	clear_eol();
15336251Sbostic 	if (longprompt) {
15436251Sbostic 		so_enter();
15536251Sbostic 		putstr(current_name);
15636251Sbostic 		putstr(":");
15736251Sbostic 		if (!ispipe) {
15836251Sbostic 			(void)sprintf(pbuf, " file %d/%d", curr_ac + 1, ac);
15936251Sbostic 			putstr(pbuf);
16036251Sbostic 		}
16136251Sbostic 		if (linenums) {
16236255Sbostic 			(void)sprintf(pbuf, " line %d", currline(BOTTOM));
16336251Sbostic 			putstr(pbuf);
16436251Sbostic 		}
16536255Sbostic 		if ((pos = position(BOTTOM)) != NULL_POSITION) {
16654196Sbostic 			(void)sprintf(pbuf, " byte %qd", pos);
16736251Sbostic 			putstr(pbuf);
16836251Sbostic 			if (!ispipe && (len = ch_length())) {
16954196Sbostic 				(void)sprintf(pbuf, "/%qd pct %qd%%",
17036255Sbostic 				    len, ((100 * pos) / len));
17136251Sbostic 				putstr(pbuf);
17236251Sbostic 			}
17336251Sbostic 		}
17436251Sbostic 		so_exit();
17536251Sbostic 		longprompt = 0;
17636251Sbostic 	}
17736251Sbostic 	else {
17835209Sbostic 		so_enter();
17936251Sbostic 		putstr(current_name);
18036251Sbostic 		if (hit_eof)
18136272Sbostic 			if (next_name) {
18240671Sleres 				putstr(": END (next file: ");
18340671Sleres 				putstr(next_name);
18440671Sleres 				putstr(")");
18536272Sbostic 			}
18636272Sbostic 			else
18736272Sbostic 				putstr(": END");
18836312Sbostic 		else if (!ispipe &&
18936312Sbostic 		    (pos = position(BOTTOM)) != NULL_POSITION &&
19036312Sbostic 		    (len = ch_length())) {
19154196Sbostic 			(void)sprintf(pbuf, " (%qd%%)", ((100 * pos) / len));
19236251Sbostic 			putstr(pbuf);
19336251Sbostic 		}
19435209Sbostic 		so_exit();
19535209Sbostic 	}
19636251Sbostic 	return(1);
19735209Sbostic }
19835209Sbostic 
19936299Sbostic /* get command character. */
20036251Sbostic static
getcc()20135209Sbostic getcc()
20235209Sbostic {
20336263Sbostic 	extern int cmdstack;
20436263Sbostic 	int ch;
20558577Sralph 	off_t position();
20636263Sbostic 
20736263Sbostic 	/* left over from error() routine. */
20836263Sbostic 	if (cmdstack) {
20936263Sbostic 		ch = cmdstack;
21036263Sbostic 		cmdstack = NULL;
21136263Sbostic 		return(ch);
21236263Sbostic 	}
21336251Sbostic 	if (cp > cmdbuf && position(TOP) == NULL_POSITION) {
21435209Sbostic 		/*
21536251Sbostic 		 * Command is incomplete, so try to complete it.
21636251Sbostic 		 * There are only two cases:
21736251Sbostic 		 * 1. We have "/string" but no newline.  Add the \n.
21836251Sbostic 		 * 2. We have a number but no command.  Treat as #g.
21936251Sbostic 		 * (This is all pretty hokey.)
22035209Sbostic 		 */
22136251Sbostic 		if (mca != A_DIGIT)
22236251Sbostic 			/* Not a number; must be search string */
22336251Sbostic 			return('\n');
22436251Sbostic 		else
22536251Sbostic 			/* A number; append a 'g' */
22636251Sbostic 			return('g');
22735209Sbostic 	}
22836251Sbostic 	return(getchr());
22935209Sbostic }
23035209Sbostic 
23136299Sbostic /* execute a multicharacter command. */
23236251Sbostic static
exec_mca()23335209Sbostic exec_mca()
23435209Sbostic {
23536251Sbostic 	extern int file;
23636251Sbostic 	extern char *tagfile;
23735209Sbostic 	register char *p;
23836251Sbostic 	char *glob();
23935209Sbostic 
24035209Sbostic 	*cp = '\0';
24136299Sbostic 	CMD_EXEC;
24236251Sbostic 	switch (mca) {
24335209Sbostic 	case A_F_SEARCH:
24436251Sbostic 		(void)search(1, cmdbuf, number, wsearch);
24535209Sbostic 		break;
24635209Sbostic 	case A_B_SEARCH:
24736251Sbostic 		(void)search(0, cmdbuf, number, wsearch);
24835209Sbostic 		break;
24936251Sbostic 	case A_EXAMINE:
25036251Sbostic 		for (p = cmdbuf; isspace(*p); ++p);
25136251Sbostic 		(void)edit(glob(p));
25235209Sbostic 		break;
25336251Sbostic 	case A_TAGFILE:
25436251Sbostic 		for (p = cmdbuf; isspace(*p); ++p);
25536251Sbostic 		findtag(p);
25636251Sbostic 		if (tagfile == NULL)
25736251Sbostic 			break;
25836251Sbostic 		if (edit(tagfile))
25936251Sbostic 			(void)tagsearch();
26035209Sbostic 		break;
26135209Sbostic 	}
26235209Sbostic }
26335209Sbostic 
26436299Sbostic /* add a character to a multi-character command. */
26536251Sbostic static
mca_char(c)26635209Sbostic mca_char(c)
26735209Sbostic 	int c;
26835209Sbostic {
26936251Sbostic 	switch (mca) {
27036251Sbostic 	case 0:			/* not in a multicharacter command. */
27136251Sbostic 	case A_PREFIX:		/* in the prefix of a command. */
27236251Sbostic 		return(NO_MCA);
27335209Sbostic 	case A_DIGIT:
27435209Sbostic 		/*
27535209Sbostic 		 * Entering digits of a number.
27635209Sbostic 		 * Terminated by a non-digit.
27735209Sbostic 		 */
27836251Sbostic 		if (!isascii(c) || !isdigit(c) &&
27936251Sbostic 		    c != erase_char && c != kill_char && c != werase_char) {
28035209Sbostic 			/*
28135209Sbostic 			 * Not part of the number.
28235209Sbostic 			 * Treat as a normal command character.
28335209Sbostic 			 */
28436299Sbostic 			*cp = '\0';
28536299Sbostic 			number = atoi(cmdbuf);
28636299Sbostic 			CMD_RESET;
28735209Sbostic 			mca = 0;
28836251Sbostic 			return(NO_MCA);
28935209Sbostic 		}
29035209Sbostic 		break;
29135209Sbostic 	}
29235209Sbostic 
29335209Sbostic 	/*
29435209Sbostic 	 * Any other multicharacter command
29535209Sbostic 	 * is terminated by a newline.
29635209Sbostic 	 */
29736251Sbostic 	if (c == '\n' || c == '\r') {
29835209Sbostic 		exec_mca();
29936251Sbostic 		return(MCA_DONE);
30035209Sbostic 	}
30136299Sbostic 
30236299Sbostic 	/* append the char to the command buffer. */
30335209Sbostic 	if (cmd_char(c))
30436251Sbostic 		return(MCA_DONE);
30536299Sbostic 
30636251Sbostic 	return(MCA_MORE);
30735209Sbostic }
30835209Sbostic 
30935209Sbostic /*
31035209Sbostic  * Main command processor.
31135209Sbostic  * Accept and execute commands until a quit command, then return.
31235209Sbostic  */
commands()31335209Sbostic commands()
31435209Sbostic {
31535209Sbostic 	register int c;
31635209Sbostic 	register int action;
31735209Sbostic 
31835209Sbostic 	last_mca = 0;
31935209Sbostic 	scroll = (sc_height + 1) / 2;
32035209Sbostic 
32136251Sbostic 	for (;;) {
32235209Sbostic 		mca = 0;
32335209Sbostic 		number = 0;
32435209Sbostic 
32535209Sbostic 		/*
32635209Sbostic 		 * See if any signals need processing.
32735209Sbostic 		 */
32836251Sbostic 		if (sigs) {
32935209Sbostic 			psignals();
33035209Sbostic 			if (quitting)
33135209Sbostic 				quit();
33235209Sbostic 		}
33335209Sbostic 		/*
33435209Sbostic 		 * Display prompt and accept a character.
33535209Sbostic 		 */
33636299Sbostic 		CMD_RESET;
33736251Sbostic 		if (!prompt()) {
33836251Sbostic 			next_file(1);
33936251Sbostic 			continue;
34036251Sbostic 		}
34135209Sbostic 		noprefix();
34235209Sbostic 		c = getcc();
34335209Sbostic 
34435706Sbostic again:		if (sigs)
34535209Sbostic 			continue;
34635209Sbostic 
34735209Sbostic 		/*
34835209Sbostic 		 * If we are in a multicharacter command, call mca_char.
34935209Sbostic 		 * Otherwise we call cmd_decode to determine the
35035209Sbostic 		 * action to be performed.
35135209Sbostic 		 */
35235209Sbostic 		if (mca)
35336251Sbostic 			switch (mca_char(c)) {
35435209Sbostic 			case MCA_MORE:
35535209Sbostic 				/*
35635209Sbostic 				 * Need another character.
35735209Sbostic 				 */
35835209Sbostic 				c = getcc();
35935209Sbostic 				goto again;
36035209Sbostic 			case MCA_DONE:
36135209Sbostic 				/*
36235209Sbostic 				 * Command has been handled by mca_char.
36335209Sbostic 				 * Start clean with a prompt.
36435209Sbostic 				 */
36535209Sbostic 				continue;
36635209Sbostic 			case NO_MCA:
36735209Sbostic 				/*
36835209Sbostic 				 * Not a multi-char command
36935209Sbostic 				 * (at least, not anymore).
37035209Sbostic 				 */
37135209Sbostic 				break;
37235209Sbostic 			}
37335209Sbostic 
37436299Sbostic 		/* decode the command character and decide what to do. */
37536299Sbostic 		switch (action = cmd_decode(c)) {
37636299Sbostic 		case A_DIGIT:		/* first digit of a number */
37735209Sbostic 			start_mca(A_DIGIT, ":");
37835209Sbostic 			goto again;
37936299Sbostic 		case A_F_SCREEN:	/* forward one screen */
38036299Sbostic 			CMD_EXEC;
38136299Sbostic 			if (number <= 0 && (number = sc_window) <= 0)
38235209Sbostic 				number = sc_height - 1;
38335209Sbostic 			forward(number, 1);
38435209Sbostic 			break;
38536299Sbostic 		case A_B_SCREEN:	/* backward one screen */
38636299Sbostic 			CMD_EXEC;
38736299Sbostic 			if (number <= 0 && (number = sc_window) <= 0)
38835209Sbostic 				number = sc_height - 1;
38935209Sbostic 			backward(number, 1);
39035209Sbostic 			break;
39136299Sbostic 		case A_F_LINE:		/* forward N (default 1) line */
39236299Sbostic 			CMD_EXEC;
39336299Sbostic 			forward(number <= 0 ? 1 : number, 0);
39435209Sbostic 			break;
39536299Sbostic 		case A_B_LINE:		/* backward N (default 1) line */
39636299Sbostic 			CMD_EXEC;
39736299Sbostic 			backward(number <= 0 ? 1 : number, 0);
39835209Sbostic 			break;
39936299Sbostic 		case A_F_SCROLL:	/* forward N lines */
40036299Sbostic 			CMD_EXEC;
40135209Sbostic 			if (number > 0)
40235209Sbostic 				scroll = number;
40335209Sbostic 			forward(scroll, 0);
40435209Sbostic 			break;
40536299Sbostic 		case A_B_SCROLL:	/* backward N lines */
40636299Sbostic 			CMD_EXEC;
40735209Sbostic 			if (number > 0)
40835209Sbostic 				scroll = number;
40935209Sbostic 			backward(scroll, 0);
41035209Sbostic 			break;
41136299Sbostic 		case A_FREPAINT:	/* flush buffers and repaint */
41236299Sbostic 			if (!ispipe) {
41335209Sbostic 				ch_init(0, 0);
41435209Sbostic 				clr_linenum();
41535209Sbostic 			}
41636299Sbostic 			/* FALLTHROUGH */
41736294Sbostic 		case A_REPAINT:		/* repaint the screen */
41836299Sbostic 			CMD_EXEC;
41935209Sbostic 			repaint();
42035209Sbostic 			break;
42136299Sbostic 		case A_GOLINE:		/* go to line N, default 1 */
42236299Sbostic 			CMD_EXEC;
42335209Sbostic 			if (number <= 0)
42435209Sbostic 				number = 1;
42535209Sbostic 			jump_back(number);
42635209Sbostic 			break;
42736299Sbostic 		case A_PERCENT:		/* go to percent of file */
42836299Sbostic 			CMD_EXEC;
42935209Sbostic 			if (number < 0)
43035209Sbostic 				number = 0;
43136299Sbostic 			else if (number > 100)
43235209Sbostic 				number = 100;
43335209Sbostic 			jump_percent(number);
43435209Sbostic 			break;
43536299Sbostic 		case A_GOEND:		/* go to line N, default end */
43636299Sbostic 			CMD_EXEC;
43735209Sbostic 			if (number <= 0)
43835209Sbostic 				jump_forw();
43935209Sbostic 			else
44035209Sbostic 				jump_back(number);
44135209Sbostic 			break;
44236251Sbostic 		case A_STAT:		/* print file name, etc. */
44336251Sbostic 			longprompt = 1;
44436251Sbostic 			continue;
44536251Sbostic 		case A_QUIT:		/* exit */
44635209Sbostic 			quit();
44736299Sbostic 		case A_F_SEARCH:	/* search for a pattern */
44835209Sbostic 		case A_B_SEARCH:
44935209Sbostic 			if (number <= 0)
45035209Sbostic 				number = 1;
45135209Sbostic 			start_mca(action, (action==A_F_SEARCH) ? "/" : "?");
45235209Sbostic 			last_mca = mca;
45335209Sbostic 			wsearch = 1;
45435209Sbostic 			c = getcc();
45536251Sbostic 			if (c == '!') {
45635209Sbostic 				/*
45736299Sbostic 				 * Invert the sense of the search; set wsearch
45836299Sbostic 				 * to 0 and get a new character for the start
45936299Sbostic 				 * of the pattern.
46035209Sbostic 				 */
46135209Sbostic 				start_mca(action,
46236299Sbostic 				    (action == A_F_SEARCH) ? "!/" : "!?");
46335209Sbostic 				wsearch = 0;
46435209Sbostic 				c = getcc();
46535209Sbostic 			}
46635209Sbostic 			goto again;
46736299Sbostic 		case A_AGAIN_SEARCH:		/* repeat previous search */
46835209Sbostic 			if (number <= 0)
46935209Sbostic 				number = 1;
47035209Sbostic 			if (wsearch)
47135209Sbostic 				start_mca(last_mca,
47236299Sbostic 				    (last_mca == A_F_SEARCH) ? "/" : "?");
47335209Sbostic 			else
47435209Sbostic 				start_mca(last_mca,
47536299Sbostic 				    (last_mca == A_F_SEARCH) ? "!/" : "!?");
47636299Sbostic 			CMD_EXEC;
47736251Sbostic 			(void)search(mca == A_F_SEARCH, (char *)NULL,
47836251Sbostic 			    number, wsearch);
47935209Sbostic 			break;
48036299Sbostic 		case A_HELP:			/* help */
48135209Sbostic 			lower_left();
48235209Sbostic 			clear_eol();
48335209Sbostic 			putstr("help");
48436299Sbostic 			CMD_EXEC;
48535209Sbostic 			help();
48635209Sbostic 			break;
48736299Sbostic 		case A_TAGFILE:			/* tag a new file */
48836299Sbostic 			CMD_RESET;
48936251Sbostic 			start_mca(A_TAGFILE, "Tag: ");
49036251Sbostic 			c = getcc();
49136251Sbostic 			goto again;
49236299Sbostic 		case A_FILE_LIST:		/* show list of file names */
49336299Sbostic 			CMD_EXEC;
49436294Sbostic 			showlist();
49536294Sbostic 			repaint();
49636294Sbostic 			break;
49736299Sbostic 		case A_EXAMINE:			/* edit a new file */
49836299Sbostic 			CMD_RESET;
49935209Sbostic 			start_mca(A_EXAMINE, "Examine: ");
50035209Sbostic 			c = getcc();
50135209Sbostic 			goto again;
50236299Sbostic 		case A_VISUAL:			/* invoke the editor */
50336299Sbostic 			if (ispipe) {
50435209Sbostic 				error("Cannot edit standard input");
50535209Sbostic 				break;
50635209Sbostic 			}
50736299Sbostic 			CMD_EXEC;
50835708Sbostic 			editfile();
50935209Sbostic 			ch_init(0, 0);
51035209Sbostic 			clr_linenum();
51135209Sbostic 			break;
51236299Sbostic 		case A_NEXT_FILE:		/* examine next file */
51335209Sbostic 			if (number <= 0)
51435209Sbostic 				number = 1;
51535209Sbostic 			next_file(number);
51635209Sbostic 			break;
51736299Sbostic 		case A_PREV_FILE:		/* examine previous file */
51835209Sbostic 			if (number <= 0)
51935209Sbostic 				number = 1;
52035209Sbostic 			prev_file(number);
52135209Sbostic 			break;
52236299Sbostic 		case A_SETMARK:			/* set a mark */
52335209Sbostic 			lower_left();
52435209Sbostic 			clear_eol();
52535209Sbostic 			start_mca(A_SETMARK, "mark: ");
52635209Sbostic 			c = getcc();
52735209Sbostic 			if (c == erase_char || c == kill_char)
52835209Sbostic 				break;
52935209Sbostic 			setmark(c);
53035209Sbostic 			break;
53136299Sbostic 		case A_GOMARK:			/* go to mark */
53235209Sbostic 			lower_left();
53335209Sbostic 			clear_eol();
53435209Sbostic 			start_mca(A_GOMARK, "goto mark: ");
53535209Sbostic 			c = getcc();
53635209Sbostic 			if (c == erase_char || c == kill_char)
53735209Sbostic 				break;
53835209Sbostic 			gomark(c);
53935209Sbostic 			break;
54035209Sbostic 		case A_PREFIX:
54135209Sbostic 			/*
54235209Sbostic 			 * The command is incomplete (more chars are needed).
54336299Sbostic 			 * Display the current char so the user knows what's
54436299Sbostic 			 * going on and get another character.
54535209Sbostic 			 */
54635209Sbostic 			if (mca != A_PREFIX)
54736299Sbostic 				start_mca(A_PREFIX, "");
54836299Sbostic 			if (CONTROL_CHAR(c)) {
54935209Sbostic 				putchr('^');
55036251Sbostic 				c = CARAT_CHAR(c);
55135209Sbostic 			}
55235209Sbostic 			putchr(c);
55335209Sbostic 			c = getcc();
55435209Sbostic 			goto again;
55535209Sbostic 		default:
55635209Sbostic 			bell();
55735209Sbostic 			break;
55835209Sbostic 		}
55935209Sbostic 	}
56035209Sbostic }
56135708Sbostic 
editfile()56235708Sbostic editfile()
56335708Sbostic {
56436251Sbostic 	extern char *current_file;
56535708Sbostic 	static int dolinenumber;
56635708Sbostic 	static char *editor;
56735708Sbostic 	int c;
56836251Sbostic 	char buf[MAXPATHLEN * 2 + 20], *getenv();
56935708Sbostic 
57035708Sbostic 	if (editor == NULL) {
57135708Sbostic 		editor = getenv("EDITOR");
57235708Sbostic 		/* pass the line number to vi */
57335708Sbostic 		if (editor == NULL || *editor == '\0') {
57437919Sbostic 			editor = _PATH_VI;
57535708Sbostic 			dolinenumber = 1;
57635708Sbostic 		}
57735708Sbostic 		else
57835708Sbostic 			dolinenumber = 0;
57935708Sbostic 	}
58035708Sbostic 	if (dolinenumber && (c = currline(MIDDLE)))
58135708Sbostic 		(void)sprintf(buf, "%s +%d %s", editor, c, current_file);
58235708Sbostic 	else
58335708Sbostic 		(void)sprintf(buf, "%s %s", editor, current_file);
58435708Sbostic 	lsystem(buf);
58535708Sbostic }
58636294Sbostic 
showlist()58736294Sbostic showlist()
58836294Sbostic {
58936294Sbostic 	extern int sc_width;
59036294Sbostic 	extern char **av;
59136294Sbostic 	register int indx, width;
59236294Sbostic 	int len;
59336294Sbostic 	char *p;
59436294Sbostic 
59536294Sbostic 	if (ac <= 0) {
59636294Sbostic 		error("No files provided as arguments.");
59736294Sbostic 		return;
59836294Sbostic 	}
59936294Sbostic 	for (width = indx = 0; indx < ac;) {
60036294Sbostic 		p = strcmp(av[indx], "-") ? av[indx] : "stdin";
60136294Sbostic 		len = strlen(p) + 1;
60236294Sbostic 		if (curr_ac == indx)
60336294Sbostic 			len += 2;
60436294Sbostic 		if (width + len + 1 >= sc_width) {
60536294Sbostic 			if (!width) {
60636294Sbostic 				if (curr_ac == indx)
60736294Sbostic 					putchr('[');
60836294Sbostic 				putstr(p);
60936294Sbostic 				if (curr_ac == indx)
61036294Sbostic 					putchr(']');
61136294Sbostic 				++indx;
61236294Sbostic 			}
61336294Sbostic 			width = 0;
61436294Sbostic 			putchr('\n');
61536294Sbostic 			continue;
61636294Sbostic 		}
61736294Sbostic 		if (width)
61836294Sbostic 			putchr(' ');
61936294Sbostic 		if (curr_ac == indx)
62036294Sbostic 			putchr('[');
62136294Sbostic 		putstr(p);
62236294Sbostic 		if (curr_ac == indx)
62336294Sbostic 			putchr(']');
62436294Sbostic 		width += len;
62536294Sbostic 		++indx;
62636294Sbostic 	}
62736294Sbostic 	putchr('\n');
62836294Sbostic 	error((char *)NULL);
62936294Sbostic }
630