Esempio n. 1
0
static int swapsystem(char *cmd)
{
	char	*prog, *args;
	int	retcode;

	for (; elvspace(*cmd); cmd++)
	{
	}
	prog = safedup(cmd);
	for (args = prog; *args && !elvspace(*args); args++)
	{
	}
	if (*args)
		*args++ = '\0';
	retcode = do_exec(prog, args, USE_ALL|HIDE_FILE, 0xFFFF, NULL);
	if (retcode == RC_NOFILE)
	{
		safefree(prog);
		prog = safealloc(strlen(cmd) + 4, sizeof(char));
		strcpy(prog, "/c ");
		strcat(prog, cmd);
		retcode = do_exec(tochar8(o_shell), prog,
					USE_ALL|HIDE_FILE, 0xFFFF, NULL);
	}
	safefree(prog);
	return retcode;
}
Esempio n. 2
0
File: guiwin.c Progetto: mbert/elvis
static ELVBOOL gwcolor (int fontcode, Char *colornam, ELVBOOL isfg, long *colorptr, unsigned char rgb[3])
{
    register int        i, j;
    int			r, g, b;
    char		*rgbfile;
    char		rgbname[100];
    FILE		*fp;
#ifdef FEATURE_IMAGE
    HBITMAP		newimg;
    long		average;
    char		*imagefile;

    /* split the name into a "colornam" part and an "imagefile" part */
    imagefile = colornam;
    if (*imagefile == '#')
        imagefile++;
    while (*imagefile && !elvpunct(*imagefile))
        imagefile++;
    while (*imagefile && imagefile > colornam && !elvspace(*imagefile))
        imagefile--;
    if (!*imagefile)
        imagefile = NULL;
    else if (imagefile > colornam)
        *imagefile++ = '\0';
    else
        colornam = "";
#endif

    /* parse the color name */
    if (*colornam == '#')
    {
        /* Accept X11's "#rrggbb" or "#rgb" notations */
        if (sscanf(tochar8(colornam), "#%2x%*2x%2x%*2x%2x", &r, &g, &b) == 3)
            /* do nothing */;
        else if (sscanf(tochar8(colornam), "#%2x%2x%2x", &r, &g, &b) == 3)
            /* do nothing */;
        else if (sscanf(tochar8(colornam), "#%1x%1x%1x", &r, &g, &b) == 3)
        {
            r *= 17;
            g *= 17;
            b *= 17;
        }
        else
        {
            msg(MSG_ERROR, "[S]bad color notation $1", colornam);
            return ElvFalse;
        }
    }
    else if (!*colornam)
    {
        r = g = b = -1;
    }
    else
    {
        /* Normalize the color name by converting to lowercase and removing
         * whitespace.  We can safely modify the colornam[] buffer in-place.
         */
        for (i = j = 0; colornam[i]; i++)
            if (!elvspace(colornam[i]))
                colornam[j++] = elvtolower(colornam[i]);
        colornam[j] = '\0';

        /* look up the color */
        for (i = 0;
                colortbl[i].name && CHARcmp(toCHAR(colortbl[i].name), colornam);
                i++)
        {
        }
        if (colortbl[i].name)
        {
            /* Use the found color */
            r = colortbl[i].rgb[0];
            g = colortbl[i].rgb[1];
            b = colortbl[i].rgb[2];
        }
        else /* not found -- try "rgb.txt" */
        {
            /* search for the color in the "rgb.txt" file */
            *rgbname = '\0';
            rgbfile = iopath(o_elvispath, "rgb.txt", ElvFalse);
            if (rgbfile) {
                fp = fopen(rgbfile, "r");
                if (fp) {
                    while (fscanf(fp, "%d %d %d %s", &r, &g, &b, &rgbname) == 4
                            && CHARcmp(tochar8(rgbname), colornam))
                    {
                    }
                    fclose(fp);
                }
            }

            /* if we didn't find it there, then fail */
            if (CHARcmp(tochar8(rgbname), colornam)) {
                if (isfg) {
                    memcpy(rgb, colorinfo[COLOR_FONT_NORMAL].da.fg_rgb, 3);
                    *colorptr = colorinfo[COLOR_FONT_NORMAL].fg;
                } else {
                    memcpy(rgb, colorinfo[COLOR_FONT_NORMAL].da.bg_rgb, 3);
                    *colorptr = colorinfo[COLOR_FONT_NORMAL].bg;
                }
                msg(MSG_ERROR, "[S]unknown color $1", colornam);
                return ElvFalse;
            }
        }
    }

#ifdef FEATURE_IMAGE
    if (imagefile && isfg)
    {
        msg(MSG_ERROR, "Can't use images for foreground");
        return ElvFalse;
    }
#endif

    /* if no image or color, then fail */
    if (
#ifdef FEATURE_IMAGE
        !imagefile &&
#endif
        r < 0)
    {
        msg(MSG_ERROR, "missing color name");
        return ElvFalse;
    }

#ifdef FEATURE_IMAGE
    /* if image name was given for "normal" or "idle" font, then load image */
    if (imagefile && (fontcode==COLOR_FONT_NORMAL || fontcode==COLOR_FONT_IDLE))
    {
        /* decide whether to use a tint */
        if (r >= 0)
            average = RGB(r, g, b);
        else
            average = -1;

        /* load the image */
        newimg = gw_load_xpm(imagefile, average, &average, NULL);
        if (newimg)
        {
            /* use the average colors */
            r = GetRValue(average);
            g = GetGValue(average);
            b = GetBValue(average);

            /* if there was an old image, discard it now */
            if (fontcode == COLOR_FONT_NORMAL && normalimage)
                gw_unload_xpm(normalimage);
            if (fontcode == COLOR_FONT_IDLE && idleimage)
                gw_unload_xpm(idleimage);

            /* store the new image */
            if (fontcode == COLOR_FONT_NORMAL)
                normalimage = newimg;
            else
                idleimage = newimg;
        }
        else
        {
            return ElvFalse;
        }
    }
    if (!imagefile && fontcode==COLOR_FONT_NORMAL && normalimage && !isfg)
    {
        gw_unload_xpm(normalimage);
        normalimage = NULL;
    }
    if (!imagefile && fontcode==COLOR_FONT_IDLE && idleimage && !isfg)
    {
        gw_unload_xpm(idleimage);
        idleimage = NULL;
    }
#endif

    /* Success!  Store the color and return ElvTrue */
    *colorptr = RGB(r, g, b);
    rgb[0] = r;
    rgb[1] = g;
    rgb[2] = b;
    return ElvTrue;
}