Преглед изворни кода

Default config file is now snf_milter.xml in the same directory as the

executable.


git-svn-id: https://svn.microneil.com/svn/SNF4CGP/trunk@46 59e8e3e7-56fa-483b-b4b4-fa6ab0af3dfc
master
adeniz пре 15 година
родитељ
комит
c3dbdd76e4
1 измењених фајлова са 19 додато и 7 уклоњено
  1. 19
    7
      SNF4CGP/main.cpp

+ 19
- 7
SNF4CGP/main.cpp Прегледај датотеку

@@ -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.
}

Loading…
Откажи
Сачувај