~ubuntu-branches/ubuntu/saucy/xterm/saucy-proposed

« back to all changes in this revision

Viewing changes to charproc.c

  • Committer: Package Import Robot
  • Author(s): Logan Rosen
  • Date: 2012-07-10 03:41:01 UTC
  • mfrom: (1.4.14) (11.1.30 sid)
  • Revision ID: package-import@ubuntu.com-20120710034101-04cavzg5kpu6f4pw
Tags: 278-1ubuntu1
* Merge from Debian unstable. Remaining changes:
  - debian/patches/950_ubuntu_charclass_highlight.diff: Enabled URL
    highlighting
  - debian/patches/Add 951_uxterm_utf8_title.diff: Set utf8Titles to true by
    default when using uxterm, so that it displays utf8 directories in titles
    properly.  May cause issues with apps that use control sequences for
    updating the xterm titlebar - users should use xterm or set utf8Title
    to false in this case.
  - debian/gbp.conf: Use "Ubuntu" in "debian-branch" directly
  - Install .desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $XTermId: charproc.c,v 1.1126 2011/07/10 23:19:26 tom Exp $ */
 
1
/* $XTermId: charproc.c,v 1.1161 2012/01/19 00:22:08 tom Exp $ */
2
2
 
3
3
/*
4
4
 * Copyright 1999-2010,2011 by Thomas E. Dickey
173
173
#define StopBlinking(screen)    /* nothing */
174
174
#endif
175
175
 
176
 
#if OPT_INPUT_METHOD
177
 
static void PreeditPosition(TScreen * screen);
 
176
#if OPT_I18N_SUPPORT && OPT_INPUT_METHOD
 
177
static void PreeditPosition(XtermWidget /* xw */ );
178
178
#endif
179
179
 
180
180
#define DEFAULT         -1
341
341
#if OPT_SCROLL_LOCK
342
342
    { "scroll-lock",            HandleScrollLock },
343
343
#endif
 
344
#if OPT_SELECTION_OPS
 
345
    { "exec-formatted",         HandleExecFormatted },
 
346
    { "exec-selectable",        HandleExecSelectable },
 
347
    { "insert-formatted",       HandleInsertFormatted },
 
348
    { "insert-selectable",      HandleInsertSelectable },
 
349
#endif
344
350
#if OPT_SHIFT_FONTS
345
351
    { "larger-vt-font",         HandleLargerFont },
346
352
    { "smaller-vt-font",        HandleSmallerFont },
434
440
    Bres(XtNtrimSelection, XtCTrimSelection, screen.trim_selection, False),
435
441
    Bres(XtNunderLine, XtCUnderLine, screen.underline, True),
436
442
    Bres(XtNvisualBell, XtCVisualBell, screen.visualbell, False),
 
443
    Bres(XtNvisualBellLine, XtCVisualBellLine, screen.flash_line, False),
 
444
 
 
445
    Dres(XtNscaleHeight, XtCScaleHeight, screen.scale_height, "1.0"),
437
446
 
438
447
    Ires(XtNbellSuppressTime, XtCBellSuppressTime, screen.bellSuppressTime, BELLSUPPRESSMSEC),
439
448
    Ires(XtNfontWarnings, XtCFontWarnings, misc.fontWarnings, fwResource),
471
480
         screen.disallowedTcapOps, DEF_DISALLOWED_TCAP),
472
481
    Sres(XtNdisallowedWindowOps, XtCDisallowedWindowOps,
473
482
         screen.disallowedWinOps, DEF_DISALLOWED_WINDOW),
 
483
    Sres(XtNeightBitMeta, XtCEightBitMeta, screen.eight_bit_meta_s, DEF_8BIT_META),
474
484
    Sres(XtNeightBitSelectTypes, XtCEightBitSelectTypes,
475
485
         screen.eightbit_select_types, NULL),
476
486
    Sres(XtNfont, XtCFont, misc.default_font.f_n, DEFFONT),
1065
1075
            /* FALLTHRU */
1066
1076
        case 2:
1067
1077
            screen->gsets[0] = 'B';     /* G0 is ASCII */
1068
 
            screen->gsets[1] = 'B';     /* G1 is ISO Latin-1 (FIXME) */
 
1078
            screen->gsets[1] = 'B';     /* G1 is ISO Latin-1 */
1069
1079
            screen->curgl = 0;
1070
1080
            screen->curgr = 1;
1071
1081
            break;
1287
1297
}
1288
1298
 
1289
1299
static int
1290
 
minus_if_default(int which)
1291
 
{
1292
 
    int result = (nparam > which) ? param[which] : -1;
1293
 
    if (result <= 0)
1294
 
        result = -1;
1295
 
    return result;
1296
 
}
1297
 
 
1298
 
static int
1299
1300
zero_if_default(int which)
1300
1301
{
1301
1302
    int result = (nparam > which) ? param[which] : 0;
1568
1569
        if (sp->nextstate == CASE_PRINT) {
1569
1570
            SafeAlloc(IChar, sp->print_area, sp->print_used, sp->print_size);
1570
1571
            if (new_string == 0) {
1571
 
                fprintf(stderr,
1572
 
                        "Cannot allocate %lu bytes for printable text\n",
1573
 
                        (unsigned long) new_length);
 
1572
                xtermWarning("Cannot allocate %lu bytes for printable text\n",
 
1573
                             (unsigned long) new_length);
1574
1574
                continue;
1575
1575
            }
1576
1576
#if OPT_VT52_MODE
1606
1606
        if (sp->parsestate == sos_table) {
1607
1607
            SafeAlloc(Char, sp->string_area, sp->string_used, sp->string_size);
1608
1608
            if (new_string == 0) {
1609
 
                fprintf(stderr,
1610
 
                        "Cannot allocate %lu bytes for string mode %d\n",
1611
 
                        (unsigned long) new_length, sp->string_mode);
 
1609
                xtermWarning("Cannot allocate %lu bytes for string mode %d\n",
 
1610
                             (unsigned long) new_length, sp->string_mode);
1612
1611
                continue;
1613
1612
            }
1614
1613
#if OPT_WIDE_CHARS
2762
2761
            ResetState(sp);
2763
2762
            break;
2764
2763
 
 
2764
        case CASE_SL:           /* ISO 6429, non-DEC */
 
2765
            TRACE(("CASE_SL - scroll left\n"));
 
2766
            if ((count = param[0]) < 1)
 
2767
                count = 1;
 
2768
            xtermScrollLR(xw, count, True);
 
2769
            ResetState(sp);
 
2770
            break;
 
2771
 
 
2772
        case CASE_SR:           /* ISO 6429, non-DEC */
 
2773
            TRACE(("CASE_SR - scroll right\n"));
 
2774
            if ((count = param[0]) < 1)
 
2775
                count = 1;
 
2776
            xtermScrollLR(xw, count, False);
 
2777
            ResetState(sp);
 
2778
            break;
 
2779
 
 
2780
        case CASE_DECDC:
 
2781
            TRACE(("CASE_DC - delete column\n"));
 
2782
            if (screen->terminal_id >= 400) {
 
2783
                if ((count = param[0]) < 1)
 
2784
                    count = 1;
 
2785
                xtermColScroll(xw, count, True, screen->cur_col);
 
2786
            }
 
2787
            ResetState(sp);
 
2788
            break;
 
2789
 
 
2790
        case CASE_DECIC:
 
2791
            TRACE(("CASE_IC - insert column\n"));
 
2792
            if (screen->terminal_id >= 400) {
 
2793
                if ((count = param[0]) < 1)
 
2794
                    count = 1;
 
2795
                xtermColScroll(xw, count, False, screen->cur_col);
 
2796
            }
 
2797
            ResetState(sp);
 
2798
            break;
 
2799
 
 
2800
        case CASE_DECBI:
 
2801
            TRACE(("CASE_BI - back index\n"));
 
2802
            if (screen->terminal_id >= 400) {
 
2803
                xtermColIndex(xw, True);
 
2804
            }
 
2805
            ResetState(sp);
 
2806
            break;
 
2807
 
 
2808
        case CASE_DECFI:
 
2809
            TRACE(("CASE_FI - forward index\n"));
 
2810
            if (screen->terminal_id >= 400) {
 
2811
                xtermColIndex(xw, False);
 
2812
            }
 
2813
            ResetState(sp);
 
2814
            break;
 
2815
 
2765
2816
        case CASE_IND:
2766
2817
            TRACE(("CASE_IND - index\n"));
2767
2818
            xtermIndex(xw, 1);
3368
3419
                    v_bufend = v_bufptr + len;
3369
3420
                } else {
3370
3421
                    /* no memory: ignore entire write request */
3371
 
                    fprintf(stderr, "%s: cannot allocate buffer space\n",
3372
 
                            ProgramName);
 
3422
                    xtermWarning("cannot allocate buffer space\n");
3373
3423
                    v_buffer = v_bufstr;        /* restore clobbered pointer */
3374
3424
                }
3375
3425
            }
3468
3518
    }
3469
3519
}
3470
3520
 
 
3521
#if OPT_BLINK_CURS || OPT_BLINK_TEXT
3471
3522
static void
3472
3523
reallyStopBlinking(TScreen * screen)
3473
3524
{
3478
3529
        xevents();
3479
3530
    }
3480
3531
}
 
3532
#endif
3481
3533
 
3482
3534
#ifdef VMS
3483
3535
#define ptymask()       (v_bufptr > v_bufstr ? pty_mask : 0)
3539
3591
            if (screen->cursor_state)
3540
3592
                HideCursor();
3541
3593
            ShowCursor();
3542
 
#if OPT_INPUT_METHOD
3543
 
            PreeditPosition(screen);
 
3594
#if OPT_I18N_SUPPORT && OPT_INPUT_METHOD
 
3595
            PreeditPosition(xw);
3544
3596
#endif
3545
3597
        } else {
3546
3598
            updateCursor(screen);
3640
3692
            if (screen->cursor_state)
3641
3693
                HideCursor();
3642
3694
            ShowCursor();
3643
 
#if OPT_INPUT_METHOD
3644
 
            PreeditPosition(screen);
 
3695
#if OPT_I18N_SUPPORT && OPT_INPUT_METHOD
 
3696
            PreeditPosition(xw);
3645
3697
#endif
3646
3698
        } else {
3647
3699
            updateCursor(screen);
3671
3723
         * The blocking is optional, because it tends to increase the load
3672
3724
         * on the host.
3673
3725
         */
3674
 
        if (XtAppPending(app_con)) {
 
3726
        if (xtermAppPending()) {
3675
3727
            select_timeout.tv_usec = 0;
3676
3728
            time_select = 1;
3677
3729
        } else if (screen->awaitInput) {
3711
3763
 
3712
3764
        /* if there are X events already in our queue, it
3713
3765
           counts as being readable */
3714
 
        if (XtAppPending(app_con) ||
 
3766
        if (xtermAppPending() ||
3715
3767
            FD_ISSET(ConnectionNumber(screen->display), &select_mask)) {
3716
3768
            xevents();
3717
3769
            if (VTbuffer->update != update)     /* HandleInterpret */
3732
3784
    return nextPtyData(screen, VTbuffer);
3733
3785
}
3734
3786
 
3735
 
#if OPT_INPUT_METHOD
 
3787
#if OPT_I18N_SUPPORT && OPT_INPUT_METHOD
3736
3788
/*
3737
3789
 *  For OverTheSpot, client has to inform the position for XIM preedit.
3738
3790
 */
3739
3791
static void
3740
 
PreeditPosition(TScreen * screen)
 
3792
PreeditPosition(XtermWidget xw)
3741
3793
{
 
3794
    TInput *input = lookupTInput(xw, (Widget) xw);
 
3795
    TScreen *screen = TScreenOf(xw);
3742
3796
    LineData *ld;
3743
3797
    XPoint spot;
3744
3798
    XVaNestedList list;
3745
3799
 
3746
 
    if (screen->xic
 
3800
    if (input->xic
3747
3801
        && (ld = getLineData(screen, screen->cur_row)) != 0) {
3748
3802
        spot.x = (short) LineCursorX(screen, ld, screen->cur_col);
3749
 
        spot.y = (short) (CursorY(screen, screen->cur_row) + screen->fs_ascent);
 
3803
        spot.y = (short) (CursorY(screen, screen->cur_row) + xw->misc.xim_fs_ascent);
3750
3804
        list = XVaCreateNestedList(0,
3751
3805
                                   XNSpotLocation, &spot,
3752
3806
                                   XNForeground, T_COLOR(screen, TEXT_FG),
3753
3807
                                   XNBackground, T_COLOR(screen, TEXT_BG),
3754
 
                                   NULL);
3755
 
        XSetICValues(screen->xic, XNPreeditAttributes, list, NULL);
 
3808
                                   (void *) 0);
 
3809
        XSetICValues(input->xic, XNPreeditAttributes, list, (void *) 0);
3756
3810
        XFree(list);
3757
3811
    }
3758
3812
}
4008
4062
                               save.menu_border));
4009
4063
 
4010
4064
                        /*
4011
 
                         * FIXME:  Window manager still may be using the old
4012
 
                         * values.  Try to fool it.
 
4065
                         * Window manager still may be using the old values. 
 
4066
                         * Try to fool it.
4013
4067
                         */
4014
4068
                        REQ_RESIZE((Widget) xw,
4015
4069
                                   screen->fullVwin.fullwidth,
4354
4408
            break;
4355
4409
#endif
4356
4410
        case SET_EXT_MODE_MOUSE:
4357
 
            set_bool_mode(screen->ext_mode_mouse);
 
4411
            /* FALLTHRU */
 
4412
        case SET_SGR_EXT_MODE_MOUSE:
 
4413
            /* FALLTHRU */
 
4414
        case SET_URXVT_EXT_MODE_MOUSE:
 
4415
            /*
 
4416
             * Rather than choose an arbitrary precedence among the coordinate
 
4417
             * modes, they are mutually exclusive.  For consistency, a reset is
 
4418
             * only effective against the matching mode.
 
4419
             */
 
4420
            if (IsSM()) {
 
4421
                screen->extend_coords = param[i];
 
4422
            } else if (screen->extend_coords == param[i]) {
 
4423
                screen->extend_coords = 0;
 
4424
            }
4358
4425
            break;
4359
4426
        case 1010:              /* rxvt */
4360
4427
            set_bool_mode(screen->scrollttyoutput);
4365
4432
            update_scrollkey();
4366
4433
            break;
4367
4434
        case 1034:
4368
 
            set_bool_mode(screen->input_eight_bits);
4369
 
            update_alt_esc();
 
4435
            if (screen->eight_bit_meta != ebNever) {
 
4436
                set_bool_mode(screen->eight_bit_meta);
 
4437
            }
4370
4438
            break;
4371
4439
#if OPT_NUM_LOCK
4372
4440
        case 1035:
4559
4627
            break;
4560
4628
#endif
4561
4629
        case SET_EXT_MODE_MOUSE:
4562
 
            DoSM(DP_X_EXT_MOUSE, screen->ext_mode_mouse);
 
4630
            /* FALLTHRU */
 
4631
        case SET_SGR_EXT_MODE_MOUSE:
 
4632
            /* FALLTHRU */
 
4633
        case SET_URXVT_EXT_MODE_MOUSE:
 
4634
            DoSM(DP_X_EXT_MOUSE, screen->extend_coords);
4563
4635
            break;
4564
4636
        case 1048:
4565
4637
            if (!xw->misc.titeInhibit) {
4730
4802
            break;
4731
4803
#endif
4732
4804
        case SET_EXT_MODE_MOUSE:
4733
 
            DoRM(DP_X_EXT_MOUSE, screen->ext_mode_mouse);
 
4805
            /* FALLTHRU */
 
4806
        case SET_SGR_EXT_MODE_MOUSE:
 
4807
            /* FALLTHRU */
 
4808
        case SET_URXVT_EXT_MODE_MOUSE:
 
4809
            DoRM(DP_X_EXT_MOUSE, screen->extend_coords);
4734
4810
            break;
4735
4811
        case 1048:
4736
4812
            if (!xw->misc.titeInhibit) {
4929
5005
 
4930
5006
    case ewSetWinSizePixels:    /* Resize the window to given size in pixels */
4931
5007
        if (AllowWindowOps(xw, ewSetWinSizePixels)) {
4932
 
            RequestResize(xw, minus_if_default(1), minus_if_default(2), False);
 
5008
            RequestResize(xw, param[1], param[2], False);
4933
5009
        }
4934
5010
        break;
4935
5011
 
4956
5032
 
4957
5033
    case ewSetWinSizeChars:     /* Resize the text-area, in characters */
4958
5034
        if (AllowWindowOps(xw, ewSetWinSizeChars)) {
4959
 
            RequestResize(xw, minus_if_default(1), minus_if_default(2), True);
 
5035
            RequestResize(xw, param[1], param[2], True);
4960
5036
        }
4961
5037
        break;
4962
5038
 
5435
5511
    }
5436
5512
#endif
5437
5513
    screen->is_running = True;
 
5514
    if (screen->embed_high && screen->embed_wide) {
 
5515
        ScreenResize(xw, screen->embed_wide, screen->embed_high, &(xw->flags));
 
5516
    }
5438
5517
#if OPT_MAXIMIZE
5439
 
    if (resource.fullscreen == esTrue || resource.fullscreen == esAlways)
 
5518
    else if (resource.fullscreen == esTrue || resource.fullscreen == esAlways)
5440
5519
        FullScreen(term, True);
5441
5520
#endif
5442
5521
    if (!setjmp(VTend))
5612
5691
#endif
5613
5692
 
5614
5693
    XSync(screen->display, False);      /* synchronize */
5615
 
    if (XtAppPending(app_con))
 
5694
    if (xtermAppPending())
5616
5695
        xevents();
5617
5696
 
5618
5697
    TRACE(("...RequestResize done\n"));
5836
5915
}
5837
5916
#endif
5838
5917
 
5839
 
static void
5840
 
ParseOnClicks(XtermWidget wnew, XtermWidget wreq, Cardinal item)
 
5918
void
 
5919
lookupSelectUnit(XtermWidget xw, Cardinal item, String value)
5841
5920
{
5842
5921
    /* *INDENT-OFF* */
5843
5922
    static struct {
5856
5935
    };
5857
5936
    /* *INDENT-ON* */
5858
5937
 
5859
 
    String res = TScreenOf(wreq)->onClick[item];
5860
 
    String next = x_skip_nonblanks(res);
 
5938
    TScreen *screen = TScreenOf(xw);
 
5939
    String next = x_skip_nonblanks(value);
5861
5940
    Cardinal n;
5862
5941
 
5863
 
    TScreenOf(wnew)->selectMap[item] = NSELECTUNITS;
 
5942
    screen->selectMap[item] = NSELECTUNITS;
5864
5943
    for (n = 0; n < XtNumber(table); ++n) {
5865
 
        if (!x_strncasecmp(table[n].name, res, (unsigned) (next - res))) {
5866
 
            TScreenOf(wnew)->selectMap[item] = table[n].code;
 
5944
        if (!x_strncasecmp(table[n].name, value, (unsigned) (next - value))) {
 
5945
            screen->selectMap[item] = table[n].code;
5867
5946
#if OPT_SELECT_REGEX
5868
5947
            if (table[n].code == Select_REGEX) {
5869
 
                TScreenOf(wnew)->selectExpr[item] = x_strtrim(next);
5870
 
                TRACE(("Parsed regex \"%s\"\n", TScreenOf(wnew)->selectExpr[item]));
 
5948
                screen->selectExpr[item] = x_strtrim(next);
 
5949
                TRACE(("Parsed regex \"%s\"\n", screen->selectExpr[item]));
5871
5950
            }
5872
5951
#endif
5873
5952
            break;
5875
5954
    }
5876
5955
}
5877
5956
 
 
5957
static void
 
5958
ParseOnClicks(XtermWidget wnew, XtermWidget wreq, Cardinal item)
 
5959
{
 
5960
    lookupSelectUnit(wnew, item, TScreenOf(wreq)->onClick[item]);
 
5961
}
 
5962
 
5878
5963
/*
5879
5964
 * Parse a comma-separated list, returning a string which the caller must
5880
5965
 * free, and updating the source pointer.
5930
6015
 
5931
6016
            value = (int) strtol(next, &temp, 0);
5932
6017
            if (!IsEmpty(temp)) {
5933
 
                fprintf(stderr, "Expected a number: %s\n", next);
 
6018
                xtermWarning("Expected a number: %s\n", next);
5934
6019
            } else {
5935
6020
                for (n = 0; n < limit; ++n) {
5936
6021
                    if (list[n].code == value) {
5951
6036
            }
5952
6037
        }
5953
6038
        if (!found) {
5954
 
            fprintf(stderr, "Unrecognized keyword: %s\n", next);
 
6039
            xtermWarning("Unrecognized keyword: %s\n", next);
5955
6040
        } else {
5956
6041
            TRACE(("...found %s (%d)\n", next, value));
5957
6042
        }
6049
6134
#undef DATA
6050
6135
#endif
6051
6136
 
 
6137
#define DATA(name) { #name, eb##name }
 
6138
    static FlagList tbl8BitMeta[] =
 
6139
    {
 
6140
        DATA(Never)
 
6141
        ,DATA(Locale)
 
6142
    };
 
6143
#undef DATA
 
6144
 
6052
6145
    XtermWidget request = (XtermWidget) wrequest;
6053
6146
    XtermWidget wnew = (XtermWidget) new_arg;
6054
6147
    Widget my_parent = SHELL_OF(wnew);
6183
6276
    init_Bres(screen.scrollttyoutput);
6184
6277
    init_Bres(screen.scrollkey);
6185
6278
 
 
6279
    init_Dres(screen.scale_height);
 
6280
    if (TScreenOf(wnew)->scale_height < 0.9)
 
6281
        TScreenOf(wnew)->scale_height = (float) 0.9;
 
6282
    if (TScreenOf(wnew)->scale_height > 1.5)
 
6283
        TScreenOf(wnew)->scale_height = (float) 1.5;
 
6284
 
6186
6285
    init_Bres(misc.autoWrap);
6187
6286
    init_Bres(misc.login_shell);
6188
6287
    init_Bres(misc.reverseWrap);
6208
6307
 
6209
6308
    init_Ires(screen.title_modes);
6210
6309
    init_Bres(screen.visualbell);
 
6310
    init_Bres(screen.flash_line);
6211
6311
    init_Ires(screen.visualBellDelay);
6212
6312
    init_Bres(screen.poponbell);
6213
6313
    init_Ires(misc.limit_resize);
6686
6786
    xtermSaveVTFonts(wnew);
6687
6787
#endif /* OPT_WIDE_CHARS */
6688
6788
 
 
6789
    init_Sres(screen.eight_bit_meta_s);
 
6790
    wnew->screen.eight_bit_meta =
 
6791
        extendedBoolean(request->screen.eight_bit_meta_s, tbl8BitMeta, uLast);
 
6792
    if (wnew->screen.eight_bit_meta == ebLocale) {
 
6793
#if OPT_WIDE_CHARS
 
6794
        if (xtermEnvUTF8()) {
 
6795
            wnew->screen.eight_bit_meta = ebFalse;
 
6796
            TRACE(("...eightBitMeta is false due to locale\n"));
 
6797
        } else
 
6798
#endif /* OPT_WIDE_CHARS */
 
6799
        {
 
6800
            wnew->screen.eight_bit_meta = ebTrue;
 
6801
            TRACE(("...eightBitMeta is true due to locale\n"));
 
6802
        }
 
6803
    }
 
6804
 
6689
6805
    init_Bres(screen.always_bold_mode);
6690
6806
    init_Bres(screen.bold_mode);
6691
6807
    init_Bres(screen.underline);
6830
6946
            name = 0; \
6831
6947
        }
6832
6948
 
6833
 
#if OPT_INPUT_METHOD
 
6949
#if OPT_I18N_SUPPORT && OPT_INPUT_METHOD
6834
6950
static void
6835
 
cleanupInputMethod(TScreen * screen)
 
6951
cleanupInputMethod(XtermWidget xw)
6836
6952
{
6837
 
    if (screen->xim) {
6838
 
        XCloseIM(screen->xim);
6839
 
        screen->xim = 0;
 
6953
    TInput *input = lookupTInput(xw, (Widget) xw);
 
6954
 
 
6955
    if (input->xim) {
 
6956
        XCloseIM(input->xim);
 
6957
        input->xim = 0;
6840
6958
        TRACE(("freed screen->xim\n"));
6841
6959
    }
6842
6960
}
6868
6986
        free(last->windowName);
6869
6987
        free(last);
6870
6988
    }
 
6989
#if OPT_ISO_COLORS
 
6990
    TRACE_FREE_LEAK(screen->cmap_data);
 
6991
    for (n = 0; n < MAXCOLORS; n++) {
 
6992
        TRACE_FREE_LEAK(screen->Acolors[n].resource);
 
6993
    }
 
6994
#endif
6871
6995
    TRACE_FREE_LEAK(screen->save_ptr);
6872
6996
    TRACE_FREE_LEAK(screen->saveBuf_data);
6873
6997
    TRACE_FREE_LEAK(screen->saveBuf_index);
6883
7007
    TRACE_FREE_LEAK(xw->misc.localefilter);
6884
7008
#endif
6885
7009
#endif
 
7010
    TRACE_FREE_LEAK(xw->misc.T_geometry);
 
7011
    TRACE_FREE_LEAK(xw->misc.geo_metry);
 
7012
    TRACE_FREE_LEAK(xw->screen.term_id);
6886
7013
#if OPT_INPUT_METHOD
6887
 
    cleanupInputMethod(screen);
 
7014
    cleanupInputMethod(xw);
6888
7015
#endif
6889
7016
    releaseCursorGCs(xw);
6890
7017
    releaseWindowGCs(xw, &(screen->fullVwin));
6903
7030
    xtermCloseFonts(xw, screen->fnts);
6904
7031
    noleaks_cachedCgs(xw);
6905
7032
 
 
7033
    TRACE_FREE_LEAK(screen->selection_targets_8bit);
 
7034
#if OPT_SELECT_REGEX
 
7035
    for (n = 0; n < NSELECTUNITS; ++n) {
 
7036
        if (screen->selectMap[n] == Select_REGEX) {
 
7037
            TRACE_FREE_LEAK(screen->selectExpr[n]);
 
7038
        }
 
7039
    }
 
7040
#endif
 
7041
 
6906
7042
#if OPT_RENDERFONT
6907
7043
    for (n = 0; n < NMENUFONTS; ++n) {
6908
7044
        xtermCloseXft(screen, &(screen->renderFontNorm[n]));
6923
7059
    TRACE_FREE_LEAK(screen->term_id);
6924
7060
    TRACE_FREE_LEAK(screen->charClass);
6925
7061
    TRACE_FREE_LEAK(screen->answer_back);
6926
 
    TRACE_FREE_LEAK(screen->printer_command);
 
7062
    TRACE_FREE_LEAK(screen->printer_state.printer_command);
6927
7063
    TRACE_FREE_LEAK(screen->keyboard_dialect);
6928
7064
    TRACE_FREE_LEAK(screen->disallowedColorOps);
6929
7065
    TRACE_FREE_LEAK(screen->disallowedFontOps);
6947
7083
#if OPT_RENDERFONT
6948
7084
    TRACE_FREE_LEAK(xw->misc.face_name);
6949
7085
    TRACE_FREE_LEAK(xw->misc.face_wide_name);
 
7086
    TRACE_FREE_LEAK(xw->misc.render_font_s);
6950
7087
#endif
6951
7088
 
6952
7089
#if OPT_SELECT_REGEX
7015
7152
                       screen->menu_font_number)) {
7016
7153
        if (XmuCompareISOLatin1(myfont->f_n, DEFFONT) != 0) {
7017
7154
            char *use_font = x_strdup(DEFFONT);
7018
 
            fprintf(stderr,
7019
 
                    "%s:  unable to open font \"%s\", trying \"%s\"....\n",
7020
 
                    ProgramName, myfont->f_n, use_font);
 
7155
            xtermWarning("unable to open font \"%s\", trying \"%s\"....\n",
 
7156
                         myfont->f_n, use_font);
7021
7157
            (void) xtermLoadFont(xw,
7022
7158
                                 xtermFontName(use_font),
7023
7159
                                 False,
7028
7164
 
7029
7165
    /* really screwed if we couldn't open default font */
7030
7166
    if (!screen->fnts[fNorm].fs) {
7031
 
        fprintf(stderr, "%s:  unable to locate a suitable font\n",
7032
 
                ProgramName);
 
7167
        xtermWarning("unable to locate a suitable font\n");
7033
7168
        Exit(1);
7034
7169
    }
7035
7170
#if OPT_WIDE_CHARS
7282
7417
 
7283
7418
#if OPT_I18N_SUPPORT && OPT_INPUT_METHOD
7284
7419
    VTInitI18N(xw);
7285
 
#else
7286
 
    screen->xic = NULL;
7287
7420
#endif
7288
7421
#if OPT_NUM_LOCK
7289
7422
    VTInitModifiers(xw);
7356
7489
                   XPointer client_data GCC_UNUSED,
7357
7490
                   XPointer call_data GCC_UNUSED)
7358
7491
{
7359
 
    if (display != XtDisplay(term))
7360
 
        return;
 
7492
    TRACE(("xim_instantiate_cb client=%p, call=%p\n", client_data, call_data));
7361
7493
 
7362
 
    VTInitI18N(term);
 
7494
    if (display == XtDisplay(term)) {
 
7495
        VTInitI18N(term);
 
7496
    }
7363
7497
}
7364
7498
 
7365
7499
static void
7367
7501
               XPointer client_data GCC_UNUSED,
7368
7502
               XPointer call_data GCC_UNUSED)
7369
7503
{
7370
 
    TScreenOf(term)->xic = NULL;
7371
 
 
7372
 
    XRegisterIMInstantiateCallback(XtDisplay(term), NULL, NULL, NULL,
 
7504
    XtermWidget xw = term;
 
7505
    TInput *input = lookupTInput(xw, (Widget) xw);
 
7506
 
 
7507
    TRACE(("xim_destroy_cb im=%lx, client=%p, call=%p\n",
 
7508
           (long) im, client_data, call_data));
 
7509
 
 
7510
    input->xic = NULL;
 
7511
    XRegisterIMInstantiateCallback(XtDisplay(xw), NULL, NULL, NULL,
7373
7512
                                   xim_instantiate_cb, NULL);
7374
7513
}
7375
7514
#endif /* X11R6+ */
7376
7515
 
 
7516
static Boolean
 
7517
xim_create_fs(XtermWidget xw)
 
7518
{
 
7519
    XFontStruct **fonts;
 
7520
    char **font_name_list;
 
7521
    char **missing_charset_list;
 
7522
    char *def_string;
 
7523
    int missing_charset_count;
 
7524
    unsigned i, j;
 
7525
 
 
7526
    if (xw->misc.xim_fs == 0) {
 
7527
        xw->misc.xim_fs = XCreateFontSet(XtDisplay(xw),
 
7528
                                         xw->misc.f_x,
 
7529
                                         &missing_charset_list,
 
7530
                                         &missing_charset_count,
 
7531
                                         &def_string);
 
7532
        if (xw->misc.xim_fs == NULL) {
 
7533
            xtermWarning("Preparation of font set "
 
7534
                         "\"%s\" for XIM failed.\n", xw->misc.f_x);
 
7535
            xw->misc.xim_fs = XCreateFontSet(XtDisplay(xw),
 
7536
                                             DEFXIMFONT,
 
7537
                                             &missing_charset_list,
 
7538
                                             &missing_charset_count,
 
7539
                                             &def_string);
 
7540
        }
 
7541
    }
 
7542
    if (xw->misc.xim_fs == NULL) {
 
7543
        xtermWarning("Preparation of default font set "
 
7544
                     "\"%s\" for XIM failed.\n", DEFXIMFONT);
 
7545
        cleanupInputMethod(xw);
 
7546
        xw->misc.cannot_im = True;
 
7547
    } else {
 
7548
        (void) XExtentsOfFontSet(xw->misc.xim_fs);
 
7549
        j = (unsigned) XFontsOfFontSet(xw->misc.xim_fs, &fonts, &font_name_list);
 
7550
        for (i = 0, xw->misc.xim_fs_ascent = 0; i < j; i++) {
 
7551
            if (xw->misc.xim_fs_ascent < (*fonts)->ascent)
 
7552
                xw->misc.xim_fs_ascent = (*fonts)->ascent;
 
7553
        }
 
7554
    }
 
7555
    return (Boolean) ! (xw->misc.cannot_im);
 
7556
}
 
7557
 
7377
7558
static void
7378
 
xim_real_init(XtermWidget xw)
 
7559
xim_create_xic(XtermWidget xw, Widget theInput)
7379
7560
{
7380
 
    TScreen *screen = TScreenOf(xw);
 
7561
    Display *myDisplay = XtDisplay(theInput);
 
7562
    Window myWindow = XtWindow(theInput);
7381
7563
    unsigned i, j;
7382
 
    char *p, *s, *t, *ns, *end, buf[32];
 
7564
    char *p = NULL, *s, *t, *ns, *end, buf[32];
7383
7565
    XIMStyles *xim_styles;
7384
7566
    XIMStyle input_style = 0;
7385
7567
    Bool found;
7397
7579
            "Root", (XIMPreeditNothing | XIMStatusNothing)
7398
7580
        },
7399
7581
    };
7400
 
 
7401
 
    screen->xic = NULL;
 
7582
    TInput *input = lookupTInput(xw, theInput);
7402
7583
 
7403
7584
    if (xw->misc.cannot_im) {
7404
7585
        return;
7405
7586
    }
7406
7587
 
7407
 
    if (!xw->misc.input_method || !*xw->misc.input_method) {
7408
 
        if ((p = XSetLocaleModifiers("")) != NULL && *p)
7409
 
            screen->xim = XOpenIM(XtDisplay(xw), NULL, NULL, NULL);
 
7588
    if (input == 0) {
 
7589
        for (i = 0; i < NINPUTWIDGETS; ++i) {
 
7590
            if (xw->misc.inputs[i].w == 0) {
 
7591
                input = xw->misc.inputs + i;
 
7592
                input->w = theInput;
 
7593
                break;
 
7594
            }
 
7595
        }
 
7596
    }
 
7597
 
 
7598
    if (input == 0) {
 
7599
        xtermWarning("attempted to add too many input widgets\n");
 
7600
        return;
 
7601
    }
 
7602
 
 
7603
    TRACE(("xim_real_init\n"));
 
7604
 
 
7605
    if (IsEmpty(xw->misc.input_method)) {
 
7606
        if ((p = XSetLocaleModifiers("")) != NULL && *p) {
 
7607
            input->xim = XOpenIM(myDisplay, NULL, NULL, NULL);
 
7608
        }
7410
7609
    } else {
7411
7610
        s = xw->misc.input_method;
7412
7611
        i = 5 + (unsigned) strlen(s);
7431
7630
                    strncat(t, s, (size_t) (end - s));
7432
7631
 
7433
7632
                    if ((p = XSetLocaleModifiers(t)) != 0 && *p
7434
 
                        && (screen->xim = XOpenIM(XtDisplay(xw),
7435
 
                                                  NULL,
7436
 
                                                  NULL,
7437
 
                                                  NULL)) != 0)
 
7633
                        && (input->xim = XOpenIM(myDisplay,
 
7634
                                                 NULL,
 
7635
                                                 NULL,
 
7636
                                                 NULL)) != 0) {
7438
7637
                        break;
 
7638
                    }
7439
7639
 
7440
7640
                }
7441
7641
                s = ns + 1;
7444
7644
        }
7445
7645
    }
7446
7646
 
7447
 
    if (screen->xim == NULL
 
7647
    if (input->xim == NULL
7448
7648
        && (p = XSetLocaleModifiers("@im=none")) != NULL
7449
7649
        && *p) {
7450
 
        screen->xim = XOpenIM(XtDisplay(xw), NULL, NULL, NULL);
 
7650
        input->xim = XOpenIM(myDisplay, NULL, NULL, NULL);
7451
7651
    }
7452
7652
 
7453
 
    if (!screen->xim) {
7454
 
        fprintf(stderr, "Failed to open input method\n");
 
7653
    if (!input->xim) {
 
7654
        xtermWarning("Failed to open input method\n");
7455
7655
        return;
7456
7656
    }
7457
 
    TRACE(("VTInitI18N opened input method\n"));
 
7657
    TRACE(("VTInitI18N opened input method:%s\n", NonNull(p)));
7458
7658
 
7459
 
    if (XGetIMValues(screen->xim, XNQueryInputStyle, &xim_styles, NULL)
 
7659
    if (XGetIMValues(input->xim, XNQueryInputStyle, &xim_styles, (void *) 0)
7460
7660
        || !xim_styles
7461
7661
        || !xim_styles->count_styles) {
7462
 
        fprintf(stderr, "input method doesn't support any style\n");
7463
 
        cleanupInputMethod(screen);
 
7662
        xtermWarning("input method doesn't support any style\n");
 
7663
        cleanupInputMethod(xw);
7464
7664
        xw->misc.cannot_im = True;
7465
7665
        return;
7466
7666
    }
7501
7701
    XFree(xim_styles);
7502
7702
 
7503
7703
    if (!found) {
7504
 
        fprintf(stderr,
7505
 
                "input method doesn't support my preedit type (%s)\n",
7506
 
                xw->misc.preedit_type);
7507
 
        cleanupInputMethod(screen);
 
7704
        xtermWarning("input method doesn't support my preedit type (%s)\n",
 
7705
                     xw->misc.preedit_type);
 
7706
        cleanupInputMethod(xw);
7508
7707
        xw->misc.cannot_im = True;
7509
7708
        return;
7510
7709
    }
7514
7713
     */
7515
7714
    TRACE(("input_style %#lx\n", input_style));
7516
7715
    if (input_style == (XIMPreeditArea | XIMStatusArea)) {
7517
 
        fprintf(stderr,
7518
 
                "This program doesn't support the 'OffTheSpot' preedit type\n");
7519
 
        cleanupInputMethod(screen);
 
7716
        xtermWarning("This program doesn't support the 'OffTheSpot' preedit type\n");
 
7717
        cleanupInputMethod(xw);
7520
7718
        xw->misc.cannot_im = True;
7521
7719
        return;
7522
7720
    }
7529
7727
     * same font cannot be used for XIM preedit.
7530
7728
     */
7531
7729
    if (input_style != (XIMPreeditNothing | XIMStatusNothing)) {
7532
 
        char **missing_charset_list;
7533
 
        int missing_charset_count;
7534
 
        char *def_string;
7535
7730
        XVaNestedList p_list;
7536
7731
        XPoint spot =
7537
7732
        {0, 0};
7538
 
        XFontStruct **fonts;
7539
 
        char **font_name_list;
7540
7733
 
7541
 
        screen->fs = XCreateFontSet(XtDisplay(xw),
7542
 
                                    xw->misc.f_x,
7543
 
                                    &missing_charset_list,
7544
 
                                    &missing_charset_count,
7545
 
                                    &def_string);
7546
 
        if (screen->fs == NULL) {
7547
 
            fprintf(stderr, "Preparation of font set "
7548
 
                    "\"%s\" for XIM failed.\n", xw->misc.f_x);
7549
 
            screen->fs = XCreateFontSet(XtDisplay(xw),
7550
 
                                        DEFXIMFONT,
7551
 
                                        &missing_charset_list,
7552
 
                                        &missing_charset_count,
7553
 
                                        &def_string);
7554
 
        }
7555
 
        if (screen->fs == NULL) {
7556
 
            fprintf(stderr, "Preparation of default font set "
7557
 
                    "\"%s\" for XIM failed.\n", DEFXIMFONT);
7558
 
            cleanupInputMethod(screen);
7559
 
            xw->misc.cannot_im = True;
7560
 
            return;
7561
 
        }
7562
 
        (void) XExtentsOfFontSet(screen->fs);
7563
 
        j = (unsigned) XFontsOfFontSet(screen->fs, &fonts, &font_name_list);
7564
 
        for (i = 0, screen->fs_ascent = 0; i < j; i++) {
7565
 
            if (screen->fs_ascent < (*fonts)->ascent)
7566
 
                screen->fs_ascent = (*fonts)->ascent;
7567
 
        }
7568
 
        p_list = XVaCreateNestedList(0,
7569
 
                                     XNSpotLocation, &spot,
7570
 
                                     XNFontSet, screen->fs,
7571
 
                                     NULL);
7572
 
        screen->xic = XCreateIC(screen->xim,
7573
 
                                XNInputStyle, input_style,
7574
 
                                XNClientWindow, XtWindow(xw),
7575
 
                                XNFocusWindow, XtWindow(xw),
7576
 
                                XNPreeditAttributes, p_list,
7577
 
                                NULL);
 
7734
        if (xim_create_fs(xw)) {
 
7735
            p_list = XVaCreateNestedList(0,
 
7736
                                         XNSpotLocation, &spot,
 
7737
                                         XNFontSet, xw->misc.xim_fs,
 
7738
                                         (void *) 0);
 
7739
            input->xic = XCreateIC(input->xim,
 
7740
                                   XNInputStyle, input_style,
 
7741
                                   XNClientWindow, myWindow,
 
7742
                                   XNFocusWindow, myWindow,
 
7743
                                   XNPreeditAttributes, p_list,
 
7744
                                   (void *) 0);
 
7745
        }
7578
7746
    } else {
7579
 
        screen->xic = XCreateIC(screen->xim, XNInputStyle, input_style,
7580
 
                                XNClientWindow, XtWindow(xw),
7581
 
                                XNFocusWindow, XtWindow(xw),
7582
 
                                NULL);
 
7747
        input->xic = XCreateIC(input->xim, XNInputStyle, input_style,
 
7748
                               XNClientWindow, myWindow,
 
7749
                               XNFocusWindow, myWindow,
 
7750
                               (void *) 0);
7583
7751
    }
7584
7752
 
7585
 
    if (!screen->xic) {
7586
 
        fprintf(stderr, "Failed to create input context\n");
7587
 
        cleanupInputMethod(screen);
 
7753
    if (!input->xic) {
 
7754
        xtermWarning("Failed to create input context\n");
 
7755
        cleanupInputMethod(xw);
7588
7756
    }
7589
7757
#if defined(USE_XIM_INSTANTIATE_CB)
7590
7758
    else {
7592
7760
 
7593
7761
        destroy_cb.callback = xim_destroy_cb;
7594
7762
        destroy_cb.client_data = NULL;
7595
 
        if (XSetIMValues(screen->xim, XNDestroyCallback, &destroy_cb, NULL))
7596
 
            fprintf(stderr, "Could not set destroy callback to IM\n");
 
7763
        if (XSetIMValues(input->xim,
 
7764
                         XNDestroyCallback,
 
7765
                         &destroy_cb,
 
7766
                         (void *) 0)) {
 
7767
            xtermWarning("Could not set destroy callback to IM\n");
 
7768
        }
7597
7769
    }
7598
7770
#endif
7599
7771
 
7601
7773
}
7602
7774
 
7603
7775
static void
 
7776
xim_real_init(XtermWidget xw)
 
7777
{
 
7778
    xim_create_xic(xw, (Widget) xw);
 
7779
}
 
7780
 
 
7781
static void
7604
7782
VTInitI18N(XtermWidget xw)
7605
7783
{
7606
7784
    if (xw->misc.open_im) {
7607
7785
        xim_real_init(xw);
7608
7786
 
7609
7787
#if defined(USE_XIM_INSTANTIATE_CB)
7610
 
        if (TScreenOf(xw)->xic == NULL
 
7788
        if (lookupTInput(xw, (Widget) xw) == NULL
7611
7789
            && !xw->misc.cannot_im
7612
7790
            && xw->misc.retry_im-- > 0) {
7613
7791
            sleep(3);
7617
7795
#endif
7618
7796
    }
7619
7797
}
 
7798
 
 
7799
TInput *
 
7800
lookupTInput(XtermWidget xw, Widget w)
 
7801
{
 
7802
    TInput *result = 0;
 
7803
    unsigned n;
 
7804
 
 
7805
    for (n = 0; n < NINPUTWIDGETS; ++n) {
 
7806
        if (xw->misc.inputs[n].w == w) {
 
7807
            result = xw->misc.inputs + n;
 
7808
            break;
 
7809
        }
 
7810
    }
 
7811
 
 
7812
    return result;
 
7813
}
7620
7814
#endif /* OPT_I18N_SUPPORT && OPT_INPUT_METHOD */
7621
7815
 
7622
7816
static void
8371
8565
        /* reset the mouse mode */
8372
8566
        screen->send_mouse_pos = MOUSE_OFF;
8373
8567
        screen->send_focus_pos = OFF;
8374
 
        screen->ext_mode_mouse = OFF;
 
8568
        screen->extend_coords = 0;
8375
8569
        screen->waitingForTrackInfo = False;
8376
8570
        screen->eventMode = NORMAL;
8377
8571
 
8427
8621
                       &replyWidth, &replyHeight);
8428
8622
            repairSizeHints();
8429
8623
            XSync(screen->display, False);      /* synchronize */
8430
 
            if (XtAppPending(app_con))
 
8624
            if (xtermAppPending())
8431
8625
                xevents();
8432
8626
        }
8433
8627
 
8472
8666
static int
8473
8667
set_character_class(char *s)
8474
8668
{
 
8669
#define FMT "%s in range string \"%s\" (position %d)\n"
8475
8670
    int i;                      /* iterator, index into s */
8476
8671
    int len;                    /* length of s */
8477
8672
    int acc;                    /* accumulator */
8479
8674
    int base;                   /* 8, 10, 16 (octal, decimal, hex) */
8480
8675
    int numbers;                /* count of numbers per range */
8481
8676
    int digits;                 /* count of digits in a number */
8482
 
    static const char errfmt[] = "%s:  %s in range string \"%s\" (position %d)\n";
8483
8677
 
8484
8678
    if (!s || !s[0])
8485
8679
        return -1;
8501
8695
            low = acc;
8502
8696
            acc = 0;
8503
8697
            if (digits == 0) {
8504
 
                fprintf(stderr, errfmt, ProgramName, "missing number", s, i);
 
8698
                xtermWarning(FMT, "missing number", s, i);
8505
8699
                return (-1);
8506
8700
            }
8507
8701
            digits = 0;
8513
8707
            else if (numbers == 1)
8514
8708
                high = acc;
8515
8709
            else {
8516
 
                fprintf(stderr, errfmt, ProgramName, "too many numbers",
8517
 
                        s, i);
 
8710
                xtermWarning(FMT, "too many numbers", s, i);
8518
8711
                return (-1);
8519
8712
            }
8520
8713
            digits = 0;
8531
8724
                numbers++;
8532
8725
            }
8533
8726
            if (numbers != 2) {
8534
 
                fprintf(stderr, errfmt, ProgramName, "bad value number",
8535
 
                        s, i);
 
8727
                xtermWarning(FMT, "bad value number", s, i);
8536
8728
            } else if (SetCharacterClassRange(low, high, acc) != 0) {
8537
 
                fprintf(stderr, errfmt, ProgramName, "bad range", s, i);
 
8729
                xtermWarning(FMT, "bad range", s, i);
8538
8730
            }
8539
8731
 
8540
8732
            low = high = -1;
8543
8735
            numbers = 0;
8544
8736
            continue;
8545
8737
        } else {
8546
 
            fprintf(stderr, errfmt, ProgramName, "bad character", s, i);
 
8738
            xtermWarning(FMT, "bad character", s, i);
8547
8739
            return (-1);
8548
8740
        }                       /* end if else if ... else */
8549
8741
 
8559
8751
    if (high < 0)
8560
8752
        high = low;
8561
8753
    if (numbers < 1 || numbers > 2) {
8562
 
        fprintf(stderr, errfmt, ProgramName, "bad value number", s, i);
 
8754
        xtermWarning(FMT, "bad value number", s, i);
8563
8755
    } else if (SetCharacterClassRange(low, high, acc) != 0) {
8564
 
        fprintf(stderr, errfmt, ProgramName, "bad range", s, i);
 
8756
        xtermWarning(FMT, "bad range", s, i);
8565
8757
    }
8566
8758
 
8567
8759
    return (0);
 
8760
#undef FMT
8568
8761
}
8569
8762
 
8570
8763
/* ARGSUSED */
8651
8844
{
8652
8845
    XtermWidget xw;
8653
8846
 
8654
 
    TRACE(("Handle ignore for %p\n", (void *) w));
 
8847
    TRACE(("Handle ignore for %p %s\n",
 
8848
           (void *) w, visibleEventType(event->type)));
8655
8849
    if ((xw = getXtermWidget(w)) != 0) {
8656
8850
        /* do nothing, but check for funny escape sequences */
8657
8851
        (void) SendMousePosition(xw, event);