Don't depend on BSD regexec extensions (REG_STARTEND)
Emulate it if it is not defined.
This commit is contained in:
parent
32d43c9cf0
commit
aab07b7582
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: search.c,v 1.3 1998/01/09 08:07:08 perry Exp $ */
|
||||
/* $NetBSD: search.c,v 1.4 2000/03/17 02:23:17 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
@ -153,6 +153,9 @@ f_search(sp, fm, rm, ptrn, eptrn, flags)
|
||||
size_t coff, len;
|
||||
int cnt, eval, rval, wrapped;
|
||||
char *l;
|
||||
#ifndef REG_STARTEND
|
||||
char c;
|
||||
#endif
|
||||
|
||||
if (search_setup(sp, FORWARD, ptrn, eptrn, flags))
|
||||
return (1);
|
||||
@ -226,17 +229,28 @@ f_search(sp, fm, rm, ptrn, eptrn, flags)
|
||||
if (len != 0 && coff == len)
|
||||
continue;
|
||||
|
||||
#ifdef REG_STARTEND
|
||||
/* Set the termination. */
|
||||
match[0].rm_so = coff;
|
||||
match[0].rm_eo = len;
|
||||
#else
|
||||
c = l[len];
|
||||
l[len] = '\0';
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG) && 0
|
||||
TRACE(sp, "F search: %lu from %u to %u\n",
|
||||
lno, coff, len != 0 ? len - 1 : len);
|
||||
#endif
|
||||
/* Search the line. */
|
||||
#ifdef REG_STARTEND
|
||||
eval = regexec(&sp->re_c, l, 1, match,
|
||||
(match[0].rm_so == 0 ? 0 : REG_NOTBOL) | REG_STARTEND);
|
||||
#else
|
||||
eval = regexec(&sp->re_c, &l[coff], 1, match,
|
||||
(match[0].rm_so == 0 ? 0 : REG_NOTBOL));
|
||||
l[len] = c;
|
||||
#endif
|
||||
if (eval == REG_NOMATCH)
|
||||
continue;
|
||||
if (eval != 0) {
|
||||
@ -319,6 +333,9 @@ b_search(sp, fm, rm, ptrn, eptrn, flags)
|
||||
size_t coff, last, len;
|
||||
int cnt, eval, rval, wrapped;
|
||||
char *l;
|
||||
#ifndef REG_STARTEND
|
||||
char c;
|
||||
#endif
|
||||
|
||||
if (search_setup(sp, BACKWARD, ptrn, eptrn, flags))
|
||||
return (1);
|
||||
@ -387,15 +404,26 @@ b_search(sp, fm, rm, ptrn, eptrn, flags)
|
||||
break;
|
||||
|
||||
/* Set the termination. */
|
||||
#ifdef REG_STARTEND
|
||||
match[0].rm_so = 0;
|
||||
match[0].rm_eo = len;
|
||||
#else
|
||||
c = l[len];
|
||||
l[len] = '\0';
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG) && 0
|
||||
TRACE(sp, "B search: %lu from 0 to %qu\n", lno, match[0].rm_eo);
|
||||
#endif
|
||||
/* Search the line. */
|
||||
#ifdef REG_STARTEND
|
||||
eval = regexec(&sp->re_c, l, 1, match,
|
||||
(match[0].rm_eo == len ? 0 : REG_NOTEOL) | REG_STARTEND);
|
||||
#else
|
||||
eval = regexec(&sp->re_c, l, 1, match,
|
||||
(match[0].rm_eo == len ? 0 : REG_NOTEOL));
|
||||
l[len] = c;
|
||||
#endif
|
||||
if (eval == REG_NOMATCH)
|
||||
continue;
|
||||
if (eval != 0) {
|
||||
@ -432,10 +460,18 @@ b_search(sp, fm, rm, ptrn, eptrn, flags)
|
||||
last = match[0].rm_so++;
|
||||
if (match[0].rm_so >= len)
|
||||
break;
|
||||
#ifdef REG_STARTEND
|
||||
match[0].rm_eo = len;
|
||||
eval = regexec(&sp->re_c, l, 1, match,
|
||||
(match[0].rm_so == 0 ? 0 : REG_NOTBOL) |
|
||||
REG_STARTEND);
|
||||
#else
|
||||
c = l[len];
|
||||
l[len] = '\0';
|
||||
eval = regexec(&sp->re_c, &l[last + 1], 1, match,
|
||||
(match[0].rm_so == 0 ? 0 : REG_NOTBOL));
|
||||
l[len] = c;
|
||||
#endif
|
||||
if (eval == REG_NOMATCH)
|
||||
break;
|
||||
if (eval != 0) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ex_global.c,v 1.7 1998/01/09 08:07:49 perry Exp $ */
|
||||
/* $NetBSD: ex_global.c,v 1.8 2000/03/17 02:23:17 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
@ -82,6 +82,9 @@ ex_g_setup(sp, cmdp, cmd)
|
||||
size_t len;
|
||||
int cnt, delim, eval;
|
||||
char *ptrn, *p, *t;
|
||||
#ifndef REG_STARTEND
|
||||
char c;
|
||||
#endif
|
||||
|
||||
NEEDFILE(sp, cmdp);
|
||||
|
||||
@ -217,9 +220,17 @@ usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
|
||||
}
|
||||
if (db_get(sp, start, DBG_FATAL, &p, &len))
|
||||
return (1);
|
||||
#ifdef REG_STARTEND
|
||||
match[0].rm_so = 0;
|
||||
match[0].rm_eo = len;
|
||||
switch (eval = regexec(&sp->re_c, p, 0, match, REG_STARTEND)) {
|
||||
eval = regexec(&sp->re_c, p, 0, match, REG_STARTEND);
|
||||
#else
|
||||
c = p[len];
|
||||
p[len] = '\0';
|
||||
eval = regexec(&sp->re_c, p, 0, match, 0);
|
||||
p[len] = c;
|
||||
#endif
|
||||
switch (eval) {
|
||||
case 0:
|
||||
if (cmd == V)
|
||||
continue;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ex_subst.c,v 1.11 1998/01/09 08:08:05 perry Exp $ */
|
||||
/* $NetBSD: ex_subst.c,v 1.12 2000/03/17 02:23:17 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
@ -365,6 +365,9 @@ s(sp, cmdp, s, re, flags)
|
||||
int didsub, do_eol_match, eflags, empty_ok, eval;
|
||||
int linechanged, matched, quit, rval;
|
||||
char *bp, *lb;
|
||||
#ifndef REG_STARTEND
|
||||
char c;
|
||||
#endif
|
||||
|
||||
NEEDFILE(sp, cmdp);
|
||||
|
||||
@ -550,7 +553,11 @@ noargs: if (F_ISSET(sp, SC_VI) && sp->c_suffix && (lflag || nflag || pflag)) {
|
||||
do_eol_match = 1;
|
||||
|
||||
/* It's not nul terminated, but we pretend it is. */
|
||||
#ifdef REG_STARTEND
|
||||
eflags = REG_STARTEND;
|
||||
#else
|
||||
eflags = 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The search area is from s + offset to the EOL.
|
||||
@ -559,11 +566,20 @@ noargs: if (F_ISSET(sp, SC_VI) && sp->c_suffix && (lflag || nflag || pflag)) {
|
||||
* of the match from the start of the search, and offset
|
||||
* is the offset of the start of the last search.
|
||||
*/
|
||||
nextmatch: match[0].rm_so = 0;
|
||||
nextmatch:
|
||||
#ifdef REG_STARTEND
|
||||
match[0].rm_so = 0;
|
||||
match[0].rm_eo = len;
|
||||
|
||||
#else
|
||||
c = ((char *)s)[len];
|
||||
((char *)s)[len] = '\0';
|
||||
#endif
|
||||
/* Get the next match. */
|
||||
eval = regexec(re, (char *)s + offset, 10, match, eflags);
|
||||
#ifndef REG_STARTEND
|
||||
((char *)s)[len] = c;
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* There wasn't a match or if there was an error, deal with
|
||||
|
Loading…
Reference in New Issue
Block a user