~ubuntu-branches/ubuntu/lucid/libx11/lucid

« back to all changes in this revision

Viewing changes to modules/lc/gen/lcGenConv.c

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2009-01-17 16:34:54 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20090117163454-gaey3cd32xyavueo
Tags: 2:1.1.99.2-1build1
Fakesync with Debian, all previous Ubuntu changes are included
in the new upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 *
33
33
 */
34
34
/*
35
 
 *  2000  
 
35
 *  2000
36
36
 *  Modifier: Ivan Pascal      The XFree86 Project
37
37
 */
38
38
/* $XFree86: xc/lib/X11/lcGenConv.c,v 3.27tsi Exp $ */
201
201
            return(mb_tmp);
202
202
    }
203
203
 
204
 
    if (codeset->side == XlcC0 || codeset->side == XlcGL || 
 
204
    if (codeset->side == XlcC0 || codeset->side == XlcGL ||
205
205
        codeset->side == XlcC1 || codeset->side == XlcGR) {
206
206
 
207
207
        for (i = 0; i < codeset->length; i++)
283
283
 
284
284
    wc = wc & ~wc_encode_mask;
285
285
    for (*glyph_index = 0, i = (*codeset)->length - 1; i >= 0; i--)
286
 
        *glyph_index = (*glyph_index << 8) | 
 
286
        *glyph_index = (*glyph_index << 8) |
287
287
                      ( ((unsigned long)wc >> (i * wc_shift_bits)) & mask );
288
288
 
289
289
    return(True);
302
302
    ParseInfo *mb_parse_list = XLC_GENERIC(state->lcd, mb_parse_list);
303
303
    ParseInfo parse_info;
304
304
    CodeSet codeset;
305
 
    
 
305
 
306
306
    for (--num ; (parse_info = mb_parse_list[num]) != NULL; num++) {
307
307
       len = compare(src, parse_info->encoding, from_len);
308
308
       if (len > 0) {
344
344
            continue;
345
345
 
346
346
        for (j = 0; j < codeset->length; j++) {
347
 
            ch = *((unsigned char *)(inbufptr + j)); 
 
347
            ch = *((unsigned char *)(inbufptr + j));
348
348
            byteM_rec = byteM[j];
349
349
            byteinfo = byteM_rec.byteinfo;
350
350
 
365
365
    }
366
366
 
367
367
    return(NULL);
368
 
}                
 
368
}
369
369
 
370
370
#define GLGR_parse_codeset(ch) \
371
371
     (isrightside(ch) ? (state->GR_codeset) : \
430
430
        if ( !(*ctr_seq_len = strlen(directionality_data[i].encoding)) )
431
431
            continue;
432
432
 
433
 
        if ( strncmp(inbufptr, directionality_data[i].encoding, 
 
433
        if ( strncmp(inbufptr, directionality_data[i].encoding,
434
434
                                                *ctr_seq_len) == 0)
435
435
            return(True);
436
436
    }
573
573
    range = segment_conv[i].range;
574
574
    if (*glyph_index < range.start || range.end < *glyph_index)
575
575
        return(True);
576
 
    
 
576
 
577
577
    *charset = segment_conv[i].dest;
578
578
    conv_rec.conv_num = segment_conv[i].conv_num;
579
579
    conv_rec.convlist = segment_conv[i].conv;
801
801
                continue;
802
802
            }
803
803
        }
804
 
    
 
804
 
805
805
        /* next mb char data for byteM ? */
806
806
        if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
807
807
            goto next_mb_char;
809
809
        /* next mb char data for GL or GR side ? */
810
810
        if ((codeset = GLGR_parse_codeset(ch)))
811
811
            goto next_mb_char;
812
 
            
 
812
 
813
813
        /* can't find codeset for the ch */
814
814
        unconv_num++;
815
815
        continue;
878
878
            /* null ? */
879
879
            src++;
880
880
            src_left--;
881
 
            if (dst) 
 
881
            if (dst)
882
882
                *dst++ = L'\0';
883
883
            dst_left--;
884
884
        }
918
918
    const wchar_t *inbufptr = (const wchar_t *) *from;
919
919
    char *outbufptr = *to;
920
920
    int from_size = *from_left;
921
 
    
 
921
 
922
922
    const char *default_string = XLC_PUBLIC(lcd, default_string);
923
923
    int defstr_len = strlen(default_string);
924
924
 
1033
1033
        if (length > 0) {
1034
1034
            src++;
1035
1035
            src_left--;
1036
 
            if (dst) 
 
1036
            if (dst)
1037
1037
                dst += length;
1038
1038
            dst_left -= length;
1039
1039
        } else if (length < 0) {
1040
1040
            src++;
1041
1041
            src_left--;
1042
1042
            unconv_num++;
1043
 
        } 
 
1043
        }
1044
1044
    }
1045
1045
 
1046
1046
    *from = (XPointer) src;
1119
1119
         * +-----+-----+-----+-----+-----+-----+-----+----   ----+-----+-----+
1120
1120
         * |     esc sequence      |  M  |  L  |     encoding name     | STX |
1121
1121
         * +-----+-----+-----+-----+-----+-----+-----+----   ----+-----+-----+
1122
 
         *           4bytes         1byte 1byte     variable length     1byte 
 
1122
         *           4bytes         1byte 1byte     variable length     1byte
1123
1123
         *                         |                                         |
1124
1124
         *                         +-----------------------------------------+
1125
1125
         *                           name length  = ((M - 128) * 128) + (L - 128)
1147
1147
                *ext_seg_len   = i % 128 + 128;
1148
1148
                ext_seg_len = NULL;
1149
1149
            }
1150
 
            
 
1150
 
1151
1151
            if (*to_left < total_len + 1) {
1152
1152
                unconv_num++;
1153
1153
                break;
1221
1221
    int buf_left2;
1222
1222
    int unconv_num1 = 0, unconv_num2 = 0;
1223
1223
 
1224
 
    unconv_num1 = stdc_wcstombs(conv, 
 
1224
    unconv_num1 = stdc_wcstombs(conv,
1225
1225
                from, from_left, &buf_ptr1, &buf_left1, args, num_args);
1226
1226
    if (unconv_num1 < 0)
1227
1227
        goto ret;
1228
1228
 
1229
1229
    buf_left2 = buf_ptr1 - buf_ptr2;
1230
1230
 
1231
 
    unconv_num2 = mbstocts(conv, 
 
1231
    unconv_num2 = mbstocts(conv,
1232
1232
                &buf_ptr2, &buf_left2, to, to_left, args, num_args);
1233
1233
    if (unconv_num2 < 0)
1234
1234
        goto ret;
1321
1321
 
1322
1322
        /* escape sequence ? */
1323
1323
        if (ch == ESC) {
1324
 
            if ( !ct_parse_charset(lcd, 
 
1324
            if ( !ct_parse_charset(lcd,
1325
1325
                        inbufptr - 1, &state->charset, &ctr_seq_len) )
1326
1326
                goto skip_the_seg;
1327
1327
 
1328
 
            if (state->charset->side == XlcC0 || 
 
1328
            if (state->charset->side == XlcC0 ||
1329
1329
                state->charset->side == XlcGL)
1330
1330
              {
1331
1331
                state->GL_charset = state->charset;
1332
1332
              }
1333
 
            else if (state->charset->side == XlcC1 || 
 
1333
            else if (state->charset->side == XlcC1 ||
1334
1334
                     state->charset->side == XlcGR)
1335
1335
              {
1336
1336
                state->GR_charset = state->charset;
1337
 
              } 
 
1337
              }
1338
1338
            else if (state->charset->side == XlcGLGR)
1339
1339
              {
1340
1340
                state->GL_charset = state->charset;
1341
1341
                state->GR_charset = state->charset;
1342
 
              } 
 
1342
              }
1343
1343
 
1344
1344
            if (*from_left + 1 < ctr_seq_len) {
1345
1345
                inbufptr--;
1353
1353
            *from_left -= (ctr_seq_len - 1);
1354
1354
 
1355
1355
            continue;
1356
 
        } 
 
1356
        }
1357
1357
 
1358
1358
        /* check current state */
1359
1359
        if (isleftside(ch))
1380
1380
            segment_conversion(lcd, &charset_tmp, &glyph_index);
1381
1381
 
1382
1382
            /* get codeset */
1383
 
            if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp, 
 
1383
            if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp,
1384
1384
                                                &codeset, &glyph_index) ) {
1385
1385
                unconv_num += gi_len;
1386
1386
                continue;
1499
1499
            segment_conversion(lcd, &charset_tmp, &glyph_index);
1500
1500
 
1501
1501
            /* get codeset */
1502
 
            if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp, 
 
1502
            if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp,
1503
1503
                                                &codeset, &glyph_index) ) {
1504
1504
                unconv_num += gi_len;
1505
1505
                continue;
1544
1544
    int buf_left2;
1545
1545
    int unconv_num1 = 0, unconv_num2 = 0;
1546
1546
 
1547
 
    unconv_num1 = ctstombs(conv, 
 
1547
    unconv_num1 = ctstombs(conv,
1548
1548
                from, from_left, &buf_ptr1, &buf_left1, args, num_args);
1549
1549
    if (unconv_num1 < 0)
1550
1550
        goto ret;
1551
1551
 
1552
1552
    buf_left2 = buf_ptr1 - buf_ptr2;
1553
1553
 
1554
 
    unconv_num2 = stdc_mbstowcs(conv, 
 
1554
    unconv_num2 = stdc_mbstowcs(conv,
1555
1555
                &buf_ptr2, &buf_left2, to, to_left, args, num_args);
1556
1556
    if (unconv_num2 < 0)
1557
1557
        goto ret;
1580
1580
    int buf_left2;
1581
1581
    int unconv_num1 = 0, unconv_num2 = 0;
1582
1582
 
1583
 
    unconv_num1 = cstombs(conv, 
 
1583
    unconv_num1 = cstombs(conv,
1584
1584
                from, from_left, &buf_ptr1, &buf_left1, args, num_args);
1585
1585
    if (unconv_num1 < 0)
1586
1586
        goto ret;
1587
1587
 
1588
1588
    buf_left2 = buf_ptr1 - buf_ptr2;
1589
1589
 
1590
 
    unconv_num2 = stdc_mbstowcs(conv, 
 
1590
    unconv_num2 = stdc_mbstowcs(conv,
1591
1591
                &buf_ptr2, &buf_left2, to, to_left, args, num_args);
1592
1592
    if (unconv_num2 < 0)
1593
1593
        goto ret;
1616
1616
    int buf_left2;
1617
1617
    int unconv_num1 = 0, unconv_num2 = 0;
1618
1618
 
1619
 
    unconv_num1 = mbstowcs_org(conv, 
 
1619
    unconv_num1 = mbstowcs_org(conv,
1620
1620
                from, from_left, &buf_ptr1, &buf_left1, args, num_args);
1621
1621
    if (unconv_num1 < 0)
1622
1622
        goto ret;
1623
1623
 
1624
1624
    buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
1625
1625
 
1626
 
    unconv_num2 += wcstocts(conv, 
 
1626
    unconv_num2 += wcstocts(conv,
1627
1627
                &buf_ptr2, &buf_left2, to, to_left, args, num_args);
1628
1628
    if (unconv_num2 < 0)
1629
1629
        goto ret;
1711
1711
        /* next char data : GL or GR side ? */
1712
1712
        if ((codeset = GLGR_parse_codeset(ch)))
1713
1713
            goto next_mb_char;
1714
 
            
 
1714
 
1715
1715
        /* can't find codeset for the ch */
1716
1716
        unconv_num++;
1717
1717
        continue;
1823
1823
        /* next mb char data for GL or GR side ? */
1824
1824
        if ((codeset = GLGR_parse_codeset(ch)))
1825
1825
            goto next_mb_char;
1826
 
            
 
1826
 
1827
1827
        /* can't find codeset for the ch */
1828
1828
        unconv_num = 1;
1829
1829
        break;
1906
1906
 
1907
1907
    ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1);
1908
1908
    charset_old = charset;
1909
 
  
 
1909
 
1910
1910
    while ( ret == 0 && *from_left && *to_left) {
1911
1911
        inbufptr = *from;
1912
1912
        in_left = *from_left;
1957
1957
    const wchar_t *inbufptr = (const wchar_t *) *from;
1958
1958
    char *outbufptr = *to;
1959
1959
    int from_size = *from_left;
1960
 
    
 
1960
 
1961
1961
    const char *default_string = XLC_PUBLIC(lcd, default_string);
1962
1962
    int defstr_len = strlen(default_string);
1963
1963
 
2073
2073
    int buf_left2;
2074
2074
    int unconv_num1 = 0, unconv_num2 = 0;
2075
2075
 
2076
 
    unconv_num1 = stdc_wcstombs(conv, 
 
2076
    unconv_num1 = stdc_wcstombs(conv,
2077
2077
                from, from_left, &buf_ptr1, &buf_left1, args, num_args);
2078
2078
    if (unconv_num1 < 0)
2079
2079
        goto ret;
2080
2080
 
2081
2081
    buf_left2 = buf_ptr1 - buf_ptr2;
2082
2082
 
2083
 
    unconv_num2 = mbstostr(conv, 
 
2083
    unconv_num2 = mbstostr(conv,
2084
2084
                &buf_ptr2, &buf_left2, to, to_left, args, num_args);
2085
2085
    if (unconv_num2 < 0)
2086
2086
        goto ret;
2206
2206
        } else {
2207
2207
            goto end;
2208
2208
        }
2209
 
                
 
2209
 
2210
2210
        if (length < 0)
2211
2211
            goto end;
2212
2212
 
2351
2351
    int buf_left2;
2352
2352
    int unconv_num1 = 0, unconv_num2 = 0;
2353
2353
 
2354
 
    unconv_num1 = ctstowcs(conv, 
 
2354
    unconv_num1 = ctstowcs(conv,
2355
2355
                from, from_left, &buf_ptr1, &buf_left1, args, num_args);
2356
2356
    if (unconv_num1 < 0)
2357
2357
        goto ret;
2358
2358
 
2359
2359
    buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
2360
2360
 
2361
 
    unconv_num2 += wcstombs_org(conv, 
 
2361
    unconv_num2 += wcstombs_org(conv,
2362
2362
                &buf_ptr2, &buf_left2, to, to_left, args, num_args);
2363
2363
    if (unconv_num2 < 0)
2364
2364
        goto ret;
2387
2387
    int buf_left2;
2388
2388
    int unconv_num1 = 0, unconv_num2 = 0;
2389
2389
 
2390
 
    unconv_num1 = cstowcs(conv, 
 
2390
    unconv_num1 = cstowcs(conv,
2391
2391
                from, from_left, &buf_ptr1, &buf_left1, args, num_args);
2392
2392
    if (unconv_num1 < 0)
2393
2393
        goto ret;
2394
2394
 
2395
2395
    buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
2396
2396
 
2397
 
    unconv_num2 += wcstombs_org(conv, 
 
2397
    unconv_num2 += wcstombs_org(conv,
2398
2398
                &buf_ptr2, &buf_left2, to, to_left, args, num_args);
2399
2399
    if (unconv_num2 < 0)
2400
2400
        goto ret;
2602
2602
    int buf_left2;
2603
2603
    int unconv_num1 = 0, unconv_num2 = 0;
2604
2604
 
2605
 
    unconv_num1 = strtombs(conv, 
 
2605
    unconv_num1 = strtombs(conv,
2606
2606
                from, from_left, &buf_ptr1, &buf_left1, args, num_args);
2607
2607
    if (unconv_num1 < 0)
2608
2608
        goto ret;
2609
2609
 
2610
2610
    buf_left2 = buf_ptr1 - buf_ptr2;
2611
2611
 
2612
 
    unconv_num2 = stdc_mbstowcs(conv, 
 
2612
    unconv_num2 = stdc_mbstowcs(conv,
2613
2613
                &buf_ptr2, &buf_left2, to, to_left, args, num_args);
2614
2614
    if (unconv_num2 < 0)
2615
2615
        goto ret;
2655
2655
    conv = (XlcConv) Xmalloc(sizeof(XlcConvRec));
2656
2656
    if (conv == NULL)
2657
2657
        return (XlcConv) NULL;
2658
 
    
 
2658
 
2659
2659
    conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec));
2660
2660
    if (conv->methods == NULL)
2661
2661
        goto err;
2662
2662
    *conv->methods = *methods;
2663
 
    conv->methods->reset = init_state; 
 
2663
    conv->methods->reset = init_state;
2664
2664
 
2665
2665
    conv->state = (XPointer) Xmalloc(sizeof(StateRec));
2666
2666
    if (conv->state == NULL)
2667
2667
        goto err;
2668
2668
    bzero((char *) conv->state, sizeof(StateRec));
2669
 
    
 
2669
 
2670
2670
    state = (State) conv->state;
2671
2671
    state->lcd = lcd;
2672
 
    
 
2672
 
2673
2673
    _XlcResetConverter(conv);
2674
 
    
 
2674
 
2675
2675
    return conv;
2676
2676
 
2677
2677
err:
3112
3112
    _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte, open_ctstombs);
3113
3113
    _XlcSetConverter(lcd, XlcNString,    lcd, XlcNMultiByte,    open_strtombs);
3114
3114
    _XlcSetConverter(lcd, XlcNCharSet,   lcd, XlcNMultiByte,    open_cstombs);
3115
 
    
 
3115
 
3116
3116
#ifdef STDCVT
3117
3117
     gen = XLC_GENERIC_PART(lcd);
3118
3118