2020-03-30 09:56:38 +03:00
|
|
|
/* $NetBSD: search.c,v 1.51 2020/03/30 06:56:38 ryo Exp $ */
|
1997-01-11 09:47:47 +03:00
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
/*-
|
|
|
|
* 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.
|
2003-08-07 20:42:00 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-06 10:01:42 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2002-03-18 19:00:50 +03:00
|
|
|
#include "config.h"
|
1994-05-06 10:01:42 +04:00
|
|
|
#if !defined(lint) && !defined(SCCSID)
|
1997-01-11 09:47:47 +03:00
|
|
|
#if 0
|
1994-05-06 10:01:42 +04:00
|
|
|
static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
|
1997-01-11 09:47:47 +03:00
|
|
|
#else
|
2020-03-30 09:56:38 +03:00
|
|
|
__RCSID("$NetBSD: search.c,v 1.51 2020/03/30 06:56:38 ryo Exp $");
|
1997-01-11 09:47:47 +03:00
|
|
|
#endif
|
1994-05-06 10:01:42 +04:00
|
|
|
#endif /* not lint && not SCCSID */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* search.c: History and character search functions
|
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
2016-02-17 01:53:14 +03:00
|
|
|
#include <string.h>
|
1994-10-02 05:10:48 +03:00
|
|
|
#if defined(REGEX)
|
|
|
|
#include <regex.h>
|
|
|
|
#elif defined(REGEXP)
|
1994-05-06 10:01:42 +04:00
|
|
|
#include <regexp.h>
|
|
|
|
#endif
|
2016-02-16 22:08:41 +03:00
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
#include "el.h"
|
2016-02-16 22:08:41 +03:00
|
|
|
#include "common.h"
|
From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
2016-04-18 20:01:19 +03:00
|
|
|
#include "fcns.h"
|
1994-05-06 10:01:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust cursor in vi mode to include the character under it
|
|
|
|
*/
|
2000-09-05 02:06:28 +04:00
|
|
|
#define EL_CURSOR(el) \
|
1994-05-06 10:01:42 +04:00
|
|
|
((el)->el_line.cursor + (((el)->el_map.type == MAP_VI) && \
|
|
|
|
((el)->el_map.current == (el)->el_map.alt)))
|
|
|
|
|
|
|
|
/* search_init():
|
|
|
|
* Initialize the search stuff
|
|
|
|
*/
|
2016-05-10 00:46:56 +03:00
|
|
|
libedit_private int
|
2000-09-05 02:06:28 +04:00
|
|
|
search_init(EditLine *el)
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
2000-09-05 02:06:28 +04:00
|
|
|
|
2019-07-23 13:18:52 +03:00
|
|
|
el->el_search.patbuf = el_calloc(EL_BUFSIZ,
|
2009-12-31 01:37:40 +03:00
|
|
|
sizeof(*el->el_search.patbuf));
|
2001-01-04 18:56:31 +03:00
|
|
|
if (el->el_search.patbuf == NULL)
|
2011-07-29 19:16:33 +04:00
|
|
|
return -1;
|
2016-04-28 15:27:45 +03:00
|
|
|
el->el_search.patbuf[0] = L'\0';
|
2000-09-05 02:06:28 +04:00
|
|
|
el->el_search.patlen = 0;
|
|
|
|
el->el_search.patdir = -1;
|
2016-04-28 15:27:45 +03:00
|
|
|
el->el_search.chacha = L'\0';
|
2002-11-15 17:32:32 +03:00
|
|
|
el->el_search.chadir = CHAR_FWD;
|
|
|
|
el->el_search.chatflg = 0;
|
2011-07-29 19:16:33 +04:00
|
|
|
return 0;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* search_end():
|
|
|
|
* Initialize the search stuff
|
|
|
|
*/
|
2016-05-10 00:46:56 +03:00
|
|
|
libedit_private void
|
2000-09-05 02:06:28 +04:00
|
|
|
search_end(EditLine *el)
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
2000-09-05 02:06:28 +04:00
|
|
|
|
2011-07-29 00:50:55 +04:00
|
|
|
el_free(el->el_search.patbuf);
|
2000-09-05 02:06:28 +04:00
|
|
|
el->el_search.patbuf = NULL;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
#ifdef REGEXP
|
|
|
|
/* regerror():
|
|
|
|
* Handle regular expression errors
|
|
|
|
*/
|
2016-04-11 21:56:31 +03:00
|
|
|
void
|
1994-05-06 10:01:42 +04:00
|
|
|
/*ARGSUSED*/
|
2000-09-05 02:06:28 +04:00
|
|
|
regerror(const char *msg)
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
/* el_match():
|
|
|
|
* Return if string matches pattern
|
|
|
|
*/
|
2016-05-10 00:46:56 +03:00
|
|
|
libedit_private int
|
2016-04-11 03:50:13 +03:00
|
|
|
el_match(const wchar_t *str, const wchar_t *pat)
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
2009-12-31 02:54:52 +03:00
|
|
|
static ct_buffer_t conv;
|
1994-10-02 05:10:48 +03:00
|
|
|
#if defined (REGEX)
|
2000-09-05 02:06:28 +04:00
|
|
|
regex_t re;
|
|
|
|
int rv;
|
1994-10-02 05:10:48 +03:00
|
|
|
#elif defined (REGEXP)
|
2000-09-05 02:06:28 +04:00
|
|
|
regexp *rp;
|
|
|
|
int rv;
|
1999-07-02 19:14:07 +04:00
|
|
|
#else
|
2000-09-05 02:06:28 +04:00
|
|
|
extern char *re_comp(const char *);
|
|
|
|
extern int re_exec(const char *);
|
1994-05-06 10:01:42 +04:00
|
|
|
#endif
|
|
|
|
|
2016-04-09 21:43:17 +03:00
|
|
|
if (wcsstr(str, pat) != 0)
|
2011-07-29 19:16:33 +04:00
|
|
|
return 1;
|
1994-10-02 05:10:48 +03:00
|
|
|
|
|
|
|
#if defined(REGEX)
|
2009-12-31 01:37:40 +03:00
|
|
|
if (regcomp(&re, ct_encode_string(pat, &conv), 0) == 0) {
|
2011-07-30 03:44:44 +04:00
|
|
|
rv = regexec(&re, ct_encode_string(str, &conv), (size_t)0, NULL,
|
|
|
|
0) == 0;
|
2000-09-05 02:06:28 +04:00
|
|
|
regfree(&re);
|
|
|
|
} else {
|
|
|
|
rv = 0;
|
|
|
|
}
|
2011-07-29 19:16:33 +04:00
|
|
|
return rv;
|
1994-10-02 05:10:48 +03:00
|
|
|
#elif defined(REGEXP)
|
2009-12-31 01:37:40 +03:00
|
|
|
if ((re = regcomp(ct_encode_string(pat, &conv))) != NULL) {
|
|
|
|
rv = regexec(re, ct_encode_string(str, &conv));
|
2011-07-29 00:50:55 +04:00
|
|
|
el_free(re);
|
2000-09-05 02:06:28 +04:00
|
|
|
} else {
|
|
|
|
rv = 0;
|
|
|
|
}
|
2011-07-29 19:16:33 +04:00
|
|
|
return rv;
|
1994-10-02 05:10:48 +03:00
|
|
|
#else
|
2009-12-31 01:37:40 +03:00
|
|
|
if (re_comp(ct_encode_string(pat, &conv)) != NULL)
|
2011-07-29 19:16:33 +04:00
|
|
|
return 0;
|
2000-09-05 02:06:28 +04:00
|
|
|
else
|
2016-01-30 07:02:51 +03:00
|
|
|
return re_exec(ct_encode_string(str, &conv)) == 1;
|
1994-05-06 10:01:42 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* c_hmatch():
|
|
|
|
* return True if the pattern matches the prefix
|
|
|
|
*/
|
2016-05-10 00:46:56 +03:00
|
|
|
libedit_private int
|
2016-04-11 03:50:13 +03:00
|
|
|
c_hmatch(EditLine *el, const wchar_t *str)
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
|
|
|
#ifdef SDEBUG
|
2020-03-30 09:54:37 +03:00
|
|
|
(void) fprintf(el->el_errfile, "match `%ls' with `%ls'\n",
|
2000-09-05 02:06:28 +04:00
|
|
|
el->el_search.patbuf, str);
|
1994-05-06 10:01:42 +04:00
|
|
|
#endif /* SDEBUG */
|
1999-07-02 19:14:07 +04:00
|
|
|
|
2011-07-29 19:16:33 +04:00
|
|
|
return el_match(str, el->el_search.patbuf);
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-02 19:14:07 +04:00
|
|
|
/* c_setpat():
|
1994-05-06 10:01:42 +04:00
|
|
|
* Set the history seatch pattern
|
|
|
|
*/
|
2016-05-10 00:46:56 +03:00
|
|
|
libedit_private void
|
2000-09-05 02:06:28 +04:00
|
|
|
c_setpat(EditLine *el)
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
2000-09-05 02:06:28 +04:00
|
|
|
if (el->el_state.lastcmd != ED_SEARCH_PREV_HISTORY &&
|
|
|
|
el->el_state.lastcmd != ED_SEARCH_NEXT_HISTORY) {
|
2011-08-16 20:25:15 +04:00
|
|
|
el->el_search.patlen =
|
|
|
|
(size_t)(EL_CURSOR(el) - el->el_line.buffer);
|
2000-09-05 02:06:28 +04:00
|
|
|
if (el->el_search.patlen >= EL_BUFSIZ)
|
|
|
|
el->el_search.patlen = EL_BUFSIZ - 1;
|
2020-03-30 09:56:38 +03:00
|
|
|
(void) wcsncpy(el->el_search.patbuf, el->el_line.buffer,
|
|
|
|
el->el_search.patlen);
|
|
|
|
el->el_search.patbuf[el->el_search.patlen] = '\0';
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
#ifdef SDEBUG
|
2000-09-05 02:06:28 +04:00
|
|
|
(void) fprintf(el->el_errfile, "\neventno = %d\n",
|
|
|
|
el->el_history.eventno);
|
2020-03-30 09:54:37 +03:00
|
|
|
(void) fprintf(el->el_errfile, "patlen = %ld\n", el->el_search.patlen);
|
|
|
|
(void) fprintf(el->el_errfile, "patbuf = \"%ls\"\n",
|
2000-09-05 02:06:28 +04:00
|
|
|
el->el_search.patbuf);
|
2020-03-30 09:54:37 +03:00
|
|
|
(void) fprintf(el->el_errfile, "cursor %ld lastchar %ld\n",
|
2000-09-05 02:06:28 +04:00
|
|
|
EL_CURSOR(el) - el->el_line.buffer,
|
|
|
|
el->el_line.lastchar - el->el_line.buffer);
|
1994-05-06 10:01:42 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ce_inc_search():
|
|
|
|
* Emacs incremental search
|
|
|
|
*/
|
2016-05-10 00:46:56 +03:00
|
|
|
libedit_private el_action_t
|
2000-09-05 02:06:28 +04:00
|
|
|
ce_inc_search(EditLine *el, int dir)
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
2016-04-11 03:50:13 +03:00
|
|
|
static const wchar_t STRfwd[] = L"fwd", STRbck[] = L"bck";
|
|
|
|
static wchar_t pchar = L':'; /* ':' = normal, '?' = failed */
|
|
|
|
static wchar_t endcmd[2] = {'\0', '\0'};
|
|
|
|
wchar_t *ocursor = el->el_line.cursor, oldpchar = pchar, ch;
|
|
|
|
const wchar_t *cp;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
el_action_t ret = CC_NORM;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
int ohisteventno = el->el_history.eventno;
|
2009-02-16 00:55:23 +03:00
|
|
|
size_t oldpatlen = el->el_search.patlen;
|
2000-09-05 02:06:28 +04:00
|
|
|
int newdir = dir;
|
|
|
|
int done, redo;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2009-12-31 01:37:40 +03:00
|
|
|
if (el->el_line.lastchar + sizeof(STRfwd) /
|
|
|
|
sizeof(*el->el_line.lastchar) + 2 +
|
2000-09-05 02:06:28 +04:00
|
|
|
el->el_search.patlen >= el->el_line.limit)
|
2011-07-29 19:16:33 +04:00
|
|
|
return CC_ERROR;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
for (;;) {
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
if (el->el_search.patlen == 0) { /* first round */
|
|
|
|
pchar = ':';
|
1994-05-06 10:01:42 +04:00
|
|
|
#ifdef ANCHOR
|
2003-10-17 01:41:26 +04:00
|
|
|
#define LEN 2
|
2000-09-05 02:06:28 +04:00
|
|
|
el->el_search.patbuf[el->el_search.patlen++] = '.';
|
|
|
|
el->el_search.patbuf[el->el_search.patlen++] = '*';
|
2003-10-17 01:41:26 +04:00
|
|
|
#else
|
|
|
|
#define LEN 0
|
1994-05-06 10:01:42 +04:00
|
|
|
#endif
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
|
|
|
done = redo = 0;
|
|
|
|
*el->el_line.lastchar++ = '\n';
|
2001-01-23 18:55:30 +03:00
|
|
|
for (cp = (newdir == ED_SEARCH_PREV_HISTORY) ? STRbck : STRfwd;
|
2000-09-05 02:06:28 +04:00
|
|
|
*cp; *el->el_line.lastchar++ = *cp++)
|
|
|
|
continue;
|
|
|
|
*el->el_line.lastchar++ = pchar;
|
2003-10-17 01:41:26 +04:00
|
|
|
for (cp = &el->el_search.patbuf[LEN];
|
2000-09-05 02:06:28 +04:00
|
|
|
cp < &el->el_search.patbuf[el->el_search.patlen];
|
|
|
|
*el->el_line.lastchar++ = *cp++)
|
|
|
|
continue;
|
1994-05-06 10:01:42 +04:00
|
|
|
*el->el_line.lastchar = '\0';
|
|
|
|
re_refresh(el);
|
|
|
|
|
2016-04-11 03:50:13 +03:00
|
|
|
if (el_wgetc(el, &ch) != 1)
|
2011-07-29 19:16:33 +04:00
|
|
|
return ed_end_of_file(el, 0);
|
2000-09-05 02:06:28 +04:00
|
|
|
|
|
|
|
switch (el->el_map.current[(unsigned char) ch]) {
|
|
|
|
case ED_INSERT:
|
|
|
|
case ED_DIGIT:
|
2003-10-17 01:41:26 +04:00
|
|
|
if (el->el_search.patlen >= EL_BUFSIZ - LEN)
|
2011-07-28 04:45:50 +04:00
|
|
|
terminal_beep(el);
|
2000-09-05 02:06:28 +04:00
|
|
|
else {
|
|
|
|
el->el_search.patbuf[el->el_search.patlen++] =
|
|
|
|
ch;
|
|
|
|
*el->el_line.lastchar++ = ch;
|
|
|
|
*el->el_line.lastchar = '\0';
|
|
|
|
re_refresh(el);
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-09-05 02:06:28 +04:00
|
|
|
|
|
|
|
case EM_INC_SEARCH_NEXT:
|
|
|
|
newdir = ED_SEARCH_NEXT_HISTORY;
|
|
|
|
redo++;
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
case EM_INC_SEARCH_PREV:
|
|
|
|
newdir = ED_SEARCH_PREV_HISTORY;
|
|
|
|
redo++;
|
|
|
|
break;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2004-11-04 04:16:03 +03:00
|
|
|
case EM_DELETE_PREV_CHAR:
|
2000-09-05 02:06:28 +04:00
|
|
|
case ED_DELETE_PREV_CHAR:
|
2003-10-17 01:41:26 +04:00
|
|
|
if (el->el_search.patlen > LEN)
|
2000-09-05 02:06:28 +04:00
|
|
|
done++;
|
|
|
|
else
|
2011-07-28 04:45:50 +04:00
|
|
|
terminal_beep(el);
|
2000-09-05 02:06:28 +04:00
|
|
|
break;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
default:
|
|
|
|
switch (ch) {
|
|
|
|
case 0007: /* ^G: Abort */
|
|
|
|
ret = CC_ERROR;
|
|
|
|
done++;
|
|
|
|
break;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
case 0027: /* ^W: Append word */
|
|
|
|
/* No can do if globbing characters in pattern */
|
2003-10-17 01:41:26 +04:00
|
|
|
for (cp = &el->el_search.patbuf[LEN];; cp++)
|
|
|
|
if (cp >= &el->el_search.patbuf[
|
|
|
|
el->el_search.patlen]) {
|
2000-09-05 02:06:28 +04:00
|
|
|
el->el_line.cursor +=
|
2003-10-17 01:41:26 +04:00
|
|
|
el->el_search.patlen - LEN - 1;
|
2000-09-05 02:06:28 +04:00
|
|
|
cp = c__next_word(el->el_line.cursor,
|
|
|
|
el->el_line.lastchar, 1,
|
|
|
|
ce__isword);
|
|
|
|
while (el->el_line.cursor < cp &&
|
|
|
|
*el->el_line.cursor != '\n') {
|
2003-10-17 01:41:26 +04:00
|
|
|
if (el->el_search.patlen >=
|
|
|
|
EL_BUFSIZ - LEN) {
|
2011-07-28 04:45:50 +04:00
|
|
|
terminal_beep(el);
|
2000-09-05 02:06:28 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
el->el_search.patbuf[el->el_search.patlen++] =
|
|
|
|
*el->el_line.cursor;
|
|
|
|
*el->el_line.lastchar++ =
|
|
|
|
*el->el_line.cursor++;
|
|
|
|
}
|
|
|
|
el->el_line.cursor = ocursor;
|
|
|
|
*el->el_line.lastchar = '\0';
|
|
|
|
re_refresh(el);
|
|
|
|
break;
|
|
|
|
} else if (isglob(*cp)) {
|
2011-07-28 04:45:50 +04:00
|
|
|
terminal_beep(el);
|
2000-09-05 02:06:28 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* Terminate and execute cmd */
|
|
|
|
endcmd[0] = ch;
|
2016-04-11 03:22:48 +03:00
|
|
|
el_wpush(el, endcmd);
|
2000-09-05 02:06:28 +04:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case 0033: /* ESC: Terminate */
|
|
|
|
ret = CC_REFRESH;
|
|
|
|
done++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
while (el->el_line.lastchar > el->el_line.buffer &&
|
|
|
|
*el->el_line.lastchar != '\n')
|
|
|
|
*el->el_line.lastchar-- = '\0';
|
|
|
|
*el->el_line.lastchar = '\0';
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
if (!done) {
|
|
|
|
|
|
|
|
/* Can't search if unmatched '[' */
|
|
|
|
for (cp = &el->el_search.patbuf[el->el_search.patlen-1],
|
2016-02-24 17:25:38 +03:00
|
|
|
ch = L']';
|
2003-10-17 01:41:26 +04:00
|
|
|
cp >= &el->el_search.patbuf[LEN];
|
2000-09-05 02:06:28 +04:00
|
|
|
cp--)
|
|
|
|
if (*cp == '[' || *cp == ']') {
|
|
|
|
ch = *cp;
|
|
|
|
break;
|
|
|
|
}
|
2016-02-24 17:25:38 +03:00
|
|
|
if (el->el_search.patlen > LEN && ch != L'[') {
|
2000-09-05 02:06:28 +04:00
|
|
|
if (redo && newdir == dir) {
|
|
|
|
if (pchar == '?') { /* wrap around */
|
|
|
|
el->el_history.eventno =
|
|
|
|
newdir == ED_SEARCH_PREV_HISTORY ? 0 : 0x7fffffff;
|
|
|
|
if (hist_get(el) == CC_ERROR)
|
|
|
|
/* el->el_history.event
|
|
|
|
* no was fixed by
|
|
|
|
* first call */
|
|
|
|
(void) hist_get(el);
|
|
|
|
el->el_line.cursor = newdir ==
|
|
|
|
ED_SEARCH_PREV_HISTORY ?
|
|
|
|
el->el_line.lastchar :
|
|
|
|
el->el_line.buffer;
|
|
|
|
} else
|
|
|
|
el->el_line.cursor +=
|
|
|
|
newdir ==
|
|
|
|
ED_SEARCH_PREV_HISTORY ?
|
|
|
|
-1 : 1;
|
|
|
|
}
|
|
|
|
#ifdef ANCHOR
|
|
|
|
el->el_search.patbuf[el->el_search.patlen++] =
|
|
|
|
'.';
|
|
|
|
el->el_search.patbuf[el->el_search.patlen++] =
|
|
|
|
'*';
|
|
|
|
#endif
|
|
|
|
el->el_search.patbuf[el->el_search.patlen] =
|
|
|
|
'\0';
|
|
|
|
if (el->el_line.cursor < el->el_line.buffer ||
|
|
|
|
el->el_line.cursor > el->el_line.lastchar ||
|
2003-10-19 03:27:36 +04:00
|
|
|
(ret = ce_search_line(el, newdir))
|
|
|
|
== CC_ERROR) {
|
2000-09-05 02:06:28 +04:00
|
|
|
/* avoid c_setpat */
|
|
|
|
el->el_state.lastcmd =
|
|
|
|
(el_action_t) newdir;
|
2011-08-16 20:25:15 +04:00
|
|
|
ret = (el_action_t)
|
|
|
|
(newdir == ED_SEARCH_PREV_HISTORY ?
|
2000-09-05 02:06:28 +04:00
|
|
|
ed_search_prev_history(el, 0) :
|
2011-08-16 20:25:15 +04:00
|
|
|
ed_search_next_history(el, 0));
|
2000-09-05 02:06:28 +04:00
|
|
|
if (ret != CC_ERROR) {
|
|
|
|
el->el_line.cursor = newdir ==
|
|
|
|
ED_SEARCH_PREV_HISTORY ?
|
|
|
|
el->el_line.lastchar :
|
|
|
|
el->el_line.buffer;
|
|
|
|
(void) ce_search_line(el,
|
|
|
|
newdir);
|
|
|
|
}
|
|
|
|
}
|
2003-10-17 01:41:26 +04:00
|
|
|
el->el_search.patlen -= LEN;
|
|
|
|
el->el_search.patbuf[el->el_search.patlen] =
|
2000-09-05 02:06:28 +04:00
|
|
|
'\0';
|
|
|
|
if (ret == CC_ERROR) {
|
2011-07-28 04:45:50 +04:00
|
|
|
terminal_beep(el);
|
2000-09-05 02:06:28 +04:00
|
|
|
if (el->el_history.eventno !=
|
|
|
|
ohisteventno) {
|
|
|
|
el->el_history.eventno =
|
|
|
|
ohisteventno;
|
|
|
|
if (hist_get(el) == CC_ERROR)
|
2011-07-29 19:16:33 +04:00
|
|
|
return CC_ERROR;
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
|
|
|
el->el_line.cursor = ocursor;
|
|
|
|
pchar = '?';
|
|
|
|
} else {
|
|
|
|
pchar = ':';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = ce_inc_search(el, newdir);
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
if (ret == CC_ERROR && pchar == '?' && oldpchar == ':')
|
|
|
|
/*
|
|
|
|
* break abort of failed search at last
|
|
|
|
* non-failed
|
|
|
|
*/
|
|
|
|
ret = CC_NORM;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
|
|
|
if (ret == CC_NORM || (ret == CC_ERROR && oldpatlen == 0)) {
|
|
|
|
/* restore on normal return or error exit */
|
|
|
|
pchar = oldpchar;
|
|
|
|
el->el_search.patlen = oldpatlen;
|
|
|
|
if (el->el_history.eventno != ohisteventno) {
|
|
|
|
el->el_history.eventno = ohisteventno;
|
|
|
|
if (hist_get(el) == CC_ERROR)
|
2011-07-29 19:16:33 +04:00
|
|
|
return CC_ERROR;
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
|
|
|
el->el_line.cursor = ocursor;
|
|
|
|
if (ret == CC_ERROR)
|
|
|
|
re_refresh(el);
|
|
|
|
}
|
|
|
|
if (done || ret != CC_NORM)
|
2011-07-29 19:16:33 +04:00
|
|
|
return ret;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* cv_search():
|
|
|
|
* Vi search.
|
|
|
|
*/
|
2016-05-10 00:46:56 +03:00
|
|
|
libedit_private el_action_t
|
2000-09-05 02:06:28 +04:00
|
|
|
cv_search(EditLine *el, int dir)
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
2016-04-11 03:50:13 +03:00
|
|
|
wchar_t ch;
|
|
|
|
wchar_t tmpbuf[EL_BUFSIZ];
|
2011-08-16 20:25:15 +04:00
|
|
|
ssize_t tmplen;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
|
|
|
#ifdef ANCHOR
|
2002-11-20 19:50:08 +03:00
|
|
|
tmpbuf[0] = '.';
|
|
|
|
tmpbuf[1] = '*';
|
1994-05-06 10:01:42 +04:00
|
|
|
#endif
|
2002-11-20 19:50:08 +03:00
|
|
|
tmplen = LEN;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2002-11-20 19:50:08 +03:00
|
|
|
el->el_search.patdir = dir;
|
|
|
|
|
|
|
|
tmplen = c_gets(el, &tmpbuf[LEN],
|
2016-04-11 03:22:48 +03:00
|
|
|
dir == ED_SEARCH_PREV_HISTORY ? L"\n/" : L"\n?" );
|
2002-11-20 19:50:08 +03:00
|
|
|
if (tmplen == -1)
|
|
|
|
return CC_REFRESH;
|
|
|
|
|
|
|
|
tmplen += LEN;
|
2000-09-05 02:06:28 +04:00
|
|
|
ch = tmpbuf[tmplen];
|
|
|
|
tmpbuf[tmplen] = '\0';
|
|
|
|
|
|
|
|
if (tmplen == LEN) {
|
|
|
|
/*
|
|
|
|
* Use the old pattern, but wild-card it.
|
|
|
|
*/
|
|
|
|
if (el->el_search.patlen == 0) {
|
|
|
|
re_refresh(el);
|
2011-07-29 19:16:33 +04:00
|
|
|
return CC_ERROR;
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
1994-05-06 10:01:42 +04:00
|
|
|
#ifdef ANCHOR
|
2000-09-05 02:06:28 +04:00
|
|
|
if (el->el_search.patbuf[0] != '.' &&
|
|
|
|
el->el_search.patbuf[0] != '*') {
|
2016-04-11 03:22:48 +03:00
|
|
|
(void) wcsncpy(tmpbuf, el->el_search.patbuf,
|
2009-12-31 01:37:40 +03:00
|
|
|
sizeof(tmpbuf) / sizeof(*tmpbuf) - 1);
|
2000-09-05 02:06:28 +04:00
|
|
|
el->el_search.patbuf[0] = '.';
|
|
|
|
el->el_search.patbuf[1] = '*';
|
2016-04-11 03:22:48 +03:00
|
|
|
(void) wcsncpy(&el->el_search.patbuf[2], tmpbuf,
|
2000-09-05 02:06:28 +04:00
|
|
|
EL_BUFSIZ - 3);
|
|
|
|
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';
|
|
|
|
}
|
1994-05-06 10:01:42 +04:00
|
|
|
#endif
|
2000-09-05 02:06:28 +04:00
|
|
|
} else {
|
1994-05-06 10:01:42 +04:00
|
|
|
#ifdef ANCHOR
|
2000-09-05 02:06:28 +04:00
|
|
|
tmpbuf[tmplen++] = '.';
|
|
|
|
tmpbuf[tmplen++] = '*';
|
1994-05-06 10:01:42 +04:00
|
|
|
#endif
|
2000-09-05 02:06:28 +04:00
|
|
|
tmpbuf[tmplen] = '\0';
|
2016-04-11 03:22:48 +03:00
|
|
|
(void) wcsncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1);
|
2011-08-16 20:25:15 +04:00
|
|
|
el->el_search.patlen = (size_t)tmplen;
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
|
|
|
el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
|
|
|
|
el->el_line.cursor = el->el_line.lastchar = el->el_line.buffer;
|
|
|
|
if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) :
|
2002-11-20 19:50:08 +03:00
|
|
|
ed_search_next_history(el, 0)) == CC_ERROR) {
|
2000-09-05 02:06:28 +04:00
|
|
|
re_refresh(el);
|
2011-07-29 19:16:33 +04:00
|
|
|
return CC_ERROR;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
2002-11-20 19:50:08 +03:00
|
|
|
if (ch == 0033) {
|
|
|
|
re_refresh(el);
|
|
|
|
return ed_newline(el, 0);
|
|
|
|
}
|
2011-07-29 19:16:33 +04:00
|
|
|
return CC_REFRESH;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ce_search_line():
|
|
|
|
* Look for a pattern inside a line
|
|
|
|
*/
|
2016-05-10 00:46:56 +03:00
|
|
|
libedit_private el_action_t
|
2003-10-19 03:27:36 +04:00
|
|
|
ce_search_line(EditLine *el, int dir)
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
2016-04-11 03:50:13 +03:00
|
|
|
wchar_t *cp = el->el_line.cursor;
|
|
|
|
wchar_t *pattern = el->el_search.patbuf;
|
|
|
|
wchar_t oc, *ocp;
|
2003-10-25 10:42:41 +04:00
|
|
|
#ifdef ANCHOR
|
|
|
|
ocp = &pattern[1];
|
|
|
|
oc = *ocp;
|
|
|
|
*ocp = '^';
|
|
|
|
#else
|
|
|
|
ocp = pattern;
|
|
|
|
oc = *ocp;
|
|
|
|
#endif
|
2000-09-05 02:06:28 +04:00
|
|
|
|
|
|
|
if (dir == ED_SEARCH_PREV_HISTORY) {
|
2003-10-19 03:27:36 +04:00
|
|
|
for (; cp >= el->el_line.buffer; cp--) {
|
2003-10-25 10:42:41 +04:00
|
|
|
if (el_match(cp, ocp)) {
|
|
|
|
*ocp = oc;
|
2000-09-05 02:06:28 +04:00
|
|
|
el->el_line.cursor = cp;
|
2011-07-29 19:16:33 +04:00
|
|
|
return CC_NORM;
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
2003-10-19 03:27:36 +04:00
|
|
|
}
|
2003-10-25 10:42:41 +04:00
|
|
|
*ocp = oc;
|
2011-07-29 19:16:33 +04:00
|
|
|
return CC_ERROR;
|
2000-09-05 02:06:28 +04:00
|
|
|
} else {
|
2003-10-19 03:27:36 +04:00
|
|
|
for (; *cp != '\0' && cp < el->el_line.limit; cp++) {
|
|
|
|
if (el_match(cp, ocp)) {
|
|
|
|
*ocp = oc;
|
2000-09-05 02:06:28 +04:00
|
|
|
el->el_line.cursor = cp;
|
2011-07-29 19:16:33 +04:00
|
|
|
return CC_NORM;
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
2003-10-19 03:27:36 +04:00
|
|
|
}
|
|
|
|
*ocp = oc;
|
2011-07-29 19:16:33 +04:00
|
|
|
return CC_ERROR;
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* cv_repeat_srch():
|
|
|
|
* Vi repeat search
|
|
|
|
*/
|
2016-05-10 00:46:56 +03:00
|
|
|
libedit_private el_action_t
|
From Ingo Schwarze:
As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.
Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.
Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.
With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.
This only changes internal interfaces; public ones remain unchanged.
2016-02-14 17:49:34 +03:00
|
|
|
cv_repeat_srch(EditLine *el, wint_t c)
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
2000-09-05 02:06:28 +04:00
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
#ifdef SDEBUG
|
2020-03-30 09:54:37 +03:00
|
|
|
static ct_buffer_t conv;
|
|
|
|
(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));
|
1994-05-06 10:01:42 +04:00
|
|
|
#endif
|
|
|
|
|
2000-09-05 02:06:28 +04:00
|
|
|
el->el_state.lastcmd = (el_action_t) c; /* Hack to stop c_setpat */
|
|
|
|
el->el_line.lastchar = el->el_line.buffer;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case ED_SEARCH_NEXT_HISTORY:
|
2011-07-29 19:16:33 +04:00
|
|
|
return ed_search_next_history(el, 0);
|
2000-09-05 02:06:28 +04:00
|
|
|
case ED_SEARCH_PREV_HISTORY:
|
2011-07-29 19:16:33 +04:00
|
|
|
return ed_search_prev_history(el, 0);
|
2000-09-05 02:06:28 +04:00
|
|
|
default:
|
2011-07-29 19:16:33 +04:00
|
|
|
return CC_ERROR;
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-15 17:32:32 +03:00
|
|
|
/* cv_csearch():
|
|
|
|
* Vi character search
|
1994-05-06 10:01:42 +04:00
|
|
|
*/
|
2016-05-10 00:46:56 +03:00
|
|
|
libedit_private el_action_t
|
From Ingo Schwarze:
As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.
Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.
Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.
With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.
This only changes internal interfaces; public ones remain unchanged.
2016-02-14 17:49:34 +03:00
|
|
|
cv_csearch(EditLine *el, int direction, wint_t ch, int count, int tflag)
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
2016-04-11 03:50:13 +03:00
|
|
|
wchar_t *cp;
|
2000-09-05 02:06:28 +04:00
|
|
|
|
2002-11-15 17:32:32 +03:00
|
|
|
if (ch == 0)
|
|
|
|
return CC_ERROR;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
From Ingo Schwarze:
As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.
Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.
Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.
With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.
This only changes internal interfaces; public ones remain unchanged.
2016-02-14 17:49:34 +03:00
|
|
|
if (ch == (wint_t)-1) {
|
2018-02-26 20:36:14 +03:00
|
|
|
wchar_t c;
|
|
|
|
if (el_wgetc(el, &c) != 1)
|
2002-11-15 17:32:32 +03:00
|
|
|
return ed_end_of_file(el, 0);
|
2018-02-26 20:36:14 +03:00
|
|
|
ch = c;
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
1994-05-06 10:01:42 +04:00
|
|
|
|
2002-11-15 17:32:32 +03:00
|
|
|
/* Save for ';' and ',' commands */
|
2016-04-11 03:50:13 +03:00
|
|
|
el->el_search.chacha = ch;
|
2002-11-15 17:32:32 +03:00
|
|
|
el->el_search.chadir = direction;
|
2011-08-16 20:25:15 +04:00
|
|
|
el->el_search.chatflg = (char)tflag;
|
2000-09-05 02:06:28 +04:00
|
|
|
|
|
|
|
cp = el->el_line.cursor;
|
|
|
|
while (count--) {
|
From Ingo Schwarze:
As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.
Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.
Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.
With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.
This only changes internal interfaces; public ones remain unchanged.
2016-02-14 17:49:34 +03:00
|
|
|
if ((wint_t)*cp == ch)
|
2002-11-15 17:32:32 +03:00
|
|
|
cp += direction;
|
|
|
|
for (;;cp += direction) {
|
|
|
|
if (cp >= el->el_line.lastchar)
|
|
|
|
return CC_ERROR;
|
|
|
|
if (cp < el->el_line.buffer)
|
|
|
|
return CC_ERROR;
|
From Ingo Schwarze:
As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.
Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.
Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.
With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.
This only changes internal interfaces; public ones remain unchanged.
2016-02-14 17:49:34 +03:00
|
|
|
if ((wint_t)*cp == ch)
|
2002-11-15 17:32:32 +03:00
|
|
|
break;
|
|
|
|
}
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
|
|
|
|
2002-11-15 17:32:32 +03:00
|
|
|
if (tflag)
|
|
|
|
cp -= direction;
|
2000-09-05 02:06:28 +04:00
|
|
|
|
|
|
|
el->el_line.cursor = cp;
|
|
|
|
|
2002-11-15 17:32:32 +03:00
|
|
|
if (el->el_chared.c_vcmd.action != NOP) {
|
|
|
|
if (direction > 0)
|
|
|
|
el->el_line.cursor++;
|
2000-09-05 02:06:28 +04:00
|
|
|
cv_delfini(el);
|
2002-11-15 17:32:32 +03:00
|
|
|
return CC_REFRESH;
|
2000-09-05 02:06:28 +04:00
|
|
|
}
|
2002-11-15 17:32:32 +03:00
|
|
|
return CC_CURSOR;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|