static void setup_cursors(void) {
void setup_cursors(void) {
static void setup_cursors(void) {	rfbCursorPtr rfb_curs;	int i, n = 0;	static int first = 1;	rfbLog("setting up %d cursors...\n", CURS_MAX);	if (first) {		for (i=0; i<CURS_MAX; i++) {			cursors[i] = NULL;		}	}	first = 0;	if (screen) {		rfbUndrawCursor(screen);		screen->cursor = NULL;		LOCK(screen->cursorMutex);	}	for (i=0; i<CURS_MAX; i++) {		cursor_info_t *ci;		if (cursors[i]) {			/* clear out any existing ones: */			ci = cursors[i];			if (ci->rfb) {				/* this is the rfbCursor part: */				if (ci->rfb->richSource) {					free(ci->rfb->richSource);				}				if (ci->rfb->source) {					free(ci->rfb->source);				}				if (ci->rfb->mask) {					free(ci->rfb->mask);				}				free(ci->rfb);			}			if (ci->data) {				free(ci->data);			}			if (ci->mask) {				free(ci->mask);			}		}		/* create new struct: */		ci = (cursor_info_t *) malloc(sizeof(cursor_info_t));		ci->data = NULL; 		ci->mask = NULL; 		ci->wx = 0;		ci->wy = 0;		ci->sx = 0;		ci->sy = 0;		ci->reverse = 0;		ci->rfb = NULL;		cursors[i] = ci;	}	/* clear any xfixes cursor cache (no freeing is done) */	get_xfixes_cursor(1);	/* manually fill in the data+masks: */	cur_empty.data	= curs_empty_data;	cur_empty.mask	= curs_empty_mask;	cur_dot.data	= curs_dot_data;	cur_dot.mask	= curs_dot_mask;	cur_arrow.data	= curs_arrow_data;	cur_arrow.mask	= curs_arrow_mask;	cur_root.data	= curs_root_data;	cur_root.mask	= curs_root_mask;	cur_plus.data	= curs_plus_data;	cur_plus.mask	= curs_plus_mask;	cur_fleur.data	= curs_fleur_data;	cur_fleur.mask	= curs_fleur_mask;	cur_xterm.data	= curs_xterm_data;	cur_xterm.mask	= curs_xterm_mask;	cursors[CURS_EMPTY] = &cur_empty;	n++;	cursors[CURS_DOT]   = &cur_dot;		n++;	cursors[CURS_ARROW] = &cur_arrow;	n++;	cursors[CURS_ROOT]  = &cur_root;	n++;	cursors[CURS_WM]    = &cur_fleur;	n++;	cursors[CURS_TERM]  = &cur_xterm;	n++;	for (i=0; i<n; i++) {		/* create rfbCursors for the special cursors: */		cursor_info_t *ci = cursors[i];		ci->data = strdup(ci->data);		ci->mask = strdup(ci->mask);		rfb_curs = rfbMakeXCursor(ci->wx, ci->wy, ci->data, ci->mask);		if (ci->reverse) {			rfb_curs->foreRed   = 0x0000;			rfb_curs->foreGreen = 0x0000;			rfb_curs->foreBlue  = 0x0000;			rfb_curs->backRed   = 0xffff;			rfb_curs->backGreen = 0xffff;			rfb_curs->backBlue  = 0xffff;		}		rfb_curs->xhot = ci->sx;		rfb_curs->yhot = ci->sy;		rfb_curs->cleanup = FALSE;		rfb_curs->cleanupSource = FALSE;		rfb_curs->cleanupMask = FALSE;		rfb_curs->cleanupRichSource = FALSE;		if (bpp == 8 && indexed_color) {			/*			 * use richsource in PseudoColor for better			 * looking cursors (i.e. two-color).			 */			int x, y, k = 0, bw;			char d, m;			int black = BlackPixel(dpy, scr);			int white = WhitePixel(dpy, scr);			rfb_curs->richSource			    = (char *)calloc(ci->wx * ci->wy, 1);			for (y = 0; y < ci->wy; y++) {			    for (x = 0; x < ci->wx; x++) {				d = *(ci->data + k);				m = *(ci->mask + k);				if (d == ' ' && m == ' ') {					k++;					continue;				} else if (m != ' ' && d == ' ') {					bw = black;				} else {					bw = white;				}				if (ci->reverse) {					if (bw == black) {						bw = white;					} else {						bw = black;					}				}				*(rfb_curs->richSource+k) = (unsigned char) bw;				k++;			    }			}		}		ci->rfb = rfb_curs;	}	if (screen) {		UNLOCK(screen->cursorMutex);	}	rfbLog("  done.\n");}