Added environment variable handling.
* source/server/main.c (main): - Added environment variable handling. - Moved "Using" messages to after both command line arguments and enviroment variables are checked and applied. - Command-line arguments override enviroment variables.
This commit is contained in:
parent
9660fd4c60
commit
0a2d03fdaa
|
@ -65,7 +65,22 @@ int main (int argc, char ** argv)
|
||||||
{"interface", required_argument, 0, 'i' }
|
{"interface", required_argument, 0, 'i' }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Check environment variables:
|
||||||
|
if (getenv("SILVERMUD_SERVER_PORT") != NULL)
|
||||||
|
{
|
||||||
|
portSpecified = true;
|
||||||
|
strncpy(serverPort, getenv("SILVERMUD_SERVER_HOST"), HOST_NAME_MAX);
|
||||||
|
}
|
||||||
|
if (getenv("SILVERMUD_SERVER_HOST") != NULL)
|
||||||
|
{
|
||||||
|
hostSpecified = true;
|
||||||
|
strncpy(serverHostname, getenv("SILVERMUD_SERVER_HOST"), HOST_NAME_MAX);
|
||||||
|
}
|
||||||
|
if (getenv("SILVERMUD_SERVER_INTERFACE") != NULL)
|
||||||
|
{
|
||||||
|
interfaceSpecified = true;
|
||||||
|
strncpy(serverInterface, getenv("SILVERMUD_SERVER_INTERFACE"), HOST_NAME_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
// Parse command-line options:
|
// Parse command-line options:
|
||||||
int selectedOption = 0, optionIndex = 0;
|
int selectedOption = 0, optionIndex = 0;
|
||||||
|
@ -75,14 +90,13 @@ int main (int argc, char ** argv)
|
||||||
{
|
{
|
||||||
case 'p':
|
case 'p':
|
||||||
{
|
{
|
||||||
printf("Using port: %s\n", optarg);
|
|
||||||
portSpecified = true;
|
portSpecified = true;
|
||||||
strncpy(serverPort, optarg, HOST_NAME_MAX);
|
strncpy(serverPort, optarg, HOST_NAME_MAX);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'h':
|
case 'h':
|
||||||
{
|
{
|
||||||
printf("Using hostname: %s\n", optarg);
|
|
||||||
hostSpecified = true;
|
hostSpecified = true;
|
||||||
strncpy(serverHostname, optarg, HOST_NAME_MAX);
|
strncpy(serverHostname, optarg, HOST_NAME_MAX);
|
||||||
break;
|
break;
|
||||||
|
@ -97,6 +111,21 @@ int main (int argc, char ** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (portSpecified)
|
||||||
|
{
|
||||||
|
printf("Using port: %s\n", serverPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hostSpecified)
|
||||||
|
{
|
||||||
|
printf("Using hostname: %s\n", serverHostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interfaceSpecified)
|
||||||
|
{
|
||||||
|
printf("Using interface: %s\n", serverInterface);
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize Scheme:
|
// Initialize Scheme:
|
||||||
scm_init_guile();
|
scm_init_guile();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue