/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1984-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* David Korn <dgk@research.att.com> *
* Pat Sullivan *
* *
***********************************************************************/
/* Adapted for ksh by David Korn */
/*+ VI.C P.D. Sullivan
*
* One line editor for the shell based on the vi editor.
*
* Questions to:
* P.D. Sullivan
* cbosgd!pds
-*/
#ifdef KSHELL
# include "defs.h"
#else
# include "io.h"
#endif /* KSHELL */
#include "history.h"
#include "edit.h"
#include "terminal.h"
#ifdef OLDTERMIO
extern char echoctl;
#else
# ifdef ECHOCTL
# else
# define echoctl 0
# endif /* ECHOCTL */
#endif /*OLDTERMIO */
#ifndef FIORDCHK
# ifndef KSHELL
# ifdef _sys_times
# ifndef included_sys_times
# endif
# else
struct tms
{
};
# endif /* _sys_times */
# endif /* KSHELL */
#endif /* FIORDCHK */
/* WINDOW-2 are available to user */
/* actual window size may be smaller */
#ifdef MULTIBYTE
static int bigvi;
#else
#endif /* MULTIBYTE */
#ifdef INT16
/* save space by defining functions for these */
#endif /* INT16 */
#ifndef KSHELL
#endif /* KSHELL */
static char repeat_set;
static char nonewline;
#ifdef FIORDCHK
#else
#endif /* FIORDCHK */
static void del_line();
static int getcount();
static void getline();
static int getrchar();
static int mvcursor();
static void pr_prompt();
static void pr_string();
static void putstring();
static void refresh();
static void replace();
static void restore_v();
static void save_last();
static void save_v();
static int search();
static void sync_cursor();
static int textmod();
/*+ VI_READ( fd, shbuf, nchar )
*
* This routine implements a one line version of vi and is
* called by _filbuf.c
*
-*/
int fd; /* input file descriptor */
register char *shbuf; /* shell line buffer */
unsigned nchar; /* number of chars to read */
{
register int c; /* general variable */
register int i; /* general variable */
#ifndef FIORDCHK
#endif /* FIORDCHK */
/*** setup prompt ***/
#ifndef RAWONLY
{
/*** Change the eol characters to '\r' and eof ***/
/* in addition to '\n' and make eof an ESC */
{
}
# ifdef FIORDCHK
# else
/* time the current line to determine typeahead */
# endif /* FIORDCHK */
# ifdef KSHELL
/* abort of interrupt has occurred */
i = -1;
else
# endif /* KSHELL */
/*** Read the line ***/
# ifndef FIORDCHK
# endif /* FIORDCHK */
if(echoctl)
{
if( i <= 0 )
{
/*** read error or eof typed ***/
return(i);
}
if( term_char == '\r' )
term_char = '\n';
shbuf[i--] = '\0';
else
}
else
{
c = shbuf[0];
/*** Save and remove the last character if its an eol, ***/
/* changing '\r' to '\n' */
if( i == 0 )
{
/*** ESC was typed as first char of line ***/
esc_or_hang = 1;
}
else if( i<0 || c==usreof )
{
/*** read error or eof typed ***/
if( c == usreof )
i = 0;
return(i);
}
else
{
if( term_char == '\r' )
term_char = '\n';
if(term_char=='\n')
{
return(i+1);
}
#endif
{
/*** remove terminator & null terminate ***/
shbuf[i--] = '\0';
}
else
{
/** terminator was ESC, which is not xmitted **/
}
}
}
}
else
#endif /* RAWONLY */
{
/*** Set raw mode ***/
#ifndef RAWONLY
if( ttyspeed == 0 )
{
/*** never did TCGETA, so do it ***/
/* avoids problem if user does 'sh -o viraw' */
}
#endif /* RAWONLY */
{
}
i = INVALID;
}
/*** Initialize some things ***/
#ifdef MULTIBYTE
shbuf[i+1] = 0;
#endif /* MULTIBYTE */
cur_phys = i + 1;
cur_virt = i;
first_virt = 0;
first_wind = 0;
last_virt = i;
last_phys = i;
last_wind = i;
long_line = ' ';
long_char = ' ';
o_v_char = '\0';
ocur_phys = 0;
in_raw = 0;
ofirst_wind = 0;
window[0] = '\0';
#else
if(yankbuf==0)
#endif
#else
if(lastline==0)
#endif
if( last_cmd == '\0' )
{
/*** first time for this shell ***/
last_cmd = 'i';
lastmotion = '\0';
lastrepeat = 1;
repeat = 1;
*yankbuf = 0;
}
/*** fiddle around with prompt length ***/
#ifndef RAWONLY
{
int kill_erase = 0;
# ifndef ECHOCTL
int cntl_char = 0;
# endif /* !ECHOCTL */
{
/*** change \r to \n, check for control characters, ***/
/* delete appropriate ^Vs, */
/* and estimate last physical column */
if( virtual[i] == '\r' )
virtual[i] = '\n';
if(!echoctl)
{
c = virtual[i];
{
/*** user typed escaped erase or kill char ***/
# ifndef ECHOCTL
cntl_char = 1;
# endif /* !ECHOCTL */
if(is_print(c))
kill_erase++;
}
else if( !is_print(c) )
{
# ifndef ECHOCTL
cntl_char = 1;
# endif /* !ECHOCTL */
if( c == cntl('V') )
{
if( i == last_virt )
{
/* so replace ^V with it */
break;
}
/*** delete ^V ***/
--cur_virt;
--last_virt;
}
}
}
}
/*** copy virtual image to window ***/
if(last_virt > 0)
{
/*** line longer than window ***/
}
else
{
/*** Line not terminated with ESC or escaped (^V) ***/
/* eol, so return after doing a total update */
/* if( (speed is greater or equal to 1200 */
/* and something was typed) and */
/* (control character present */
/* or typeahead occurred) ) */
# ifdef ECHOCTL
&& typeahead)
# else
# endif /*ECHOCTL */
{
if(echoctl)
crlf;
else
while(kill_erase-- > 0)
putchar(' ');
}
if( term_char=='\n' )
{
if(!echoctl)
crlf;
}
last_cmd = 'i';
save_last();
#ifdef MULTIBYTE
return(last_virt);
#else
return(++last_virt);
#endif /* MULTIBYTE */
}
/* so set raw mode */
{
/*
* The following prevents drivers that return 0 on
* reads after disconnect (rather than -1), from
* causing an infinite loop
*/
if(esc_or_hang)
return(-1);
#ifdef MULTIBYTE
return(last_virt);
#else
return(++last_virt);
#endif /* MULTIBYTE */
}
if(echoctl) /*** for cntl-echo erase the ^[ ***/
pr_string("\b\b \b\b");
{
/*** start over since there may be ***/
/*** a control char, or cursor might not ***/
/*** be at left margin (this lets us know ***/
/*** where we are ***/
cur_phys = 0;
window[0] = '\0';
else
}
else
{
/*** just update everything internally ***/
}
}
else
#endif /* RAWONLY */
virtual[0] = '\0';
/*** Handle usrintr, usrquit, or EOF ***/
if(i !=0)
{
virtual[0] = '\0';
switch(i)
{
case UEOF:
/*** EOF ***/
return(0);
case UINTR:
/** interrupt **/
return(SYSERR);
}
return(SYSERR);
}
/*** Get a line from the terminal ***/
U_saved = 0;
#ifdef RAWONLY
#else
else
#endif /* RAWONLY */
/*** add a new line if user typed unescaped \n ***/
/* to cause the shell to process the line */
if( addnl )
{
crlf;
}
if( ++last_virt >= 0 )
{
#ifdef MULTIBYTE
if(bigvi)
{
bigvi = 0;
}
else
{
}
#endif /* MULTIBYTE */
return(last_virt);
}
else
return(SYSERR);
}
/*{ APPEND( char, mode )
*
* This routine will append char after cur_virt in the virtual image.
* mode = APPEND, shift chars right before appending
* REPLACE, replace char if possible
*
}*/
static void
int c;
int mode;
{
register int i;
{
{
{
}
}
}
else
bell;
return;
}
/*{ BACKWORD( nwords, cmd )
*
* This routine will position cur_virt at the nth previous word.
*
}*/
static void
int nwords;
register int cmd;
{
{
&& tcur_virt>first_virt )
--tcur_virt;
else if(cmd != 'B')
{
--tcur_virt;
}
--tcur_virt;
if( cmd == 'B' )
{
--tcur_virt;
}
else
{
--tcur_virt;
else
&& tcur_virt>=first_virt )
--tcur_virt;
}
}
return;
}
/*{ CNTLMODE()
*
* This routine implements the vi command subset.
* The cursor will always be positioned at the char of interest.
*
}*/
static int
cntlmode()
{
register int c;
register int i;
int was_inmacro;
if( !U_saved )
{
/*** save virtual image if never done before ***/
U_saved = 1;
}
save_last();
first_virt = 0;
repeat = 1;
{
/*** make sure cursor is at the last char ***/
sync_cursor();
}
/*** Read control char until something happens to cause a ***/
while( c=getchar() )
{
repeat_set = 0;
if( c == '0' )
{
/*** move to leftmost column ***/
cur_virt = 0;
sync_cursor();
continue;
}
if( digit(c) )
{
lastrepeat = repeat;
c = getcount(c);
if( c == '.' )
lastrepeat = repeat;
}
/*** see if it's a move cursor command ***/
{
sync_cursor();
repeat = 1;
continue;
}
/*** see if it's a repeat of the last command ***/
if( c == '.' )
{
c = last_cmd;
repeat = lastrepeat;
i = textmod(c, c);
}
else
{
i = textmod(c, 0);
}
/*** see if it's a text modification command ***/
switch(i)
{
case BAD:
break;
default: /** input mode **/
if(!was_inmacro)
{
last_cmd = c;
lastrepeat = repeat;
}
repeat = 1;
if( i == GOOD )
continue;
return(i);
}
switch( c )
{
/***** Other stuff *****/
/*** print the prompt and ***/
/* force a total refresh */
if(nonewline==0)
putchar('\n');
nonewline = 0;
window[0] = '\0';
long_line = ' ';
break;
case cntl('V'):
{
register const char *p = &e_version[5];
save_v();
while(c = *p++)
ed_getchar();
restore_v();
break;
}
case '/': /** Search **/
case '?':
case 'N':
case 'n':
save_v();
switch( search(c) )
{
case GOOD:
/*** force a total refresh ***/
window[0] = '\0';
goto newhist;
case BAD:
/*** no match ***/
bell;
default:
else
restore_v();
break;
}
break;
case 'j': /** get next command **/
case '+': /** get next command **/
{
goto ringbell;
}
{
restore_v();
break;
}
save_v();
goto newhist;
case 'k': /** get previous command **/
case '-': /** get previous command **/
{
i = u_column;
save_v();
u_column = i;
}
{
goto ringbell;
}
save_v();
#ifdef MULTIBYTE
#endif /* MULTIBYTE */
cur_virt = 0;
else
break;
case 'u': /** undo the last thing done **/
restore_v();
break;
case 'U': /** Undo everything **/
save_v();
if( virtual[0] == '\0' )
goto ringbell;
else
{
cur_virt = 0;
}
break;
#ifdef KSHELL
case 'v':
if(repeat_set==0)
goto vcommand;
#endif /* KSHELL */
case 'G': /** goto command repeat **/
if(repeat_set==0)
{
goto ringbell;
}
save_v();
if(c == 'G')
goto newhist;
#ifdef KSHELL
if(ed_fulledit()==GOOD)
return(BIGVI);
else
goto ringbell;
#endif /* KSHELL */
case '#': /** insert(delete) # to (no)comment command **/
{
*p = 0;
/*** see whether first char is comment char ***/
c = (virtual[0]=='#');
while(p-- >= virtual)
{
if(*p=='\n' || p<virtual)
{
if(c) /* delete '#' */
{
if(p[1]=='#')
{
last_virt--;
}
}
else
{
}
}
}
if(c)
{
cur_virt = 0;
break;
}
}
case '\n': /** send to shell **/
return(ENTER);
default:
bell;
repeat = 1;
continue;
}
repeat = 1;
}
return 0;
}
/*{ CURSOR( new_current_physical )
*
* This routine will position the virtual cursor at
* physical column x in the window.
*
}*/
static void
cursor(x)
register int x;
{
register int delta;
#ifdef MULTIBYTE
x++;
#endif /* MULTIBYTE */
if( delta == 0 )
return;
if( delta > 0 )
{
/*** move to right ***/
}
else
{
/*** move to left ***/
/*** attempt to optimize cursor movement ***/
{
while( delta-- )
putchar('\b');
}
else
{
}
}
cur_phys = x;
return;
}
/*{ DELETE( nchars, mode )
*
* Delete nchars from the virtual space and leave cur_virt positioned
* at cur_virt-1.
*
* If mode = 'c', do not save the characters deleted
* = 'd', save them in yankbuf and delete.
* = 'y', save them in yankbuf but do not delete.
*
}*/
static void
register int nchars;
char mode;
{
register int i;
if( cur_virt < first_virt )
{
bell;
return;
}
if( nchars > 0 )
{
{
/*** set nchars to number actually deleted ***/
}
/*** save characters to be deleted ***/
if( mode != 'c' )
{
}
/*** now delete these characters ***/
if( mode != 'y' )
{
}
}
return;
}
/*{ DEL_LINE( mode )
*
* This routine will delete the line.
* mode = GOOD, do a save_v()
*
}*/
static void
int mode;
{
return;
save_v();
cur_virt = 0;
first_virt = 0;
cur_phys = 0;
first_wind = 0;
o_v_char = '\0';
ocur_phys = 0;
ofirst_wind = 0;
window[0] = '\0';
return;
}
/*{ DELMOTION( motion, mode )
*
* Delete thru motion.
*
* mode = 'd', save deleted characters, delete
* = 'c', do not save characters, change
* = 'y', save characters, yank
*
* Returns GOOD if operation successful; else BAD.
*
}*/
static int
int motion;
char mode;
{
register int begin;
register int end;
/* the following saves a register */
return(BAD);
if( mode != 'y' )
save_v();
/*** fake out the motion routines by appending a blank ***/
return(BAD);
{
/*** called by change operation, user really expects ***/
/* the effect of the eE commands, so back up to end of word */
--end;
++end;
}
if( delta >= 0 )
{
++delta;
}
else
{
}
if( mode == 'y' )
return(GOOD);
}
/*{ ENDWORD( nwords, cmd )
*
* This routine will move cur_virt to the end of the nth word.
*
}*/
static void
int nwords;
register int cmd;
{
while( nwords-- )
{
++tcur_virt;
++tcur_virt;
if( cmd == 'E' )
{
++tcur_virt;
}
else
{
++tcur_virt;
else
++tcur_virt;
}
if( tcur_virt > first_virt )
tcur_virt--;
}
return;
}
/*{ FORWARD( nwords, cmd )
*
* This routine will move cur_virt forward to the next nth word.
*
}*/
static void
register int nwords;
char cmd;
{
while( nwords-- )
{
if( cmd == 'W' )
{
++tcur_virt;
}
else
{
{
++tcur_virt;
}
else
{
++tcur_virt;
}
}
++tcur_virt;
}
return;
}
/*{ GETCOUNT(c)
*
* Set repeat to the user typed number and return the terminating
* character.
*
}*/
static int
getcount(c)
register int c;
{
register int i;
/*** get any repeat count ***/
if( c == '0' )
return(c);
repeat_set++;
i = 0;
while( digit(c) )
{
i = i*10 + c - '0';
c = getchar();
}
if( i > 0 )
repeat *= i;
return(c);
}
/*{ GETLINE( mode )
*
* This routine will fetch a line.
* mode = APPEND, allow escape to cntlmode subroutine
* appending characters.
* = REPLACE, allow escape to cntlmode subroutine
* replacing characters.
* = SEARCH, no escape allowed
* = ESC, enter control mode immediately
*
* The cursor will always be positioned after the last
* char printed.
*
* This routine returns when cr, nl, or (eof in column 0) is
* received (column 0 is the first char position).
*
}*/
static void
register int mode;
{
register int c;
register int tmp;
addnl = 1;
{
/*** go directly to control mode ***/
goto escape;
}
for(;;)
{
{
/*** implement ^V to escape next char ***/
in_raw++;
c = getchar();
in_raw = 0;
continue;
}
if( c == usreof )
c = UEOF;
else if( c == usrerase )
c = UERASE;
else if( c == usrkill )
c = UKILL;
switch( c )
{
case ESC: /** enter control mode **/
{
bell;
continue;
}
else
{
--cur_virt;
{
#ifdef MULTIBYTE
#endif /* MULTIBYTE */
return;
}
{
continue;
}
}
break;
case UERASE: /** user erase char **/
/*** treat as backspace ***/
case '\b': /** backspace **/
{
}
else
{
{
first_virt = 0;
return;
}
}
break;
{
}
else
{
}
break;
case UKILL: /** user kill line char **/
{
}
else
{
{
cur_virt = 1;
}
else if(first_virt)
{
}
else
}
break;
case UEOF: /** eof char **/
continue;
addnl = 0;
case '\n': /** newline or return **/
save_last();
return;
default:
{
{
replace(c, 1);
continue;
}
}
break;
}
}
}
/*{ MVCURSOR( motion )
*
* This routine will move the virtual cursor according to motion
* for repeat times.
*
* It returns GOOD if successful; else BAD.
*
}*/
static int
register int motion;
{
register int count;
register int tcur_virt;
register int bound = 0;
switch(motion)
{
/***** Cursor move commands *****/
case '0': /** First column **/
tcur_virt = 0;
break;
case '^': /** First nonblank character **/
++tcur_virt;
break;
case '|':
break;
/* fall through */
case '$': /** End of line **/
break;
case 'h': /** Left one **/
case '\b':
motion = first_virt;
goto walk;
case ' ':
case 'l': /** Right one **/
incr = 1;
walk:
{
}
else
{
return(BAD);
}
break;
case 'B':
case 'b': /** back word **/
return(BAD);
return(GOOD);
case 'E':
case 'e': /** end of word **/
if(tcur_virt >=0)
return(BAD);
return(GOOD);
case ',': /** reverse find old char **/
case ';': /** find old char **/
switch(last_find)
{
case 't':
case 'f':
if(motion==';')
{
incr = 1;
}
goto find_b;
case 'T':
case 'F':
if(motion==',')
{
incr = 1;
}
goto find_b;
default:
return(BAD);
}
case 't': /** find up to new char forward **/
case 'f': /** find new char forward **/
incr = 1;
case 'T': /** find up to new char backward **/
case 'F': /** find new char backward **/
return(GOOD);
while( count-- )
{
{
return(BAD);
}
}
break;
/* new, undocumented feature */
case '%':
{
int nextmotion;
int nextc;
tcur_virt++;
return(BAD);
if(count < 3)
{
incr = 1;
}
else
count = 1;
{
count--;
count++;
}
if(count)
return(BAD);
break;
}
case 'W':
case 'w': /** forward word **/
return(BAD);
return(GOOD);
default:
return(BAD);
}
return(GOOD);
}
/*
* print a string
*/
static void
pr_string(s)
register char *s;
{
/*** copy string s ***/
while(*s)
*ptr++ = *s++;
return;
}
/*{ PUTSTRING( column, nchars )
*
* Put nchars starting at column of physical into the workspace
* to be printed.
*
}*/
static void
register int col;
register int nchars;
{
while( nchars-- )
return;
}
/*{ REFRESH( mode )
*
* This routine will refresh the crt so the physical image matches
* the virtual image and display the proper window.
*
* mode = CONTROL, refresh in control mode, ie. leave cursor
* positioned at last char printed.
* = INPUT, refresh in input mode; leave cursor positioned
* after last char printed.
* = TRANSLATE, perform virtual to physical translation
* and adjust left margin only.
*
* +-------------------------------+
* | | | virtual | | |
* +-------------------------------+
* cur_virt last_virt
*
* +-----------------------------------------------+
* | | | physical | | |
* +-----------------------------------------------+
* cur_phys last_phys
*
* 0 w_size - 1
* +-----------------------+
* | | | window |
* +-----------------------+
* cur_window = cur_phys - first_wind
}*/
static void
int mode;
{
register int p;
register int regb;
int p_differ;
int new_lw;
int ncur_phys;
# define w regb
# define v regb
/*** find out if it's necessary to start translating at beginning ***/
if(lookahead>0)
{
}
v = cur_virt;
|| ( v==ocur_virt
{
opflag = 0;
p = 0;
v = 0;
}
else
{
opflag = 1;
p = ocur_phys;
v = ocur_virt;
{
/*** avoid double ^'s ***/
++p;
++v;
}
}
if( --p < 0 )
last_phys = 0;
else
last_phys = p;
/*** see if this was a translate only ***/
return;
/*** adjust left margin if necessary ***/
{
if( first_w < 0 )
first_w = 0;
}
/*** attempt to optimize search somewhat to find ***/
/*** out where physical and window images differ ***/
{
p = ocur_phys;
w = p - first_w;
}
else
{
p = first_w;
w = 0;
}
{
break;
}
p_differ = p;
{
/*** images are identical ***/
return;
}
/*** copy the physical image to the window image ***/
{
}
new_lw = w;
/*** erase trailing characters if needed ***/
while( w <= last_wind )
window[w++] = ' ';
last_wind = --w;
p = p_differ;
/*** move cursor to start of difference ***/
cursor(p);
/*** and output difference ***/
w = p - first_w;
while( w <= last_wind )
{
if( first_w == 0 )
long_char = '>';
long_char = '<';
else
long_char = '*';
}
else
long_char = ' ';
{
/*** indicate lines longer than window ***/
while( w++ < w_size )
{
putchar(' ');
++cur_phys;
}
++cur_phys;
}
++ncur_phys;
ed_flush();
return;
}
/*{ REPLACE( char, increment )
*
* Replace the cur_virt character with char. This routine attempts
* to avoid using refresh().
*
* increment = 1, increment cur_virt after replacement.
* = 0, leave cur_virt where it is.
*
}*/
static void
register int c;
register int increment;
{
register int cur_window;
{
/*** can't replace invalid cursor ***/
bell;
return;
}
#ifdef MULTIBYTE
#endif /* MULTIBYTE */
{
/*** must use standard refresh routine ***/
++cur_virt;
}
else
{
window[cur_window] = c;
putchar(c);
if( increment )
{
++cur_phys;
}
else
{
putchar('\b');
}
o_v_char = c;
ed_flush();
}
return;
}
/*{ RESTORE_V()
*
* Restore the contents of virtual space from u_space.
*
}*/
static void
{
register int tmpcol;
{
/*** never saved anything ***/
bell;
return;
}
save_v();
return;
}
/*{ SAVE_LAST()
*
* If the user has typed something, save it in last line.
*
}*/
static void
{
register int i;
{
/*** save last thing user typed ***/
lastline[i] = '\0';
}
return;
}
/*{ SAVE_V()
*
* This routine will save the contents of virtual in u_space.
*
}*/
static void
save_v()
{
if(!inmacro)
{
}
return;
}
/*{ SEARCH( mode )
*
* Search history file for regular expression.
*
* mode = '/' require search string and search new to old
* mode = '?' require search string and search old to new
* mode = 'N' repeat last search in reverse direction
* mode = 'n' repeat last search
*
}*/
static int
register char mode;
{
register int new_direction;
register int oldcurhline;
{
/*** new search expression ***/
first_virt = 1;
first_virt = 0;
}
{
/*** no operation ***/
return(ABORT);
}
{
/*** user wants repeat of last search ***/
#ifdef MULTIBYTE
*((char*)virtual) = '/';
#endif /* MULTIBYTE */
}
if( mode == 'N' )
else
/*** now search ***/
#ifdef MULTIBYTE
#endif /* MULTIBYTE */
{
return(GOOD);
}
/*** could not find matching line ***/
return(BAD);
}
/*{ SYNC_CURSOR()
*
* This routine will move the physical cursor to the same
* column as the virtual cursor.
*
}*/
static void
{
register int p;
register int v;
register int c;
int new_phys;
return;
/*** find physical col that corresponds to virtual col ***/
new_phys = 0;
{
/*** try to optimize search a little ***/
p = ocur_phys + 1;
#ifdef MULTIBYTE
p++;
#endif /* MULTIBYTE */
v = ocur_virt + 1;
}
else
{
p = 0;
v = 0;
}
for(; v <= last_virt; ++p, ++v)
{
#ifdef MULTIBYTE
int d;
c = virtual[v];
if(d = icharset(c))
{
if( v != cur_virt )
p += (out_csize(d)-1);
}
else
#else
c = virtual[v];
#endif /* MULTIBYTE */
if( !isprint(c) )
{
if( c == '\t' )
{
p += (TABSIZE-1);
}
else
{
++p;
}
}
if( v == cur_virt )
{
new_phys = p;
break;
}
}
{
/*** asked to move outside of window ***/
window[0] = '\0';
return;
}
ed_flush();
return;
}
/*{ TEXTMOD( command, mode )
*
* Modify text operations.
*
* mode != 0, repeat previous operation
*
}*/
static int
register int c;
int mode;
{
register int i;
#ifdef KSHELL
static int lastmacro;
#endif
lastmotion = ';';
if( fold(c) == 'P' )
{
/*** change p from lastline to yankbuf ***/
p = yankbuf;
}
switch( c )
{
/***** Input commands *****/
#ifdef KSHELL
case '*': /** do file name expansion in place **/
case '\\': /** do file name completion in place **/
return(BAD);
case '=': /** list file name expansions **/
save_v();
i = last_virt;
++last_virt;
{
last_virt = i;
bell;
}
else if(c == '=')
{
last_virt = i;
nonewline++;
return(GOOD);
}
else
{
--cur_virt;
--last_virt;
return(APPEND);
}
break;
case '@': /** macro expansion **/
if( mode )
c = lastmacro;
else
return(GOOD);
if(!inmacro)
lastmacro = c;
if(ed_macro(c))
{
save_v();
inmacro++;
return(GOOD);
}
bell;
return(BAD);
#endif /* KSHELL */
case '_': /** append last argument of prev command **/
save_v();
{
if(repeat_set==0)
repeat = -1;
#ifndef KSHELL
if(p==0)
{
bell;
break;
}
#endif /* KSHELL */
#ifdef MULTIBYTE
ed_internal((char*)p,tmpbuf);
p = tmpbuf;
#endif /* MULTIBYTE */
i = ' ';
do
{
}
while(i = *p++);
return(APPEND);
}
case 'A': /** append to end of line **/
sync_cursor();
case 'a': /** append **/
{
c = 'p';
goto addin;
}
save_v();
{
ed_flush();
}
return(APPEND);
case 'I': /** insert at beginning of line **/
sync_cursor();
case 'i': /** insert **/
{
c = 'P';
goto addin;
}
save_v();
{
first_virt = cur_virt--;
}
return(INSERT);
case 'C': /** change to eol **/
c = '$';
goto chgeol;
case 'c': /** change **/
if( mode )
c = lastmotion;
else
lastmotion = c;
if( c == 'c' )
{
return(APPEND);
}
return(BAD);
if( mode == 'c' )
{
c = 'p';
trepeat = 1;
goto addin;
}
return(APPEND);
case 'D': /** delete to eol **/
c = '$';
goto deleol;
case 'd': /** delete **/
if( mode )
c = lastmotion;
else
lastmotion = c;
if( c == 'd' )
{
break;
}
return(BAD);
++cur_virt;
break;
case 'P':
if( p[0] == '\0' )
return(BAD);
{
if(!is_print(i))
--cur_virt;
}
case 'p': /** print **/
if( p[0] == '\0' )
return(BAD);
{
save_v();
if( c == 'P' )
{
/*** fix stored cur_virt ***/
++u_column;
}
}
if( mode == 'R' )
else
savep = p;
for(i=0; i<trepeat; ++i)
{
while(c= *p++)
p = savep;
}
break;
case 'R': /* Replace many chars **/
if( mode == 'R' )
{
c = 'P';
goto addin;
}
save_v();
return(REPLACE);
case 'r': /** replace **/
if( mode )
c = *p;
else
return(GOOD);
*p = c;
save_v();
while(trepeat--)
return(GOOD);
case 'S': /** Substitute line - cc **/
c = 'c';
goto chgeol;
case 's': /** substitute **/
save_v();
if( mode )
{
c = 'p';
trepeat = 1;
goto addin;
}
return(APPEND);
case 'Y': /** Yank to end of line **/
c = '$';
goto yankeol;
case 'y': /** yank thru motion **/
if( mode )
c = lastmotion;
else
lastmotion = c;
if( c == 'y' )
{
}
{
return(BAD);
}
break;
case 'x': /** delete repeat chars forward - dl **/
c = 'l';
goto deleol;
case 'X': /** delete repeat chars backward - dh **/
c = 'h';
goto deleol;
case '~': /** invert case and advance **/
{
save_v();
i = INVALID;
{
i = cur_virt;
#ifdef MULTIBYTE
if((c&~STRIP)==0)
#endif /* MULTIBYTE */
if( isupper(c) )
c = tolower(c);
else if( islower(c) )
c = toupper(c);
replace(c, 1);
}
return(GOOD);
}
else
return(BAD);
default:
return(BAD);
}
return(GOOD);
}
#ifdef INT16
/* making these functions reduces the size of the text region */
int isalph(c)
register int c;
{
register int v = virtual[c];
return(isalnum(v));
}
int isblank(c)
register int c;
{
register int v = virtual[c];
return(isspace(v));
}
int ismetach(c)
register int c;
{
register int v = virtual[c];
return(ismeta(v));
}
#endif /* INT16 */
#ifdef MULTIBYTE
int isalph(c)
register int c;
{
register int v = virtual[c];
}
int isblank(c)
register int c;
{
register int v = virtual[c];
}
int ismetach(c)
register int c;
{
register int v = virtual[c];
}
#endif /* MULTIBYTE */
/*
* get a character, after ^V processing
*/
static int getrchar()
{
register int c;
{
in_raw++;
c = getchar();
in_raw = 0;
}
return(c);
}