[10091] Use ACE for command line options parse.

Note: "--service run" renamed to "-s run"
in consistence with other serrvice options.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
Astellar 2010-06-21 06:37:25 +04:00 committed by VladimirMangos
parent 9d8dd578ca
commit 78400f8406
4 changed files with 110 additions and 109 deletions

View file

@ -31,6 +31,7 @@
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
#include <ace/Version.h>
#include <ace/Get_Opt.h>
#ifdef WIN32
#include "ServiceWin32.h"
@ -56,11 +57,11 @@ uint32 realmID; ///< Id of the realm
void usage(const char *prog)
{
sLog.outString("Usage: \n %s [<options>]\n"
" --version print version and exist\n\r"
" -v, --version print version and exist\n\r"
" -c config_file use config_file as configuration file\n\r"
#ifdef WIN32
" Running as service functions:\n\r"
" --service run as service\n\r"
" -s run run as service\n\r"
" -s install install service\n\r"
" -s uninstall uninstall service\n\r"
#endif
@ -75,69 +76,69 @@ extern int main(int argc, char **argv)
//char *leak = new char[1000]; // test leak detection
///- Command line parsing to get the configuration file name
///- Command line parsing
char const* cfg_file = _MANGOSD_CONFIG;
int c=1;
while(c < argc)
#ifdef WIN32
char const *options = ":c:s:";
#else
char const *options = ":c:";
#endif
ACE_Get_Opt cmd_opts(argc, argv, options);
cmd_opts.long_option("version", 'v');
int option;
while ((option = cmd_opts()) != EOF)
{
if (strcmp(argv[c],"-c") == 0)
switch (option)
{
if (++c >= argc)
case 'c':
cfg_file = cmd_opts.opt_arg();
break;
case 'v':
printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID));
return 0;
#ifdef WIN32
case 's':
{
sLog.outError("Runtime-Error: -c option requires an input argument");
usage(argv[0]);
return 1;
const char *mode = cmd_opts.opt_arg();
if (!strcmp(mode, "install"))
{
if (WinServiceInstall())
sLog.outString("Installing service");
return 1;
}
else if (!strcmp(mode, "uninstall"))
{
if (WinServiceUninstall())
sLog.outString("Uninstalling service");
return 1;
}
else if (!strcmp(mode, "run"))
WinServiceRun();
else
{
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
usage(argv[0]);
Log::WaitBeforeContinueIfNeed();
return 1;
}
break;
}
else
cfg_file = argv[c];
}
if (strcmp(argv[c],"--version") == 0)
{
printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID));
return 0;
}
#ifdef WIN32
////////////
//Services//
////////////
if (strcmp(argv[c],"-s") == 0)
{
if (++c >= argc)
{
sLog.outError("Runtime-Error: -s option requires an input argument");
#endif
case ':':
sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt());
usage(argv[0]);
Log::WaitBeforeContinueIfNeed();
return 1;
}
else if (strcmp(argv[c],"install") == 0)
{
if (WinServiceInstall())
sLog.outString("Installing service");
return 1;
}
else if ( strcmp(argv[c],"uninstall") == 0)
{
if(WinServiceUninstall())
sLog.outString("Uninstalling service");
return 1;
}
else
{
sLog.outError("Runtime-Error: unsupported option %s",argv[c]);
default:
sLog.outError("Runtime-Error: bad format of commandline arguments");
usage(argv[0]);
Log::WaitBeforeContinueIfNeed();
return 1;
}
}
if (strcmp(argv[c],"--service") == 0)
{
WinServiceRun();
}
////
#endif
++c;
}
if (!sConfig.SetSource(cfg_file))