summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bfs.h88
-rw-r--r--bftw.c128
-rw-r--r--bftw.h27
-rw-r--r--color.c28
-rw-r--r--color.h10
-rw-r--r--eval.c72
-rw-r--r--main.c2
-rw-r--r--parse.c158
8 files changed, 254 insertions, 259 deletions
diff --git a/bfs.h b/bfs.h
index a8efffb..15f25ee 100644
--- a/bfs.h
+++ b/bfs.h
@@ -18,19 +18,14 @@
#include <time.h>
/**
- * The parsed command line.
- */
-typedef struct cmdline cmdline;
-
-/**
* A command line expression.
*/
-typedef struct expression expression;
+struct expr;
/**
* Ephemeral state for evaluating an expression.
*/
-typedef struct eval_state eval_state;
+struct eval_state;
/**
* Expression evaluation function.
@@ -42,8 +37,11 @@ typedef struct eval_state eval_state;
* @return
* The result of the test.
*/
-typedef bool eval_fn(const expression *expr, eval_state *state);
+typedef bool eval_fn(const struct expr *expr, struct eval_state *state);
+/**
+ * The parsed command line.
+ */
struct cmdline {
/** The array of paths to start from. */
const char **roots;
@@ -51,7 +49,7 @@ struct cmdline {
size_t nroots;
/** Color data. */
- color_table *colors;
+ struct color_table *colors;
/** -color option. */
bool color;
@@ -64,7 +62,7 @@ struct cmdline {
int flags;
/** The command line expression. */
- expression *expr;
+ struct expr *expr;
/** The current time. */
struct timespec now;
@@ -73,24 +71,24 @@ struct cmdline {
/**
* Possible types of numeric comparison.
*/
-typedef enum {
+enum cmpflag {
/** Exactly n. */
CMP_EXACT,
/** Less than n. */
CMP_LESS,
/** Greater than n. */
CMP_GREATER,
-} cmpflag;
+};
-struct expression {
+struct expr {
/** The left hand side of the expression. */
- expression *lhs;
+ struct expr *lhs;
/** The right hand side of the expression. */
- expression *rhs;
+ struct expr *rhs;
/** The function that evaluates this expression. */
eval_fn *eval;
/** The comparison flag. */
- cmpflag cmp;
+ enum cmpflag cmp;
/** Optional integer data for this expression. */
int idata;
/** Optional string data for this expression. */
@@ -100,52 +98,52 @@ struct expression {
/**
* Parse the command line.
*/
-cmdline *parse_cmdline(int argc, char *argv[]);
+struct cmdline *parse_cmdline(int argc, char *argv[]);
/**
* Evaluate the command line.
*/
-int eval_cmdline(cmdline *cl);
+int eval_cmdline(struct cmdline *cl);
/**
* Free the parsed command line.
*/
-void free_cmdline(cmdline *cl);
+void free_cmdline(struct cmdline *cl);
// Predicate evaluation functions
-bool eval_true(const expression *expr, eval_state *state);
-bool eval_false(const expression *expr, eval_state *state);
+bool eval_true(const struct expr *expr, struct eval_state *state);
+bool eval_false(const struct expr *expr, struct eval_state *state);
-bool eval_access(const expression *expr, eval_state *state);
+bool eval_access(const struct expr *expr, struct eval_state *state);
-bool eval_amin(const expression *expr, eval_state *state);
-bool eval_atime(const expression *expr, eval_state *state);
-bool eval_cmin(const expression *expr, eval_state *state);
-bool eval_ctime(const expression *expr, eval_state *state);
-bool eval_mmin(const expression *expr, eval_state *state);
-bool eval_mtime(const expression *expr, eval_state *state);
+bool eval_amin(const struct expr *expr, struct eval_state *state);
+bool eval_atime(const struct expr *expr, struct eval_state *state);
+bool eval_cmin(const struct expr *expr, struct eval_state *state);
+bool eval_ctime(const struct expr *expr, struct eval_state *state);
+bool eval_mmin(const struct expr *expr, struct eval_state *state);
+bool eval_mtime(const struct expr *expr, struct eval_state *state);
-bool eval_gid(const expression *expr, eval_state *state);
-bool eval_uid(const expression *expr, eval_state *state);
+bool eval_gid(const struct expr *expr, struct eval_state *state);
+bool eval_uid(const struct expr *expr, struct eval_state *state);
-bool eval_empty(const expression *expr, eval_state *state);
-bool eval_hidden(const expression *expr, eval_state *state);
-bool eval_type(const expression *expr, eval_state *state);
+bool eval_empty(const struct expr *expr, struct eval_state *state);
+bool eval_hidden(const struct expr *expr, struct eval_state *state);
+bool eval_type(const struct expr *expr, struct eval_state *state);
-bool eval_name(const expression *expr, eval_state *state);
-bool eval_path(const expression *expr, eval_state *state);
+bool eval_name(const struct expr *expr, struct eval_state *state);
+bool eval_path(const struct expr *expr, struct eval_state *state);
-bool eval_delete(const expression *expr, eval_state *state);
-bool eval_nohidden(const expression *expr, eval_state *state);
-bool eval_print(const expression *expr, eval_state *state);
-bool eval_print0(const expression *expr, eval_state *state);
-bool eval_prune(const expression *expr, eval_state *state);
-bool eval_quit(const expression *expr, eval_state *state);
+bool eval_delete(const struct expr *expr, struct eval_state *state);
+bool eval_nohidden(const struct expr *expr, struct eval_state *state);
+bool eval_print(const struct expr *expr, struct eval_state *state);
+bool eval_print0(const struct expr *expr, struct eval_state *state);
+bool eval_prune(const struct expr *expr, struct eval_state *state);
+bool eval_quit(const struct expr *expr, struct eval_state *state);
// Operator evaluation functions
-bool eval_not(const expression *expr, eval_state *state);
-bool eval_and(const expression *expr, eval_state *state);
-bool eval_or(const expression *expr, eval_state *state);
-bool eval_comma(const expression *expr, eval_state *state);
+bool eval_not(const struct expr *expr, struct eval_state *state);
+bool eval_and(const struct expr *expr, struct eval_state *state);
+bool eval_or(const struct expr *expr, struct eval_state *state);
+bool eval_comma(const struct expr *expr, struct eval_state *state);
#endif // BFS_H
diff --git a/bftw.c b/bftw.c
index 5e22ddc..99e26e1 100644
--- a/bftw.c
+++ b/bftw.c
@@ -37,21 +37,21 @@
/**
* Simple dynamically-sized string type.
*/
-typedef struct {
+struct dynstr {
char *str;
size_t length;
size_t capacity;
-} dynstr;
+};
/** Initialize a dynstr. */
-static void dynstr_init(dynstr *dstr) {
+static void dynstr_init(struct dynstr *dstr) {
dstr->str = NULL;
dstr->length = 0;
dstr->capacity = 0;
}
/** Grow a dynstr to the given capacity if necessary. */
-static int dynstr_grow(dynstr *dstr, size_t length) {
+static int dynstr_grow(struct dynstr *dstr, size_t length) {
if (length >= dstr->capacity) {
size_t new_capacity = 3*(length + 1)/2;
char *new_str = realloc(dstr->str, new_capacity);
@@ -67,7 +67,7 @@ static int dynstr_grow(dynstr *dstr, size_t length) {
}
/** Concatenate a string to a dynstr at the given position. */
-static int dynstr_concat(dynstr *dstr, size_t pos, const char *more) {
+static int dynstr_concat(struct dynstr *dstr, size_t pos, const char *more) {
size_t morelen = strlen(more);
size_t length = pos + morelen;
if (dynstr_grow(dstr, length) != 0) {
@@ -80,25 +80,23 @@ static int dynstr_concat(dynstr *dstr, size_t pos, const char *more) {
}
/** Free a dynstr. */
-static void dynstr_free(dynstr *dstr) {
+static void dynstr_free(struct dynstr *dstr) {
free(dstr->str);
}
/**
* A single entry in the dircache.
*/
-typedef struct dircache_entry dircache_entry;
-
struct dircache_entry {
/** The parent entry, if any. */
- dircache_entry *parent;
+ struct dircache_entry *parent;
/** This directory's depth in the walk. */
size_t depth;
/** Previous node in the LRU list. */
- dircache_entry *lru_prev;
+ struct dircache_entry *lru_prev;
/** Next node in the LRU list. */
- dircache_entry *lru_next;
+ struct dircache_entry *lru_next;
/** The DIR pointer, if open. */
DIR *dir;
@@ -117,26 +115,26 @@ struct dircache_entry {
/**
* A directory cache.
*/
-typedef struct {
+struct dircache {
/** Most recently used entry. */
- dircache_entry *lru_head;
+ struct dircache_entry *lru_head;
/** Least recently used entry. */
- dircache_entry *lru_tail;
+ struct dircache_entry *lru_tail;
/** Remaining LRU list capacity. */
size_t lru_remaining;
-} dircache;
+};
/** Initialize a dircache. */
-static void dircache_init(dircache *cache, size_t lru_size) {
+static void dircache_init(struct dircache *cache, size_t lru_size) {
assert(lru_size > 0);
cache->lru_head = cache->lru_tail = NULL;
cache->lru_remaining = lru_size;
}
/** Add an entry to the dircache. */
-static dircache_entry *dircache_add(dircache *cache, dircache_entry *parent, const char *name) {
+static struct dircache_entry *dircache_add(struct dircache *cache, struct dircache_entry *parent, const char *name) {
size_t namelen = strlen(name);
- size_t size = sizeof(dircache_entry) + namelen + 1;
+ size_t size = sizeof(struct dircache_entry) + namelen + 1;
bool needs_slash = false;
if (namelen == 0 || name[namelen - 1] != '/') {
@@ -144,7 +142,7 @@ static dircache_entry *dircache_add(dircache *cache, dircache_entry *parent, con
++size;
}
- dircache_entry *entry = malloc(size);
+ struct dircache_entry *entry = malloc(size);
if (!entry) {
return NULL;
}
@@ -179,7 +177,7 @@ static dircache_entry *dircache_add(dircache *cache, dircache_entry *parent, con
}
/** Add an entry to the head of the LRU list. */
-static void dircache_lru_add(dircache *cache, dircache_entry *entry) {
+static void dircache_lru_add(struct dircache *cache, struct dircache_entry *entry) {
assert(entry->dir);
assert(entry->lru_prev == NULL);
assert(entry->lru_next == NULL);
@@ -199,7 +197,7 @@ static void dircache_lru_add(dircache *cache, dircache_entry *entry) {
}
/** Remove an entry from the LRU list. */
-static void dircache_lru_remove(dircache *cache, dircache_entry *entry) {
+static void dircache_lru_remove(struct dircache *cache, struct dircache_entry *entry) {
if (entry->lru_prev) {
assert(cache->lru_head != entry);
entry->lru_prev->lru_next = entry->lru_next;
@@ -222,7 +220,7 @@ static void dircache_lru_remove(dircache *cache, dircache_entry *entry) {
}
/** Close a dircache_entry and remove it from the LRU list. */
-static void dircache_entry_close(dircache *cache, dircache_entry *entry) {
+static void dircache_entry_close(struct dircache *cache, struct dircache_entry *entry) {
dircache_lru_remove(cache, entry);
closedir(entry->dir);
entry->dir = NULL;
@@ -250,7 +248,7 @@ static DIR *opendirat(int fd, const char *name) {
* @param[out] path
* Will hold the full path to the entry, with a trailing '/'.
*/
-static int dircache_entry_path(const dircache_entry *entry, dynstr *path) {
+static int dircache_entry_path(const struct dircache_entry *entry, struct dynstr *path) {
size_t namelen = entry->namelen;
size_t pathlen = entry->nameoff + namelen;
@@ -285,8 +283,8 @@ static int dircache_entry_path(const dircache_entry *entry, dynstr *path) {
* Will hold the appropriate path to use.
* @return The closest open ancestor entry.
*/
-static dircache_entry *dircache_entry_base(dircache *cache, dircache_entry *entry, int *at_fd, const char **at_path) {
- dircache_entry *base = entry;
+static struct dircache_entry *dircache_entry_base(struct dircache *cache, struct dircache_entry *entry, int *at_fd, const char **at_path) {
+ struct dircache_entry *base = entry;
do {
base = base->parent;
@@ -315,7 +313,7 @@ static dircache_entry *dircache_entry_base(dircache *cache, dircache_entry *entr
* @return
* The opened DIR *, or NULL on error.
*/
-static DIR *dircache_entry_open(dircache *cache, dircache_entry *entry, const char *path) {
+static DIR *dircache_entry_open(struct dircache *cache, struct dircache_entry *entry, const char *path) {
assert(!entry->dir);
if (cache->lru_remaining == 0) {
@@ -324,7 +322,7 @@ static DIR *dircache_entry_open(dircache *cache, dircache_entry *entry, const ch
int at_fd = AT_FDCWD;
const char *at_path = path;
- dircache_entry *base = dircache_entry_base(cache, entry, &at_fd, &at_path);
+ struct dircache_entry *base = dircache_entry_base(cache, entry, &at_fd, &at_path);
DIR *dir = opendirat(at_fd, at_path);
@@ -347,7 +345,7 @@ static DIR *dircache_entry_open(dircache *cache, dircache_entry *entry, const ch
}
/** Free a dircache_entry. */
-static void dircache_entry_free(dircache *cache, dircache_entry *entry) {
+static void dircache_entry_free(struct dircache *cache, struct dircache_entry *entry) {
if (entry) {
assert(entry->refcount == 0);
@@ -364,40 +362,38 @@ static void dircache_entry_free(dircache *cache, dircache_entry *entry) {
/**
* A single block in the dirqueue chain.
*/
-typedef struct dirqueue_block dirqueue_block;
-
struct dirqueue_block {
/** The next block in the chain. */
- dirqueue_block *next;
+ struct dirqueue_block *next;
/** The elements in the queue. */
- dircache_entry *entries[DIRQUEUE_BLOCK_SIZE];
+ struct dircache_entry *entries[DIRQUEUE_BLOCK_SIZE];
};
/**
* A queue of 'dircache_entry's to examine.
*/
-typedef struct {
+struct dirqueue {
/** The first block. */
- dirqueue_block *head;
+ struct dirqueue_block *head;
/** The last block. */
- dirqueue_block *tail;
+ struct dirqueue_block *tail;
/** The index in 'head' of the next entry to read. */
size_t front;
/** The index in 'tail' of the next entry to write. */
size_t back;
-} dirqueue;
+};
/** Initialize a dirqueue. */
-static void dirqueue_init(dirqueue *queue) {
+static void dirqueue_init(struct dirqueue *queue) {
queue->head = queue->tail = NULL;
queue->front = 0;
queue->back = DIRQUEUE_BLOCK_SIZE;
}
/** Add an entry to the dirqueue. */
-static int dirqueue_push(dirqueue *queue, dircache_entry *entry) {
+static int dirqueue_push(struct dirqueue *queue, struct dircache_entry *entry) {
if (queue->back == DIRQUEUE_BLOCK_SIZE) {
- dirqueue_block *block = malloc(sizeof(dirqueue_block));
+ struct dirqueue_block *block = malloc(sizeof(struct dirqueue_block));
if (!block) {
return -1;
}
@@ -421,7 +417,7 @@ static int dirqueue_push(dirqueue *queue, dircache_entry *entry) {
}
/** Remove an entry from the dirqueue. */
-static dircache_entry *dirqueue_pop(dirqueue *queue) {
+static struct dircache_entry *dirqueue_pop(struct dirqueue *queue) {
if (!queue->head) {
return NULL;
}
@@ -432,8 +428,8 @@ static dircache_entry *dirqueue_pop(dirqueue *queue) {
return NULL;
}
- dirqueue_block *head = queue->head;
- dircache_entry *entry = head->entries[queue->front];
+ struct dirqueue_block *head = queue->head;
+ struct dircache_entry *entry = head->entries[queue->front];
if (++queue->front == DIRQUEUE_BLOCK_SIZE) {
queue->head = head->next;
queue->front = 0;
@@ -513,19 +509,19 @@ static int ftwbuf_stat(struct BFTW *ftwbuf, struct stat *sb) {
/**
* Possible bftw() traversal statuses.
*/
-typedef enum {
+enum bftw_status {
/** The current path is state.current. */
BFTW_CURRENT,
/** The current path is a child of state.current. */
BFTW_CHILD,
/** dircache_entry's are being garbage collected. */
BFTW_GC,
-} bftw_status;
+};
/**
* Holds the current state of the bftw() traversal.
*/
-typedef struct {
+struct bftw_state {
/** bftw() callback. */
bftw_fn *fn;
/** bftw() flags. */
@@ -537,27 +533,27 @@ typedef struct {
int error;
/** The cache of open directories. */
- dircache cache;
+ struct dircache cache;
/** The current dircache entry. */
- dircache_entry *current;
+ struct dircache_entry *current;
/** The current traversal status. */
- bftw_status status;
+ enum bftw_status status;
/** The queue of directories left to explore. */
- dirqueue queue;
+ struct dirqueue queue;
/** The current path being explored. */
- dynstr path;
+ struct dynstr path;
/** Extra data about the current file. */
struct BFTW ftwbuf;
/** stat() buffer for the current file. */
struct stat statbuf;
-} bftw_state;
+};
/**
* Initialize the bftw() state.
*/
-static void bftw_state_init(bftw_state *state, bftw_fn *fn, int nopenfd, int flags, void *ptr) {
+static void bftw_state_init(struct bftw_state *state, bftw_fn *fn, int nopenfd, int flags, void *ptr) {
state->fn = fn;
state->flags = flags;
state->ptr = ptr;
@@ -576,10 +572,10 @@ static void bftw_state_init(bftw_state *state, bftw_fn *fn, int nopenfd, int fla
/**
* Concatenate a subpath to the current path.
*/
-static int bftw_path_concat(bftw_state *state, const char *subpath) {
+static int bftw_path_concat(struct bftw_state *state, const char *subpath) {
size_t nameoff = 0;
- dircache_entry *current = state->current;
+ struct dircache_entry *current = state->current;
if (current) {
nameoff = current->nameoff + current->namelen;
}
@@ -592,7 +588,7 @@ static int bftw_path_concat(bftw_state *state, const char *subpath) {
/**
* Initialize the buffers with data about the current path.
*/
-static void bftw_init_buffers(bftw_state *state, const struct dirent *de) {
+static void bftw_init_buffers(struct bftw_state *state, const struct dirent *de) {
struct BFTW *ftwbuf = &state->ftwbuf;
ftwbuf->path = state->path.str;
ftwbuf->nameoff = 0;
@@ -603,7 +599,7 @@ static void bftw_init_buffers(bftw_state *state, const struct dirent *de) {
ftwbuf->at_fd = AT_FDCWD;
ftwbuf->at_path = ftwbuf->path;
- dircache_entry *current = state->current;
+ struct dircache_entry *current = state->current;
if (current) {
ftwbuf->nameoff = current->nameoff;
ftwbuf->depth = current->depth;
@@ -638,13 +634,13 @@ static void bftw_init_buffers(bftw_state *state, const struct dirent *de) {
/**
* Invoke the callback on the given path.
*/
-static int bftw_handle_path(bftw_state *state) {
+static int bftw_handle_path(struct bftw_state *state) {
// Never give the callback BFTW_ERROR unless BFTW_RECOVER is specified
if (state->ftwbuf.typeflag == BFTW_ERROR && !(state->flags & BFTW_RECOVER)) {
return BFTW_FAIL;
}
- bftw_action action = state->fn(&state->ftwbuf, state->ptr);
+ enum bftw_action action = state->fn(&state->ftwbuf, state->ptr);
switch (action) {
case BFTW_CONTINUE:
case BFTW_SKIP_SIBLINGS:
@@ -661,8 +657,8 @@ static int bftw_handle_path(bftw_state *state) {
/**
* Push a new entry onto the queue.
*/
-static int bftw_push(bftw_state *state, const char *name) {
- dircache_entry *entry = dircache_add(&state->cache, state->current, name);
+static int bftw_push(struct bftw_state *state, const char *name) {
+ struct dircache_entry *entry = dircache_add(&state->cache, state->current, name);
if (!entry) {
return -1;
}
@@ -673,9 +669,9 @@ static int bftw_push(bftw_state *state, const char *name) {
/**
* Pop an entry off the queue.
*/
-static int bftw_pop(bftw_state *state, bool invoke_callback) {
+static int bftw_pop(struct bftw_state *state, bool invoke_callback) {
int ret = BFTW_CONTINUE;
- dircache_entry *entry = state->current;
+ struct dircache_entry *entry = state->current;
if (!(state->flags & BFTW_DEPTH)) {
invoke_callback = false;
@@ -691,7 +687,7 @@ static int bftw_pop(bftw_state *state, bool invoke_callback) {
state->status = BFTW_GC;
while (entry) {
- dircache_entry *current = entry;
+ struct dircache_entry *current = entry;
entry = entry->parent;
if (--current->refcount > 0) {
@@ -736,7 +732,7 @@ static int bftw_pop(bftw_state *state, bool invoke_callback) {
/**
* Dispose of the bftw() state.
*/
-static void bftw_state_free(bftw_state *state) {
+static void bftw_state_free(struct bftw_state *state) {
while (state->current) {
bftw_pop(state, false);
}
@@ -744,10 +740,10 @@ static void bftw_state_free(bftw_state *state) {
dynstr_free(&state->path);
}
-int bftw(const char *path, bftw_fn *fn, int nopenfd, bftw_flags flags, void *ptr) {
+int bftw(const char *path, bftw_fn *fn, int nopenfd, enum bftw_flags flags, void *ptr) {
int ret = -1;
- bftw_state state;
+ struct bftw_state state;
bftw_state_init(&state, fn, nopenfd, flags, ptr);
// Handle 'path' itself first
diff --git a/bftw.h b/bftw.h
index 2082390..1375594 100644
--- a/bftw.h
+++ b/bftw.h
@@ -18,7 +18,7 @@
/**
* Possible file types.
*/
-typedef enum {
+enum bftw_typeflag {
/** Unknown type. */
BFTW_UNKNOWN,
/** Block device. */
@@ -37,17 +37,17 @@ typedef enum {
BFTW_SOCK,
/** An error occurred for this file. */
BFTW_ERROR,
-} bftw_typeflag;
+};
/**
* Possible visit occurrences.
*/
-typedef enum {
+enum bftw_visit {
/** Pre-order visit. */
BFTW_PRE,
/** Post-order visit. */
BFTW_POST,
-} bftw_visit;
+};
/**
* Data about the current file for the bftw() callback.
@@ -61,10 +61,10 @@ struct BFTW {
/** The depth of this file in the traversal. */
size_t depth;
/** Which visit this is. */
- bftw_visit visit;
+ enum bftw_visit visit;
/** The file type. */
- bftw_typeflag typeflag;
+ enum bftw_typeflag typeflag;
/** The errno that occurred, if typeflag == BFTW_ERROR. */
int error;
@@ -77,7 +77,7 @@ struct BFTW {
const char *at_path;
};
-typedef enum {
+enum bftw_action {
/** Keep walking. */
BFTW_CONTINUE,
/** Skip this path's siblings. */
@@ -86,7 +86,7 @@ typedef enum {
BFTW_SKIP_SUBTREE,
/** Stop walking. */
BFTW_STOP,
-} bftw_action;
+};
/**
* Callback function type for bftw().
@@ -98,16 +98,19 @@ typedef enum {
* @return
* An action value.
*/
-typedef bftw_action bftw_fn(struct BFTW *ftwbuf, void *ptr);
+typedef enum bftw_action bftw_fn(struct BFTW *ftwbuf, void *ptr);
-typedef enum {
+/**
+ * Flags that control bftw() behavior.
+ */
+enum bftw_flags {
/** stat() each encountered file. */
BFTW_STAT = 1 << 0,
/** Attempt to recover from encountered errors. */
BFTW_RECOVER = 1 << 1,
/** Visit directories in post-order as well as pre-order. */
BFTW_DEPTH = 1 << 2,
-} bftw_flags;
+};
/**
* Breadth First Tree Walk (or Better File Tree Walk).
@@ -129,6 +132,6 @@ typedef enum {
* @return
* 0 on success, or -1 on failure.
*/
-int bftw(const char *path, bftw_fn *fn, int nopenfd, bftw_flags flags, void *ptr);
+int bftw(const char *path, bftw_fn *fn, int nopenfd, enum bftw_flags flags, void *ptr);
#endif // BFS_BFTW_H
diff --git a/color.c b/color.c
index b67d6a4..8e22340 100644
--- a/color.c
+++ b/color.c
@@ -18,15 +18,13 @@
#include <string.h>
#include <sys/stat.h>
-typedef struct ext_color ext_color;
-
struct ext_color {
const char *ext;
size_t len;
const char *color;
- ext_color *next;
+ struct ext_color *next;
};
struct color_table {
@@ -50,11 +48,11 @@ struct color_table {
const char *sticky;
const char *exec;
- ext_color *ext_list;
+ struct ext_color *ext_list;
};
-color_table *parse_colors(char *ls_colors) {
- color_table *colors = malloc(sizeof(color_table));
+struct color_table *parse_colors(char *ls_colors) {
+ struct color_table *colors = malloc(sizeof(struct color_table));
if (!colors) {
goto done;
}
@@ -87,7 +85,7 @@ color_table *parse_colors(char *ls_colors) {
char *start = ls_colors;
char *end;
- ext_color *ext;
+ struct ext_color *ext;
for (end = strchr(start, ':'); *start && end; start = end + 1, end = strchr(start, ':')) {
char *equals = strchr(start, '=');
if (!equals) {
@@ -186,7 +184,7 @@ color_table *parse_colors(char *ls_colors) {
break;
case '*':
- ext = malloc(sizeof(ext_color));
+ ext = malloc(sizeof(struct ext_color));
if (ext) {
ext->ext = key + 1;
ext->len = strlen(ext->ext);
@@ -201,7 +199,7 @@ done:
return colors;
}
-static const char *file_color(const color_table *colors, const char *filename, const struct stat *sb) {
+static const char *file_color(const struct color_table *colors, const char *filename, const struct stat *sb) {
if (!sb) {
return colors->orphan;
}
@@ -221,7 +219,7 @@ static const char *file_color(const color_table *colors, const char *filename, c
if (!color) {
size_t namelen = strlen(filename);
- for (ext_color *ext = colors->ext_list; ext; ext = ext->next) {
+ for (struct ext_color *ext = colors->ext_list; ext; ext = ext->next) {
if (namelen >= ext->len && memcmp(filename + namelen - ext->len, ext->ext, ext->len) == 0) {
color = ext->color;
break;
@@ -282,7 +280,7 @@ static void print_esc(const char *esc, FILE *file) {
fputs("m", file);
}
-void pretty_print(const color_table *colors, const struct BFTW *ftwbuf) {
+void pretty_print(const struct color_table *colors, const struct BFTW *ftwbuf) {
const char *path = ftwbuf->path;
if (!colors) {
@@ -311,7 +309,7 @@ void pretty_print(const color_table *colors, const struct BFTW *ftwbuf) {
fputs("\n", stdout);
}
-void print_error(const color_table *colors, const char *path, int error) {
+void print_error(const struct color_table *colors, const char *path, int error) {
const char *color = NULL;
if (colors) {
color = colors->orphan;
@@ -326,11 +324,11 @@ void print_error(const color_table *colors, const char *path, int error) {
}
}
-void free_colors(color_table *colors) {
+void free_colors(struct color_table *colors) {
if (colors) {
- ext_color *ext = colors->ext_list;
+ struct ext_color *ext = colors->ext_list;
while (ext) {
- ext_color *saved = ext;
+ struct ext_color *saved = ext;
ext = ext->next;
free(saved);
}
diff --git a/color.h b/color.h
index e8d984c..d022d34 100644
--- a/color.h
+++ b/color.h
@@ -17,7 +17,7 @@
/**
* A lookup table for colors.
*/
-typedef struct color_table color_table;
+struct color_table;
/**
* Parse a color table.
@@ -26,7 +26,7 @@ typedef struct color_table color_table;
* A color table in the LS_COLORS environment variable format.
* @return The parsed color table.
*/
-color_table *parse_colors(char *ls_colors);
+struct color_table *parse_colors(char *ls_colors);
/**
* Pretty-print a file path.
@@ -36,7 +36,7 @@ color_table *parse_colors(char *ls_colors);
* @param ftwbuf
* The bftw() data for the current path.
*/
-void pretty_print(const color_table *colors, const struct BFTW *ftwbuf);
+void pretty_print(const struct color_table *colors, const struct BFTW *ftwbuf);
/**
* Pretty-print an error.
@@ -48,7 +48,7 @@ void pretty_print(const color_table *colors, const struct BFTW *ftwbuf);
* @param error
* The error code that occurred.
*/
-void print_error(const color_table *colors, const char *path, int error);
+void print_error(const struct color_table *colors, const char *path, int error);
/**
* Free a color table.
@@ -56,6 +56,6 @@ void print_error(const color_table *colors, const char *path, int error);
* @param colors
* The color table to free.
*/
-void free_colors(color_table *colors);
+void free_colors(struct color_table *colors);
#endif // BFS_COLOR_H
diff --git a/eval.c b/eval.c
index b042339..7de11bf 100644
--- a/eval.c
+++ b/eval.c
@@ -15,9 +15,9 @@ struct eval_state {
/** Data about the current file. */
struct BFTW *ftwbuf;
/** The parsed command line. */
- const cmdline *cl;
+ const struct cmdline *cl;
/** The bftw() callback return value. */
- bftw_action action;
+ enum bftw_action action;
/** A stat() buffer, if necessary. */
struct stat statbuf;
};
@@ -25,7 +25,7 @@ struct eval_state {
/**
* Perform a stat() call if necessary.
*/
-static const struct stat *fill_statbuf(eval_state *state) {
+static const struct stat *fill_statbuf(struct eval_state *state) {
struct BFTW *ftwbuf = state->ftwbuf;
if (!ftwbuf->statbuf) {
if (fstatat(ftwbuf->at_fd, ftwbuf->at_path, &state->statbuf, AT_SYMLINK_NOFOLLOW) == 0) {
@@ -65,7 +65,7 @@ static time_t to_days(time_t seconds) {
/**
* Perform a comparison.
*/
-static bool do_cmp(const expression *expr, int n) {
+static bool do_cmp(const struct expr *expr, int n) {
switch (expr->cmp) {
case CMP_EXACT:
return n == expr->idata;
@@ -81,21 +81,21 @@ static bool do_cmp(const expression *expr, int n) {
/**
* -true test.
*/
-bool eval_true(const expression *expr, eval_state *state) {
+bool eval_true(const struct expr *expr, struct eval_state *state) {
return true;
}
/**
* -false test.
*/
-bool eval_false(const expression *expr, eval_state *state) {
+bool eval_false(const struct expr *expr, struct eval_state *state) {
return false;
}
/**
* -executable, -readable, -writable tests.
*/
-bool eval_access(const expression *expr, eval_state *state) {
+bool eval_access(const struct expr *expr, struct eval_state *state) {
struct BFTW *ftwbuf = state->ftwbuf;
return faccessat(ftwbuf->at_fd, ftwbuf->at_path, expr->idata, AT_SYMLINK_NOFOLLOW) == 0;
}
@@ -103,7 +103,7 @@ bool eval_access(const expression *expr, eval_state *state) {
/**
* -amin test.
*/
-bool eval_amin(const expression *expr, eval_state *state) {
+bool eval_amin(const struct expr *expr, struct eval_state *state) {
const struct stat *statbuf = fill_statbuf(state);
if (!statbuf) {
return false;
@@ -116,7 +116,7 @@ bool eval_amin(const expression *expr, eval_state *state) {
/**
* -atime test.
*/
-bool eval_atime(const expression *expr, eval_state *state) {
+bool eval_atime(const struct expr *expr, struct eval_state *state) {
const struct stat *statbuf = fill_statbuf(state);
if (!statbuf) {
return false;
@@ -129,7 +129,7 @@ bool eval_atime(const expression *expr, eval_state *state) {
/**
* -cmin test.
*/
-bool eval_cmin(const expression *expr, eval_state *state) {
+bool eval_cmin(const struct expr *expr, struct eval_state *state) {
const struct stat *statbuf = fill_statbuf(state);
if (!statbuf) {
return false;
@@ -142,7 +142,7 @@ bool eval_cmin(const expression *expr, eval_state *state) {
/**
* -ctime test.
*/
-bool eval_ctime(const expression *expr, eval_state *state) {
+bool eval_ctime(const struct expr *expr, struct eval_state *state) {
const struct stat *statbuf = fill_statbuf(state);
if (!statbuf) {
return false;
@@ -155,7 +155,7 @@ bool eval_ctime(const expression *expr, eval_state *state) {
/**
* -mmin test.
*/
-bool eval_mmin(const expression *expr, eval_state *state) {
+bool eval_mmin(const struct expr *expr, struct eval_state *state) {
const struct stat *statbuf = fill_statbuf(state);
if (!statbuf) {
return false;
@@ -168,7 +168,7 @@ bool eval_mmin(const expression *expr, eval_state *state) {
/**
* -mtime test.
*/
-bool eval_mtime(const expression *expr, eval_state *state) {
+bool eval_mtime(const struct expr *expr, struct eval_state *state) {
const struct stat *statbuf = fill_statbuf(state);
if (!statbuf) {
return false;
@@ -181,7 +181,7 @@ bool eval_mtime(const expression *expr, eval_state *state) {
/**
* -gid test.
*/
-bool eval_gid(const expression *expr, eval_state *state) {
+bool eval_gid(const struct expr *expr, struct eval_state *state) {
const struct stat *statbuf = fill_statbuf(state);
if (!statbuf) {
return false;
@@ -193,7 +193,7 @@ bool eval_gid(const expression *expr, eval_state *state) {
/**
* -uid test.
*/
-bool eval_uid(const expression *expr, eval_state *state) {
+bool eval_uid(const struct expr *expr, struct eval_state *state) {
const struct stat *statbuf = fill_statbuf(state);
if (!statbuf) {
return false;
@@ -205,7 +205,7 @@ bool eval_uid(const expression *expr, eval_state *state) {
/**
* -delete action.
*/
-bool eval_delete(const expression *expr, eval_state *state) {
+bool eval_delete(const struct expr *expr, struct eval_state *state) {
struct BFTW *ftwbuf = state->ftwbuf;
int flag = 0;
@@ -224,7 +224,7 @@ bool eval_delete(const expression *expr, eval_state *state) {
/**
* -empty test.
*/
-bool eval_empty(const expression *expr, eval_state *state) {
+bool eval_empty(const struct expr *expr, struct eval_state *state) {
bool ret = false;
struct BFTW *ftwbuf = state->ftwbuf;
@@ -267,7 +267,7 @@ done:
/**
* -prune action.
*/
-bool eval_prune(const expression *expr, eval_state *state) {
+bool eval_prune(const struct expr *expr, struct eval_state *state) {
state->action = BFTW_SKIP_SUBTREE;
return true;
}
@@ -275,7 +275,7 @@ bool eval_prune(const expression *expr, eval_state *state) {
/**
* -hidden test.
*/
-bool eval_hidden(const expression *expr, eval_state *state) {
+bool eval_hidden(const struct expr *expr, struct eval_state *state) {
struct BFTW *ftwbuf = state->ftwbuf;
return ftwbuf->nameoff > 0 && ftwbuf->path[ftwbuf->nameoff] == '.';
}
@@ -283,7 +283,7 @@ bool eval_hidden(const expression *expr, eval_state *state) {
/**
* -nohidden action.
*/
-bool eval_nohidden(const expression *expr, eval_state *state) {
+bool eval_nohidden(const struct expr *expr, struct eval_state *state) {
if (eval_hidden(expr, state)) {
eval_prune(expr, state);
return false;
@@ -295,7 +295,7 @@ bool eval_nohidden(const expression *expr, eval_state *state) {
/**
* -name test.
*/
-bool eval_name(const expression *expr, eval_state *state) {
+bool eval_name(const struct expr *expr, struct eval_state *state) {
struct BFTW *ftwbuf = state->ftwbuf;
return fnmatch(expr->sdata, ftwbuf->path + ftwbuf->nameoff, 0) == 0;
}
@@ -303,7 +303,7 @@ bool eval_name(const expression *expr, eval_state *state) {
/**
* -path test.
*/
-bool eval_path(const expression *expr, eval_state *state) {
+bool eval_path(const struct expr *expr, struct eval_state *state) {
struct BFTW *ftwbuf = state->ftwbuf;
return fnmatch(expr->sdata, ftwbuf->path, 0) == 0;
}
@@ -311,8 +311,8 @@ bool eval_path(const expression *expr, eval_state *state) {
/**
* -print action.
*/
-bool eval_print(const expression *expr, eval_state *state) {
- color_table *colors = state->cl->colors;
+bool eval_print(const struct expr *expr, struct eval_state *state) {
+ struct color_table *colors = state->cl->colors;
if (colors) {
fill_statbuf(state);
}
@@ -323,7 +323,7 @@ bool eval_print(const expression *expr, eval_state *state) {
/**
* -print0 action.
<