"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libedit/search.c" between
tnftp-20151004.tar.gz and tnftp-20200705.tar.gz

About: tnftp is an enhanced ftp client (prior name "lukemftp").

search.c  (tnftp-20151004):search.c  (tnftp-20200705)
/* $NetBSD: search.c,v 1.5 2005/06/09 16:48:58 lukem Exp $ */ /* $NetBSD: search.c,v 1.8 2020/07/04 13:43:21 lukem Exp $ */
/* from NetBSD: search.c,v 1.20 2004/11/04 01:16:03 christos Exp * /* from NetBSD: search.c,v 1.51 2020/03/30 06:56:38 ryo Exp */
/
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* This code is derived from software contributed to Berkeley by * This code is derived from software contributed to Berkeley by
* Christos Zoulas of Cornell University. * Christos Zoulas of Cornell University.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
skipping to change at line 36 skipping to change at line 36
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * 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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include "tnftp.h" #include "config.h"
#include "sys.h"
#if 0 /* tnftp */
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID(" NetBSD: search.c,v 1.51 2020/03/30 06:56:38 ryo Exp ");
#endif
#endif /* not lint && not SCCSID */
#endif /* tnftp */
/* /*
* search.c: History and character search functions * search.c: History and character search functions
*/ */
#if 0 /* tnftp */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#if defined(REGEX)
#include <regex.h>
#elif defined(REGEXP)
#include <regexp.h>
#endif
#endif /* tnftp */
#include "el.h" #include "el.h"
#include "common.h"
#include "fcns.h"
/* /*
* Adjust cursor in vi mode to include the character under it * Adjust cursor in vi mode to include the character under it
*/ */
#define EL_CURSOR(el) \ #define EL_CURSOR(el) \
((el)->el_line.cursor + (((el)->el_map.type == MAP_VI) && \ ((el)->el_line.cursor + (((el)->el_map.type == MAP_VI) && \
((el)->el_map.current == (el)->el_map.alt))) ((el)->el_map.current == (el)->el_map.alt)))
/* search_init(): /* search_init():
* Initialize the search stuff * Initialize the search stuff
*/ */
protected int libedit_private int
search_init(EditLine *el) search_init(EditLine *el)
{ {
el->el_search.patbuf = (char *) el_malloc(EL_BUFSIZ); el->el_search.patbuf = el_calloc(EL_BUFSIZ,
sizeof(*el->el_search.patbuf));
if (el->el_search.patbuf == NULL) if (el->el_search.patbuf == NULL)
return (-1); return -1;
el->el_search.patbuf[0] = L'\0';
el->el_search.patlen = 0; el->el_search.patlen = 0;
el->el_search.patdir = -1; el->el_search.patdir = -1;
el->el_search.chacha = '\0'; el->el_search.chacha = L'\0';
el->el_search.chadir = CHAR_FWD; el->el_search.chadir = CHAR_FWD;
el->el_search.chatflg = 0; el->el_search.chatflg = 0;
return (0); return 0;
} }
/* search_end(): /* search_end():
* Initialize the search stuff * Initialize the search stuff
*/ */
protected void libedit_private void
search_end(EditLine *el) search_end(EditLine *el)
{ {
el_free((ptr_t) el->el_search.patbuf); el_free(el->el_search.patbuf);
el->el_search.patbuf = NULL; el->el_search.patbuf = NULL;
} }
#ifdef REGEXP #ifdef REGEXP
/* regerror(): /* regerror():
* Handle regular expression errors * Handle regular expression errors
*/ */
public void void
/*ARGSUSED*/ /*ARGSUSED*/
regerror(const char *msg) regerror(const char *msg)
{ {
} }
#endif #endif
/* el_match(): /* el_match():
* Return if string matches pattern * Return if string matches pattern
*/ */
protected int libedit_private int
el_match(const char *str, const char *pat) el_match(const wchar_t *str, const wchar_t *pat)
{ {
static ct_buffer_t conv;
#if defined (REGEX) #if defined (REGEX)
regex_t re; regex_t re;
int rv; int rv;
#elif defined (REGEXP) #elif defined (REGEXP)
regexp *rp; regexp *rp;
int rv; int rv;
#else #else
extern char *re_comp(const char *); extern char *re_comp(const char *);
extern int re_exec(const char *); extern int re_exec(const char *);
#endif #endif
if (strstr(str, pat) != NULL) if (wcsstr(str, pat) != 0)
return (1); return 1;
#if defined(REGEX) #if defined(REGEX)
if (regcomp(&re, pat, 0) == 0) { if (regcomp(&re, ct_encode_string(pat, &conv), 0) == 0) {
rv = regexec(&re, str, 0, NULL, 0) == 0; rv = regexec(&re, ct_encode_string(str, &conv), (size_t)0, NULL,
0) == 0;
regfree(&re); regfree(&re);
} else { } else {
rv = 0; rv = 0;
} }
return (rv); return rv;
#elif defined(REGEXP) #elif defined(REGEXP)
if ((re = regcomp(pat)) != NULL) { if ((re = regcomp(ct_encode_string(pat, &conv))) != NULL) {
rv = regexec(re, str); rv = regexec(re, ct_encode_string(str, &conv));
free((ptr_t) re); el_free(re);
} else { } else {
rv = 0; rv = 0;
} }
return (rv); return rv;
#else #else
if (re_comp(pat) != NULL) if (re_comp(ct_encode_string(pat, &conv)) != NULL)
return (0); return 0;
else else
return (re_exec(str) == 1); return re_exec(ct_encode_string(str, &conv)) == 1;
#endif #endif
} }
/* c_hmatch(): /* c_hmatch():
* return True if the pattern matches the prefix * return True if the pattern matches the prefix
*/ */
protected int libedit_private int
c_hmatch(EditLine *el, const char *str) c_hmatch(EditLine *el, const wchar_t *str)
{ {
#ifdef SDEBUG #ifdef SDEBUG
(void) fprintf(el->el_errfile, "match `%s' with `%s'\n", (void) fprintf(el->el_errfile, "match `%ls' with `%ls'\n",
el->el_search.patbuf, str); el->el_search.patbuf, str);
#endif /* SDEBUG */ #endif /* SDEBUG */
return (el_match(str, el->el_search.patbuf)); return el_match(str, el->el_search.patbuf);
} }
/* c_setpat(): /* c_setpat():
* Set the history seatch pattern * Set the history seatch pattern
*/ */
protected void libedit_private void
c_setpat(EditLine *el) c_setpat(EditLine *el)
{ {
if (el->el_state.lastcmd != ED_SEARCH_PREV_HISTORY && if (el->el_state.lastcmd != ED_SEARCH_PREV_HISTORY &&
el->el_state.lastcmd != ED_SEARCH_NEXT_HISTORY) { el->el_state.lastcmd != ED_SEARCH_NEXT_HISTORY) {
el->el_search.patlen = EL_CURSOR(el) - el->el_line.buffer; el->el_search.patlen =
(size_t)(EL_CURSOR(el) - el->el_line.buffer);
if (el->el_search.patlen >= EL_BUFSIZ) if (el->el_search.patlen >= EL_BUFSIZ)
el->el_search.patlen = EL_BUFSIZ - 1; el->el_search.patlen = EL_BUFSIZ - 1;
if (el->el_search.patlen != 0) { (void) wcsncpy(el->el_search.patbuf, el->el_line.buffer,
(void) strncpy(el->el_search.patbuf, el->el_line.buffer, el->el_search.patlen);
el->el_search.patlen); el->el_search.patbuf[el->el_search.patlen] = '\0';
el->el_search.patbuf[el->el_search.patlen] = '\0';
} else
el->el_search.patlen = strlen(el->el_search.patbuf);
} }
#ifdef SDEBUG #ifdef SDEBUG
(void) fprintf(el->el_errfile, "\neventno = %d\n", (void) fprintf(el->el_errfile, "\neventno = %d\n",
el->el_history.eventno); el->el_history.eventno);
(void) fprintf(el->el_errfile, "patlen = %d\n", el->el_search.patlen); (void) fprintf(el->el_errfile, "patlen = %ld\n", el->el_search.patlen);
(void) fprintf(el->el_errfile, "patbuf = \"%s\"\n", (void) fprintf(el->el_errfile, "patbuf = \"%ls\"\n",
el->el_search.patbuf); el->el_search.patbuf);
(void) fprintf(el->el_errfile, "cursor %d lastchar %d\n", (void) fprintf(el->el_errfile, "cursor %ld lastchar %ld\n",
EL_CURSOR(el) - el->el_line.buffer, EL_CURSOR(el) - el->el_line.buffer,
el->el_line.lastchar - el->el_line.buffer); el->el_line.lastchar - el->el_line.buffer);
#endif #endif
} }
/* ce_inc_search(): /* ce_inc_search():
* Emacs incremental search * Emacs incremental search
*/ */
protected el_action_t libedit_private el_action_t
ce_inc_search(EditLine *el, int dir) ce_inc_search(EditLine *el, int dir)
{ {
static const char STRfwd[] = {'f', 'w', 'd', '\0'}, static const wchar_t STRfwd[] = L"fwd", STRbck[] = L"bck";
STRbck[] = {'b', 'c', 'k', '\0'}; static wchar_t pchar = L':'; /* ':' = normal, '?' = failed */
static char pchar = ':';/* ':' = normal, '?' = failed */ static wchar_t endcmd[2] = {'\0', '\0'};
static char endcmd[2] = {'\0', '\0'}; wchar_t *ocursor = el->el_line.cursor, oldpchar = pchar, ch;
char ch, *ocursor = el->el_line.cursor, oldpchar = pchar; const wchar_t *cp;
const char *cp;
el_action_t ret = CC_NORM; el_action_t ret = CC_NORM;
int ohisteventno = el->el_history.eventno; int ohisteventno = el->el_history.eventno;
int oldpatlen = el->el_search.patlen; size_t oldpatlen = el->el_search.patlen;
int newdir = dir; int newdir = dir;
int done, redo; int done, redo;
if (el->el_line.lastchar + sizeof(STRfwd) / sizeof(char) + 2 + if (el->el_line.lastchar + sizeof(STRfwd) /
sizeof(*el->el_line.lastchar) + 2 +
el->el_search.patlen >= el->el_line.limit) el->el_search.patlen >= el->el_line.limit)
return (CC_ERROR); return CC_ERROR;
for (;;) { for (;;) {
if (el->el_search.patlen == 0) { /* first round */ if (el->el_search.patlen == 0) { /* first round */
pchar = ':'; pchar = ':';
#ifdef ANCHOR #ifdef ANCHOR
#define LEN 2 #define LEN 2
el->el_search.patbuf[el->el_search.patlen++] = '.'; el->el_search.patbuf[el->el_search.patlen++] = '.';
el->el_search.patbuf[el->el_search.patlen++] = '*'; el->el_search.patbuf[el->el_search.patlen++] = '*';
#else #else
skipping to change at line 229 skipping to change at line 251
*cp; *el->el_line.lastchar++ = *cp++) *cp; *el->el_line.lastchar++ = *cp++)
continue; continue;
*el->el_line.lastchar++ = pchar; *el->el_line.lastchar++ = pchar;
for (cp = &el->el_search.patbuf[LEN]; for (cp = &el->el_search.patbuf[LEN];
cp < &el->el_search.patbuf[el->el_search.patlen]; cp < &el->el_search.patbuf[el->el_search.patlen];
*el->el_line.lastchar++ = *cp++) *el->el_line.lastchar++ = *cp++)
continue; continue;
*el->el_line.lastchar = '\0'; *el->el_line.lastchar = '\0';
re_refresh(el); re_refresh(el);
if (el_getc(el, &ch) != 1) if (el_wgetc(el, &ch) != 1)
return (ed_end_of_file(el, 0)); return ed_end_of_file(el, 0);
switch (el->el_map.current[(unsigned char) ch]) { switch (el->el_map.current[(unsigned char) ch]) {
case ED_INSERT: case ED_INSERT:
case ED_DIGIT: case ED_DIGIT:
if (el->el_search.patlen >= EL_BUFSIZ - LEN) if (el->el_search.patlen >= EL_BUFSIZ - LEN)
term_beep(el); terminal_beep(el);
else { else {
el->el_search.patbuf[el->el_search.patlen++] = el->el_search.patbuf[el->el_search.patlen++] =
ch; ch;
*el->el_line.lastchar++ = ch; *el->el_line.lastchar++ = ch;
*el->el_line.lastchar = '\0'; *el->el_line.lastchar = '\0';
re_refresh(el); re_refresh(el);
} }
break; break;
case EM_INC_SEARCH_NEXT: case EM_INC_SEARCH_NEXT:
skipping to change at line 261 skipping to change at line 283
case EM_INC_SEARCH_PREV: case EM_INC_SEARCH_PREV:
newdir = ED_SEARCH_PREV_HISTORY; newdir = ED_SEARCH_PREV_HISTORY;
redo++; redo++;
break; break;
case EM_DELETE_PREV_CHAR: case EM_DELETE_PREV_CHAR:
case ED_DELETE_PREV_CHAR: case ED_DELETE_PREV_CHAR:
if (el->el_search.patlen > LEN) if (el->el_search.patlen > LEN)
done++; done++;
else else
term_beep(el); terminal_beep(el);
break; break;
default: default:
switch (ch) { switch (ch) {
case 0007: /* ^G: Abort */ case 0007: /* ^G: Abort */
ret = CC_ERROR; ret = CC_ERROR;
done++; done++;
break; break;
case 0027: /* ^W: Append word */ case 0027: /* ^W: Append word */
skipping to change at line 285 skipping to change at line 307
el->el_search.patlen]) { el->el_search.patlen]) {
el->el_line.cursor += el->el_line.cursor +=
el->el_search.patlen - LEN - 1; el->el_search.patlen - LEN - 1;
cp = c__next_word(el->el_line.cursor, cp = c__next_word(el->el_line.cursor,
el->el_line.lastchar, 1, el->el_line.lastchar, 1,
ce__isword); ce__isword);
while (el->el_line.cursor < cp && while (el->el_line.cursor < cp &&
*el->el_line.cursor != '\n') { *el->el_line.cursor != '\n') {
if (el->el_search.patlen >= if (el->el_search.patlen >=
EL_BUFSIZ - LEN) { EL_BUFSIZ - LEN) {
term_beep(el); terminal_beep(el);
break; break;
} }
el->el_search.patbuf[el->el_searc h.patlen++] = el->el_search.patbuf[el->el_searc h.patlen++] =
*el->el_line.cursor; *el->el_line.cursor;
*el->el_line.lastchar++ = *el->el_line.lastchar++ =
*el->el_line.cursor++; *el->el_line.cursor++;
} }
el->el_line.cursor = ocursor; el->el_line.cursor = ocursor;
*el->el_line.lastchar = '\0'; *el->el_line.lastchar = '\0';
re_refresh(el); re_refresh(el);
break; break;
} else if (isglob(*cp)) { } else if (isglob(*cp)) {
term_beep(el); terminal_beep(el);
break; break;
} }
break; break;
default: /* Terminate and execute cmd */ default: /* Terminate and execute cmd */
endcmd[0] = ch; endcmd[0] = ch;
el_push(el, endcmd); el_wpush(el, endcmd);
/* FALLTHROUGH */ /* FALLTHROUGH */
case 0033: /* ESC: Terminate */ case 0033: /* ESC: Terminate */
ret = CC_REFRESH; ret = CC_REFRESH;
done++; done++;
break; break;
} }
break; break;
} }
while (el->el_line.lastchar > el->el_line.buffer && while (el->el_line.lastchar > el->el_line.buffer &&
*el->el_line.lastchar != '\n') *el->el_line.lastchar != '\n')
*el->el_line.lastchar-- = '\0'; *el->el_line.lastchar-- = '\0';
*el->el_line.lastchar = '\0'; *el->el_line.lastchar = '\0';
if (!done) { if (!done) {
/* Can't search if unmatched '[' */ /* Can't search if unmatched '[' */
for (cp = &el->el_search.patbuf[el->el_search.patlen-1], for (cp = &el->el_search.patbuf[el->el_search.patlen-1],
ch = ']'; ch = L']';
cp >= &el->el_search.patbuf[LEN]; cp >= &el->el_search.patbuf[LEN];
cp--) cp--)
if (*cp == '[' || *cp == ']') { if (*cp == '[' || *cp == ']') {
ch = *cp; ch = *cp;
break; break;
} }
if (el->el_search.patlen > LEN && ch != '[') { if (el->el_search.patlen > LEN && ch != L'[') {
if (redo && newdir == dir) { if (redo && newdir == dir) {
if (pchar == '?') { /* wrap around */ if (pchar == '?') { /* wrap around */
el->el_history.eventno = el->el_history.eventno =
newdir == ED_SEARCH_PREV_HIST ORY ? 0 : 0x7fffffff; newdir == ED_SEARCH_PREV_HIST ORY ? 0 : 0x7fffffff;
if (hist_get(el) == CC_ERROR) if (hist_get(el) == CC_ERROR)
/* el->el_history.event /* el->el_history.event
* no was fixed by * no was fixed by
* first call */ * first call */
(void) hist_get(el); (void) hist_get(el);
el->el_line.cursor = newdir == el->el_line.cursor = newdir ==
skipping to change at line 367 skipping to change at line 389
#endif #endif
el->el_search.patbuf[el->el_search.patlen] = el->el_search.patbuf[el->el_search.patlen] =
'\0'; '\0';
if (el->el_line.cursor < el->el_line.buffer || if (el->el_line.cursor < el->el_line.buffer ||
el->el_line.cursor > el->el_line.lastchar || el->el_line.cursor > el->el_line.lastchar ||
(ret = ce_search_line(el, newdir)) (ret = ce_search_line(el, newdir))
== CC_ERROR) { == CC_ERROR) {
/* avoid c_setpat */ /* avoid c_setpat */
el->el_state.lastcmd = el->el_state.lastcmd =
(el_action_t) newdir; (el_action_t) newdir;
ret = newdir == ED_SEARCH_PREV_HISTORY ? ret = (el_action_t)
(newdir == ED_SEARCH_PREV_HISTORY ?
ed_search_prev_history(el, 0) : ed_search_prev_history(el, 0) :
ed_search_next_history(el, 0); ed_search_next_history(el, 0));
if (ret != CC_ERROR) { if (ret != CC_ERROR) {
el->el_line.cursor = newdir == el->el_line.cursor = newdir ==
ED_SEARCH_PREV_HISTORY ? ED_SEARCH_PREV_HISTORY ?
el->el_line.lastchar : el->el_line.lastchar :
el->el_line.buffer; el->el_line.buffer;
(void) ce_search_line(el, (void) ce_search_line(el,
newdir); newdir);
} }
} }
el->el_search.patlen -= LEN; el->el_search.patlen -= LEN;
el->el_search.patbuf[el->el_search.patlen] = el->el_search.patbuf[el->el_search.patlen] =
'\0'; '\0';
if (ret == CC_ERROR) { if (ret == CC_ERROR) {
term_beep(el); terminal_beep(el);
if (el->el_history.eventno != if (el->el_history.eventno !=
ohisteventno) { ohisteventno) {
el->el_history.eventno = el->el_history.eventno =
ohisteventno; ohisteventno;
if (hist_get(el) == CC_ERROR) if (hist_get(el) == CC_ERROR)
return (CC_ERROR); return CC_ERROR;
} }
el->el_line.cursor = ocursor; el->el_line.cursor = ocursor;
pchar = '?'; pchar = '?';
} else { } else {
pchar = ':'; pchar = ':';
} }
} }
ret = ce_inc_search(el, newdir); ret = ce_inc_search(el, newdir);
if (ret == CC_ERROR && pchar == '?' && oldpchar == ':') if (ret == CC_ERROR && pchar == '?' && oldpchar == ':')
skipping to change at line 414 skipping to change at line 437
ret = CC_NORM; ret = CC_NORM;
} }
if (ret == CC_NORM || (ret == CC_ERROR && oldpatlen == 0)) { if (ret == CC_NORM || (ret == CC_ERROR && oldpatlen == 0)) {
/* restore on normal return or error exit */ /* restore on normal return or error exit */
pchar = oldpchar; pchar = oldpchar;
el->el_search.patlen = oldpatlen; el->el_search.patlen = oldpatlen;
if (el->el_history.eventno != ohisteventno) { if (el->el_history.eventno != ohisteventno) {
el->el_history.eventno = ohisteventno; el->el_history.eventno = ohisteventno;
if (hist_get(el) == CC_ERROR) if (hist_get(el) == CC_ERROR)
return (CC_ERROR); return CC_ERROR;
} }
el->el_line.cursor = ocursor; el->el_line.cursor = ocursor;
if (ret == CC_ERROR) if (ret == CC_ERROR)
re_refresh(el); re_refresh(el);
} }
if (done || ret != CC_NORM) if (done || ret != CC_NORM)
return (ret); return ret;
} }
} }
/* cv_search(): /* cv_search():
* Vi search. * Vi search.
*/ */
protected el_action_t libedit_private el_action_t
cv_search(EditLine *el, int dir) cv_search(EditLine *el, int dir)
{ {
char ch; wchar_t ch;
char tmpbuf[EL_BUFSIZ]; wchar_t tmpbuf[EL_BUFSIZ];
int tmplen; ssize_t tmplen;
#ifdef ANCHOR #ifdef ANCHOR
tmpbuf[0] = '.'; tmpbuf[0] = '.';
tmpbuf[1] = '*'; tmpbuf[1] = '*';
#endif #endif
tmplen = LEN; tmplen = LEN;
el->el_search.patdir = dir; el->el_search.patdir = dir;
tmplen = c_gets(el, &tmpbuf[LEN], tmplen = c_gets(el, &tmpbuf[LEN],
dir == ED_SEARCH_PREV_HISTORY ? "\n/" : "\n?" ); dir == ED_SEARCH_PREV_HISTORY ? L"\n/" : L"\n?" );
if (tmplen == -1) if (tmplen == -1)
return CC_REFRESH; return CC_REFRESH;
tmplen += LEN; tmplen += LEN;
ch = tmpbuf[tmplen]; ch = tmpbuf[tmplen];
tmpbuf[tmplen] = '\0'; tmpbuf[tmplen] = '\0';
if (tmplen == LEN) { if (tmplen == LEN) {
/* /*
* Use the old pattern, but wild-card it. * Use the old pattern, but wild-card it.
*/ */
if (el->el_search.patlen == 0) { if (el->el_search.patlen == 0) {
re_refresh(el); re_refresh(el);
return (CC_ERROR); return CC_ERROR;
} }
#ifdef ANCHOR #ifdef ANCHOR
if (el->el_search.patbuf[0] != '.' && if (el->el_search.patbuf[0] != '.' &&
el->el_search.patbuf[0] != '*') { el->el_search.patbuf[0] != '*') {
(void) strncpy(tmpbuf, el->el_search.patbuf, (void) wcsncpy(tmpbuf, el->el_search.patbuf,
sizeof(tmpbuf) - 1); sizeof(tmpbuf) / sizeof(*tmpbuf) - 1);
el->el_search.patbuf[0] = '.'; el->el_search.patbuf[0] = '.';
el->el_search.patbuf[1] = '*'; el->el_search.patbuf[1] = '*';
(void) strncpy(&el->el_search.patbuf[2], tmpbuf, (void) wcsncpy(&el->el_search.patbuf[2], tmpbuf,
EL_BUFSIZ - 3); EL_BUFSIZ - 3);
el->el_search.patlen++; el->el_search.patlen++;
el->el_search.patbuf[el->el_search.patlen++] = '.'; el->el_search.patbuf[el->el_search.patlen++] = '.';
el->el_search.patbuf[el->el_search.patlen++] = '*'; el->el_search.patbuf[el->el_search.patlen++] = '*';
el->el_search.patbuf[el->el_search.patlen] = '\0'; el->el_search.patbuf[el->el_search.patlen] = '\0';
} }
#endif #endif
} else { } else {
#ifdef ANCHOR #ifdef ANCHOR
tmpbuf[tmplen++] = '.'; tmpbuf[tmplen++] = '.';
tmpbuf[tmplen++] = '*'; tmpbuf[tmplen++] = '*';
#endif #endif
tmpbuf[tmplen] = '\0'; tmpbuf[tmplen] = '\0';
(void) strncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1); (void) wcsncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1);
el->el_search.patlen = tmplen; el->el_search.patlen = (size_t)tmplen;
} }
el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */ el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
el->el_line.cursor = el->el_line.lastchar = el->el_line.buffer; el->el_line.cursor = el->el_line.lastchar = el->el_line.buffer;
if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) : if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) :
ed_search_next_history(el, 0)) == CC_ERROR) { ed_search_next_history(el, 0)) == CC_ERROR) {
re_refresh(el); re_refresh(el);
return (CC_ERROR); return CC_ERROR;
} }
if (ch == 0033) { if (ch == 0033) {
re_refresh(el); re_refresh(el);
return ed_newline(el, 0); return ed_newline(el, 0);
} }
return (CC_REFRESH); return CC_REFRESH;
} }
/* ce_search_line(): /* ce_search_line():
* Look for a pattern inside a line * Look for a pattern inside a line
*/ */
protected el_action_t libedit_private el_action_t
ce_search_line(EditLine *el, int dir) ce_search_line(EditLine *el, int dir)
{ {
char *cp = el->el_line.cursor; wchar_t *cp = el->el_line.cursor;
char *pattern = el->el_search.patbuf; wchar_t *pattern = el->el_search.patbuf;
char oc, *ocp; wchar_t oc, *ocp;
#ifdef ANCHOR #ifdef ANCHOR
ocp = &pattern[1]; ocp = &pattern[1];
oc = *ocp; oc = *ocp;
*ocp = '^'; *ocp = '^';
#else #else
ocp = pattern; ocp = pattern;
oc = *ocp; oc = *ocp;
#endif #endif
if (dir == ED_SEARCH_PREV_HISTORY) { if (dir == ED_SEARCH_PREV_HISTORY) {
for (; cp >= el->el_line.buffer; cp--) { for (; cp >= el->el_line.buffer; cp--) {
if (el_match(cp, ocp)) { if (el_match(cp, ocp)) {
*ocp = oc; *ocp = oc;
el->el_line.cursor = cp; el->el_line.cursor = cp;
return (CC_NORM); return CC_NORM;
} }
} }
*ocp = oc; *ocp = oc;
return (CC_ERROR); return CC_ERROR;
} else { } else {
for (; *cp != '\0' && cp < el->el_line.limit; cp++) { for (; *cp != '\0' && cp < el->el_line.limit; cp++) {
if (el_match(cp, ocp)) { if (el_match(cp, ocp)) {
*ocp = oc; *ocp = oc;
el->el_line.cursor = cp; el->el_line.cursor = cp;
return (CC_NORM); return CC_NORM;
} }
} }
*ocp = oc; *ocp = oc;
return (CC_ERROR); return CC_ERROR;
} }
} }
/* cv_repeat_srch(): /* cv_repeat_srch():
* Vi repeat search * Vi repeat search
*/ */
protected el_action_t libedit_private el_action_t
cv_repeat_srch(EditLine *el, int c) cv_repeat_srch(EditLine *el, wint_t c)
{ {
#ifdef SDEBUG #ifdef SDEBUG
(void) fprintf(el->el_errfile, "dir %d patlen %d patbuf %s\n", static ct_buffer_t conv;
c, el->el_search.patlen, el->el_search.patbuf); (void) fprintf(el->el_errfile, "dir %d patlen %ld patbuf %s\n",
c, el->el_search.patlen, ct_encode_string(el->el_search.patbuf, &conv
));
#endif #endif
el->el_state.lastcmd = (el_action_t) c; /* Hack to stop c_setpat */ el->el_state.lastcmd = (el_action_t) c; /* Hack to stop c_setpat */
el->el_line.lastchar = el->el_line.buffer; el->el_line.lastchar = el->el_line.buffer;
switch (c) { switch (c) {
case ED_SEARCH_NEXT_HISTORY: case ED_SEARCH_NEXT_HISTORY:
return (ed_search_next_history(el, 0)); return ed_search_next_history(el, 0);
case ED_SEARCH_PREV_HISTORY: case ED_SEARCH_PREV_HISTORY:
return (ed_search_prev_history(el, 0)); return ed_search_prev_history(el, 0);
default: default:
return (CC_ERROR); return CC_ERROR;
} }
} }
/* cv_csearch(): /* cv_csearch():
* Vi character search * Vi character search
*/ */
protected el_action_t libedit_private el_action_t
cv_csearch(EditLine *el, int direction, int ch, int count, int tflag) cv_csearch(EditLine *el, int direction, wint_t ch, int count, int tflag)
{ {
char *cp; wchar_t *cp;
if (ch == 0) if (ch == 0)
return CC_ERROR; return CC_ERROR;
if (ch == -1) { if (ch == (wint_t)-1) {
char c; wchar_t c;
if (el_getc(el, &c) != 1) if (el_wgetc(el, &c) != 1)
return ed_end_of_file(el, 0); return ed_end_of_file(el, 0);
ch = c; ch = c;
} }
/* Save for ';' and ',' commands */ /* Save for ';' and ',' commands */
el->el_search.chacha = ch; el->el_search.chacha = ch;
el->el_search.chadir = direction; el->el_search.chadir = direction;
el->el_search.chatflg = tflag; el->el_search.chatflg = (char)tflag;
cp = el->el_line.cursor; cp = el->el_line.cursor;
while (count--) { while (count--) {
if (*cp == ch) if ((wint_t)*cp == ch)
cp += direction; cp += direction;
for (;;cp += direction) { for (;;cp += direction) {
if (cp >= el->el_line.lastchar) if (cp >= el->el_line.lastchar)
return CC_ERROR; return CC_ERROR;
if (cp < el->el_line.buffer) if (cp < el->el_line.buffer)
return CC_ERROR; return CC_ERROR;
if (*cp == ch) if ((wint_t)*cp == ch)
break; break;
} }
} }
if (tflag) if (tflag)
cp -= direction; cp -= direction;
el->el_line.cursor = cp; el->el_line.cursor = cp;
if (el->el_chared.c_vcmd.action != NOP) { if (el->el_chared.c_vcmd.action != NOP) {
 End of changes. 75 change blocks. 
104 lines changed or deleted 128 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)