"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libedit/common.c" between
tnftp-20151004.tar.gz and tnftp-20200705.tar.gz

About: tnftp is an enhanced ftp client (prior name "lukemftp").

common.c  (tnftp-20151004):common.c  (tnftp-20200705)
/* $NetBSD: common.c,v 1.5 2005/06/09 16:48:57 lukem Exp $ */ /* $NetBSD: common.c,v 1.8 2020/07/04 13:43:21 lukem Exp $ */
/* from NetBSD: common.c,v 1.16 2003/08/07 16:44:30 agc Exp */ /* from NetBSD: common.c,v 1.49 2020/03/30 06:54:37 ryo Exp */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* This code is derived from software contributed to Berkeley by * This code is derived from software contributed to Berkeley by
* Christos Zoulas of Cornell University. * Christos Zoulas of Cornell University.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
skipping to change at line 36 skipping to change at line 36
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * 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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include "tnftp.h" #include "config.h"
#include "sys.h"
#if 0 /* tnftp */
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID(" NetBSD: common.c,v 1.49 2020/03/30 06:54:37 ryo Exp ");
#endif
#endif /* not lint && not SCCSID */
#endif /* tnftp */
/* /*
* common.c: Common Editor functions * common.c: Common Editor functions
*/ */
#include <ctype.h>
#include <string.h>
#include "el.h" #include "el.h"
#include "common.h"
#include "fcns.h"
#include "parse.h"
#include "vi.h"
/* ed_end_of_file(): /* ed_end_of_file():
* Indicate end of file * Indicate end of file
* [^D] * [^D]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_end_of_file(EditLine *el, int c __attribute__((__unused__))) ed_end_of_file(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
re_goto_bottom(el); re_goto_bottom(el);
*el->el_line.lastchar = '\0'; *el->el_line.lastchar = '\0';
return (CC_EOF); return CC_EOF;
} }
/* ed_insert(): /* ed_insert():
* Add character to the line * Add character to the line
* Insert a character [bound to all insert keys] * Insert a character [bound to all insert keys]
*/ */
protected el_action_t libedit_private el_action_t
ed_insert(EditLine *el, int c) ed_insert(EditLine *el, wint_t c)
{ {
int count = el->el_state.argument; int count = el->el_state.argument;
if (c == '\0') if (c == '\0')
return (CC_ERROR); return CC_ERROR;
if (el->el_line.lastchar + el->el_state.argument >= if (el->el_line.lastchar + el->el_state.argument >=
el->el_line.limit) { el->el_line.limit) {
/* end of buffer space, try to allocate more */ /* end of buffer space, try to allocate more */
if (!ch_enlargebufs(el, (size_t) count)) if (!ch_enlargebufs(el, (size_t) count))
return CC_ERROR; /* error allocating more */ return CC_ERROR; /* error allocating more */
} }
if (count == 1) { if (count == 1) {
if (el->el_state.inputmode == MODE_INSERT if (el->el_state.inputmode == MODE_INSERT
skipping to change at line 96 skipping to change at line 112
c_insert(el, el->el_state.argument); c_insert(el, el->el_state.argument);
while (count-- && el->el_line.cursor < el->el_line.lastchar) while (count-- && el->el_line.cursor < el->el_line.lastchar)
*el->el_line.cursor++ = c; *el->el_line.cursor++ = c;
re_refresh(el); re_refresh(el);
} }
if (el->el_state.inputmode == MODE_REPLACE_1) if (el->el_state.inputmode == MODE_REPLACE_1)
return vi_command_mode(el, 0); return vi_command_mode(el, 0);
return (CC_NORM); return CC_NORM;
} }
/* ed_delete_prev_word(): /* ed_delete_prev_word():
* Delete from beginning of current word to cursor * Delete from beginning of current word to cursor
* [M-^?] [^W] * [M-^?] [^W]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_delete_prev_word(EditLine *el, int c __attribute__((__unused__))) ed_delete_prev_word(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
char *cp, *p, *kp; wchar_t *cp, *p, *kp;
if (el->el_line.cursor == el->el_line.buffer) if (el->el_line.cursor == el->el_line.buffer)
return (CC_ERROR); return CC_ERROR;
cp = c__prev_word(el->el_line.cursor, el->el_line.buffer, cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
el->el_state.argument, ce__isword); el->el_state.argument, ce__isword);
for (p = cp, kp = el->el_chared.c_kill.buf; p < el->el_line.cursor; p++) for (p = cp, kp = el->el_chared.c_kill.buf; p < el->el_line.cursor; p++)
*kp++ = *p; *kp++ = *p;
el->el_chared.c_kill.last = kp; el->el_chared.c_kill.last = kp;
c_delbefore(el, el->el_line.cursor - cp); /* delete before dot */ c_delbefore(el, (int)(el->el_line.cursor - cp));/* delete before dot */
el->el_line.cursor = cp; el->el_line.cursor = cp;
if (el->el_line.cursor < el->el_line.buffer) if (el->el_line.cursor < el->el_line.buffer)
el->el_line.cursor = el->el_line.buffer; /* bounds check */ el->el_line.cursor = el->el_line.buffer; /* bounds check */
return (CC_REFRESH); return CC_REFRESH;
} }
/* ed_delete_next_char(): /* ed_delete_next_char():
* Delete character under cursor * Delete character under cursor
* [^D] [x] * [^D] [x]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_delete_next_char(EditLine *el, int c __attribute__((__unused__))) ed_delete_next_char(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
#ifdef notdef /* XXX */ #ifdef DEBUG_EDIT
#define EL el->el_line #define EL el->el_line
(void) fprintf(el->el_errlfile, (void) fprintf(el->el_errfile,
"\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n", "\nD(b: %p(%ls) c: %p(%ls) last: %p(%ls) limit: %p(%ls)\n",
EL.buffer, EL.buffer, EL.cursor, EL.cursor, EL.lastchar, EL.buffer, EL.buffer, EL.cursor, EL.cursor, EL.lastchar,
EL.lastchar, EL.limit, EL.limit); EL.lastchar, EL.limit, EL.limit);
#endif #endif
if (el->el_line.cursor == el->el_line.lastchar) { if (el->el_line.cursor == el->el_line.lastchar) {
/* if I'm at the end */ /* if I'm at the end */
if (el->el_map.type == MAP_VI) { if (el->el_map.type == MAP_VI) {
if (el->el_line.cursor == el->el_line.buffer) { if (el->el_line.cursor == el->el_line.buffer) {
/* if I'm also at the beginning */ /* if I'm also at the beginning */
#ifdef KSHVI #ifdef KSHVI
return (CC_ERROR); return CC_ERROR;
#else #else
term_overwrite(el, STReof, 4); /* then do an EOF */
/* then do a EOF */ terminal_writec(el, c);
term__flush(); return CC_EOF;
return (CC_EOF);
#endif #endif
} else { } else {
#ifdef KSHVI #ifdef KSHVI
el->el_line.cursor--; el->el_line.cursor--;
#else #else
return (CC_ERROR); return CC_ERROR;
#endif #endif
} }
} else { } else
if (el->el_line.cursor != el->el_line.buffer) return CC_ERROR;
el->el_line.cursor--;
else
return (CC_ERROR);
}
} }
c_delafter(el, el->el_state.argument); /* delete after dot */ c_delafter(el, el->el_state.argument); /* delete after dot */
if (el->el_line.cursor >= el->el_line.lastchar && if (el->el_map.type == MAP_VI &&
el->el_line.cursor >= el->el_line.lastchar &&
el->el_line.cursor > el->el_line.buffer) el->el_line.cursor > el->el_line.buffer)
/* bounds check */ /* bounds check */
el->el_line.cursor = el->el_line.lastchar - 1; el->el_line.cursor = el->el_line.lastchar - 1;
return (CC_REFRESH); return CC_REFRESH;
} }
/* ed_kill_line(): /* ed_kill_line():
* Cut to the end of line * Cut to the end of line
* [^K] [^K] * [^K] [^K]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_kill_line(EditLine *el, int c __attribute__((__unused__))) ed_kill_line(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
char *kp, *cp; wchar_t *kp, *cp;
cp = el->el_line.cursor; cp = el->el_line.cursor;
kp = el->el_chared.c_kill.buf; kp = el->el_chared.c_kill.buf;
while (cp < el->el_line.lastchar) while (cp < el->el_line.lastchar)
*kp++ = *cp++; /* copy it */ *kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp; el->el_chared.c_kill.last = kp;
/* zap! -- delete to end */ /* zap! -- delete to end */
el->el_line.lastchar = el->el_line.cursor; el->el_line.lastchar = el->el_line.cursor;
return (CC_REFRESH); return CC_REFRESH;
} }
/* ed_move_to_end(): /* ed_move_to_end():
* Move cursor to the end of line * Move cursor to the end of line
* [^E] [^E] * [^E] [^E]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_move_to_end(EditLine *el, int c __attribute__((__unused__))) ed_move_to_end(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
el->el_line.cursor = el->el_line.lastchar; el->el_line.cursor = el->el_line.lastchar;
if (el->el_map.type == MAP_VI) { if (el->el_map.type == MAP_VI) {
#ifdef VI_MOVE
el->el_line.cursor--;
#endif
if (el->el_chared.c_vcmd.action != NOP) { if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el); cv_delfini(el);
return (CC_REFRESH); return CC_REFRESH;
} }
#ifdef VI_MOVE
el->el_line.cursor--;
#endif
} }
return (CC_CURSOR); return CC_CURSOR;
} }
/* ed_move_to_beg(): /* ed_move_to_beg():
* Move cursor to the beginning of line * Move cursor to the beginning of line
* [^A] [^A] * [^A] [^A]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_move_to_beg(EditLine *el, int c __attribute__((__unused__))) ed_move_to_beg(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
el->el_line.cursor = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer;
if (el->el_map.type == MAP_VI) { if (el->el_map.type == MAP_VI) {
/* We want FIRST non space character */ /* We want FIRST non space character */
while (isspace((unsigned char) *el->el_line.cursor)) while (iswspace(*el->el_line.cursor))
el->el_line.cursor++; el->el_line.cursor++;
if (el->el_chared.c_vcmd.action != NOP) { if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el); cv_delfini(el);
return (CC_REFRESH); return CC_REFRESH;
} }
} }
return (CC_CURSOR); return CC_CURSOR;
} }
/* ed_transpose_chars(): /* ed_transpose_chars():
* Exchange the character to the left of the cursor with the one under it * Exchange the character to the left of the cursor with the one under it
* [^T] [^T] * [^T] [^T]
*/ */
protected el_action_t libedit_private el_action_t
ed_transpose_chars(EditLine *el, int c) ed_transpose_chars(EditLine *el, wint_t c)
{ {
if (el->el_line.cursor < el->el_line.lastchar) { if (el->el_line.cursor < el->el_line.lastchar) {
if (el->el_line.lastchar <= &el->el_line.buffer[1]) if (el->el_line.lastchar <= &el->el_line.buffer[1])
return (CC_ERROR); return CC_ERROR;
else else
el->el_line.cursor++; el->el_line.cursor++;
} }
if (el->el_line.cursor > &el->el_line.buffer[1]) { if (el->el_line.cursor > &el->el_line.buffer[1]) {
/* must have at least two chars entered */ /* must have at least two chars entered */
c = el->el_line.cursor[-2]; c = el->el_line.cursor[-2];
el->el_line.cursor[-2] = el->el_line.cursor[-1]; el->el_line.cursor[-2] = el->el_line.cursor[-1];
el->el_line.cursor[-1] = c; el->el_line.cursor[-1] = c;
return (CC_REFRESH); return CC_REFRESH;
} else } else
return (CC_ERROR); return CC_ERROR;
} }
/* ed_next_char(): /* ed_next_char():
* Move to the right one character * Move to the right one character
* [^F] [^F] * [^F] [^F]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_next_char(EditLine *el, int c __attribute__((__unused__))) ed_next_char(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
char *lim = el->el_line.lastchar; wchar_t *lim = el->el_line.lastchar;
if (el->el_line.cursor >= lim || if (el->el_line.cursor >= lim ||
(el->el_line.cursor == lim - 1 && (el->el_line.cursor == lim - 1 &&
el->el_map.type == MAP_VI && el->el_map.type == MAP_VI &&
el->el_chared.c_vcmd.action == NOP)) el->el_chared.c_vcmd.action == NOP))
return (CC_ERROR); return CC_ERROR;
el->el_line.cursor += el->el_state.argument; el->el_line.cursor += el->el_state.argument;
if (el->el_line.cursor > lim) if (el->el_line.cursor > lim)
el->el_line.cursor = lim; el->el_line.cursor = lim;
if (el->el_map.type == MAP_VI) if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) { if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el); cv_delfini(el);
return (CC_REFRESH); return CC_REFRESH;
} }
return (CC_CURSOR); return CC_CURSOR;
} }
/* ed_prev_word(): /* ed_prev_word():
* Move to the beginning of the current word * Move to the beginning of the current word
* [M-b] [b] * [M-b] [b]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_prev_word(EditLine *el, int c __attribute__((__unused__))) ed_prev_word(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
if (el->el_line.cursor == el->el_line.buffer) if (el->el_line.cursor == el->el_line.buffer)
return (CC_ERROR); return CC_ERROR;
el->el_line.cursor = c__prev_word(el->el_line.cursor, el->el_line.cursor = c__prev_word(el->el_line.cursor,
el->el_line.buffer, el->el_line.buffer,
el->el_state.argument, el->el_state.argument,
ce__isword); ce__isword);
if (el->el_map.type == MAP_VI) if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) { if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el); cv_delfini(el);
return (CC_REFRESH); return CC_REFRESH;
} }
return (CC_CURSOR); return CC_CURSOR;
} }
/* ed_prev_char(): /* ed_prev_char():
* Move to the left one character * Move to the left one character
* [^B] [^B] * [^B] [^B]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_prev_char(EditLine *el, int c __attribute__((__unused__))) ed_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
if (el->el_line.cursor > el->el_line.buffer) { if (el->el_line.cursor > el->el_line.buffer) {
el->el_line.cursor -= el->el_state.argument; el->el_line.cursor -= el->el_state.argument;
if (el->el_line.cursor < el->el_line.buffer) if (el->el_line.cursor < el->el_line.buffer)
el->el_line.cursor = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer;
if (el->el_map.type == MAP_VI) if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) { if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el); cv_delfini(el);
return (CC_REFRESH); return CC_REFRESH;
} }
return (CC_CURSOR); return CC_CURSOR;
} else } else
return (CC_ERROR); return CC_ERROR;
} }
/* ed_quoted_insert(): /* ed_quoted_insert():
* Add the next character typed verbatim * Add the next character typed verbatim
* [^V] [^V] * [^V] [^V]
*/ */
protected el_action_t libedit_private el_action_t
ed_quoted_insert(EditLine *el, int c) /*ARGSUSED*/
ed_quoted_insert(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
int num; int num;
char tc; wchar_t ch;
tty_quotemode(el); tty_quotemode(el);
num = el_getc(el, &tc); num = el_wgetc(el, &ch);
c = (unsigned char) tc;
tty_noquotemode(el); tty_noquotemode(el);
if (num == 1) if (num == 1)
return (ed_insert(el, c)); return ed_insert(el, ch);
else else
return (ed_end_of_file(el, 0)); return ed_end_of_file(el, 0);
} }
/* ed_digit(): /* ed_digit():
* Adds to argument or enters a digit * Adds to argument or enters a digit
*/ */
protected el_action_t libedit_private el_action_t
ed_digit(EditLine *el, int c) ed_digit(EditLine *el, wint_t c)
{ {
if (!isdigit(c)) if (!iswdigit(c))
return (CC_ERROR); return CC_ERROR;
if (el->el_state.doingarg) { if (el->el_state.doingarg) {
/* if doing an arg, add this in... */ /* if doing an arg, add this in... */
if (el->el_state.lastcmd == EM_UNIVERSAL_ARGUMENT) if (el->el_state.lastcmd == EM_UNIVERSAL_ARGUMENT)
el->el_state.argument = c - '0'; el->el_state.argument = c - '0';
else { else {
if (el->el_state.argument > 1000000) if (el->el_state.argument > 1000000)
return (CC_ERROR); return CC_ERROR;
el->el_state.argument = el->el_state.argument =
(el->el_state.argument * 10) + (c - '0'); (el->el_state.argument * 10) + (c - '0');
} }
return (CC_ARGHACK); return CC_ARGHACK;
} }
return ed_insert(el, c); return ed_insert(el, c);
} }
/* ed_argument_digit(): /* ed_argument_digit():
* Digit that starts argument * Digit that starts argument
* For ESC-n * For ESC-n
*/ */
protected el_action_t libedit_private el_action_t
ed_argument_digit(EditLine *el, int c) ed_argument_digit(EditLine *el, wint_t c)
{ {
if (!isdigit(c)) if (!iswdigit(c))
return (CC_ERROR); return CC_ERROR;
if (el->el_state.doingarg) { if (el->el_state.doingarg) {
if (el->el_state.argument > 1000000) if (el->el_state.argument > 1000000)
return (CC_ERROR); return CC_ERROR;
el->el_state.argument = (el->el_state.argument * 10) + el->el_state.argument = (el->el_state.argument * 10) +
(c - '0'); (c - '0');
} else { /* else starting an argument */ } else { /* else starting an argument */
el->el_state.argument = c - '0'; el->el_state.argument = c - '0';
el->el_state.doingarg = 1; el->el_state.doingarg = 1;
} }
return (CC_ARGHACK); return CC_ARGHACK;
} }
/* ed_unassigned(): /* ed_unassigned():
* Indicates unbound character * Indicates unbound character
* Bound to keys that are not assigned * Bound to keys that are not assigned
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_unassigned(EditLine *el, int c __attribute__((__unused__))) ed_unassigned(EditLine *el __attribute__((__unused__)),
wint_t c __attribute__((__unused__)))
{ {
return (CC_ERROR); return CC_ERROR;
} }
/** /* ed_ignore():
** TTY key handling. * Input characters that have no effect
**/ * [^C ^O ^Q ^S ^Z ^\ ^]] [^C ^O ^Q ^S ^\]
/* ed_tty_sigint():
* Tty interrupt character
* [^C]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_tty_sigint(EditLine *el __attribute__((__unused__)), ed_ignore(EditLine *el __attribute__((__unused__)),
int c __attribute__((__unused__))) wint_t c __attribute__((__unused__)))
{ {
return (CC_NORM); return CC_NORM;
}
/* ed_tty_dsusp():
* Tty delayed suspend character
* [^Y]
*/
protected el_action_t
/*ARGSUSED*/
ed_tty_dsusp(EditLine *el __attribute__((__unused__)),
int c __attribute__((__unused__)))
{
return (CC_NORM);
}
/* ed_tty_flush_output():
* Tty flush output characters
* [^O]
*/
protected el_action_t
/*ARGSUSED*/
ed_tty_flush_output(EditLine *el __attribute__((__unused__)),
int c __attribute__((__unused__)))
{
return (CC_NORM);
}
/* ed_tty_sigquit():
* Tty quit character
* [^\]
*/
protected el_action_t
/*ARGSUSED*/
ed_tty_sigquit(EditLine *el __attribute__((__unused__)),
int c __attribute__((__unused__)))
{
return (CC_NORM);
}
/* ed_tty_sigtstp():
* Tty suspend character
* [^Z]
*/
protected el_action_t
/*ARGSUSED*/
ed_tty_sigtstp(EditLine *el __attribute__((__unused__)),
int c __attribute__((__unused__)))
{
return (CC_NORM);
}
/* ed_tty_stop_output():
* Tty disallow output characters
* [^S]
*/
protected el_action_t
/*ARGSUSED*/
ed_tty_stop_output(EditLine *el __attribute__((__unused__)),
int c __attribute__((__unused__)))
{
return (CC_NORM);
}
/* ed_tty_start_output():
* Tty allow output characters
* [^Q]
*/
protected el_action_t
/*ARGSUSED*/
ed_tty_start_output(EditLine *el __attribute__((__unused__)),
int c __attribute__((__unused__)))
{
return (CC_NORM);
} }
/* ed_newline(): /* ed_newline():
* Execute command * Execute command
* [^J] * [^J]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_newline(EditLine *el, int c __attribute__((__unused__))) ed_newline(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
re_goto_bottom(el); re_goto_bottom(el);
*el->el_line.lastchar++ = '\n'; *el->el_line.lastchar++ = '\n';
*el->el_line.lastchar = '\0'; *el->el_line.lastchar = '\0';
return (CC_NEWLINE); return CC_NEWLINE;
} }
/* ed_delete_prev_char(): /* ed_delete_prev_char():
* Delete the character to the left of the cursor * Delete the character to the left of the cursor
* [^?] * [^?]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_delete_prev_char(EditLine *el, int c __attribute__((__unused__))) ed_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
if (el->el_line.cursor <= el->el_line.buffer) if (el->el_line.cursor <= el->el_line.buffer)
return (CC_ERROR); return CC_ERROR;
c_delbefore(el, el->el_state.argument); c_delbefore(el, el->el_state.argument);
el->el_line.cursor -= el->el_state.argument; el->el_line.cursor -= el->el_state.argument;
if (el->el_line.cursor < el->el_line.buffer) if (el->el_line.cursor < el->el_line.buffer)
el->el_line.cursor = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer;
return (CC_REFRESH); return CC_REFRESH;
} }
/* ed_clear_screen(): /* ed_clear_screen():
* Clear screen leaving current line at the top * Clear screen leaving current line at the top
* [^L] * [^L]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_clear_screen(EditLine *el, int c __attribute__((__unused__))) ed_clear_screen(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
term_clear_screen(el); /* clear the whole real screen */ terminal_clear_screen(el); /* clear the whole real screen */
re_clear_display(el); /* reset everything */ re_clear_display(el); /* reset everything */
return (CC_REFRESH); return CC_REFRESH;
} }
/* ed_redisplay(): /* ed_redisplay():
* Redisplay everything * Redisplay everything
* ^R * ^R
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_redisplay(EditLine *el __attribute__((__unused__)), ed_redisplay(EditLine *el __attribute__((__unused__)),
int c __attribute__((__unused__))) wint_t c __attribute__((__unused__)))
{ {
return (CC_REDISPLAY); return CC_REDISPLAY;
} }
/* ed_start_over(): /* ed_start_over():
* Erase current line and start from scratch * Erase current line and start from scratch
* [^G] * [^G]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_start_over(EditLine *el, int c __attribute__((__unused__))) ed_start_over(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
ch_reset(el); ch_reset(el);
return (CC_REFRESH); return CC_REFRESH;
} }
/* ed_sequence_lead_in(): /* ed_sequence_lead_in():
* First character in a bound sequence * First character in a bound sequence
* Placeholder for external keys * Placeholder for external keys
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_sequence_lead_in(EditLine *el __attribute__((__unused__)), ed_sequence_lead_in(EditLine *el __attribute__((__unused__)),
int c __attribute__((__unused__))) wint_t c __attribute__((__unused__)))
{ {
return (CC_NORM); return CC_NORM;
} }
/* ed_prev_history(): /* ed_prev_history():
* Move to the previous history line * Move to the previous history line
* [^P] [k] * [^P] [k]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_prev_history(EditLine *el, int c __attribute__((__unused__))) ed_prev_history(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
char beep = 0; char beep = 0;
int sv_event = el->el_history.eventno; int sv_event = el->el_history.eventno;
el->el_chared.c_undo.len = -1; el->el_chared.c_undo.len = -1;
*el->el_line.lastchar = '\0'; /* just in case */ *el->el_line.lastchar = '\0'; /* just in case */
if (el->el_history.eventno == 0) { /* save the current buffer if (el->el_history.eventno == 0) { /* save the current buffer
* away */ * away */
(void) strncpy(el->el_history.buf, el->el_line.buffer, (void) wcsncpy(el->el_history.buf, el->el_line.buffer,
EL_BUFSIZ); EL_BUFSIZ);
el->el_history.last = el->el_history.buf + el->el_history.last = el->el_history.buf +
(el->el_line.lastchar - el->el_line.buffer); (el->el_line.lastchar - el->el_line.buffer);
} }
el->el_history.eventno += el->el_state.argument; el->el_history.eventno += el->el_state.argument;
if (hist_get(el) == CC_ERROR) { if (hist_get(el) == CC_ERROR) {
if (el->el_map.type == MAP_VI) { if (el->el_map.type == MAP_VI) {
el->el_history.eventno = sv_event; el->el_history.eventno = sv_event;
return CC_ERROR;
} }
beep = 1; beep = 1;
/* el->el_history.eventno was fixed by first call */ /* el->el_history.eventno was fixed by first call */
(void) hist_get(el); (void) hist_get(el);
} }
if (beep) if (beep)
return CC_REFRESH_BEEP; return CC_REFRESH_BEEP;
return CC_REFRESH; return CC_REFRESH;
} }
/* ed_next_history(): /* ed_next_history():
* Move to the next history line * Move to the next history line
* [^N] [j] * [^N] [j]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_next_history(EditLine *el, int c __attribute__((__unused__))) ed_next_history(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
el_action_t beep = CC_REFRESH, rval; el_action_t beep = CC_REFRESH, rval;
el->el_chared.c_undo.len = -1; el->el_chared.c_undo.len = -1;
*el->el_line.lastchar = '\0'; /* just in case */ *el->el_line.lastchar = '\0'; /* just in case */
el->el_history.eventno -= el->el_state.argument; el->el_history.eventno -= el->el_state.argument;
if (el->el_history.eventno < 0) { if (el->el_history.eventno < 0) {
el->el_history.eventno = 0; el->el_history.eventno = 0;
skipping to change at line 672 skipping to change at line 602
if (rval == CC_REFRESH) if (rval == CC_REFRESH)
return beep; return beep;
return rval; return rval;
} }
/* ed_search_prev_history(): /* ed_search_prev_history():
* Search previous in history for a line matching the current * Search previous in history for a line matching the current
* next search history [M-P] [K] * next search history [M-P] [K]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_search_prev_history(EditLine *el, int c __attribute__((__unused__))) ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
const char *hp; const wchar_t *hp;
int h; int h;
bool_t found = 0; int found = 0;
el->el_chared.c_vcmd.action = NOP; el->el_chared.c_vcmd.action = NOP;
el->el_chared.c_undo.len = -1; el->el_chared.c_undo.len = -1;
*el->el_line.lastchar = '\0'; /* just in case */ *el->el_line.lastchar = '\0'; /* just in case */
if (el->el_history.eventno < 0) { if (el->el_history.eventno < 0) {
#ifdef DEBUG_EDIT #ifdef DEBUG_EDIT
(void) fprintf(el->el_errfile, (void) fprintf(el->el_errfile,
"e_prev_search_hist(): eventno < 0;\n"); "e_prev_search_hist(): eventno < 0;\n");
#endif #endif
el->el_history.eventno = 0; el->el_history.eventno = 0;
return (CC_ERROR); return CC_ERROR;
} }
if (el->el_history.eventno == 0) { if (el->el_history.eventno == 0) {
(void) strncpy(el->el_history.buf, el->el_line.buffer, (void) wcsncpy(el->el_history.buf, el->el_line.buffer,
EL_BUFSIZ); EL_BUFSIZ);
el->el_history.last = el->el_history.buf + el->el_history.last = el->el_history.buf +
(el->el_line.lastchar - el->el_line.buffer); (el->el_line.lastchar - el->el_line.buffer);
} }
if (el->el_history.ref == NULL) if (el->el_history.ref == NULL)
return (CC_ERROR); return CC_ERROR;
hp = HIST_FIRST(el); hp = HIST_FIRST(el);
if (hp == NULL) if (hp == NULL)
return (CC_ERROR); return CC_ERROR;
c_setpat(el); /* Set search pattern !! */ c_setpat(el); /* Set search pattern !! */
for (h = 1; h <= el->el_history.eventno; h++) for (h = 1; h <= el->el_history.eventno; h++)
hp = HIST_NEXT(el); hp = HIST_NEXT(el);
while (hp != NULL) { while (hp != NULL) {
#ifdef SDEBUG #ifdef SDEBUG
(void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp); (void) fprintf(el->el_errfile, "Comparing with \"%ls\"\n", hp);
#endif #endif
if ((strncmp(hp, el->el_line.buffer, (size_t) if ((wcsncmp(hp, el->el_line.buffer, (size_t)
(el->el_line.lastchar - el->el_line.buffer)) || (el->el_line.lastchar - el->el_line.buffer)) ||
hp[el->el_line.lastchar - el->el_line.buffer]) && hp[el->el_line.lastchar - el->el_line.buffer]) &&
c_hmatch(el, hp)) { c_hmatch(el, hp)) {
found++; found = 1;
break; break;
} }
h++; h++;
hp = HIST_NEXT(el); hp = HIST_NEXT(el);
} }
if (!found) { if (!found) {
#ifdef SDEBUG #ifdef SDEBUG
(void) fprintf(el->el_errfile, "not found\n"); (void) fprintf(el->el_errfile, "not found\n");
#endif #endif
return (CC_ERROR); return CC_ERROR;
} }
el->el_history.eventno = h; el->el_history.eventno = h;
return (hist_get(el)); return hist_get(el);
} }
/* ed_search_next_history(): /* ed_search_next_history():
* Search next in history for a line matching the current * Search next in history for a line matching the current
* [M-N] [J] * [M-N] [J]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_search_next_history(EditLine *el, int c __attribute__((__unused__))) ed_search_next_history(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
const char *hp; const wchar_t *hp;
int h; int h;
bool_t found = 0; int found = 0;
el->el_chared.c_vcmd.action = NOP; el->el_chared.c_vcmd.action = NOP;
el->el_chared.c_undo.len = -1; el->el_chared.c_undo.len = -1;
*el->el_line.lastchar = '\0'; /* just in case */ *el->el_line.lastchar = '\0'; /* just in case */
if (el->el_history.eventno == 0) if (el->el_history.eventno == 0)
return (CC_ERROR); return CC_ERROR;
if (el->el_history.ref == NULL) if (el->el_history.ref == NULL)
return (CC_ERROR); return CC_ERROR;
hp = HIST_FIRST(el); hp = HIST_FIRST(el);
if (hp == NULL) if (hp == NULL)
return (CC_ERROR); return CC_ERROR;
c_setpat(el); /* Set search pattern !! */ c_setpat(el); /* Set search pattern !! */
for (h = 1; h < el->el_history.eventno && hp; h++) { for (h = 1; h < el->el_history.eventno && hp; h++) {
#ifdef SDEBUG #ifdef SDEBUG
(void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp); (void) fprintf(el->el_errfile, "Comparing with \"%ls\"\n", hp);
#endif #endif
if ((strncmp(hp, el->el_line.buffer, (size_t) if ((wcsncmp(hp, el->el_line.buffer, (size_t)
(el->el_line.lastchar - el->el_line.buffer)) || (el->el_line.lastchar - el->el_line.buffer)) ||
hp[el->el_line.lastchar - el->el_line.buffer]) && hp[el->el_line.lastchar - el->el_line.buffer]) &&
c_hmatch(el, hp)) c_hmatch(el, hp))
found = h; found = h;
hp = HIST_NEXT(el); hp = HIST_NEXT(el);
} }
if (!found) { /* is it the current history number? */ if (!found) { /* is it the current history number? */
if (!c_hmatch(el, el->el_history.buf)) { if (!c_hmatch(el, el->el_history.buf)) {
#ifdef SDEBUG #ifdef SDEBUG
(void) fprintf(el->el_errfile, "not found\n"); (void) fprintf(el->el_errfile, "not found\n");
#endif #endif
return (CC_ERROR); return CC_ERROR;
} }
} }
el->el_history.eventno = found; el->el_history.eventno = found;
return (hist_get(el)); return hist_get(el);
} }
/* ed_prev_line(): /* ed_prev_line():
* Move up one line * Move up one line
* Could be [k] [^p] * Could be [k] [^p]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_prev_line(EditLine *el, int c __attribute__((__unused__))) ed_prev_line(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
char *ptr; wchar_t *ptr;
int nchars = c_hpos(el); int nchars = c_hpos(el);
/* /*
* Move to the line requested * Move to the line requested
*/ */
if (*(ptr = el->el_line.cursor) == '\n') if (*(ptr = el->el_line.cursor) == '\n')
ptr--; ptr--;
for (; ptr >= el->el_line.buffer; ptr--) for (; ptr >= el->el_line.buffer; ptr--)
if (*ptr == '\n' && --el->el_state.argument <= 0) if (*ptr == '\n' && --el->el_state.argument <= 0)
break; break;
if (el->el_state.argument > 0) if (el->el_state.argument > 0)
return (CC_ERROR); return CC_ERROR;
/* /*
* Move to the beginning of the line * Move to the beginning of the line
*/ */
for (ptr--; ptr >= el->el_line.buffer && *ptr != '\n'; ptr--) for (ptr--; ptr >= el->el_line.buffer && *ptr != '\n'; ptr--)
continue; continue;
/* /*
* Move to the character requested * Move to the character requested
*/ */
for (ptr++; for (ptr++;
nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n'; nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
ptr++) ptr++)
continue; continue;
el->el_line.cursor = ptr; el->el_line.cursor = ptr;
return (CC_CURSOR); return CC_CURSOR;
} }
/* ed_next_line(): /* ed_next_line():
* Move down one line * Move down one line
* Could be [j] [^n] * Could be [j] [^n]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_next_line(EditLine *el, int c __attribute__((__unused__))) ed_next_line(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
char *ptr; wchar_t *ptr;
int nchars = c_hpos(el); int nchars = c_hpos(el);
/* /*
* Move to the line requested * Move to the line requested
*/ */
for (ptr = el->el_line.cursor; ptr < el->el_line.lastchar; ptr++) for (ptr = el->el_line.cursor; ptr < el->el_line.lastchar; ptr++)
if (*ptr == '\n' && --el->el_state.argument <= 0) if (*ptr == '\n' && --el->el_state.argument <= 0)
break; break;
if (el->el_state.argument > 0) if (el->el_state.argument > 0)
return (CC_ERROR); return CC_ERROR;
/* /*
* Move to the character requested * Move to the character requested
*/ */
for (ptr++; for (ptr++;
nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n'; nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
ptr++) ptr++)
continue; continue;
el->el_line.cursor = ptr; el->el_line.cursor = ptr;
return (CC_CURSOR); return CC_CURSOR;
} }
/* ed_command(): /* ed_command():
* Editline extended command * Editline extended command
* [M-X] [:] * [M-X] [:]
*/ */
protected el_action_t libedit_private el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_command(EditLine *el, int c __attribute__((__unused__))) ed_command(EditLine *el, wint_t c __attribute__((__unused__)))
{ {
char tmpbuf[EL_BUFSIZ]; wchar_t tmpbuf[EL_BUFSIZ];
int tmplen; int tmplen;
tmplen = c_gets(el, tmpbuf, "\n: "); tmplen = c_gets(el, tmpbuf, L"\n: ");
term__putc('\n'); terminal__putc(el, '\n');
if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1) if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
term_beep(el); terminal_beep(el);
el->el_map.current = el->el_map.key; el->el_map.current = el->el_map.key;
re_clear_display(el); re_clear_display(el);
return CC_REFRESH; return CC_REFRESH;
} }
 End of changes. 146 change blocks. 
250 lines changed or deleted 180 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)