Pedro,

Excuse my silence these last days, I've had to wrap up things at work.

I've hacked rshd.c a bit so it has a UI, this has the benefit of making
the process visible in the WinCE process list. The UI is only half done,
it has toggles to set the command line options that you had in the
source, but I've not hooked the toggles to the variables yet. Should be
easy though.

Also I've not been able to spend time on the incomplete "spaces in
command lines" patch, so that's still at the state I left it the other
time, please disregard that.

Comments please?

        Danny
-- 
Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
Index: rshd.c
===================================================================
--- rshd.c	(revision 1034)
+++ rshd.c	(working copy)
@@ -35,6 +35,9 @@
 
 #include <PipeLib.h>
 
+#include <ctype.h>
+#include <commctrl.h>
+
 /* from coredll.dll */
 extern BOOL GetStdioPathW (int, wchar_t*, DWORD*);
 extern BOOL SetStdioPathW (int, const wchar_t*);
@@ -510,7 +513,11 @@
       return NULL;
     }
 
+  if (strcmp(program, "exit") == 0)
+	  exit(0);
+
   argslen = 0;
+#if 0
   args = program;
   /* TODO: program paths with embedded spaces?  */
   args = strchr (args, ' ');
@@ -519,6 +526,28 @@
   else
     args = "";
   argslen = strlen (args);
+#else
+  /* Find the first blank that's not preceded by a backslash */
+  for (args=program; *args; args++) {
+	  if (isspace(args[1]) && args[0] != '\\') {
+		  args[1] = '\0';
+		  args+=2;
+		  break;
+	  }
+  }
+  /* Now, in program, remove backslashes followed by spaces */
+  char *p, *q;
+  for (p=q=program; *p; p++) {
+	  if (isspace(p[1]) && p[0] == '\\')
+		  /* Skip backslash */;
+	  else {
+		  *q++ = *p;
+	  }
+  }
+  *q = '\0';
+  if (*args && args != program)
+	  argslen = strlen(args);
+#endif
   wargs = alloca ((argslen + 1) * sizeof (wchar_t));
   mbstowcs (wargs, args, argslen + 1);
 
@@ -536,8 +565,33 @@
   for (i = 0; i < 3; i++)
     {
       wchar_t devname[MAX_PATH];
-      if (!CreatePipe (&readh[i], &writeh[i], NULL, 0))
-	return NULL;
+      if (!CreatePipe (&readh[i], &writeh[i], NULL, 0)) {
+	      DWORD err = GetLastError ();
+	      static char x[256];
+	      sprintf(x, "CreatePipe failed (err %d) : %s", 
+			      (int) err, strwinerror (err));
+#if 1
+	      /*
+	       * We could return 0 here, but there is no way to send
+	       * error strings back to the calling rsh without changing
+	       * the function that calls us.
+	       * This might be a better idea though, we could point
+	       * out that e.g. PipeDev.dll is not installed.
+	       */
+	      static wchar_t wx[256];
+	      mbstowcs(wx, x, strlen(x)+1);
+	      MessageBoxW(0, wx, L"rshd", 0);
+	      exit(1);
+#else
+	      /*
+	       * We need to be able to use "s2" from the function that
+	       * calls us.
+	       */
+	      send(s2, x, strlen(x), 0);
+	      send(s2, "\r\n", 2, 0);
+	      return 0;
+#endif
+      }
 
       wsprintf (devname, L"dev%d", i);
       SetPipeTag (readh[i], devname);
@@ -974,8 +1028,13 @@
   return 0;
 }
 
+#if 1
+static DWORD WINAPI
+accept_connections(void *arg)
+#else
 static void
 accept_connections (void)
+#endif
 {
   int s;
   struct sockaddr_in sin;
@@ -1043,8 +1102,13 @@
       if ((s2 = accept (s, NULL, NULL)) == -1)
 	{
 	  perror ("accept");
+#if 1
+	  MessageBoxW(0, L"Accept failed", L"Rshd", 0);
 	  closesocket (s);
 	  exit (1);
+#else
+	  continue;
+#endif
 	}
 
       logprintf ("handle_conn: accepted\n");
@@ -1074,35 +1138,161 @@
   exit (1);
 }
 
-int
-main (int argc, char **argv)
+/*
+ * Global variables
+ */
+HWND	MainWindow, b1, b2, b3, b4, f3, SaveButton, QuitButton, CmdBar, title;
+HINSTANCE MainInstance;
+static wchar_t	*wAppName = L"rshd";
+static wchar_t	*wTitle = L"rshd";
+
+static void Save(void)
 {
-  int c;
-  WSADATA wsad;
-  WSAStartup (MAKEWORD (2, 0), &wsad);
+	MessageBoxW(0, L"Saving", L"Msg", 0);
+}
 
-  progname = argv[0];
-  while ((c = getopt (argc, argv, "hdel:")) != -1)
-    {
-      switch (c)
-      {
-      case 'h':
-	usage ();
-      case 'd':
-	debug = 1;
-	break;
-      case 'e':
-	localecho = 1;
-	break;
-      case 'l':
-	logfile = optarg;
-	break;
-      default:
-	fprintf (stderr, "Unknown option -- %c\n", optopt);
-	usage ();
-      }
+LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+	switch (message) {
+		case WM_CREATE:
+			break;
+		case WM_COMMAND:
+			if ((HWND)lParam == QuitButton) {
+				PostQuitMessage(0);
+			}
+			if ((HWND)lParam == SaveButton) {
+				Save();
+			}
+			break;
+		case WM_CLOSE:
+			DestroyWindow(hWnd);
+			break;
+		case WM_DESTROY:
+			PostQuitMessage(0);
+			break;
+		default:
+			return DefWindowProc(hWnd, message, wParam, lParam);
+	}
+	return 0;
+}
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
+{
+    int		c;
+    WSADATA	wsad;
+    WNDCLASS	wc;
+    HANDLE	t;
+    MSG		msg;
+
+    wc.style          = CS_HREDRAW | CS_VREDRAW;
+    wc.lpfnWndProc    = (WNDPROC) WndProc;
+    wc.cbClsExtra     = 0;
+    wc.cbWndExtra     = 0;
+    wc.hInstance      = hInstance;
+    wc.hIcon          = NULL;
+    wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
+    wc.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);
+    wc.lpszMenuName   = NULL;
+    wc.lpszClassName  = wAppName;
+
+    RegisterClass(&wc);
+    MainInstance = hInstance;
+    InitCommonControls();
+
+    /* If we're already running, don't start a second process. */
+    MainWindow = FindWindow(wAppName, wTitle);
+    if (MainWindow) {
+	    SetForegroundWindow((HWND) ((ULONG)MainWindow | 0x0001));
+	    return 0;
     }
 
-  accept_connections ();
-  return 0;
+    MainWindow = CreateWindow(wAppName,	// Class
+		    wTitle,		// Title
+		    WS_VISIBLE,		// Style
+		    0, 0,		// x, y-position
+		    CW_USEDEFAULT,	// x-size
+		    CW_USEDEFAULT,	// y-size
+		    NULL,		// Parent handle
+		    NULL,		// Menu handle
+		    hInstance,		// Instance handle
+		    NULL);		// Creation
+    if (! MainWindow) {
+	    MessageBoxW(0, L"No main window", L"Error", MB_OK);
+	    return 0;
+    }
+
+    title = CreateWindow(WC_STATIC, L"RSHD Configuration",
+		    WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_EX_CONTROLPARENT,
+		    4, 34, 230, 18,
+		    MainWindow, NULL,
+		    MainInstance, NULL);
+    b1 = CreateWindow(WC_BUTTON, L"Debug",
+		    WS_TABSTOP | WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | BS_CHECKBOX | BS_LEFT,
+		    4, 16 + 18 * 2, 104, 18,
+		    MainWindow, NULL,
+		    MainInstance, NULL);
+    b2 = CreateWindow(WC_BUTTON, L"Echo stdio to local console",
+		    WS_TABSTOP | WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | BS_CHECKBOX | BS_LEFT,
+		    4, 16 + 18 * 3, 204, 18,
+		    MainWindow, NULL,
+		    MainInstance, NULL);
+    b3 = CreateWindow(WC_BUTTON, L"Log to file",
+		    WS_TABSTOP | WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | BS_CHECKBOX | BS_LEFT,
+		    4, 16 + 18 * 4, 104, 18,
+		    MainWindow, NULL,
+		    MainInstance, NULL);
+    f3 = CreateWindow(WC_EDIT, L"\\Temp\\rshd-log.txt",
+		    WS_TABSTOP | WS_CHILD | WS_VISIBLE,
+		    34, 16 + 18 * 5, 154, 18,
+		    MainWindow, NULL,
+		    MainInstance, NULL);
+    SetBkColor(f3, RGB(80, 80, 80));
+    b4 = CreateWindow(WC_BUTTON, L"Show config screen on startup",
+		    WS_TABSTOP | WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | BS_CHECKBOX | BS_LEFT,
+		    4, 16 + 18 * 6, 204, 18,
+		    MainWindow, NULL,
+		    MainInstance, NULL);
+    QuitButton = CreateWindow(WC_BUTTON, L"Terminate rshd immediately",
+		    WS_TABSTOP | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_DEFPUSHBUTTON,
+		    4, 16 + 18 * 12, 204, 18,	/* Further down. */
+		    MainWindow, NULL,
+		    MainInstance, NULL);
+
+    WSAStartup (MAKEWORD (2, 0), &wsad);
+#if 0
+    progname = argv[0];
+    while ((c = getopt (argc, argv, "hdel:")) != -1) {
+	    switch (c)
+	    {
+		    case 'h':
+			    usage ();
+		    case 'd':
+			    debug = 1;
+			    break;
+		    case 'e':
+			    localecho = 1;
+			    break;
+		    case 'l':
+			    logfile = optarg;
+			    break;
+		    default:
+			    fprintf (stderr, "Unknown option -- %c\n", optopt);
+			    usage ();
+	    }
+    }
+#endif
+
+//    ShowWindow(MainWindow, SW_SHOWNORMAL);
+    ShowWindow(MainWindow, SW_SHOW);
+    UpdateWindow(MainWindow);
+
+    t = CreateThread (NULL, 0, accept_connections, 0, 0, NULL);
+    CloseHandle(t);
+
+    /* Standard event loop */
+    while (GetMessage(&msg, NULL, 0, 0) != FALSE) {
+	    TranslateMessage(&msg);
+	    DispatchMessage(&msg);
+    }
+    return msg.wParam;
 }

Attachment: signature.asc
Description: This is a digitally signed message part

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel

Reply via email to