Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
10 static void die(const char *s
);
11 static int qstrcmp(const void *a
, const void *b
);
12 static void scan(void);
13 static int uptodate(void);
15 static char **items
= NULL
;
16 static const char *home
, *path
;
20 if(!(home
= getenv("HOME")))
22 if(!(path
= getenv("PATH")))
27 execl("/bin/cat", "cat", CACHE
, NULL
);
36 fprintf(stderr
, "dmenu_path: %s\n", s
);
41 qstrcmp(const void *a
, const void *b
) {
42 return strcmp(*(const char **)a
, *(const char **)b
);
55 if(!(p
= strdup(path
)))
57 for(dir
= strtok(p
, ":"); dir
; dir
= strtok(NULL
, ":")) {
58 if(!(dp
= opendir(dir
)))
60 while((ent
= readdir(dp
))) {
61 snprintf(buf
, sizeof buf
, "%s/%s", dir
, ent
->d_name
);
62 if(ent
->d_name
[0] == '.' || access(buf
, X_OK
) < 0)
64 if(!(items
= realloc(items
, ++count
* sizeof *items
)))
66 if(!(items
[count
-1] = strdup(ent
->d_name
)))
71 qsort(items
, count
, sizeof *items
, qstrcmp
);
72 if(!(cache
= fopen(CACHE
, "w")))
74 for(i
= 0; i
< count
; i
++) {
75 if(i
> 0 && !strcmp(items
[i
], items
[i
-1]))
77 fprintf(cache
, "%s\n", items
[i
]);
78 fprintf(stdout
, "%s\n", items
[i
]);
90 if(stat(CACHE
, &st
) < 0)
93 if(!(p
= strdup(path
)))
95 for(dir
= strtok(p
, ":"); dir
; dir
= strtok(NULL
, ":"))
96 if(!stat(dir
, &st
) && st
.st_mtime
> mtime
)