summaryrefslogtreecommitdiffstats
path: root/dist/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'dist/common.c')
-rw-r--r--dist/common.c218
1 files changed, 94 insertions, 124 deletions
diff --git a/dist/common.c b/dist/common.c
index dfb8a71..15b3aa2 100644
--- a/dist/common.c
+++ b/dist/common.c
@@ -1,4 +1,4 @@
-/* $NetBSD: common.c,v 1.10 2001/01/10 07:45:41 jdolecek Exp $ */
+/* $NetBSD: common.c,v 1.17 2005/08/01 23:00:15 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -15,11 +15,7 @@
* 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -36,19 +32,18 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
+#include "config.h"
#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.10 2001/01/10 07:45:41 jdolecek Exp $");
+__RCSID("$NetBSD: common.c,v 1.17 2005/08/01 23:00:15 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
/*
* common.c: Common Editor functions
*/
-#include "sys.h"
#include "el.h"
/* ed_end_of_file():
@@ -57,7 +52,7 @@ __RCSID("$NetBSD: common.c,v 1.10 2001/01/10 07:45:41 jdolecek Exp $");
*/
protected el_action_t
/*ARGSUSED*/
-ed_end_of_file(EditLine *el, int c)
+ed_end_of_file(EditLine *el, int c __attribute__((__unused__)))
{
re_goto_bottom(el);
@@ -73,7 +68,7 @@ ed_end_of_file(EditLine *el, int c)
protected el_action_t
ed_insert(EditLine *el, int c)
{
- int i;
+ int count = el->el_state.argument;
if (c == '\0')
return (CC_ERROR);
@@ -81,42 +76,28 @@ ed_insert(EditLine *el, int c)
if (el->el_line.lastchar + el->el_state.argument >=
el->el_line.limit) {
/* end of buffer space, try to allocate more */
- if (!ch_enlargebufs(el, (size_t) el->el_state.argument))
+ if (!ch_enlargebufs(el, (size_t) count))
return CC_ERROR; /* error allocating more */
}
- if (el->el_state.argument == 1) {
- if (el->el_state.inputmode != MODE_INSERT) {
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] =
- *el->el_line.cursor;
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] =
- '\0';
- c_delafter(el, 1);
- }
- c_insert(el, 1);
+ if (count == 1) {
+ if (el->el_state.inputmode == MODE_INSERT
+ || el->el_line.cursor >= el->el_line.lastchar)
+ c_insert(el, 1);
*el->el_line.cursor++ = c;
- el->el_state.doingarg = 0; /* just in case */
re_fastaddc(el); /* fast refresh for one char. */
} else {
- if (el->el_state.inputmode != MODE_INSERT) {
- for (i = 0; i < el->el_state.argument; i++)
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] =
- el->el_line.cursor[i];
-
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] =
- '\0';
- c_delafter(el, el->el_state.argument);
- }
- c_insert(el, el->el_state.argument);
+ if (el->el_state.inputmode != MODE_REPLACE_1)
+ c_insert(el, el->el_state.argument);
- while (el->el_state.argument--)
+ while (count-- && el->el_line.cursor < el->el_line.lastchar)
*el->el_line.cursor++ = c;
re_refresh(el);
}
if (el->el_state.inputmode == MODE_REPLACE_1)
- (void) vi_command_mode(el, 0);
+ return vi_command_mode(el, 0);
return (CC_NORM);
}
@@ -128,7 +109,7 @@ ed_insert(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_delete_prev_word(EditLine *el, int c)
+ed_delete_prev_word(EditLine *el, int c __attribute__((__unused__)))
{
char *cp, *p, *kp;
@@ -156,7 +137,7 @@ ed_delete_prev_word(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_delete_next_char(EditLine *el, int c)
+ed_delete_next_char(EditLine *el, int c __attribute__((__unused__)))
{
#ifdef notdef /* XXX */
#define EL el->el_line
@@ -207,7 +188,7 @@ ed_delete_next_char(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_kill_line(EditLine *el, int c)
+ed_kill_line(EditLine *el, int c __attribute__((__unused__)))
{
char *kp, *cp;
@@ -228,7 +209,7 @@ ed_kill_line(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_move_to_end(EditLine *el, int c)
+ed_move_to_end(EditLine *el, int c __attribute__((__unused__)))
{
el->el_line.cursor = el->el_line.lastchar;
@@ -236,7 +217,7 @@ ed_move_to_end(EditLine *el, int c)
#ifdef VI_MOVE
el->el_line.cursor--;
#endif
- if (el->el_chared.c_vcmd.action & DELETE) {
+ if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
return (CC_REFRESH);
}
@@ -251,7 +232,7 @@ ed_move_to_end(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_move_to_beg(EditLine *el, int c)
+ed_move_to_beg(EditLine *el, int c __attribute__((__unused__)))
{
el->el_line.cursor = el->el_line.buffer;
@@ -260,7 +241,7 @@ ed_move_to_beg(EditLine *el, int c)
/* We want FIRST non space character */
while (isspace((unsigned char) *el->el_line.cursor))
el->el_line.cursor++;
- if (el->el_chared.c_vcmd.action & DELETE) {
+ if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
return (CC_REFRESH);
}
@@ -300,18 +281,22 @@ ed_transpose_chars(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_next_char(EditLine *el, int c)
+ed_next_char(EditLine *el, int c __attribute__((__unused__)))
{
+ char *lim = el->el_line.lastchar;
- if (el->el_line.cursor >= el->el_line.lastchar)
+ if (el->el_line.cursor >= lim ||
+ (el->el_line.cursor == lim - 1 &&
+ el->el_map.type == MAP_VI &&
+ el->el_chared.c_vcmd.action == NOP))
return (CC_ERROR);
el->el_line.cursor += el->el_state.argument;
- if (el->el_line.cursor > el->el_line.lastchar)
- el->el_line.cursor = el->el_line.lastchar;
+ if (el->el_line.cursor > lim)
+ el->el_line.cursor = lim;
if (el->el_map.type == MAP_VI)
- if (el->el_chared.c_vcmd.action & DELETE) {
+ if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
return (CC_REFRESH);
}
@@ -325,7 +310,7 @@ ed_next_char(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_prev_word(EditLine *el, int c)
+ed_prev_word(EditLine *el, int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.buffer)
@@ -337,7 +322,7 @@ ed_prev_word(EditLine *el, int c)
ce__isword);
if (el->el_map.type == MAP_VI)
- if (el->el_chared.c_vcmd.action & DELETE) {
+ if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
return (CC_REFRESH);
}
@@ -351,7 +336,7 @@ ed_prev_word(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_prev_char(EditLine *el, int c)
+ed_prev_char(EditLine *el, int c __attribute__((__unused__)))
{
if (el->el_line.cursor > el->el_line.buffer) {
@@ -360,7 +345,7 @@ ed_prev_char(EditLine *el, int c)
el->el_line.cursor = el->el_line.buffer;
if (el->el_map.type == MAP_VI)
- if (el->el_chared.c_vcmd.action & DELETE) {
+ if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
return (CC_REFRESH);
}
@@ -412,25 +397,9 @@ ed_digit(EditLine *el, int c)
(el->el_state.argument * 10) + (c - '0');
}
return (CC_ARGHACK);
- } else {
- if (el->el_line.lastchar + 1 >= el->el_line.limit) {
- if (!ch_enlargebufs(el, 1))
- return (CC_ERROR);
- }
-
- if (el->el_state.inputmode != MODE_INSERT) {
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] =
- *el->el_line.cursor;
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] =
- '\0';
- c_delafter(el, 1);
- }
- c_insert(el, 1);
- *el->el_line.cursor++ = c;
- el->el_state.doingarg = 0;
- re_fastaddc(el);
}
- return (CC_NORM);
+
+ return ed_insert(el, c);
}
@@ -464,12 +433,10 @@ ed_argument_digit(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_unassigned(EditLine *el, int c)
+ed_unassigned(EditLine *el, int c __attribute__((__unused__)))
{
- term_beep(el);
- term__flush();
- return (CC_NORM);
+ return (CC_ERROR);
}
@@ -483,7 +450,8 @@ ed_unassigned(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_sigint(EditLine *el, int c)
+ed_tty_sigint(EditLine *el __attribute__((__unused__)),
+ int c __attribute__((__unused__)))
{
return (CC_NORM);
@@ -496,7 +464,8 @@ ed_tty_sigint(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_dsusp(EditLine *el, int c)
+ed_tty_dsusp(EditLine *el __attribute__((__unused__)),
+ int c __attribute__((__unused__)))
{
return (CC_NORM);
@@ -509,7 +478,8 @@ ed_tty_dsusp(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_flush_output(EditLine *el, int c)
+ed_tty_flush_output(EditLine *el __attribute__((__unused__)),
+ int c __attribute__((__unused__)))
{
return (CC_NORM);
@@ -522,7 +492,8 @@ ed_tty_flush_output(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_sigquit(EditLine *el, int c)
+ed_tty_sigquit(EditLine *el __attribute__((__unused__)),
+ int c __attribute__((__unused__)))
{
return (CC_NORM);
@@ -535,7 +506,8 @@ ed_tty_sigquit(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_sigtstp(EditLine *el, int c)
+ed_tty_sigtstp(EditLine *el __attribute__((__unused__)),
+ int c __attribute__((__unused__)))
{
return (CC_NORM);
@@ -548,7 +520,8 @@ ed_tty_sigtstp(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_stop_output(EditLine *el, int c)
+ed_tty_stop_output(EditLine *el __attribute__((__unused__)),
+ int c __attribute__((__unused__)))
{
return (CC_NORM);
@@ -561,7 +534,8 @@ ed_tty_stop_output(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_start_output(EditLine *el, int c)
+ed_tty_start_output(EditLine *el __attribute__((__unused__)),
+ int c __attribute__((__unused__)))
{
return (CC_NORM);
@@ -574,14 +548,12 @@ ed_tty_start_output(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_newline(EditLine *el, int c)
+ed_newline(EditLine *el, int c __attribute__((__unused__)))
{
re_goto_bottom(el);
*el->el_line.lastchar++ = '\n';
*el->el_line.lastchar = '\0';
- if (el->el_map.type == MAP_VI)
- el->el_chared.c_vcmd.ins = el->el_line.buffer;
return (CC_NEWLINE);
}
@@ -592,7 +564,7 @@ ed_newline(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_delete_prev_char(EditLine *el, int c)
+ed_delete_prev_char(EditLine *el, int c __attribute__((__unused__)))
{
if (el->el_line.cursor <= el->el_line.buffer)
@@ -612,7 +584,7 @@ ed_delete_prev_char(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_clear_screen(EditLine *el, int c)
+ed_clear_screen(EditLine *el, int c __attribute__((__unused__)))
{
term_clear_screen(el); /* clear the whole real screen */
@@ -627,7 +599,8 @@ ed_clear_screen(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_redisplay(EditLine *el, int c)
+ed_redisplay(EditLine *el __attribute__((__unused__)),
+ int c __attribute__((__unused__)))
{
return (CC_REDISPLAY);
@@ -640,10 +613,10 @@ ed_redisplay(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_start_over(EditLine *el, int c)
+ed_start_over(EditLine *el, int c __attribute__((__unused__)))
{
- ch_reset(el);
+ ch_reset(el, 0);
return (CC_REFRESH);
}
@@ -654,7 +627,8 @@ ed_start_over(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_sequence_lead_in(EditLine *el, int c)
+ed_sequence_lead_in(EditLine *el __attribute__((__unused__)),
+ int c __attribute__((__unused__)))
{
return (CC_NORM);
@@ -667,11 +641,12 @@ ed_sequence_lead_in(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_prev_history(EditLine *el, int c)
+ed_prev_history(EditLine *el, int c __attribute__((__unused__)))
{
char beep = 0;
+ int sv_event = el->el_history.eventno;
- el->el_chared.c_undo.action = NOP;
+ el->el_chared.c_undo.len = -1;
*el->el_line.lastchar = '\0'; /* just in case */
if (el->el_history.eventno == 0) { /* save the current buffer
@@ -684,15 +659,17 @@ ed_prev_history(EditLine *el, int c)
el->el_history.eventno += el->el_state.argument;
if (hist_get(el) == CC_ERROR) {
+ if (el->el_map.type == MAP_VI) {
+ el->el_history.eventno = sv_event;
+ return CC_ERROR;
+ }
beep = 1;
/* el->el_history.eventno was fixed by first call */
(void) hist_get(el);
}
- re_refresh(el);
if (beep)
- return (CC_ERROR);
- else
- return (CC_NORM); /* was CC_UP_HIST */
+ return CC_REFRESH_BEEP;
+ return CC_REFRESH;
}
@@ -702,19 +679,24 @@ ed_prev_history(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_next_history(EditLine *el, int c)
+ed_next_history(EditLine *el, int c __attribute__((__unused__)))
{
+ el_action_t beep = CC_REFRESH, rval;
- el->el_chared.c_undo.action = NOP;
+ el->el_chared.c_undo.len = -1;
*el->el_line.lastchar = '\0'; /* just in case */
el->el_history.eventno -= el->el_state.argument;
if (el->el_history.eventno < 0) {
el->el_history.eventno = 0;
- return (CC_ERROR);/* make it beep */
+ beep = CC_REFRESH_BEEP;
}
- return (hist_get(el));
+ rval = hist_get(el);
+ if (rval == CC_REFRESH)
+ return beep;
+ return rval;
+
}
@@ -724,14 +706,14 @@ ed_next_history(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_search_prev_history(EditLine *el, int c)
+ed_search_prev_history(EditLine *el, int c __attribute__((__unused__)))
{
const char *hp;
int h;
bool_t found = 0;
el->el_chared.c_vcmd.action = NOP;
- el->el_chared.c_undo.action = NOP;
+ el->el_chared.c_undo.len = -1;
*el->el_line.lastchar = '\0'; /* just in case */
if (el->el_history.eventno < 0) {
#ifdef DEBUG_EDIT
@@ -792,14 +774,14 @@ ed_search_prev_history(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_search_next_history(EditLine *el, int c)
+ed_search_next_history(EditLine *el, int c __attribute__((__unused__)))
{
const char *hp;
int h;
bool_t found = 0;
el->el_chared.c_vcmd.action = NOP;
- el->el_chared.c_undo.action = NOP;
+ el->el_chared.c_undo.len = -1;
*el->el_line.lastchar = '\0'; /* just in case */
if (el->el_history.eventno == 0)
@@ -846,7 +828,7 @@ ed_search_next_history(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_prev_line(EditLine *el, int c)
+ed_prev_line(EditLine *el, int c __attribute__((__unused__)))
{
char *ptr;
int nchars = c_hpos(el);
@@ -889,7 +871,7 @@ ed_prev_line(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_next_line(EditLine *el, int c)
+ed_next_line(EditLine *el, int c __attribute__((__unused__)))
{
char *ptr;
int nchars = c_hpos(el);
@@ -923,30 +905,18 @@ ed_next_line(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_command(EditLine *el, int c)
+ed_command(EditLine *el, int c __attribute__((__unused__)))
{
char tmpbuf[EL_BUFSIZ];
int tmplen;
- el->el_line.buffer[0] = '\0';
- el->el_line.lastchar = el->el_line.buffer;
- el->el_line.cursor = el->el_line.buffer;
-
- c_insert(el, 3); /* prompt + ": " */
- *el->el_line.cursor++ = '\n';
- *el->el_line.cursor++ = ':';
- *el->el_line.cursor++ = ' ';
- re_refresh(el);
-
- tmplen = c_gets(el, tmpbuf);
- tmpbuf[tmplen] = '\0';
+ tmplen = c_gets(el, tmpbuf, "\n: ");
+ term__putc('\n');
- el->el_line.buffer[0] = '\0';
- el->el_line.lastchar = el->el_line.buffer;
- el->el_line.cursor = el->el_line.buffer;
+ if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
+ term_beep(el);
- if (parse_line(el, tmpbuf) == -1)
- return (CC_ERROR);
- else
- return (CC_REFRESH);
+ el->el_map.current = el->el_map.key;
+ re_clear_display(el);
+ return CC_REFRESH;
}
OpenPOWER on IntegriCloud