diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-02-04 12:40:43 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-02-04 12:40:43 -0500 |
commit | 035dbc05163f897ad74487afbb9d6c778b683b61 (patch) | |
tree | e99dd0ccd3659b5b1e05e601115ee50e1f8301fe | |
parent | 70fadadf1fc7e1bd09c3d0f451614a678277409c (diff) | |
download | bfs-035dbc05163f897ad74487afbb9d6c778b683b61.tar.xz |
Don't use typedefs to avoid struct/enum tags.
-rw-r--r-- | bfs.h | 88 | ||||
-rw-r--r-- | bftw.c | 128 | ||||
-rw-r--r-- | bftw.h | 27 | ||||
-rw-r--r-- | color.c | 28 | ||||
-rw-r--r-- | color.h | 10 | ||||
-rw-r--r-- | eval.c | 72 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | parse.c | 158 |
8 files changed, 254 insertions, 259 deletions
@@ -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 @@ -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 @@ -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 @@ -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); } @@ -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 @@ -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. */ -bool eval_print0(const expression *expr, eval_state *state) { +bool eval_print0(const struct expr *expr, struct eval_state *state) { const char *path = state->ftwbuf->path; fwrite(path, 1, strlen(path) + 1, stdout); return true; @@ -332,7 +332,7 @@ bool eval_print0(const expression *expr, eval_state *state) { /** * -quit action. */ -bool eval_quit(const expression *expr, eval_state *state) { +bool eval_quit(const struct expr *expr, struct eval_state *state) { state->action = BFTW_STOP; return true; } @@ -340,35 +340,35 @@ bool eval_quit(const expression *expr, eval_state *state) { /** * -type test. */ -bool eval_type(const expression *expr, eval_state *state) { +bool eval_type(const struct expr *expr, struct eval_state *state) { return state->ftwbuf->typeflag == expr->idata; } /** * Evaluate a negation. */ -bool eval_not(const expression *expr, eval_state *state) { +bool eval_not(const struct expr *expr, struct eval_state *state) { return !expr->rhs->eval(expr, state); } /** * Evaluate a conjunction. */ -bool eval_and(const expression *expr, eval_state *state) { +bool eval_and(const struct expr *expr, struct eval_state *state) { return expr->lhs->eval(expr->lhs, state) && expr->rhs->eval(expr->rhs, state); } /** * Evaluate a disjunction. */ -bool eval_or(const expression *expr, eval_state *state) { +bool eval_or(const struct expr *expr, struct eval_state *state) { return expr->lhs->eval(expr->lhs, state) || expr->rhs->eval(expr->rhs, state); } /** * Evaluate the comma operator. */ -bool eval_comma(const expression *expr, eval_state *state) { +bool eval_comma(const struct expr *expr, struct eval_state *state) { expr->lhs->eval(expr->lhs, state); return expr->rhs->eval(expr->rhs, state); } @@ -397,15 +397,15 @@ static int infer_nopenfd() { /** * bftw() callback. */ -static bftw_action cmdline_callback(struct BFTW *ftwbuf, void *ptr) { - const cmdline *cl = ptr; +static enum bftw_action cmdline_callback(struct BFTW *ftwbuf, void *ptr) { + const struct cmdline *cl = ptr; if (ftwbuf->typeflag == BFTW_ERROR) { print_error(cl->colors, ftwbuf->path, ftwbuf->error); return BFTW_SKIP_SUBTREE; } - eval_state state = { + struct eval_state state = { .ftwbuf = ftwbuf, .cl = cl, .action = BFTW_CONTINUE, @@ -416,7 +416,7 @@ static bftw_action cmdline_callback(struct BFTW *ftwbuf, void *ptr) { } // In -depth mode, only handle directories on the BFTW_POST visit - bftw_visit expected_visit = BFTW_PRE; + enum bftw_visit expected_visit = BFTW_PRE; if ((cl->flags & BFTW_DEPTH) && ftwbuf->typeflag == BFTW_DIR && ftwbuf->depth < cl->maxdepth) { @@ -435,7 +435,7 @@ static bftw_action cmdline_callback(struct BFTW *ftwbuf, void *ptr) { /** * Evaluate the command line. */ -int eval_cmdline(cmdline *cl) { +int eval_cmdline(struct cmdline *cl) { int ret = 0; int nopenfd = infer_nopenfd(); @@ -15,7 +15,7 @@ int main(int argc, char *argv[]) { int ret = EXIT_FAILURE; - cmdline *cl = parse_cmdline(argc, argv); + struct cmdline *cl = parse_cmdline(argc, argv); if (cl) { if (eval_cmdline(cl) == 0) { ret = EXIT_SUCCESS; @@ -8,8 +8,8 @@ /** * Create a new expression. */ -static expression *new_expression(eval_fn *eval) { - expression *expr = malloc(sizeof(expression)); +static struct expr *new_expr(eval_fn *eval) { + struct expr *expr = malloc(sizeof(struct expr)); if (!expr) { perror("malloc()"); return NULL; @@ -27,7 +27,7 @@ static expression *new_expression(eval_fn *eval) { /** * Singleton true expression instance. */ -static expression expr_true = { +static struct expr expr_true = { .lhs = NULL, .rhs = NULL, .eval = eval_true, @@ -38,7 +38,7 @@ static expression expr_true = { /** * Singleton false expression instance. */ -static expression expr_false = { +static struct expr expr_false = { .lhs = NULL, .rhs = NULL, .eval = eval_false, @@ -49,10 +49,10 @@ static expression expr_false = { /** * Free an expression. */ -static void free_expression(expression *expr) { +static void free_expr(struct expr *expr) { if (expr && expr != &expr_true && expr != &expr_false) { - free_expression(expr->lhs); - free_expression(expr->rhs); + free_expr(expr->lhs); + free_expr(expr->rhs); free(expr); } } @@ -60,10 +60,10 @@ static void free_expression(expression *expr) { /** * Create a new unary expression. */ -static expression *new_unary_expression(expression *rhs, eval_fn *eval) { - expression *expr = new_expression(eval); +static struct expr *new_unary_expr(struct expr *rhs, eval_fn *eval) { + struct expr *expr = new_expr(eval); if (!expr) { - free_expression(rhs); + free_expr(rhs); return NULL; } @@ -75,11 +75,11 @@ static expression *new_unary_expression(expression *rhs, eval_fn *eval) { /** * Create a new binary expression. */ -static expression *new_binary_expression(expression *lhs, expression *rhs, eval_fn *eval) { - expression *expr = new_expression(eval); +static struct expr *new_binary_expr(struct expr *lhs, struct expr *rhs, eval_fn *eval) { + struct expr *expr = new_expr(eval); if (!expr) { - free_expression(rhs); - free_expression(lhs); + free_expr(rhs); + free_expr(lhs); return NULL; } @@ -92,9 +92,9 @@ static expression *new_binary_expression(expression *lhs, expression *rhs, eval_ /** * Free the parsed command line. */ -void free_cmdline(cmdline *cl) { +void free_cmdline(struct cmdline *cl) { if (cl) { - free_expression(cl->expr); + free_expr(cl->expr); free_colors(cl->colors); free(cl->roots); free(cl); @@ -104,7 +104,7 @@ void free_cmdline(cmdline *cl) { /** * Add a root path to the cmdline. */ -static bool cmdline_add_root(cmdline *cl, const char *root) { +static bool cmdline_add_root(struct cmdline *cl, const char *root) { size_t i = cl->nroots++; const char **roots = realloc(cl->roots, cl->nroots*sizeof(const char *)); if (!roots) { @@ -120,9 +120,9 @@ static bool cmdline_add_root(cmdline *cl, const char *root) { /** * Ephemeral state for parsing the command line. */ -typedef struct { +struct parser_state { /** The command line being parsed. */ - cmdline *cl; + struct cmdline *cl; /** The command line arguments. */ char **argv; /** Current argument index. */ @@ -134,17 +134,17 @@ typedef struct { bool warn; /** Whether any non-option arguments have been encountered. */ bool non_option_seen; -} parser_state; +}; /** * Parse the expression specified on the command line. */ -static expression *parse_expression(parser_state *state); +static struct expr *parse_expr(struct parser_state *state); /** * While parsing an expression, skip any paths and add them to the cmdline. */ -static const char *skip_paths(parser_state *state) { +static const char *skip_paths(struct parser_state *state) { while (true) { const char *arg = state->argv[state->i]; if (!arg @@ -190,7 +190,7 @@ bad: /** * Parse an integer and a comparison flag. */ -static bool parse_icmp(const char *str, expression *expr) { +static bool parse_icmp(const char *str, struct expr *expr) { switch (str[0]) { case '-': expr->cmp = CMP_LESS; @@ -211,7 +211,7 @@ static bool parse_icmp(const char *str, expression *expr) { /** * Create a new option expression. */ -static expression *new_option(parser_state *state, const char *option) { +static struct expr *new_option(struct parser_state *state, const char *option) { if (state->warn && state->non_option_seen) { fprintf(stderr, "The '%s' option applies to the entire command line.\n" @@ -225,23 +225,23 @@ static expression *new_option(parser_state *state, const char *option) { /** * Create a new positional option expression. */ -static expression *new_positional_option(parser_state *state) { +static struct expr *new_positional_option(struct parser_state *state) { return &expr_true; } /** * Create a new test expression. */ -static expression *new_test(parser_state *state, eval_fn *eval) { +static struct expr *new_test(struct parser_state *state, eval_fn *eval) { state->non_option_seen = true; - return new_expression(eval); + return new_expr(eval); } /** * Create a new test expression with integer data. */ -static expression *new_test_idata(parser_state *state, eval_fn *eval, int idata) { - expression *test = new_test(state, eval); +static struct expr *new_test_idata(struct parser_state *state, eval_fn *eval, int idata) { + struct expr *test = new_test(state, eval); if (test) { test->idata = idata; } @@ -251,8 +251,8 @@ static expression *new_test_idata(parser_state *state, eval_fn *eval, int idata) /** * Create a new test expression with string data. */ -static expression *new_test_sdata(parser_state *state, eval_fn *eval, const char *sdata) { - expression *test = new_test(state, eval); +static struct expr *new_test_sdata(struct parser_state *state, eval_fn *eval, const char *sdata) { + struct expr *test = new_test(state, eval); if (test) { test->sdata = sdata; } @@ -262,20 +262,20 @@ static expression *new_test_sdata(parser_state *state, eval_fn *eval, const char /** * Create a new action expression. */ -static expression *new_action(parser_state *state, eval_fn *eval) { +static struct expr *new_action(struct parser_state *state, eval_fn *eval) { if (eval != eval_nohidden && eval != eval_prune) { state->implicit_print = false; } state->non_option_seen = true; - return new_expression(eval); + return new_expr(eval); } /** * Parse a test expression with integer data and a comparison flag. */ -static expression *parse_test_icmp(parser_state *state, const char *test, eval_fn *eval) { +static struct expr *parse_test_icmp(struct parser_state *state, const char *test, eval_fn *eval) { const char *arg = state->argv[state->i]; if (!arg) { fprintf(stderr, "%s needs a value.\n", test); @@ -284,10 +284,10 @@ static expression *parse_test_icmp(parser_state *state, const char *test, eval_f ++state->i; - expression *expr = new_test(state, eval); + struct expr *expr = new_test(state, eval); if (expr) { if (!parse_icmp(arg, expr)) { - free_expression(expr); + free_expr(expr); expr = NULL; } } @@ -297,7 +297,7 @@ static expression *parse_test_icmp(parser_state *state, const char *test, eval_f /** * Parse a test that takes a string argument. */ -static expression *parse_test_sdata(parser_state *state, const char *test, eval_fn *eval) { +static struct expr *parse_test_sdata(struct parser_state *state, const char *test, eval_fn *eval) { const char *arg = state->argv[state->i]; if (!arg) { fprintf(stderr, "%s needs a value.\n", test); @@ -312,7 +312,7 @@ static expression *parse_test_sdata(parser_state *state, const char *test, eval_ /** * Parse -{min,max}depth N. */ -static expression *parse_depth(parser_state *state, const char *option, int *depth) { +static struct expr *parse_depth(struct parser_state *state, const char *option, int *depth) { const char *arg = state->argv[state->i]; if (!arg) { fprintf(stderr, "%s needs a value.\n", option); @@ -331,7 +331,7 @@ static expression *parse_depth(parser_state *state, const char *option, int *dep /** * Parse -type [bcdpfls]. */ -static expression *parse_type(parser_state *state) { +static struct expr *parse_type(struct parser_state *state) { const char *arg = state->argv[state->i]; if (!arg) { fputs("-type needs a value.\n", stderr); @@ -379,7 +379,7 @@ static expression *parse_type(parser_state *state) { * | TEST * | ACTION */ -static expression *parse_literal(parser_state *state) { +static struct expr *parse_literal(struct parser_state *state) { // Paths are already skipped at this point const char *arg = state->argv[state->i++]; @@ -460,13 +460,13 @@ static expression *parse_literal(parser_state *state) { /** * Create a "not" expression. */ -static expression *new_not_expression(expression *rhs) { +static struct expr *new_not_expr(struct expr *rhs) { if (rhs == &expr_true) { return &expr_false; } else if (rhs == &expr_false) { return &expr_true; } else { - return new_unary_expression(rhs, eval_not); + return new_unary_expr(rhs, eval_not); } } @@ -475,7 +475,7 @@ static expression *new_not_expression(expression *rhs) { * | "!" FACTOR | "-not" FACTOR * | LITERAL */ -static expression *parse_factor(parser_state *state) { +static struct expr *parse_factor(struct parser_state *state) { const char *arg = skip_paths(state); if (!arg) { fputs("Expression terminated prematurely.\n", stderr); @@ -484,7 +484,7 @@ static expression *parse_factor(parser_state *state) { if (strcmp(arg, "(") == 0) { ++state->i; - expression *expr = parse_expression(state); + struct expr *expr = parse_expr(state); if (!expr) { return NULL; } @@ -492,7 +492,7 @@ static expression *parse_factor(parser_state *state) { arg = skip_paths(state); if (!arg || strcmp(arg, ")") != 0) { fputs("Expected a ')'.\n", stderr); - free_expression(expr); + free_expr(expr); return NULL; } ++state->i; @@ -501,12 +501,12 @@ static expression *parse_factor(parser_state *state) { } else if (strcmp(arg, "!") == 0 || strcmp(arg, "-not") == 0) { ++state->i; - expression *factor = parse_factor(state); + struct expr *factor = parse_factor(state); if (!factor) { return NULL; } - return new_not_expression(factor); + return new_not_expr(factor); } else { return parse_literal(state); } @@ -515,16 +515,16 @@ static expression *parse_factor(parser_state *state) { /** * Create an "and" expression. */ -static expression *new_and_expression(expression *lhs, expression *rhs) { +static struct expr *new_and_expr(struct expr *lhs, struct expr *rhs) { if (lhs == &expr_true) { return rhs; } else if (lhs == &expr_false) { - free_expression(rhs); + free_expr(rhs); return lhs; } else if (rhs == &expr_true) { return lhs; } else { - return new_binary_expression(lhs, rhs, eval_and); + return new_binary_expr(lhs, rhs, eval_and); } } @@ -534,8 +534,8 @@ static expression *new_and_expression(expression *lhs, expression *rhs) { * | TERM "-a" FACTOR * | TERM "-and" FACTOR */ -static expression *parse_term(parser_state *state) { - expression *term = parse_factor(state); +static struct expr *parse_term(struct parser_state *state) { + struct expr *term = parse_factor(state); while (term) { const char *arg = skip_paths(state); @@ -553,14 +553,14 @@ static expression *parse_term(parser_state *state) { ++state->i; } - expression *lhs = term; - expression *rhs = parse_factor(state); + struct expr *lhs = term; + struct expr *rhs = parse_factor(state); if (!rhs) { - free_expression(lhs); + free_expr(lhs); return NULL; } - term = new_and_expression(lhs, rhs); + term = new_and_expr(lhs, rhs); } return term; @@ -569,16 +569,16 @@ static expression *parse_term(parser_state *state) { /** * Create an "or" expression. */ -static expression *new_or_expression(expression *lhs, expression *rhs) { +static struct expr *new_or_expr(struct expr *lhs, struct expr *rhs) { if (lhs == &expr_true) { - free_expression(rhs); + free_expr(rhs); return lhs; } else if (lhs == &expr_false) { return rhs; } else if (rhs == &expr_false) { return lhs; } else { - return new_binary_expression(lhs, rhs, eval_or); + return new_binary_expr(lhs, rhs, eval_or); } } @@ -587,8 +587,8 @@ static expression *new_or_expression(expression *lhs, expression *rhs) { * | CLAUSE "-o" TERM * | CLAUSE "-or" TERM */ -static expression *parse_clause(parser_state *state) { - expression *clause = parse_term(state); +static struct expr *parse_clause(struct parser_state *state) { + struct expr *clause = parse_term(state); while (clause) { const char *arg = skip_paths(state); @@ -602,14 +602,14 @@ static expression *parse_clause(parser_state *state) { ++state->i; - expression *lhs = clause; - expression *rhs = parse_term(state); + struct expr *lhs = clause; + struct expr *rhs = parse_term(state); if (!rhs) { - free_expression(lhs); + free_expr(lhs); return NULL; } - clause = new_or_expression(lhs, rhs); + clause = new_or_expr(lhs, rhs); } return clause; @@ -618,11 +618,11 @@ static expression *parse_clause(parser_state *state) { /** * Create a "comma" expression. */ -static expression *new_comma_expression(expression *lhs, expression *rhs) { +static struct expr *new_comma_expr(struct expr *lhs, struct expr *rhs) { if (lhs == &expr_true || lhs == &expr_false) { return rhs; } else { - return new_binary_expression(lhs, rhs, eval_comma); + return new_binary_expr(lhs, rhs, eval_comma); } } @@ -630,8 +630,8 @@ static expression *new_comma_expression(expression *lhs, expression *rhs) { * EXPR : CLAUSE * | EXPR "," CLAUSE */ -static expression *parse_expression(parser_state *state) { - expression *expr = parse_clause(state); +static struct expr *parse_expr(struct parser_state *state) { + struct expr *expr = parse_clause(state); while (expr) { const char *arg = skip_paths(state); @@ -645,14 +645,14 @@ static expression *parse_expression(parser_state *state) { ++state->i; - expression *lhs = expr; - expression *rhs = parse_clause(state); + struct expr *lhs = expr; + struct expr *rhs = parse_clause(state); if (!rhs) { - free_expression(lhs); + free_expr(lhs); return NULL; } - expr = new_comma_expression(lhs, rhs); + expr = new_comma_expr(lhs, rhs); } return expr; @@ -661,8 +661,8 @@ static expression *parse_expression(parser_state *state) { /** * Parse the command line. */ -cmdline *parse_cmdline(int argc, char *argv[]) { - cmdline *cl = malloc(sizeof(cmdline)); +struct cmdline *parse_cmdline(int argc, char *argv[]) { + struct cmdline *cl = malloc(sizeof(struct cmdline)); if (!cl) { goto fail; } @@ -681,7 +681,7 @@ cmdline *parse_cmdline(int argc, char *argv[]) { goto fail; } - parser_state state = { + struct parser_state state = { .cl = cl, .argv = argv, .i = 1, @@ -691,7 +691,7 @@ cmdline *parse_cmdline(int argc, char *argv[]) { }; if (skip_paths(&state)) { - cl->expr = parse_expression(&state); + cl->expr = parse_expr(&state); if (!cl->expr) { goto fail; } @@ -703,12 +703,12 @@ cmdline *parse_cmdline(int argc, char *argv[]) { } if (state.implicit_print) { - expression *print = new_expression(eval_print); + struct expr *print = new_expr(eval_print); if (!print) { goto fail; } - cl->expr = new_and_expression(cl->expr, print); + cl->expr = new_and_expr(cl->expr, print); if (!cl->expr) { goto fail; } |