909 |
{ |
{ |
910 |
char buf[MAXPATHLEN+1], *path; |
char buf[MAXPATHLEN+1], *path; |
911 |
FILE *op; |
FILE *op; |
|
const char *parser, *av; |
|
912 |
int count; |
int count; |
913 |
STRBUF *sb = strbuf_open(0); |
STRBUF *comline = strbuf_open(0); |
914 |
STRBUF *path_list = strbuf_open(MAXPATHLEN); |
STRBUF *path_list = strbuf_open(MAXPATHLEN); |
915 |
int path_list_max; |
int path_list_max; |
916 |
|
|
922 |
/* |
/* |
923 |
* get parser. |
* get parser. |
924 |
*/ |
*/ |
925 |
if (!getconfs(dbname(db), sb)) |
if (!getconfs(dbname(db), comline)) |
926 |
die("cannot get parser for %s.", dbname(db)); |
die("cannot get parser for %s.", dbname(db)); |
|
parser = strbuf_value(sb); |
|
|
|
|
927 |
/* |
/* |
928 |
* determine the maximum length of the list of paths. |
* determine the maximum length of the list of paths. |
929 |
*/ |
*/ |
933 |
if (path_list_max > 20 * 1024) |
if (path_list_max > 20 * 1024) |
934 |
path_list_max = 20 * 1024; |
path_list_max = 20 * 1024; |
935 |
path_list_max -= env_size(); |
path_list_max -= env_size(); |
936 |
path_list_max -= strbuf_getlen(sb); |
path_list_max -= strbuf_getlen(comline); |
937 |
path_list_max -= 40; |
path_list_max -= 40; |
938 |
if (path_list_max < 0) |
if (path_list_max < 0) |
939 |
path_list_max = 0; |
path_list_max = 0; |
947 |
die("GPATH not found."); |
die("GPATH not found."); |
948 |
count = 0; |
count = 0; |
949 |
for (; argc > 0; argv++, argc--) { |
for (; argc > 0; argv++, argc--) { |
950 |
av = argv[0]; |
const char *av = argv[0]; |
951 |
|
|
952 |
if (!test("f", av)) { |
if (!test("f", av)) { |
953 |
if (test("d", av)) { |
if (test("d", av)) { |
954 |
if (!qflag) |
if (!qflag) |
979 |
fprintf(stderr, "'%s' not found in GPATH.\n", path); |
fprintf(stderr, "'%s' not found in GPATH.\n", path); |
980 |
continue; |
continue; |
981 |
} |
} |
982 |
|
/* |
983 |
if (strbuf_getlen(path_list) |
* Execute parser when path name collects enough. |
984 |
&& strbuf_getlen(path_list) + strlen(path) > path_list_max) { |
* Though the path_list is \0 separated list of string, |
985 |
count += exec_parser(parser, path_list, cwd, root, op); |
* we can think its length equals to the length of |
986 |
strbuf_reset(path_list); |
* argument string because each \0 can be replaced |
987 |
|
* with a blank. |
988 |
|
*/ |
989 |
|
if (strbuf_getlen(path_list)) { |
990 |
|
if (strbuf_getlen(path_list) + strlen(path) > path_list_max) { |
991 |
|
count += exec_parser(strbuf_value(comline), path_list, cwd, root, op); |
992 |
|
strbuf_reset(path_list); |
993 |
|
} |
994 |
} |
} |
995 |
|
/* |
996 |
|
* Add a path to the path list. |
997 |
|
*/ |
998 |
strbuf_puts0(path_list, path); |
strbuf_puts0(path_list, path); |
999 |
} |
} |
1000 |
if (strbuf_getlen(path_list)) |
if (strbuf_getlen(path_list)) |
1001 |
count += exec_parser(parser, path_list, cwd, root, op); |
count += exec_parser(strbuf_value(comline), path_list, cwd, root, op); |
1002 |
gpath_close(); |
gpath_close(); |
1003 |
closefilter(op); |
closefilter(op); |
1004 |
strbuf_close(sb); |
strbuf_close(comline); |
1005 |
strbuf_close(path_list); |
strbuf_close(path_list); |
1006 |
if (vflag) { |
if (vflag) { |
1007 |
if (count == 0) |
if (count == 0) |