Skip to content
Browse files

libedit: Upgrade NetBSD version 2011-03-11

As NetBSD has properly packaged regular releases of their libedit
library (readline replacement), a new vendor branch has been created
for it.  Libedit was last synchronized with NetBSD 4 years ago, to
the week.

During that time, a new function was added to the DragonFly version
that still doesn't exist on NetBSD.  It is necessary to support GDB
7.x, so the addition of rl_completion_word_break_hook function has
been carried over to this update.
  • Loading branch information...
1 parent edce0eb commit c22639f2f9ab7a553a48a826103c4a9b7c77f86a @jrmarino jrmarino committed May 10, 2012
Showing with 539 additions and 18,758 deletions.
  1. +2 −78 lib/libedit/Makefile
  2. +1 −0 lib/libedit/Makefile.inc
  3. +0 −14 lib/libedit/TEST/Makefile
  4. +0 −295 lib/libedit/TEST/test.c
  5. +0 −769 lib/libedit/chared.c
  6. +0 −167 lib/libedit/chared.h
  7. +0 −916 lib/libedit/common.c
  8. +0 −19 lib/libedit/config.h
  9. +0 −576 lib/libedit/el.c
  10. +0 −150 lib/libedit/el.h
  11. +0 −502 lib/libedit/emacs.c
  12. +0 −537 lib/libedit/filecomplete.c
  13. +0 −45 lib/libedit/filecomplete.h
  14. +0 −205 lib/libedit/hist.c
  15. +0 −76 lib/libedit/hist.h
  16. +0 −986 lib/libedit/history.c
  17. +0 −701 lib/libedit/key.c
  18. +0 −81 lib/libedit/key.h
  19. +115 −0 lib/libedit/libedit/Makefile
  20. +292 −0 lib/libedit/libedit/config.h
  21. +117 −56 lib/libedit/{ → libedit}/editline.3
  22. +9 −28 lib/libedit/{ → libedit}/editrc.5
  23. +0 −250 lib/libedit/makelist
  24. +0 −1,417 lib/libedit/map.c
  25. +0 −75 lib/libedit/map.h
  26. +0 −258 lib/libedit/parse.c
  27. +0 −48 lib/libedit/parse.h
  28. +0 −165 lib/libedit/prompt.c
  29. +0 −58 lib/libedit/prompt.h
  30. +0 −623 lib/libedit/read.c
  31. +0 −51 lib/libedit/read.h
  32. +0 −1,978 lib/libedit/readline.c
  33. +3 −3 lib/libedit/readline/Makefile
  34. +0 −202 lib/libedit/readline/readline.h
  35. +0 −1,134 lib/libedit/refresh.c
  36. +0 −59 lib/libedit/refresh.h
  37. +0 −628 lib/libedit/search.c
  38. +0 −66 lib/libedit/search.h
  39. +0 −189 lib/libedit/sig.c
  40. +0 −69 lib/libedit/sig.h
  41. +0 −140 lib/libedit/sys.h
  42. +0 −1,671 lib/libedit/term.c
  43. +0 −125 lib/libedit/term.h
  44. +0 −442 lib/libedit/tokenizer.c
  45. +0 −1,307 lib/libedit/tty.c
  46. +0 −480 lib/libedit/tty.h
  47. +0 −1,119 lib/libedit/vi.c
View
80 lib/libedit/Makefile
@@ -1,79 +1,3 @@
-# @(#)Makefile 8.1 (Berkeley) 6/4/93
-# $FreeBSD: src/lib/libedit/Makefile,v 1.18.2.2 2002/07/23 10:20:19 ru Exp $
-# $DragonFly: src/lib/libedit/Makefile,v 1.6 2008/06/27 08:06:48 corecode Exp $
+SUBDIR= readline libedit
-LIB= edit
-SHLIB_MAJOR= 5
-
-OSRCS= chared.c common.c el.c emacs.c fcns.c filecomplete.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
-
-DPADD= ${LIBNCURSES}
-LDADD= -lncurses
-
-WARNS?= 2
-
-MAN= editline.3 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_get.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 \
- editline.3 tok_init.3 editline.3 tok_end.3 editline.3 tok_reset.3 \
- editline.3 tok_line.3 editline.3 tok_str.3
-
-# For speed and debugging
-#SRCS= ${OSRCS} tokenizer.c history.c
-# For protection
-SRCS= editline.c tokenizer.c history.c readline.c
-
-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
-ASRC=${.CURDIR}/vi.c ${.CURDIR}/emacs.c ${.CURDIR}/common.c
-
-SUBDIR= readline
-
-vi.h: vi.c makelist
- sh ${.CURDIR}/makelist -h ${.CURDIR}/vi.c > ${.TARGET}
-
-emacs.h: emacs.c makelist
- sh ${.CURDIR}/makelist -h ${.CURDIR}/emacs.c > ${.TARGET}
-
-common.h: common.c makelist
- sh ${.CURDIR}/makelist -h ${.CURDIR}/common.c > ${.TARGET}
-
-fcns.h: ${AHDR} makelist
- sh ${.CURDIR}/makelist -fh ${AHDR} > ${.TARGET}
-
-fcns.c: ${AHDR} fcns.h help.h makelist
- sh ${.CURDIR}/makelist -fc ${AHDR} > ${.TARGET}
-
-help.c: ${ASRC} makelist
- sh ${.CURDIR}/makelist -bc ${ASRC} > ${.TARGET}
-
-help.h: ${ASRC} makelist
- sh ${.CURDIR}/makelist -bh ${ASRC} > ${.TARGET}
-
-editline.c: ${OSRCS} makelist
- sh ${.CURDIR}/makelist -e ${OSRCS} > ${.TARGET}
-
-beforedepend editline.o editline.po editline.So: \
- vi.h emacs.h common.h fcns.h fcns.c help.h help.c
-
-# Not up to date
-#test.o: ${.CURDIR}/TEST/test.c
-#
-#test: test.o libedit.a ${DPADD} ${LIBTERMCAP}
-# ${CC} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD}
-
-.include <bsd.lib.mk>
+.include <bsd.subdir.mk>
View
1 lib/libedit/Makefile.inc
@@ -0,0 +1 @@
+BASEDIR= ${.CURDIR}/${RELATIVE}../../../contrib/libedit
View
14 lib/libedit/TEST/Makefile
@@ -1,14 +0,0 @@
-# $NetBSD: Makefile,v 1.2 2003/12/05 13:37:48 lukem Exp $
-# $DragonFly: src/lib/libedit/TEST/Makefile,v 1.2 2007/05/05 00:27:40 pavalos Exp $
-
-NOMAN=1
-PROG=test
-CFLAGS=-I${.CURDIR}/..
-LDADD+=-ledit -ltermcap
-DPADD+=${LIBEDIT} ${LIBTERMCAP}
-
-.ifdef DEBUG
-CFLAGS+=-DDEBUG
-.endif
-
-.include <bsd.prog.mk>
View
295 lib/libedit/TEST/test.c
@@ -1,295 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * 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. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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.
- *
- * @(#)test.c 8.1 (Berkeley) 6/4/93
- * $NetBSD: test.c,v 1.18 2005/06/01 11:37:52 lukem Exp $
- * $DragonFly: src/lib/libedit/TEST/test.c,v 1.3 2005/11/13 11:58:30 corecode Exp $
- */
-
-#include "config.h"
-#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
- The Regents of the University of California. All rights reserved.\n");
-#endif /* not lint */
-
-/*
- * test.c: A little test program
- */
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/wait.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <dirent.h>
-
-#include "histedit.h"
-
-static int continuation = 0;
-volatile sig_atomic_t gotsig = 0;
-
-static unsigned char complete(EditLine *, int);
- int main(int, char **);
-static char *prompt(EditLine *);
-static void sig(int);
-
-static char *
-prompt(EditLine *el)
-{
- static char a[] = "Edit$ ";
- static char b[] = "Edit> ";
-
- return (continuation ? b : a);
-}
-
-static void
-sig(int i)
-{
- gotsig = i;
-}
-
-static unsigned char
-complete(EditLine *el, int ch)
-{
- DIR *dd = opendir(".");
- struct dirent *dp;
- const char* ptr;
- const LineInfo *lf = el_line(el);
- int len;
-
- /*
- * Find the last word
- */
- for (ptr = lf->cursor - 1;
- !isspace((unsigned char)*ptr) && ptr > lf->buffer; ptr--)
- continue;
- len = lf->cursor - ++ptr;
-
- for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
- if (len > strlen(dp->d_name))
- continue;
- if (strncmp(dp->d_name, ptr, len) == 0) {
- closedir(dd);
- if (el_insertstr(el, &dp->d_name[len]) == -1)
- return (CC_ERROR);
- else
- return (CC_REFRESH);
- }
- }
-
- closedir(dd);
- return (CC_ERROR);
-}
-
-int
-main(int argc, char *argv[])
-{
- EditLine *el = NULL;
- int num;
- const char *buf;
- Tokenizer *tok;
-#if 0
- int lastevent = 0;
-#endif
- int ncontinuation;
- History *hist;
- HistEvent ev;
-
- (void) signal(SIGINT, sig);
- (void) signal(SIGQUIT, sig);
- (void) signal(SIGHUP, sig);
- (void) signal(SIGTERM, sig);
-
- hist = history_init(); /* Init the builtin history */
- /* Remember 100 events */
- history(hist, &ev, H_SETSIZE, 100);
-
- tok = tok_init(NULL); /* Initialize the tokenizer */
-
- /* Initialize editline */
- el = el_init(*argv, stdin, stdout, stderr);
-
- el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */
- el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
- el_set(el, EL_PROMPT, prompt); /* Set the prompt function */
-
- /* Tell editline to use this history interface */
- el_set(el, EL_HIST, history, hist);
-
- /* Add a user-defined function */
- el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
-
- /* Bind tab to it */
- el_set(el, EL_BIND, "^I", "ed-complete", NULL);
-
- /*
- * Bind j, k in vi command mode to previous and next line, instead
- * of previous and next history.
- */
- el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
- el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
-
- /*
- * Source the user's defaults file.
- */
- el_source(el, NULL);
-
- while ((buf = el_gets(el, &num)) != NULL && num != 0) {
- int ac, cc, co;
-#ifdef DEBUG
- int i;
-#endif
- const char **av;
- const LineInfo *li;
- li = el_line(el);
-#ifdef DEBUG
- (void) fprintf(stderr, "==> got %d %s", num, buf);
- (void) fprintf(stderr, " > li `%.*s_%.*s'\n",
- (li->cursor - li->buffer), li->buffer,
- (li->lastchar - 1 - li->cursor),
- (li->cursor >= li->lastchar) ? "" : li->cursor);
-
-#endif
- if (gotsig) {
- (void) fprintf(stderr, "Got signal %d.\n", gotsig);
- gotsig = 0;
- el_reset(el);
- }
-
- if (!continuation && num == 1)
- continue;
-
- ac = cc = co = 0;
- ncontinuation = tok_line(tok, li, &ac, &av, &cc, &co);
- if (ncontinuation < 0) {
- (void) fprintf(stderr, "Internal error\n");
- continuation = 0;
- continue;
- }
-#ifdef DEBUG
- (void) fprintf(stderr, " > nc %d ac %d cc %d co %d\n",
- ncontinuation, ac, cc, co);
-#endif
-#if 0
- if (continuation) {
- /*
- * Append to the right event in case the user
- * moved around in history.
- */
- if (history(hist, &ev, H_SET, lastevent) == -1)
- err(1, "%d: %s", lastevent, ev.str);
- history(hist, &ev, H_ADD , buf);
- } else {
- history(hist, &ev, H_ENTER, buf);
- lastevent = ev.num;
- }
-#else
- /* Simpler */
- history(hist, &ev, continuation ? H_APPEND : H_ENTER, buf);
-#endif
-
- continuation = ncontinuation;
- ncontinuation = 0;
- if (continuation)
- continue;
-#ifdef DEBUG
- for (i = 0; i < ac; i++) {
- (void) fprintf(stderr, " > arg# %2d ", i);
- if (i != cc)
- (void) fprintf(stderr, "`%s'\n", av[i]);
- else
- (void) fprintf(stderr, "`%.*s_%s'\n",
- co, av[i], av[i] + co);
- }
-#endif
-
- if (strcmp(av[0], "history") == 0) {
- int rv;
-
- switch (ac) {
- case 1:
- for (rv = history(hist, &ev, H_LAST); rv != -1;
- rv = history(hist, &ev, H_PREV))
- (void) fprintf(stdout, "%4d %s",
- ev.num, ev.str);
- break;
-
- case 2:
- if (strcmp(av[1], "clear") == 0)
- history(hist, &ev, H_CLEAR);
- else
- goto badhist;
- break;
-
- case 3:
- if (strcmp(av[1], "load") == 0)
- history(hist, &ev, H_LOAD, av[2]);
- else if (strcmp(av[1], "save") == 0)
- history(hist, &ev, 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], (char *const *)(void *)(unsigned long)(const void *)(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);
- }
-
- el_end(el);
- tok_end(tok);
- history_end(hist);
-
- return (0);
-}
View
769 lib/libedit/chared.c
@@ -1,769 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * 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. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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.
- *
- * @(#)chared.c 8.1 (Berkeley) 6/4/93
- * $NetBSD: chared.c,v 1.25 2005/08/08 01:41:30 christos Exp $
- * $DragonFly: src/lib/libedit/chared.c,v 1.9 2008/09/30 16:57:05 swildner Exp $
- */
-
-#include "config.h"
-
-/*
- * chared.c: Character editor utilities
- */
-#include <stdlib.h>
-#include "el.h"
-
-private void ch__clearmacro(EditLine *);
-
-/* value to leave unused in line buffer */
-#define EL_LEAVE 2
-
-/* cv_undo():
- * Handle state for the vi undo command
- */
-protected void
-cv_undo(EditLine *el)
-{
- c_undo_t *vu = &el->el_chared.c_undo;
- c_redo_t *r = &el->el_chared.c_redo;
- unsigned int size;
-
- /* Save entire line for undo */
- size = el->el_line.lastchar - el->el_line.buffer;
- vu->len = size;
- vu->cursor = el->el_line.cursor - el->el_line.buffer;
- memcpy(vu->buf, el->el_line.buffer, size);
-
- /* save command info for redo */
- r->count = el->el_state.doingarg ? el->el_state.argument : 0;
- r->action = el->el_chared.c_vcmd.action;
- r->pos = r->buf;
- r->cmd = el->el_state.thiscmd;
- r->ch = el->el_state.thisch;
-}
-
-/* cv_yank():
- * Save yank/delete data for paste
- */
-protected void
-cv_yank(EditLine *el, const char *ptr, int size)
-{
- c_kill_t *k = &el->el_chared.c_kill;
-
- memcpy(k->buf, ptr, size +0u);
- k->last = k->buf + size;
-}
-
-
-/* c_insert():
- * Insert num characters
- */
-protected void
-c_insert(EditLine *el, int num)
-{
- char *cp;
-
- if (el->el_line.lastchar + num >= el->el_line.limit) {
- if (!ch_enlargebufs(el, num +0u))
- return; /* can't go past end of buffer */
- }
-
- 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;
- }
- el->el_line.lastchar += num;
-}
-
-
-/* c_delafter():
- * Delete num characters after the cursor
- */
-protected void
-c_delafter(EditLine *el, int num)
-{
-
- if (el->el_line.cursor + num > el->el_line.lastchar)
- num = el->el_line.lastchar - el->el_line.cursor;
-
- if (el->el_map.current != el->el_map.emacs) {
- cv_undo(el);
- cv_yank(el, el->el_line.cursor, num);
- }
-
- if (num > 0) {
- char *cp;
-
- for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
- *cp = cp[num];
-
- el->el_line.lastchar -= num;
- }
-}
-
-
-/* c_delafter1():
- * Delete the character after the cursor, do not yank
- */
-protected void
-c_delafter1(EditLine *el)
-{
- char *cp;
-
- for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
- *cp = cp[1];
-
- el->el_line.lastchar--;
-}
-
-
-/* c_delbefore():
- * Delete num characters before the cursor
- */
-protected void
-c_delbefore(EditLine *el, int num)
-{
-
- if (el->el_line.cursor - num < el->el_line.buffer)
- num = el->el_line.cursor - el->el_line.buffer;
-
- if (el->el_map.current != el->el_map.emacs) {
- cv_undo(el);
- cv_yank(el, el->el_line.cursor - num, num);
- }
-
- if (num > 0) {
- char *cp;
-
- for (cp = el->el_line.cursor - num;
- cp <= el->el_line.lastchar;
- cp++)
- *cp = cp[num];
-
- el->el_line.lastchar -= num;
- }
-}
-
-
-/* c_delbefore1():
- * Delete the character before the cursor, do not yank
- */
-protected void
-c_delbefore1(EditLine *el)
-{
- char *cp;
-
- for (cp = el->el_line.cursor - 1; cp <= el->el_line.lastchar; cp++)
- *cp = cp[1];
-
- el->el_line.lastchar--;
-}
-
-
-/* ce__isword():
- * Return if p is part of a word according to emacs
- */
-protected int
-ce__isword(int p)
-{
- return (isalnum(p) || strchr("*?_-.[]~=", p) != NULL);
-}
-
-
-/* cv__isword():
- * Return if p is part of a word according to vi
- */
-protected int
-cv__isword(int p)
-{
- if (isalnum(p) || p == '_')
- return 1;
- if (isgraph(p))
- return 2;
- return 0;
-}
-
-
-/* cv__isWord():
- * Return if p is part of a big word according to vi
- */
-protected int
-cv__isWord(int p)
-{
- return (!isspace(p));
-}
-
-
-/* c__prev_word():
- * Find the previous word
- */
-protected char *
-c__prev_word(char *p, char *low, int n, int (*wtest)(int))
-{
- p--;
-
- while (n--) {
- while ((p >= low) && !(*wtest)((unsigned char) *p))
- p--;
- while ((p >= low) && (*wtest)((unsigned char) *p))
- p--;
- }
-
- /* cp now points to one character before the word */
- p++;
- if (p < low)
- p = low;
- /* cp now points where we want it */
- return (p);
-}
-
-
-/* c__next_word():
- * Find the next word
- */
-protected char *
-c__next_word(char *p, char *high, int n, int (*wtest)(int))
-{
- while (n--) {
- while ((p < high) && !(*wtest)((unsigned char) *p))
- p++;
- while ((p < high) && (*wtest)((unsigned char) *p))
- p++;
- }
- if (p > high)
- p = high;
- /* p now points where we want it */
- return (p);
-}
-
-/* cv_next_word():
- * Find the next word vi style
- */
-protected char *
-cv_next_word(EditLine *el, char *p, char *high, int n, int (*wtest)(int))
-{
- int test;
-
- while (n--) {
- test = (*wtest)((unsigned char) *p);
- 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 (n || el->el_chared.c_vcmd.action != (DELETE|INSERT))
- while ((p < high) && isspace((unsigned char) *p))
- p++;
- }
-
- /* p now points where we want it */
- if (p > high)
- return (high);
- else
- return (p);
-}
-
-
-/* cv_prev_word():
- * Find the previous word vi style
- */
-protected char *
-cv_prev_word(char *p, char *low, int n, int (*wtest)(int))
-{
- int test;
-
- p--;
- while (n--) {
- while ((p > low) && isspace((unsigned char) *p))
- p--;
- test = (*wtest)((unsigned char) *p);
- while ((p >= low) && (*wtest)((unsigned char) *p) == test)
- p--;
- }
- p++;
-
- /* p now points where we want it */
- if (p < low)
- return (low);
- else
- return (p);
-}
-
-
-#ifdef notdef
-/* c__number():
- * Ignore character p points to, return number appearing after that.
- * A '$' by itself means a big number; "$-" is for negative; '^' means 1.
- * Return p pointing to last char used.
- */
-protected char *
-c__number(
- char *p, /* character position */
- int *num, /* Return value */
- int dval) /* dval is the number to subtract from like $-3 */
-{
- int i;
- int sign = 1;
-
- if (*++p == '^') {
- *num = 1;
- return (p);
- }
- if (*p == '$') {
- if (*++p != '-') {
- *num = 0x7fffffff; /* Handle $ */
- return (--p);
- }
- sign = -1; /* Handle $- */
- ++p;
- }
- for (i = 0; isdigit((unsigned char) *p); i = 10 * i + *p++ - '0')
- continue;
- *num = (sign < 0 ? dval - i : i);
- return (--p);
-}
-#endif
-
-/* cv_delfini():
- * Finish vi delete action
- */
-protected void
-cv_delfini(EditLine *el)
-{
- int size;
- int action = el->el_chared.c_vcmd.action;
-
- if (action & INSERT)
- el->el_map.current = el->el_map.key;
-
- if (el->el_chared.c_vcmd.pos == 0)
- /* sanity */
- return;
-
- size = el->el_line.cursor - el->el_chared.c_vcmd.pos;
- if (size == 0)
- size = 1;
- el->el_line.cursor = el->el_chared.c_vcmd.pos;
- if (action & YANK) {
- if (size > 0)
- cv_yank(el, el->el_line.cursor, size);
- else
- cv_yank(el, el->el_line.cursor + size, -size);
- } else {
- if (size > 0) {
- c_delafter(el, size);
- re_refresh_cursor(el);
- } else {
- c_delbefore(el, -size);
- el->el_line.cursor += size;
- }
- }
- el->el_chared.c_vcmd.action = NOP;
-}
-
-
-#ifdef notdef
-/* ce__endword():
- * Go to the end of this word according to emacs
- */
-protected char *
-ce__endword(char *p, char *high, int n)
-{
- p++;
-
- while (n--) {
- while ((p < high) && isspace((unsigned char) *p))
- p++;
- while ((p < high) && !isspace((unsigned char) *p))
- p++;
- }
-
- p--;
- return (p);
-}
-#endif
-
-
-/* cv__endword():
- * Go to the end of this word according to vi
- */
-protected char *
-cv__endword(char *p, char *high, int n, int (*wtest)(int))
-{
- int test;
-
- p++;
-
- while (n--) {
- while ((p < high) && isspace((unsigned char) *p))
- p++;
-
- test = (*wtest)((unsigned char) *p);
- while ((p < high) && (*wtest)((unsigned char) *p) == test)
- p++;
- }
- p--;
- return (p);
-}
-
-/* ch_init():
- * Initialize the character editor
- */
-protected int
-ch_init(EditLine *el)
-{
- c_macro_t *ma = &el->el_chared.c_macro;
-
- el->el_line.buffer = (char *) el_malloc(EL_BUFSIZ);
- if (el->el_line.buffer == NULL)
- return (-1);
-
- (void) memset(el->el_line.buffer, 0, EL_BUFSIZ);
- el->el_line.cursor = el->el_line.buffer;
- el->el_line.lastchar = el->el_line.buffer;
- el->el_line.limit = &el->el_line.buffer[EL_BUFSIZ - EL_LEAVE];
-
- el->el_chared.c_undo.buf = (char *) el_malloc(EL_BUFSIZ);
- if (el->el_chared.c_undo.buf == NULL)
- return (-1);
- (void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ);
- el->el_chared.c_undo.len = -1;
- el->el_chared.c_undo.cursor = 0;
- el->el_chared.c_redo.buf = (char *) el_malloc(EL_BUFSIZ);
- if (el->el_chared.c_redo.buf == NULL)
- return (-1);
- el->el_chared.c_redo.pos = el->el_chared.c_redo.buf;
- el->el_chared.c_redo.lim = el->el_chared.c_redo.buf + EL_BUFSIZ;
- el->el_chared.c_redo.cmd = ED_UNASSIGNED;
-
- el->el_chared.c_vcmd.action = NOP;
- el->el_chared.c_vcmd.pos = el->el_line.buffer;
-
- el->el_chared.c_kill.buf = (char *) el_malloc(EL_BUFSIZ);
- if (el->el_chared.c_kill.buf == NULL)
- return (-1);
- (void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ);
- el->el_chared.c_kill.mark = el->el_line.buffer;
- el->el_chared.c_kill.last = el->el_chared.c_kill.buf;
-
- el->el_map.current = el->el_map.key;
-
- el->el_state.inputmode = MODE_INSERT; /* XXX: save a default */
- el->el_state.doingarg = 0;
- el->el_state.metanext = 0;
- el->el_state.argument = 1;
- el->el_state.lastcmd = ED_UNASSIGNED;
-
- ma->level = -1;
- ma->offset = 0;
- ma->macro = (char **) el_malloc(EL_MAXMACRO * sizeof(char *));
- if (ma->macro == NULL)
- return (-1);
- return (0);
-}
-
-/* ch_reset():
- * Reset the character editor
- */
-protected void
-ch_reset(EditLine *el, int mclear)
-{
- el->el_line.cursor = el->el_line.buffer;
- el->el_line.lastchar = el->el_line.buffer;
-
- el->el_chared.c_undo.len = -1;
- el->el_chared.c_undo.cursor = 0;
-
- el->el_chared.c_vcmd.action = NOP;
- el->el_chared.c_vcmd.pos = el->el_line.buffer;
-
- el->el_chared.c_kill.mark = el->el_line.buffer;
-
- el->el_map.current = el->el_map.key;
-
- el->el_state.inputmode = MODE_INSERT; /* XXX: save a default */
- el->el_state.doingarg = 0;
- el->el_state.metanext = 0;
- el->el_state.argument = 1;
- el->el_state.lastcmd = ED_UNASSIGNED;
-
- el->el_history.eventno = 0;
-
- if (mclear)
- ch__clearmacro(el);
-}
-
-private void
-ch__clearmacro(EditLine *el)
-{
- c_macro_t *ma = &el->el_chared.c_macro;
- while (ma->level >= 0)
- el_free((ptr_t)ma->macro[ma->level--]);
-}
-
-/* ch_enlargebufs():
- * Enlarge line buffer to be able to hold twice as much characters.
- * Returns 1 if successful, 0 if not.
- */
-protected int
-ch_enlargebufs(EditLine *el, size_t addlen)
-{
- size_t sz, newsz;
- char *newbuffer, *oldbuf, *oldkbuf;
-
- sz = el->el_line.limit - el->el_line.buffer + EL_LEAVE;
- newsz = sz * 2;
- /*
- * If newly required length is longer than current buffer, we need
- * to make the buffer big enough to hold both old and new stuff.
- */
- if (addlen > sz) {
- while(newsz - sz < addlen)
- newsz *= 2;
- }
-
- /*
- * Reallocate line buffer.
- */
- newbuffer = el_realloc(el->el_line.buffer, newsz);
- if (!newbuffer)
- return 0;
-
- /* zero the newly added memory, leave old data in */
- (void) memset(&newbuffer[sz], 0, newsz - sz);
-
- oldbuf = el->el_line.buffer;
-
- el->el_line.buffer = newbuffer;
- el->el_line.cursor = newbuffer + (el->el_line.cursor - oldbuf);
- el->el_line.lastchar = newbuffer + (el->el_line.lastchar - oldbuf);
- /* don't set new size until all buffers are enlarged */
- el->el_line.limit = &newbuffer[sz - EL_LEAVE];
-
- /*
- * Reallocate kill buffer.
- */
- newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz);
- if (!newbuffer)
- return 0;
-
- /* zero the newly added memory, leave old data in */
- (void) memset(&newbuffer[sz], 0, newsz - sz);
-
- oldkbuf = el->el_chared.c_kill.buf;
-
- el->el_chared.c_kill.buf = newbuffer;
- el->el_chared.c_kill.last = newbuffer +
- (el->el_chared.c_kill.last - oldkbuf);
- el->el_chared.c_kill.mark = el->el_line.buffer +
- (el->el_chared.c_kill.mark - oldbuf);
-
- /*
- * Reallocate undo buffer.
- */
- newbuffer = el_realloc(el->el_chared.c_undo.buf, newsz);
- if (!newbuffer)
- return 0;
-
- /* zero the newly added memory, leave old data in */
- (void) memset(&newbuffer[sz], 0, newsz - sz);
- el->el_chared.c_undo.buf = newbuffer;
-
- newbuffer = el_realloc(el->el_chared.c_redo.buf, newsz);
- if (!newbuffer)
- return 0;
- el->el_chared.c_redo.pos = newbuffer +
- (el->el_chared.c_redo.pos - el->el_chared.c_redo.buf);
- el->el_chared.c_redo.lim = newbuffer +
- (el->el_chared.c_redo.lim - el->el_chared.c_redo.buf);
- el->el_chared.c_redo.buf = newbuffer;
-
- if (!hist_enlargebuf(el, sz, newsz))
- return 0;
-
- /* Safe to set enlarged buffer size */
- el->el_line.limit = &el->el_line.buffer[newsz - EL_LEAVE];
- return 1;
-}
-
-/* ch_end():
- * Free the data structures used by the editor
- */
-protected void
-ch_end(EditLine *el)
-{
- el_free((ptr_t) el->el_line.buffer);
- el->el_line.buffer = NULL;
- el->el_line.limit = NULL;
- el_free((ptr_t) el->el_chared.c_undo.buf);
- el->el_chared.c_undo.buf = NULL;
- el_free((ptr_t) el->el_chared.c_redo.buf);
- el->el_chared.c_redo.buf = NULL;
- el->el_chared.c_redo.pos = NULL;
- el->el_chared.c_redo.lim = NULL;
- el->el_chared.c_redo.cmd = ED_UNASSIGNED;
- el_free((ptr_t) el->el_chared.c_kill.buf);
- el->el_chared.c_kill.buf = NULL;
- ch_reset(el, 1);
- el_free((ptr_t) el->el_chared.c_macro.macro);
- el->el_chared.c_macro.macro = NULL;
-}
-
-
-/* el_insertstr():
- * Insert string at cursorI
- */
-public int
-el_insertstr(EditLine *el, const char *s)
-{
- size_t len;
-
- if ((len = strlen(s)) == 0)
- return (-1);
- if (el->el_line.lastchar + len >= el->el_line.limit) {
- if (!ch_enlargebufs(el, len))
- return (-1);
- }
-
- c_insert(el, (int)len);
- while (*s)
- *el->el_line.cursor++ = *s++;
- return (0);
-}
-
-
-/* el_deletestr():
- * Delete num characters before the cursor
- */
-public void
-el_deletestr(EditLine *el, int n)
-{
- if (n <= 0)
- return;
-
- if (el->el_line.cursor < &el->el_line.buffer[n])
- return;
-
- c_delbefore(el, n); /* delete before dot */
- el->el_line.cursor -= n;
- if (el->el_line.cursor < el->el_line.buffer)
- el->el_line.cursor = el->el_line.buffer;
-}
-
-/* c_gets():
- * Get a string
- */
-protected int
-c_gets(EditLine *el, char *buf, const char *prompt)
-{
- char ch;
- int len;
- char *cp = el->el_line.buffer;
-
- if (prompt) {
- len = strlen(prompt);
- memcpy(cp, prompt, len + 0u);
- cp += len;
- }
- len = 0;
-
- for (;;) {
- el->el_line.cursor = cp;
- *cp = ' ';
- el->el_line.lastchar = cp + 1;
- re_refresh(el);
-
- if (el_getc(el, &ch) != 1) {
- ed_end_of_file(el, 0);
- len = -1;
- break;
- }
-
- switch (ch) {
-
- case 0010: /* Delete and backspace */
- case 0177:
- if (len <= 0) {
- len = -1;
- break;
- }
- cp--;
- continue;
-
- case 0033: /* ESC */
- case '\r': /* Newline */
- case '\n':
- buf[len] = ch;
- break;
-
- default:
- if (len >= EL_BUFSIZ - 16)
- term_beep(el);
- else {
- buf[len++] = ch;
- *cp++ = ch;
- }
- continue;
- }
- break;
- }
-
- el->el_line.buffer[0] = '\0';
- el->el_line.lastchar = el->el_line.buffer;
- el->el_line.cursor = el->el_line.buffer;
- return len;
-}
-
-
-/* c_hpos():
- * Return the current horizontal position of the cursor
- */
-protected int
-c_hpos(EditLine *el)
-{
- char *ptr;
-
- /*
- * Find how many characters till the beginning of this line.
- */
- if (el->el_line.cursor == el->el_line.buffer)
- return (0);
- else {
- for (ptr = el->el_line.cursor - 1;
- ptr >= el->el_line.buffer && *ptr != '\n';
- ptr--)
- continue;
- return (el->el_line.cursor - ptr - 1);
- }
-}
View
167 lib/libedit/chared.h
@@ -1,167 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * 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. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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.
- *
- * @(#)chared.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: chared.h,v 1.17 2006/03/06 21:11:56 christos Exp $
- * $DragonFly: src/lib/libedit/chared.h,v 1.5 2007/05/05 00:27:39 pavalos Exp $
- */
-
-/*
- * el.chared.h: Character editor interface
- */
-#ifndef _h_el_chared
-#define _h_el_chared
-
-#include <ctype.h>
-#include <string.h>
-
-#include "histedit.h"
-
-#define EL_MAXMACRO 10
-
-/*
- * This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works
- * 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
- * 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.
- */
-#define VI_MOVE
-
-
-typedef struct c_macro_t {
- int level;
- int offset;
- char **macro;
-} c_macro_t;
-
-/*
- * Undo information for vi - no undo in emacs (yet)
- */
-typedef struct c_undo_t {
- int len; /* length of saved line */
- int cursor; /* position of saved cursor */
- char *buf; /* full saved text */
-} c_undo_t;
-
-/* redo for vi */
-typedef struct c_redo_t {
- char *buf; /* redo insert key sequence */
- char *pos;
- char *lim;
- el_action_t cmd; /* command to redo */
- char ch; /* char that invoked it */
- int count;
- int action; /* from cv_action() */
-} c_redo_t;
-
-/*
- * Current action information for vi
- */
-typedef struct c_vcmd_t {
- int action;
- char *pos;
-} c_vcmd_t;
-
-/*
- * Kill buffer for emacs
- */
-typedef struct c_kill_t {
- char *buf;
- char *last;
- char *mark;
-} c_kill_t;
-
-/*
- * Note that we use both data structures because the user can bind
- * commands from both editors!
- */
-typedef struct el_chared_t {
- c_undo_t c_undo;
- c_kill_t c_kill;
- c_redo_t c_redo;
- c_vcmd_t c_vcmd;
- c_macro_t c_macro;
-} el_chared_t;
-
-
-#define STRQQ "\"\""
-
-#define isglob(a) (strchr("*[]?", (a)) != NULL)
-#define isword(a) (isprint(a))
-
-#define NOP 0x00
-#define DELETE 0x01
-#define INSERT 0x02
-#define YANK 0x04
-
-#define CHAR_FWD (+1)
-#define CHAR_BACK (-1)
-
-#define MODE_INSERT 0
-#define MODE_REPLACE 1
-#define MODE_REPLACE_1 2
-
-#include "common.h"
-#include "vi.h"
-#include "emacs.h"
-#include "search.h"
-#include "fcns.h"
-
-
-protected int cv__isword(int);
-protected int cv__isWord(int);
-protected void cv_delfini(EditLine *);
-protected char *cv__endword(char *, char *, int, int (*)(int));
-protected int ce__isword(int);
-protected void cv_undo(EditLine *);
-protected void cv_yank(EditLine *, const char *, int);
-protected char *cv_next_word(EditLine*, char *, char *, int, int (*)(int));
-protected char *cv_prev_word(char *, char *, int, int (*)(int));
-protected char *c__next_word(char *, char *, int, int (*)(int));
-protected char *c__prev_word(char *, char *, int, int (*)(int));
-protected void c_insert(EditLine *, int);
-protected void c_delbefore(EditLine *, int);
-protected void c_delbefore1(EditLine *);
-protected void c_delafter(EditLine *, int);
-protected void c_delafter1(EditLine *);
-protected int c_gets(EditLine *, char *, const char *);
-protected int c_hpos(EditLine *);
-
-protected int ch_init(EditLine *);
-protected void ch_reset(EditLine *, int);
-protected int ch_enlargebufs(EditLine *, size_t);
-protected void ch_end(EditLine *);
-
-#endif /* _h_el_chared */
View
916 lib/libedit/common.c
@@ -1,916 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * 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. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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.
- *
- * @(#)common.c 8.1 (Berkeley) 6/4/93
- * $NetBSD: common.c,v 1.19 2006/03/06 21:11:56 christos Exp $
- * $DragonFly: src/lib/libedit/common.c,v 1.6 2007/05/05 00:27:39 pavalos Exp $
- */
-
-#include "config.h"
-
-/*
- * common.c: Common Editor functions
- */
-#include "el.h"
-
-/* ed_end_of_file():
- * Indicate end of file
- * [^D]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_end_of_file(EditLine *el, int c __attribute__((__unused__)))
-{
-
- re_goto_bottom(el);
- *el->el_line.lastchar = '\0';
- return (CC_EOF);
-}
-
-
-/* ed_insert():
- * Add character to the line
- * Insert a character [bound to all insert keys]
- */
-protected el_action_t
-ed_insert(EditLine *el, int c)
-{
- int count = el->el_state.argument;
-
- if (c == '\0')
- return (CC_ERROR);
-
- if (el->el_line.lastchar + el->el_state.argument >=
- el->el_line.limit) {
- /* end of buffer space, try to allocate more */
- if (!ch_enlargebufs(el, (size_t) count))
- return CC_ERROR; /* error allocating more */
- }
-
- if (count == 1) {
- if (el->el_state.inputmode == MODE_INSERT
- || el->el_line.cursor >= el->el_line.lastchar)
- c_insert(el, 1);
-
- *el->el_line.cursor++ = c;
- re_fastaddc(el); /* fast refresh for one char. */
- } else {
- if (el->el_state.inputmode != MODE_REPLACE_1)
- c_insert(el, el->el_state.argument);
-
- while (count-- && el->el_line.cursor < el->el_line.lastchar)
- *el->el_line.cursor++ = c;
- re_refresh(el);
- }
-
- if (el->el_state.inputmode == MODE_REPLACE_1)
- return vi_command_mode(el, 0);
-
- return (CC_NORM);
-}
-
-
-/* ed_delete_prev_word():
- * Delete from beginning of current word to cursor
- * [M-^?] [^W]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_delete_prev_word(EditLine *el, int c __attribute__((__unused__)))
-{
- char *cp, *p, *kp;
-
- if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
-
- 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++)
- *kp++ = *p;
- el->el_chared.c_kill.last = kp;
-
- c_delbefore(el, el->el_line.cursor - cp); /* delete before dot */
- el->el_line.cursor = cp;
- if (el->el_line.cursor < el->el_line.buffer)
- el->el_line.cursor = el->el_line.buffer; /* bounds check */
- return (CC_REFRESH);
-}
-
-
-/* ed_delete_next_char():
- * Delete character under cursor
- * [^D] [x]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_delete_next_char(EditLine *el, int c)
-{
-#ifdef notdef /* XXX */
-#define EL el->el_line
- (void) fprintf(el->el_errlfile,
- "\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 I'm also at the beginning */
-#ifdef KSHVI
- return (CC_ERROR);
-#else
- /* then do an EOF */
- term_writechar(el, c);
- return (CC_EOF);
-#endif
- } else {
-#ifdef KSHVI
- el->el_line.cursor--;
-#else
- return (CC_ERROR);
-#endif
- }
- } else {
- if (el->el_line.cursor != el->el_line.buffer)
- el->el_line.cursor--;
- else
- return (CC_ERROR);
- }
- }
- c_delafter(el, el->el_state.argument); /* delete after dot */
- if (el->el_line.cursor >= el->el_line.lastchar &&
- el->el_line.cursor > el->el_line.buffer)
- /* bounds check */
- el->el_line.cursor = el->el_line.lastchar - 1;
- return (CC_REFRESH);
-}
-
-
-/* ed_kill_line():
- * Cut to the end of line
- * [^K] [^K]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_kill_line(EditLine *el, int c __attribute__((__unused__)))
-{
- char *kp, *cp;
-
- cp = el->el_line.cursor;
- kp = el->el_chared.c_kill.buf;
- while (cp < el->el_line.lastchar)
- *kp++ = *cp++; /* copy it */
- el->el_chared.c_kill.last = kp;
- /* zap! -- delete to end */
- el->el_line.lastchar = el->el_line.cursor;
- return (CC_REFRESH);
-}
-
-
-/* ed_move_to_end():
- * Move cursor to the end of line
- * [^E] [^E]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_move_to_end(EditLine *el, int c __attribute__((__unused__)))
-{
-
- el->el_line.cursor = el->el_line.lastchar;
- if (el->el_map.type == MAP_VI) {
-#ifdef VI_MOVE
- el->el_line.cursor--;
-#endif
- if (el->el_chared.c_vcmd.action != NOP) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- }
- return (CC_CURSOR);
-}
-
-
-/* ed_move_to_beg():
- * Move cursor to the beginning of line
- * [^A] [^A]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_move_to_beg(EditLine *el, int c __attribute__((__unused__)))
-{
-
- el->el_line.cursor = el->el_line.buffer;
-
- if (el->el_map.type == MAP_VI) {
- /* We want FIRST non space character */
- while (isspace((unsigned char) *el->el_line.cursor))
- el->el_line.cursor++;
- if (el->el_chared.c_vcmd.action != NOP) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- }
- return (CC_CURSOR);
-}
-
-
-/* ed_transpose_chars():
- * Exchange the character to the left of the cursor with the one under it
- * [^T] [^T]
- */
-protected el_action_t
-ed_transpose_chars(EditLine *el, int c)
-{
-
- if (el->el_line.cursor < el->el_line.lastchar) {
- if (el->el_line.lastchar <= &el->el_line.buffer[1])
- return (CC_ERROR);
- else
- el->el_line.cursor++;
- }
- if (el->el_line.cursor > &el->el_line.buffer[1]) {
- /* must have at least two chars entered */
- c = el->el_line.cursor[-2];
- el->el_line.cursor[-2] = el->el_line.cursor[-1];
- el->el_line.cursor[-1] = c;
- return (CC_REFRESH);
- } else
- return (CC_ERROR);
-}
-
-
-/* ed_next_char():
- * Move to the right one character
- * [^F] [^F]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_next_char(EditLine *el, int c __attribute__((__unused__)))
-{
- char *lim = el->el_line.lastchar;
-
- if (el->el_line.cursor >= lim ||
- (el->el_line.cursor == lim - 1 &&
- el->el_map.type == MAP_VI &&
- el->el_chared.c_vcmd.action == NOP))
- return (CC_ERROR);
-
- el->el_line.cursor += el->el_state.argument;
- if (el->el_line.cursor > lim)
- el->el_line.cursor = lim;
-
- if (el->el_map.type == MAP_VI)
- if (el->el_chared.c_vcmd.action != NOP) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
-}
-
-
-/* ed_prev_word():
- * Move to the beginning of the current word
- * [M-b] [b]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_prev_word(EditLine *el, int c __attribute__((__unused__)))
-{
-
- 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,
- ce__isword);
-
- if (el->el_map.type == MAP_VI)
- if (el->el_chared.c_vcmd.action != NOP) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
-}
-
-
-/* ed_prev_char():
- * Move to the left one character
- * [^B] [^B]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_prev_char(EditLine *el, int c __attribute__((__unused__)))
-{
-
- if (el->el_line.cursor > el->el_line.buffer) {
- 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;
-
- if (el->el_map.type == MAP_VI)
- if (el->el_chared.c_vcmd.action != NOP) {
- cv_delfini(el);
- return (CC_REFRESH);
- }
- return (CC_CURSOR);
- } else
- return (CC_ERROR);
-}
-
-
-/* ed_quoted_insert():
- * Add the next character typed verbatim
- * [^V] [^V]
- */
-protected el_action_t
-ed_quoted_insert(EditLine *el, int c)
-{
- int num;
- char tc;
-
- tty_quotemode(el);
- num = el_getc(el, &tc);
- c = (unsigned char) tc;
- tty_noquotemode(el);
- if (num == 1)
- return (ed_insert(el, c));
- else
- return (ed_end_of_file(el, 0));
-}
-
-
-/* ed_digit():
- * Adds to argument or enters a digit
- */
-protected el_action_t
-ed_digit(EditLine *el, int c)
-{
-
- if (!isdigit(c))
- return (CC_ERROR);
-
- if (el->el_state.doingarg) {
- /* if doing an arg, add this in... */
- 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 * 10) + (c - '0');
- }
- return (CC_ARGHACK);
- }
-
- return ed_insert(el, c);
-}
-
-
-/* ed_argument_digit():
- * Digit that starts argument
- * For ESC-n
- */
-protected el_action_t
-ed_argument_digit(EditLine *el, int c)
-{
-
- if (!isdigit(c))
- return (CC_ERROR);
-
- if (el->el_state.doingarg) {
- if (el->el_state.argument > 1000000)
- return (CC_ERROR);
- el->el_state.argument = (el->el_state.argument * 10) +
- (c - '0');
- } else { /* else starting an argument */
- el->el_state.argument = c - '0';
- el->el_state.doingarg = 1;
- }
- return (CC_ARGHACK);
-}
-
-
-/* ed_unassigned():
- * Indicates unbound character
- * Bound to keys that are not assigned
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_unassigned(EditLine *el, int c __attribute__((__unused__)))
-{
-
- return (CC_ERROR);
-}
-
-
-/**
- ** TTY key handling.
- **/
-
-/* ed_tty_sigint():
- * Tty interrupt character
- * [^C]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_sigint(EditLine *el __attribute__((__unused__)),
- int c __attribute__((__unused__)))
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_tty_dsusp():
- * Tty delayed suspend character
- * [^Y]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_dsusp(EditLine *el __attribute__((__unused__)),
- int c __attribute__((__unused__)))
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_tty_flush_output():
- * Tty flush output characters
- * [^O]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_flush_output(EditLine *el __attribute__((__unused__)),
- int c __attribute__((__unused__)))
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_tty_sigquit():
- * Tty quit character
- * [^\]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_sigquit(EditLine *el __attribute__((__unused__)),
- int c __attribute__((__unused__)))
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_tty_sigtstp():
- * Tty suspend character
- * [^Z]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_sigtstp(EditLine *el __attribute__((__unused__)),
- int c __attribute__((__unused__)))
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_tty_stop_output():
- * Tty disallow output characters
- * [^S]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_stop_output(EditLine *el __attribute__((__unused__)),
- int c __attribute__((__unused__)))
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_tty_start_output():
- * Tty allow output characters
- * [^Q]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_tty_start_output(EditLine *el __attribute__((__unused__)),
- int c __attribute__((__unused__)))
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_newline():
- * Execute command
- * [^J]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_newline(EditLine *el, int c __attribute__((__unused__)))
-{
-
- re_goto_bottom(el);
- *el->el_line.lastchar++ = '\n';
- *el->el_line.lastchar = '\0';
- return (CC_NEWLINE);
-}
-
-
-/* ed_delete_prev_char():
- * Delete the character to the left of the cursor
- * [^?]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_delete_prev_char(EditLine *el, int c __attribute__((__unused__)))
-{
-
- if (el->el_line.cursor <= el->el_line.buffer)
- return (CC_ERROR);
-
- 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;
- return (CC_REFRESH);
-}
-
-
-/* ed_clear_screen():
- * Clear screen leaving current line at the top
- * [^L]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_clear_screen(EditLine *el, int c __attribute__((__unused__)))
-{
-
- term_clear_screen(el); /* clear the whole real screen */
- re_clear_display(el); /* reset everything */
- return (CC_REFRESH);
-}
-
-
-/* ed_redisplay():
- * Redisplay everything
- * ^R
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_redisplay(EditLine *el __attribute__((__unused__)),
- int c __attribute__((__unused__)))
-{
-
- return (CC_REDISPLAY);
-}
-
-
-/* ed_start_over():
- * Erase current line and start from scratch
- * [^G]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_start_over(EditLine *el, int c __attribute__((__unused__)))
-{
-
- ch_reset(el, 0);
- return (CC_REFRESH);
-}
-
-
-/* ed_sequence_lead_in():
- * First character in a bound sequence
- * Placeholder for external keys
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_sequence_lead_in(EditLine *el __attribute__((__unused__)),
- int c __attribute__((__unused__)))
-{
-
- return (CC_NORM);
-}
-
-
-/* ed_prev_history():
- * Move to the previous history line
- * [^P] [k]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_prev_history(EditLine *el, int c __attribute__((__unused__)))
-{
- char beep = 0;
- int sv_event = el->el_history.eventno;
-
- el->el_chared.c_undo.len = -1;
- *el->el_line.lastchar = '\0'; /* just in case */
-
- if (el->el_history.eventno == 0) { /* save the current buffer
- * away */
- (void) strncpy(el->el_history.buf, el->el_line.buffer,
- EL_BUFSIZ);
- el->el_history.last = el->el_history.buf +
- (el->el_line.lastchar - el->el_line.buffer);
- }
- el->el_history.eventno += el->el_state.argument;
-
- if (hist_get(el) == CC_ERROR) {
- if (el->el_map.type == MAP_VI) {
- el->el_history.eventno = sv_event;
- return CC_ERROR;
- }
- beep = 1;
- /* el->el_history.eventno was fixed by first call */
- (void) hist_get(el);
- }
- if (beep)
- return CC_REFRESH_BEEP;
- return CC_REFRESH;
-}
-
-
-/* ed_next_history():
- * Move to the next history line
- * [^N] [j]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_next_history(EditLine *el, int c __attribute__((__unused__)))
-{
- el_action_t beep = CC_REFRESH, rval;
-
- el->el_chared.c_undo.len = -1;
- *el->el_line.lastchar = '\0'; /* just in case */
-
- el->el_history.eventno -= el->el_state.argument;
-
- if (el->el_history.eventno < 0) {
- el->el_history.eventno = 0;
- beep = CC_REFRESH_BEEP;
- }
- rval = hist_get(el);
- if (rval == CC_REFRESH)
- return beep;
- return rval;
-
-}
-
-
-/* ed_search_prev_history():
- * Search previous in history for a line matching the current
- * next search history [M-P] [K]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_search_prev_history(EditLine *el, int c __attribute__((__unused__)))
-{
- const char *hp;
- int h;
- bool_t found = 0;
-
- el->el_chared.c_vcmd.action = NOP;
- el->el_chared.c_undo.len = -1;
- *el->el_line.lastchar = '\0'; /* just in case */
- if (el->el_history.eventno < 0) {
-#ifdef DEBUG_EDIT
- (void) fprintf(el->el_errfile,
- "e_prev_search_hist(): eventno < 0;\n");
-#endif
- el->el_history.eventno = 0;
- return (CC_ERROR);
- }
- 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_line.lastchar - el->el_line.buffer);
- }
- if (el->el_history.ref == NULL)
- return (CC_ERROR);
-
- hp = HIST_FIRST(el);
- if (hp == NULL)
- return (CC_ERROR);
-
- c_setpat(el); /* Set search pattern !! */
-
- for (h = 1; h <= el->el_history.eventno; h++)
- hp = HIST_NEXT(el);
-
- while (hp != NULL) {
-#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
-#endif
- if ((strncmp(hp, el->el_line.buffer, (size_t)
- (el->el_line.lastchar - el->el_line.buffer)) ||
- hp[el->el_line.lastchar - el->el_line.buffer]) &&
- c_hmatch(el, hp)) {
- found++;
- break;
- }
- h++;
- hp = HIST_NEXT(el);
- }
-
- if (!found) {
-#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "not found\n");
-#endif
- return (CC_ERROR);
- }
- el->el_history.eventno = h;
-
- return (hist_get(el));
-}
-
-
-/* ed_search_next_history():
- * Search next in history for a line matching the current
- * [M-N] [J]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_search_next_history(EditLine *el, int c __attribute__((__unused__)))
-{
- const char *hp;
- int h;
- bool_t found = 0;
-
- el->el_chared.c_vcmd.action = NOP;
- el->el_chared.c_undo.len = -1;
- *el->el_line.lastchar = '\0'; /* just in case */
-
- if (el->el_history.eventno == 0)
- return (CC_ERROR);
-
- if (el->el_history.ref == NULL)
- return (CC_ERROR);
-
- hp = HIST_FIRST(el);
- if (hp == NULL)
- return (CC_ERROR);
-
- c_setpat(el); /* Set search pattern !! */
-
- for (h = 1; h < el->el_history.eventno && hp; h++) {
-#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
-#endif
- if ((strncmp(hp, el->el_line.buffer, (size_t)
- (el->el_line.lastchar - el->el_line.buffer)) ||
- hp[el->el_line.lastchar - el->el_line.buffer]) &&
- c_hmatch(el, hp))
- found = h;
- hp = HIST_NEXT(el);
- }
-
- 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");
-#endif
- return (CC_ERROR);
- }
- }
- el->el_history.eventno = found;
-
- return (hist_get(el));
-}
-
-
-/* ed_prev_line():
- * Move up one line
- * Could be [k] [^p]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_prev_line(EditLine *el, int c __attribute__((__unused__)))
-{
- char *ptr;
- int nchars = c_hpos(el);
-
- /*
- * Move to the line requested
- */
- if (*(ptr = el->el_line.cursor) == '\n')
- ptr--;
-
- for (; ptr >= el->el_line.buffer; ptr--)
- if (*ptr == '\n' && --el->el_state.argument <= 0)
- break;
-
- if (el->el_state.argument > 0)
- return (CC_ERROR);
-
- /*
- * Move to the beginning of the line
- */
- 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';
- ptr++)
- continue;
-
- el->el_line.cursor = ptr;
- return (CC_CURSOR);
-}
-
-
-/* ed_next_line():
- * Move down one line
- * Could be [j] [^n]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_next_line(EditLine *el, int c __attribute__((__unused__)))
-{
- char *ptr;
- int nchars = c_hpos(el);
-
- /*
- * Move to the line requested
- */
- for (ptr = el->el_line.cursor; ptr < el->el_line.lastchar; ptr++)
- if (*ptr == '\n' && --el->el_state.argument <= 0)
- break;
-
- if (el->el_state.argument > 0)
- return (CC_ERROR);
-
- /*
- * Move to the character requested
- */
- for (ptr++;
- nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
- ptr++)
- continue;
-
- el->el_line.cursor = ptr;
- return (CC_CURSOR);
-}
-
-
-/* ed_command():
- * Editline extended command
- * [M-X] [:]
- */
-protected el_action_t
-/*ARGSUSED*/
-ed_command(EditLine *el, int c __attribute__((__unused__)))
-{
- char tmpbuf[EL_BUFSIZ];
- int tmplen;
-
- tmplen = c_gets(el, tmpbuf, "\n: ");
- term__putc('\n');
-
- if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
- term_beep(el);
-
- el->el_map.current = el->el_map.key;
- re_clear_display(el);
- return CC_REFRESH;
-}
View
19 lib/libedit/config.h
@@ -1,19 +0,0 @@
-/* $DragonFly: src/lib/libedit/config.h,v 1.1 2005/11/13 11:58:30 corecode Exp $ */
-/* config.h. Generated automatically by configure. */
-/* #undef SUNOS */
-
-#define HAVE_SYS_CDEFS_H 1
-#define HAVE_TERMCAP_H 1
-#define HAVE_CURSES_H 1
-#define HAVE_NCURSES_H 1
-#define HAVE_TERM_H 1
-#define HAVE_VIS_H 1
-#define HAVE_ISSETUGID 1
-
-#define HAVE_STRLCAT 1
-#define HAVE_STRLCPY 1
-#define HAVE_FGETLN 1
-#define HAVE_STRVIS 1
-#define HAVE_STRUNVIS 1
-
-#include "sys.h"
View
576 lib/libedit/el.c
@@ -1,576 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas of Cornell University.
- *
- * 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. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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.
- *
- * @(#)el.c 8.2 (Berkeley) 1/3/94
- * $NetBSD: el.c,v 1.45 2008/04/05 15:53:28 christos Exp $
- * $DragonFly: src/lib/libedit/el.c,v 1.7 2008/05/17 22:48:04 pavalos Exp $
- */
-
-#include "config.h"
-
-/*
- * el.c: EditLine interface functions
- */
-#include <sys/types.h>
-#include <sys/param.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include "el.h"
-
-/* el_init():
- * Initialize editline and set default parameters.
- */
-public EditLine *
-el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
-{
-
- EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
-
- if (el == NULL)
- return (NULL);
-
- memset(el, 0, sizeof(EditLine));
-
- el->el_infile = fin;
- el->el_outfile = fout;
- el->el_errfile = ferr;
-
- el->el_infd = fileno(fin);
-
- if ((el->el_prog = el_strdup(prog)) == NULL) {
- el_free(el);
- return NULL;
- }
-
- /*
- * Initialize all the modules. Order is important!!!
- */
- el->el_flags = 0;
-
- if (term_init(el) == -1) {
- el_free(el->el_prog);
- el_free(el);
- return NULL;
- }
- (void) key_init(el);
- (void) map_init(el);
- if (tty_init(el) == -1)
- el->el_flags |= NO_TTY;
- (void) ch_init(el);
- (void) search_init(el);
- (void) hist_init(el);
- (void) prompt_init(el);
- (void) sig_init(el);
- (void) read_init(el);
-
- return (el);
-}
-
-
-/* el_end():
- * Clean up.
- */
-public void
-el_end(EditLine *el)
-{
-
- if (el == NULL)
- return;
-
- el_reset(el);
-
- term_end(el);
- key_end(el);
- map_end(el);
- tty_end(el);
- ch_end(el);
- search_end(el);
- hist_end(el);
- prompt_end(el);
- sig_end(el);
-
- el_free((ptr_t) el->el_prog);
- el_free((ptr_t) el);
-}
-
-
-/* el_reset():
- * Reset the tty and the parser
- */
-public void
-el_reset(EditLine *el)
-{
-
- tty_cookedmode(el);
- ch_reset(el, 0); /* XXX: Do we want that? */
-}
-
-
-/* el_set():
- * set the editline parameters
- */
-public int
-el_set(EditLine *el, int op, ...)
-{
- va_list ap;
- int rv = 0;
-
- if (el == NULL)
- return (-1);
- va_start(ap, op);
-
- switch (op) {
- case EL_PROMPT:
- case EL_RPROMPT:
- rv = prompt_set(el, va_arg(ap, el_pfunc_t), op);
- break;
-
- case EL_TERMINAL:
- rv = term_set(el, va_arg(ap, char *));
- break;
-
- case EL_EDITOR:
- rv = map_set_editor(el, va_arg(ap, char *));
- break;
-
- case EL_SIGNAL:
- if (va_arg(ap, int))
- el->el_flags |= HANDLE_SIGNALS;
- else
- el->el_flags &= ~HANDLE_SIGNALS;
- break;
-
- case EL_BIND:
- case EL_TELLTC:
- case EL_SETTC:
- case EL_GETTC:
- case EL_ECHOTC:
- case EL_SETTY:
- {
- const char *argv[20];
- int i;
-
- for (i = 1; i < 20; i++)
- if ((argv[i] = va_arg(ap, char *)) == NULL)
- break;
-
- switch (op) {
- case EL_BIND:
- argv[0] = "bind";
- rv = map_bind(el, i, argv);
- break;
-
- case EL_TELLTC:
- argv[0] = "telltc";
- rv = term_telltc(el, i, argv);
- break;
-
- case EL_SETTC:
- argv[0] = "settc";
- rv = term_settc(el, i, argv);
- break;
-
- case EL_ECHOTC:
- argv[0] = "echotc";
- rv = term_echotc(el, i, argv);
- break;
-
- case EL_SETTY:
- argv[0] = "setty";
- rv = tty_stty(el, i, argv);
- break;
-
- default:
- rv = -1;
- EL_ABORT((el->el_errfile, "Bad op %d\n", op));
- break;
- }
- break;
- }
-
- case EL_ADDFN:
- {
- char *name = va_arg(ap, char *);
- char *help = va_arg(ap, char *);
- el_func_t func = va_arg(ap, el_func_t);
-
- rv = map_addfunc(el, name, help, func);
- break;
- }
-
- case EL_HIST:
- {
- hist_fun_t func = va_arg(ap, hist_fun_t);
- ptr_t ptr = va_arg(ap, char *);
-
- rv = hist_set(el, func, ptr);
- break;
- }
-
- case EL_EDITMODE:
- if (va_arg(ap, int))
- el->el_flags &= ~EDIT_DISABLED;
- else
- el->el_flags |= EDIT_DISABLED;
- rv = 0;
- break;
-
- case EL_GETCFN:
- {
- el_rfunc_t rc = va_arg(ap, el_rfunc_t);