Loading .bzrignore +1 −1 Original line number Diff line number Diff line Loading @@ -258,7 +258,7 @@ cmd-line-utils/libedit/common.h cmd-line-utils/libedit/makelist comon.h config.cache config.h ./config.h config.h.in config.log config.status Loading cmd-line-utils/libedit/Makefile.am +17 −17 Original line number Diff line number Diff line Loading @@ -7,28 +7,30 @@ AHDR=vi.h emacs.h common.h INCLUDES = -I$(top_srcdir)/include -I$(srcdir)/../.. -I.. noinst_LIBRARIES = liblibedit.a noinst_LIBRARIES = libedit.a liblibedit_a_SOURCES = chared.c el.c fgetln.c history.c map.c \ prompt.c readline.c search.c \ strlcpy.c tokenizer.c vi.c common.c \ emacs.c hist.c key.c parse.c read.c \ refresh.c sig.c term.c tty.c help.c \ fcns.c libedit_a_SOURCES = chared.c el.c history.c map.c prompt.c readline.c \ search.c tokenizer.c vi.c common.c emacs.c \ hist.c key.c parse.c read.c refresh.c sig.c term.c \ tty.c help.c fcns.c EXTRA_libedit_a_SOURCES = np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c \ np/fgetln.c libedit_a_LIBADD = @LIBEDIT_LOBJECTS@ libedit_a_DEPENDENCIES = @LIBEDIT_LOBJECTS@ pkginclude_HEADERS = readline/readline.h noinst_HEADERS = chared.h el.h histedit.h key.h \ parse.h refresh.h sig.h sys.h \ tokenizer.h compat.h compat_conf.h fgetln.h \ hist.h map.h prompt.h search.h \ strlcpy.h libedit_term.h tty.h noinst_HEADERS = chared.h el.h histedit.h key.h parse.h refresh.h sig.h \ sys.h tokenizer.h config.h hist.h map.h prompt.h \ search.h tty.h EXTRA_DIST = makelist.sh EXTRA_DIST = makelist.sh np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c np/fgetln.c CLEANFILES = makelist CLEANFILES = makelist common.h emacs.h vi.h fcns.h help.h fcns.c help.c DEFS = -DUNDEF_THREADS_HACK -DHAVE_CONFIG_H -DNO_KILL_INTR DEFS = -DUNDEF_THREADS_HACK -DHAVE_CONFIG_H -DNO_KILL_INTR '-D__RCSID(x)=' '-D__COPYRIGHT(x)=' '-D__RENAME(x)=' '-D_DIAGASSERT(x)=' SUFFIXES = .sh Loading Loading @@ -73,13 +75,11 @@ fcns.c: ${AHDR} fcns.h makelist chared.o: vi.h emacs.h common.h help.h fcns.h el.o: vi.h emacs.h common.h help.h fcns.h fgetln.o: vi.h emacs.h common.h help.h fcns.h history.o: vi.h emacs.h common.h help.h fcns.h map.o: vi.h emacs.h common.h help.h fcns.h prompt.o: vi.h emacs.h common.h help.h fcns.h readline.o: vi.h emacs.h common.h help.h fcns.h search.o: vi.h emacs.h common.h help.h fcns.h strlcpy.o: vi.h emacs.h common.h help.h fcns.h tokenizer.o: vi.h emacs.h common.h help.h fcns.h vi.o: vi.h emacs.h common.h help.h fcns.h common.o: vi.h emacs.h common.h help.h fcns.h Loading cmd-line-utils/libedit/chared.c +165 −117 Original line number Diff line number Diff line /* $NetBSD: chared.c,v 1.14 2001/05/17 01:02:17 christos Exp $ */ /* $NetBSD: chared.c,v 1.18 2002/11/20 16:50:08 christos Exp $ */ /*- * Copyright (c) 1992, 1993 Loading Loading @@ -36,13 +36,18 @@ * SUCH DAMAGE. */ #include "compat.h" #include "config.h" #if !defined(lint) && !defined(SCCSID) #if 0 static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93"; #else __RCSID("$NetBSD: chared.c,v 1.18 2002/11/20 16:50:08 christos Exp $"); #endif #endif /* not lint && not SCCSID */ /* * chared.c: Character editor utilities */ #include "sys.h" #include <stdlib.h> #include "el.h" Loading @@ -53,17 +58,36 @@ * Handle state for the vi undo command */ protected void cv_undo(EditLine *el,int action, size_t size, char *ptr) cv_undo(EditLine *el) { c_undo_t *vu = &el->el_chared.c_undo; vu->action = action; vu->ptr = ptr; vu->isize = size; (void) memcpy(vu->buf, vu->ptr, size); #ifdef DEBUG_UNDO (void) fprintf(el->el_errfile, "Undo buffer \"%s\" size = +%d -%d\n", vu->ptr, vu->isize, vu->dsize); #endif c_redo_t *r = &el->el_chared.c_redo; uint 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; } Loading @@ -75,8 +99,10 @@ c_insert(EditLine *el, int num) { char *cp; if (el->el_line.lastchar + num >= el->el_line.limit) 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 */ Loading @@ -97,12 +123,14 @@ 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; if (el->el_map.current != el->el_map.emacs) cv_undo(el, INSERT, (size_t)num, el->el_line.cursor); for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++) *cp = cp[num]; Loading @@ -121,13 +149,14 @@ 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; if (el->el_map.current != el->el_map.emacs) cv_undo(el, INSERT, (size_t)num, el->el_line.cursor - num); for (cp = el->el_line.cursor - num; cp <= el->el_line.lastchar; cp++) Loading @@ -144,7 +173,7 @@ c_delbefore(EditLine *el, int num) protected int ce__isword(int p) { return (isalpha(p) || isdigit(p) || strchr("*?_-.[]~=", p) != NULL); return (isalnum(p) || strchr("*?_-.[]~=", p) != NULL); } Loading @@ -153,6 +182,20 @@ ce__isword(int p) */ 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)); } Loading Loading @@ -216,7 +259,7 @@ cv_next_word(EditLine *el, char *p, char *high, int n, int (*wtest)(int)) * 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)) if (n || el->el_chared.c_vcmd.action != (DELETE|INSERT)) while ((p < high) && isspace((unsigned char) *p)) p++; } Loading @@ -233,26 +276,19 @@ cv_next_word(EditLine *el, char *p, char *high, int n, int (*wtest)(int)) * Find the previous word vi style */ protected char * cv_prev_word(EditLine *el, char *p, char *low, int n, int (*wtest)(int)) cv_prev_word(char *p, char *low, int n, int (*wtest)(int)) { int test; while (n--) { p--; /* * 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 (n--) { while ((p > low) && isspace((unsigned char) *p)) p--; test = (*wtest)((unsigned char) *p); while ((p >= low) && (*wtest)((unsigned char) *p) == test) p--; p++; while (isspace((unsigned char) *p)) p++; } p++; /* p now points where we want it */ if (p < low) Loading Loading @@ -303,47 +339,34 @@ protected void cv_delfini(EditLine *el) { int size; int oaction; int action = el->el_chared.c_vcmd.action; if (el->el_chared.c_vcmd.action & INSERT) if (action & INSERT) el->el_map.current = el->el_map.key; oaction = el->el_chared.c_vcmd.action; el->el_chared.c_vcmd.action = NOP; if (el->el_chared.c_vcmd.pos == 0) /* sanity */ 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); 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; re_refresh_cursor(el); } else if (el->el_line.cursor < el->el_chared.c_vcmd.pos) { size = (int)(el->el_chared.c_vcmd.pos - el->el_line.cursor); c_delafter(el, size); 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 { size = 1; if (size > 0) { c_delafter(el, size); re_refresh_cursor(el); } else { c_delbefore(el, -size); el->el_line.cursor += size; } switch (oaction) { case DELETE|INSERT: el->el_chared.c_undo.action = DELETE|INSERT; break; case DELETE: el->el_chared.c_undo.action = INSERT; break; case NOP: case INSERT: default: EL_ABORT((el->el_errfile, "Bad oaction %d\n", oaction)); break; } el->el_chared.c_undo.ptr = el->el_line.cursor; el->el_chared.c_undo.dsize = size; el->el_chared.c_vcmd.action = NOP; } Loading Loading @@ -373,20 +396,18 @@ ce__endword(char *p, char *high, int n) * Go to the end of this word according to vi */ protected char * cv__endword(char *p, char *high, int n) cv__endword(char *p, char *high, int n, int (*wtest)(int)) { int test; p++; while (n--) { while ((p < high) && isspace((unsigned char) *p)) p++; if (isalnum((unsigned char) *p)) while ((p < high) && isalnum((unsigned char) *p)) p++; else while ((p < high) && !(isspace((unsigned char) *p) || isalnum((unsigned char) *p))) test = (*wtest)((unsigned char) *p); while ((p < high) && (*wtest)((unsigned char) *p) == test) p++; } p--; Loading @@ -406,20 +427,23 @@ ch_init(EditLine *el) (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 - 2]; 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.action = NOP; el->el_chared.c_undo.isize = 0; el->el_chared.c_undo.dsize = 0; el->el_chared.c_undo.ptr = el->el_line.buffer; 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_vcmd.ins = el->el_line.buffer; el->el_chared.c_kill.buf = (char *) el_malloc(EL_BUFSIZ); if (el->el_chared.c_kill.buf == NULL) Loading Loading @@ -454,14 +478,11 @@ ch_reset(EditLine *el) el->el_line.cursor = el->el_line.buffer; el->el_line.lastchar = el->el_line.buffer; el->el_chared.c_undo.action = NOP; el->el_chared.c_undo.isize = 0; el->el_chared.c_undo.dsize = 0; el->el_chared.c_undo.ptr = 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_vcmd.ins = el->el_line.buffer; el->el_chared.c_kill.mark = el->el_line.buffer; Loading Loading @@ -516,7 +537,8 @@ ch_enlargebufs(el, addlen) 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); el->el_line.limit = &newbuffer[newsz - EL_LEAVE]; /* don't set new size until all buffers are enlarged */ el->el_line.limit = &newbuffer[sz - EL_LEAVE]; /* * Reallocate kill buffer. Loading Loading @@ -545,14 +567,22 @@ ch_enlargebufs(el, addlen) /* zero the newly added memory, leave old data in */ (void) memset(&newbuffer[sz], 0, newsz - sz); el->el_chared.c_undo.ptr = el->el_line.buffer + (el->el_chared.c_undo.ptr - oldbuf); 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 = &newbuffer[newsz - EL_LEAVE]; return 1; } Loading @@ -567,6 +597,11 @@ ch_end(EditLine *el) 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; el_free((ptr_t) el->el_chared.c_macro.macro); Loading Loading @@ -619,51 +654,64 @@ el_deletestr(EditLine *el, int n) * Get a string */ protected int c_gets(EditLine *el, char *buf) c_gets(EditLine *el, char *buf, const char *prompt) { char ch; int len = 0; int len; char *cp = el->el_line.buffer; if (prompt) { len = strlen(prompt); memcpy(cp, prompt, len + 0u); cp += len; } len = 0; for (;;) { el->el_line.cursor = cp; *cp = ' '; el->el_line.lastchar = cp + 1; re_refresh(el); if (el_getc(el, &ch) != 1) { ed_end_of_file(el, 0); len = -1; break; } for (ch = 0; ch == 0;) { if (el_getc(el, &ch) != 1) return (ed_end_of_file(el, 0)); switch (ch) { case 0010: /* Delete and backspace */ case 0177: if (len > 1) { *el->el_line.cursor-- = '\0'; el->el_line.lastchar = el->el_line.cursor; buf[len--] = '\0'; } else { el->el_line.buffer[0] = '\0'; el->el_line.lastchar = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer; return (CC_REFRESH); } re_refresh(el); ch = 0; 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) if (len >= EL_BUFSIZ - 16) term_beep(el); else { buf[len++] = ch; *el->el_line.cursor++ = ch; el->el_line.lastchar = el->el_line.cursor; *cp++ = ch; } re_refresh(el); ch = 0; break; continue; } break; } buf[len] = ch; return (len); el->el_line.buffer[0] = '\0'; el->el_line.lastchar = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer; return len; } Loading cmd-line-utils/libedit/chared.h +27 −16 Original line number Diff line number Diff line /* $NetBSD: chared.h,v 1.6 2001/01/10 07:45:41 jdolecek Exp $ */ /* $NetBSD: chared.h,v 1.11 2002/11/20 16:50:08 christos Exp $ */ /*- * Copyright (c) 1992, 1993 Loading Loading @@ -71,23 +71,31 @@ typedef struct c_macro_t { } c_macro_t; /* * Undo information for both vi and emacs * Undo information for vi - no undo in emacs (yet) */ typedef struct c_undo_t { int action; size_t isize; size_t dsize; char *ptr; char *buf; 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; char *ins; } c_vcmd_t; /* Loading @@ -106,6 +114,7 @@ typedef struct c_kill_t { 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; Loading @@ -120,10 +129,10 @@ typedef struct el_chared_t { #define NOP 0x00 #define DELETE 0x01 #define INSERT 0x02 #define CHANGE 0x04 #define YANK 0x04 #define CHAR_FWD 0 #define CHAR_BACK 1 #define CHAR_FWD (+1) #define CHAR_BACK (-1) #define MODE_INSERT 0 #define MODE_REPLACE 1 Loading @@ -137,23 +146,25 @@ typedef struct el_chared_t { protected int cv__isword(int); protected int cv__isWord(int); protected void cv_delfini(EditLine *); protected char *cv__endword(char *, char *, int); protected char *cv__endword(char *, char *, int, int (*)(int)); protected int ce__isword(int); protected void cv_undo(EditLine *, int, size_t, char *); 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(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_delafter(EditLine *, int); protected int c_gets(EditLine *, char *); protected int c_gets(EditLine *, char *, const char *); protected int c_hpos(EditLine *); protected int ch_init(EditLine *); protected void ch_reset(EditLine *); protected int ch_enlargebufs __P((EditLine *, size_t)); protected int ch_enlargebufs(EditLine *, size_t); protected void ch_end(EditLine *); #endif /* _h_el_chared */ cmd-line-utils/libedit/common.c +69 −96 Original line number Diff line number Diff line /* $NetBSD: common.c,v 1.10 2001/01/10 07:45:41 jdolecek Exp $ */ /* $NetBSD: common.c,v 1.14 2002/11/20 16:50:08 christos Exp $ */ /*- * Copyright (c) 1992, 1993 Loading Loading @@ -36,12 +36,18 @@ * SUCH DAMAGE. */ #include "compat.h" #include "config.h" #if !defined(lint) && !defined(SCCSID) #if 0 static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93"; #else __RCSID("$NetBSD: common.c,v 1.14 2002/11/20 16:50:08 christos Exp $"); #endif #endif /* not lint && not SCCSID */ /* * common.c: Common Editor functions */ #include "sys.h" #include "el.h" /* ed_end_of_file(): Loading @@ -66,7 +72,7 @@ ed_end_of_file(EditLine *el, int c __attribute__((unused))) protected el_action_t ed_insert(EditLine *el, int c) { int i; int count = el->el_state.argument; if (c == '\0') return (CC_ERROR); Loading @@ -74,42 +80,28 @@ ed_insert(EditLine *el, int c) if (el->el_line.lastchar + el->el_state.argument >= el->el_line.limit) { /* end of buffer space, try to allocate more */ if (!ch_enlargebufs(el, (size_t) el->el_state.argument)) if (!ch_enlargebufs(el, (size_t) count)) return CC_ERROR; /* error allocating more */ } if (el->el_state.argument == 1) { if (el->el_state.inputmode != MODE_INSERT) { el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] = *el->el_line.cursor; el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] = '\0'; c_delafter(el, 1); } if (count == 1) { if (el->el_state.inputmode == MODE_INSERT || el->el_line.cursor >= el->el_line.lastchar) c_insert(el, 1); *el->el_line.cursor++ = c; el->el_state.doingarg = 0; /* just in case */ re_fastaddc(el); /* fast refresh for one char. */ } else { if (el->el_state.inputmode != MODE_INSERT) { for (i = 0; i < el->el_state.argument; i++) el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] = el->el_line.cursor[i]; el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] = '\0'; c_delafter(el, el->el_state.argument); } if (el->el_state.inputmode != MODE_REPLACE_1) c_insert(el, el->el_state.argument); while (el->el_state.argument--) while (count-- && el->el_line.cursor < el->el_line.lastchar) *el->el_line.cursor++ = c; re_refresh(el); } if (el->el_state.inputmode == MODE_REPLACE_1) (void) vi_command_mode(el, 0); return vi_command_mode(el, 0); return (CC_NORM); } Loading Loading @@ -229,7 +221,7 @@ ed_move_to_end(EditLine *el, int c __attribute__((unused))) #ifdef VI_MOVE el->el_line.cursor--; #endif if (el->el_chared.c_vcmd.action & DELETE) { if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } Loading @@ -253,7 +245,7 @@ ed_move_to_beg(EditLine *el, int c __attribute__((unused))) /* We want FIRST non space character */ while (isspace((unsigned char) *el->el_line.cursor)) el->el_line.cursor++; if (el->el_chared.c_vcmd.action & DELETE) { if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } Loading Loading @@ -295,16 +287,20 @@ 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 >= el->el_line.lastchar) if (el->el_line.cursor >= lim || (el->el_line.cursor == lim - 1 && el->el_map.type == MAP_VI && el->el_chared.c_vcmd.action == NOP)) return (CC_ERROR); el->el_line.cursor += el->el_state.argument; if (el->el_line.cursor > el->el_line.lastchar) el->el_line.cursor = el->el_line.lastchar; if (el->el_line.cursor > lim) el->el_line.cursor = lim; if (el->el_map.type == MAP_VI) if (el->el_chared.c_vcmd.action & DELETE) { if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } Loading @@ -330,7 +326,7 @@ ed_prev_word(EditLine *el, int c __attribute__((unused))) ce__isword); if (el->el_map.type == MAP_VI) if (el->el_chared.c_vcmd.action & DELETE) { if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } Loading @@ -353,7 +349,7 @@ ed_prev_char(EditLine *el, int c __attribute__((unused))) el->el_line.cursor = el->el_line.buffer; if (el->el_map.type == MAP_VI) if (el->el_chared.c_vcmd.action & DELETE) { if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } Loading Loading @@ -405,25 +401,9 @@ ed_digit(EditLine *el, int c) (el->el_state.argument * 10) + (c - '0'); } return (CC_ARGHACK); } else { if (el->el_line.lastchar + 1 >= el->el_line.limit) { if (!ch_enlargebufs(el, 1)) return (CC_ERROR); } if (el->el_state.inputmode != MODE_INSERT) { el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] = *el->el_line.cursor; el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] = '\0'; c_delafter(el, 1); } c_insert(el, 1); *el->el_line.cursor++ = c; el->el_state.doingarg = 0; re_fastaddc(el); } return (CC_NORM); return ed_insert(el, c); } Loading Loading @@ -457,12 +437,11 @@ ed_argument_digit(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ ed_unassigned(EditLine *el, int c __attribute__((unused))) ed_unassigned(EditLine *el __attribute__((unused)), int c __attribute__((unused))) { term_beep(el); term__flush(); return (CC_NORM); return (CC_ERROR); } Loading Loading @@ -580,8 +559,6 @@ ed_newline(EditLine *el, int c __attribute__((unused))) re_goto_bottom(el); *el->el_line.lastchar++ = '\n'; *el->el_line.lastchar = '\0'; if (el->el_map.type == MAP_VI) el->el_chared.c_vcmd.ins = el->el_line.buffer; return (CC_NEWLINE); } Loading Loading @@ -672,8 +649,9 @@ protected el_action_t ed_prev_history(EditLine *el, int c __attribute__((unused))) { char beep = 0; int sv_event = el->el_history.eventno; el->el_chared.c_undo.action = NOP; el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ if (el->el_history.eventno == 0) { /* save the current buffer Loading @@ -686,15 +664,17 @@ ed_prev_history(EditLine *el, int c __attribute__((unused))) el->el_history.eventno += el->el_state.argument; if (hist_get(el) == CC_ERROR) { if (el->el_map.type == MAP_VI) { el->el_history.eventno = sv_event; return CC_ERROR; } beep = 1; /* el->el_history.eventno was fixed by first call */ (void) hist_get(el); } re_refresh(el); if (beep) return (CC_ERROR); else return (CC_NORM); /* was CC_UP_HIST */ return CC_REFRESH_BEEP; return CC_REFRESH; } Loading @@ -706,17 +686,22 @@ 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.action = NOP; el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ el->el_history.eventno -= el->el_state.argument; if (el->el_history.eventno < 0) { el->el_history.eventno = 0; return (CC_ERROR);/* make it beep */ beep = CC_REFRESH_BEEP; } return (hist_get(el)); rval = hist_get(el); if (rval == CC_REFRESH) return beep; return rval; } Loading @@ -733,7 +718,7 @@ ed_search_prev_history(EditLine *el, int c __attribute__((unused))) bool_t found = 0; el->el_chared.c_vcmd.action = NOP; el->el_chared.c_undo.action = NOP; el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ if (el->el_history.eventno < 0) { #ifdef DEBUG_EDIT Loading Loading @@ -801,7 +786,7 @@ ed_search_next_history(EditLine *el, int c __attribute__((unused))) bool_t found = 0; el->el_chared.c_vcmd.action = NOP; el->el_chared.c_undo.action = NOP; el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ if (el->el_history.eventno == 0) Loading Loading @@ -930,25 +915,13 @@ ed_command(EditLine *el, int c __attribute__((unused))) char tmpbuf[EL_BUFSIZ]; int tmplen; el->el_line.buffer[0] = '\0'; el->el_line.lastchar = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer; tmplen = c_gets(el, tmpbuf, "\n: "); term__putc('\n'); c_insert(el, 3); /* prompt + ": " */ *el->el_line.cursor++ = '\n'; *el->el_line.cursor++ = ':'; *el->el_line.cursor++ = ' '; re_refresh(el); tmplen = c_gets(el, tmpbuf); tmpbuf[tmplen] = '\0'; el->el_line.buffer[0] = '\0'; el->el_line.lastchar = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer; if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1) term_beep(el); if (parse_line(el, tmpbuf) == -1) return (CC_ERROR); else return (CC_REFRESH); el->el_map.current = el->el_map.key; re_clear_display(el); return CC_REFRESH; } Loading
.bzrignore +1 −1 Original line number Diff line number Diff line Loading @@ -258,7 +258,7 @@ cmd-line-utils/libedit/common.h cmd-line-utils/libedit/makelist comon.h config.cache config.h ./config.h config.h.in config.log config.status Loading
cmd-line-utils/libedit/Makefile.am +17 −17 Original line number Diff line number Diff line Loading @@ -7,28 +7,30 @@ AHDR=vi.h emacs.h common.h INCLUDES = -I$(top_srcdir)/include -I$(srcdir)/../.. -I.. noinst_LIBRARIES = liblibedit.a noinst_LIBRARIES = libedit.a liblibedit_a_SOURCES = chared.c el.c fgetln.c history.c map.c \ prompt.c readline.c search.c \ strlcpy.c tokenizer.c vi.c common.c \ emacs.c hist.c key.c parse.c read.c \ refresh.c sig.c term.c tty.c help.c \ fcns.c libedit_a_SOURCES = chared.c el.c history.c map.c prompt.c readline.c \ search.c tokenizer.c vi.c common.c emacs.c \ hist.c key.c parse.c read.c refresh.c sig.c term.c \ tty.c help.c fcns.c EXTRA_libedit_a_SOURCES = np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c \ np/fgetln.c libedit_a_LIBADD = @LIBEDIT_LOBJECTS@ libedit_a_DEPENDENCIES = @LIBEDIT_LOBJECTS@ pkginclude_HEADERS = readline/readline.h noinst_HEADERS = chared.h el.h histedit.h key.h \ parse.h refresh.h sig.h sys.h \ tokenizer.h compat.h compat_conf.h fgetln.h \ hist.h map.h prompt.h search.h \ strlcpy.h libedit_term.h tty.h noinst_HEADERS = chared.h el.h histedit.h key.h parse.h refresh.h sig.h \ sys.h tokenizer.h config.h hist.h map.h prompt.h \ search.h tty.h EXTRA_DIST = makelist.sh EXTRA_DIST = makelist.sh np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c np/fgetln.c CLEANFILES = makelist CLEANFILES = makelist common.h emacs.h vi.h fcns.h help.h fcns.c help.c DEFS = -DUNDEF_THREADS_HACK -DHAVE_CONFIG_H -DNO_KILL_INTR DEFS = -DUNDEF_THREADS_HACK -DHAVE_CONFIG_H -DNO_KILL_INTR '-D__RCSID(x)=' '-D__COPYRIGHT(x)=' '-D__RENAME(x)=' '-D_DIAGASSERT(x)=' SUFFIXES = .sh Loading Loading @@ -73,13 +75,11 @@ fcns.c: ${AHDR} fcns.h makelist chared.o: vi.h emacs.h common.h help.h fcns.h el.o: vi.h emacs.h common.h help.h fcns.h fgetln.o: vi.h emacs.h common.h help.h fcns.h history.o: vi.h emacs.h common.h help.h fcns.h map.o: vi.h emacs.h common.h help.h fcns.h prompt.o: vi.h emacs.h common.h help.h fcns.h readline.o: vi.h emacs.h common.h help.h fcns.h search.o: vi.h emacs.h common.h help.h fcns.h strlcpy.o: vi.h emacs.h common.h help.h fcns.h tokenizer.o: vi.h emacs.h common.h help.h fcns.h vi.o: vi.h emacs.h common.h help.h fcns.h common.o: vi.h emacs.h common.h help.h fcns.h Loading
cmd-line-utils/libedit/chared.c +165 −117 Original line number Diff line number Diff line /* $NetBSD: chared.c,v 1.14 2001/05/17 01:02:17 christos Exp $ */ /* $NetBSD: chared.c,v 1.18 2002/11/20 16:50:08 christos Exp $ */ /*- * Copyright (c) 1992, 1993 Loading Loading @@ -36,13 +36,18 @@ * SUCH DAMAGE. */ #include "compat.h" #include "config.h" #if !defined(lint) && !defined(SCCSID) #if 0 static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93"; #else __RCSID("$NetBSD: chared.c,v 1.18 2002/11/20 16:50:08 christos Exp $"); #endif #endif /* not lint && not SCCSID */ /* * chared.c: Character editor utilities */ #include "sys.h" #include <stdlib.h> #include "el.h" Loading @@ -53,17 +58,36 @@ * Handle state for the vi undo command */ protected void cv_undo(EditLine *el,int action, size_t size, char *ptr) cv_undo(EditLine *el) { c_undo_t *vu = &el->el_chared.c_undo; vu->action = action; vu->ptr = ptr; vu->isize = size; (void) memcpy(vu->buf, vu->ptr, size); #ifdef DEBUG_UNDO (void) fprintf(el->el_errfile, "Undo buffer \"%s\" size = +%d -%d\n", vu->ptr, vu->isize, vu->dsize); #endif c_redo_t *r = &el->el_chared.c_redo; uint 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; } Loading @@ -75,8 +99,10 @@ c_insert(EditLine *el, int num) { char *cp; if (el->el_line.lastchar + num >= el->el_line.limit) 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 */ Loading @@ -97,12 +123,14 @@ 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; if (el->el_map.current != el->el_map.emacs) cv_undo(el, INSERT, (size_t)num, el->el_line.cursor); for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++) *cp = cp[num]; Loading @@ -121,13 +149,14 @@ 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; if (el->el_map.current != el->el_map.emacs) cv_undo(el, INSERT, (size_t)num, el->el_line.cursor - num); for (cp = el->el_line.cursor - num; cp <= el->el_line.lastchar; cp++) Loading @@ -144,7 +173,7 @@ c_delbefore(EditLine *el, int num) protected int ce__isword(int p) { return (isalpha(p) || isdigit(p) || strchr("*?_-.[]~=", p) != NULL); return (isalnum(p) || strchr("*?_-.[]~=", p) != NULL); } Loading @@ -153,6 +182,20 @@ ce__isword(int p) */ 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)); } Loading Loading @@ -216,7 +259,7 @@ cv_next_word(EditLine *el, char *p, char *high, int n, int (*wtest)(int)) * 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)) if (n || el->el_chared.c_vcmd.action != (DELETE|INSERT)) while ((p < high) && isspace((unsigned char) *p)) p++; } Loading @@ -233,26 +276,19 @@ cv_next_word(EditLine *el, char *p, char *high, int n, int (*wtest)(int)) * Find the previous word vi style */ protected char * cv_prev_word(EditLine *el, char *p, char *low, int n, int (*wtest)(int)) cv_prev_word(char *p, char *low, int n, int (*wtest)(int)) { int test; while (n--) { p--; /* * 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 (n--) { while ((p > low) && isspace((unsigned char) *p)) p--; test = (*wtest)((unsigned char) *p); while ((p >= low) && (*wtest)((unsigned char) *p) == test) p--; p++; while (isspace((unsigned char) *p)) p++; } p++; /* p now points where we want it */ if (p < low) Loading Loading @@ -303,47 +339,34 @@ protected void cv_delfini(EditLine *el) { int size; int oaction; int action = el->el_chared.c_vcmd.action; if (el->el_chared.c_vcmd.action & INSERT) if (action & INSERT) el->el_map.current = el->el_map.key; oaction = el->el_chared.c_vcmd.action; el->el_chared.c_vcmd.action = NOP; if (el->el_chared.c_vcmd.pos == 0) /* sanity */ 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); 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; re_refresh_cursor(el); } else if (el->el_line.cursor < el->el_chared.c_vcmd.pos) { size = (int)(el->el_chared.c_vcmd.pos - el->el_line.cursor); c_delafter(el, size); 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 { size = 1; if (size > 0) { c_delafter(el, size); re_refresh_cursor(el); } else { c_delbefore(el, -size); el->el_line.cursor += size; } switch (oaction) { case DELETE|INSERT: el->el_chared.c_undo.action = DELETE|INSERT; break; case DELETE: el->el_chared.c_undo.action = INSERT; break; case NOP: case INSERT: default: EL_ABORT((el->el_errfile, "Bad oaction %d\n", oaction)); break; } el->el_chared.c_undo.ptr = el->el_line.cursor; el->el_chared.c_undo.dsize = size; el->el_chared.c_vcmd.action = NOP; } Loading Loading @@ -373,20 +396,18 @@ ce__endword(char *p, char *high, int n) * Go to the end of this word according to vi */ protected char * cv__endword(char *p, char *high, int n) cv__endword(char *p, char *high, int n, int (*wtest)(int)) { int test; p++; while (n--) { while ((p < high) && isspace((unsigned char) *p)) p++; if (isalnum((unsigned char) *p)) while ((p < high) && isalnum((unsigned char) *p)) p++; else while ((p < high) && !(isspace((unsigned char) *p) || isalnum((unsigned char) *p))) test = (*wtest)((unsigned char) *p); while ((p < high) && (*wtest)((unsigned char) *p) == test) p++; } p--; Loading @@ -406,20 +427,23 @@ ch_init(EditLine *el) (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 - 2]; 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.action = NOP; el->el_chared.c_undo.isize = 0; el->el_chared.c_undo.dsize = 0; el->el_chared.c_undo.ptr = el->el_line.buffer; 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_vcmd.ins = el->el_line.buffer; el->el_chared.c_kill.buf = (char *) el_malloc(EL_BUFSIZ); if (el->el_chared.c_kill.buf == NULL) Loading Loading @@ -454,14 +478,11 @@ ch_reset(EditLine *el) el->el_line.cursor = el->el_line.buffer; el->el_line.lastchar = el->el_line.buffer; el->el_chared.c_undo.action = NOP; el->el_chared.c_undo.isize = 0; el->el_chared.c_undo.dsize = 0; el->el_chared.c_undo.ptr = 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_vcmd.ins = el->el_line.buffer; el->el_chared.c_kill.mark = el->el_line.buffer; Loading Loading @@ -516,7 +537,8 @@ ch_enlargebufs(el, addlen) 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); el->el_line.limit = &newbuffer[newsz - EL_LEAVE]; /* don't set new size until all buffers are enlarged */ el->el_line.limit = &newbuffer[sz - EL_LEAVE]; /* * Reallocate kill buffer. Loading Loading @@ -545,14 +567,22 @@ ch_enlargebufs(el, addlen) /* zero the newly added memory, leave old data in */ (void) memset(&newbuffer[sz], 0, newsz - sz); el->el_chared.c_undo.ptr = el->el_line.buffer + (el->el_chared.c_undo.ptr - oldbuf); 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 = &newbuffer[newsz - EL_LEAVE]; return 1; } Loading @@ -567,6 +597,11 @@ ch_end(EditLine *el) 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; el_free((ptr_t) el->el_chared.c_macro.macro); Loading Loading @@ -619,51 +654,64 @@ el_deletestr(EditLine *el, int n) * Get a string */ protected int c_gets(EditLine *el, char *buf) c_gets(EditLine *el, char *buf, const char *prompt) { char ch; int len = 0; int len; char *cp = el->el_line.buffer; if (prompt) { len = strlen(prompt); memcpy(cp, prompt, len + 0u); cp += len; } len = 0; for (;;) { el->el_line.cursor = cp; *cp = ' '; el->el_line.lastchar = cp + 1; re_refresh(el); if (el_getc(el, &ch) != 1) { ed_end_of_file(el, 0); len = -1; break; } for (ch = 0; ch == 0;) { if (el_getc(el, &ch) != 1) return (ed_end_of_file(el, 0)); switch (ch) { case 0010: /* Delete and backspace */ case 0177: if (len > 1) { *el->el_line.cursor-- = '\0'; el->el_line.lastchar = el->el_line.cursor; buf[len--] = '\0'; } else { el->el_line.buffer[0] = '\0'; el->el_line.lastchar = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer; return (CC_REFRESH); } re_refresh(el); ch = 0; 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) if (len >= EL_BUFSIZ - 16) term_beep(el); else { buf[len++] = ch; *el->el_line.cursor++ = ch; el->el_line.lastchar = el->el_line.cursor; *cp++ = ch; } re_refresh(el); ch = 0; break; continue; } break; } buf[len] = ch; return (len); el->el_line.buffer[0] = '\0'; el->el_line.lastchar = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer; return len; } Loading
cmd-line-utils/libedit/chared.h +27 −16 Original line number Diff line number Diff line /* $NetBSD: chared.h,v 1.6 2001/01/10 07:45:41 jdolecek Exp $ */ /* $NetBSD: chared.h,v 1.11 2002/11/20 16:50:08 christos Exp $ */ /*- * Copyright (c) 1992, 1993 Loading Loading @@ -71,23 +71,31 @@ typedef struct c_macro_t { } c_macro_t; /* * Undo information for both vi and emacs * Undo information for vi - no undo in emacs (yet) */ typedef struct c_undo_t { int action; size_t isize; size_t dsize; char *ptr; char *buf; 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; char *ins; } c_vcmd_t; /* Loading @@ -106,6 +114,7 @@ typedef struct c_kill_t { 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; Loading @@ -120,10 +129,10 @@ typedef struct el_chared_t { #define NOP 0x00 #define DELETE 0x01 #define INSERT 0x02 #define CHANGE 0x04 #define YANK 0x04 #define CHAR_FWD 0 #define CHAR_BACK 1 #define CHAR_FWD (+1) #define CHAR_BACK (-1) #define MODE_INSERT 0 #define MODE_REPLACE 1 Loading @@ -137,23 +146,25 @@ typedef struct el_chared_t { protected int cv__isword(int); protected int cv__isWord(int); protected void cv_delfini(EditLine *); protected char *cv__endword(char *, char *, int); protected char *cv__endword(char *, char *, int, int (*)(int)); protected int ce__isword(int); protected void cv_undo(EditLine *, int, size_t, char *); 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(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_delafter(EditLine *, int); protected int c_gets(EditLine *, char *); protected int c_gets(EditLine *, char *, const char *); protected int c_hpos(EditLine *); protected int ch_init(EditLine *); protected void ch_reset(EditLine *); protected int ch_enlargebufs __P((EditLine *, size_t)); protected int ch_enlargebufs(EditLine *, size_t); protected void ch_end(EditLine *); #endif /* _h_el_chared */
cmd-line-utils/libedit/common.c +69 −96 Original line number Diff line number Diff line /* $NetBSD: common.c,v 1.10 2001/01/10 07:45:41 jdolecek Exp $ */ /* $NetBSD: common.c,v 1.14 2002/11/20 16:50:08 christos Exp $ */ /*- * Copyright (c) 1992, 1993 Loading Loading @@ -36,12 +36,18 @@ * SUCH DAMAGE. */ #include "compat.h" #include "config.h" #if !defined(lint) && !defined(SCCSID) #if 0 static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93"; #else __RCSID("$NetBSD: common.c,v 1.14 2002/11/20 16:50:08 christos Exp $"); #endif #endif /* not lint && not SCCSID */ /* * common.c: Common Editor functions */ #include "sys.h" #include "el.h" /* ed_end_of_file(): Loading @@ -66,7 +72,7 @@ ed_end_of_file(EditLine *el, int c __attribute__((unused))) protected el_action_t ed_insert(EditLine *el, int c) { int i; int count = el->el_state.argument; if (c == '\0') return (CC_ERROR); Loading @@ -74,42 +80,28 @@ ed_insert(EditLine *el, int c) if (el->el_line.lastchar + el->el_state.argument >= el->el_line.limit) { /* end of buffer space, try to allocate more */ if (!ch_enlargebufs(el, (size_t) el->el_state.argument)) if (!ch_enlargebufs(el, (size_t) count)) return CC_ERROR; /* error allocating more */ } if (el->el_state.argument == 1) { if (el->el_state.inputmode != MODE_INSERT) { el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] = *el->el_line.cursor; el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] = '\0'; c_delafter(el, 1); } if (count == 1) { if (el->el_state.inputmode == MODE_INSERT || el->el_line.cursor >= el->el_line.lastchar) c_insert(el, 1); *el->el_line.cursor++ = c; el->el_state.doingarg = 0; /* just in case */ re_fastaddc(el); /* fast refresh for one char. */ } else { if (el->el_state.inputmode != MODE_INSERT) { for (i = 0; i < el->el_state.argument; i++) el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] = el->el_line.cursor[i]; el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] = '\0'; c_delafter(el, el->el_state.argument); } if (el->el_state.inputmode != MODE_REPLACE_1) c_insert(el, el->el_state.argument); while (el->el_state.argument--) while (count-- && el->el_line.cursor < el->el_line.lastchar) *el->el_line.cursor++ = c; re_refresh(el); } if (el->el_state.inputmode == MODE_REPLACE_1) (void) vi_command_mode(el, 0); return vi_command_mode(el, 0); return (CC_NORM); } Loading Loading @@ -229,7 +221,7 @@ ed_move_to_end(EditLine *el, int c __attribute__((unused))) #ifdef VI_MOVE el->el_line.cursor--; #endif if (el->el_chared.c_vcmd.action & DELETE) { if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } Loading @@ -253,7 +245,7 @@ ed_move_to_beg(EditLine *el, int c __attribute__((unused))) /* We want FIRST non space character */ while (isspace((unsigned char) *el->el_line.cursor)) el->el_line.cursor++; if (el->el_chared.c_vcmd.action & DELETE) { if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } Loading Loading @@ -295,16 +287,20 @@ 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 >= el->el_line.lastchar) if (el->el_line.cursor >= lim || (el->el_line.cursor == lim - 1 && el->el_map.type == MAP_VI && el->el_chared.c_vcmd.action == NOP)) return (CC_ERROR); el->el_line.cursor += el->el_state.argument; if (el->el_line.cursor > el->el_line.lastchar) el->el_line.cursor = el->el_line.lastchar; if (el->el_line.cursor > lim) el->el_line.cursor = lim; if (el->el_map.type == MAP_VI) if (el->el_chared.c_vcmd.action & DELETE) { if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } Loading @@ -330,7 +326,7 @@ ed_prev_word(EditLine *el, int c __attribute__((unused))) ce__isword); if (el->el_map.type == MAP_VI) if (el->el_chared.c_vcmd.action & DELETE) { if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } Loading @@ -353,7 +349,7 @@ ed_prev_char(EditLine *el, int c __attribute__((unused))) el->el_line.cursor = el->el_line.buffer; if (el->el_map.type == MAP_VI) if (el->el_chared.c_vcmd.action & DELETE) { if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } Loading Loading @@ -405,25 +401,9 @@ ed_digit(EditLine *el, int c) (el->el_state.argument * 10) + (c - '0'); } return (CC_ARGHACK); } else { if (el->el_line.lastchar + 1 >= el->el_line.limit) { if (!ch_enlargebufs(el, 1)) return (CC_ERROR); } if (el->el_state.inputmode != MODE_INSERT) { el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] = *el->el_line.cursor; el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] = '\0'; c_delafter(el, 1); } c_insert(el, 1); *el->el_line.cursor++ = c; el->el_state.doingarg = 0; re_fastaddc(el); } return (CC_NORM); return ed_insert(el, c); } Loading Loading @@ -457,12 +437,11 @@ ed_argument_digit(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ ed_unassigned(EditLine *el, int c __attribute__((unused))) ed_unassigned(EditLine *el __attribute__((unused)), int c __attribute__((unused))) { term_beep(el); term__flush(); return (CC_NORM); return (CC_ERROR); } Loading Loading @@ -580,8 +559,6 @@ ed_newline(EditLine *el, int c __attribute__((unused))) re_goto_bottom(el); *el->el_line.lastchar++ = '\n'; *el->el_line.lastchar = '\0'; if (el->el_map.type == MAP_VI) el->el_chared.c_vcmd.ins = el->el_line.buffer; return (CC_NEWLINE); } Loading Loading @@ -672,8 +649,9 @@ protected el_action_t ed_prev_history(EditLine *el, int c __attribute__((unused))) { char beep = 0; int sv_event = el->el_history.eventno; el->el_chared.c_undo.action = NOP; el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ if (el->el_history.eventno == 0) { /* save the current buffer Loading @@ -686,15 +664,17 @@ ed_prev_history(EditLine *el, int c __attribute__((unused))) el->el_history.eventno += el->el_state.argument; if (hist_get(el) == CC_ERROR) { if (el->el_map.type == MAP_VI) { el->el_history.eventno = sv_event; return CC_ERROR; } beep = 1; /* el->el_history.eventno was fixed by first call */ (void) hist_get(el); } re_refresh(el); if (beep) return (CC_ERROR); else return (CC_NORM); /* was CC_UP_HIST */ return CC_REFRESH_BEEP; return CC_REFRESH; } Loading @@ -706,17 +686,22 @@ 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.action = NOP; el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ el->el_history.eventno -= el->el_state.argument; if (el->el_history.eventno < 0) { el->el_history.eventno = 0; return (CC_ERROR);/* make it beep */ beep = CC_REFRESH_BEEP; } return (hist_get(el)); rval = hist_get(el); if (rval == CC_REFRESH) return beep; return rval; } Loading @@ -733,7 +718,7 @@ ed_search_prev_history(EditLine *el, int c __attribute__((unused))) bool_t found = 0; el->el_chared.c_vcmd.action = NOP; el->el_chared.c_undo.action = NOP; el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ if (el->el_history.eventno < 0) { #ifdef DEBUG_EDIT Loading Loading @@ -801,7 +786,7 @@ ed_search_next_history(EditLine *el, int c __attribute__((unused))) bool_t found = 0; el->el_chared.c_vcmd.action = NOP; el->el_chared.c_undo.action = NOP; el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ if (el->el_history.eventno == 0) Loading Loading @@ -930,25 +915,13 @@ ed_command(EditLine *el, int c __attribute__((unused))) char tmpbuf[EL_BUFSIZ]; int tmplen; el->el_line.buffer[0] = '\0'; el->el_line.lastchar = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer; tmplen = c_gets(el, tmpbuf, "\n: "); term__putc('\n'); c_insert(el, 3); /* prompt + ": " */ *el->el_line.cursor++ = '\n'; *el->el_line.cursor++ = ':'; *el->el_line.cursor++ = ' '; re_refresh(el); tmplen = c_gets(el, tmpbuf); tmpbuf[tmplen] = '\0'; el->el_line.buffer[0] = '\0'; el->el_line.lastchar = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer; if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1) term_beep(el); if (parse_line(el, tmpbuf) == -1) return (CC_ERROR); else return (CC_REFRESH); el->el_map.current = el->el_map.key; re_clear_display(el); return CC_REFRESH; }