[BACK]Return to re_search.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Diff for /src/usr.bin/mg/re_search.c between version 1.8 and 1.9

version 1.8, 2001/05/23 22:20:36 version 1.9, 2001/05/24 03:05:25
Line 6 
Line 6 
  * 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.
  */   */
Line 41 
Line 41 
   
 /*  /*
  * 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 */
Line 87 
Line 87 
 }  }
   
 /*  /*
  * 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
Line 110 
Line 110 
                 }                  }
                 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);
Line 143 
Line 143 
   
         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)
Line 216 
Line 216 
  */   */
 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;
Line 273 
Line 273 
                                 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')
Line 302 
Line 302 
   
   
 /*  /*
  * 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.
  */   */
Line 332 
Line 332 
         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);
Line 350 
Line 350 
   
 /*  /*
  * 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
Line 486 
Line 486 
 {  {
         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);
   
Line 503 
Line 503 
 {  {
         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);
   
Line 511 
Line 511 
         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)
Line 531 
Line 531 
                 /* 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 */
Line 607 
Line 607 
                 /* 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 */

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9