mirror of
https://git.savannah.gnu.org/git/make.git
synced 2025-02-07 06:47:52 +00:00
Formerly dir.c.~5~
This commit is contained in:
parent
29002aca14
commit
8140043344
1 changed files with 64 additions and 0 deletions
64
dir.c
64
dir.c
|
@ -490,3 +490,67 @@ print_dir_data_base ()
|
||||||
printf ("%u", impossible);
|
printf ("%u", impossible);
|
||||||
printf (" impossibilities in %u directories.\n", dirs);
|
printf (" impossibilities in %u directories.\n", dirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Hooks for globbing. */
|
||||||
|
|
||||||
|
#include <glob.h>
|
||||||
|
|
||||||
|
/* Structure describing state of iterating through a directory hash table. */
|
||||||
|
|
||||||
|
struct dirstream
|
||||||
|
{
|
||||||
|
struct directory_contents *contents; /* The directory being read. */
|
||||||
|
|
||||||
|
unsigned int bucket; /* Current hash bucket. */
|
||||||
|
struct dirfile *elt; /* Current elt in bucket. */
|
||||||
|
};
|
||||||
|
|
||||||
|
static __ptr_t
|
||||||
|
open_dirstream (directory)
|
||||||
|
const char *directory;
|
||||||
|
{
|
||||||
|
struct dirstream *new;
|
||||||
|
struct directory *dir = find_directory (directory);
|
||||||
|
|
||||||
|
if (dir->contents == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Read all the contents of the directory now. There is no benefit
|
||||||
|
in being lazy, since glob will want to see every file anyway. */
|
||||||
|
|
||||||
|
(void) dir_contents_file_exists_p (dir->contents, (char *) 0);
|
||||||
|
|
||||||
|
new = (struct dirstream *) xmalloc (sizeof (struct dirstream));
|
||||||
|
new->contents = dir->contents;
|
||||||
|
new->bucket = 0;
|
||||||
|
new->elt = new->contents->files[0];
|
||||||
|
|
||||||
|
return new;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
read_dirstream (stream)
|
||||||
|
__ptr_t stream;
|
||||||
|
{
|
||||||
|
struct dirstream *const ds = (struct dirstream *) stream;
|
||||||
|
register struct dirfile *df;
|
||||||
|
|
||||||
|
while (ds->bucket < DIRFILE_BUCKETS)
|
||||||
|
{
|
||||||
|
while ((df = ds->elt) != 0)
|
||||||
|
{
|
||||||
|
ds->elt = df->next;
|
||||||
|
if (!df->impossible)
|
||||||
|
return df->name;
|
||||||
|
}
|
||||||
|
ds->elt = ds->contents->files[++ds->bucket];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
init_dir ()
|
||||||
|
{
|
||||||
|
__glob_opendir_hook = open_dirstream;
|
||||||
|
__glob_readdir_hook = read_dirstream;
|
||||||
|
__glob_closedir_hook = free;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue