/*
*
- * $Id: ghci.c,v 1.5 2002/01/07 16:32:54 sof Exp $
+ * $Id: ghci.c,v 1.8 2003/06/12 09:48:17 simonpj Exp $
*
- * ghci wrapper - invokes ghc.exe with the added command-line
+ * ghci wrapper for Win32 only
+ *
+ * This wrapper invokes ghc.exe with the added command-line
* option "--interactive".
+ * (On Unix this is done by the ghci.sh shell script, but
+ * that does not work so well on Win32.)
*
* (c) The GHC Team 2001
*
}
for ( i=1; i < argc; i++ ) {
- new_argv[i+1] = (char*)malloc(sizeof(char) * (strlen(argv[i]) + 1));
+ int len = strlen(argv[i]);
+ /* to avoid quoting issues, surround each option in double quotes */
+ new_argv[i+1] = (char*)malloc(sizeof(char) * (len + 3));
if (new_argv[i+1] == NULL) {
errmsg("failed to start up ghc.exe");
return 1;
} else {
- strcpy(new_argv[i+1], argv[i]);
+ new_argv[i+1][0] = '"';
+ strcpy(1 + new_argv[i+1], argv[i]);
+ new_argv[i+1][len+1] = '"';
+ new_argv[i+1][len+2] = '\0';
}
}
new_argv[i+1] = NULL;
Cygwin gives me the right behaviour, but does it by
implementing it in terms of spawnv(), so you pay
the cost of having to create an extra process.
+ Plus, of course, we aren't allowed to use Cygwin here, because
+ GHC does not assume Cygwin.
- ==> Just use spawnv().
+ ==> Just use spawnv(), which is provided by msvcrt.dll, the
+ Microsoft C runtime to which mingw delegates almost all
+ system calls
+
+ [Sigbjorn adds 12 Jun 03]
+ We probably ought to use CreateProcess() in ghci.c -- or better still an exec()-like
+ that didn't have to create a separate process from the wrapper (which is what that
+ code comment in there is driving at.)
+
+ CreateProcess() is a more wieldy function to invoke, which is probably why
+ I opted for spawnv(). spawnv() performs the equivalent of Prelude.unwords
+ (to look at the code itself, or at least an older version, see dospawn.c in the
+ vc98/crt/src/ directory of an MSVC6 installation.)
+
+ CreateProcess() is a native Win32 API though, which has the merit that it is
+ guaranteed to work the same with both the mingw and cygwin ports.
*/
#if 0
fprintf(stderr, "Invoking ghc: ");