~ubuntu-branches/ubuntu/precise/xterm/precise-updates

« back to all changes in this revision

Viewing changes to misc.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Hooker
  • Date: 2010-06-10 22:13:44 UTC
  • mfrom: (1.1.18 upstream) (11.1.19 sid)
  • Revision ID: james.westby@ubuntu.com-20100610221344-s4wbmxbevlklu7fv
Tags: 259-1ubuntu1
* Merge from debian unstable. Remaining Ubuntu changes:
  - Revert the libutempter change because it's in universe. (LP: #539473)
  - Enabled URL highlighting
  - Add 100_uxterm_utf8_title.patch: 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. (LP: #320388, #408496)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $XTermId: misc.c,v 1.483 2010/03/03 22:32:26 Chris.Adams Exp $ */
 
1
/* $XTermId: misc.c,v 1.499 2010/06/04 01:02:08 tom Exp $ */
2
2
 
3
3
/*
4
 
 *
5
4
 * Copyright 1999-2009,2010 by Thomas E. Dickey
6
5
 *
7
 
 *                        All Rights Reserved
 
6
 *                         All Rights Reserved
8
7
 *
9
8
 * Permission is hereby granted, free of charge, to any person obtaining a
10
9
 * copy of this software and associated documentation files (the
128
127
Readlink(const char *filename)
129
128
{
130
129
    char *buf = NULL;
131
 
    unsigned size = 100;
 
130
    size_t size = 100;
132
131
    int n;
133
132
 
134
133
    for (;;) {
135
134
        buf = TypeRealloc(char, size, buf);
136
135
        memset(buf, 0, size);
137
136
 
138
 
        n = readlink(filename, buf, size);
 
137
        n = (int) readlink(filename, buf, size);
139
138
        if (n < 0) {
140
139
            free(buf);
141
140
            return NULL;
184
183
        if (screen->cursor_state)
185
184
            ShowCursor();
186
185
    }
 
186
    GetScrollLock(screen);
187
187
}
188
188
 
189
189
static void
373
373
    /*
374
374
     * process timeouts, relying on the fact that XtAppProcessEvent
375
375
     * will process the timeout and return without blockng on the
376
 
     * XEvent queue.  Other sources i.e. the pty are handled elsewhere
 
376
     * XEvent queue.  Other sources i.e., the pty are handled elsewhere
377
377
     * with select().
378
378
     */
379
 
    while ((input_mask = XtAppPending(app_con)) & XtIMTimer)
380
 
        XtAppProcessEvent(app_con, XtIMTimer);
 
379
    while ((input_mask = XtAppPending(app_con)) != 0) {
 
380
        if (input_mask & XtIMTimer)
 
381
            XtAppProcessEvent(app_con, (XtInputMask) XtIMTimer);
381
382
#if OPT_SESSION_MGT
382
 
    /*
383
 
     * Session management events are alternative input events. Deal with
384
 
     * them in the same way.
385
 
     */
386
 
    while ((input_mask = XtAppPending(app_con)) & XtIMAlternateInput)
387
 
        XtAppProcessEvent(app_con, XtIMAlternateInput);
 
383
        /*
 
384
         * Session management events are alternative input events. Deal with
 
385
         * them in the same way.
 
386
         */
 
387
        else if (input_mask & XtIMAlternateInput)
 
388
            XtAppProcessEvent(app_con, (XtInputMask) XtIMAlternateInput);
388
389
#endif
 
390
        else
 
391
            break;
 
392
    }
389
393
 
390
394
    /*
391
395
     * If there's no XEvents, don't wait around...
445
449
                case Expose:
446
450
                case NoExpose:
447
451
                case PropertyNotify:
 
452
                case ClientMessage:
448
453
                    break;
449
454
                default:
450
455
                    xtermShowPointer(xw, True);
454
459
 
455
460
            XtDispatchEvent(&event);
456
461
        }
457
 
    } while ((input_mask = XtAppPending(app_con)) & XtIMXEvent);
 
462
    } while (XtAppPending(app_con) & XtIMXEvent);
458
463
}
459
464
 
460
465
static Cursor
592
597
     */
593
598
    child_exe = Readlink(PROCFS_ROOT "/self/exe");
594
599
    if (!child_exe) {
595
 
        if (strncmp(ProgramName, "./", 2)
596
 
            && strncmp(ProgramName, "../", 3)) {
 
600
        if (strncmp(ProgramName, "./", (size_t) 2)
 
601
            && strncmp(ProgramName, "../", (size_t) 3)) {
597
602
            child_exe = xtermFindShell(ProgramName, True);
598
603
        } else {
599
604
            fprintf(stderr, "Cannot exec-xterm given %s\n", ProgramName);
677
682
    if (*param_count == 1) {
678
683
        char *value = params[0];
679
684
        int need = (int) strlen(value);
680
 
        int used = VTbuffer->next - VTbuffer->buffer;
681
 
        int have = VTbuffer->last - VTbuffer->buffer;
 
685
        int used = (int) (VTbuffer->next - VTbuffer->buffer);
 
686
        int have = (int) (VTbuffer->last - VTbuffer->buffer);
682
687
 
683
688
        if (have - used + need < BUF_SIZE) {
684
689
 
1074
1079
    char *expansion;
1075
1080
    Char *copybuffer;
1076
1081
    size_t hint_len;
1077
 
    unsigned del_cnt;
1078
 
    unsigned buf_cnt;
 
1082
    size_t del_cnt;
 
1083
    size_t buf_cnt;
1079
1084
    int result = 0;
1080
1085
    LineData *ld;
1081
1086
 
1099
1104
                    screen->dabbrev_working = True;
1100
1105
                    /* we are in the middle of dabbrev process */
1101
1106
                }
 
1107
            } else {
 
1108
                return result;
1102
1109
            }
 
1110
        } else {
 
1111
            return result;
1103
1112
        }
1104
1113
        if (!screen->dabbrev_working) {
1105
1114
            if (lastexpansion != 0) {
1108
1117
            }
1109
1118
            return result;
1110
1119
        }
1111
 
    } else {
1112
1120
    }
1113
1121
 
 
1122
    if (dabbrev_hint == 0)
 
1123
        return result;
 
1124
 
1114
1125
    hint_len = strlen(dabbrev_hint);
1115
1126
    for (;;) {
1116
1127
        if ((expansion = dabbrev_prev_word(screen, &cell, &ld)) == 0) {
1138
1149
            memmove(copybuffer + del_cnt,
1139
1150
                    expansion + hint_len,
1140
1151
                    strlen(expansion) - hint_len);
1141
 
            v_write(pty, copybuffer, buf_cnt);
 
1152
            v_write(pty, copybuffer, (unsigned) buf_cnt);
1142
1153
            /* v_write() just reset our flag */
1143
1154
            screen->dabbrev_working = True;
1144
1155
            free(copybuffer);
1760
1771
#endif /* VMS */
1761
1772
        cp = VTbuffer->next;
1762
1773
        if (screen->logstart != 0
1763
 
            && (i = cp - screen->logstart) > 0) {
1764
 
            IGNORE_RC(write(screen->logfd, screen->logstart, (unsigned) i));
 
1774
            && (i = (int) (cp - screen->logstart)) > 0) {
 
1775
            IGNORE_RC(write(screen->logfd, screen->logstart, (size_t) i));
1765
1776
        }
1766
1777
        screen->logstart = VTbuffer->next;
1767
1778
    }
1941
1952
            result = 1;
1942
1953
            SET_COLOR_RES(res, def.pixel);
1943
1954
            TRACE(("AllocateAnsiColor[%d] %s (pixel %#lx)\n",
1944
 
                   (res - screen->Acolors), spec, def.pixel));
 
1955
                   (int) (res - screen->Acolors), spec, def.pixel));
1945
1956
#if OPT_COLOR_RES
1946
1957
            if (!res->mode)
1947
1958
                result = 0;
1965
1976
        result = res->value;
1966
1977
    } else {
1967
1978
        TRACE(("xtermGetColorRes for Acolors[%d]\n",
1968
 
               res - TScreenOf(xw)->Acolors));
 
1979
               (int) (res - TScreenOf(xw)->Acolors)));
1969
1980
 
1970
1981
        if (res >= TScreenOf(xw)->Acolors) {
1971
1982
            assert(res - TScreenOf(xw)->Acolors < MAXCOLORS);
2093
2104
        while (!IsEmpty(buf)) {
2094
2105
            char *next;
2095
2106
 
2096
 
            color = strtol(buf, &next, 10);
2097
 
            if (next == buf)
 
2107
            color = (int) strtol(buf, &next, 10);
 
2108
            if ((next == buf) || (color < 0))
2098
2109
                break;          /* no number at all */
2099
2110
            if (next != 0) {
2100
2111
                if (strchr(";", *next) == 0)
2190
2201
                screen->base64_final = final;
2191
2202
 
2192
2203
                /* terminator will be written in this call */
2193
 
                xtermGetSelection((Widget) xw, 0, select_args, n, NULL);
 
2204
                xtermGetSelection((Widget) xw, (Time) 0, select_args, n, NULL);
2194
2205
            }
2195
2206
        } else {
2196
2207
            if (AllowWindowOps(xw, ewSetSelection)) {
2292
2303
{
2293
2304
    int i;
2294
2305
    if (pOldColors == NULL) {
2295
 
        pOldColors = (ScrnColors *) XtMalloc(sizeof(ScrnColors));
 
2306
        pOldColors = (ScrnColors *) XtMalloc((Cardinal) sizeof(ScrnColors));
2296
2307
        if (pOldColors == NULL) {
2297
2308
            fprintf(stderr, "allocation failure in GetOldColors\n");
2298
2309
            return (False);
2475
2486
                } else if (!pOldColors->names[ndx]
2476
2487
                           || (thisName
2477
2488
                               && strcmp(thisName, pOldColors->names[ndx]))) {
2478
 
                    AllocateTermColor(xw, &newColors, ndx, thisName);
 
2489
                    AllocateTermColor(xw, &newColors, ndx, thisName, False);
2479
2490
                }
2480
2491
            }
2481
2492
        }
2514
2525
        if (thisName != 0
2515
2526
            && pOldColors->names[ndx] != 0
2516
2527
            && strcmp(thisName, pOldColors->names[ndx])) {
2517
 
            AllocateTermColor(xw, &newColors, ndx, thisName);
 
2528
            AllocateTermColor(xw, &newColors, ndx, thisName, False);
2518
2529
 
2519
2530
            if (newColors.which != 0) {
2520
2531
                ChangeColors(xw, &newColors);
2698
2709
/***====================================================================***/
2699
2710
 
2700
2711
void
2701
 
do_osc(XtermWidget xw, Char * oscbuf, unsigned len GCC_UNUSED, int final)
 
2712
do_osc(XtermWidget xw, Char * oscbuf, size_t len, int final)
2702
2713
{
2703
2714
    TScreen *screen = TScreenOf(xw);
2704
2715
    int mode;
2735
2746
            /* FALLTHRU */
2736
2747
        case 1:
2737
2748
            if (*cp != ';') {
2738
 
                TRACE(("do_osc did not find semicolon offset %d\n", cp - oscbuf));
 
2749
                TRACE(("do_osc did not find semicolon offset %d\n",
 
2750
                       (int) (cp - oscbuf)));
2739
2751
                return;
2740
2752
            }
2741
2753
            state = 2;
2754
2766
                default:
2755
2767
                    TRACE(("do_osc found nonprinting char %02X offset %d\n",
2756
2768
                           CharOf(*cp),
2757
 
                           cp - oscbuf));
 
2769
                           (int) (cp - oscbuf)));
2758
2770
                    return;
2759
2771
                }
2760
2772
            }
3173
3185
    Bool okay;
3174
3186
    ANSI params;
3175
3187
 
3176
 
    TRACE(("do_dcs(%s:%d)\n", (char *) dcsbuf, dcslen));
 
3188
    TRACE(("do_dcs(%s:%lu)\n", (char *) dcsbuf, (unsigned long) dcslen));
3177
3189
 
3178
3190
    if (dcslen != strlen(cp))
3179
3191
        /* shouldn't have nulls in the string */
3392
3404
 
3393
3405
    char *my_attr;
3394
3406
    char *name;
3395
 
    unsigned limit;
 
3407
    size_t limit;
3396
3408
    Char *c1;
3397
3409
    Char *cp;
3398
3410
 
3473
3485
        /* If the attribute isn't going to change, then don't bother... */
3474
3486
 
3475
3487
        if (resource.sameName) {
3476
 
            char *buf;
 
3488
            char *buf = 0;
3477
3489
            XtSetArg(args[0], my_attr, &buf);
3478
3490
            XtGetValues(top, args, 1);
3479
3491
            TRACE(("...comparing{%s}\n", buf));
3480
 
            if (strcmp(name, buf) == 0)
 
3492
            if (buf != 0 && strcmp(name, buf) == 0)
3481
3493
                changed = False;
3482
3494
        }
3483
3495
#endif /* OPT_SAME_NAME */
3624
3636
AllocateTermColor(XtermWidget xw,
3625
3637
                  ScrnColors * pNew,
3626
3638
                  int ndx,
3627
 
                  const char *name)
 
3639
                  const char *name,
 
3640
                  Bool always)
3628
3641
{
3629
3642
    Bool result = False;
3630
3643
 
3631
 
    if (AllowColorOps(xw, ecSetColor)) {
 
3644
    if (always || AllowColorOps(xw, ecSetColor)) {
3632
3645
        XColor def;
3633
3646
        TScreen *screen = TScreenOf(xw);
3634
3647
        Colormap cmap = xw->core.colormap;
3707
3720
        { ERROR_INIT,           "spawn: can't initialize window" },
3708
3721
        { ERROR_TIOCKSET,       "spawn: ioctl() failed on TIOCKSET" },
3709
3722
        { ERROR_TIOCKSETC,      "spawn: ioctl() failed on TIOCKSETC" },
3710
 
        { ERROR_SPREALLOC,      "spawn: realloc of ttydev failed" },
3711
3723
        { ERROR_LUMALLOC,       "luit: command-line malloc failed" },
3712
3724
        { ERROR_SELECT,         "in_put: select() failed" },
3713
3725
        { ERROR_VINIT,          "VTInit: can't initialize window" },
3783
3795
        if (resource.sessionMgt) {
3784
3796
            XtVaSetValues(toplevel,
3785
3797
                          XtNjoinSession, False,
3786
 
                          (XtPointer *) 0);
 
3798
                          NULL);
3787
3799
        }
3788
3800
#endif
3789
3801
    }
4030
4042
    TRACE(("set_tek_visibility(%d)\n", on));
4031
4043
 
4032
4044
    if (on) {
4033
 
        if (!TEK4014_SHOWN(term) && (tekWidget || TekInit())) {
4034
 
            Widget tekParent = SHELL_OF(tekWidget);
4035
 
            XtRealizeWidget(tekParent);
4036
 
            XtMapWidget(XtParent(tekWidget));
 
4045
        if (!TEK4014_SHOWN(term)) {
 
4046
            if (tekWidget == 0) {
 
4047
                TekInit();      /* will exit on failure */
 
4048
            }
 
4049
            if (tekWidget != 0) {
 
4050
                Widget tekParent = SHELL_OF(tekWidget);
 
4051
                XtRealizeWidget(tekParent);
 
4052
                XtMapWidget(XtParent(tekWidget));
4037
4053
#if OPT_TOOLBAR
4038
 
            /* we need both of these during initialization */
4039
 
            XtMapWidget(tekParent);
4040
 
            XtMapWidget(tekWidget);
 
4054
                /* we need both of these during initialization */
 
4055
                XtMapWidget(tekParent);
 
4056
                XtMapWidget(tekWidget);
4041
4057
#endif
4042
 
            XtOverrideTranslations(tekParent,
4043
 
                                   XtParseTranslationTable
4044
 
                                   ("<Message>WM_PROTOCOLS: DeleteWindow()"));
4045
 
            (void) XSetWMProtocols(XtDisplay(tekParent),
4046
 
                                   XtWindow(tekParent),
4047
 
                                   &wm_delete_window, 1);
4048
 
            TEK4014_SHOWN(term) = True;
 
4058
                XtOverrideTranslations(tekParent,
 
4059
                                       XtParseTranslationTable
 
4060
                                       ("<Message>WM_PROTOCOLS: DeleteWindow()"));
 
4061
                (void) XSetWMProtocols(XtDisplay(tekParent),
 
4062
                                       XtWindow(tekParent),
 
4063
                                       &wm_delete_window, 1);
 
4064
                TEK4014_SHOWN(term) = True;
 
4065
            }
4049
4066
        }
4050
4067
    } else {
4051
4068
        if (TEK4014_SHOWN(term) && tekWidget) {
4154
4171
 
4155
4172
        /* make a sorted index to 'resources' */
4156
4173
        res_array = TypeCallocN(XrmOptionDescRec, res_count);
4157
 
        for (j = 0; j < res_count; j++)
4158
 
            res_array[j] = descs[j];
4159
 
        qsort(res_array, res_count, sizeof(*res_array), cmp_resources);
 
4174
        if (res_array != 0) {
 
4175
            for (j = 0; j < res_count; j++)
 
4176
                res_array[j] = descs[j];
 
4177
            qsort(res_array, (size_t) res_count, sizeof(*res_array), cmp_resources);
 
4178
        }
4160
4179
    }
4161
4180
    return res_array;
4162
4181
}
4184
4203
#endif
4185
4204
 
4186
4205
    if (opt_array == 0) {
4187
 
        Cardinal opt_count, j;
 
4206
        size_t opt_count, j;
4188
4207
#if OPT_TRACE
4189
4208
        Cardinal k;
4190
4209
        XrmOptionDescRec *res_array = sortedOptDescs(descs, numDescs);
4345
4364
        else {
4346
4365
            /* some vendors leave trash in this string */
4347
4366
            for (;;) {
4348
 
                if (!strncmp(vendor, "Version ", 8))
 
4367
                if (!strncmp(vendor, "Version ", (size_t) 8))
4349
4368
                    vendor += 8;
4350
4369
                else if (isspace(CharOf(*vendor)))
4351
4370
                    ++vendor;