2012-02-20 00:53:59 +00:00
|
|
|
/* $Header: /p/tcsh/cvsroot/tcsh/ed.chared.c,v 3.98 2010/05/08 00:37:39 christos Exp $ */
|
2000-04-15 04:41:27 +00:00
|
|
|
/*
|
|
|
|
* ed.chared.c: Character editing functions.
|
|
|
|
*/
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1980, 1991 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2002-07-24 16:23:10 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2000-04-15 04:41:27 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
Bjorn Knutsson @ Thu Jun 24 19:02:17 1999
|
|
|
|
|
|
|
|
e_dabbrev_expand() did not do proper completion if quoted spaces were present
|
|
|
|
in the string being completed. Exemple:
|
|
|
|
|
|
|
|
# echo hello\ world
|
|
|
|
hello world
|
|
|
|
# echo h<press key bound to dabbrev-expande>
|
|
|
|
# echo hello\<cursor>
|
|
|
|
|
|
|
|
Correct behavior is:
|
|
|
|
# echo h<press key bound to dabbrev-expande>
|
|
|
|
# echo hello\ world<cursor>
|
|
|
|
|
|
|
|
The same problem occured if spaces were present in a string withing quotation
|
|
|
|
marks. Example:
|
|
|
|
|
|
|
|
# echo "hello world"
|
|
|
|
hello world
|
|
|
|
# echo "h<press key bound to dabbrev-expande>
|
|
|
|
# echo "hello<cursor>
|
|
|
|
|
|
|
|
The former problem could be solved with minor modifications of c_preword()
|
|
|
|
and c_endword(). The latter, however, required a significant rewrite of
|
|
|
|
c_preword(), since quoted strings must be parsed from start to end to
|
|
|
|
determine if a given character is inside or outside the quotation marks.
|
|
|
|
|
|
|
|
Compare the following two strings:
|
|
|
|
|
|
|
|
# echo \"" 'foo \' bar\"
|
|
|
|
" 'foo \' bar\
|
|
|
|
# echo '\"" 'foo \' bar\"
|
|
|
|
\"" foo ' bar"
|
|
|
|
|
|
|
|
The only difference between the two echo lines is in the first character
|
|
|
|
after the echo command. The result is either one or three arguments.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sh.h"
|
|
|
|
|
2012-02-20 00:53:59 +00:00
|
|
|
RCSID("$tcsh: ed.chared.c,v 3.98 2010/05/08 00:37:39 christos Exp $")
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
#include "ed.h"
|
|
|
|
#include "tw.h"
|
|
|
|
#include "ed.defns.h"
|
|
|
|
|
|
|
|
/* #define SDEBUG */
|
|
|
|
|
|
|
|
#define TCSHOP_NOP 0x00
|
|
|
|
#define TCSHOP_DELETE 0x01
|
|
|
|
#define TCSHOP_INSERT 0x02
|
|
|
|
#define TCSHOP_CHANGE 0x04
|
|
|
|
|
|
|
|
#define CHAR_FWD 0
|
|
|
|
#define CHAR_BACK 1
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vi word treatment
|
|
|
|
* from: Gert-Jan Vons <vons@cesar.crbca1.sinet.slb.com>
|
|
|
|
*/
|
|
|
|
#define C_CLASS_WHITE 1
|
|
|
|
#define C_CLASS_ALNUM 2
|
|
|
|
#define C_CLASS_OTHER 3
|
|
|
|
|
|
|
|
static Char *InsertPos = InputBuf; /* Where insertion starts */
|
|
|
|
static Char *ActionPos = 0; /* Where action begins */
|
|
|
|
static int ActionFlag = TCSHOP_NOP; /* What delayed action to take */
|
|
|
|
/*
|
|
|
|
* Word search state
|
|
|
|
*/
|
|
|
|
static int searchdir = F_UP_SEARCH_HIST; /* Direction of last search */
|
2007-03-11 22:33:41 +00:00
|
|
|
static struct Strbuf patbuf; /* = Strbuf_INIT; Search target */
|
2000-04-15 04:41:27 +00:00
|
|
|
/*
|
|
|
|
* Char search state
|
|
|
|
*/
|
|
|
|
static int srch_dir = CHAR_FWD; /* Direction of last search */
|
|
|
|
static Char srch_char = 0; /* Search target */
|
|
|
|
|
|
|
|
/* all routines that start with c_ are private to this set of routines */
|
2007-03-11 22:33:41 +00:00
|
|
|
static void c_alternativ_key_map (int);
|
|
|
|
void c_insert (int);
|
|
|
|
void c_delafter (int);
|
|
|
|
void c_delbefore (int);
|
|
|
|
static int c_to_class (Char);
|
|
|
|
static Char *c_prev_word (Char *, Char *, int);
|
|
|
|
static Char *c_next_word (Char *, Char *, int);
|
|
|
|
static Char *c_number (Char *, int *, int);
|
|
|
|
static Char *c_expand (Char *);
|
2009-07-10 21:47:20 +00:00
|
|
|
static int c_excl (Char *);
|
|
|
|
static int c_substitute (void);
|
2007-03-11 22:33:41 +00:00
|
|
|
static void c_delfini (void);
|
|
|
|
static int c_hmatch (Char *);
|
|
|
|
static void c_hsetpat (void);
|
2000-04-15 04:41:27 +00:00
|
|
|
#ifdef COMMENT
|
2007-03-11 22:33:41 +00:00
|
|
|
static void c_get_word (Char **, Char **);
|
2000-04-15 04:41:27 +00:00
|
|
|
#endif
|
2007-03-11 22:33:41 +00:00
|
|
|
static Char *c_preword (Char *, Char *, int, Char *);
|
|
|
|
static Char *c_nexword (Char *, Char *, int);
|
|
|
|
static Char *c_endword (Char *, Char *, int, Char *);
|
|
|
|
static Char *c_eword (Char *, Char *, int);
|
|
|
|
static void c_push_kill (Char *, Char *);
|
|
|
|
static void c_save_inputbuf (void);
|
|
|
|
static CCRETVAL c_search_line (Char *, int);
|
|
|
|
static CCRETVAL v_repeat_srch (int);
|
|
|
|
static CCRETVAL e_inc_search (int);
|
|
|
|
#ifdef notyet
|
|
|
|
static CCRETVAL e_insert_str (Char *);
|
|
|
|
#endif
|
|
|
|
static CCRETVAL v_search (int);
|
|
|
|
static CCRETVAL v_csearch_fwd (Char, int, int);
|
|
|
|
static CCRETVAL v_action (int);
|
|
|
|
static CCRETVAL v_csearch_back (Char, int, int);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
c_alternativ_key_map(int state)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case 0:
|
|
|
|
CurrentKeyMap = CcKeyMap;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
CurrentKeyMap = CcAltMap;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AltKeyMap = (Char) state;
|
|
|
|
}
|
|
|
|
|
2001-09-05 17:49:32 +00:00
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
c_insert(int num)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *cp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (LastChar + num >= InputLim)
|
|
|
|
return; /* can't go past end of buffer */
|
|
|
|
|
|
|
|
if (Cursor < LastChar) { /* if I must move chars */
|
|
|
|
for (cp = LastChar; cp >= Cursor; cp--)
|
|
|
|
cp[num] = *cp;
|
2005-04-24 19:41:08 +00:00
|
|
|
if (Mark && Mark > Cursor)
|
|
|
|
Mark += num;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
LastChar += num;
|
|
|
|
}
|
|
|
|
|
2000-11-30 21:05:33 +00:00
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
c_delafter(int num)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *cp, *kp = NULL;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (num > LastChar - Cursor)
|
|
|
|
num = (int) (LastChar - Cursor); /* bounds check */
|
|
|
|
|
|
|
|
if (num > 0) { /* if I can delete anything */
|
|
|
|
if (VImode) {
|
|
|
|
kp = UndoBuf; /* Set Up for VI undo command */
|
|
|
|
UndoAction = TCSHOP_INSERT;
|
|
|
|
UndoSize = num;
|
|
|
|
UndoPtr = Cursor;
|
|
|
|
for (cp = Cursor; cp <= LastChar; cp++) {
|
|
|
|
*kp++ = *cp; /* Save deleted chars into undobuf */
|
|
|
|
*cp = cp[num];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2005-04-24 19:41:08 +00:00
|
|
|
for (cp = Cursor; cp + num <= LastChar; cp++)
|
2000-04-15 04:41:27 +00:00
|
|
|
*cp = cp[num];
|
|
|
|
LastChar -= num;
|
2007-03-11 22:33:41 +00:00
|
|
|
/* Mark was within the range of the deleted word? */
|
|
|
|
if (Mark && Mark > Cursor && Mark <= Cursor+num)
|
|
|
|
Mark = Cursor;
|
|
|
|
/* Mark after the deleted word? */
|
|
|
|
else if (Mark && Mark > Cursor)
|
2005-04-24 19:41:08 +00:00
|
|
|
Mark -= num;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
#ifdef notdef
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* XXX: We don't want to do that. In emacs mode overwrite should be
|
|
|
|
* sticky. I am not sure how that affects vi mode
|
|
|
|
*/
|
|
|
|
inputmode = MODE_INSERT;
|
|
|
|
}
|
|
|
|
#endif /* notdef */
|
|
|
|
}
|
|
|
|
|
2000-11-30 21:05:33 +00:00
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
c_delbefore(int num) /* delete before dot, with bounds checking */
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *cp, *kp = NULL;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (num > Cursor - InputBuf)
|
|
|
|
num = (int) (Cursor - InputBuf); /* bounds check */
|
|
|
|
|
|
|
|
if (num > 0) { /* if I can delete anything */
|
|
|
|
if (VImode) {
|
|
|
|
kp = UndoBuf; /* Set Up for VI undo command */
|
|
|
|
UndoAction = TCSHOP_INSERT;
|
|
|
|
UndoSize = num;
|
|
|
|
UndoPtr = Cursor - num;
|
|
|
|
for (cp = Cursor - num; cp <= LastChar; cp++) {
|
|
|
|
*kp++ = *cp;
|
|
|
|
*cp = cp[num];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2005-04-24 19:41:08 +00:00
|
|
|
for (cp = Cursor - num; cp + num <= LastChar; cp++)
|
2000-04-15 04:41:27 +00:00
|
|
|
*cp = cp[num];
|
|
|
|
LastChar -= num;
|
2005-04-24 19:41:08 +00:00
|
|
|
Cursor -= num;
|
2007-03-11 22:33:41 +00:00
|
|
|
/* Mark was within the range of the deleted word? */
|
|
|
|
if (Mark && Mark > Cursor && Mark <= Cursor+num)
|
|
|
|
Mark = Cursor;
|
|
|
|
/* Mark after the deleted word? */
|
|
|
|
else if (Mark && Mark > Cursor)
|
2005-04-24 19:41:08 +00:00
|
|
|
Mark -= num;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
c_preword(Char *p, Char *low, int n, Char *delim)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
while (n--) {
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *prev = low;
|
|
|
|
Char *new;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
2001-09-05 17:49:32 +00:00
|
|
|
while (prev < p) { /* Skip initial non-word chars */
|
|
|
|
if (!Strchr(delim, *prev) || *(prev-1) == (Char)'\\')
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
prev++;
|
|
|
|
}
|
|
|
|
|
|
|
|
new = prev;
|
|
|
|
|
|
|
|
while (new < p) {
|
|
|
|
prev = new;
|
2001-09-05 17:49:32 +00:00
|
|
|
new = c_endword(prev-1, p, 1, delim); /* Skip to next non-word char */
|
2000-04-15 04:41:27 +00:00
|
|
|
new++; /* Step away from end of word */
|
2001-09-05 17:49:32 +00:00
|
|
|
while (new <= p) { /* Skip trailing non-word chars */
|
|
|
|
if (!Strchr(delim, *new) || *(new-1) == (Char)'\\')
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
new++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = prev; /* Set to previous word start */
|
|
|
|
|
|
|
|
}
|
|
|
|
if (p < low)
|
|
|
|
p = low;
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* c_to_class() returns the class of the given character.
|
|
|
|
*
|
|
|
|
* This is used to make the c_prev_word() and c_next_word() functions
|
|
|
|
* work like vi's, which classify characters. A word is a sequence of
|
|
|
|
* characters belonging to the same class, classes being defined as
|
|
|
|
* follows:
|
|
|
|
*
|
|
|
|
* 1/ whitespace
|
|
|
|
* 2/ alphanumeric chars, + underscore
|
|
|
|
* 3/ others
|
|
|
|
*/
|
|
|
|
static int
|
2007-03-11 22:33:41 +00:00
|
|
|
c_to_class(Char ch)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
if (Isspace(ch))
|
|
|
|
return C_CLASS_WHITE;
|
|
|
|
|
|
|
|
if (Isdigit(ch) || Isalpha(ch) || ch == '_')
|
|
|
|
return C_CLASS_ALNUM;
|
|
|
|
|
|
|
|
return C_CLASS_OTHER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
c_prev_word(Char *p, Char *low, int n)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
p--;
|
|
|
|
|
|
|
|
if (!VImode) {
|
|
|
|
while (n--) {
|
|
|
|
while ((p >= low) && !isword(*p))
|
|
|
|
p--;
|
|
|
|
while ((p >= low) && isword(*p))
|
|
|
|
p--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cp now points to one character before the word */
|
|
|
|
p++;
|
|
|
|
if (p < low)
|
|
|
|
p = low;
|
|
|
|
/* cp now points where we want it */
|
|
|
|
return(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (n--) {
|
2001-09-05 17:49:32 +00:00
|
|
|
int c_class;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (p < low)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* scan until beginning of current word (may be all whitespace!) */
|
|
|
|
c_class = c_to_class(*p);
|
|
|
|
while ((p >= low) && c_class == c_to_class(*p))
|
|
|
|
p--;
|
|
|
|
|
|
|
|
/* if this was a non_whitespace word, we're ready */
|
|
|
|
if (c_class != C_CLASS_WHITE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* otherwise, move back to beginning of the word just found */
|
|
|
|
c_class = c_to_class(*p);
|
|
|
|
while ((p >= low) && c_class == c_to_class(*p))
|
|
|
|
p--;
|
|
|
|
}
|
|
|
|
|
|
|
|
p++; /* correct overshoot */
|
|
|
|
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
c_next_word(Char *p, Char *high, int n)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
if (!VImode) {
|
|
|
|
while (n--) {
|
|
|
|
while ((p < high) && !isword(*p))
|
|
|
|
p++;
|
|
|
|
while ((p < high) && isword(*p))
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if (p > high)
|
|
|
|
p = high;
|
|
|
|
/* p now points where we want it */
|
|
|
|
return(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (n--) {
|
2001-09-05 17:49:32 +00:00
|
|
|
int c_class;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (p >= high)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* scan until end of current word (may be all whitespace!) */
|
|
|
|
c_class = c_to_class(*p);
|
|
|
|
while ((p < high) && c_class == c_to_class(*p))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
/* if this was all whitespace, we're ready */
|
|
|
|
if (c_class == C_CLASS_WHITE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* if we've found white-space at the end of the word, skip it */
|
|
|
|
while ((p < high) && c_to_class(*p) == C_CLASS_WHITE)
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
p--; /* correct overshoot */
|
|
|
|
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
c_nexword(Char *p, Char *high, int n)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
while (n--) {
|
|
|
|
while ((p < high) && !Isspace(*p))
|
|
|
|
p++;
|
|
|
|
while ((p < high) && Isspace(*p))
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p > high)
|
|
|
|
p = high;
|
|
|
|
/* p now points where we want it */
|
|
|
|
return(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Expand-History (originally "Magic-Space") code added by
|
|
|
|
* Ray Moody <ray@gibbs.physics.purdue.edu>
|
|
|
|
* this is a neat, but odd, addition.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* c_number: Ignore character p points to, return number appearing after that.
|
|
|
|
* A '$' by itself means a big number; "$-" is for negative; '^' means 1.
|
|
|
|
* Return p pointing to last char used.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dval is the number to subtract from for things like $-3
|
|
|
|
*/
|
|
|
|
|
|
|
|
static Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
c_number(Char *p, int *num, int dval)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
int i;
|
|
|
|
int sign = 1;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (*++p == '^') {
|
|
|
|
*num = 1;
|
|
|
|
return(p);
|
|
|
|
}
|
|
|
|
if (*p == '$') {
|
|
|
|
if (*++p != '-') {
|
2007-03-11 22:33:41 +00:00
|
|
|
*num = INT_MAX; /* Handle $ */
|
2000-04-15 04:41:27 +00:00
|
|
|
return(--p);
|
|
|
|
}
|
|
|
|
sign = -1; /* Handle $- */
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
for (i = 0; *p >= '0' && *p <= '9'; i = 10 * i + *p++ - '0')
|
|
|
|
continue;
|
|
|
|
*num = (sign < 0 ? dval - i : i);
|
|
|
|
return(--p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* excl_expand: There is an excl to be expanded to p -- do the right thing
|
|
|
|
* with it and return a version of p advanced over the expanded stuff. Also,
|
|
|
|
* update tsh_cur and related things as appropriate...
|
|
|
|
*/
|
|
|
|
|
|
|
|
static Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
c_expand(Char *p)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *q;
|
|
|
|
struct Hist *h = Histlist.Hnext;
|
|
|
|
struct wordent *l;
|
2000-04-15 04:41:27 +00:00
|
|
|
int i, from, to, dval;
|
2005-04-24 19:41:08 +00:00
|
|
|
int all_dig;
|
|
|
|
int been_once = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
Char *op = p;
|
2007-03-11 22:33:41 +00:00
|
|
|
Char *buf;
|
|
|
|
size_t buf_len;
|
|
|
|
Char *modbuf;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
buf = NULL;
|
2000-04-15 04:41:27 +00:00
|
|
|
if (!h)
|
|
|
|
goto excl_err;
|
|
|
|
excl_sw:
|
|
|
|
switch (*(q = p + 1)) {
|
|
|
|
|
|
|
|
case '^':
|
2007-03-11 22:33:41 +00:00
|
|
|
buf = expand_lex(&h->Hlex, 1, 1);
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '$':
|
|
|
|
if ((l = (h->Hlex).prev) != 0)
|
2007-03-11 22:33:41 +00:00
|
|
|
buf = expand_lex(l->prev->prev, 0, 0);
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '*':
|
2007-03-11 22:33:41 +00:00
|
|
|
buf = expand_lex(&h->Hlex, 1, INT_MAX);
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (been_once) { /* unknown argument */
|
|
|
|
/* assume it's a modifier, e.g. !foo:h, and get whole cmd */
|
2007-03-11 22:33:41 +00:00
|
|
|
buf = expand_lex(&h->Hlex, 0, INT_MAX);
|
2000-04-15 04:41:27 +00:00
|
|
|
q -= 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
been_once = 1;
|
|
|
|
|
|
|
|
if (*q == ':') /* short form: !:arg */
|
|
|
|
--q;
|
|
|
|
|
2012-02-20 00:53:59 +00:00
|
|
|
if (HIST != '\0' && *q != HIST) {
|
2000-04-15 04:41:27 +00:00
|
|
|
/*
|
|
|
|
* Search for a space, tab, or colon. See if we have a number (as
|
|
|
|
* in !1234:xyz). Remember the number.
|
|
|
|
*/
|
|
|
|
for (i = 0, all_dig = 1;
|
|
|
|
*q != ' ' && *q != '\t' && *q != ':' && q < Cursor; q++) {
|
|
|
|
/*
|
|
|
|
* PWP: !-4 is a valid history argument too, therefore the test
|
|
|
|
* is if not a digit, or not a - as the first character.
|
|
|
|
*/
|
|
|
|
if ((*q < '0' || *q > '9') && (*q != '-' || q != p + 1))
|
|
|
|
all_dig = 0;
|
|
|
|
else if (*q == '-')
|
|
|
|
all_dig = 2;/* we are sneeky about this */
|
|
|
|
else
|
|
|
|
i = 10 * i + *q - '0';
|
|
|
|
}
|
|
|
|
--q;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have a number, search for event i. Otherwise, search for
|
|
|
|
* a named event (as in !foo). (In this case, I is the length of
|
|
|
|
* the named event).
|
|
|
|
*/
|
|
|
|
if (all_dig) {
|
|
|
|
if (all_dig == 2)
|
|
|
|
i = -i; /* make it negitive */
|
|
|
|
if (i < 0) /* if !-4 (for example) */
|
|
|
|
i = eventno + 1 + i; /* remember: i is < 0 */
|
|
|
|
for (; h; h = h->Hnext) {
|
|
|
|
if (h->Hnum == i)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i = (int) (q - p); h; h = h->Hnext) {
|
|
|
|
if ((l = &h->Hlex) != 0) {
|
|
|
|
if (!Strncmp(p + 1, l->next->word, (size_t) i))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!h)
|
|
|
|
goto excl_err;
|
|
|
|
if (q[1] == ':' || q[1] == '-' || q[1] == '*' ||
|
|
|
|
q[1] == '$' || q[1] == '^') { /* get some args */
|
|
|
|
p = q[1] == ':' ? ++q : q;
|
|
|
|
/*
|
|
|
|
* Go handle !foo:*
|
|
|
|
*/
|
|
|
|
if ((q[1] < '0' || q[1] > '9') &&
|
|
|
|
q[1] != '-' && q[1] != '$' && q[1] != '^')
|
|
|
|
goto excl_sw;
|
|
|
|
/*
|
|
|
|
* Go handle !foo:$
|
|
|
|
*/
|
|
|
|
if (q[1] == '$' && (q[2] != '-' || q[3] < '0' || q[3] > '9'))
|
|
|
|
goto excl_sw;
|
|
|
|
/*
|
|
|
|
* Count up the number of words in this event. Store it in dval.
|
|
|
|
* Dval will be fed to number.
|
|
|
|
*/
|
|
|
|
dval = 0;
|
|
|
|
if ((l = h->Hlex.prev) != 0) {
|
|
|
|
for (l = l->prev; l != h->Hlex.next; l = l->prev, dval++)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!dval)
|
|
|
|
goto excl_err;
|
|
|
|
if (q[1] == '-')
|
|
|
|
from = 0;
|
|
|
|
else
|
|
|
|
q = c_number(q, &from, dval);
|
|
|
|
if (q[1] == '-') {
|
|
|
|
++q;
|
|
|
|
if ((q[1] < '0' || q[1] > '9') && q[1] != '$')
|
|
|
|
to = dval - 1;
|
|
|
|
else
|
|
|
|
q = c_number(q, &to, dval);
|
|
|
|
}
|
|
|
|
else if (q[1] == '*') {
|
|
|
|
++q;
|
2007-03-11 22:33:41 +00:00
|
|
|
to = INT_MAX;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
to = from;
|
|
|
|
}
|
|
|
|
if (from < 0 || to < from)
|
|
|
|
goto excl_err;
|
2007-03-11 22:33:41 +00:00
|
|
|
buf = expand_lex(&h->Hlex, from, to);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
else /* get whole cmd */
|
|
|
|
buf = expand_lex(&h->Hlex, 0, INT_MAX);
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
buf = SAVE("");
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Apply modifiers, if any.
|
|
|
|
*/
|
|
|
|
if (q[1] == ':') {
|
2007-03-11 22:33:41 +00:00
|
|
|
modbuf = buf;
|
2000-04-15 04:41:27 +00:00
|
|
|
while (q[1] == ':' && modbuf != NULL) {
|
|
|
|
switch (q[2]) {
|
|
|
|
case 'r':
|
|
|
|
case 'e':
|
|
|
|
case 'h':
|
|
|
|
case 't':
|
|
|
|
case 'q':
|
|
|
|
case 'x':
|
|
|
|
case 'u':
|
|
|
|
case 'l':
|
2007-03-11 22:33:41 +00:00
|
|
|
if ((modbuf = domod(buf, (int) q[2])) != NULL) {
|
|
|
|
xfree(buf);
|
|
|
|
buf = modbuf;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
++q;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'a':
|
|
|
|
case 'g':
|
|
|
|
/* Not implemented; this needs to be done before expanding
|
|
|
|
* lex. We don't have the words available to us anymore.
|
|
|
|
*/
|
|
|
|
++q;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
/* Ok */
|
|
|
|
++q;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\0':
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
++q;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (q[1])
|
|
|
|
++q;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
buf_len = Strlen(buf);
|
2000-04-15 04:41:27 +00:00
|
|
|
/*
|
2007-03-11 22:33:41 +00:00
|
|
|
* Now replace the text from op to q inclusive with the text from buf.
|
2000-04-15 04:41:27 +00:00
|
|
|
*/
|
|
|
|
q++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now replace text non-inclusively like a real CS major!
|
|
|
|
*/
|
2007-03-11 22:33:41 +00:00
|
|
|
if (LastChar + buf_len - (q - op) >= InputLim)
|
2000-04-15 04:41:27 +00:00
|
|
|
goto excl_err;
|
2007-03-11 22:33:41 +00:00
|
|
|
(void) memmove(op + buf_len, q, (LastChar - q) * sizeof(Char));
|
|
|
|
LastChar += buf_len - (q - op);
|
|
|
|
Cursor += buf_len - (q - op);
|
|
|
|
(void) memcpy(op, buf, buf_len * sizeof(Char));
|
2000-04-15 04:41:27 +00:00
|
|
|
*LastChar = '\0';
|
2007-03-11 22:33:41 +00:00
|
|
|
xfree(buf);
|
|
|
|
return op + buf_len;
|
2000-04-15 04:41:27 +00:00
|
|
|
excl_err:
|
2007-03-11 22:33:41 +00:00
|
|
|
xfree(buf);
|
2000-04-15 04:41:27 +00:00
|
|
|
SoundBeep();
|
|
|
|
return(op + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* c_excl: An excl has been found at point p -- back up and find some white
|
|
|
|
* space (or the beginning of the buffer) and properly expand all the excl's
|
|
|
|
* from there up to the current cursor position. We also avoid (trying to)
|
|
|
|
* expanding '>!'
|
2009-07-10 21:47:20 +00:00
|
|
|
* Returns number of expansions attempted (doesn't matter whether they succeeded
|
|
|
|
* or not).
|
2000-04-15 04:41:27 +00:00
|
|
|
*/
|
|
|
|
|
2009-07-10 21:47:20 +00:00
|
|
|
static int
|
2007-03-11 22:33:41 +00:00
|
|
|
c_excl(Char *p)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
int i;
|
|
|
|
Char *q;
|
2009-07-10 21:47:20 +00:00
|
|
|
int nr_exp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if />[SPC TAB]*![SPC TAB]/, back up p to just after the >. otherwise,
|
|
|
|
* back p up to just before the current word.
|
|
|
|
*/
|
|
|
|
if ((p[1] == ' ' || p[1] == '\t') &&
|
|
|
|
(p[-1] == ' ' || p[-1] == '\t' || p[-1] == '>')) {
|
|
|
|
for (q = p - 1; q > InputBuf && (*q == ' ' || *q == '\t'); --q)
|
|
|
|
continue;
|
|
|
|
if (*q == '>')
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (*p != ' ' && *p != '\t' && p > InputBuf)
|
|
|
|
--p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Forever: Look for history char. (Stop looking when we find the cursor.)
|
2009-07-10 21:47:20 +00:00
|
|
|
* Count backslashes. If odd, skip history char. Expand if even number of
|
|
|
|
* backslashes.
|
2000-04-15 04:41:27 +00:00
|
|
|
*/
|
2009-07-10 21:47:20 +00:00
|
|
|
nr_exp = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
for (;;) {
|
2012-02-20 00:53:59 +00:00
|
|
|
if (HIST != '\0')
|
|
|
|
while (*p != HIST && p < Cursor)
|
|
|
|
++p;
|
2000-04-15 04:41:27 +00:00
|
|
|
for (i = 1; (p - i) >= InputBuf && p[-i] == '\\'; i++)
|
|
|
|
continue;
|
|
|
|
if (i % 2 == 0)
|
|
|
|
++p;
|
2009-07-10 21:47:20 +00:00
|
|
|
if (p >= Cursor) /* all done */
|
|
|
|
return nr_exp;
|
|
|
|
if (i % 2 == 1) {
|
2000-04-15 04:41:27 +00:00
|
|
|
p = c_expand(p);
|
2009-07-10 21:47:20 +00:00
|
|
|
++nr_exp;
|
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-10 21:47:20 +00:00
|
|
|
static int
|
2007-03-11 22:33:41 +00:00
|
|
|
c_substitute(void)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *p;
|
2009-07-10 21:47:20 +00:00
|
|
|
int nr_exp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start p out one character before the cursor. Move it backwards looking
|
|
|
|
* for white space, the beginning of the line, or a history character.
|
|
|
|
*/
|
|
|
|
for (p = Cursor - 1;
|
2012-02-20 00:53:59 +00:00
|
|
|
p > InputBuf && *p != ' ' && *p != '\t' && *p && *p != HIST; --p)
|
2000-04-15 04:41:27 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we found a history character, go expand it.
|
|
|
|
*/
|
2012-02-20 00:53:59 +00:00
|
|
|
if (HIST != '\0' && *p == HIST)
|
2009-07-10 21:47:20 +00:00
|
|
|
nr_exp = c_excl(p);
|
|
|
|
else
|
|
|
|
nr_exp = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
Refresh();
|
2009-07-10 21:47:20 +00:00
|
|
|
|
|
|
|
return nr_exp;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
c_delfini(void) /* Finish up delete action */
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
int Size;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (ActionFlag & TCSHOP_INSERT)
|
|
|
|
c_alternativ_key_map(0);
|
|
|
|
|
|
|
|
ActionFlag = TCSHOP_NOP;
|
|
|
|
|
|
|
|
if (ActionPos == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
UndoAction = TCSHOP_INSERT;
|
|
|
|
|
|
|
|
if (Cursor > ActionPos) {
|
|
|
|
Size = (int) (Cursor-ActionPos);
|
|
|
|
c_delbefore(Size);
|
|
|
|
RefCursor();
|
|
|
|
}
|
|
|
|
else if (Cursor < ActionPos) {
|
|
|
|
Size = (int)(ActionPos-Cursor);
|
|
|
|
c_delafter(Size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Size = 1;
|
|
|
|
c_delafter(Size);
|
|
|
|
}
|
|
|
|
UndoPtr = Cursor;
|
|
|
|
UndoSize = Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
c_endword(Char *p, Char *high, int n, Char *delim)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
Char inquote = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
p++;
|
|
|
|
|
|
|
|
while (n--) {
|
2001-09-05 17:49:32 +00:00
|
|
|
while (p < high) { /* Skip non-word chars */
|
|
|
|
if (!Strchr(delim, *p) || *(p-1) == (Char)'\\')
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
while (p < high) { /* Skip string */
|
|
|
|
if ((*p == (Char)'\'' || *p == (Char)'"')) { /* Quotation marks? */
|
2001-09-05 17:49:32 +00:00
|
|
|
if (inquote || *(p-1) != (Char)'\\') { /* Should it be honored? */
|
2000-04-15 04:41:27 +00:00
|
|
|
if (inquote == 0) inquote = *p;
|
|
|
|
else if (inquote == *p) inquote = 0;
|
|
|
|
}
|
|
|
|
}
|
2001-09-05 17:49:32 +00:00
|
|
|
/* Break if unquoted non-word char */
|
|
|
|
if (!inquote && Strchr(delim, *p) && *(p-1) != (Char)'\\')
|
2000-04-15 04:41:27 +00:00
|
|
|
break;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p--;
|
|
|
|
return(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
c_eword(Char *p, Char *high, int n)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
p++;
|
|
|
|
|
|
|
|
while (n--) {
|
|
|
|
while ((p < high) && Isspace(*p))
|
|
|
|
p++;
|
|
|
|
|
2012-02-20 00:53:59 +00:00
|
|
|
if (isword(*p))
|
|
|
|
while ((p < high) && isword(*p))
|
2000-04-15 04:41:27 +00:00
|
|
|
p++;
|
|
|
|
else
|
2012-02-20 00:53:59 +00:00
|
|
|
while ((p < high) && !(Isspace(*p) || isword(*p)))
|
2000-04-15 04:41:27 +00:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
p--;
|
|
|
|
return(p);
|
|
|
|
}
|
|
|
|
|
2001-09-05 17:49:32 +00:00
|
|
|
/* Set the max length of the kill ring */
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
SetKillRing(int max)
|
2001-09-05 17:49:32 +00:00
|
|
|
{
|
|
|
|
CStr *new;
|
|
|
|
int count, i, j;
|
|
|
|
|
|
|
|
if (max < 1)
|
|
|
|
max = 1; /* no ring, but always one buffer */
|
|
|
|
if (max == KillRingMax)
|
|
|
|
return;
|
2007-03-11 22:33:41 +00:00
|
|
|
new = xcalloc(max, sizeof(CStr));
|
2001-09-05 17:49:32 +00:00
|
|
|
if (KillRing != NULL) {
|
|
|
|
if (KillRingLen != 0) {
|
|
|
|
if (max >= KillRingLen) {
|
|
|
|
count = KillRingLen;
|
|
|
|
j = KillPos;
|
|
|
|
} else {
|
|
|
|
count = max;
|
|
|
|
j = (KillPos - count + KillRingLen) % KillRingLen;
|
|
|
|
}
|
|
|
|
for (i = 0; i < KillRingLen; i++) {
|
|
|
|
if (i < count) /* copy latest */
|
|
|
|
new[i] = KillRing[j];
|
|
|
|
else /* free the others */
|
|
|
|
xfree(KillRing[j].buf);
|
|
|
|
j = (j + 1) % KillRingLen;
|
|
|
|
}
|
|
|
|
KillRingLen = count;
|
|
|
|
KillPos = count % max;
|
|
|
|
YankPos = count - 1;
|
|
|
|
}
|
|
|
|
xfree(KillRing);
|
|
|
|
}
|
|
|
|
KillRing = new;
|
|
|
|
KillRingMax = max;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Push string from start upto (but not including) end onto kill ring */
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
c_push_kill(Char *start, Char *end)
|
2001-09-05 17:49:32 +00:00
|
|
|
{
|
|
|
|
CStr save, *pos;
|
|
|
|
Char *dp, *cp, *kp;
|
|
|
|
int len = end - start, i, j, k;
|
|
|
|
|
|
|
|
/* Check for duplicates? */
|
|
|
|
if (KillRingLen > 0 && (dp = varval(STRkilldup)) != STRNULL) {
|
|
|
|
YankPos = (KillPos - 1 + KillRingLen) % KillRingLen;
|
|
|
|
if (eq(dp, STRerase)) { /* erase earlier one (actually move up) */
|
|
|
|
j = YankPos;
|
|
|
|
for (i = 0; i < KillRingLen; i++) {
|
|
|
|
if (Strncmp(KillRing[j].buf, start, (size_t) len) == 0 &&
|
|
|
|
KillRing[j].buf[len] == '\0') {
|
|
|
|
save = KillRing[j];
|
|
|
|
for ( ; i > 0; i--) {
|
|
|
|
k = j;
|
|
|
|
j = (j + 1) % KillRingLen;
|
|
|
|
KillRing[k] = KillRing[j];
|
|
|
|
}
|
|
|
|
KillRing[j] = save;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
j = (j - 1 + KillRingLen) % KillRingLen;
|
|
|
|
}
|
|
|
|
} else if (eq(dp, STRall)) { /* skip if any earlier */
|
|
|
|
for (i = 0; i < KillRingLen; i++)
|
|
|
|
if (Strncmp(KillRing[i].buf, start, (size_t) len) == 0 &&
|
|
|
|
KillRing[i].buf[len] == '\0')
|
|
|
|
return;
|
|
|
|
} else if (eq(dp, STRprev)) { /* skip if immediately previous */
|
|
|
|
j = YankPos;
|
|
|
|
if (Strncmp(KillRing[j].buf, start, (size_t) len) == 0 &&
|
|
|
|
KillRing[j].buf[len] == '\0')
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No duplicate, go ahead and push */
|
|
|
|
len++; /* need space for '\0' */
|
|
|
|
YankPos = KillPos;
|
|
|
|
if (KillRingLen < KillRingMax)
|
|
|
|
KillRingLen++;
|
|
|
|
pos = &KillRing[KillPos];
|
|
|
|
KillPos = (KillPos + 1) % KillRingMax;
|
|
|
|
if (pos->len < len) {
|
2007-03-11 22:33:41 +00:00
|
|
|
pos->buf = xrealloc(pos->buf, len * sizeof(Char));
|
2001-09-05 17:49:32 +00:00
|
|
|
pos->len = len;
|
|
|
|
}
|
|
|
|
cp = start;
|
|
|
|
kp = pos->buf;
|
|
|
|
while (cp < end)
|
|
|
|
*kp++ = *cp++;
|
|
|
|
*kp = '\0';
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
/* Save InputBuf etc in SavedBuf etc for restore after cmd exec */
|
|
|
|
static void
|
|
|
|
c_save_inputbuf()
|
|
|
|
{
|
|
|
|
SavedBuf.len = 0;
|
|
|
|
Strbuf_append(&SavedBuf, InputBuf);
|
|
|
|
Strbuf_terminate(&SavedBuf);
|
|
|
|
LastSaved = LastChar - InputBuf;
|
|
|
|
CursSaved = Cursor - InputBuf;
|
|
|
|
HistSaved = Hist_num;
|
|
|
|
RestoreSaved = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCRETVAL
|
|
|
|
GetHistLine()
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
struct Hist *hp;
|
|
|
|
int h;
|
|
|
|
|
|
|
|
if (Hist_num == 0) { /* if really the current line */
|
2007-03-11 22:33:41 +00:00
|
|
|
if (HistBuf.s != NULL)
|
|
|
|
copyn(InputBuf, HistBuf.s, INBUFSIZE);/*FIXBUF*/
|
|
|
|
else
|
|
|
|
*InputBuf = '\0';
|
|
|
|
LastChar = InputBuf + HistBuf.len;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
#ifdef KSHVI
|
|
|
|
if (VImode)
|
|
|
|
Cursor = InputBuf;
|
|
|
|
else
|
|
|
|
#endif /* KSHVI */
|
|
|
|
Cursor = LastChar;
|
|
|
|
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
hp = Histlist.Hnext;
|
|
|
|
if (hp == NULL)
|
|
|
|
return(CC_ERROR);
|
|
|
|
|
|
|
|
for (h = 1; h < Hist_num; h++) {
|
|
|
|
if ((hp->Hnext) == NULL) {
|
|
|
|
Hist_num = h;
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
hp = hp->Hnext;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HistLit && hp->histline) {
|
2007-03-11 22:33:41 +00:00
|
|
|
copyn(InputBuf, hp->histline, INBUFSIZE);/*FIXBUF*/
|
2000-04-15 04:41:27 +00:00
|
|
|
CurrentHistLit = 1;
|
|
|
|
}
|
|
|
|
else {
|
2007-03-11 22:33:41 +00:00
|
|
|
Char *p;
|
|
|
|
|
|
|
|
p = sprlex(&hp->Hlex);
|
|
|
|
copyn(InputBuf, p, sizeof(InputBuf) / sizeof(Char));/*FIXBUF*/
|
|
|
|
xfree(p);
|
2000-04-15 04:41:27 +00:00
|
|
|
CurrentHistLit = 0;
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
LastChar = Strend(InputBuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (LastChar > InputBuf) {
|
|
|
|
if (LastChar[-1] == '\n')
|
|
|
|
LastChar--;
|
|
|
|
#if 0
|
|
|
|
if (LastChar[-1] == ' ')
|
|
|
|
LastChar--;
|
|
|
|
#endif
|
|
|
|
if (LastChar < InputBuf)
|
|
|
|
LastChar = InputBuf;
|
|
|
|
}
|
2005-04-24 19:41:08 +00:00
|
|
|
|
2000-04-15 04:41:27 +00:00
|
|
|
#ifdef KSHVI
|
|
|
|
if (VImode)
|
|
|
|
Cursor = InputBuf;
|
|
|
|
else
|
|
|
|
#endif /* KSHVI */
|
|
|
|
Cursor = LastChar;
|
|
|
|
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
static CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
c_search_line(Char *pattern, int dir)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char *cp;
|
2007-03-11 22:33:41 +00:00
|
|
|
size_t len;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
len = Strlen(pattern);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (dir == F_UP_SEARCH_HIST) {
|
|
|
|
for (cp = Cursor; cp >= InputBuf; cp--)
|
2007-03-11 22:33:41 +00:00
|
|
|
if (Strncmp(cp, pattern, len) == 0 ||
|
2000-04-15 04:41:27 +00:00
|
|
|
Gmatch(cp, pattern)) {
|
|
|
|
Cursor = cp;
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
return(CC_ERROR);
|
|
|
|
} else {
|
|
|
|
for (cp = Cursor; *cp != '\0' && cp < InputLim; cp++)
|
2007-03-11 22:33:41 +00:00
|
|
|
if (Strncmp(cp, pattern, len) == 0 ||
|
2000-04-15 04:41:27 +00:00
|
|
|
Gmatch(cp, pattern)) {
|
|
|
|
Cursor = cp;
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_inc_search(int dir)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2007-03-11 22:33:41 +00:00
|
|
|
static const Char STRfwd[] = { 'f', 'w', 'd', '\0' },
|
|
|
|
STRbck[] = { 'b', 'c', 'k', '\0' };
|
2000-04-15 04:41:27 +00:00
|
|
|
static Char pchar = ':'; /* ':' = normal, '?' = failed */
|
|
|
|
static Char endcmd[2];
|
2007-03-11 22:33:41 +00:00
|
|
|
const Char *cp;
|
|
|
|
Char ch,
|
2000-04-15 04:41:27 +00:00
|
|
|
*oldCursor = Cursor,
|
|
|
|
oldpchar = pchar;
|
|
|
|
CCRETVAL ret = CC_NORM;
|
|
|
|
int oldHist_num = Hist_num,
|
2007-03-11 22:33:41 +00:00
|
|
|
oldpatlen = patbuf.len,
|
2000-04-15 04:41:27 +00:00
|
|
|
newdir = dir,
|
|
|
|
done, redo;
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
if (LastChar + sizeof(STRfwd)/sizeof(Char) + 2 + patbuf.len >= InputLim)
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_ERROR);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
if (patbuf.len == 0) { /* first round */
|
2000-04-15 04:41:27 +00:00
|
|
|
pchar = ':';
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&patbuf, '*');
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
done = redo = 0;
|
|
|
|
*LastChar++ = '\n';
|
|
|
|
for (cp = newdir == F_UP_SEARCH_HIST ? STRbck : STRfwd;
|
|
|
|
*cp; *LastChar++ = *cp++)
|
|
|
|
continue;
|
|
|
|
*LastChar++ = pchar;
|
2007-03-11 22:33:41 +00:00
|
|
|
for (cp = &patbuf.s[1]; cp < &patbuf.s[patbuf.len];
|
|
|
|
*LastChar++ = *cp++)
|
2000-04-15 04:41:27 +00:00
|
|
|
continue;
|
|
|
|
*LastChar = '\0';
|
2007-03-11 22:33:41 +00:00
|
|
|
if (adrof(STRhighlight) && pchar == ':') {
|
|
|
|
/* if the no-glob-search patch is applied, remove the - 1 below */
|
|
|
|
IncMatchLen = patbuf.len - 1;
|
|
|
|
ClearLines();
|
|
|
|
ClearDisp();
|
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
Refresh();
|
|
|
|
|
|
|
|
if (GetNextChar(&ch) != 1)
|
|
|
|
return(e_send_eof(0));
|
|
|
|
|
2005-04-24 19:41:08 +00:00
|
|
|
switch (ch > NT_NUM_KEYS
|
|
|
|
? F_INSERT : CurrentKeyMap[(unsigned char) ch]) {
|
2000-04-15 04:41:27 +00:00
|
|
|
case F_INSERT:
|
|
|
|
case F_DIGIT:
|
|
|
|
case F_MAGIC_SPACE:
|
2007-03-11 22:33:41 +00:00
|
|
|
if (LastChar + 1 >= InputLim) /*FIXBUF*/
|
2000-04-15 04:41:27 +00:00
|
|
|
SoundBeep();
|
|
|
|
else {
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&patbuf, ch);
|
2000-04-15 04:41:27 +00:00
|
|
|
*LastChar++ = ch;
|
|
|
|
*LastChar = '\0';
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case F_INC_FWD:
|
|
|
|
newdir = F_DOWN_SEARCH_HIST;
|
|
|
|
redo++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case F_INC_BACK:
|
|
|
|
newdir = F_UP_SEARCH_HIST;
|
|
|
|
redo++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case F_DELPREV:
|
2007-03-11 22:33:41 +00:00
|
|
|
if (patbuf.len > 1)
|
2000-04-15 04:41:27 +00:00
|
|
|
done++;
|
|
|
|
else
|
|
|
|
SoundBeep();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-03-11 22:33:41 +00:00
|
|
|
switch (ASC(ch)) {
|
2000-04-15 04:41:27 +00:00
|
|
|
case 0007: /* ^G: Abort */
|
|
|
|
ret = CC_ERROR;
|
|
|
|
done++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0027: /* ^W: Append word */
|
|
|
|
/* No can do if globbing characters in pattern */
|
2007-03-11 22:33:41 +00:00
|
|
|
for (cp = &patbuf.s[1]; ; cp++)
|
|
|
|
if (cp >= &patbuf.s[patbuf.len]) {
|
|
|
|
Cursor += patbuf.len - 1;
|
2000-04-15 04:41:27 +00:00
|
|
|
cp = c_next_word(Cursor, LastChar, 1);
|
|
|
|
while (Cursor < cp && *Cursor != '\n') {
|
2007-03-11 22:33:41 +00:00
|
|
|
if (LastChar + 1 >= InputLim) {/*FIXBUF*/
|
2000-04-15 04:41:27 +00:00
|
|
|
SoundBeep();
|
|
|
|
break;
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&patbuf, *Cursor);
|
2000-04-15 04:41:27 +00:00
|
|
|
*LastChar++ = *Cursor++;
|
|
|
|
}
|
|
|
|
Cursor = oldCursor;
|
|
|
|
*LastChar = '\0';
|
|
|
|
Refresh();
|
|
|
|
break;
|
|
|
|
} else if (isglob(*cp)) {
|
|
|
|
SoundBeep();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* Terminate and execute cmd */
|
|
|
|
endcmd[0] = ch;
|
|
|
|
PushMacro(endcmd);
|
|
|
|
/*FALLTHROUGH*/
|
|
|
|
|
|
|
|
case 0033: /* ESC: Terminate */
|
|
|
|
ret = CC_REFRESH;
|
|
|
|
done++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (LastChar > InputBuf && *LastChar != '\n')
|
|
|
|
*LastChar-- = '\0';
|
|
|
|
*LastChar = '\0';
|
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
|
|
|
|
/* Can't search if unmatched '[' */
|
2007-03-11 22:33:41 +00:00
|
|
|
for (cp = &patbuf.s[patbuf.len - 1], ch = ']'; cp > patbuf.s; cp--)
|
2000-04-15 04:41:27 +00:00
|
|
|
if (*cp == '[' || *cp == ']') {
|
|
|
|
ch = *cp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
if (patbuf.len > 1 && ch != '[') {
|
2000-04-15 04:41:27 +00:00
|
|
|
if (redo && newdir == dir) {
|
|
|
|
if (pchar == '?') { /* wrap around */
|
2007-03-11 22:33:41 +00:00
|
|
|
Hist_num = newdir == F_UP_SEARCH_HIST ? 0 : INT_MAX;
|
|
|
|
if (GetHistLine() == CC_ERROR)
|
2000-04-15 04:41:27 +00:00
|
|
|
/* Hist_num was fixed by first call */
|
2007-03-11 22:33:41 +00:00
|
|
|
(void) GetHistLine();
|
2000-04-15 04:41:27 +00:00
|
|
|
Cursor = newdir == F_UP_SEARCH_HIST ?
|
|
|
|
LastChar : InputBuf;
|
|
|
|
} else
|
|
|
|
Cursor += newdir == F_UP_SEARCH_HIST ? -1 : 1;
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&patbuf, '*');
|
|
|
|
Strbuf_terminate(&patbuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (Cursor < InputBuf || Cursor > LastChar ||
|
2007-03-11 22:33:41 +00:00
|
|
|
(ret = c_search_line(&patbuf.s[1], newdir)) == CC_ERROR) {
|
2000-04-15 04:41:27 +00:00
|
|
|
LastCmd = (KEYCMD) newdir; /* avoid c_hsetpat */
|
|
|
|
ret = newdir == F_UP_SEARCH_HIST ?
|
|
|
|
e_up_search_hist(0) : e_down_search_hist(0);
|
|
|
|
if (ret != CC_ERROR) {
|
|
|
|
Cursor = newdir == F_UP_SEARCH_HIST ?
|
|
|
|
LastChar : InputBuf;
|
2007-03-11 22:33:41 +00:00
|
|
|
(void) c_search_line(&patbuf.s[1], newdir);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
patbuf.s[--patbuf.len] = '\0';
|
2000-04-15 04:41:27 +00:00
|
|
|
if (ret == CC_ERROR) {
|
|
|
|
SoundBeep();
|
|
|
|
if (Hist_num != oldHist_num) {
|
|
|
|
Hist_num = oldHist_num;
|
2007-03-11 22:33:41 +00:00
|
|
|
if (GetHistLine() == CC_ERROR)
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
Cursor = oldCursor;
|
|
|
|
pchar = '?';
|
|
|
|
} else {
|
|
|
|
pchar = ':';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = e_inc_search(newdir);
|
|
|
|
|
|
|
|
if (ret == CC_ERROR && pchar == '?' && oldpchar == ':') {
|
|
|
|
/* break abort of failed search at last non-failed */
|
|
|
|
ret = CC_NORM;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == CC_NORM || (ret == CC_ERROR && oldpatlen == 0)) {
|
|
|
|
/* restore on normal return or error exit */
|
|
|
|
pchar = oldpchar;
|
2007-03-11 22:33:41 +00:00
|
|
|
patbuf.len = oldpatlen;
|
2000-04-15 04:41:27 +00:00
|
|
|
if (Hist_num != oldHist_num) {
|
|
|
|
Hist_num = oldHist_num;
|
2007-03-11 22:33:41 +00:00
|
|
|
if (GetHistLine() == CC_ERROR)
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
Cursor = oldCursor;
|
|
|
|
if (ret == CC_ERROR)
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
if (done || ret != CC_NORM)
|
|
|
|
return(ret);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_search(int dir)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2007-03-11 22:33:41 +00:00
|
|
|
struct Strbuf tmpbuf = Strbuf_INIT;
|
2000-04-15 04:41:27 +00:00
|
|
|
Char ch;
|
2007-03-11 22:33:41 +00:00
|
|
|
Char *oldbuf;
|
2000-04-15 04:41:27 +00:00
|
|
|
Char *oldlc, *oldc;
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_push(&tmpbuf, Strbuf_cleanup);
|
|
|
|
oldbuf = Strsave(InputBuf);
|
|
|
|
cleanup_push(oldbuf, xfree);
|
2000-04-15 04:41:27 +00:00
|
|
|
oldlc = LastChar;
|
|
|
|
oldc = Cursor;
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&tmpbuf, '*');
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
InputBuf[0] = '\0';
|
|
|
|
LastChar = InputBuf;
|
|
|
|
Cursor = InputBuf;
|
|
|
|
searchdir = dir;
|
|
|
|
|
|
|
|
c_insert(2); /* prompt + '\n' */
|
|
|
|
*Cursor++ = '\n';
|
|
|
|
*Cursor++ = dir == F_UP_SEARCH_HIST ? '?' : '/';
|
|
|
|
Refresh();
|
|
|
|
for (ch = 0;ch == 0;) {
|
2007-03-11 22:33:41 +00:00
|
|
|
if (GetNextChar(&ch) != 1) {
|
|
|
|
cleanup_until(&tmpbuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
return(e_send_eof(0));
|
2007-03-11 22:33:41 +00:00
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
switch (ASC(ch)) {
|
|
|
|
case 0010: /* Delete and backspace */
|
|
|
|
case 0177:
|
2007-03-11 22:33:41 +00:00
|
|
|
if (tmpbuf.len > 1) {
|
2000-04-15 04:41:27 +00:00
|
|
|
*Cursor-- = '\0';
|
|
|
|
LastChar = Cursor;
|
2007-03-11 22:33:41 +00:00
|
|
|
tmpbuf.len--;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-03-11 22:33:41 +00:00
|
|
|
copyn(InputBuf, oldbuf, INBUFSIZE);/*FIXBUF*/
|
2000-04-15 04:41:27 +00:00
|
|
|
LastChar = oldlc;
|
|
|
|
Cursor = oldc;
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(&tmpbuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
Refresh();
|
|
|
|
ch = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0033: /* ESC */
|
2000-11-30 21:05:33 +00:00
|
|
|
#ifdef IS_ASCII
|
2000-04-15 04:41:27 +00:00
|
|
|
case '\r': /* Newline */
|
|
|
|
case '\n':
|
|
|
|
#else
|
2000-11-30 21:05:33 +00:00
|
|
|
case '\012': /* ASCII Line feed */
|
|
|
|
case '\015': /* ASCII (or EBCDIC) Return */
|
2000-04-15 04:41:27 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&tmpbuf, ch);
|
|
|
|
*Cursor++ = ch;
|
|
|
|
LastChar = Cursor;
|
2000-04-15 04:41:27 +00:00
|
|
|
Refresh();
|
|
|
|
ch = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(oldbuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
if (tmpbuf.len == 1) {
|
2000-04-15 04:41:27 +00:00
|
|
|
/*
|
|
|
|
* Use the old pattern, but wild-card it.
|
|
|
|
*/
|
2007-03-11 22:33:41 +00:00
|
|
|
if (patbuf.len == 0) {
|
2000-04-15 04:41:27 +00:00
|
|
|
InputBuf[0] = '\0';
|
|
|
|
LastChar = InputBuf;
|
|
|
|
Cursor = InputBuf;
|
|
|
|
Refresh();
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(&tmpbuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
if (patbuf.s[0] != '*') {
|
|
|
|
oldbuf = Strsave(patbuf.s);
|
|
|
|
patbuf.len = 0;
|
|
|
|
Strbuf_append1(&patbuf, '*');
|
|
|
|
Strbuf_append(&patbuf, oldbuf);
|
|
|
|
xfree(oldbuf);
|
|
|
|
Strbuf_append1(&patbuf, '*');
|
|
|
|
Strbuf_terminate(&patbuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-03-11 22:33:41 +00:00
|
|
|
Strbuf_append1(&tmpbuf, '*');
|
|
|
|
Strbuf_terminate(&tmpbuf);
|
|
|
|
patbuf.len = 0;
|
|
|
|
Strbuf_append(&patbuf, tmpbuf.s);
|
|
|
|
Strbuf_terminate(&patbuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(&tmpbuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
LastCmd = (KEYCMD) dir; /* avoid c_hsetpat */
|
|
|
|
Cursor = LastChar = InputBuf;
|
|
|
|
if ((dir == F_UP_SEARCH_HIST ? e_up_search_hist(0) :
|
|
|
|
e_down_search_hist(0)) == CC_ERROR) {
|
|
|
|
Refresh();
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
else {
|
2007-03-11 22:33:41 +00:00
|
|
|
if (ASC(ch) == 0033) {
|
2000-04-15 04:41:27 +00:00
|
|
|
Refresh();
|
|
|
|
*LastChar++ = '\n';
|
|
|
|
*LastChar = '\0';
|
|
|
|
PastBottom();
|
|
|
|
return(CC_NEWLINE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* semi-PUBLIC routines. Any routine that is of type CCRETVAL is an
|
|
|
|
* entry point, called from the CcKeyMap indirected into the
|
|
|
|
* CcFuncTbl array.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_cmd_mode(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
InsertPos = 0;
|
|
|
|
ActionFlag = TCSHOP_NOP; /* [Esc] cancels pending action */
|
|
|
|
ActionPos = 0;
|
|
|
|
DoingArg = 0;
|
|
|
|
if (UndoPtr > Cursor)
|
|
|
|
UndoSize = (int)(UndoPtr - Cursor);
|
|
|
|
else
|
|
|
|
UndoSize = (int)(Cursor - UndoPtr);
|
|
|
|
|
|
|
|
inputmode = MODE_INSERT;
|
|
|
|
c_alternativ_key_map(1);
|
|
|
|
#ifdef notdef
|
|
|
|
/*
|
|
|
|
* We don't want to move the cursor, because all the editing
|
|
|
|
* commands don't include the character under the cursor.
|
|
|
|
*/
|
|
|
|
if (Cursor > InputBuf)
|
|
|
|
Cursor--;
|
|
|
|
#endif
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_unassigned(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* bound to keys that arn't really assigned */
|
|
|
|
USE(c);
|
|
|
|
SoundBeep();
|
|
|
|
flush();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
#ifdef notyet
|
2005-04-24 19:41:08 +00:00
|
|
|
static CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_insert_str(Char *c)
|
2005-04-24 19:41:08 +00:00
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
n = Strlen(c);
|
|
|
|
if (LastChar + Argument * n >= InputLim)
|
|
|
|
return(CC_ERROR); /* end of buffer space */
|
|
|
|
if (inputmode != MODE_INSERT) {
|
2007-03-11 22:33:41 +00:00
|
|
|
c_delafter(Argument * Strlen(c));
|
2005-04-24 19:41:08 +00:00
|
|
|
}
|
|
|
|
c_insert(Argument * n);
|
|
|
|
while (Argument--) {
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
*Cursor++ = c[i];
|
|
|
|
}
|
|
|
|
Refresh();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
#endif
|
2005-04-24 19:41:08 +00:00
|
|
|
|
2000-04-15 04:41:27 +00:00
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_insert(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
#ifndef SHORT_STRINGS
|
|
|
|
c &= ASCII; /* no meta chars ever */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!c)
|
|
|
|
return(CC_ERROR); /* no NULs in the input ever!! */
|
|
|
|
|
|
|
|
if (LastChar + Argument >= InputLim)
|
|
|
|
return(CC_ERROR); /* end of buffer space */
|
|
|
|
|
|
|
|
if (Argument == 1) { /* How was this optimized ???? */
|
|
|
|
|
|
|
|
if (inputmode != MODE_INSERT) {
|
|
|
|
UndoBuf[UndoSize++] = *Cursor;
|
|
|
|
UndoBuf[UndoSize] = '\0';
|
|
|
|
c_delafter(1); /* Do NOT use the saving ONE */
|
|
|
|
}
|
|
|
|
|
|
|
|
c_insert(1);
|
|
|
|
*Cursor++ = (Char) c;
|
|
|
|
DoingArg = 0; /* just in case */
|
2005-04-24 19:41:08 +00:00
|
|
|
RefPlusOne(1); /* fast refresh for one char. */
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (inputmode != MODE_INSERT) {
|
2005-04-24 19:41:08 +00:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < Argument; i++)
|
|
|
|
UndoBuf[UndoSize++] = *(Cursor + i);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
UndoBuf[UndoSize] = '\0';
|
|
|
|
c_delafter(Argument); /* Do NOT use the saving ONE */
|
|
|
|
}
|
|
|
|
|
|
|
|
c_insert(Argument);
|
|
|
|
|
|
|
|
while (Argument--)
|
|
|
|
*Cursor++ = (Char) c;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputmode == MODE_REPLACE_1)
|
|
|
|
(void) v_cmd_mode(0);
|
|
|
|
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-11 22:33:41 +00:00
|
|
|
InsertStr(Char *s) /* insert ASCIZ s at cursor (for complete) */
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
int len;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if ((len = (int) Strlen(s)) <= 0)
|
|
|
|
return -1;
|
|
|
|
if (LastChar + len >= InputLim)
|
|
|
|
return -1; /* end of buffer space */
|
|
|
|
|
|
|
|
c_insert(len);
|
|
|
|
while (len--)
|
|
|
|
*Cursor++ = *s++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
DeleteBack(int n) /* delete the n characters before . */
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
if (n <= 0)
|
|
|
|
return;
|
|
|
|
if (Cursor >= &InputBuf[n]) {
|
|
|
|
c_delbefore(n); /* delete before dot */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_digit(Char c) /* gray magic here */
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
if (!Isdigit(c))
|
|
|
|
return(CC_ERROR); /* no NULs in the input ever!! */
|
|
|
|
|
|
|
|
if (DoingArg) { /* if doing an arg, add this in... */
|
|
|
|
if (LastCmd == F_ARGFOUR) /* if last command was ^U */
|
|
|
|
Argument = c - '0';
|
|
|
|
else {
|
|
|
|
if (Argument > 1000000)
|
|
|
|
return CC_ERROR;
|
|
|
|
Argument = (Argument * 10) + (c - '0');
|
|
|
|
}
|
|
|
|
return(CC_ARGHACK);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (LastChar + 1 >= InputLim)
|
|
|
|
return CC_ERROR; /* end of buffer space */
|
|
|
|
|
|
|
|
if (inputmode != MODE_INSERT) {
|
|
|
|
UndoBuf[UndoSize++] = *Cursor;
|
|
|
|
UndoBuf[UndoSize] = '\0';
|
|
|
|
c_delafter(1); /* Do NOT use the saving ONE */
|
|
|
|
}
|
|
|
|
c_insert(1);
|
|
|
|
*Cursor++ = (Char) c;
|
|
|
|
DoingArg = 0; /* just in case */
|
2005-04-24 19:41:08 +00:00
|
|
|
RefPlusOne(1); /* fast refresh for one char. */
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_argdigit(Char c) /* for ESC-n */
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2007-03-11 22:33:41 +00:00
|
|
|
#ifdef IS_ASCII
|
2000-04-15 04:41:27 +00:00
|
|
|
c &= ASCII;
|
2007-03-11 22:33:41 +00:00
|
|
|
#else
|
|
|
|
c = CTL_ESC(ASC(c) & ASCII); /* stripping for EBCDIC done the ASCII way */
|
|
|
|
#endif
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (!Isdigit(c))
|
|
|
|
return(CC_ERROR); /* no NULs in the input ever!! */
|
|
|
|
|
|
|
|
if (DoingArg) { /* if doing an arg, add this in... */
|
|
|
|
if (Argument > 1000000)
|
|
|
|
return CC_ERROR;
|
|
|
|
Argument = (Argument * 10) + (c - '0');
|
|
|
|
}
|
|
|
|
else { /* else starting an argument */
|
|
|
|
Argument = c - '0';
|
|
|
|
DoingArg = 1;
|
|
|
|
}
|
|
|
|
return(CC_ARGHACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_zero(Char c) /* command mode 0 for vi */
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
if (DoingArg) { /* if doing an arg, add this in... */
|
|
|
|
if (Argument > 1000000)
|
|
|
|
return CC_ERROR;
|
|
|
|
Argument = (Argument * 10) + (c - '0');
|
|
|
|
return(CC_ARGHACK);
|
|
|
|
}
|
|
|
|
else { /* else starting an argument */
|
|
|
|
Cursor = InputBuf;
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
RefCursor(); /* move the cursor */
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_newline(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* always ignore argument */
|
|
|
|
USE(c);
|
2007-03-11 22:33:41 +00:00
|
|
|
if (adrof(STRhighlight) && MarkIsSet) {
|
|
|
|
MarkIsSet = 0;
|
|
|
|
ClearLines();
|
|
|
|
ClearDisp();
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
MarkIsSet = 0;
|
|
|
|
|
2000-04-15 04:41:27 +00:00
|
|
|
/* PastBottom(); NOW done in ed.inputl.c */
|
|
|
|
*LastChar++ = '\n'; /* for the benefit of CSH */
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
if (VImode)
|
|
|
|
InsertPos = InputBuf; /* Reset editing position */
|
|
|
|
return(CC_NEWLINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_newline_hold(Char c)
|
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
c_save_inputbuf();
|
|
|
|
HistSaved = 0;
|
|
|
|
*LastChar++ = '\n'; /* for the benefit of CSH */
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_NEWLINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
|
|
|
e_newline_down_hist(Char c)
|
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Hist_num > 1) {
|
|
|
|
HistSaved = Hist_num;
|
|
|
|
}
|
|
|
|
*LastChar++ = '\n'; /* for the benefit of CSH */
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_NEWLINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
|
|
|
e_send_eof(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* for when ^D is ONLY send-eof */
|
|
|
|
USE(c);
|
|
|
|
PastBottom();
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_EOF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_complete(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_COMPLETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_complete_back(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_COMPLETE_BACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_complete_fwd(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_COMPLETE_FWD);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_complete_all(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_COMPLETE_ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_cm_complete(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor < LastChar)
|
|
|
|
Cursor++;
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_COMPLETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_toggle_hist(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
struct Hist *hp;
|
|
|
|
int h;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
|
|
|
|
if (Hist_num <= 0) {
|
|
|
|
return CC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
hp = Histlist.Hnext;
|
|
|
|
if (hp == NULL) { /* this is only if no history */
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (h = 1; h < Hist_num; h++)
|
|
|
|
hp = hp->Hnext;
|
|
|
|
|
|
|
|
if (!CurrentHistLit) {
|
|
|
|
if (hp->histline) {
|
2007-03-11 22:33:41 +00:00
|
|
|
copyn(InputBuf, hp->histline, INBUFSIZE);/*FIXBUF*/
|
2000-04-15 04:41:27 +00:00
|
|
|
CurrentHistLit = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return CC_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-03-11 22:33:41 +00:00
|
|
|
Char *p;
|
|
|
|
|
|
|
|
p = sprlex(&hp->Hlex);
|
|
|
|
copyn(InputBuf, p, sizeof(InputBuf) / sizeof(Char));/*FIXBUF*/
|
|
|
|
xfree(p);
|
2000-04-15 04:41:27 +00:00
|
|
|
CurrentHistLit = 0;
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
LastChar = Strend(InputBuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (LastChar > InputBuf) {
|
|
|
|
if (LastChar[-1] == '\n')
|
|
|
|
LastChar--;
|
|
|
|
if (LastChar[-1] == ' ')
|
|
|
|
LastChar--;
|
|
|
|
if (LastChar < InputBuf)
|
|
|
|
LastChar = InputBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef KSHVI
|
|
|
|
if (VImode)
|
|
|
|
Cursor = InputBuf;
|
|
|
|
else
|
|
|
|
#endif /* KSHVI */
|
|
|
|
Cursor = LastChar;
|
|
|
|
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_up_hist(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char beep = 0;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
UndoAction = TCSHOP_NOP;
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
|
|
|
|
if (Hist_num == 0) { /* save the current buffer away */
|
2007-03-11 22:33:41 +00:00
|
|
|
HistBuf.len = 0;
|
|
|
|
Strbuf_append(&HistBuf, InputBuf);
|
|
|
|
Strbuf_terminate(&HistBuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Hist_num += Argument;
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
if (GetHistLine() == CC_ERROR) {
|
2000-04-15 04:41:27 +00:00
|
|
|
beep = 1;
|
2007-03-11 22:33:41 +00:00
|
|
|
(void) GetHistLine(); /* Hist_num was fixed by first call */
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
if (beep)
|
|
|
|
return(CC_ERROR);
|
|
|
|
else
|
|
|
|
return(CC_NORM); /* was CC_UP_HIST */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_down_hist(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
UndoAction = TCSHOP_NOP;
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
|
|
|
|
Hist_num -= Argument;
|
|
|
|
|
|
|
|
if (Hist_num < 0) {
|
|
|
|
Hist_num = 0;
|
|
|
|
return(CC_ERROR); /* make it beep */
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
return(GetHistLine());
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* c_hmatch() return True if the pattern matches the prefix
|
|
|
|
*/
|
|
|
|
static int
|
2007-03-11 22:33:41 +00:00
|
|
|
c_hmatch(Char *str)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2007-03-11 22:33:41 +00:00
|
|
|
if (Strncmp(patbuf.s, str, patbuf.len) == 0)
|
2000-04-15 04:41:27 +00:00
|
|
|
return 1;
|
2007-03-11 22:33:41 +00:00
|
|
|
return Gmatch(str, patbuf.s);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* c_hsetpat(): Set the history seatch pattern
|
|
|
|
*/
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
c_hsetpat(void)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
if (LastCmd != F_UP_SEARCH_HIST && LastCmd != F_DOWN_SEARCH_HIST) {
|
2007-03-11 22:33:41 +00:00
|
|
|
patbuf.len = 0;
|
|
|
|
Strbuf_appendn(&patbuf, InputBuf, Cursor - InputBuf);
|
|
|
|
Strbuf_terminate(&patbuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
#ifdef SDEBUG
|
|
|
|
xprintf("\nHist_num = %d\n", Hist_num);
|
2007-03-11 22:33:41 +00:00
|
|
|
xprintf("patlen = %d\n", (int)patbuf.len);
|
|
|
|
xprintf("patbuf = \"%S\"\n", patbuf.s);
|
2000-04-15 04:41:27 +00:00
|
|
|
xprintf("Cursor %d LastChar %d\n", Cursor - InputBuf, LastChar - InputBuf);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_up_search_hist(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
struct Hist *hp;
|
|
|
|
int h;
|
2005-04-24 19:41:08 +00:00
|
|
|
int found = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
|
|
|
ActionFlag = TCSHOP_NOP;
|
|
|
|
UndoAction = TCSHOP_NOP;
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
if (Hist_num < 0) {
|
|
|
|
#ifdef DEBUG_EDIT
|
|
|
|
xprintf("%s: e_up_search_hist(): Hist_num < 0; resetting.\n", progname);
|
|
|
|
#endif
|
|
|
|
Hist_num = 0;
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
if (Hist_num == 0) {
|
|
|
|
HistBuf.len = 0;
|
|
|
|
Strbuf_append(&HistBuf, InputBuf);
|
|
|
|
Strbuf_terminate(&HistBuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
hp = Histlist.Hnext;
|
|
|
|
if (hp == NULL)
|
|
|
|
return(CC_ERROR);
|
|
|
|
|
|
|
|
c_hsetpat(); /* Set search pattern !! */
|
|
|
|
|
|
|
|
for (h = 1; h <= Hist_num; h++)
|
|
|
|
hp = hp->Hnext;
|
|
|
|
|
|
|
|
while (hp != NULL) {
|
2007-03-11 22:33:41 +00:00
|
|
|
Char *hl;
|
|
|
|
int matched;
|
|
|
|
|
|
|
|
if (hp->histline == NULL)
|
|
|
|
hp->histline = sprlex(&hp->Hlex);
|
|
|
|
if (HistLit)
|
|
|
|
hl = hp->histline;
|
|
|
|
else {
|
|
|
|
hl = sprlex(&hp->Hlex);
|
|
|
|
cleanup_push(hl, xfree);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
#ifdef SDEBUG
|
|
|
|
xprintf("Comparing with \"%S\"\n", hl);
|
|
|
|
#endif
|
2007-03-11 22:33:41 +00:00
|
|
|
matched = (Strncmp(hl, InputBuf, (size_t) (LastChar - InputBuf)) ||
|
|
|
|
hl[LastChar-InputBuf]) && c_hmatch(hl);
|
|
|
|
if (!HistLit)
|
|
|
|
cleanup_until(hl);
|
|
|
|
if (matched) {
|
2000-04-15 04:41:27 +00:00
|
|
|
found++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
h++;
|
|
|
|
hp = hp->Hnext;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
#ifdef SDEBUG
|
2007-03-11 22:33:41 +00:00
|
|
|
xprintf("not found\n");
|
2000-04-15 04:41:27 +00:00
|
|
|
#endif
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
Hist_num = h;
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
return(GetHistLine());
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_down_search_hist(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
struct Hist *hp;
|
|
|
|
int h;
|
2005-04-24 19:41:08 +00:00
|
|
|
int found = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
|
|
|
ActionFlag = TCSHOP_NOP;
|
|
|
|
UndoAction = TCSHOP_NOP;
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
|
|
|
|
if (Hist_num == 0)
|
|
|
|
return(CC_ERROR);
|
|
|
|
|
|
|
|
hp = Histlist.Hnext;
|
|
|
|
if (hp == 0)
|
|
|
|
return(CC_ERROR);
|
|
|
|
|
|
|
|
c_hsetpat(); /* Set search pattern !! */
|
|
|
|
|
|
|
|
for (h = 1; h < Hist_num && hp; h++) {
|
2007-03-11 22:33:41 +00:00
|
|
|
Char *hl;
|
|
|
|
if (hp->histline == NULL)
|
|
|
|
hp->histline = sprlex(&hp->Hlex);
|
|
|
|
if (HistLit)
|
|
|
|
hl = hp->histline;
|
|
|
|
else {
|
|
|
|
hl = sprlex(&hp->Hlex);
|
|
|
|
cleanup_push(hl, xfree);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
#ifdef SDEBUG
|
|
|
|
xprintf("Comparing with \"%S\"\n", hl);
|
|
|
|
#endif
|
|
|
|
if ((Strncmp(hl, InputBuf, (size_t) (LastChar - InputBuf)) ||
|
|
|
|
hl[LastChar-InputBuf]) && c_hmatch(hl))
|
|
|
|
found = h;
|
2007-03-11 22:33:41 +00:00
|
|
|
if (!HistLit)
|
|
|
|
cleanup_until(hl);
|
2000-04-15 04:41:27 +00:00
|
|
|
hp = hp->Hnext;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) { /* is it the current history number? */
|
2007-03-11 22:33:41 +00:00
|
|
|
if (!c_hmatch(HistBuf.s)) {
|
2000-04-15 04:41:27 +00:00
|
|
|
#ifdef SDEBUG
|
2007-03-11 22:33:41 +00:00
|
|
|
xprintf("not found\n");
|
2000-04-15 04:41:27 +00:00
|
|
|
#endif
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Hist_num = found;
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
return(GetHistLine());
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_helpme(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
PastBottom();
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_HELPME);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_correct(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_CORRECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_correctl(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_CORRECT_L);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_run_fg_editor(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
struct process *pp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
|
|
|
if ((pp = find_stop_ed()) != NULL) {
|
|
|
|
/* save our editor state so we can restore it */
|
2007-03-11 22:33:41 +00:00
|
|
|
c_save_inputbuf();
|
2000-04-15 04:41:27 +00:00
|
|
|
Hist_num = 0; /* for the history commands */
|
|
|
|
|
|
|
|
/* put the tty in a sane mode */
|
|
|
|
PastBottom();
|
|
|
|
(void) Cookedmode(); /* make sure the tty is set up correctly */
|
|
|
|
|
|
|
|
/* do it! */
|
|
|
|
fg_proc_entry(pp);
|
|
|
|
|
|
|
|
(void) Rawmode(); /* go on */
|
|
|
|
Refresh();
|
2007-03-11 22:33:41 +00:00
|
|
|
RestoreSaved = 0;
|
|
|
|
HistSaved = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_list_choices(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
PastBottom();
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_LIST_CHOICES);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_list_all(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
PastBottom();
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_LIST_ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_list_glob(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
PastBottom();
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_LIST_GLOB);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_expand_glob(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_EXPAND_GLOB);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_normalize_path(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_NORMALIZE_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_normalize_command(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_NORMALIZE_COMMAND);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_expand_vars(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_EXPAND_VARS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_which(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* do a fast command line which(1) */
|
|
|
|
USE(c);
|
2007-03-11 22:33:41 +00:00
|
|
|
c_save_inputbuf();
|
|
|
|
Hist_num = 0; /* for the history commands */
|
2000-04-15 04:41:27 +00:00
|
|
|
PastBottom();
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_WHICH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_last_item(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* insert the last element of the prev. cmd */
|
2001-09-05 17:49:32 +00:00
|
|
|
struct Hist *hp;
|
|
|
|
struct wordent *wp, *firstp;
|
|
|
|
int i;
|
2007-03-11 22:33:41 +00:00
|
|
|
Char *expanded;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
|
|
|
if (Argument <= 0)
|
|
|
|
return(CC_ERROR);
|
|
|
|
|
|
|
|
hp = Histlist.Hnext;
|
|
|
|
if (hp == NULL) { /* this is only if no history */
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
wp = (hp->Hlex).prev;
|
|
|
|
|
|
|
|
if (wp->prev == (struct wordent *) NULL)
|
|
|
|
return(CC_ERROR); /* an empty history entry */
|
|
|
|
|
|
|
|
firstp = (hp->Hlex).next;
|
|
|
|
|
|
|
|
/* back up arg words in lex */
|
|
|
|
for (i = 0; i < Argument && wp != firstp; i++) {
|
|
|
|
wp = wp->prev;
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
expanded = expand_lex(wp->prev, 0, i - 1);
|
|
|
|
if (InsertStr(expanded)) {
|
|
|
|
xfree(expanded);
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_ERROR);
|
2007-03-11 22:33:41 +00:00
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
xfree(expanded);
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_dabbrev_expand(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* expand to preceding word matching prefix */
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *cp, *ncp, *bp;
|
|
|
|
struct Hist *hp;
|
2007-03-11 22:33:41 +00:00
|
|
|
int arg = 0, i;
|
|
|
|
size_t len = 0;
|
2005-04-24 19:41:08 +00:00
|
|
|
int found = 0;
|
2007-03-11 22:33:41 +00:00
|
|
|
Char *hbuf;
|
2000-04-15 04:41:27 +00:00
|
|
|
static int oldevent, hist, word;
|
|
|
|
static Char *start, *oldcursor;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
if (Argument <= 0)
|
|
|
|
return(CC_ERROR);
|
|
|
|
|
2001-09-05 17:49:32 +00:00
|
|
|
cp = c_preword(Cursor, InputBuf, 1, STRshwordsep);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (cp == Cursor || Isspace(*cp))
|
|
|
|
return(CC_ERROR);
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
hbuf = NULL;
|
2000-04-15 04:41:27 +00:00
|
|
|
hp = Histlist.Hnext;
|
|
|
|
bp = InputBuf;
|
|
|
|
if (Argument == 1 && eventno == oldevent && cp == start &&
|
2007-03-11 22:33:41 +00:00
|
|
|
Cursor == oldcursor && patbuf.len > 0
|
|
|
|
&& Strncmp(patbuf.s, cp, patbuf.len) == 0){
|
2000-04-15 04:41:27 +00:00
|
|
|
/* continue previous search - go to last match (hist/word) */
|
|
|
|
if (hist != 0) { /* need to move up history */
|
|
|
|
for (i = 1; i < hist && hp != NULL; i++)
|
|
|
|
hp = hp->Hnext;
|
|
|
|
if (hp == NULL) /* "can't happen" */
|
2007-03-11 22:33:41 +00:00
|
|
|
goto err_hbuf;
|
|
|
|
hbuf = expand_lex(&hp->Hlex, 0, INT_MAX);
|
|
|
|
cp = Strend(hbuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
bp = hbuf;
|
|
|
|
hp = hp->Hnext;
|
|
|
|
}
|
2001-09-05 17:49:32 +00:00
|
|
|
cp = c_preword(cp, bp, word, STRshwordsep);
|
2000-04-15 04:41:27 +00:00
|
|
|
} else { /* starting new search */
|
|
|
|
oldevent = eventno;
|
|
|
|
start = cp;
|
2007-03-11 22:33:41 +00:00
|
|
|
patbuf.len = 0;
|
|
|
|
Strbuf_appendn(&patbuf, cp, Cursor - cp);
|
2000-04-15 04:41:27 +00:00
|
|
|
hist = 0;
|
|
|
|
word = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!found) {
|
2001-09-05 17:49:32 +00:00
|
|
|
ncp = c_preword(cp, bp, 1, STRshwordsep);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (ncp == cp || Isspace(*ncp)) { /* beginning of line */
|
|
|
|
hist++;
|
|
|
|
word = 0;
|
|
|
|
if (hp == NULL)
|
2007-03-11 22:33:41 +00:00
|
|
|
goto err_hbuf;
|
|
|
|
hbuf = expand_lex(&hp->Hlex, 0, INT_MAX);
|
|
|
|
cp = Strend(hbuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
bp = hbuf;
|
|
|
|
hp = hp->Hnext;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
word++;
|
2007-03-11 22:33:41 +00:00
|
|
|
len = c_endword(ncp-1, cp, 1, STRshwordsep) - ncp + 1;
|
2000-04-15 04:41:27 +00:00
|
|
|
cp = ncp;
|
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
if (len > patbuf.len && Strncmp(cp, patbuf.s, patbuf.len) == 0) {
|
2000-04-15 04:41:27 +00:00
|
|
|
/* We don't fully check distinct matches as Gnuemacs does: */
|
|
|
|
if (Argument > 1) { /* just count matches */
|
|
|
|
if (++arg >= Argument)
|
|
|
|
found++;
|
|
|
|
} else { /* match if distinct from previous */
|
2007-03-11 22:33:41 +00:00
|
|
|
if (len != (size_t)(Cursor - start)
|
|
|
|
|| Strncmp(cp, start, len) != 0)
|
2000-04-15 04:41:27 +00:00
|
|
|
found++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LastChar + len - (Cursor - start) >= InputLim)
|
2007-03-11 22:33:41 +00:00
|
|
|
goto err_hbuf; /* no room */
|
2000-04-15 04:41:27 +00:00
|
|
|
DeleteBack(Cursor - start);
|
|
|
|
c_insert(len);
|
|
|
|
while (len--)
|
|
|
|
*Cursor++ = *cp++;
|
|
|
|
oldcursor = Cursor;
|
2007-03-11 22:33:41 +00:00
|
|
|
xfree(hbuf);
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_REFRESH);
|
2007-03-11 22:33:41 +00:00
|
|
|
|
|
|
|
err_hbuf:
|
|
|
|
xfree(hbuf);
|
|
|
|
return CC_ERROR;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_yank_kill(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* almost like GnuEmacs */
|
2001-09-05 17:49:32 +00:00
|
|
|
int len;
|
|
|
|
Char *kp, *cp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
2001-09-05 17:49:32 +00:00
|
|
|
if (KillRingLen == 0) /* nothing killed */
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_ERROR);
|
2001-09-05 17:49:32 +00:00
|
|
|
len = Strlen(KillRing[YankPos].buf);
|
|
|
|
if (LastChar + len >= InputLim)
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_ERROR); /* end of buffer space */
|
|
|
|
|
|
|
|
/* else */
|
|
|
|
cp = Cursor; /* for speed */
|
|
|
|
|
2001-09-05 17:49:32 +00:00
|
|
|
c_insert(len); /* open the space, */
|
|
|
|
for (kp = KillRing[YankPos].buf; *kp; kp++) /* copy the chars */
|
2000-04-15 04:41:27 +00:00
|
|
|
*cp++ = *kp;
|
|
|
|
|
2001-09-05 17:49:32 +00:00
|
|
|
if (Argument == 1) { /* if no arg */
|
|
|
|
Mark = Cursor; /* mark at beginning, cursor at end */
|
|
|
|
Cursor = cp;
|
|
|
|
} else {
|
|
|
|
Mark = cp; /* else cursor at beginning, mark at end */
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
if (adrof(STRhighlight) && MarkIsSet) {
|
|
|
|
ClearLines();
|
|
|
|
ClearDisp();
|
|
|
|
}
|
|
|
|
MarkIsSet = 0;
|
2001-09-05 17:49:32 +00:00
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_yank_pop(Char c)
|
2001-09-05 17:49:32 +00:00
|
|
|
{ /* almost like GnuEmacs */
|
|
|
|
int m_bef_c, del_len, ins_len;
|
|
|
|
Char *kp, *cp;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* XXX This "should" be here, but doesn't work, since LastCmd
|
|
|
|
gets set on CC_ERROR and CC_ARGHACK, which it shouldn't(?).
|
|
|
|
(But what about F_ARGFOUR?) I.e. if you hit M-y twice the
|
|
|
|
second one will "succeed" even if the first one wasn't preceded
|
|
|
|
by a yank, and giving an argument is impossible. Now we "succeed"
|
|
|
|
regardless of previous command, which is wrong too of course. */
|
|
|
|
if (LastCmd != F_YANK_KILL && LastCmd != F_YANK_POP)
|
|
|
|
return(CC_ERROR);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (KillRingLen == 0) /* nothing killed */
|
|
|
|
return(CC_ERROR);
|
|
|
|
YankPos -= Argument;
|
|
|
|
while (YankPos < 0)
|
|
|
|
YankPos += KillRingLen;
|
|
|
|
YankPos %= KillRingLen;
|
|
|
|
|
|
|
|
if (Cursor > Mark) {
|
|
|
|
del_len = Cursor - Mark;
|
|
|
|
m_bef_c = 1;
|
|
|
|
} else {
|
|
|
|
del_len = Mark - Cursor;
|
|
|
|
m_bef_c = 0;
|
|
|
|
}
|
|
|
|
ins_len = Strlen(KillRing[YankPos].buf);
|
|
|
|
if (LastChar + ins_len - del_len >= InputLim)
|
|
|
|
return(CC_ERROR); /* end of buffer space */
|
|
|
|
|
|
|
|
if (m_bef_c) {
|
|
|
|
c_delbefore(del_len);
|
|
|
|
} else {
|
|
|
|
c_delafter(del_len);
|
|
|
|
}
|
|
|
|
cp = Cursor; /* for speed */
|
|
|
|
|
|
|
|
c_insert(ins_len); /* open the space, */
|
|
|
|
for (kp = KillRing[YankPos].buf; *kp; kp++) /* copy the chars */
|
|
|
|
*cp++ = *kp;
|
|
|
|
|
|
|
|
if (m_bef_c) {
|
|
|
|
Mark = Cursor; /* mark at beginning, cursor at end */
|
|
|
|
Cursor = cp;
|
|
|
|
} else {
|
|
|
|
Mark = cp; /* else cursor at beginning, mark at end */
|
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
if (adrof(STRhighlight) && MarkIsSet) {
|
|
|
|
ClearLines();
|
|
|
|
ClearDisp();
|
|
|
|
}
|
|
|
|
MarkIsSet = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_delprev(Char c) /* Backspace key in insert mode */
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
rc = CC_ERROR;
|
|
|
|
|
|
|
|
if (InsertPos != 0) {
|
|
|
|
if (Argument <= Cursor - InsertPos) {
|
|
|
|
c_delbefore(Argument); /* delete before */
|
|
|
|
rc = CC_REFRESH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(rc);
|
|
|
|
} /* v_delprev */
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_delprev(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor > InputBuf) {
|
|
|
|
c_delbefore(Argument); /* delete before dot */
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_delwordprev(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *cp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == InputBuf)
|
|
|
|
return(CC_ERROR);
|
|
|
|
/* else */
|
|
|
|
|
|
|
|
cp = c_prev_word(Cursor, InputBuf, Argument);
|
|
|
|
|
2001-09-05 17:49:32 +00:00
|
|
|
c_push_kill(cp, Cursor); /* save the text */
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
c_delbefore((int)(Cursor - cp)); /* delete before dot */
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DCS <dcs@neutron.chem.yale.edu>, 9 Oct 93
|
|
|
|
*
|
|
|
|
* Changed the names of some of the ^D family of editor functions to
|
|
|
|
* correspond to what they actually do and created new e_delnext_list
|
|
|
|
* for completeness.
|
|
|
|
*
|
|
|
|
* Old names: New names:
|
|
|
|
*
|
|
|
|
* delete-char delete-char-or-eof
|
|
|
|
* F_DELNEXT F_DELNEXT_EOF
|
|
|
|
* e_delnext e_delnext_eof
|
|
|
|
* edelnxt edelnxteof
|
|
|
|
* delete-char-or-eof delete-char
|
|
|
|
* F_DELNEXT_EOF F_DELNEXT
|
|
|
|
* e_delnext_eof e_delnext
|
|
|
|
* edelnxteof edelnxt
|
|
|
|
* delete-char-or-list delete-char-or-list-or-eof
|
|
|
|
* F_LIST_DELNEXT F_DELNEXT_LIST_EOF
|
|
|
|
* e_list_delnext e_delnext_list_eof
|
|
|
|
* edellsteof
|
|
|
|
* (no old equivalent) delete-char-or-list
|
|
|
|
* F_DELNEXT_LIST
|
|
|
|
* e_delnext_list
|
|
|
|
* e_delnxtlst
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* added by mtk@ari.ncl.omron.co.jp (920818) */
|
|
|
|
/* rename e_delnext() -> e_delnext_eof() */
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_delnext(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == LastChar) {/* if I'm at the end */
|
|
|
|
if (!VImode) {
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (Cursor != InputBuf)
|
|
|
|
Cursor--;
|
|
|
|
else
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c_delafter(Argument); /* delete after dot */
|
|
|
|
if (Cursor > LastChar)
|
|
|
|
Cursor = LastChar; /* bounds check */
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_delnext_eof(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == LastChar) {/* if I'm at the end */
|
|
|
|
if (!VImode) {
|
|
|
|
if (Cursor == InputBuf) {
|
|
|
|
/* if I'm also at the beginning */
|
|
|
|
so_write(STReof, 4);/* then do a EOF */
|
|
|
|
flush();
|
|
|
|
return(CC_EOF);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (Cursor != InputBuf)
|
|
|
|
Cursor--;
|
|
|
|
else
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c_delafter(Argument); /* delete after dot */
|
|
|
|
if (Cursor > LastChar)
|
|
|
|
Cursor = LastChar; /* bounds check */
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_delnext_list(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == LastChar) { /* if I'm at the end */
|
|
|
|
PastBottom();
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_LIST_CHOICES);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
c_delafter(Argument); /* delete after dot */
|
|
|
|
if (Cursor > LastChar)
|
|
|
|
Cursor = LastChar; /* bounds check */
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_delnext_list_eof(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == LastChar) { /* if I'm at the end */
|
|
|
|
if (Cursor == InputBuf) { /* if I'm also at the beginning */
|
|
|
|
so_write(STReof, 4);/* then do a EOF */
|
|
|
|
flush();
|
|
|
|
return(CC_EOF);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PastBottom();
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return(CC_LIST_CHOICES);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
c_delafter(Argument); /* delete after dot */
|
|
|
|
if (Cursor > LastChar)
|
|
|
|
Cursor = LastChar; /* bounds check */
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_list_eof(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
CCRETVAL rv;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == LastChar && Cursor == InputBuf) {
|
|
|
|
so_write(STReof, 4); /* then do a EOF */
|
|
|
|
flush();
|
|
|
|
rv = CC_EOF;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PastBottom();
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
rv = CC_LIST_CHOICES;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_delwordnext(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *cp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == LastChar)
|
|
|
|
return(CC_ERROR);
|
|
|
|
/* else */
|
|
|
|
|
|
|
|
cp = c_next_word(Cursor, LastChar, Argument);
|
|
|
|
|
2001-09-05 17:49:32 +00:00
|
|
|
c_push_kill(Cursor, cp); /* save the text */
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
c_delafter((int)(cp - Cursor)); /* delete after dot */
|
|
|
|
if (Cursor > LastChar)
|
|
|
|
Cursor = LastChar; /* bounds check */
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_toend(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
Cursor = LastChar;
|
|
|
|
if (VImode)
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
RefCursor(); /* move the cursor */
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_tobeg(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
Cursor = InputBuf;
|
|
|
|
|
|
|
|
if (VImode) {
|
|
|
|
while (Isspace(*Cursor)) /* We want FIRST non space character */
|
|
|
|
Cursor++;
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RefCursor(); /* move the cursor */
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_killend(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
2001-09-05 17:49:32 +00:00
|
|
|
c_push_kill(Cursor, LastChar); /* copy it */
|
2007-03-11 22:33:41 +00:00
|
|
|
LastChar = Cursor; /* zap! -- delete to end */
|
|
|
|
if (Mark > Cursor)
|
|
|
|
Mark = Cursor;
|
|
|
|
MarkIsSet = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_killbeg(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
2001-09-05 17:49:32 +00:00
|
|
|
c_push_kill(InputBuf, Cursor); /* copy it */
|
2000-04-15 04:41:27 +00:00
|
|
|
c_delbefore((int)(Cursor - InputBuf));
|
2005-04-24 19:41:08 +00:00
|
|
|
if (Mark && Mark > Cursor)
|
|
|
|
Mark -= Cursor-InputBuf;
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_killall(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
2001-09-05 17:49:32 +00:00
|
|
|
c_push_kill(InputBuf, LastChar); /* copy it */
|
2005-04-24 19:41:08 +00:00
|
|
|
Cursor = Mark = LastChar = InputBuf; /* zap! -- delete all of it */
|
2007-03-11 22:33:41 +00:00
|
|
|
MarkIsSet = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_killregion(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (!Mark)
|
|
|
|
return(CC_ERROR);
|
|
|
|
|
|
|
|
if (Mark > Cursor) {
|
2001-09-05 17:49:32 +00:00
|
|
|
c_push_kill(Cursor, Mark); /* copy it */
|
|
|
|
c_delafter((int)(Mark - Cursor)); /* delete it - UNUSED BY VI mode */
|
|
|
|
Mark = Cursor;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
else { /* mark is before cursor */
|
2001-09-05 17:49:32 +00:00
|
|
|
c_push_kill(Mark, Cursor); /* copy it */
|
|
|
|
c_delbefore((int)(Cursor - Mark));
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
2007-03-11 22:33:41 +00:00
|
|
|
if (adrof(STRhighlight) && MarkIsSet) {
|
|
|
|
ClearLines();
|
|
|
|
ClearDisp();
|
|
|
|
}
|
|
|
|
MarkIsSet = 0;
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_copyregion(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (!Mark)
|
|
|
|
return(CC_ERROR);
|
|
|
|
|
|
|
|
if (Mark > Cursor) {
|
2001-09-05 17:49:32 +00:00
|
|
|
c_push_kill(Cursor, Mark); /* copy it */
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
else { /* mark is before cursor */
|
2001-09-05 17:49:32 +00:00
|
|
|
c_push_kill(Mark, Cursor); /* copy it */
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
return(CC_NORM); /* don't even need to Refresh() */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_charswitch(Char cc)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
Char c;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(cc);
|
|
|
|
|
|
|
|
/* do nothing if we are at beginning of line or have only one char */
|
|
|
|
if (Cursor == &InputBuf[0] || LastChar == &InputBuf[1]) {
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Cursor < LastChar) {
|
|
|
|
Cursor++;
|
|
|
|
}
|
|
|
|
c = Cursor[-2];
|
|
|
|
Cursor[-2] = Cursor[-1];
|
|
|
|
Cursor[-1] = c;
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_gcharswitch(Char cc)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* gosmacs style ^T */
|
2001-09-05 17:49:32 +00:00
|
|
|
Char c;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(cc);
|
|
|
|
if (Cursor > &InputBuf[1]) {/* must have at least two chars entered */
|
|
|
|
c = Cursor[-2];
|
|
|
|
Cursor[-2] = Cursor[-1];
|
|
|
|
Cursor[-1] = c;
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_charback(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor > InputBuf) {
|
2007-03-11 22:33:41 +00:00
|
|
|
if (Argument > Cursor - InputBuf)
|
2000-04-15 04:41:27 +00:00
|
|
|
Cursor = InputBuf;
|
|
|
|
else
|
2007-03-11 22:33:41 +00:00
|
|
|
Cursor -= Argument;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (VImode)
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_wordback(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == InputBuf)
|
|
|
|
return(CC_ERROR);
|
|
|
|
/* else */
|
|
|
|
|
2001-09-05 17:49:32 +00:00
|
|
|
Cursor = c_preword(Cursor, InputBuf, Argument, STRshwspace); /* bounds check */
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_wordback(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == InputBuf)
|
|
|
|
return(CC_ERROR);
|
|
|
|
/* else */
|
|
|
|
|
|
|
|
Cursor = c_prev_word(Cursor, InputBuf, Argument); /* bounds check */
|
|
|
|
|
|
|
|
if (VImode)
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_charfwd(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor < LastChar) {
|
2007-03-11 22:33:41 +00:00
|
|
|
Cursor += Argument;
|
2000-04-15 04:41:27 +00:00
|
|
|
if (Cursor > LastChar)
|
|
|
|
Cursor = LastChar;
|
|
|
|
|
|
|
|
if (VImode)
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_wordfwd(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == LastChar)
|
|
|
|
return(CC_ERROR);
|
|
|
|
/* else */
|
|
|
|
|
|
|
|
Cursor = c_next_word(Cursor, LastChar, Argument);
|
|
|
|
|
|
|
|
if (VImode)
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_wordfwd(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == LastChar)
|
|
|
|
return(CC_ERROR);
|
|
|
|
/* else */
|
|
|
|
|
|
|
|
Cursor = c_nexword(Cursor, LastChar, Argument);
|
|
|
|
|
|
|
|
if (VImode)
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_wordbegnext(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == LastChar)
|
|
|
|
return(CC_ERROR);
|
|
|
|
/* else */
|
|
|
|
|
|
|
|
Cursor = c_next_word(Cursor, LastChar, Argument);
|
|
|
|
if (Cursor < LastChar)
|
|
|
|
Cursor++;
|
|
|
|
|
|
|
|
if (VImode)
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_repeat_srch(int c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
CCRETVAL rv = CC_ERROR;
|
|
|
|
#ifdef SDEBUG
|
2007-03-11 22:33:41 +00:00
|
|
|
xprintf("dir %d patlen %d patbuf %S\n",
|
|
|
|
c, (int)patbuf.len, patbuf.s);
|
2000-04-15 04:41:27 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
LastCmd = (KEYCMD) c; /* Hack to stop c_hsetpat */
|
|
|
|
LastChar = InputBuf;
|
|
|
|
switch (c) {
|
|
|
|
case F_DOWN_SEARCH_HIST:
|
|
|
|
rv = e_down_search_hist(0);
|
|
|
|
break;
|
|
|
|
case F_UP_SEARCH_HIST:
|
|
|
|
rv = e_up_search_hist(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_csearch_back(Char ch, int count, int tflag)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char *cp;
|
|
|
|
|
|
|
|
cp = Cursor;
|
|
|
|
while (count--) {
|
|
|
|
if (*cp == ch)
|
|
|
|
cp--;
|
|
|
|
while (cp > InputBuf && *cp != ch)
|
|
|
|
cp--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cp < InputBuf || (cp == InputBuf && *cp != ch))
|
|
|
|
return(CC_ERROR);
|
|
|
|
|
|
|
|
if (*cp == ch && tflag)
|
|
|
|
cp++;
|
|
|
|
|
|
|
|
Cursor = cp;
|
|
|
|
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
Cursor++;
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
static CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_csearch_fwd(Char ch, int count, int tflag)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char *cp;
|
|
|
|
|
|
|
|
cp = Cursor;
|
|
|
|
while (count--) {
|
|
|
|
if(*cp == ch)
|
|
|
|
cp++;
|
|
|
|
while (cp < LastChar && *cp != ch)
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cp >= LastChar)
|
|
|
|
return(CC_ERROR);
|
|
|
|
|
|
|
|
if (*cp == ch && tflag)
|
|
|
|
cp--;
|
|
|
|
|
|
|
|
Cursor = cp;
|
|
|
|
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
Cursor++;
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_action(int c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *cp, *kp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (ActionFlag == TCSHOP_DELETE) {
|
|
|
|
ActionFlag = TCSHOP_NOP;
|
|
|
|
ActionPos = 0;
|
|
|
|
|
|
|
|
UndoSize = 0;
|
|
|
|
kp = UndoBuf;
|
|
|
|
for (cp = InputBuf; cp < LastChar; cp++) {
|
|
|
|
*kp++ = *cp;
|
|
|
|
UndoSize++;
|
|
|
|
}
|
|
|
|
|
|
|
|
UndoAction = TCSHOP_INSERT;
|
|
|
|
UndoPtr = InputBuf;
|
|
|
|
LastChar = InputBuf;
|
|
|
|
Cursor = InputBuf;
|
|
|
|
if (c & TCSHOP_INSERT)
|
|
|
|
c_alternativ_key_map(0);
|
|
|
|
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
#ifdef notdef
|
|
|
|
else if (ActionFlag == TCSHOP_NOP) {
|
|
|
|
#endif
|
|
|
|
ActionPos = Cursor;
|
|
|
|
ActionFlag = c;
|
|
|
|
return(CC_ARGHACK); /* Do NOT clear out argument */
|
|
|
|
#ifdef notdef
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ActionFlag = 0;
|
|
|
|
ActionPos = 0;
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef COMMENT
|
|
|
|
/* by: Brian Allison <uiucdcs!convex!allison@RUTGERS.EDU> */
|
|
|
|
static void
|
2007-03-11 22:33:41 +00:00
|
|
|
c_get_word(Char **begin, Char **end)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char *cp;
|
|
|
|
|
|
|
|
cp = &Cursor[0];
|
|
|
|
while (Argument--) {
|
|
|
|
while ((cp <= LastChar) && (isword(*cp)))
|
|
|
|
cp++;
|
|
|
|
*end = --cp;
|
|
|
|
while ((cp >= InputBuf) && (isword(*cp)))
|
|
|
|
cp--;
|
|
|
|
*begin = ++cp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* COMMENT */
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_uppercase(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char *cp, *end;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
end = c_next_word(Cursor, LastChar, Argument);
|
|
|
|
|
|
|
|
for (cp = Cursor; cp < end; cp++) /* PWP: was cp=begin */
|
|
|
|
if (Islower(*cp))
|
|
|
|
*cp = Toupper(*cp);
|
|
|
|
|
|
|
|
Cursor = end;
|
|
|
|
if (Cursor > LastChar)
|
|
|
|
Cursor = LastChar;
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_capitolcase(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char *cp, *end;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
end = c_next_word(Cursor, LastChar, Argument);
|
|
|
|
|
|
|
|
cp = Cursor;
|
|
|
|
for (; cp < end; cp++) {
|
|
|
|
if (Isalpha(*cp)) {
|
|
|
|
if (Islower(*cp))
|
|
|
|
*cp = Toupper(*cp);
|
|
|
|
cp++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (; cp < end; cp++)
|
|
|
|
if (Isupper(*cp))
|
|
|
|
*cp = Tolower(*cp);
|
|
|
|
|
|
|
|
Cursor = end;
|
|
|
|
if (Cursor > LastChar)
|
|
|
|
Cursor = LastChar;
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_lowercase(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char *cp, *end;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
end = c_next_word(Cursor, LastChar, Argument);
|
|
|
|
|
|
|
|
for (cp = Cursor; cp < end; cp++)
|
|
|
|
if (Isupper(*cp))
|
|
|
|
*cp = Tolower(*cp);
|
|
|
|
|
|
|
|
Cursor = end;
|
|
|
|
if (Cursor > LastChar)
|
|
|
|
Cursor = LastChar;
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_set_mark(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
2007-03-11 22:33:41 +00:00
|
|
|
if (adrof(STRhighlight) && MarkIsSet && Mark != Cursor) {
|
|
|
|
ClearLines();
|
|
|
|
ClearDisp();
|
|
|
|
Refresh();
|
|
|
|
}
|
2000-04-15 04:41:27 +00:00
|
|
|
Mark = Cursor;
|
2007-03-11 22:33:41 +00:00
|
|
|
MarkIsSet = 1;
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_exchange_mark(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *cp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
|
|
|
cp = Cursor;
|
|
|
|
Cursor = Mark;
|
|
|
|
Mark = cp;
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_argfour(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* multiply current argument by 4 */
|
|
|
|
USE(c);
|
|
|
|
if (Argument > 1000000)
|
|
|
|
return CC_ERROR;
|
|
|
|
DoingArg = 1;
|
|
|
|
Argument *= 4;
|
|
|
|
return(CC_ARGHACK);
|
|
|
|
}
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
static void
|
|
|
|
quote_mode_cleanup(void *unused)
|
|
|
|
{
|
|
|
|
USE(unused);
|
|
|
|
QuoteModeOff();
|
|
|
|
}
|
|
|
|
|
2000-04-15 04:41:27 +00:00
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_quote(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char ch;
|
|
|
|
int num;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
QuoteModeOn();
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_push(&c, quote_mode_cleanup); /* Using &c just as a mark */
|
2000-04-15 04:41:27 +00:00
|
|
|
num = GetNextChar(&ch);
|
2007-03-11 22:33:41 +00:00
|
|
|
cleanup_until(&c);
|
2000-04-15 04:41:27 +00:00
|
|
|
if (num == 1)
|
|
|
|
return e_insert(ch);
|
|
|
|
else
|
|
|
|
return e_send_eof(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_metanext(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
MetaNext = 1;
|
|
|
|
return(CC_ARGHACK); /* preserve argument */
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef notdef
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_extendnext(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
CurrentKeyMap = CcAltMap;
|
|
|
|
return(CC_ARGHACK); /* preserve argument */
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_insbeg(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* move to beginning of line and start vi
|
|
|
|
* insert mode */
|
|
|
|
USE(c);
|
|
|
|
Cursor = InputBuf;
|
|
|
|
InsertPos = Cursor;
|
|
|
|
|
|
|
|
UndoPtr = Cursor;
|
|
|
|
UndoAction = TCSHOP_DELETE;
|
|
|
|
|
|
|
|
RefCursor(); /* move the cursor */
|
|
|
|
c_alternativ_key_map(0);
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_replone(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* vi mode overwrite one character */
|
|
|
|
USE(c);
|
|
|
|
c_alternativ_key_map(0);
|
|
|
|
inputmode = MODE_REPLACE_1;
|
|
|
|
UndoAction = TCSHOP_CHANGE; /* Set Up for VI undo command */
|
|
|
|
UndoPtr = Cursor;
|
|
|
|
UndoSize = 0;
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_replmode(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* vi mode start overwriting */
|
|
|
|
USE(c);
|
|
|
|
c_alternativ_key_map(0);
|
|
|
|
inputmode = MODE_REPLACE;
|
|
|
|
UndoAction = TCSHOP_CHANGE; /* Set Up for VI undo command */
|
|
|
|
UndoPtr = Cursor;
|
|
|
|
UndoSize = 0;
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_substchar(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* vi mode substitute for one char */
|
|
|
|
USE(c);
|
|
|
|
c_delafter(Argument);
|
|
|
|
c_alternativ_key_map(0);
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_substline(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* vi mode replace whole line */
|
|
|
|
USE(c);
|
|
|
|
(void) e_killall(0);
|
|
|
|
c_alternativ_key_map(0);
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_chgtoend(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* vi mode change to end of line */
|
|
|
|
USE(c);
|
|
|
|
(void) e_killend(0);
|
|
|
|
c_alternativ_key_map(0);
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_insert(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* vi mode start inserting */
|
|
|
|
USE(c);
|
|
|
|
c_alternativ_key_map(0);
|
|
|
|
|
|
|
|
InsertPos = Cursor;
|
|
|
|
UndoPtr = Cursor;
|
|
|
|
UndoAction = TCSHOP_DELETE;
|
|
|
|
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_add(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* vi mode start adding */
|
|
|
|
USE(c);
|
|
|
|
c_alternativ_key_map(0);
|
|
|
|
if (Cursor < LastChar)
|
|
|
|
{
|
|
|
|
Cursor++;
|
|
|
|
if (Cursor > LastChar)
|
|
|
|
Cursor = LastChar;
|
|
|
|
RefCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
InsertPos = Cursor;
|
|
|
|
UndoPtr = Cursor;
|
|
|
|
UndoAction = TCSHOP_DELETE;
|
|
|
|
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_addend(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* vi mode to add at end of line */
|
|
|
|
USE(c);
|
|
|
|
c_alternativ_key_map(0);
|
|
|
|
Cursor = LastChar;
|
|
|
|
|
|
|
|
InsertPos = LastChar; /* Mark where insertion begins */
|
|
|
|
UndoPtr = LastChar;
|
|
|
|
UndoAction = TCSHOP_DELETE;
|
|
|
|
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_change_case(Char cc)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2005-04-24 19:41:08 +00:00
|
|
|
Char c;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(cc);
|
|
|
|
if (Cursor < LastChar) {
|
2000-11-30 21:05:33 +00:00
|
|
|
#ifndef WINNT_NATIVE
|
2000-04-15 04:41:27 +00:00
|
|
|
c = *Cursor;
|
|
|
|
#else
|
|
|
|
c = CHAR & *Cursor;
|
2000-11-30 21:05:33 +00:00
|
|
|
#endif /* WINNT_NATIVE */
|
2000-04-15 04:41:27 +00:00
|
|
|
if (Isupper(c))
|
|
|
|
*Cursor++ = Tolower(c);
|
|
|
|
else if (Islower(c))
|
|
|
|
*Cursor++ = Toupper(c);
|
|
|
|
else
|
|
|
|
Cursor++;
|
2005-04-24 19:41:08 +00:00
|
|
|
RefPlusOne(1); /* fast refresh for one char */
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_expand(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *p;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
|
|
|
for (p = InputBuf; Isspace(*p); p++)
|
|
|
|
continue;
|
|
|
|
if (p == LastChar)
|
|
|
|
return(CC_ERROR);
|
|
|
|
|
|
|
|
justpr++;
|
|
|
|
Expand++;
|
|
|
|
return(e_newline(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_startover(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{ /* erase all of current line, start again */
|
|
|
|
USE(c);
|
|
|
|
ResetInLine(0); /* reset the input pointers */
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_redisp(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
ClearLines();
|
|
|
|
ClearDisp();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_cleardisp(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
ClearScreen(); /* clear the whole real screen */
|
|
|
|
ClearDisp(); /* reset everything */
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_tty_int(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
2000-11-30 21:05:33 +00:00
|
|
|
#if defined(_MINIX) || defined(WINNT_NATIVE)
|
2000-04-15 04:41:27 +00:00
|
|
|
/* SAK PATCH: erase all of current line, start again */
|
|
|
|
ResetInLine(0); /* reset the input pointers */
|
|
|
|
xputchar('\n');
|
|
|
|
ClearDisp();
|
|
|
|
return (CC_REFRESH);
|
2000-11-30 21:05:33 +00:00
|
|
|
#else /* !_MINIX && !WINNT_NATIVE */
|
2000-04-15 04:41:27 +00:00
|
|
|
/* do no editing */
|
|
|
|
return (CC_NORM);
|
2000-11-30 21:05:33 +00:00
|
|
|
#endif /* _MINIX || WINNT_NATIVE */
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* From: ghazi@cesl.rutgers.edu (Kaveh R. Ghazi)
|
|
|
|
* Function to send a character back to the input stream in cooked
|
|
|
|
* mode. Only works if we have TIOCSTI
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_stuff_char(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
#ifdef TIOCSTI
|
|
|
|
int was_raw = Tty_raw_mode;
|
2005-04-24 19:41:08 +00:00
|
|
|
char buf[MB_LEN_MAX];
|
|
|
|
size_t i, len;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (was_raw)
|
|
|
|
(void) Cookedmode();
|
|
|
|
|
2007-03-11 22:33:41 +00:00
|
|
|
(void) xwrite(SHIN, "\n", 1);
|
2005-04-24 19:41:08 +00:00
|
|
|
len = one_wctomb(buf, c & CHAR);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
(void) ioctl(SHIN, TIOCSTI, (ioctl_t) &buf[i]);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (was_raw)
|
2007-03-11 22:33:41 +00:00
|
|
|
(void) Rawmode();
|
2000-04-15 04:41:27 +00:00
|
|
|
return(e_redisp(c));
|
|
|
|
#else /* !TIOCSTI */
|
|
|
|
return(CC_ERROR);
|
|
|
|
#endif /* !TIOCSTI */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_insovr(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
inputmode = (inputmode == MODE_INSERT ? MODE_REPLACE : MODE_INSERT);
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_tty_dsusp(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
/* do no editing */
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_tty_flusho(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
/* do no editing */
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_tty_quit(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
/* do no editing */
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_tty_tsusp(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
/* do no editing */
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_tty_stopo(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
/* do no editing */
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
2009-07-10 21:47:20 +00:00
|
|
|
/* returns the number of (attempted) expansions */
|
|
|
|
int
|
|
|
|
ExpandHistory(void)
|
|
|
|
{
|
|
|
|
*LastChar = '\0'; /* just in case */
|
|
|
|
return c_substitute();
|
|
|
|
}
|
|
|
|
|
2000-04-15 04:41:27 +00:00
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_expand_history(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
2009-07-10 21:47:20 +00:00
|
|
|
(void)ExpandHistory();
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_magic_space(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
*LastChar = '\0'; /* just in case */
|
2009-07-10 21:47:20 +00:00
|
|
|
(void)c_substitute();
|
2000-04-15 04:41:27 +00:00
|
|
|
return(e_insert(' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_inc_fwd(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2007-03-11 22:33:41 +00:00
|
|
|
CCRETVAL ret;
|
|
|
|
|
2000-04-15 04:41:27 +00:00
|
|
|
USE(c);
|
2007-03-11 22:33:41 +00:00
|
|
|
patbuf.len = 0;
|
|
|
|
MarkIsSet = 0;
|
|
|
|
ret = e_inc_search(F_DOWN_SEARCH_HIST);
|
|
|
|
if (adrof(STRhighlight) && IncMatchLen) {
|
|
|
|
IncMatchLen = 0;
|
|
|
|
ClearLines();
|
|
|
|
ClearDisp();
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
IncMatchLen = 0;
|
|
|
|
return ret;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_inc_back(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2007-03-11 22:33:41 +00:00
|
|
|
CCRETVAL ret;
|
|
|
|
|
2000-04-15 04:41:27 +00:00
|
|
|
USE(c);
|
2007-03-11 22:33:41 +00:00
|
|
|
patbuf.len = 0;
|
|
|
|
MarkIsSet = 0;
|
|
|
|
ret = e_inc_search(F_UP_SEARCH_HIST);
|
|
|
|
if (adrof(STRhighlight) && IncMatchLen) {
|
|
|
|
IncMatchLen = 0;
|
|
|
|
ClearLines();
|
|
|
|
ClearDisp();
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
IncMatchLen = 0;
|
|
|
|
return ret;
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_copyprev(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
Char *cp, *oldc, *dp;
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == InputBuf)
|
|
|
|
return(CC_ERROR);
|
|
|
|
/* else */
|
|
|
|
|
|
|
|
oldc = Cursor;
|
|
|
|
/* does a bounds check */
|
|
|
|
cp = c_prev_word(Cursor, InputBuf, Argument);
|
|
|
|
|
|
|
|
c_insert((int)(oldc - cp));
|
|
|
|
for (dp = oldc; cp < oldc && dp < LastChar; cp++)
|
|
|
|
*dp++ = *cp;
|
|
|
|
|
|
|
|
Cursor = dp; /* put cursor at end */
|
|
|
|
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_tty_starto(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
/* do no editing */
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_load_average(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
PastBottom();
|
|
|
|
#ifdef TIOCSTAT
|
|
|
|
/*
|
|
|
|
* Here we pass &c to the ioctl because some os's (NetBSD) expect it
|
|
|
|
* there even if they don't use it. (lukem@netbsd.org)
|
|
|
|
*/
|
|
|
|
if (ioctl(SHIN, TIOCSTAT, (ioctl_t) &c) < 0)
|
|
|
|
#endif
|
2009-07-10 21:47:20 +00:00
|
|
|
xprintf("%s", CGETS(5, 1, "Load average unavailable\n"));
|
2000-04-15 04:41:27 +00:00
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_chgmeta(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
/*
|
|
|
|
* Delete with insert == change: first we delete and then we leave in
|
|
|
|
* insert mode.
|
|
|
|
*/
|
|
|
|
return(v_action(TCSHOP_DELETE|TCSHOP_INSERT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_delmeta(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
return(v_action(TCSHOP_DELETE));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_endword(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == LastChar)
|
|
|
|
return(CC_ERROR);
|
|
|
|
/* else */
|
|
|
|
|
2001-09-05 17:49:32 +00:00
|
|
|
Cursor = c_endword(Cursor, LastChar, Argument, STRshwspace);
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
if (ActionFlag & TCSHOP_DELETE)
|
|
|
|
{
|
|
|
|
Cursor++;
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_eword(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (Cursor == LastChar)
|
|
|
|
return(CC_ERROR);
|
|
|
|
/* else */
|
|
|
|
|
|
|
|
Cursor = c_eword(Cursor, LastChar, Argument);
|
|
|
|
|
|
|
|
if (ActionFlag & TCSHOP_DELETE) {
|
|
|
|
Cursor++;
|
|
|
|
c_delfini();
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefCursor();
|
|
|
|
return(CC_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_char_fwd(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char ch;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
if (GetNextChar(&ch) != 1)
|
|
|
|
return e_send_eof(0);
|
|
|
|
|
|
|
|
srch_dir = CHAR_FWD;
|
|
|
|
srch_char = ch;
|
|
|
|
|
|
|
|
return v_csearch_fwd(ch, Argument, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_char_back(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char ch;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
if (GetNextChar(&ch) != 1)
|
|
|
|
return e_send_eof(0);
|
|
|
|
|
|
|
|
srch_dir = CHAR_BACK;
|
|
|
|
srch_char = ch;
|
|
|
|
|
|
|
|
return v_csearch_back(ch, Argument, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_charto_fwd(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char ch;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
if (GetNextChar(&ch) != 1)
|
|
|
|
return e_send_eof(0);
|
|
|
|
|
|
|
|
return v_csearch_fwd(ch, Argument, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_charto_back(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Char ch;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
if (GetNextChar(&ch) != 1)
|
|
|
|
return e_send_eof(0);
|
|
|
|
|
|
|
|
return v_csearch_back(ch, Argument, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_rchar_fwd(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (srch_char == 0)
|
|
|
|
return CC_ERROR;
|
|
|
|
|
|
|
|
return srch_dir == CHAR_FWD ? v_csearch_fwd(srch_char, Argument, 0) :
|
|
|
|
v_csearch_back(srch_char, Argument, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_rchar_back(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
if (srch_char == 0)
|
|
|
|
return CC_ERROR;
|
|
|
|
|
|
|
|
return srch_dir == CHAR_BACK ? v_csearch_fwd(srch_char, Argument, 0) :
|
|
|
|
v_csearch_back(srch_char, Argument, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_undo(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
2001-09-05 17:49:32 +00:00
|
|
|
int loop;
|
|
|
|
Char *kp, *cp;
|
2000-04-15 04:41:27 +00:00
|
|
|
Char temp;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
USE(c);
|
|
|
|
switch (UndoAction) {
|
|
|
|
case TCSHOP_DELETE|TCSHOP_INSERT:
|
|
|
|
case TCSHOP_DELETE:
|
|
|
|
if (UndoSize == 0) return(CC_NORM);
|
|
|
|
cp = UndoPtr;
|
|
|
|
kp = UndoBuf;
|
|
|
|
for (loop=0; loop < UndoSize; loop++) /* copy the chars */
|
|
|
|
*kp++ = *cp++; /* into UndoBuf */
|
|
|
|
|
|
|
|
for (cp = UndoPtr; cp <= LastChar; cp++)
|
|
|
|
*cp = cp[UndoSize];
|
|
|
|
|
|
|
|
LastChar -= UndoSize;
|
|
|
|
Cursor = UndoPtr;
|
|
|
|
|
|
|
|
UndoAction = TCSHOP_INSERT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TCSHOP_INSERT:
|
|
|
|
if (UndoSize == 0) return(CC_NORM);
|
|
|
|
cp = UndoPtr;
|
|
|
|
Cursor = UndoPtr;
|
|
|
|
kp = UndoBuf;
|
|
|
|
c_insert(UndoSize); /* open the space, */
|
|
|
|
for (loop = 0; loop < UndoSize; loop++) /* copy the chars */
|
|
|
|
*cp++ = *kp++;
|
|
|
|
|
|
|
|
UndoAction = TCSHOP_DELETE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TCSHOP_CHANGE:
|
|
|
|
if (UndoSize == 0) return(CC_NORM);
|
|
|
|
cp = UndoPtr;
|
|
|
|
Cursor = UndoPtr;
|
|
|
|
kp = UndoBuf;
|
|
|
|
size = (int)(Cursor-LastChar); /* NOT NSL independant */
|
|
|
|
if (size < UndoSize)
|
|
|
|
size = UndoSize;
|
|
|
|
for(loop = 0; loop < size; loop++) {
|
|
|
|
temp = *kp;
|
|
|
|
*kp++ = *cp;
|
|
|
|
*cp++ = temp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return(CC_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(CC_REFRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_ush_meta(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
return v_search(F_UP_SEARCH_HIST);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_dsh_meta(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
return v_search(F_DOWN_SEARCH_HIST);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_rsrch_fwd(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
2007-03-11 22:33:41 +00:00
|
|
|
if (patbuf.len == 0) return(CC_ERROR);
|
2000-04-15 04:41:27 +00:00
|
|
|
return(v_repeat_srch(searchdir));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
v_rsrch_back(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
2007-03-11 22:33:41 +00:00
|
|
|
if (patbuf.len == 0) return(CC_ERROR);
|
2000-04-15 04:41:27 +00:00
|
|
|
return(v_repeat_srch(searchdir == F_UP_SEARCH_HIST ?
|
|
|
|
F_DOWN_SEARCH_HIST : F_UP_SEARCH_HIST));
|
|
|
|
}
|
|
|
|
|
2000-11-30 21:05:33 +00:00
|
|
|
#ifndef WINNT_NATIVE
|
2000-04-15 04:41:27 +00:00
|
|
|
/* Since ed.defns.h is generated from ed.defns.c, these empty
|
|
|
|
functions will keep the F_NUM_FNS consistent
|
|
|
|
*/
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_copy_to_clipboard(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
return CC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_paste_from_clipboard(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
return (CC_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_dosify_next(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
return (CC_ERROR);
|
|
|
|
}
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_dosify_prev(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
|
|
|
return (CC_ERROR);
|
|
|
|
}
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_page_up(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
2000-11-30 21:05:33 +00:00
|
|
|
return (CC_ERROR);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
|
|
|
CCRETVAL
|
2007-03-11 22:33:41 +00:00
|
|
|
e_page_down(Char c)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
USE(c);
|
2000-11-30 21:05:33 +00:00
|
|
|
return (CC_ERROR);
|
2000-04-15 04:41:27 +00:00
|
|
|
}
|
2000-11-30 21:05:33 +00:00
|
|
|
#endif /* !WINNT_NATIVE */
|
2000-04-15 04:41:27 +00:00
|
|
|
|
|
|
|
#ifdef notdef
|
|
|
|
void
|
2007-03-11 22:33:41 +00:00
|
|
|
MoveCursor(int n) /* move cursor + right - left char */
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
Cursor = Cursor + n;
|
|
|
|
if (Cursor < InputBuf)
|
|
|
|
Cursor = InputBuf;
|
|
|
|
if (Cursor > LastChar)
|
|
|
|
Cursor = LastChar;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Char *
|
2007-03-11 22:33:41 +00:00
|
|
|
GetCursor(void)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
return(Cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-11 22:33:41 +00:00
|
|
|
PutCursor(Char *p)
|
2000-04-15 04:41:27 +00:00
|
|
|
{
|
|
|
|
if (p < InputBuf || p > LastChar)
|
|
|
|
return 1; /* Error */
|
|
|
|
Cursor = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|