[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.52 and 1.53

version 1.52, 2015/12/14 20:02:07 version 1.53, 2015/12/22 17:07:06
Line 34 
Line 34 
 #include <errno.h>  #include <errno.h>
 #include <fts.h>  #include <fts.h>
 #include <regex.h>  #include <regex.h>
   #include <stdbool.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
Line 50 
Line 51 
 static int      procline(str_t *l, int);  static int      procline(str_t *l, int);
 static int      grep_search(fastgrep_t *, 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 char *, const char *, size_t);  static bool     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 485 
Line 486 
                                 j = 0;                                  j = 0;
                         if (!((fg->bol && fg->eol) && (dataLen != fg->patternLen)))                          if (!((fg->bol && fg->eol) && (dataLen != fg->patternLen)))
                                 if (grep_cmp(fg->pattern, data + j,                                  if (grep_cmp(fg->pattern, data + j,
                                     fg->patternLen) == -1) {                                      fg->patternLen)) {
                                         pmatch->rm_so = j;                                          pmatch->rm_so = j;
                                         pmatch->rm_eo = j + fg->patternLen;                                          pmatch->rm_eo = j + fg->patternLen;
                                         if (!fg->wmatch || wmatch(data, dataLen,                                          if (!fg->wmatch || wmatch(data, dataLen,
Line 498 
Line 499 
                 j = dataLen;                  j = dataLen;
                 do {                  do {
                         if (grep_cmp(fg->pattern, data + j - fg->patternLen,                          if (grep_cmp(fg->pattern, data + j - fg->patternLen,
                             fg->patternLen) == -1) {                              fg->patternLen)) {
                                 pmatch->rm_so = j - fg->patternLen;                                  pmatch->rm_so = j - fg->patternLen;
                                 pmatch->rm_eo = j;                                  pmatch->rm_eo = j;
                                 if (!fg->wmatch || wmatch(data, dataLen,                                  if (!fg->wmatch || wmatch(data, dataLen,
Line 516 
Line 517 
                 /* Quick Search algorithm. */                  /* Quick Search algorithm. */
                 j = 0;                  j = 0;
                 do {                  do {
                         if (grep_cmp(fg->pattern, data + j, fg->patternLen) == -1) {                          if (grep_cmp(fg->pattern, data + j, fg->patternLen)) {
                                 pmatch->rm_so = j;                                  pmatch->rm_so = j;
                                 pmatch->rm_eo = j + fg->patternLen;                                  pmatch->rm_eo = j + fg->patternLen;
                                 if (fg->patternLen == 0 || !fg->wmatch ||                                  if (fg->patternLen == 0 || !fg->wmatch ||
Line 578 
Line 579 
   
 #ifndef SMALL  #ifndef SMALL
 /*  /*
  * Returns:     i >= 0 on failure (position that it failed)   * Returns:     true on success, false on failure
  *              -1 on success  
  */   */
 static int  static bool
 grep_cmp(const char *pattern, const char *data, size_t len)  grep_cmp(const char *pattern, const char *data, size_t len)
 {  {
         int i;          size_t i;
   
         for (i = 0; i < len; i++) {          for (i = 0; i < len; i++) {
                 if (((pattern[i] == data[i]) || (!Fflag && pattern[i] == '.'))                  if (((pattern[i] == data[i]) || (!Fflag && pattern[i] == '.'))
                     || (iflag && pattern[i] == toupper(data[i])))                      || (iflag && pattern[i] == toupper(data[i])))
                         continue;                          continue;
                 return (i);                  return false;
         }          }
   
         return (-1);          return true;
 }  }
   
 static void  static void

Legend:
Removed from v.1.52  
changed lines
  Added in v.1.53