From ce4fe3550920241f33e597b3a11985924f98a7ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Wed, 10 Jul 2013 16:49:39 +0200 Subject: [PATCH] Removed back AppConfiguration class. Postponed its implementation. --- Makefile.am | 4 ++-- src/global/AppConfiguration.cpp | 9 -------- src/global/AppConfiguration.h | 10 --------- src/kernel/kernel.cpp | 37 +++++++++++++++++++++++++-------- src/net/lognet.cpp | 25 +++++++++++++++------- 5 files changed, 48 insertions(+), 37 deletions(-) delete mode 100644 src/global/AppConfiguration.cpp delete mode 100644 src/global/AppConfiguration.h diff --git a/Makefile.am b/Makefile.am index f802c53..e8624a5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -37,7 +37,7 @@ src/graph/loggraph.moc: clean-loggraph-extra: rm -f src/graph/*.moc.cpp -bin_lognet_SOURCES = src/net/lognet.cpp src/net/lognet.moc.cpp src/global/AppConfiguration.cpp +bin_lognet_SOURCES = src/net/lognet.cpp src/net/lognet.moc.cpp bin_lognet_CPPFLAGS = $(bin_lognet_CFLAGS) bin_lognet_LDADD = $(bin_lognet_LIBS) src/net/lognet.moc.cpp: @@ -46,7 +46,7 @@ src/net/lognet.moc.cpp: clean-lognet-extra: rm -f src/net/*.moc.cpp -bin_logker_SOURCES = src/kernel/kernel.cpp src/kernel/kernel.moc src/global/AppConfiguration.cpp +bin_logker_SOURCES = src/kernel/kernel.cpp src/kernel/kernel.moc bin_logker_CPPFLAGS = $(bin_logker_CFLAGS) bin_logker_LDADD = $(bin_logker_LIBS) src/kernel/kernel.moc: diff --git a/src/global/AppConfiguration.cpp b/src/global/AppConfiguration.cpp deleted file mode 100644 index b29b76e..0000000 --- a/src/global/AppConfiguration.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "AppConfiguration.h" - -void AppConfiguration::error(config_t *cfg) -{ - fprintf(stderr, "%s: In file %s, line %d\n", - config_error_text(cfg), - config_error_file(cfg), - config_error_line(cfg)); -} diff --git a/src/global/AppConfiguration.h b/src/global/AppConfiguration.h deleted file mode 100644 index 23e2eb0..0000000 --- a/src/global/AppConfiguration.h +++ /dev/null @@ -1,10 +0,0 @@ -#include - -/** - * Class for maintaining application configuration. - */ -class AppConfiguration { -protected: -public: - static void error(config_t *cfg); -}; diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index 1de50af..3126480 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -72,7 +72,6 @@ #include #include -#include "AppConfiguration.h" #define GPATH "loggr" #define IPATH "logi" @@ -304,22 +303,29 @@ void QKernel::LoadConfig(char * fname) exit(3); } /* File exists, so file has been locked. Release it. */ - fclose(file); config_init(&cfg); /* Read the file. If there is an error, report it and exit. */ - if(!config_read_file(&cfg, fname)) + if(!config_read(&cfg, file)) { - AppConfiguration::error(&cfg); + fprintf(stderr, "%s! In file %s, line %d\n", + config_error_text(&cfg), + config_error_file(&cfg), + config_error_line(&cfg)); config_destroy(&cfg); + fclose(file); exit(3);/* from original code. */ } if(!config_lookup_int(&cfg, "node_number", &NodeNumber)) { - AppConfiguration::error(&cfg); + fprintf(stderr, "%s! In file %s, '%s' was not found.\n", + "Warning", + fname, + "node_number"); config_destroy(&cfg); + fclose(file); exit(3); } @@ -327,7 +333,10 @@ void QKernel::LoadConfig(char * fname) ConType = (strcmp(str, "explicit") == 0) ? 1 : 2; } else { - AppConfiguration::error(&cfg); + fprintf(stderr, "%s! In file %s, '%s' was not found.\n", + "Warning", + fname, + "type"); } @@ -335,24 +344,34 @@ void QKernel::LoadConfig(char * fname) ConnectList.append(new ConnectEntry((char*)str)); } else { - AppConfiguration::error(&cfg); + fprintf(stderr, "%s! In file %s, '%s' was not found.\n", + "Warning", + fname, + "host"); } if(config_lookup_string(&cfg, "progdir", &str)){ strncpy(progdir, str, 256); } else { - AppConfiguration::error(&cfg); + fprintf(stderr, "%s! In file %s, '%s' was not found.\n", + "Warning", + fname, + "progdir"); } if(config_lookup_string(&cfg, "homedir", &str)){ strncpy(HomeDir, str, 255); } else { - AppConfiguration::error(&cfg); + fprintf(stderr, "%s! In file %s, '%s' was not found.\n", + "Warning", + fname, + "homedir"); } config_destroy(&cfg); + fclose(file); } /* +++++++++++++++++++++++++++++++++++++++++++++++ */ diff --git a/src/net/lognet.cpp b/src/net/lognet.cpp index fce3aee..dc2a750 100644 --- a/src/net/lognet.cpp +++ b/src/net/lognet.cpp @@ -23,7 +23,6 @@ #include #include -#include "AppConfiguration.h" #define REMOTE_PATH "REMOTE" #define MAXLINKS 30 @@ -199,16 +198,19 @@ void NETMOD::load_config(char *fname) if (!file) { fprintf(stderr, "Error: Cannot load configuration file %s!\n", fname); write_at_console("Cannot load configuration file!"); + fclose(file); exit(3); } - /* File exists, so file has been locked. Release it. */ - fclose(file); /* Read the file. If there is an error, report it and exit. */ - if(!config_read_file(&cfg, fname)) + if(!config_read(&cfg, file)) { - AppConfiguration::error(&cfg); + fprintf(stderr, "%s: In file %s, line %d\n", + config_error_text(&cfg), + config_error_file(&cfg), + config_error_line(&cfg)); config_destroy(&cfg); + fclose(file); exit(3);/* from original code. */ } @@ -217,13 +219,18 @@ void NETMOD::load_config(char *fname) if (MyNode==-1) { write_at_console("Node number must be specified"); config_destroy(&cfg); + fclose(file); exit(1); }; } else { - AppConfiguration::error(&cfg); + fprintf(stderr, "%s! In file %s, '%s' was not found.\n", + "Warning", + fname, + "node_number"); config_destroy(&cfg); + fclose(file); exit(1); } @@ -240,10 +247,14 @@ void NETMOD::load_config(char *fname) to_connect++; } else { - AppConfiguration::error(&cfg); + fprintf(stderr, "%s! In file %s, '%s' was not found.\n", + "Warning", + fname, + "host"); } config_destroy(&cfg); + fclose(file); if (k==0) all_connected=TRUE; } -- 2.30.2