[Olsr-dev] [PATCH v1 18/43] main: minor improvements to loadConfig
Ferry Huberts
(spam-protected)
Wed Nov 11 17:21:51 CET 2015
From: Ferry Huberts <(spam-protected)>
And add some comments
Signed-off-by: Ferry Huberts <(spam-protected)>
---
src/main.c | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/src/main.c b/src/main.c
index 5897ed1..20dec74 100644
--- a/src/main.c
+++ b/src/main.c
@@ -182,48 +182,54 @@ static void loadConfig(int *argc, char *argv[], char * conf_file_name, int conf_
bool loadedConfig = false;
int i;
+ /* setup the default olsrd configuration file name in conf_file_name */
#ifdef _WIN32
size_t len = 0;
#ifndef WINCE
+ /* get the current directory */
GetWindowsDirectory(conf_file_name, FILENAME_MAX - 11);
#else /* WINCE */
- conf_file_name[0] = 0;
+ conf_file_name[0] = '\0';
#endif /* WINCE */
len = strlen(conf_file_name);
-
- if (len == 0 || conf_file_name[len - 1] != '\\')
- conf_file_name[len++] = '\\';
+ if (!len || (conf_file_name[len - 1] != '\\')) {
+ conf_file_name[len++] = '\\';
+ }
strscpy(conf_file_name + len, "olsrd.conf", sizeof(conf_file_name) - len);
#else /* _WIN32 */
strscpy(conf_file_name, OLSRD_GLOBAL_CONF_FILE, conf_file_name_size);
#endif /* _WIN32 */
+ /* get the default configuration */
olsr_cnf = olsrd_get_default_cnf(strdup(conf_file_name));
- for (i = 1; i < *argc - 1;) {
+ /* scan for -f configFile arguments */
+ for (i = 1; i < (*argc - 1);) {
if (strcmp(argv[i], "-f") == 0) {
- loadedConfig = true;
-
- if (olsrmain_load_config(argv[i + 1]) < 0) {
- olsr_exit(NULL, EXIT_FAILURE);
- }
+ /* setup the provided olsrd configuration file name in conf_file_name */
strscpy(conf_file_name, argv[i + 1], conf_file_name_size);
- if (i + 2 < *argc) {
+ /* remove -f confgFile arguments from argc and argv */
+ if ((i + 2) < *argc) {
memmove(&argv[i], &argv[i + 2], sizeof(*argv) * (*argc - i - 1));
}
*argc -= 2;
+
+ /* load the config from the file */
+ if (olsrmain_load_config(conf_file_name) < 0) {
+ olsr_exit(NULL, EXIT_FAILURE);
+ }
+
+ loadedConfig = true;
} else {
i++;
}
}
- /*
- * set up configuration prior to processing commandline options
- */
+ /* set up configuration prior to processing command-line options */
if (!loadedConfig && olsrmain_load_config(conf_file_name) == 0) {
loadedConfig = true;
}
--
2.5.0
More information about the Olsr-dev
mailing list