version 1.52, 2015/12/14 20:02:07 |
version 1.53, 2015/12/22 17:07:06 |
|
|
#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> |
|
|
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 |
|
|
|
|
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, |
|
|
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, |
|
|
/* 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 || |
|
|
|
|
#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 |