forked from metin2/server
1
0
Fork 0

Fixed getopt routine

This commit is contained in:
Exynox 2022-11-23 21:44:45 +02:00
parent ef2aee6b6b
commit ecf8b71218
1 changed files with 21 additions and 20 deletions

View File

@ -509,29 +509,28 @@ int start(int argc, char **argv)
std::string st_localeServiceName;
bool bVerbose = false;
char ch;
//_malloc_options = "A";
#if defined(__FreeBSD__) && defined(DEBUG_ALLOC)
_malloc_message = WriteMallocMessage;
#endif
while ((ch = getopt(argc, argv, "npverltI")) != -1)
int ch;
while ((ch = getopt(argc, argv, "n:p:verl:tI:")) != -1)
{
char* ep = NULL;
switch (ch)
{
case 'I': // IP
strncpy(g_szPublicIP, argv[optind], sizeof(g_szPublicIP));
strncpy(g_szPublicIP, optarg, sizeof(g_szPublicIP));
printf("IP %s\n", g_szPublicIP);
optind = 0;
break;
case 'p': // port
mother_port = strtol(argv[optind], &ep, 10);
mother_port = strtol(optarg, &ep, 10);
if (mother_port <= 1024)
{
@ -539,31 +538,21 @@ int start(int argc, char **argv)
return 0;
}
printf("port %d\n", mother_port);
printf("port %hu\n", mother_port);
optind = 0;
break;
case 'l':
{
int l = strtol(argv[optind], &ep, 10);
int l = strtol(optarg, &ep, 10);
log_set_level(l);
optind = 0;
}
break;
// LOCALE_SERVICE
case 'n':
{
if (optind < argc)
{
st_localeServiceName = argv[optind];
optind = 0;
}
}
st_localeServiceName = optarg;
break;
// END_OF_LOCALE_SERVICE
@ -580,6 +569,18 @@ int start(int argc, char **argv)
g_bTrafficProfileOn = true;
break;
// END_OF_TRAFFIC_PROFILER
case '?':
if (strchr("Ipln", optopt))
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
default:
usage();
return 1;
break;
}
}