diff options
author | scratko <m@scratko.xyz> | 2025-09-08 01:44:13 +0300 |
---|---|---|
committer | scratko <m@scratko.xyz> | 2025-09-08 01:44:13 +0300 |
commit | 6b7b0ea022ad18b30622acd5e1354ff64cf14d86 (patch) | |
tree | 3d8a8cdfc9985b7c242e66e3734c5cefcda21215 /data_struct.h | |
download | ls-imitation-6b7b0ea022ad18b30622acd5e1354ff64cf14d86.tar.gz ls-imitation-6b7b0ea022ad18b30622acd5e1354ff64cf14d86.tar.bz2 ls-imitation-6b7b0ea022ad18b30622acd5e1354ff64cf14d86.zip |
Diffstat (limited to 'data_struct.h')
-rw-r--r-- | data_struct.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/data_struct.h b/data_struct.h new file mode 100644 index 0000000..694150a --- /dev/null +++ b/data_struct.h @@ -0,0 +1,60 @@ +#ifndef DATA_STRUCT_H_SENTRY +#define DATA_STRUCT_H_SENTRY + +#include <stddef.h> + +/* + * data_struct.h + * + * This module provides basic data structures and helper functions + * for handling file information, directory/file arguments, and + * transforming them between linked lists and arrays. + * + */ + +enum { + buffer_size = 512 +}; + +/* + * Stores separated command-line arguments: + * dirs is array of directory paths + * files is array of file paths + */ +struct arg_arrays { + const char **dirs; + const char **files; +}; + +/* + * Single-linked list node containing file entry: + * info_line -- formatted string with file information + * filename used for sorting + */ +struct file_item { + char *info_line; + char *filename; + struct file_item *next; +}; + +/* + * array-based representation of file_item list: + * array -- dynamic array of pointers to file_item + */ +struct file_item_array { + struct file_item **array; + size_t length; +}; + +void init_arg_arrays(struct arg_arrays *split, int argc); +void init_item_array(struct file_item_array *arr); +void add_new_item(struct file_item **list, struct file_item **entry, + const char *file_name); +void copy_list_to_array(struct file_item *list, struct file_item_array *arr); +void free_file_item_array(struct file_item_array *arr, struct file_item **list); +void free_arg_arrays(struct arg_arrays *split); +int is_empty_array(const char **paths_array, int argc); +int is_last_arr_element(const char **paths_array, int argc, size_t pos); +void sort_array_by_names(struct file_item_array *arr); + +#endif |