summaryrefslogtreecommitdiffstats
path: root/lib/libedit
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libedit')
-rw-r--r--lib/libedit/Makefile40
-rw-r--r--lib/libedit/TEST/test.c72
-rw-r--r--lib/libedit/chared.c78
-rw-r--r--lib/libedit/chared.h6
-rw-r--r--lib/libedit/common.c156
-rw-r--r--lib/libedit/editline.3532
-rw-r--r--lib/libedit/editrc.5292
-rw-r--r--lib/libedit/el.c25
-rw-r--r--lib/libedit/emacs.c64
-rw-r--r--lib/libedit/hist.c2
-rw-r--r--lib/libedit/hist.h2
-rw-r--r--lib/libedit/history.c179
-rw-r--r--lib/libedit/key.c54
-rw-r--r--lib/libedit/key.h4
-rw-r--r--lib/libedit/map.c52
-rw-r--r--lib/libedit/map.h2
-rw-r--r--lib/libedit/parse.c23
-rw-r--r--lib/libedit/parse.h2
-rw-r--r--lib/libedit/prompt.c6
-rw-r--r--lib/libedit/read.c25
-rw-r--r--lib/libedit/refresh.c84
-rw-r--r--lib/libedit/search.c119
-rw-r--r--lib/libedit/search.h4
-rw-r--r--lib/libedit/sig.c10
-rw-r--r--lib/libedit/sys.h4
-rw-r--r--lib/libedit/term.c191
-rw-r--r--lib/libedit/term.h4
-rw-r--r--lib/libedit/tokenizer.c10
-rw-r--r--lib/libedit/tokenizer.h2
-rw-r--r--lib/libedit/tty.c84
-rw-r--r--lib/libedit/tty.h15
-rw-r--r--lib/libedit/vi.c130
32 files changed, 1590 insertions, 683 deletions
diff --git a/lib/libedit/Makefile b/lib/libedit/Makefile
index 9dc0471..2f4feda 100644
--- a/lib/libedit/Makefile
+++ b/lib/libedit/Makefile
@@ -2,21 +2,36 @@
LIB= edit
-OSRCS= chared.c common.c el.c emacs.c hist.c key.c map.c parse.c \
- prompt.c read.c refresh.c search.c sig.c term.c tty.c vi.c \
- help.c fcns.c
+OSRCS= chared.c common.c el.c emacs.c fcns.c help.c hist.c key.c map.c \
+ parse.c prompt.c read.c refresh.c search.c sig.c term.c tty.c vi.c
+
+LDADD+= -ltermcap
+DPADD+= ${LIBTERMCAP}
+
+MAN3= editline.3
+MAN5= editrc.5
+
+MLINKS= editline.3 el_init.3 editline.3 el_end.3 editline.3 el_reset.3 \
+ editline.3 el_gets.3 editline.3 el_getc.3 editline.3 el_push.3 \
+ editline.3 el_parse.3 editline.3 el_set.3 editline.3 el_source.3 \
+ editline.3 el_resize.3 editline.3 el_line.3 \
+ editline.3 el_insertstr.3 editline.3 el_deletestr.3 \
+ editline.3 history_init.3 editline.3 history_end.3 editline.3 history.3
+
# For speed and debugging
#SRCS= ${OSRCS} tokenizer.c history.c
# For protection
SRCS= editline.c tokenizer.c history.c
-CLEANFILES+=common.h emacs.h fcns.h help.h vi.h help.c fcns.c editline.c
-CFLAGS+=-I. -I${.CURDIR}
+SRCS+= common.h emacs.h fcns.h help.h vi.h
+
+CLEANFILES+=common.h editline.c emacs.h fcns.c fcns.h help.c help.h vi.h
+CFLAGS+=-I. -I${.CURDIR}
CFLAGS+=#-DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG -DDEBUG_REFRESH
CFLAGS+=#-DDEBUG_PASTE
-AHDR=vi.h emacs.h common.h
+AHDR=vi.h emacs.h common.h
ASRC=${.CURDIR}/vi.c ${.CURDIR}/emacs.c ${.CURDIR}/common.c
vi.h: vi.c makelist
@@ -34,7 +49,7 @@ fcns.h: ${AHDR} makelist
fcns.c: ${AHDR} fcns.h makelist
sh ${.CURDIR}/makelist -fc ${AHDR} > ${.TARGET}
-help.c: ${ASRC} makelist
+help.c: ${ASRC} makelist
sh ${.CURDIR}/makelist -bc ${ASRC} > ${.TARGET}
help.h: ${ASRC} makelist
@@ -45,14 +60,7 @@ editline.c: ${OSRCS}
.depend: vi.h emacs.h common.h fcns.h help.h help.c
-
-test: libedit.a test.o
- ${CC} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD} -ltermcap
-
-beforeinstall:
- -cd ${.CURDIR}; cmp -s histedit.h ${DESTDIR}/usr/include/histedit.h > \
- /dev/null 2>&1 || \
- install -c -o ${BINOWN} -g ${BINGRP} -m 444 histedit.h \
- ${DESTDIR}/usr/include
+test: test.o libedit.a ${DPADD} ${LIBTERMCAP}
+ ${CC} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD}
.include <bsd.lib.mk>
diff --git a/lib/libedit/TEST/test.c b/lib/libedit/TEST/test.c
index f456f51..097055a 100644
--- a/lib/libedit/TEST/test.c
+++ b/lib/libedit/TEST/test.c
@@ -87,7 +87,7 @@ complete(el, ch)
EditLine *el;
int ch;
{
- DIR *dd = opendir(".");
+ DIR *dd = opendir(".");
struct dirent *dp;
const char* ptr;
const LineInfo *lf = el_line(el);
@@ -179,28 +179,56 @@ main(argc, argv)
history(hist, continuation ? H_ADD : H_ENTER, buf);
continuation = 0;
- if (el_parse(el, ac, av) != -1) {
- tok_reset(tok);
- continue;
- }
- switch (fork()) {
- case 0:
- execvp(av[0], av);
- perror(av[0]);
- _exit(1);
- /*NOTREACHED*/
- break;
-
- case -1:
- perror("fork");
- break;
-
- default:
- if (wait(&num) == -1)
- perror("wait");
- (void) fprintf(stderr, "Exit %x\n", num);
- break;
+ if (strcmp(av[0], "history") == 0) {
+ const struct HistEvent *he;
+
+ switch (ac) {
+ case 1:
+ for (he = history(hist, H_LAST); he;
+ he = history(hist, H_PREV))
+ (void) fprintf(stdout, "%4d %s", he->num, he->str);
+ break;
+
+ case 2:
+ if (strcmp(av[1], "clear") == 0)
+ history(hist, H_CLEAR);
+ else
+ goto badhist;
+ break;
+
+ case 3:
+ if (strcmp(av[1], "load") == 0)
+ history(hist, H_LOAD, av[2]);
+ else if (strcmp(av[1], "save") == 0)
+ history(hist, H_SAVE, av[2]);
+ break;
+
+ badhist:
+ default:
+ (void) fprintf(stderr, "Bad history arguments\n");
+ break;
+ }
+ }
+ else if (el_parse(el, ac, av) == -1) {
+ switch (fork()) {
+ case 0:
+ execvp(av[0], av);
+ perror(av[0]);
+ _exit(1);
+ /*NOTREACHED*/
+ break;
+
+ case -1:
+ perror("fork");
+ break;
+
+ default:
+ if (wait(&num) == -1)
+ perror("wait");
+ (void) fprintf(stderr, "Exit %x\n", num);
+ break;
+ }
}
tok_reset(tok);
}
diff --git a/lib/libedit/chared.c b/lib/libedit/chared.c
index 5a393a7..dcd189c 100644
--- a/lib/libedit/chared.c
+++ b/lib/libedit/chared.c
@@ -38,7 +38,7 @@
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */
-/*
+/*
* chared.c: Character editor utilities
*/
#include "sys.h"
@@ -67,7 +67,7 @@ cv_undo(el, action, size, ptr)
}
-/* c_insert():
+/* c_insert():
* Insert num characters
*/
protected void
@@ -80,7 +80,7 @@ c_insert(el, num)
if (el->el_line.lastchar + num >= el->el_line.limit)
return; /* can't go past end of buffer */
- if (el->el_line.cursor < el->el_line.lastchar) {
+ if (el->el_line.cursor < el->el_line.lastchar) {
/* if I must move chars */
for (cp = el->el_line.lastchar; cp >= el->el_line.cursor; cp--)
cp[num] = *cp;
@@ -93,7 +93,7 @@ c_insert(el, num)
* Delete num characters after the cursor
*/
protected void
-c_delafter(el, num)
+c_delafter(el, num)
EditLine *el;
int num;
{
@@ -101,10 +101,10 @@ c_delafter(el, num)
if (el->el_line.cursor + num > el->el_line.lastchar)
num = el->el_line.lastchar - el->el_line.cursor;
- if (num > 0) {
+ if (num > 0) {
char *cp;
- if (el->el_map.current != el->el_map.emacs)
+ if (el->el_map.current != el->el_map.emacs)
cv_undo(el, INSERT, num, el->el_line.cursor);
for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
@@ -125,12 +125,12 @@ c_delbefore(el, num)
{
if (el->el_line.cursor - num < el->el_line.buffer)
- num = el->el_line.cursor - el->el_line.buffer;
+ num = el->el_line.cursor - el->el_line.buffer;
- if (num > 0) {
+ if (num > 0) {
char *cp;
- if (el->el_map.current != el->el_map.emacs)
+ if (el->el_map.current != el->el_map.emacs)
cv_undo(el, INSERT, num, el->el_line.cursor - num);
for (cp = el->el_line.cursor - num; cp <= el->el_line.lastchar; cp++)
@@ -145,10 +145,10 @@ c_delbefore(el, num)
* Return if p is part of a word according to emacs
*/
protected int
-ce__isword(p)
+ce__isword(p)
int p;
{
- return isalpha(p) || isdigit(p) || strchr("*?_-.[]~=", p) != NULL;
+ return isalpha((unsigned char) p) || isdigit((unsigned char) p) || strchr("*?_-.[]~=", p) != NULL;
}
@@ -156,10 +156,10 @@ ce__isword(p)
* Return if p is part of a word according to vi
*/
protected int
-cv__isword(p)
+cv__isword(p)
int p;
{
- return !isspace(p);
+ return !isspace((unsigned char) p);
}
@@ -167,7 +167,7 @@ cv__isword(p)
* Find the previous word
*/
protected char *
-c__prev_word(p, low, n, wtest)
+c__prev_word(p, low, n, wtest)
register char *p, *low;
register int n;
int (*wtest) __P((int));
@@ -175,9 +175,9 @@ c__prev_word(p, low, n, wtest)
p--;
while (n--) {
- while ((p >= low) && !(*wtest)((unsigned char) *p))
+ while ((p >= low) && !(*wtest)((unsigned char) *p))
p--;
- while ((p >= low) && (*wtest)((unsigned char) *p))
+ while ((p >= low) && (*wtest)((unsigned char) *p))
p--;
}
@@ -200,9 +200,9 @@ c__next_word(p, high, n, wtest)
int (*wtest) __P((int));
{
while (n--) {
- while ((p < high) && !(*wtest)((unsigned char) *p))
+ while ((p < high) && !(*wtest)((unsigned char) *p))
p++;
- while ((p < high) && (*wtest)((unsigned char) *p))
+ while ((p < high) && (*wtest)((unsigned char) *p))
p++;
}
if (p > high)
@@ -225,14 +225,14 @@ cv_next_word(el, p, high, n, wtest)
while (n--) {
test = (*wtest)((unsigned char) *p);
- while ((p < high) && (*wtest)((unsigned char) *p) == test)
+ while ((p < high) && (*wtest)((unsigned char) *p) == test)
p++;
/*
* vi historically deletes with cw only the word preserving the
* trailing whitespace! This is not what 'w' does..
*/
- if (el->el_chared.c_vcmd.action != (DELETE|INSERT))
- while ((p < high) && isspace((unsigned char) *p))
+ if (el->el_chared.c_vcmd.action != (DELETE|INSERT))
+ while ((p < high) && isspace((unsigned char) *p))
p++;
}
@@ -262,14 +262,14 @@ cv_prev_word(el, p, low, n, wtest)
* vi historically deletes with cb only the word preserving the
* leading whitespace! This is not what 'b' does..
*/
- if (el->el_chared.c_vcmd.action != (DELETE|INSERT))
- while ((p > low) && isspace((unsigned char) *p))
+ if (el->el_chared.c_vcmd.action != (DELETE|INSERT))
+ while ((p > low) && isspace((unsigned char) *p))
p--;
test = (*wtest)((unsigned char) *p);
- while ((p >= low) && (*wtest)((unsigned char) *p) == test)
+ while ((p >= low) && (*wtest)((unsigned char) *p) == test)
p--;
p++;
- while (isspace((unsigned char) *p))
+ while (isspace((unsigned char) *p))
p++;
}
@@ -319,7 +319,7 @@ c__number(p, num, dval)
* Finish vi delete action
*/
protected void
-cv_delfini(el)
+cv_delfini(el)
EditLine *el;
{
register int size;
@@ -331,13 +331,13 @@ cv_delfini(el)
oaction = el->el_chared.c_vcmd.action;
el->el_chared.c_vcmd.action = NOP;
- if (el->el_chared.c_vcmd.pos == 0)
+ if (el->el_chared.c_vcmd.pos == 0)
return;
if (el->el_line.cursor > el->el_chared.c_vcmd.pos) {
size = (int) (el->el_line.cursor - el->el_chared.c_vcmd.pos);
- c_delbefore(el, size);
+ c_delbefore(el, size);
el->el_line.cursor = el->el_chared.c_vcmd.pos;
re_refresh_cursor(el);
}
@@ -362,7 +362,7 @@ cv_delfini(el)
abort();
break;
}
-
+
el->el_chared.c_undo.ptr = el->el_line.cursor;
el->el_chared.c_undo.dsize = size;
@@ -383,7 +383,7 @@ ce__endword(p, high, n)
while (n--) {
while ((p < high) && isspace((unsigned char) *p))
p++;
- while ((p < high) && !isspace((unsigned char) *p))
+ while ((p < high) && !isspace((unsigned char) *p))
p++;
}
@@ -404,14 +404,14 @@ cv__endword(p, high, n)
p++;
while (n--) {
- while ((p < high) && isspace((unsigned char) *p))
+ while ((p < high) && isspace((unsigned char) *p))
p++;
if (isalnum((unsigned char) *p))
- while ((p < high) && isalnum((unsigned char) *p))
+ while ((p < high) && isalnum((unsigned char) *p))
p++;
else
- while ((p < high) && !(isspace((unsigned char) *p) ||
+ while ((p < high) && !(isspace((unsigned char) *p) ||
isalnum((unsigned char) *p)))
p++;
}
@@ -458,7 +458,7 @@ ch_init(el)
el->el_chared.c_macro.nline = NULL;
el->el_chared.c_macro.level = -1;
- el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO *
+ el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO *
sizeof(char *));
return 0;
}
@@ -551,7 +551,7 @@ el_deletestr(el, n)
if (n <= 0)
return;
- if (el->el_line.cursor < &el->el_line.buffer[n])
+ if (el->el_line.cursor < &el->el_line.buffer[n])
return;
c_delbefore(el, n); /* delete before dot */
@@ -575,8 +575,8 @@ c_gets(el, buf)
if (el_getc(el, &ch) != 1)
return ed_end_of_file(el, 0);
switch (ch) {
- case 0010: /* Delete and backspace */
- case 0177:
+ case '\010': /* Delete and backspace */
+ case '\177':
if (len > 1) {
*el->el_line.cursor-- = '\0';
el->el_line.lastchar = el->el_line.cursor;
@@ -592,7 +592,7 @@ c_gets(el, buf)
ch = 0;
break;
- case 0033: /* ESC */
+ case '\033': /* ESC */
case '\r': /* Newline */
case '\n':
break;
@@ -630,7 +630,7 @@ c_hpos(el)
if (el->el_line.cursor == el->el_line.buffer)
return 0;
else {
- for (ptr = el->el_line.cursor - 1;
+ for (ptr = el->el_line.cursor - 1;
ptr >= el->el_line.buffer && *ptr != '\n';
ptr--)
continue;
diff --git a/lib/libedit/chared.h b/lib/libedit/chared.h
index 20da6c8..22d07f0 100644
--- a/lib/libedit/chared.h
+++ b/lib/libedit/chared.h
@@ -54,7 +54,7 @@
* like real vi: i.e. the transition from command<->insert modes moves
* the cursor.
*
- * On the other hand we really don't want to move the cursor, because
+ * On the other hand we really don't want to move the cursor, because
* all the editing commands don't include the character under the cursor.
* Probably the best fix is to make all the editing commands aware of
* this fact.
@@ -68,7 +68,7 @@ typedef struct c_macro_t {
char *nline;
} c_macro_t;
-/*
+/*
* Undo information for both vi and emacs
*/
typedef struct c_undo_t {
@@ -139,7 +139,7 @@ protected void cv_delfini __P((EditLine *));
protected char *cv__endword __P((char *, char *, int));
protected int ce__isword __P((int));
protected void cv_undo __P((EditLine *, int, int, char *));
-protected char *cv_next_word __P((EditLine*, char *, char *, int,
+protected char *cv_next_word __P((EditLine*, char *, char *, int,
int (*)(int)));
protected char *cv_prev_word __P((EditLine*, char *, char *, int,
int (*)(int)));
diff --git a/lib/libedit/common.c b/lib/libedit/common.c
index 696da52..6908819 100644
--- a/lib/libedit/common.c
+++ b/lib/libedit/common.c
@@ -44,7 +44,7 @@ static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93";
#include "sys.h"
#include "el.h"
-/* ed_end_of_file():
+/* ed_end_of_file():
* Indicate end of file
* [^D]
*/
@@ -60,7 +60,7 @@ ed_end_of_file(el, c)
}
-/* ed_insert():
+/* ed_insert():
* Add character to the line
* Insert a character [bound to all insert keys]
*/
@@ -74,16 +74,16 @@ ed_insert(el, c)
if (c == '\0')
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)
return CC_ERROR; /* end of buffer space */
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_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_delafter(el, 1);
}
c_insert(el, 1);
@@ -95,12 +95,12 @@ ed_insert(el, c)
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++] =
+ 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_delafter(el, el->el_state.argument);
}
c_insert(el, el->el_state.argument);
@@ -117,7 +117,7 @@ ed_insert(el, c)
}
-/* ed_delete_prev_word():
+/* ed_delete_prev_word():
* Delete from beginning of current word to cursor
* [M-^?] [^W]
*/
@@ -132,7 +132,7 @@ ed_delete_prev_word(el, c)
if (el->el_line.cursor == el->el_line.buffer)
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);
for (p = cp, kp = el->el_chared.c_kill.buf; p < el->el_line.cursor; p++)
@@ -147,7 +147,7 @@ ed_delete_prev_word(el, c)
}
-/* ed_delete_next_char():
+/* ed_delete_next_char():
* Delete character under cursor
* [^D] [x]
*/
@@ -159,12 +159,12 @@ ed_delete_next_char(el, c)
{
#ifdef notdef /* XXX */
#define EL el->el_line
-fprintf(stderr, "\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n",
+fprintf(stderr, "\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n",
EL.buffer, EL.buffer, EL.cursor, EL.cursor, EL.lastchar, EL.lastchar, EL.limit, EL.limit);
#endif
if (el->el_line.cursor == el->el_line.lastchar) {/* if I'm at the end */
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 */
#ifdef KSHVI
return CC_ERROR;
@@ -196,7 +196,7 @@ fprintf(stderr, "\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n",
}
-/* ed_kill_line():
+/* ed_kill_line():
* Cut to the end of line
* [^K] [^K]
*/
@@ -218,7 +218,7 @@ ed_kill_line(el, c)
}
-/* ed_move_to_end():
+/* ed_move_to_end():
* Move cursor to the end of line
* [^E] [^E]
*/
@@ -242,7 +242,7 @@ ed_move_to_end(el, c)
}
-/* ed_move_to_beg():
+/* ed_move_to_beg():
* Move cursor to the beginning of line
* [^A] [^A]
*/
@@ -256,7 +256,7 @@ ed_move_to_beg(el, c)
if (el->el_map.type == MAP_VI) {
/* We want FIRST non space character */
- while (isspace(*el->el_line.cursor))
+ while (isspace((unsigned char) *el->el_line.cursor))
el->el_line.cursor++;
if (el->el_chared.c_vcmd.action & DELETE) {
cv_delfini(el);
@@ -268,7 +268,7 @@ ed_move_to_beg(el, c)
}
-/* ed_transpose_chars():
+/* ed_transpose_chars():
* Exchange the character to the left of the cursor with the one under it
* [^T] [^T]
*/
@@ -280,7 +280,7 @@ ed_transpose_chars(el, c)
if (el->el_line.cursor < el->el_line.lastchar) {
if (el->el_line.lastchar <= &el->el_line.buffer[1])
return CC_ERROR;
- else
+ else
el->el_line.cursor++;
}
if (el->el_line.cursor > &el->el_line.buffer[1]) {
@@ -290,12 +290,12 @@ ed_transpose_chars(el, c)
el->el_line.cursor[-1] = c;
return CC_REFRESH;
}
- else
+ else
return CC_ERROR;
}
-/* ed_next_char():
+/* ed_next_char():
* Move to the right one character
* [^F] [^F]
*/
@@ -322,7 +322,7 @@ ed_next_char(el, c)
}
-/* ed_prev_word():
+/* ed_prev_word():
* Move to the beginning of the current word
* [M-b] [b]
*/
@@ -335,8 +335,8 @@ ed_prev_word(el, c)
if (el->el_line.cursor == el->el_line.buffer)
return CC_ERROR;
- el->el_line.cursor = c__prev_word(el->el_line.cursor, el->el_line.buffer,
- el->el_state.argument,
+ el->el_line.cursor = c__prev_word(el->el_line.cursor, el->el_line.buffer,
+ el->el_state.argument,
ce__isword);
if (el->el_map.type == MAP_VI)
@@ -349,7 +349,7 @@ ed_prev_word(el, c)
}
-/* ed_prev_char():
+/* ed_prev_char():
* Move to the left one character
* [^B] [^B]
*/
@@ -372,12 +372,12 @@ ed_prev_char(el, c)
return CC_CURSOR;
}
- else
+ else
return CC_ERROR;
}
-/* ed_quoted_insert():
+/* ed_quoted_insert():
* Add the next character typed verbatim
* [^V] [^V]
*/
@@ -400,7 +400,7 @@ ed_quoted_insert(el, c)
}
-/* ed_digit():
+/* ed_digit():
* Adds to argument or enters a digit
*/
protected el_action_t
@@ -408,17 +408,17 @@ ed_digit(el, c)
EditLine *el;
int c;
{
- if (!isdigit(c))
+ if (!isdigit((unsigned char) c))
return CC_ERROR;
- if (el->el_state.doingarg) {
+ if (el->el_state.doingarg) {
/* 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';
else {
if (el->el_state.argument > 1000000)
return CC_ERROR;
- el->el_state.argument =
+ el->el_state.argument =
(el->el_state.argument * 10) + (c - '0');
}
return CC_ARGHACK;
@@ -428,10 +428,10 @@ ed_digit(el, c)
return CC_ERROR;
if (el->el_state.inputmode != MODE_INSERT) {
- el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] =
+ 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_delafter(el, 1);
}
c_insert(el, 1);
*el->el_line.cursor++ = c;
@@ -442,7 +442,7 @@ ed_digit(el, c)
}
-/* ed_argument_digit():
+/* ed_argument_digit():
* Digit that starts argument
* For ESC-n
*/
@@ -451,7 +451,7 @@ ed_argument_digit(el, c)
EditLine *el;
register int c;
{
- if (!isdigit(c))
+ if (!isdigit((unsigned char) c))
return CC_ERROR;
if (el->el_state.doingarg) {
@@ -467,7 +467,7 @@ ed_argument_digit(el, c)
}
-/* ed_unassigned():
+/* ed_unassigned():
* Indicates unbound character
* Bound to keys that are not assigned
*/
@@ -487,7 +487,7 @@ ed_unassigned(el, c)
** TTY key handling.
**/
-/* ed_tty_sigint():
+/* ed_tty_sigint():
* Tty interrupt character
* [^C]
*/
@@ -496,12 +496,12 @@ protected el_action_t
ed_tty_sigint(el, c)
EditLine *el;
int c;
-{
+{
return CC_NORM;
}
-/* ed_tty_dsusp():
+/* ed_tty_dsusp():
* Tty delayed suspend character
* [^Y]
*/
@@ -515,7 +515,7 @@ ed_tty_dsusp(el, c)
}
-/* ed_tty_flush_output():
+/* ed_tty_flush_output():
* Tty flush output characters
* [^O]
*/
@@ -529,7 +529,7 @@ ed_tty_flush_output(el, c)
}
-/* ed_tty_sigquit():
+/* ed_tty_sigquit():
* Tty quit character
* [^\]
*/
@@ -543,7 +543,7 @@ ed_tty_sigquit(el, c)
}
-/* ed_tty_sigtstp():
+/* ed_tty_sigtstp():
* Tty suspend character
* [^Z]
*/
@@ -557,7 +557,7 @@ ed_tty_sigtstp(el, c)
}
-/* ed_tty_stop_output():
+/* ed_tty_stop_output():
* Tty disallow output characters
* [^S]
*/
@@ -571,7 +571,7 @@ ed_tty_stop_output(el, c)
}
-/* ed_tty_start_output():
+/* ed_tty_start_output():
* Tty allow output characters
* [^Q]
*/
@@ -585,7 +585,7 @@ ed_tty_start_output(el, c)
}
-/* ed_newline():
+/* ed_newline():
* Execute command
* [^J]
*/
@@ -604,7 +604,7 @@ ed_newline(el, c)
}
-/* ed_delete_prev_char():
+/* ed_delete_prev_char():
* Delete the character to the left of the cursor
* [^?]
*/
@@ -614,10 +614,10 @@ ed_delete_prev_char(el, c)
EditLine *el;
int c;
{
- if (el->el_line.cursor <= el->el_line.buffer)
+ if (el->el_line.cursor <= el->el_line.buffer)
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;
if (el->el_line.cursor < el->el_line.buffer)
el->el_line.cursor = el->el_line.buffer;
@@ -625,7 +625,7 @@ ed_delete_prev_char(el, c)
}
-/* ed_clear_screen():
+/* ed_clear_screen():
* Clear screen leaving current line at the top
* [^L]
*/
@@ -641,7 +641,7 @@ ed_clear_screen(el, c)
}
-/* ed_redisplay():
+/* ed_redisplay():
* Redisplay everything
* ^R
*/
@@ -651,13 +651,11 @@ ed_redisplay(el, c)
EditLine *el;
int c;
{
- re_clear_lines(el);
- re_clear_display(el);
- return CC_REFRESH;
+ return CC_REDISPLAY;
}
-/* ed_start_over():
+/* ed_start_over():
* Erase current line and start from scratch
* [^G]
*/
@@ -672,7 +670,7 @@ ed_start_over(el, c)
}
-/* ed_sequence_lead_in():
+/* ed_sequence_lead_in():
* First character in a bound sequence
* Placeholder for external keys
*/
@@ -686,7 +684,7 @@ ed_sequence_lead_in(el, c)
}
-/* ed_prev_history():
+/* ed_prev_history():
* Move to the previous history line
* [^P] [k]
*/
@@ -703,7 +701,7 @@ ed_prev_history(el, c)
if (el->el_history.eventno == 0) { /* save the current buffer away */
(void) strncpy(el->el_history.buf, el->el_line.buffer, 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);
}
@@ -712,7 +710,7 @@ ed_prev_history(el, c)
if (hist_get(el) == CC_ERROR) {
beep = 1;
/* el->el_history.eventno was fixed by first call */
- (void) hist_get(el);
+ (void) hist_get(el);
}
re_refresh(el);
@@ -723,7 +721,7 @@ ed_prev_history(el, c)
}
-/* ed_next_history():
+/* ed_next_history():
* Move to the next history line
* [^N] [j]
*/
@@ -747,7 +745,7 @@ ed_next_history(el, c)
}
-/* ed_search_prev_history():
+/* ed_search_prev_history():
* Search previous in history for a line matching the current
* next search history [M-P] [K]
*/
@@ -774,7 +772,7 @@ ed_search_prev_history(el, c)
if (el->el_history.eventno == 0) {
(void) strncpy(el->el_history.buf, el->el_line.buffer, 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);
}
@@ -795,9 +793,9 @@ ed_search_prev_history(el, c)
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
#endif
- if ((strncmp(hp, el->el_line.buffer,
- el->el_line.lastchar - el->el_line.buffer) ||
- hp[el->el_line.lastchar-el->el_line.buffer]) &&
+ if ((strncmp(hp, el->el_line.buffer,
+ el->el_line.lastchar - el->el_line.buffer) ||
+ hp[el->el_line.lastchar-el->el_line.buffer]) &&
c_hmatch(el, hp)) {
found++;
break;
@@ -808,7 +806,7 @@ ed_search_prev_history(el, c)
if (!found) {
#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "not found\n");
+ (void) fprintf(el->el_errfile, "not found\n");
#endif
return CC_ERROR;
}
@@ -819,7 +817,7 @@ ed_search_prev_history(el, c)
}
-/* ed_search_next_history():
+/* ed_search_next_history():
* Search next in history for a line matching the current
* [M-N] [J]
*/
@@ -853,9 +851,9 @@ ed_search_next_history(el, c)
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
#endif
- if ((strncmp(hp, el->el_line.buffer,
- el->el_line.lastchar - el->el_line.buffer) ||
- hp[el->el_line.lastchar-el->el_line.buffer]) &&
+ if ((strncmp(hp, el->el_line.buffer,
+ el->el_line.lastchar - el->el_line.buffer) ||
+ hp[el->el_line.lastchar-el->el_line.buffer]) &&
c_hmatch(el, hp))
found = h;
hp = HIST_NEXT(el);
@@ -864,7 +862,7 @@ ed_search_next_history(el, c)
if (!found) { /* is it the current history number? */
if (!c_hmatch(el, el->el_history.buf)) {
#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "not found\n");
+ (void) fprintf(el->el_errfile, "not found\n");
#endif
return CC_ERROR;
}
@@ -888,7 +886,7 @@ ed_prev_line(el, c)
{
char *ptr;
int nchars = c_hpos(el);
-
+
/*
* Move to the line requested
*/
@@ -907,15 +905,15 @@ ed_prev_line(el, c)
*/
for (ptr--; ptr >= el->el_line.buffer && *ptr != '\n'; ptr--)
continue;
-
+
/*
* Move to the character requested
*/
- for (ptr++;
- nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
+ for (ptr++;
+ nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
ptr++)
continue;
-
+
el->el_line.cursor = ptr;
return CC_CURSOR;
}
@@ -948,16 +946,16 @@ ed_next_line(el, c)
* Move to the character requested
*/
for (ptr++;
- nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
+ nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
ptr++)
continue;
-
+
el->el_line.cursor = ptr;
return CC_CURSOR;
}
-/* ed_command():
+/* ed_command():
* Editline extended command
* [M-X] [:]
*/
diff --git a/lib/libedit/editline.3 b/lib/libedit/editline.3
new file mode 100644
index 0000000..b2858f6
--- /dev/null
+++ b/lib/libedit/editline.3
@@ -0,0 +1,532 @@
+.\" $NetBSD: editline.3,v 1.4 1997/01/14 04:17:23 lukem Exp $
+.\"
+.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 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 NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT 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 SUCH DAMAGE.
+.\"
+.Dd January 11, 1997
+.Os BSD 4.4
+.Dt EDITLINE 3
+.Sh NAME
+.Nm editline ,
+.Nm el_init ,
+.Nm el_end ,
+.Nm el_reset ,
+.Nm el_gets ,
+.Nm el_getc ,
+.Nm el_push ,
+.Nm el_parse ,
+.Nm el_set ,
+.Nm el_source ,
+.Nm el_resize ,
+.Nm el_line ,
+.Nm el_insertstr ,
+.Nm el_deletestr ,
+.Nm history_init ,
+.Nm history_end ,
+.Nm history
+.Nd line editor and history functions
+.Sh SYNOPSIS
+.Fd #include <histedit.h>
+.Ft EditLine *
+.Fn el_init "const char *prog" "FILE *fin" "FILE *fout"
+.Ft void
+.Fn el_end "EditLine *e"
+.Ft void
+.Fn el_reset "EditLine *e"
+.Ft const char *
+.Fn el_gets "EditLine *e" "int *count"
+.Ft int
+.Fn el_getc "EditLine *e" "char *ch"
+.Ft void
+.Fn el_push "EditLine *e" "const char *str"
+.Ft int
+.Fn el_parse "EditLine *e" "int argc" "char *argv[]"
+.Ft int
+.Fn el_set "EditLine *e" "int op" "..."
+.Ft int
+.Fn el_source "EditLine *e" "const char *file"
+.Ft void
+.Fn el_resize "EditLine *e"
+.Ft const LineInfo *
+.Fn el_line "EditLine *e"
+.Ft int
+.Fn el_insertstr "EditLine *e" "char *str"
+.Ft void
+.Fn el_deletestr "EditLine *e" "int count"
+.Ft History *
+.Fn history_init
+.Ft void
+.Fn history_end "History *h"
+.Ft HistEvent *
+.Fn history "History h" "int op" "..."
+.Sh DESCRIPTION
+The
+.Nm
+library provides generic line editing and history functions,
+similar to those found in
+.Xr sh 1 .
+.Pp
+These functions are available in the
+.Nm libedit
+library (which needs the
+.Nm libtermcap
+library).
+Programs should be linked with
+.Fl ledit ltermcap .
+.Sh LINE EDITING FUNCTIONS
+The line editing functions use a common data structure,
+.Fa EditLine ,
+which is created by
+.Fn el_init
+and freed by
+.Fn el_end .
+.Pp
+The following functions are available:
+.Bl -tag -width 4n
+.It Fn el_init
+Initialise the line editor, and return a data structure
+to be used by all other line editing functions.
+.Fa prog
+is the name of the invoking program, used when reading the
+.Xr editrc 5
+file to determine which settings to use.
+.Fa fin
+and
+.Fa fout
+are the input and output streams (respectively) to use.
+In this documentation, references to
+.Dq the tty
+are actually to this input/output stream combination.
+.It Fn el_end
+Clean up and finish with
+.Fa e ,
+assumed to have been created with
+.Fn el_init .
+.It Fn el_reset
+Reset the tty and the parser.
+This should be called after an error which may have upset the tty's
+state.
+.It Fn el_gets
+Read a line from the tty.
+.Fa count
+is modified to contain the number of characters read.
+Returns the line read if successful, or
+.Dv NULL
+if no characters were read or if an error occurred.
+.It Fn el_getc
+Read a character from the tty.
+.Fa ch
+is modified to contain the character read.
+Returns the number of characters read if successful, -1 otherwise.
+.It Fn el_push
+Pushes
+.Fa str
+back onto the input stream.
+This is used by the macro expansion mechanism.
+Refer to the description of
+.Ic bind
+.Fl s
+in
+.Xr editrc 5
+for more information.
+.It Fn el_parse
+Parses the
+.Fa argv
+array (which is
+.Fa argc
+elements in size)
+to execute builtin
+.Nm
+commands.
+If the command is prefixed with
+.Dq prog:
+then
+.Fn el_parse
+will only execute the command if
+.Dq prog
+matches the
+.Fa prog
+argument supplied to
+.Fn el_init .
+The return value is
+-1 if the command is unknown,
+0 if there was no error or
+.Dq prog
+didn't match, or
+1 if the command returned an error.
+Refer to
+.Xr editrc 5
+for more information.
+.Pp
+.Em NOTE:
+.Va argv[0]
+may be modified by
+.Fn el_parse .
+The colon between
+.Dq prog
+and the command,
+.Ar command ,
+will be replaced with a NUL
+.Po
+.Dq \e0
+.Pc .
+.It Fn el_set
+Set
+.Nm
+parameters.
+.Fa op
+determines which parameter to set, and each operation has its
+own parameter list.
+.Pp
+The following values for
+.Fa op
+are supported, along with the required argument list:
+.Bl -tag -width 4n
+.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
+Define prompt printing function as
+.Fa f ,
+which is to return a string that contains the prompt.
+.It Dv EL_TERMINAL , Fa "const char *type"
+Define terminal type of the tty to be
+.Fa type ,
+or to
+.Ev TERM
+if
+.Fa type
+is
+.Dv NULL .
+.It Dv EL_EDITOR , Fa "const char *mode"
+Set editing mode to
+.Fa mode ,
+which must be one of
+.Dq emacs
+or
+.Dq vi .
+.It Dv EL_SIGNAL , Fa "int flag"
+If
+.Fa flag
+is non-zero,
+.Nm
+will install its own signal handler for the following signals when
+reading command input:
+.Dv SIGCONT ,
+.Dv SIGHUP ,
+.Dv SIGINT ,
+.Dv SIGQUIT ,
+.Dv SIGSTOP ,
+.Dv SIGTERM ,
+.Dv SIGTSTP ,
+and
+.Dv SIGWINCH .
+Otherwise, the current signal handlers will be used.
+.It Dv EL_BIND , Xo
+.Fa "const char *" ,
+.Fa "..." ,
+.Dv NULL
+.Xc
+Perform the
+.Ic bind
+builtin command.
+Refer to
+.Xr editrc 5
+for more information.
+.It Dv EL_ECHOTC , Xo
+.Fa "const char *" ,
+.Fa "..." ,
+.Dv NULL
+.Xc
+Perform the
+.Ic echotc
+builtin command.
+Refer to
+.Xr editrc 5
+for more information.
+.It Dv EL_SETTC , Xo
+.Fa "const char *" ,
+.Fa "..." ,
+.Dv NULL
+.Xc
+Perform the
+.Ic settc
+builtin command.
+Refer to
+.Xr editrc 5
+for more information.
+.It Dv EL_SETTY , Xo
+.Fa "const char *" ,
+.Fa "..." ,
+.Dv NULL
+.Xc
+Perform the
+.Ic setty
+builtin command.
+Refer to
+.Xr editrc 5
+for more information.
+.It Dv EL_TELLTC , Xo
+.Fa "const char *" ,
+.Fa "..." ,
+.Dv NULL
+.Xc
+Perform the
+.Ic telltc
+builtin command.
+Refer to
+.Xr editrc 5
+for more information.
+.It Dv EL_ADDFN , Xo
+.Fa "const char *name" ,
+.Fa "const char *help" ,
+.Fa "unsigned char (*func)(EditLine *e, int ch)
+.Xc
+Add a user defined function,
+.Fn func ,
+referred to as
+.Fa name
+which is invoked when a key which is bound to
+.Fa name
+is entered.
+.Fa help
+is a description of
+.Fa name .
+At invocation time,
+.Fa ch
+is the key which caused the invocation.
+The return value of
+.Fn func
+should be one of:
+.Bl -tag -width "CC_REDISPLAY"
+.It Dv CC_NORM
+Add a normal character.
+.It Dv CC_NEWLINE
+End of line was entered.
+.It Dv CC_EOF
+EOF was entered.
+.It Dv CC_ARGHACK
+Expecting further command input as arguments, do nothing visually.
+.It Dv CC_REFRESH
+Refresh display.
+.It Dv CC_CURSOR
+Cursor moved, so update and perform
+.Dv CC_REFRESH.
+.It Dv CC_REDISPLAY
+Redisplay entire input line.
+This is useful if a key binding outputs extra information.
+.It Dv CC_ERROR
+An error occurred.
+Beep, and flush tty.
+.It Dv CC_FATAL
+Fatal error, reset tty to known state.
+.El
+.It Dv EL_HIST , Xo
+.Fa "History *(*func)(History *, int op, ...)" ,
+.Fa "const char *ptr"
+.Xc
+Defines which history function to use, which is usually
+.Fn history .
+.Fa ptr
+should be the value returned by
+.Fn history_init .
+.El
+.It Fn el_source
+Initialise
+.Nm
+by reading the contents of
+.Fa file .
+.Fn el_parse
+is called for each line in
+.Fa file .
+If
+.Fa file
+is
+.Dv NULL ,
+try
+.Pa $PWD/.editrc
+then
+.Pa $HOME/.editrc .
+Refer to
+.Xr editrc 5
+for details on the format of
+.Fa file .
+.It Fn el_resize
+Must be called if the terminal size changes.
+If
+.Dv EL_SIGNAL
+has been set with
+.Fn el_set ,
+then this is done automatically.
+Otherwise, it's the responsibility of the application to call
+.Fn el_resize
+on the appropriate occasions.
+.It Fn el_line
+Return the editing information for the current line in a
+.Fa LineInfo
+structure, which is defined as follows:
+.Bd -literal
+typedef struct lineinfo {
+ const char *buffer; /* address of buffer */
+ const char *cursor; /* address of cursor */
+ const char *lastchar; /* address of last character */
+} LineInfo;
+.Ed
+.It Fn el_insertstr
+Insert
+.Fa str
+into the line at the cursor.
+Returns -1 if
+.Fa str
+is empty or won't fit, and 0 otherwise.
+.It Fn el_deletestr
+Delete
+.Fa num
+characters before the cursor.
+.El
+.Sh HISTORY LIST FUNCTIONS
+The history functions use a common data structure,
+.Fa History ,
+which is created by
+.Fn history_init
+and freed by
+.Fn history_end .
+.Pp
+The following functions are available:
+.Bl -tag -width 4n
+.It Fn history_init
+Initialise the history list, and return a data structure
+to be used by all other history list functions.
+.It Fn history_end
+Clean up and finish with
+.Fa h ,
+assumed to have been created with
+.Fn history_init .
+.It Fn history
+Perform operation
+.Fa op
+on the history list, with optional arguments as needed by the
+operation.
+The following values for
+.Fa op
+are supported, along with the required argument list:
+.Bl -tag -width 4n
+.It Dv H_EVENT , Fa "int size"
+Set size of history to
+.Fa size
+elements.
+.It Dv H_END
+Cleans up and finishes with
+.Fa h ,
+assumed to be created with
+.Fn history_init .
+.It Dv H_CLEAR
+Clear the history.
+.It Dv H_FUNC , Xo
+.Fa "void *ptr" ,
+.Fa "history_gfun_t first" ,
+.Fa "history_gfun_t next" ,
+.Fa "history_gfun_t last" ,
+.Fa "history_gfun_t prev" ,
+.Fa "history_gfun_t curr" ,
+.Fa "history_vfun_t clear" ,
+.Fa "history_efun_t enter" ,
+.Fa "history_efun_t add"
+.Xc
+Define functions to perform various history operations.
+.Fa ptr
+is the argument given to a function when it's invoked.
+.It Dv H_FIRST
+Return the first element in the history.
+.It Dv H_LAST
+Return the last element in the history.
+.It Dv H_PREV
+Return the previous element in the history.
+.It Dv H_NEXT
+Return the next element in the history.
+.It Dv H_CURR
+Return the current element in the history.
+.It Dv H_ADD , Fa "const char *str"
+Append
+.Fa str
+to the current element of the history, or create an element with
+.Dv H_ENTER
+if there isn't one.
+.It Dv H_ENTER , Fa "const char *str"
+Add
+.Fa str
+as a new element to the history, and, if necessary,
+removing the oldest entry to keep the list to the created size.
+.It Dv H_PREV_STR , Fa "const char *str"
+Return the closest previous event that starts with
+.Fa str .
+.It Dv H_NEXT_STR , Fa "const char *str"
+Return the closest next event that starts with
+.Fa str .
+.It Dv H_PREV_EVENT , Fa "int e"
+Return the previous event numbered
+.Fa e .
+.It Dv H_NEXT_EVENT , Fa "int e"
+Return the next event numbered
+.Fa e .
+.It Dv H_LOAD , Fa "const char *file"
+Load the history list stored in
+.Fa file .
+.It Dv H_SAVE , Fa "const char *file"
+Save the history list to
+.Fa file .
+.El
+.El
+.\"XXX.Sh EXAMPLES
+.\"XXX: provide some examples
+.Sh SEE ALSO
+.Xr editrc 5 ,
+.Xr sh 1 ,
+.Xr signal 3 ,
+.Xr termcap 3
+.Sh HISTORY
+The
+.Nm
+library first appeared in
+.Bx 4.4 .
+.Sh AUTHORS
+The
+.Nm
+library was written by Christos Zoulas,
+and this manual was written by Luke Mewburn.
+.Sh BUGS
+This documentation is probably incomplete.
+.Pp
+.Fn el_parse
+should not modify the supplied
+.Va argv[0] .
+.Pp
+The tokenization functions are not publically defined in
+.Fd <histedit.h>
diff --git a/lib/libedit/editrc.5 b/lib/libedit/editrc.5
new file mode 100644
index 0000000..e9b2992
--- /dev/null
+++ b/lib/libedit/editrc.5
@@ -0,0 +1,292 @@
+.\" $NetBSD: editrc.5,v 1.4 1997/04/24 20:20:31 christos Exp $
+.\"
+.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 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 NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT 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 SUCH DAMAGE.
+.\"
+.Dd January 11, 1997
+.Os BSD 4.4
+.Dt EDITRC 5
+.Sh NAME
+.Nm editrc
+.Nd configuration file for editline library
+.Sh SYNOPSIS
+.Nm
+.Sh DESCRIPTION
+The
+.Nm
+file defines various settings to be used by the
+.Xr editline 3
+library.
+.Pp
+The format of each line is either:
+.Dl prog:command [arg [...]]
+or
+.Dl command [arg [...]]
+.Pp
+.Ar command
+is one of the
+.Xr editline 3
+builtin commands.
+Refer to
+.Sx BUILTIN COMMANDS
+for more information.
+.Pp
+.Ar prog
+is the program name string that a program defines when it calls
+.Xr el_init 3
+to setup
+.Xr editline 3 ,
+which is usually
+.Va argv[0] .
+.Ar command
+will be executed for any program which matches
+.Ar prog .
+.Pp
+.Ar prog
+may also be a
+.Xr regex 3
+style
+regular expression, in which case
+.Ar command
+will be executed for any program that matches the regular expression.
+.Sh BUILTIN COMMANDS
+The
+.Nm editline
+library has some builtin commands, which affect the way
+that the line editing and history functions operate.
+These are based on similar named builtins present in the
+.Xr tcsh 1
+shell.
+.Pp
+The following builtin commands are available:
+.Bl -tag -width 4n
+.It Ic bind Xo
+.Op Fl a
+.Op Fl e
+.Op Fl k
+.Op Fl l
+.Op Fl r
+.Op Fl s
+.Op Fl v
+.Op Ar key Op Ar command
+.Xc
+Without options, list all bound keys, and the editor command to which
+each is bound.
+If
+.Ar key
+is supplied, show the bindings for
+.Ar key .
+If
+.Ar key command
+is supplied, bind
+.Ar command
+to
+.Ar key .
+Options include:
+.Bl -tag -width 4n
+.It Fl e
+Bind all keys to the standard GNU Emacs-like bindings.
+.It Fl v
+Bind all keys to the standard
+.Xr vi 1 -like
+bindings.
+.It Fl a
+List or change key bindings in the
+.Xr vi 1
+mode alternate (command mode) key map.
+.It Fl k
+.Ar key
+is interpreted as a symbolic arrow key name, which may be one of
+.Sq up ,
+.Sq down ,
+.Sq left
+or
+.Sq right .
+.It Fl l
+List all editor commands and a short description of each.
+.It Fl r
+Remove a key's binding.
+.It Fl s
+.Ar command
+is taken as a literal string and treated as terminal input when
+.Ar key
+is typed.
+Bound keys in
+.Ar command
+are themselves reinterpreted, and this continues for ten levels of
+interpretation.
+.El
+.Pp
+.Ar key
+and
+.Ar command
+can contain control characters of the form
+.Sm off
+.Sq No ^ Ar character
+.Sm on
+.Po
+e.g.
+.Sq ^A
+.Pc ,
+and the following backslashed escape sequences:
+.Pp
+.Bl -tag -compact -offset indent -width 4n
+.It Ic \ea
+Bell
+.It Ic \eb
+Backspace
+.It Ic \ee
+Escape
+.It Ic \ef
+Formfeed
+.It Ic \en
+Newline
+.It Ic \er
+Carriage return
+.It Ic \et
+Horizontal tab
+.It Ic \ev
+Vertical tab
+.Sm off
+.It Sy \e Ar nnn
+.Sm on
+The ASCII character corresponding to the octal number
+.Ar nnn .
+.El
+.Pp
+.Sq \e
+nullifies the special meaning of the following character,
+if it has any, notably
+.Sq \e
+and
+.Sq ^ .
+.It Ic echotc Xo
+.Op Fl sv
+.Ar arg
+.Ar ...
+.Xc
+Exercise terminal capabilities given in
+.Ar arg Ar ... .
+If
+.Ar arg
+is
+.Sq baud ,
+.Sq cols ,
+.Sq lines ,
+.Sq rows ,
+.Sq meta or
+.Sq tabs ,
+the value of that capability is printed, with
+.Dq yes
+or
+.Dq no
+indicating that the terminal does or does not have that capability.
+.Pp
+.Fl s
+returns an emptry string for non-existant capabilities, rather than
+causing an error.
+.Fl v
+causes messages to be verbose.
+.It Ic history
+List the history.
+.It Ic telltc
+List the values of all the terminal capabilities (see
+.Xr termcap 5 ).
+.It Ic settc Ar cap Ar val
+Set the terminal capability
+.Ar cap
+to
+.Ar val ,
+as defined in
+.Xr termcap 5 .
+No sanity checking is done.
+.It Ic setty Xo
+.Op Fl a
+.Op Fl d
+.Op Fl q
+.Op Fl x
+.Op Ar +mode
+.Op Ar -mode
+.Op Ar mode
+.Xc
+Control which tty modes that
+.Nm
+won't allow the user to change.
+.Fl d ,
+.Fl q
+or
+.Fl x
+tells
+.Ic setty
+to act on the
+.Sq edit ,
+.Sq quote
+or
+.Sq execute
+set of tty modes respectively; defaulting to
+.Fl x .
+.Pp
+Without other arguments,
+.Ic setty
+lists the modes in the chosen set which are fixed on
+.Po
+.Sq +mode
+.Pc
+or off
+.Po
+.Sq -mode
+.Pc .
+.Fl a
+lists all tty modes in the chosen set regardless of the setting.
+With
+.Ar +mode ,
+.Ar -mode
+or
+.Ar mode ,
+fixes
+.Ar mode
+on or off or removes control of
+.Ar mode
+in the chosen set.
+.El
+.Sh SEE ALSO
+.Xr editline 3 ,
+.Xr regex 3 ,
+.Xr termcap 5
+.Sh AUTHORS
+The
+.Nm editline
+library was written by Christos Zoulas,
+and this manual was written by Luke Mewburn,
+with some sections inspired by
+.Xr tcsh 1 .
diff --git a/lib/libedit/el.c b/lib/libedit/el.c
index 7314477..f163ec8 100644
--- a/lib/libedit/el.c
+++ b/lib/libedit/el.c
@@ -86,7 +86,7 @@ el_init(prog, fin, fout)
return NULL;
}
}
- else
+ else
#endif
el->el_errfile = stderr;
@@ -132,7 +132,7 @@ el_end(el)
el_free((ptr_t) el->el_prog);
el_free((ptr_t) el);
-} /* end el_end */
+} /* end el_end */
/* el_reset():
@@ -170,7 +170,7 @@ el_set(va_alist)
el = va_arg(va, EditLine *);
op = va_arg(va, int);
#endif
-
+
switch (op) {
case EL_PROMPT:
rv = prompt_set(el, va_arg(va, el_pfunc_t));
@@ -237,7 +237,7 @@ el_set(va_alist)
}
}
break;
-
+
case EL_ADDFN:
{
char *name = va_arg(va, char *);
@@ -291,23 +291,26 @@ el_source(el, fname)
if (fname == NULL) {
fname = &elpath[1];
if ((fp = fopen(fname, "r")) == NULL) {
- if ((ptr = getenv("HOME")) == NULL)
+ if ((ptr = getenv("HOME")) == NULL)
return -1;
- fname = strncpy(path, ptr, MAXPATHLEN);
- (void) strncat(path, elpath, MAXPATHLEN);
- path[MAXPATHLEN-1] = '\0';
+ (void)snprintf(path, sizeof(path), "%s%s", ptr, elpath);
+ fname = path;
}
}
- if ((fp = fopen(fname, "r")) == NULL)
+ if ((fp = fopen(fname, "r")) == NULL)
return -1;
- while ((ptr = fgetln(fp, &len)) != NULL)
- ptr[len - 1] = '\0';
+ while ((ptr = fgetln(fp, &len)) != NULL) {
+ if (ptr[len - 1] == '\n')
+ --len;
+ ptr[len] = '\0';
+
if (parse_line(el, ptr) == -1) {
(void) fclose(fp);
return -1;
}
+ }
(void) fclose(fp);
return 0;
diff --git a/lib/libedit/emacs.c b/lib/libedit/emacs.c
index f960a54..d84c360 100644
--- a/lib/libedit/emacs.c
+++ b/lib/libedit/emacs.c
@@ -38,7 +38,7 @@
static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */
-/*
+/*
* emacs.c: Emacs functions
*/
#include "sys.h"
@@ -55,20 +55,16 @@ em_delete_or_list(el, c)
int c;
{
if (el->el_line.cursor == el->el_line.lastchar) { /* if I'm at the end */
-#ifdef notyet
if (el->el_line.cursor == el->el_line.buffer) { /* and the beginning */
-#endif
term_overwrite(el, STReof, 4);/* then do a EOF */
term__flush();
return CC_EOF;
-#ifdef notyet
}
else {
- re_goto_bottom(el);
- *el->el_line.lastchar = '\0'; /* just in case */
- return CC_LIST_CHOICES;
+ /* Here we could list completions, but it is an error right now */
+ term_beep(el);
+ return CC_ERROR;
}
-#endif
}
else {
c_delafter(el, el->el_state.argument); /* delete after dot */
@@ -94,7 +90,7 @@ em_delete_next_word(el, c)
if (el->el_line.cursor == el->el_line.lastchar)
return CC_ERROR;
- cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
+ cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (p = el->el_line.cursor, kp = el->el_chared.c_kill.buf; p < cp; p++)
@@ -124,8 +120,8 @@ em_yank(el, c)
if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf)
return CC_ERROR;
- if (el->el_line.lastchar +
- (el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
+ if (el->el_line.lastchar +
+ (el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
el->el_line.limit)
return CC_ERROR;
@@ -133,13 +129,13 @@ em_yank(el, c)
cp = el->el_line.cursor;
/* open the space, */
- c_insert(el, el->el_chared.c_kill.last - el->el_chared.c_kill.buf);
+ c_insert(el, el->el_chared.c_kill.last - el->el_chared.c_kill.buf);
/* copy the chars */
- for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
+ for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
*cp++ = *kp;
/* if an arg, cursor at beginning else cursor at end */
- if (el->el_state.argument == 1)
+ if (el->el_state.argument == 1)
el->el_line.cursor = cp;
return CC_REFRESH;
@@ -255,7 +251,7 @@ em_gosmacs_traspose(el, c)
el->el_line.cursor[-1] = c;
return CC_REFRESH;
}
- else
+ else
return CC_ERROR;
}
@@ -273,11 +269,11 @@ em_next_word(el, c)
if (el->el_line.cursor == el->el_line.lastchar)
return CC_ERROR;
- el->el_line.cursor = c__next_word(el->el_line.cursor, el->el_line.lastchar,
+ el->el_line.cursor = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument,
ce__isword);
- if (el->el_map.type == MAP_VI)
+ if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action & DELETE) {
cv_delfini(el);
return CC_REFRESH;
@@ -298,12 +294,12 @@ em_upper_case(el, c)
{
char *cp, *ep;
- ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
+ ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++)
- if (islower(*cp))
- *cp = toupper(*cp);
+ if (islower((unsigned char)*cp))
+ *cp = toupper((unsigned char)*cp);
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
@@ -324,20 +320,20 @@ em_capitol_case(el, c)
{
char *cp, *ep;
- ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
+ ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++) {
- if (isalpha(*cp)) {
- if (islower(*cp))
- *cp = toupper(*cp);
+ if (isalpha((unsigned char)*cp)) {
+ if (islower((unsigned char)*cp))
+ *cp = toupper((unsigned char)*cp);
cp++;
break;
}
}
for (; cp < ep; cp++)
- if (isupper(*cp))
- *cp = tolower(*cp);
+ if (isupper((unsigned char)*cp))
+ *cp = tolower((unsigned char)*cp);
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
@@ -357,12 +353,12 @@ em_lower_case(el, c)
{
char *cp, *ep;
- ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
+ ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++)
- if (isupper(*cp))
- *cp = tolower(*cp);
+ if (isupper((unsigned char)*cp))
+ *cp = tolower((unsigned char)*cp);
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
@@ -387,7 +383,7 @@ em_set_mark(el, c)
/* em_exchange_mark():
- * Exchange the cursor and mark
+ * Exchange the cursor and mark
* [^X^X]
*/
protected el_action_t
@@ -431,7 +427,7 @@ em_meta_next(el, c)
EditLine *el;
int c;
{
- el->el_state.metanext = 1;
+ el->el_state.metanext = 1;
return CC_ARGHACK;
}
@@ -445,7 +441,7 @@ em_toggle_overwrite(el, c)
EditLine *el;
int c;
{
- el->el_state.inputmode =
+ el->el_state.inputmode =
(el->el_state.inputmode == MODE_INSERT) ? MODE_REPLACE : MODE_INSERT;
return CC_NORM;
}
@@ -467,8 +463,8 @@ em_copy_prev_word(el, c)
oldc = el->el_line.cursor;
/* does a bounds check */
- cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
- el->el_state.argument, ce__isword);
+ cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
+ el->el_state.argument, ce__isword);
c_insert(el, oldc - cp);
for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
diff --git a/lib/libedit/hist.c b/lib/libedit/hist.c
index 394df63..27dacd1 100644
--- a/lib/libedit/hist.c
+++ b/lib/libedit/hist.c
@@ -101,7 +101,7 @@ hist_get(el)
if (el->el_history.eventno == 0) { /* if really the current line */
(void) strncpy(el->el_line.buffer, el->el_history.buf, EL_BUFSIZ);
- el->el_line.lastchar = el->el_line.buffer +
+ el->el_line.lastchar = el->el_line.buffer +
(el->el_history.last - el->el_history.buf);
#ifdef KSHVI
diff --git a/lib/libedit/hist.h b/lib/libedit/hist.h
index 90c0569..3f0fb9e 100644
--- a/lib/libedit/hist.h
+++ b/lib/libedit/hist.h
@@ -65,6 +65,8 @@ typedef struct el_history_t {
#define HIST_LAST(el) HIST_FUN(el, H_LAST, NULL)
#define HIST_PREV(el) HIST_FUN(el, H_PREV, NULL)
#define HIST_EVENT(el, num) HIST_FUN(el, H_EVENT, num)
+#define HIST_LOAD(el, fname) HIST_FUN(el, H_LOAD fname)
+#define HIST_SAVE(el, fname) HIST_FUN(el, H_SAVE fname)
protected int hist_init __P((EditLine *));
protected void hist_end __P((EditLine *));
diff --git a/lib/libedit/history.c b/lib/libedit/history.c
index e866548..ac9c3a9 100644
--- a/lib/libedit/history.c
+++ b/lib/libedit/history.c
@@ -51,10 +51,13 @@ static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93";
#include <varargs.h>
#endif
+static const char hist_cookie[] = "_HiStOrY_V1_\n";
+
#include "histedit.h"
typedef const HistEvent * (*history_gfun_t) __P((ptr_t));
typedef const HistEvent * (*history_efun_t) __P((ptr_t, const char *));
+typedef void (*history_vfun_t) __P((ptr_t));
struct history {
ptr_t h_ref; /* Argument for history fcns */
@@ -63,6 +66,7 @@ struct history {
history_gfun_t h_last; /* Get the last element */
history_gfun_t h_prev; /* Get the previous element */
history_gfun_t h_curr; /* Get the current element */
+ history_vfun_t h_clear; /* Clear the history list */
history_efun_t h_enter; /* Add an element */
history_efun_t h_add; /* Append to an element */
};
@@ -72,6 +76,7 @@ struct history {
#define HPREV(h) (*(h)->h_prev)((h)->h_ref)
#define HLAST(h) (*(h)->h_last)((h)->h_ref)
#define HCURR(h) (*(h)->h_curr)((h)->h_ref)
+#define HCLEAR(h) (*(h)->h_clear)((h)->h_ref)
#define HENTER(h, str) (*(h)->h_enter)((h)->h_ref, str)
#define HADD(h, str) (*(h)->h_add)((h)->h_ref, str)
@@ -80,13 +85,9 @@ struct history {
private int history_set_num __P((History *, int));
-private int history_set_fun __P((History *, history_gfun_t,
- history_gfun_t,
- history_gfun_t,
- history_gfun_t,
- history_gfun_t,
- history_efun_t,
- history_efun_t, ptr_t));
+private int history_set_fun __P((History *, History *));
+private int history_load __P((History *, const char *));
+private int history_save __P((History *, const char *));
private const HistEvent *history_prev_event __P((History *, int));
private const HistEvent *history_next_event __P((History *, int));
private const HistEvent *history_next_string __P((History *, const char *));
@@ -120,7 +121,7 @@ private const HistEvent *history_def_curr __P((ptr_t));
private const HistEvent *history_def_enter __P((ptr_t, const char *));
private const HistEvent *history_def_add __P((ptr_t, const char *));
private void history_def_init __P((ptr_t *, int));
-private void history_def_end __P((ptr_t));
+private void history_def_clear __P((ptr_t));
private const HistEvent *history_def_insert __P((history_t *, const char *));
private void history_def_delete __P((history_t *, hentry_t *));
@@ -130,7 +131,7 @@ private void history_def_delete __P((history_t *, hentry_t *));
/* history_def_first():
* Default function to return the first event in the history.
*/
-private const HistEvent *
+private const HistEvent *
history_def_first(p)
ptr_t p;
{
@@ -145,7 +146,7 @@ history_def_first(p)
/* history_def_last():
* Default function to return the last event in the history.
*/
-private const HistEvent *
+private const HistEvent *
history_def_last(p)
ptr_t p;
{
@@ -160,7 +161,7 @@ history_def_last(p)
/* history_def_next():
* Default function to return the next event in the history.
*/
-private const HistEvent *
+private const HistEvent *
history_def_next(p)
ptr_t p;
{
@@ -181,7 +182,7 @@ history_def_next(p)
/* history_def_prev():
* Default function to return the previous event in the history.
*/
-private const HistEvent *
+private const HistEvent *
history_def_prev(p)
ptr_t p;
{
@@ -202,7 +203,7 @@ history_def_prev(p)
/* history_def_curr():
* Default function to return the current event in the history.
*/
-private const HistEvent *
+private const HistEvent *
history_def_curr(p)
ptr_t p;
{
@@ -231,8 +232,8 @@ history_def_add(p, str)
return (history_def_enter(p, str));
len = strlen(h->cursor->ev.str) + strlen(str) + 1;
s = (char *) h_malloc(len);
- (void) strcpy(s, h->cursor->ev.str);
- (void) strcat(s, str);
+ (void)strcpy(s, h->cursor->ev.str); /* XXX strcpy is safe */
+ (void)strcat(s, str); /* XXX strcat is safe */
h_free((ptr_t) h->cursor->ev.str);
h->cursor->ev.str = s;
return &h->cursor->ev;
@@ -296,7 +297,7 @@ history_def_enter(p, str)
* Always keep at least one entry.
* This way we don't have to check for the empty list.
*/
- while (h->cur > h->max + 1)
+ while (h->cur > h->max + 1)
history_def_delete(h, h->list.prev);
return ev;
}
@@ -324,17 +325,19 @@ history_def_init(p, n)
}
-/* history_def_end():
+/* history_def_clear():
* Default history cleanup function
*/
private void
-history_def_end(p)
+history_def_clear(p)
ptr_t p;
{
history_t *h = (history_t *) p;
while (h->list.prev != &h->list)
history_def_delete(h, h->list.prev);
+ h->eventno = 0;
+ h->cur = 0;
}
/************************************************************************/
@@ -354,6 +357,7 @@ history_init()
h->h_last = history_def_last;
h->h_prev = history_def_prev;
h->h_curr = history_def_curr;
+ h->h_clear = history_def_clear;
h->h_enter = history_def_enter;
h->h_add = history_def_add;
@@ -369,7 +373,7 @@ history_end(h)
History *h;
{
if (h->h_next == history_def_next)
- history_def_end(h->h_ref);
+ history_def_clear(h->h_ref);
}
@@ -393,16 +397,13 @@ history_set_num(h, num)
* Set history functions
*/
private int
-history_set_fun(h, first, next, last, prev, curr, enter, add, ptr)
- History *h;
- history_gfun_t first, next, last, prev, curr;
- history_efun_t enter, add;
- ptr_t ptr;
+history_set_fun(h, nh)
+ History *h, *nh;
{
- if (first == NULL || next == NULL ||
- last == NULL || prev == NULL || curr == NULL ||
- enter == NULL || add == NULL ||
- ptr == NULL ) {
+ if (nh->h_first == NULL || nh->h_next == NULL ||
+ nh->h_last == NULL || nh->h_prev == NULL || nh->h_curr == NULL ||
+ nh->h_enter == NULL || nh->h_add == NULL || nh->h_clear == NULL ||
+ nh->h_ref == NULL) {
if (h->h_next != history_def_next) {
history_def_init(&h->h_ref, 0);
h->h_first = history_def_first;
@@ -410,6 +411,7 @@ history_set_fun(h, first, next, last, prev, curr, enter, add, ptr)
h->h_last = history_def_last;
h->h_prev = history_def_prev;
h->h_curr = history_def_curr;
+ h->h_clear = history_def_clear;
h->h_enter = history_def_enter;
h->h_add = history_def_add;
}
@@ -417,16 +419,78 @@ history_set_fun(h, first, next, last, prev, curr, enter, add, ptr)
}
if (h->h_next == history_def_next)
- history_def_end(h->h_ref);
-
- h->h_next = next;
- h->h_first = first;
- h->h_enter = enter;
- h->h_add = add;
+ history_def_clear(h->h_ref);
+
+ h->h_first = nh->h_first;
+ h->h_next = nh->h_next;
+ h->h_last = nh->h_last;
+ h->h_prev = nh->h_prev;
+ h->h_curr = nh->h_curr;
+ h->h_clear = nh->h_clear;
+ h->h_enter = nh->h_enter;
+ h->h_add = nh->h_add;
return 0;
}
+/* history_load():
+ * History load function
+ */
+private int
+history_load(h, fname)
+ History *h;
+ const char *fname;
+{
+ FILE *fp;
+ char *line;
+ size_t sz;
+ int i = -1;
+
+ if ((fp = fopen(fname, "r")) == NULL)
+ return i;
+
+ if ((line = fgetln(fp, &sz)) == NULL)
+ goto done;
+
+ if (strncmp(line, hist_cookie, sz) != 0)
+ goto done;
+
+ for (i = 0; (line = fgetln(fp, &sz)) != NULL; i++) {
+ char c = line[sz];
+ line[sz] = '\0';
+ HENTER(h, line);
+ line[sz] = c;
+ }
+
+done:
+ (void) fclose(fp);
+ return i;
+}
+
+
+/* history_save():
+ * History save function
+ */
+private int
+history_save(h, fname)
+ History *h;
+ const char *fname;
+{
+ FILE *fp;
+ const HistEvent *ev;
+ int i = 0;
+
+ if ((fp = fopen(fname, "w")) == NULL)
+ return -1;
+
+ (void) fputs(hist_cookie, fp);
+ for (ev = HLAST(h); ev != NULL; ev = HPREV(h), i++)
+ (void) fprintf(fp, "%s", ev->str);
+ (void) fclose(fp);
+ return i;
+}
+
+
/* history_prev_event():
* Find the previous event, with number given
*/
@@ -509,12 +573,12 @@ history(va_alist)
va_list va;
const HistEvent *ev = NULL;
const char *str;
- static const HistEvent sev = { 0, "" };
+ static HistEvent sev = { 0, "" };
#if __STDC__
va_start(va, fun);
#else
- History *h;
+ History *h;
int fun;
va_start(va);
h = va_arg(va, History *);
@@ -552,6 +616,20 @@ history(va_alist)
ev = HCURR(h);
break;
+ case H_CLEAR:
+ HCLEAR(h);
+ break;
+
+ case H_LOAD:
+ sev.num = history_load(h, va_arg(va, const char *));
+ ev = &sev;
+ break;
+
+ case H_SAVE:
+ sev.num = history_save(h, va_arg(va, const char *));
+ ev = &sev;
+ break;
+
case H_PREV_EVENT:
ev = history_prev_event(h, va_arg(va, int));
break;
@@ -569,24 +647,29 @@ history(va_alist)
break;
case H_EVENT:
- if (history_set_num(h, va_arg(va, int)) == 0)
+ if (history_set_num(h, va_arg(va, int)) == 0) {
+ sev.num = -1;
ev = &sev;
+ }
break;
case H_FUNC:
{
- history_gfun_t first = va_arg(va, history_gfun_t);
- history_gfun_t next = va_arg(va, history_gfun_t);
- history_gfun_t last = va_arg(va, history_gfun_t);
- history_gfun_t prev = va_arg(va, history_gfun_t);
- history_gfun_t curr = va_arg(va, history_gfun_t);
- history_efun_t enter = va_arg(va, history_efun_t);
- history_efun_t add = va_arg(va, history_efun_t);
- ptr_t ptr = va_arg(va, ptr_t);
-
- if (history_set_fun(h, first, next, last, prev,
- curr, enter, add, ptr) == 0)
+ History hf;
+ hf.h_ref = va_arg(va, ptr_t);
+ hf.h_first = va_arg(va, history_gfun_t);
+ hf.h_next = va_arg(va, history_gfun_t);
+ hf.h_last = va_arg(va, history_gfun_t);
+ hf.h_prev = va_arg(va, history_gfun_t);
+ hf.h_curr = va_arg(va, history_gfun_t);
+ hf.h_clear = va_arg(va, history_vfun_t);
+ hf.h_enter = va_arg(va, history_efun_t);
+ hf.h_add = va_arg(va, history_efun_t);
+
+ if (history_set_fun(h, &hf) == 0) {
+ sev.num = -1;
ev = &sev;
+ }
}
break;
diff --git a/lib/libedit/key.c b/lib/libedit/key.c
index 058da0e..3da65d5 100644
--- a/lib/libedit/key.c
+++ b/lib/libedit/key.c
@@ -42,10 +42,10 @@ static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93";
* key.c: This module contains the procedures for maintaining
* the extended-key map.
*
- * An extended-key (key) is a sequence of keystrokes introduced
- * with an sequence introducer and consisting of an arbitrary
- * number of characters. This module maintains a map (the el->el_key.map)
- * to convert these extended-key sequences into input strs
+ * An extended-key (key) is a sequence of keystrokes introduced
+ * with an sequence introducer and consisting of an arbitrary
+ * number of characters. This module maintains a map (the el->el_key.map)
+ * to convert these extended-key sequences into input strs
* (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE).
*
* Warning:
@@ -65,8 +65,8 @@ static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93";
#include "el.h"
-/*
- * The Nodes of the el->el_key.map. The el->el_key.map is a linked list
+/*
+ * The Nodes of the el->el_key.map. The el->el_key.map is a linked list
* of these node elements
*/
struct key_node_t {
@@ -78,9 +78,9 @@ struct key_node_t {
struct key_node_t *sibling; /* ptr to another key with same prefix */
};
-private int node_trav __P((EditLine *, key_node_t *, char *,
+private int node_trav __P((EditLine *, key_node_t *, char *,
key_value_t *));
-private int node__try __P((key_node_t *, char *,
+private int node__try __P((key_node_t *, char *,
key_value_t *, int));
private key_node_t *node__get __P((int));
private void node__put __P((key_node_t *));
@@ -104,7 +104,7 @@ key_init(el)
el->el_key.map = NULL;
key_reset(el);
return 0;
-}
+}
/* key_end():
@@ -118,7 +118,7 @@ key_end(el)
el->el_key.buf = NULL;
/* XXX: provide a function to clear the keys */
el->el_key.map = NULL;
-}
+}
/* key_map_cmd():
@@ -167,7 +167,7 @@ key_reset(el)
* Looks up *ch in map and then reads characters until a
* complete match is found or a mismatch occurs. Returns the
* type of the match found (XK_STR, XK_CMD, or XK_EXE).
- * Returns NULL in val.str and XK_STR for no match.
+ * Returns NULL in val.str and XK_STR for no match.
* The last character read is returned in *ch.
*/
protected int
@@ -195,7 +195,7 @@ key_add(el, key, val, ntype)
int ntype;
{
if (key[0] == '\0') {
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"key_add: Null extended-key not allowed.\n");
return;
}
@@ -211,7 +211,7 @@ key_add(el, key, val, ntype)
el->el_key.map = node__get(key[0]); /* it is properly initialized */
/* Now recurse through el->el_key.map */
- (void) node__try(el->el_key.map, key, val, ntype);
+ (void) node__try(el->el_key.map, key, val, ntype);
return;
}
@@ -226,9 +226,9 @@ key_clear(el, map, in)
char *in;
{
if ((map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN) &&
- ((map == el->el_map.key &&
+ ((map == el->el_map.key &&
el->el_map.alt[(unsigned char) *in] != ED_SEQUENCE_LEAD_IN) ||
- (map == el->el_map.alt &&
+ (map == el->el_map.alt &&
el->el_map.key[(unsigned char) *in] != ED_SEQUENCE_LEAD_IN)))
(void) key_delete(el, in);
}
@@ -244,7 +244,7 @@ key_delete(el, key)
char *key;
{
if (key[0] == '\0') {
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"key_delete: Null extended-key not allowed.\n");
return -1;
}
@@ -515,7 +515,7 @@ node_lookup(el, str, ptr, cnt)
/* If match put this char into el->el_key.buf. Recurse */
if (ptr->ch == *str) {
/* match found */
- ncnt = key__decode_char(el->el_key.buf, cnt,
+ ncnt = key__decode_char(el->el_key.buf, cnt,
(unsigned char) ptr->ch);
if (ptr->next != NULL)
/* not yet at leaf */
@@ -557,7 +557,7 @@ node_enum(el, ptr, cnt)
if (cnt >= KEY_BUFSIZ - 5) { /* buffer too small */
el->el_key.buf[++cnt] = '"';
el->el_key.buf[++cnt] = '\0';
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"Some extended keys too long for internal print buffer");
(void) fprintf(el->el_errfile, " \"%s...\"\n", el->el_key.buf);
return 0;
@@ -607,18 +607,18 @@ key_kprint(el, key, val, ntype)
switch (ntype) {
case XK_STR:
case XK_EXE:
- (void) fprintf(el->el_errfile, fmt, key,
- key__decode_str(val->str, unparsbuf,
+ (void) fprintf(el->el_errfile, fmt, key,
+ key__decode_str(val->str, unparsbuf,
ntype == XK_STR ? "\"\"" : "[]"));
break;
case XK_CMD:
- for (fp = el->el_map.help; fp->name; fp++)
+ for (fp = el->el_map.help; fp->name; fp++)
if (val->cmd == fp->func) {
(void) fprintf(el->el_errfile, fmt, key, fp->name);
break;
}
#ifdef DEBUG_KEY
- if (fp->name == NULL)
+ if (fp->name == NULL)
(void) fprintf(el->el_errfile, "BUG! Command not found.\n");
#endif
@@ -640,6 +640,8 @@ key__decode_char(buf, cnt, ch)
char *buf;
int cnt, ch;
{
+ ch = (unsigned char)ch;
+
if (ch == 0) {
buf[cnt++] = '^';
buf[cnt] = '@';
@@ -648,10 +650,10 @@ key__decode_char(buf, cnt, ch)
if (iscntrl(ch)) {
buf[cnt++] = '^';
- if (ch == '\177')
+ if (ch == 0177)
buf[cnt] = '?';
else
- buf[cnt] = ch | 0100;
+ buf[cnt] = toascii(ch) | 0100;
}
else if (ch == '^') {
buf[cnt++] = '\\';
@@ -702,13 +704,13 @@ key__decode_str(str, buf, sep)
if (*p == '\177')
*b++ = '?';
else
- *b++ = *p | 0100;
+ *b++ = toascii(*p) | 0100;
}
else if (*p == '^' || *p == '\\') {
*b++ = '\\';
*b++ = *p;
}
- else if (*p == ' ' || (isprint((unsigned char) *p) &&
+ else if (*p == ' ' || (isprint((unsigned char) *p) &&
!isspace((unsigned char) *p))) {
*b++ = *p;
}
diff --git a/lib/libedit/key.h b/lib/libedit/key.h
index 2ed3afc..eed0818 100644
--- a/lib/libedit/key.h
+++ b/lib/libedit/key.h
@@ -65,7 +65,7 @@ protected void key_end __P((EditLine *));
protected key_value_t * key_map_cmd __P((EditLine *, int));
protected key_value_t * key_map_str __P((EditLine *, char *));
protected void key_reset __P((EditLine *));
-protected int key_get __P((EditLine *, char *,
+protected int key_get __P((EditLine *, char *,
key_value_t *));
protected void key_add __P((EditLine *, char *, key_value_t *,
int));
@@ -73,7 +73,7 @@ protected void key_clear __P((EditLine *, el_action_t *,
char *));
protected int key_delete __P((EditLine *, char *));
protected void key_print __P((EditLine *, char *));
-protected void key_kprint __P((EditLine *, char *,
+protected void key_kprint __P((EditLine *, char *,
key_value_t *, int));
protected char *key__decode_str __P((char *, char *, char *));
diff --git a/lib/libedit/map.c b/lib/libedit/map.c
index 3378217..3b282cc 100644
--- a/lib/libedit/map.c
+++ b/lib/libedit/map.c
@@ -39,7 +39,7 @@ static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */
/*
- * map.c: Editor function definitions
+ * map.c: Editor function definitions
*/
#include "sys.h"
#include <stdlib.h>
@@ -660,8 +660,8 @@ private el_action_t el_map_vi_command[] = {
/* 41 */ ED_UNASSIGNED, /* ) */
/* 42 */ ED_UNASSIGNED, /* * */
/* 43 */ ED_NEXT_HISTORY, /* + */
- /* 44 */ VI_REPEAT_PREV_CHAR, /* , */
- /* 45 */ ED_PREV_HISTORY, /* - */
+ /* 44 */ VI_REPEAT_PREV_CHAR, /* , */
+ /* 45 */ ED_PREV_HISTORY, /* - */
/* 46 */ ED_UNASSIGNED, /* . */
/* 47 */ VI_SEARCH_PREV, /* / */
/* 48 */ VI_ZERO, /* 0 */
@@ -882,7 +882,7 @@ protected int
map_init(el)
EditLine *el;
{
-
+
/*
* Make sure those are correct before starting.
*/
@@ -902,7 +902,7 @@ map_init(el)
el->el_map.vii = el_map_vi_insert;
el->el_map.help = (el_bindings_t *) el_malloc(sizeof(el_bindings_t) *
EL_NUM_FCNS);
- (void) memcpy(el->el_map.help, help__get(),
+ (void) memcpy(el->el_map.help, help__get(),
sizeof(el_bindings_t) * EL_NUM_FCNS);
el->el_map.func = (el_func_t *) el_malloc(sizeof(el_func_t) * EL_NUM_FCNS);
memcpy(el->el_map.func, func__get(), sizeof(el_func_t) * EL_NUM_FCNS);
@@ -948,8 +948,8 @@ map_init_nls(el)
int i;
el_action_t *map = el->el_map.key;
- for (i = 0200; i <= 0377; i++)
- if (isprint(i))
+ for (i = 0200; i <= 0377; i++)
+ if (isprint(i))
map[i] = ED_INSERT;
}
@@ -977,12 +977,12 @@ map_init_meta(el)
if (el->el_map.type == MAP_VI)
map = alt;
}
- else
+ else
map = alt;
}
buf[0] = (char) i;
buf[2] = 0;
- for (i = 0200; i <= 0377; i++)
+ for (i = 0200; i <= 0377; i++)
switch (map[i]) {
case ED_INSERT:
case ED_UNASSIGNED:
@@ -1061,17 +1061,17 @@ map_init_emacs(el)
map_init_nls(el);
buf[0] = CONTROL('X');
- buf[2] = 0;
buf[1] = CONTROL('X');
+ buf[2] = 0;
key_add(el, buf, key_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
-
+
tty_bind_char(el, 1);
term_bind_arrow(el);
}
/* map_set_editor():
- * Set the editor
+ * Set the editor
*/
protected int
map_set_editor(el, editor)
@@ -1106,12 +1106,12 @@ map_print_key(el, map, in)
(void) key__decode_str(in, outbuf, "");
for (bp = el->el_map.help; bp->name != NULL; bp++)
if (bp->func == map[(unsigned char) *in]) {
- (void) fprintf(el->el_outfile,
+ (void) fprintf(el->el_outfile,
"%s\t->\t%s\n", outbuf, bp->name);
return;
}
}
- else
+ else
key_print(el, in);
}
@@ -1144,13 +1144,13 @@ map_print_some_keys(el, map, first, last)
if (bp->func == map[first]) {
if (first == last) {
(void) fprintf(el->el_outfile, "%-15s-> %s\n",
- key__decode_str(firstbuf, unparsbuf, STRQQ),
+ key__decode_str(firstbuf, unparsbuf, STRQQ),
bp->name);
}
else {
(void) fprintf(el->el_outfile, "%-4s to %-7s-> %s\n",
key__decode_str(firstbuf, unparsbuf, STRQQ),
- key__decode_str(lastbuf, extrabuf, STRQQ),
+ key__decode_str(lastbuf, extrabuf, STRQQ),
bp->name);
}
return;
@@ -1160,13 +1160,13 @@ map_print_some_keys(el, map, first, last)
if (map == el->el_map.key) {
(void) fprintf(el->el_outfile, "BUG!!! %s isn't bound to anything.\n",
key__decode_str(firstbuf, unparsbuf, STRQQ));
- (void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
+ (void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
first, el->el_map.key[first]);
}
else {
(void) fprintf(el->el_outfile, "BUG!!! %s isn't bound to anything.\n",
key__decode_str(firstbuf, unparsbuf, STRQQ));
- (void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n",
+ (void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n",
first, el->el_map.alt[first]);
}
#endif
@@ -1268,8 +1268,8 @@ map_bind(el, argc, argv)
return 0;
case 'l':
- for (bp = el->el_map.help; bp->name != NULL; bp++)
- (void) fprintf(el->el_outfile, "%s\n\t%s\n",
+ for (bp = el->el_map.help; bp->name != NULL; bp++)
+ (void) fprintf(el->el_outfile, "%s\n\t%s\n",
bp->name, bp->description);
return 0;
default:
@@ -1298,11 +1298,11 @@ map_bind(el, argc, argv)
(void) term_clear_arrow(el, in);
return -1;
}
- if (in[1])
+ if (in[1])
(void) key_delete(el, in);
- else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN)
+ else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN)
(void) key_delete(el, in);
- else
+ else
map[(unsigned char) *in] = ED_UNASSIGNED;
return 0;
}
@@ -1326,7 +1326,7 @@ map_bind(el, argc, argv)
case XK_STR:
case XK_EXE:
if ((out = parse__string(outbuf, argv[argc])) == NULL) {
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"%s: Invalid \\ or ^ in outstring.\n", argv[0]);
return -1;
}
@@ -1339,7 +1339,7 @@ map_bind(el, argc, argv)
case XK_CMD:
if ((cmd = parse_cmd(el, argv[argc])) == -1) {
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"%s: Invalid command `%s'.\n", argv[0], argv[argc]);
return -1;
}
@@ -1379,7 +1379,7 @@ map_addfunc(el, name, help, func)
if (name == NULL || help == NULL || func == NULL)
return -1;
- el->el_map.func = (el_func_t *)
+ el->el_map.func = (el_func_t *)
el_realloc(el->el_map.func, nf * sizeof(el_func_t));
el->el_map.help = (el_bindings_t *)
el_realloc(el->el_map.help, nf * sizeof(el_bindings_t));
diff --git a/lib/libedit/map.h b/lib/libedit/map.h
index 71c93b4..c0f16f1 100644
--- a/lib/libedit/map.h
+++ b/lib/libedit/map.h
@@ -71,7 +71,7 @@ protected void map_end __P((EditLine *));
protected void map_init_vi __P((EditLine *));
protected void map_init_emacs __P((EditLine *));
protected int map_set_editor __P((EditLine *, char *));
-protected int map_addfunc __P((EditLine *, const char *,
+protected int map_addfunc __P((EditLine *, const char *,
const char *, el_func_t));
#endif /* _h_el_map */
diff --git a/lib/libedit/parse.c b/lib/libedit/parse.c
index 2fe746f..dd5bd94 100644
--- a/lib/libedit/parse.c
+++ b/lib/libedit/parse.c
@@ -47,6 +47,9 @@ static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
* echotc
* settc
* gettc
+ * history
+ * settc
+ * setty
*/
#include "sys.h"
#include "el.h"
@@ -97,12 +100,12 @@ el_parse(el, argc, argv)
char *ptr;
int i;
- for (ptr = argv[0]; *ptr && *ptr != ':'; ptr++)
- continue;
-
- if (*ptr == ':') {
- *ptr = '\0';
- if (el_match(el->el_prog, ptr))
+ if (argc < 1)
+ return -1;
+ ptr = strchr(argv[0], ':');
+ if (ptr != NULL) {
+ *ptr++ = '\0';
+ if (! el_match(el->el_prog, argv[0]))
return 0;
}
else
@@ -131,7 +134,7 @@ parse__escape(ptr)
p = *ptr;
- if (p[1] == 0)
+ if (p[1] == 0)
return -1;
if (*p == '\\') {
@@ -180,7 +183,7 @@ parse__escape(ptr)
}
c = (c << 3) | (ch - '0');
}
- if ((c & 0xffffff00) != 0)
+ if ((c & 0xffffff00) != 0)
return -1;
--p;
}
@@ -190,14 +193,14 @@ parse__escape(ptr)
break;
}
}
- else if (*p == '^' && isalpha((unsigned char) *p)) {
+ else if (*p == '^' && isascii(p[1]) && (p[1] == '?' || isalpha(p[1]))) {
p++;
c = (*p == '?') ? '\177' : (*p & 0237);
}
else
c = *p;
*ptr = ++p;
- return c;
+ return (unsigned char)c;
}
/* parse__string():
diff --git a/lib/libedit/parse.h b/lib/libedit/parse.h
index 263076b..0601746 100644
--- a/lib/libedit/parse.h
+++ b/lib/libedit/parse.h
@@ -42,7 +42,7 @@
#ifndef _h_el_parse
#define _h_el_parse
-protected int parse_line __P((EditLine *, const char *));
+protected int parse_line __P((EditLine *, const char *));
protected int parse__escape __P((const char ** const));
protected char * parse__string __P((char *, const char *));
protected int parse_cmd __P((EditLine *, const char *));
diff --git a/lib/libedit/prompt.c b/lib/libedit/prompt.c
index cea7ad7..59ba200 100644
--- a/lib/libedit/prompt.c
+++ b/lib/libedit/prompt.c
@@ -83,7 +83,7 @@ prompt_print(el)
/* prompt_init():
* Initialize the prompt stuff
*/
-protected int
+protected int
prompt_init(el)
EditLine *el;
{
@@ -98,7 +98,7 @@ prompt_init(el)
* Clean up the prompt stuff
*/
protected void
-/*ARGSUSED*/
+/*ARGSUSED*/
prompt_end(el)
EditLine *el;
{
@@ -108,7 +108,7 @@ prompt_end(el)
/* prompt_set():
* Install a prompt printing function
*/
-protected int
+protected int
prompt_set(el, prf)
EditLine *el;
el_pfunc_t prf;
diff --git a/lib/libedit/read.c b/lib/libedit/read.c
index ccfc88b..6475a25 100644
--- a/lib/libedit/read.c
+++ b/lib/libedit/read.c
@@ -86,13 +86,17 @@ read__fixio(fd, e)
#ifdef EWOULDBLOCK
case EWOULDBLOCK:
-# define TRY_AGAIN
+# ifndef TRY_AGAIN
+# define TRY_AGAIN
+# endif
#endif /* EWOULDBLOCK */
#if defined(POSIX) && defined(EAGAIN)
# if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EAGAIN:
-# define TRY_AGAIN
+# ifndef TRY_AGAIN
+# define TRY_AGAIN
+# endif
# endif /* EWOULDBLOCK && EWOULDBLOCK != EAGAIN */
#endif /* POSIX && EAGAIN */
@@ -104,7 +108,7 @@ read__fixio(fd, e)
if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1)
return -1;
- else
+ else
e = 1;
# endif /* F_SETFL && O_NDELAY */
@@ -233,7 +237,7 @@ read_getcmd(el, cmdnum, ch)
break;
}
}
- if (el->el_map.alt == NULL)
+ if (el->el_map.alt == NULL)
el->el_map.current = el->el_map.key;
}
*cmdnum = cmd;
@@ -261,9 +265,9 @@ el_getc(el, cp)
if (!read_preread(el))
break;
}
- if (ma->level < 0)
+ if (ma->level < 0)
break;
-
+
if (*ma->macro[ma->level] == 0) {
ma->level--;
continue;
@@ -347,7 +351,7 @@ el_gets(el, nread)
if (cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */
#ifdef DEBUG_EDIT
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"ERROR: illegal command from key 0%o\r\n", ch);
#endif /* DEBUG_EDIT */
continue; /* try again */
@@ -379,6 +383,11 @@ el_gets(el, nread)
re_refresh_cursor(el);
break;
+ case CC_REDISPLAY:
+ re_clear_lines(el);
+ re_clear_display(el);
+ /* FALLTHROUGH */
+
case CC_REFRESH:
el->el_state.argument = 1;
el->el_state.doingarg = 0;
@@ -399,7 +408,7 @@ el_gets(el, nread)
break;
case CC_NEWLINE: /* normal end of line */
- num = el->el_line.lastchar - el->el_line.buffer;
+ num = el->el_line.lastchar - el->el_line.buffer;
break;
case CC_FATAL: /* fatal error, reset to known state */
diff --git a/lib/libedit/refresh.c b/lib/libedit/refresh.c
index b64d011..6c3ee93 100644
--- a/lib/libedit/refresh.c
+++ b/lib/libedit/refresh.c
@@ -43,7 +43,6 @@ static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
*/
#include "sys.h"
#include <stdio.h>
-#include <ctype.h>
#include <unistd.h>
#include <string.h>
@@ -51,9 +50,9 @@ static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
private void re_addc __P((EditLine *, int));
private void re_update_line __P((EditLine *, char *, char *, int));
-private void re_insert __P((EditLine *, char *, int, int,
+private void re_insert __P((EditLine *, char *, int, int,
char *, int));
-private void re_delete __P((EditLine *, char *, int, int,
+private void re_delete __P((EditLine *, char *, int, int,
int));
private void re_fastputc __P((EditLine *, int));
@@ -61,7 +60,7 @@ private void re__strncopy __P((char *, char *, size_t));
private void re__copy_and_pad __P((char *, char *, size_t));
#ifdef DEBUG_REFRESH
-private void re_printstr __P((EditLine *, char *, char *,
+private void re_printstr __P((EditLine *, char *, char *,
char *));
# define __F el->el_errfile
# define RE_DEBUG(a, b, c) do \
@@ -83,7 +82,7 @@ re_printstr(el, str, f, t)
while (f < t)
RE_DEBUG(1,(__F, "%c", *f++ & 0177),);
RE_DEBUG(1,(__F, "\"\r\n"),);
-}
+}
#else
# define RE_DEBUG(a, b, c)
#endif
@@ -97,6 +96,8 @@ re_addc(el, c)
EditLine *el;
int c;
{
+ c = (unsigned char)c;
+
if (isprint(c)) {
re_putc(el, c);
return;
@@ -116,11 +117,11 @@ re_addc(el, c)
}
else if (iscntrl(c)) {
re_putc(el, '^');
- if (c == '\177')
+ if (c == 0177)
re_putc(el, '?');
- else
+ else
/* uncontrolify it; works only for iso8859-1 like sets */
- re_putc(el, (c | 0100));
+ re_putc(el, (toascii(c) | 0100));
}
else {
re_putc(el, '\\');
@@ -144,11 +145,11 @@ re_putc(el, c)
el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_refresh.r_cursor.h] = c;
el->el_refresh.r_cursor.h++; /* advance to next place */
if (el->el_refresh.r_cursor.h >= el->el_term.t_size.h) {
- el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_term.t_size.h] = '\0';
+ el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_term.t_size.h] = '\0';
/* assure end of line */
el->el_refresh.r_cursor.h = 0; /* reset it. */
el->el_refresh.r_cursor.v++;
- RE_DEBUG(el->el_refresh.r_cursor.v >= el->el_term.t_size.v,
+ RE_DEBUG(el->el_refresh.r_cursor.v >= el->el_term.t_size.v,
(__F, "\r\nre_putc: overflow! r_cursor.v == %d > %d\r\n",
el->el_refresh.r_cursor.v, el->el_term.t_size.v), abort());
}
@@ -194,12 +195,12 @@ re_refresh(el)
cur.v = el->el_refresh.r_cursor.v;
}
/* must be done BEFORE the NUL is written */
- el->el_refresh.r_newcv = el->el_refresh.r_cursor.v;
+ el->el_refresh.r_newcv = el->el_refresh.r_cursor.v;
re_putc(el, '\0'); /* put NUL on end */
- RE_DEBUG(1,(__F,
+ RE_DEBUG(1,(__F,
"term.h=%d vcur.h=%d vcur.v=%d vdisplay[0]=\r\n:%80.80s:\r\n",
- el->el_term.t_size.h, el->el_refresh.r_cursor.h,
+ el->el_term.t_size.h, el->el_refresh.r_cursor.h,
el->el_refresh.r_cursor.v, el->el_vdisplay[0]),);
RE_DEBUG(1,(__F, "updating %d lines.\r\n", el->el_refresh.r_newcv),);
@@ -213,14 +214,14 @@ re_refresh(el)
* cursor by writing the character that is at the end of the
* screen line, it won't be a NUL or some old leftover stuff.
*/
- re__copy_and_pad(el->el_display[i], el->el_vdisplay[i],
+ re__copy_and_pad(el->el_display[i], el->el_vdisplay[i],
el->el_term.t_size.h);
}
RE_DEBUG(1,(__F,
"\r\nel->el_refresh.r_cursor.v=%d,el->el_refresh.r_oldcv=%d i=%d\r\n",
el->el_refresh.r_cursor.v, el->el_refresh.r_oldcv, i),);
- if (el->el_refresh.r_oldcv > el->el_refresh.r_newcv)
+ if (el->el_refresh.r_oldcv > el->el_refresh.r_newcv)
for (; i <= el->el_refresh.r_oldcv; i++) {
term_move_to_line(el, i);
term_move_to_char(el, 0);
@@ -230,11 +231,11 @@ re_refresh(el)
#endif /* DEBUG_REFRESH */
*el->el_display[i] = '\0';
}
-
+
el->el_refresh.r_oldcv = el->el_refresh.r_newcv; /* set for next time */
- RE_DEBUG(1,(__F,
+ RE_DEBUG(1,(__F,
"\r\ncursor.h = %d, cursor.v = %d, cur.h = %d, cur.v = %d\r\n",
- el->el_refresh.r_cursor.h, el->el_refresh.r_cursor.v,
+ el->el_refresh.r_cursor.h, el->el_refresh.r_cursor.v,
cur.h, cur.v),);
term_move_to_line(el, cur.v); /* go to where the cursor is */
term_move_to_char(el, cur.h);
@@ -242,7 +243,7 @@ re_refresh(el)
/* re_goto_bottom():
- * used to go to last used screen line
+ * used to go to last used screen line
*/
protected void
re_goto_bottom(el)
@@ -258,7 +259,7 @@ re_goto_bottom(el)
/* re_insert():
* insert num characters of s into d (in front of the character)
- * at dat, maximum length of d is dlen
+ * at dat, maximum length of d is dlen
*/
private void
/*ARGSUSED*/
@@ -288,7 +289,7 @@ re_insert(el, d, dat, dlen, s, num)
*b-- = *a--;
d[dlen] = '\0'; /* just in case */
}
- RE_DEBUG(1,(__F,
+ RE_DEBUG(1,(__F,
"re_insert() after insert: %d at %d max %d, d == \"%s\"\n",
num, dat, dlen, d),);
RE_DEBUG(1,(__F, "s == \"%s\"n", s),);
@@ -304,7 +305,7 @@ re_insert(el, d, dat, dlen, s, num)
/* re_delete():
- * delete num characters d at dat, maximum length of d is dlen
+ * delete num characters d at dat, maximum length of d is dlen
*/
private void
/*ARGSUSED*/
@@ -399,7 +400,7 @@ re_update_line(el, old, new, i)
*/
while (*o)
o++;
- /*
+ /*
* Remove any trailing blanks off of the end, being careful not to
* back up past the beginning.
*/
@@ -410,7 +411,7 @@ re_update_line(el, old, new, i)
}
oe = o;
*oe = '\0';
-
+
while (*n)
n++;
@@ -422,7 +423,7 @@ re_update_line(el, old, new, i)
}
ne = n;
*ne = '\0';
-
+
/*
* if no diff, continue to next line of redraw
*/
@@ -573,7 +574,7 @@ re_update_line(el, old, new, i)
ofd - old, osb - old, ose - old, ols - old, oe - old),);
RE_DEBUG(1,(__F, "nfd %d, nsb %d, nse %d, nls %d, ne %d\n",
nfd - new, nsb - new, nse - new, nls - new, ne - new),);
- RE_DEBUG(1,(__F,
+ RE_DEBUG(1,(__F,
"xxx-xxx:\"00000000001111111111222222222233333333334\"\r\n"),);
RE_DEBUG(1,(__F,
"xxx-xxx:\"01234567890123456789012345678901234567890\"\r\n"),);
@@ -601,14 +602,14 @@ re_update_line(el, old, new, i)
/*
* at this point we have something like this:
- *
+ *
* /old /ofd /osb /ose /ols /oe
* v.....................v v..................v v........v
* eddie> Oh, my fredded gruntle-buggy is to me, as foo var lurgid as
* eddie> Oh, my fredded quiux buggy is to me, as gruntle-lurgid as
- * ^.....................^ ^..................^ ^........^
+ * ^.....................^ ^..................^ ^........^
* \new \nfd \nsb \nse \nls \ne
- *
+ *
* fx is the difference in length between the the chars between nfd and
* nsb, and the chars between ofd and osb, and is thus the number of
* characters to delete if < 0 (new is shorter than old, as above),
@@ -738,7 +739,7 @@ re_update_line(el, old, new, i)
* Again a duplicate test.
*/
if (sx < 0) {
- RE_DEBUG(!EL_CAN_DELETE,
+ RE_DEBUG(!EL_CAN_DELETE,
(__F, "ERROR: cannot delete in second diff\n"),);
term_deletechars(el, -sx);
}
@@ -768,7 +769,7 @@ re_update_line(el, old, new, i)
*/
if (nsb != ne) {
RE_DEBUG(1,(__F, "with stuff to keep at end\r\n"),);
- /*
+ /*
* We have to recalculate fx here because we set it
* to zero above as a flag saying that we hadn't done
* an early first insert.
@@ -863,7 +864,8 @@ protected void
re_refresh_cursor(el)
EditLine *el;
{
- char *cp, c;
+ char *cp;
+ int c;
int h, v, th;
/* first we must find where the cursor is... */
@@ -872,8 +874,8 @@ re_refresh_cursor(el)
th = el->el_term.t_size.h; /* optimize for speed */
/* do input buffer to el->el_line.cursor */
- for (cp = el->el_line.buffer; cp < el->el_line.cursor; cp++) {
- c = *cp;
+ for (cp = el->el_line.buffer; cp < el->el_line.cursor; cp++) {
+ c = (unsigned char)*cp;
h++; /* all chars at least this long */
if (c == '\n') { /* handle newline in data part too */
@@ -925,7 +927,7 @@ re_fastputc(el, c)
{
term__putc(c);
el->el_display[el->el_cursor.v][el->el_cursor.h++] = c;
- if (el->el_cursor.h >= el->el_term.t_size.h) {
+ if (el->el_cursor.h >= el->el_term.t_size.h) {
/* if we must overflow */
el->el_cursor.h = 0;
el->el_cursor.v++;
@@ -938,15 +940,15 @@ re_fastputc(el, c)
/* re_fastaddc():
* we added just one char, handle it fast.
- * Assumes that screen cursor == real cursor
+ * Assumes that screen cursor == real cursor
*/
protected void
re_fastaddc(el)
EditLine *el;
{
- char c;
+ int c;
- c = el->el_line.cursor[-1];
+ c = (unsigned char)el->el_line.cursor[-1];
if (c == '\t' || el->el_line.cursor != el->el_line.lastchar) {
re_refresh(el); /* too hard to handle */
@@ -954,7 +956,7 @@ re_fastaddc(el)
} /* else (only do at end of line, no TAB) */
if (iscntrl(c)) { /* if control char, do caret */
- char mc = (c == '\177') ? '?' : (c | 0100);
+ char mc = (c == 0177) ? '?' : (toascii(c) | 0100);
re_fastputc(el, '^');
re_fastputc(el, mc);
}
@@ -972,7 +974,7 @@ re_fastaddc(el)
/* re_clear_display():
- * clear the screen buffers so that new new prompt starts fresh.
+ * clear the screen buffers so that new new prompt starts fresh.
*/
protected void
re_clear_display(el)
@@ -989,7 +991,7 @@ re_clear_display(el)
/* re_clear_lines():
- * Make sure all lines are *really* blank
+ * Make sure all lines are *really* blank
*/
protected void
re_clear_lines(el)
diff --git a/lib/libedit/search.c b/lib/libedit/search.c
index 4ff9c61..508835e 100644
--- a/lib/libedit/search.c
+++ b/lib/libedit/search.c
@@ -43,7 +43,9 @@ static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
*/
#include "sys.h"
#include <stdlib.h>
-#ifdef REGEXP
+#if defined(REGEX)
+#include <regex.h>
+#elif defined(REGEXP)
#include <regexp.h>
#endif
#include "el.h"
@@ -86,7 +88,7 @@ search_end(el)
/* regerror():
* Handle regular expression errors
*/
-public void
+public void
/*ARGSUSED*/
regerror(msg)
const char *msg;
@@ -102,31 +104,42 @@ el_match(str, pat)
const char *str;
const char *pat;
{
-#ifndef REGEXP
+#if defined (REGEX)
+ regex_t re;
+ int rv;
+#elif defined (REGEXP)
+ regexp *rp;
+ int rv;
+#else
extern char *re_comp __P((const char *));
extern int re_exec __P((const char *));
-#else
- regexp *re;
- int rv;
#endif
if (strstr(str, pat) != NULL)
return 1;
-#ifndef REGEXP
- if (re_comp(pat) != NULL)
- return 0;
- else
- return re_exec(str) == 1;
-#else
+
+#if defined(REGEX)
+ if (regcomp(&re, pat, 0) == 0) {
+ rv = regexec(&re, str, 0, NULL, 0) == 0;
+ regfree(&re);
+ } else {
+ rv = 0;
+ }
+ return rv;
+#elif defined(REGEXP)
if ((re = regcomp(pat)) != NULL) {
rv = regexec(re, str);
free((ptr_t) re);
- }
- else
+ } else {
rv = 0;
+ }
return rv;
+#else
+ if (re_comp(pat) != NULL)
+ return 0;
+ else
+ return re_exec(str) == 1;
#endif
-
}
@@ -142,25 +155,25 @@ c_hmatch(el, str)
(void) fprintf(el->el_errfile, "match `%s' with `%s'\n",
el->el_search.patbuf, str);
#endif /* SDEBUG */
-
+
return el_match(str, el->el_search.patbuf);
}
-/* c_setpat():
+/* c_setpat():
* Set the history seatch pattern
*/
protected void
c_setpat(el)
EditLine *el;
{
- if (el->el_state.lastcmd != ED_SEARCH_PREV_HISTORY &&
+ if (el->el_state.lastcmd != ED_SEARCH_PREV_HISTORY &&
el->el_state.lastcmd != ED_SEARCH_NEXT_HISTORY) {
el->el_search.patlen = EL_CURSOR(el) - el->el_line.buffer;
- if (el->el_search.patlen >= EL_BUFSIZ)
+ if (el->el_search.patlen >= EL_BUFSIZ)
el->el_search.patlen = EL_BUFSIZ -1;
if (el->el_search.patlen >= 0) {
- (void) strncpy(el->el_search.patbuf, el->el_line.buffer,
+ (void) strncpy(el->el_search.patbuf, el->el_line.buffer,
el->el_search.patlen);
el->el_search.patbuf[el->el_search.patlen] = '\0';
}
@@ -171,8 +184,8 @@ c_setpat(el)
(void) fprintf(el->el_errfile, "\neventno = %d\n", el->el_history.eventno);
(void) fprintf(el->el_errfile, "patlen = %d\n", el->el_search.patlen);
(void) fprintf(el->el_errfile, "patbuf = \"%s\"\n", el->el_search.patbuf);
- (void) fprintf(el->el_errfile, "cursor %d lastchar %d\n",
- EL_CURSOR(el) - el->el_line.buffer,
+ (void) fprintf(el->el_errfile, "cursor %d lastchar %d\n",
+ EL_CURSOR(el) - el->el_line.buffer,
el->el_line.lastchar - el->el_line.buffer);
#endif
}
@@ -199,7 +212,7 @@ ce_inc_search(el, dir)
newdir = dir,
done, redo;
- if (el->el_line.lastchar + sizeof(STRfwd) / sizeof(char) + 2 +
+ if (el->el_line.lastchar + sizeof(STRfwd) / sizeof(char) + 2 +
el->el_search.patlen >= el->el_line.limit)
return CC_ERROR;
@@ -214,12 +227,12 @@ ce_inc_search(el, dir)
}
done = redo = 0;
*el->el_line.lastchar++ = '\n';
- for (cp = newdir == ED_SEARCH_PREV_HISTORY ? STRbck : STRfwd;
+ for (cp = newdir == ED_SEARCH_PREV_HISTORY ? STRbck : STRfwd;
*cp; *el->el_line.lastchar++ = *cp++)
continue;
*el->el_line.lastchar++ = pchar;
- for (cp = &el->el_search.patbuf[1];
- cp < &el->el_search.patbuf[el->el_search.patlen];
+ for (cp = &el->el_search.patbuf[1];
+ cp < &el->el_search.patbuf[el->el_search.patlen];
*el->el_line.lastchar++ = *cp++)
continue;
*el->el_line.lastchar = '\0';
@@ -254,7 +267,7 @@ ce_inc_search(el, dir)
case ED_DELETE_PREV_CHAR:
if (el->el_search.patlen > 1)
done++;
- else
+ else
term_beep(el);
break;
@@ -270,15 +283,15 @@ ce_inc_search(el, dir)
for (cp = &el->el_search.patbuf[1]; ; cp++)
if (cp >= &el->el_search.patbuf[el->el_search.patlen]) {
el->el_line.cursor += el->el_search.patlen - 1;
- cp = c__next_word(el->el_line.cursor,
+ cp = c__next_word(el->el_line.cursor,
el->el_line.lastchar, 1, ce__isword);
- while (el->el_line.cursor < cp &&
+ while (el->el_line.cursor < cp &&
*el->el_line.cursor != '\n') {
if (el->el_search.patlen > EL_BUFSIZ - 3) {
term_beep(el);
break;
}
- el->el_search.patbuf[el->el_search.patlen++] =
+ el->el_search.patbuf[el->el_search.patlen++] =
*el->el_line.cursor;
*el->el_line.lastchar++ = *el->el_line.cursor++;
}
@@ -291,10 +304,10 @@ ce_inc_search(el, dir)
break;
}
break;
-
+
default: /* Terminate and execute cmd */
endcmd[0] = ch;
- el_push(el, endcmd);
+ el_push(el, endcmd);
/*FALLTHROUGH*/
case 0033: /* ESC: Terminate */
@@ -305,7 +318,7 @@ ce_inc_search(el, dir)
break;
}
- while (el->el_line.lastchar > el->el_line.buffer &&
+ while (el->el_line.lastchar > el->el_line.buffer &&
*el->el_line.lastchar != '\n')
*el->el_line.lastchar-- = '\0';
*el->el_line.lastchar = '\0';
@@ -313,7 +326,7 @@ ce_inc_search(el, dir)
if (!done) {
/* Can't search if unmatched '[' */
- for (cp = &el->el_search.patbuf[el->el_search.patlen-1], ch = ']';
+ for (cp = &el->el_search.patbuf[el->el_search.patlen-1], ch = ']';
cp > el->el_search.patbuf; cp--)
if (*cp == '[' || *cp == ']') {
ch = *cp;
@@ -323,7 +336,7 @@ ce_inc_search(el, dir)
if (el->el_search.patlen > 1 && ch != '[') {
if (redo && newdir == dir) {
if (pchar == '?') { /* wrap around */
- el->el_history.eventno =
+ el->el_history.eventno =
newdir == ED_SEARCH_PREV_HISTORY ? 0 : 0x7fffffff;
if (hist_get(el) == CC_ERROR)
/* el->el_history.eventno was fixed by first call */
@@ -331,7 +344,7 @@ ce_inc_search(el, dir)
el->el_line.cursor = newdir == ED_SEARCH_PREV_HISTORY ?
el->el_line.lastchar : el->el_line.buffer;
} else
- el->el_line.cursor +=
+ el->el_line.cursor +=
newdir == ED_SEARCH_PREV_HISTORY ? -1 : 1;
}
#ifdef ANCHOR
@@ -339,19 +352,19 @@ ce_inc_search(el, dir)
el->el_search.patbuf[el->el_search.patlen++] = '*';
#endif
el->el_search.patbuf[el->el_search.patlen] = '\0';
- 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.lastchar ||
- (ret = ce_search_line(el, &el->el_search.patbuf[1],
+ (ret = ce_search_line(el, &el->el_search.patbuf[1],
newdir)) == CC_ERROR) {
/* avoid c_setpat */
- el->el_state.lastcmd = (el_action_t) newdir;
+ el->el_state.lastcmd = (el_action_t) newdir;
ret = newdir == ED_SEARCH_PREV_HISTORY ?
- ed_search_prev_history(el, 0) :
+ ed_search_prev_history(el, 0) :
ed_search_next_history(el, 0);
if (ret != CC_ERROR) {
el->el_line.cursor = newdir == ED_SEARCH_PREV_HISTORY ?
el->el_line.lastchar : el->el_line.buffer;
- (void) ce_search_line(el, &el->el_search.patbuf[1],
+ (void) ce_search_line(el, &el->el_search.patbuf[1],
newdir);
}
}
@@ -372,7 +385,7 @@ ce_inc_search(el, dir)
ret = ce_inc_search(el, newdir);
- if (ret == CC_ERROR && pchar == '?' && oldpchar == ':')
+ if (ret == CC_ERROR && pchar == '?' && oldpchar == ':')
/* break abort of failed search at last non-failed */
ret = CC_NORM;
@@ -448,10 +461,11 @@ cv_search(el, dir)
}
#ifdef ANCHOR
if (el->el_search.patbuf[0] != '.' && el->el_search.patbuf[0] != '*') {
- (void) strcpy(tmpbuf, el->el_search.patbuf);
+ (void)strncpy(tmpbuf, el->el_search.patbuf, sizeof(tmpbuf) - 1);
el->el_search.patbuf[0] = '.';
el->el_search.patbuf[1] = '*';
- (void) strcpy(&el->el_search.patbuf[2], tmpbuf);
+ (void)strncpy(&el->el_search.patbuf[2], tmpbuf,
+ sizeof(el->el_search.patbuf) - 3);
el->el_search.patlen++;
el->el_search.patbuf[el->el_search.patlen++] = '.';
el->el_search.patbuf[el->el_search.patlen++] = '*';
@@ -465,12 +479,13 @@ cv_search(el, dir)
tmpbuf[tmplen++] = '*';
#endif
tmpbuf[tmplen] = '\0';
- (void) strcpy(el->el_search.patbuf, tmpbuf);
+ (void)strncpy(el->el_search.patbuf, tmpbuf,
+ sizeof(el->el_search.patbuf) - 1);
el->el_search.patlen = tmplen;
}
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) :
+ if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) :
ed_search_next_history(el, 0)) == CC_ERROR) {
re_refresh(el);
return CC_ERROR;
@@ -508,7 +523,7 @@ ce_search_line(el, pattern, dir)
}
return CC_ERROR;
} else {
- for (cp = el->el_line.cursor; *cp != '\0' &&
+ for (cp = el->el_line.cursor; *cp != '\0' &&
cp < el->el_line.limit; cp++)
if (el_match(cp, pattern)) {
el->el_line.cursor = cp;
@@ -528,7 +543,7 @@ cv_repeat_srch(el, c)
int c;
{
#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "dir %d patlen %d patbuf %s\n",
+ (void) fprintf(el->el_errfile, "dir %d patlen %d patbuf %s\n",
c, el->el_search.patlen, el->el_search.patbuf);
#endif
@@ -558,9 +573,9 @@ cv_csearch_back(el, ch, count, tflag)
cp = el->el_line.cursor;
while (count--) {
- if (*cp == ch)
+ if (*cp == ch)
cp--;
- while (cp > el->el_line.buffer && *cp != ch)
+ while (cp > el->el_line.buffer && *cp != ch)
cp--;
}
@@ -595,9 +610,9 @@ cv_csearch_fwd(el, ch, count, tflag)
cp = el->el_line.cursor;
while (count--) {
- if(*cp == ch)
+ if(*cp == ch)
cp++;
- while (cp < el->el_line.lastchar && *cp != ch)
+ while (cp < el->el_line.lastchar && *cp != ch)
cp++;
}
diff --git a/lib/libedit/search.h b/lib/libedit/search.h
index 51c58b4..346b38c 100644
--- a/lib/libedit/search.h
+++ b/lib/libedit/search.h
@@ -39,8 +39,8 @@
/*
* el.search.h: Line and history searching utilities
*/
-#ifndef _h_el_search
-#define _h_el_search
+#ifndef _h_el_search
+#define _h_el_search
#include "histedit.h"
diff --git a/lib/libedit/sig.c b/lib/libedit/sig.c
index 94ab4bb..d0a780a 100644
--- a/lib/libedit/sig.c
+++ b/lib/libedit/sig.c
@@ -91,7 +91,7 @@ sig_handler(signo)
break;
}
- for (i = 0; sighdl[i] != -1; i++)
+ for (i = 0; sighdl[i] != -1; i++)
if (signo == sighdl[i])
break;
@@ -120,8 +120,8 @@ sig_init(el)
#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(sig_t))
el->el_signal = (sig_t *) el_malloc(SIGSIZE);
- for (i = 0; sighdl[i] != -1; i++)
- el->el_signal[i] = BADSIG;
+ for (i = 0; sighdl[i] != -1; i++)
+ el->el_signal[i] = SIG_ERR;
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
@@ -184,8 +184,8 @@ sig_clr(el)
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
- for (i = 0; sighdl[i] != -1; i++)
- if (el->el_signal[i] != BADSIG)
+ for (i = 0; sighdl[i] != -1; i++)
+ if (el->el_signal[i] != SIG_ERR)
(void) signal(sighdl[i], el->el_signal[i]);
sel = NULL; /* we are going to die if the handler is called */
diff --git a/lib/libedit/sys.h b/lib/libedit/sys.h
index cc260f5..9e5fd0f 100644
--- a/lib/libedit/sys.h
+++ b/lib/libedit/sys.h
@@ -76,9 +76,11 @@ typedef char* ioctl_t;
#endif
#include <stdio.h>
-#define REGEXP
+#define REGEX /* Use POSIX.2 regular expression functions */
+#undef REGEXP /* Use UNIX V8 regular expression functions */
#ifdef SUNOS
+# undef REGEX
# undef REGEXP
# include <malloc.h>
typedef void (*sig_t)__P((int));
diff --git a/lib/libedit/term.c b/lib/libedit/term.c
index 4b793b7..8de3027 100644
--- a/lib/libedit/term.c
+++ b/lib/libedit/term.c
@@ -49,8 +49,9 @@ static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
-#include "termcap.h" /* XXX: should be <termcap.h> */
+#include <termcap.h>
#include <sys/types.h>
+#include <sys/ioctl.h>
#include "el.h"
@@ -68,76 +69,6 @@ static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
#define Str(a) el->el_term.t_str[a]
#define Val(a) el->el_term.t_val[a]
-private struct {
- char *b_name;
- int b_rate;
-} baud_rate[] = {
-#ifdef B0
- { "0", B0 },
-#endif
-#ifdef B50
- { "50", B50 },
-#endif
-#ifdef B75
- { "75", B75 },
-#endif
-#ifdef B110
- { "110", B110 },
-#endif
-#ifdef B134
- { "134", B134 },
-#endif
-#ifdef B150
- { "150", B150 },
-#endif
-#ifdef B200
- { "200", B200 },
-#endif
-#ifdef B300
- { "300", B300 },
-#endif
-#ifdef B600
- { "600", B600 },
-#endif
-#ifdef B900
- { "900", B900 },
-#endif
-#ifdef B1200
- { "1200", B1200 },
-#endif
-#ifdef B1800
- { "1800", B1800 },
-#endif
-#ifdef B2400
- { "2400", B2400 },
-#endif
-#ifdef B3600
- { "3600", B3600 },
-#endif
-#ifdef B4800
- { "4800", B4800 },
-#endif
-#ifdef B7200
- { "7200", B7200 },
-#endif
-#ifdef B9600
- { "9600", B9600 },
-#endif
-#ifdef EXTA
- { "19200", EXTA },
-#endif
-#ifdef B19200
- { "19200", B19200 },
-#endif
-#ifdef EXTB
- { "38400", EXTB },
-#endif
-#ifdef B38400
- { "38400", B38400 },
-#endif
- { NULL, 0 }
-};
-
private struct termcapstr {
char *name;
char *long_name;
@@ -171,7 +102,7 @@ private struct termcapstr {
{ "ho", "home cursor" },
#define T_ic 13
{ "ic", "insert character" },
-#define T_im 14
+#define T_im 14
{ "im", "start insert mode" },
#define T_ip 15
{ "ip", "insert padding" },
@@ -245,7 +176,7 @@ private void term_rebuffer_display __P((EditLine *));
private void term_free_display __P((EditLine *));
private void term_alloc_display __P((EditLine *));
private void term_alloc __P((EditLine *,
- struct termcapstr *, char *));
+ struct termcapstr *, char *));
private void term_init_arrow __P((EditLine *));
private void term_reset_arrow __P((EditLine *));
@@ -261,7 +192,7 @@ term_setflags(el)
EditLine *el;
{
EL_FLAGS = 0;
- if (el->el_tty.t_tabs)
+ if (el->el_tty.t_tabs)
EL_FLAGS |= (Val(T_pt) && !Val(T_xt)) ? TERM_CAN_TAB : 0;
EL_FLAGS |= (Val(T_km) || Val(T_MT)) ? TERM_HAS_META : 0;
@@ -304,6 +235,7 @@ term_init(el)
el->el_term.t_buf = (char *) el_malloc(TC_BUFSIZE);
el->el_term.t_cap = (char *) el_malloc(TC_BUFSIZE);
el->el_term.t_fkey = (fkey_t *) el_malloc(4 * sizeof(fkey_t));
+ (void) memset(el->el_term.t_fkey, 0, 4 * sizeof(fkey_t));
el->el_term.t_loc = 0;
el->el_term.t_str = (char **) el_malloc(T_str * sizeof(char*));
(void) memset(el->el_term.t_str, 0, T_str * sizeof(char*));
@@ -362,7 +294,7 @@ term_alloc(el, t, cap)
* New string is shorter; no need to allocate space
*/
if (clen <= tlen) {
- (void) strcpy(*str, cap);
+ (void)strcpy(*str, cap); /* XXX strcpy is safe */
return;
}
@@ -370,7 +302,8 @@ term_alloc(el, t, cap)
* New string is longer; see if we have enough space to append
*/
if (el->el_term.t_loc + 3 < TC_BUFSIZE) {
- (void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap);
+ /* XXX strcpy is safe */
+ (void)strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap);
el->el_term.t_loc += clen + 1; /* one for \0 */
return;
}
@@ -394,7 +327,8 @@ term_alloc(el, t, cap)
(void) fprintf(el->el_errfile, "Out of termcap string space.\n");
return;
}
- (void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap);
+ /* XXX strcpy is safe */
+ (void)strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap);
el->el_term.t_loc += clen + 1; /* one for \0 */
return;
} /* end term_alloc */
@@ -479,7 +413,7 @@ term_free_display(el)
protected void
term_move_to_line(el, where)
EditLine *el;
- int where;
+ int where;
{
int del, i;
@@ -488,7 +422,7 @@ term_move_to_line(el, where)
if (where > el->el_term.t_size.v) {
#ifdef DEBUG_SCREEN
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"term_move_to_line: where is ridiculous: %d\r\n", where);
#endif /* DEBUG_SCREEN */
return;
@@ -532,7 +466,7 @@ mc_again:
if (where > (el->el_term.t_size.h + 1)) {
#ifdef DEBUG_SCREEN
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"term_move_to_char: where is riduculous: %d\r\n", where);
#endif /* DEBUG_SCREEN */
return;
@@ -557,7 +491,7 @@ mc_again:
if (EL_CAN_TAB) { /* if I can do tabs, use them */
if ((el->el_cursor.h & 0370) != (where & 0370)) {
/* if not within tab stop */
- for (i = (el->el_cursor.h & 0370);
+ for (i = (el->el_cursor.h & 0370);
i < (where & 0370); i += 8)
term__putc('\t'); /* then tab over */
el->el_cursor.h = where & 0370;
@@ -566,8 +500,8 @@ mc_again:
/* it's usually cheaper to just write the chars, so we do. */
/* NOTE THAT term_overwrite() WILL CHANGE el->el_cursor.h!!! */
- term_overwrite(el,
- &el->el_display[el->el_cursor.v][el->el_cursor.h],
+ term_overwrite(el,
+ &el->el_display[el->el_cursor.v][el->el_cursor.h],
where - el->el_cursor.h);
}
@@ -638,7 +572,7 @@ term_deletechars(el, num)
if (num > el->el_term.t_size.h) {
#ifdef DEBUG_SCREEN
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"term_deletechars: num is riduculous: %d\r\n", num);
#endif /* DEBUG_SCREEN */
return;
@@ -663,11 +597,11 @@ term_deletechars(el, num)
/* term_insertwrite():
- * Puts terminal in insert character mode or inserts num
- * characters in the line
+ * Puts terminal in insert character mode or inserts num
+ * characters in the line
*/
protected void
-term_insertwrite(el, cp, num)
+term_insertwrite(el, cp, num)
EditLine *el;
char *cp;
int num;
@@ -699,7 +633,7 @@ term_insertwrite(el, cp, num)
(void) tputs(Str(T_im), 1, term__putc);
el->el_cursor.h += num;
- do
+ do
term__putc(*cp++);
while (--num);
@@ -726,10 +660,10 @@ term_insertwrite(el, cp, num)
/* term_clear_EOL():
- * clear to end of line. There are num characters to clear
+ * clear to end of line. There are num characters to clear
*/
protected void
-term_clear_EOL(el, num)
+term_clear_EOL(el, num)
EditLine *el;
int num;
{
@@ -746,7 +680,7 @@ term_clear_EOL(el, num)
/* term_clear_screen():
- * Clear the screen
+ * Clear the screen
*/
protected void
term_clear_screen(el)
@@ -833,11 +767,11 @@ term_set(el, term)
i = tgetent(el->el_term.t_cap, term);
if (i <= 0) {
- if (i == -1)
- (void) fprintf(el->el_errfile, "Cannot open /etc/termcap.\n");
- else if (i == 0)
- (void) fprintf(el->el_errfile,
- "No entry for terminal type \"%s\"\n", term);
+ if (i == -1)
+ (void) fprintf(el->el_errfile, "Cannot read termcap database;\n");
+ else if (i == 0)
+ (void) fprintf(el->el_errfile,
+ "No entry for terminal type \"%s\";\n", term);
(void) fprintf(el->el_errfile, "using dumb terminal settings.\n");
Val(T_co) = 80; /* do a dumb terminal */
Val(T_pt) = Val(T_km) = Val(T_li) = 0;
@@ -873,13 +807,13 @@ term_set(el, term)
term_change_size(el, lins, cols);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
term_bind_arrow(el);
- return 0;
+ return i <= 0 ? -1 : 0;
} /* end term_set */
/* term_get_size():
* Return the new window size in lines and cols, and
- * true if the size was changed.
+ * true if the size was changed.
*/
protected int
term_get_size(el, lins, cols)
@@ -971,7 +905,7 @@ term_init_arrow(el)
* Reset arrow key bindings
*/
private void
-term_reset_arrow(el)
+term_reset_arrow(el)
EditLine *el;
{
fkey_t *arrow = el->el_term.t_fkey;
@@ -1095,8 +1029,8 @@ term_bind_arrow(el)
/*
* Assign the arrow keys only if:
*
- * 1. They are multi-character arrow keys and the user
- * has not re-assigned the leading character, or
+ * 1. They are multi-character arrow keys and the user
+ * has not re-assigned the leading character, or
* has re-assigned the leading character to be
* ED_SEQUENCE_LEAD_IN
* 2. They are single arrow keys pointing to an unassigned key.
@@ -1104,7 +1038,7 @@ term_bind_arrow(el)
if (arrow[i].type == XK_NOD)
key_clear(el, map, p);
else {
- if (p[1] && (dmap[j] == map[j] ||
+ if (p[1] && (dmap[j] == map[j] ||
map[j] == ED_SEQUENCE_LEAD_IN)) {
key_add(el, p, &arrow[i].fun, arrow[i].type);
map[j] = ED_SEQUENCE_LEAD_IN;
@@ -1125,11 +1059,11 @@ term_bind_arrow(el)
/* term__putc():
* Add a character
*/
-protected void
+protected int
term__putc(c)
int c;
{
- (void) fputc(c, term_outfile);
+ return fputc(c, term_outfile);
} /* end term__putc */
@@ -1161,21 +1095,21 @@ term_telltc(el, argc, argv)
(void) fprintf(el->el_outfile, "\tfollowing characteristics:\n\n");
(void) fprintf(el->el_outfile, "\tIt has %d columns and %d lines\n",
Val(T_co), Val(T_li));
- (void) fprintf(el->el_outfile,
+ (void) fprintf(el->el_outfile,
"\tIt has %s meta key\n", EL_HAS_META ? "a" : "no");
- (void) fprintf(el->el_outfile,
+ (void) fprintf(el->el_outfile,
"\tIt can%suse tabs\n", EL_CAN_TAB ? " " : "not ");
#ifdef notyet
- (void) fprintf(el->el_outfile, "\tIt %s automatic margins\n",
+ (void) fprintf(el->el_outfile, "\tIt %s automatic margins\n",
(T_Margin&MARGIN_AUTO)? "has": "does not have");
if (T_Margin & MARGIN_AUTO)
- (void) fprintf(el->el_outfile, "\tIt %s magic margins\n",
+ (void) fprintf(el->el_outfile, "\tIt %s magic margins\n",
(T_Margin&MARGIN_MAGIC)?"has":"does not have");
#endif
for (t = tstr, ts = el->el_term.t_str; t->name != NULL; t++, ts++)
- (void) fprintf(el->el_outfile, "\t%25s (%s) == %s\n", t->long_name,
- t->name, *ts && **ts ?
+ (void) fprintf(el->el_outfile, "\t%25s (%s) == %s\n", t->long_name,
+ t->name, *ts && **ts ?
key__decode_str(*ts, upbuf, "") : "(empty)");
(void) fputc('\n', el->el_outfile);
return 0;
@@ -1223,7 +1157,7 @@ term_settc(el, argc, argv)
break;
if (tv->name != NULL) {
- if (tv == &tval[T_pt] || tv == &tval[T_km]
+ if (tv == &tval[T_pt] || tv == &tval[T_km]
#ifdef notyet
|| tv == &tval[T_am] || tv == &tval[T_xn]
#endif
@@ -1303,25 +1237,18 @@ term_echotc(el, argc, argv)
}
#ifdef notyet
else if (strcmp(*argv, "xn") == 0) {
- (void) fprintf(el->el_outfile, fmts, T_Margin & MARGIN_MAGIC ?
+ (void) fprintf(el->el_outfile, fmts, T_Margin & MARGIN_MAGIC ?
"yes" : "no");
return 0;
}
else if (strcmp(*argv, "am") == 0) {
- (void) fprintf(el->el_outfile, fmts, T_Margin & MARGIN_AUTO ?
+ (void) fprintf(el->el_outfile, fmts, T_Margin & MARGIN_AUTO ?
"yes" : "no");
return 0;
}
#endif
else if (strcmp(*argv, "baud") == 0) {
- int i;
-
- for (i = 0; baud_rate[i].b_name != NULL; i++)
- if (el->el_tty.t_speed == baud_rate[i].b_rate) {
- (void) fprintf(el->el_outfile, fmts, baud_rate[i].b_name);
- return 0;
- }
- (void) fprintf(el->el_outfile, fmtd, 0);
+ (void) fprintf(el->el_outfile, "%ld\n", el->el_tty.t_speed);
return 0;
}
else if (strcmp(*argv, "rows") == 0 || strcmp(*argv, "lines") == 0) {
@@ -1333,7 +1260,7 @@ term_echotc(el, argc, argv)
return 0;
}
- /*
+ /*
* Try to use our local definition first
*/
scap = NULL;
@@ -1346,7 +1273,7 @@ term_echotc(el, argc, argv)
scap = tgetstr(*argv, &area);
if (!scap || scap[0] == '\0') {
if (!silent)
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"echotc: Termcap parameter `%s' not found.\n", *argv);
return -1;
}
@@ -1377,7 +1304,7 @@ term_echotc(el, argc, argv)
* hpux has lot's of them...
*/
if (verbose)
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"echotc: Warning: unknown termcap %% `%c'.\n", *cap);
/* This is bad, but I won't complain */
break;
@@ -1388,7 +1315,7 @@ term_echotc(el, argc, argv)
argv++;
if (*argv && *argv[0]) {
if (!silent)
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"echotc: Warning: Extra argument `%s'.\n", *argv);
return -1;
}
@@ -1398,7 +1325,7 @@ term_echotc(el, argc, argv)
argv++;
if (!*argv || *argv[0] == '\0') {
if (!silent)
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"echotc: Warning: Missing argument.\n");
return -1;
}
@@ -1407,7 +1334,7 @@ term_echotc(el, argc, argv)
argv++;
if (*argv && *argv[0]) {
if (!silent)
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"echotc: Warning: Extra argument `%s'.\n", *argv);
return -1;
}
@@ -1416,15 +1343,15 @@ term_echotc(el, argc, argv)
default:
/* This is wrong, but I will ignore it... */
if (verbose)
- (void) fprintf(el->el_errfile,
- "echotc: Warning: Too many required arguments (%d).\n",
+ (void) fprintf(el->el_errfile,
+ "echotc: Warning: Too many required arguments (%d).\n",
arg_need);
/*FALLTHROUGH*/
case 2:
argv++;
if (!*argv || *argv[0] == '\0') {
if (!silent)
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"echotc: Warning: Missing argument.\n");
return -1;
}
@@ -1432,7 +1359,7 @@ term_echotc(el, argc, argv)
argv++;
if (!*argv || *argv[0] == '\0') {
if (!silent)
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"echotc: Warning: Missing argument.\n");
return -1;
}
@@ -1440,7 +1367,7 @@ term_echotc(el, argc, argv)
argv++;
if (*argv && *argv[0]) {
if (!silent)
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"echotc: Warning: Extra argument `%s'.\n", *argv);
return -1;
}
diff --git a/lib/libedit/term.h b/lib/libedit/term.h
index 416e73e..f9de221 100644
--- a/lib/libedit/term.h
+++ b/lib/libedit/term.h
@@ -92,7 +92,7 @@ protected int term_init __P((EditLine *));
protected void term_bind_arrow __P((EditLine *));
protected void term_print_arrow __P((EditLine *, char *));
protected int term_clear_arrow __P((EditLine *, char *));
-protected int term_set_arrow __P((EditLine *, char *,
+protected int term_set_arrow __P((EditLine *, char *,
key_value_t *, int));
protected void term_end __P((EditLine *));
protected int term_set __P((EditLine *, char *));
@@ -100,7 +100,7 @@ protected int term_settc __P((EditLine *, int, char **));
protected int term_telltc __P((EditLine *, int, char **));
protected int term_echotc __P((EditLine *, int, char **));
-protected void term__putc __P((int));
+protected int term__putc __P((int));
protected void term__flush __P((void));
/*
diff --git a/lib/libedit/tokenizer.c b/lib/libedit/tokenizer.c
index 41095fa..bbe847e 100644
--- a/lib/libedit/tokenizer.c
+++ b/lib/libedit/tokenizer.c
@@ -155,7 +155,7 @@ tok_end(tok)
* 3: Quoted return
* 2: Unmatched double quote
* 1: Unmatched single quote
- * 0: Ok
+ * 0: Ok
*/
public int
tok_line(tok, line, argc, argv)
@@ -225,7 +225,7 @@ tok_line(tok, line, argc, argv)
*tok->wptr++ = *ptr;
break;
- default:
+ default:
return(-1);
}
break;
@@ -242,7 +242,7 @@ tok_line(tok, line, argc, argv)
tok->quote = Q_doubleone;/* Quote next character */
break;
- case Q_one:
+ case Q_one:
*tok->wptr++ = *ptr;
tok->quote = Q_none; /* Quote this, restore state */
break;
@@ -274,7 +274,7 @@ tok_line(tok, line, argc, argv)
case Q_double:
*tok->wptr++ = *ptr; /* Add the return */
break;
-
+
case Q_doubleone:
tok->flags |= TOK_EAT;
tok->quote = Q_double; /* Back to double, eat the '\n' */
@@ -377,7 +377,7 @@ tok_line(tok, line, argc, argv)
if (tok->argc >= tok->amax - 4) {
tok->amax += AINCR;
- tok->argv = (char **) tok_realloc(tok->argv,
+ tok->argv = (char **) tok_realloc(tok->argv,
tok->amax * sizeof(char*));
}
diff --git a/lib/libedit/tokenizer.h b/lib/libedit/tokenizer.h
index d495dc6..86911e1 100644
--- a/lib/libedit/tokenizer.h
+++ b/lib/libedit/tokenizer.h
@@ -47,7 +47,7 @@ typedef struct tokenizer Tokenizer;
Tokenizer *tok_init __P((const char *));
void tok_reset __P((Tokenizer *));
void tok_end __P((Tokenizer *));
-int tok_line __P((Tokenizer *, const char *,
+int tok_line __P((Tokenizer *, const char *,
int *, char ***));
#endif /* _h_tokenizer */
diff --git a/lib/libedit/tty.c b/lib/libedit/tty.c
index ac99843..961e340 100644
--- a/lib/libedit/tty.c
+++ b/lib/libedit/tty.c
@@ -38,7 +38,7 @@
static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */
-/*
+/*
* tty.c: tty interface stuff
*/
#include "sys.h"
@@ -47,7 +47,7 @@ static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
typedef struct ttymodes_t {
char *m_name;
- int m_value;
+ u_int m_value;
int m_type;
} ttymodes_t;
@@ -57,7 +57,7 @@ typedef struct ttymap_t {
} ttymap_t;
-private ttyperm_t ttyperm = {
+private ttyperm_t ttyperm = {
{
{ "iflag:", ICRNL, (INLCR|IGNCR) },
{ "oflag:", (OPOST|ONLCR), ONLRET },
@@ -87,8 +87,8 @@ private ttyperm_t ttyperm = {
private ttychar_t ttychar = {
{
- CINTR, CQUIT, CERASE, CKILL,
- CEOF, CEOL, CEOL2, CSWTCH,
+ CINTR, CQUIT, CERASE, CKILL,
+ CEOF, CEOL, CEOL2, CSWTCH,
CDSWTCH, CERASE2, CSTART, CSTOP,
CWERASE, CSUSP, CDSUSP, CREPRINT,
CDISCARD, CLNEXT, CSTATUS, CPAGE,
@@ -96,15 +96,15 @@ private ttychar_t ttychar = {
CTIME
},
{
- CINTR, CQUIT, CERASE, CKILL,
- _POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE,
- _POSIX_VDISABLE, CERASE2, CSTART, CSTOP,
- _POSIX_VDISABLE, CSUSP, _POSIX_VDISABLE, _POSIX_VDISABLE,
- CDISCARD, _POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE,
+ CINTR, CQUIT, CERASE, CKILL,
+ _POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE,
+ _POSIX_VDISABLE, CERASE2, CSTART, CSTOP,
+ _POSIX_VDISABLE, CSUSP, _POSIX_VDISABLE, _POSIX_VDISABLE,
+ CDISCARD, _POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE,
_POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE, 1,
0
},
- {
+ {
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
@@ -117,38 +117,38 @@ private ttychar_t ttychar = {
private ttymap_t tty_map[] = {
#ifdef VERASE
- { C_ERASE, VERASE,
+ { C_ERASE, VERASE,
{ ED_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR } },
#endif /* VERASE */
#ifdef VERASE2
- { C_ERASE2, VERASE2,
+ { C_ERASE2, VERASE2,
{ ED_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR } },
#endif /* VERASE2 */
#ifdef VKILL
- { C_KILL, VKILL,
+ { C_KILL, VKILL,
{ EM_KILL_LINE, VI_KILL_LINE_PREV, ED_UNASSIGNED } },
#endif /* VKILL */
#ifdef VKILL2
- { C_KILL2, VKILL2,
+ { C_KILL2, VKILL2,
{ EM_KILL_LINE, VI_KILL_LINE_PREV, ED_UNASSIGNED } },
#endif /* VKILL2 */
#ifdef VEOF
- { C_EOF, VEOF,
+ { C_EOF, VEOF,
{ EM_DELETE_OR_LIST, VI_LIST_OR_EOF, ED_UNASSIGNED } },
#endif /* VEOF */
#ifdef VWERASE
- { C_WERASE, VWERASE,
+ { C_WERASE, VWERASE,
{ ED_DELETE_PREV_WORD, ED_DELETE_PREV_WORD, ED_PREV_WORD } },
#endif /* VWERASE */
#ifdef VREPRINT
- { C_REPRINT, VREPRINT,
+ { C_REPRINT, VREPRINT,
{ ED_REDISPLAY, ED_INSERT, ED_REDISPLAY } },
#endif /* VREPRINT */
#ifdef VLNEXT
- { C_LNEXT, VLNEXT,
+ { C_LNEXT, VLNEXT,
{ ED_QUOTED_INSERT, ED_QUOTED_INSERT, ED_UNASSIGNED } },
#endif /* VLNEXT */
- { -1, -1,
+ { -1, -1,
{ ED_UNASSIGNED, ED_UNASSIGNED, ED_UNASSIGNED } }
};
@@ -359,7 +359,7 @@ private ttymodes_t ttymodes[] = {
{ "extproc",EXTPROC, M_LIN },
# endif /* EXTPROC */
-# if defined(VINTR)
+# if defined(VINTR)
{ "intr", C_SH(C_INTR), M_CHAR },
# endif /* VINTR */
# if defined(VQUIT)
@@ -422,7 +422,7 @@ private ttymodes_t ttymodes[] = {
# if defined(VPGOFF)
{ "pgoff", C_SH(C_PGOFF), M_CHAR },
# endif /* VPGOFF */
-# if defined(VKILL2)
+# if defined(VKILL2)
{ "kill2", C_SH(C_KILL2), M_CHAR },
# endif /* VKILL2 */
# if defined(VBRK)
@@ -440,7 +440,7 @@ private ttymodes_t ttymodes[] = {
#define tty_getty(el, td) tcgetattr((el)->el_infd, (td))
-#define tty_setty(el, td) tcsetattr((el)->el_infd, TCSADRAIN, (td))
+#define tty_setty(el, td) tcsetattr((el)->el_infd, TCSADRAIN, (td))
#define tty__gettabs(td) ((((td)->c_oflag & TAB3) == TAB3) ? 0 : 1)
#define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8)
@@ -457,14 +457,14 @@ private int tty_setup __P((EditLine *));
/* tty_setup():
* Get the tty parameters and initialize the editing state
*/
-private int
+private int
tty_setup(el)
EditLine *el;
{
int rst = 1;
if (tty_getty(el, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile,
+ (void) fprintf(el->el_errfile,
"tty_setup: tty_getty: %s\n", strerror(errno));
#endif /* DEBUG_TTY */
return(-1);
@@ -509,7 +509,7 @@ tty_setup(el)
tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
if (tty_setty(el, &el->el_tty.t_ex) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "tty_setup: tty_setty: %s\n",
+ (void) fprintf(el->el_errfile, "tty_setup: tty_setty: %s\n",
strerror(errno));
#endif /* DEBUG_TTY */
return(-1);
@@ -580,7 +580,7 @@ private void
tty__getchar(td, s)
struct termios *td;
unsigned char *s;
-{
+{
# ifdef VINTR
s[C_INTR] = td->c_cc[VINTR];
# endif /* VINTR */
@@ -663,7 +663,7 @@ private void
tty__setchar(td, s)
struct termios *td;
unsigned char *s;
-{
+{
# ifdef VINTR
td->c_cc[VINTR] = s[C_INTR];
# endif /* VINTR */
@@ -810,7 +810,7 @@ tty_rawmode(el)
el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ts);
el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ts);
- if (tty__getspeed(&el->el_tty.t_ex) != el->el_tty.t_speed ||
+ if (tty__getspeed(&el->el_tty.t_ex) != el->el_tty.t_speed ||
tty__getspeed(&el->el_tty.t_ed) != el->el_tty.t_speed) {
(void) cfsetispeed(&el->el_tty.t_ex, el->el_tty.t_speed);
(void) cfsetospeed(&el->el_tty.t_ex, el->el_tty.t_speed);
@@ -819,7 +819,7 @@ tty_rawmode(el)
}
if (tty__cooked_mode(&el->el_tty.t_ts)) {
- if (el->el_tty.t_ts.c_cflag != el->el_tty.t_ex.c_cflag) {
+ if (el->el_tty.t_ts.c_cflag != el->el_tty.t_ex.c_cflag) {
el->el_tty.t_ex.c_cflag = el->el_tty.t_ts.c_cflag;
el->el_tty.t_ex.c_cflag &= ~el->el_tty.t_t[EX_IO][M_CTL].t_clrmask;
el->el_tty.t_ex.c_cflag |= el->el_tty.t_t[EX_IO][M_CTL].t_setmask;
@@ -862,9 +862,9 @@ tty_rawmode(el)
el->el_tty.t_ed.c_oflag |= el->el_tty.t_t[ED_IO][M_OUT].t_setmask;
}
- if (tty__gettabs(&el->el_tty.t_ex) == 0)
+ if (tty__gettabs(&el->el_tty.t_ex) == 0)
el->el_tty.t_tabs = 0;
- else
+ else
el->el_tty.t_tabs = EL_CAN_TAB ? 1 : 0;
{
@@ -879,7 +879,7 @@ tty_rawmode(el)
for (i = 0; i < C_NCC; i++)
if (el->el_tty.t_c[TS_IO][i] != el->el_tty.t_c[EX_IO][i])
break;
-
+
if (i != C_NCC) {
/*
* Propagate changes only to the unprotected chars
@@ -910,7 +910,7 @@ tty_rawmode(el)
if (tty_setty(el, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n",
+ (void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n",
strerror(errno));
#endif /* DEBUG_TTY */
return -1;
@@ -932,7 +932,7 @@ tty_cookedmode(el)
if (tty_setty(el, &el->el_tty.t_ex) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "tty_cookedmode: tty_setty: %s\n",
+ (void) fprintf(el->el_errfile, "tty_cookedmode: tty_setty: %s\n",
strerror(errno));
#endif /* DEBUG_TTY */
return -1;
@@ -968,7 +968,7 @@ tty_quotemode(el)
if (tty_setty(el, &el->el_tty.t_qu) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n",
+ (void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n",
strerror(errno));
#endif /* DEBUG_TTY */
return -1;
@@ -989,7 +989,7 @@ tty_noquotemode(el)
return 0;
if (tty_setty(el, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n",
+ (void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n",
strerror(errno));
#endif /* DEBUG_TTY */
return -1;
@@ -1019,7 +1019,7 @@ tty_stty(el, argc, argv)
return -1;
name = *argv++;
- while (argv && *argv && argv[0][0] == '-' && argv[0][2] == '\0')
+ while (argv && *argv && argv[0][0] == '-' && argv[0][2] == '\0')
switch (argv[0][1]) {
case 'a':
aflag++;
@@ -1048,7 +1048,7 @@ tty_stty(el, argc, argv)
int len = 0, st = 0, cu;
for (m = ttymodes; m->m_name; m++) {
if (m->m_type != i) {
- (void) fprintf(el->el_outfile, "%s%s", i != -1 ? "\n" : "",
+ (void) fprintf(el->el_outfile, "%s%s", i != -1 ? "\n" : "",
el->el_tty.t_t[z][m->m_type].t_name);
i = m->m_type;
st = len = strlen(el->el_tty.t_t[z][m->m_type].t_name);
@@ -1065,7 +1065,7 @@ tty_stty(el, argc, argv)
(void) fprintf(el->el_outfile, "\n%*s", st, "");
len = st + cu;
}
- else
+ else
len += cu;
if (x != '\0')
@@ -1131,7 +1131,7 @@ tty_printchar(el, s)
int i;
for (i = 0; i < C_NCC; i++) {
- for (m = el->el_tty.t_t; m->m_name; m++)
+ for (m = el->el_tty.t_t; m->m_name; m++)
if (m->m_type == M_CHAR && C_SH(i) == m->m_value)
break;
if (m->m_name)
@@ -1139,6 +1139,6 @@ tty_printchar(el, s)
if (i % 5 == 0)
(void) fprintf(el->el_errfile, "\n");
}
- (void) fprintf(el->el_errfile, "\n");
+ (void) fprintf(el->el_errfile, "\n");
}
#endif /* notyet */
diff --git a/lib/libedit/tty.h b/lib/libedit/tty.h
index 12da50d..294c36a 100644
--- a/lib/libedit/tty.h
+++ b/lib/libedit/tty.h
@@ -46,7 +46,7 @@
#include <termios.h>
/* Define our own since everyone gets it wrong! */
-#define CONTROL(A) ((A) & 037)
+#define CONTROL(A) ((A) & 037)
/*
* Aix compatible names
@@ -145,7 +145,12 @@
# endif /* IEXTEN != 0 */
#endif /* convex || __convex__ */
-
+/*
+ * So that we don't lose job control.
+ */
+#ifdef __SVR4
+# undef CSWTCH
+#endif
#ifndef _POSIX_VDISABLE
# define _POSIX_VDISABLE ((unsigned char) -1)
@@ -444,10 +449,10 @@
#define M_CHAR 4
#define M_NN 5
-typedef struct {
+typedef struct {
char *t_name;
- int t_setmask;
- int t_clrmask;
+ u_int t_setmask;
+ u_int t_clrmask;
} ttyperm_t[NN_IO][M_NN];
typedef unsigned char ttychar_t[NN_IO][C_NCC];
diff --git a/lib/libedit/vi.c b/lib/libedit/vi.c
index 030ee22..3a8ef05 100644
--- a/lib/libedit/vi.c
+++ b/lib/libedit/vi.c
@@ -59,7 +59,7 @@ cv_action(el, c)
if (el->el_chared.c_vcmd.action & DELETE) {
el->el_chared.c_vcmd.action = NOP;
el->el_chared.c_vcmd.pos = 0;
-
+
el->el_chared.c_undo.isize = 0;
el->el_chared.c_undo.dsize = 0;
kp = el->el_chared.c_undo.buf;
@@ -67,14 +67,14 @@ cv_action(el, c)
*kp++ = *cp;
el->el_chared.c_undo.dsize++;
}
-
+
el->el_chared.c_undo.action = INSERT;
el->el_chared.c_undo.ptr = el->el_line.buffer;
el->el_line.lastchar = el->el_line.buffer;
el->el_line.cursor = el->el_line.buffer;
if (c & INSERT)
el->el_map.current = el->el_map.key;
-
+
return CC_REFRESH;
}
@@ -111,7 +111,7 @@ cv_paste(el, c)
char *ptr;
c_undo_t *un = &el->el_chared.c_undo;
#ifdef DEBUG_PASTE
- (void) fprintf(el->el_errfile, "Paste: %x \"%s\" +%d -%d\n",
+ (void) fprintf(el->el_errfile, "Paste: %x \"%s\" +%d -%d\n",
un->action, un->buf, un->isize, un->dsize);
#endif
if (un->isize == 0)
@@ -120,7 +120,7 @@ cv_paste(el, c)
if (!c && el->el_line.cursor < el->el_line.lastchar)
el->el_line.cursor++;
ptr = el->el_line.cursor;
-
+
c_insert(el, un->isize);
if (el->el_line.cursor + un->isize > el->el_line.lastchar)
return CC_ERROR;
@@ -129,7 +129,7 @@ cv_paste(el, c)
}
-/* vi_paste_next():
+/* vi_paste_next():
* Vi paste previous deletion to the right of the cursor
* [p]
*/
@@ -143,7 +143,7 @@ vi_paste_next(el, c)
}
-/* vi_paste_prev():
+/* vi_paste_prev():
* Vi paste previous deletion to the left of the cursor
* [P]
*/
@@ -157,7 +157,7 @@ vi_paste_prev(el, c)
}
-/* vi_prev_space_word():
+/* vi_prev_space_word():
* Vi move to the previous space delimited word
* [B]
*/
@@ -170,10 +170,10 @@ vi_prev_space_word(el, c)
if (el->el_line.cursor == el->el_line.buffer)
return CC_ERROR;
- el->el_line.cursor = cv_prev_word(el, el->el_line.cursor,
- el->el_line.buffer,
- el->el_state.argument,
- cv__isword);
+ el->el_line.cursor = cv_prev_word(el, el->el_line.cursor,
+ el->el_line.buffer,
+ el->el_state.argument,
+ cv__isword);
if (el->el_chared.c_vcmd.action & DELETE) {
cv_delfini(el);
@@ -184,7 +184,7 @@ vi_prev_space_word(el, c)
}
-/* vi_prev_word():
+/* vi_prev_word():
* Vi move to the previous word
* [B]
*/
@@ -197,10 +197,10 @@ vi_prev_word(el, c)
if (el->el_line.cursor == el->el_line.buffer)
return CC_ERROR;
- el->el_line.cursor = cv_prev_word(el, el->el_line.cursor,
- el->el_line.buffer,
- el->el_state.argument,
- ce__isword);
+ el->el_line.cursor = cv_prev_word(el, el->el_line.cursor,
+ el->el_line.buffer,
+ el->el_state.argument,
+ ce__isword);
if (el->el_chared.c_vcmd.action & DELETE) {
cv_delfini(el);
@@ -211,7 +211,7 @@ vi_prev_word(el, c)
}
-/* vi_next_space_word():
+/* vi_next_space_word():
* Vi move to the next space delimited word
* [W]
*/
@@ -224,9 +224,9 @@ vi_next_space_word(el, c)
if (el->el_line.cursor == el->el_line.lastchar)
return CC_ERROR;
- el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
- el->el_line.lastchar,
- el->el_state.argument,
+ el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
+ el->el_line.lastchar,
+ el->el_state.argument,
cv__isword);
if (el->el_map.type == MAP_VI)
@@ -238,7 +238,7 @@ vi_next_space_word(el, c)
return CC_CURSOR;
}
-/* vi_next_word():
+/* vi_next_word():
* Vi move to the next word
* [w]
*/
@@ -251,8 +251,8 @@ vi_next_word(el, c)
if (el->el_line.cursor == el->el_line.lastchar)
return CC_ERROR;
- el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
- el->el_line.lastchar,
+ el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
+ el->el_line.lastchar,
el->el_state.argument,
ce__isword);
@@ -267,7 +267,7 @@ vi_next_word(el, c)
-/* vi_change_case():
+/* vi_change_case():
* Vi change case of character under the cursor and advance one character
* [~]
*/
@@ -277,7 +277,7 @@ vi_change_case(el, c)
int c;
{
if (el->el_line.cursor < el->el_line.lastchar) {
- c = *el->el_line.cursor;
+ c = (unsigned char)*el->el_line.cursor;
if (isupper(c))
*el->el_line.cursor++ = tolower(c);
else if (islower(c))
@@ -291,7 +291,7 @@ vi_change_case(el, c)
}
-/* vi_change_meta():
+/* vi_change_meta():
* Vi change prefix command
* [c]
*/
@@ -309,7 +309,7 @@ vi_change_meta(el, c)
}
-/* vi_insert_at_bol():
+/* vi_insert_at_bol():
* Vi enter insert mode at the beginning of line
* [I]
*/
@@ -330,7 +330,7 @@ vi_insert_at_bol(el, c)
}
-/* vi_replace_char():
+/* vi_replace_char():
* Vi replace character under the cursor with the next character typed
* [r]
*/
@@ -350,7 +350,7 @@ vi_replace_char(el, c)
}
-/* vi_replace_mode():
+/* vi_replace_mode():
* Vi enter replace mode
* [R]
*/
@@ -370,7 +370,7 @@ vi_replace_mode(el, c)
}
-/* vi_substitute_char():
+/* vi_substitute_char():
* Vi replace character under the cursor and enter insert mode
* [r]
*/
@@ -386,7 +386,7 @@ vi_substitute_char(el, c)
}
-/* vi_substitute_line():
+/* vi_substitute_line():
* Vi substitute entire line
* [S]
*/
@@ -402,7 +402,7 @@ vi_substitute_line(el, c)
}
-/* vi_change_to_eol():
+/* vi_change_to_eol():
* Vi change to end of line
* [C]
*/
@@ -439,7 +439,7 @@ vi_insert(el, c)
/* vi_add():
- * Vi enter insert mode after the cursor
+ * Vi enter insert mode after the cursor
* [a]
*/
protected el_action_t
@@ -481,7 +481,7 @@ vi_add_at_eol(el, c)
el->el_line.cursor = el->el_line.lastchar;
/* Mark where insertion begins */
- el->el_chared.c_vcmd.ins = el->el_line.lastchar;
+ el->el_chared.c_vcmd.ins = el->el_line.lastchar;
el->el_chared.c_undo.ptr = el->el_line.lastchar;
el->el_chared.c_undo.action = DELETE;
return CC_CURSOR;
@@ -489,7 +489,7 @@ vi_add_at_eol(el, c)
/* vi_delete_meta():
- * Vi delete prefix command
+ * Vi delete prefix command
* [d]
*/
protected el_action_t
@@ -503,8 +503,8 @@ vi_delete_meta(el, c)
/* vi_end_word():
- * Vi move to the end of the current space delimited word
- * [E]
+ * Vi move to the end of the current space delimited word
+ * [E]
*/
protected el_action_t
/*ARGSUSED*/
@@ -515,7 +515,7 @@ vi_end_word(el, c)
if (el->el_line.cursor == el->el_line.lastchar)
return CC_ERROR;
- el->el_line.cursor = cv__endword(el->el_line.cursor, el->el_line.lastchar,
+ el->el_line.cursor = cv__endword(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument);
if (el->el_chared.c_vcmd.action & DELETE) {
@@ -541,7 +541,7 @@ vi_to_end_word(el, c)
if (el->el_line.cursor == el->el_line.lastchar)
return CC_ERROR;
- el->el_line.cursor = cv__endword(el->el_line.cursor, el->el_line.lastchar,
+ el->el_line.cursor = cv__endword(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument);
if (el->el_chared.c_vcmd.action & DELETE) {
@@ -570,12 +570,12 @@ vi_undo(el, c)
c_undo_t *un = &el->el_chared.c_undo;
#ifdef DEBUG_UNDO
- (void) fprintf(el->el_errfile, "Undo: %x \"%s\" +%d -%d\n",
+ (void) fprintf(el->el_errfile, "Undo: %x \"%s\" +%d -%d\n",
un->action, un->buf, un->isize, un->dsize);
#endif
switch (un->action) {
case DELETE:
- if (un->dsize == 0)
+ if (un->dsize == 0)
return CC_NORM;
(void) memcpy(un->buf, un->ptr, un->dsize);
@@ -584,7 +584,7 @@ vi_undo(el, c)
el->el_line.lastchar -= un->dsize;
el->el_line.cursor = un->ptr;
-
+
un->action = INSERT;
un->isize = un->dsize;
un->dsize = 0;
@@ -592,9 +592,9 @@ vi_undo(el, c)
case DELETE|INSERT:
size = un->isize - un->dsize;
- if (size > 0)
+ if (size > 0)
i = un->dsize;
- else
+ else
i = un->isize;
cp = un->ptr;
kp = un->buf;
@@ -627,7 +627,7 @@ vi_undo(el, c)
break;
case INSERT:
- if (un->isize == 0)
+ if (un->isize == 0)
return CC_NORM;
el->el_line.cursor = un->ptr;
@@ -639,11 +639,11 @@ vi_undo(el, c)
break;
case CHANGE:
- if (un->isize == 0)
+ if (un->isize == 0)
return CC_NORM;
el->el_line.cursor = un->ptr;
- size = (int) (el->el_line.cursor - el->el_line.lastchar);
+ size = (int) (el->el_line.cursor - el->el_line.lastchar);
if (size < un->isize)
size = un->isize;
cp = un->ptr;
@@ -677,7 +677,7 @@ vi_command_mode(el, c)
int size;
/* [Esc] cancels pending action */
el->el_chared.c_vcmd.ins = 0;
- el->el_chared.c_vcmd.action = NOP;
+ el->el_chared.c_vcmd.action = NOP;
el->el_chared.c_vcmd.pos = 0;
el->el_state.doingarg = 0;
@@ -700,7 +700,7 @@ vi_command_mode(el, c)
}
/* vi_zero():
- * Vi move to the beginning of line
+ * Vi move to the beginning of line
* [0]
*/
protected el_action_t
@@ -711,7 +711,7 @@ vi_zero(el, c)
if (el->el_state.doingarg) {
if (el->el_state.argument > 1000000)
return CC_ERROR;
- el->el_state.argument =
+ el->el_state.argument =
(el->el_state.argument * 10) + (c - '0');
return CC_ARGHACK;
}
@@ -727,23 +727,23 @@ vi_zero(el, c)
/* vi_delete_prev_char():
- * Vi move to previous character (backspace)
+ * Vi move to previous character (backspace)
* [^H]
- */
+ */
protected el_action_t
/*ARGSUSED*/
vi_delete_prev_char(el, c)
EditLine *el;
int c;
{
- if (el->el_chared.c_vcmd.ins == 0)
+ if (el->el_chared.c_vcmd.ins == 0)
return CC_ERROR;
- if (el->el_chared.c_vcmd.ins >
+ if (el->el_chared.c_vcmd.ins >
el->el_line.cursor - el->el_state.argument)
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;
return CC_REFRESH;
@@ -761,7 +761,7 @@ vi_list_or_eof(el, c)
int c;
{
#ifdef notyet
- if (el->el_line.cursor == el->el_line.lastchar &&
+ if (el->el_line.cursor == el->el_line.lastchar &&
el->el_line.cursor == el->el_line.buffer) {
#endif
term_overwrite(el, STReof, 4); /* then do a EOF */
@@ -779,7 +779,7 @@ vi_list_or_eof(el, c)
/* vi_kill_line_prev():
- * Vi cut from beginning of line to cursor
+ * Vi cut from beginning of line to cursor
* [^U]
*/
protected el_action_t
@@ -839,7 +839,7 @@ vi_repeat_search_next(el, c)
EditLine *el;
int c;
{
- if (el->el_search.patlen == 0)
+ if (el->el_search.patlen == 0)
return CC_ERROR;
else
return cv_repeat_srch(el, el->el_search.patdir);
@@ -856,10 +856,10 @@ vi_repeat_search_prev(el, c)
EditLine *el;
int c;
{
- if (el->el_search.patlen == 0)
+ if (el->el_search.patlen == 0)
return CC_ERROR;
else
- return cv_repeat_srch(el,
+ return cv_repeat_srch(el,
el->el_search.patdir == ED_SEARCH_PREV_HISTORY ?
ED_SEARCH_NEXT_HISTORY : ED_SEARCH_PREV_HISTORY);
}
@@ -961,8 +961,8 @@ vi_repeat_next_char(el, c)
if (el->el_search.chacha == 0)
return CC_ERROR;
- return el->el_search.chadir == CHAR_FWD ?
- cv_csearch_fwd(el, el->el_search.chacha, el->el_state.argument, 0) :
+ return el->el_search.chadir == CHAR_FWD ?
+ cv_csearch_fwd(el, el->el_search.chacha, el->el_state.argument, 0) :
cv_csearch_back(el, el->el_search.chacha, el->el_state.argument, 0);
}
@@ -980,7 +980,7 @@ vi_repeat_prev_char(el, c)
if (el->el_search.chacha == 0)
return CC_ERROR;
- return el->el_search.chadir == CHAR_BACK ?
- cv_csearch_fwd(el, el->el_search.chacha, el->el_state.argument, 0) :
+ return el->el_search.chadir == CHAR_BACK ?
+ cv_csearch_fwd(el, el->el_search.chacha, el->el_state.argument, 0) :
cv_csearch_back(el, el->el_search.chacha, el->el_state.argument, 0);
}
OpenPOWER on IntegriCloud