80 |
static FILE *ip; |
static FILE *ip; |
81 |
static FILE *temp; |
static FILE *temp; |
82 |
static char rootdir[MAXPATHLEN+1]; |
static char rootdir[MAXPATHLEN+1]; |
83 |
static int opened; |
static int status; |
84 |
#define FIND_OPEN 1 |
#define FIND_OPEN 1 |
85 |
#define FILELIST_OPEN 2 |
#define FILELIST_OPEN 2 |
86 |
|
#define END_OF_FIND 3 |
87 |
|
|
88 |
static void trim(char *); |
static void trim(char *); |
89 |
|
static char *find_read_traverse(void); |
90 |
static char *find_read_filelist(void); |
static char *find_read_filelist(void); |
91 |
|
|
92 |
extern int qflag; |
extern int qflag; |
401 |
void |
void |
402 |
find_open(const char *start) |
find_open(const char *start) |
403 |
{ |
{ |
404 |
assert(opened == 0); |
assert(status == 0); |
405 |
opened = FIND_OPEN; |
status = FIND_OPEN; |
406 |
|
|
407 |
if (!start) |
if (!start) |
408 |
start = "."; |
start = "."; |
435 |
void |
void |
436 |
find_open_filelist(const char *filename, const char *root) |
find_open_filelist(const char *filename, const char *root) |
437 |
{ |
{ |
438 |
assert(opened == 0); |
assert(status == 0); |
439 |
opened = FILELIST_OPEN; |
status = FILELIST_OPEN; |
440 |
|
|
441 |
if (!strcmp(filename, "-")) { |
if (!strcmp(filename, "-")) { |
442 |
/* |
/* |
470 |
* |
* |
471 |
* r) path |
* r) path |
472 |
*/ |
*/ |
473 |
char * |
char * |
474 |
find_read(void) |
find_read(void) |
475 |
{ |
{ |
476 |
|
static char *path; |
477 |
|
|
478 |
|
assert(status != 0); |
479 |
|
if (status == END_OF_FIND) |
480 |
|
path = NULL; |
481 |
|
else if (status == FILELIST_OPEN) |
482 |
|
path = find_read_filelist(); |
483 |
|
else if (status == FIND_OPEN) |
484 |
|
path = find_read_traverse(); |
485 |
|
else |
486 |
|
die("find_read: internal error."); |
487 |
|
return path; |
488 |
|
} |
489 |
|
/* |
490 |
|
* find_read_traverse: read path without GPATH. |
491 |
|
* |
492 |
|
* r) path |
493 |
|
*/ |
494 |
|
char * |
495 |
|
find_read_traverse(void) |
496 |
|
{ |
497 |
static char val[MAXPATHLEN+1]; |
static char val[MAXPATHLEN+1]; |
498 |
|
|
|
assert(opened != 0); |
|
|
if (opened == FILELIST_OPEN) |
|
|
return find_read_filelist(); |
|
499 |
for (;;) { |
for (;;) { |
500 |
while (curp->p < curp->end) { |
while (curp->p < curp->end) { |
501 |
char type = *(curp->p); |
char type = *(curp->p); |
566 |
curp--; |
curp--; |
567 |
*(curp->dirp) = 0; |
*(curp->dirp) = 0; |
568 |
} |
} |
569 |
|
status = END_OF_FIND; |
570 |
return NULL; |
return NULL; |
571 |
} |
} |
572 |
/* |
/* |
579 |
{ |
{ |
580 |
STATIC_STRBUF(ib); |
STATIC_STRBUF(ib); |
581 |
static char buf[MAXPATHLEN + 1]; |
static char buf[MAXPATHLEN + 1]; |
582 |
char *path; |
static char *path; |
583 |
|
|
584 |
strbuf_clear(ib); |
strbuf_clear(ib); |
585 |
for (;;) { |
for (;;) { |
586 |
path = strbuf_fgets(ib, ip, STRBUF_NOCRLF); |
path = strbuf_fgets(ib, ip, STRBUF_NOCRLF); |
587 |
if (path == NULL) { |
if (path == NULL) { |
588 |
/* EOF */ |
/* EOF */ |
589 |
|
status = END_OF_FIND; |
590 |
return NULL; |
return NULL; |
591 |
} |
} |
592 |
if (*path == '\0') { |
if (*path == '\0') { |
648 |
void |
void |
649 |
find_close(void) |
find_close(void) |
650 |
{ |
{ |
651 |
assert(opened != 0); |
assert(status != 0); |
652 |
if (opened == FIND_OPEN) { |
if (status == FIND_OPEN) { |
653 |
for (curp = &stack[0]; curp < topp; curp++) |
for (curp = &stack[0]; curp < topp; curp++) |
654 |
if (curp->sb != NULL) |
if (curp->sb != NULL) |
655 |
strbuf_close(curp->sb); |
strbuf_close(curp->sb); |
656 |
} else if (opened == FILELIST_OPEN) { |
} else if (status == FILELIST_OPEN) { |
657 |
/* |
/* |
658 |
* The --file=- option is specified, we don't close file |
* The --file=- option is specified, we don't close file |
659 |
* to read it repeatedly. |
* to read it repeatedly. |
660 |
*/ |
*/ |
661 |
if (ip != temp) |
if (ip != temp) |
662 |
fclose(ip); |
fclose(ip); |
663 |
} else { |
} else if (status != END_OF_FIND) { |
664 |
die("illegal find_close"); |
die("illegal find_close"); |
665 |
} |
} |
666 |
regfree(suff); |
regfree(suff); |
667 |
if (skip) |
if (skip) |
668 |
regfree(skip); |
regfree(skip); |
669 |
opened = 0; |
status = 0; |
670 |
} |
} |