version 1.8, 2001/05/23 22:20:36 |
version 1.9, 2001/05/24 03:05:25 |
|
|
* This file contains functions to implement several of gnuemacs's regular |
* This file contains functions to implement several of gnuemacs's regular |
* expression functions for Mg. Several of the routines below are just minor |
* expression functions for Mg. Several of the routines below are just minor |
* re-arrangements of Mg's non-regular expression search functions. Some of |
* re-arrangements of Mg's non-regular expression search functions. Some of |
* them are similar in structure to the original MicroEMACS, others are |
* them are similar in structure to the original MicroEMACS, others are |
* modifications of Rich Ellison's code. Peter Newton re-wrote about half of |
* modifications of Rich Ellison's code. Peter Newton re-wrote about half of |
* them from scratch. |
* them from scratch. |
*/ |
*/ |
|
|
|
|
/* |
/* |
* Search forward. |
* Search forward. |
* Get a search string from the user and search for it starting at ".". If |
* Get a search string from the user and search for it starting at ".". If |
* found, move "." to just after the matched characters. display does all |
* found, move "." to just after the matched characters. display does all |
* the hard stuff. If not found, it just prints a message. |
* the hard stuff. If not found, it just prints a message. |
*/ |
*/ |
/* ARGSUSED */ |
/* ARGSUSED */ |
|
|
} |
} |
|
|
/* |
/* |
* Search again, using the same search string and direction as the last search |
* Search again, using the same search string and direction as the last search |
* command. The direction has been saved in "srch_lastdir", so you know which |
* command. The direction has been saved in "srch_lastdir", so you know which |
* way to go. |
* way to go. |
* |
* |
* XXX: This code has problems -- some incompatibility(?) with extend.c causes |
* XXX: This code has problems -- some incompatibility(?) with extend.c causes |
|
|
} |
} |
return (TRUE); |
return (TRUE); |
} |
} |
if (re_srch_lastdir == SRCH_BACK) |
if (re_srch_lastdir == SRCH_BACK) |
if (re_backsrch() == FALSE) { |
if (re_backsrch() == FALSE) { |
ewprintf("Search failed: \"%s\"", re_pat); |
ewprintf("Search failed: \"%s\"", re_pat); |
return (FALSE); |
return (FALSE); |
|
|
|
|
if ((s = re_readpattern("RE Query replace")) != TRUE) |
if ((s = re_readpattern("RE Query replace")) != TRUE) |
return (s); |
return (s); |
if ((s = |
if ((s = |
ereply("Query replace %s with: ", news, NPAT, re_pat)) == ABORT) |
ereply("Query replace %s with: ", news, NPAT, re_pat)) == ABORT) |
return (s); |
return (s); |
if (s == FALSE) |
if (s == FALSE) |
|
|
*/ |
*/ |
static int |
static int |
re_doreplace(plen, st, f) |
re_doreplace(plen, st, f) |
RSIZE plen; /* length to remove */ |
RSIZE plen; /* length to remove */ |
char *st; /* replacement string */ |
char *st; /* replacement string */ |
int f; /* case hack disable */ |
int f; /* case hack disable */ |
{ |
{ |
int j, k, s, more, num, state; |
int j, k, s, more, num, state; |
LINE *clp; |
LINE *clp; |
|
|
k = re_match[num].rm_eo - re_match[num].rm_so; |
k = re_match[num].rm_eo - re_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[re_match[num].rm_so]), |
&repstr[j], k); |
&repstr[j], k); |
j += k; |
j += k; |
if (*st == '\0') |
if (*st == '\0') |
|
|
|
|
|
|
/* |
/* |
* This routine does the real work of a forward search. The pattern is |
* This routine does the real work of a forward search. The pattern is |
* sitting in the external variable "pat". If found, dot is updated, the |
* sitting in the external variable "pat". If found, dot is updated, the |
* window system is notified of the change, and TRUE is returned. If the |
* window system is notified of the change, and TRUE is returned. If the |
* string isn't found, FALSE is returned. |
* string isn't found, FALSE is returned. |
*/ |
*/ |
|
|
while (clp != (curbp->b_linep)) { |
while (clp != (curbp->b_linep)) { |
re_match[0].rm_so = tbo; |
re_match[0].rm_so = tbo; |
re_match[0].rm_eo = llength(clp); |
re_match[0].rm_eo = llength(clp); |
error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, |
error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, |
REG_STARTEND); |
REG_STARTEND); |
if (error != 0) { |
if (error != 0) { |
clp = lforw(clp); |
clp = lforw(clp); |
|
|
|
|
/* |
/* |
* This routine does the real work of a backward search. The pattern is sitting |
* This routine does the real work of a backward search. The pattern is sitting |
* in the external variable "re_pat". If found, dot is updated, the window |
* in the external variable "re_pat". If found, dot is updated, the window |
* system is notified of the change, and TRUE is returned. If the string isn't |
* system is notified of the change, and TRUE is returned. If the string isn't |
* found, FALSE is returned. |
* found, FALSE is returned. |
*/ |
*/ |
static int |
static int |
|
|
{ |
{ |
int s; |
int s; |
|
|
if ((s = re_readpattern("Flush lines (containing match for regexp)")) |
if ((s = re_readpattern("Flush lines (containing match for regexp)")) |
!= TRUE) |
!= TRUE) |
return (s); |
return (s); |
|
|
|
|
{ |
{ |
int s; |
int s; |
|
|
if ((s = re_readpattern("Keep lines (containing match for regexp)")) |
if ((s = re_readpattern("Keep lines (containing match for regexp)")) |
!= TRUE) |
!= TRUE) |
return (s); |
return (s); |
|
|
|
|
return (s); |
return (s); |
} |
} |
|
|
/* |
/* |
* This function does the work of deleting matching lines |
* This function does the work of deleting matching lines |
*/ |
*/ |
static int |
static int |
killmatches(cond) |
killmatches(cond) |
|
|
/* see if line matches */ |
/* see if line matches */ |
re_match[0].rm_so = 0; |
re_match[0].rm_so = 0; |
re_match[0].rm_eo = llength(clp); |
re_match[0].rm_eo = llength(clp); |
error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, |
error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, |
REG_STARTEND); |
REG_STARTEND); |
|
|
/* Delete line when appropriate */ |
/* Delete line when appropriate */ |
|
|
/* see if line matches */ |
/* see if line matches */ |
re_match[0].rm_so = 0; |
re_match[0].rm_so = 0; |
re_match[0].rm_eo = llength(clp); |
re_match[0].rm_eo = llength(clp); |
error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, |
error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, |
REG_STARTEND); |
REG_STARTEND); |
|
|
/* Count line when appropriate */ |
/* Count line when appropriate */ |