~ubuntu-branches/ubuntu/trusty/xterm/trusty

« back to all changes in this revision

Viewing changes to misc.c

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2010-03-31 12:32:27 UTC
  • mfrom: (1.1.17 upstream) (11.1.17 sid)
  • Revision ID: james.westby@ubuntu.com-20100331123227-8a6qwmyciob6j88y
Tags: 256-1ubuntu1
* Merge from Debian unstable.
* Revert the libutempter change for lucid. (LP: #539473)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $XTermId: misc.c,v 1.456 2009/12/08 00:49:07 tom Exp $ */
 
1
/* $XTermId: misc.c,v 1.483 2010/03/03 22:32:26 Chris.Adams Exp $ */
2
2
 
3
3
/*
4
4
 *
5
 
 * Copyright 1999-2008,2009 by Thomas E. Dickey
 
5
 * Copyright 1999-2009,2010 by Thomas E. Dickey
6
6
 *
7
7
 *                        All Rights Reserved
8
8
 *
800
800
 
801
801
    for (n = 0; n < XtNumber(table); ++n) {
802
802
        if (table[n].value == which) {
803
 
            result = XInternAtom(XtDisplay(xw), table[n].name, True);
 
803
            result = XInternAtom(XtDisplay(xw), table[n].name, False);
804
804
            break;
805
805
        }
806
806
    }
814
814
    TScreen *screen = TScreenOf(xw);
815
815
#if defined(HAVE_XKB_BELL_EXT)
816
816
    Atom tony = AtomBell(xw, which);
 
817
#endif
 
818
 
 
819
    switch (which) {
 
820
    case XkbBI_Info:
 
821
    case XkbBI_MinorError:
 
822
    case XkbBI_MajorError:
 
823
    case XkbBI_TerminalBell:
 
824
        switch (screen->warningVolume) {
 
825
        case bvOff:
 
826
            percent = -100;
 
827
            break;
 
828
        case bvLow:
 
829
            break;
 
830
        case bvHigh:
 
831
            percent = 100;
 
832
            break;
 
833
        }
 
834
        break;
 
835
    case XkbBI_MarginBell:
 
836
        switch (screen->marginVolume) {
 
837
        case bvOff:
 
838
            percent = -100;
 
839
            break;
 
840
        case bvLow:
 
841
            break;
 
842
        case bvHigh:
 
843
            percent = 100;
 
844
            break;
 
845
        }
 
846
        break;
 
847
    default:
 
848
        break;
 
849
    }
 
850
 
 
851
#if defined(HAVE_XKB_BELL_EXT)
817
852
    if (tony != None) {
818
853
        XkbBell(screen->display, VShellWindow, percent, tony);
819
854
    } else
822
857
}
823
858
 
824
859
void
825
 
Bell(int which GCC_UNUSED, int percent)
 
860
Bell(int which, int percent)
826
861
{
827
862
    XtermWidget xw = term;
828
863
    TScreen *screen = TScreenOf(xw);
1740
1775
static void
1741
1776
ReportAnsiColorRequest(XtermWidget xw, int colornum, int final)
1742
1777
{
1743
 
    XColor color;
1744
 
    Colormap cmap = xw->core.colormap;
1745
 
    char buffer[80];
 
1778
    if (AllowColorOps(xw, ecGetAnsiColor)) {
 
1779
        XColor color;
 
1780
        Colormap cmap = xw->core.colormap;
 
1781
        char buffer[80];
1746
1782
 
1747
 
    TRACE(("ReportAnsiColorRequest %d\n", colornum));
1748
 
    color.pixel = GET_COLOR_RES(xw, TScreenOf(xw)->Acolors[colornum]);
1749
 
    XQueryColor(TScreenOf(xw)->display, cmap, &color);
1750
 
    sprintf(buffer, "4;%d;rgb:%04x/%04x/%04x",
1751
 
            colornum,
1752
 
            color.red,
1753
 
            color.green,
1754
 
            color.blue);
1755
 
    unparseputc1(xw, ANSI_OSC);
1756
 
    unparseputs(xw, buffer);
1757
 
    unparseputc1(xw, final);
1758
 
    unparse_end(xw);
 
1783
        TRACE(("ReportAnsiColorRequest %d\n", colornum));
 
1784
        color.pixel = GET_COLOR_RES(xw, TScreenOf(xw)->Acolors[colornum]);
 
1785
        XQueryColor(TScreenOf(xw)->display, cmap, &color);
 
1786
        sprintf(buffer, "4;%d;rgb:%04x/%04x/%04x",
 
1787
                colornum,
 
1788
                color.red,
 
1789
                color.green,
 
1790
                color.blue);
 
1791
        unparseputc1(xw, ANSI_OSC);
 
1792
        unparseputs(xw, buffer);
 
1793
        unparseputc1(xw, final);
 
1794
        unparse_end(xw);
 
1795
    }
1759
1796
}
1760
1797
 
1761
1798
static unsigned
2053
2090
    TRACE(("ResetAnsiColorRequest(%s)\n", buf));
2054
2091
    if (*buf != '\0') {
2055
2092
        /* reset specific colors */
2056
 
        while ((buf != 0) && (*buf != '\0')) {
 
2093
        while (!IsEmpty(buf)) {
2057
2094
            char *next;
2058
2095
 
2059
2096
            color = strtol(buf, &next, 10);
2311
2348
static void
2312
2349
ReportColorRequest(XtermWidget xw, int ndx, int final)
2313
2350
{
2314
 
    XColor color;
2315
 
    Colormap cmap = xw->core.colormap;
2316
 
    char buffer[80];
2317
 
 
2318
 
    /*
2319
 
     * ChangeColorsRequest() has "always" chosen the opposite color when
2320
 
     * reverse-video is set.  Report this as the original color index, but
2321
 
     * reporting the opposite color which would be used.
2322
 
     */
2323
 
    int i = (xw->misc.re_verse) ? oppositeColor(ndx) : ndx;
2324
 
 
2325
 
    GetOldColors(xw);
2326
 
    color.pixel = pOldColors->colors[ndx];
2327
 
    XQueryColor(TScreenOf(xw)->display, cmap, &color);
2328
 
    sprintf(buffer, "%d;rgb:%04x/%04x/%04x", i + 10,
2329
 
            color.red,
2330
 
            color.green,
2331
 
            color.blue);
2332
 
    TRACE(("ReportColors %d: %#lx as %s\n", ndx, pOldColors->colors[ndx], buffer));
2333
 
    unparseputc1(xw, ANSI_OSC);
2334
 
    unparseputs(xw, buffer);
2335
 
    unparseputc1(xw, final);
2336
 
    unparse_end(xw);
 
2351
    if (AllowColorOps(xw, ecGetColor)) {
 
2352
        XColor color;
 
2353
        Colormap cmap = xw->core.colormap;
 
2354
        char buffer[80];
 
2355
 
 
2356
        /*
 
2357
         * ChangeColorsRequest() has "always" chosen the opposite color when
 
2358
         * reverse-video is set.  Report this as the original color index, but
 
2359
         * reporting the opposite color which would be used.
 
2360
         */
 
2361
        int i = (xw->misc.re_verse) ? oppositeColor(ndx) : ndx;
 
2362
 
 
2363
        GetOldColors(xw);
 
2364
        color.pixel = pOldColors->colors[ndx];
 
2365
        XQueryColor(TScreenOf(xw)->display, cmap, &color);
 
2366
        sprintf(buffer, "%d;rgb:%04x/%04x/%04x", i + 10,
 
2367
                color.red,
 
2368
                color.green,
 
2369
                color.blue);
 
2370
        TRACE(("ReportColors %d: %#lx as %s\n",
 
2371
               ndx, pOldColors->colors[ndx], buffer));
 
2372
        unparseputc1(xw, ANSI_OSC);
 
2373
        unparseputs(xw, buffer);
 
2374
        unparseputc1(xw, final);
 
2375
        unparse_end(xw);
 
2376
    }
2337
2377
}
2338
2378
 
2339
2379
static Bool
2419
2459
            if (xw->misc.re_verse)
2420
2460
                ndx = oppositeColor(ndx);
2421
2461
 
2422
 
            if ((names == NULL) || (names[0] == '\0')) {
 
2462
            if (IsEmpty(names)) {
2423
2463
                newColors.names[ndx] = NULL;
2424
2464
            } else {
2425
2465
                if (names[0] == ';')
2487
2527
    return result;
2488
2528
}
2489
2529
 
 
2530
#if OPT_SHIFT_FONTS
 
2531
/*
 
2532
 * Initially, 'source' points to '#' or '?'.
 
2533
 *
 
2534
 * Look for an optional sign and optional number.  If those are found, lookup
 
2535
 * the corresponding menu font entry.
 
2536
 */
 
2537
static int
 
2538
ParseShiftedFont(XtermWidget xw, char *source, char **target)
 
2539
{
 
2540
    TScreen *screen = TScreenOf(xw);
 
2541
    int num = screen->menu_font_number;
 
2542
    int rel = 0;
 
2543
 
 
2544
    if (*++source == '+') {
 
2545
        rel = 1;
 
2546
        source++;
 
2547
    } else if (*source == '-') {
 
2548
        rel = -1;
 
2549
        source++;
 
2550
    }
 
2551
 
 
2552
    if (isdigit(CharOf(*source))) {
 
2553
        int val = atoi(source);
 
2554
        if (rel > 0)
 
2555
            rel = val;
 
2556
        else if (rel < 0)
 
2557
            rel = -val;
 
2558
        else
 
2559
            num = val;
 
2560
    }
 
2561
 
 
2562
    if (rel != 0) {
 
2563
        num = lookupRelativeFontSize(xw,
 
2564
                                     screen->menu_font_number, rel);
 
2565
 
 
2566
    }
 
2567
    TRACE(("ParseShiftedFont(%s) ->%d (%s)\n", *target, num, source));
 
2568
    *target = source;
 
2569
    return num;
 
2570
}
 
2571
 
 
2572
static void
 
2573
QueryFontRequest(XtermWidget xw, char *buf, int final)
 
2574
{
 
2575
    if (AllowFontOps(xw, efGetFont)) {
 
2576
        TScreen *screen = TScreenOf(xw);
 
2577
        Bool success = True;
 
2578
        int num;
 
2579
        char *base = buf + 1;
 
2580
        char *name = 0;
 
2581
        char temp[10];
 
2582
 
 
2583
        num = ParseShiftedFont(xw, buf, &buf);
 
2584
        if (num < 0
 
2585
            || num > fontMenu_lastBuiltin) {
 
2586
            Bell(XkbBI_MinorError, 0);
 
2587
            success = False;
 
2588
        } else {
 
2589
#if OPT_RENDERFONT
 
2590
            if (UsingRenderFont(xw)) {
 
2591
                name = getFaceName(xw, False);
 
2592
            } else
 
2593
#endif
 
2594
            if ((name = screen->MenuFontName(num)) == 0) {
 
2595
                success = False;
 
2596
            }
 
2597
        }
 
2598
 
 
2599
        unparseputc1(xw, ANSI_OSC);
 
2600
        unparseputs(xw, "50");
 
2601
 
 
2602
        if (success) {
 
2603
            unparseputc(xw, ';');
 
2604
            if (buf >= base) {
 
2605
                /* identify the font-entry, unless it is the current one */
 
2606
                if (*buf != '\0') {
 
2607
                    unparseputc(xw, '#');
 
2608
                    sprintf(temp, "%d", num);
 
2609
                    unparseputs(xw, temp);
 
2610
                    if (*name != '\0')
 
2611
                        unparseputc(xw, ' ');
 
2612
                }
 
2613
            }
 
2614
            unparseputs(xw, name);
 
2615
        }
 
2616
 
 
2617
        unparseputc1(xw, final);
 
2618
        unparse_end(xw);
 
2619
    }
 
2620
}
 
2621
 
 
2622
static void
 
2623
ChangeFontRequest(XtermWidget xw, char *buf)
 
2624
{
 
2625
    if (AllowFontOps(xw, efSetFont)) {
 
2626
        TScreen *screen = TScreenOf(xw);
 
2627
        Bool success = True;
 
2628
        int num;
 
2629
        VTFontNames fonts;
 
2630
        char *name;
 
2631
 
 
2632
        /*
 
2633
         * If the font specification is a "#", followed by an optional sign and
 
2634
         * optional number, lookup the corresponding menu font entry.
 
2635
         *
 
2636
         * Further, if the "#", etc., is followed by a font name, use that
 
2637
         * to load the font entry.
 
2638
         */
 
2639
        if (*buf == '#') {
 
2640
            num = ParseShiftedFont(xw, buf, &buf);
 
2641
 
 
2642
            if (num < 0
 
2643
                || num > fontMenu_lastBuiltin) {
 
2644
                Bell(XkbBI_MinorError, 0);
 
2645
                success = False;
 
2646
            } else {
 
2647
                /*
 
2648
                 * Skip past the optional number, and any whitespace to look
 
2649
                 * for a font specification within the control.
 
2650
                 */
 
2651
                while (isdigit(CharOf(*buf))) {
 
2652
                    ++buf;
 
2653
                }
 
2654
                while (isspace(CharOf(*buf))) {
 
2655
                    ++buf;
 
2656
                }
 
2657
#if OPT_RENDERFONT
 
2658
                if (UsingRenderFont(xw)) {
 
2659
                    ;           /* there is only one font entry to load */
 
2660
                } else
 
2661
#endif
 
2662
                {
 
2663
                    /*
 
2664
                     * Normally there is no font specified in the control.
 
2665
                     * But if there is, simply overwrite the font entry.
 
2666
                     */
 
2667
                    if (*buf == '\0') {
 
2668
                        if ((buf = screen->MenuFontName(num)) == 0) {
 
2669
                            success = False;
 
2670
                        }
 
2671
                    }
 
2672
                }
 
2673
            }
 
2674
        } else {
 
2675
            num = screen->menu_font_number;
 
2676
        }
 
2677
        name = x_strtrim(buf);
 
2678
        if (success && !IsEmpty(name)) {
 
2679
#if OPT_RENDERFONT
 
2680
            if (UsingRenderFont(xw)) {
 
2681
                setFaceName(xw, name);
 
2682
                xtermUpdateFontInfo(xw, True);
 
2683
            } else
 
2684
#endif
 
2685
            {
 
2686
                memset(&fonts, 0, sizeof(fonts));
 
2687
                fonts.f_n = name;
 
2688
                SetVTFont(xw, num, True, &fonts);
 
2689
            }
 
2690
        } else {
 
2691
            Bell(XkbBI_MinorError, 0);
 
2692
        }
 
2693
        free(name);
 
2694
    }
 
2695
}
 
2696
#endif /* OPT_SHIFT_FONTS */
 
2697
 
2490
2698
/***====================================================================***/
2491
2699
 
2492
2700
void
2584
2792
 
2585
2793
    /*
2586
2794
     * Check if we have data when we want, and not when we do not want it.
 
2795
     * Either way, that is a malformed control sequence, and will be ignored.
2587
2796
     */
2588
 
    if (buf == 0) {
 
2797
    if (IsEmpty(buf)) {
2589
2798
        if (need_data) {
2590
2799
            TRACE(("do_osc found no data\n"));
2591
2800
            return;
2680
2889
         * Warning, enabling this feature allows people to overwrite
2681
2890
         * arbitrary files accessible to the person running xterm.
2682
2891
         */
2683
 
        if (buf != 0
2684
 
            && strcmp(buf, "?")
 
2892
        if (strcmp(buf, "?")
2685
2893
            && (cp = CastMallocN(char, strlen(buf)) != NULL)) {
2686
2894
            strcpy(cp, buf);
2687
2895
            if (screen->logfile)
2697
2905
 
2698
2906
    case 50:
2699
2907
#if OPT_SHIFT_FONTS
2700
 
        if (!AllowFontOps(xw) && xw->misc.shift_fonts) {
2701
 
            ;                   /* disabled via resource or control-sequence */
2702
 
        } else if (buf != 0 && !strcmp(buf, "?")) {
2703
 
            int num = screen->menu_font_number;
2704
 
 
2705
 
            unparseputc1(xw, ANSI_OSC);
2706
 
            unparseputs(xw, "50");
2707
 
 
2708
 
            if ((buf = screen->MenuFontName(num)) != 0) {
2709
 
                unparseputc(xw, ';');
2710
 
                unparseputs(xw, buf);
2711
 
            }
2712
 
            unparseputc1(xw, final);
2713
 
            unparse_end(xw);
2714
 
        } else if (buf != 0) {
2715
 
            int num = screen->menu_font_number;
2716
 
            VTFontNames fonts;
2717
 
 
2718
 
            memset(&fonts, 0, sizeof(fonts));
2719
 
 
2720
 
            /*
2721
 
             * If the font specification is a "#", followed by an
2722
 
             * optional sign and optional number, lookup the
2723
 
             * corresponding menu font entry.
2724
 
             */
2725
 
            if (*buf == '#') {
2726
 
                int rel = 0;
2727
 
 
2728
 
                if (*++buf == '+') {
2729
 
                    rel = 1;
2730
 
                    buf++;
2731
 
                } else if (*buf == '-') {
2732
 
                    rel = -1;
2733
 
                    buf++;
2734
 
                }
2735
 
 
2736
 
                if (isdigit(CharOf(*buf))) {
2737
 
                    int val = atoi(buf);
2738
 
                    if (rel > 0)
2739
 
                        rel = val;
2740
 
                    else if (rel < 0)
2741
 
                        rel = -val;
2742
 
                    else
2743
 
                        num = val;
2744
 
                } else if (rel == 0) {
2745
 
                    num = 0;
2746
 
                }
2747
 
 
2748
 
                if (rel != 0) {
2749
 
                    num = lookupRelativeFontSize(xw,
2750
 
                                                 screen->menu_font_number, rel);
2751
 
 
2752
 
                }
2753
 
                if (num < 0
2754
 
                    || num > fontMenu_lastBuiltin
2755
 
                    || (buf = screen->MenuFontName(num)) == 0) {
2756
 
                    Bell(XkbBI_MinorError, 0);
2757
 
                    break;
2758
 
                }
2759
 
            } else {
2760
 
                num = fontMenu_fontescape;
2761
 
            }
2762
 
            fonts.f_n = buf;
2763
 
            SetVTFont(xw, num, True, &fonts);
 
2908
        if (*buf == '?') {
 
2909
            QueryFontRequest(xw, buf, final);
 
2910
        } else if (xw->misc.shift_fonts) {
 
2911
            ChangeFontRequest(xw, buf);
2764
2912
        }
2765
2913
#endif /* OPT_SHIFT_FONTS */
2766
2914
        break;
3134
3282
#if OPT_TCAP_QUERY
3135
3283
    case '+':
3136
3284
        cp++;
3137
 
        if ((*cp == 'q') && AllowTcapOps(xw)) {
3138
 
            Bool fkey;
3139
 
            unsigned state;
3140
 
            int code;
3141
 
            const char *tmp;
3142
 
            const char *parsed = ++cp;
3143
 
 
3144
 
            code = xtermcapKeycode(xw, &parsed, &state, &fkey);
3145
 
 
3146
 
            unparseputc1(xw, ANSI_DCS);
3147
 
 
3148
 
            unparseputc(xw, code >= 0 ? '1' : '0');
3149
 
 
3150
 
            unparseputc(xw, '+');
3151
 
            unparseputc(xw, 'r');
3152
 
 
3153
 
            while (*cp != 0 && (code >= -1)) {
3154
 
                if (cp == parsed)
3155
 
                    break;      /* no data found, error */
3156
 
 
3157
 
                for (tmp = cp; tmp != parsed; ++tmp)
3158
 
                    unparseputc(xw, *tmp);
3159
 
 
3160
 
                if (code >= 0) {
3161
 
                    unparseputc(xw, '=');
3162
 
                    screen->tc_query_code = code;
3163
 
                    screen->tc_query_fkey = fkey;
 
3285
        switch (*cp) {
 
3286
        case 'p':
 
3287
            if (AllowTcapOps(xw, etSetTcap)) {
 
3288
                set_termcap(xw, cp + 1);
 
3289
            }
 
3290
            break;
 
3291
        case 'q':
 
3292
            if (AllowTcapOps(xw, etGetTcap)) {
 
3293
                Bool fkey;
 
3294
                unsigned state;
 
3295
                int code;
 
3296
                const char *tmp;
 
3297
                const char *parsed = ++cp;
 
3298
 
 
3299
                code = xtermcapKeycode(xw, &parsed, &state, &fkey);
 
3300
 
 
3301
                unparseputc1(xw, ANSI_DCS);
 
3302
 
 
3303
                unparseputc(xw, code >= 0 ? '1' : '0');
 
3304
 
 
3305
                unparseputc(xw, '+');
 
3306
                unparseputc(xw, 'r');
 
3307
 
 
3308
                while (*cp != 0 && (code >= -1)) {
 
3309
                    if (cp == parsed)
 
3310
                        break;  /* no data found, error */
 
3311
 
 
3312
                    for (tmp = cp; tmp != parsed; ++tmp)
 
3313
                        unparseputc(xw, *tmp);
 
3314
 
 
3315
                    if (code >= 0) {
 
3316
                        unparseputc(xw, '=');
 
3317
                        screen->tc_query_code = code;
 
3318
                        screen->tc_query_fkey = fkey;
3164
3319
#if OPT_ISO_COLORS
3165
 
                    /* XK_COLORS is a fake code for the "Co" entry (maximum
3166
 
                     * number of colors) */
3167
 
                    if (code == XK_COLORS) {
3168
 
                        unparseputn(xw, NUM_ANSI_COLORS);
3169
 
                    } else
 
3320
                        /* XK_COLORS is a fake code for the "Co" entry (maximum
 
3321
                         * number of colors) */
 
3322
                        if (code == XK_COLORS) {
 
3323
                            unparseputn(xw, NUM_ANSI_COLORS);
 
3324
                        } else
3170
3325
#endif
3171
 
                    {
3172
 
                        XKeyEvent event;
3173
 
                        event.state = state;
3174
 
                        Input(xw, &event, False);
 
3326
                        if (code == XK_TCAPNAME) {
 
3327
                            unparseputs(xw, xterm_name);
 
3328
                        } else {
 
3329
                            XKeyEvent event;
 
3330
                            event.state = state;
 
3331
                            Input(xw, &event, False);
 
3332
                        }
 
3333
                        screen->tc_query_code = -1;
 
3334
                    } else {
 
3335
                        break;  /* no match found, error */
3175
3336
                    }
3176
 
                    screen->tc_query_code = -1;
3177
 
                } else {
3178
 
                    break;      /* no match found, error */
3179
 
                }
3180
3337
 
3181
 
                cp = parsed;
3182
 
                if (*parsed == ';') {
3183
 
                    unparseputc(xw, *parsed++);
3184
3338
                    cp = parsed;
3185
 
                    code = xtermcapKeycode(xw, &parsed, &state, &fkey);
 
3339
                    if (*parsed == ';') {
 
3340
                        unparseputc(xw, *parsed++);
 
3341
                        cp = parsed;
 
3342
                        code = xtermcapKeycode(xw, &parsed, &state, &fkey);
 
3343
                    }
3186
3344
                }
 
3345
                unparseputc1(xw, ANSI_ST);
3187
3346
            }
3188
 
            unparseputc1(xw, ANSI_ST);
 
3347
            break;
3189
3348
        }
3190
3349
        break;
3191
3350
#endif
3294
3453
                if (CharOf(name[n]) > 127) {
3295
3454
                    if (converted != 0)
3296
3455
                        free(converted);
3297
 
                    if ((converted = TypeMallocN(Char, 1 + (5 * limit))) != 0) {
 
3456
                    if ((converted = TypeMallocN(Char, 1 + (6 * limit))) != 0) {
3298
3457
                        Char *temp = converted;
3299
3458
                        while (*name != 0) {
3300
3459
                            temp = convertToUTF8(temp, CharOf(*name));
3467
3626
                  int ndx,
3468
3627
                  const char *name)
3469
3628
{
3470
 
    XColor def;
3471
 
    TScreen *screen = TScreenOf(xw);
3472
 
    Colormap cmap = xw->core.colormap;
3473
 
    char *newName;
3474
 
 
3475
 
    if (XParseColor(screen->display, cmap, name, &def)
3476
 
        && (XAllocColor(screen->display, cmap, &def)
3477
 
            || find_closest_color(screen->display, cmap, &def))
3478
 
        && (newName = x_strdup(name)) != 0) {
3479
 
        if (COLOR_DEFINED(pNew, ndx))
3480
 
            free(pNew->names[ndx]);
3481
 
        SET_COLOR_VALUE(pNew, ndx, def.pixel);
3482
 
        SET_COLOR_NAME(pNew, ndx, newName);
3483
 
        TRACE(("AllocateTermColor #%d: %s (pixel %#lx)\n", ndx, newName, def.pixel));
3484
 
        return (True);
 
3629
    Bool result = False;
 
3630
 
 
3631
    if (AllowColorOps(xw, ecSetColor)) {
 
3632
        XColor def;
 
3633
        TScreen *screen = TScreenOf(xw);
 
3634
        Colormap cmap = xw->core.colormap;
 
3635
        char *newName;
 
3636
 
 
3637
        if (XParseColor(screen->display, cmap, name, &def)
 
3638
            && (XAllocColor(screen->display, cmap, &def)
 
3639
                || find_closest_color(screen->display, cmap, &def))
 
3640
            && (newName = x_strdup(name)) != 0) {
 
3641
            if (COLOR_DEFINED(pNew, ndx))
 
3642
                free(pNew->names[ndx]);
 
3643
            SET_COLOR_VALUE(pNew, ndx, def.pixel);
 
3644
            SET_COLOR_NAME(pNew, ndx, newName);
 
3645
            TRACE(("AllocateTermColor #%d: %s (pixel %#lx)\n", ndx, newName, def.pixel));
 
3646
            result = True;
 
3647
        } else {
 
3648
            TRACE(("AllocateTermColor #%d: %s (failed)\n", ndx, name));
 
3649
        }
3485
3650
    }
3486
 
    TRACE(("AllocateTermColor #%d: %s (failed)\n", ndx, name));
3487
 
    return (False);
 
3651
    return result;
3488
3652
}
3489
3653
/***====================================================================***/
3490
3654