[pcre-dev] pcregrep --include does not recurse

トップ ページ
このメッセージを削除
著者: Mike Huffman
日付:  
To: pcre-dev
題目: [pcre-dev] pcregrep --include does not recurse
pcregrep 7.6 built with gcc (GCC) 4.1.2 20061115 (prerelease) (Debian
4.1.1- 21), tested on Linux; MS Visual C++ 6.0 (sp5), tested on Windows XP:
the --include option does not recurse into sub- directories with -r or
-d recurse, while --exclude works as expected.

I studied and added various debug print statements in and around the
while loop at about line 1400 in the grep_or_recurse() function in
pcregrep.c and cannot figure out why --exclude works as expected, but
--include will not recurse. Maybe someone with a better understanding of
recursing directory trees will have an explanation.

In any event, removing the tests for include/exclude from the loop and
inserting them BELOW the loop in the else if clause (with applicable
changes) as shown below seems to have solved the problem:

/* Control reaches here if we have a regular file ...

pathlen = strlen(pathname);

  if (exclude_compiled != NULL &&
      pcre_exec(exclude_compiled, NULL, pathname, pathlen, 0, 0, NULL, 
0) >= 0)
    return rc;


  if (include_compiled != NULL &&
      pcre_exec(include_compiled, NULL, pathname, pathlen, 0, 0, NULL, 
0) < 0)
    return rc;


Compiled and tested in the same environments as stated above --include
seems to be working.

Mike