rfbLog("For a list of options run: x11vnc -help\n");
rfbLog("For a list of options run: x11vnc -opts\n"); rfbLog("or for the full help: x11vnc -help\n");
void initialize_screen(int *argc, char **argv, XImage *fb) {	int have_masks = 0;	int width  = fb->width;	int height = fb->height;	int create_screen = screen ? 0 : 1;	int bits_per_color;		main_bytes_per_line = fb->bytes_per_line;	setup_scaling(&width, &height);		if (scaling) {		rfbLog("scaling screen: %dx%d -> %dx%d  scale_fac=%.5f\n",		    fb->width, fb->height, scaled_x, scaled_y, scale_fac);		rfb_bytes_per_line = (main_bytes_per_line / fb->width) * width;	} else {		rfb_bytes_per_line = main_bytes_per_line;	}	/*	 * These are just hints wrt pixel format just to let	 * rfbGetScreen/rfbNewFramebuffer proceed with reasonable	 * defaults.  We manually set them in painful detail below.	 */	bits_per_color = guess_bits_per_color(fb->bits_per_pixel);	/* n.b. samplesPerPixel (set = 1 here) seems to be unused. */	if (create_screen) {		screen = rfbGetScreen(argc, argv, width, height,		    bits_per_color, 1, (int) fb->bits_per_pixel/8);		if (screen && http_dir) {			http_connections(1);		}	} else {		/* set set frameBuffer member below. */		rfbLog("rfbNewFramebuffer(0x%x, 0x%x, %d, %d, %d, %d, %d)\n",		    screen, NULL, width, height,		    bits_per_color, 1, fb->bits_per_pixel/8);		/* these are probably overwritten, but just to be safe: */		screen->bitsPerPixel = fb->bits_per_pixel;		screen->depth = fb->depth;		rfbNewFramebuffer(screen, NULL, width, height,		    bits_per_color, 1, (int) fb->bits_per_pixel/8);	}	if (! screen) {		int i;		rfbLogEnable(1);		rfbLog("\n");		rfbLog("failed to create rfb screen.\n");		for (i=0; i< *argc; i++)  {			rfbLog("\t[%d]  %s\n", i, argv[i]);		}		clean_up_exit(1);	}	if (create_screen && *argc != 1) {		int i;		rfbLogEnable(1);		rfbLog("*** unrecognized option(s) ***\n");		for (i=1; i< *argc; i++)  {			rfbLog("\t[%d]  %s\n", i, argv[i]);		}		rfbLog("For a list of options run: x11vnc -help\n");		rfbLog("\n");		rfbLog("Here is a list of removed or obsolete"		    " options:\n");		rfbLog("\n");		rfbLog("removed: -hints, -nohints\n");		rfbLog("removed: -cursorposall\n");		rfbLog("\n");		rfbLog("renamed: -old_copytile, use -onetile\n");		rfbLog("renamed: -mouse,   use -cursor\n");		rfbLog("renamed: -mouseX,  use -cursor X\n");		rfbLog("renamed: -X,       use -cursor X\n");		rfbLog("renamed: -nomouse, use -nocursor\n");		rfbLog("renamed: -old_pointer, use -pointer_mode 1\n");			clean_up_exit(1);	}	/* set up format from scratch: */	screen->paddedWidthInBytes = rfb_bytes_per_line;	screen->serverFormat.bitsPerPixel = fb->bits_per_pixel;	screen->serverFormat.depth = fb->depth;	screen->serverFormat.trueColour = TRUE;	screen->serverFormat.redShift   = 0;	screen->serverFormat.greenShift = 0;	screen->serverFormat.blueShift  = 0;	screen->serverFormat.redMax     = 0;	screen->serverFormat.greenMax   = 0;	screen->serverFormat.blueMax    = 0;	/* these main_* formats are used generally. */	main_red_shift   = 0;	main_green_shift = 0;	main_blue_shift  = 0;	main_red_max     = 0;	main_green_max   = 0;	main_blue_max    = 0;	main_red_mask    = fb->red_mask;	main_green_mask  = fb->green_mask;	main_blue_mask   = fb->blue_mask;	have_masks = ((fb->red_mask|fb->green_mask|fb->blue_mask) != 0);	if (force_indexed_color) {		have_masks = 0;	}	if (! have_masks && screen->serverFormat.bitsPerPixel == 8	    && dpy && CellsOfScreen(ScreenOfDisplay(dpy, scr))) {		/* indexed color */		if (!quiet) {			rfbLog("X display %s is 8bpp indexed color\n",			    DisplayString(dpy));			if (! flash_cmap && ! overlay) {				rfbLog("\n");				rfbLog("In 8bpp PseudoColor mode if you "				    "experience color\n");				rfbLog("problems you may want to enable "				    "following the\n");				rfbLog("changing colormap by using the "				    "-flashcmap option.\n");				rfbLog("\n");			}		}		screen->serverFormat.trueColour = FALSE;		indexed_color = 1;		set_colormap(1);		debug_colormap(fb);	} else {		/* 		 * general case, we call it truecolor, but could be direct		 * color, static color, etc....		 */		if (! quiet) {			if (raw_fb) {				rfbLog("Raw fb at addr %p is %dbpp depth=%d "				    "true color\n", raw_fb_addr,				    fb->bits_per_pixel, fb->depth);			} else {				rfbLog("X display %s is %dbpp depth=%d true "				    "color\n", DisplayString(dpy),				    fb->bits_per_pixel, fb->depth);			}		}		indexed_color = 0;		/* convert masks to bit shifts and max # colors */		if (fb->red_mask) {			while (! (fb->red_mask			    & (1 << screen->serverFormat.redShift))) {				    screen->serverFormat.redShift++;			}		}		if (fb->green_mask) {			while (! (fb->green_mask			    & (1 << screen->serverFormat.greenShift))) {				    screen->serverFormat.greenShift++;			}		}		if (fb->blue_mask) {			while (! (fb->blue_mask			    & (1 << screen->serverFormat.blueShift))) {				    screen->serverFormat.blueShift++;			}		}		screen->serverFormat.redMax		    = fb->red_mask   >> screen->serverFormat.redShift;		screen->serverFormat.greenMax		    = fb->green_mask >> screen->serverFormat.greenShift;		screen->serverFormat.blueMax		    = fb->blue_mask  >> screen->serverFormat.blueShift;		main_red_max     = screen->serverFormat.redMax;		main_green_max   = screen->serverFormat.greenMax;		main_blue_max    = screen->serverFormat.blueMax;		main_red_shift   = screen->serverFormat.redShift;		main_green_shift = screen->serverFormat.greenShift;		main_blue_shift  = screen->serverFormat.blueShift;	}#if !SMALL_FOOTPRINT	if (!quiet) {		fprintf(stderr, "\n");		fprintf(stderr, "FrameBuffer Info:\n");		fprintf(stderr, " width:            %d\n", fb->width);		fprintf(stderr, " height:           %d\n", fb->height);		fprintf(stderr, " scaled_width:     %d\n", width);		fprintf(stderr, " scaled_height:    %d\n", height);		fprintf(stderr, " indexed_color:    %d\n", indexed_color);		fprintf(stderr, " bits_per_pixel:   %d\n", fb->bits_per_pixel);		fprintf(stderr, " depth:            %d\n", fb->depth);		fprintf(stderr, " red_mask:   0x%08lx  %s\n", fb->red_mask,		    bitprint(fb->red_mask, 32));		fprintf(stderr, " green_mask: 0x%08lx  %s\n", fb->green_mask,		    bitprint(fb->green_mask, 32));		fprintf(stderr, " blue_mask:  0x%08lx  %s\n", fb->blue_mask,		    bitprint(fb->blue_mask, 32));		fprintf(stderr, " red:   max: %3d  shift: %2d\n",			main_red_max, main_red_shift);		fprintf(stderr, " green: max: %3d  shift: %2d\n",			main_green_max, main_green_shift);		fprintf(stderr, " blue:  max: %3d  shift: %2d\n",			main_blue_max, main_blue_shift);		fprintf(stderr, " mainfb_bytes_per_line: %d\n",			main_bytes_per_line);		fprintf(stderr, " rfb_fb_bytes_per_line: %d\n",			rfb_bytes_per_line);		switch(fb->format) {		case XYBitmap:			fprintf(stderr, " format:     XYBitmap\n"); break;		case XYPixmap:			fprintf(stderr, " format:     XYPixmap\n"); break;		case ZPixmap:			fprintf(stderr, " format:     ZPixmap\n"); break;		default:			fprintf(stderr, " format:     %d\n", fb->format); break;		}		switch(fb->byte_order) {		case LSBFirst:			fprintf(stderr, " byte_order: LSBFirst\n"); break;		case MSBFirst:			fprintf(stderr, " byte_order: MSBFirst\n"); break;		default:			fprintf(stderr, " byte_order: %d\n", fb->byte_order);			break;		}		fprintf(stderr, " bitmap_pad:  %d\n", fb->bitmap_pad);		fprintf(stderr, " bitmap_unit: %d\n", fb->bitmap_unit);		switch(fb->bitmap_bit_order) {		case LSBFirst:			fprintf(stderr, " bitmap_bit_order: LSBFirst\n"); break;		case MSBFirst:			fprintf(stderr, " bitmap_bit_order: MSBFirst\n"); break;		default:			fprintf(stderr, " bitmap_bit_order: %d\n",			fb->bitmap_bit_order); break;		}	}	if (overlay && ! quiet) {		rfbLog("\n");		rfbLog("Overlay mode enabled:  If you experience color\n");		rfbLog("problems when popup menus are on the screen, try\n");		rfbLog("disabling SaveUnders in your X server, one way is\n");		rfbLog("to start the X server with the '-su' option, e.g.:\n");		rfbLog("Xsun -su ... see Xserver(1), xinit(1) for more info.\n");		rfbLog("\n");	}#endif	/* nofb is for pointer/keyboard only handling.  */	if (nofb) {		main_fb = NULL;		rfb_fb = main_fb;		screen->displayHook = nofb_hook;	} else {		main_fb = fb->data;		if (scaling) {			rfb_fb = (char *) malloc(rfb_bytes_per_line * height);			memset(rfb_fb, 0, rfb_bytes_per_line * height);		} else {			rfb_fb = main_fb;		}	}	screen->frameBuffer = rfb_fb;	if (!quiet) {		fprintf(stderr, " main_fb:     %p\n", main_fb);		fprintf(stderr, " rfb_fb:      %p\n", rfb_fb);		fprintf(stderr, "\n");	}	bpp   = screen->serverFormat.bitsPerPixel;	depth = screen->serverFormat.depth;	/* may need, bpp, main_red_max, etc. */	parse_wireframe();	parse_scroll_copyrect();	setup_cursors_and_push();	if (scaling) {		mark_rect_as_modified(0, 0, dpy_x, dpy_y, 0);	}	if (! create_screen) {		rfbClientIteratorPtr iter;		rfbClientPtr cl;		/* 		 * since bits_per_color above may have been approximate,		 * try to reset the individual translation tables...		 * we do not seem to need this with rfbGetScreen()...		 */		if (!quiet) rfbLog("calling setTranslateFunction()...\n");		iter = rfbGetClientIterator(screen);		while ((cl = rfbClientIteratorNext(iter)) != NULL) {			screen->setTranslateFunction(cl);		}		rfbReleaseClientIterator(iter);		if (!quiet) rfbLog("  done.\n");		do_copy_screen = 1;				/* done for framebuffer change case */		return;	}	/*	 * the rest is screen server initialization, etc, only needed	 * at screen creation time.	 */	/* called from inetd, we need to treat stdio as our socket */	if (inetd) {		int fd = dup(0);		if (fd < 0) {			rfbLogEnable(1);			rfbErr("dup(0) = %d failed.\n", fd);			rfbLogPerror("dup");			clean_up_exit(1);		}		fclose(stdin);		fclose(stdout);		/* we keep stderr for logging */		screen->inetdSock = fd;		screen->port = 0;	} else if (! got_rfbport) {		screen->autoPort = TRUE;	}	if (! got_nevershared && ! got_alwaysshared) {		if (shared) {			screen->alwaysShared = TRUE;		} else {			screen->neverShared = TRUE;		}		screen->dontDisconnect = TRUE;	}	if (! got_deferupdate) {		screen->deferUpdateTime = defer_update;	}	/* event callbacks: */	screen->newClientHook = new_client;	screen->kbdAddEvent = keyboard;	screen->ptrAddEvent = pointer;	screen->setXCutText = xcut_receive;	rfbInitServer(screen);	if (viewonly_passwd) {		/* append the view only passwd after the normal passwd */		char **passwds_new = (char **) malloc(3*sizeof(char *));		char **passwds_old = (char **) screen->authPasswdData;		passwds_new[0] = passwds_old[0];		passwds_new[1] = viewonly_passwd;		passwds_new[2] = NULL;		screen->authPasswdData = (void*) passwds_new;	}}