Fix problem with previous patches that broke vi history.
- c_gets() was usually returning a length, but sometimes one of the CC_xxx values (which are small +ve integers)! - fixed c_gets() by putting a ' ' under the cursor. From David Laight.
This commit is contained in:
parent
6cde54195b
commit
4a97685c19
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: chared.c,v 1.17 2002/11/15 14:32:32 christos Exp $ */
|
||||
/* $NetBSD: chared.c,v 1.18 2002/11/20 16:50:08 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -41,7 +41,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: chared.c,v 1.17 2002/11/15 14:32:32 christos Exp $");
|
||||
__RCSID("$NetBSD: chared.c,v 1.18 2002/11/20 16:50:08 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -654,51 +654,64 @@ el_deletestr(EditLine *el, int n)
|
|||
* Get a string
|
||||
*/
|
||||
protected int
|
||||
c_gets(EditLine *el, char *buf)
|
||||
c_gets(EditLine *el, char *buf, const char *prompt)
|
||||
{
|
||||
char ch;
|
||||
int len = 0;
|
||||
int len;
|
||||
char *cp = el->el_line.buffer;
|
||||
|
||||
if (prompt) {
|
||||
len = strlen(prompt);
|
||||
memcpy(cp, prompt, len + 0u);
|
||||
cp += len;
|
||||
}
|
||||
len = 0;
|
||||
|
||||
for (;;) {
|
||||
el->el_line.cursor = cp;
|
||||
*cp = ' ';
|
||||
el->el_line.lastchar = cp + 1;
|
||||
re_refresh(el);
|
||||
|
||||
if (el_getc(el, &ch) != 1) {
|
||||
ed_end_of_file(el, 0);
|
||||
len = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
for (ch = 0; ch == 0;) {
|
||||
if (el_getc(el, &ch) != 1)
|
||||
return (ed_end_of_file(el, 0));
|
||||
switch (ch) {
|
||||
|
||||
case 0010: /* Delete and backspace */
|
||||
case 0177:
|
||||
if (len > 1) {
|
||||
*el->el_line.cursor-- = '\0';
|
||||
el->el_line.lastchar = el->el_line.cursor;
|
||||
buf[len--] = '\0';
|
||||
} else {
|
||||
el->el_line.buffer[0] = '\0';
|
||||
el->el_line.lastchar = el->el_line.buffer;
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
return (CC_REFRESH);
|
||||
if (len <= 0) {
|
||||
len = -1;
|
||||
break;
|
||||
}
|
||||
re_refresh(el);
|
||||
ch = 0;
|
||||
break;
|
||||
cp--;
|
||||
continue;
|
||||
|
||||
case 0033: /* ESC */
|
||||
case '\r': /* Newline */
|
||||
case '\n':
|
||||
buf[len] = ch;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (len >= EL_BUFSIZ)
|
||||
if (len >= EL_BUFSIZ - 16)
|
||||
term_beep(el);
|
||||
else {
|
||||
buf[len++] = ch;
|
||||
*el->el_line.cursor++ = ch;
|
||||
el->el_line.lastchar = el->el_line.cursor;
|
||||
*cp++ = ch;
|
||||
}
|
||||
re_refresh(el);
|
||||
ch = 0;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
buf[len] = ch;
|
||||
return (len);
|
||||
|
||||
el->el_line.buffer[0] = '\0';
|
||||
el->el_line.lastchar = el->el_line.buffer;
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: chared.h,v 1.10 2002/11/15 14:32:33 christos Exp $ */
|
||||
/* $NetBSD: chared.h,v 1.11 2002/11/20 16:50:08 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -159,7 +159,7 @@ protected char *c__prev_word(char *, char *, int, int (*)(int));
|
|||
protected void c_insert(EditLine *, int);
|
||||
protected void c_delbefore(EditLine *, int);
|
||||
protected void c_delafter(EditLine *, int);
|
||||
protected int c_gets(EditLine *, char *);
|
||||
protected int c_gets(EditLine *, char *, const char *);
|
||||
protected int c_hpos(EditLine *);
|
||||
|
||||
protected int ch_init(EditLine *);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: common.c,v 1.13 2002/11/15 14:32:33 christos Exp $ */
|
||||
/* $NetBSD: common.c,v 1.14 2002/11/20 16:50:08 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -41,7 +41,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: common.c,v 1.13 2002/11/15 14:32:33 christos Exp $");
|
||||
__RCSID("$NetBSD: common.c,v 1.14 2002/11/20 16:50:08 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -905,25 +905,13 @@ ed_command(EditLine *el, int c)
|
|||
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;
|
||||
tmplen = c_gets(el, tmpbuf, "\n: ");
|
||||
term__putc('\n');
|
||||
|
||||
c_insert(el, 3); /* prompt + ": " */
|
||||
*el->el_line.cursor++ = '\n';
|
||||
*el->el_line.cursor++ = ':';
|
||||
*el->el_line.cursor++ = ' ';
|
||||
re_refresh(el);
|
||||
if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
|
||||
term_beep(el);
|
||||
|
||||
tmplen = c_gets(el, tmpbuf);
|
||||
tmpbuf[tmplen] = '\0';
|
||||
|
||||
el->el_line.buffer[0] = '\0';
|
||||
el->el_line.lastchar = el->el_line.buffer;
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: read.c,v 1.23 2002/11/15 14:32:34 christos Exp $ */
|
||||
/* $NetBSD: read.c,v 1.24 2002/11/20 16:50:08 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -41,7 +41,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: read.c,v 1.23 2002/11/15 14:32:34 christos Exp $");
|
||||
__RCSID("$NetBSD: read.c,v 1.24 2002/11/20 16:50:08 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -428,6 +428,8 @@ el_gets(EditLine *el, int *nread)
|
|||
break;
|
||||
cp = &el->el_line.buffer[idx];
|
||||
}
|
||||
if (*cp == 4) /* ought to be stty eof */
|
||||
break;
|
||||
cp++;
|
||||
if (cp[-1] == '\r' || cp[-1] == '\n')
|
||||
break;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: search.c,v 1.13 2002/11/15 14:32:34 christos Exp $ */
|
||||
/* $NetBSD: search.c,v 1.14 2002/11/20 16:50:08 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -41,7 +41,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: search.c,v 1.13 2002/11/15 14:32:34 christos Exp $");
|
||||
__RCSID("$NetBSD: search.c,v 1.14 2002/11/20 16:50:08 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -449,29 +449,23 @@ cv_search(EditLine *el, int dir)
|
|||
char tmpbuf[EL_BUFSIZ];
|
||||
int tmplen;
|
||||
|
||||
tmplen = 0;
|
||||
#ifdef ANCHOR
|
||||
tmpbuf[tmplen++] = '.';
|
||||
tmpbuf[tmplen++] = '*';
|
||||
#endif
|
||||
|
||||
el->el_line.buffer[0] = '\0';
|
||||
el->el_line.lastchar = el->el_line.buffer;
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
el->el_search.patdir = dir;
|
||||
|
||||
c_insert(el, 2); /* prompt + '\n' */
|
||||
*el->el_line.cursor++ = '\n';
|
||||
*el->el_line.cursor++ = dir == ED_SEARCH_PREV_HISTORY ? '/' : '?';
|
||||
re_refresh(el);
|
||||
|
||||
#ifdef ANCHOR
|
||||
tmpbuf[0] = '.';
|
||||
tmpbuf[1] = '*';
|
||||
#define LEN 2
|
||||
#else
|
||||
#define LEN 0
|
||||
#endif
|
||||
tmplen = LEN;
|
||||
|
||||
tmplen = c_gets(el, &tmpbuf[LEN]) + LEN;
|
||||
el->el_search.patdir = dir;
|
||||
|
||||
tmplen = c_gets(el, &tmpbuf[LEN],
|
||||
dir == ED_SEARCH_PREV_HISTORY ? "\n/" : "\n?" );
|
||||
if (tmplen == -1)
|
||||
return CC_REFRESH;
|
||||
|
||||
tmplen += LEN;
|
||||
ch = tmpbuf[tmplen];
|
||||
tmpbuf[tmplen] = '\0';
|
||||
|
||||
|
@ -480,9 +474,6 @@ cv_search(EditLine *el, int dir)
|
|||
* Use the old pattern, but wild-card it.
|
||||
*/
|
||||
if (el->el_search.patlen == 0) {
|
||||
el->el_line.buffer[0] = '\0';
|
||||
el->el_line.lastchar = el->el_line.buffer;
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
re_refresh(el);
|
||||
return (CC_ERROR);
|
||||
}
|
||||
|
@ -513,19 +504,15 @@ cv_search(EditLine *el, int dir)
|
|||
el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
|
||||
el->el_line.cursor = el->el_line.lastchar = el->el_line.buffer;
|
||||
if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) :
|
||||
ed_search_next_history(el, 0)) == CC_ERROR) {
|
||||
ed_search_next_history(el, 0)) == CC_ERROR) {
|
||||
re_refresh(el);
|
||||
return (CC_ERROR);
|
||||
} else {
|
||||
if (ch == 0033) {
|
||||
re_refresh(el);
|
||||
*el->el_line.lastchar++ = '\n';
|
||||
*el->el_line.lastchar = '\0';
|
||||
re_goto_bottom(el);
|
||||
return (CC_NEWLINE);
|
||||
} else
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
if (ch == 0033) {
|
||||
re_refresh(el);
|
||||
return ed_newline(el, 0);
|
||||
}
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue