54 |
void closefilter(FILE *); |
void closefilter(FILE *); |
55 |
void completion(const char *, const char *, const char *); |
void completion(const char *, const char *, const char *); |
56 |
void idutils(const char *, const char *); |
void idutils(const char *, const char *); |
57 |
void grep(const char *); |
void grep(const char *, const char *); |
58 |
void pathlist(const char *, const char *); |
void pathlist(const char *, const char *); |
59 |
void parsefile(int, char **, const char *, const char *, const char *, int); |
void parsefile(int, char **, const char *, const char *, const char *, int); |
60 |
void printtag(FILE *, const char *); |
void printtag(FILE *, const char *); |
467 |
*/ |
*/ |
468 |
if (gflag) { |
if (gflag) { |
469 |
chdir(root); |
chdir(root); |
470 |
grep(av); |
grep(dbpath, av); |
471 |
exit(0); |
exit(0); |
472 |
} |
} |
473 |
/* |
/* |
760 |
* i) pattern POSIX regular expression |
* i) pattern POSIX regular expression |
761 |
*/ |
*/ |
762 |
void |
void |
763 |
grep(const char *pattern) |
grep(const char *dbpath, const char *pattern) |
764 |
{ |
{ |
765 |
FILE *op, *fp; |
FILE *op, *fp; |
766 |
STRBUF *ib = strbuf_open(MAXBUFLEN); |
STRBUF *ib = strbuf_open(MAXBUFLEN); |
767 |
const char *path, *p; |
const char *path; |
768 |
char edit[IDENTLEN+1]; |
char edit[IDENTLEN+1]; |
769 |
const char *buffer; |
const char *buffer; |
770 |
int linenum, count; |
int linenum, count; |
785 |
if (!(op = openfilter())) |
if (!(op = openfilter())) |
786 |
die("cannot open output filter."); |
die("cannot open output filter."); |
787 |
count = 0; |
count = 0; |
788 |
for (vfind_open(localprefix, oflag); (p = vfind_read()) != NULL; ) { |
gfind_open(dbpath, localprefix, oflag); |
789 |
path = (*p == ' ') ? ++p : p; |
while ((path = gfind_read()) != NULL) { |
790 |
if (!(fp = fopen(path, "r"))) |
if (!(fp = fopen(path, "r"))) |
791 |
die("cannot open file '%s'.", path); |
die("cannot open file '%s'.", path); |
792 |
linenum = 0; |
linenum = 0; |
809 |
} |
} |
810 |
fclose(fp); |
fclose(fp); |
811 |
} |
} |
812 |
vfind_close(); |
gfind_close(); |
813 |
closefilter(op); |
closefilter(op); |
814 |
strbuf_close(ib); |
strbuf_close(ib); |
815 |
regfree(&preg); |
regfree(&preg); |
854 |
if (!(op = openfilter())) |
if (!(op = openfilter())) |
855 |
die("cannot open output filter."); |
die("cannot open output filter."); |
856 |
count = 0; |
count = 0; |
857 |
for (vfind_open(localprefix, oflag); (p = vfind_read()) != NULL; ) { |
gfind_open(dbpath, localprefix, oflag); |
858 |
path = (*p == ' ') ? ++p : p; |
while ((path = gfind_read()) != NULL) { |
859 |
/* |
/* |
860 |
* skip localprefix because end-user doesn't see it. |
* skip localprefix because end-user doesn't see it. |
861 |
*/ |
*/ |
872 |
} |
} |
873 |
count++; |
count++; |
874 |
} |
} |
875 |
vfind_close(); |
gfind_close(); |
876 |
closefilter(op); |
closefilter(op); |
877 |
if (av) |
if (av) |
878 |
regfree(&preg); |
regfree(&preg); |
959 |
} |
} |
960 |
path -= 2; |
path -= 2; |
961 |
*path = '.'; |
*path = '.'; |
962 |
if (!gpath_path2fid(path)) { |
if (!gpath_path2fid(path, NULL)) { |
963 |
if (!qflag) |
if (!qflag) |
964 |
fprintf(stderr, "'%s' not found in GPATH.\n", path); |
fprintf(stderr, "'%s' not found in GPATH.\n", path); |
965 |
continue; |
continue; |