forked from slepp/rtlmux
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.c
44 lines (34 loc) · 865 Bytes
/
config.c
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
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include "cmdline.h"
#include "config.h"
#include "slog.h"
struct config config;
static struct gengetopt_args_info args;
int convertConfig(struct gengetopt_args_info *args) {
config.host = args->host_arg;
config.port = args->port_arg;
config.clientPort = args->listen_arg;
return 1;
}
int parseConfig(int argc, char **argv) {
int cr;
struct cmdline_c_params params;
cmdline_c_params_init(¶ms);
params.initialize = 1;
params.override = 0;
params.check_required = 0;
params.check_ambiguity = 0;
if((cr = cmdline_c_ext(argc, argv, &args, ¶ms)) != 0) {
exit(2);
}
if(cmdline_c_required(&args, argv[0]) != 0) {
printf("Please try again.");
exit(4);
}
return convertConfig(&args);
}