int simple_gui = 0;
int simple_gui = 0, none_gui = 0;
void do_gui(char *opts, int sleep) {	char *s, *p;	char *old_xauth = NULL;	char *gui_xdisplay = NULL;	int got_gui_xdisplay = 0;	int start_x11vnc = 1;	int connect_to_x11vnc = 0;	int simple_gui = 0;	Display *test_dpy;	if (opts) {		s = strdup(opts);	} else {		s = strdup("");	}	if (use_dpy) {		/* worst case */		gui_xdisplay = strdup(use_dpy);			}	if (getenv("DISPLAY") != NULL) {		/* better */		gui_xdisplay = strdup(getenv("DISPLAY"));	}	p = strtok(s, ",");	while(p) {		if (*p == '\0') {			;		} else if (strchr(p, ':') != NULL) {			/* best */			if (gui_xdisplay) {				free(gui_xdisplay);			}			gui_xdisplay = strdup(p);			got_gui_xdisplay = 1;		} else if (!strcmp(p, "wait")) {			start_x11vnc = 0;			connect_to_x11vnc = 0;		} else if (!strcmp(p, "conn") || !strcmp(p, "connect")) {			start_x11vnc = 0;			connect_to_x11vnc = 1;		} else if (!strcmp(p, "ez") || !strcmp(p, "simple")) {			simple_gui = 1;		} else if (strstr(p, "iconfont") == p) {			char *q;			if ((q = strchr(p, '=')) != NULL) {				icon_mode_font = strdup(q+1);			}		} else if (strstr(p, "tray") == p || strstr(p, "icon") == p) {			char *q;			icon_mode = 1;			if ((q = strchr(p, '=')) != NULL) {				icon_mode_params = strdup(q+1);				if (strstr(icon_mode_params, "setp")) {					deny_all = 1;				}			}			if (strstr(p, "tray") == p) {				icon_in_tray = 1;			}		} else if (strstr(p, "geom") == p) {			char *q;			if ((q = strchr(p, '=')) != NULL) {				gui_geometry = strdup(q+1);			}		} else {			fprintf(stderr, "unrecognized gui opt: %s\n", p);		}				p = strtok(NULL, ",");	}	free(s);	if (start_x11vnc) {		connect_to_x11vnc = 1;	}	if (icon_mode && !got_gui_xdisplay) {		/* for tray mode, prefer the polled DISPLAY */		if (use_dpy) {			if (gui_xdisplay) {				free(gui_xdisplay);			}			gui_xdisplay = strdup(use_dpy);		}	}	if (! gui_xdisplay) {		fprintf(stderr, "error: cannot determine X DISPLAY for gui"		    " to display on.\n");		exit(1);	}	fprintf(stderr, "starting gui, trying display: %s\n", gui_xdisplay);	test_dpy = XOpenDisplay(gui_xdisplay);	if (! test_dpy && auth_file) {		if (getenv("XAUTHORITY") != NULL) {			old_xauth = strdup(getenv("XAUTHORITY"));		}		set_env("XAUTHORITY", auth_file);		test_dpy = XOpenDisplay(gui_xdisplay);	}	if (! test_dpy) {		if (! old_xauth && getenv("XAUTHORITY") != NULL) {			old_xauth = strdup(getenv("XAUTHORITY"));		}		set_env("XAUTHORITY", "");		test_dpy = XOpenDisplay(gui_xdisplay);	}	if (! test_dpy) {		fprintf(stderr, "error: cannot connect to gui X DISPLAY: %s\n",		    gui_xdisplay);		exit(1);	}	if (icon_mode && icon_in_tray) {		if (tray_manager_running(test_dpy, NULL)) {			tray_manager_ok = 1;		} else {			tray_manager_ok = 0;		}	}	XCloseDisplay(test_dpy);	if (start_x11vnc) {#if LIBVNCSERVER_HAVE_FORK		/* fork into the background now */		int p;		pid_t parent = getpid();		if (icon_mode) {			char tf[100]; 			double dn = dnow();			struct stat sbuf;			/* FIXME */			dn = dn - ((int) dn);			sprintf(tf, "/tmp/x11vnc.tray%d%d", (int) (1000000*dn),			    (int) getpid());			unlink(tf);			/* race begins.. */			if (stat(tf, &sbuf) == 0) {				icon_mode = 0;			} else {				icon_mode_fh = fopen(tf, "w");				if (! icon_mode_fh) {					icon_mode = 0;				} else {					chmod(tf, 0400);					icon_mode_file = strdup(tf);					fprintf(icon_mode_fh, "none\n");					fprintf(icon_mode_fh, "none\n");					fflush(icon_mode_fh);					if (! got_connect_once) {						/* want -forever for tray */						connect_once = 0;					}				}			}		}		if ((p = fork()) > 0)  {			;	/* parent */		} else if (p == -1) {			fprintf(stderr, "could not fork\n");			perror("fork");			clean_up_exit(1);		} else {			if (sleep > 0) {				usleep(sleep * 1000 * 1000);			}			run_gui(gui_xdisplay, connect_to_x11vnc, simple_gui,			    parent, opts);			exit(1);		}#else		fprintf(stderr, "system does not support fork: start "		    "x11vnc in the gui.\n");		start_x11vnc = 0;#endif	}	if (!start_x11vnc) {		run_gui(gui_xdisplay, connect_to_x11vnc, simple_gui, 0, opts);		exit(1);	}	if (old_xauth) {		set_env("XAUTHORITY", old_xauth);	}}