diff options
Diffstat (limited to 'common.c')
| -rw-r--r-- | common.c | 202 |
1 files changed, 57 insertions, 145 deletions
@@ -1,4 +1,4 @@ -/* $NetBSD: common.c,v 1.40 2016/03/02 19:24:20 christos Exp $ */ +/* $NetBSD: common.c,v 1.47 2016/05/22 19:44:26 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: common.c,v 1.40 2016/03/02 19:24:20 christos Exp $"); +__RCSID("$NetBSD: common.c,v 1.47 2016/05/22 19:44:26 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -49,6 +49,7 @@ __RCSID("$NetBSD: common.c,v 1.40 2016/03/02 19:24:20 christos Exp $"); #include "el.h" #include "common.h" +#include "fcns.h" #include "parse.h" #include "vi.h" @@ -56,7 +57,7 @@ __RCSID("$NetBSD: common.c,v 1.40 2016/03/02 19:24:20 christos Exp $"); * Indicate end of file * [^D] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_end_of_file(EditLine *el, wint_t c __attribute__((__unused__))) { @@ -71,7 +72,7 @@ ed_end_of_file(EditLine *el, wint_t c __attribute__((__unused__))) * Add character to the line * Insert a character [bound to all insert keys] */ -protected el_action_t +libedit_private el_action_t ed_insert(EditLine *el, wint_t c) { int count = el->el_state.argument; @@ -91,14 +92,14 @@ ed_insert(EditLine *el, wint_t c) || el->el_line.cursor >= el->el_line.lastchar) c_insert(el, 1); - *el->el_line.cursor++ = (Char)c; + *el->el_line.cursor++ = c; re_fastaddc(el); /* fast refresh for one char. */ } else { if (el->el_state.inputmode != MODE_REPLACE_1) c_insert(el, el->el_state.argument); while (count-- && el->el_line.cursor < el->el_line.lastchar) - *el->el_line.cursor++ = (Char)c; + *el->el_line.cursor++ = c; re_refresh(el); } @@ -113,11 +114,11 @@ ed_insert(EditLine *el, wint_t c) * Delete from beginning of current word to cursor * [M-^?] [^W] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ 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) return CC_ERROR; @@ -141,15 +142,14 @@ ed_delete_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) * Delete character under cursor * [^D] [x] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_delete_next_char(EditLine *el, wint_t c __attribute__((__unused__))) { #ifdef DEBUG_EDIT #define EL el->el_line (void) fprintf(el->el_errfile, - "\nD(b: %p(" FSTR ") c: %p(" FSTR ") last: %p(" FSTR - ") limit: %p(" FSTR ")\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.lastchar, EL.limit, EL.limit); #endif @@ -189,11 +189,11 @@ ed_delete_next_char(EditLine *el, wint_t c __attribute__((__unused__))) * Cut to the end of line * [^K] [^K] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_kill_line(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *kp, *cp; + wchar_t *kp, *cp; cp = el->el_line.cursor; kp = el->el_chared.c_kill.buf; @@ -210,7 +210,7 @@ ed_kill_line(EditLine *el, wint_t c __attribute__((__unused__))) * Move cursor to the end of line * [^E] [^E] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_move_to_end(EditLine *el, wint_t c __attribute__((__unused__))) { @@ -233,7 +233,7 @@ ed_move_to_end(EditLine *el, wint_t c __attribute__((__unused__))) * Move cursor to the beginning of line * [^A] [^A] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_move_to_beg(EditLine *el, wint_t c __attribute__((__unused__))) { @@ -242,7 +242,7 @@ ed_move_to_beg(EditLine *el, wint_t c __attribute__((__unused__))) if (el->el_map.type == MAP_VI) { /* We want FIRST non space character */ - while (Isspace(*el->el_line.cursor)) + while (iswspace(*el->el_line.cursor)) el->el_line.cursor++; if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); @@ -257,7 +257,7 @@ ed_move_to_beg(EditLine *el, wint_t c __attribute__((__unused__))) * Exchange the character to the left of the cursor with the one under it * [^T] [^T] */ -protected el_action_t +libedit_private el_action_t ed_transpose_chars(EditLine *el, wint_t c) { @@ -271,7 +271,7 @@ ed_transpose_chars(EditLine *el, wint_t c) /* must have at least two chars entered */ c = el->el_line.cursor[-2]; el->el_line.cursor[-2] = el->el_line.cursor[-1]; - el->el_line.cursor[-1] = (Char)c; + el->el_line.cursor[-1] = c; return CC_REFRESH; } else return CC_ERROR; @@ -282,11 +282,11 @@ ed_transpose_chars(EditLine *el, wint_t c) * Move to the right one character * [^F] [^F] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ 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 || (el->el_line.cursor == lim - 1 && @@ -311,7 +311,7 @@ ed_next_char(EditLine *el, wint_t c __attribute__((__unused__))) * Move to the beginning of the current word * [M-b] [b] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) { @@ -337,7 +337,7 @@ ed_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) * Move to the left one character * [^B] [^B] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { @@ -362,7 +362,7 @@ ed_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) * Add the next character typed verbatim * [^V] [^V] */ -protected el_action_t +libedit_private el_action_t ed_quoted_insert(EditLine *el, wint_t c) { int num; @@ -380,11 +380,11 @@ ed_quoted_insert(EditLine *el, wint_t c) /* ed_digit(): * Adds to argument or enters a digit */ -protected el_action_t +libedit_private el_action_t ed_digit(EditLine *el, wint_t c) { - if (!Isdigit(c)) + if (!iswdigit(c)) return CC_ERROR; if (el->el_state.doingarg) { @@ -408,11 +408,11 @@ ed_digit(EditLine *el, wint_t c) * Digit that starts argument * For ESC-n */ -protected el_action_t +libedit_private el_action_t ed_argument_digit(EditLine *el, wint_t c) { - if (!Isdigit(c)) + if (!iswdigit(c)) return CC_ERROR; if (el->el_state.doingarg) { @@ -432,7 +432,7 @@ ed_argument_digit(EditLine *el, wint_t c) * Indicates unbound character * Bound to keys that are not assigned */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_unassigned(EditLine *el __attribute__((__unused__)), wint_t c __attribute__((__unused__))) @@ -442,17 +442,13 @@ ed_unassigned(EditLine *el __attribute__((__unused__)), } -/** - ** TTY key handling. - **/ - -/* ed_tty_sigint(): - * Tty interrupt character - * [^C] +/* ed_ignore(): + * Input characters that have no effect + * [^C ^O ^Q ^S ^Z ^\ ^]] [^C ^O ^Q ^S ^\] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_tty_sigint(EditLine *el __attribute__((__unused__)), +ed_ignore(EditLine *el __attribute__((__unused__)), wint_t c __attribute__((__unused__))) { @@ -460,95 +456,11 @@ ed_tty_sigint(EditLine *el __attribute__((__unused__)), } -/* ed_tty_dsusp(): - * Tty delayed suspend character - * [^Y] - */ -protected el_action_t -/*ARGSUSED*/ -ed_tty_dsusp(EditLine *el __attribute__((__unused__)), - wint_t 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__)), - wint_t c __attribute__((__unused__))) -{ - - return CC_NORM; -} - - -/* ed_tty_sigquit(): - * Tty quit character - * [^\] - */ -protected el_action_t -/*ARGSUSED*/ -ed_tty_sigquit(EditLine *el __attribute__((__unused__)), - wint_t 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__)), - wint_t 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__)), - wint_t 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__)), - wint_t c __attribute__((__unused__))) -{ - - return CC_NORM; -} - - /* ed_newline(): * Execute command * [^J] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_newline(EditLine *el, wint_t c __attribute__((__unused__))) { @@ -564,7 +476,7 @@ ed_newline(EditLine *el, wint_t c __attribute__((__unused__))) * Delete the character to the left of the cursor * [^?] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { @@ -584,7 +496,7 @@ ed_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) * Clear screen leaving current line at the top * [^L] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_clear_screen(EditLine *el, wint_t c __attribute__((__unused__))) { @@ -599,7 +511,7 @@ ed_clear_screen(EditLine *el, wint_t c __attribute__((__unused__))) * Redisplay everything * ^R */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_redisplay(EditLine *el __attribute__((__unused__)), wint_t c __attribute__((__unused__))) @@ -613,12 +525,12 @@ ed_redisplay(EditLine *el __attribute__((__unused__)), * Erase current line and start from scratch * [^G] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_start_over(EditLine *el, wint_t c __attribute__((__unused__))) { - ch_reset(el, 0); + ch_reset(el); return CC_REFRESH; } @@ -627,7 +539,7 @@ ed_start_over(EditLine *el, wint_t c __attribute__((__unused__))) * First character in a bound sequence * Placeholder for external keys */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_sequence_lead_in(EditLine *el __attribute__((__unused__)), wint_t c __attribute__((__unused__))) @@ -641,7 +553,7 @@ ed_sequence_lead_in(EditLine *el __attribute__((__unused__)), * Move to the previous history line * [^P] [k] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) { @@ -653,7 +565,7 @@ ed_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) if (el->el_history.eventno == 0) { /* save the current buffer * away */ - (void) Strncpy(el->el_history.buf, el->el_line.buffer, + (void) wcsncpy(el->el_history.buf, el->el_line.buffer, EL_BUFSIZ); el->el_history.last = el->el_history.buf + (el->el_line.lastchar - el->el_line.buffer); @@ -678,7 +590,7 @@ ed_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) * Move to the next history line * [^N] [j] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_next_history(EditLine *el, wint_t c __attribute__((__unused__))) { @@ -705,11 +617,11 @@ ed_next_history(EditLine *el, wint_t c __attribute__((__unused__))) * Search previous in history for a line matching the current * next search history [M-P] [K] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) { - const Char *hp; + const wchar_t *hp; int h; int found = 0; @@ -725,7 +637,7 @@ ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) return CC_ERROR; } 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->el_history.last = el->el_history.buf + (el->el_line.lastchar - el->el_line.buffer); @@ -746,7 +658,7 @@ ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) #ifdef SDEBUG (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp); #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)) || hp[el->el_line.lastchar - el->el_line.buffer]) && c_hmatch(el, hp)) { @@ -773,11 +685,11 @@ ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) * Search next in history for a line matching the current * [M-N] [J] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_search_next_history(EditLine *el, wint_t c __attribute__((__unused__))) { - const Char *hp; + const wchar_t *hp; int h; int found = 0; @@ -801,7 +713,7 @@ ed_search_next_history(EditLine *el, wint_t c __attribute__((__unused__))) #ifdef SDEBUG (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp); #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)) || hp[el->el_line.lastchar - el->el_line.buffer]) && c_hmatch(el, hp)) @@ -827,11 +739,11 @@ ed_search_next_history(EditLine *el, wint_t c __attribute__((__unused__))) * Move up one line * Could be [k] [^p] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_prev_line(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *ptr; + wchar_t *ptr; int nchars = c_hpos(el); /* @@ -870,11 +782,11 @@ ed_prev_line(EditLine *el, wint_t c __attribute__((__unused__))) * Move down one line * Could be [j] [^n] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_next_line(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *ptr; + wchar_t *ptr; int nchars = c_hpos(el); /* @@ -904,14 +816,14 @@ ed_next_line(EditLine *el, wint_t c __attribute__((__unused__))) * Editline extended command * [M-X] [:] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_command(EditLine *el, wint_t c __attribute__((__unused__))) { - Char tmpbuf[EL_BUFSIZ]; + wchar_t tmpbuf[EL_BUFSIZ]; int tmplen; - tmplen = c_gets(el, tmpbuf, STR("\n: ")); + tmplen = c_gets(el, tmpbuf, L"\n: "); terminal__putc(el, '\n'); if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1) |
