⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 initapp.c

📁 具有IDE功能的编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
	break;    case 18:	c = transform (option_color_18);	break;    case 19:	c = transform (option_color_19);	break;    case 20:	c = transform (option_color_20);	break;    case 21:	c = transform (option_color_21);	break;    case 22:	c = transform (option_color_22);	break;    case 23:	c = transform (option_color_23);	break;    case 24:	c = transform (option_color_24);	break;    case 25:	c = transform (option_color_25);	break;    case 26:	c = transform (option_color_26);	break;    }    color->red = ((c >> 16) & 0xFF) << 8;    color->green = ((c >> 8) & 0xFF) << 8;    color->blue = ((c >> 0) & 0xFF) << 8;    color->flags = DoRed | DoBlue | DoGreen;}void alloc_grey_scale (Colormap cmap){    XColor color;    int i;    if (option_using_grey_scale) {	for (i = 0; i < 64; i++) {	    get_grey_colors (&color, i);	    CAllocColor (cmap, &color);	    color_pixels[i + 43] = color.pixel;	}    }}/*   This sets up static color, but tries to be more intelligent about the   way it handles grey scales. This allows resonable color display on 16   color VGA servers. */static void setup_staticcolor (void){    XColor *c;    unsigned short *grey_levels;    XColor color;    int size, i, j, k, n, m = 0, num_greys, grey;    c = get_cells (CColormap, &size);    grey_levels = CMalloc ((size + 2) * sizeof (unsigned short));    num_greys = 0;/* we are probably not going to find our coolwwidget colors here,   so use greyscale for the buttons. first count how many greys,   and sort them: */    grey = 0;    for (i = 0; i < size; i++) {	if (c[i].red == c[i].green && c[i].green == c[i].blue) {	    if (grey) {		for (n = 0; n < grey; n++)		    if (c[i].green == grey_levels[n])			goto cont;		for (n = grey - 1; n >= 0; n--)		    if (grey_levels[n] > c[i].green) {			memmove (&(grey_levels[n + 1]), &(grey_levels[n]), (grey - n) * sizeof (unsigned short));			grey_levels[n] = c[i].green;			grey++;			goto cont;		    }		grey_levels[grey] = c[i].green;	    } else		grey_levels[grey] = c[i].green;	    grey++;	  cont:;	}    }    num_greys = grey;    if (num_greys <= 2) {	/* there's just no hope  :(   */	if (verbose_operation)	    printf (_ ("This will work, but it may look terrible.\n"));	for (grey = 0; grey < 16; grey++) {	    color.flags = DoRed | DoGreen | DoBlue;	    color.red = grey * 65535 / 15;	    color.green = grey * 65535 / 15;	    color.blue = grey * 65535 / 15;	    if (!XAllocColor (CDisplay, CColormap, &color))		alloccolorerror ();	    color_pixels[grey] = color.pixel;	}	alloc_grey_scale (CColormap);    } else {	j = 0;	k = 0;	for (grey = 0; grey < num_greys; grey++) {/* button colors */	    color.red = color.green = grey_levels[grey];	    color.blue = grey_levels[grey];	    color.flags = DoRed | DoGreen | DoBlue;	    for (; j < (grey + 1) * 16 / num_greys; j++) {		CAllocColor (CColormap, &color);		color_pixels[j] = color.pixel;	    }/* grey scale */	    if (option_using_grey_scale) {		for (; k < (grey + 1) * 64 / num_greys; k++) {		    CAllocColor (CColormap, &color);		    color_pixels[k + 43] = color.pixel;		}	    }	}    }    for (i = 0; i < 27; i++) {	get_general_colors (&color, i);	m = CGetCloseColor (c, size, color, 0);	CAllocColor (CColormap, &(c[m]));	color_pixels[16 + i] = c[m].pixel;    }    free (grey_levels);    free (c);}static void make_grey (XColor * color){    long g;    g = ((long) color->red) * 8L + ((long) color->green) * 10L + ((long) color->blue) * 5L;    g /= (8l + 10L + 5L);    color->red = color->green = g;    color->blue = g;}/*   For TrueColor displays, colors can always be found. Hence we   need not find the "closest" matching color. */static void setup_alloc_colors (int force_grey){    int i;    XColor color;    color.flags = DoRed | DoGreen | DoBlue;    for (i = 0; i < 16; i++) {	get_button_color (&color, i);	if (force_grey)	    make_grey (&color);	CAllocColor (CColormap, &color);	color_pixels[i] = color.pixel;    }    for (i = 0; i < 27; i++) {	get_general_colors (&color, i);	if (force_grey)	    make_grey (&color);	CAllocColor (CColormap, &color);	color_pixels[16 + i] = color.pixel;    }    alloc_grey_scale (CColormap);}void store_grey_scale (Colormap cmap){    XColor color;    int i;    if (verbose_operation)/* "Grey scale" is a list of increasingly bright grey levels of color */	printf (_ ("Storing grey scale.\n"));    if (!XAllocColorCells (CDisplay, cmap, 1, color_planes, 6, color_pixels + 43, 1))	alloccolorerror ();    for (i = 0; i < 64; i++) {	color_pixels[43 + i] = color_pixels[43] + i;	color.pixel = color_pixels[43 + i];	get_grey_colors (&color, i);	XStoreColor (CDisplay, cmap, &color);    }}void try_color (Colormap cmap, XColor * c, int size, XColor color, int i){    int x;    long error;    XColor closest;    x = CGetCloseColor (c, size, color, &error);    closest = c[x];    if (error) {	if (XAllocColorCells (CDisplay, cmap, 0, color_planes, 0, color_pixels + i, 1)) {	    color.pixel = color_pixels[i];	    XStoreColor (CDisplay, cmap, &color);	    if (verbose_operation)/* "Assign color" */		printf (_ ("Store,"));	    return;	}    }    if (!XAllocColor (CDisplay, cmap, &closest))	if (verbose_operation)/* "Ignoring" means that the program will continue regardless of this error */	    printf (_ ("\nerror allocating this color - ignoring;"));	/* this should never happen since closest comes from the colormap */    color_pixels[i] = closest.pixel;    if (verbose_operation)	printf ("%ld,", ((error == 0) ? 0 : 1) + ((error / (8 + 10 + 5)) >> (16 - BitsPerRGBofVisual (CVisual))));}/*   for PseudoColor displays. This tries to be conservative in the number   of entries its going to store, while still keeping the colors exact.   first it looks for an entry in the default colormap and only stores   in the map if no match is found. Multiple coolwidget applications can   therefore share the same map. At worst 16 + 27 of the palette are used   plus another 64 if you are using greyscale. */static void setup_store_colors (void){    int i, size;    XColor *c;    XColor color;    c = get_cells (CColormap, &size);    color.flags = DoRed | DoGreen | DoBlue;/* grey scale has to be contigous to be fast so store a 64 colors */    if (option_using_grey_scale) {#if 0	i = find_coolwidget_grey_scale (c, size);	if (i >= 0) {	    if (verbose_operation)/* Not essential to translate */		printf (_ ("found grey scale\n"));	    alloc_grey_scale (CColormap);	} else {#endif	    store_grey_scale (CColormap);#if 0	}#endif    }    if (verbose_operation)/* This isn't very important, run cooledit -verbose to see how this works */	printf (_ ("Trying colors...\n( 'Store'=store my own color, Number=integer error with existing color )\n"));    for (i = 0; i < 16; i++) {	get_button_color (&color, i);	try_color (CColormap, c, size, color, i);    }    for (i = 0; i < 27; i++) {	get_general_colors (&color, i);	try_color (CColormap, c, size, color, i + 16);    }    if (verbose_operation)	printf ("\n");    free (c);}static void setup_colormap (int class){    switch (class) {    case StaticColor:    case StaticGray:	setup_staticcolor ();	break;    case GrayScale:	setup_alloc_colors (1);	return;    case DirectColor:    case TrueColor:	setup_alloc_colors (0);	return;    case PseudoColor:	setup_store_colors ();	break;    }}int CSendEvent (XEvent * e);static XEvent xevent;static int cursor_blink_rate;/*   Aim1: Get the cursor to flash all the time:   Aim2: Have coolwidgets send an alarm event, just like   any other event. For the application to use.   Requirements: XNextEvent must still be the blocker   so that the process doesn't hog when idle.   Problems: If the alarm handler sends an event using   XSendEvent it may hang the program.   To solve, we put a pause() before XNextEvent so that it waits for    an alarm, and also define our own CSendEvent routine with   its own queue. So that things don't slow down, we pause() only   if no events are pending. Also make the alarm rate high (100 X per sec).   (I hope this is the easiest way to do this  :|   ) */void CSetCursorBlinkRate (int b){    if (b < 1)	b = 1;    cursor_blink_rate = b;}int CGetCursorBlinkRate (void){    return cursor_blink_rate;}/* does nothing and calls nothing for t seconds, resolution is ALRM_PER_SECOND */void CSleep (double t){    float i;    for (i = 0; i < t; i += 1.0 / ALRM_PER_SECOND)	pause ();}static struct itimerval alarm_every ={    {	0, 0    },    {	0, 1000000 / ALRM_PER_SECOND    }};static struct itimerval alarm_off ={    {	0, 0    },    {	0, 0    }};/*   This flag goes non-zero during the CSendEvent procedure. This   prevents the small chance that an alarm event might occur during   a CSendEvent. */int block_push_event = 0;static RETSIGTYPE alarmhandler (int x){    static int count = ALRM_PER_SECOND;    if (count) {	count--;	if (CQueueSize () < 16 && !block_push_event) {	    CSendEvent (&xevent);	}    } else {	xevent.type = AlarmEvent;	if (CQueueSize () < 128 && !block_push_event) {		/* say */	    CSendEvent (&xevent);	}	xevent.type = TickEvent;	count = ALRM_PER_SECOND / cursor_blink_rate;    }    signal (SIGALRM, alarmhandler);    setitimer (ITIMER_REAL, &alarm_every, NULL);#if (RETSIGTYPE==void)    return;#else    return 1;			/* :guess --- I don't know what to return here */#endif}#define CHILD_EXITED_MAX	32static struct {    pid_t pid;    int status;    unsigned long count;} children_exitted[CHILD_EXITED_MAX];static long child_exit_counter = 1;static int num_children_exitted = 0;#if (RETSIGTYPE==void)#define handler_return return#else#define handler_return return 1#endifstatic RETSIGTYPE childhandler (int x){    num_children_exitted++;    signal (SIGCHLD, childhandler);    handler_return;}void  childhandler_ (void){    pid_t p, save_errno = errno;    int i, status, j, n;    if (!num_children_exitted)	return;    n = num_children_exitted + 1;    for (j = 0; j < n; j++) {	do {	    errno = 0;	} while ((-1 == (p = waitpid (-1, NULL, WNOHANG))) && (errno == EINTR));	if (num_children_exitted > 0)	    num_children_exitted--;	if (p > 0) {	    unsigned long minimum = (unsigned long) (-1);	    int i_min = 0;	    for (i = 0; i < CHILD_EXITED_MAX; i++) {		if (!children_exitted[i].pid) {		    i_min = i;		    break;		}		if (children_exitted[i].count < minimum) {		    minimum = children_exitted[i].count;		    i_min = i;		}	    }	    children_exitted[i_min].pid = p;	    children_exitted[i_min].status = status;	    children_exitted[i_min].count = child_exit_counter++;	}    }    errno = save_errno;}/* returns non-zero on child exit */int CChildExitted (pid_t p, int *status){    int i;    for (i = 0; i < CHILD_EXITED_MAX; i++)	if (p && children_exitted[i].pid == p) {	    if (status)		*status = children_exitted[i].status;	    children_exitted[i].pid = 0;	    children_exitted[i].count = 0;	    return 1;	}    return 0;}static void set_child_handler (void){    memset (children_exitted, 0, sizeof (children_exitted));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -