|
|
@@ -17,11 +17,12 @@ const string SNF4CGP_VERSION_INFO = "CGPSNF Version 0.1.0 Build: " __DATE__ " " |
|
|
|
|
|
|
|
const int ConfigPathArgNumber = 1;
|
|
|
|
const int MaxArgcNumber = 2;
|
|
|
|
const string DefaultConfigFile = "snf_engine.xml";
|
|
|
|
|
|
|
|
#if defined(WIN32) || defined(WIN64)
|
|
|
|
const string DefaultConfigPath = "C:\\CommuniGatePro\\CGPSNF\\snf_engine.xml";
|
|
|
|
const string PathSep = "\\";
|
|
|
|
#else
|
|
|
|
const string DefaultConfigPath = "/var/CommuniGate/CGPSNF/snf_engine.xml";
|
|
|
|
const string PathSep = "/";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool CommandLineIsValid(int argc, char*argv[]) { // Validate the command line.
|
|
|
@@ -30,18 +31,29 @@ bool CommandLineIsValid(int argc, char*argv[]) { |
|
|
|
<< "\tCGPSNF <path_to_config_file>" << endl
|
|
|
|
<< "to use the specified config file, or" << endl
|
|
|
|
<< "\tCGSNF" << endl
|
|
|
|
<< "to use the default config file '" << DefaultConfigPath << "'"
|
|
|
|
<< "to use the default config file '" << DefaultConfigFile << "' "
|
|
|
|
<< "in the same directory as the executable."
|
|
|
|
<< endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
string GetConfigPath(int argc, char *argv[]) { // Returns the config file name.
|
|
|
|
if (ConfigPathArgNumber < argc) {
|
|
|
|
string ConfigPathFromArgv0(const string Argv0) { // Return the config file name in
|
|
|
|
// the same directory as the executable.
|
|
|
|
string::size_type LastSlashIndex = Argv0.find_last_of(PathSep);
|
|
|
|
if (string::npos == LastSlashIndex) { // If there's no slash in the path...
|
|
|
|
return DefaultConfigFile;
|
|
|
|
}
|
|
|
|
return Argv0.substr(0, LastSlashIndex + 1) + DefaultConfigFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
string getConfigPath(int argc, char *argv[]) { // Returns the config file name.
|
|
|
|
bool ConfigurationPathProvided = (ConfigPathArgNumber < argc);
|
|
|
|
if (ConfigurationPathProvided) {
|
|
|
|
return string(argv[ConfigPathArgNumber]);
|
|
|
|
}
|
|
|
|
return DefaultConfigPath;
|
|
|
|
return ConfigPathFromArgv0(argv[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void go(string ConfigurationPath) { // Application's main thread.
|
|
|
@@ -60,6 +72,6 @@ void go(string ConfigurationPath) { |
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) { // Main entry point.
|
|
|
|
if(CommandLineIsValid(argc, argv)) go(GetConfigPath(argc, argv)); // With a good command line we go.
|
|
|
|
if(CommandLineIsValid(argc, argv)) go(getConfigPath(argc, argv)); // With a good command line we go.
|
|
|
|
return 0; // Then we're done.
|
|
|
|
}
|