/[global]/global/libutil/find.c
ViewVC logotype

Diff of /global/libutil/find.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.56 by shigio, Tue Oct 4 07:59:04 2005 UTC revision 1.57 by shigio, Mon Oct 24 00:13:48 2005 UTC
# Line 80  static char **listarray;               /* list for sk Line 80  static char **listarray;               /* list for sk
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;
# Line 399  getdirs(const char *dir, STRBUF *sb) Line 401  getdirs(const char *dir, STRBUF *sb)
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 = ".";
# Line 433  find_open(const char *start) Line 435  find_open(const char *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                  /*                  /*
# Line 468  find_open_filelist(const char *filename, Line 470  find_open_filelist(const char *filename,
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);
# Line 546  find_read(void) Line 566  find_read(void)
566                  curp--;                  curp--;
567                  *(curp->dirp) = 0;                  *(curp->dirp) = 0;
568          }          }
569            status = END_OF_FIND;
570          return NULL;          return NULL;
571  }  }
572  /*  /*
# Line 558  find_read_filelist(void) Line 579  find_read_filelist(void)
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') {
# Line 626  find_read_filelist(void) Line 648  find_read_filelist(void)
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  }  }

Legend:
Removed from v.1.56  
changed lines
  Added in v.1.57

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26