WinHugs, add /edit flag

Neil Mitchell <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.hugs
Message-ID <[email protected]>
Hi,

This patch adds an /edit flag.
The behaviour of winhugs on:
winhugs.exe /edit filename.hs

is to fire up whichever editor is configured with winhugs and exit
winhugs. The massive advantage of this is a user can set winhugs /edit
as their file handler for editing haskell files, and as they change
the option in winhugs, it gets changed in their system.

This patch lays the groundwork for a new installer (expect that patch
tomorrow :) )

Neil

_______________________________________________
Cvs-hugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-hugs
edit_flag.patch (application/octet-stream, 1.9 KB)
Index: src/winhugs/StartCode.c
===================================================================
RCS file: /cvs/hugs98/src/winhugs/StartCode.c,v
retrieving revision 1.7
diff -u -r1.7 StartCode.c
--- src/winhugs/StartCode.c	16 Sep 2005 16:58:13 -0000	1.7
+++ src/winhugs/StartCode.c	5 Oct 2005 12:57:43 -0000
@@ -8,6 +8,10 @@
 #include "evaluator.h"
 #include "connect.h"
 #include "errors.h"
+#include "machdep.h"
+#include "opts.h"
+#include "strutil.h"
+
 
 // store the extern HINSTANCE
 HINSTANCE hThisInstance;
@@ -91,10 +95,45 @@
 
 int main(int  argc,char *argv[]);
 
+void RunEditor(LPSTR File)
+{
+    if (File[0] == 0)
+    {
+	MessageBox(NULL, "Error: /edit option used with no file", "WinHugs", MB_ICONERROR);
+	return;
+    }
+
+    // do some of the evaluation stuff from initialise()
+    // break before any scripts get loaded
+    startEvaluator();
+    hugsEdit = strCopy(fromEnv("EDITOR",NULL));
+    if (hugsEdit == NULL)
+	hugsEdit = WinHugsPickDefaultEditor();
+    readOptions("-p\"%s> \" -r$$",FALSE);
+    readOptionSettings();
+
+    startEdit(0, File);
+}
+
 INT APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, INT nCmdShow)
 {
     int i;
 
+    if (strnicmp(lpszCmdLine, "/edit", 5) == 0)
+    {
+        lpszCmdLine += 5;
+	while (lpszCmdLine[0] == ' ')
+	    lpszCmdLine++;
+	if (lpszCmdLine[0] == '\"')
+	{
+	    char* s = strchr(++lpszCmdLine, '\"');
+	    if (s != NULL)
+	        s[0] = 0;
+	}
+        RunEditor(lpszCmdLine);
+	return 0;
+    }
+
     InitCommonControls();
     LoadLibrary("RICHED32.DLL");
 
@@ -127,7 +166,7 @@
 LPCSTR appName = "Hugs for Windows";
 
 BOOL InAutoReloadFiles = FALSE;	/* TRUE =>loading files before eval*/
-BOOL autoLoadFiles     = TRUE; /* TRUE => automatically reloaded modified files */
+Bool autoLoadFiles     = TRUE; /* TRUE => automatically reloaded modified files */
 
 void ErrorBox(LPCSTR Msg)
 {
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.