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
|
#include <stdio.h>
#include "defs.h"
#include "utils.h"
#include "configuration.h"
#define FLAG_IMPLEMENTATION
#include "flag.h"
void
print_help ();
void
parse_args (int argc,str_t* argv);
int main(int argc, char **argv) {
parse_args (argc, argv);
return 0;
}
void
print_help () {
fprintf (stdout, PROJECT_NAME " " PROJECT_VERSION "\n");
fprintf (stdout, "OPTIONS:\n");
flag_print_options (stdout);
}
void
parse_args (int argc, str_t* argv) {
bool *_help = flag_bool ("help", false, "Print the this help message.");
str_t* _in_path = flag_str ("i", "", "The path to the input file");
str_t* _out_path = flag_str ("o", "a.out", "The path to the output file");
if (!flag_parse(argc, argv)) {
print_help ();
flag_print_error(stderr);
exit(1);
}
if (*_help) {
print_help ();
}
if (!(strlen(*_in_path))) {
fprintf (stdout, "Missing input file.\n\n");
print_help ();
exit (1);
}
// check if file exists.
FILE * f;
f = fopen (*_in_path, "r");
if (f) {
fclose (f);
} else {
err_print ("File %s can not be found or is unreadable.\n", *_in_path);
}
f = fopen (*_out_path, "w");
if (f) {
fclose (f);
} else {
err_print ("Could not write to file %s."
" Do you have accesse to the file?\n",
*_out_path);
}
Configuration * cfg = configuration_get_default ();
cfg->in_file_path = *_in_path;
cfg->out_file_path = *_out_path;
}
|