changeset: 371:6e4d0de0ae38
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Fri Oct 08 23:36:45 2010 +0100
files: dmenu_path.c
description:
cleaned up
diff -r 69fbc9d47026 -r 6e4d0de0ae38 dmenu_path.c
--- a/dmenu_path.c Fri Oct 08 23:24:22 2010 +0100
+++ b/dmenu_path.c Fri Oct 08 23:36:45 2010 +0100
@@ -8,22 +8,21 @@
#define CACHE ".dmenu_cache"
+static void die(const char *s);
static int qstrcmp(const void *a, const void *b);
-static void die(const char *s);
static void scan(void);
static int uptodate(void);
static char **items = NULL;
-static const char *Home, *Path;
-static size_t count = 0;
+static const char *home, *path;
int
main(void) {
- if(!(Home = getenv("HOME")))
+ if(!(home = getenv("HOME")))
die("no $HOME");
- if(!(Path = getenv("PATH")))
+ if(!(path = getenv("PATH")))
die("no $PATH");
- if(chdir(Home) < 0)
+ if(chdir(home) < 0)
die("chdir failed");
if(uptodate()) {
execlp("cat", "cat", CACHE, NULL);
@@ -47,15 +46,16 @@
void
scan(void) {
char buf[PATH_MAX];
- char *dir, *path;
- size_t i;
+ char *dir, *p;
+ size_t i, count;
struct dirent *ent;
DIR *dp;
FILE *cache;
- if(!(path = strdup(Path)))
+ count = 0;
+ if(!(p = strdup(path)))
die("strdup failed");
- for(dir = strtok(path, ":"); dir; dir = strtok(NULL, ":")) {
+ for(dir = strtok(p, ":"); dir; dir = strtok(NULL, ":")) {
if(!(dp = opendir(dir)))
continue;
while((ent = readdir(dp))) {
@@ -79,23 +79,23 @@
fprintf(stdout, "%s\n", items[i]);
}
fclose(cache);
- free(path);
+ free(p);
}
int
uptodate(void) {
- char *dir, *path;
+ char *dir, *p;
time_t mtime;
struct stat st;
if(stat(CACHE, &st) < 0)
return 0;
mtime = st.st_mtime;
- if(!(path = strdup(Path)))
+ if(!(p = strdup(path)))
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)
return 0;
- free(path);
+ free(p);
return 1;
}
Received on Sat Oct 09 2010 - 00:36:47 CEST
This archive was generated by hypermail 2.2.0 : Sat Oct 09 2010 - 00:48:04 CEST