Skip to content
Snippets Groups Projects
Commit d38c2400 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Usage/syntax help output, read svdm.ini from path of svdm.exe

Support specifying an additional or alternate .ini file to read using -c<fname> option.
parent 2926ff0b
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -92,9 +92,23 @@ static void dprintf(const char *fmt, ...) ...@@ -92,9 +92,23 @@ static void dprintf(const char *fmt, ...)
OutputDebugString(buf); OutputDebugString(buf);
} }
void usage(void) void usage(const char* progname)
{ {
fprintf(stderr, "usage:\n"); fprintf(stderr, "usage: %s [-opts] <program> [options]\n"
"opts:\n"
"\t-telnet Use Telnet protocol by default\n"
"\t-raw Use Raw TCP by default\n"
"\t-4 Use IPv4 address family by default\n"
"\t-6 Use IPv6 address family by default\n"
"\t-l[addr] Listen for incoming TCP connections\n"
"\t [on optionally-specified network interface]\n"
"\t-p<port> Specify default TCP port number (decimal)\n"
"\t-d Enable debug output\n"
"\t-h<sock> Specify socket descriptor/handle to use (decimal)\n"
"\t-r<cps> Specify maximum receive data rate (chars/second)\n"
"\t-c<fname> Specify alternate configuration (.ini) filename\n"
,progname
);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
...@@ -945,6 +959,26 @@ void listen_thread(void* arg) ...@@ -945,6 +959,26 @@ void listen_thread(void* arg)
} }
} }
bool read_ini(const char* ini_fname)
{
printf("Reading '%s'\n", ini_fname);
FILE* fp = iniOpenFile(ini_fname, /* create: */false);
if(fp == NULL)
return false;
ini = iniReadFile(fp);
iniCloseFile(fp);
mode = iniGetEnum(ini, ROOT_SECTION, "Mode", modeNames, mode);
cfg.port = iniGetShortInt(ini, ROOT_SECTION, "Port", cfg.port);
cfg.node_num = iniGetInteger(ini, ROOT_SECTION, "Node", cfg.node_num);
cfg.listen = iniGetBool(ini, ROOT_SECTION, "Listen", cfg.listen);
cfg.debug = iniGetBool(ini, ROOT_SECTION, "Debug", cfg.debug);
cfg.server_echo = iniGetBool(ini, ROOT_SECTION, "ServerEcho", cfg.server_echo);
cfg.data_rate = iniGetLongInt(ini, ROOT_SECTION, "Rate", cfg.data_rate);
cfg.address_family = iniGetEnum(ini, ROOT_SECTION, "AddressFamily", addrFamilyNames, cfg.address_family);
return true;
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int argn = 1; int argn = 1;
...@@ -972,25 +1006,13 @@ int main(int argc, char** argv) ...@@ -972,25 +1006,13 @@ int main(int argc, char** argv)
cfg.address_family = ADDRESS_FAMILY_INET; cfg.address_family = ADDRESS_FAMILY_INET;
ini = strListInit(); ini = strListInit();
SAFECOPY(ini_fname, argv[0]); GetModuleFileName(NULL, ini_fname, sizeof(ini_fname) - 1);
char* ext = getfext(ini_fname); char* ext = getfext(ini_fname);
if(ext != NULL) if(ext != NULL)
*ext = 0; *ext = 0;
SAFECAT(ini_fname, ".ini"); SAFECAT(ini_fname, ".ini");
fprintf(stderr, "ini_fname = '%s'\n", ini_fname); if(fexist(ini_fname))
FILE* fp = iniOpenFile(ini_fname, /* create: */false); read_ini(ini_fname);
if(fp != NULL) {
ini = iniReadFile(fp);
iniCloseFile(fp);
mode = iniGetEnum(ini, ROOT_SECTION, "Mode", modeNames, mode);
cfg.port = iniGetShortInt(ini, ROOT_SECTION, "Port", cfg.port);
cfg.node_num = iniGetInteger(ini, ROOT_SECTION, "Node", cfg.node_num);
cfg.listen = iniGetBool(ini, ROOT_SECTION, "Listen", cfg.listen);
cfg.debug = iniGetBool(ini, ROOT_SECTION, "Debug", cfg.debug);
cfg.server_echo = iniGetBool(ini, ROOT_SECTION, "ServerEcho", cfg.server_echo);
cfg.data_rate = iniGetLongInt(ini, ROOT_SECTION, "Rate", cfg.data_rate);
cfg.address_family = iniGetEnum(ini, ROOT_SECTION, "AddressFamily", addrFamilyNames, cfg.address_family);
}
for(; argn < argc; argn++) { for(; argn < argc; argn++) {
char* arg = argv[argn]; char* arg = argv[argn];
...@@ -1027,6 +1049,12 @@ int main(int argc, char** argv) ...@@ -1027,6 +1049,12 @@ int main(int argc, char** argv)
case 'p': case 'p':
cfg.port = atoi(arg + 1); cfg.port = atoi(arg + 1);
break; break;
case 'c':
if(!read_ini(arg + 1)) {
fprintf(stderr, "!Error %d reading: %s\n", errno, arg + 1);
return EXIT_FAILURE;
}
break;
case 'd': case 'd':
cfg.debug = true; cfg.debug = true;
break; break;
...@@ -1042,12 +1070,12 @@ int main(int argc, char** argv) ...@@ -1042,12 +1070,12 @@ int main(int argc, char** argv)
rx_delay = strtoul(arg + 1, NULL, 10); rx_delay = strtoul(arg + 1, NULL, 10);
break; break;
default: default:
usage(); usage(argv[0]);
break; break;
} }
} }
if(argn >= argc) { if(argn >= argc) {
usage(); usage(argv[0]);
} }
struct modem modem = {0}; struct modem modem = {0};
...@@ -1086,7 +1114,7 @@ int main(int argc, char** argv) ...@@ -1086,7 +1114,7 @@ int main(int argc, char** argv)
} }
const char* dropfile = "dosxtrn.env"; const char* dropfile = "dosxtrn.env";
fp = fopen(dropfile, "w"); FILE* fp = fopen(dropfile, "w");
if(fp == NULL) { if(fp == NULL) {
perror(dropfile); perror(dropfile);
return EXIT_FAILURE; return EXIT_FAILURE;
...@@ -1154,7 +1182,7 @@ int main(int argc, char** argv) ...@@ -1154,7 +1182,7 @@ int main(int argc, char** argv)
BOOL x64 = FALSE; BOOL x64 = FALSE;
IsWow64Process(GetCurrentProcess(), &x64); IsWow64Process(GetCurrentProcess(), &x64);
sprintf(fullmodemline, "dosxtrn.exe %s %s %u svdm.ini", dropfile, x64 ? "x64" : "NT", cfg.node_num); sprintf(fullmodemline, "dosxtrn.exe %s %s %u %s", dropfile, x64 ? "x64" : "NT", cfg.node_num, ini_fname);
PROCESS_INFORMATION process_info; PROCESS_INFORMATION process_info;
if(!CreateProcess( if(!CreateProcess(
...@@ -1163,7 +1191,7 @@ int main(int argc, char** argv) ...@@ -1163,7 +1191,7 @@ int main(int argc, char** argv)
NULL, // process security attributes NULL, // process security attributes
NULL, // thread security attributes NULL, // thread security attributes
FALSE, // handle inheritance flag FALSE, // handle inheritance flag
0, //CREATE_NEW_CONSOLE/*|CREATE_SEPARATE_WOW_VDM*/, // creation flags 0, // creation flags
NULL, // pointer to new environment block NULL, // pointer to new environment block
NULL , // pointer to current directory name NULL , // pointer to current directory name
&startup_info, // pointer to STARTUPINFO &startup_info, // pointer to STARTUPINFO
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment