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

Diff for /src/usr.bin/grep/util.c between version 1.39 and 1.40

version 1.39, 2010/07/02 22:18:03 version 1.40, 2011/07/08 01:20:24
Line 48 
Line 48 
   
 static int      linesqueued;  static int      linesqueued;
 static int      procline(str_t *l, int);  static int      procline(str_t *l, int);
 static int      grep_search(fastgrep_t *, unsigned char *, size_t, regmatch_t *pmatch);  static int      grep_search(fastgrep_t *, char *, size_t, regmatch_t *pmatch);
 #ifndef SMALL  #ifndef SMALL
 static int      grep_cmp(const unsigned char *, const unsigned char *, size_t);  static int      grep_cmp(const char *, const char *, size_t);
 static void     grep_revstr(unsigned char *, int);  static void     grep_revstr(unsigned char *, int);
 #endif  #endif
   
Line 169 
Line 169 
 {  {
         regmatch_t      pmatch;          regmatch_t      pmatch;
         int             c, i, r;          int             c, i, r;
           int             offset;
   
           c = 0;
           i = 0;
         if (matchall) {          if (matchall) {
                 c = !vflag;  
                 goto print;                  goto print;
         }          }
   
         for (c = i = 0; i < patterns; i++) {          for (i = 0; i < patterns; i++) {
                   offset = 0;
   redo:
                 if (fg_pattern[i].pattern) {                  if (fg_pattern[i].pattern) {
                         r = grep_search(&fg_pattern[i], (unsigned char *)l->dat,                          r = grep_search(&fg_pattern[i], l->dat + offset,
                             l->len, &pmatch);                              l->len - offset, &pmatch);
                           pmatch.rm_so += offset;
                           pmatch.rm_eo += offset;
                 } else {                  } else {
                         pmatch.rm_so = 0;                          pmatch.rm_so = offset;
                         pmatch.rm_eo = l->len;                          pmatch.rm_eo = l->len - offset;
                         r = regexec(&r_pattern[i], l->dat, 1, &pmatch, eflags);                          r = regexec(&r_pattern[i], l->dat, 1, &pmatch, eflags);
                 }                  }
                 if (r == 0 && xflag) {                  if (r == 0 && xflag) {
Line 189 
Line 195 
                                 r = REG_NOMATCH;                                  r = REG_NOMATCH;
                 }                  }
                 if (r == 0) {                  if (r == 0) {
                         c++;                          c = 1;
                           if (oflag)
                                   goto print;
                         break;                          break;
                 }                  }
         }          }
           if (oflag)
                   return c;
   print:
         if (vflag)          if (vflag)
                 c = !c;                  c = !c;
   
 print:  
         if (c && binbehave == BIN_FILE_BIN && nottext)          if (c && binbehave == BIN_FILE_BIN && nottext)
                 return c; /* Binary file */                  return c; /* Binary file */
   
Line 210 
Line 220 
                         if (Bflag > 0)                          if (Bflag > 0)
                                 printqueue();                                  printqueue();
                         linesqueued = 0;                          linesqueued = 0;
                         printline(l, ':');                          printline(l, ':', oflag ? &pmatch : NULL);
                 } else {                  } else {
                         printline(l, '-');                          printline(l, '-', oflag ? &pmatch : NULL);
                         tail--;                          tail--;
                 }                  }
         }          }
           if (oflag && !matchall) {
                   offset = pmatch.rm_eo;
                   goto redo;
           }
         return c;          return c;
 }  }
   
Line 424 
Line 438 
           e > s && isword(d[s]) && isword(d[e-1]))            e > s && isword(d[s]) && isword(d[e-1]))
   
 static int  static int
 grep_search(fastgrep_t *fg, unsigned char *data, size_t dataLen, regmatch_t *pmatch)  grep_search(fastgrep_t *fg, char *data, size_t dataLen, regmatch_t *pmatch)
 {  {
 #ifdef SMALL  #ifdef SMALL
         return 0;          return 0;
Line 476 
Line 490 
                         /* Shift if within bounds, otherwise, we are done. */                          /* Shift if within bounds, otherwise, we are done. */
                         if (j == fg->patternLen)                          if (j == fg->patternLen)
                                 break;                                  break;
                         j -= fg->qsBc[data[j - fg->patternLen - 1]];                          j -= fg->qsBc[(unsigned char)data[j - fg->patternLen - 1]];
                 } while (j >= fg->patternLen);                  } while (j >= fg->patternLen);
         } else {          } else {
                 /* Quick Search algorithm. */                  /* Quick Search algorithm. */
Line 497 
Line 511 
                         if (j + fg->patternLen == dataLen)                          if (j + fg->patternLen == dataLen)
                                 break;                                  break;
                         else                          else
                                 j += fg->qsBc[data[j + fg->patternLen]];                                  j += fg->qsBc[(unsigned char)data[j + fg->patternLen]];
                 } while (j <= (dataLen - fg->patternLen));                  } while (j <= (dataLen - fg->patternLen));
         }          }
   
Line 540 
Line 554 
  *              -1 on success   *              -1 on success
  */   */
 static int  static int
 grep_cmp(const unsigned char *pattern, const unsigned char *data, size_t len)  grep_cmp(const char *pattern, const char *data, size_t len)
 {  {
         int i;          int i;
   
Line 569 
Line 583 
 #endif  #endif
   
 void  void
 printline(str_t *line, int sep)  printline(str_t *line, int sep, regmatch_t *pmatch)
 {  {
         int n;          int n;
   
Line 592 
Line 606 
         }          }
         if (n)          if (n)
                 putchar(sep);                  putchar(sep);
         fwrite(line->dat, line->len, 1, stdout);          if (pmatch)
                   fwrite(line->dat + pmatch->rm_so,
                       pmatch->rm_eo - pmatch->rm_so, 1, stdout);
           else
                   fwrite(line->dat, line->len, 1, stdout);
         putchar('\n');          putchar('\n');
 }  }

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.40