58 const char *outfile = NULL;
62 while (*argv && argv[0][0] ==
'-') {
63 if (strcmp(argv[0],
"--rebuild") == 0) {
68 if (strcmp(argv[0],
"--preload") == 0) {
73 if (strcmp(argv[0],
"--out") == 0) {
75 zwarnnam(nam,
"--out requires an argument");
82 if (strcmp(argv[0],
"--") == 0) {
104 if (outfile && !rebuild) {
105 FILE *rf = fopen(outfile,
"r");
111 if (fgets(line,
sizeof(line), rf) &&
112 strncmp(line,
"# zpmod fpath-index v1", 22) == 0) {
127 while (fgets(line,
sizeof(line), rf)) {
128 if (strncmp(line,
"# dir ", 6) != 0) {
136 long mt_recorded = 0;
138 if (sscanf(line,
"# %7s %d %2047s %ld", tag, &i_hdr, pathbuf,
139 &mt_recorded) != 4) {
145 if (strcmp(tag,
"dir") != 0 || i_hdr != idx) {
151 if (!fpath[idx] || strcmp(fpath[idx], pathbuf) != 0) {
167 if (stat(fpath[idx], &st_now) == 0) {
168 mt_current = (long)st_now.st_mtime;
173 if (mt_current != mt_recorded) {
192 if (header_ok && fpath[idx] == NULL) {
204 for (
int i = 0; i < idx; i++) {
205 DIR *d = opendir(fpath[i]);
211 while ((de = readdir(d))) {
212 if (de->d_name[0] ==
'.' || de->d_name[0] ==
'_') {
218 Shfunc sf = (Shfunc)
zalloc(
sizeof(*sf));
223 memset(sf, 0,
sizeof(*sf));
225 sf->filename =
ztrdup(fpath[i]);
240 FILE *out_fp = stdout;
242 out_fp = fopen(outfile,
"w");
244 zwarnnam(nam,
"cannot open for writing: %s", outfile);
247 fprintf(out_fp,
"# zpmod fpath-index v1\n");
253 for (
int i = 0; fpath[i]; ++i) {
255 if (stat(fpath[i], &st) == 0) {
256 mt = (long)st.st_mtime;
258 fprintf(out_fp,
"# dir %d %s %ld\n", i, fpath[i], mt);
262 for (
int i = 0; fpath[i]; i++) {
263 DIR *d = opendir(fpath[i]);
268 while ((de = readdir(d))) {
269 if (de->d_name[0] ==
'.' || de->d_name[0] ==
'_') {
273 #ifdef ZSH_OOT_MODULE
278 Shfunc sf = (Shfunc)
zalloc(
sizeof(*sf));
282 memset(sf, 0,
sizeof(*sf));
284 sf->filename =
ztrdup(fpath[i]);
289 fprintf(out_fp,
"%s %s/%s\n", de->d_name, fpath[i], de->d_name);
295 if (outfile && out_fp != stdout) {
int cmd_fpath_index(char *nam, char **argv)
Implements zpmod fpath-index with intelligent skip detection.
Module declaration header (mdh) for zpmod.
Prototype stub for zpmod when building out-of-tree.
void * zalloc(size_t size)
char * dupstring(const char *s)
char ** getaparam(const char *name)
void zwarnnam(const char *, const char *,...)
HashNode gethashnode2(HashTable, const char *)
void addhashnode(HashTable, char *, void *)
char * ztrdup(const char *)
Local, non-invasive shims to suppress benign vendor header warnings.