1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912
|
/* $XConsortium: ResEncod.c /main/8 1996/11/12 05:37:04 pascale $ */
/*
* Motif
*
* Copyright (c) 1987-2012, The Open Group. All rights reserved.
*
* These libraries and programs are free software; you can
* redistribute them and/or modify them under the terms of the GNU
* Lesser General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* These libraries and programs are distributed in the hope that
* they will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with these librararies and programs; if not, write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*
*/
/*
* HISTORY
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#ifndef X_NOT_STDC_ENV
#include <stdlib.h>
#endif
#include <string.h>
#include <ctype.h>
#ifdef UTF8_SUPPORTED
#include <iconv.h>
#endif
#include <errno.h>
#include <Xm/XmosP.h>
#include "MessagesI.h"
#include "ResEncodI.h"
#include "XmI.h"
#include "XmosI.h"
#include "XmStringI.h"
#include "ResConverI.h"
#define MSG8 _XmMMsgResConvert_0007
#define MSG9 _XmMMsgResConvert_0008
#define MSG10 _XmMMsgResConvert_0009
#define MSG11 _XmMMsgResConvert_0010
#define MSG13 _XmMMsgResConvert_0012
#define MSG14 _XmMMsgResConvert_0013
typedef unsigned char Octet;
typedef Octet *OctetPtr;
typedef XmConst Octet *const_OctetPtr;
typedef enum {
ct_Dir_StackEmpty,
ct_Dir_Undefined,
ct_Dir_LeftToRight,
ct_Dir_RightToLeft
} ct_Direction;
/*
** ct_Charset is used in the xmstring_to_text conversion to keep track
** of the prevous character set. The order is not important.
*/
typedef enum {
cs_none,
cs_Hanzi,
cs_JapaneseGCS,
cs_Katakana,
cs_KoreanGCS,
cs_Latin1,
cs_Latin2,
cs_Latin3,
cs_Latin4,
cs_Latin5,
cs_LatinArabic,
cs_LatinCyrillic,
cs_LatinGreek,
cs_LatinHebrew,
cs_NonStandard,
cs_ir111
} ct_Charset;
/* Internal context block */
typedef struct _ct_context {
OctetPtr octet; /* octet ptr into compound text stream */
OctetPtr lastoctet; /* ptr to last octet in stream */
struct { /* flags */
unsigned dircs : 1; /* direction control seq encountered */
unsigned gchar : 1; /* graphic characters encountered */
unsigned ignext : 1; /* ignore extensions */
unsigned gl : 1; /* text is for gl */
unsigned text : 1; /* current item is a text seq */
} flags;
ct_Direction *dirstack; /* direction stack pointer */
unsigned int dirsp; /* current dir stack index */
unsigned int dirstacksize; /* size of direction stack */
OctetPtr encoding; /* ptr to current encoding sequence */
unsigned int encodinglen; /* length of encoding sequence */
OctetPtr item; /* ptr to current item */
unsigned int itemlen; /* length of current item */
unsigned int version; /* version of compound text */
XmConst char* gl_charset; /* ptr to GL character set */
unsigned char gl_charset_size; /* # of chars in GL charset */
unsigned char gl_octets_per_char; /* # of octets per GL char */
XmConst char* gr_charset; /* ptr to GR character set */
unsigned char gr_charset_size; /* # of chars in GR charset */
unsigned char gr_octets_per_char; /* # of octets per GR char */
XmString xmstring; /* compound string to be returned */
XmString xmsep; /* compound string separator segment */
XmString xmtab; /* compound string tab segment */
} ct_context;
/*
* Segment Encoding Registry datatype and macros
*/
typedef struct _EncodingRegistry {
char *fontlist_tag;
char *ct_encoding;
struct _EncodingRegistry *next;
} SegmentEncoding;
#define EncodingRegistryTag(er) ((SegmentEncoding *)(er))->fontlist_tag
#define EncodingRegistryEncoding(er) ((SegmentEncoding *)(er))->ct_encoding
#define EncodingRegistryNext(er) ((SegmentEncoding *)(er))->next
/*
** Define standard character set strings
*/
static XmConst char CS_ISO8859_1[] = "ISO8859-1" ;
static XmConst char CS_ISO8859_2[] = "ISO8859-2" ;
static XmConst char CS_ISO8859_3[] = "ISO8859-3" ;
static XmConst char CS_ISO8859_4[] = "ISO8859-4" ;
static XmConst char CS_ISO8859_5[] = "ISO8859-5" ;
static XmConst char CS_ISO8859_6[] = "ISO8859-6" ;
static XmConst char CS_ISO8859_7[] = "ISO8859-7" ;
static XmConst char CS_ISO8859_8[] = "ISO8859-8" ;
static XmConst char CS_ISO8859_9[] = "ISO8859-9" ;
static XmConst char CS_JISX0201[] = "JISX0201.1976-0" ;
static XmConst char CS_GB2312_0[] = "GB2312.1980-0" ;
static XmConst char CS_GB2312_1[] = "GB2312.1980-1" ;
static XmConst char CS_JISX0208_0[] = "JISX0208.1983-0" ;
static XmConst char CS_JISX0208_1[] = "JISX0208.1983-1" ;
static XmConst char CS_KSC5601_0[] = "KSC5601.1987-0" ;
static XmConst char CS_KSC5601_1[] = "KSC5601.1987-1" ;
static XmConst char CS_UTF_8[] = "UTF-8" ;
static XmConst char CS_ISO_IR_111[] = "ISO-IR-111" ;
/* Define handy macros (note: these constants are in OCTAL) */
#define EOS 00
#define STX 02
#define HT 011
#define NL 012
#define ESC 033
#define CSI 0233
static XmConst Octet NEWLINESTRING[] = "\012";
#define NEWLINESTRING_LEN sizeof(NEWLINESTRING)-1
static XmConst Octet TABSTRING[] = "\011";
#define TABSTRING_LEN sizeof(TABSTRING)-1
static XmConst Octet CTEXT_L_TO_R[] = "\233\061\135";
#define CTEXT_L_TO_R_LEN sizeof(CTEXT_L_TO_R)-1
static XmConst Octet CTEXT_R_TO_L[] = "\233\062\135";
#define CTEXT_R_TO_L_LEN sizeof(CTEXT_R_TO_L)-1
static XmConst Octet CTEXT_SET_ISO8859_1[] = "\033\050\102\033\055\101";
#define CTEXT_SET_ISO8859_1_LEN sizeof(CTEXT_SET_ISO8859_1)-1
static XmConst Octet CTEXT_SET_ISO8859_2[] = "\033\050\102\033\055\102";
#define CTEXT_SET_ISO8859_2_LEN sizeof(CTEXT_SET_ISO8859_2)-1
static XmConst Octet CTEXT_SET_ISO8859_3[] = "\033\050\102\033\055\103";
#define CTEXT_SET_ISO8859_3_LEN sizeof(CTEXT_SET_ISO8859_3)-1
static XmConst Octet CTEXT_SET_ISO8859_4[] = "\033\050\102\033\055\104";
#define CTEXT_SET_ISO8859_4_LEN sizeof(CTEXT_SET_ISO8859_4)-1
static XmConst Octet CTEXT_SET_ISO8859_5[] = "\033\050\102\033\055\114";
#define CTEXT_SET_ISO8859_5_LEN sizeof(CTEXT_SET_ISO8859_5)-1
static XmConst Octet CTEXT_SET_ISO8859_6[] = "\033\050\102\033\055\107";
#define CTEXT_SET_ISO8859_6_LEN sizeof(CTEXT_SET_ISO8859_6)-1
static XmConst Octet CTEXT_SET_ISO8859_7[] = "\033\050\102\033\055\106";
#define CTEXT_SET_ISO8859_7_LEN sizeof(CTEXT_SET_ISO8859_7)-1
static XmConst Octet CTEXT_SET_ISO8859_8[] = "\033\050\102\033\055\110";
#define CTEXT_SET_ISO8859_8_LEN sizeof(CTEXT_SET_ISO8859_8)-1
static XmConst Octet CTEXT_SET_ISO8859_9[] = "\033\050\102\033\055\115";
#define CTEXT_SET_ISO8859_9_LEN sizeof(CTEXT_SET_ISO8859_9)-1
static XmConst Octet CTEXT_SET_JISX0201[] = "\033\050\112\033\051\111";
#define CTEXT_SET_JISX0201_LEN sizeof(CTEXT_SET_JISX0201)-1
static XmConst Octet CTEXT_SET_GB2312_0[] = "\033\044\050\101\033\044\051\101";
#define CTEXT_SET_GB2312_0_LEN sizeof(CTEXT_SET_GB2312_0)-1
static XmConst Octet CTEXT_SET_JISX0208_0[] = "\033\044\050\102\033\044\051\102";
#define CTEXT_SET_JISX0208_0_LEN sizeof(CTEXT_SET_JISX0208_0)-1
static XmConst Octet CTEXT_SET_KSC5601_0[] = "\033\044\050\103\033\044\051\103";
#define CTEXT_SET_KSC5601_0_LEN sizeof(CTEXT_SET_KSC5601_0)-1
static XmConst Octet CTEXT_SET_IR_111[] = "\033\050\102\033\055\100";
#define CTEXT_SET_IR_111_LEN sizeof(CTEXT_SET_IR_111)-1
#ifdef UTF8_SUPPORTED
static XmConst char UTF8_NEWLINESTRING[] = "\012";
#define UTF8_NEWLINESTRING_LEN sizeof(UTF8_NEWLINESTRING)-1
static XmConst char UTF8_TABSTRING[] = "\011";
#define UTF8_TABSTRING_LEN sizeof(UTF8_TABSTRING)-1
static XmConst char UTF8_L_TO_R[] = "\342\200\216";
#define UTF8_L_TO_R_LEN sizeof(UTF8_L_TO_R)-1
static XmConst char UTF8_R_TO_L[] = "\342\200\217";
#define UTF8_R_TO_L_LEN sizeof(UTF8_R_TO_L)-1
#endif /* UTF8_SUPPORTED */
#define CTVERSION 1
#define _IsValidC0(ctx, c) (((c) == HT) || ((c) == NL) || ((ctx)->version > CTVERSION))
#define _IsValidC1(ctx, c) ((ctx)->version > CTVERSION)
#define _IsValidESCFinal(c) (((c) >= 0x30) && ((c) <= 0x7e))
#define _IsValidCSIFinal(c) (((c) >= 0x40) && ((c) <= 0x7e))
#define _IsInC0Set(c) ((c) <= 0x1f)
#define _IsInC1Set(c) (((c) >= 0x80) && ((c) <= 0x9f))
#define _IsInGLSet(c) (((c) >= 0x20) && ((c) <= 0x7f))
#define _IsInGRSet(c) ((c) >= 0xa0)
#define _IsInColumn2(c) (((c) >= 0x20) && ((c) <= 0x2f))
#define _IsInColumn3(c) (((c) >= 0x30) && ((c) <= 0x3f))
#define _IsInColumn4(c) (((c) >= 0x40) && ((c) <= 0x4f))
#define _IsInColumn5(c) (((c) >= 0x50) && ((c) <= 0x5f))
#define _IsInColumn6(c) (((c) >= 0x60) && ((c) <= 0x6f))
#define _IsInColumn7(c) (((c) >= 0x70) && ((c) <= 0x7f))
#define _IsInColumn4or5(c) (((c) >= 0x40) && ((c) <= 0x5f))
#define _SetGL(ctx, charset, size, octets)\
(ctx)->flags.gl = True;\
(ctx)->gl_charset = (charset);\
(ctx)->gl_charset_size = (size);\
(ctx)->gl_octets_per_char = (octets)
#define _SetGR(ctx, charset, size, octets)\
(ctx)->flags.gl = False;\
(ctx)->gr_charset = (charset);\
(ctx)->gr_charset_size = (size);\
(ctx)->gr_octets_per_char = (octets)
#define _PushDir(ctx, dir)\
if ( (ctx)->dirsp == ((ctx)->dirstacksize - 1) ) {\
(ctx)->dirstacksize += 8;\
(ctx)->dirstack = \
(ct_Direction *)XtRealloc((char *)(ctx)->dirstack,\
(ctx)->dirstacksize * sizeof(ct_Direction));\
}\
(ctx)->dirstack[++((ctx)->dirsp)] = dir;\
(ctx)->flags.dircs = True
#define _PopDir(ctx) ((ctx)->dirsp)--
#define _CurDir(ctx) (ctx)->dirstack[(ctx)->dirsp]
/* this should probably be the other way around, (XmFONTLIST_DEFAULT_TAG map to
_MOTIF_DEFAULT_LOCALE) but this is the smallest code change, and the code
will not work any differently */
/* Define the MIT registered charset */
static SegmentEncoding _mit_ISO_IR_1111_registry =
{ "ISO-IR-111", "ISO-IR-111", NULL};
static SegmentEncoding _mit_UTF_8_registry =
{ "UTF-8", "UTF-8", &_mit_ISO_IR_1111_registry};
static SegmentEncoding _mit_KSC5601_1987_1_registry =
{ "KSC5601.1987-1", "KSC5601.1987-1", &_mit_UTF_8_registry};
static SegmentEncoding _mit_KSC5601_1987_0_registry =
{ "KSC5601.1987-0", "KSC5601.1987-0", &_mit_KSC5601_1987_1_registry};
static SegmentEncoding _mit_JISX0208_1983_1_registry =
{ "JISX0208.1983-1", "JISX0208.1983-1", &_mit_KSC5601_1987_0_registry};
static SegmentEncoding _mit_JISX0208_1983_0_registry =
{ "JISX0208.1983-0", "JISX0208.1983-0", &_mit_JISX0208_1983_1_registry};
static SegmentEncoding _mit_GB2312_1980_1_registry =
{ "GB2312.1980-1", "GB2312.1980-1", &_mit_JISX0208_1983_0_registry};
static SegmentEncoding _mit_GB2312_1980_0_registry =
{ "GB2312.1980-0", "GB2312.1980-0", &_mit_GB2312_1980_1_registry};
static SegmentEncoding _mit_JISX0201_1976_0_registry =
{ "JISX0201.1976-0", "JISX0201.1976-0", &_mit_GB2312_1980_0_registry};
static SegmentEncoding _mit_ISO8859_9_registry =
{ "ISO8859-9", "ISO8859-9", &_mit_JISX0201_1976_0_registry};
static SegmentEncoding _mit_ISO8859_8_registry =
{ "ISO8859-8", "ISO8859-8", &_mit_ISO8859_9_registry};
static SegmentEncoding _mit_ISO8859_7_registry =
{ "ISO8859-7", "ISO8859-7", &_mit_ISO8859_8_registry};
static SegmentEncoding _mit_ISO8859_6_registry =
{ "ISO8859-6", "ISO8859-6", &_mit_ISO8859_7_registry};
static SegmentEncoding _mit_ISO8859_5_registry =
{ "ISO8859-5", "ISO8859-5", &_mit_ISO8859_6_registry};
static SegmentEncoding _mit_ISO8859_4_registry =
{ "ISO8859-4", "ISO8859-4", &_mit_ISO8859_5_registry};
static SegmentEncoding _mit_ISO8859_3_registry =
{ "ISO8859-3", "ISO8859-3", &_mit_ISO8859_4_registry};
static SegmentEncoding _mit_ISO8859_2_registry =
{ "ISO8859-2", "ISO8859-2", &_mit_ISO8859_3_registry};
static SegmentEncoding _mit_ISO8859_1_registry =
{ "ISO8859-1", "ISO8859-1", &_mit_ISO8859_2_registry};
static SegmentEncoding _loc_encoding_registry =
{ _MOTIF_DEFAULT_LOCALE, XmFONTLIST_DEFAULT_TAG, &_mit_ISO8859_1_registry};
static SegmentEncoding _encoding_registry =
{ XmFONTLIST_DEFAULT_TAG, XmFONTLIST_DEFAULT_TAG, &_loc_encoding_registry};
static SegmentEncoding *_encoding_registry_ptr = &_encoding_registry;
/******** Static Function Declarations ********/
static SegmentEncoding * FindEncoding(
char *fontlist_tag) ;
static Boolean processCharsetAndText(XmStringCharSet tag,
OctetPtr ctext,
#if NeedWidePrototypes
int separator,
#else
Boolean separator,
#endif /* NeedWidePrototypes */
OctetPtr *outc,
unsigned int *outlen,
ct_Charset *prev);
#ifdef UTF8_SUPPORTED
static Boolean processCharsetAndTextUtf8(XmStringCharSet tag,
OctetPtr ctext,
#if NeedWidePrototypes
int separator,
#else
Boolean separator,
#endif /* NeedWidePrototypes */
OctetPtr *outc,
unsigned int *outlen,
ct_Charset *prev);
#endif
static Boolean processESCHack(
ct_context *ctx,
#if NeedWidePrototypes
int final) ;
#else
Octet final) ;
#endif /* NeedWidePrototypes */
static Boolean processExtendedSegmentsHack(
ct_context *ctx,
#if NeedWidePrototypes
int final) ;
#else
Octet final) ;
#endif /* NeedWidePrototypes */
static Boolean cvtTextToXmString(
XrmValue *from,
XrmValue *to) ;
static void outputXmString(
ct_context *ctx,
#if NeedWidePrototypes
int separator) ;
#else
Boolean separator) ;
#endif /* NeedWidePrototypes */
static XmString concatStringToXmString(
XmString compoundstring,
char *textstring,
int textlen,
char *charset,
#if NeedWidePrototypes
int direction,
int separator) ;
#else
XmStringDirection direction,
Boolean separator) ;
#endif /* NeedWidePrototypes */
static Boolean processESC(
ct_context *ctx,
#if NeedWidePrototypes
int final) ;
#else
Octet final) ;
#endif /* NeedWidePrototypes */
static Boolean processCSI(
ct_context *ctx,
#if NeedWidePrototypes
int final) ;
#else
Octet final) ;
#endif /* NeedWidePrototypes */
static Boolean processExtendedSegments(
ct_context *ctx,
#if NeedWidePrototypes
int final) ;
#else
Octet final) ;
#endif /* NeedWidePrototypes */
static Boolean process94n(
ct_context *ctx,
#if NeedWidePrototypes
int final) ;
#else
Octet final) ;
#endif /* NeedWidePrototypes */
static Boolean process94GL(
ct_context *ctx,
#if NeedWidePrototypes
int final) ;
#else
Octet final) ;
#endif /* NeedWidePrototypes */
static Boolean process94GR(
ct_context *ctx,
#if NeedWidePrototypes
int final) ;
#else
Octet final) ;
#endif /* NeedWidePrototypes */
static Boolean process96GR(
ct_context *ctx,
#if NeedWidePrototypes
int final) ;
#else
Octet final) ;
#endif /* NeedWidePrototypes */
static Boolean cvtXmStringToText(
XrmValue *from,
XrmValue *to) ;
static OctetPtr ctextConcat(
OctetPtr str1,
unsigned int str1len,
const_OctetPtr str2,
unsigned int str2len) ;
#ifdef UTF8_SUPPORTED
static Boolean cvtXmStringToUTF8String(
XrmValue *from,
XrmValue *to ) ;
static char* Convert(
const char *str,
unsigned int len,
const char *to_codeset,
const char *from_codeset);
static char* ConvertWithIconv(
const char *str,
unsigned int len,
iconv_t converter);
#endif
/******** End Static Function Declarations ********/
/************************************************************************
*
* FindEncoding
* Find the SegmentEncoding with fontlist_tag. Return NULL if no
* such SegmentEncoding exists. As a side effect, free any encodings
* encountered that have been unregistered.
*
************************************************************************/
static SegmentEncoding *
FindEncoding(char *fontlist_tag)
{
SegmentEncoding *prevPtr, *encodingPtr = _encoding_registry_ptr;
String encoding = NULL;
if (encodingPtr)
{
if (strcmp(fontlist_tag, EncodingRegistryTag(encodingPtr)) == 0)
{
encoding = EncodingRegistryEncoding(encodingPtr);
/* Free unregistered encodings. */
if (encoding == NULL)
{
_encoding_registry_ptr = EncodingRegistryNext(encodingPtr);
XtFree( (char *) encodingPtr);
encodingPtr = NULL;
}
return(encodingPtr);
}
}
else return(encodingPtr);
for (prevPtr = encodingPtr, encodingPtr = EncodingRegistryNext(encodingPtr);
encodingPtr != NULL;
prevPtr = encodingPtr, encodingPtr = EncodingRegistryNext(encodingPtr))
{
if (strcmp(fontlist_tag, EncodingRegistryTag(encodingPtr)) == 0)
{
encoding = EncodingRegistryEncoding(encodingPtr);
/* Free unregistered encodings. */
if (encoding == NULL)
{
EncodingRegistryNext(prevPtr) =
EncodingRegistryNext(encodingPtr);
XtFree( (char *) encodingPtr);
encodingPtr = NULL;
}
return(encodingPtr);
}
/* Free unregistered encodings. */
else if (EncodingRegistryEncoding(encodingPtr) == NULL)
{
EncodingRegistryNext(prevPtr) = EncodingRegistryNext(encodingPtr);
XtFree( (char *) encodingPtr);
}
}
return(NULL);
}
/************************************************************************
*
* XmRegisterSegmentEncoding
* Register a compound text encoding format for a specified font list
* element tag. Returns NULL for a new tag or a copy of the old encoding
* for an already registered tag.
*
************************************************************************/
char *
XmRegisterSegmentEncoding(
char *fontlist_tag,
char *ct_encoding)
{
SegmentEncoding *encodingPtr = NULL;
String ret_val = NULL;
_XmProcessLock();
encodingPtr = FindEncoding(fontlist_tag);
if (encodingPtr)
{
ret_val = XtNewString(EncodingRegistryEncoding(encodingPtr));
EncodingRegistryEncoding(encodingPtr) =
ct_encoding ? XtNewString(ct_encoding) : (String)NULL;
}
else if (ct_encoding != NULL)
{
encodingPtr =
(SegmentEncoding *)XtMalloc((Cardinal)sizeof(SegmentEncoding));
EncodingRegistryTag(encodingPtr) = XtNewString(fontlist_tag);
EncodingRegistryEncoding(encodingPtr) = XtNewString(ct_encoding);
EncodingRegistryNext(encodingPtr) = _encoding_registry_ptr;
_encoding_registry_ptr = encodingPtr;
}
_XmProcessUnlock();
return(ret_val);
}
/************************************************************************
*
* _XmGetEncodingRegistryTarget returns the current encoding registry
* as a list of NULL separated items. The length is returned through
* the passed length pointer.
*
************************************************************************/
XtPointer
_XmGetEncodingRegistryTarget(int *length)
{
int i, count, total_size;
SegmentEncoding *current;
char *rval;
total_size = 0;
_XmProcessLock();
current = _encoding_registry_ptr;
while(current != NULL) {
total_size += strlen(EncodingRegistryTag(current)) +
strlen(EncodingRegistryEncoding(current)) + 2;
current = EncodingRegistryNext(current);
}
*length = total_size;
/* Create output buffer large enough for all the
pairs of tags and encodings */
rval = XtMalloc(sizeof(char) * total_size);
i = 0;
current = _encoding_registry_ptr;
while(current != NULL) {
count = strlen(EncodingRegistryTag(current));
strcpy(&rval[i], EncodingRegistryTag(current));
i += count;
rval[i] = 0;
i++;
count = strlen(EncodingRegistryEncoding(current));
strcpy(&rval[i], EncodingRegistryEncoding(current));
i += count;
rval[i] = 0;
i++;
current = EncodingRegistryNext(current);
}
_XmProcessUnlock();
return((XtPointer) rval);
}
/************************************************************************
*
* XmMapSegmentEncoding
* Returns the compound text encoding format associated with the
* specified font list element tag. Returns NULL if not found.
*
************************************************************************/
char *
XmMapSegmentEncoding(char *fontlist_tag)
{
SegmentEncoding *encodingPtr = NULL;
String ret_val = NULL;
_XmProcessLock();
encodingPtr = FindEncoding(fontlist_tag);
if (encodingPtr)
ret_val = XtNewString(EncodingRegistryEncoding(encodingPtr));
_XmProcessUnlock();
return(ret_val);
}
/************************************************************************
*
* XmCvtCTToXmString
* Convert a compound text string to a XmString. This is the public
* version which takes only a compound text string as an argument.
* Note: processESC and processExtendedSegments have to be hacked
* for this to work.
*
************************************************************************/
XmString
XmCvtCTToXmString(
char *text )
{
ct_context *ctx; /* compound text context block */
Boolean ok = True;
Octet c;
XmString xmsReturned; /* returned Xm string */
ctx = (ct_context *) XtMalloc(sizeof(ct_context));
/* initialize the context block */
ctx->octet = (OctetPtr)text;
ctx->flags.dircs = False;
ctx->flags.gchar = False;
ctx->flags.ignext = False;
ctx->flags.gl = False;
ctx->flags.text = False;
ctx->dirstacksize = 8;
ctx->dirstack = (ct_Direction *)
XtMalloc(ctx->dirstacksize*sizeof(ct_Direction));
/*
* Define XLIB_HANDLES_DIRECTION if vendor's X library knows how
* to deal with direction control sequences in CT. Otherwise
* no such ones will be output if there are no Rtol segments
* in the XmString. Note that the MIT sample implementation
* does not deal with direction control sequences...
*/
#ifdef XLIB_HANDLES_DIRECTION
ctx->dirstack[0] = ct_Dir_StackEmpty;
ctx->dirsp = 0;
#else
ctx->dirstack[0] = ct_Dir_StackEmpty;
ctx->dirstack[1] = ct_Dir_LeftToRight;
ctx->dirsp = 1;
#endif
ctx->encoding = NULL;
ctx->encodinglen = 0;
ctx->item = NULL;
ctx->itemlen = 0;
ctx->version = CTVERSION;
ctx->gl_charset = CS_ISO8859_1;
ctx->gl_charset_size = 94;
ctx->gl_octets_per_char = 1;
ctx->gr_charset = CS_ISO8859_1;
ctx->gr_charset_size = 96;
ctx->gr_octets_per_char = 1;
ctx->xmstring = NULL;
ctx->xmsep = NULL;
ctx->xmtab = NULL;
/*
** check for version/ignore extensions sequence (must be first if present)
** Format is: ESC 02/03 V 03/00 ignoring extensions is OK
** ESC 02/03 V 03/01 ignoring extensions is not OK
** where V is in the range 02/00 thru 02/15 and represents versions 1 thru 16
*/
if ( (ctx->octet[0] == ESC)
&& (ctx->octet[1] == 0x23)
&& (_IsInColumn2(ctx->octet[2])
&& ((ctx->octet[3] == 0x30) || ctx->octet[3] == 0x31))
) {
ctx->version = ctx->octet[2] - 0x1f; /* 0x20-0x2f => version 1-16 */
if (ctx->octet[3] == 0x30) /* 0x30 == can ignore extensions */
ctx->flags.ignext = True;
ctx->octet += 4; /* advance ptr to next seq */
}
while (ctx->octet[0] != 0) {
switch (*ctx->octet) { /* look at next octet in seq */
case ESC:
/* %%% TEMP
** if we have any text to output, do it
** this section needs to be optimized so that it handles
** paired character sets without outputting a new segment.
*/
if (ctx->flags.text) {
outputXmString(ctx, False); /* with no separator */
}
ctx->flags.text = False;
ctx->item = ctx->octet; /* remember start of this item */
ctx->itemlen = 0;
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
/* scan for final char */
while ( (ctx->octet[0] != 0)
&& (_IsInColumn2(*ctx->octet)) ) {
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
}
if (ctx->octet[0] == 0) { /* if nothing after this, it's an error */
ok = False;
break;
}
c = *ctx->octet; /* get next char in seq */
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
if (_IsValidESCFinal(c)) {
/* we have a valid ESC sequence - handle it */
ok = processESCHack(ctx, c);
} else {
ok = False;
}
if (ok) {
ctx->encoding = ctx->item;
ctx->encodinglen = ctx->itemlen;
}
break;
case CSI:
/*
** CSI format is: CSI P I F where
** 03/00 <= P <= 03/15
** 02/00 <= I <= 02/15
** 04/00 <= F <= 07/14
*/
/* %%% TEMP
** if we have any text to output, do it
** This may need optimization.
*/
if (ctx->flags.text) {
/* check whether we have a specific direction set */
if (((ctx->octet[1] == 0x31) && (ctx->octet[2] == 0x5d))||
((ctx->octet[1] == 0x32) && (ctx->octet[2] == 0x5d))||
(ctx->octet[1] == 0x5d))
outputXmString(ctx, False); /* without a separator*/
else
outputXmString(ctx, True); /* with a separator */
}
ctx->flags.text = False;
ctx->item = ctx->octet; /* remember start of this item */
ctx->itemlen = 0;
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
/* scan for final char */
while ( (ctx->octet[0] != 0)
&& _IsInColumn3(*ctx->octet) ) {
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
}
while ( (ctx->octet[0] != 0)
&& _IsInColumn2(*ctx->octet) ) {
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
}
/* if nothing after this, it's an error */
if (ctx->octet[0] == 0) {
ok = False;
break;
}
c = *ctx->octet; /* get next char in seq */
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
if (_IsValidCSIFinal(c)) {
/* we have a valid CSI sequence - handle it */
ok = processCSI(ctx, c);
} else {
ok = False;
}
break;
case NL: /* new line */
/* if we have any text to output, do it */
if (ctx->flags.text) {
outputXmString(ctx, True); /* with a separator */
ctx->flags.text = False;
} else {
if (ctx->xmsep == NULL) {
ctx->xmsep = XmStringSeparatorCreate();
}
ctx->xmstring = XmStringConcatAndFree(ctx->xmstring,
XmStringCopy(ctx->xmsep));
}
ctx->octet++; /* advance ptr to next char */
break;
case HT:
/* if we have any text to output, do it */
if (ctx->flags.text) {
outputXmString(ctx, False);
ctx->flags.text = False;
}
if (ctx->xmtab == NULL) {
ctx->xmtab = XmStringComponentCreate(XmSTRING_COMPONENT_TAB, 0,
NULL);
}
ctx->xmstring = XmStringConcatAndFree(ctx->xmstring,
XmStringCopy(ctx->xmtab));
ctx->octet++; /* advance ptr to next char */
break;
default: /* just 'normal' text */
ctx->item = ctx->octet; /* remember start of this item */
ctx->itemlen = 0;
ctx->flags.text = True;
while (ctx->octet[0] != 0) {
c = *ctx->octet;
if ((c == ESC) || (c == CSI) || (c == NL) || (c == HT)) {
break;
}
if ( (_IsInC0Set(c) && (!_IsValidC0(ctx, c)))
|| (_IsInC1Set(c) && (!_IsValidC1(ctx, c))) ) {
ok = False;
break;
}
ctx->flags.gchar = True; /* We have a character! */
/*
* We should look at the actual character to
* decide whether it's a gl or gr character.
*
* We'll hit the problem if we get a CT that
* isn't generated by Motif.
*/
if (isascii((unsigned char)c)) {
ctx->itemlen += ctx->gl_octets_per_char;
ctx->octet += ctx->gl_octets_per_char;
} else {
ctx->octet += ctx->gr_octets_per_char;
ctx->itemlen += ctx->gr_octets_per_char;
}
} /* end while */
break;
} /* end switch */
if (!ok) break;
} /* end while */
/* if we have any text left to output, do it */
if (ctx->flags.text) {
outputXmString(ctx, False); /* with no separator */
}
XtFree((char *) ctx->dirstack);
if (ctx->xmsep != NULL) XmStringFree(ctx->xmsep);
if (ctx->xmtab != NULL) XmStringFree(ctx->xmtab);
xmsReturned = (XmString)ctx->xmstring;
XtFree((char *) ctx);
if (ok)
return ( xmsReturned );
else
return ( (XmString)NULL );
}
/***********************************************************************
*
* Hacked procedures to work with XmCvtCTToXmString.
*
***********************************************************************/
/* processESCHack - handle valid ESC sequences */
static Boolean
processESCHack(
ct_context *ctx,
#if NeedWidePrototypes
int final )
#else
Octet final )
#endif /* NeedWidePrototypes */
{
Boolean ok;
switch (ctx->item[1]) {
case 0x24: /* 02/04 - invoke 94(n) charset into GL or GR */
ok = process94n(ctx, final);
break;
case 0x25: /* 02/05 - extended segments */
/* if we have any text to output, do it */
if (ctx->flags.text) {
outputXmString(ctx, False); /* with no separator */
ctx->flags.text = False;
}
ok = processExtendedSegmentsHack(ctx, final);
break;
case 0x28: /* 02/08 - invoke 94 charset into GL */
ok = process94GL(ctx, final);
break;
case 0x29: /* 02/09 - invoke 94 charset into GR */
ok = process94GR(ctx, final);
break;
case 0x2d: /* 02/13 - invoke 96 charset into GR */
ok = process96GR(ctx, final);
break;
default:
ok = False;
break;
}
return(ok);
}
static Boolean
processExtendedSegmentsHack(
ct_context *ctx,
#if NeedWidePrototypes
int final )
#else
Octet final )
#endif /* NeedWidePrototypes */
{
OctetPtr esptr; /* ptr into ext seg */
unsigned int seglen; /* length of ext seg */
unsigned int len; /* length */
String charset_copy; /* ptr to NULL-terminated copy of ext seg charset */
OctetPtr text_copy; /* ptr to NULL-terminated copy of ext seg text */
XmString tempxm1;
Boolean ok = True;
/* Extended segments
** 01/11 02/05 02/15 03/00 M L variable # of octets/char
** 01/11 02/05 02/15 03/01 M L 1 octet/char
** 01/11 02/05 02/15 03/02 M L 2 octets/char
** 01/11 02/05 02/15 03/03 M L 3 octets/char
** 01/11 02/05 02/15 03/04 M L 4 octets/char
*/
if ( (ctx->itemlen == 4)
&& (ctx->item[2] == 0x2f)
&& (_IsInColumn3(final))
)
{
if ( (ctx->octet[0] < 0x80)
|| (ctx->octet[1] < 0x80)
)
{
return(False);
}
/*
** The most significant bit of M and L are always set to 1
** The number is computed as ((M-128)*128)+(L-128)
*/
seglen = *ctx->octet - 0x80;
ctx->octet++; ctx->itemlen++; /* advance pointer */
seglen = (seglen << 7) + (*ctx->octet - 0x80);
ctx->octet++; ctx->itemlen++; /* advance pointer */
/* Check for premature end. */
for (esptr = ctx->octet; esptr < (ctx->octet + seglen); esptr++)
{
if (*esptr == 0)
{
return(False);
}
}
esptr = ctx->octet; /* point to charset */
ctx->itemlen += seglen; /* advance pointer over segment */
ctx->octet += seglen;
switch (final) {
case 0x30: /* variable # of octets per char */
case 0x31: /* 1 octet per char */
case 0x32: /* 2 octets per char */
/* scan for STX separator between charset and text */
len = 0;
while (esptr[len] != STX)
len++;
if (len > ctx->itemlen) { /* if we ran off the end, error */
ok = False;
break;
}
charset_copy = XtMalloc(len + 1);
strncpy(charset_copy, (char *) esptr, len);
charset_copy[len] = EOS;
esptr += len + 1; /* point to text part */
len = seglen - len - 1; /* calc length of text part */
/* For two-octets charsets, make sure the text
* contains an integral number of characters. */
if (final == 0x32 && len % 2) {
XtFree(charset_copy);
return (False);
}
text_copy = (unsigned char *) XtMalloc(len + 1);
memcpy( text_copy, esptr, len);
text_copy[len] = EOS;
tempxm1 = XmStringConcatAndFree(
XmStringDirectionCreate((_CurDir(ctx) ==
ct_Dir_LeftToRight ?
XmSTRING_DIRECTION_L_TO_R :
(_CurDir(ctx) ==
ct_Dir_RightToLeft ?
XmSTRING_DIRECTION_R_TO_L :
XmSTRING_DIRECTION_UNSET))),
XmStringCreate((char *)text_copy, charset_copy));
ctx->xmstring = XmStringConcatAndFree(ctx->xmstring, tempxm1);
XtFree((char *) text_copy);
XtFree((char *) charset_copy);
ok = True;
break;
case 0x33: /* 3 octets per char */
case 0x34: /* 4 octets per char */
/* not supported */
ok = False;
break;
default:
/* reserved for future use */
ok = False;
break;
} /* end switch */
} /* end if */
return(ok);
}
/************************************************************************
*
* XmCvtTextToXmString
* Convert a compound text string to a XmString.
*
************************************************************************/
/*ARGSUSED*/
Boolean
XmCvtTextToXmString(
Display *display,
XrmValuePtr args, /* unused */
Cardinal *num_args, /* unused */
XrmValue *from_val,
XrmValue *to_val,
XtPointer *converter_data ) /* unused */
{
Boolean ok;
if (from_val->addr == NULL)
return( FALSE);
ok = cvtTextToXmString(from_val, to_val);
if (!ok)
{
to_val->addr = NULL;
to_val->size = 0;
XtAppWarningMsg(XtDisplayToApplicationContext(display),
"conversionError","compoundText", "XtToolkitError",
MSG13, (String *)NULL, (Cardinal *)NULL);
}
return(ok);
}
static Boolean
cvtTextToXmString(
XrmValue *from,
XrmValue *to )
{
ct_context *ctx; /* compound text context block */
Boolean ok = True;
Octet c;
ctx = (ct_context *) XtMalloc(sizeof(ct_context));
/* initialize the context block */
ctx->octet = (OctetPtr)from->addr;
ctx->lastoctet = ctx->octet + from->size;
ctx->flags.dircs = False;
ctx->flags.gchar = False;
ctx->flags.ignext = False;
ctx->flags.gl = False;
ctx->flags.text = False;
ctx->dirstacksize = 8;
ctx->dirstack = (ct_Direction *)
XtMalloc(ctx->dirstacksize*sizeof(ct_Direction));
/*
* Define XLIB_HANDLES_DIRECTION if vendor's X library knows how
* to deal with direction control sequences in CT. Otherwise
* no such ones will be output if there are no Rtol segments
* in the XmString. Note that the MIT sample implementation
* does not deal with direction control sequences...
*/
#ifdef XLIB_HANDLES_DIRECTION
ctx->dirstack[0] = ct_Dir_StackEmpty;
ctx->dirsp = 0;
#else
ctx->dirstack[0] = ct_Dir_StackEmpty;
ctx->dirstack[1] = ct_Dir_LeftToRight;
ctx->dirsp = 1;
#endif
ctx->encoding = NULL;
ctx->encodinglen = 0;
ctx->item = NULL;
ctx->itemlen = 0;
ctx->version = CTVERSION;
ctx->gl_charset = CS_ISO8859_1;
ctx->gl_charset_size = 94;
ctx->gl_octets_per_char = 1;
ctx->gr_charset = CS_ISO8859_1;
ctx->gr_charset_size = 96;
ctx->gr_octets_per_char = 1;
ctx->xmstring = NULL;
ctx->xmsep = NULL;
ctx->xmtab = NULL;
/*
** check for version/ignore extensions sequence (must be first if present)
** Format is: ESC 02/03 V 03/00 ignoring extensions is OK
** ESC 02/03 V 03/01 ignoring extensions is not OK
** where V is in the range 02/00 thru 02/15 and represents versions 1 thru 16
*/
if ( (from->size >= 4)
&& (ctx->octet[0] == ESC)
&& (ctx->octet[1] == 0x23)
&& (_IsInColumn2(ctx->octet[2])
&& ((ctx->octet[3] == 0x30) || ctx->octet[3] == 0x31))
) {
ctx->version = ctx->octet[2] - 0x1f; /* 0x20-0x2f => version 1-16 */
if (ctx->octet[3] == 0x30) /* 0x30 == can ignore extensions */
ctx->flags.ignext = True;
ctx->octet += 4; /* advance ptr to next seq */
}
while (ctx->octet < ctx->lastoctet) {
switch (*ctx->octet) { /* look at next octet in seq */
case ESC:
/* %%% TEMP
** if we have any text to output, do it
** this section needs to be optimized so that it handles
** paired character sets without outputting a new segment.
*/
if (ctx->flags.text) {
outputXmString(ctx, False); /* with no separator */
}
ctx->flags.text = False;
ctx->item = ctx->octet; /* remember start of this item */
ctx->itemlen = 0;
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
/* scan for final char */
while ( (ctx->octet != ctx->lastoctet)
&& (_IsInColumn2(*ctx->octet)) ) {
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
}
if (ctx->octet == ctx->lastoctet) { /* if nothing after this, it's an error */
ok = False;
break;
}
c = *ctx->octet; /* get next char in seq */
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
if (_IsValidESCFinal(c)) {
/* we have a valid ESC sequence - handle it */
ok = processESC(ctx, c);
} else {
ok = False;
}
if (ok) {
ctx->encoding = ctx->item;
ctx->encodinglen = ctx->itemlen;
}
break;
case CSI:
/*
** CSI format is: CSI P I F where
** 03/00 <= P <= 03/15
** 02/00 <= I <= 02/15
** 04/00 <= F <= 07/14
*/
/* %%% TEMP
** if we have any text to output, do it
** This may need optimization.
*/
if (ctx->flags.text) {
/* check whether we have a specific direction set */
if (((ctx->octet[1] == 0x31) && (ctx->octet[2] == 0x5d))||
((ctx->octet[1] == 0x32) && (ctx->octet[2] == 0x5d))||
(ctx->octet[1] == 0x5d))
outputXmString(ctx, False); /* without a separator*/
else
outputXmString(ctx, True); /* with a separator */
}
ctx->flags.text = False;
ctx->item = ctx->octet; /* remember start of this item */
ctx->itemlen = 0;
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
/* scan for final char */
while ( (ctx->octet != ctx->lastoctet)
&& _IsInColumn3(*ctx->octet) ) {
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
}
while ( (ctx->octet != ctx->lastoctet)
&& _IsInColumn2(*ctx->octet) ) {
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
}
/* if nothing after this, it's an error */
if (ctx->octet == ctx->lastoctet) {
ok = False;
break;
}
c = *ctx->octet; /* get next char in seq */
ctx->octet++; ctx->itemlen++; /* advance ptr to next char */
if (_IsValidCSIFinal(c)) {
/* we have a valid CSI sequence - handle it */
ok = processCSI(ctx, c);
} else {
ok = False;
}
break;
case NL: /* new line */
/* if we have any text to output, do it */
if (ctx->flags.text) {
outputXmString(ctx, True); /* with a separator */
ctx->flags.text = False;
} else {
if (ctx->xmsep == NULL) {
ctx->xmsep = XmStringSeparatorCreate();
}
ctx->xmstring = XmStringConcatAndFree(ctx->xmstring,
XmStringCopy(ctx->xmsep));
}
ctx->octet++; /* advance ptr to next char */
break;
case HT:
/* if we have any text to output, do it */
if (ctx->flags.text) {
outputXmString(ctx, False);
ctx->flags.text = False;
}
if (ctx->xmtab == NULL) {
ctx->xmtab = XmStringComponentCreate(XmSTRING_COMPONENT_TAB, 0,
NULL);
}
ctx->xmstring = XmStringConcatAndFree(ctx->xmstring,
XmStringCopy(ctx->xmtab));
ctx->octet++; /* advance ptr to next char */
break;
default: /* just 'normal' text */
ctx->item = ctx->octet; /* remember start of this item */
ctx->itemlen = 0;
ctx->flags.text = True;
while (ctx->octet < ctx->lastoctet) {
c = *ctx->octet;
if ((c == ESC) || (c == CSI) || (c == NL) || (c == HT)) {
break;
}
if ( (_IsInC0Set(c) && (!_IsValidC0(ctx, c)))
|| (_IsInC1Set(c) && (!_IsValidC1(ctx, c))) ) {
ok = False;
break;
}
ctx->flags.gchar = True; /* We have a character! */
/*
* We should look at the actual character to
* decide whether it's a gl or gr character.
*
* We'll hit the problem if we get a CT that
* isn't generated by Motif.
*/
if (isascii((unsigned char)c)) {
ctx->octet += ctx->gl_octets_per_char;
ctx->itemlen += ctx->gl_octets_per_char;
} else {
ctx->octet += ctx->gr_octets_per_char;
ctx->itemlen += ctx->gr_octets_per_char;
}
if (ctx->octet > ctx->lastoctet) {
ok = False;
break;
}
} /* end while */
break;
} /* end switch */
if (!ok) break;
} /* end while */
/* if we have any text left to output, do it */
if (ctx->flags.text) {
outputXmString(ctx, False); /* with no separator */
}
XtFree((char *) ctx->dirstack);
if (ctx->xmstring != NULL) {
to->addr = (char *) ctx->xmstring;
to->size = sizeof(XmString);
}
if (ctx->xmsep != NULL) XmStringFree(ctx->xmsep);
if (ctx->xmtab != NULL) XmStringFree(ctx->xmtab);
XtFree((char *) ctx);
return (ok);
}
static char **
cvtCTsegment(ct_context *ctx,
OctetPtr item,
unsigned int length)
{
XTextProperty tmp_prop;
OctetPtr octets;
Boolean free_octets = False;
int count;
int ret_val;
char **strings = NULL;
if (ctx->encoding) {
if (ctx->encoding + ctx->encodinglen != item) {
octets =
(OctetPtr)XtMalloc((ctx->encodinglen + length) * sizeof(Octet));
memcpy((char *)octets, (char *)ctx->encoding, ctx->encodinglen);
memcpy((char *)(octets + ctx->encodinglen), (char *)item, length);
free_octets = True;
} else {
octets = ctx->encoding;
}
} else {
octets = ctx->item;
}
tmp_prop.value = octets;
tmp_prop.encoding = XInternAtom(_XmGetDefaultDisplay(),
XmSCOMPOUND_TEXT, False);
tmp_prop.format = 8;
tmp_prop.nitems = ctx->encodinglen + length;
ret_val = XmbTextPropertyToTextList(_XmGetDefaultDisplay(),
&tmp_prop,
&strings,
&count);
if (ret_val > 0) {
XFreeStringList(strings);
strings = NULL;
}
if (free_octets)
XtFree((char *)octets);
return strings;
}
/* outputXmString */
static void
outputXmString(
ct_context *ctx,
#if NeedWidePrototypes
int separator )
#else
Boolean separator )
#endif /* NeedWidePrototypes */
{
char **strings = NULL;
/*
* CR # 8544: XmbTextListToTextProperty converts from locale encoding
* to MIT registered encodings. We have to convert back - UNLESS the
* CT was not created with XmbTextListToTextProperty. However, there
* is no way to tell how we got the CT, but in most cases, the
* tag will be FONTLIST_DEFAULT_TAG, and then we want to do this. So
* we try this, and only use the encoding tags if we could not convert.
*/
strings = cvtCTsegment(ctx, ctx->item, ctx->itemlen);
if (strings) {
ctx->xmstring = concatStringToXmString
(ctx->xmstring,
strings[0],
strlen(strings[0]),
XmFONTLIST_DEFAULT_TAG,
(XmStringDirection) ((_CurDir(ctx) == ct_Dir_LeftToRight) ?
XmSTRING_DIRECTION_L_TO_R :
((_CurDir(ctx) == ct_Dir_RightToLeft) ?
XmSTRING_DIRECTION_R_TO_L :
XmSTRING_DIRECTION_UNSET)),
separator );
XFreeStringList(strings);
return;
}
/* If we couldn't convert to locale encoding... */
/* This is not really right. We can probably never draw this string and
get something that looks right out of this */
/*
* If the GL charset is ISO8859-1, and the GR charset is any ISO8859
* charset, then they're a pair, so we can create a single segment using
* just the GR charset.
*
* If GL and GR are multibyte charsets and they match (both GB2312 or both
* KSC5601) except for JISX0208, then we can create a single segment using
* just the GR charset. If GL and GR are multibyte charsets and they DON'T
* match, or if GL or GR is multibyte and the other is singlebyte, then
* there's no way to tell which characters belong to GL and which to GR,
* so treat it like a non-Latin1 in GL - 7 bit characters go to GL, 8 bit
* characters to to GR. *** THIS APPEARS TO BE A HOLE IN THE COMPOUND
* TEXT SPEC ***.
*
* Otherwise the charsets are not a pair and we will switch between GL
* and GR segments each time the high bit changes.
*/
if (((ctx->gl_charset == CS_ISO8859_1)
&&
((ctx->gr_charset == CS_ISO8859_1) ||
(ctx->gr_charset == CS_ISO8859_2) ||
(ctx->gr_charset == CS_ISO8859_3) ||
(ctx->gr_charset == CS_ISO8859_4) ||
(ctx->gr_charset == CS_ISO8859_5) ||
(ctx->gr_charset == CS_ISO8859_6) ||
(ctx->gr_charset == CS_ISO8859_7) ||
(ctx->gr_charset == CS_ISO8859_8) ||
(ctx->gr_charset == CS_ISO8859_9)))
||
((ctx->gl_charset == CS_GB2312_0) &&
(ctx->gr_charset == CS_GB2312_1))
||
((ctx->gl_charset == CS_KSC5601_0) &&
(ctx->gr_charset == CS_KSC5601_1)))
{
/* OK to do single segment output but always use GR charset */
ctx->xmstring = concatStringToXmString
(ctx->xmstring,
(char *) ctx->item,
ctx->itemlen,
(char *) ctx->gr_charset,
(XmStringDirection) ((_CurDir(ctx) == ct_Dir_LeftToRight) ?
XmSTRING_DIRECTION_L_TO_R :
((_CurDir(ctx) == ct_Dir_RightToLeft) ?
XmSTRING_DIRECTION_R_TO_L :
XmSTRING_DIRECTION_UNSET)),
separator );
}
else
{
/* have to create a new segment everytime the highbit changes */
unsigned int j = 0;
unsigned int start = 0;
Octet c;
Boolean curseg_is_gl;
curseg_is_gl = isascii((unsigned char)ctx->item[0]);
while (j < ctx->itemlen)
{
c = ctx->item[j];
if (isascii((unsigned char)c))
{
if (!curseg_is_gl)
{
/* output gr string */
assert(j > start);
ctx->xmstring = concatStringToXmString
(ctx->xmstring,
(char *)ctx->item + start,
j - start,
(char *) ctx->gr_charset,
(XmStringDirection)
((_CurDir(ctx) == ct_Dir_LeftToRight) ?
XmSTRING_DIRECTION_L_TO_R :
((_CurDir(ctx) == ct_Dir_RightToLeft) ?
XmSTRING_DIRECTION_R_TO_L :
XmSTRING_DIRECTION_UNSET)),
False );
start = j;
curseg_is_gl = True; /* start gl segment */
};
j++;
}
else
{
if (curseg_is_gl)
{
/* output gl string */
assert(j > start);
ctx->xmstring = concatStringToXmString
(ctx->xmstring,
(char *)ctx->item + start,
j - start,
(char *) ctx->gl_charset,
(XmStringDirection)
((_CurDir(ctx) == ct_Dir_LeftToRight) ?
XmSTRING_DIRECTION_L_TO_R :
((_CurDir(ctx) == ct_Dir_RightToLeft) ?
XmSTRING_DIRECTION_R_TO_L :
XmSTRING_DIRECTION_UNSET)),
False );
start = j;
curseg_is_gl = False; /* start gr segment */
};
j++;
}; /* end if */
}; /* end while */
/* output last segment */
ctx->xmstring = concatStringToXmString
(ctx->xmstring,
(char *)ctx->item + start,
ctx->itemlen - start,
(char *) ((curseg_is_gl) ?
ctx->gl_charset :
ctx->gr_charset ),
(XmStringDirection) ((_CurDir(ctx) == ct_Dir_LeftToRight) ?
XmSTRING_DIRECTION_L_TO_R :
((_CurDir(ctx) == ct_Dir_RightToLeft) ?
XmSTRING_DIRECTION_R_TO_L :
XmSTRING_DIRECTION_UNSET)),
False );
if (separator)
{
if (ctx->xmsep == NULL)
{
ctx->xmsep = XmStringSeparatorCreate();
};
ctx->xmstring = XmStringConcatAndFree(ctx->xmstring,
XmStringCopy(ctx->xmsep));
};
}; /* end if paired */
}
static XmString
concatStringToXmString(
XmString compoundstring,
char *textstring,
int textlen,
char *charset,
#if NeedWidePrototypes
int direction,
int separator )
#else
XmStringDirection direction,
Boolean separator )
#endif /* NeedWidePrototypes */
{
XmString tempxm1;
tempxm1 =
XmStringConcatAndFree(XmStringDirectionCreate(direction),
_XmStringNCreate(textstring, charset, textlen));
if (separator)
tempxm1 = XmStringConcatAndFree(tempxm1,
XmStringSeparatorCreate());
compoundstring = XmStringConcatAndFree(compoundstring, tempxm1);
return (compoundstring);
}
/* processESC - handle valid ESC sequences */
static Boolean
processESC(
ct_context *ctx,
#if NeedWidePrototypes
int final )
#else
Octet final )
#endif /* NeedWidePrototypes */
{
Boolean ok;
switch (ctx->item[1]) {
case 0x24: /* 02/04 - invoke 94(n) charset into GL or GR */
ok = process94n(ctx, final);
break;
case 0x25: /* 02/05 - extended segments */
/* if we have any text to output, do it */
if (ctx->flags.text) {
outputXmString(ctx, False); /* with no separator */
ctx->flags.text = False;
}
ok = processExtendedSegments(ctx, final);
break;
case 0x28: /* 02/08 - invoke 94 charset into GL */
ok = process94GL(ctx, final);
break;
case 0x29: /* 02/09 - invoke 94 charset into GR */
ok = process94GR(ctx, final);
break;
case 0x2d: /* 02/13 - invoke 96 charset into GR */
ok = process96GR(ctx, final);
break;
default:
ok = False;
break;
}
return(ok);
}
/*
** processCSI - handle valid CSI sequences
** CSI sequences
** 09/11 03/01 05/13 begin left-to-right text
** 09/11 03/02 05/13 begin right-to-left text
** 09/11 05/13 end of string
** 09/11 P I F reserved for use in future extensions
*/
static Boolean
processCSI(
ct_context *ctx,
#if NeedWidePrototypes
int final )
#else
Octet final )
#endif /* NeedWidePrototypes */
{
Boolean ok = True;
switch (final) {
case 0x5d: /* end of direction sequence */
switch (ctx->item[1]) {
case 0x31: /* start left to right */
if (ctx->flags.gchar && ctx->dirsp == 0) {
ok = False;
} else {
_PushDir(ctx, ct_Dir_LeftToRight);
}
break;
case 0x32: /* start right to left */
if (ctx->flags.gchar && ctx->dirsp == 0) {
ok = False;
} else {
_PushDir(ctx, ct_Dir_RightToLeft);
}
break;
case 0x5d: /* Just CSI EOS - revert */
if (ctx->dirsp > 0) {
_PopDir(ctx);
} else {
ok = False;
}
break;
default: /* anything else is an error */
ok = False;
}
break;
default: /* reserved for future extensions */
ok = False;
break;
}
return(ok);
}
static Boolean
processExtendedSegments(
ct_context *ctx,
#if NeedWidePrototypes
int final )
#else
Octet final )
#endif /* NeedWidePrototypes */
{
OctetPtr esptr; /* ptr into ext seg */
unsigned int seglen; /* length of ext seg */
unsigned int len; /* length */
String charset_copy; /* ptr to NULL-terminated copy of ext seg charset */
OctetPtr text_copy; /* ptr to NULL-terminated copy of ext seg text */
XmString tempxm1;
Boolean ok = True;
/* Extended segments
** 01/11 02/05 02/15 03/00 M L variable # of octets/char
** 01/11 02/05 02/15 03/01 M L 1 octet/char
** 01/11 02/05 02/15 03/02 M L 2 octets/char
** 01/11 02/05 02/15 03/03 M L 3 octets/char
** 01/11 02/05 02/15 03/04 M L 4 octets/char
*/
if ( (ctx->itemlen == 4)
&& (ctx->item[2] == 0x2f)
&& (_IsInColumn3(final))
) {
if ( ((ctx->lastoctet - ctx->octet) < 2)
|| (ctx->octet[0] < 0x80)
|| (ctx->octet[1] < 0x80)
) {
return(False);
}
/*
** The most significant bit of M and L are always set to 1
** The number is computed as ((M-128)*128)+(L-128)
*/
seglen = *ctx->octet - 0x80;
ctx->octet++; ctx->itemlen++; /* advance pointer */
seglen = (seglen << 7) + (*ctx->octet - 0x80);
ctx->octet++; ctx->itemlen++; /* advance pointer */
if ((ctx->lastoctet - ctx->octet) < seglen) {
return(False);
}
esptr = ctx->octet; /* point to charset */
ctx->itemlen += seglen; /* advance pointer over segment */
ctx->octet += seglen;
switch (final) {
case 0x30: /* variable # of octets per char */
case 0x31: /* 1 octet per char */
case 0x32: /* 2 octets per char */
/* scan for STX separator between charset and text */
len = 0;
while (esptr[len] != STX)
len++;
if (len > ctx->itemlen) { /* if we ran off the end, error */
ok = False;
break;
}
charset_copy = XtMalloc(len + 1);
strncpy(charset_copy, (char *) esptr, len);
charset_copy[len] = EOS;
esptr += len + 1; /* point to text part */
len = seglen - len - 1; /* calc length of text part */
text_copy = (unsigned char *) XtMalloc(len + 1);
memcpy( text_copy, esptr, len);
text_copy[len] = EOS;
tempxm1 = XmStringConcatAndFree(
XmStringDirectionCreate((_CurDir(ctx) ==
ct_Dir_LeftToRight ?
XmSTRING_DIRECTION_L_TO_R :
(_CurDir(ctx) ==
ct_Dir_RightToLeft ?
XmSTRING_DIRECTION_R_TO_L :
XmSTRING_DIRECTION_UNSET))),
XmStringCreate((char *)text_copy, charset_copy));
ctx->xmstring = XmStringConcatAndFree(ctx->xmstring, tempxm1);
XtFree((char *) text_copy);
XtFree(charset_copy);
ok = True;
break;
case 0x33: /* 3 octets per char */
case 0x34: /* 4 octets per char */
/* not supported */
ok = False;
break;
default:
/* reserved for future use */
ok = False;
break;
} /* end switch */
} /* end if */
return(ok);
}
static Boolean
process94n(
ct_context *ctx,
#if NeedWidePrototypes
int final )
#else
Octet final )
#endif /* NeedWidePrototypes */
{
if (ctx->itemlen > 3) {
switch (ctx->item[2]) {
case 0x28: /* into GL */
switch (final) {
case 0x41: /* 04/01 - China (PRC) Hanzi */
_SetGL(ctx, CS_GB2312_0, 94, 2);
break;
case 0x42: /* 04/02 - Japanese GCS, level 2 */
_SetGL(ctx, CS_JISX0208_0, 94, 2);
break;
case 0x43: /* 04/03 - Korean GCS */
_SetGL(ctx, CS_KSC5601_0, 94, 2);
break;
default:
/* other character sets are not supported */
return False;
} /* end switch (final) */
break;
case 0x29: /* into GR */
switch (final) {
case 0x41: /* 04/01 - China (PRC) Hanzi */
_SetGR(ctx, CS_GB2312_1, 94, 2);
break;
case 0x42: /* 04/02 - Japanese GCS, level 2 */
_SetGR(ctx, CS_JISX0208_1, 94, 2);
break;
case 0x43: /* 04/03 - Korean GCS */
_SetGR(ctx, CS_KSC5601_1, 94, 2);
break;
default:
/* other character sets are not supported */
return False;
} /* end switch (final) */
break;
default:
/* error */
return False;
} /* end switch item[2] */
}
else {
/* error */
return False;
} /* end if */
return True;
}
static Boolean
process94GL(
ct_context *ctx,
#if NeedWidePrototypes
int final )
#else
Octet final )
#endif /* NeedWidePrototypes */
{
switch (final) {
case 0x42: /* 04/02 - Left half, ISO8859* (ASCII) */
_SetGL(ctx, CS_ISO8859_1, 94, 1);
break;
case 0x4a: /* 04/10 - Left half, Katakana */
_SetGL(ctx, CS_JISX0201, 94, 1);
break;
default:
return False;
}
return(True);
}
static Boolean
process94GR(
ct_context *ctx,
#if NeedWidePrototypes
int final )
#else
Octet final )
#endif /* NeedWidePrototypes */
{
switch (final) {
case 0x49: /* 04/09 - Right half, Katakana */
_SetGR(ctx, CS_JISX0201, 94, 1);
break;
default:
return False;
}
return(True);
}
static Boolean
process96GR(
ct_context *ctx,
#if NeedWidePrototypes
int final )
#else
Octet final )
#endif /* NeedWidePrototypes */
{
switch (final) {
case 0x40: /* 04/00 - Right half, IR-111 */
_SetGR(ctx, CS_ISO_IR_111, 96, 1);
break;
case 0x41: /* 04/01 - Right half, Latin 1 */
_SetGR(ctx, CS_ISO8859_1, 96, 1);
break;
case 0x42: /* 04/02 - Right half, Latin 2 */
_SetGR(ctx, CS_ISO8859_2, 96, 1);
break;
case 0x43: /* 04/03 - Right half, Latin 3 */
_SetGR(ctx, CS_ISO8859_3, 96, 1);
break;
case 0x44: /* 04/04 - Right half, Latin 4 */
_SetGR(ctx, CS_ISO8859_4, 96, 1);
break;
case 0x46: /* 04/06 - Right half, Latin/Greek */
_SetGR(ctx, CS_ISO8859_7, 96, 1);
break;
case 0x47: /* 04/07 - Right half, Latin/Arabic */
_SetGR(ctx, CS_ISO8859_6, 96, 1);
break;
case 0x48: /* 04/08 - Right half, Latin/Hebrew */
_SetGR(ctx, CS_ISO8859_8, 96, 1);
break;
case 0x4c: /* 04/12 - Right half, Latin/Cyrillic */
_SetGR(ctx, CS_ISO8859_5, 96, 1);
break;
case 0x4d: /* 04/13 - Right half, Latin 5 */
_SetGR(ctx, CS_ISO8859_9, 96, 1);
break;
default:
return False;
}
return(True);
}
/************************************************************************
*
* XmCvtXmStringToCT
* Convert an XmString to a compound text string directly.
* This is the public version of the resource converter and only
* requires the XmString as an argument.
*
************************************************************************/
char *
XmCvtXmStringToCT(
XmString string )
{
Boolean ok;
/* Dummy up some XrmValues to pass to cvtXmStringToText. */
XrmValue from_val;
XrmValue to_val;
if (string == NULL)
return ( (char *) NULL );
from_val.addr = (char *) string;
ok = cvtXmStringToText(&from_val, &to_val);
if (!ok)
{
XtWarningMsg( "conversionError","compoundText", "XtToolkitError",
MSG8, NULL, NULL) ;
return( (char *) NULL ) ;
}
return( (char *) to_val.addr) ;
}
#ifdef UTF8_SUPPORTED
/************************************************************************
*
* XmCvtXmStringToUTF8String
* Convert an XmString to a compound utf8 string directly.
* This is the public version of the resource converter and only
* requires the XmString as an argument.
*
************************************************************************/
char *
XmCvtXmStringToUTF8String(
XmString string )
{
Boolean ok;
/* Dummy up some XrmValues to pass to cvtXmStringToText. */
XrmValue from_val;
XrmValue to_val;
if (string == NULL)
return ( (char *) NULL );
from_val.addr = (char *) string;
ok = cvtXmStringToUTF8String(&from_val, &to_val);
if (!ok)
{
XtWarningMsg( "conversionError","compoundText", "XtToolkitError",
MSG8, NULL, NULL) ;
return( (char *) NULL ) ;
}
return( (char *) to_val.addr) ;
}
#endif
/***************************************************************************
* *
* _XmConvertCSToString - Converts compound string to corresponding *
* STRING if it can be fully converted. Otherwise returns NULL. *
* *
***************************************************************************/
/*ARGSUSED*/
char *
_XmConvertCSToString(XmString cs) /* unused */
{
return((char *)NULL);
}
/***************************************************************************
* *
* _XmCvtXmStringToCT - public wrapper for the widgets to use. *
* This returns the length info as well - critical for the list widget *
* *
***************************************************************************/
Boolean
_XmCvtXmStringToCT(
XrmValue *from,
XrmValue *to )
{
return (cvtXmStringToText( from, to ));
}
#ifdef UTF8_SUPPORTED
/***************************************************************************
* *
* _XmCvtXmStringToUTF8String - public wrapper for the widgets to use. *
* This returns the length info as well - critical for the list widget *
* *
***************************************************************************/
Boolean
_XmCvtXmStringToUTF8String(
XrmValue *from,
XrmValue *to )
{
return (cvtXmStringToUTF8String( from, to ));
}
#endif
/************************************************************************
*
* XmCvtXmStringToText
* Convert an XmString to an ASCII string.
*
************************************************************************/
/*ARGSUSED*/
Boolean
XmCvtXmStringToText(
Display *display,
XrmValuePtr args, /* unused */
Cardinal *num_args, /* unused */
XrmValue *from_val,
XrmValue *to_val,
XtPointer *converter_data ) /* unused */
{
Boolean ok;
if (from_val->addr == NULL)
return( FALSE) ;
ok = cvtXmStringToText(from_val, to_val);
if (!ok)
{
XtAppWarningMsg(XtDisplayToApplicationContext(display),
"conversionError","compoundText", "XtToolkitError",
MSG14, (String *)NULL, (Cardinal *)NULL);
}
return(ok);
}
#ifdef UTF8_SUPPORTED
/************************************************************************
*
* cvtXmStringToUTF8String
* Convert an XmString to a compound text string. This is the
* underlying conversion routine for XmCvtXmStringToUTF8String,
* _XmCvtXmStringToUTF8String.
*
************************************************************************/
static Boolean
cvtXmStringToUTF8String(
XrmValue *from,
XrmValue *to )
{
Boolean ok;
OctetPtr outc = NULL;
unsigned int outlen = 0;
_XmStringContextRec stack_context;
XmStringCharSet ct_encoding = NULL, cset_save = NULL;
ct_Direction prev_direction = ct_Dir_LeftToRight;
ct_Charset prev_charset = cs_Latin1;
XmStringComponentType comp;
unsigned int len;
XtPointer val = NULL;
Octet tmp_buf[256];
OctetPtr tmp;
/* Initialize the return parameters. */
to->addr = (XPointer) NULL;
to->size = 0;
if (!from->addr)
return(False);
_XmStringContextReInit(&stack_context, (XmString) from->addr);
/* BEGIN OSF Fix CR 7403 */
while ((comp = XmeStringGetComponent(&stack_context, True, False,
&len, &val)) !=
XmSTRING_COMPONENT_END)
{
switch (comp)
{
case XmSTRING_COMPONENT_LOCALE_TEXT:
cset_save = XmFONTLIST_DEFAULT_TAG;
/* Fall through */
case XmSTRING_COMPONENT_TEXT:
if (cset_save != NULL) {
/* Check Registry */
if (ct_encoding)
XtFree((char *)ct_encoding);
ct_encoding = XmMapSegmentEncoding(cset_save);
}
/* We must duplicate val because the routines we want to */
/* call don't take a length parameter. */
tmp = (OctetPtr) XmStackAlloc(len + 1, tmp_buf);
memcpy((char*)tmp, val, len);
tmp[len] = EOS;
if (ct_encoding != NULL) {
/* We have a mapping. */
ok = processCharsetAndTextUtf8(ct_encoding, tmp, FALSE,
&outc, &outlen, &prev_charset);
} else {
/* No mapping. Vendor dependent. */
ok = processCharsetAndTextUtf8(cset_save, tmp, FALSE,
&outc, &outlen,
&prev_charset);
}
/* Free our local copy of val. */
XmStackFree((char*) tmp, tmp_buf);
if (!ok)
{
_XmStringContextFree(&stack_context);
return(False);
}
break;
case XmSTRING_COMPONENT_CHARSET:
cset_save = (XmStringCharSet)val;
break;
case XmSTRING_COMPONENT_DIRECTION:
/* Output the direction, if changed */
if (*(XmStringDirection *)val == XmSTRING_DIRECTION_L_TO_R) {
if (prev_direction != ct_Dir_LeftToRight) {
outc = ctextConcat(outc, outlen,
(unsigned char *) UTF8_L_TO_R,
(unsigned int)UTF8_L_TO_R_LEN);
outlen += UTF8_L_TO_R_LEN;
prev_direction = ct_Dir_LeftToRight;
}
} else {
if (prev_direction != ct_Dir_RightToLeft) {
outc = ctextConcat(outc, outlen,
(unsigned char *) UTF8_R_TO_L,
(unsigned int)UTF8_R_TO_L_LEN);
outlen += UTF8_R_TO_L_LEN;
prev_direction = ct_Dir_RightToLeft;
}
};
break;
case XmSTRING_COMPONENT_SEPARATOR:
if (ct_encoding != NULL) { /* We have a mapping. */
ok = processCharsetAndTextUtf8(ct_encoding, NULL, TRUE,
&outc, &outlen, &prev_charset);
}
else
{
/* No mapping. Vendor dependent. */
ok = processCharsetAndTextUtf8(cset_save, NULL, TRUE,
&outc, &outlen, &prev_charset);
}
if (!ok)
{
_XmStringContextFree(&stack_context);
return(False);
}
break;
case XmSTRING_COMPONENT_TAB:
outc = ctextConcat(outc, outlen,
(unsigned char *)UTF8_TABSTRING,
(unsigned int)UTF8_TABSTRING_LEN);
outlen++;
break;
default:
/* Just ignore it. */
break;
}
} /* end while */
if (ct_encoding)
XtFree((char *)ct_encoding);
/* END OSF Fix CR 7403 */
if (outc != NULL) {
to->addr = (char *) outc;
to->size = outlen;
}
_XmStringContextFree(&stack_context);
return(True);
}
#endif
/************************************************************************
*
* cvtXmStringToText
* Convert an XmString to a compound text string. This is the
* underlying conversion routine for XmCvtXmStringToCT,
* _XmCvtXmStringToCT, and XmCvtXmStringToText.
*
************************************************************************/
static Boolean
cvtXmStringToText(
XrmValue *from,
XrmValue *to )
{
Boolean ok;
OctetPtr outc = NULL;
unsigned int outlen = 0;
_XmStringContextRec stack_context;
XmStringCharSet ct_encoding = NULL, cset_save = NULL;
/*
* Define XLIB_HANDLES_DIRECTION if vendor's X library knows how
* to deal with direction control sequences in CT. Otherwise
* no such beasts will be output if there are no Rtol segments
* in the XmString. Note that the MIT sample implementation
* does not deal with direction control sequences...
*/
#ifdef XLIB_HANDLES_DIRECTION
ct_Direction prev_direction = ct_Dir_Undefined;
#else
ct_Direction prev_direction = ct_Dir_LeftToRight;
#endif
ct_Charset prev_charset = cs_Latin1;
XmStringComponentType comp;
unsigned int len;
XtPointer val = NULL;
Octet tmp_buf[256];
OctetPtr tmp;
/* Initialize the return parameters. */
to->addr = (XPointer) NULL;
to->size = 0;
if (!from->addr)
return(False);
_XmStringContextReInit(&stack_context, (XmString) from->addr);
/* BEGIN OSF Fix CR 7403 */
while ((comp = XmeStringGetComponent(&stack_context, True, False,
&len, &val)) !=
XmSTRING_COMPONENT_END)
{
switch (comp)
{
case XmSTRING_COMPONENT_LOCALE_TEXT:
cset_save = XmFONTLIST_DEFAULT_TAG;
/* Fall through */
case XmSTRING_COMPONENT_TEXT:
if (cset_save != NULL) {
/* Check Registry */
if (ct_encoding)
XtFree((char *)ct_encoding);
ct_encoding = XmMapSegmentEncoding(cset_save);
}
/* We must duplicate val because the routines we want to */
/* call don't take a length parameter. */
tmp = (OctetPtr) XmStackAlloc(len + 1, tmp_buf);
memcpy((char*)tmp, val, len);
tmp[len] = EOS;
if (ct_encoding != NULL) {
/* We have a mapping. */
ok = processCharsetAndText(ct_encoding, tmp, FALSE,
&outc, &outlen, &prev_charset);
} else {
/* No mapping. Vendor dependent. */
ok = _XmOSProcessUnmappedCharsetAndText(cset_save, tmp, FALSE,
&outc, &outlen,
&prev_charset);
}
/* Free our local copy of val. */
XmStackFree((char*) tmp, tmp_buf);
if (!ok)
{
_XmStringContextFree(&stack_context);
return(False);
}
break;
case XmSTRING_COMPONENT_CHARSET:
cset_save = (XmStringCharSet)val;
break;
case XmSTRING_COMPONENT_DIRECTION:
/* Output the direction, if changed */
if (*(XmStringDirection *)val == XmSTRING_DIRECTION_L_TO_R) {
if (prev_direction != ct_Dir_LeftToRight) {
outc = ctextConcat(outc, outlen,
(unsigned char *) CTEXT_L_TO_R,
(unsigned int)CTEXT_L_TO_R_LEN);
outlen += CTEXT_L_TO_R_LEN;
prev_direction = ct_Dir_LeftToRight;
}
} else {
if (prev_direction != ct_Dir_RightToLeft) {
outc = ctextConcat(outc, outlen,
(unsigned char *) CTEXT_R_TO_L,
(unsigned int)CTEXT_R_TO_L_LEN);
outlen += CTEXT_R_TO_L_LEN;
prev_direction = ct_Dir_RightToLeft;
}
};
break;
case XmSTRING_COMPONENT_SEPARATOR:
if (ct_encoding != NULL) { /* We have a mapping. */
ok = processCharsetAndText(ct_encoding, NULL, TRUE,
&outc, &outlen, &prev_charset);
}
else
{
/* No mapping. Vendor dependent. */
ok = _XmOSProcessUnmappedCharsetAndText(cset_save, NULL, TRUE,
&outc, &outlen, &prev_charset);
}
if (!ok)
{
_XmStringContextFree(&stack_context);
return(False);
}
break;
case XmSTRING_COMPONENT_TAB:
outc = ctextConcat(outc, outlen,
(unsigned char *)TABSTRING,
(unsigned int)TABSTRING_LEN);
outlen++;
break;
default:
/* Just ignore it. */
break;
}
} /* end while */
if (ct_encoding)
XtFree((char *)ct_encoding);
/* END OSF Fix CR 7403 */
if (outc != NULL) {
to->addr = (char *) outc;
to->size = outlen;
}
_XmStringContextFree(&stack_context);
return(True);
}
#ifdef UTF8_SUPPORTED
static Boolean
processCharsetAndTextUtf8(XmStringCharSet tag,
OctetPtr ctext,
#if NeedWidePrototypes
int separator,
#else
Boolean separator,
#endif /* NeedWidePrototypes */
OctetPtr *outc,
unsigned int *outlen,
ct_Charset *prev)
{
unsigned int ctlen = 0, len;
if (strcmp(tag, XmFONTLIST_DEFAULT_TAG) == 0) {
if (_XmStringIsCurrentCharset("UTF-8")) {
if (ctext)
ctlen = strlen((char *)ctext);
if (ctlen > 0) {
*outc = ctextConcat(*outc, *outlen, ctext, ctlen);
*outlen += ctlen;
};
} else {
XTextProperty prop_rtn;
int ret_val;
String msg;
/* Call XmbTextListToTextProperty */
ret_val =
XmbTextListToTextProperty(_XmGetDefaultDisplay(),
(char **)&ctext,
1, XUTF8StringStyle, &prop_rtn);
if (ret_val) {
switch (ret_val) {
case XNoMemory:
msg = MSG9;
break;
case XLocaleNotSupported:
msg = MSG10;
break;
default:
msg = MSG11;
break;
}
XtWarningMsg("conversionError", "textProperty",
"XtToolkitError", msg, NULL, 0);
return(False);
}
ctlen = strlen((char *)prop_rtn.value);
/* Now copy in the text */
if (ctlen > 0) {
*outc = ctextConcat(*outc, *outlen, prop_rtn.value, ctlen);
*outlen += ctlen;
};
XFree(prop_rtn.value);
}
/* Finally, add the separator if any */
if (separator) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)UTF8_NEWLINESTRING,
(unsigned int)UTF8_NEWLINESTRING_LEN);
(*outlen)++;
};
*prev = cs_none;
return(True);
}
if (ctext)
ctlen = strlen((char *)ctext);
/* Now copy in the text */
if (ctlen > 0) {
char *text = Convert((char *)ctext, ctlen, "UTF-8", tag);
if (text == NULL) return(False);
*outc = ctextConcat(*outc, *outlen, (const_OctetPtr)text, strlen(text));
*outlen += ctlen;
XtFree(text);
};
/* Finally, add the separator if any */
if (separator) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)UTF8_NEWLINESTRING,
(unsigned int)UTF8_NEWLINESTRING_LEN);
(*outlen)++;
}
return(True);
}
#endif
static Boolean
processCharsetAndText(XmStringCharSet tag,
OctetPtr ctext,
#if NeedWidePrototypes
int separator,
#else
Boolean separator,
#endif /* NeedWidePrototypes */
OctetPtr *outc,
unsigned int *outlen,
ct_Charset *prev)
{
unsigned int ctlen = 0, len;
if (strcmp(tag, CS_UTF_8) == 0)
tag = XmFONTLIST_DEFAULT_TAG;
if (strcmp(tag, XmFONTLIST_DEFAULT_TAG) == 0)
{
XTextProperty prop_rtn;
int ret_val;
String msg;
/* Call XmbTextListToTextProperty */
ret_val =
XmbTextListToTextProperty(_XmGetDefaultDisplay(), (char **)&ctext,
1, XCompoundTextStyle, &prop_rtn);
if (ret_val)
{
switch (ret_val)
{
case XNoMemory:
msg = MSG9;
break;
case XLocaleNotSupported:
msg = MSG10;
break;
default:
msg = MSG11;
break;
}
XtWarningMsg("conversionError", "textProperty", "XtToolkitError",
msg, NULL, 0);
return(False);
}
/* Now copy in the text */
if (prop_rtn.value) {
ctlen = strlen((char *)prop_rtn.value);
*outc = ctextConcat(*outc, *outlen, prop_rtn.value, ctlen);
*outlen += ctlen;
};
XFree(prop_rtn.value);
/* Finally, add the separator if any */
if (separator) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)NEWLINESTRING,
(unsigned int)NEWLINESTRING_LEN);
(*outlen)++;
};
*prev = cs_none;
return(True);
}
if (ctext)
ctlen = strlen((char *)ctext);
/* Next output the charset */
if (strcmp(tag, CS_ISO8859_1) == 0) {
if (*prev != cs_Latin1) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_ISO8859_1,
(unsigned int)CTEXT_SET_ISO8859_1_LEN);
*outlen += CTEXT_SET_ISO8859_1_LEN;
*prev = cs_Latin1;
};
}
else if (strcmp(tag, CS_ISO8859_2) == 0) {
if (*prev != cs_Latin2) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_ISO8859_2,
(unsigned int)CTEXT_SET_ISO8859_2_LEN);
*outlen += CTEXT_SET_ISO8859_2_LEN;
*prev = cs_Latin2;
};
}
else if (strcmp(tag, CS_ISO8859_3) == 0) {
if (*prev != cs_Latin3) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_ISO8859_3,
(unsigned int)CTEXT_SET_ISO8859_3_LEN);
*outlen += CTEXT_SET_ISO8859_3_LEN;
*prev = cs_Latin3;
};
}
else if (strcmp(tag, CS_ISO8859_4) == 0) {
if (*prev != cs_Latin4) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_ISO8859_4,
(unsigned int)CTEXT_SET_ISO8859_4_LEN);
*outlen += CTEXT_SET_ISO8859_4_LEN;
*prev = cs_Latin4;
};
}
else if (strcmp(tag, CS_ISO8859_5) == 0) {
if (*prev != cs_LatinCyrillic) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_ISO8859_5,
(unsigned int)CTEXT_SET_ISO8859_5_LEN);
*outlen += CTEXT_SET_ISO8859_5_LEN;
*prev = cs_LatinCyrillic;
};
}
else if (strcmp(tag, CS_ISO8859_6) == 0) {
if (*prev != cs_LatinArabic) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_ISO8859_6,
(unsigned int)CTEXT_SET_ISO8859_6_LEN);
*outlen += CTEXT_SET_ISO8859_6_LEN;
*prev = cs_LatinArabic;
};
}
else if (strcmp(tag, CS_ISO8859_7) == 0) {
if (*prev != cs_LatinGreek) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_ISO8859_7,
(unsigned int)CTEXT_SET_ISO8859_7_LEN);
*outlen += CTEXT_SET_ISO8859_7_LEN;
*prev = cs_LatinGreek;
};
}
else if (strcmp(tag, CS_ISO8859_8) == 0) {
if (*prev != cs_LatinHebrew) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_ISO8859_8,
(unsigned int)CTEXT_SET_ISO8859_8_LEN);
*outlen += CTEXT_SET_ISO8859_8_LEN;
*prev = cs_LatinHebrew;
};
}
else
if (strcmp(tag, CS_ISO8859_9) == 0) {
if (*prev != cs_Latin5) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_ISO8859_9,
(unsigned int)CTEXT_SET_ISO8859_9_LEN);
*outlen += CTEXT_SET_ISO8859_9_LEN;
*prev = cs_Latin5;
};
}
else if (strcmp(tag, CS_JISX0201) == 0) {
if (*prev != cs_Katakana) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_JISX0201,
(unsigned int)CTEXT_SET_JISX0201_LEN);
*outlen += CTEXT_SET_JISX0201_LEN;
*prev = cs_Katakana;
};
}
else if ((strcmp(tag, CS_GB2312_0) == 0) ||
(strcmp(tag, CS_GB2312_1) == 0)) {
if (*prev != cs_Hanzi) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_GB2312_0,
(unsigned int)CTEXT_SET_GB2312_0_LEN);
*outlen += CTEXT_SET_GB2312_0_LEN;
*prev = cs_Hanzi;
};
}
else if ((strcmp(tag, CS_JISX0208_0) == 0) ||
(strcmp(tag, CS_JISX0208_1) == 0)) {
if (*prev != cs_JapaneseGCS) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_JISX0208_0,
(unsigned int)CTEXT_SET_JISX0208_0_LEN);
*outlen += CTEXT_SET_JISX0208_0_LEN;
*prev = cs_JapaneseGCS;
};
}
else if ((strcmp(tag, CS_KSC5601_0) == 0) ||
(strcmp(tag, CS_KSC5601_1) == 0)) {
if (*prev != cs_KoreanGCS) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_KSC5601_0,
(unsigned int)CTEXT_SET_KSC5601_0_LEN);
*outlen += CTEXT_SET_KSC5601_0_LEN;
*prev = cs_KoreanGCS;
};
}
else if (strcmp(tag, CS_ISO_IR_111) == 0) {
if (*prev != cs_ir111) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)CTEXT_SET_IR_111,
(unsigned int)CTEXT_SET_IR_111_LEN);
*outlen += CTEXT_SET_IR_111_LEN;
*prev = cs_ir111;
};
}
else {
/* Must be a non-standard character set! */
OctetPtr temp;
len = strlen(tag);
temp = (unsigned char *) XtMalloc(*outlen + 6 + len + 2);
/* orig + header + tag + STX + EOS */
memcpy( temp, *outc, *outlen);
XtFree((char *) *outc);
*outc = temp;
temp = &((*outc)[*outlen]);
/*
** Format is:
** 01/11 02/05 02/15 03/nn M L tag 00/02 text
*/
*temp++ = 0x1b;
*temp++ = 0x25;
*temp++ = 0x2f;
/*
** HACK! The next octet in the sequence is the # of octets/char.
** XmStrings don't have this information, so just set it to be
** variable # of octets/char, and hope the caller knows what to do.
*/
*temp++ = 0x30;
/* encode len in next 2 octets */
*temp++ = 0x80 + (len+ctlen+1)/128;
*temp++ = 0x80 + (len+ctlen+1)%128;
strcpy((char *) temp, tag);
temp += len;
*temp++ = STX;
*temp = EOS; /* make sure there's a \0 on the end */
*prev = cs_NonStandard;
*outlen += 6 + len + 1;
};
/* Now copy in the text */
if (ctlen > 0) {
*outc = ctextConcat(*outc, *outlen, ctext, ctlen);
*outlen += ctlen;
};
/* Finally, add the separator if any */
if (separator) {
*outc = ctextConcat(*outc, *outlen,
(unsigned char *)NEWLINESTRING,
(unsigned int)NEWLINESTRING_LEN);
(*outlen)++;
}
return(True);
}
static OctetPtr
ctextConcat(
OctetPtr str1,
unsigned int str1len,
const_OctetPtr str2,
unsigned int str2len )
{
str1 = (OctetPtr)XtRealloc((char *)str1, (str1len + str2len + 1));
memcpy( &str1[str1len], str2, str2len);
str1[str1len+str2len] = EOS;
return(str1);
}
#ifdef UTF8_SUPPORTED
char*
Convert(const char *str,
unsigned int len,
const char *to_codeset,
const char *from_codeset)
{
char *res;
iconv_t cd;
if (str == NULL || to_codeset == NULL || from_codeset == NULL)
return NULL;
cd = iconv_open(to_codeset, from_codeset);
if (cd == (iconv_t) -1) {
char msg[255];
snprintf(msg, sizeof(msg),
"Could not open converter from '%s' to '%s'",
from_codeset, to_codeset);
XmeWarning(NULL, msg);
return NULL;
}
res = ConvertWithIconv(str, len, cd);
iconv_close(cd);
return res;
}
char*
ConvertWithIconv(const char *str,
unsigned int len,
iconv_t converter)
{
char *dest;
char *outp;
const char *p;
size_t inbytes_remaining;
size_t outbytes_remaining;
size_t err;
size_t outbuf_size;
Boolean have_error = FALSE;
if (str == NULL || converter == (iconv_t) -1)
return NULL;
if (len < 0)
len = strlen(str);
p = str;
inbytes_remaining = len;
outbuf_size = len + 1; /* + 1 for nul in case len == 1 */
outbytes_remaining = outbuf_size - 1; /* -1 for nul */
outp = dest = XtMalloc(outbuf_size);
again:
err = iconv(converter, (char **)&p, &inbytes_remaining, &outp,
&outbytes_remaining);
if (err == (size_t) -1) {
switch (errno) {
case EINVAL:
/* Incomplete text, do not report an error */
break;
case E2BIG:
{
size_t used = outp - dest;
outbuf_size *= 2;
dest = XtRealloc(dest, outbuf_size);
outp = dest + used;
outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
goto again;
}
case EILSEQ:
XmeWarning(NULL, "Invalid byte sequence in conversion input");
have_error = TRUE;
break;
default:
{
char msg[255];
snprintf(msg, sizeof(msg), "Error during conversion: %s",
strerror(errno));
XmeWarning(NULL, msg);
have_error = TRUE;
break;
}
}
}
*outp = '\0';
if (have_error) {
XtFree(dest);
dest = NULL;
}
return dest;
}
#endif
|