Commit 292535fe authored by Frédéric Leroy's avatar Frédéric Leroy

refactor(conf2uedata.c): rewrite main() and add parse_config_file()

parent 804595d4
...@@ -8,21 +8,19 @@ ...@@ -8,21 +8,19 @@
char * make_filename(const char *output_dir, const char *filename, int ueid); char * make_filename(const char *output_dir, const char *filename, int ueid);
int get_config_from_file(const char *filename, config_t *config); int get_config_from_file(const char *filename, config_t *config);
int parse_config_file(const char *filename);
int main(int argc, char**argv) { int main(int argc, char**argv) {
int rc = EXIT_SUCCESS;
int option; int option;
const char* conf_file = NULL; const char* conf_file = NULL;
while ((option = getopt(argc, argv, options)) != -1) { while ((option = getopt(argc, argv, options)) != -1) {
switch (option) { switch (option) {
case 'c': case 'c':
parse_data = TRUE;
conf_file = optarg; conf_file = optarg;
break; break;
case 'o': case 'o':
output_dir = optarg; output_dir = optarg;
output = TRUE;
break; break;
case 'h': case 'h':
_display_usage(); _display_usage();
...@@ -33,25 +31,28 @@ int main(int argc, char**argv) { ...@@ -33,25 +31,28 @@ int main(int argc, char**argv) {
} }
} }
if (output == FALSE && parse_data == TRUE) { if (output_dir == NULL ) {
printf("No output option found\n"); printf("No output option found\n");
_display_usage(); _display_usage();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (output == TRUE && parse_data == FALSE) { if ( conf_file == NULL ) {
printf("No Configuration file is given\n"); printf("No Configuration file is given\n");
_display_usage(); _display_usage();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (parse_data == FALSE && print_data == FALSE) { if ( parse_config_file(conf_file) == EXIT_FAILURE ) {
printf("No options found\n"); exit(EXIT_FAILURE);
_display_usage();
return EXIT_FAILURE;
} }
if (parse_data) { exit(EXIT_SUCCESS);
}
int parse_config_file(const char *filename) {
int rc = EXIT_SUCCESS;
int ret; int ret;
int ue_nb = 0; int ue_nb = 0;
config_setting_t *root_setting = NULL; config_setting_t *root_setting = NULL;
...@@ -60,7 +61,7 @@ int main(int argc, char**argv) { ...@@ -60,7 +61,7 @@ int main(int argc, char**argv) {
char user[10]; char user[10];
config_t cfg; config_t cfg;
ret = get_config_from_file(conf_file, &cfg); ret = get_config_from_file(filename, &cfg);
if (ret == EXIT_FAILURE) { if (ret == EXIT_FAILURE) {
exit(1); exit(1);
} }
...@@ -113,9 +114,7 @@ int main(int argc, char**argv) { ...@@ -113,9 +114,7 @@ int main(int argc, char**argv) {
_display_usim_data(i); _display_usim_data(i);
} }
config_destroy(&cfg); config_destroy(&cfg);
} return(EXIT_SUCCESS);
exit(EXIT_SUCCESS);
} }
int get_config_from_file(const char *filename, config_t *config) { int get_config_from_file(const char *filename, config_t *config) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment