[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.27 and 1.28

version 1.27, 2013/05/31 18:03:45 version 1.28, 2013/09/24 13:29:51
Line 120 
Line 120 
 }  }
   
 /* 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.
Line 152 
Line 152 
                 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++;
Line 173 
Line 173 
                         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++;
Line 262 
Line 262 
                         } 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')
Line 320 
Line 320 
          * 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(&regex_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);
Line 366 
Line 366 
          * 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(&regex_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, &regex_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(&regex_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);
Line 425 
Line 425 
                 else                  else
                         flags = REG_EXTENDED;                          flags = REG_EXTENDED;
                 if (dofree)                  if (dofree)
                         regfree(&re_buff);                          regfree(&regex_buff);
                 error = regcomp(&re_buff, re_pat, flags);                  error = regcomp(&regex_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, &regex_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);
Line 519 
Line 519 
   
         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(&regex_buff, ltext(clp), RE_NMATCH, regex_match,
                     REG_STARTEND);                      REG_STARTEND);
   
                 /* Delete line when appropriate */                  /* Delete line when appropriate */
Line 594 
Line 594 
   
         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(&regex_buff, ltext(clp), RE_NMATCH, regex_match,
                     REG_STARTEND);                      REG_STARTEND);
   
                 /* Count line when appropriate */                  /* Count line when appropriate */

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28