diff options
| -rw-r--r-- | dmenu_path.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/dmenu_path.c b/dmenu_path.c index 1575f1d..15d0da0 100644 --- a/dmenu_path.c +++ b/dmenu_path.c | |||
| @@ -8,22 +8,21 @@ | |||
| 8 | 8 | ||
| 9 | #define CACHE ".dmenu_cache" | 9 | #define CACHE ".dmenu_cache" |
| 10 | 10 | ||
| 11 | static int qstrcmp(const void *a, const void *b); | ||
| 12 | static void die(const char *s); | 11 | static void die(const char *s); |
| 12 | static int qstrcmp(const void *a, const void *b); | ||
| 13 | static void scan(void); | 13 | static void scan(void); |
| 14 | static int uptodate(void); | 14 | static int uptodate(void); |
| 15 | 15 | ||
| 16 | static char **items = NULL; | 16 | static char **items = NULL; |
| 17 | static const char *Home, *Path; | 17 | static const char *home, *path; |
| 18 | static size_t count = 0; | ||
| 19 | 18 | ||
| 20 | int | 19 | int |
| 21 | main(void) { | 20 | main(void) { |
| 22 | if(!(Home = getenv("HOME"))) | 21 | if(!(home = getenv("HOME"))) |
| 23 | die("no $HOME"); | 22 | die("no $HOME"); |
| 24 | if(!(Path = getenv("PATH"))) | 23 | if(!(path = getenv("PATH"))) |
| 25 | die("no $PATH"); | 24 | die("no $PATH"); |
| 26 | if(chdir(Home) < 0) | 25 | if(chdir(home) < 0) |
| 27 | die("chdir failed"); | 26 | die("chdir failed"); |
| 28 | if(uptodate()) { | 27 | if(uptodate()) { |
| 29 | execlp("cat", "cat", CACHE, NULL); | 28 | execlp("cat", "cat", CACHE, NULL); |
| @@ -47,15 +46,16 @@ qstrcmp(const void *a, const void *b) { | |||
| 47 | void | 46 | void |
| 48 | scan(void) { | 47 | scan(void) { |
| 49 | char buf[PATH_MAX]; | 48 | char buf[PATH_MAX]; |
| 50 | char *dir, *path; | 49 | char *dir, *p; |
| 51 | size_t i; | 50 | size_t i, count; |
| 52 | struct dirent *ent; | 51 | struct dirent *ent; |
| 53 | DIR *dp; | 52 | DIR *dp; |
| 54 | FILE *cache; | 53 | FILE *cache; |
| 55 | 54 | ||
| 56 | if(!(path = strdup(Path))) | 55 | count = 0; |
| 56 | if(!(p = strdup(path))) | ||
| 57 | die("strdup failed"); | 57 | die("strdup failed"); |
| 58 | for(dir = strtok(path, ":"); dir; dir = strtok(NULL, ":")) { | 58 | for(dir = strtok(p, ":"); dir; dir = strtok(NULL, ":")) { |
| 59 | if(!(dp = opendir(dir))) | 59 | if(!(dp = opendir(dir))) |
| 60 | continue; | 60 | continue; |
| 61 | while((ent = readdir(dp))) { | 61 | while((ent = readdir(dp))) { |
| @@ -79,23 +79,23 @@ scan(void) { | |||
| 79 | fprintf(stdout, "%s\n", items[i]); | 79 | fprintf(stdout, "%s\n", items[i]); |
| 80 | } | 80 | } |
| 81 | fclose(cache); | 81 | fclose(cache); |
| 82 | free(path); | 82 | free(p); |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | int | 85 | int |
| 86 | uptodate(void) { | 86 | uptodate(void) { |
| 87 | char *dir, *path; | 87 | char *dir, *p; |
| 88 | time_t mtime; | 88 | time_t mtime; |
| 89 | struct stat st; | 89 | struct stat st; |
| 90 | 90 | ||
| 91 | if(stat(CACHE, &st) < 0) | 91 | if(stat(CACHE, &st) < 0) |
| 92 | return 0; | 92 | return 0; |
| 93 | mtime = st.st_mtime; | 93 | mtime = st.st_mtime; |
| 94 | if(!(path = strdup(Path))) | 94 | if(!(p = strdup(path))) |
| 95 | die("strdup failed"); | 95 | die("strdup failed"); |
| 96 | for(dir = strtok(path, ":"); dir; dir = strtok(NULL, ":")) | 96 | for(dir = strtok(p, ":"); dir; dir = strtok(NULL, ":")) |
| 97 | if(!stat(dir, &st) && st.st_mtime > mtime) | 97 | if(!stat(dir, &st) && st.st_mtime > mtime) |
| 98 | return 0; | 98 | return 0; |
| 99 | free(path); | 99 | free(p); |
| 100 | return 1; | 100 | return 1; |
| 101 | } | 101 | } |
