back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/data_struct.h
blob: 694150a08b6fcf114ff079cb87a435238704bc6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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