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)
(cherry picked from commit b7f4e10fe1)
This commit is contained in:
Matthew Flatt 2013-12-31 10:53:16 -07:00 committed by Ryan Culpepper
parent 2da854f448
commit 5087b9932b
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)
{
if ((*cmd == '-') || (*cmd == '/'))
cmd++;
else
return 0;
while (*flag) {
if (toupper(*cmd) != toupper(*flag))
return 0;
@ -111,6 +116,10 @@ int IsFlag(LPCTSTR cmd, LPCTSTR flag)
#define DLL_RELATIVE_PATH L"."
#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,
@ -135,13 +144,18 @@ extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
_ASSERTE(SUCCEEDED(hRes));
_Module.Init(ObjectMap, hInstance, &LIBID_MZCOMLib);
_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;
BOOL bRun = TRUE;
LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
while (lpszToken != NULL)
LPCTSTR lpszToken;
for (i = 1; i < argc; i++)
{
lpszToken = argv[i];
if (IsFlag(lpszToken, _T("UnregServer")))
{
if (!nRet) {
@ -185,7 +199,6 @@ extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
bRun = FALSE;
break;
}
lpszToken = FindOneOf(lpszToken, szTokens);
}
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_set_exec_cmd(exeBuff);
scheme_set_collects_path(scheme_make_path("../collects"));
scheme_set_config_path(scheme_make_path("../etc"));
scheme_init_collection_paths(env, scheme_make_null());
// initialize namespace
@ -309,6 +310,7 @@ static unsigned WINAPI evalLoop(void *args) XFORM_SKIP_PROC {
scheme_register_tls_space(&tls_space, 0);
#endif
scheme_set_atexit(record_at_exit);
return scheme_main_setup(1, do_evalLoop, 0, (char **)args);
}

View File

@ -1,5 +1,6 @@
/* Windows command-line parsing */
#ifndef ASSUME_ASCII_COMMAND_LINE
static char *wchar_to_char(wchar_t *wa, int len)
{
char *a;
@ -16,6 +17,7 @@ static char *wchar_to_char(wchar_t *wa, int len)
return a;
}
#endif
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)
{
#ifndef ASSUME_ASCII_COMMAND_LINE
LPWSTR m_lpCmdLine;
int j, argc, l;
int j, l;
#endif
int argc;
char *a, **argv, *normalized_path;
#ifdef ASSUME_ASCII_COMMAND_LINE
a = GetCommandLine();
#else
m_lpCmdLine = GetCommandLineW();
for (j = 0; m_lpCmdLine[j]; j++) {
}
a = wchar_to_char(m_lpCmdLine, j);
#endif
argc = parse_command_line(&argv, a);
#ifndef ASSUME_ASCII_COMMAND_LINE
/* 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
GetModuleFileName, just in case */
@ -119,6 +128,9 @@ static char **cmdline_to_argv(int *_argc, char **_normalized_path)
}
}
}
#else
normalized_path = "?";
#endif
*_argc = argc;
if (_normalized_path)