ed.chared.c revision 59243
159243Sobrien/* $Header: /src/pub/tcsh/ed.chared.c,v 3.59 1999/08/13 16:34:57 christos Exp $ */
259243Sobrien/*
359243Sobrien * ed.chared.c: Character editing functions.
459243Sobrien */
559243Sobrien/*-
659243Sobrien * Copyright (c) 1980, 1991 The Regents of the University of California.
759243Sobrien * All rights reserved.
859243Sobrien *
959243Sobrien * Redistribution and use in source and binary forms, with or without
1059243Sobrien * modification, are permitted provided that the following conditions
1159243Sobrien * are met:
1259243Sobrien * 1. Redistributions of source code must retain the above copyright
1359243Sobrien *    notice, this list of conditions and the following disclaimer.
1459243Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1559243Sobrien *    notice, this list of conditions and the following disclaimer in the
1659243Sobrien *    documentation and/or other materials provided with the distribution.
1759243Sobrien * 3. All advertising materials mentioning features or use of this software
1859243Sobrien *    must display the following acknowledgement:
1959243Sobrien *	This product includes software developed by the University of
2059243Sobrien *	California, Berkeley and its contributors.
2159243Sobrien * 4. Neither the name of the University nor the names of its contributors
2259243Sobrien *    may be used to endorse or promote products derived from this software
2359243Sobrien *    without specific prior written permission.
2459243Sobrien *
2559243Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2659243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2759243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2859243Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2959243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3059243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3159243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3259243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3359243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3459243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3559243Sobrien * SUCH DAMAGE.
3659243Sobrien */
3759243Sobrien/*
3859243Sobrien  Bjorn Knutsson @ Thu Jun 24 19:02:17 1999
3959243Sobrien
4059243Sobrien  e_dabbrev_expand() did not do proper completion if quoted spaces were present
4159243Sobrien  in the string being completed. Exemple:
4259243Sobrien
4359243Sobrien  # echo hello\ world
4459243Sobrien  hello world
4559243Sobrien  # echo h<press key bound to dabbrev-expande>
4659243Sobrien  # echo hello\<cursor>
4759243Sobrien
4859243Sobrien  Correct behavior is:
4959243Sobrien  # echo h<press key bound to dabbrev-expande>
5059243Sobrien  # echo hello\ world<cursor>
5159243Sobrien
5259243Sobrien  The same problem occured if spaces were present in a string withing quotation
5359243Sobrien  marks. Example:
5459243Sobrien
5559243Sobrien  # echo "hello world"
5659243Sobrien  hello world
5759243Sobrien  # echo "h<press key bound to dabbrev-expande>
5859243Sobrien  # echo "hello<cursor>
5959243Sobrien
6059243Sobrien  The former problem could be solved with minor modifications of c_preword()
6159243Sobrien  and c_endword(). The latter, however, required a significant rewrite of
6259243Sobrien  c_preword(), since quoted strings must be parsed from start to end to
6359243Sobrien  determine if a given character is inside or outside the quotation marks.
6459243Sobrien
6559243Sobrien  Compare the following two strings:
6659243Sobrien
6759243Sobrien  # echo \"" 'foo \' bar\"
6859243Sobrien  " 'foo \' bar\
6959243Sobrien  # echo '\"" 'foo \' bar\"
7059243Sobrien  \"" foo ' bar"
7159243Sobrien
7259243Sobrien  The only difference between the two echo lines is in the first character
7359243Sobrien  after the echo command. The result is either one or three arguments.
7459243Sobrien
7559243Sobrien */
7659243Sobrien
7759243Sobrien#include "sh.h"
7859243Sobrien
7959243SobrienRCSID("$Id: ed.chared.c,v 3.59 1999/08/13 16:34:57 christos Exp $")
8059243Sobrien
8159243Sobrien#include "ed.h"
8259243Sobrien#include "tw.h"
8359243Sobrien#include "ed.defns.h"
8459243Sobrien
8559243Sobrien/* #define SDEBUG */
8659243Sobrien
8759243Sobrien#define TCSHOP_NOP    	  0x00
8859243Sobrien#define TCSHOP_DELETE 	  0x01
8959243Sobrien#define TCSHOP_INSERT 	  0x02
9059243Sobrien#define TCSHOP_CHANGE 	  0x04
9159243Sobrien
9259243Sobrien#define CHAR_FWD	0
9359243Sobrien#define CHAR_BACK	1
9459243Sobrien
9559243Sobrien/*
9659243Sobrien * vi word treatment
9759243Sobrien * from: Gert-Jan Vons <vons@cesar.crbca1.sinet.slb.com>
9859243Sobrien */
9959243Sobrien#define C_CLASS_WHITE	1
10059243Sobrien#define C_CLASS_ALNUM	2
10159243Sobrien#define C_CLASS_OTHER	3
10259243Sobrien
10359243Sobrienstatic Char *InsertPos = InputBuf; /* Where insertion starts */
10459243Sobrienstatic Char *ActionPos = 0;	   /* Where action begins  */
10559243Sobrienstatic int  ActionFlag = TCSHOP_NOP;	   /* What delayed action to take */
10659243Sobrien/*
10759243Sobrien * Word search state
10859243Sobrien */
10959243Sobrienstatic int  searchdir = F_UP_SEARCH_HIST; 	/* Direction of last search */
11059243Sobrienstatic Char patbuf[INBUFSIZE];			/* Search target */
11159243Sobrienstatic int patlen = 0;
11259243Sobrien/*
11359243Sobrien * Char search state
11459243Sobrien */
11559243Sobrienstatic int  srch_dir = CHAR_FWD;		/* Direction of last search */
11659243Sobrienstatic Char srch_char = 0;			/* Search target */
11759243Sobrien
11859243Sobrien/* all routines that start with c_ are private to this set of routines */
11959243Sobrienstatic	void	 c_alternativ_key_map	__P((int));
12059243Sobrienstatic	void	 c_insert		__P((int));
12159243Sobrienstatic	void	 c_delafter		__P((int));
12259243Sobrienstatic	void	 c_delbefore		__P((int));
12359243Sobrienstatic 	int	 c_to_class		__P((int));
12459243Sobrienstatic	Char	*c_prev_word		__P((Char *, Char *, int));
12559243Sobrienstatic	Char	*c_next_word		__P((Char *, Char *, int));
12659243Sobrienstatic	Char	*c_number		__P((Char *, int *, int));
12759243Sobrienstatic	Char	*c_expand		__P((Char *));
12859243Sobrienstatic	void	 c_excl			__P((Char *));
12959243Sobrienstatic	void	 c_substitute		__P((void));
13059243Sobrienstatic	void	 c_delfini		__P((void));
13159243Sobrienstatic	int	 c_hmatch		__P((Char *));
13259243Sobrienstatic	void	 c_hsetpat		__P((void));
13359243Sobrien#ifdef COMMENT
13459243Sobrienstatic	void	 c_get_word		__P((Char **, Char **));
13559243Sobrien#endif
13659243Sobrienstatic	Char	*c_preword		__P((Char *, Char *, int));
13759243Sobrienstatic	Char	*c_nexword		__P((Char *, Char *, int));
13859243Sobrienstatic	Char	*c_endword		__P((Char *, Char *, int));
13959243Sobrienstatic	Char	*c_eword		__P((Char *, Char *, int));
14059243Sobrienstatic  CCRETVAL c_get_histline		__P((void));
14159243Sobrienstatic  CCRETVAL c_search_line		__P((Char *, int));
14259243Sobrienstatic  CCRETVAL v_repeat_srch		__P((int));
14359243Sobrienstatic	CCRETVAL e_inc_search		__P((int));
14459243Sobrienstatic	CCRETVAL v_search		__P((int));
14559243Sobrienstatic	CCRETVAL v_csearch_fwd		__P((int, int, int));
14659243Sobrienstatic	CCRETVAL v_action		__P((int));
14759243Sobrienstatic	CCRETVAL v_csearch_back		__P((int, int, int));
14859243Sobrien
14959243Sobrien#if defined(DSPMBYTE)
15059243Sobrienstatic	void 	 e_charfwd_mbyte	__P((int));
15159243Sobrienstatic	void 	 e_charback_mbyte	__P((int));
15259243Sobrienstatic  int extdel;
15359243Sobrienstatic  int extins = 0;
15459243Sobrien#endif
15559243Sobrien
15659243Sobrienstatic void
15759243Sobrienc_alternativ_key_map(state)
15859243Sobrien    int     state;
15959243Sobrien{
16059243Sobrien    switch (state) {
16159243Sobrien    case 0:
16259243Sobrien	CurrentKeyMap = CcKeyMap;
16359243Sobrien	break;
16459243Sobrien    case 1:
16559243Sobrien	CurrentKeyMap = CcAltMap;
16659243Sobrien	break;
16759243Sobrien    default:
16859243Sobrien	return;
16959243Sobrien    }
17059243Sobrien
17159243Sobrien    AltKeyMap = (Char) state;
17259243Sobrien}
17359243Sobrien
17459243Sobrienstatic void
17559243Sobrienc_insert(num)
17659243Sobrien    register int num;
17759243Sobrien{
17859243Sobrien    register Char *cp;
17959243Sobrien
18059243Sobrien    if (LastChar + num >= InputLim)
18159243Sobrien	return;			/* can't go past end of buffer */
18259243Sobrien
18359243Sobrien    if (Cursor < LastChar) {	/* if I must move chars */
18459243Sobrien	for (cp = LastChar; cp >= Cursor; cp--)
18559243Sobrien	    cp[num] = *cp;
18659243Sobrien    }
18759243Sobrien    LastChar += num;
18859243Sobrien}
18959243Sobrien
19059243Sobrienstatic void
19159243Sobrienc_delafter(num)
19259243Sobrien    register int num;
19359243Sobrien{
19459243Sobrien    register Char *cp, *kp = NULL;
19559243Sobrien
19659243Sobrien#if defined(DSPMBYTE)
19759243Sobrien    Char *wkcp;
19859243Sobrien
19959243Sobrien    extdel = 0;
20059243Sobrien#endif
20159243Sobrien
20259243Sobrien    if (num > LastChar - Cursor)
20359243Sobrien	num = (int) (LastChar - Cursor);	/* bounds check */
20459243Sobrien
20559243Sobrien    if (num > 0) {			/* if I can delete anything */
20659243Sobrien#if defined(DSPMBYTE)
20759243Sobrien	/* check for code of deleted character */
20859243Sobrien	if (_enable_mbdisp) {
20959243Sobrien	    for (wkcp = Cursor ; wkcp < Cursor + num; wkcp++) {
21059243Sobrien		if (extdel == 0)
21159243Sobrien		    extdel = Ismbyte1(*wkcp); /* check to 1st. byte */
21259243Sobrien		else
21359243Sobrien		    extdel = 0;	/* if 2nd. byte, force set to 0 */
21459243Sobrien	    }
21559243Sobrien	}
21659243Sobrien#endif
21759243Sobrien	if (VImode) {
21859243Sobrien	    kp = UndoBuf;		/* Set Up for VI undo command */
21959243Sobrien	    UndoAction = TCSHOP_INSERT;
22059243Sobrien	    UndoSize = num;
22159243Sobrien	    UndoPtr  = Cursor;
22259243Sobrien	    for (cp = Cursor; cp <= LastChar; cp++) {
22359243Sobrien		*kp++ = *cp;	/* Save deleted chars into undobuf */
22459243Sobrien		*cp = cp[num];
22559243Sobrien	    }
22659243Sobrien	}
22759243Sobrien	else
22859243Sobrien	    for (cp = Cursor; cp <= LastChar; cp++)
22959243Sobrien		*cp = cp[num];
23059243Sobrien	LastChar -= num;
23159243Sobrien#if defined(DSPMBYTE)
23259243Sobrien	if (_enable_mbdisp && extdel && Ismbyte2(*Cursor)) {
23359243Sobrien	    if( VImode ) {
23459243Sobrien		UndoSize++;
23559243Sobrien		*kp++ = *Cursor; /* Save deleted chars into undobuf */
23659243Sobrien	    }
23759243Sobrien	    for (cp = Cursor; cp <= LastChar; cp++)
23859243Sobrien		*cp = cp[1];
23959243Sobrien	    LastChar--;
24059243Sobrien	    e_redisp( 1 );
24159243Sobrien	}
24259243Sobrien	else
24359243Sobrien	    extdel = 0;
24459243Sobrien#endif
24559243Sobrien    }
24659243Sobrien#ifdef notdef
24759243Sobrien    else {
24859243Sobrien	/*
24959243Sobrien	 * XXX: We don't want to do that. In emacs mode overwrite should be
25059243Sobrien	 * sticky. I am not sure how that affects vi mode
25159243Sobrien	 */
25259243Sobrien	inputmode = MODE_INSERT;
25359243Sobrien    }
25459243Sobrien#endif /* notdef */
25559243Sobrien}
25659243Sobrien
25759243Sobrienstatic void
25859243Sobrienc_delbefore(num)		/* delete before dot, with bounds checking */
25959243Sobrien    register int num;
26059243Sobrien{
26159243Sobrien    register Char *cp, *kp = NULL;
26259243Sobrien
26359243Sobrien#if defined(DSPMBYTE)
26459243Sobrien    Char *nowcur, *wkcp;
26559243Sobrien    Char delc;
26659243Sobrien
26759243Sobrien    extdel = 0;
26859243Sobrien#endif
26959243Sobrien
27059243Sobrien    if (num > Cursor - InputBuf)
27159243Sobrien	num = (int) (Cursor - InputBuf);	/* bounds check */
27259243Sobrien
27359243Sobrien    if (num > 0) {			/* if I can delete anything */
27459243Sobrien#if defined(DSPMBYTE)
27559243Sobrien	nowcur = Cursor - num;
27659243Sobrien	delc = *nowcur;
27759243Sobrien#endif
27859243Sobrien	if (VImode) {
27959243Sobrien	    kp = UndoBuf;		/* Set Up for VI undo command */
28059243Sobrien	    UndoAction = TCSHOP_INSERT;
28159243Sobrien	    UndoSize = num;
28259243Sobrien	    UndoPtr  = Cursor - num;
28359243Sobrien	    for (cp = Cursor - num; cp <= LastChar; cp++) {
28459243Sobrien		*kp++ = *cp;
28559243Sobrien		*cp = cp[num];
28659243Sobrien	    }
28759243Sobrien	}
28859243Sobrien	else
28959243Sobrien	    for (cp = Cursor - num; cp <= LastChar; cp++)
29059243Sobrien		*cp = cp[num];
29159243Sobrien	LastChar -= num;
29259243Sobrien#if defined(DSPMBYTE)
29359243Sobrien	if (_enable_mbdisp) {
29459243Sobrien	    for (wkcp = InputBuf; wkcp < nowcur; wkcp++) {
29559243Sobrien		if(extdel == 0)
29659243Sobrien		    extdel = Ismbyte1(*wkcp); /* check to 1st. byte */
29759243Sobrien		else
29859243Sobrien		    extdel = 0;	/* if 2nd. byte, force set to 0 */
29959243Sobrien	    }
30059243Sobrien	    if (extdel && Ismbyte2(delc)) {
30159243Sobrien		if( VImode ) {
30259243Sobrien		    UndoSize++;
30359243Sobrien		    UndoPtr--;
30459243Sobrien		    *kp++ = *(nowcur-1);
30559243Sobrien				/* Save deleted chars into undobuf */
30659243Sobrien		}
30759243Sobrien		for (cp = nowcur - 1; cp <= LastChar; cp++)
30859243Sobrien		    *cp = cp[1];
30959243Sobrien		LastChar--;
31059243Sobrien	    }
31159243Sobrien	}
31259243Sobrien	else
31359243Sobrien	    extdel = 0;
31459243Sobrien#endif
31559243Sobrien    }
31659243Sobrien}
31759243Sobrien
31859243Sobrienstatic Char *
31959243Sobrienc_preword(p, low, n)
32059243Sobrien    register Char *p, *low;
32159243Sobrien    register int n;
32259243Sobrien{
32359243Sobrien  while (n--) {
32459243Sobrien    register Char *prev = low;
32559243Sobrien    register Char *new;
32659243Sobrien
32759243Sobrien    while (prev < p) {		/* Skip initial spaces */
32859243Sobrien      if (!Isspace(*prev) || (Isspace(*prev) && *(prev-1) == (Char)'\\'))
32959243Sobrien	break;
33059243Sobrien      prev++;
33159243Sobrien    }
33259243Sobrien
33359243Sobrien    new = prev;
33459243Sobrien
33559243Sobrien    while (new < p) {
33659243Sobrien      prev = new;
33759243Sobrien      new = c_endword(prev-1, p, 1);	/* Skip to next space */
33859243Sobrien      new++;			/* Step away from end of word */
33959243Sobrien      while (new <= p) {	/* Skip trailing spaces */
34059243Sobrien	if (!Isspace(*new) || (Isspace(*new) && *(new-1) == (Char)'\\'))
34159243Sobrien	  break;
34259243Sobrien	new++;
34359243Sobrien      }
34459243Sobrien    }
34559243Sobrien
34659243Sobrien    p = prev;			/* Set to previous word start */
34759243Sobrien
34859243Sobrien  }
34959243Sobrien  if (p < low)
35059243Sobrien    p = low;
35159243Sobrien  return (p);
35259243Sobrien}
35359243Sobrien
35459243Sobrien/*
35559243Sobrien * c_to_class() returns the class of the given character.
35659243Sobrien *
35759243Sobrien * This is used to make the c_prev_word() and c_next_word() functions
35859243Sobrien * work like vi's, which classify characters. A word is a sequence of
35959243Sobrien * characters belonging to the same class, classes being defined as
36059243Sobrien * follows:
36159243Sobrien *
36259243Sobrien *	1/ whitespace
36359243Sobrien *	2/ alphanumeric chars, + underscore
36459243Sobrien *	3/ others
36559243Sobrien */
36659243Sobrienstatic int
36759243Sobrienc_to_class(ch)
36859243Sobrienregister int  ch;
36959243Sobrien{
37059243Sobrien    if (Isspace(ch))
37159243Sobrien        return C_CLASS_WHITE;
37259243Sobrien
37359243Sobrien    if (Isdigit(ch) || Isalpha(ch) || ch == '_')
37459243Sobrien        return C_CLASS_ALNUM;
37559243Sobrien
37659243Sobrien    return C_CLASS_OTHER;
37759243Sobrien}
37859243Sobrien
37959243Sobrienstatic Char *
38059243Sobrienc_prev_word(p, low, n)
38159243Sobrien    register Char *p, *low;
38259243Sobrien    register int n;
38359243Sobrien{
38459243Sobrien    p--;
38559243Sobrien
38659243Sobrien    if (!VImode) {
38759243Sobrien	while (n--) {
38859243Sobrien	    while ((p >= low) && !isword(*p))
38959243Sobrien		p--;
39059243Sobrien	    while ((p >= low) && isword(*p))
39159243Sobrien		p--;
39259243Sobrien	}
39359243Sobrien
39459243Sobrien	/* cp now points to one character before the word */
39559243Sobrien	p++;
39659243Sobrien	if (p < low)
39759243Sobrien	    p = low;
39859243Sobrien	/* cp now points where we want it */
39959243Sobrien	return(p);
40059243Sobrien    }
40159243Sobrien
40259243Sobrien    while (n--) {
40359243Sobrien        register int  c_class;
40459243Sobrien
40559243Sobrien        if (p < low)
40659243Sobrien            break;
40759243Sobrien
40859243Sobrien        /* scan until beginning of current word (may be all whitespace!) */
40959243Sobrien        c_class = c_to_class(*p);
41059243Sobrien        while ((p >= low) && c_class == c_to_class(*p))
41159243Sobrien            p--;
41259243Sobrien
41359243Sobrien        /* if this was a non_whitespace word, we're ready */
41459243Sobrien        if (c_class != C_CLASS_WHITE)
41559243Sobrien            continue;
41659243Sobrien
41759243Sobrien        /* otherwise, move back to beginning of the word just found */
41859243Sobrien        c_class = c_to_class(*p);
41959243Sobrien        while ((p >= low) && c_class == c_to_class(*p))
42059243Sobrien            p--;
42159243Sobrien    }
42259243Sobrien
42359243Sobrien    p++;                        /* correct overshoot */
42459243Sobrien
42559243Sobrien    return (p);
42659243Sobrien}
42759243Sobrien
42859243Sobrienstatic Char *
42959243Sobrienc_next_word(p, high, n)
43059243Sobrien    register Char *p, *high;
43159243Sobrien    register int n;
43259243Sobrien{
43359243Sobrien    if (!VImode) {
43459243Sobrien	while (n--) {
43559243Sobrien	    while ((p < high) && !isword(*p))
43659243Sobrien		p++;
43759243Sobrien	    while ((p < high) && isword(*p))
43859243Sobrien		p++;
43959243Sobrien	}
44059243Sobrien	if (p > high)
44159243Sobrien	    p = high;
44259243Sobrien	/* p now points where we want it */
44359243Sobrien	return(p);
44459243Sobrien    }
44559243Sobrien
44659243Sobrien    while (n--) {
44759243Sobrien        register int  c_class;
44859243Sobrien
44959243Sobrien        if (p >= high)
45059243Sobrien            break;
45159243Sobrien
45259243Sobrien        /* scan until end of current word (may be all whitespace!) */
45359243Sobrien        c_class = c_to_class(*p);
45459243Sobrien        while ((p < high) && c_class == c_to_class(*p))
45559243Sobrien            p++;
45659243Sobrien
45759243Sobrien        /* if this was all whitespace, we're ready */
45859243Sobrien        if (c_class == C_CLASS_WHITE)
45959243Sobrien            continue;
46059243Sobrien
46159243Sobrien	/* if we've found white-space at the end of the word, skip it */
46259243Sobrien        while ((p < high) && c_to_class(*p) == C_CLASS_WHITE)
46359243Sobrien            p++;
46459243Sobrien    }
46559243Sobrien
46659243Sobrien    p--;                        /* correct overshoot */
46759243Sobrien
46859243Sobrien    return (p);
46959243Sobrien}
47059243Sobrien
47159243Sobrienstatic Char *
47259243Sobrienc_nexword(p, high, n)
47359243Sobrien    register Char *p, *high;
47459243Sobrien    register int n;
47559243Sobrien{
47659243Sobrien    while (n--) {
47759243Sobrien	while ((p < high) && !Isspace(*p))
47859243Sobrien	    p++;
47959243Sobrien	while ((p < high) && Isspace(*p))
48059243Sobrien	    p++;
48159243Sobrien    }
48259243Sobrien
48359243Sobrien    if (p > high)
48459243Sobrien	p = high;
48559243Sobrien    /* p now points where we want it */
48659243Sobrien    return(p);
48759243Sobrien}
48859243Sobrien
48959243Sobrien/*
49059243Sobrien * Expand-History (originally "Magic-Space") code added by
49159243Sobrien * Ray Moody <ray@gibbs.physics.purdue.edu>
49259243Sobrien * this is a neat, but odd, addition.
49359243Sobrien */
49459243Sobrien
49559243Sobrien/*
49659243Sobrien * c_number: Ignore character p points to, return number appearing after that.
49759243Sobrien * A '$' by itself means a big number; "$-" is for negative; '^' means 1.
49859243Sobrien * Return p pointing to last char used.
49959243Sobrien */
50059243Sobrien
50159243Sobrien/*
50259243Sobrien * dval is the number to subtract from for things like $-3
50359243Sobrien */
50459243Sobrien
50559243Sobrienstatic Char *
50659243Sobrienc_number(p, num, dval)
50759243Sobrien    register Char *p;
50859243Sobrien    register int *num;
50959243Sobrien    register int dval;
51059243Sobrien{
51159243Sobrien    register int i;
51259243Sobrien    register int sign = 1;
51359243Sobrien
51459243Sobrien    if (*++p == '^') {
51559243Sobrien	*num = 1;
51659243Sobrien	return(p);
51759243Sobrien    }
51859243Sobrien    if (*p == '$') {
51959243Sobrien	if (*++p != '-') {
52059243Sobrien	    *num = NCARGS;	/* Handle $ */
52159243Sobrien	    return(--p);
52259243Sobrien	}
52359243Sobrien	sign = -1;		/* Handle $- */
52459243Sobrien	++p;
52559243Sobrien    }
52659243Sobrien    for (i = 0; *p >= '0' && *p <= '9'; i = 10 * i + *p++ - '0')
52759243Sobrien	continue;
52859243Sobrien    *num = (sign < 0 ? dval - i : i);
52959243Sobrien    return(--p);
53059243Sobrien}
53159243Sobrien
53259243Sobrien/*
53359243Sobrien * excl_expand: There is an excl to be expanded to p -- do the right thing
53459243Sobrien * with it and return a version of p advanced over the expanded stuff.  Also,
53559243Sobrien * update tsh_cur and related things as appropriate...
53659243Sobrien */
53759243Sobrien
53859243Sobrienstatic Char *
53959243Sobrienc_expand(p)
54059243Sobrien    register Char *p;
54159243Sobrien{
54259243Sobrien    register Char *q;
54359243Sobrien    register struct Hist *h = Histlist.Hnext;
54459243Sobrien    register struct wordent *l;
54559243Sobrien    int     i, from, to, dval;
54659243Sobrien    bool    all_dig;
54759243Sobrien    bool    been_once = 0;
54859243Sobrien    Char   *op = p;
54959243Sobrien    Char    buf[INBUFSIZE];
55059243Sobrien    Char   *bend = buf;
55159243Sobrien    Char   *modbuf, *omodbuf;
55259243Sobrien
55359243Sobrien    if (!h)
55459243Sobrien	goto excl_err;
55559243Sobrienexcl_sw:
55659243Sobrien    switch (*(q = p + 1)) {
55759243Sobrien
55859243Sobrien    case '^':
55959243Sobrien	bend = expand_lex(buf, INBUFSIZE, &h->Hlex, 1, 1);
56059243Sobrien	break;
56159243Sobrien
56259243Sobrien    case '$':
56359243Sobrien	if ((l = (h->Hlex).prev) != 0)
56459243Sobrien	    bend = expand_lex(buf, INBUFSIZE, l->prev->prev, 0, 0);
56559243Sobrien	break;
56659243Sobrien
56759243Sobrien    case '*':
56859243Sobrien	bend = expand_lex(buf, INBUFSIZE, &h->Hlex, 1, NCARGS);
56959243Sobrien	break;
57059243Sobrien
57159243Sobrien    default:
57259243Sobrien	if (been_once) {	/* unknown argument */
57359243Sobrien	    /* assume it's a modifier, e.g. !foo:h, and get whole cmd */
57459243Sobrien	    bend = expand_lex(buf, INBUFSIZE, &h->Hlex, 0, NCARGS);
57559243Sobrien	    q -= 2;
57659243Sobrien	    break;
57759243Sobrien	}
57859243Sobrien	been_once = 1;
57959243Sobrien
58059243Sobrien	if (*q == ':')		/* short form: !:arg */
58159243Sobrien	    --q;
58259243Sobrien
58359243Sobrien	if (*q != HIST) {
58459243Sobrien	    /*
58559243Sobrien	     * Search for a space, tab, or colon.  See if we have a number (as
58659243Sobrien	     * in !1234:xyz).  Remember the number.
58759243Sobrien	     */
58859243Sobrien	    for (i = 0, all_dig = 1;
58959243Sobrien		 *q != ' ' && *q != '\t' && *q != ':' && q < Cursor; q++) {
59059243Sobrien		/*
59159243Sobrien		 * PWP: !-4 is a valid history argument too, therefore the test
59259243Sobrien		 * is if not a digit, or not a - as the first character.
59359243Sobrien		 */
59459243Sobrien		if ((*q < '0' || *q > '9') && (*q != '-' || q != p + 1))
59559243Sobrien		    all_dig = 0;
59659243Sobrien		else if (*q == '-')
59759243Sobrien		    all_dig = 2;/* we are sneeky about this */
59859243Sobrien		else
59959243Sobrien		    i = 10 * i + *q - '0';
60059243Sobrien	    }
60159243Sobrien	    --q;
60259243Sobrien
60359243Sobrien	    /*
60459243Sobrien	     * If we have a number, search for event i.  Otherwise, search for
60559243Sobrien	     * a named event (as in !foo).  (In this case, I is the length of
60659243Sobrien	     * the named event).
60759243Sobrien	     */
60859243Sobrien	    if (all_dig) {
60959243Sobrien		if (all_dig == 2)
61059243Sobrien		    i = -i;	/* make it negitive */
61159243Sobrien		if (i < 0)	/* if !-4 (for example) */
61259243Sobrien		    i = eventno + 1 + i;	/* remember: i is < 0 */
61359243Sobrien		for (; h; h = h->Hnext) {
61459243Sobrien		    if (h->Hnum == i)
61559243Sobrien			break;
61659243Sobrien		}
61759243Sobrien	    }
61859243Sobrien	    else {
61959243Sobrien		for (i = (int) (q - p); h; h = h->Hnext) {
62059243Sobrien		    if ((l = &h->Hlex) != 0) {
62159243Sobrien			if (!Strncmp(p + 1, l->next->word, (size_t) i))
62259243Sobrien			    break;
62359243Sobrien		    }
62459243Sobrien		}
62559243Sobrien	    }
62659243Sobrien	}
62759243Sobrien	if (!h)
62859243Sobrien	    goto excl_err;
62959243Sobrien	if (q[1] == ':' || q[1] == '-' || q[1] == '*' ||
63059243Sobrien	    q[1] == '$' || q[1] == '^') {	/* get some args */
63159243Sobrien	    p = q[1] == ':' ? ++q : q;
63259243Sobrien	    /*
63359243Sobrien	     * Go handle !foo:*
63459243Sobrien	     */
63559243Sobrien	    if ((q[1] < '0' || q[1] > '9') &&
63659243Sobrien		q[1] != '-' && q[1] != '$' && q[1] != '^')
63759243Sobrien		goto excl_sw;
63859243Sobrien	    /*
63959243Sobrien	     * Go handle !foo:$
64059243Sobrien	     */
64159243Sobrien	    if (q[1] == '$' && (q[2] != '-' || q[3] < '0' || q[3] > '9'))
64259243Sobrien		goto excl_sw;
64359243Sobrien	    /*
64459243Sobrien	     * Count up the number of words in this event.  Store it in dval.
64559243Sobrien	     * Dval will be fed to number.
64659243Sobrien	     */
64759243Sobrien	    dval = 0;
64859243Sobrien	    if ((l = h->Hlex.prev) != 0) {
64959243Sobrien		for (l = l->prev; l != h->Hlex.next; l = l->prev, dval++)
65059243Sobrien		    continue;
65159243Sobrien	    }
65259243Sobrien	    if (!dval)
65359243Sobrien		goto excl_err;
65459243Sobrien	    if (q[1] == '-')
65559243Sobrien		from = 0;
65659243Sobrien	    else
65759243Sobrien		q = c_number(q, &from, dval);
65859243Sobrien	    if (q[1] == '-') {
65959243Sobrien		++q;
66059243Sobrien		if ((q[1] < '0' || q[1] > '9') && q[1] != '$')
66159243Sobrien		    to = dval - 1;
66259243Sobrien		else
66359243Sobrien		    q = c_number(q, &to, dval);
66459243Sobrien	    }
66559243Sobrien	    else if (q[1] == '*') {
66659243Sobrien		++q;
66759243Sobrien		to = NCARGS;
66859243Sobrien	    }
66959243Sobrien	    else {
67059243Sobrien		to = from;
67159243Sobrien	    }
67259243Sobrien	    if (from < 0 || to < from)
67359243Sobrien		goto excl_err;
67459243Sobrien	    bend = expand_lex(buf, INBUFSIZE, &h->Hlex, from, to);
67559243Sobrien	}
67659243Sobrien	else {			/* get whole cmd */
67759243Sobrien	    bend = expand_lex(buf, INBUFSIZE, &h->Hlex, 0, NCARGS);
67859243Sobrien	}
67959243Sobrien	break;
68059243Sobrien    }
68159243Sobrien
68259243Sobrien    /*
68359243Sobrien     * Apply modifiers, if any.
68459243Sobrien     */
68559243Sobrien    if (q[1] == ':') {
68659243Sobrien	*bend = '\0';
68759243Sobrien	modbuf = omodbuf = buf;
68859243Sobrien	while (q[1] == ':' && modbuf != NULL) {
68959243Sobrien	    switch (q[2]) {
69059243Sobrien	    case 'r':
69159243Sobrien	    case 'e':
69259243Sobrien	    case 'h':
69359243Sobrien	    case 't':
69459243Sobrien	    case 'q':
69559243Sobrien	    case 'x':
69659243Sobrien	    case 'u':
69759243Sobrien	    case 'l':
69859243Sobrien		if ((modbuf = domod(omodbuf, (int) q[2])) != NULL) {
69959243Sobrien		    if (omodbuf != buf)
70059243Sobrien			xfree((ptr_t) omodbuf);
70159243Sobrien		    omodbuf = modbuf;
70259243Sobrien		}
70359243Sobrien		++q;
70459243Sobrien		break;
70559243Sobrien
70659243Sobrien	    case 'a':
70759243Sobrien	    case 'g':
70859243Sobrien		/* Not implemented; this needs to be done before expanding
70959243Sobrien		 * lex. We don't have the words available to us anymore.
71059243Sobrien		 */
71159243Sobrien		++q;
71259243Sobrien		break;
71359243Sobrien
71459243Sobrien	    case 'p':
71559243Sobrien		/* Ok */
71659243Sobrien		++q;
71759243Sobrien		break;
71859243Sobrien
71959243Sobrien	    case '\0':
72059243Sobrien		break;
72159243Sobrien
72259243Sobrien	    default:
72359243Sobrien		++q;
72459243Sobrien		break;
72559243Sobrien	    }
72659243Sobrien	    if (q[1])
72759243Sobrien		++q;
72859243Sobrien	}
72959243Sobrien	if (omodbuf != buf) {
73059243Sobrien	    (void) Strcpy(buf, omodbuf);
73159243Sobrien	    xfree((ptr_t) omodbuf);
73259243Sobrien	    bend = Strend(buf);
73359243Sobrien	}
73459243Sobrien    }
73559243Sobrien
73659243Sobrien    /*
73759243Sobrien     * Now replace the text from op to q inclusive with the text from buf to
73859243Sobrien     * bend.
73959243Sobrien     */
74059243Sobrien    q++;
74159243Sobrien
74259243Sobrien    /*
74359243Sobrien     * Now replace text non-inclusively like a real CS major!
74459243Sobrien     */
74559243Sobrien    if (LastChar + (bend - buf) - (q - op) >= InputLim)
74659243Sobrien	goto excl_err;
74759243Sobrien    (void) memmove((ptr_t) (q + (bend - buf) - (q - op)), (ptr_t) q,
74859243Sobrien		   (size_t) ((LastChar - q) * sizeof(Char)));
74959243Sobrien    LastChar += (bend - buf) - (q - op);
75059243Sobrien    Cursor += (bend - buf) - (q - op);
75159243Sobrien    (void) memmove((ptr_t) op, (ptr_t) buf,
75259243Sobrien		   (size_t) ((bend - buf) * sizeof(Char)));
75359243Sobrien    *LastChar = '\0';
75459243Sobrien    return(op + (bend - buf));
75559243Sobrienexcl_err:
75659243Sobrien    SoundBeep();
75759243Sobrien    return(op + 1);
75859243Sobrien}
75959243Sobrien
76059243Sobrien/*
76159243Sobrien * c_excl: An excl has been found at point p -- back up and find some white
76259243Sobrien * space (or the beginning of the buffer) and properly expand all the excl's
76359243Sobrien * from there up to the current cursor position. We also avoid (trying to)
76459243Sobrien * expanding '>!'
76559243Sobrien */
76659243Sobrien
76759243Sobrienstatic void
76859243Sobrienc_excl(p)
76959243Sobrien    register Char *p;
77059243Sobrien{
77159243Sobrien    register int i;
77259243Sobrien    register Char *q;
77359243Sobrien
77459243Sobrien    /*
77559243Sobrien     * if />[SPC TAB]*![SPC TAB]/, back up p to just after the >. otherwise,
77659243Sobrien     * back p up to just before the current word.
77759243Sobrien     */
77859243Sobrien    if ((p[1] == ' ' || p[1] == '\t') &&
77959243Sobrien	(p[-1] == ' ' || p[-1] == '\t' || p[-1] == '>')) {
78059243Sobrien	for (q = p - 1; q > InputBuf && (*q == ' ' || *q == '\t'); --q)
78159243Sobrien	    continue;
78259243Sobrien	if (*q == '>')
78359243Sobrien	    ++p;
78459243Sobrien    }
78559243Sobrien    else {
78659243Sobrien	while (*p != ' ' && *p != '\t' && p > InputBuf)
78759243Sobrien	    --p;
78859243Sobrien    }
78959243Sobrien
79059243Sobrien    /*
79159243Sobrien     * Forever: Look for history char.  (Stop looking when we find the cursor.)
79259243Sobrien     * Count backslashes.  Of odd, skip history char. Return if all done.
79359243Sobrien     * Expand if even number of backslashes.
79459243Sobrien     */
79559243Sobrien    for (;;) {
79659243Sobrien	while (*p != HIST && p < Cursor)
79759243Sobrien	    ++p;
79859243Sobrien	for (i = 1; (p - i) >= InputBuf && p[-i] == '\\'; i++)
79959243Sobrien	    continue;
80059243Sobrien	if (i % 2 == 0)
80159243Sobrien	    ++p;
80259243Sobrien	if (p >= Cursor)
80359243Sobrien	    return;
80459243Sobrien	if (i % 2 == 1)
80559243Sobrien	    p = c_expand(p);
80659243Sobrien    }
80759243Sobrien}
80859243Sobrien
80959243Sobrien
81059243Sobrienstatic void
81159243Sobrienc_substitute()
81259243Sobrien{
81359243Sobrien    register Char *p;
81459243Sobrien
81559243Sobrien    /*
81659243Sobrien     * Start p out one character before the cursor.  Move it backwards looking
81759243Sobrien     * for white space, the beginning of the line, or a history character.
81859243Sobrien     */
81959243Sobrien    for (p = Cursor - 1;
82059243Sobrien	 p > InputBuf && *p != ' ' && *p != '\t' && *p != HIST; --p)
82159243Sobrien	continue;
82259243Sobrien
82359243Sobrien    /*
82459243Sobrien     * If we found a history character, go expand it.
82559243Sobrien     */
82659243Sobrien    if (*p == HIST)
82759243Sobrien	c_excl(p);
82859243Sobrien    Refresh();
82959243Sobrien}
83059243Sobrien
83159243Sobrienstatic void
83259243Sobrienc_delfini()		/* Finish up delete action */
83359243Sobrien{
83459243Sobrien    register int Size;
83559243Sobrien
83659243Sobrien    if (ActionFlag & TCSHOP_INSERT)
83759243Sobrien	c_alternativ_key_map(0);
83859243Sobrien
83959243Sobrien    ActionFlag = TCSHOP_NOP;
84059243Sobrien
84159243Sobrien    if (ActionPos == 0)
84259243Sobrien	return;
84359243Sobrien
84459243Sobrien    UndoAction = TCSHOP_INSERT;
84559243Sobrien
84659243Sobrien    if (Cursor > ActionPos) {
84759243Sobrien	Size = (int) (Cursor-ActionPos);
84859243Sobrien	c_delbefore(Size);
84959243Sobrien	Cursor = ActionPos;
85059243Sobrien#if defined(DSPMBYTE)
85159243Sobrien	if (_enable_mbdisp && extdel) {
85259243Sobrien	    Cursor--;
85359243Sobrien	    e_redisp(1);
85459243Sobrien	}
85559243Sobrien#endif
85659243Sobrien	RefCursor();
85759243Sobrien    }
85859243Sobrien    else if (Cursor < ActionPos) {
85959243Sobrien	Size = (int)(ActionPos-Cursor);
86059243Sobrien	c_delafter(Size);
86159243Sobrien    }
86259243Sobrien    else  {
86359243Sobrien	Size = 1;
86459243Sobrien	c_delafter(Size);
86559243Sobrien    }
86659243Sobrien    UndoPtr = Cursor;
86759243Sobrien    UndoSize = Size;
86859243Sobrien}
86959243Sobrien
87059243Sobrienstatic Char *
87159243Sobrienc_endword(p, high, n)
87259243Sobrien    register Char *p, *high;
87359243Sobrien    register int n;
87459243Sobrien{
87559243Sobrien    register int inquote = 0;
87659243Sobrien    p++;
87759243Sobrien
87859243Sobrien    while (n--) {
87959243Sobrien        while (p < high) {	/* Skip spaces */
88059243Sobrien	  if (!Isspace(*p) || (Isspace(*p) && *(p-1) == (Char)'\\'))
88159243Sobrien	    break;
88259243Sobrien	  p++;
88359243Sobrien        }
88459243Sobrien	while (p < high) {	/* Skip string */
88559243Sobrien	  if ((*p == (Char)'\'' || *p == (Char)'"')) { /* Quotation marks? */
88659243Sobrien	    if ((!inquote && *(p-1) != (Char)'\\') || inquote) { /* Should it be honored? */
88759243Sobrien	      if (inquote == 0) inquote = *p;
88859243Sobrien	      else if (inquote == *p) inquote = 0;
88959243Sobrien	    }
89059243Sobrien	  }
89159243Sobrien	  if (!inquote && (Isspace(*p) && *(p-1) != (Char)'\\')) /* Break if unquoted space */
89259243Sobrien	    break;
89359243Sobrien	  p++;
89459243Sobrien	}
89559243Sobrien    }
89659243Sobrien
89759243Sobrien    p--;
89859243Sobrien    return(p);
89959243Sobrien}
90059243Sobrien
90159243Sobrien
90259243Sobrienstatic Char *
90359243Sobrienc_eword(p, high, n)
90459243Sobrien    register Char *p, *high;
90559243Sobrien    register int n;
90659243Sobrien{
90759243Sobrien    p++;
90859243Sobrien
90959243Sobrien    while (n--) {
91059243Sobrien	while ((p < high) && Isspace(*p))
91159243Sobrien	    p++;
91259243Sobrien
91359243Sobrien	if (Isalnum(*p))
91459243Sobrien	    while ((p < high) && Isalnum(*p))
91559243Sobrien		p++;
91659243Sobrien	else
91759243Sobrien	    while ((p < high) && !(Isspace(*p) || Isalnum(*p)))
91859243Sobrien		p++;
91959243Sobrien    }
92059243Sobrien
92159243Sobrien    p--;
92259243Sobrien    return(p);
92359243Sobrien}
92459243Sobrien
92559243Sobrienstatic CCRETVAL
92659243Sobrienc_get_histline()
92759243Sobrien{
92859243Sobrien    struct Hist *hp;
92959243Sobrien    int     h;
93059243Sobrien
93159243Sobrien    if (Hist_num == 0) {	/* if really the current line */
93259243Sobrien	copyn(InputBuf, HistBuf, INBUFSIZE);
93359243Sobrien	LastChar = InputBuf + (LastHist - HistBuf);
93459243Sobrien
93559243Sobrien#ifdef KSHVI
93659243Sobrien    if (VImode)
93759243Sobrien	Cursor = InputBuf;
93859243Sobrien    else
93959243Sobrien#endif /* KSHVI */
94059243Sobrien	Cursor = LastChar;
94159243Sobrien
94259243Sobrien	return(CC_REFRESH);
94359243Sobrien    }
94459243Sobrien
94559243Sobrien    hp = Histlist.Hnext;
94659243Sobrien    if (hp == NULL)
94759243Sobrien	return(CC_ERROR);
94859243Sobrien
94959243Sobrien    for (h = 1; h < Hist_num; h++) {
95059243Sobrien	if ((hp->Hnext) == NULL) {
95159243Sobrien	    Hist_num = h;
95259243Sobrien	    return(CC_ERROR);
95359243Sobrien	}
95459243Sobrien	hp = hp->Hnext;
95559243Sobrien    }
95659243Sobrien
95759243Sobrien    if (HistLit && hp->histline) {
95859243Sobrien	copyn(InputBuf, hp->histline, INBUFSIZE);
95959243Sobrien	CurrentHistLit = 1;
96059243Sobrien    }
96159243Sobrien    else {
96259243Sobrien	(void) sprlex(InputBuf, sizeof(InputBuf), &hp->Hlex);
96359243Sobrien	CurrentHistLit = 0;
96459243Sobrien    }
96559243Sobrien    LastChar = InputBuf + Strlen(InputBuf);
96659243Sobrien
96759243Sobrien    if (LastChar > InputBuf) {
96859243Sobrien	if (LastChar[-1] == '\n')
96959243Sobrien	    LastChar--;
97059243Sobrien#if 0
97159243Sobrien	if (LastChar[-1] == ' ')
97259243Sobrien	    LastChar--;
97359243Sobrien#endif
97459243Sobrien	if (LastChar < InputBuf)
97559243Sobrien	    LastChar = InputBuf;
97659243Sobrien    }
97759243Sobrien
97859243Sobrien#ifdef KSHVI
97959243Sobrien    if (VImode)
98059243Sobrien	Cursor = InputBuf;
98159243Sobrien    else
98259243Sobrien#endif /* KSHVI */
98359243Sobrien	Cursor = LastChar;
98459243Sobrien
98559243Sobrien    return(CC_REFRESH);
98659243Sobrien}
98759243Sobrien
98859243Sobrienstatic CCRETVAL
98959243Sobrienc_search_line(pattern, dir)
99059243SobrienChar *pattern;
99159243Sobrienint dir;
99259243Sobrien{
99359243Sobrien    Char *cp;
99459243Sobrien    int len;
99559243Sobrien
99659243Sobrien    len = (int) Strlen(pattern);
99759243Sobrien
99859243Sobrien    if (dir == F_UP_SEARCH_HIST) {
99959243Sobrien	for (cp = Cursor; cp >= InputBuf; cp--)
100059243Sobrien	    if (Strncmp(cp, pattern, (size_t) len) == 0 ||
100159243Sobrien		Gmatch(cp, pattern)) {
100259243Sobrien		Cursor = cp;
100359243Sobrien		return(CC_NORM);
100459243Sobrien	    }
100559243Sobrien	return(CC_ERROR);
100659243Sobrien    } else {
100759243Sobrien	for (cp = Cursor; *cp != '\0' && cp < InputLim; cp++)
100859243Sobrien	    if (Strncmp(cp, pattern, (size_t) len) == 0 ||
100959243Sobrien		Gmatch(cp, pattern)) {
101059243Sobrien		Cursor = cp;
101159243Sobrien		return(CC_NORM);
101259243Sobrien	    }
101359243Sobrien	return(CC_ERROR);
101459243Sobrien    }
101559243Sobrien}
101659243Sobrien
101759243Sobrienstatic CCRETVAL
101859243Sobriene_inc_search(dir)
101959243Sobrien    int dir;
102059243Sobrien{
102159243Sobrien    static Char STRfwd[] = { 'f', 'w', 'd', '\0' },
102259243Sobrien		STRbck[] = { 'b', 'c', 'k', '\0' };
102359243Sobrien    static Char pchar = ':';	/* ':' = normal, '?' = failed */
102459243Sobrien    static Char endcmd[2];
102559243Sobrien    Char ch, *cp,
102659243Sobrien	*oldCursor = Cursor,
102759243Sobrien	oldpchar = pchar;
102859243Sobrien    CCRETVAL ret = CC_NORM;
102959243Sobrien    int oldHist_num = Hist_num,
103059243Sobrien	oldpatlen = patlen,
103159243Sobrien	newdir = dir,
103259243Sobrien        done, redo;
103359243Sobrien
103459243Sobrien    if (LastChar + sizeof(STRfwd)/sizeof(Char) + 2 + patlen >= InputLim)
103559243Sobrien	return(CC_ERROR);
103659243Sobrien
103759243Sobrien    for (;;) {
103859243Sobrien
103959243Sobrien	if (patlen == 0) {	/* first round */
104059243Sobrien	    pchar = ':';
104159243Sobrien	    patbuf[patlen++] = '*';
104259243Sobrien	}
104359243Sobrien	done = redo = 0;
104459243Sobrien	*LastChar++ = '\n';
104559243Sobrien	for (cp = newdir == F_UP_SEARCH_HIST ? STRbck : STRfwd;
104659243Sobrien	     *cp; *LastChar++ = *cp++)
104759243Sobrien	    continue;
104859243Sobrien	*LastChar++ = pchar;
104959243Sobrien	for (cp = &patbuf[1]; cp < &patbuf[patlen]; *LastChar++ = *cp++)
105059243Sobrien	    continue;
105159243Sobrien	*LastChar = '\0';
105259243Sobrien	Refresh();
105359243Sobrien
105459243Sobrien	if (GetNextChar(&ch) != 1)
105559243Sobrien	    return(e_send_eof(0));
105659243Sobrien
105759243Sobrien	switch (CurrentKeyMap[(unsigned char) ch]) {
105859243Sobrien	case F_INSERT:
105959243Sobrien	case F_DIGIT:
106059243Sobrien	case F_MAGIC_SPACE:
106159243Sobrien	    if (patlen > INBUFSIZE - 3)
106259243Sobrien		SoundBeep();
106359243Sobrien	    else {
106459243Sobrien		patbuf[patlen++] = ch;
106559243Sobrien		*LastChar++ = ch;
106659243Sobrien		*LastChar = '\0';
106759243Sobrien		Refresh();
106859243Sobrien	    }
106959243Sobrien	    break;
107059243Sobrien
107159243Sobrien	case F_INC_FWD:
107259243Sobrien	    newdir = F_DOWN_SEARCH_HIST;
107359243Sobrien	    redo++;
107459243Sobrien	    break;
107559243Sobrien
107659243Sobrien	case F_INC_BACK:
107759243Sobrien	    newdir = F_UP_SEARCH_HIST;
107859243Sobrien	    redo++;
107959243Sobrien	    break;
108059243Sobrien
108159243Sobrien	case F_DELPREV:
108259243Sobrien	    if (patlen > 1)
108359243Sobrien		done++;
108459243Sobrien	    else
108559243Sobrien		SoundBeep();
108659243Sobrien	    break;
108759243Sobrien
108859243Sobrien	default:
108959243Sobrien	    switch (ch) {
109059243Sobrien	    case 0007:		/* ^G: Abort */
109159243Sobrien		ret = CC_ERROR;
109259243Sobrien		done++;
109359243Sobrien		break;
109459243Sobrien
109559243Sobrien	    case 0027:		/* ^W: Append word */
109659243Sobrien		/* No can do if globbing characters in pattern */
109759243Sobrien		for (cp = &patbuf[1]; ; cp++)
109859243Sobrien		    if (cp >= &patbuf[patlen]) {
109959243Sobrien			Cursor += patlen - 1;
110059243Sobrien			cp = c_next_word(Cursor, LastChar, 1);
110159243Sobrien			while (Cursor < cp && *Cursor != '\n') {
110259243Sobrien			    if (patlen > INBUFSIZE - 3) {
110359243Sobrien				SoundBeep();
110459243Sobrien				break;
110559243Sobrien			    }
110659243Sobrien			    patbuf[patlen++] = *Cursor;
110759243Sobrien			    *LastChar++ = *Cursor++;
110859243Sobrien			}
110959243Sobrien			Cursor = oldCursor;
111059243Sobrien			*LastChar = '\0';
111159243Sobrien			Refresh();
111259243Sobrien			break;
111359243Sobrien		    } else if (isglob(*cp)) {
111459243Sobrien			SoundBeep();
111559243Sobrien			break;
111659243Sobrien		    }
111759243Sobrien		break;
111859243Sobrien
111959243Sobrien	    default:		/* Terminate and execute cmd */
112059243Sobrien		endcmd[0] = ch;
112159243Sobrien		PushMacro(endcmd);
112259243Sobrien		/*FALLTHROUGH*/
112359243Sobrien
112459243Sobrien	    case 0033:		/* ESC: Terminate */
112559243Sobrien		ret = CC_REFRESH;
112659243Sobrien		done++;
112759243Sobrien		break;
112859243Sobrien	    }
112959243Sobrien	    break;
113059243Sobrien	}
113159243Sobrien
113259243Sobrien	while (LastChar > InputBuf && *LastChar != '\n')
113359243Sobrien	    *LastChar-- = '\0';
113459243Sobrien	*LastChar = '\0';
113559243Sobrien
113659243Sobrien	if (!done) {
113759243Sobrien
113859243Sobrien	    /* Can't search if unmatched '[' */
113959243Sobrien	    for (cp = &patbuf[patlen - 1], ch = ']'; cp > patbuf; cp--)
114059243Sobrien		if (*cp == '[' || *cp == ']') {
114159243Sobrien		    ch = *cp;
114259243Sobrien		    break;
114359243Sobrien		}
114459243Sobrien
114559243Sobrien	    if (patlen > 1 && ch != '[') {
114659243Sobrien		if (redo && newdir == dir) {
114759243Sobrien		    if (pchar == '?') {	/* wrap around */
114859243Sobrien			Hist_num = newdir == F_UP_SEARCH_HIST ? 0 : 0x7fffffff;
114959243Sobrien			if (c_get_histline() == CC_ERROR)
115059243Sobrien			    /* Hist_num was fixed by first call */
115159243Sobrien			    (void) c_get_histline();
115259243Sobrien			Cursor = newdir == F_UP_SEARCH_HIST ?
115359243Sobrien			    LastChar : InputBuf;
115459243Sobrien		    } else
115559243Sobrien			Cursor += newdir == F_UP_SEARCH_HIST ? -1 : 1;
115659243Sobrien		}
115759243Sobrien		patbuf[patlen++] = '*';
115859243Sobrien		patbuf[patlen] = '\0';
115959243Sobrien		if (Cursor < InputBuf || Cursor > LastChar ||
116059243Sobrien		    (ret = c_search_line(&patbuf[1], newdir)) == CC_ERROR) {
116159243Sobrien		    LastCmd = (KEYCMD) newdir; /* avoid c_hsetpat */
116259243Sobrien		    ret = newdir == F_UP_SEARCH_HIST ?
116359243Sobrien			e_up_search_hist(0) : e_down_search_hist(0);
116459243Sobrien		    if (ret != CC_ERROR) {
116559243Sobrien			Cursor = newdir == F_UP_SEARCH_HIST ?
116659243Sobrien			    LastChar : InputBuf;
116759243Sobrien			(void) c_search_line(&patbuf[1], newdir);
116859243Sobrien		    }
116959243Sobrien		}
117059243Sobrien		patbuf[--patlen] = '\0';
117159243Sobrien		if (ret == CC_ERROR) {
117259243Sobrien		    SoundBeep();
117359243Sobrien		    if (Hist_num != oldHist_num) {
117459243Sobrien			Hist_num = oldHist_num;
117559243Sobrien			if (c_get_histline() == CC_ERROR)
117659243Sobrien			    return(CC_ERROR);
117759243Sobrien		    }
117859243Sobrien		    Cursor = oldCursor;
117959243Sobrien		    pchar = '?';
118059243Sobrien		} else {
118159243Sobrien		    pchar = ':';
118259243Sobrien		}
118359243Sobrien	    }
118459243Sobrien
118559243Sobrien	    ret = e_inc_search(newdir);
118659243Sobrien
118759243Sobrien	    if (ret == CC_ERROR && pchar == '?' && oldpchar == ':') {
118859243Sobrien		/* break abort of failed search at last non-failed */
118959243Sobrien		ret = CC_NORM;
119059243Sobrien	    }
119159243Sobrien
119259243Sobrien	}
119359243Sobrien
119459243Sobrien	if (ret == CC_NORM || (ret == CC_ERROR && oldpatlen == 0)) {
119559243Sobrien	    /* restore on normal return or error exit */
119659243Sobrien	    pchar = oldpchar;
119759243Sobrien	    patlen = oldpatlen;
119859243Sobrien	    if (Hist_num != oldHist_num) {
119959243Sobrien		Hist_num = oldHist_num;
120059243Sobrien		if (c_get_histline() == CC_ERROR)
120159243Sobrien		    return(CC_ERROR);
120259243Sobrien	    }
120359243Sobrien	    Cursor = oldCursor;
120459243Sobrien	    if (ret == CC_ERROR)
120559243Sobrien		Refresh();
120659243Sobrien	}
120759243Sobrien	if (done || ret != CC_NORM)
120859243Sobrien	    return(ret);
120959243Sobrien
121059243Sobrien    }
121159243Sobrien
121259243Sobrien}
121359243Sobrien
121459243Sobrienstatic CCRETVAL
121559243Sobrienv_search(dir)
121659243Sobrien    int dir;
121759243Sobrien{
121859243Sobrien    Char ch;
121959243Sobrien    Char tmpbuf[INBUFSIZE];
122059243Sobrien    Char oldbuf[INBUFSIZE];
122159243Sobrien    Char *oldlc, *oldc;
122259243Sobrien    int tmplen;
122359243Sobrien
122459243Sobrien    copyn(oldbuf, InputBuf, INBUFSIZE);
122559243Sobrien    oldlc = LastChar;
122659243Sobrien    oldc = Cursor;
122759243Sobrien    tmplen = 0;
122859243Sobrien    tmpbuf[tmplen++] = '*';
122959243Sobrien
123059243Sobrien    InputBuf[0] = '\0';
123159243Sobrien    LastChar = InputBuf;
123259243Sobrien    Cursor = InputBuf;
123359243Sobrien    searchdir = dir;
123459243Sobrien
123559243Sobrien    c_insert(2);	/* prompt + '\n' */
123659243Sobrien    *Cursor++ = '\n';
123759243Sobrien    *Cursor++ = dir == F_UP_SEARCH_HIST ? '?' : '/';
123859243Sobrien    Refresh();
123959243Sobrien    for (ch = 0;ch == 0;) {
124059243Sobrien	if (GetNextChar(&ch) != 1)
124159243Sobrien	    return(e_send_eof(0));
124259243Sobrien	switch (ASC(ch)) {
124359243Sobrien	case 0010:	/* Delete and backspace */
124459243Sobrien	case 0177:
124559243Sobrien	    if (tmplen > 1) {
124659243Sobrien		*Cursor-- = '\0';
124759243Sobrien		LastChar = Cursor;
124859243Sobrien		tmpbuf[tmplen--] = '\0';
124959243Sobrien	    }
125059243Sobrien	    else {
125159243Sobrien		copyn(InputBuf, oldbuf, INBUFSIZE);
125259243Sobrien		LastChar = oldlc;
125359243Sobrien		Cursor = oldc;
125459243Sobrien		return(CC_REFRESH);
125559243Sobrien	    }
125659243Sobrien	    Refresh();
125759243Sobrien	    ch = 0;
125859243Sobrien	    break;
125959243Sobrien
126059243Sobrien	case 0033:	/* ESC */
126159243Sobrien#ifndef _OSD_POSIX
126259243Sobrien	case '\r':	/* Newline */
126359243Sobrien	case '\n':
126459243Sobrien#else
126559243Sobrien	case '\012':    /* Newline */
126659243Sobrien	case '\015':    /* Return */
126759243Sobrien#endif
126859243Sobrien	    break;
126959243Sobrien
127059243Sobrien	default:
127159243Sobrien	    if (tmplen >= INBUFSIZE)
127259243Sobrien		SoundBeep();
127359243Sobrien	    else {
127459243Sobrien		tmpbuf[tmplen++] = ch;
127559243Sobrien		*Cursor++ = ch;
127659243Sobrien		LastChar = Cursor;
127759243Sobrien	    }
127859243Sobrien	    Refresh();
127959243Sobrien	    ch = 0;
128059243Sobrien	    break;
128159243Sobrien	}
128259243Sobrien    }
128359243Sobrien
128459243Sobrien    if (tmplen == 1) {
128559243Sobrien	/*
128659243Sobrien	 * Use the old pattern, but wild-card it.
128759243Sobrien	 */
128859243Sobrien	if (patlen == 0) {
128959243Sobrien	    InputBuf[0] = '\0';
129059243Sobrien	    LastChar = InputBuf;
129159243Sobrien	    Cursor = InputBuf;
129259243Sobrien	    Refresh();
129359243Sobrien	    return(CC_ERROR);
129459243Sobrien	}
129559243Sobrien	if (patbuf[0] != '*') {
129659243Sobrien	    (void) Strcpy(tmpbuf, patbuf);
129759243Sobrien	    patbuf[0] = '*';
129859243Sobrien	    (void) Strcpy(&patbuf[1], tmpbuf);
129959243Sobrien	    patlen++;
130059243Sobrien	    patbuf[patlen++] = '*';
130159243Sobrien	    patbuf[patlen] = '\0';
130259243Sobrien	}
130359243Sobrien    }
130459243Sobrien    else {
130559243Sobrien	tmpbuf[tmplen++] = '*';
130659243Sobrien	tmpbuf[tmplen] = '\0';
130759243Sobrien	(void) Strcpy(patbuf, tmpbuf);
130859243Sobrien	patlen = tmplen;
130959243Sobrien    }
131059243Sobrien    LastCmd = (KEYCMD) dir; /* avoid c_hsetpat */
131159243Sobrien    Cursor = LastChar = InputBuf;
131259243Sobrien    if ((dir == F_UP_SEARCH_HIST ? e_up_search_hist(0) :
131359243Sobrien				   e_down_search_hist(0)) == CC_ERROR) {
131459243Sobrien	Refresh();
131559243Sobrien	return(CC_ERROR);
131659243Sobrien    }
131759243Sobrien    else {
131859243Sobrien	if (ch == 0033) {
131959243Sobrien	    Refresh();
132059243Sobrien	    *LastChar++ = '\n';
132159243Sobrien	    *LastChar = '\0';
132259243Sobrien	    PastBottom();
132359243Sobrien	    return(CC_NEWLINE);
132459243Sobrien	}
132559243Sobrien	else
132659243Sobrien	    return(CC_REFRESH);
132759243Sobrien    }
132859243Sobrien}
132959243Sobrien
133059243Sobrien/*
133159243Sobrien * semi-PUBLIC routines.  Any routine that is of type CCRETVAL is an
133259243Sobrien * entry point, called from the CcKeyMap indirected into the
133359243Sobrien * CcFuncTbl array.
133459243Sobrien */
133559243Sobrien
133659243Sobrien/*ARGSUSED*/
133759243SobrienCCRETVAL
133859243Sobrienv_cmd_mode(c)
133959243Sobrien    int c;
134059243Sobrien{
134159243Sobrien    USE(c);
134259243Sobrien    InsertPos = 0;
134359243Sobrien    ActionFlag = TCSHOP_NOP;	/* [Esc] cancels pending action */
134459243Sobrien    ActionPos = 0;
134559243Sobrien    DoingArg = 0;
134659243Sobrien    if (UndoPtr > Cursor)
134759243Sobrien	UndoSize = (int)(UndoPtr - Cursor);
134859243Sobrien    else
134959243Sobrien	UndoSize = (int)(Cursor - UndoPtr);
135059243Sobrien
135159243Sobrien    inputmode = MODE_INSERT;
135259243Sobrien    c_alternativ_key_map(1);
135359243Sobrien#ifdef notdef
135459243Sobrien    /*
135559243Sobrien     * We don't want to move the cursor, because all the editing
135659243Sobrien     * commands don't include the character under the cursor.
135759243Sobrien     */
135859243Sobrien    if (Cursor > InputBuf)
135959243Sobrien	Cursor--;
136059243Sobrien#endif
136159243Sobrien    RefCursor();
136259243Sobrien    return(CC_NORM);
136359243Sobrien}
136459243Sobrien
136559243Sobrien/*ARGSUSED*/
136659243SobrienCCRETVAL
136759243Sobriene_unassigned(c)
136859243Sobrien    int c;
136959243Sobrien{				/* bound to keys that arn't really assigned */
137059243Sobrien    USE(c);
137159243Sobrien    SoundBeep();
137259243Sobrien    flush();
137359243Sobrien    return(CC_NORM);
137459243Sobrien}
137559243Sobrien
137659243SobrienCCRETVAL
137759243Sobriene_insert(c)
137859243Sobrien    register int c;
137959243Sobrien{
138059243Sobrien    register int i;
138159243Sobrien#if defined(DSPMBYTE)
138259243Sobrien    CCRETVAL ret;
138359243Sobrien    static Char savec;
138459243Sobrien    static int exterr = 0;
138559243Sobrien#endif
138659243Sobrien#ifndef SHORT_STRINGS
138759243Sobrien    c &= ASCII;			/* no meta chars ever */
138859243Sobrien#endif
138959243Sobrien#if defined(DSPMBYTE)
139059243Sobrien    ret = (CCRETVAL) CC_NORM;
139159243Sobrien#endif
139259243Sobrien
139359243Sobrien    if (!c)
139459243Sobrien	return(CC_ERROR);	/* no NULs in the input ever!! */
139559243Sobrien
139659243Sobrien    if (LastChar + Argument >= InputLim)
139759243Sobrien	return(CC_ERROR);	/* end of buffer space */
139859243Sobrien
139959243Sobrien    if (Argument == 1) {  	/* How was this optimized ???? */
140059243Sobrien
140159243Sobrien#if defined(DSPMBYTE)
140259243Sobrien	if(_enable_mbdisp && extins && exterr && Ismbyte2(c)) {
140359243Sobrien	    extins = 0;
140459243Sobrien	    exterr = 0;
140559243Sobrien	    return(CC_ERROR);
140659243Sobrien	}
140759243Sobrien#endif
140859243Sobrien	if (inputmode != MODE_INSERT) {
140959243Sobrien	    UndoBuf[UndoSize++] = *Cursor;
141059243Sobrien	    UndoBuf[UndoSize] = '\0';
141159243Sobrien	    c_delafter(1);   /* Do NOT use the saving ONE */
141259243Sobrien    	}
141359243Sobrien
141459243Sobrien        c_insert(1);
141559243Sobrien
141659243Sobrien#if defined(DSPMBYTE)
141759243Sobrien	/* 1st. byte is store to special buffer, and replace space */
141859243Sobrien	if(_enable_mbdisp && extins == 0 && Ismbyte1(c)) {
141959243Sobrien	    extins++;
142059243Sobrien	    savec = (Char) c;
142159243Sobrien	    *Cursor++ = (Char) ' ';
142259243Sobrien	}
142359243Sobrien	else if (_enable_mbdisp && extins && Ismbyte2(c)) {
142459243Sobrien	    *(Cursor-1) = savec;
142559243Sobrien	    *Cursor++ = (Char) c;
142659243Sobrien	    extins = 0;
142759243Sobrien	    e_redisp(1);
142859243Sobrien	    Refresh();
142959243Sobrien	    ret = CC_REFRESH;
143059243Sobrien	}
143159243Sobrien	else
143259243Sobrien	    *Cursor++ = (Char) c;
143359243Sobrien	DoingArg = 0;		/* just in case */
143459243Sobrien	if (ret != CC_REFRESH)
143559243Sobrien	    RefPlusOne();	/* fast refresh for one char. */
143659243Sobrien#else
143759243Sobrien	*Cursor++ = (Char) c;
143859243Sobrien	DoingArg = 0;		/* just in case */
143959243Sobrien	RefPlusOne();		/* fast refresh for one char. */
144059243Sobrien#endif
144159243Sobrien    }
144259243Sobrien    else {
144359243Sobrien#if defined(DSPMBYTE)
144459243Sobrien	/* Cannot use ESC-(number) for multi-byte */
144559243Sobrien	if (_enable_mbdisp && extins == 0 && Ismbyte1(c)) {
144659243Sobrien	    extins++;
144759243Sobrien	    exterr++;
144859243Sobrien	    return(CC_ERROR);
144959243Sobrien	}
145059243Sobrien	else if (_enable_mbdisp && extins && exterr && Ismbyte2(c))
145159243Sobrien	{
145259243Sobrien	    extins = 0;
145359243Sobrien	    exterr = 0;
145459243Sobrien	    return(CC_ERROR);
145559243Sobrien	}
145659243Sobrien#endif
145759243Sobrien	if (inputmode != MODE_INSERT) {
145859243Sobrien
145959243Sobrien	    for(i=0;i<Argument;i++)
146059243Sobrien		UndoBuf[UndoSize++] = *(Cursor+i);
146159243Sobrien
146259243Sobrien	    UndoBuf[UndoSize] = '\0';
146359243Sobrien	    c_delafter(Argument);   /* Do NOT use the saving ONE */
146459243Sobrien    	}
146559243Sobrien
146659243Sobrien        c_insert(Argument);
146759243Sobrien
146859243Sobrien	while (Argument--)
146959243Sobrien	    *Cursor++ = (Char) c;
147059243Sobrien	Refresh();
147159243Sobrien    }
147259243Sobrien
147359243Sobrien    if (inputmode == MODE_REPLACE_1)
147459243Sobrien	(void) v_cmd_mode(0);
147559243Sobrien
147659243Sobrien#if defined(DSPMBYTE)
147759243Sobrien    return(ret);
147859243Sobrien#else
147959243Sobrien    return(CC_NORM);
148059243Sobrien#endif
148159243Sobrien}
148259243Sobrien
148359243Sobrienint
148459243SobrienInsertStr(s)			/* insert ASCIZ s at cursor (for complete) */
148559243Sobrien    Char   *s;
148659243Sobrien{
148759243Sobrien    register int len;
148859243Sobrien
148959243Sobrien    if ((len = (int) Strlen(s)) <= 0)
149059243Sobrien	return -1;
149159243Sobrien    if (LastChar + len >= InputLim)
149259243Sobrien	return -1;		/* end of buffer space */
149359243Sobrien
149459243Sobrien    c_insert(len);
149559243Sobrien    while (len--)
149659243Sobrien	*Cursor++ = *s++;
149759243Sobrien    return 0;
149859243Sobrien}
149959243Sobrien
150059243Sobrienvoid
150159243SobrienDeleteBack(n)			/* delete the n characters before . */
150259243Sobrien    int     n;
150359243Sobrien{
150459243Sobrien    if (n <= 0)
150559243Sobrien	return;
150659243Sobrien    if (Cursor >= &InputBuf[n]) {
150759243Sobrien	c_delbefore(n);		/* delete before dot */
150859243Sobrien	if (n > Cursor - InputBuf)
150959243Sobrien	    Cursor = InputBuf;	/* bounds check */
151059243Sobrien	else
151159243Sobrien	    Cursor -= n;
151259243Sobrien#if defined(DSPMBYTE)
151359243Sobrien	if(_enable_mbdisp && extdel && Cursor > InputBuf) {
151459243Sobrien	    Cursor--;
151559243Sobrien	    e_redisp(1);
151659243Sobrien	}
151759243Sobrien#endif
151859243Sobrien    }
151959243Sobrien}
152059243Sobrien
152159243SobrienCCRETVAL
152259243Sobriene_digit(c)			/* gray magic here */
152359243Sobrien    register int c;
152459243Sobrien{
152559243Sobrien    if (!Isdigit(c))
152659243Sobrien	return(CC_ERROR);	/* no NULs in the input ever!! */
152759243Sobrien
152859243Sobrien    if (DoingArg) {		/* if doing an arg, add this in... */
152959243Sobrien	if (LastCmd == F_ARGFOUR)	/* if last command was ^U */
153059243Sobrien	    Argument = c - '0';
153159243Sobrien	else {
153259243Sobrien	    if (Argument > 1000000)
153359243Sobrien		return CC_ERROR;
153459243Sobrien	    Argument = (Argument * 10) + (c - '0');
153559243Sobrien	}
153659243Sobrien	return(CC_ARGHACK);
153759243Sobrien    }
153859243Sobrien    else {
153959243Sobrien	if (LastChar + 1 >= InputLim)
154059243Sobrien	    return CC_ERROR;	/* end of buffer space */
154159243Sobrien
154259243Sobrien	if (inputmode != MODE_INSERT) {
154359243Sobrien	    UndoBuf[UndoSize++] = *Cursor;
154459243Sobrien	    UndoBuf[UndoSize] = '\0';
154559243Sobrien	    c_delafter(1);   /* Do NOT use the saving ONE */
154659243Sobrien    	}
154759243Sobrien	c_insert(1);
154859243Sobrien	*Cursor++ = (Char) c;
154959243Sobrien	DoingArg = 0;		/* just in case */
155059243Sobrien	RefPlusOne();		/* fast refresh for one char. */
155159243Sobrien    }
155259243Sobrien    return(CC_NORM);
155359243Sobrien}
155459243Sobrien
155559243SobrienCCRETVAL
155659243Sobriene_argdigit(c)			/* for ESC-n */
155759243Sobrien    register int c;
155859243Sobrien{
155959243Sobrien    c &= ASCII;
156059243Sobrien
156159243Sobrien    if (!Isdigit(c))
156259243Sobrien	return(CC_ERROR);	/* no NULs in the input ever!! */
156359243Sobrien
156459243Sobrien    if (DoingArg) {		/* if doing an arg, add this in... */
156559243Sobrien	if (Argument > 1000000)
156659243Sobrien	    return CC_ERROR;
156759243Sobrien	Argument = (Argument * 10) + (c - '0');
156859243Sobrien    }
156959243Sobrien    else {			/* else starting an argument */
157059243Sobrien	Argument = c - '0';
157159243Sobrien	DoingArg = 1;
157259243Sobrien    }
157359243Sobrien    return(CC_ARGHACK);
157459243Sobrien}
157559243Sobrien
157659243SobrienCCRETVAL
157759243Sobrienv_zero(c)			/* command mode 0 for vi */
157859243Sobrien    register int c;
157959243Sobrien{
158059243Sobrien    if (DoingArg) {		/* if doing an arg, add this in... */
158159243Sobrien	if (Argument > 1000000)
158259243Sobrien	    return CC_ERROR;
158359243Sobrien	Argument = (Argument * 10) + (c - '0');
158459243Sobrien	return(CC_ARGHACK);
158559243Sobrien    }
158659243Sobrien    else {			/* else starting an argument */
158759243Sobrien	Cursor = InputBuf;
158859243Sobrien	if (ActionFlag & TCSHOP_DELETE) {
158959243Sobrien	   c_delfini();
159059243Sobrien	   return(CC_REFRESH);
159159243Sobrien        }
159259243Sobrien	RefCursor();		/* move the cursor */
159359243Sobrien	return(CC_NORM);
159459243Sobrien    }
159559243Sobrien}
159659243Sobrien
159759243Sobrien/*ARGSUSED*/
159859243SobrienCCRETVAL
159959243Sobriene_newline(c)
160059243Sobrien    int c;
160159243Sobrien{				/* always ignore argument */
160259243Sobrien    USE(c);
160359243Sobrien  /*  PastBottom();  NOW done in ed.inputl.c */
160459243Sobrien    *LastChar++ = '\n';		/* for the benefit of CSH */
160559243Sobrien    *LastChar = '\0';		/* just in case */
160659243Sobrien    if (VImode)
160759243Sobrien	InsertPos = InputBuf;	/* Reset editing position */
160859243Sobrien    return(CC_NEWLINE);
160959243Sobrien}
161059243Sobrien
161159243Sobrien/*ARGSUSED*/
161259243SobrienCCRETVAL
161359243Sobriene_send_eof(c)
161459243Sobrien    int c;
161559243Sobrien{				/* for when ^D is ONLY send-eof */
161659243Sobrien    USE(c);
161759243Sobrien    PastBottom();
161859243Sobrien    *LastChar = '\0';		/* just in case */
161959243Sobrien    return(CC_EOF);
162059243Sobrien}
162159243Sobrien
162259243Sobrien/*ARGSUSED*/
162359243SobrienCCRETVAL
162459243Sobriene_complete(c)
162559243Sobrien    int c;
162659243Sobrien{
162759243Sobrien    USE(c);
162859243Sobrien    *LastChar = '\0';		/* just in case */
162959243Sobrien    return(CC_COMPLETE);
163059243Sobrien}
163159243Sobrien
163259243Sobrien/*ARGSUSED*/
163359243SobrienCCRETVAL
163459243Sobriene_complete_back(c)
163559243Sobrien    int c;
163659243Sobrien{
163759243Sobrien    USE(c);
163859243Sobrien    *LastChar = '\0';		/* just in case */
163959243Sobrien    return(CC_COMPLETE_BACK);
164059243Sobrien}
164159243Sobrien
164259243Sobrien/*ARGSUSED*/
164359243SobrienCCRETVAL
164459243Sobriene_complete_fwd(c)
164559243Sobrien    int c;
164659243Sobrien{
164759243Sobrien    USE(c);
164859243Sobrien    *LastChar = '\0';		/* just in case */
164959243Sobrien    return(CC_COMPLETE_FWD);
165059243Sobrien}
165159243Sobrien
165259243Sobrien/*ARGSUSED*/
165359243SobrienCCRETVAL
165459243Sobriene_complete_all(c)
165559243Sobrien    int c;
165659243Sobrien{
165759243Sobrien    USE(c);
165859243Sobrien    *LastChar = '\0';		/* just in case */
165959243Sobrien    return(CC_COMPLETE_ALL);
166059243Sobrien}
166159243Sobrien
166259243Sobrien/*ARGSUSED*/
166359243SobrienCCRETVAL
166459243Sobrienv_cm_complete(c)
166559243Sobrien    int c;
166659243Sobrien{
166759243Sobrien    USE(c);
166859243Sobrien    if (Cursor < LastChar)
166959243Sobrien	Cursor++;
167059243Sobrien    *LastChar = '\0';		/* just in case */
167159243Sobrien    return(CC_COMPLETE);
167259243Sobrien}
167359243Sobrien
167459243Sobrien/*ARGSUSED*/
167559243SobrienCCRETVAL
167659243Sobriene_toggle_hist(c)
167759243Sobrien    int c;
167859243Sobrien{
167959243Sobrien    struct Hist *hp;
168059243Sobrien    int     h;
168159243Sobrien
168259243Sobrien    USE(c);
168359243Sobrien    *LastChar = '\0';		/* just in case */
168459243Sobrien
168559243Sobrien    if (Hist_num <= 0) {
168659243Sobrien	return CC_ERROR;
168759243Sobrien    }
168859243Sobrien
168959243Sobrien    hp = Histlist.Hnext;
169059243Sobrien    if (hp == NULL) {	/* this is only if no history */
169159243Sobrien	return(CC_ERROR);
169259243Sobrien    }
169359243Sobrien
169459243Sobrien    for (h = 1; h < Hist_num; h++)
169559243Sobrien	hp = hp->Hnext;
169659243Sobrien
169759243Sobrien    if (!CurrentHistLit) {
169859243Sobrien	if (hp->histline) {
169959243Sobrien	    copyn(InputBuf, hp->histline, INBUFSIZE);
170059243Sobrien	    CurrentHistLit = 1;
170159243Sobrien	}
170259243Sobrien	else {
170359243Sobrien	    return CC_ERROR;
170459243Sobrien	}
170559243Sobrien    }
170659243Sobrien    else {
170759243Sobrien	(void) sprlex(InputBuf, sizeof(InputBuf), &hp->Hlex);
170859243Sobrien	CurrentHistLit = 0;
170959243Sobrien    }
171059243Sobrien
171159243Sobrien    LastChar = InputBuf + Strlen(InputBuf);
171259243Sobrien    if (LastChar > InputBuf) {
171359243Sobrien	if (LastChar[-1] == '\n')
171459243Sobrien	    LastChar--;
171559243Sobrien	if (LastChar[-1] == ' ')
171659243Sobrien	    LastChar--;
171759243Sobrien	if (LastChar < InputBuf)
171859243Sobrien	    LastChar = InputBuf;
171959243Sobrien    }
172059243Sobrien
172159243Sobrien#ifdef KSHVI
172259243Sobrien    if (VImode)
172359243Sobrien	Cursor = InputBuf;
172459243Sobrien    else
172559243Sobrien#endif /* KSHVI */
172659243Sobrien	Cursor = LastChar;
172759243Sobrien
172859243Sobrien    return(CC_REFRESH);
172959243Sobrien}
173059243Sobrien
173159243Sobrien/*ARGSUSED*/
173259243SobrienCCRETVAL
173359243Sobriene_up_hist(c)
173459243Sobrien    int c;
173559243Sobrien{
173659243Sobrien    Char    beep = 0;
173759243Sobrien
173859243Sobrien    USE(c);
173959243Sobrien    UndoAction = TCSHOP_NOP;
174059243Sobrien    *LastChar = '\0';		/* just in case */
174159243Sobrien
174259243Sobrien    if (Hist_num == 0) {	/* save the current buffer away */
174359243Sobrien	copyn(HistBuf, InputBuf, INBUFSIZE);
174459243Sobrien	LastHist = HistBuf + (LastChar - InputBuf);
174559243Sobrien    }
174659243Sobrien
174759243Sobrien    Hist_num += Argument;
174859243Sobrien
174959243Sobrien    if (c_get_histline() == CC_ERROR) {
175059243Sobrien	beep = 1;
175159243Sobrien	(void) c_get_histline(); /* Hist_num was fixed by first call */
175259243Sobrien    }
175359243Sobrien
175459243Sobrien    Refresh();
175559243Sobrien    if (beep)
175659243Sobrien	return(CC_ERROR);
175759243Sobrien    else
175859243Sobrien	return(CC_NORM);	/* was CC_UP_HIST */
175959243Sobrien}
176059243Sobrien
176159243Sobrien/*ARGSUSED*/
176259243SobrienCCRETVAL
176359243Sobriene_down_hist(c)
176459243Sobrien    int c;
176559243Sobrien{
176659243Sobrien    USE(c);
176759243Sobrien    UndoAction = TCSHOP_NOP;
176859243Sobrien    *LastChar = '\0';		/* just in case */
176959243Sobrien
177059243Sobrien    Hist_num -= Argument;
177159243Sobrien
177259243Sobrien    if (Hist_num < 0) {
177359243Sobrien	Hist_num = 0;
177459243Sobrien	return(CC_ERROR);	/* make it beep */
177559243Sobrien    }
177659243Sobrien
177759243Sobrien    return(c_get_histline());
177859243Sobrien}
177959243Sobrien
178059243Sobrien
178159243Sobrien
178259243Sobrien/*
178359243Sobrien * c_hmatch() return True if the pattern matches the prefix
178459243Sobrien */
178559243Sobrienstatic int
178659243Sobrienc_hmatch(str)
178759243SobrienChar *str;
178859243Sobrien{
178959243Sobrien    if (Strncmp(patbuf, str, (size_t) patlen) == 0)
179059243Sobrien	return 1;
179159243Sobrien    return Gmatch(str, patbuf);
179259243Sobrien}
179359243Sobrien
179459243Sobrien/*
179559243Sobrien * c_hsetpat(): Set the history seatch pattern
179659243Sobrien */
179759243Sobrienstatic void
179859243Sobrienc_hsetpat()
179959243Sobrien{
180059243Sobrien    if (LastCmd != F_UP_SEARCH_HIST && LastCmd != F_DOWN_SEARCH_HIST) {
180159243Sobrien	patlen = (int) (Cursor - InputBuf);
180259243Sobrien	if (patlen >= INBUFSIZE) patlen = INBUFSIZE -1;
180359243Sobrien	if (patlen >= 0)  {
180459243Sobrien	    (void) Strncpy(patbuf, InputBuf, (size_t) patlen);
180559243Sobrien	    patbuf[patlen] = '\0';
180659243Sobrien	}
180759243Sobrien	else
180859243Sobrien	    patlen = (int) Strlen(patbuf);
180959243Sobrien    }
181059243Sobrien#ifdef SDEBUG
181159243Sobrien    xprintf("\nHist_num = %d\n", Hist_num);
181259243Sobrien    xprintf("patlen = %d\n", patlen);
181359243Sobrien    xprintf("patbuf = \"%S\"\n", patbuf);
181459243Sobrien    xprintf("Cursor %d LastChar %d\n", Cursor - InputBuf, LastChar - InputBuf);
181559243Sobrien#endif
181659243Sobrien}
181759243Sobrien
181859243Sobrien/*ARGSUSED*/
181959243SobrienCCRETVAL
182059243Sobriene_up_search_hist(c)
182159243Sobrien    int c;
182259243Sobrien{
182359243Sobrien    struct Hist *hp;
182459243Sobrien    int h;
182559243Sobrien    bool    found = 0;
182659243Sobrien
182759243Sobrien    USE(c);
182859243Sobrien    ActionFlag = TCSHOP_NOP;
182959243Sobrien    UndoAction = TCSHOP_NOP;
183059243Sobrien    *LastChar = '\0';		/* just in case */
183159243Sobrien    if (Hist_num < 0) {
183259243Sobrien#ifdef DEBUG_EDIT
183359243Sobrien	xprintf("%s: e_up_search_hist(): Hist_num < 0; resetting.\n", progname);
183459243Sobrien#endif
183559243Sobrien	Hist_num = 0;
183659243Sobrien	return(CC_ERROR);
183759243Sobrien    }
183859243Sobrien
183959243Sobrien    if (Hist_num == 0)
184059243Sobrien    {
184159243Sobrien	copyn(HistBuf, InputBuf, INBUFSIZE);
184259243Sobrien	LastHist = HistBuf + (LastChar - InputBuf);
184359243Sobrien    }
184459243Sobrien
184559243Sobrien
184659243Sobrien    hp = Histlist.Hnext;
184759243Sobrien    if (hp == NULL)
184859243Sobrien	return(CC_ERROR);
184959243Sobrien
185059243Sobrien    c_hsetpat();		/* Set search pattern !! */
185159243Sobrien
185259243Sobrien    for (h = 1; h <= Hist_num; h++)
185359243Sobrien	hp = hp->Hnext;
185459243Sobrien
185559243Sobrien    while (hp != NULL) {
185659243Sobrien	Char sbuf[INBUFSIZE], *hl;
185759243Sobrien	if (hp->histline == NULL) {
185859243Sobrien	    hp->histline = Strsave(sprlex(sbuf, sizeof(sbuf), &hp->Hlex));
185959243Sobrien	}
186059243Sobrien	hl = HistLit ? hp->histline : sprlex(sbuf, sizeof(sbuf), &hp->Hlex);
186159243Sobrien#ifdef SDEBUG
186259243Sobrien	xprintf("Comparing with \"%S\"\n", hl);
186359243Sobrien#endif
186459243Sobrien	if ((Strncmp(hl, InputBuf, (size_t) (LastChar - InputBuf)) ||
186559243Sobrien	     hl[LastChar-InputBuf]) && c_hmatch(hl)) {
186659243Sobrien	    found++;
186759243Sobrien	    break;
186859243Sobrien	}
186959243Sobrien	h++;
187059243Sobrien	hp = hp->Hnext;
187159243Sobrien    }
187259243Sobrien
187359243Sobrien    if (!found) {
187459243Sobrien#ifdef SDEBUG
187559243Sobrien	xprintf("not found\n");
187659243Sobrien#endif
187759243Sobrien	return(CC_ERROR);
187859243Sobrien    }
187959243Sobrien
188059243Sobrien    Hist_num = h;
188159243Sobrien
188259243Sobrien    return(c_get_histline());
188359243Sobrien}
188459243Sobrien
188559243Sobrien/*ARGSUSED*/
188659243SobrienCCRETVAL
188759243Sobriene_down_search_hist(c)
188859243Sobrien    int c;
188959243Sobrien{
189059243Sobrien    struct Hist *hp;
189159243Sobrien    int h;
189259243Sobrien    bool    found = 0;
189359243Sobrien
189459243Sobrien    USE(c);
189559243Sobrien    ActionFlag = TCSHOP_NOP;
189659243Sobrien    UndoAction = TCSHOP_NOP;
189759243Sobrien    *LastChar = '\0';		/* just in case */
189859243Sobrien
189959243Sobrien    if (Hist_num == 0)
190059243Sobrien	return(CC_ERROR);
190159243Sobrien
190259243Sobrien    hp = Histlist.Hnext;
190359243Sobrien    if (hp == 0)
190459243Sobrien	return(CC_ERROR);
190559243Sobrien
190659243Sobrien    c_hsetpat();		/* Set search pattern !! */
190759243Sobrien
190859243Sobrien    for (h = 1; h < Hist_num && hp; h++) {
190959243Sobrien	Char sbuf[INBUFSIZE], *hl;
191059243Sobrien	if (hp->histline == NULL) {
191159243Sobrien	    hp->histline = Strsave(sprlex(sbuf, sizeof(sbuf), &hp->Hlex));
191259243Sobrien	}
191359243Sobrien	hl = HistLit ? hp->histline : sprlex(sbuf, sizeof(sbuf), &hp->Hlex);
191459243Sobrien#ifdef SDEBUG
191559243Sobrien	xprintf("Comparing with \"%S\"\n", hl);
191659243Sobrien#endif
191759243Sobrien	if ((Strncmp(hl, InputBuf, (size_t) (LastChar - InputBuf)) ||
191859243Sobrien	     hl[LastChar-InputBuf]) && c_hmatch(hl))
191959243Sobrien	    found = h;
192059243Sobrien	hp = hp->Hnext;
192159243Sobrien    }
192259243Sobrien
192359243Sobrien    if (!found) {		/* is it the current history number? */
192459243Sobrien	if (!c_hmatch(HistBuf)) {
192559243Sobrien#ifdef SDEBUG
192659243Sobrien	    xprintf("not found\n");
192759243Sobrien#endif
192859243Sobrien	    return(CC_ERROR);
192959243Sobrien	}
193059243Sobrien    }
193159243Sobrien
193259243Sobrien    Hist_num = found;
193359243Sobrien
193459243Sobrien    return(c_get_histline());
193559243Sobrien}
193659243Sobrien
193759243Sobrien/*ARGSUSED*/
193859243SobrienCCRETVAL
193959243Sobriene_helpme(c)
194059243Sobrien    int c;
194159243Sobrien{
194259243Sobrien    USE(c);
194359243Sobrien    PastBottom();
194459243Sobrien    *LastChar = '\0';		/* just in case */
194559243Sobrien    return(CC_HELPME);
194659243Sobrien}
194759243Sobrien
194859243Sobrien/*ARGSUSED*/
194959243SobrienCCRETVAL
195059243Sobriene_correct(c)
195159243Sobrien    int c;
195259243Sobrien{
195359243Sobrien    USE(c);
195459243Sobrien    *LastChar = '\0';		/* just in case */
195559243Sobrien    return(CC_CORRECT);
195659243Sobrien}
195759243Sobrien
195859243Sobrien/*ARGSUSED*/
195959243SobrienCCRETVAL
196059243Sobriene_correctl(c)
196159243Sobrien    int c;
196259243Sobrien{
196359243Sobrien    USE(c);
196459243Sobrien    *LastChar = '\0';		/* just in case */
196559243Sobrien    return(CC_CORRECT_L);
196659243Sobrien}
196759243Sobrien
196859243Sobrien/*ARGSUSED*/
196959243SobrienCCRETVAL
197059243Sobriene_run_fg_editor(c)
197159243Sobrien    int c;
197259243Sobrien{
197359243Sobrien    register struct process *pp;
197459243Sobrien    extern bool tellwhat;
197559243Sobrien
197659243Sobrien    USE(c);
197759243Sobrien    if ((pp = find_stop_ed()) != NULL) {
197859243Sobrien	/* save our editor state so we can restore it */
197959243Sobrien	tellwhat = 1;
198059243Sobrien	copyn(WhichBuf, InputBuf, INBUFSIZE);
198159243Sobrien	LastWhich = WhichBuf + (LastChar - InputBuf);
198259243Sobrien	CursWhich = WhichBuf + (Cursor - InputBuf);
198359243Sobrien	HistWhich = Hist_num;
198459243Sobrien	Hist_num = 0;		/* for the history commands */
198559243Sobrien
198659243Sobrien	/* put the tty in a sane mode */
198759243Sobrien	PastBottom();
198859243Sobrien	(void) Cookedmode();	/* make sure the tty is set up correctly */
198959243Sobrien
199059243Sobrien	/* do it! */
199159243Sobrien	fg_proc_entry(pp);
199259243Sobrien
199359243Sobrien	(void) Rawmode();	/* go on */
199459243Sobrien	Refresh();
199559243Sobrien	tellwhat = 0;
199659243Sobrien    }
199759243Sobrien    return(CC_NORM);
199859243Sobrien}
199959243Sobrien
200059243Sobrien/*ARGSUSED*/
200159243SobrienCCRETVAL
200259243Sobriene_list_choices(c)
200359243Sobrien    int c;
200459243Sobrien{
200559243Sobrien    USE(c);
200659243Sobrien    PastBottom();
200759243Sobrien    *LastChar = '\0';		/* just in case */
200859243Sobrien    return(CC_LIST_CHOICES);
200959243Sobrien}
201059243Sobrien
201159243Sobrien/*ARGSUSED*/
201259243SobrienCCRETVAL
201359243Sobriene_list_all(c)
201459243Sobrien    int c;
201559243Sobrien{
201659243Sobrien    USE(c);
201759243Sobrien    PastBottom();
201859243Sobrien    *LastChar = '\0';		/* just in case */
201959243Sobrien    return(CC_LIST_ALL);
202059243Sobrien}
202159243Sobrien
202259243Sobrien/*ARGSUSED*/
202359243SobrienCCRETVAL
202459243Sobriene_list_glob(c)
202559243Sobrien    int c;
202659243Sobrien{
202759243Sobrien    USE(c);
202859243Sobrien    PastBottom();
202959243Sobrien    *LastChar = '\0';		/* just in case */
203059243Sobrien    return(CC_LIST_GLOB);
203159243Sobrien}
203259243Sobrien
203359243Sobrien/*ARGSUSED*/
203459243SobrienCCRETVAL
203559243Sobriene_expand_glob(c)
203659243Sobrien    int c;
203759243Sobrien{
203859243Sobrien    USE(c);
203959243Sobrien    *LastChar = '\0';		/* just in case */
204059243Sobrien    return(CC_EXPAND_GLOB);
204159243Sobrien}
204259243Sobrien
204359243Sobrien/*ARGSUSED*/
204459243SobrienCCRETVAL
204559243Sobriene_normalize_path(c)
204659243Sobrien    int c;
204759243Sobrien{
204859243Sobrien    USE(c);
204959243Sobrien    *LastChar = '\0';		/* just in case */
205059243Sobrien    return(CC_NORMALIZE_PATH);
205159243Sobrien}
205259243Sobrien
205359243Sobrien/*ARGSUSED*/
205459243SobrienCCRETVAL
205559243Sobriene_normalize_command(c)
205659243Sobrien    int c;
205759243Sobrien{
205859243Sobrien    USE(c);
205959243Sobrien    *LastChar = '\0';		/* just in case */
206059243Sobrien    return(CC_NORMALIZE_COMMAND);
206159243Sobrien}
206259243Sobrien
206359243Sobrien/*ARGSUSED*/
206459243SobrienCCRETVAL
206559243Sobriene_expand_vars(c)
206659243Sobrien    int c;
206759243Sobrien{
206859243Sobrien    USE(c);
206959243Sobrien    *LastChar = '\0';		/* just in case */
207059243Sobrien    return(CC_EXPAND_VARS);
207159243Sobrien}
207259243Sobrien
207359243Sobrien/*ARGSUSED*/
207459243SobrienCCRETVAL
207559243Sobriene_which(c)
207659243Sobrien    int c;
207759243Sobrien{				/* do a fast command line which(1) */
207859243Sobrien    USE(c);
207959243Sobrien    PastBottom();
208059243Sobrien    *LastChar = '\0';		/* just in case */
208159243Sobrien    return(CC_WHICH);
208259243Sobrien}
208359243Sobrien
208459243Sobrien/*ARGSUSED*/
208559243SobrienCCRETVAL
208659243Sobriene_last_item(c)
208759243Sobrien    int c;
208859243Sobrien{				/* insert the last element of the prev. cmd */
208959243Sobrien    register Char *cp;
209059243Sobrien    register struct Hist *hp;
209159243Sobrien    register struct wordent *wp, *firstp;
209259243Sobrien    register int i;
209359243Sobrien    Char buf[INBUFSIZE];
209459243Sobrien
209559243Sobrien    USE(c);
209659243Sobrien    if (Argument <= 0)
209759243Sobrien	return(CC_ERROR);
209859243Sobrien
209959243Sobrien    hp = Histlist.Hnext;
210059243Sobrien    if (hp == NULL) {	/* this is only if no history */
210159243Sobrien	return(CC_ERROR);
210259243Sobrien    }
210359243Sobrien
210459243Sobrien    wp = (hp->Hlex).prev;
210559243Sobrien
210659243Sobrien    if (wp->prev == (struct wordent *) NULL)
210759243Sobrien	return(CC_ERROR);	/* an empty history entry */
210859243Sobrien
210959243Sobrien    firstp = (hp->Hlex).next;
211059243Sobrien
211159243Sobrien    /* back up arg words in lex */
211259243Sobrien    for (i = 0; i < Argument && wp != firstp; i++) {
211359243Sobrien	wp = wp->prev;
211459243Sobrien    }
211559243Sobrien
211659243Sobrien    cp = expand_lex(buf, INBUFSIZE, wp->prev, 0, i - 1);
211759243Sobrien    *cp = '\0';
211859243Sobrien    if (InsertStr(buf))
211959243Sobrien	return(CC_ERROR);
212059243Sobrien
212159243Sobrien    return(CC_REFRESH);
212259243Sobrien}
212359243Sobrien
212459243Sobrien/*ARGSUSED*/
212559243SobrienCCRETVAL
212659243Sobriene_dabbrev_expand(c)
212759243Sobrien    int c;
212859243Sobrien{				/* expand to preceding word matching prefix */
212959243Sobrien    register Char *cp, *ncp, *bp;
213059243Sobrien    register struct Hist *hp;
213159243Sobrien    register int arg = 0, len = 0, i; /* len = 0 to shut up gcc -Wall */
213259243Sobrien    register bool found = 0;
213359243Sobrien    Char hbuf[INBUFSIZE];
213459243Sobrien    static int oldevent, hist, word;
213559243Sobrien    static Char *start, *oldcursor;
213659243Sobrien
213759243Sobrien    USE(c);
213859243Sobrien    if (Argument <= 0)
213959243Sobrien	return(CC_ERROR);
214059243Sobrien
214159243Sobrien    cp = c_preword(Cursor, InputBuf, 1);
214259243Sobrien    if (cp == Cursor || Isspace(*cp))
214359243Sobrien	return(CC_ERROR);
214459243Sobrien
214559243Sobrien    hp = Histlist.Hnext;
214659243Sobrien    bp = InputBuf;
214759243Sobrien    if (Argument == 1 && eventno == oldevent && cp == start &&
214859243Sobrien	Cursor == oldcursor && patlen > 0 && Strncmp(patbuf, cp, patlen) == 0){
214959243Sobrien	/* continue previous search - go to last match (hist/word) */
215059243Sobrien	if (hist != 0) {		/* need to move up history */
215159243Sobrien	    for (i = 1; i < hist && hp != NULL; i++)
215259243Sobrien		hp = hp->Hnext;
215359243Sobrien	    if (hp == NULL)	/* "can't happen" */
215459243Sobrien		return(CC_ERROR);
215559243Sobrien	    cp = expand_lex(hbuf, INBUFSIZE, &hp->Hlex, 0, NCARGS);
215659243Sobrien	    *cp = '\0';
215759243Sobrien	    bp = hbuf;
215859243Sobrien	    hp = hp->Hnext;
215959243Sobrien	}
216059243Sobrien	cp = c_preword(cp, bp, word);
216159243Sobrien    } else {			/* starting new search */
216259243Sobrien	oldevent = eventno;
216359243Sobrien	start = cp;
216459243Sobrien	patlen = (int) (Cursor - cp);
216559243Sobrien	(void) Strncpy(patbuf, cp, patlen);
216659243Sobrien	hist = 0;
216759243Sobrien	word = 0;
216859243Sobrien    }
216959243Sobrien
217059243Sobrien    while (!found) {
217159243Sobrien	ncp = c_preword(cp, bp, 1);
217259243Sobrien	if (ncp == cp || Isspace(*ncp)) { /* beginning of line */
217359243Sobrien	    hist++;
217459243Sobrien	    word = 0;
217559243Sobrien	    if (hp == NULL)
217659243Sobrien		return(CC_ERROR);
217759243Sobrien	    cp = expand_lex(hbuf, INBUFSIZE, &hp->Hlex, 0, NCARGS);
217859243Sobrien	    *cp = '\0';
217959243Sobrien	    bp = hbuf;
218059243Sobrien	    hp = hp->Hnext;
218159243Sobrien	    continue;
218259243Sobrien	} else {
218359243Sobrien	    word++;
218459243Sobrien	    len = (int) (c_endword(ncp-1, cp, 1) - ncp + 1);
218559243Sobrien	    cp = ncp;
218659243Sobrien	}
218759243Sobrien	if (len > patlen && Strncmp(cp, patbuf, patlen) == 0) {
218859243Sobrien	    /* We don't fully check distinct matches as Gnuemacs does: */
218959243Sobrien	    if (Argument > 1) {	/* just count matches */
219059243Sobrien		if (++arg >= Argument)
219159243Sobrien		    found++;
219259243Sobrien	    } else {		/* match if distinct from previous */
219359243Sobrien		if (len != Cursor - start || Strncmp(cp, start, len) != 0)
219459243Sobrien		    found++;
219559243Sobrien	    }
219659243Sobrien	}
219759243Sobrien    }
219859243Sobrien
219959243Sobrien    if (LastChar + len - (Cursor - start) >= InputLim)
220059243Sobrien	return(CC_ERROR);	/* no room */
220159243Sobrien    DeleteBack(Cursor - start);
220259243Sobrien    c_insert(len);
220359243Sobrien    while (len--)
220459243Sobrien	*Cursor++ = *cp++;
220559243Sobrien    oldcursor = Cursor;
220659243Sobrien    return(CC_REFRESH);
220759243Sobrien}
220859243Sobrien
220959243Sobrien/*ARGSUSED*/
221059243SobrienCCRETVAL
221159243Sobriene_yank_kill(c)
221259243Sobrien    int c;
221359243Sobrien{				/* almost like GnuEmacs */
221459243Sobrien    register Char *kp, *cp;
221559243Sobrien
221659243Sobrien    USE(c);
221759243Sobrien    if (LastKill == KillBuf)	/* if zero content */
221859243Sobrien	return(CC_ERROR);
221959243Sobrien
222059243Sobrien    if (LastChar + (LastKill - KillBuf) >= InputLim)
222159243Sobrien	return(CC_ERROR);	/* end of buffer space */
222259243Sobrien
222359243Sobrien    /* else */
222459243Sobrien    Mark = Cursor;		/* set the mark */
222559243Sobrien    cp = Cursor;		/* for speed */
222659243Sobrien
222759243Sobrien    c_insert((int)(LastKill - KillBuf));	/* open the space, */
222859243Sobrien    for (kp = KillBuf; kp < LastKill; kp++)	/* copy the chars */
222959243Sobrien	*cp++ = *kp;
223059243Sobrien
223159243Sobrien    if (Argument == 1)		/* if an arg, cursor at beginning */
223259243Sobrien	Cursor = cp;		/* else cursor at end */
223359243Sobrien
223459243Sobrien    return(CC_REFRESH);
223559243Sobrien}
223659243Sobrien
223759243Sobrien/*ARGSUSED*/
223859243SobrienCCRETVAL
223959243Sobrienv_delprev(c) 		/* Backspace key in insert mode */
224059243Sobrien    int c;
224159243Sobrien{
224259243Sobrien    int rc;
224359243Sobrien
224459243Sobrien    USE(c);
224559243Sobrien    rc = CC_ERROR;
224659243Sobrien
224759243Sobrien    if (InsertPos != 0) {
224859243Sobrien	if (Argument <= Cursor - InsertPos) {
224959243Sobrien	    c_delbefore(Argument);	/* delete before */
225059243Sobrien	    Cursor -= Argument;
225159243Sobrien#if defined(DSPMBYTE)
225259243Sobrien	if (_enable_mbdisp && extdel) {
225359243Sobrien	    Cursor--;
225459243Sobrien	    e_redisp(c);
225559243Sobrien	}
225659243Sobrien#endif
225759243Sobrien	    rc = CC_REFRESH;
225859243Sobrien	}
225959243Sobrien    }
226059243Sobrien    return(rc);
226159243Sobrien}   /* v_delprev  */
226259243Sobrien
226359243Sobrien/*ARGSUSED*/
226459243SobrienCCRETVAL
226559243Sobriene_delprev(c)
226659243Sobrien    int c;
226759243Sobrien{
226859243Sobrien    USE(c);
226959243Sobrien    if (Cursor > InputBuf) {
227059243Sobrien	c_delbefore(Argument);	/* delete before dot */
227159243Sobrien	if (Argument > Cursor - InputBuf)
227259243Sobrien	    Cursor = InputBuf;	/* bounds check */
227359243Sobrien	else
227459243Sobrien	    Cursor -= Argument;
227559243Sobrien#if defined(DSPMBYTE)
227659243Sobrien	if (_enable_mbdisp && extdel && Cursor > InputBuf) {
227759243Sobrien	    Cursor--;
227859243Sobrien	    e_redisp(c);
227959243Sobrien	}
228059243Sobrien#endif
228159243Sobrien	return(CC_REFRESH);
228259243Sobrien    }
228359243Sobrien    else {
228459243Sobrien	return(CC_ERROR);
228559243Sobrien    }
228659243Sobrien}
228759243Sobrien
228859243Sobrien/*ARGSUSED*/
228959243SobrienCCRETVAL
229059243Sobriene_delwordprev(c)
229159243Sobrien    int c;
229259243Sobrien{
229359243Sobrien    register Char *cp, *p, *kp;
229459243Sobrien
229559243Sobrien    USE(c);
229659243Sobrien    if (Cursor == InputBuf)
229759243Sobrien	return(CC_ERROR);
229859243Sobrien    /* else */
229959243Sobrien
230059243Sobrien    cp = c_prev_word(Cursor, InputBuf, Argument);
230159243Sobrien
230259243Sobrien    for (p = cp, kp = KillBuf; p < Cursor; p++)	/* save the text */
230359243Sobrien	*kp++ = *p;
230459243Sobrien    LastKill = kp;
230559243Sobrien
230659243Sobrien    c_delbefore((int)(Cursor - cp));	/* delete before dot */
230759243Sobrien    Cursor = cp;
230859243Sobrien    if (Cursor < InputBuf)
230959243Sobrien	Cursor = InputBuf;	/* bounds check */
231059243Sobrien    return(CC_REFRESH);
231159243Sobrien}
231259243Sobrien
231359243Sobrien/* DCS <dcs@neutron.chem.yale.edu>, 9 Oct 93
231459243Sobrien *
231559243Sobrien * Changed the names of some of the ^D family of editor functions to
231659243Sobrien * correspond to what they actually do and created new e_delnext_list
231759243Sobrien * for completeness.
231859243Sobrien *
231959243Sobrien *   Old names:			New names:
232059243Sobrien *
232159243Sobrien *   delete-char		delete-char-or-eof
232259243Sobrien *     F_DELNEXT		  F_DELNEXT_EOF
232359243Sobrien *     e_delnext		  e_delnext_eof
232459243Sobrien *     edelnxt			  edelnxteof
232559243Sobrien *   delete-char-or-eof		delete-char
232659243Sobrien *     F_DELNEXT_EOF		  F_DELNEXT
232759243Sobrien *     e_delnext_eof		  e_delnext
232859243Sobrien *     edelnxteof		  edelnxt
232959243Sobrien *   delete-char-or-list	delete-char-or-list-or-eof
233059243Sobrien *     F_LIST_DELNEXT		  F_DELNEXT_LIST_EOF
233159243Sobrien *     e_list_delnext		  e_delnext_list_eof
233259243Sobrien *   				  edellsteof
233359243Sobrien *   (no old equivalent)	delete-char-or-list
233459243Sobrien *   				  F_DELNEXT_LIST
233559243Sobrien *   				  e_delnext_list
233659243Sobrien *   				  e_delnxtlst
233759243Sobrien */
233859243Sobrien
233959243Sobrien/* added by mtk@ari.ncl.omron.co.jp (920818) */
234059243Sobrien/* rename e_delnext() -> e_delnext_eof() */
234159243Sobrien/*ARGSUSED*/
234259243SobrienCCRETVAL
234359243Sobriene_delnext(c)
234459243Sobrien    int c;
234559243Sobrien{
234659243Sobrien    USE(c);
234759243Sobrien    if (Cursor == LastChar) {/* if I'm at the end */
234859243Sobrien	if (!VImode) {
234959243Sobrien		return(CC_ERROR);
235059243Sobrien	}
235159243Sobrien	else {
235259243Sobrien	    if (Cursor != InputBuf)
235359243Sobrien		Cursor--;
235459243Sobrien	    else
235559243Sobrien		return(CC_ERROR);
235659243Sobrien	}
235759243Sobrien    }
235859243Sobrien    c_delafter(Argument);	/* delete after dot */
235959243Sobrien    if (Cursor > LastChar)
236059243Sobrien	Cursor = LastChar;	/* bounds check */
236159243Sobrien    return(CC_REFRESH);
236259243Sobrien}
236359243Sobrien
236459243Sobrien
236559243Sobrien/*ARGSUSED*/
236659243SobrienCCRETVAL
236759243Sobriene_delnext_eof(c)
236859243Sobrien    int c;
236959243Sobrien{
237059243Sobrien    USE(c);
237159243Sobrien    if (Cursor == LastChar) {/* if I'm at the end */
237259243Sobrien	if (!VImode) {
237359243Sobrien	    if (Cursor == InputBuf) {
237459243Sobrien		/* if I'm also at the beginning */
237559243Sobrien		so_write(STReof, 4);/* then do a EOF */
237659243Sobrien		flush();
237759243Sobrien		return(CC_EOF);
237859243Sobrien	    }
237959243Sobrien	    else
238059243Sobrien		return(CC_ERROR);
238159243Sobrien	}
238259243Sobrien	else {
238359243Sobrien	    if (Cursor != InputBuf)
238459243Sobrien		Cursor--;
238559243Sobrien	    else
238659243Sobrien		return(CC_ERROR);
238759243Sobrien	}
238859243Sobrien    }
238959243Sobrien    c_delafter(Argument);	/* delete after dot */
239059243Sobrien    if (Cursor > LastChar)
239159243Sobrien	Cursor = LastChar;	/* bounds check */
239259243Sobrien    return(CC_REFRESH);
239359243Sobrien}
239459243Sobrien
239559243Sobrien/*ARGSUSED*/
239659243SobrienCCRETVAL
239759243Sobriene_delnext_list(c)
239859243Sobrien    int c;
239959243Sobrien{
240059243Sobrien    USE(c);
240159243Sobrien    if (Cursor == LastChar) {	/* if I'm at the end */
240259243Sobrien	PastBottom();
240359243Sobrien	*LastChar = '\0';	/* just in case */
240459243Sobrien	return(CC_LIST_CHOICES);
240559243Sobrien    }
240659243Sobrien    else {
240759243Sobrien	c_delafter(Argument);	/* delete after dot */
240859243Sobrien	if (Cursor > LastChar)
240959243Sobrien	    Cursor = LastChar;	/* bounds check */
241059243Sobrien	return(CC_REFRESH);
241159243Sobrien    }
241259243Sobrien}
241359243Sobrien
241459243Sobrien/*ARGSUSED*/
241559243SobrienCCRETVAL
241659243Sobriene_delnext_list_eof(c)
241759243Sobrien    int c;
241859243Sobrien{
241959243Sobrien    USE(c);
242059243Sobrien    if (Cursor == LastChar) {	/* if I'm at the end */
242159243Sobrien	if (Cursor == InputBuf) {	/* if I'm also at the beginning */
242259243Sobrien	    so_write(STReof, 4);/* then do a EOF */
242359243Sobrien	    flush();
242459243Sobrien	    return(CC_EOF);
242559243Sobrien	}
242659243Sobrien	else {
242759243Sobrien	    PastBottom();
242859243Sobrien	    *LastChar = '\0';	/* just in case */
242959243Sobrien	    return(CC_LIST_CHOICES);
243059243Sobrien	}
243159243Sobrien    }
243259243Sobrien    else {
243359243Sobrien	c_delafter(Argument);	/* delete after dot */
243459243Sobrien	if (Cursor > LastChar)
243559243Sobrien	    Cursor = LastChar;	/* bounds check */
243659243Sobrien	return(CC_REFRESH);
243759243Sobrien    }
243859243Sobrien}
243959243Sobrien
244059243Sobrien/*ARGSUSED*/
244159243SobrienCCRETVAL
244259243Sobriene_list_eof(c)
244359243Sobrien    int c;
244459243Sobrien{
244559243Sobrien    CCRETVAL rv;
244659243Sobrien
244759243Sobrien    USE(c);
244859243Sobrien    if (Cursor == LastChar && Cursor == InputBuf) {
244959243Sobrien	so_write(STReof, 4);	/* then do a EOF */
245059243Sobrien	flush();
245159243Sobrien	rv = CC_EOF;
245259243Sobrien    }
245359243Sobrien    else {
245459243Sobrien	PastBottom();
245559243Sobrien	*LastChar = '\0';	/* just in case */
245659243Sobrien	rv = CC_LIST_CHOICES;
245759243Sobrien    }
245859243Sobrien    return rv;
245959243Sobrien}
246059243Sobrien
246159243Sobrien/*ARGSUSED*/
246259243SobrienCCRETVAL
246359243Sobriene_delwordnext(c)
246459243Sobrien    int c;
246559243Sobrien{
246659243Sobrien    register Char *cp, *p, *kp;
246759243Sobrien
246859243Sobrien    USE(c);
246959243Sobrien    if (Cursor == LastChar)
247059243Sobrien	return(CC_ERROR);
247159243Sobrien    /* else */
247259243Sobrien
247359243Sobrien    cp = c_next_word(Cursor, LastChar, Argument);
247459243Sobrien
247559243Sobrien    for (p = Cursor, kp = KillBuf; p < cp; p++)	/* save the text */
247659243Sobrien	*kp++ = *p;
247759243Sobrien    LastKill = kp;
247859243Sobrien
247959243Sobrien    c_delafter((int)(cp - Cursor));	/* delete after dot */
248059243Sobrien    if (Cursor > LastChar)
248159243Sobrien	Cursor = LastChar;	/* bounds check */
248259243Sobrien    return(CC_REFRESH);
248359243Sobrien}
248459243Sobrien
248559243Sobrien/*ARGSUSED*/
248659243SobrienCCRETVAL
248759243Sobriene_toend(c)
248859243Sobrien    int c;
248959243Sobrien{
249059243Sobrien    USE(c);
249159243Sobrien    Cursor = LastChar;
249259243Sobrien    if (VImode)
249359243Sobrien	if (ActionFlag & TCSHOP_DELETE) {
249459243Sobrien	    c_delfini();
249559243Sobrien	    return(CC_REFRESH);
249659243Sobrien	}
249759243Sobrien    RefCursor();		/* move the cursor */
249859243Sobrien    return(CC_NORM);
249959243Sobrien}
250059243Sobrien
250159243Sobrien/*ARGSUSED*/
250259243SobrienCCRETVAL
250359243Sobriene_tobeg(c)
250459243Sobrien    int c;
250559243Sobrien{
250659243Sobrien    USE(c);
250759243Sobrien    Cursor = InputBuf;
250859243Sobrien
250959243Sobrien    if (VImode) {
251059243Sobrien       while (Isspace(*Cursor)) /* We want FIRST non space character */
251159243Sobrien	Cursor++;
251259243Sobrien	if (ActionFlag & TCSHOP_DELETE) {
251359243Sobrien	    c_delfini();
251459243Sobrien	    return(CC_REFRESH);
251559243Sobrien	}
251659243Sobrien    }
251759243Sobrien
251859243Sobrien    RefCursor();		/* move the cursor */
251959243Sobrien    return(CC_NORM);
252059243Sobrien}
252159243Sobrien
252259243Sobrien/*ARGSUSED*/
252359243SobrienCCRETVAL
252459243Sobriene_killend(c)
252559243Sobrien    int c;
252659243Sobrien{
252759243Sobrien    register Char *kp, *cp;
252859243Sobrien
252959243Sobrien    USE(c);
253059243Sobrien    cp = Cursor;
253159243Sobrien    kp = KillBuf;
253259243Sobrien    while (cp < LastChar)
253359243Sobrien	*kp++ = *cp++;		/* copy it */
253459243Sobrien    LastKill = kp;
253559243Sobrien    LastChar = Cursor;		/* zap! -- delete to end */
253659243Sobrien    return(CC_REFRESH);
253759243Sobrien}
253859243Sobrien
253959243Sobrien
254059243Sobrien/*ARGSUSED*/
254159243SobrienCCRETVAL
254259243Sobriene_killbeg(c)
254359243Sobrien    int c;
254459243Sobrien{
254559243Sobrien    register Char *kp, *cp;
254659243Sobrien
254759243Sobrien    USE(c);
254859243Sobrien    cp = InputBuf;
254959243Sobrien    kp = KillBuf;
255059243Sobrien    while (cp < Cursor)
255159243Sobrien	*kp++ = *cp++;		/* copy it */
255259243Sobrien    LastKill = kp;
255359243Sobrien    c_delbefore((int)(Cursor - InputBuf));
255459243Sobrien    Cursor = InputBuf;		/* zap! */
255559243Sobrien    return(CC_REFRESH);
255659243Sobrien}
255759243Sobrien
255859243Sobrien/*ARGSUSED*/
255959243SobrienCCRETVAL
256059243Sobriene_killall(c)
256159243Sobrien    int c;
256259243Sobrien{
256359243Sobrien    register Char *kp, *cp;
256459243Sobrien
256559243Sobrien    USE(c);
256659243Sobrien    cp = InputBuf;
256759243Sobrien    kp = KillBuf;
256859243Sobrien    while (cp < LastChar)
256959243Sobrien	*kp++ = *cp++;		/* copy it */
257059243Sobrien    LastKill = kp;
257159243Sobrien    LastChar = InputBuf;	/* zap! -- delete all of it */
257259243Sobrien    Cursor = InputBuf;
257359243Sobrien    return(CC_REFRESH);
257459243Sobrien}
257559243Sobrien
257659243Sobrien/*ARGSUSED*/
257759243SobrienCCRETVAL
257859243Sobriene_killregion(c)
257959243Sobrien    int c;
258059243Sobrien{
258159243Sobrien    register Char *kp, *cp;
258259243Sobrien
258359243Sobrien    USE(c);
258459243Sobrien    if (!Mark)
258559243Sobrien	return(CC_ERROR);
258659243Sobrien
258759243Sobrien    if (Mark > Cursor) {
258859243Sobrien	cp = Cursor;
258959243Sobrien	kp = KillBuf;
259059243Sobrien	while (cp < Mark)
259159243Sobrien	    *kp++ = *cp++;	/* copy it */
259259243Sobrien	LastKill = kp;
259359243Sobrien	c_delafter((int)(cp - Cursor));	/* delete it - UNUSED BY VI mode */
259459243Sobrien    }
259559243Sobrien    else {			/* mark is before cursor */
259659243Sobrien	cp = Mark;
259759243Sobrien	kp = KillBuf;
259859243Sobrien	while (cp < Cursor)
259959243Sobrien	    *kp++ = *cp++;	/* copy it */
260059243Sobrien	LastKill = kp;
260159243Sobrien	c_delbefore((int)(cp - Mark));
260259243Sobrien	Cursor = Mark;
260359243Sobrien    }
260459243Sobrien    return(CC_REFRESH);
260559243Sobrien}
260659243Sobrien
260759243Sobrien/*ARGSUSED*/
260859243SobrienCCRETVAL
260959243Sobriene_copyregion(c)
261059243Sobrien    int c;
261159243Sobrien{
261259243Sobrien    register Char *kp, *cp;
261359243Sobrien
261459243Sobrien    USE(c);
261559243Sobrien    if (!Mark)
261659243Sobrien	return(CC_ERROR);
261759243Sobrien
261859243Sobrien    if (Mark > Cursor) {
261959243Sobrien	cp = Cursor;
262059243Sobrien	kp = KillBuf;
262159243Sobrien	while (cp < Mark)
262259243Sobrien	    *kp++ = *cp++;	/* copy it */
262359243Sobrien	LastKill = kp;
262459243Sobrien    }
262559243Sobrien    else {			/* mark is before cursor */
262659243Sobrien	cp = Mark;
262759243Sobrien	kp = KillBuf;
262859243Sobrien	while (cp < Cursor)
262959243Sobrien	    *kp++ = *cp++;	/* copy it */
263059243Sobrien	LastKill = kp;
263159243Sobrien    }
263259243Sobrien    return(CC_NORM);		/* don't even need to Refresh() */
263359243Sobrien}
263459243Sobrien
263559243Sobrien/*ARGSUSED*/
263659243SobrienCCRETVAL
263759243Sobriene_charswitch(cc)
263859243Sobrien    int cc;
263959243Sobrien{
264059243Sobrien    register Char c;
264159243Sobrien
264259243Sobrien    USE(cc);
264359243Sobrien
264459243Sobrien    /* do nothing if we are at beginning of line or have only one char */
264559243Sobrien    if (Cursor == &InputBuf[0] || LastChar == &InputBuf[1]) {
264659243Sobrien	return(CC_ERROR);
264759243Sobrien    }
264859243Sobrien
264959243Sobrien    if (Cursor < LastChar) {
265059243Sobrien	Cursor++;
265159243Sobrien    }
265259243Sobrien    c = Cursor[-2];
265359243Sobrien    Cursor[-2] = Cursor[-1];
265459243Sobrien    Cursor[-1] = c;
265559243Sobrien    return(CC_REFRESH);
265659243Sobrien}
265759243Sobrien
265859243Sobrien/*ARGSUSED*/
265959243SobrienCCRETVAL
266059243Sobriene_gcharswitch(cc)
266159243Sobrien    int cc;
266259243Sobrien{				/* gosmacs style ^T */
266359243Sobrien    register Char c;
266459243Sobrien
266559243Sobrien    USE(cc);
266659243Sobrien    if (Cursor > &InputBuf[1]) {/* must have at least two chars entered */
266759243Sobrien	c = Cursor[-2];
266859243Sobrien	Cursor[-2] = Cursor[-1];
266959243Sobrien	Cursor[-1] = c;
267059243Sobrien	return(CC_REFRESH);
267159243Sobrien    }
267259243Sobrien    else {
267359243Sobrien	return(CC_ERROR);
267459243Sobrien    }
267559243Sobrien}
267659243Sobrien
267759243Sobrien#if defined(DSPMBYTE) /* BY TAGA Nayuta VERY THANKS */
267859243Sobrien/*ARGSUSED*/
267959243Sobrienstatic void
268059243Sobriene_charback_mbyte(argument)
268159243Sobrien     int argument;
268259243Sobrien{
268359243Sobrien    if (!_enable_mbdisp) {
268459243Sobrien	if (Argument > Cursor - InputBuf)
268559243Sobrien	    Cursor = InputBuf;
268659243Sobrien	else
268759243Sobrien	    Cursor -= Argument;
268859243Sobrien    }
268959243Sobrien    else {
269059243Sobrien	while (0 < argument && Cursor > InputBuf) {
269159243Sobrien	    if (Cursor - 1 != InputBuf &&
269259243Sobrien		Ismbyte1(*(Cursor - 2)) && Ismbyte2(*(Cursor - 1))) {
269359243Sobrien		Cursor--;
269459243Sobrien	    }
269559243Sobrien	    Cursor--;
269659243Sobrien	    argument--;
269759243Sobrien	}
269859243Sobrien    }
269959243Sobrien}
270059243Sobrien#endif
270159243Sobrien
270259243Sobrien/*ARGSUSED*/
270359243SobrienCCRETVAL
270459243Sobriene_charback(c)
270559243Sobrien    int c;
270659243Sobrien{
270759243Sobrien    USE(c);
270859243Sobrien    if (Cursor > InputBuf) {
270959243Sobrien#if defined(DSPMBYTE) /* BY TAGA Nayuta VERY THANKS */
271059243Sobrien	e_charback_mbyte(Argument);
271159243Sobrien#else
271259243Sobrien	if (Argument > Cursor - InputBuf)
271359243Sobrien	    Cursor = InputBuf;
271459243Sobrien	else
271559243Sobrien	    Cursor -= Argument;
271659243Sobrien#endif
271759243Sobrien
271859243Sobrien	if (VImode)
271959243Sobrien	    if (ActionFlag & TCSHOP_DELETE) {
272059243Sobrien		c_delfini();
272159243Sobrien		return(CC_REFRESH);
272259243Sobrien	    }
272359243Sobrien
272459243Sobrien	RefCursor();
272559243Sobrien	return(CC_NORM);
272659243Sobrien    }
272759243Sobrien    else {
272859243Sobrien	return(CC_ERROR);
272959243Sobrien    }
273059243Sobrien}
273159243Sobrien
273259243Sobrien/*ARGSUSED*/
273359243SobrienCCRETVAL
273459243Sobrienv_wordback(c)
273559243Sobrien    int c;
273659243Sobrien{
273759243Sobrien    USE(c);
273859243Sobrien    if (Cursor == InputBuf)
273959243Sobrien	return(CC_ERROR);
274059243Sobrien    /* else */
274159243Sobrien
274259243Sobrien    Cursor = c_preword(Cursor, InputBuf, Argument); /* bounds check */
274359243Sobrien
274459243Sobrien    if (ActionFlag & TCSHOP_DELETE) {
274559243Sobrien	c_delfini();
274659243Sobrien	return(CC_REFRESH);
274759243Sobrien    }
274859243Sobrien
274959243Sobrien    RefCursor();
275059243Sobrien    return(CC_NORM);
275159243Sobrien}
275259243Sobrien
275359243Sobrien/*ARGSUSED*/
275459243SobrienCCRETVAL
275559243Sobriene_wordback(c)
275659243Sobrien    int c;
275759243Sobrien{
275859243Sobrien    USE(c);
275959243Sobrien    if (Cursor == InputBuf)
276059243Sobrien	return(CC_ERROR);
276159243Sobrien    /* else */
276259243Sobrien
276359243Sobrien    Cursor = c_prev_word(Cursor, InputBuf, Argument); /* bounds check */
276459243Sobrien
276559243Sobrien    if (VImode)
276659243Sobrien	if (ActionFlag & TCSHOP_DELETE) {
276759243Sobrien	    c_delfini();
276859243Sobrien	    return(CC_REFRESH);
276959243Sobrien	}
277059243Sobrien
277159243Sobrien    RefCursor();
277259243Sobrien    return(CC_NORM);
277359243Sobrien}
277459243Sobrien
277559243Sobrien#if defined(DSPMBYTE) /* BY TAGA Nayuta VERY THANKS */
277659243Sobrien/*ARGSUSED*/
277759243Sobrienstatic void
277859243Sobriene_charfwd_mbyte(argument)
277959243Sobrien     int argument;
278059243Sobrien{
278159243Sobrien    if (!_enable_mbdisp)
278259243Sobrien	Cursor += argument;
278359243Sobrien    else
278459243Sobrien	while (0 < argument && Cursor < LastChar) {
278559243Sobrien	    if (Cursor + 1 != LastChar &&
278659243Sobrien		Ismbyte1(*Cursor) && Ismbyte2(*(Cursor + 1))) {
278759243Sobrien		Cursor++;
278859243Sobrien	    }
278959243Sobrien	    Cursor++;
279059243Sobrien	    argument--;
279159243Sobrien	}
279259243Sobrien}
279359243Sobrien#endif
279459243Sobrien
279559243Sobrien/*ARGSUSED*/
279659243SobrienCCRETVAL
279759243Sobriene_charfwd(c)
279859243Sobrien    int c;
279959243Sobrien{
280059243Sobrien    USE(c);
280159243Sobrien    if (Cursor < LastChar) {
280259243Sobrien#if defined(DSPMBYTE) /* BY TAGA Nayuta VERY THANKS */
280359243Sobrien	e_charfwd_mbyte(Argument);
280459243Sobrien#else
280559243Sobrien	Cursor += Argument;
280659243Sobrien#endif
280759243Sobrien	if (Cursor > LastChar)
280859243Sobrien	    Cursor = LastChar;
280959243Sobrien
281059243Sobrien	if (VImode)
281159243Sobrien	    if (ActionFlag & TCSHOP_DELETE) {
281259243Sobrien		c_delfini();
281359243Sobrien		return(CC_REFRESH);
281459243Sobrien	    }
281559243Sobrien
281659243Sobrien	RefCursor();
281759243Sobrien	return(CC_NORM);
281859243Sobrien    }
281959243Sobrien    else {
282059243Sobrien	return(CC_ERROR);
282159243Sobrien    }
282259243Sobrien}
282359243Sobrien
282459243Sobrien/*ARGSUSED*/
282559243SobrienCCRETVAL
282659243Sobriene_wordfwd(c)
282759243Sobrien    int c;
282859243Sobrien{
282959243Sobrien    USE(c);
283059243Sobrien    if (Cursor == LastChar)
283159243Sobrien	return(CC_ERROR);
283259243Sobrien    /* else */
283359243Sobrien
283459243Sobrien    Cursor = c_next_word(Cursor, LastChar, Argument);
283559243Sobrien
283659243Sobrien    if (VImode)
283759243Sobrien	if (ActionFlag & TCSHOP_DELETE) {
283859243Sobrien	    c_delfini();
283959243Sobrien	    return(CC_REFRESH);
284059243Sobrien	}
284159243Sobrien
284259243Sobrien    RefCursor();
284359243Sobrien    return(CC_NORM);
284459243Sobrien}
284559243Sobrien
284659243Sobrien/*ARGSUSED*/
284759243SobrienCCRETVAL
284859243Sobrienv_wordfwd(c)
284959243Sobrien    int c;
285059243Sobrien{
285159243Sobrien    USE(c);
285259243Sobrien    if (Cursor == LastChar)
285359243Sobrien	return(CC_ERROR);
285459243Sobrien    /* else */
285559243Sobrien
285659243Sobrien    Cursor = c_nexword(Cursor, LastChar, Argument);
285759243Sobrien
285859243Sobrien    if (VImode)
285959243Sobrien	if (ActionFlag & TCSHOP_DELETE) {
286059243Sobrien	    c_delfini();
286159243Sobrien	    return(CC_REFRESH);
286259243Sobrien	}
286359243Sobrien
286459243Sobrien    RefCursor();
286559243Sobrien    return(CC_NORM);
286659243Sobrien}
286759243Sobrien
286859243Sobrien/*ARGSUSED*/
286959243SobrienCCRETVAL
287059243Sobrienv_wordbegnext(c)
287159243Sobrien    int c;
287259243Sobrien{
287359243Sobrien    USE(c);
287459243Sobrien    if (Cursor == LastChar)
287559243Sobrien	return(CC_ERROR);
287659243Sobrien    /* else */
287759243Sobrien
287859243Sobrien    Cursor = c_next_word(Cursor, LastChar, Argument);
287959243Sobrien    if (Cursor < LastChar)
288059243Sobrien	Cursor++;
288159243Sobrien
288259243Sobrien    if (VImode)
288359243Sobrien	if (ActionFlag & TCSHOP_DELETE) {
288459243Sobrien	    c_delfini();
288559243Sobrien	    return(CC_REFRESH);
288659243Sobrien	}
288759243Sobrien
288859243Sobrien    RefCursor();
288959243Sobrien    return(CC_NORM);
289059243Sobrien}
289159243Sobrien
289259243Sobrien/*ARGSUSED*/
289359243Sobrienstatic CCRETVAL
289459243Sobrienv_repeat_srch(c)
289559243Sobrien    int c;
289659243Sobrien{
289759243Sobrien    CCRETVAL rv = CC_ERROR;
289859243Sobrien#ifdef SDEBUG
289959243Sobrien    xprintf("dir %d patlen %d patbuf %S\n",
290059243Sobrien	    c, patlen, patbuf);
290159243Sobrien#endif
290259243Sobrien
290359243Sobrien    LastCmd = (KEYCMD) c;  /* Hack to stop c_hsetpat */
290459243Sobrien    LastChar = InputBuf;
290559243Sobrien    switch (c) {
290659243Sobrien    case F_DOWN_SEARCH_HIST:
290759243Sobrien	rv = e_down_search_hist(0);
290859243Sobrien	break;
290959243Sobrien    case F_UP_SEARCH_HIST:
291059243Sobrien	rv = e_up_search_hist(0);
291159243Sobrien	break;
291259243Sobrien    default:
291359243Sobrien	break;
291459243Sobrien    }
291559243Sobrien    return rv;
291659243Sobrien}
291759243Sobrien
291859243Sobrienstatic CCRETVAL
291959243Sobrienv_csearch_back(ch, count, tflag)
292059243Sobrien    int ch, count, tflag;
292159243Sobrien{
292259243Sobrien    Char *cp;
292359243Sobrien
292459243Sobrien    cp = Cursor;
292559243Sobrien    while (count--) {
292659243Sobrien	if (*cp == ch)
292759243Sobrien	    cp--;
292859243Sobrien	while (cp > InputBuf && *cp != ch)
292959243Sobrien	    cp--;
293059243Sobrien    }
293159243Sobrien
293259243Sobrien    if (cp < InputBuf || (cp == InputBuf && *cp != ch))
293359243Sobrien	return(CC_ERROR);
293459243Sobrien
293559243Sobrien    if (*cp == ch && tflag)
293659243Sobrien	cp++;
293759243Sobrien
293859243Sobrien    Cursor = cp;
293959243Sobrien
294059243Sobrien    if (ActionFlag & TCSHOP_DELETE) {
294159243Sobrien	Cursor++;
294259243Sobrien	c_delfini();
294359243Sobrien	return(CC_REFRESH);
294459243Sobrien    }
294559243Sobrien
294659243Sobrien    RefCursor();
294759243Sobrien    return(CC_NORM);
294859243Sobrien}
294959243Sobrien
295059243Sobrienstatic CCRETVAL
295159243Sobrienv_csearch_fwd(ch, count, tflag)
295259243Sobrien    int ch, count, tflag;
295359243Sobrien{
295459243Sobrien    Char *cp;
295559243Sobrien
295659243Sobrien    cp = Cursor;
295759243Sobrien    while (count--) {
295859243Sobrien	if(*cp == ch)
295959243Sobrien	    cp++;
296059243Sobrien	while (cp < LastChar && *cp != ch)
296159243Sobrien	    cp++;
296259243Sobrien    }
296359243Sobrien
296459243Sobrien    if (cp >= LastChar)
296559243Sobrien	return(CC_ERROR);
296659243Sobrien
296759243Sobrien    if (*cp == ch && tflag)
296859243Sobrien	cp--;
296959243Sobrien
297059243Sobrien    Cursor = cp;
297159243Sobrien
297259243Sobrien    if (ActionFlag & TCSHOP_DELETE) {
297359243Sobrien	Cursor++;
297459243Sobrien	c_delfini();
297559243Sobrien	return(CC_REFRESH);
297659243Sobrien    }
297759243Sobrien    RefCursor();
297859243Sobrien    return(CC_NORM);
297959243Sobrien}
298059243Sobrien
298159243Sobrien/*ARGSUSED*/
298259243Sobrienstatic CCRETVAL
298359243Sobrienv_action(c)
298459243Sobrien    int c;
298559243Sobrien{
298659243Sobrien    register Char *cp, *kp;
298759243Sobrien
298859243Sobrien    if (ActionFlag == TCSHOP_DELETE) {
298959243Sobrien	ActionFlag = TCSHOP_NOP;
299059243Sobrien	ActionPos = 0;
299159243Sobrien
299259243Sobrien	UndoSize = 0;
299359243Sobrien	kp = UndoBuf;
299459243Sobrien	for (cp = InputBuf; cp < LastChar; cp++) {
299559243Sobrien	    *kp++ = *cp;
299659243Sobrien	    UndoSize++;
299759243Sobrien	}
299859243Sobrien
299959243Sobrien	UndoAction = TCSHOP_INSERT;
300059243Sobrien	UndoPtr  = InputBuf;
300159243Sobrien	LastChar = InputBuf;
300259243Sobrien	Cursor   = InputBuf;
300359243Sobrien	if (c & TCSHOP_INSERT)
300459243Sobrien	    c_alternativ_key_map(0);
300559243Sobrien
300659243Sobrien	return(CC_REFRESH);
300759243Sobrien    }
300859243Sobrien#ifdef notdef
300959243Sobrien    else if (ActionFlag == TCSHOP_NOP) {
301059243Sobrien#endif
301159243Sobrien	ActionPos = Cursor;
301259243Sobrien	ActionFlag = c;
301359243Sobrien	return(CC_ARGHACK);  /* Do NOT clear out argument */
301459243Sobrien#ifdef notdef
301559243Sobrien    }
301659243Sobrien    else {
301759243Sobrien	ActionFlag = 0;
301859243Sobrien	ActionPos = 0;
301959243Sobrien	return(CC_ERROR);
302059243Sobrien    }
302159243Sobrien#endif
302259243Sobrien}
302359243Sobrien
302459243Sobrien#ifdef COMMENT
302559243Sobrien/* by: Brian Allison <uiucdcs!convex!allison@RUTGERS.EDU> */
302659243Sobrienstatic void
302759243Sobrienc_get_word(begin, end)
302859243Sobrien    Char  **begin;
302959243Sobrien    Char  **end;
303059243Sobrien{
303159243Sobrien    Char   *cp;
303259243Sobrien
303359243Sobrien    cp = &Cursor[0];
303459243Sobrien    while (Argument--) {
303559243Sobrien	while ((cp <= LastChar) && (isword(*cp)))
303659243Sobrien	    cp++;
303759243Sobrien	*end = --cp;
303859243Sobrien	while ((cp >= InputBuf) && (isword(*cp)))
303959243Sobrien	    cp--;
304059243Sobrien	*begin = ++cp;
304159243Sobrien    }
304259243Sobrien}
304359243Sobrien#endif /* COMMENT */
304459243Sobrien
304559243Sobrien/*ARGSUSED*/
304659243SobrienCCRETVAL
304759243Sobriene_uppercase(c)
304859243Sobrien    int c;
304959243Sobrien{
305059243Sobrien    Char   *cp, *end;
305159243Sobrien
305259243Sobrien    USE(c);
305359243Sobrien    end = c_next_word(Cursor, LastChar, Argument);
305459243Sobrien
305559243Sobrien    for (cp = Cursor; cp < end; cp++)	/* PWP: was cp=begin */
305659243Sobrien	if (Islower(*cp))
305759243Sobrien	    *cp = Toupper(*cp);
305859243Sobrien
305959243Sobrien    Cursor = end;
306059243Sobrien    if (Cursor > LastChar)
306159243Sobrien	Cursor = LastChar;
306259243Sobrien    return(CC_REFRESH);
306359243Sobrien}
306459243Sobrien
306559243Sobrien
306659243Sobrien/*ARGSUSED*/
306759243SobrienCCRETVAL
306859243Sobriene_capitolcase(c)
306959243Sobrien    int c;
307059243Sobrien{
307159243Sobrien    Char   *cp, *end;
307259243Sobrien
307359243Sobrien    USE(c);
307459243Sobrien    end = c_next_word(Cursor, LastChar, Argument);
307559243Sobrien
307659243Sobrien    cp = Cursor;
307759243Sobrien    for (; cp < end; cp++) {
307859243Sobrien	if (Isalpha(*cp)) {
307959243Sobrien	    if (Islower(*cp))
308059243Sobrien		*cp = Toupper(*cp);
308159243Sobrien	    cp++;
308259243Sobrien	    break;
308359243Sobrien	}
308459243Sobrien    }
308559243Sobrien    for (; cp < end; cp++)
308659243Sobrien	if (Isupper(*cp))
308759243Sobrien	    *cp = Tolower(*cp);
308859243Sobrien
308959243Sobrien    Cursor = end;
309059243Sobrien    if (Cursor > LastChar)
309159243Sobrien	Cursor = LastChar;
309259243Sobrien    return(CC_REFRESH);
309359243Sobrien}
309459243Sobrien
309559243Sobrien/*ARGSUSED*/
309659243SobrienCCRETVAL
309759243Sobriene_lowercase(c)
309859243Sobrien    int c;
309959243Sobrien{
310059243Sobrien    Char   *cp, *end;
310159243Sobrien
310259243Sobrien    USE(c);
310359243Sobrien    end = c_next_word(Cursor, LastChar, Argument);
310459243Sobrien
310559243Sobrien    for (cp = Cursor; cp < end; cp++)
310659243Sobrien	if (Isupper(*cp))
310759243Sobrien	    *cp = Tolower(*cp);
310859243Sobrien
310959243Sobrien    Cursor = end;
311059243Sobrien    if (Cursor > LastChar)
311159243Sobrien	Cursor = LastChar;
311259243Sobrien    return(CC_REFRESH);
311359243Sobrien}
311459243Sobrien
311559243Sobrien
311659243Sobrien/*ARGSUSED*/
311759243SobrienCCRETVAL
311859243Sobriene_set_mark(c)
311959243Sobrien    int c;
312059243Sobrien{
312159243Sobrien    USE(c);
312259243Sobrien    Mark = Cursor;
312359243Sobrien    return(CC_NORM);
312459243Sobrien}
312559243Sobrien
312659243Sobrien/*ARGSUSED*/
312759243SobrienCCRETVAL
312859243Sobriene_exchange_mark(c)
312959243Sobrien    int c;
313059243Sobrien{
313159243Sobrien    register Char *cp;
313259243Sobrien
313359243Sobrien    USE(c);
313459243Sobrien    cp = Cursor;
313559243Sobrien    Cursor = Mark;
313659243Sobrien    Mark = cp;
313759243Sobrien    RefCursor();
313859243Sobrien    return(CC_NORM);
313959243Sobrien}
314059243Sobrien
314159243Sobrien/*ARGSUSED*/
314259243SobrienCCRETVAL
314359243Sobriene_argfour(c)
314459243Sobrien    int c;
314559243Sobrien{				/* multiply current argument by 4 */
314659243Sobrien    USE(c);
314759243Sobrien    if (Argument > 1000000)
314859243Sobrien	return CC_ERROR;
314959243Sobrien    DoingArg = 1;
315059243Sobrien    Argument *= 4;
315159243Sobrien    return(CC_ARGHACK);
315259243Sobrien}
315359243Sobrien
315459243Sobrien/*ARGSUSED*/
315559243SobrienCCRETVAL
315659243Sobriene_quote(c)
315759243Sobrien    int c;
315859243Sobrien{
315959243Sobrien    Char    ch;
316059243Sobrien    int     num;
316159243Sobrien
316259243Sobrien    USE(c);
316359243Sobrien    QuoteModeOn();
316459243Sobrien    num = GetNextChar(&ch);
316559243Sobrien    QuoteModeOff();
316659243Sobrien    if (num == 1)
316759243Sobrien	return e_insert(ch);
316859243Sobrien    else
316959243Sobrien	return e_send_eof(0);
317059243Sobrien}
317159243Sobrien
317259243Sobrien/*ARGSUSED*/
317359243SobrienCCRETVAL
317459243Sobriene_metanext(c)
317559243Sobrien    int c;
317659243Sobrien{
317759243Sobrien    USE(c);
317859243Sobrien    MetaNext = 1;
317959243Sobrien    return(CC_ARGHACK);	/* preserve argument */
318059243Sobrien}
318159243Sobrien
318259243Sobrien#ifdef notdef
318359243Sobrien/*ARGSUSED*/
318459243SobrienCCRETVAL
318559243Sobriene_extendnext(c)
318659243Sobrien    int c;
318759243Sobrien{
318859243Sobrien    CurrentKeyMap = CcAltMap;
318959243Sobrien    return(CC_ARGHACK);	/* preserve argument */
319059243Sobrien}
319159243Sobrien
319259243Sobrien#endif
319359243Sobrien
319459243Sobrien/*ARGSUSED*/
319559243SobrienCCRETVAL
319659243Sobrienv_insbeg(c)
319759243Sobrien    int c;
319859243Sobrien{				/* move to beginning of line and start vi
319959243Sobrien				 * insert mode */
320059243Sobrien    USE(c);
320159243Sobrien    Cursor = InputBuf;
320259243Sobrien    InsertPos = Cursor;
320359243Sobrien
320459243Sobrien    UndoPtr  = Cursor;
320559243Sobrien    UndoAction = TCSHOP_DELETE;
320659243Sobrien
320759243Sobrien    RefCursor();		/* move the cursor */
320859243Sobrien    c_alternativ_key_map(0);
320959243Sobrien    return(CC_NORM);
321059243Sobrien}
321159243Sobrien
321259243Sobrien/*ARGSUSED*/
321359243SobrienCCRETVAL
321459243Sobrienv_replone(c)
321559243Sobrien    int c;
321659243Sobrien{				/* vi mode overwrite one character */
321759243Sobrien    USE(c);
321859243Sobrien    c_alternativ_key_map(0);
321959243Sobrien    inputmode = MODE_REPLACE_1;
322059243Sobrien    UndoAction = TCSHOP_CHANGE;	/* Set Up for VI undo command */
322159243Sobrien    UndoPtr = Cursor;
322259243Sobrien    UndoSize = 0;
322359243Sobrien    return(CC_NORM);
322459243Sobrien}
322559243Sobrien
322659243Sobrien/*ARGSUSED*/
322759243SobrienCCRETVAL
322859243Sobrienv_replmode(c)
322959243Sobrien    int c;
323059243Sobrien{				/* vi mode start overwriting */
323159243Sobrien    USE(c);
323259243Sobrien    c_alternativ_key_map(0);
323359243Sobrien    inputmode = MODE_REPLACE;
323459243Sobrien    UndoAction = TCSHOP_CHANGE;	/* Set Up for VI undo command */
323559243Sobrien    UndoPtr = Cursor;
323659243Sobrien    UndoSize = 0;
323759243Sobrien    return(CC_NORM);
323859243Sobrien}
323959243Sobrien
324059243Sobrien/*ARGSUSED*/
324159243SobrienCCRETVAL
324259243Sobrienv_substchar(c)
324359243Sobrien    int c;
324459243Sobrien{				/* vi mode substitute for one char */
324559243Sobrien    USE(c);
324659243Sobrien    c_delafter(Argument);
324759243Sobrien    c_alternativ_key_map(0);
324859243Sobrien    return(CC_REFRESH);
324959243Sobrien}
325059243Sobrien
325159243Sobrien/*ARGSUSED*/
325259243SobrienCCRETVAL
325359243Sobrienv_substline(c)
325459243Sobrien    int c;
325559243Sobrien{				/* vi mode replace whole line */
325659243Sobrien    USE(c);
325759243Sobrien    (void) e_killall(0);
325859243Sobrien    c_alternativ_key_map(0);
325959243Sobrien    return(CC_REFRESH);
326059243Sobrien}
326159243Sobrien
326259243Sobrien/*ARGSUSED*/
326359243SobrienCCRETVAL
326459243Sobrienv_chgtoend(c)
326559243Sobrien    int c;
326659243Sobrien{				/* vi mode change to end of line */
326759243Sobrien    USE(c);
326859243Sobrien    (void) e_killend(0);
326959243Sobrien    c_alternativ_key_map(0);
327059243Sobrien    return(CC_REFRESH);
327159243Sobrien}
327259243Sobrien
327359243Sobrien/*ARGSUSED*/
327459243SobrienCCRETVAL
327559243Sobrienv_insert(c)
327659243Sobrien    int c;
327759243Sobrien{				/* vi mode start inserting */
327859243Sobrien    USE(c);
327959243Sobrien    c_alternativ_key_map(0);
328059243Sobrien
328159243Sobrien    InsertPos = Cursor;
328259243Sobrien    UndoPtr = Cursor;
328359243Sobrien    UndoAction = TCSHOP_DELETE;
328459243Sobrien
328559243Sobrien    return(CC_NORM);
328659243Sobrien}
328759243Sobrien
328859243Sobrien/*ARGSUSED*/
328959243SobrienCCRETVAL
329059243Sobrienv_add(c)
329159243Sobrien    int c;
329259243Sobrien{				/* vi mode start adding */
329359243Sobrien    USE(c);
329459243Sobrien    c_alternativ_key_map(0);
329559243Sobrien    if (Cursor < LastChar)
329659243Sobrien    {
329759243Sobrien	Cursor++;
329859243Sobrien	if (Cursor > LastChar)
329959243Sobrien	    Cursor = LastChar;
330059243Sobrien	RefCursor();
330159243Sobrien    }
330259243Sobrien
330359243Sobrien    InsertPos = Cursor;
330459243Sobrien    UndoPtr = Cursor;
330559243Sobrien    UndoAction = TCSHOP_DELETE;
330659243Sobrien
330759243Sobrien    return(CC_NORM);
330859243Sobrien}
330959243Sobrien
331059243Sobrien/*ARGSUSED*/
331159243SobrienCCRETVAL
331259243Sobrienv_addend(c)
331359243Sobrien    int c;
331459243Sobrien{				/* vi mode to add at end of line */
331559243Sobrien    USE(c);
331659243Sobrien    c_alternativ_key_map(0);
331759243Sobrien    Cursor = LastChar;
331859243Sobrien
331959243Sobrien    InsertPos = LastChar;	/* Mark where insertion begins */
332059243Sobrien    UndoPtr = LastChar;
332159243Sobrien    UndoAction = TCSHOP_DELETE;
332259243Sobrien
332359243Sobrien    RefCursor();
332459243Sobrien    return(CC_NORM);
332559243Sobrien}
332659243Sobrien
332759243Sobrien/*ARGSUSED*/
332859243SobrienCCRETVAL
332959243Sobrienv_change_case(cc)
333059243Sobrien    int cc;
333159243Sobrien{
333259243Sobrien    char    c;
333359243Sobrien
333459243Sobrien    USE(cc);
333559243Sobrien    if (Cursor < LastChar) {
333659243Sobrien#ifndef WINNT
333759243Sobrien	c = *Cursor;
333859243Sobrien#else
333959243Sobrien	c = CHAR & *Cursor;
334059243Sobrien#endif /* WINNT */
334159243Sobrien	if (Isupper(c))
334259243Sobrien	    *Cursor++ = Tolower(c);
334359243Sobrien	else if (Islower(c))
334459243Sobrien	    *Cursor++ = Toupper(c);
334559243Sobrien	else
334659243Sobrien	    Cursor++;
334759243Sobrien	RefPlusOne();		/* fast refresh for one char */
334859243Sobrien	return(CC_NORM);
334959243Sobrien    }
335059243Sobrien    return(CC_ERROR);
335159243Sobrien}
335259243Sobrien
335359243Sobrien/*ARGSUSED*/
335459243SobrienCCRETVAL
335559243Sobriene_expand(c)
335659243Sobrien    int c;
335759243Sobrien{
335859243Sobrien    register Char *p;
335959243Sobrien    extern bool justpr;
336059243Sobrien
336159243Sobrien    USE(c);
336259243Sobrien    for (p = InputBuf; Isspace(*p); p++)
336359243Sobrien	continue;
336459243Sobrien    if (p == LastChar)
336559243Sobrien	return(CC_ERROR);
336659243Sobrien
336759243Sobrien    justpr++;
336859243Sobrien    Expand++;
336959243Sobrien    return(e_newline(0));
337059243Sobrien}
337159243Sobrien
337259243Sobrien/*ARGSUSED*/
337359243SobrienCCRETVAL
337459243Sobriene_startover(c)
337559243Sobrien    int c;
337659243Sobrien{				/* erase all of current line, start again */
337759243Sobrien    USE(c);
337859243Sobrien    ResetInLine(0);		/* reset the input pointers */
337959243Sobrien    return(CC_REFRESH);
338059243Sobrien}
338159243Sobrien
338259243Sobrien/*ARGSUSED*/
338359243SobrienCCRETVAL
338459243Sobriene_redisp(c)
338559243Sobrien    int c;
338659243Sobrien{
338759243Sobrien    USE(c);
338859243Sobrien    ClearLines();
338959243Sobrien    ClearDisp();
339059243Sobrien    return(CC_REFRESH);
339159243Sobrien}
339259243Sobrien
339359243Sobrien/*ARGSUSED*/
339459243SobrienCCRETVAL
339559243Sobriene_cleardisp(c)
339659243Sobrien    int c;
339759243Sobrien{
339859243Sobrien    USE(c);
339959243Sobrien    ClearScreen();		/* clear the whole real screen */
340059243Sobrien    ClearDisp();		/* reset everything */
340159243Sobrien    return(CC_REFRESH);
340259243Sobrien}
340359243Sobrien
340459243Sobrien/*ARGSUSED*/
340559243SobrienCCRETVAL
340659243Sobriene_tty_int(c)
340759243Sobrien    int c;
340859243Sobrien{
340959243Sobrien    USE(c);
341059243Sobrien#if defined(_MINIX) || defined(WINNT)
341159243Sobrien    /* SAK PATCH: erase all of current line, start again */
341259243Sobrien    ResetInLine(0);		/* reset the input pointers */
341359243Sobrien    xputchar('\n');
341459243Sobrien    ClearDisp();
341559243Sobrien    return (CC_REFRESH);
341659243Sobrien#else /* !_MINIX && !WINNT */
341759243Sobrien    /* do no editing */
341859243Sobrien    return (CC_NORM);
341959243Sobrien#endif /* _MINIX || WINNT */
342059243Sobrien}
342159243Sobrien
342259243Sobrien/*
342359243Sobrien * From: ghazi@cesl.rutgers.edu (Kaveh R. Ghazi)
342459243Sobrien * Function to send a character back to the input stream in cooked
342559243Sobrien * mode. Only works if we have TIOCSTI
342659243Sobrien */
342759243Sobrien/*ARGSUSED*/
342859243SobrienCCRETVAL
342959243Sobriene_stuff_char(c)
343059243Sobrien     int c;
343159243Sobrien{
343259243Sobrien#ifdef TIOCSTI
343359243Sobrien     extern int Tty_raw_mode;
343459243Sobrien     int was_raw = Tty_raw_mode;
343559243Sobrien     char ch = (char) c;
343659243Sobrien
343759243Sobrien     if (was_raw)
343859243Sobrien         (void) Cookedmode();
343959243Sobrien
344059243Sobrien     (void) write(SHIN, "\n", 1);
344159243Sobrien     (void) ioctl(SHIN, TIOCSTI, (ioctl_t) &ch);
344259243Sobrien
344359243Sobrien     if (was_raw)
344459243Sobrien         (void) Rawmode();
344559243Sobrien     return(e_redisp(c));
344659243Sobrien#else /* !TIOCSTI */
344759243Sobrien     return(CC_ERROR);
344859243Sobrien#endif /* !TIOCSTI */
344959243Sobrien}
345059243Sobrien
345159243Sobrien/*ARGSUSED*/
345259243SobrienCCRETVAL
345359243Sobriene_insovr(c)
345459243Sobrien    int c;
345559243Sobrien{
345659243Sobrien    USE(c);
345759243Sobrien    inputmode = (inputmode == MODE_INSERT ? MODE_REPLACE : MODE_INSERT);
345859243Sobrien    return(CC_NORM);
345959243Sobrien}
346059243Sobrien
346159243Sobrien/*ARGSUSED*/
346259243SobrienCCRETVAL
346359243Sobriene_tty_dsusp(c)
346459243Sobrien    int c;
346559243Sobrien{
346659243Sobrien    USE(c);
346759243Sobrien    /* do no editing */
346859243Sobrien    return(CC_NORM);
346959243Sobrien}
347059243Sobrien
347159243Sobrien/*ARGSUSED*/
347259243SobrienCCRETVAL
347359243Sobriene_tty_flusho(c)
347459243Sobrien    int c;
347559243Sobrien{
347659243Sobrien    USE(c);
347759243Sobrien    /* do no editing */
347859243Sobrien    return(CC_NORM);
347959243Sobrien}
348059243Sobrien
348159243Sobrien/*ARGSUSED*/
348259243SobrienCCRETVAL
348359243Sobriene_tty_quit(c)
348459243Sobrien    int c;
348559243Sobrien{
348659243Sobrien    USE(c);
348759243Sobrien    /* do no editing */
348859243Sobrien    return(CC_NORM);
348959243Sobrien}
349059243Sobrien
349159243Sobrien/*ARGSUSED*/
349259243SobrienCCRETVAL
349359243Sobriene_tty_tsusp(c)
349459243Sobrien    int c;
349559243Sobrien{
349659243Sobrien    USE(c);
349759243Sobrien    /* do no editing */
349859243Sobrien    return(CC_NORM);
349959243Sobrien}
350059243Sobrien
350159243Sobrien/*ARGSUSED*/
350259243SobrienCCRETVAL
350359243Sobriene_tty_stopo(c)
350459243Sobrien    int c;
350559243Sobrien{
350659243Sobrien    USE(c);
350759243Sobrien    /* do no editing */
350859243Sobrien    return(CC_NORM);
350959243Sobrien}
351059243Sobrien
351159243Sobrien/*ARGSUSED*/
351259243SobrienCCRETVAL
351359243Sobriene_expand_history(c)
351459243Sobrien    int c;
351559243Sobrien{
351659243Sobrien    USE(c);
351759243Sobrien    *LastChar = '\0';		/* just in case */
351859243Sobrien    c_substitute();
351959243Sobrien    return(CC_NORM);
352059243Sobrien}
352159243Sobrien
352259243Sobrien/*ARGSUSED*/
352359243SobrienCCRETVAL
352459243Sobriene_magic_space(c)
352559243Sobrien    int c;
352659243Sobrien{
352759243Sobrien    USE(c);
352859243Sobrien    *LastChar = '\0';		/* just in case */
352959243Sobrien    c_substitute();
353059243Sobrien    return(e_insert(' '));
353159243Sobrien}
353259243Sobrien
353359243Sobrien/*ARGSUSED*/
353459243SobrienCCRETVAL
353559243Sobriene_inc_fwd(c)
353659243Sobrien    int c;
353759243Sobrien{
353859243Sobrien    USE(c);
353959243Sobrien    patlen = 0;
354059243Sobrien    return e_inc_search(F_DOWN_SEARCH_HIST);
354159243Sobrien}
354259243Sobrien
354359243Sobrien
354459243Sobrien/*ARGSUSED*/
354559243SobrienCCRETVAL
354659243Sobriene_inc_back(c)
354759243Sobrien    int c;
354859243Sobrien{
354959243Sobrien    USE(c);
355059243Sobrien    patlen = 0;
355159243Sobrien    return e_inc_search(F_UP_SEARCH_HIST);
355259243Sobrien}
355359243Sobrien
355459243Sobrien/*ARGSUSED*/
355559243SobrienCCRETVAL
355659243Sobriene_copyprev(c)
355759243Sobrien    int c;
355859243Sobrien{
355959243Sobrien    register Char *cp, *oldc, *dp;
356059243Sobrien
356159243Sobrien    USE(c);
356259243Sobrien    if (Cursor == InputBuf)
356359243Sobrien	return(CC_ERROR);
356459243Sobrien    /* else */
356559243Sobrien
356659243Sobrien    oldc = Cursor;
356759243Sobrien    /* does a bounds check */
356859243Sobrien    cp = c_prev_word(Cursor, InputBuf, Argument);
356959243Sobrien
357059243Sobrien    c_insert((int)(oldc - cp));
357159243Sobrien    for (dp = oldc; cp < oldc && dp < LastChar; cp++)
357259243Sobrien	*dp++ = *cp;
357359243Sobrien
357459243Sobrien    Cursor = dp;		/* put cursor at end */
357559243Sobrien
357659243Sobrien    return(CC_REFRESH);
357759243Sobrien}
357859243Sobrien
357959243Sobrien/*ARGSUSED*/
358059243SobrienCCRETVAL
358159243Sobriene_tty_starto(c)
358259243Sobrien    int c;
358359243Sobrien{
358459243Sobrien    USE(c);
358559243Sobrien    /* do no editing */
358659243Sobrien    return(CC_NORM);
358759243Sobrien}
358859243Sobrien
358959243Sobrien/*ARGSUSED*/
359059243SobrienCCRETVAL
359159243Sobriene_load_average(c)
359259243Sobrien    int c;
359359243Sobrien{
359459243Sobrien    USE(c);
359559243Sobrien    PastBottom();
359659243Sobrien#ifdef TIOCSTAT
359759243Sobrien    /*
359859243Sobrien     * Here we pass &c to the ioctl because some os's (NetBSD) expect it
359959243Sobrien     * there even if they don't use it. (lukem@netbsd.org)
360059243Sobrien     */
360159243Sobrien    if (ioctl(SHIN, TIOCSTAT, (ioctl_t) &c) < 0)
360259243Sobrien#endif
360359243Sobrien	xprintf(CGETS(5, 1, "Load average unavailable\n"));
360459243Sobrien    return(CC_REFRESH);
360559243Sobrien}
360659243Sobrien
360759243Sobrien/*ARGSUSED*/
360859243SobrienCCRETVAL
360959243Sobrienv_chgmeta(c)
361059243Sobrien    int c;
361159243Sobrien{
361259243Sobrien    USE(c);
361359243Sobrien    /*
361459243Sobrien     * Delete with insert == change: first we delete and then we leave in
361559243Sobrien     * insert mode.
361659243Sobrien     */
361759243Sobrien    return(v_action(TCSHOP_DELETE|TCSHOP_INSERT));
361859243Sobrien}
361959243Sobrien
362059243Sobrien/*ARGSUSED*/
362159243SobrienCCRETVAL
362259243Sobrienv_delmeta(c)
362359243Sobrien    int c;
362459243Sobrien{
362559243Sobrien    USE(c);
362659243Sobrien    return(v_action(TCSHOP_DELETE));
362759243Sobrien}
362859243Sobrien
362959243Sobrien
363059243Sobrien/*ARGSUSED*/
363159243SobrienCCRETVAL
363259243Sobrienv_endword(c)
363359243Sobrien    int c;
363459243Sobrien{
363559243Sobrien    USE(c);
363659243Sobrien    if (Cursor == LastChar)
363759243Sobrien	return(CC_ERROR);
363859243Sobrien    /* else */
363959243Sobrien
364059243Sobrien    Cursor = c_endword(Cursor, LastChar, Argument);
364159243Sobrien
364259243Sobrien    if (ActionFlag & TCSHOP_DELETE)
364359243Sobrien    {
364459243Sobrien	Cursor++;
364559243Sobrien	c_delfini();
364659243Sobrien	return(CC_REFRESH);
364759243Sobrien    }
364859243Sobrien
364959243Sobrien    RefCursor();
365059243Sobrien    return(CC_NORM);
365159243Sobrien}
365259243Sobrien
365359243Sobrien/*ARGSUSED*/
365459243SobrienCCRETVAL
365559243Sobrienv_eword(c)
365659243Sobrien    int c;
365759243Sobrien{
365859243Sobrien    USE(c);
365959243Sobrien    if (Cursor == LastChar)
366059243Sobrien	return(CC_ERROR);
366159243Sobrien    /* else */
366259243Sobrien
366359243Sobrien    Cursor = c_eword(Cursor, LastChar, Argument);
366459243Sobrien
366559243Sobrien    if (ActionFlag & TCSHOP_DELETE) {
366659243Sobrien	Cursor++;
366759243Sobrien	c_delfini();
366859243Sobrien	return(CC_REFRESH);
366959243Sobrien    }
367059243Sobrien
367159243Sobrien    RefCursor();
367259243Sobrien    return(CC_NORM);
367359243Sobrien}
367459243Sobrien
367559243Sobrien/*ARGSUSED*/
367659243SobrienCCRETVAL
367759243Sobrienv_char_fwd(c)
367859243Sobrien    int c;
367959243Sobrien{
368059243Sobrien    Char ch;
368159243Sobrien
368259243Sobrien    USE(c);
368359243Sobrien    if (GetNextChar(&ch) != 1)
368459243Sobrien	return e_send_eof(0);
368559243Sobrien
368659243Sobrien    srch_dir = CHAR_FWD;
368759243Sobrien    srch_char = ch;
368859243Sobrien
368959243Sobrien    return v_csearch_fwd(ch, Argument, 0);
369059243Sobrien
369159243Sobrien}
369259243Sobrien
369359243Sobrien/*ARGSUSED*/
369459243SobrienCCRETVAL
369559243Sobrienv_char_back(c)
369659243Sobrien    int c;
369759243Sobrien{
369859243Sobrien    Char ch;
369959243Sobrien
370059243Sobrien    USE(c);
370159243Sobrien    if (GetNextChar(&ch) != 1)
370259243Sobrien	return e_send_eof(0);
370359243Sobrien
370459243Sobrien    srch_dir = CHAR_BACK;
370559243Sobrien    srch_char = ch;
370659243Sobrien
370759243Sobrien    return v_csearch_back(ch, Argument, 0);
370859243Sobrien}
370959243Sobrien
371059243Sobrien/*ARGSUSED*/
371159243SobrienCCRETVAL
371259243Sobrienv_charto_fwd(c)
371359243Sobrien    int c;
371459243Sobrien{
371559243Sobrien    Char ch;
371659243Sobrien
371759243Sobrien    USE(c);
371859243Sobrien    if (GetNextChar(&ch) != 1)
371959243Sobrien	return e_send_eof(0);
372059243Sobrien
372159243Sobrien    return v_csearch_fwd(ch, Argument, 1);
372259243Sobrien
372359243Sobrien}
372459243Sobrien
372559243Sobrien/*ARGSUSED*/
372659243SobrienCCRETVAL
372759243Sobrienv_charto_back(c)
372859243Sobrien    int c;
372959243Sobrien{
373059243Sobrien    Char ch;
373159243Sobrien
373259243Sobrien    USE(c);
373359243Sobrien    if (GetNextChar(&ch) != 1)
373459243Sobrien	return e_send_eof(0);
373559243Sobrien
373659243Sobrien    return v_csearch_back(ch, Argument, 1);
373759243Sobrien}
373859243Sobrien
373959243Sobrien/*ARGSUSED*/
374059243SobrienCCRETVAL
374159243Sobrienv_rchar_fwd(c)
374259243Sobrien    int c;
374359243Sobrien{
374459243Sobrien    USE(c);
374559243Sobrien    if (srch_char == 0)
374659243Sobrien	return CC_ERROR;
374759243Sobrien
374859243Sobrien    return srch_dir == CHAR_FWD ? v_csearch_fwd(srch_char, Argument, 0) :
374959243Sobrien			          v_csearch_back(srch_char, Argument, 0);
375059243Sobrien}
375159243Sobrien
375259243Sobrien/*ARGSUSED*/
375359243SobrienCCRETVAL
375459243Sobrienv_rchar_back(c)
375559243Sobrien    int c;
375659243Sobrien{
375759243Sobrien    USE(c);
375859243Sobrien    if (srch_char == 0)
375959243Sobrien	return CC_ERROR;
376059243Sobrien
376159243Sobrien    return srch_dir == CHAR_BACK ? v_csearch_fwd(srch_char, Argument, 0) :
376259243Sobrien			           v_csearch_back(srch_char, Argument, 0);
376359243Sobrien}
376459243Sobrien
376559243Sobrien/*ARGSUSED*/
376659243SobrienCCRETVAL
376759243Sobrienv_undo(c)
376859243Sobrien    int c;
376959243Sobrien{
377059243Sobrien    register int  loop;
377159243Sobrien    register Char *kp, *cp;
377259243Sobrien    Char temp;
377359243Sobrien    int	 size;
377459243Sobrien
377559243Sobrien    USE(c);
377659243Sobrien    switch (UndoAction) {
377759243Sobrien    case TCSHOP_DELETE|TCSHOP_INSERT:
377859243Sobrien    case TCSHOP_DELETE:
377959243Sobrien	if (UndoSize == 0) return(CC_NORM);
378059243Sobrien	cp = UndoPtr;
378159243Sobrien	kp = UndoBuf;
378259243Sobrien	for (loop=0; loop < UndoSize; loop++)	/* copy the chars */
378359243Sobrien	    *kp++ = *cp++;			/* into UndoBuf   */
378459243Sobrien
378559243Sobrien	for (cp = UndoPtr; cp <= LastChar; cp++)
378659243Sobrien	    *cp = cp[UndoSize];
378759243Sobrien
378859243Sobrien	LastChar -= UndoSize;
378959243Sobrien	Cursor   =  UndoPtr;
379059243Sobrien
379159243Sobrien	UndoAction = TCSHOP_INSERT;
379259243Sobrien	break;
379359243Sobrien
379459243Sobrien    case TCSHOP_INSERT:
379559243Sobrien	if (UndoSize == 0) return(CC_NORM);
379659243Sobrien	cp = UndoPtr;
379759243Sobrien	Cursor = UndoPtr;
379859243Sobrien	kp = UndoBuf;
379959243Sobrien	c_insert(UndoSize);		/* open the space, */
380059243Sobrien	for (loop = 0; loop < UndoSize; loop++)	/* copy the chars */
380159243Sobrien	    *cp++ = *kp++;
380259243Sobrien
380359243Sobrien	UndoAction = TCSHOP_DELETE;
380459243Sobrien	break;
380559243Sobrien
380659243Sobrien    case TCSHOP_CHANGE:
380759243Sobrien	if (UndoSize == 0) return(CC_NORM);
380859243Sobrien	cp = UndoPtr;
380959243Sobrien	Cursor = UndoPtr;
381059243Sobrien	kp = UndoBuf;
381159243Sobrien	size = (int)(Cursor-LastChar); /*  NOT NSL independant */
381259243Sobrien	if (size < UndoSize)
381359243Sobrien	    size = UndoSize;
381459243Sobrien	for(loop = 0; loop < size; loop++) {
381559243Sobrien	    temp = *kp;
381659243Sobrien	    *kp++ = *cp;
381759243Sobrien	    *cp++ = temp;
381859243Sobrien	}
381959243Sobrien	break;
382059243Sobrien
382159243Sobrien    default:
382259243Sobrien	return(CC_ERROR);
382359243Sobrien    }
382459243Sobrien
382559243Sobrien    return(CC_REFRESH);
382659243Sobrien}
382759243Sobrien
382859243Sobrien/*ARGSUSED*/
382959243SobrienCCRETVAL
383059243Sobrienv_ush_meta(c)
383159243Sobrien    int c;
383259243Sobrien{
383359243Sobrien    USE(c);
383459243Sobrien    return v_search(F_UP_SEARCH_HIST);
383559243Sobrien}
383659243Sobrien
383759243Sobrien/*ARGSUSED*/
383859243SobrienCCRETVAL
383959243Sobrienv_dsh_meta(c)
384059243Sobrien    int c;
384159243Sobrien{
384259243Sobrien    USE(c);
384359243Sobrien    return v_search(F_DOWN_SEARCH_HIST);
384459243Sobrien}
384559243Sobrien
384659243Sobrien/*ARGSUSED*/
384759243SobrienCCRETVAL
384859243Sobrienv_rsrch_fwd(c)
384959243Sobrien    int c;
385059243Sobrien{
385159243Sobrien    USE(c);
385259243Sobrien    if (patlen == 0) return(CC_ERROR);
385359243Sobrien    return(v_repeat_srch(searchdir));
385459243Sobrien}
385559243Sobrien
385659243Sobrien/*ARGSUSED*/
385759243SobrienCCRETVAL
385859243Sobrienv_rsrch_back(c)
385959243Sobrien    int c;
386059243Sobrien{
386159243Sobrien    USE(c);
386259243Sobrien    if (patlen == 0) return(CC_ERROR);
386359243Sobrien    return(v_repeat_srch(searchdir == F_UP_SEARCH_HIST ?
386459243Sobrien			 F_DOWN_SEARCH_HIST : F_UP_SEARCH_HIST));
386559243Sobrien}
386659243Sobrien
386759243Sobrien#ifndef WINNT
386859243Sobrien/* Since ed.defns.h  is generated from ed.defns.c, these empty
386959243Sobrien   functions will keep the F_NUM_FNS consistent
387059243Sobrien */
387159243SobrienCCRETVAL
387259243Sobriene_copy_to_clipboard(c)
387359243Sobrien    int c;
387459243Sobrien{
387559243Sobrien    USE(c);
387659243Sobrien    return CC_ERROR;
387759243Sobrien}
387859243Sobrien
387959243SobrienCCRETVAL
388059243Sobriene_paste_from_clipboard(c)
388159243Sobrien    int c;
388259243Sobrien{
388359243Sobrien    USE(c);
388459243Sobrien    return (CC_ERROR);
388559243Sobrien}
388659243Sobrien
388759243SobrienCCRETVAL
388859243Sobriene_dosify_next(c)
388959243Sobrien    int c;
389059243Sobrien{
389159243Sobrien    USE(c);
389259243Sobrien    return (CC_ERROR);
389359243Sobrien}
389459243SobrienCCRETVAL
389559243Sobriene_dosify_prev(c)
389659243Sobrien    int c;
389759243Sobrien{
389859243Sobrien    USE(c);
389959243Sobrien    return (CC_ERROR);
390059243Sobrien}
390159243Sobrien#else /* WINNT */
390259243Sobrien/*ARGSUSED*/
390359243SobrienCCRETVAL
390459243Sobriene_dosify_next(c)
390559243Sobrien    int c;
390659243Sobrien{
390759243Sobrien    register Char *cp, *p, *kp;
390859243Sobrien
390959243Sobrien    USE(c);
391059243Sobrien    if (Cursor == LastChar)
391159243Sobrien	return(CC_ERROR);
391259243Sobrien    /* else */
391359243Sobrien
391459243Sobrien	cp = Cursor;
391559243Sobrien	while(  cp < LastChar) {
391659243Sobrien		if ( (*cp & CHAR == ' ') && (cp[-1] & CHAR != '\\') )
391759243Sobrien			break;
391859243Sobrien		cp++;
391959243Sobrien	}
392059243Sobrien
392159243Sobrien    for (p = Cursor, kp = KillBuf; p < cp; p++)	{/* save the text */
392259243Sobrien	if ( ( *p & CHAR ) == '/') {
392359243Sobrien	    *kp++ = '\\';
392459243Sobrien	    *kp++ = '\\';
392559243Sobrien	}
392659243Sobrien	else
392759243Sobrien	    *kp++ = *p;
392859243Sobrien    }
392959243Sobrien    LastKill = kp;
393059243Sobrien
393159243Sobrien    c_delafter((int)(cp - Cursor));	/* delete after dot */
393259243Sobrien    if (Cursor > LastChar)
393359243Sobrien	Cursor = LastChar;	/* bounds check */
393459243Sobrien    return (e_yank_kill(c));
393559243Sobrien}
393659243Sobrien/*ARGSUSED*/
393759243SobrienCCRETVAL
393859243Sobriene_dosify_prev(c)
393959243Sobrien    int c;
394059243Sobrien{
394159243Sobrien    register Char *cp, *p, *kp;
394259243Sobrien
394359243Sobrien    USE(c);
394459243Sobrien    if (Cursor == InputBuf)
394559243Sobrien	return(CC_ERROR);
394659243Sobrien    /* else */
394759243Sobrien
394859243Sobrien    cp = Cursor-1;
394959243Sobrien    /* Skip trailing spaces */
395059243Sobrien    while ((cp > InputBuf) && ( (*cp & CHAR) == ' '))
395159243Sobrien    	cp--;
395259243Sobrien
395359243Sobrien    while (cp > InputBuf) {
395459243Sobrien	if ( ((*cp & CHAR) == ' ') && ((cp[-1] & CHAR) != '\\') )
395559243Sobrien	    break;
395659243Sobrien	cp--;
395759243Sobrien    }
395859243Sobrien
395959243Sobrien    for (p = cp, kp = KillBuf; p < Cursor; p++)	{/* save the text */
396059243Sobrien	if ( ( *p & CHAR ) == '/') {
396159243Sobrien	    *kp++ = '\\';
396259243Sobrien	    *kp++ = '\\';
396359243Sobrien	}
396459243Sobrien	else
396559243Sobrien	    *kp++ = *p;
396659243Sobrien    }
396759243Sobrien    LastKill = kp;
396859243Sobrien
396959243Sobrien    c_delbefore((int)(Cursor - cp));	/* delete before dot */
397059243Sobrien    Cursor = cp;
397159243Sobrien    if (Cursor < InputBuf)
397259243Sobrien	Cursor = InputBuf;	/* bounds check */
397359243Sobrien    return(e_yank_kill(c));
397459243Sobrien}
397559243Sobrien#endif /* !WINNT */
397659243Sobrien
397759243Sobrien#ifdef notdef
397859243Sobrienvoid
397959243SobrienMoveCursor(n)			/* move cursor + right - left char */
398059243Sobrien    int     n;
398159243Sobrien{
398259243Sobrien    Cursor = Cursor + n;
398359243Sobrien    if (Cursor < InputBuf)
398459243Sobrien	Cursor = InputBuf;
398559243Sobrien    if (Cursor > LastChar)
398659243Sobrien	Cursor = LastChar;
398759243Sobrien    return;
398859243Sobrien}
398959243Sobrien
399059243SobrienChar *
399159243SobrienGetCursor()
399259243Sobrien{
399359243Sobrien    return(Cursor);
399459243Sobrien}
399559243Sobrien
399659243Sobrienint
399759243SobrienPutCursor(p)
399859243Sobrien    Char   *p;
399959243Sobrien{
400059243Sobrien    if (p < InputBuf || p > LastChar)
400159243Sobrien	return 1;		/* Error */
400259243Sobrien    Cursor = p;
400359243Sobrien    return 0;
400459243Sobrien}
400559243Sobrien#endif
4006