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