Browse Source

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 years ago
parent
commit
c3dbdd76e4
1 changed files with 19 additions and 7 deletions
  1. 19
    7
      SNF4CGP/main.cpp

+ 19
- 7
SNF4CGP/main.cpp View File

const int ConfigPathArgNumber = 1; const int ConfigPathArgNumber = 1;
const int MaxArgcNumber = 2; const int MaxArgcNumber = 2;
const string DefaultConfigFile = "snf_engine.xml";
#if defined(WIN32) || defined(WIN64) #if defined(WIN32) || defined(WIN64)
const string DefaultConfigPath = "C:\\CommuniGatePro\\CGPSNF\\snf_engine.xml";
const string PathSep = "\\";
#else #else
const string DefaultConfigPath = "/var/CommuniGate/CGPSNF/snf_engine.xml";
const string PathSep = "/";
#endif #endif
bool CommandLineIsValid(int argc, char*argv[]) { // Validate the command line. bool CommandLineIsValid(int argc, char*argv[]) { // Validate the command line.
<< "\tCGPSNF <path_to_config_file>" << endl << "\tCGPSNF <path_to_config_file>" << endl
<< "to use the specified config file, or" << endl << "to use the specified config file, or" << endl
<< "\tCGSNF" << 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; << endl;
return false; return false;
} }
return true; 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 string(argv[ConfigPathArgNumber]);
} }
return DefaultConfigPath;
return ConfigPathFromArgv0(argv[0]);
} }
void go(string ConfigurationPath) { // Application's main thread. void go(string ConfigurationPath) { // Application's main thread.
} }
int main(int argc, char* argv[]) { // Main entry point. 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. return 0; // Then we're done.
} }

Loading…
Cancel
Save