mirror of git://git.suckless.org/dmenu
cleaned up
This commit is contained in:
parent
bf7b8e37ee
commit
e0add428d2
30
dmenu_path.c
30
dmenu_path.c
|
@ -8,22 +8,21 @@
|
||||||
|
|
||||||
#define CACHE ".dmenu_cache"
|
#define CACHE ".dmenu_cache"
|
||||||
|
|
||||||
static int qstrcmp(const void *a, const void *b);
|
|
||||||
static void die(const char *s);
|
static void die(const char *s);
|
||||||
|
static int qstrcmp(const void *a, const void *b);
|
||||||
static void scan(void);
|
static void scan(void);
|
||||||
static int uptodate(void);
|
static int uptodate(void);
|
||||||
|
|
||||||
static char **items = NULL;
|
static char **items = NULL;
|
||||||
static const char *Home, *Path;
|
static const char *home, *path;
|
||||||
static size_t count = 0;
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void) {
|
main(void) {
|
||||||
if(!(Home = getenv("HOME")))
|
if(!(home = getenv("HOME")))
|
||||||
die("no $HOME");
|
die("no $HOME");
|
||||||
if(!(Path = getenv("PATH")))
|
if(!(path = getenv("PATH")))
|
||||||
die("no $PATH");
|
die("no $PATH");
|
||||||
if(chdir(Home) < 0)
|
if(chdir(home) < 0)
|
||||||
die("chdir failed");
|
die("chdir failed");
|
||||||
if(uptodate()) {
|
if(uptodate()) {
|
||||||
execlp("cat", "cat", CACHE, NULL);
|
execlp("cat", "cat", CACHE, NULL);
|
||||||
|
@ -47,15 +46,16 @@ qstrcmp(const void *a, const void *b) {
|
||||||
void
|
void
|
||||||
scan(void) {
|
scan(void) {
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
char *dir, *path;
|
char *dir, *p;
|
||||||
size_t i;
|
size_t i, count;
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
FILE *cache;
|
FILE *cache;
|
||||||
|
|
||||||
if(!(path = strdup(Path)))
|
count = 0;
|
||||||
|
if(!(p = strdup(path)))
|
||||||
die("strdup failed");
|
die("strdup failed");
|
||||||
for(dir = strtok(path, ":"); dir; dir = strtok(NULL, ":")) {
|
for(dir = strtok(p, ":"); dir; dir = strtok(NULL, ":")) {
|
||||||
if(!(dp = opendir(dir)))
|
if(!(dp = opendir(dir)))
|
||||||
continue;
|
continue;
|
||||||
while((ent = readdir(dp))) {
|
while((ent = readdir(dp))) {
|
||||||
|
@ -79,23 +79,23 @@ scan(void) {
|
||||||
fprintf(stdout, "%s\n", items[i]);
|
fprintf(stdout, "%s\n", items[i]);
|
||||||
}
|
}
|
||||||
fclose(cache);
|
fclose(cache);
|
||||||
free(path);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
uptodate(void) {
|
uptodate(void) {
|
||||||
char *dir, *path;
|
char *dir, *p;
|
||||||
time_t mtime;
|
time_t mtime;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if(stat(CACHE, &st) < 0)
|
if(stat(CACHE, &st) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
mtime = st.st_mtime;
|
mtime = st.st_mtime;
|
||||||
if(!(path = strdup(Path)))
|
if(!(p = strdup(path)))
|
||||||
die("strdup failed");
|
die("strdup failed");
|
||||||
for(dir = strtok(path, ":"); dir; dir = strtok(NULL, ":"))
|
for(dir = strtok(p, ":"); dir; dir = strtok(NULL, ":"))
|
||||||
if(!stat(dir, &st) && st.st_mtime > mtime)
|
if(!stat(dir, &st) && st.st_mtime > mtime)
|
||||||
return 0;
|
return 0;
|
||||||
free(path);
|
free(p);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue