1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1982-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* David Korn <dgk@research.att.com> * 1N/A***********************************************************************/ 1N/A * edit.c - common routines for vi and emacs one line editors in shell 1N/A * David Korn P.D. Sullivan 1N/A char e_version[] =
"\n@(#)$Id: Editlib version 1993-12-28 r $\0\n";
1N/A#
endif /* SHOPT_OLDTERMIO */ 1N/A#
endif /* TIOCGETP */ 1N/A#
endif /* _hdr_sgtty */ 1N/A static int compare(
const char*,
const char*,
int);
1N/A static const char bellchr[] =
"\a";
/* bell char */ 1N/A#
endif /* SHOPT_VSH || SHOPT_ESH */ 1N/A * This routine returns true if fd refers to a terminal 1N/A * This should be equivalent to isatty 1N/A * Get the current terminal attributes 1N/A * This routine remembers the attributes and just returns them if it 1N/A * is called again without an intervening tty_set() 1N/A /* save terminal settings if in cannonical state */ 1N/A * Set the terminal attributes 1N/A * If fd<0, then current attributes are invalidated 1N/A * This routine will set the tty in cooked mode. 1N/A * It is also called by error.done(). 1N/A /* restore alternate break character */ 1N/A /* restore alternate break character */ 1N/A /*** don't do tty_set unless ttyparm has valid data ***/ 1N/A * This routine will set the tty in raw mode. 1N/A#
endif /* SHOPT_RAWONLY */ 1N/A /* try to remove effect of ^V and ^Y and ^O */ 1N/A#
endif /* TIOCGLTC */ 1N/A#
endif /* VREPRINT */ 1N/A#
endif /* VDISCARD */ 1N/A#
endif /* VWERASE */ 1N/A * Get tty parameters and make ESC and '\r' wakeup characters. 1N/A /* escape character echos as ^[ */ 1N/A /* switch VEOL2 and EOF, since EOF isn't echo'd by driver */ 1N/A#
endif /* ECHOCTL */ 1N/A#
endif /* VREPRINT */ 1N/A#
endif /* VDISCARD */ 1N/A#
endif /* VWERASE */ 1N/A#
endif /* TIOCGETC */ 1N/A#
endif /* SHOPT_RAWONLY */ 1N/A * return the window size 1N/A * Flush the output buffer. 1N/A * send the bell character ^G to the terminal 1N/A * send a carriage return line feed to the terminal 1N/A/* ED_SETUP( max_prompt_size ) 1N/A * This routine sets up the prompt string 1N/A * The following is an unadvertised feature. 1N/A * Escape sequences in the prompt can be excluded from the calculated 1N/A * prompt length. This is accomplished as follows: 1N/A * - if the prompt string starts with "%\r, or contains \r%\r", where % 1N/A * represents any char, then % is taken to be the quote character. 1N/A * - strings enclosed by this quote character, and the quote character, 1N/A * are not counted as part of the prompt length. 1N/A#
endif /* SHOPT_EDPREDICT */ 1N/A if(c==
'\a' || c==
ESC || c==
'\r')
1N/A else if(n>
2 || (c!=
'[' && c!=
']'))
1N/A /* can't use output buffer when reading from stderr */ 1N/A /* make sure SF_READ not on */ 1N/A * Do read, restart on interrupt unless SH_SIGSET or SH_SIGTRAP is set 1N/A * Use sfpkrd() to poll() or select() to wait for input if possible 1N/A * Unfortunately, systems that get interrupted from slow reads update 1N/A * this access time for for the terminal (in violation of POSIX). 1N/A * The fixtime() macro, resets the time to the time at entry in 1N/A * this case. This is not necessary for systems that can handle 1N/A * sfpkrd() correctly (i,e., those that support poll() or select() 1N/A /* move cursor to start of first line */ 1N/A /* clear the current command line */ 1N/A /* an interrupt that should be ignored */ 1N/A#
endif /* _hdr_utime */ 1N/A /* an interrupt that should be ignored */ 1N/A * put <string> of length <nbyte> onto lookahead stack 1N/A * if <type> is non-zero, the negation of the character is put 1N/A * onto the stack so that it can be checked for KEYTRAP 1N/A * putstack() returns 1 except when in the middle of a multi-byte char 1N/A if(c<
0x80 && c!=
'<')
1N/A /*** user break key ***/ 1N/A p--;
/* incremented below */ 1N/A /* shift lookahead buffer if necessary */ 1N/A /*** user break key ***/ 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A * routine to perform read from terminal for vi and emacs mode 1N/A * <mode> can be one of the following: 1N/A * -2 vi insert mode - key binding is in effect 1N/A * -1 vi control mode - key binding is in effect 1N/A * 0 normal command mode - key binding is in effect 1N/A * 1 edit keys not mapped 1N/A * 2 Next key is literal 1N/A /* The while is necessary for reads of partial multbyte chars */ 1N/A /* check for possible key mapping */ 1N/A if(c>=
'0' && c<=
'9' && n>
2)
1N/A if(n>
2 || (c!=
'[' && c!=
'O'))
1N/A /*** map '\r' to '\n' ***/ 1N/A * put a character into the output buffer 1N/A /* check for place holder */ 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A * returns the line and column corresponding to offset <off> in the physical buffer 1N/A * if <cur> is non-zero and <= <off>, then correspodning <curpos> will start the search 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A /*** move to left ***/ 1N/A /*** attempt to optimize cursor movement ***/ 1N/A * copy virtual to physical and return the index for cursor in physical buffer 1N/A /* multiple width character put in place holders */ 1N/A /* in vi mode the cursor is at the last character */ 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A /* in vi mode the cursor is at the last character */ 1N/A * convert external representation <src> to an array of genchars <dest> 1N/A * <src> and <dest> can be the same 1N/A * returns number of chars in dest 1N/A register const unsigned char *
cp = (
unsigned char *)
src;
1N/A * convert internal representation <src> into character array <dest>. 1N/A * The <src> and <dest> may be the same. 1N/A * returns number of chars in dest. 1N/A /* copy the character as is */ 1N/A * copy at most <n> items from <sp> to <dp> 1N/A * find the string length of <str> 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A#
endif /* SHOPT_ESH || SHOPT_VSH */ 1N/A * returns 1 when <n> bytes starting at <a> and <b> are equal 1N/Astatic int compare(
register const char *a,
register const char *b,
register int n)
1N/A#
endif /* !ECHOCTL */ 1N/A * For backward compatibility only 1N/A * This version will use termios when possible, otherwise termio 1N/A#
endif /* SHOPT_OLDTERMIO */ 1N/A * Execute keyboard trap on given buffer <inbuff> of given size <isize> 1N/A * <mode> < 0 for vi insert mode 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A /* don't bother updating the screen if there is typeahead */ 1N/A#
endif /* SHOPT_EDPREDICT */