version 1.27, 2013/05/31 18:03:45 |
version 1.28, 2013/09/24 13:29:51 |
|
|
} |
} |
|
|
/* Compiled regex goes here-- changed only when new pattern read */ |
/* Compiled regex goes here-- changed only when new pattern read */ |
static regex_t re_buff; |
static regex_t regex_buff; |
static regmatch_t re_match[RE_NMATCH]; |
static regmatch_t regex_match[RE_NMATCH]; |
|
|
/* |
/* |
* Re-Query Replace. |
* Re-Query Replace. |
|
|
update(CMODE); |
update(CMODE); |
switch (getkey(FALSE)) { |
switch (getkey(FALSE)) { |
case ' ': |
case ' ': |
plen = re_match[0].rm_eo - re_match[0].rm_so; |
plen = regex_match[0].rm_eo - regex_match[0].rm_so; |
if (re_doreplace((RSIZE)plen, news) == FALSE) |
if (re_doreplace((RSIZE)plen, news) == FALSE) |
return (FALSE); |
return (FALSE); |
rcnt++; |
rcnt++; |
break; |
break; |
|
|
case '.': |
case '.': |
plen = re_match[0].rm_eo - re_match[0].rm_so; |
plen = regex_match[0].rm_eo - regex_match[0].rm_so; |
if (re_doreplace((RSIZE)plen, news) == FALSE) |
if (re_doreplace((RSIZE)plen, news) == FALSE) |
return (FALSE); |
return (FALSE); |
rcnt++; |
rcnt++; |
|
|
goto stopsearch; |
goto stopsearch; |
case '!': |
case '!': |
do { |
do { |
plen = re_match[0].rm_eo - re_match[0].rm_so; |
plen = regex_match[0].rm_eo - regex_match[0].rm_so; |
if (re_doreplace((RSIZE)plen, news) == FALSE) |
if (re_doreplace((RSIZE)plen, news) == FALSE) |
return (FALSE); |
return (FALSE); |
rcnt++; |
rcnt++; |
|
|
} else { |
} else { |
if (num >= RE_NMATCH) |
if (num >= RE_NMATCH) |
return (FALSE); |
return (FALSE); |
k = re_match[num].rm_eo - re_match[num].rm_so; |
k = regex_match[num].rm_eo - regex_match[num].rm_so; |
if (j + k >= REPLEN) |
if (j + k >= REPLEN) |
return (FALSE); |
return (FALSE); |
bcopy(&(clp->l_text[re_match[num].rm_so]), |
bcopy(&(clp->l_text[regex_match[num].rm_so]), |
&repstr[j], k); |
&repstr[j], k); |
j += k; |
j += k; |
if (*st == '\0') |
if (*st == '\0') |
|
|
* always makes the last line empty so this is good. |
* always makes the last line empty so this is good. |
*/ |
*/ |
while (clp != (curbp->b_headp)) { |
while (clp != (curbp->b_headp)) { |
re_match[0].rm_so = tbo; |
regex_match[0].rm_so = tbo; |
re_match[0].rm_eo = llength(clp); |
regex_match[0].rm_eo = llength(clp); |
error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, |
error = regexec(®ex_buff, ltext(clp), RE_NMATCH, regex_match, |
REG_STARTEND); |
REG_STARTEND); |
if (error != 0) { |
if (error != 0) { |
clp = lforw(clp); |
clp = lforw(clp); |
tbo = 0; |
tbo = 0; |
} else { |
} else { |
curwp->w_doto = re_match[0].rm_eo; |
curwp->w_doto = regex_match[0].rm_eo; |
curwp->w_dotp = clp; |
curwp->w_dotp = clp; |
curwp->w_rflag |= WFMOVE; |
curwp->w_rflag |= WFMOVE; |
return (TRUE); |
return (TRUE); |
|
|
* always makes the last line empty so this is good. |
* always makes the last line empty so this is good. |
*/ |
*/ |
while (clp != (curbp->b_headp)) { |
while (clp != (curbp->b_headp)) { |
re_match[0].rm_so = 0; |
regex_match[0].rm_so = 0; |
re_match[0].rm_eo = llength(clp); |
regex_match[0].rm_eo = llength(clp); |
lastmatch.rm_so = -1; |
lastmatch.rm_so = -1; |
/* |
/* |
* Keep searching until we don't match any longer. Assumes a |
* Keep searching until we don't match any longer. Assumes a |
* non-match does not modify the re_match array. We have to |
* non-match does not modify the regex_match array. We have to |
* do this character-by-character after the first match since |
* do this character-by-character after the first match since |
* POSIX regexps don't give you a way to do reverse matches. |
* POSIX regexps don't give you a way to do reverse matches. |
*/ |
*/ |
while (!regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, |
while (!regexec(®ex_buff, ltext(clp), RE_NMATCH, regex_match, |
REG_STARTEND) && re_match[0].rm_so < tbo) { |
REG_STARTEND) && regex_match[0].rm_so < tbo) { |
memcpy(&lastmatch, &re_match[0], sizeof(regmatch_t)); |
memcpy(&lastmatch, ®ex_match[0], sizeof(regmatch_t)); |
re_match[0].rm_so++; |
regex_match[0].rm_so++; |
re_match[0].rm_eo = llength(clp); |
regex_match[0].rm_eo = llength(clp); |
} |
} |
if (lastmatch.rm_so == -1) { |
if (lastmatch.rm_so == -1) { |
clp = lback(clp); |
clp = lback(clp); |
tbo = llength(clp); |
tbo = llength(clp); |
} else { |
} else { |
memcpy(&re_match[0], &lastmatch, sizeof(regmatch_t)); |
memcpy(®ex_match[0], &lastmatch, sizeof(regmatch_t)); |
curwp->w_doto = re_match[0].rm_so; |
curwp->w_doto = regex_match[0].rm_so; |
curwp->w_dotp = clp; |
curwp->w_dotp = clp; |
curwp->w_rflag |= WFMOVE; |
curwp->w_rflag |= WFMOVE; |
return (TRUE); |
return (TRUE); |
|
|
else |
else |
flags = REG_EXTENDED; |
flags = REG_EXTENDED; |
if (dofree) |
if (dofree) |
regfree(&re_buff); |
regfree(®ex_buff); |
error = regcomp(&re_buff, re_pat, flags); |
error = regcomp(®ex_buff, re_pat, flags); |
if (error != 0) { |
if (error != 0) { |
char message[256]; |
char message[256]; |
regerror(error, &re_buff, message, sizeof(message)); |
regerror(error, ®ex_buff, message, sizeof(message)); |
ewprintf("Regex Error: %s", message); |
ewprintf("Regex Error: %s", message); |
re_pat[0] = '\0'; |
re_pat[0] = '\0'; |
return (FALSE); |
return (FALSE); |
|
|
|
|
while (clp != (curbp->b_headp)) { |
while (clp != (curbp->b_headp)) { |
/* see if line matches */ |
/* see if line matches */ |
re_match[0].rm_so = 0; |
regex_match[0].rm_so = 0; |
re_match[0].rm_eo = llength(clp); |
regex_match[0].rm_eo = llength(clp); |
error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, |
error = regexec(®ex_buff, ltext(clp), RE_NMATCH, regex_match, |
REG_STARTEND); |
REG_STARTEND); |
|
|
/* Delete line when appropriate */ |
/* Delete line when appropriate */ |
|
|
|
|
while (clp != (curbp->b_headp)) { |
while (clp != (curbp->b_headp)) { |
/* see if line matches */ |
/* see if line matches */ |
re_match[0].rm_so = 0; |
regex_match[0].rm_so = 0; |
re_match[0].rm_eo = llength(clp); |
regex_match[0].rm_eo = llength(clp); |
error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, |
error = regexec(®ex_buff, ltext(clp), RE_NMATCH, regex_match, |
REG_STARTEND); |
REG_STARTEND); |
|
|
/* Count line when appropriate */ |
/* Count line when appropriate */ |