Index: main.cc
===================================================================
--- main.cc	(revision 5985)
+++ main.cc	(working copy)
@@ -131,6 +131,50 @@
 }
 #endif
 
+static char *findprog(char *name)
+{
+	static char filepath[MAXPATHLEN];
+	char *pptr;
+	struct stat st;
+
+	memset(filepath, 0, sizeof filepath);
+
+	if (stat(name, &st) != -1 && !S_ISDIR(st.st_mode)) {
+		Strncpy(filepath, name, sizeof filepath);
+		return filepath;
+	}
+
+	/* Doh!  We must find it in path */
+	if ((pptr = getenv("PATH"))) {
+		char path[4096];
+		char *base;
+		char *endptr;
+
+		Strncpy(path, pptr, sizeof(path));
+		pptr = path;
+
+		base = path_get_basename(name);
+
+		if (!base)
+			pfatal("%s: Could not get basename for %s", __func__, name);
+
+		while (pptr && *pptr) {
+			endptr = strchr(pptr, ':');
+			if (endptr)
+				*endptr = '\0';
+			Snprintf(filepath, sizeof(filepath), "%s/%s", pptr, base);
+			if (stat(filepath, &st) != -1)
+				break;
+			filepath[0] = '\0';
+			pptr = endptr ? endptr + 1 : NULL;
+		}
+
+		free(base);
+	}
+
+	return strlen(filepath) ? filepath : NULL;
+}
+
 /* global options */
 extern NmapOps o;  /* option structure */
 
@@ -150,9 +194,6 @@
   char fakeargs[1024];
   char nmappath[MAXPATHLEN];
   char *pptr;
-  char path[4096];
-  struct stat st;
-  char *endptr;
   int interactivemode = 0;
   int fd;
   struct timeval tv;
@@ -210,6 +251,24 @@
     return ret;
   }
 
+  if (argc >= 2 && strcmp("--gui", argv[1]) == 0) {
+	char *args[2] = { NULL, NULL };
+	char *guis[] = { "umit", "nmapfe", "xnmap", NULL };
+	char **p;
+
+	for (p = guis; *p; p++) {
+		args[0] = *p;
+
+		pptr = findprog(args[0]);
+		if (pptr) {
+			if (execv(pptr, args) == -1)
+				gh_perror("Couldn't exec %s", args[0]);
+		}
+	}
+
+	fatal("Ran out of GUIs to try!");
+  }
+
   if (interactivemode == 0 &&
       argc == 2 && strcmp("--interactive", argv[1]) == 0) {
     interactivemode = 1;
@@ -305,37 +364,12 @@
 	}
 	/* Now we figure out where the #@$#@ Nmap is located */
 	if (!*nmappath) {
-	  if (stat(argv[0], &st) != -1 && !S_ISDIR(st.st_mode)) {
-	    strncpy(nmappath, argv[0], sizeof(nmappath));
-	  } else {
-	    nmappath[0] = '\0';
-	    /* Doh!  We must find it in path */
-	    if ((pptr = getenv("PATH"))) {
-	      Strncpy(path, pptr, sizeof(path));
-	      pptr = path;
-	      /* Get the name Nmap was called as. */
-	      char *nmapcalledas = path_get_basename(argv[0]);
-	      if (nmapcalledas == NULL)
-		pfatal("Could not get nmap executable basename");
-	      while(pptr && *pptr) {
-		endptr = strchr(pptr, ':');
-		if (endptr) { 
-		  *endptr = '\0';
-		}
-		Snprintf(nmappath, sizeof(nmappath), "%s/%s", pptr, nmapcalledas);
-		if (stat(nmappath, &st) != -1)
-		  break;
-		nmappath[0] = '\0';
-		if (endptr) pptr = endptr + 1;
-		else pptr = NULL;
-	      }
-	      free(nmapcalledas);
-	    }
-	  }
+		pptr = findprog(argv[0]);
+		if (pptr)
+			Strncpy(nmappath, pptr, sizeof nmappath);
+		else
+			fatal("Could not find Nmap -- you must add --nmap-path argument");
 	}
-	if (!*nmappath) {
-	  fatal("Could not find Nmap -- you must add --nmap-path argument");
-	}       
 
 	/* We should be courteous and give Nmap reasonable signal defaults */
 #if HAVE_SIGNAL
