MzCom: fix command-line parsing

I couldn't get MzCOM to work in a release build, because my
installations always had a "-" in the path.

Merge bug fix to v6.0 (pending review)
This commit is contained in:
Matthew Flatt 2013-12-31 10:53:16 -07:00
parent 947bebad23
commit b7f4e10fe1
3 changed files with 33 additions and 6 deletions

View File

@ -97,6 +97,11 @@ LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2)
int IsFlag(LPCTSTR cmd, LPCTSTR flag) int IsFlag(LPCTSTR cmd, LPCTSTR flag)
{ {
if ((*cmd == '-') || (*cmd == '/'))
cmd++;
else
return 0;
while (*flag) { while (*flag) {
if (toupper(*cmd) != toupper(*flag)) if (toupper(*cmd) != toupper(*flag))
return 0; return 0;
@ -111,6 +116,10 @@ int IsFlag(LPCTSTR cmd, LPCTSTR flag)
#define DLL_RELATIVE_PATH L"." #define DLL_RELATIVE_PATH L"."
#include "../racket/delayed.inc" #include "../racket/delayed.inc"
#define ASSUME_ASCII_COMMAND_LINE
#define GC_CAN_IGNORE
#include "../racket/parse_cmdl.inc"
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
@ -135,13 +144,18 @@ extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
_ASSERTE(SUCCEEDED(hRes)); _ASSERTE(SUCCEEDED(hRes));
_Module.Init(ObjectMap, hInstance, &LIBID_MZCOMLib); _Module.Init(ObjectMap, hInstance, &LIBID_MZCOMLib);
_Module.dwThreadID = GetCurrentThreadId(); _Module.dwThreadID = GetCurrentThreadId();
TCHAR szTokens[] = _T("-/");
int argc, i;
char **argv, *normalized_path;
argv = cmdline_to_argv(&argc, &normalized_path);
int nRet = 0, verbose = 0; int nRet = 0, verbose = 0;
BOOL bRun = TRUE; BOOL bRun = TRUE;
LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); LPCTSTR lpszToken;
while (lpszToken != NULL) for (i = 1; i < argc; i++)
{ {
lpszToken = argv[i];
if (IsFlag(lpszToken, _T("UnregServer"))) if (IsFlag(lpszToken, _T("UnregServer")))
{ {
if (!nRet) { if (!nRet) {
@ -185,7 +199,6 @@ extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
bRun = FALSE; bRun = FALSE;
break; break;
} }
lpszToken = FindOneOf(lpszToken, szTokens);
} }
if (bRun) if (bRun)

View File

@ -157,6 +157,7 @@ void setupSchemeEnv(Scheme_Env *in_env)
scheme_add_global("mzcom-exe",scheme_make_utf8_string(exeBuff),env); scheme_add_global("mzcom-exe",scheme_make_utf8_string(exeBuff),env);
scheme_set_exec_cmd(exeBuff); scheme_set_exec_cmd(exeBuff);
scheme_set_collects_path(scheme_make_path("../collects")); scheme_set_collects_path(scheme_make_path("../collects"));
scheme_set_config_path(scheme_make_path("../etc"));
scheme_init_collection_paths(env, scheme_make_null()); scheme_init_collection_paths(env, scheme_make_null());
// initialize namespace // initialize namespace
@ -309,6 +310,7 @@ static unsigned WINAPI evalLoop(void *args) XFORM_SKIP_PROC {
scheme_register_tls_space(&tls_space, 0); scheme_register_tls_space(&tls_space, 0);
#endif #endif
scheme_set_atexit(record_at_exit); scheme_set_atexit(record_at_exit);
return scheme_main_setup(1, do_evalLoop, 0, (char **)args); return scheme_main_setup(1, do_evalLoop, 0, (char **)args);
} }

View File

@ -1,5 +1,6 @@
/* Windows command-line parsing */ /* Windows command-line parsing */
#ifndef ASSUME_ASCII_COMMAND_LINE
static char *wchar_to_char(wchar_t *wa, int len) static char *wchar_to_char(wchar_t *wa, int len)
{ {
char *a; char *a;
@ -16,6 +17,7 @@ static char *wchar_to_char(wchar_t *wa, int len)
return a; return a;
} }
#endif
static int parse_command_line(char ***_command, char *buf) static int parse_command_line(char ***_command, char *buf)
{ {
@ -80,18 +82,25 @@ static int parse_command_line(char ***_command, char *buf)
static char **cmdline_to_argv(int *_argc, char **_normalized_path) static char **cmdline_to_argv(int *_argc, char **_normalized_path)
{ {
#ifndef ASSUME_ASCII_COMMAND_LINE
LPWSTR m_lpCmdLine; LPWSTR m_lpCmdLine;
int j, argc, l; int j, l;
#endif
int argc;
char *a, **argv, *normalized_path; char *a, **argv, *normalized_path;
#ifdef ASSUME_ASCII_COMMAND_LINE
a = GetCommandLine();
#else
m_lpCmdLine = GetCommandLineW(); m_lpCmdLine = GetCommandLineW();
for (j = 0; m_lpCmdLine[j]; j++) { for (j = 0; m_lpCmdLine[j]; j++) {
} }
a = wchar_to_char(m_lpCmdLine, j); a = wchar_to_char(m_lpCmdLine, j);
#endif
argc = parse_command_line(&argv, a); argc = parse_command_line(&argv, a);
#ifndef ASSUME_ASCII_COMMAND_LINE
/* argv[0] should be the name of the executable, but Windows doesn't /* argv[0] should be the name of the executable, but Windows doesn't
specify really where this name comes from, so we get it from specify really where this name comes from, so we get it from
GetModuleFileName, just in case */ GetModuleFileName, just in case */
@ -119,6 +128,9 @@ static char **cmdline_to_argv(int *_argc, char **_normalized_path)
} }
} }
} }
#else
normalized_path = "?";
#endif
*_argc = argc; *_argc = argc;
if (_normalized_path) if (_normalized_path)