diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/list_management.h | 35 | ||||
| -rw-r--r-- | include/options.h | 44 | ||||
| -rw-r--r-- | include/output.h | 29 |
3 files changed, 108 insertions, 0 deletions
diff --git a/include/list_management.h b/include/list_management.h new file mode 100644 index 0000000..0a887c7 --- /dev/null +++ b/include/list_management.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +/* Copyright 2025 Thorsten Töpper + * + * list_management - data handling related code + * + * vim:ts=4:sw=4:expandtab + */ + +#ifndef LIST_MANAGEMENT_H +#define LIST_MANAGEMENT_H + +#include <time.h> + +/* === DEFINITIONS === */ +struct list_node { + struct list_node *next; + size_t fsize; + char fname[256]; + time_t ftime; /* can be creation, access or modification */ +}; + +struct list_head { + struct list_node *first; +}; + +struct list_node *create_node(char *fname, size_t fsize, time_t ftime); +struct list_head *create_list_sort_reversed(struct list_head *list); +void destroy_list(struct list_head *list); +int insert_sorted_by_size(struct list_head *list, struct list_node *node); +int insert_sorted_by_time(struct list_head *list, struct list_node *node); + + +#endif + diff --git a/include/options.h b/include/options.h new file mode 100644 index 0000000..70f22e4 --- /dev/null +++ b/include/options.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +/* Copyright 2025 Thorsten Töpper + * + * dir_monitor - print specified stat() information from entries of a given + * directory to stdout. Call it via watch for repeated output to a terminal. + * + * vim:ts=4:sw=4:expandtab + */ + +#ifndef OPTIONS_H +#define OPTIONS_H + +#include <stdbool.h> + +#include "output.h" +#include "list_management.h" + + + +/* === DEFINITIONS === */ +#define PATH_SEP '/' + +enum esort_type { SORT_BY_SIZE, SORT_BY_TIME }; + + +/* === GLOBAL VARIABLES === */ +extern bool option_sort_reverse_order; +extern enum esort_type option_sort_type; +extern bool option_show_hidden_entries; +extern bool option_timestamp_long; + + +int parse_arguments(int argc, char **argv); +void set_option(const char *option_name, char *option_argument); +/* In theory a part of output, but it's easier to place it near the struct + * containing the options in options.c */ +void usage(char *executable); + + + + +#endif + diff --git a/include/output.h b/include/output.h new file mode 100644 index 0000000..22f3885 --- /dev/null +++ b/include/output.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +/* Copyright 2025 Thorsten Töpper + * + * output related functions and definitions + * + * vim:ts=4:sw=4:expandtab + */ +#ifndef OUTPUT_H +#define OUTPUT_H +#include <stdio.h> + +#include "list_management.h" + + +#define LOGERR(...) {fprintf(stderr, "[%s:%d] %s: ", __FILE__, __LINE__, __func__); fprintf(stderr, __VA_ARGS__);} + +#ifdef DEBUGBUILD +#define DBGTRC(...) LOGERR(__VA_ARGS__) +#else +#define DBGTRC(...) +#endif + + +int fputc_all_cols(char c, FILE *fdout); +int fputc_width_x(char c, size_t x, FILE *fdout); +void print_list(struct list_head *list); +#endif + |
