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

« back to all changes in this revision

Viewing changes to ptydata.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: ptydata.c,v 1.91 2009/11/28 14:13:48 tom Exp $ */
 
1
/* $XTermId: ptydata.c,v 1.94 2010/01/21 02:08:28 tom 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
 
331
331
}
332
332
 
333
333
/*
334
 
 * Initialize a buffer for the caller, using its data in 'source'.
 
334
 * Initialize a buffer for the caller, using its data in 'next'.
335
335
 */
336
336
#if OPT_WIDE_CHARS
337
337
PtyData *
400
400
Char *
401
401
convertToUTF8(Char * lp, unsigned c)
402
402
{
403
 
    if (c < 0x80) {             /*  0*******  */
404
 
        *lp++ = (Char) (c);
405
 
    } else if (c < 0x800) {     /*  110***** 10******  */
406
 
        *lp++ = (Char) (0xc0 | (c >> 6));
407
 
        *lp++ = (Char) (0x80 | (c & 0x3f));
408
 
    } else {                    /*  1110**** 10****** 10******  */
409
 
        *lp++ = (Char) (0xe0 | (c >> 12));
410
 
        *lp++ = (Char) (0x80 | ((c >> 6) & 0x3f));
411
 
        *lp++ = (Char) (0x80 | (c & 0x3f));
 
403
#define CH(n) (Char)((c) >> ((n) * 8))
 
404
    if (c < 0x80) {
 
405
        /*  0*******  */
 
406
        *lp++ = (Char) CH(0);
 
407
    } else if (c < 0x800) {
 
408
        /*  110***** 10******  */
 
409
        *lp++ = (Char) (0xc0 | (CH(0) >> 6) | ((CH(1) & 0x07) << 2));
 
410
        *lp++ = (Char) (0x80 | (CH(0) & 0x3f));
 
411
    } else if (c < 0x00010000) {
 
412
        /*  1110**** 10****** 10******  */
 
413
        *lp++ = (Char) (0xe0 | ((int) (CH(1) & 0xf0) >> 4));
 
414
        *lp++ = (Char) (0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
 
415
        *lp++ = (Char) (0x80 | (CH(0) & 0x3f));
 
416
    } else if (c < 0x00200000) {
 
417
        *lp++ = (Char) (0xf0 | ((int) (CH(2) & 0x1f) >> 2));
 
418
        *lp++ = (Char) (0x80 |
 
419
                        ((int) (CH(1) & 0xf0) >> 4) |
 
420
                        ((int) (CH(2) & 0x03) << 4));
 
421
        *lp++ = (Char) (0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
 
422
        *lp++ = (Char) (0x80 | (CH(0) & 0x3f));
 
423
    } else if (c < 0x04000000) {
 
424
        *lp++ = (Char) (0xf8 | (CH(3) & 0x03));
 
425
        *lp++ = (Char) (0x80 | (CH(2) >> 2));
 
426
        *lp++ = (Char) (0x80 |
 
427
                        ((int) (CH(1) & 0xf0) >> 4) |
 
428
                        ((int) (CH(2) & 0x03) << 4));
 
429
        *lp++ = (Char) (0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
 
430
        *lp++ = (Char) (0x80 | (CH(0) & 0x3f));
 
431
    } else {
 
432
        *lp++ = (Char) (0xfc | ((int) (CH(3) & 0x40) >> 6));
 
433
        *lp++ = (Char) (0x80 | (CH(3) & 0x3f));
 
434
        *lp++ = (Char) (0x80 | (CH(2) >> 2));
 
435
        *lp++ = (Char) (0x80 | (CH(1) >> 4) | ((CH(2) & 0x03) << 4));
 
436
        *lp++ = (Char) (0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
 
437
        *lp++ = (Char) (0x80 | (CH(0) & 0x3f));
412
438
    }
413
 
    /*
414
 
     * UTF-8 is defined for words of up to 31 bits, but we need only 16
415
 
     * bits here, since that's all that X11R6 supports.
416
 
     */
417
439
    return lp;
 
440
#undef CH
418
441
}
419
442
 
420
443
/*
454
477
    }
455
478
}
456
479
#endif
 
480
 
 
481
#if 0
 
482
void
 
483
test_ptydata(void)
 
484
{
 
485
    PtyData *data;
 
486
    unsigned code;
 
487
 
 
488
    initPtyData(&data);
 
489
    TRACE(("test_ptydata\n"));
 
490
    for (code = 0; code <= 0x7fffffff; ++code) {
 
491
        int use_size;
 
492
 
 
493
        memset(data, 0, sizeof(*data));
 
494
        data->next = data->buffer;
 
495
        data->last = convertToUTF8(data->buffer, code);
 
496
 
 
497
        use_size = (data->last - data->next);
 
498
 
 
499
        if (decodeUtf8(data)) {
 
500
            if (code != data->utf_data) {
 
501
                TRACE(("code %#x ->%#x\n", code, data->utf_data));
 
502
            } else if (use_size != data->utf_size) {
 
503
                TRACE(("size %#x %d->%d\n", code, use_size, data->utf_size));
 
504
            }
 
505
        } else {
 
506
            TRACE(("fail %#x\n", code));
 
507
        }
 
508
    }
 
509
}
 
510
#endif