-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.h
138 lines (123 loc) · 3.38 KB
/
config.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* @file config.h
* @author MeerkatBoss (solodovnikov.ia@phystech.edu)
*
* @brief
*
* @version 0.1
* @date 2023-04-23
*
* @copyright Copyright MeerkatBoss (c) 2023
*/
#ifndef __TABLE_UTILS_CONFIG_H
#define __TABLE_UTILS_CONFIG_H
#include <stdio.h>
#include "meerkat_args/argparser.h"
static const size_t hash_table_bucket_count = 7019;
struct ProgramConfig
{
const char* filename1;
const char* filename2;
FILE* output;
int print_verbose;
ssize_t max_words;
};
/**
* @brief Load program configuration
*
* @param[in] argc - Argument vector length
* @param[in] argv - Program argument vector
* @param[out] config - Loaded program configuration
*
* @return 0 upon success, -1 upon loading error
*/
int configure_program(int argc, const char* const* argv, ProgramConfig* config);
/**
* @brief Dispose the `ProgramConfig` object
*
* @param[inout] config - `ProgramConfig` instance to be disposed
*/
void unload_config(ProgramConfig* config);
/**
* @brief Output help information on parameter tags and terminate program
*
*/
__attribute__((noreturn))
int config_get_help(const char* const* str, void* params);
/**
* @brief Set output file for program
*
* @param[in] str - Input arguments
* @param[inout] params - `ProgramConfig` instance
*
* @return 1 on successful parse, -1 otherwise
*/
int config_set_output_file(const char* const* str, void* params);
/**
* @brief Set verbose output for program
*
* @param[in] str - Input arguments
* @param[inout] params - `ProgramConfig` instance
*
* @return 0
*/
int config_set_verbose(const char* const* str, void* params);
/**
* @brief Set max number of words to be read from file
*
* @param[in] str - Input arguments
* @param[inout] params - `ProgramConfig` instance
*
* @return 1 on successful parse, -1 otherwise
*/
int config_set_max_words(const char* const* str, void* params);
/**
* @brief Add input file for program
*
* @param[in] str - Input arguments
* @param[inout] params - `ProgramConfig` instance
*
* @return 1 on successful parse, -1 otherwise
*/
int config_add_input_file(const char* const* str, void* params);
static const arg_tag PARAMETER_TAGS[] = {
{
.short_tag = 'h',
.long_tag = "help",
.callback = config_get_help,
.description =
"Print help message and exit program"
},
{
.short_tag = 'o',
.long_tag = "output-file",
.callback = config_set_output_file,
.description =
"Print output to specified file instead of stdout"
},
{
.short_tag = 'v',
.long_tag = "verbose-diff",
.callback = config_set_verbose,
.description =
"Output each differing entry, instead of only the count"
},
{
.short_tag = 'n',
.long_tag = NULL,
.callback = config_set_max_words,
.description =
"Read only first <n> words from both files"
}
};
static const arg_info PROGRAM_ARGS = {
.help_message =
"hash_table [-o <file> | --output-file <file>]\n"
"\t[-v | --verbose-diff] <file1> <file2>\t- Compare text files\n"
"hash_table [-h | --help]\t- Get help on program usage",
.name_handler = NULL,
.plain_handler = config_add_input_file,
.tags = PARAMETER_TAGS,
.tag_cnt = sizeof(PARAMETER_TAGS) / sizeof(*PARAMETER_TAGS)
};
#endif /* config.h */