Re: Feature, implement :main command

Neil Mitchell <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.hugs
Message-ID <404396ef0510300607k39ba06ch6ee2e283fb2f1a41__36416.1784681075$1130681329$gmane$org@mail.gmail.com>
> Well the Main module probably imports System.Environment anyway
Mine never does, I always import System, which doesn't include withArgs

> I guess this is harmless, and presumably this will be used by some
> WinHugs thing.
Indeed :)

> The usual way to parse arguments to Hugs commands is readFilename(),
That does make it much easier, and much shorter, attached is a new
version. If no one has any objections I'll check it in.

Thanks

Neil

_______________________________________________
Cvs-hugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-hugs
main2.patch (application/octet-stream, 2.2 KB)
Index: src/command.h
===================================================================
RCS file: /home/cvs/root/hugs98/src/command.h,v
retrieving revision 1.14
diff -u -r1.14 command.h
--- src/command.h	14 Oct 2003 13:56:21 -0000	1.14
+++ src/command.h	30 Oct 2005 14:05:22 -0000
@@ -46,6 +46,7 @@
 #ifdef __SYMBIAN32__
 #define PRNDIR  21
 #endif
+#define MAIN    22
 
 #if OBSERVATIONS
 /*-------------------------------------------------------------------------*
Index: src/hugs.c
===================================================================
RCS file: /home/cvs/root/hugs98/src/hugs.c,v
retrieving revision 1.145
diff -u -r1.145 hugs.c
--- src/hugs.c	16 Sep 2005 16:55:10 -0000	1.145
+++ src/hugs.c	30 Oct 2005 14:05:23 -0000
@@ -246,7 +246,7 @@
  {":reload", RELOAD}, {":gc",   COLLECT}, {":edit",    EDIT},
  {":quit",   QUIT},   {":set",  SET},     {":find",    FIND},
  {":names",  NAMES},  {":info", INFO},    {":module",  SETMODULE}, 
- {":browse", BROWSE},
+ {":browse", BROWSE}, {":main", MAIN},
 #if EXPLAIN_INSTANCE_RESOLUTION
  {":xplain", XPLAIN},
 #endif
@@ -276,6 +276,7 @@
     Printf(":names [pat]        list names currently in scope\n");
     Printf(":info <names>       describe named objects\n");
     Printf(":browse <modules>   browse names exported by <modules>\n");
+    Printf(":main <aruments>    run the main function with the given arguments\n");
 #if EXPLAIN_INSTANCE_RESOLUTION
     Printf(":xplain <context>   explain instance resolution for <context>\n");
 #endif
@@ -539,6 +540,25 @@
 }
 #endif
 
+static Void local runmain() {
+    String args[11];
+    String s;
+    int argPos = 1, i;
+    args[0] = "Hugs";
+
+    while (argPos < 10 && (s = readFilename())) {
+	args[argPos++] = strCopy(s);
+    }
+
+    setHugsArgs(argPos, args);
+    for (i = 1; i < argPos; i++)
+	free(args[i]);
+
+    stringInput((LPSTR) "main");
+    input(BREAK);
+    doCommand();
+}
+
 /* --------------------------------------------------------------------------
  * Enhanced help system:  print current list of scripts or give information
  * about an object.
@@ -1098,6 +1118,8 @@
 				 cellsRecovered);
 			  break;
 	    case NOCMD  : break;
+	    case MAIN: runmain();
+	    	  break;
 #ifdef __SYMBIAN32__
         case PRNDIR : printDir();
               break;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.