From: sewardj Date: Mon, 10 Apr 2000 14:28:14 +0000 (+0000) Subject: [project @ 2000-04-10 14:28:14 by sewardj] X-Git-Tag: Approximately_9120_patches~4756 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=674ad01f5f5edcc20e3fee4e5f39a2d8388120a3;hp=7d446f085a1e5ce22b3a54b718e79a3da1bd8091;p=ghc-hetmet.git [project @ 2000-04-10 14:28:14 by sewardj] Make getArgs and getProgName behave identically in combined and standalone modes. --- diff --git a/ghc/includes/RtsAPI.h b/ghc/includes/RtsAPI.h index 231af06..b28d7ab 100644 --- a/ghc/includes/RtsAPI.h +++ b/ghc/includes/RtsAPI.h @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- - * $Id: RtsAPI.h,v 1.11 2000/03/31 03:09:35 hwloidl Exp $ + * $Id: RtsAPI.h,v 1.12 2000/04/10 14:28:14 sewardj Exp $ * * (c) The GHC Team, 1998-1999 * @@ -26,9 +26,11 @@ typedef StgClosure *HaskellObj; /* ---------------------------------------------------------------------------- Starting up and shutting down the Haskell RTS. ------------------------------------------------------------------------- */ -extern void startupHaskell ( int argc, char *argv[], void *init_root ); -extern void shutdownHaskell ( void ); +extern void startupHaskell ( int argc, char *argv[], void *init_root ); +extern void shutdownHaskell ( void ); extern void shutdownHaskellAndExit ( int exitCode ); +extern void setProgArgv ( int argc, char *argv[] ); +extern void getProgArgv ( int *argc, char **argv[] ); /* ---------------------------------------------------------------------------- Building Haskell objects from C datatypes. diff --git a/ghc/interpreter/hugs.c b/ghc/interpreter/hugs.c index 7244877..c1120b1 100644 --- a/ghc/interpreter/hugs.c +++ b/ghc/interpreter/hugs.c @@ -9,8 +9,8 @@ * included in the distribution. * * $RCSfile: hugs.c,v $ - * $Revision: 1.64 $ - * $Date: 2000/04/10 09:40:03 $ + * $Revision: 1.65 $ + * $Date: 2000/04/10 14:28:14 $ * ------------------------------------------------------------------------*/ #include @@ -200,11 +200,9 @@ char *argv[]; { * Initialization, interpret command line args and read prelude: * ------------------------------------------------------------------------*/ -static List /*CONID*/ initialize(argc,argv) /* Interpreter initialization */ -Int argc; -String argv[]; { - Int i; - char argv_0_orig[1000]; +static List /*CONID*/ initialize ( Int argc, String argv[] ) +{ + Int i, j; List initialModules; setLastEdit((String)0,0); @@ -220,11 +218,6 @@ String argv[]; { readOptions("-p\"%s> \" -r$$"); readOptions(fromEnv("STGHUGSFLAGS","")); - strncpy(argv_0_orig,argv[0],1000); /* startupHaskell mangles argv[0] */ - startupHaskell (argc,argv,NULL); - argc = prog_argc; - argv = prog_argv; - # if DEBUG { char exe_name[N_INSTALLDIR + 6]; @@ -234,29 +227,37 @@ String argv[]; { } # endif + /* startupHaskell extracts args between +RTS ... -RTS, and sets + prog_argc/prog_argv to the rest. We want to further process + the rest, so we then get hold of them again. + */ + startupHaskell ( argc, argv, NULL ); + getProgArgv ( &argc, &argv ); + /* Find out early on if we're in combined mode or not. everybody(PREPREL) needs to know this. Also, establish the heap size; */ - for (i=1; i < argc; ++i) { + for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "--")==0) break; if (strcmp(argv[i], "-c")==0) combined = FALSE; if (strcmp(argv[i], "+c")==0) combined = TRUE; - if (strncmp(argv[i],"+h",2)==0 || - strncmp(argv[i],"-h",2)==0) + if (strncmp(argv[i],"+h",2)==0 || strncmp(argv[i],"-h",2)==0) setHeapSize(&(argv[i][2])); } everybody(PREPREL); initialModules = NIL; - for (i=1; i < argc; ++i) { /* process command line arguments */ - if (strcmp(argv[i], "--")==0) break; - if (argv[i] && argv[i][0]/* workaround for /bin/sh silliness*/ - && !processOption(argv[i])) { - initialModules - = cons ( mkCon(findText(argv[i])), initialModules ); + for (i = 1; i < argc; ++i) { /* process command line arguments */ + if (strcmp(argv[i], "--")==0) + { argv[i] = NULL; break; } + if (argv[i] && argv[i][0]/* workaround for /bin/sh silliness*/) { + if (!processOption(argv[i])) + initialModules + = cons ( mkCon(findText(argv[i])), initialModules ); + argv[i] = NULL; } } @@ -276,6 +277,16 @@ String argv[]; { " combined mode\n\n" ); } + /* slide args back over the deleted ones. */ + j = 1; + for (i = 1; i < argc; i++) + if (argv[i]) + argv[j++] = argv[i]; + + argc = j; + + setProgArgv ( argc, argv ); + initDone = TRUE; return initialModules; } diff --git a/ghc/lib/std/System.lhs b/ghc/lib/std/System.lhs index 63bfb40..0404492 100644 --- a/ghc/lib/std/System.lhs +++ b/ghc/lib/std/System.lhs @@ -210,7 +210,7 @@ data ExitCode = ExitSuccess | ExitFailure Int getArgs :: IO [String] getArgs = primGetRawArgs >>= \rawargs -> - return (drop 1 (dropWhile (/= "--") rawargs)) + return (tail rawargs) getProgName :: IO String getProgName = primGetRawArgs >>= \rawargs -> diff --git a/ghc/rts/RtsStartup.c b/ghc/rts/RtsStartup.c index 75102f4..17b194f 100644 --- a/ghc/rts/RtsStartup.c +++ b/ghc/rts/RtsStartup.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: RtsStartup.c,v 1.39 2000/04/03 16:28:08 simonmar Exp $ + * $Id: RtsStartup.c,v 1.40 2000/04/10 14:28:14 sewardj Exp $ * * (c) The GHC Team, 1998-2000 * @@ -53,6 +53,26 @@ EXTFUN(__init_Prelude); static void initModules ( void * ); void +setProgArgv(int argc, char *argv[]) +{ + /* Usually this is done by startupHaskell, so we don't need to call this. + However, sometimes Hugs wants to change the arguments which Haskell + getArgs >>= ... will be fed. So you can do that by calling here + _after_ calling startupHaskell. + */ + prog_argc = argc; + prog_argv = argv; +} + +void +getProgArgv(int *argc, char **argv[]) +{ + *argc = prog_argc; + *argv = prog_argv; +} + + +void startupHaskell(int argc, char *argv[], void *init_root) { /* To avoid repeated initialisations of the RTS */