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 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267
|
/*
* $Xorg: charproc.c,v 1.6 2001/02/09 02:06:02 xorgcvs Exp $
*/
/* $XFree86: xc/programs/xterm/charproc.c,v 3.139 2003/02/25 23:36:55 dickey Exp $ */
/*
Copyright 1999-2002,2003 by Thomas E. Dickey
All Rights Reserved
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name(s) of the above copyright
holders shall not be used in advertising or otherwise to promote the
sale, use or other dealings in this Software without prior written
authorization.
Copyright 1988 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
/*
* Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
*
* All Rights Reserved
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of Digital Equipment
* Corporation not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior permission.
*
*
* DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
* DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/* charproc.c */
#include <version.h>
#include <xterm.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <X11/Xmu/Atoms.h>
#include <X11/Xmu/CharSet.h>
#include <X11/Xmu/Converters.h>
#if OPT_INPUT_METHOD
#if defined(HAVE_LIB_XAW)
#include <X11/Xaw/XawImP.h>
#elif defined(HAVE_LIB_XAW3D)
#include <X11/Xaw3d/XawImP.h>
#elif defined(HAVE_LIB_NEXTAW)
#include <X11/neXtaw/XawImP.h>
#endif
#endif
#if OPT_WIDE_CHARS
#include <wcwidth.h>
#include <precompose.h>
#endif
#if OPT_INPUT_METHOD
#include <X11/Xlocale.h>
#endif
#include <stdio.h>
#include <ctype.h>
#include <VTparse.h>
#include <data.h>
#include <error.h>
#include <menu.h>
#include <main.h>
#include <fontutils.h>
#include <xcharmouse.h>
#include <charclass.h>
#include <xstrings.h>
#if OPT_ZICONBEEP || OPT_TOOLBAR
#define HANDLE_STRUCT_NOTIFY 1
#else
#define HANDLE_STRUCT_NOTIFY 0
#endif
static IChar in_put(void);
static int set_character_class(char *s);
static void FromAlternate(TScreen * screen);
static void RequestResize(XtermWidget termw, int rows, int cols, int text);
static void SwitchBufs(TScreen * screen);
static void ToAlternate(TScreen * screen);
static void VTallocbuf(void);
static void WriteText(TScreen * screen, PAIRED_CHARS(Char * str, Char *
str2), Cardinal len);
static void ansi_modes(XtermWidget termw,
void (*func) (unsigned *p, unsigned mask));
static void bitclr(unsigned *p, unsigned mask);
static void bitcpy(unsigned *p, unsigned q, unsigned mask);
static void bitset(unsigned *p, unsigned mask);
static void dpmodes(XtermWidget termw, void (*func) (unsigned *p, unsigned mask));
static void restoremodes(XtermWidget termw);
static void savemodes(XtermWidget termw);
static void unparseputn(unsigned int n, int fd);
static void window_ops(XtermWidget termw);
#if OPT_BLINK_CURS
static void BlinkCursor(XtPointer closure, XtIntervalId * id);
static void StartBlinking(TScreen * screen);
static void StopBlinking(TScreen * screen);
#else
#define StartBlinking(screen) /* nothing */
#define StopBlinking(screen) /* nothing */
#endif
#if OPT_INPUT_METHOD
static void PreeditPosition(TScreen * screen);
#endif
#define DEFAULT -1
#define BELLSUPPRESSMSEC 200
#define doinput() (morePtyData(&VTbuffer) ? nextPtyData(&VTbuffer) : in_put())
static int nparam;
static ANSI reply;
static int param[NPARAM];
#ifdef UNUSED
static unsigned long ctotal;
static unsigned long ntotal;
#endif
static jmp_buf vtjmpbuf;
/* event handlers */
static void HandleBell PROTO_XT_ACTIONS_ARGS;
static void HandleIgnore PROTO_XT_ACTIONS_ARGS;
static void HandleKeymapChange PROTO_XT_ACTIONS_ARGS;
static void HandleVisualBell PROTO_XT_ACTIONS_ARGS;
#if HANDLE_STRUCT_NOTIFY
static void HandleStructNotify PROTO_XT_EV_HANDLER_ARGS;
#endif
/*
* NOTE: VTInitialize zeros out the entire ".screen" component of the
* XtermWidget, so make sure to add an assignment statement in VTInitialize()
* for each new ".screen" field added to this resource list.
*/
/* Defaults */
#if OPT_ISO_COLORS
/*
* If we default to colorMode enabled, compile-in defaults for the ANSI colors.
*/
#if DFT_COLORMODE
#define DFT_COLOR(name) name
#else
#define DFT_COLOR(name) XtDefaultForeground
#endif
#endif
static char *_Font_Selected_ = "yes"; /* string is arbitrary */
static char defaultTranslations[] =
"\
Shift <KeyPress> Prior:scroll-back(1,halfpage) \n\
Shift <KeyPress> Next:scroll-forw(1,halfpage) \n\
Shift <KeyPress> Select:select-cursor-start() select-cursor-end(PRIMARY, CUT_BUFFER0) \n\
Shift <KeyPress> Insert:insert-selection(PRIMARY, CUT_BUFFER0) \n\
"
#if OPT_SHIFT_FONTS
"\
Shift~Ctrl <KeyPress> KP_Add:larger-vt-font() \n\
Shift Ctrl <KeyPress> KP_Add:smaller-vt-font() \n\
Shift <KeyPress> KP_Subtract:smaller-vt-font() \n\
"
#endif
"\
~Meta <KeyPress>:insert-seven-bit() \n\
Meta <KeyPress>:insert-eight-bit() \n\
!Ctrl <Btn1Down>:popup-menu(mainMenu) \n\
!Lock Ctrl <Btn1Down>:popup-menu(mainMenu) \n\
!Lock Ctrl @Num_Lock <Btn1Down>:popup-menu(mainMenu) \n\
! @Num_Lock Ctrl <Btn1Down>:popup-menu(mainMenu) \n\
~Meta <Btn1Down>:select-start() \n\
~Meta <Btn1Motion>:select-extend() \n\
!Ctrl <Btn2Down>:popup-menu(vtMenu) \n\
!Lock Ctrl <Btn2Down>:popup-menu(vtMenu) \n\
!Lock Ctrl @Num_Lock <Btn2Down>:popup-menu(vtMenu) \n\
! @Num_Lock Ctrl <Btn2Down>:popup-menu(vtMenu) \n\
~Ctrl ~Meta <Btn2Down>:ignore() \n\
Meta <Btn2Down>:clear-saved-lines() \n\
~Ctrl ~Meta <Btn2Up>:insert-selection(PRIMARY, CUT_BUFFER0) \n\
!Ctrl <Btn3Down>:popup-menu(fontMenu) \n\
!Lock Ctrl <Btn3Down>:popup-menu(fontMenu) \n\
!Lock Ctrl @Num_Lock <Btn3Down>:popup-menu(fontMenu) \n\
! @Num_Lock Ctrl <Btn3Down>:popup-menu(fontMenu) \n\
~Ctrl ~Meta <Btn3Down>:start-extend() \n\
~Meta <Btn3Motion>:select-extend() \n\
Ctrl <Btn4Down>:scroll-back(1,halfpage,m) \n\
Lock Ctrl <Btn4Down>:scroll-back(1,halfpage,m) \n\
Lock @Num_Lock Ctrl <Btn4Down>:scroll-back(1,halfpage,m) \n\
@Num_Lock Ctrl <Btn4Down>:scroll-back(1,halfpage,m) \n\
<Btn4Down>:scroll-back(5,line,m) \n\
Ctrl <Btn5Down>:scroll-forw(1,halfpage,m) \n\
Lock Ctrl <Btn5Down>:scroll-forw(1,halfpage,m) \n\
Lock @Num_Lock Ctrl <Btn5Down>:scroll-forw(1,halfpage,m) \n\
@Num_Lock Ctrl <Btn5Down>:scroll-forw(1,halfpage,m) \n\
<Btn5Down>:scroll-forw(5,line,m) \n\
<BtnUp>:select-end(PRIMARY, CUT_BUFFER0) \n\
<BtnDown>:bell(0) \
"; /* PROCURA added "Meta <Btn2Down>:clear-saved-lines()" */
/* *INDENT-OFF* */
static XtActionsRec actionsList[] = {
{ "allow-send-events", HandleAllowSends },
{ "bell", HandleBell },
{ "clear-saved-lines", HandleClearSavedLines },
{ "create-menu", HandleCreateMenu },
{ "dired-button", DiredButton },
{ "hard-reset", HandleHardReset },
{ "ignore", HandleIgnore },
{ "insert", HandleKeyPressed }, /* alias for insert-seven-bit */
{ "insert-eight-bit", HandleEightBitKeyPressed },
{ "insert-selection", HandleInsertSelection },
{ "insert-seven-bit", HandleKeyPressed },
{ "interpret", HandleInterpret },
{ "keymap", HandleKeymapChange },
{ "popup-menu", HandlePopupMenu },
{ "print", HandlePrintScreen },
{ "print-redir", HandlePrintControlMode },
{ "quit", HandleQuit },
{ "redraw", HandleRedraw },
{ "delete-is-del", HandleDeleteIsDEL },
{ "scroll-back", HandleScrollBack },
{ "scroll-forw", HandleScrollForward },
{ "secure", HandleSecure },
{ "select-cursor-end", HandleKeyboardSelectEnd },
{ "select-cursor-start", HandleKeyboardSelectStart },
{ "select-end", HandleSelectEnd },
{ "select-extend", HandleSelectExtend },
{ "select-set", HandleSelectSet },
{ "select-start", HandleSelectStart },
{ "send-signal", HandleSendSignal },
{ "set-8-bit-control", Handle8BitControl },
{ "set-allow132", HandleAllow132 },
{ "set-altscreen", HandleAltScreen },
{ "set-appcursor", HandleAppCursor },
{ "set-appkeypad", HandleAppKeypad },
{ "set-autolinefeed", HandleAutoLineFeed },
{ "set-autowrap", HandleAutoWrap },
{ "set-backarrow", HandleBackarrow },
{ "set-cursesemul", HandleCursesEmul },
{ "set-jumpscroll", HandleJumpscroll },
{ "set-old-function-keys", HandleOldFunctionKeys },
{ "set-marginbell", HandleMarginBell },
{ "set-reverse-video", HandleReverseVideo },
{ "set-reversewrap", HandleReverseWrap },
{ "set-scroll-on-key", HandleScrollKey },
{ "set-scroll-on-tty-output", HandleScrollTtyOutput },
{ "set-scrollbar", HandleScrollbar },
{ "set-sun-function-keys", HandleSunFunctionKeys },
{ "set-sun-keyboard", HandleSunKeyboard },
{ "set-titeInhibit", HandleTiteInhibit },
{ "set-visual-bell", HandleSetVisualBell },
{ "set-pop-on-bell", HandleSetPopOnBell },
{ "set-vt-font", HandleSetFont },
{ "soft-reset", HandleSoftReset },
{ "start-cursor-extend", HandleKeyboardStartExtend },
{ "start-extend", HandleStartExtend },
{ "string", HandleStringEvent },
{ "vi-button", ViButton },
{ "visual-bell", HandleVisualBell },
#ifdef ALLOWLOGGING
{ "set-logging", HandleLogging },
#endif
#if OPT_BLINK_CURS
{ "set-cursorblink", HandleCursorBlink },
#endif
#if OPT_BOX_CHARS
{ "set-font-linedrawing", HandleFontBoxChars },
#endif
#if OPT_DEC_CHRSET
{ "set-font-doublesize", HandleFontDoublesize },
#endif
#if OPT_DEC_SOFTFONT
{ "set-font-loading", HandleFontLoading },
#endif
#if OPT_HP_FUNC_KEYS
{ "set-hp-function-keys", HandleHpFunctionKeys },
#endif
#if OPT_MAXIMIZE
{ "deiconify", HandleDeIconify },
{ "iconify", HandleIconify },
{ "maximize", HandleMaximize },
{ "restore", HandleRestoreSize },
#endif
#if OPT_NUM_LOCK
{ "meta-sends-escape", HandleMetaEsc },
{ "set-num-lock", HandleNumLock },
#endif
#if OPT_READLINE
{ "readline-button", ReadLineButton },
#endif
#if OPT_SCO_FUNC_KEYS
{ "set-sco-function-keys", HandleScoFunctionKeys },
#endif
#if OPT_SHIFT_FONTS
{ "larger-vt-font", HandleLargerFont },
{ "smaller-vt-font", HandleSmallerFont },
#endif
#if OPT_TEK4014
{ "set-terminal-type", HandleSetTerminalType },
{ "set-visibility", HandleVisibility },
{ "set-tek-text", HandleSetTekText },
{ "tek-page", HandleTekPage },
{ "tek-reset", HandleTekReset },
{ "tek-copy", HandleTekCopy },
#endif
};
/* *INDENT-ON* */
#ifdef VMS
#define OS_DEPENDENT_PRINT_COMMAND "print/delete/noflag"
#else /* VMS */
#define OS_DEPENDENT_PRINT_COMMAND "lpr"
#endif /* VMS */
static XtResource resources[] =
{
Bres(XtNallowSendEvents, XtCAllowSendEvents, screen.allowSendEvents, FALSE),
Bres(XtNallowWindowOps, XtCAllowWindowOps, screen.allowWindowOps, TRUE),
Bres(XtNalwaysHighlight, XtCAlwaysHighlight, screen.always_highlight, FALSE),
Bres(XtNappcursorDefault, XtCAppcursorDefault, misc.appcursorDefault, FALSE),
Bres(XtNappkeypadDefault, XtCAppkeypadDefault, misc.appkeypadDefault, FALSE),
Bres(XtNautoWrap, XtCAutoWrap, misc.autoWrap, TRUE),
Bres(XtNawaitInput, XtCAwaitInput, screen.awaitInput, FALSE),
Bres(XtNfreeBoldBox, XtCBoolean, screen.free_bold_box, FALSE),
Bres(XtNforceBoxChars, XtCBoolean, screen.force_box_chars, FALSE),
Bres(XtNbackarrowKey, XtCBackarrowKey, screen.backarrow_key, TRUE),
Bres(XtNboldMode, XtCBoldMode, screen.bold_mode, TRUE),
Bres(XtNbrokenSelections, XtCBrokenSelections, screen.brokenSelections, FALSE),
Bres(XtNc132, XtCC132, screen.c132, FALSE),
Bres(XtNcurses, XtCCurses, screen.curses, FALSE),
Bres(XtNcutNewline, XtCCutNewline, screen.cutNewline, TRUE),
Bres(XtNcutToBeginningOfLine, XtCCutToBeginningOfLine,
screen.cutToBeginningOfLine, TRUE),
Bres(XtNdeleteIsDEL, XtCDeleteIsDEL, screen.delete_is_del, 2),
Bres(XtNdynamicColors, XtCDynamicColors, misc.dynamicColors, TRUE),
Bres(XtNeightBitControl, XtCEightBitControl, screen.control_eight_bits, FALSE),
Bres(XtNeightBitInput, XtCEightBitInput, screen.input_eight_bits, TRUE),
Bres(XtNeightBitOutput, XtCEightBitOutput, screen.output_eight_bits, TRUE),
Bres(XtNhighlightSelection, XtCHighlightSelection,
screen.highlight_selection, FALSE),
Bres(XtNhpLowerleftBugCompat, XtCHpLowerleftBugCompat, screen.hp_ll_bc, FALSE),
Bres(XtNi18nSelections, XtCI18nSelections, screen.i18nSelections, TRUE),
Bres(XtNjumpScroll, XtCJumpScroll, screen.jumpscroll, TRUE),
Bres(XtNloginShell, XtCLoginShell, misc.login_shell, FALSE),
Bres(XtNmarginBell, XtCMarginBell, screen.marginbell, FALSE),
Bres(XtNmetaSendsEscape, XtCMetaSendsEscape, screen.meta_sends_esc, FALSE),
Bres(XtNmultiScroll, XtCMultiScroll, screen.multiscroll, FALSE),
Bres(XtNoldXtermFKeys, XtCOldXtermFKeys, screen.old_fkeys, FALSE),
Bres(XtNpopOnBell, XtCPopOnBell, screen.poponbell, FALSE),
Bres(XtNprinterAutoClose, XtCPrinterAutoClose, screen.printer_autoclose, FALSE),
Bres(XtNprinterExtent, XtCPrinterExtent, screen.printer_extent, FALSE),
Bres(XtNprinterFormFeed, XtCPrinterFormFeed, screen.printer_formfeed, FALSE),
Bres(XtNreverseVideo, XtCReverseVideo, misc.re_verse, FALSE),
Bres(XtNreverseWrap, XtCReverseWrap, misc.reverseWrap, FALSE),
Bres(XtNscrollBar, XtCScrollBar, misc.scrollbar, FALSE),
Bres(XtNscrollKey, XtCScrollCond, screen.scrollkey, FALSE),
Bres(XtNscrollTtyOutput, XtCScrollCond, screen.scrollttyoutput, TRUE),
Bres(XtNsignalInhibit, XtCSignalInhibit, misc.signalInhibit, FALSE),
Bres(XtNtiteInhibit, XtCTiteInhibit, misc.titeInhibit, FALSE),
Bres(XtNtiXtraScroll, XtCTiXtraScroll, misc.tiXtraScroll, FALSE),
Bres(XtNtrimSelection, XtCTrimSelection, screen.trim_selection, FALSE),
Bres(XtNunderLine, XtCUnderLine, screen.underline, TRUE),
Bres(XtNvisualBell, XtCVisualBell, screen.visualbell, FALSE),
Cres(XtNcursorColor, XtCCursorColor, screen.cursorcolor, XtDefaultForeground),
Cres(XtNforeground, XtCForeground, screen.foreground, XtDefaultForeground),
Cres(XtNpointerColor, XtCPointerColor, screen.mousecolor, XtDefaultForeground),
Cres(XtNbackground, XtCBackground, core.background_pixel, XtDefaultBackground),
Cres(XtNpointerColorBackground, XtCBackground, screen.mousecolorback, XtDefaultBackground),
Ires(XtNbellSuppressTime, XtCBellSuppressTime, screen.bellSuppressTime, BELLSUPPRESSMSEC),
Ires(XtNinternalBorder, XtCBorderWidth, screen.border, DEFBORDER),
Ires(XtNlimitResize, XtCLimitResize, misc.limit_resize, 1),
Ires(XtNmultiClickTime, XtCMultiClickTime, screen.multiClickTime, MULTICLICKTIME),
Ires(XtNnMarginBell, XtCColumn, screen.nmarginbell, N_MARGINBELL),
Ires(XtNprinterControlMode, XtCPrinterControlMode,
screen.printer_controlmode, 0),
Ires(XtNsaveLines, XtCSaveLines, screen.savelines, SAVELINES),
Ires(XtNscrollLines, XtCScrollLines, screen.scrolllines, SCROLLLINES),
Sres("font1", "Font1", screen.menu_font_names[fontMenu_font1], NULL),
Sres("font2", "Font2", screen.menu_font_names[fontMenu_font2], NULL),
Sres("font3", "Font3", screen.menu_font_names[fontMenu_font3], NULL),
Sres("font4", "Font4", screen.menu_font_names[fontMenu_font4], NULL),
Sres("font5", "Font5", screen.menu_font_names[fontMenu_font5], NULL),
Sres("font6", "Font6", screen.menu_font_names[fontMenu_font6], NULL),
Sres(XtNanswerbackString, XtCAnswerbackString, screen.answer_back, ""),
Sres(XtNboldFont, XtCBoldFont, misc.f_b, DEFBOLDFONT),
Sres(XtNcharClass, XtCCharClass, screen.charClass, NULL),
Sres(XtNdecTerminalID, XtCDecTerminalID, screen.term_id, DFT_DECID),
Sres(XtNfont, XtCFont, misc.f_n, DEFFONT),
Sres(XtNgeometry, XtCGeometry, misc.geo_metry, NULL),
Sres(XtNkeyboardDialect, XtCKeyboardDialect, screen.keyboard_dialect, DFT_KBD_DIALECT),
Sres(XtNprinterCommand, XtCPrinterCommand, screen.printer_command, OS_DEPENDENT_PRINT_COMMAND),
Sres(XtNtekGeometry, XtCGeometry, misc.T_geometry, NULL),
{XtNresizeGravity, XtCResizeGravity, XtRGravity, sizeof(XtGravity),
XtOffsetOf(XtermWidgetRec, misc.resizeGravity),
XtRImmediate, (XtPointer) SouthWestGravity},
{XtNpointerShape, XtCCursor, XtRCursor, sizeof(Cursor),
XtOffsetOf(XtermWidgetRec, screen.pointer_cursor),
XtRString, (XtPointer) "xterm"},
#ifdef ALLOWLOGGING
Bres(XtNlogInhibit, XtCLogInhibit, misc.logInhibit, FALSE),
Bres(XtNlogging, XtCLogging, misc.log_on, FALSE),
Sres(XtNlogFile, XtCLogfile, screen.logfile, NULL),
#endif
#ifndef NO_ACTIVE_ICON
Bres("activeIcon", "ActiveIcon", misc.active_icon, FALSE),
Ires("iconBorderWidth", XtCBorderWidth, misc.icon_border_width, 2),
{"iconFont", "IconFont", XtRFontStruct, sizeof(XFontStruct),
XtOffsetOf(XtermWidgetRec, screen.fnt_icon),
XtRString, (XtPointer) XtExtdefaultfont},
{"iconBorderColor", XtCBorderColor, XtRPixel, sizeof(Pixel),
XtOffsetOf(XtermWidgetRec, misc.icon_border_pixel),
XtRString, XtExtdefaultbackground},
#endif /* NO_ACTIVE_ICON */
#if OPT_BLINK_CURS
Bres(XtNcursorBlink, XtCCursorBlink, screen.cursor_blink, FALSE),
Ires(XtNcursorOnTime, XtCCursorOnTime, screen.cursor_on, 600),
Ires(XtNcursorOffTime, XtCCursorOffTime, screen.cursor_off, 300),
#endif
#if OPT_DEC_CHRSET
Bres(XtNfontDoublesize, XtCFontDoublesize, screen.font_doublesize, TRUE),
Ires(XtNcacheDoublesize, XtCCacheDoublesize, screen.cache_doublesize, NUM_CHRSET),
#endif
#if OPT_HIGHLIGHT_COLOR
Cres(XtNhighlightColor, XtCHighlightColor, screen.highlightcolor, XtDefaultForeground),
#endif /* OPT_HIGHLIGHT_COLOR */
#if OPT_INPUT_METHOD
Bres(XtNopenIm, XtCOpenIm, misc.open_im, TRUE),
Sres(XtNinputMethod, XtCInputMethod, misc.input_method, NULL),
Sres(XtNpreeditType, XtCPreeditType, misc.preedit_type,
"OverTheSpot,Root"),
#endif
#if OPT_ISO_COLORS
Bres(XtNboldColors, XtCColorMode, screen.boldColors, TRUE),
Ires(XtNveryBoldColors, XtCColorMode, screen.veryBoldColors, 0),
Bres(XtNcolorAttrMode, XtCColorMode, screen.colorAttrMode, FALSE),
Bres(XtNcolorBDMode, XtCColorMode, screen.colorBDMode, FALSE),
Bres(XtNcolorBLMode, XtCColorMode, screen.colorBLMode, FALSE),
Bres(XtNcolorMode, XtCColorMode, screen.colorMode, DFT_COLORMODE),
Bres(XtNcolorRVMode, XtCColorMode, screen.colorRVMode, FALSE),
Bres(XtNcolorULMode, XtCColorMode, screen.colorULMode, FALSE),
COLOR_RES("0", screen.Acolors[COLOR_0], DFT_COLOR("black")),
COLOR_RES("1", screen.Acolors[COLOR_1], DFT_COLOR("red3")),
COLOR_RES("2", screen.Acolors[COLOR_2], DFT_COLOR("green3")),
COLOR_RES("3", screen.Acolors[COLOR_3], DFT_COLOR("yellow3")),
COLOR_RES("4", screen.Acolors[COLOR_4], DFT_COLOR("blue3")),
COLOR_RES("5", screen.Acolors[COLOR_5], DFT_COLOR("magenta3")),
COLOR_RES("6", screen.Acolors[COLOR_6], DFT_COLOR("cyan3")),
COLOR_RES("7", screen.Acolors[COLOR_7], DFT_COLOR("gray90")),
COLOR_RES("8", screen.Acolors[COLOR_8], DFT_COLOR("gray30")),
COLOR_RES("9", screen.Acolors[COLOR_9], DFT_COLOR("red")),
COLOR_RES("10", screen.Acolors[COLOR_10], DFT_COLOR("green")),
COLOR_RES("11", screen.Acolors[COLOR_11], DFT_COLOR("yellow")),
COLOR_RES("12", screen.Acolors[COLOR_12], DFT_COLOR("blue")),
COLOR_RES("13", screen.Acolors[COLOR_13], DFT_COLOR("magenta")),
COLOR_RES("14", screen.Acolors[COLOR_14], DFT_COLOR("cyan")),
COLOR_RES("15", screen.Acolors[COLOR_15], DFT_COLOR("white")),
COLOR_RES("BD", screen.Acolors[COLOR_BD], DFT_COLOR(XtDefaultForeground)),
COLOR_RES("BL", screen.Acolors[COLOR_BL], DFT_COLOR(XtDefaultForeground)),
COLOR_RES("UL", screen.Acolors[COLOR_UL], DFT_COLOR(XtDefaultForeground)),
COLOR_RES("RV", screen.Acolors[COLOR_RV], DFT_COLOR(XtDefaultForeground)),
#if OPT_256_COLORS
# include <256colres.h>
#elif OPT_88_COLORS
# include <88colres.h>
#endif
#endif /* OPT_ISO_COLORS */
#if OPT_MOD_FKEYS
Ires(XtNmodifyCursorKeys, XtCModifyCursorKeys,
keyboard.modify_cursor_keys, 2),
#endif
#if OPT_NUM_LOCK
Bres(XtNalwaysUseMods, XtCAlwaysUseMods, misc.alwaysUseMods, FALSE),
Bres(XtNnumLock, XtCNumLock, misc.real_NumLock, TRUE),
#endif
#if OPT_PRINT_COLORS
Ires(XtNprintAttributes, XtCPrintAttributes, screen.print_attributes, 1),
#endif
#if OPT_SHIFT_FONTS
Bres(XtNshiftFonts, XtCShiftFonts, misc.shift_fonts, TRUE),
#endif
#if OPT_SUNPC_KBD
Ires(XtNctrlFKeys, XtCCtrlFKeys, misc.ctrl_fkeys, 10),
#endif
#if OPT_TEK4014
Bres(XtNtekInhibit, XtCTekInhibit, misc.tekInhibit, FALSE),
Bres(XtNtekSmall, XtCTekSmall, misc.tekSmall, FALSE),
Bres(XtNtekStartup, XtCTekStartup, screen.TekEmu, FALSE),
#endif
#if OPT_TOOLBAR
{XtNmenuBar, XtCMenuBar, XtRWidget, sizeof(Widget),
XtOffsetOf(XtermWidgetRec, screen.fullVwin.menu_bar),
XtRWidget, (XtPointer) 0},
Ires(XtNmenuHeight, XtCMenuHeight, screen.fullVwin.menu_height, 25),
#endif
#if OPT_WIDE_CHARS
Ires(XtNutf8, XtCUtf8, screen.utf8_mode, 3),
Bres(XtNwideChars, XtCWideChars, screen.wide_chars, FALSE),
Bres(XtNcjkWidth, XtCCjkWidth, misc.cjk_width, FALSE),
Bres(XtNvt100Graphics, XtCVT100Graphics, screen.vt100_graphics, TRUE),
Sres(XtNwideBoldFont, XtCWideBoldFont, misc.f_wb, DEFWIDEBOLDFONT),
Sres(XtNwideFont, XtCWideFont, misc.f_w, DEFWIDEFONT),
#endif
#if OPT_LUIT_PROG
Sres(XtNlocale, XtCLocale, misc.locale_str, "medium"),
Sres(XtNlocaleFilter, XtCLocaleFilter, misc.localefilter, DEFLOCALEFILTER),
#endif
#if OPT_INPUT_METHOD
Sres(XtNximFont, XtCXimFont, misc.f_x, DEFXIMFONT),
#endif
#if OPT_XMC_GLITCH
Bres(XtNxmcInline, XtCXmcInline, screen.xmc_inline, FALSE),
Bres(XtNxmcMoveSGR, XtCXmcMoveSGR, screen.move_sgr_ok, TRUE),
Ires(XtNxmcAttributes, XtCXmcAttributes, screen.xmc_attributes, 1),
Ires(XtNxmcGlitch, XtCXmcGlitch, screen.xmc_glitch, 0),
#endif
#ifdef SCROLLBAR_RIGHT
Bres(XtNrightScrollBar, XtCRightScrollBar, misc.useRight, FALSE),
#endif
#ifdef XRENDERFONT
Ires(XtNfaceSize, XtCFaceSize, misc.face_size, DEFFACESIZE),
Sres(XtNfaceName, XtCFaceName, misc.face_name, DEFFACENAME),
#endif
};
static Boolean VTSetValues(Widget cur, Widget request, Widget new_arg,
ArgList args, Cardinal * num_args);
static void VTClassInit(void);
static void VTDestroy(Widget w);
static void VTExpose(Widget w, XEvent * event, Region region);
static void VTInitialize(Widget wrequest, Widget new_arg, ArgList args,
Cardinal * num_args);
static void VTRealize(Widget w, XtValueMask * valuemask,
XSetWindowAttributes * values);
static void VTResize(Widget w);
#if OPT_I18N_SUPPORT && OPT_INPUT_METHOD
static void VTInitI18N(void);
#endif
#ifdef VMS
globaldef {
"xtermclassrec"
} noshare
#else
static
#endif /* VMS */
WidgetClassRec xtermClassRec =
{
{
/* core_class fields */
(WidgetClass) & widgetClassRec, /* superclass */
"VT100", /* class_name */
sizeof(XtermWidgetRec), /* widget_size */
VTClassInit, /* class_initialize */
NULL, /* class_part_initialize */
FALSE, /* class_inited */
VTInitialize, /* initialize */
NULL, /* initialize_hook */
VTRealize, /* realize */
actionsList, /* actions */
XtNumber(actionsList), /* num_actions */
resources, /* resources */
XtNumber(resources), /* num_resources */
NULLQUARK, /* xrm_class */
TRUE, /* compress_motion */
FALSE, /* compress_exposure */
TRUE, /* compress_enterleave */
FALSE, /* visible_interest */
VTDestroy, /* destroy */
VTResize, /* resize */
VTExpose, /* expose */
VTSetValues, /* set_values */
NULL, /* set_values_hook */
NULL, /* set_values_almost */
NULL, /* get_values_hook */
NULL, /* accept_focus */
XtVersion, /* version */
NULL, /* callback_offsets */
defaultTranslations, /* tm_table */
XtInheritQueryGeometry, /* query_geometry */
XtInheritDisplayAccelerator, /* display_accelerator */
NULL /* extension */
}
};
#ifdef VMS
globaldef {
"xtermwidgetclass"
}
noshare
#endif /* VMS */
WidgetClass xtermWidgetClass = (WidgetClass) & xtermClassRec;
#if OPT_ISO_COLORS
/*
* The terminal's foreground and background colors are set via two mechanisms:
* text (cur_foreground, cur_background values that are passed down to
* XDrawImageString and XDrawString)
* area (X11 graphics context used in XClearArea and XFillRectangle)
*/
void
SGR_Foreground(int color)
{
register TScreen *screen = &term->screen;
Pixel fg;
/* FIXME HideCursor(); */
if (color >= 0) {
term->flags |= FG_COLOR;
} else {
term->flags &= ~FG_COLOR;
}
fg = getXtermForeground(term->flags, color);
term->cur_foreground = color;
XSetForeground(screen->display, NormalGC(screen), fg);
XSetBackground(screen->display, ReverseGC(screen), fg);
if (NormalGC(screen) != NormalBoldGC(screen)) {
XSetForeground(screen->display, NormalBoldGC(screen), fg);
XSetBackground(screen->display, ReverseBoldGC(screen), fg);
}
}
void
SGR_Background(int color)
{
register TScreen *screen = &term->screen;
Pixel bg;
/*
* An indexing operation may have set screen->scroll_amt, which would
* normally result in calling FlushScroll() in WriteText(). However,
* if we're changing the background color now, then the new value
* should not apply to the pending blank lines.
*/
if (screen->scroll_amt && (color != term->cur_background))
FlushScroll(screen);
if (color >= 0) {
term->flags |= BG_COLOR;
} else {
term->flags &= ~BG_COLOR;
}
bg = getXtermBackground(term->flags, color);
term->cur_background = color;
XSetBackground(screen->display, NormalGC(screen), bg);
XSetForeground(screen->display, ReverseGC(screen), bg);
if (NormalGC(screen) != NormalBoldGC(screen)) {
XSetBackground(screen->display, NormalBoldGC(screen), bg);
XSetForeground(screen->display, ReverseBoldGC(screen), bg);
}
}
/* Invoked after updating bold/underline flags, computes the extended color
* index to use for foreground. (See also 'extract_fg()').
*/
static void
setExtendedFG(void)
{
int fg = term->sgr_foreground;
if (term->screen.colorAttrMode
|| (fg < 0)) {
if (term->screen.colorULMode && (term->flags & UNDERLINE))
fg = COLOR_UL;
if (term->screen.colorBDMode && (term->flags & BOLD))
fg = COLOR_BD;
if (term->screen.colorBLMode && (term->flags & BLINK))
fg = COLOR_BL;
}
/* This implements the IBM PC-style convention of 8-colors, with one
* bit for bold, thus mapping the 0-7 codes to 8-15. It won't make
* much sense for 16-color applications, but we keep it to retain
* compatiblity with ANSI-color applications.
*/
#if OPT_PC_COLORS /* XXXJTL should be settable at runtime (resource or OSC?) */
if (term->screen.boldColors
&& (!term->sgr_extended)
&& (fg >= 0)
&& (fg < 8)
&& (term->flags & BOLD))
fg |= 8;
#endif
SGR_Foreground(fg);
}
/* Invoked after updating inverse flag, computes the extended color
* index to use for background. (See also 'extract_bg()').
*/
static void
setExtendedBG(void)
{
int bg = term->sgr_background;
if (term->screen.colorAttrMode
|| (bg < 0)) {
if (term->screen.colorRVMode && (term->flags & INVERSE))
bg = COLOR_RV;
}
SGR_Background(bg);
}
static void
reset_SGR_Foreground(void)
{
term->sgr_foreground = -1;
term->sgr_extended = 0;
setExtendedFG();
}
static void
reset_SGR_Background(void)
{
term->sgr_background = -1;
setExtendedBG();
}
static void
reset_SGR_Colors(void)
{
reset_SGR_Foreground();
reset_SGR_Background();
}
#endif /* OPT_ISO_COLORS */
void
resetCharsets(TScreen * screen)
{
screen->gsets[0] = 'B'; /* ASCII_G */
screen->gsets[1] = '0'; /* line drawing */
screen->gsets[2] = 'B'; /* DEC supplemental. */
screen->gsets[3] = 'B';
screen->curgl = 0; /* G0 => GL. */
screen->curgr = 2; /* G2 => GR. */
screen->curss = 0; /* No single shift. */
}
/* allocate larger buffer if needed/possible */
#define SafeAlloc(type, area, used, size) \
type *new_string = area; \
unsigned new_length = size; \
if (new_length == 0) { \
new_length = 256; \
new_string = (type *)malloc(new_length * sizeof(type)); \
} else if (used+1 >= new_length) { \
new_length = size * 2; \
new_string = (type *)malloc(new_length * sizeof(type)); \
if (new_string != 0 \
&& area != 0 \
&& used != 0) \
memcpy(new_string, area, used * sizeof(type)); \
}
#define MotionOff( s, t ) \
if ((s)->event_mask & PointerMotionMask) { \
(s)->event_mask |= ButtonMotionMask; \
(s)->event_mask &= ~PointerMotionMask; \
XSelectInput(XtDisplay((t)), XtWindow((t)), (s)->event_mask); \
}
extern int last_written_col, last_written_row;
static void
VTparse(void)
{
/* Buffer for processing printable text */
static IChar *print_area;
static size_t print_size, print_used;
/* Buffer for processing strings (e.g., OSC ... ST) */
static Char *string_area;
static size_t string_size, string_used;
#if OPT_VT52_MODE
static Bool vt52_cup = FALSE;
#endif
Const PARSE_T *groundtable = ansi_table;
TScreen *screen = &term->screen;
Const PARSE_T *parsestate;
unsigned int c;
Char *cp;
int row, col, top, bot, scstype, count;
Bool private_function; /* distinguish private-mode from standard */
int string_mode; /* nonzero iff we're processing a string */
int lastchar; /* positive iff we had a graphic character */
int nextstate;
int laststate;
#if OPT_WIDE_CHARS
int last_was_wide;
#endif
/* We longjmp back to this point in VTReset() */
(void) setjmp(vtjmpbuf);
#if OPT_VT52_MODE
groundtable = screen->ansi_level ? ansi_table : vt52_table;
#else
groundtable = ansi_table;
#endif
parsestate = groundtable;
scstype = 0;
private_function = False;
string_mode = 0;
lastchar = -1; /* not a legal IChar */
nextstate = -1; /* not a legal state */
#if OPT_WIDE_CHARS
last_was_wide = 0;
#endif
for (;;) {
int thischar = -1;
c = doinput();
#if OPT_WIDE_CHARS
if (screen->wide_chars
&& my_wcwidth(c) == 0) {
unsigned single = 0;
int prev, precomposed;
if (screen->curss) {
dotext(screen, screen->gsets[(int) (screen->curss)],
print_area, 1);
screen->curss = 0;
single++;
}
if (print_used > single) {
dotext(screen,
screen->gsets[(int) (screen->curgl)],
print_area + single,
print_used - single);
}
print_used = 0;
prev = getXtermCell(screen, last_written_row, last_written_col);
precomposed = do_precomposition(prev, c);
if (precomposed != -1) {
putXtermCell(screen, last_written_row, last_written_col, precomposed);
} else {
addXtermCombining(screen,
last_written_row,
last_written_col, c);
}
if (!screen->scroll_amt)
ScrnRefresh(screen,
last_written_row,
last_written_col, 1, 1, 1);
continue;
}
#endif
/* Intercept characters for printer controller mode */
if (screen->printer_controlmode == 2) {
if ((c = xtermPrinterControl(c)) == 0)
continue;
}
/*
* VT52 is a little ugly in the one place it has a parameterized
* control sequence, since the parameter falls after the character
* that denotes the type of sequence.
*/
#if OPT_VT52_MODE
if (vt52_cup) {
param[nparam++] = (c & 0x7f) - 32;
if (nparam < 2)
continue;
vt52_cup = FALSE;
if ((row = param[0]) < 0)
row = 0;
if ((col = param[1]) < 0)
col = 0;
CursorSet(screen, row, col, term->flags);
parsestate = vt52_table;
param[0] = 0;
param[1] = 0;
continue;
}
#endif
/*
* The parsing tables all have 256 entries. If we're supporting
* wide characters, we handle them by treating them the same as
* printing characters.
*/
laststate = nextstate;
#if OPT_WIDE_CHARS
if (c > 255) {
if (parsestate == groundtable) {
nextstate = CASE_PRINT;
} else if (parsestate == sos_table) {
c &= 0xffff;
if (c > 255) {
TRACE(("Found code > 255 while in SOS state: %04X\n", c));
c = '?';
}
} else {
nextstate = CASE_GROUND_STATE;
}
} else
#endif
nextstate = parsestate[E2A(c)];
#if OPT_WIDE_CHARS
/* if this character is a different width than
the last one, put the previous text into
the buffer and draw it now */
if (iswide(c) != last_was_wide) {
unsigned single = 0;
if (screen->curss) {
dotext(screen,
screen->gsets[(int) (screen->curss)],
print_area, 1);
screen->curss = 0;
single++;
}
if (print_used > single) {
dotext(screen,
screen->gsets[(int) (screen->curgl)],
print_area + single,
print_used - single);
}
print_used = 0;
}
#endif
/*
* Accumulate string for printable text. This may be 8/16-bit
* characters.
*/
if (nextstate == CASE_PRINT) {
SafeAlloc(IChar, print_area, print_used, print_size);
if (new_string == 0) {
fprintf(stderr,
"Cannot allocate %d bytes for printable text\n",
new_length);
continue;
}
#if OPT_VT52_MODE
/*
* Strip output text to 7-bits for VT52. We should do this for
* VT100 also (which is a 7-bit device), but xterm has been
* doing this for so long we shouldn't change this behavior.
*/
if (screen->ansi_level < 1)
c &= 0x7f;
#endif
print_area = new_string;
print_size = new_length;
print_area[print_used++] = lastchar = thischar = c;
#if OPT_WIDE_CHARS
last_was_wide = iswide(c);
#endif
if (morePtyData(&VTbuffer)) {
continue;
}
}
if (nextstate == CASE_PRINT
|| (laststate == CASE_PRINT && print_used)) {
unsigned single = 0;
if (screen->curss) {
dotext(screen,
screen->gsets[(int) (screen->curss)],
print_area, 1);
screen->curss = 0;
single++;
}
if (print_used > single) {
dotext(screen,
screen->gsets[(int) (screen->curgl)],
print_area + single,
print_used - single);
}
print_used = 0;
}
/*
* Accumulate string for APC, DCS, PM, OSC, SOS controls
* This should always be 8-bit characters.
*/
if (parsestate == sos_table) {
SafeAlloc(Char, string_area, string_used, string_size);
if (new_string == 0) {
fprintf(stderr,
"Cannot allocate %d bytes for string mode %d\n",
new_length, string_mode);
continue;
}
#if OPT_WIDE_CHARS
/*
* We cannot display codes above 255, but let's try to
* accommodate the application a little by not aborting the
* string.
*/
if ((c & 0xffff) > 255) {
nextstate = CASE_PRINT;
c = '?';
}
#endif
string_area = new_string;
string_size = new_length;
string_area[string_used++] = c;
} else if (parsestate != esc_table) {
/* if we were accumulating, we're not any more */
string_mode = 0;
string_used = 0;
}
TRACE(("parse %04X -> %d\n", c, nextstate));
switch (nextstate) {
case CASE_PRINT:
/* printable characters (see above) */
break;
case CASE_GROUND_STATE:
/* exit ignore mode */
parsestate = groundtable;
break;
case CASE_IGNORE:
/* Ignore character */
break;
case CASE_ENQ:
for (count = 0; screen->answer_back[count] != 0; count++)
unparseputc(screen->answer_back[count], screen->respond);
break;
case CASE_BELL:
if (string_mode == OSC) {
if (string_used)
string_area[--string_used] = '\0';
do_osc(string_area, string_used, c);
parsestate = groundtable;
} else {
/* bell */
Bell(XkbBI_TerminalBell, 0);
}
break;
case CASE_BS:
/* backspace */
CursorBack(screen, 1);
break;
case CASE_CR:
/* carriage return */
CarriageReturn(screen);
break;
case CASE_ESC:
/* escape */
if_OPT_VT52_MODE(screen, {
parsestate = vt52_esc_table;
break;
});
parsestate = esc_table;
break;
#if OPT_VT52_MODE
case CASE_VT52_CUP:
vt52_cup = TRUE;
nparam = 0;
break;
case CASE_VT52_IGNORE:
parsestate = vt52_ignore_table;
break;
#endif
case CASE_VMOT:
/*
* form feed, line feed, vertical tab
*/
xtermAutoPrint(c);
xtermIndex(screen, 1);
if (term->flags & LINEFEED)
CarriageReturn(screen);
do_xevents();
break;
case CASE_CBT:
/* cursor backward tabulation */
if ((count = param[0]) == DEFAULT)
count = 1;
while ((count-- > 0)
&& (TabToPrevStop())) ;
parsestate = groundtable;
break;
case CASE_CHT:
/* cursor forward tabulation */
if ((count = param[0]) == DEFAULT)
count = 1;
while ((count-- > 0)
&& (TabToNextStop())) ;
parsestate = groundtable;
break;
case CASE_TAB:
/* tab */
TabToNextStop();
break;
case CASE_SI:
screen->curgl = 0;
break;
case CASE_SO:
screen->curgl = 1;
break;
case CASE_DECDHL:
xterm_DECDHL(c == '3');
parsestate = groundtable;
break;
case CASE_DECSWL:
xterm_DECSWL();
parsestate = groundtable;
break;
case CASE_DECDWL:
xterm_DECDWL();
parsestate = groundtable;
break;
case CASE_SCR_STATE:
/* enter scr state */
parsestate = scrtable;
break;
case CASE_SCS0_STATE:
/* enter scs state 0 */
scstype = 0;
parsestate = scstable;
break;
case CASE_SCS1_STATE:
/* enter scs state 1 */
scstype = 1;
parsestate = scstable;
break;
case CASE_SCS2_STATE:
/* enter scs state 2 */
scstype = 2;
parsestate = scstable;
break;
case CASE_SCS3_STATE:
/* enter scs state 3 */
scstype = 3;
parsestate = scstable;
break;
case CASE_ESC_IGNORE:
/* unknown escape sequence */
parsestate = eigtable;
break;
case CASE_ESC_DIGIT:
/* digit in csi or dec mode */
if ((row = param[nparam - 1]) == DEFAULT)
row = 0;
param[nparam - 1] = 10 * row + (c - '0');
if (param[nparam - 1] > 65535)
param[nparam - 1] = 65535;
if (parsestate == csi_table)
parsestate = csi2_table;
break;
case CASE_ESC_SEMI:
/* semicolon in csi or dec mode */
if (nparam < NPARAM)
param[nparam++] = DEFAULT;
if (parsestate == csi_table)
parsestate = csi2_table;
break;
case CASE_DEC_STATE:
/* enter dec mode */
parsestate = dec_table;
break;
case CASE_DEC2_STATE:
/* enter dec2 mode */
parsestate = dec2_table;
break;
case CASE_DEC3_STATE:
/* enter dec3 mode */
parsestate = dec3_table;
break;
case CASE_ICH:
/* ICH */
if ((row = param[0]) < 1)
row = 1;
InsertChar(screen, row);
parsestate = groundtable;
break;
case CASE_CUU:
/* CUU */
if ((row = param[0]) < 1)
row = 1;
CursorUp(screen, row);
parsestate = groundtable;
break;
case CASE_CUD:
/* CUD */
if ((row = param[0]) < 1)
row = 1;
CursorDown(screen, row);
parsestate = groundtable;
break;
case CASE_CUF:
/* CUF */
if ((col = param[0]) < 1)
col = 1;
CursorForward(screen, col);
parsestate = groundtable;
break;
case CASE_CUB:
/* CUB */
if ((col = param[0]) < 1)
col = 1;
CursorBack(screen, col);
parsestate = groundtable;
break;
case CASE_CUP:
/* CUP | HVP */
if_OPT_XMC_GLITCH(screen, {
Jump_XMC(screen);
});
if ((row = param[0]) < 1)
row = 1;
if (nparam < 2 || (col = param[1]) < 1)
col = 1;
CursorSet(screen, row - 1, col - 1, term->flags);
parsestate = groundtable;
break;
case CASE_VPA:
if ((row = param[0]) < 1)
row = 1;
CursorSet(screen, row - 1, screen->cur_col, term->flags);
parsestate = groundtable;
break;
case CASE_HPA:
/* HPA | CHA */
if ((col = param[0]) < 1)
col = 1;
CursorSet(screen, screen->cur_row, col - 1, term->flags);
parsestate = groundtable;
break;
case CASE_HP_BUGGY_LL:
/* Some HP-UX applications have the bug that they
assume ESC F goes to the lower left corner of
the screen, regardless of what terminfo says. */
if (screen->hp_ll_bc)
CursorSet(screen, screen->max_row, 0, term->flags);
parsestate = groundtable;
break;
case CASE_ED:
/* ED */
do_erase_display(screen, param[0], OFF_PROTECT);
parsestate = groundtable;
break;
case CASE_EL:
/* EL */
do_erase_line(screen, param[0], OFF_PROTECT);
parsestate = groundtable;
break;
case CASE_ECH:
/* ECH */
ClearRight(screen, param[0] < 1 ? 1 : param[0]);
parsestate = groundtable;
break;
case CASE_IL:
/* IL */
if ((row = param[0]) < 1)
row = 1;
InsertLine(screen, row);
parsestate = groundtable;
break;
case CASE_DL:
/* DL */
if ((row = param[0]) < 1)
row = 1;
DeleteLine(screen, row);
parsestate = groundtable;
break;
case CASE_DCH:
/* DCH */
if ((row = param[0]) < 1)
row = 1;
DeleteChar(screen, row);
parsestate = groundtable;
break;
case CASE_TRACK_MOUSE:
if (screen->send_mouse_pos == VT200_HIGHLIGHT_MOUSE
|| nparam > 1) {
/* Track mouse as long as in window and between
* specified rows
*/
TrackMouse(param[0],
param[2] - 1, param[1] - 1,
param[3] - 1, param[4] - 2);
} else {
/* SD */
if ((count = param[0]) < 1)
count = 1;
RevScroll(screen, count);
do_xevents();
}
parsestate = groundtable;
break;
case CASE_DECID:
if_OPT_VT52_MODE(screen, {
unparseputc(ESC, screen->respond);
unparseputc('/', screen->respond);
unparseputc('Z', screen->respond);
parsestate = groundtable;
break;
});
param[0] = -1; /* Default ID parameter */
/* FALLTHRU */
case CASE_DA1:
/* DA1 */
if (param[0] <= 1) { /* less than means DEFAULT */
count = 0;
reply.a_type = CSI;
reply.a_pintro = '?';
/* The first param corresponds to the highest
* operating level (i.e., service level) of the
* emulation. A DEC terminal can be setup to
* respond with a different DA response, but
* there's no control sequence that modifies this.
* We set it via a resource.
*/
if (screen->terminal_id < 200) {
switch (screen->terminal_id) {
case 102:
reply.a_param[count++] = 6; /* VT102 */
break;
case 101:
reply.a_param[count++] = 1; /* VT101 */
reply.a_param[count++] = 0; /* no options */
break;
default: /* VT100 */
reply.a_param[count++] = 1; /* VT100 */
reply.a_param[count++] = 2; /* AVO */
break;
}
} else {
reply.a_param[count++] = 60 + screen->terminal_id / 100;
reply.a_param[count++] = 1; /* 132-columns */
reply.a_param[count++] = 2; /* printer */
reply.a_param[count++] = 6; /* selective-erase */
#if OPT_SUNPC_KBD
if (term->keyboard.type == keyboardIsVT220)
#endif
reply.a_param[count++] = 8; /* user-defined-keys */
reply.a_param[count++] = 9; /* national replacement charsets */
reply.a_param[count++] = 15; /* technical characters */
if_OPT_ISO_COLORS(screen, {
reply.a_param[count++] = 22; /* ANSI color, VT525 */
});
#if OPT_DEC_LOCATOR
reply.a_param[count++] = 29; /* ANSI text locator */
#endif
}
reply.a_nparam = count;
reply.a_inters = 0;
reply.a_final = 'c';
unparseseq(&reply, screen->respond);
}
parsestate = groundtable;
break;
case CASE_DA2:
/* DA2 */
if (param[0] <= 0) { /* less than means DEFAULT */
count = 0;
reply.a_type = CSI;
reply.a_pintro = '>';
if (screen->terminal_id >= 200)
reply.a_param[count++] = 1; /* VT220 */
else
reply.a_param[count++] = 0; /* VT100 (nonstandard) */
reply.a_param[count++] = XTERM_PATCH; /* Version */
reply.a_param[count++] = 0; /* options (none) */
reply.a_nparam = count;
reply.a_inters = 0;
reply.a_final = 'c';
unparseseq(&reply, screen->respond);
}
parsestate = groundtable;
break;
case CASE_DECRPTUI:
/* DECRPTUI */
if ((screen->terminal_id >= 400)
&& (param[0] <= 0)) { /* less than means DEFAULT */
unparseputc1(DCS, screen->respond);
unparseputc('!', screen->respond);
unparseputc('|', screen->respond);
unparseputc('0', screen->respond);
unparseputc1(ST, screen->respond);
}
parsestate = groundtable;
break;
case CASE_TBC:
/* TBC */
if ((row = param[0]) <= 0) /* less than means default */
TabClear(term->tabs, screen->cur_col);
else if (row == 3)
TabZonk(term->tabs);
parsestate = groundtable;
break;
case CASE_SET:
/* SET */
ansi_modes(term, bitset);
parsestate = groundtable;
break;
case CASE_RST:
/* RST */
ansi_modes(term, bitclr);
parsestate = groundtable;
break;
case CASE_SGR:
/* SGR */
for (row = 0; row < nparam; ++row) {
if_OPT_XMC_GLITCH(screen, {
Mark_XMC(screen, param[row]);
});
switch (param[row]) {
case DEFAULT:
case 0:
term->flags &=
~(INVERSE | BOLD | BLINK | UNDERLINE | INVISIBLE);
if_OPT_ISO_COLORS(screen, {
reset_SGR_Colors();
});
break;
case 1: /* Bold */
term->flags |= BOLD;
if_OPT_ISO_COLORS(screen, {
setExtendedFG();
});
break;
case 5: /* Blink */
term->flags |= BLINK;
if_OPT_ISO_COLORS(screen, {
setExtendedFG();
});
break;
case 4: /* Underscore */
term->flags |= UNDERLINE;
if_OPT_ISO_COLORS(screen, {
setExtendedFG();
});
break;
case 7:
term->flags |= INVERSE;
if_OPT_ISO_COLORS(screen, {
setExtendedBG();
});
break;
case 8:
term->flags |= INVISIBLE;
break;
case 22: /* reset 'bold' */
term->flags &= ~BOLD;
if_OPT_ISO_COLORS(screen, {
setExtendedFG();
});
break;
case 24:
term->flags &= ~UNDERLINE;
if_OPT_ISO_COLORS(screen, {
setExtendedFG();
});
break;
case 25: /* reset 'blink' */
term->flags &= ~BLINK;
if_OPT_ISO_COLORS(screen, {
setExtendedFG();
});
break;
case 27:
term->flags &= ~INVERSE;
if_OPT_ISO_COLORS(screen, {
setExtendedBG();
});
break;
case 28:
term->flags &= ~INVISIBLE;
break;
case 30:
case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
if_OPT_ISO_COLORS(screen, {
term->sgr_foreground = (param[row] - 30);
term->sgr_extended = 0;
setExtendedFG();
});
break;
case 38:
/* This is more complicated than I'd
like, but it should properly eat all
the parameters for unsupported modes
*/
if_OPT_ISO_COLORS(screen, {
row++;
if (row < nparam) {
switch (param[row]) {
case 5:
row++;
if (row < nparam &&
param[row] < NUM_ANSI_COLORS) {
term->sgr_foreground = param[row];
term->sgr_extended = 1;
setExtendedFG();
}
break;
default:
row += 7;
break;
}
}
});
break;
case 39:
if_OPT_ISO_COLORS(screen, {
reset_SGR_Foreground();
});
break;
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:
case 47:
if_OPT_ISO_COLORS(screen, {
term->sgr_background = (param[row] - 40);
setExtendedBG();
});
break;
case 48:
if_OPT_ISO_COLORS(screen, {
row++;
if (row < nparam) {
switch (param[row]) {
case 5:
row++;
if (row < nparam &&
param[row] < NUM_ANSI_COLORS) {
term->sgr_background = param[row];
setExtendedBG();
}
break;
default:
row += 7;
break;
}
}
});
break;
case 49:
if_OPT_ISO_COLORS(screen, {
reset_SGR_Background();
});
break;
case 90:
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
case 97:
if_OPT_AIX_COLORS(screen, {
term->sgr_foreground = (param[row] - 90 + 8);
term->sgr_extended = 0;
setExtendedFG();
});
break;
case 100:
#if !OPT_AIX_COLORS
if_OPT_ISO_COLORS(screen, {
reset_SGR_Foreground();
reset_SGR_Background();
});
break;
#endif
case 101:
case 102:
case 103:
case 104:
case 105:
case 106:
case 107:
if_OPT_AIX_COLORS(screen, {
term->sgr_background = (param[row] - 100 + 8);
setExtendedBG();
});
break;
}
}
parsestate = groundtable;
break;
/* DSR (except for the '?') is a superset of CPR */
case CASE_DSR:
private_function = True;
/* FALLTHRU */
case CASE_CPR:
count = 0;
reply.a_type = CSI;
reply.a_pintro = private_function ? '?' : 0;
reply.a_inters = 0;
reply.a_final = 'n';
switch (param[0]) {
case 5:
/* operating status */
reply.a_param[count++] = 0; /* (no malfunction ;-) */
break;
case 6:
/* CPR */
/* DECXCPR (with page=0) */
reply.a_param[count++] = screen->cur_row + 1;
reply.a_param[count++] = screen->cur_col + 1;
reply.a_final = 'R';
break;
case 15:
/* printer status */
reply.a_param[count++] = 13; /* implement printer */
break;
case 25:
/* UDK status */
reply.a_param[count++] = 20; /* UDK always unlocked */
break;
case 26:
/* keyboard status */
reply.a_param[count++] = 27;
reply.a_param[count++] = 1; /* North American */
if (screen->terminal_id >= 400) {
reply.a_param[count++] = 0; /* ready */
reply.a_param[count++] = 0; /* LK201 */
}
break;
case 53:
/* Locator status */
#if OPT_DEC_LOCATOR
reply.a_param[count++] = 50; /* locator ready */
#else
reply.a_param[count++] = 53; /* no locator */
#endif
break;
}
if ((reply.a_nparam = count) != 0)
unparseseq(&reply, screen->respond);
parsestate = groundtable;
private_function = False;
break;
case CASE_MC:
xtermMediaControl(param[0], FALSE);
parsestate = groundtable;
break;
case CASE_DEC_MC:
xtermMediaControl(param[0], TRUE);
parsestate = groundtable;
break;
case CASE_HP_MEM_LOCK:
case CASE_HP_MEM_UNLOCK:
if (screen->scroll_amt)
FlushScroll(screen);
if (parsestate[c] == CASE_HP_MEM_LOCK)
screen->top_marg = screen->cur_row;
else
screen->top_marg = 0;
parsestate = groundtable;
break;
case CASE_DECSTBM:
/* DECSTBM - set scrolling region */
if ((top = param[0]) < 1)
top = 1;
if (nparam < 2 || (bot = param[1]) == DEFAULT
|| bot > screen->max_row + 1
|| bot == 0)
bot = screen->max_row + 1;
if (bot > top) {
if (screen->scroll_amt)
FlushScroll(screen);
screen->top_marg = top - 1;
screen->bot_marg = bot - 1;
CursorSet(screen, 0, 0, term->flags);
}
parsestate = groundtable;
break;
case CASE_DECREQTPARM:
/* DECREQTPARM */
if (screen->terminal_id < 200) { /* VT102 */
if ((row = param[0]) == DEFAULT)
row = 0;
if (row == 0 || row == 1) {
reply.a_type = CSI;
reply.a_pintro = 0;
reply.a_nparam = 7;
reply.a_param[0] = row + 2;
reply.a_param[1] = 1; /* no parity */
reply.a_param[2] = 1; /* eight bits */
reply.a_param[3] = 128; /* transmit 38.4k baud */
reply.a_param[4] = 128; /* receive 38.4k baud */
reply.a_param[5] = 1; /* clock multiplier ? */
reply.a_param[6] = 0; /* STP flags ? */
reply.a_inters = 0;
reply.a_final = 'x';
unparseseq(&reply, screen->respond);
}
}
parsestate = groundtable;
break;
case CASE_DECSET:
/* DECSET */
dpmodes(term, bitset);
parsestate = groundtable;
#if OPT_TEK4014
if (screen->TekEmu)
return;
#endif
break;
case CASE_DECRST:
/* DECRST */
dpmodes(term, bitclr);
#if OPT_VT52_MODE
if (screen->ansi_level == 0)
groundtable = vt52_table;
else if (screen->terminal_id >= 100)
groundtable = ansi_table;
#endif
parsestate = groundtable;
break;
case CASE_DECALN:
/* DECALN */
if (screen->cursor_state)
HideCursor();
for (row = screen->max_row; row >= 0; row--) {
bzero(SCRN_BUF_ATTRS(screen, row),
col = screen->max_col + 1);
for (cp = SCRN_BUF_CHARS(screen, row); col > 0; col--)
*cp++ = (Char) 'E';
if_OPT_WIDE_CHARS(screen, {
bzero(SCRN_BUF_WIDEC(screen, row),
screen->max_col + 1);
});
}
ScrnRefresh(screen, 0, 0, screen->max_row + 1,
screen->max_col + 1, False);
parsestate = groundtable;
break;
case CASE_GSETS:
TRACE(("CASE_GSETS(%d) = '%c'\n", scstype, c));
screen->gsets[scstype] = c;
parsestate = groundtable;
break;
case CASE_DECSC:
/* DECSC */
CursorSave(term);
parsestate = groundtable;
break;
case CASE_DECRC:
/* DECRC */
CursorRestore(term);
if_OPT_ISO_COLORS(screen, {
setExtendedFG();
});
parsestate = groundtable;
break;
case CASE_DECKPAM:
/* DECKPAM */
term->keyboard.flags |= MODE_DECKPAM;
update_appkeypad();
parsestate = groundtable;
break;
case CASE_DECKPNM:
/* DECKPNM */
term->keyboard.flags &= ~MODE_DECKPAM;
update_appkeypad();
parsestate = groundtable;
break;
case CASE_CSI_QUOTE_STATE:
parsestate = csi_quo_table;
break;
/* the ANSI conformance levels are noted in the
* vt400 user's manual (I assume they're the non-DEC
* equivalents of DECSCL - T.Dickey)
*/
case CASE_ANSI_LEVEL_1:
if (screen->terminal_id >= 100) {
screen->ansi_level = 1;
show_8bit_control(False);
#if OPT_VT52_MODE
groundtable =
parsestate = ansi_table;
#endif
}
parsestate = groundtable;
break;
case CASE_ANSI_LEVEL_2:
if (screen->terminal_id >= 200)
screen->ansi_level = 2;
parsestate = groundtable;
break;
case CASE_ANSI_LEVEL_3:
if (screen->terminal_id >= 300)
screen->ansi_level = 3;
parsestate = groundtable;
break;
case CASE_DECSCL:
if (param[0] >= 61 && param[0] <= 63) {
screen->ansi_level = param[0] - 60;
if (param[0] > 61) {
if (param[1] == 1)
show_8bit_control(False);
else if (param[1] == 0 || param[1] == 2)
show_8bit_control(True);
}
}
parsestate = groundtable;
break;
case CASE_DECSCA:
screen->protected_mode = DEC_PROTECT;
if (param[0] <= 0 || param[0] == 2)
term->flags &= ~PROTECTED;
else if (param[0] == 1)
term->flags |= PROTECTED;
parsestate = groundtable;
break;
case CASE_DECSED:
/* DECSED */
do_erase_display(screen, param[0], DEC_PROTECT);
parsestate = groundtable;
break;
case CASE_DECSEL:
/* DECSEL */
do_erase_line(screen, param[0], DEC_PROTECT);
parsestate = groundtable;
break;
case CASE_ST:
if (!string_used)
break;
string_area[--string_used] = '\0';
switch (string_mode) {
case APC:
/* ignored */
break;
case DCS:
do_dcs(string_area, string_used);
break;
case OSC:
do_osc(string_area, string_used, ST);
break;
case PM:
/* ignored */
break;
case SOS:
/* ignored */
break;
}
parsestate = groundtable;
break;
case CASE_SOS:
/* Start of String */
string_mode = SOS;
parsestate = sos_table;
break;
case CASE_PM:
/* Privacy Message */
string_mode = PM;
parsestate = sos_table;
break;
case CASE_DCS:
/* Device Control String */
string_mode = DCS;
parsestate = sos_table;
break;
case CASE_APC:
/* Application Program Command */
string_mode = APC;
parsestate = sos_table;
break;
case CASE_SPA:
screen->protected_mode = ISO_PROTECT;
term->flags |= PROTECTED;
parsestate = groundtable;
break;
case CASE_EPA:
term->flags &= ~PROTECTED;
parsestate = groundtable;
break;
case CASE_SU:
/* SU */
if ((count = param[0]) < 1)
count = 1;
xtermScroll(screen, count);
parsestate = groundtable;
break;
case CASE_IND:
/* IND */
xtermIndex(screen, 1);
do_xevents();
parsestate = groundtable;
break;
case CASE_CPL:
/* cursor prev line */
CursorPrevLine(screen, param[0]);
parsestate = groundtable;
break;
case CASE_CNL:
/* cursor next line */
CursorNextLine(screen, param[0]);
parsestate = groundtable;
break;
case CASE_NEL:
/* NEL */
xtermIndex(screen, 1);
CarriageReturn(screen);
do_xevents();
parsestate = groundtable;
break;
case CASE_HTS:
/* HTS */
TabSet(term->tabs, screen->cur_col);
parsestate = groundtable;
break;
case CASE_RI:
/* RI */
RevIndex(screen, 1);
parsestate = groundtable;
break;
case CASE_SS2:
/* SS2 */
screen->curss = 2;
parsestate = groundtable;
break;
case CASE_SS3:
/* SS3 */
screen->curss = 3;
parsestate = groundtable;
break;
case CASE_CSI_STATE:
/* enter csi state */
nparam = 1;
param[0] = DEFAULT;
parsestate = csi_table;
break;
case CASE_ESC_SP_STATE:
/* esc space */
parsestate = esc_sp_table;
break;
case CASE_CSI_EX_STATE:
/* csi exclamation */
parsestate = csi_ex_table;
break;
#if OPT_DEC_LOCATOR
case CASE_CSI_TICK_STATE:
/* csi tick (') */
parsestate = csi_tick_table;
break;
case CASE_DECEFR:
TRACE(("DECEFR - Enable Filter Rectangle\n"));
if (screen->send_mouse_pos == DEC_LOCATOR) {
MotionOff(screen, term);
if ((screen->loc_filter_top = param[0]) < 1)
screen->loc_filter_top = LOC_FILTER_POS;
if (nparam < 2 || (screen->loc_filter_left = param[1]) < 1)
screen->loc_filter_left = LOC_FILTER_POS;
if (nparam < 3 || (screen->loc_filter_bottom = param[2]) < 1)
screen->loc_filter_bottom = LOC_FILTER_POS;
if (nparam < 4 || (screen->loc_filter_right = param[3]) < 1)
screen->loc_filter_right = LOC_FILTER_POS;
InitLocatorFilter(term);
}
parsestate = groundtable;
break;
case CASE_DECELR:
MotionOff(screen, term);
if (param[0] <= 0 || param[0] > 2) {
screen->send_mouse_pos = MOUSE_OFF;
TRACE(("DECELR - Disable Locator Reports\n"));
} else {
TRACE(("DECELR - Enable Locator Reports\n"));
screen->send_mouse_pos = DEC_LOCATOR;
if (param[0] == 2) {
screen->locator_reset = TRUE;
} else {
screen->locator_reset = FALSE;
}
if (nparam < 2 || param[1] != 1) {
screen->locator_pixels = FALSE;
} else {
screen->locator_pixels = TRUE;
}
screen->loc_filter = FALSE;
}
parsestate = groundtable;
break;
case CASE_DECSLE:
TRACE(("DECSLE - Select Locator Events\n"));
for (count = 0; count < nparam; ++count) {
switch (param[count]) {
case DEFAULT:
case 0:
MotionOff(screen, term);
screen->loc_filter = FALSE;
screen->locator_events = 0;
break;
case 1:
screen->locator_events |= LOC_BTNS_DN;
break;
case 2:
screen->locator_events &= ~LOC_BTNS_DN;
break;
case 3:
screen->locator_events |= LOC_BTNS_UP;
break;
case 4:
screen->locator_events &= ~LOC_BTNS_UP;
break;
}
}
parsestate = groundtable;
break;
case CASE_DECRQLP:
TRACE(("DECRQLP - Request Locator Position\n"));
if (param[0] < 2) {
/* Issue DECLRP Locator Position Report */
GetLocatorPosition(term);
}
parsestate = groundtable;
break;
#endif /* OPT_DEC_LOCATOR */
case CASE_S7C1T:
show_8bit_control(False);
parsestate = groundtable;
break;
case CASE_S8C1T:
#if OPT_VT52_MODE
if (screen->ansi_level <= 1)
break;
#endif
show_8bit_control(True);
parsestate = groundtable;
break;
case CASE_OSC:
/* Operating System Command */
parsestate = sos_table;
string_mode = OSC;
break;
case CASE_RIS:
/* RIS */
VTReset(TRUE, TRUE);
parsestate = groundtable;
break;
case CASE_DECSTR:
/* DECSTR */
VTReset(FALSE, FALSE);
parsestate = groundtable;
break;
case CASE_REP:
/* REP */
if (lastchar >= 0 &&
groundtable[E2A(lastchar)] == CASE_PRINT) {
IChar repeated[2];
count = (param[0] < 1) ? 1 : param[0];
repeated[0] = lastchar;
while (count-- > 0) {
dotext(screen,
screen->gsets[(int) (screen->curgl)],
repeated, 1);
}
}
parsestate = groundtable;
break;
case CASE_LS2:
/* LS2 */
screen->curgl = 2;
parsestate = groundtable;
break;
case CASE_LS3:
/* LS3 */
screen->curgl = 3;
parsestate = groundtable;
break;
case CASE_LS3R:
/* LS3R */
screen->curgr = 3;
parsestate = groundtable;
break;
case CASE_LS2R:
/* LS2R */
screen->curgr = 2;
parsestate = groundtable;
break;
case CASE_LS1R:
/* LS1R */
screen->curgr = 1;
parsestate = groundtable;
break;
case CASE_XTERM_SAVE:
savemodes(term);
parsestate = groundtable;
break;
case CASE_XTERM_RESTORE:
restoremodes(term);
parsestate = groundtable;
break;
case CASE_XTERM_WINOPS:
if (screen->allowWindowOps)
window_ops(term);
parsestate = groundtable;
break;
#if OPT_WIDE_CHARS
case CASE_ESC_PERCENT:
parsestate = esc_pct_table;
break;
case CASE_UTF8:
/* If we did not set UTF-8 mode from resource or the
* command-line, allow it to be enabled/disabled by
* control sequence. To keep the logic simple, require
* that wide_chars have been set during initialization
* so that we have been maintaining data structures for
* wide characters, anyway. Otherwise we would have to
* reallocate everything the first time we turned UTF-8
* mode on.
*/
if (screen->wide_chars
&& screen->utf8_mode != 2) {
screen->utf8_mode = (c == 'G');
TRACE(("UTF8 mode %s\n",
screen->utf8_mode ? "ON" : "OFF"));
} else {
TRACE(("UTF8 mode NOT turned %s (%s)\n",
(c == 'G') ? "ON" : "OFF",
(screen->utf8_mode == 2)
? "UTF-8 mode set from command-line"
: "wideChars resource was not set"));
}
parsestate = groundtable;
break;
#endif
case CASE_CSI_IGNORE:
parsestate = cigtable;
break;
}
if (parsestate == groundtable)
lastchar = thischar;
}
}
static Char *v_buffer; /* pointer to physical buffer */
static Char *v_bufstr = NULL; /* beginning of area to write */
static Char *v_bufptr; /* end of area to write */
static Char *v_bufend; /* end of physical buffer */
/* Write data to the pty as typed by the user, pasted with the mouse,
or generated by us in response to a query ESC sequence. */
int
v_write(int f, Char * data, int len)
{
int riten;
int c = len;
if (v_bufstr == NULL && len > 0) {
v_buffer = (Char *) XtMalloc(len);
v_bufstr = v_buffer;
v_bufptr = v_buffer;
v_bufend = v_buffer + len;
}
#ifdef DEBUG
if (debug) {
fprintf(stderr, "v_write called with %d bytes (%d left over)",
len, v_bufptr - v_bufstr);
if (len > 1 && len < 10)
fprintf(stderr, " \"%.*s\"", len, (char *) data);
fprintf(stderr, "\n");
}
#endif
#ifdef VMS
if ((1 << f) != pty_mask)
return (tt_write((char *) data, len));
#else /* VMS */
if (!FD_ISSET(f, &pty_mask))
return (write(f, (char *) data, len));
#endif /* VMS */
/*
* Append to the block we already have.
* Always doing this simplifies the code, and
* isn't too bad, either. If this is a short
* block, it isn't too expensive, and if this is
* a long block, we won't be able to write it all
* anyway.
*/
if (len > 0) {
if (v_bufend < v_bufptr + len) { /* we've run out of room */
if (v_bufstr != v_buffer) {
/* there is unused space, move everything down */
/* possibly overlapping memmove here */
#ifdef DEBUG
if (debug)
fprintf(stderr, "moving data down %d\n",
v_bufstr - v_buffer);
#endif
memmove(v_buffer, v_bufstr, v_bufptr - v_bufstr);
v_bufptr -= v_bufstr - v_buffer;
v_bufstr = v_buffer;
}
if (v_bufend < v_bufptr + len) {
/* still won't fit: get more space */
/* Don't use XtRealloc because an error is not fatal. */
int size = v_bufptr - v_buffer; /* save across realloc */
v_buffer = (Char *) realloc(v_buffer, size + len);
if (v_buffer) {
#ifdef DEBUG
if (debug)
fprintf(stderr, "expanded buffer to %d\n",
size + len);
#endif
v_bufstr = v_buffer;
v_bufptr = v_buffer + size;
v_bufend = v_bufptr + len;
} else {
/* no memory: ignore entire write request */
fprintf(stderr, "%s: cannot allocate buffer space\n",
xterm_name);
v_buffer = v_bufstr; /* restore clobbered pointer */
c = 0;
}
}
}
if (v_bufend >= v_bufptr + len) {
/* new stuff will fit */
memmove(v_bufptr, data, len);
v_bufptr += len;
}
}
/*
* Write out as much of the buffer as we can.
* Be careful not to overflow the pty's input silo.
* We are conservative here and only write
* a small amount at a time.
*
* If we can't push all the data into the pty yet, we expect write
* to return a non-negative number less than the length requested
* (if some data written) or -1 and set errno to EAGAIN,
* EWOULDBLOCK, or EINTR (if no data written).
*
* (Not all systems do this, sigh, so the code is actually
* a little more forgiving.)
*/
#define MAX_PTY_WRITE 128 /* 1/2 POSIX minimum MAX_INPUT */
if (v_bufptr > v_bufstr) {
#ifdef VMS
riten = tt_write(v_bufstr,
((v_bufptr - v_bufstr <= VMS_TERM_BUFFER_SIZE)
? v_bufptr - v_bufstr
: VMS_TERM_BUFFER_SIZE));
if (riten == 0)
return (riten);
#else /* VMS */
riten = write(f, v_bufstr,
((v_bufptr - v_bufstr <= MAX_PTY_WRITE)
? v_bufptr - v_bufstr
: MAX_PTY_WRITE));
if (riten < 0)
#endif /* VMS */
{
#ifdef DEBUG
if (debug)
perror("write");
#endif
riten = 0;
}
#ifdef DEBUG
if (debug)
fprintf(stderr, "write called with %d, wrote %d\n",
v_bufptr - v_bufstr <= MAX_PTY_WRITE ?
v_bufptr - v_bufstr : MAX_PTY_WRITE,
riten);
#endif
v_bufstr += riten;
if (v_bufstr >= v_bufptr) /* we wrote it all */
v_bufstr = v_bufptr = v_buffer;
}
/*
* If we have lots of unused memory allocated, return it
*/
if (v_bufend - v_bufptr > 1024) { /* arbitrary hysteresis */
/* save pointers across realloc */
int start = v_bufstr - v_buffer;
int size = v_bufptr - v_buffer;
int allocsize = size ? size : 1;
v_buffer = (Char *) realloc(v_buffer, allocsize);
if (v_buffer) {
v_bufstr = v_buffer + start;
v_bufptr = v_buffer + size;
v_bufend = v_buffer + allocsize;
#ifdef DEBUG
if (debug)
fprintf(stderr, "shrunk buffer to %d\n", allocsize);
#endif
} else {
/* should we print a warning if couldn't return memory? */
v_buffer = v_bufstr - start; /* restore clobbered pointer */
}
}
return (c);
}
#ifdef VMS
static int select_mask;
static int write_mask;
static int pty_read_bytes;
#define ptymask() (v_bufptr > v_bufstr ? pty_mask : 0)
static IChar
in_put(void)
{
int status;
Dimension replyWidth, replyHeight;
XtGeometryResult stat;
register TScreen *screen = &term->screen;
register char *cp;
register int i;
select_mask = pty_mask; /* force initial read */
for (;;) {
/* if the terminal changed size, resize the widget */
if (tt_changed) {
tt_changed = FALSE;
stat = XtMakeResizeRequest((Widget) term,
((Dimension) FontWidth(screen)
* (tt_width)
+ 2 * screen->border
+ screen->fullVwin.sb_info.width),
((Dimension) FontHeight(screen)
* (tt_length)
+ 2 * screen->border),
&replyWidth, &replyHeight);
if (stat == XtGeometryYes || stat == XtGeometryDone) {
term->core.width = replyWidth;
term->core.height = replyHeight;
ScreenResize(&term->screen, replyWidth, replyHeight,
&term->flags);
}
}
if ((select_mask & pty_mask) && (eventMode == NORMAL)) {
#ifdef ALLOWLOGGING
if (screen->logging) {
FlushLog(screen);
}
#endif
if (read_queue.flink != 0) {
VTbuffer.cnt = tt_read(VTbuffer.ptr = VTbuffer.buf);
if (VTbuffer.cnt == 0)
Panic("input: read returned zero\n", 0);
else {
/* strip parity bit */
for (i = VTbuffer.cnt, cp = VTbuffer.ptr; i > 0; i--)
*cp++ &= 0177; /* originally CHAR */
if (screen->scrollWidget && screen->scrollttyoutput &&
screen->topline < 0)
/* Scroll to bottom */
WindowScroll(screen, 0);
break;
}
} else {
sys$hiber();
}
}
if (screen->scroll_amt)
FlushScroll(screen);
if (screen->cursor_set && (screen->cursor_col != screen->cur_col
|| screen->cursor_row != screen->cur_row)) {
if (screen->cursor_state)
HideCursor();
ShowCursor();
} else if (screen->cursor_set != screen->cursor_state) {
if (screen->cursor_set)
ShowCursor();
else
HideCursor();
}
#if OPT_INPUT_METHOD
PreeditPosition(screen);
#endif
if (QLength(screen->display)) {
select_mask = X_mask;
} else {
write_mask = ptymask();
XFlush(screen->display);
select_mask = Select_mask;
if (eventMode != NORMAL)
select_mask = X_mask;
}
if (write_mask & ptymask()) {
v_write(screen->respond, 0, 0); /* flush buffer */
}
if (select_mask & X_mask) {
if (VTbuffer.cnt <= 0) {
VTbuffer.cnt = 0;
VTbuffer.ptr = VTbuffer.buf;
}
xevents();
if (VTbuffer.cnt > 0)
break;
}
}
VTbuffer.cnt--;
return (*VTbuffer.ptr++);
}
#else /* VMS */
static fd_set select_mask;
static fd_set write_mask;
static int pty_read_bytes;
static IChar
in_put(void)
{
register TScreen *screen = &term->screen;
register int i, time_select;
static struct timeval select_timeout;
#if OPT_BLINK_CURS
#define TICK (1000/8)
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
int tick = MAX(1, MIN(screen->cursor_on, screen->cursor_off)) * TICK;
#endif
for (;;) {
if (eventMode == NORMAL
&& getPtyData(screen, &select_mask, &VTbuffer)) {
if (screen->scrollWidget
&& screen->scrollttyoutput
&& screen->topline < 0)
WindowScroll(screen, 0); /* Scroll to bottom */
pty_read_bytes += VTbuffer.cnt;
/* stop speed reading at some point to look for X stuff */
/* (4096 is just a random large number.) */
if (pty_read_bytes > 4096)
FD_CLR(screen->respond, &select_mask);
break;
}
pty_read_bytes = 0;
/* update the screen */
if (screen->scroll_amt)
FlushScroll(screen);
if (screen->cursor_set && (screen->cursor_col != screen->cur_col
|| screen->cursor_row != screen->cur_row)) {
if (screen->cursor_state)
HideCursor();
ShowCursor();
} else if (screen->cursor_set != screen->cursor_state) {
if (screen->cursor_set)
ShowCursor();
else
HideCursor();
}
#if OPT_INPUT_METHOD
PreeditPosition(screen);
#endif
XFlush(screen->display); /* always flush writes before waiting */
/* Update the masks and, unless X events are already in the queue,
wait for I/O to be possible. */
XFD_COPYSET(&Select_mask, &select_mask);
/* in selection mode xterm does not read pty */
if (eventMode != NORMAL)
FD_CLR(screen->respond, &select_mask);
if (v_bufptr > v_bufstr) {
XFD_COPYSET(&pty_mask, &write_mask);
} else
FD_ZERO(&write_mask);
select_timeout.tv_sec = 0;
time_select = 0;
/*
* if there's either an XEvent or an XtTimeout pending, just take
* a quick peek, i.e. timeout from the select() immediately. If
* there's nothing pending, let select() block a little while, but
* for a shorter interval than the arrow-style scrollbar timeout.
* The blocking is optional, because it tends to increase the load
* on the host.
*/
if (XtAppPending(app_con)) {
select_timeout.tv_usec = 0;
time_select = 1;
} else if (screen->awaitInput) {
select_timeout.tv_usec = 50000;
time_select = 1;
#if OPT_BLINK_CURS
} else if ((screen->cursor_blink &&
((screen->select & FOCUS) || screen->always_highlight)) ||
(screen->cursor_state == BLINKED_OFF)) {
select_timeout.tv_usec = tick;
while (select_timeout.tv_usec > 1000000) {
select_timeout.tv_usec -= 1000000;
select_timeout.tv_sec++;
}
time_select = 1;
#endif
}
i = select(max_plus1, &select_mask, &write_mask, 0,
time_select ? &select_timeout : 0);
if (i < 0) {
if (errno != EINTR)
SysError(ERROR_SELECT);
continue;
}
/* if there is room to write more data to the pty, go write more */
if (FD_ISSET(screen->respond, &write_mask)) {
v_write(screen->respond, (Char *) 0, 0); /* flush buffer */
}
/* if there are X events already in our queue, it
counts as being readable */
if (XtAppPending(app_con) ||
FD_ISSET(ConnectionNumber(screen->display), &select_mask)) {
xevents();
if (VTbuffer.cnt > 0) /* HandleInterpret */
break;
}
}
return nextPtyData(&VTbuffer);
}
#endif /* VMS */
#if OPT_INPUT_METHOD
/*
* For OverTheSpot, client has to inform the position for XIM preedit.
*/
static void
PreeditPosition(TScreen * screen)
{
XPoint spot;
XVaNestedList list;
if (!screen->xic)
return;
spot.x = CurCursorX(screen, screen->cur_row, screen->cur_col);
spot.y = CursorY(screen, screen->cur_row) + screen->fs_ascent;
list = XVaCreateNestedList(0,
XNSpotLocation, &spot,
XNForeground, screen->foreground,
XNBackground, term->core.background_pixel,
NULL);
XSetICValues(screen->xic, XNPreeditAttributes, list, NULL);
XFree(list);
}
#endif
/*
* process a string of characters according to the character set indicated
* by charset. worry about end of line conditions (wraparound if selected).
*/
void
dotext(TScreen * screen,
int charset,
IChar * buf, /* start of characters to process */
Cardinal len) /* end */
{
#if OPT_WIDE_CHARS
Cardinal chars_chomped;
#else
int next_col, last_col, this_col; /* must be signed */
#endif
Cardinal offset;
#if OPT_WIDE_CHARS
/* don't translate if we use UTF-8, and are not handling legacy support
* for line-drawing characters.
*/
if (!screen->utf8_mode
|| (screen->vt100_graphics && charset == '0'))
#endif
if (!xtermCharSetOut(buf, buf + len, charset))
return;
if_OPT_XMC_GLITCH(screen, {
Cardinal n;
if (charset != '?') {
for (n = 0; n < len; n++) {
if (buf[n] == XMC_GLITCH)
buf[n] = XMC_GLITCH + 1;
}
}
});
#if OPT_WIDE_CHARS
for (offset = 0; offset < len; offset += chars_chomped) {
int width_available = screen->max_col - screen->cur_col + 1;
int width_here = 0, need_wrap = 0;
chars_chomped = 0;
if (screen->do_wrap && (term->flags & WRAPAROUND)) {
/* mark that we had to wrap this line */
ScrnSetWrapped(screen, screen->cur_row);
xtermAutoPrint('\n');
xtermIndex(screen, 1);
screen->cur_col = 0;
screen->do_wrap = 0;
width_available = screen->max_col - screen->cur_col + 1;
}
while (width_here <= width_available && chars_chomped < (len - offset)) {
width_here += my_wcwidth(buf[chars_chomped + offset]);
chars_chomped++;
}
if (width_here > width_available) {
chars_chomped--;
width_here -= my_wcwidth(buf[chars_chomped + offset]);
need_wrap = 1;
}
if (width_here == width_available) {
need_wrap = 1;
}
if (chars_chomped != (len - offset)) {
need_wrap = 1;
}
/*
* Split the wide characters back into separate arrays of 8-bit
* characters so we can use the existing interface.
*
* FIXME: If we rewrote this interface, it would involve
* rewriting all of the memory-management for the screen
* buffers (perhaps this is simpler).
*/
{
static unsigned limit;
static Char *hibyte, *lobyte;
Boolean both = False;
unsigned j, k;
if (chars_chomped >= limit) {
limit = (chars_chomped + 1) * 2;
lobyte = (Char *) XtRealloc((char *) lobyte, limit);
hibyte = (Char *) XtRealloc((char *) hibyte, limit);
}
for (j = offset; j < offset + chars_chomped; j++) {
k = j - offset;
lobyte[k] = buf[j];
if (buf[j] > 255) {
hibyte[k] = (buf[j] >> 8);
both = True;
} else {
hibyte[k] = 0;
}
}
WriteText(screen, PAIRED_CHARS(lobyte,
(both ? hibyte : 0)),
chars_chomped);
}
screen->do_wrap = need_wrap;
}
#else
for (offset = 0; offset < len; offset += this_col) {
last_col = CurMaxCol(screen, screen->cur_row);
this_col = last_col - screen->cur_col + 1;
if (this_col <= 1) {
if (screen->do_wrap && (term->flags & WRAPAROUND)) {
/* mark that we had to wrap this line */
ScrnSetWrapped(screen, screen->cur_row);
xtermAutoPrint('\n');
xtermIndex(screen, 1);
screen->cur_col = 0;
screen->do_wrap = 0;
this_col = last_col + 1;
} else
this_col = 1;
}
if (offset + this_col > len) {
this_col = len - offset;
}
next_col = screen->cur_col + this_col;
WriteText(screen, PAIRED_CHARS(buf + offset,
buf2 ? buf2 + offset : 0),
this_col);
/*
* the call to WriteText updates screen->cur_col.
* If screen->cur_col != next_col, we must have
* hit the right margin, so set the do_wrap flag.
*/
screen->do_wrap = (screen->cur_col < (int) next_col);
}
#endif
}
#if HANDLE_STRUCT_NOTIFY
/* Flag icon name with "*** " on window output when iconified.
* I'd like to do something like reverse video, but I don't
* know how to tell this to window managers in general.
*
* mapstate can be IsUnmapped, !IsUnmapped, or -1;
* -1 means no change; the other two are set by event handlers
* and indicate a new mapstate. !IsMapped is done in the handler.
* we worry about IsUnmapped when output occurs. -IAN!
*/
static int mapstate = -1;
#endif /* HANDLE_STRUCT_NOTIFY */
#if OPT_WIDE_CHARS
int
visual_width(PAIRED_CHARS(Char * str, Char * str2), Cardinal len)
{
/* returns the visual width of a string (doublewide characters count
as 2, normalwide characters count as 1) */
int my_len = 0;
while (len) {
int ch = *str;
if (str2)
ch |= *str2 << 8;
if (str)
str++;
if (str2)
str2++;
if (iswide(ch))
my_len += 2;
else
my_len++;
len--;
}
return my_len;
}
#endif
/*
* write a string str of length len onto the screen at
* the current cursor position. update cursor position.
*/
static void
WriteText(TScreen * screen, PAIRED_CHARS(Char * str, Char * str2), Cardinal len)
{
unsigned test;
unsigned flags = term->flags;
int fg_bg = makeColorPair(term->cur_foreground, term->cur_background);
GC currentGC;
TRACE(("WriteText (%2d,%2d) (%d) %3d:%s\n",
screen->cur_row,
screen->cur_col,
curXtermChrSet(screen->cur_row),
len, visibleChars(PAIRED_CHARS(str, str2), len)));
if (screen->cur_row - screen->topline <= screen->max_row) {
if (screen->cursor_state)
HideCursor();
if (flags & INSERT) {
InsertChar(screen, visual_width(PAIRED_CHARS(str, str2), len));
}
if (!AddToRefresh(screen)) {
/* make sure that the correct GC is current */
currentGC = updatedXtermGC(screen, flags, fg_bg, False);
if (screen->scroll_amt)
FlushScroll(screen);
if (flags & INVISIBLE) {
memset(str, ' ', len);
if_OPT_WIDE_CHARS(screen, {
if (str2 != 0)
memset(str2, ' ', len);
});
}
TRACE(("WriteText calling drawXtermText (%d,%d)\n",
screen->cur_col,
screen->cur_row));
test = flags;
checkVeryBoldColors(test, term->cur_foreground);
drawXtermText(screen, test, currentGC,
CurCursorX(screen, screen->cur_row, screen->cur_col),
CursorY(screen, screen->cur_row),
curXtermChrSet(screen->cur_row),
PAIRED_CHARS(str, str2), len, 0);
resetXtermGC(screen, flags, False);
/*
* The following statements compile data to compute the
* average number of characters written on each call to
* XText. The data may be examined via the use of a
* "hidden" escape sequence.
*/
#ifdef UNUSED
ctotal += len;
++ntotal;
#endif
}
}
ScreenWrite(screen, PAIRED_CHARS(str, str2), flags, fg_bg, len);
CursorForward(screen, visual_width(PAIRED_CHARS(str, str2), len));
#if OPT_ZICONBEEP
/* Flag icon name with "***" on window output when iconified.
*/
if (zIconBeep && mapstate == IsUnmapped && !zIconBeep_flagged) {
static char *icon_name;
static Arg args[] =
{
{XtNiconName, (XtArgVal) & icon_name}
};
icon_name = NULL;
XtGetValues(toplevel, args, XtNumber(args));
if (icon_name != NULL) {
zIconBeep_flagged = True;
Changename(icon_name);
}
if (zIconBeep > 0)
XBell(XtDisplay(toplevel), zIconBeep);
}
mapstate = -1;
#endif /* OPT_ZICONBEEP */
}
#if HANDLE_STRUCT_NOTIFY
/* Flag icon name with "***" on window output when iconified.
*/
static void
HandleStructNotify(Widget w GCC_UNUSED,
XtPointer closure GCC_UNUSED,
XEvent * event,
Boolean * cont GCC_UNUSED)
{
static char *icon_name;
static Arg args[] =
{
{XtNiconName, (XtArgVal) & icon_name}
};
switch (event->type) {
case MapNotify:
TRACE(("HandleStructNotify(MapNotify)\n"));
#if OPT_ZICONBEEP
if (zIconBeep_flagged) {
zIconBeep_flagged = False;
icon_name = NULL;
XtGetValues(toplevel, args, XtNumber(args));
if (icon_name != NULL) {
char *buf = (char *) malloc(strlen(icon_name) + 1);
if (buf == NULL) {
zIconBeep_flagged = True;
return;
}
strcpy(buf, icon_name + 4);
Changename(buf);
free(buf);
}
}
#endif /* OPT_ZICONBEEP */
mapstate = !IsUnmapped;
break;
case UnmapNotify:
TRACE(("HandleStructNotify(UnmapNotify)\n"));
mapstate = IsUnmapped;
break;
case ConfigureNotify:
TRACE(("HandleStructNotify(ConfigureNotify)\n"));
#if OPT_TOOLBAR
if (term->screen.Vshow) {
#ifndef NO_ACTIVE_ICON
struct _vtwin *Vwin = term->screen.whichVwin;
#else
struct _vtwin *Vwin = &(term->screen.fullVwin);
#endif
if (Vwin->menu_bar) {
XtVaGetValues(Vwin->menu_bar,
XtNheight, &Vwin->menu_height,
(XtPointer) 0);
TRACE(("...menu_height %d\n", Vwin->menu_height));
}
}
#endif
break;
default:
TRACE(("HandleStructNotify(event %d)\n", event->type));
break;
}
}
#endif /* HANDLE_STRUCT_NOTIFY */
/*
* process ANSI modes set, reset
*/
static void
ansi_modes(XtermWidget termw,
void (*func) (unsigned *p, unsigned mask))
{
register int i;
for (i = 0; i < nparam; ++i) {
switch (param[i]) {
case 2: /* KAM (if set, keyboard locked */
(*func) (&termw->keyboard.flags, MODE_KAM);
break;
case 4: /* IRM */
(*func) (&termw->flags, INSERT);
break;
case 12: /* SRM (if set, local echo */
(*func) (&termw->keyboard.flags, MODE_SRM);
break;
case 20: /* LNM */
(*func) (&termw->flags, LINEFEED);
update_autolinefeed();
break;
}
}
}
#define set_mousemode(mode) \
screen->send_mouse_pos = (func == bitset) ? mode : MOUSE_OFF
#define set_mouseflag(f) \
((func == bitset) \
? SCREEN_FLAG_set(screen, f) \
: SCREEN_FLAG_unset(screen, f))
/*
* process DEC private modes set, reset
*/
static void
dpmodes(XtermWidget termw,
void (*func) (unsigned *p, unsigned mask))
{
register TScreen *screen = &termw->screen;
register int i, j;
for (i = 0; i < nparam; ++i) {
TRACE(("%s %d\n", (func == bitset) ? "DECSET" : "DECRST", param[i]));
switch (param[i]) {
case 1: /* DECCKM */
(*func) (&termw->keyboard.flags, MODE_DECCKM);
update_appcursor();
break;
case 2: /* ANSI/VT52 mode */
if (func == bitset) { /* ANSI (VT100) */
resetCharsets(screen);
if_OPT_VT52_MODE(screen, {
screen->ansi_level = 1;
});
}
#if OPT_VT52_MODE
else if (screen->terminal_id >= 100) { /* VT52 */
screen->ansi_level = 0;
param[0] = 0;
param[1] = 0;
resetCharsets(screen);
}
#endif
break;
case 3: /* DECCOLM */
if (screen->c132) {
ClearScreen(screen);
CursorSet(screen, 0, 0, termw->flags);
if ((j = func == bitset ? 132 : 80) !=
((termw->flags & IN132COLUMNS) ? 132 : 80) ||
j != screen->max_col + 1)
RequestResize(termw, -1, j, TRUE);
(*func) (&termw->flags, IN132COLUMNS);
}
break;
case 4: /* DECSCLM (slow scroll) */
if (func == bitset) {
screen->jumpscroll = 0;
if (screen->scroll_amt)
FlushScroll(screen);
} else
screen->jumpscroll = 1;
(*func) (&termw->flags, SMOOTHSCROLL);
update_jumpscroll();
break;
case 5: /* DECSCNM */
j = termw->flags;
(*func) (&termw->flags, REVERSE_VIDEO);
if ((termw->flags ^ j) & REVERSE_VIDEO)
ReverseVideo(termw);
/* update_reversevideo done in RevVid */
break;
case 6: /* DECOM */
(*func) (&termw->flags, ORIGIN);
CursorSet(screen, 0, 0, termw->flags);
break;
case 7: /* DECAWM */
(*func) (&termw->flags, WRAPAROUND);
update_autowrap();
break;
case 8: /* DECARM */
/* ignore autorepeat */
break;
case SET_X10_MOUSE: /* MIT bogus sequence */
MotionOff(screen, termw);
set_mousemode(X10_MOUSE);
break;
case 18: /* DECPFF: print form feed */
screen->printer_formfeed = (func == bitset) ? ON : OFF;
break;
case 19: /* DECPEX: print extent */
screen->printer_extent = (func == bitset) ? ON : OFF;
break;
case 25: /* DECTCEM: Show/hide cursor (VT200) */
screen->cursor_set = (func == bitset) ? ON : OFF;
break;
case 30: /* rxvt */
if (screen->fullVwin.sb_info.width != ((func == bitset) ? ON : OFF))
ToggleScrollBar(termw);
break;
#if OPT_SHIFT_FONTS
case 35: /* rxvt */
term->misc.shift_fonts = (func == bitset) ? ON : OFF;
break;
#endif
case 38: /* DECTEK */
#if OPT_TEK4014
if (func == bitset && !(screen->inhibit & I_TEK)) {
#ifdef ALLOWLOGGING
if (screen->logging && TekPtyData()) {
FlushLog(screen);
screen->logstart = DecodedData(Tbuffer);
}
#endif
screen->TekEmu = TRUE;
}
#endif
break;
case 40: /* 132 column mode */
screen->c132 = (func == bitset);
update_allow132();
break;
case 41: /* curses hack */
screen->curses = (func == bitset);
update_cursesemul();
break;
case 42: /* DECNRCM national charset (VT220) */
(*func) (&termw->flags, NATIONAL);
break;
case 44: /* margin bell */
screen->marginbell = (func == bitset);
if (!screen->marginbell)
screen->bellarmed = -1;
update_marginbell();
break;
case 45: /* reverse wraparound */
(*func) (&termw->flags, REVERSEWRAP);
update_reversewrap();
break;
#ifdef ALLOWLOGGING
case 46: /* logging */
#ifdef ALLOWLOGFILEONOFF
/*
* if this feature is enabled, logging may be
* enabled and disabled via escape sequences.
*/
if (func == bitset)
StartLog(screen);
else
CloseLog(screen);
#else
Bell(XkbBI_Info, 0);
Bell(XkbBI_Info, 0);
#endif /* ALLOWLOGFILEONOFF */
break;
#endif
case 1049: /* alternate buffer & cursor */
if (!termw->misc.titeInhibit) {
if (func == bitset) {
CursorSave(termw);
ToAlternate(screen);
ClearScreen(screen);
} else {
FromAlternate(screen);
CursorRestore(termw);
}
} else if (termw->misc.tiXtraScroll) {
if (func == bitset) {
xtermScroll(screen, screen->max_row);
}
}
break;
case 1047:
case 47: /* alternate buffer */
if (!termw->misc.titeInhibit) {
if (func == bitset) {
ToAlternate(screen);
} else {
if (screen->alternate
&& (param[i] == 1047))
ClearScreen(screen);
FromAlternate(screen);
}
} else if (termw->misc.tiXtraScroll) {
if (func == bitset) {
xtermScroll(screen, screen->max_row);
}
}
break;
case 66: /* DECNKM */
(*func) (&termw->keyboard.flags, MODE_DECKPAM);
update_appkeypad();
break;
case 67: /* DECBKM */
/* back-arrow mapped to backspace or delete(D) */
(*func) (&termw->keyboard.flags, MODE_DECBKM);
TRACE(("DECSET DECBKM %s\n",
(termw->keyboard.flags & MODE_DECBKM)
? "on"
: "off"));
update_decbkm();
break;
case SET_VT200_MOUSE: /* xterm bogus sequence */
MotionOff(screen, termw);
set_mousemode(VT200_MOUSE);
break;
case SET_VT200_HIGHLIGHT_MOUSE: /* xterm sequence w/hilite tracking */
MotionOff(screen, termw);
set_mousemode(VT200_HIGHLIGHT_MOUSE);
break;
case SET_BTN_EVENT_MOUSE:
MotionOff(screen, termw);
set_mousemode(BTN_EVENT_MOUSE);
break;
case SET_ANY_EVENT_MOUSE:
set_mousemode(ANY_EVENT_MOUSE);
if (screen->send_mouse_pos == MOUSE_OFF) {
screen->event_mask |= ButtonMotionMask;
screen->event_mask &= ~PointerMotionMask;
} else {
screen->event_mask &= ~ButtonMotionMask;
screen->event_mask |= PointerMotionMask;
}
XSelectInput(XtDisplay(termw), XtWindow(term), screen->event_mask);
break;
case 1010: /* rxvt */
screen->scrollttyoutput = (func == bitset) ? ON : OFF;
update_scrollttyoutput();
break;
case 1011: /* rxvt */
screen->scrollkey = (func == bitset) ? ON : OFF;
update_scrollkey();
break;
#if OPT_NUM_LOCK
case 1035:
term->misc.real_NumLock = (func == bitset) ? ON : OFF;
break;
case 1036:
screen->meta_sends_esc = (func == bitset) ? ON : OFF;
break;
#endif
case 1037:
screen->delete_is_del = (func == bitset) ? ON : OFF;
break;
case 1048:
if (!termw->misc.titeInhibit) {
if (func == bitset)
CursorSave(termw);
else
CursorRestore(termw);
}
break;
case 1051:
set_keyboard_type(keyboardIsSun, func == bitset);
break;
#if OPT_HP_FUNC_KEYS
case 1052:
set_keyboard_type(keyboardIsHP, func == bitset);
break;
#endif
#if OPT_SCO_FUNC_KEYS
case 1053:
set_keyboard_type(keyboardIsSCO, func == bitset);
break;
#endif
case 1060:
set_keyboard_type(keyboardIsLegacy, func == bitset);
break;
#if OPT_SUNPC_KBD
case 1061:
set_keyboard_type(keyboardIsVT220, func == bitset);
break;
#endif
#if OPT_READLINE
case SET_BUTTON1_MOVE_POINT:
set_mouseflag(click1_moves);
break;
case SET_BUTTON2_MOVE_POINT:
set_mouseflag(paste_moves);
break;
case SET_DBUTTON3_DELETE:
set_mouseflag(dclick3_deletes);
break;
case SET_PASTE_IN_BRACKET:
set_mouseflag(paste_brackets);
break;
case SET_PASTE_QUOTE:
set_mouseflag(paste_quotes);
break;
case SET_PASTE_LITERAL_NL:
set_mouseflag(paste_literal_nl);
break;
#endif /* OPT_READLINE */
}
}
}
/*
* process xterm private modes save
*/
static void
savemodes(XtermWidget termw)
{
register TScreen *screen = &termw->screen;
register int i;
for (i = 0; i < nparam; i++) {
switch (param[i]) {
case 1: /* DECCKM */
DoSM(DP_DECCKM, termw->keyboard.flags & MODE_DECCKM);
break;
case 3: /* DECCOLM */
if (screen->c132)
DoSM(DP_DECCOLM, termw->flags & IN132COLUMNS);
break;
case 4: /* DECSCLM (slow scroll) */
DoSM(DP_DECSCLM, termw->flags & SMOOTHSCROLL);
break;
case 5: /* DECSCNM */
DoSM(DP_DECSCNM, termw->flags & REVERSE_VIDEO);
break;
case 6: /* DECOM */
DoSM(DP_DECOM, termw->flags & ORIGIN);
break;
case 7: /* DECAWM */
DoSM(DP_DECAWM, termw->flags & WRAPAROUND);
break;
case 8: /* DECARM */
/* ignore autorepeat */
break;
case SET_X10_MOUSE: /* mouse bogus sequence */
DoSM(DP_X_X10MSE, screen->send_mouse_pos);
break;
case 40: /* 132 column mode */
DoSM(DP_X_DECCOLM, screen->c132);
break;
case 41: /* curses hack */
DoSM(DP_X_MORE, screen->curses);
break;
case 44: /* margin bell */
DoSM(DP_X_MARGIN, screen->marginbell);
break;
case 45: /* reverse wraparound */
DoSM(DP_X_REVWRAP, termw->flags & REVERSEWRAP);
break;
#ifdef ALLOWLOGGING
case 46: /* logging */
DoSM(DP_X_LOGGING, screen->logging);
break;
#endif
case 1047: /* alternate buffer */
/* FALLTHRU */
case 47: /* alternate buffer */
DoSM(DP_X_ALTSCRN, screen->alternate);
break;
case SET_VT200_MOUSE: /* mouse bogus sequence */
case SET_VT200_HIGHLIGHT_MOUSE:
case SET_BTN_EVENT_MOUSE:
case SET_ANY_EVENT_MOUSE:
DoSM(DP_X_MOUSE, screen->send_mouse_pos);
break;
case 1048:
if (!termw->misc.titeInhibit) {
CursorSave(termw);
}
break;
#if OPT_READLINE
case SET_BUTTON1_MOVE_POINT:
SCREEN_FLAG_save(screen, click1_moves);
break;
case SET_BUTTON2_MOVE_POINT:
SCREEN_FLAG_save(screen, paste_moves);
break;
case SET_DBUTTON3_DELETE:
SCREEN_FLAG_save(screen, dclick3_deletes);
break;
case SET_PASTE_IN_BRACKET:
SCREEN_FLAG_save(screen, paste_brackets);
break;
case SET_PASTE_QUOTE:
SCREEN_FLAG_save(screen, paste_quotes);
break;
case SET_PASTE_LITERAL_NL:
SCREEN_FLAG_save(screen, paste_literal_nl);
break;
#endif /* OPT_READLINE */
}
}
}
/*
* process xterm private modes restore
*/
static void
restoremodes(XtermWidget termw)
{
register TScreen *screen = &termw->screen;
register int i, j;
for (i = 0; i < nparam; i++) {
switch (param[i]) {
case 1: /* DECCKM */
bitcpy(&termw->keyboard.flags,
screen->save_modes[DP_DECCKM], MODE_DECCKM);
update_appcursor();
break;
case 3: /* DECCOLM */
if (screen->c132) {
ClearScreen(screen);
CursorSet(screen, 0, 0, termw->flags);
if ((j = (screen->save_modes[DP_DECCOLM] & IN132COLUMNS)
? 132 : 80) != ((termw->flags & IN132COLUMNS)
? 132 : 80) || j != screen->max_col + 1)
RequestResize(termw, -1, j, TRUE);
bitcpy(&termw->flags,
screen->save_modes[DP_DECCOLM],
IN132COLUMNS);
}
break;
case 4: /* DECSCLM (slow scroll) */
if (screen->save_modes[DP_DECSCLM] & SMOOTHSCROLL) {
screen->jumpscroll = 0;
if (screen->scroll_amt)
FlushScroll(screen);
} else
screen->jumpscroll = 1;
bitcpy(&termw->flags, screen->save_modes[DP_DECSCLM], SMOOTHSCROLL);
update_jumpscroll();
break;
case 5: /* DECSCNM */
if ((screen->save_modes[DP_DECSCNM] ^ termw->flags) & REVERSE_VIDEO) {
bitcpy(&termw->flags, screen->save_modes[DP_DECSCNM], REVERSE_VIDEO);
ReverseVideo(termw);
/* update_reversevideo done in RevVid */
}
break;
case 6: /* DECOM */
bitcpy(&termw->flags, screen->save_modes[DP_DECOM], ORIGIN);
CursorSet(screen, 0, 0, termw->flags);
break;
case 7: /* DECAWM */
bitcpy(&termw->flags, screen->save_modes[DP_DECAWM], WRAPAROUND);
update_autowrap();
break;
case 8: /* DECARM */
/* ignore autorepeat */
break;
case SET_X10_MOUSE: /* MIT bogus sequence */
DoRM(DP_X_X10MSE, screen->send_mouse_pos);
break;
case 40: /* 132 column mode */
DoRM(DP_X_DECCOLM, screen->c132);
update_allow132();
break;
case 41: /* curses hack */
DoRM(DP_X_MORE, screen->curses);
update_cursesemul();
break;
case 44: /* margin bell */
if ((DoRM(DP_X_MARGIN, screen->marginbell)) == 0)
screen->bellarmed = -1;
update_marginbell();
break;
case 45: /* reverse wraparound */
bitcpy(&termw->flags, screen->save_modes[DP_X_REVWRAP], REVERSEWRAP);
update_reversewrap();
break;
#ifdef ALLOWLOGGING
case 46: /* logging */
#ifdef ALLOWLOGFILEONOFF
if (screen->save_modes[DP_X_LOGGING])
StartLog(screen);
else
CloseLog(screen);
#endif /* ALLOWLOGFILEONOFF */
/* update_logging done by StartLog and CloseLog */
break;
#endif
case 1047: /* alternate buffer */
/* FALLTHRU */
case 47: /* alternate buffer */
if (!termw->misc.titeInhibit) {
if (screen->save_modes[DP_X_ALTSCRN])
ToAlternate(screen);
else
FromAlternate(screen);
/* update_altscreen done by ToAlt and FromAlt */
} else if (termw->misc.tiXtraScroll) {
if (screen->save_modes[DP_X_ALTSCRN]) {
xtermScroll(screen, screen->max_row);
}
}
break;
case SET_VT200_MOUSE: /* mouse bogus sequence */
case SET_VT200_HIGHLIGHT_MOUSE:
case SET_BTN_EVENT_MOUSE:
case SET_ANY_EVENT_MOUSE:
DoRM(DP_X_MOUSE, screen->send_mouse_pos);
break;
case 1048:
if (!termw->misc.titeInhibit) {
CursorRestore(termw);
}
break;
#if OPT_READLINE
case SET_BUTTON1_MOVE_POINT:
SCREEN_FLAG_restore(screen, click1_moves);
break;
case SET_BUTTON2_MOVE_POINT:
SCREEN_FLAG_restore(screen, paste_moves);
break;
case SET_DBUTTON3_DELETE:
SCREEN_FLAG_restore(screen, dclick3_deletes);
break;
case SET_PASTE_IN_BRACKET:
SCREEN_FLAG_restore(screen, paste_brackets);
break;
case SET_PASTE_QUOTE:
SCREEN_FLAG_restore(screen, paste_quotes);
break;
case SET_PASTE_LITERAL_NL:
SCREEN_FLAG_restore(screen, paste_literal_nl);
break;
#endif /* OPT_READLINE */
}
}
}
/*
* Report window label (icon or title) in dtterm protocol
* ESC ] code label ESC backslash
*/
static void
report_win_label(TScreen * screen,
int code,
XTextProperty * text,
Status ok)
{
char **list;
int length = 0;
reply.a_type = ESC;
unparseputc(ESC, screen->respond);
unparseputc(']', screen->respond);
unparseputc(code, screen->respond);
if (ok) {
if (XTextPropertyToStringList(text, &list, &length)) {
int n, c;
for (n = 0; n < length; n++) {
char *s = list[n];
while ((c = *s++) != '\0')
unparseputc(c, screen->respond);
}
XFreeStringList(list);
}
if (text->value != 0)
XFree(text->value);
}
unparseputc(ESC, screen->respond);
unparseputc('\\', screen->respond);
}
/*
* Window operations (from CDE dtterm description, as well as extensions)
*/
static void
window_ops(XtermWidget termw)
{
register TScreen *screen = &termw->screen;
XWindowChanges values;
XWindowAttributes win_attrs;
XTextProperty text;
unsigned int value_mask;
unsigned root_width, root_height;
switch (param[0]) {
case 1: /* Restore (de-iconify) window */
XMapWindow(screen->display,
VShellWindow);
break;
case 2: /* Minimize (iconify) window */
XIconifyWindow(screen->display,
VShellWindow,
DefaultScreen(screen->display));
break;
case 3: /* Move the window to the given position */
values.x = param[1];
values.y = param[2];
value_mask = (CWX | CWY);
XReconfigureWMWindow(
screen->display,
VShellWindow,
DefaultScreen(screen->display),
value_mask,
&values);
break;
case 4: /* Resize the window to given size in pixels */
RequestResize(termw, param[1], param[2], FALSE);
break;
case 5: /* Raise the window to the front of the stack */
XRaiseWindow(screen->display, VShellWindow);
break;
case 6: /* Lower the window to the bottom of the stack */
XLowerWindow(screen->display, VShellWindow);
break;
case 7: /* Refresh the window */
Redraw();
break;
case 8: /* Resize the text-area, in characters */
RequestResize(termw, param[1], param[2], TRUE);
break;
#if OPT_MAXIMIZE
case 9: /* Maximize or restore */
RequestMaximize(termw, param[1]);
break;
#endif
case 11: /* Report the window's state */
XGetWindowAttributes(screen->display,
VWindow(screen),
&win_attrs);
reply.a_type = CSI;
reply.a_pintro = 0;
reply.a_nparam = 1;
reply.a_param[0] = (win_attrs.map_state == IsViewable) ? 1 : 2;
reply.a_inters = 0;
reply.a_final = 't';
unparseseq(&reply, screen->respond);
break;
case 13: /* Report the window's position */
XGetWindowAttributes(screen->display,
WMFrameWindow(termw),
&win_attrs);
reply.a_type = CSI;
reply.a_pintro = 0;
reply.a_nparam = 3;
reply.a_param[0] = 3;
reply.a_param[1] = win_attrs.x;
reply.a_param[2] = win_attrs.y;
reply.a_inters = 0;
reply.a_final = 't';
unparseseq(&reply, screen->respond);
break;
case 14: /* Report the window's size in pixels */
XGetWindowAttributes(screen->display,
VWindow(screen),
&win_attrs);
reply.a_type = CSI;
reply.a_pintro = 0;
reply.a_nparam = 3;
reply.a_param[0] = 4;
/*FIXME: find if dtterm uses
* win_attrs.height or Height
* win_attrs.width or Width
*/
reply.a_param[1] = Height(screen);
reply.a_param[2] = Width(screen);
reply.a_inters = 0;
reply.a_final = 't';
unparseseq(&reply, screen->respond);
break;
case 18: /* Report the text's size in characters */
reply.a_type = CSI;
reply.a_pintro = 0;
reply.a_nparam = 3;
reply.a_param[0] = 8;
reply.a_param[1] = screen->max_row + 1;
reply.a_param[2] = screen->max_col + 1;
reply.a_inters = 0;
reply.a_final = 't';
unparseseq(&reply, screen->respond);
break;
#if OPT_MAXIMIZE
case 19: /* Report the screen's size, in characters */
if (!QueryMaximize(screen, &root_height, &root_width)) {
root_height = 0;
root_width = 0;
}
reply.a_type = CSI;
reply.a_pintro = 0;
reply.a_nparam = 3;
reply.a_param[0] = 9;
reply.a_param[1] = root_height / FontHeight(screen);
reply.a_param[2] = root_width / FontWidth(screen);
reply.a_inters = 0;
reply.a_final = 't';
unparseseq(&reply, screen->respond);
break;
#endif
case 20: /* Report the icon's label */
report_win_label(screen, 'L', &text,
XGetWMIconName(
screen->display,
VShellWindow,
&text));
break;
case 21: /* Report the window's title */
report_win_label(screen, 'l', &text,
XGetWMName(
screen->display,
VShellWindow,
&text));
break;
default: /* DECSLPP (24, 25, 36, 48, 72, 144) */
if (param[0] >= 24)
RequestResize(termw, param[0], -1, TRUE);
break;
}
}
/*
* set a bit in a word given a pointer to the word and a mask.
*/
static void
bitset(unsigned *p, unsigned mask)
{
*p |= mask;
}
/*
* clear a bit in a word given a pointer to the word and a mask.
*/
static void
bitclr(unsigned *p, unsigned mask)
{
*p &= ~mask;
}
/*
* Copy bits from one word to another, given a mask
*/
static void
bitcpy(unsigned *p, unsigned q, unsigned mask)
{
bitclr(p, mask);
bitset(p, q & mask);
}
void
unparseputc1(int c, int fd)
{
if (c >= 0x80 && c <= 0x9F) {
if (!term->screen.control_eight_bits) {
unparseputc(A2E(ESC), fd);
c = A2E(c - 0x40);
}
}
unparseputc(c, fd);
}
void
unparseseq(register ANSI * ap, int fd)
{
register int c;
register int i;
register int inters;
unparseputc1(c = ap->a_type, fd);
if (c == ESC
|| c == DCS
|| c == CSI
|| c == OSC
|| c == PM
|| c == APC
|| c == SS3) {
if (ap->a_pintro != 0)
unparseputc((char) ap->a_pintro, fd);
for (i = 0; i < ap->a_nparam; ++i) {
if (i != 0)
unparseputc(';', fd);
unparseputn((unsigned int) ap->a_param[i], fd);
}
inters = ap->a_inters;
for (i = 3; i >= 0; --i) {
c = CharOf(inters >> (8 * i));
if (c != 0)
unparseputc(c, fd);
}
unparseputc((char) ap->a_final, fd);
}
}
static void
unparseputn(unsigned int n, int fd)
{
unsigned int q;
q = n / 10;
if (q != 0)
unparseputn(q, fd);
unparseputc((char) ('0' + (n % 10)), fd);
}
void
unparseputc(int c, int fd)
{
register TScreen *screen = &term->screen;
IChar buf[2];
register int i = 1;
#if OPT_TCAP_QUERY
/*
* If we're returning a termcap string, it has to be translated since
* a DCS must not contain any characters except for the normal 7-bit
* printable ASCII (counting tab, carriage return, etc). For now,
* just use hexadecimal for the whole thing.
*/
if (screen->tc_query >= 0) {
char tmp[3];
sprintf(tmp, "%02X", c & 0xFF);
buf[0] = tmp[0];
buf[1] = tmp[1];
i = 2;
} else
#endif
if ((buf[0] = c) == '\r' && (term->flags & LINEFEED)) {
buf[1] = '\n';
i++;
}
#ifdef VMS
tt_write(&buf, i);
#else /* VMS */
writePtyData(fd, buf, i);
#endif /* VMS */
/* If send/receive mode is reset, we echo characters locally */
if ((term->keyboard.flags & MODE_SRM) == 0) {
dotext(screen, screen->gsets[(int) (screen->curgl)], buf, i);
}
}
void
unparseputs(char *s, int fd)
{
while (*s)
unparseputc(*s++, fd);
}
#if OPT_BLINK_CURS
void
ToggleCursorBlink(register TScreen * screen)
{
ShowCursor();
if (screen->cursor_blink) {
screen->cursor_blink = FALSE;
StopBlinking(screen);
} else {
screen->cursor_blink = TRUE;
StartBlinking(screen);
}
update_cursorblink();
}
#endif
void
ToggleAlternate(register TScreen * screen)
{
if (screen->alternate)
FromAlternate(screen);
else
ToAlternate(screen);
}
static void
ToAlternate(register TScreen * screen)
{
if (screen->alternate)
return;
TRACE(("ToAlternate\n"));
if (!screen->altbuf)
screen->altbuf = Allocate(screen->max_row + 1, screen->max_col
+ 1, &screen->abuf_address);
SwitchBufs(screen);
screen->alternate = TRUE;
update_altscreen();
}
static void
FromAlternate(register TScreen * screen)
{
if (!screen->alternate)
return;
TRACE(("FromAlternate\n"));
if (screen->scroll_amt)
FlushScroll(screen);
screen->alternate = FALSE;
SwitchBufs(screen);
update_altscreen();
}
static void
SwitchBufs(register TScreen * screen)
{
register int rows, top;
if (screen->cursor_state)
HideCursor();
rows = screen->max_row + 1;
SwitchBufPtrs(screen);
TrackText(0, 0, 0, 0); /* remove any highlighting */
if ((top = -screen->topline) < rows) {
if (screen->scroll_amt)
FlushScroll(screen);
if (top == 0)
XClearWindow(screen->display, VWindow(screen));
else
XClearArea(
screen->display,
VWindow(screen),
(int) OriginX(screen),
(int) top * FontHeight(screen) + screen->border,
(unsigned) Width(screen),
(unsigned) (rows - top) * FontHeight(screen),
FALSE);
}
ScrnRefresh(screen, 0, 0, rows, screen->max_col + 1, False);
}
/* swap buffer line pointers between alt and regular screens */
void
SwitchBufPtrs(register TScreen * screen)
{
size_t len = ScrnPointers(screen, screen->max_row + 1);
memcpy((char *) screen->save_ptr, (char *) screen->visbuf, len);
memcpy((char *) screen->visbuf, (char *) screen->altbuf, len);
memcpy((char *) screen->altbuf, (char *) screen->save_ptr, len);
}
void
VTRun(void)
{
register TScreen *screen = &term->screen;
#if OPT_TEK4014
register int i;
#endif
if (!screen->Vshow) {
set_vt_visibility(TRUE);
}
update_vttekmode();
update_vtshow();
update_tekshow();
set_vthide_sensitivity();
if (screen->allbuf == NULL)
VTallocbuf();
screen->cursor_state = OFF;
screen->cursor_set = ON;
StartBlinking(screen);
initPtyData(&VTbuffer);
#if OPT_TEK4014
while (Tpushb > Tpushback) {
*(VTbuffer.ptr)++ = *--Tpushb;
VTbuffer.cnt++;
}
VTbuffer.cnt += (i = (Tbuffer ? Tbuffer->cnt : 0));
for (; i > 0; i--)
*(VTbuffer.ptr)++ = *(Tbuffer->ptr)++;
VTbuffer.ptr = DecodedData(&VTbuffer);
#endif
if (!setjmp(VTend))
VTparse();
StopBlinking(screen);
HideCursor();
screen->cursor_set = OFF;
}
/*ARGSUSED*/
static void
VTExpose(Widget w GCC_UNUSED,
XEvent * event,
Region region GCC_UNUSED)
{
register TScreen *screen = &term->screen;
#ifdef DEBUG
if (debug)
fputs("Expose\n", stderr);
#endif /* DEBUG */
if (event->type == Expose)
HandleExposure(screen, event);
}
static void
VTGraphicsOrNoExpose(XEvent * event)
{
register TScreen *screen = &term->screen;
if (screen->incopy <= 0) {
screen->incopy = 1;
if (screen->scrolls > 0)
screen->scrolls--;
}
if (event->type == GraphicsExpose)
if (HandleExposure(screen, event))
screen->cursor_state = OFF;
if ((event->type == NoExpose)
|| ((XGraphicsExposeEvent *) event)->count == 0) {
if (screen->incopy <= 0 && screen->scrolls > 0)
screen->scrolls--;
if (screen->scrolls)
screen->incopy = -1;
else
screen->incopy = 0;
}
}
/*ARGSUSED*/
static void
VTNonMaskableEvent(Widget w GCC_UNUSED,
XtPointer closure GCC_UNUSED,
XEvent * event,
Boolean * cont GCC_UNUSED)
{
switch (event->type) {
case GraphicsExpose:
case NoExpose:
VTGraphicsOrNoExpose(event);
break;
}
}
static void
VTResize(Widget w)
{
if (XtIsRealized(w))
ScreenResize(&term->screen, term->core.width, term->core.height,
&term->flags);
}
#define okDimension(src,dst) ((src <= 32767) && ((dst = src) == src))
static void
RequestResize(XtermWidget termw, int rows, int cols, int text)
{
#ifndef nothack
XSizeHints sizehints;
long supp;
#endif
TScreen *screen = &termw->screen;
unsigned long value;
Dimension replyWidth, replyHeight;
Dimension askedWidth, askedHeight;
XtGeometryResult status;
XWindowAttributes attrs;
TRACE(("RequestResize(rows=%d, cols=%d, text=%d)\n", rows, cols, text));
if ((askedWidth = cols) < cols
|| (askedHeight = rows) < rows)
return;
if (askedHeight == 0
|| askedWidth == 0
|| term->misc.limit_resize > 0) {
XGetWindowAttributes(XtDisplay(termw),
RootWindowOfScreen(XtScreen(termw)), &attrs);
}
if (text) {
if ((value = rows) != 0) {
if (rows < 0)
value = screen->max_row + 1;
value *= FontHeight(screen);
value += (2 * screen->border);
if (!okDimension(value, askedHeight))
return;
}
if ((value = cols) != 0) {
if (cols < 0)
value = screen->max_col + 1;
value *= FontWidth(screen);
value += (2 * screen->border) + ScrollbarWidth(screen);
if (!okDimension(value, askedWidth))
return;
}
} else {
if (rows < 0)
askedHeight = FullHeight(screen);
if (cols < 0)
askedWidth = FullWidth(screen);
}
if (rows == 0)
askedHeight = attrs.height;
if (cols == 0)
askedWidth = attrs.width;
if (term->misc.limit_resize > 0) {
Dimension high = term->misc.limit_resize * attrs.height;
Dimension wide = term->misc.limit_resize * attrs.width;
if (high < attrs.height)
high = attrs.height;
if (askedHeight > high)
askedHeight = high;
if (wide < attrs.width)
wide = attrs.width;
if (askedWidth > wide)
askedWidth = wide;
}
#ifndef nothack
if (!XGetWMNormalHints(screen->display, VShellWindow,
&sizehints, &supp))
bzero(&sizehints, sizeof(sizehints));
#endif
status = XtMakeResizeRequest(
(Widget) termw,
askedWidth, askedHeight,
&replyWidth, &replyHeight);
TRACE(("charproc.c XtMakeResizeRequest %dx%d -> %dx%d (status %d)\n",
askedHeight, askedWidth,
replyHeight, replyWidth,
status));
if (status == XtGeometryYes ||
status == XtGeometryDone) {
ScreenResize(&termw->screen,
replyWidth,
replyHeight,
&termw->flags);
}
#ifndef nothack
/*
* XtMakeResizeRequest() has the undesirable side-effect of clearing
* the window manager's hints, even on a failed request. This would
* presumably be fixed if the shell did its own work.
*/
if (sizehints.flags
&& replyHeight
&& replyWidth) {
sizehints.height = replyHeight;
sizehints.width = replyWidth;
XSetWMNormalHints(screen->display, VShellWindow, &sizehints);
}
#endif
XSync(screen->display, FALSE); /* synchronize */
if (XtAppPending(app_con))
xevents();
}
static String xterm_trans =
"<ClientMessage>WM_PROTOCOLS: DeleteWindow()\n\
<MappingNotify>: KeyboardMapping()\n";
int
VTInit(void)
{
register TScreen *screen = &term->screen;
Widget vtparent = SHELL_OF(term);
XtRealizeWidget(vtparent);
XtOverrideTranslations(vtparent, XtParseTranslationTable(xterm_trans));
(void) XSetWMProtocols(XtDisplay(vtparent), XtWindow(vtparent),
&wm_delete_window, 1);
TRACE_TRANS("shell", vtparent);
TRACE_TRANS("vt100", (Widget) (term));
if (screen->allbuf == NULL)
VTallocbuf();
return (1);
}
static void
VTallocbuf(void)
{
register TScreen *screen = &term->screen;
int nrows = screen->max_row + 1;
/* allocate screen buffer now, if necessary. */
if (screen->scrollWidget)
nrows += screen->savelines;
screen->allbuf = Allocate(nrows, screen->max_col + 1,
&screen->sbuf_address);
if (screen->scrollWidget)
screen->visbuf = &screen->allbuf[MAX_PTRS * screen->savelines];
else
screen->visbuf = screen->allbuf;
return;
}
static void
VTClassInit(void)
{
XtAddConverter(XtRString, XtRGravity, XmuCvtStringToGravity,
(XtConvertArgList) NULL, (Cardinal) 0);
}
#if OPT_TRACE
#define init_Bres(name) \
TRACE(("init " #name " = %s\n", \
(wnew->name = request->name) != FALSE \
? "on" : "off"))
#define init_Cres(name) \
TRACE(("init " #name " = %#lx\n", \
wnew->name = request->name))
#define init_Ires(name) \
TRACE(("init " #name " = %d\n", \
wnew->name = request->name))
#define init_Sres(name) \
TRACE(("init " #name " = \"%s\"\n", \
(wnew->name = x_strtrim(request->name)) != NULL \
? wnew->name : "<null>"))
#else
#define init_Bres(name) wnew->name = request->name
#define init_Cres(name) wnew->name = request->name
#define init_Ires(name) wnew->name = request->name
#define init_Sres(name) wnew->name = x_strtrim(request->name)
#endif
#if OPT_WIDE_CHARS
static void
VTInitialize_locale(XtermWidget request)
{
char *locale;
Boolean is_utf8;
if ((locale = getenv("LC_ALL")) == 0 || *locale == '\0')
if ((locale = getenv("LC_CTYPE")) == 0 || *locale == '\0')
if ((locale = getenv("LANG")) == 0 || *locale == '\0')
locale = "";
#ifdef HAVE_LANGINFO_CODESET /* FIXME: not available yet */
is_utf8 = (strcmp(nl_langinfo(CODESET), "UTF-8") == 0);
#else
is_utf8 = (strstr(locale, "UTF-8") != NULL);
#endif
#if OPT_LUIT_PROG
request->misc.callfilter = 0;
request->misc.use_encoding = 0;
if (x_strcasecmp(request->misc.locale_str, "TRUE") == 0 ||
x_strcasecmp(request->misc.locale_str, "ON") == 0 ||
x_strcasecmp(request->misc.locale_str, "YES") == 0 ||
x_strcasecmp(request->misc.locale_str, "AUTO") == 0 ||
strcmp(request->misc.locale_str, "1") == 0) {
/* when true ... fully obeying LC_CTYPE locale */
request->misc.callfilter = is_utf8 ? 0 : 1;
request->screen.utf8_mode = 2;
} else if (x_strcasecmp(request->misc.locale_str, "FALSE") == 0 ||
x_strcasecmp(request->misc.locale_str, "OFF") == 0 ||
x_strcasecmp(request->misc.locale_str, "NO") == 0 ||
strcmp(request->misc.locale_str, "0") == 0) {
/* when false ... original value of utf8_mode is effective */
if (request->screen.utf8_mode == 3) {
request->screen.utf8_mode = is_utf8 ? 2 : 0;
}
} else if (x_strcasecmp(request->misc.locale_str, "MEDIUM") == 0 ||
x_strcasecmp(request->misc.locale_str, "SEMIAUTO") == 0) {
/* when medium ... obeying locale only for UTF-8 and Asian */
if (is_utf8) {
request->screen.utf8_mode = 2;
} else if (
#ifdef MB_CUR_MAX
MB_CUR_MAX > 1 ||
#else
!strncmp(locale, "ja", 2) ||
!strncmp(locale, "ko", 2) ||
!strncmp(locale, "zh", 2) ||
#endif
!strncmp(locale, "th", 2) ||
!strncmp(locale, "vi", 2)) {
request->misc.callfilter = 1;
request->screen.utf8_mode = 2;
} else {
request->screen.utf8_mode = 0;
}
} else if (x_strcasecmp(request->misc.locale_str, "UTF-8") == 0 ||
x_strcasecmp(request->misc.locale_str, "UTF8") == 0) {
/* when UTF-8 ... UTF-8 mode */
request->screen.utf8_mode = 2;
} else {
/* other words are regarded as encoding name passed to luit */
request->misc.callfilter = 1;
request->screen.utf8_mode = 2;
request->misc.use_encoding = 1;
}
#else
if (request->screen.utf8_mode == 3) {
request->screen.utf8_mode = is_utf8 ? 2 : 0;
}
#endif /* OPT_LUIT_PROG */
}
#endif
/* ARGSUSED */
static void
VTInitialize(Widget wrequest,
Widget new_arg,
ArgList args GCC_UNUSED,
Cardinal * num_args GCC_UNUSED)
{
XtermWidget request = (XtermWidget) wrequest;
XtermWidget wnew = (XtermWidget) new_arg;
Widget my_parent = SHELL_OF(wnew);
int i;
#if OPT_ISO_COLORS
Boolean color_ok;
#endif
char *s;
/* Zero out the entire "screen" component of "wnew" widget, then do
* field-by-field assignment of "screen" fields that are named in the
* resource list.
*/
bzero((char *) &wnew->screen, sizeof(wnew->screen));
/* dummy values so that we don't try to Realize the parent shell with height
* or width of 0, which is illegal in X. The real size is computed in the
* xtermWidget's Realize proc, but the shell's Realize proc is called first,
* and must see a valid size.
*/
wnew->core.height = wnew->core.width = 1;
/*
* The definition of -rv now is that it changes the definition of
* XtDefaultForeground and XtDefaultBackground. So, we no longer
* need to do anything special.
*/
wnew->screen.display = wnew->core.screen->display;
/*
* We use the default foreground/background colors to compare/check if a
* color-resource has been set.
*/
#define MyBlackPixel(dpy) BlackPixel(dpy,DefaultScreen(dpy))
#define MyWhitePixel(dpy) WhitePixel(dpy,DefaultScreen(dpy))
if (request->misc.re_verse) {
wnew->dft_foreground = MyWhitePixel(wnew->screen.display);
wnew->dft_background = MyBlackPixel(wnew->screen.display);
} else {
wnew->dft_foreground = MyBlackPixel(wnew->screen.display);
wnew->dft_background = MyWhitePixel(wnew->screen.display);
}
TRACE(("Color resource initialization:\n"));
TRACE((" Default foreground %#lx\n", wnew->dft_foreground));
TRACE((" Default background %#lx\n", wnew->dft_background));
TRACE((" Screen foreground %#lx\n", request->screen.foreground));
TRACE((" Screen background %#lx\n", request->core.background_pixel));
wnew->screen.mouse_button = -1;
wnew->screen.mouse_row = -1;
wnew->screen.mouse_col = -1;
init_Bres(screen.force_box_chars);
init_Bres(screen.free_bold_box);
init_Bres(screen.c132);
init_Bres(screen.curses);
init_Bres(screen.hp_ll_bc);
#if OPT_XMC_GLITCH
init_Ires(screen.xmc_glitch);
init_Ires(screen.xmc_attributes);
init_Bres(screen.xmc_inline);
init_Bres(screen.move_sgr_ok);
#endif
init_Cres(screen.foreground);
init_Cres(screen.cursorcolor);
#if OPT_BLINK_CURS
init_Bres(screen.cursor_blink);
init_Ires(screen.cursor_on);
init_Ires(screen.cursor_off);
#endif
init_Ires(screen.border);
init_Bres(screen.jumpscroll);
init_Bres(screen.old_fkeys);
init_Bres(screen.delete_is_del);
wnew->keyboard.type = wnew->screen.old_fkeys
? keyboardIsLegacy
: keyboardIsDefault;
#ifdef ALLOWLOGGING
init_Sres(screen.logfile);
#endif
init_Bres(screen.marginbell);
init_Cres(screen.mousecolor);
init_Cres(screen.mousecolorback);
init_Bres(screen.multiscroll);
init_Ires(screen.nmarginbell);
init_Ires(screen.savelines);
init_Ires(screen.scrolllines);
init_Bres(screen.scrollttyoutput);
init_Bres(screen.scrollkey);
init_Sres(screen.term_id);
for (s = request->screen.term_id; *s; s++) {
if (!isalpha(CharOf(*s)))
break;
}
wnew->screen.terminal_id = atoi(s);
if (wnew->screen.terminal_id < MIN_DECID)
wnew->screen.terminal_id = MIN_DECID;
if (wnew->screen.terminal_id > MAX_DECID)
wnew->screen.terminal_id = MAX_DECID;
TRACE(("term_id '%s' -> terminal_id %d\n",
wnew->screen.term_id,
wnew->screen.terminal_id));
wnew->screen.ansi_level = (wnew->screen.terminal_id / 100);
init_Bres(screen.visualbell);
init_Bres(screen.poponbell);
init_Ires(misc.limit_resize);
#if OPT_NUM_LOCK
init_Bres(misc.real_NumLock);
init_Bres(misc.alwaysUseMods);
wnew->misc.num_lock = 0;
wnew->misc.alt_left = 0;
wnew->misc.alt_right = 0;
wnew->misc.meta_trans = False;
wnew->misc.meta_left = 0;
wnew->misc.meta_right = 0;
#endif
#if OPT_SHIFT_FONTS
init_Bres(misc.shift_fonts);
#endif
#if OPT_SUNPC_KBD
init_Ires(misc.ctrl_fkeys);
#endif
#if OPT_TEK4014
init_Bres(misc.tekInhibit);
init_Bres(misc.tekSmall);
init_Bres(screen.TekEmu);
#endif
#if OPT_TCAP_QUERY
wnew->screen.tc_query = -1;
#endif
wnew->misc.re_verse0 = request->misc.re_verse;
init_Bres(misc.re_verse);
init_Ires(screen.multiClickTime);
init_Ires(screen.bellSuppressTime);
init_Sres(screen.charClass);
init_Bres(screen.cutNewline);
init_Bres(screen.cutToBeginningOfLine);
init_Bres(screen.highlight_selection);
init_Bres(screen.trim_selection);
init_Bres(screen.i18nSelections);
init_Bres(screen.brokenSelections);
init_Bres(screen.always_highlight);
wnew->screen.pointer_cursor = request->screen.pointer_cursor;
init_Sres(screen.answer_back);
init_Sres(screen.printer_command);
init_Bres(screen.printer_autoclose);
init_Bres(screen.printer_extent);
init_Bres(screen.printer_formfeed);
init_Ires(screen.printer_controlmode);
#if OPT_PRINT_COLORS
init_Ires(screen.print_attributes);
#endif
init_Sres(screen.keyboard_dialect);
init_Bres(screen.input_eight_bits);
init_Bres(screen.output_eight_bits);
init_Bres(screen.control_eight_bits);
init_Bres(screen.backarrow_key);
init_Bres(screen.meta_sends_esc);
init_Bres(screen.allowSendEvents);
init_Bres(screen.allowWindowOps);
#ifndef NO_ACTIVE_ICON
wnew->screen.fnt_icon = request->screen.fnt_icon;
#endif /* NO_ACTIVE_ICON */
init_Bres(misc.titeInhibit);
init_Bres(misc.tiXtraScroll);
init_Bres(misc.dynamicColors);
for (i = fontMenu_font1; i <= fontMenu_lastBuiltin; i++) {
init_Sres(screen.menu_font_names[i]);
}
/* set default in realize proc */
wnew->screen.menu_font_names[fontMenu_fontdefault] = NULL;
wnew->screen.menu_font_names[fontMenu_fontescape] = NULL;
wnew->screen.menu_font_names[fontMenu_fontsel] = NULL;
wnew->screen.menu_font_number = fontMenu_fontdefault;
#if OPT_DEC_CHRSET
init_Bres(screen.font_doublesize);
init_Ires(screen.cache_doublesize);
if (wnew->screen.cache_doublesize > NUM_CHRSET)
wnew->screen.cache_doublesize = NUM_CHRSET;
if (wnew->screen.cache_doublesize == 0)
wnew->screen.font_doublesize = False;
TRACE(("Doublesize%s enabled, up to %d fonts\n",
wnew->screen.font_doublesize ? "" : " not",
wnew->screen.cache_doublesize));
#endif
#if OPT_ISO_COLORS || OPT_DEC_CHRSET || OPT_WIDE_CHARS
wnew->num_ptrs = (OFF_ATTRS + 1); /* OFF_FLAGS, OFF_CHARS, OFF_ATTRS */
#endif
#if OPT_ISO_COLORS
init_Ires(screen.veryBoldColors);
init_Bres(screen.boldColors);
init_Bres(screen.colorAttrMode);
init_Bres(screen.colorBDMode);
init_Bres(screen.colorBLMode);
init_Bres(screen.colorMode);
init_Bres(screen.colorULMode);
init_Bres(screen.colorRVMode);
for (i = 0, color_ok = False; i < MAXCOLORS; i++) {
wnew->screen.Acolors[i] = request->screen.Acolors[i];
#if OPT_COLOR_RES
TRACE(("Acolors[%d] = %s\n", i, request->screen.Acolors[i].resource));
wnew->screen.Acolors[i].mode = False;
if (strcmp(wnew->screen.Acolors[i].resource, XtDefaultForeground))
color_ok = True;
#else
TRACE(("Acolors[%d] = %#lx\n", i, request->screen.Acolors[i]));
if (wnew->screen.Acolors[i] != wnew->dft_foreground
&& wnew->screen.Acolors[i] != request->screen.foreground
&& wnew->screen.Acolors[i] != request->core.background_pixel)
color_ok = True;
#endif
}
/*
* Check if we're trying to use color in a monochrome screen. Disable color
* in that case, since that would make ANSI colors unusable. A 4-bit or
* 8-bit display is usable, so we do not have to check for anything more
* specific.
*/
if (color_ok) {
Display *display = wnew->screen.display;
XVisualInfo template, *visInfoPtr;
int numFound;
template.visualid = XVisualIDFromVisual(DefaultVisual(display,
XDefaultScreen(display)));
visInfoPtr = XGetVisualInfo(display, (long) VisualIDMask,
&template, &numFound);
if (visInfoPtr == 0
|| numFound == 0
|| visInfoPtr->depth <= 1) {
TRACE(("disabling color since screen is monochrome\n"));
color_ok = False;
}
}
/* If none of the colors are anything other than the foreground or
* background, we'll assume this isn't color, no matter what the colorMode
* resource says. (There doesn't seem to be any good way to determine if
* the resource lookup failed versus the user having misconfigured this).
*/
if (!color_ok) {
wnew->screen.colorMode = False;
TRACE(("All colors are foreground or background: disable colorMode\n"));
}
#if OPT_EXT_COLORS
wnew->num_ptrs = (OFF_BGRND + 1);
#else
wnew->num_ptrs = (OFF_COLOR + 1);
#endif
wnew->sgr_foreground = -1;
wnew->sgr_background = -1;
wnew->sgr_extended = 0;
#endif /* OPT_ISO_COLORS */
#if OPT_HIGHLIGHT_COLOR
init_Cres(screen.highlightcolor);
#endif
#if OPT_DEC_CHRSET
wnew->num_ptrs = (OFF_CSETS + 1);
#endif
#if OPT_WIDE_CHARS
VTInitialize_locale(request);
#if OPT_LUIT_PROG
init_Bres(misc.callfilter);
init_Bres(misc.use_encoding);
init_Sres(misc.locale_str);
init_Sres(misc.localefilter);
#endif
init_Bres(screen.vt100_graphics);
init_Bres(screen.wide_chars);
init_Bres(misc.cjk_width);
if (request->screen.utf8_mode) {
wnew->screen.wide_chars = True;
wnew->screen.utf8_mode = 2; /* disable further change */
} else {
wnew->screen.utf8_mode = 0;
}
TRACE(("initialized UTF-8 mode to %d\n", wnew->screen.utf8_mode));
if (wnew->screen.wide_chars != False)
wnew->num_ptrs = (OFF_COM2H + 1);
#endif
init_Bres(screen.bold_mode);
init_Bres(screen.underline);
#ifdef XRENDERFONT
wnew->screen.renderFont = 0;
wnew->screen.renderFontBold = 0;
wnew->screen.renderDraw = 0;
#endif
wnew->cur_foreground = 0;
wnew->cur_background = 0;
wnew->keyboard.flags = MODE_SRM;
if (wnew->screen.backarrow_key)
wnew->keyboard.flags |= MODE_DECBKM;
TRACE(("initialized DECBKM %s\n",
(wnew->keyboard.flags & MODE_DECBKM) ? "on" : "off"));
/* look for focus related events on the shell, because we need
* to care about the shell's border being part of our focus.
*/
XtAddEventHandler(my_parent, EnterWindowMask, FALSE,
HandleEnterWindow, (Opaque) NULL);
XtAddEventHandler(my_parent, LeaveWindowMask, FALSE,
HandleLeaveWindow, (Opaque) NULL);
XtAddEventHandler(my_parent, FocusChangeMask, FALSE,
HandleFocusChange, (Opaque) NULL);
XtAddEventHandler((Widget) wnew, 0L, TRUE,
VTNonMaskableEvent, (Opaque) NULL);
XtAddEventHandler((Widget) wnew, PropertyChangeMask, FALSE,
HandleBellPropertyChange, (Opaque) NULL);
#if HANDLE_STRUCT_NOTIFY
#if OPT_TOOLBAR
wnew->screen.fullVwin.menu_bar = request->screen.fullVwin.menu_bar;
init_Ires(screen.fullVwin.menu_height);
#else
/* Flag icon name with "***" on window output when iconified.
* Put in a handler that will tell us when we get Map/Unmap events.
*/
if (zIconBeep)
#endif
XtAddEventHandler(my_parent, StructureNotifyMask, FALSE,
HandleStructNotify, (XtPointer) 0);
#endif /* HANDLE_STRUCT_NOTIFY */
wnew->screen.bellInProgress = FALSE;
set_character_class(wnew->screen.charClass);
/* create it, but don't realize it */
ScrollBarOn(wnew, TRUE, FALSE);
/* make sure that the resize gravity acceptable */
if (wnew->misc.resizeGravity != NorthWestGravity &&
wnew->misc.resizeGravity != SouthWestGravity) {
Cardinal nparams = 1;
XtAppWarningMsg(app_con, "rangeError", "resizeGravity", "XTermError",
"unsupported resizeGravity resource value (%d)",
(String *) & (wnew->misc.resizeGravity), &nparams);
wnew->misc.resizeGravity = SouthWestGravity;
}
#ifndef NO_ACTIVE_ICON
wnew->screen.whichVwin = &wnew->screen.fullVwin;
#if OPT_TEK4014
wnew->screen.whichTwin = &wnew->screen.fullTwin;
#endif
#endif /* NO_ACTIVE_ICON */
if (wnew->screen.savelines < 0)
wnew->screen.savelines = 0;
init_Bres(screen.awaitInput);
wnew->flags = 0;
if (!wnew->screen.jumpscroll)
wnew->flags |= SMOOTHSCROLL;
if (wnew->misc.reverseWrap)
wnew->flags |= REVERSEWRAP;
if (wnew->misc.autoWrap)
wnew->flags |= WRAPAROUND;
if (wnew->misc.re_verse != wnew->misc.re_verse0)
wnew->flags |= REVERSE_VIDEO;
wnew->initflags = wnew->flags;
init_Ires(keyboard.modify_cursor_keys);
init_Ires(misc.appcursorDefault);
if (wnew->misc.appcursorDefault)
wnew->keyboard.flags |= MODE_DECCKM;
init_Ires(misc.appkeypadDefault);
if (wnew->misc.appkeypadDefault)
wnew->keyboard.flags |= MODE_DECKPAM;
return;
}
static void
VTDestroy(Widget w)
{
XtFree(((XtermWidget) w)->screen.selection_data);
}
/*ARGSUSED*/
static void
VTRealize(Widget w,
XtValueMask * valuemask,
XSetWindowAttributes * values)
{
unsigned int width, height;
register TScreen *screen = &term->screen;
int xpos, ypos, pr;
XSizeHints sizehints;
int scrollbar_width;
TabReset(term->tabs);
screen->menu_font_names[fontMenu_fontdefault] = term->misc.f_n;
screen->fnt_norm = NULL;
screen->fnt_bold = NULL;
#if OPT_WIDE_CHARS
screen->fnt_dwd = NULL;
screen->fnt_dwdb = NULL;
#endif
if (!xtermLoadFont(screen,
VT_FONTSET(term->misc.f_n,
term->misc.f_b,
term->misc.f_w,
term->misc.f_wb),
False, 0)) {
if (XmuCompareISOLatin1(term->misc.f_n, "fixed") != 0) {
fprintf(stderr,
"%s: unable to open font \"%s\", trying \"fixed\"....\n",
xterm_name, term->misc.f_n);
(void) xtermLoadFont(screen,
VT_FONTSET("fixed", NULL, NULL, NULL),
False, 0);
screen->menu_font_names[fontMenu_fontdefault] = "fixed";
}
}
/* really screwed if we couldn't open default font */
if (!screen->fnt_norm) {
fprintf(stderr, "%s: unable to locate a suitable font\n",
xterm_name);
Exit(1);
}
/* making cursor */
if (!screen->pointer_cursor)
screen->pointer_cursor = make_colored_cursor(XC_xterm,
screen->mousecolor,
screen->mousecolorback);
else
recolor_cursor(screen->pointer_cursor,
screen->mousecolor, screen->mousecolorback);
scrollbar_width = (term->misc.scrollbar ?
screen->scrollWidget->core.width : 0);
/* set defaults */
xpos = 1;
ypos = 1;
width = 80;
height = 24;
pr = XParseGeometry(term->misc.geo_metry, &xpos, &ypos,
&width, &height);
screen->max_col = (width - 1); /* units in character cells */
screen->max_row = (height - 1); /* units in character cells */
xtermUpdateFontInfo(&term->screen, False);
width = screen->fullVwin.fullwidth;
height = screen->fullVwin.fullheight;
if ((pr & XValue) && (XNegative & pr))
xpos += DisplayWidth(screen->display, DefaultScreen(screen->display))
- width - (XtParent(term)->core.border_width * 2);
if ((pr & YValue) && (YNegative & pr))
ypos += DisplayHeight(screen->display, DefaultScreen(screen->display))
- height - (XtParent(term)->core.border_width * 2);
/* set up size hints for window manager; min 1 char by 1 char */
bzero(&sizehints, sizeof(sizehints));
sizehints.base_width = 2 * screen->border + scrollbar_width;
sizehints.base_height = 2 * screen->border;
sizehints.width_inc = FontWidth(screen);
sizehints.height_inc = FontHeight(screen);
sizehints.min_width = sizehints.base_width + sizehints.width_inc;
sizehints.min_height = sizehints.base_height + sizehints.height_inc;
sizehints.flags = (PBaseSize | PMinSize | PResizeInc);
sizehints.x = xpos;
sizehints.y = ypos;
if ((XValue & pr) || (YValue & pr)) {
sizehints.flags |= USSize | USPosition;
sizehints.flags |= PWinGravity;
switch (pr & (XNegative | YNegative)) {
case 0:
sizehints.win_gravity = NorthWestGravity;
break;
case XNegative:
sizehints.win_gravity = NorthEastGravity;
break;
case YNegative:
sizehints.win_gravity = SouthWestGravity;
break;
default:
sizehints.win_gravity = SouthEastGravity;
break;
}
} else {
/* set a default size, but do *not* set position */
sizehints.flags |= PSize;
}
sizehints.width = width;
sizehints.height = height;
if ((WidthValue & pr) || (HeightValue & pr))
sizehints.flags |= USSize;
else
sizehints.flags |= PSize;
(void) XtMakeResizeRequest((Widget) term,
(Dimension) width, (Dimension) height,
&term->core.width, &term->core.height);
/* XXX This is bogus. We are parsing geometries too late. This
* is information that the shell widget ought to have before we get
* realized, so that it can do the right thing.
*/
if (sizehints.flags & USPosition)
XMoveWindow(XtDisplay(term), XtWindow(XtParent(term)),
sizehints.x, sizehints.y);
XSetWMNormalHints(XtDisplay(term), XtWindow(XtParent(term)),
&sizehints);
XFlush(XtDisplay(term)); /* get it out to window manager */
/* use ForgetGravity instead of SouthWestGravity because translating
the Expose events for ConfigureNotifys is too hard */
values->bit_gravity = term->misc.resizeGravity == NorthWestGravity ?
NorthWestGravity : ForgetGravity;
term->screen.fullVwin.window = XtWindow(term) =
XCreateWindow(XtDisplay(term), XtWindow(XtParent(term)),
term->core.x, term->core.y,
term->core.width, term->core.height, term->core.border_width,
(int) term->core.depth,
InputOutput, CopyFromParent,
*valuemask | CWBitGravity, values);
screen->event_mask = values->event_mask;
#ifndef NO_ACTIVE_ICON
if (term->misc.active_icon && screen->fnt_icon) {
int iconX = 0, iconY = 0;
Widget shell = XtParent(term);
unsigned long mask;
XGCValues xgcv;
XtVaGetValues(shell, XtNiconX, &iconX, XtNiconY, &iconY, (XtPointer) 0);
xtermComputeFontInfo(screen, &(screen->iconVwin), screen->fnt_icon, 0);
/* since only one client is permitted to select for Button
* events, we have to let the window manager get 'em...
*/
values->event_mask &= ~(ButtonPressMask | ButtonReleaseMask);
values->border_pixel = term->misc.icon_border_pixel;
screen->iconVwin.window =
XCreateWindow(XtDisplay(term),
RootWindowOfScreen(XtScreen(shell)),
iconX, iconY,
screen->iconVwin.fullwidth,
screen->iconVwin.fullheight,
term->misc.icon_border_width,
(int) term->core.depth,
InputOutput, CopyFromParent,
*valuemask | CWBitGravity | CWBorderPixel,
values);
XtVaSetValues(shell,
XtNiconWindow, screen->iconVwin.window,
(XtPointer) 0);
XtRegisterDrawable(XtDisplay(term), screen->iconVwin.window, w);
mask = (GCFont | GCForeground | GCBackground |
GCGraphicsExposures | GCFunction);
xgcv.font = screen->fnt_icon->fid;
xgcv.foreground = screen->foreground;
xgcv.background = term->core.background_pixel;
xgcv.graphics_exposures = TRUE; /* default */
xgcv.function = GXcopy;
screen->iconVwin.normalGC =
screen->iconVwin.normalboldGC =
XtGetGC(shell, mask, &xgcv);
xgcv.foreground = term->core.background_pixel;
xgcv.background = screen->foreground;
screen->iconVwin.reverseGC =
screen->iconVwin.reverseboldGC =
XtGetGC(shell, mask, &xgcv);
} else {
term->misc.active_icon = False;
}
#endif /* NO_ACTIVE_ICON */
#if OPT_I18N_SUPPORT && OPT_INPUT_METHOD
VTInitI18N();
#else
term->screen.xic = NULL;
#endif
#if OPT_NUM_LOCK
VTInitModifiers();
#endif
set_cursor_gcs(screen);
/* Reset variables used by ANSI emulation. */
resetCharsets(screen);
XDefineCursor(screen->display, VShellWindow, screen->pointer_cursor);
screen->cur_col = screen->cur_row = 0;
screen->max_col = Width(screen) / screen->fullVwin.f_width - 1;
screen->top_marg = 0;
screen->bot_marg = screen->max_row = Height(screen) /
screen->fullVwin.f_height - 1;
memset(screen->sc, 0, sizeof(screen->sc));
/* Mark screen buffer as unallocated. We wait until the run loop so
that the child process does not fork and exec with all the dynamic
memory it will never use. If we were to do it here, the
swap space for new process would be huge for huge savelines. */
#if OPT_TEK4014
if (!tekWidget) /* if not called after fork */
#endif
screen->visbuf = screen->allbuf = NULL;
screen->do_wrap = 0;
screen->scrolls = screen->incopy = 0;
xtermSetCursorBox(screen);
screen->savedlines = 0;
if (term->misc.scrollbar) {
screen->fullVwin.sb_info.width = 0;
ScrollBarOn(term, FALSE, TRUE);
}
CursorSave(term);
return;
}
#if OPT_I18N_SUPPORT && OPT_INPUT_METHOD
static void
VTInitI18N(void)
{
unsigned i, j;
char *p, *s, *t, *ns, *end, buf[32];
XIM xim = (XIM) NULL;
XIMStyles *xim_styles;
XIMStyle input_style = 0;
Boolean found;
static struct {
char *name;
unsigned long code;
} known_style[] = {
{
"OverTheSpot", (XIMPreeditPosition | XIMStatusNothing)
},
{
"OffTheSpot", (XIMPreeditArea | XIMStatusArea)
},
{
"Root", (XIMPreeditNothing | XIMStatusNothing)
},
};
term->screen.xic = NULL;
if (!term->misc.open_im)
return;
if (!term->misc.input_method || !*term->misc.input_method) {
if ((p = XSetLocaleModifiers("")) != NULL && *p)
xim = XOpenIM(XtDisplay(term), NULL, NULL, NULL);
} else {
s = term->misc.input_method;
i = 5 + strlen(s);
t = (char *) MyStackAlloc(i, buf);
if (t == NULL)
SysError(ERROR_VINIT);
for (ns = s; ns && *s;) {
while (*s && isspace(CharOf(*s)))
s++;
if (!*s)
break;
if ((ns = end = strchr(s, ',')) == 0)
end = s + strlen(s);
while ((end != s) && isspace(CharOf(end[-1])))
end--;
if (end != s) {
strcpy(t, "@im=");
strncat(t, s, end - s);
if ((p = XSetLocaleModifiers(t)) != 0 && *p
&& (xim = XOpenIM(XtDisplay(term), NULL, NULL, NULL)) != 0)
break;
}
s = ns + 1;
}
MyStackFree(t, buf);
}
if (xim == NULL && (p = XSetLocaleModifiers("@im=none")) != NULL && *p)
xim = XOpenIM(XtDisplay(term), NULL, NULL, NULL);
if (!xim) {
fprintf(stderr, "Failed to open input method\n");
return;
}
TRACE(("VTInitI18N opened input method\n"));
if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL)
|| !xim_styles
|| !xim_styles->count_styles) {
fprintf(stderr, "input method doesn't support any style\n");
XCloseIM(xim);
return;
}
found = False;
for (s = term->misc.preedit_type; s && !found;) {
while (*s && isspace(CharOf(*s)))
s++;
if (!*s)
break;
if ((ns = end = strchr(s, ',')) != 0)
ns++;
else
end = s + strlen(s);
while ((end != s) && isspace(CharOf(end[-1])))
end--;
if (end != s) { /* just in case we have a spurious comma */
TRACE(("looking for style '%.*s'\n", end - s, s));
for (i = 0; i < XtNumber(known_style); i++) {
if ((int) strlen(known_style[i].name) == (end - s)
&& !strncmp(s, known_style[i].name, end - s)) {
input_style = known_style[i].code;
for (j = 0; j < xim_styles->count_styles; j++) {
if (input_style == xim_styles->supported_styles[j]) {
found = True;
break;
}
}
if (found)
break;
}
}
}
s = ns;
}
XFree(xim_styles);
if (!found) {
fprintf(stderr,
"input method doesn't support my preedit type (%s)\n",
term->misc.preedit_type);
XCloseIM(xim);
return;
}
/*
* Check for styles we do not yet support.
*/
if (input_style == (XIMPreeditArea | XIMStatusArea)) {
fprintf(stderr,
"This program doesn't support the 'OffTheSpot' preedit type\n");
XCloseIM(xim);
return;
}
/*
* For XIMPreeditPosition (or OverTheSpot), XIM client has to
* prepare a font.
* The font has to be locale-dependent XFontSet, whereas
* XTerm use Unicode font. This leads a problem that the
* same font cannot be used for XIM preedit.
*/
if (input_style != (XIMPreeditNothing | XIMStatusNothing)) {
char **missing_charset_list;
int missing_charset_count;
char *def_string;
XVaNestedList p_list;
XPoint spot =
{0, 0};
XFontSetExtents *extents;
XFontStruct **fonts;
char **font_name_list;
term->screen.fs = XCreateFontSet(XtDisplay(term),
term->misc.f_x,
&missing_charset_list,
&missing_charset_count,
&def_string);
if (term->screen.fs == NULL) {
fprintf(stderr, "Preparation of font set "
"\"%s\" for XIM failed.\n", term->misc.f_x);
term->screen.fs = XCreateFontSet(XtDisplay(term),
DEFXIMFONT,
&missing_charset_list,
&missing_charset_count,
&def_string);
}
if (term->screen.fs == NULL) {
fprintf(stderr, "Preparation of default font set "
"\"%s\" for XIM failed.\n", DEFXIMFONT);
XCloseIM(xim);
return;
}
extents = XExtentsOfFontSet(term->screen.fs);
j = XFontsOfFontSet(term->screen.fs, &fonts, &font_name_list);
for (i = 0, term->screen.fs_ascent = 0; i < j; i++) {
if (term->screen.fs_ascent < (*fonts)->ascent)
term->screen.fs_ascent = (*fonts)->ascent;
}
p_list = XVaCreateNestedList(0,
XNSpotLocation, &spot,
XNFontSet, term->screen.fs,
NULL);
term->screen.xic = XCreateIC(xim,
XNInputStyle, input_style,
XNClientWindow, XtWindow(term),
XNFocusWindow, XtWindow(term),
XNPreeditAttributes, p_list,
NULL);
} else {
term->screen.xic = XCreateIC(xim, XNInputStyle, input_style,
XNClientWindow, XtWindow(term),
XNFocusWindow, XtWindow(term),
NULL);
}
if (!term->screen.xic) {
fprintf(stderr, "Failed to create input context\n");
XCloseIM(xim);
}
return;
}
#endif
static Boolean
VTSetValues(Widget cur,
Widget request GCC_UNUSED,
Widget wnew,
ArgList args GCC_UNUSED,
Cardinal * num_args GCC_UNUSED)
{
XtermWidget curvt = (XtermWidget) cur;
XtermWidget newvt = (XtermWidget) wnew;
Boolean refresh_needed = FALSE;
Boolean fonts_redone = FALSE;
if (curvt->core.background_pixel != newvt->core.background_pixel
|| curvt->screen.foreground != newvt->screen.foreground
|| curvt->screen.menu_font_names[curvt->screen.menu_font_number]
!= newvt->screen.menu_font_names[newvt->screen.menu_font_number]
|| curvt->misc.f_n != newvt->misc.f_n) {
if (curvt->misc.f_n != newvt->misc.f_n)
newvt->screen.menu_font_names[fontMenu_fontdefault] = newvt->misc.f_n;
if (xtermLoadFont(&newvt->screen,
VT_FONTSET(newvt->screen.menu_font_names[curvt->screen.menu_font_number],
newvt->screen.menu_font_names[curvt->screen.menu_font_number],
NULL,
NULL),
TRUE, newvt->screen.menu_font_number)) {
/* resizing does the redisplay, so don't ask for it here */
refresh_needed = TRUE;
fonts_redone = TRUE;
} else if (curvt->misc.f_n != newvt->misc.f_n)
newvt->screen.menu_font_names[fontMenu_fontdefault] = curvt->misc.f_n;
}
if (!fonts_redone
&& curvt->screen.cursorcolor != newvt->screen.cursorcolor) {
set_cursor_gcs(&newvt->screen);
refresh_needed = TRUE;
}
if (curvt->misc.re_verse != newvt->misc.re_verse) {
newvt->flags ^= REVERSE_VIDEO;
ReverseVideo(newvt);
newvt->misc.re_verse = !newvt->misc.re_verse; /* ReverseVideo toggles */
refresh_needed = TRUE;
}
if (curvt->screen.mousecolor != newvt->screen.mousecolor
|| curvt->screen.mousecolorback != newvt->screen.mousecolorback) {
recolor_cursor(newvt->screen.pointer_cursor,
newvt->screen.mousecolor,
newvt->screen.mousecolorback);
refresh_needed = TRUE;
}
if (curvt->misc.scrollbar != newvt->misc.scrollbar) {
ToggleScrollBar(newvt);
}
return refresh_needed;
}
/*
* Shows cursor at new cursor position in screen.
*/
void
ShowCursor(void)
{
register TScreen *screen = &term->screen;
register int x, y, flags;
Char clo;
int fg_bg = 0;
GC currentGC;
Boolean in_selection;
Boolean reversed;
Pixel fg_pix;
Pixel bg_pix;
Pixel tmp;
#if OPT_HIGHLIGHT_COLOR
Pixel hi_pix = screen->highlightcolor;
#endif
#if OPT_WIDE_CHARS
Char chi = 0;
Char c1h = 0;
Char c1l = 0;
Char c2h = 0;
Char c2l = 0;
int base;
#endif
int cursor_col;
if (screen->cursor_state == BLINKED_OFF)
return;
if (eventMode != NORMAL)
return;
if (screen->cur_row - screen->topline > screen->max_row)
return;
screen->cursor_row = screen->cur_row;
cursor_col = screen->cursor_col = screen->cur_col;
#ifndef NO_ACTIVE_ICON
if (IsIcon(screen)) {
screen->cursor_state = ON;
return;
}
#endif /* NO_ACTIVE_ICON */
#if OPT_WIDE_CHARS
base =
#endif
clo = SCRN_BUF_CHARS(screen, screen->cursor_row)[cursor_col];
if_OPT_WIDE_CHARS(screen, {
int my_col;
chi = SCRN_BUF_WIDEC(screen, screen->cursor_row)[cursor_col];
if (clo == HIDDEN_LO && chi == HIDDEN_HI) {
/* if cursor points to non-initial part of wide character,
* back it up
*/
--cursor_col;
clo = SCRN_BUF_CHARS(screen, screen->cursor_row)[cursor_col];
chi = SCRN_BUF_WIDEC(screen, screen->cursor_row)[cursor_col];
}
my_col = cursor_col;
base = (chi << 8) | clo;
if (iswide(base))
my_col += 1;
c1l = SCRN_BUF_COM1L(screen, screen->cursor_row)[my_col];
c1h = SCRN_BUF_COM1H(screen, screen->cursor_row)[my_col];
c2l = SCRN_BUF_COM2L(screen, screen->cursor_row)[my_col];
c2h = SCRN_BUF_COM2H(screen, screen->cursor_row)[my_col];
});
flags = SCRN_BUF_ATTRS(screen, screen->cursor_row)[cursor_col];
if (clo == 0
#if OPT_WIDE_CHARS
&& chi == 0
#endif
) {
clo = ' ';
}
/*
* Compare the current cell to the last set of colors used for the
* cursor and update the GC's if needed.
*/
if_OPT_EXT_COLORS(screen, {
fg_bg = (SCRN_BUF_FGRND(screen, screen->cursor_row)[cursor_col] << 8)
| (SCRN_BUF_BGRND(screen, screen->cursor_row)[cursor_col]);
});
if_OPT_ISO_TRADITIONAL_COLORS(screen, {
fg_bg = SCRN_BUF_COLOR(screen, screen->cursor_row)[cursor_col];
});
fg_pix = getXtermForeground(flags, extract_fg(fg_bg, flags));
bg_pix = getXtermBackground(flags, extract_bg(fg_bg, flags));
if (screen->cur_row > screen->endHRow ||
(screen->cur_row == screen->endHRow &&
screen->cur_col >= screen->endHCol) ||
screen->cur_row < screen->startHRow ||
(screen->cur_row == screen->startHRow &&
screen->cur_col < screen->startHCol))
in_selection = False;
else
in_selection = True;
reversed = ReverseOrHilite(screen, flags, in_selection);
/* This is like updatedXtermGC(), except that we have to worry about
* whether the window has focus, since in that case we want just an
* outline for the cursor.
*/
if (screen->select || screen->always_highlight) {
if (reversed) { /* text is reverse video */
if (screen->cursorGC) {
currentGC = screen->cursorGC;
} else {
if (flags & (BOLD | BLINK)) {
currentGC = NormalBoldGC(screen);
} else {
currentGC = NormalGC(screen);
}
}
#if OPT_HIGHLIGHT_COLOR
if (hi_pix != screen->foreground
&& hi_pix != fg_pix
&& hi_pix != bg_pix
&& hi_pix != term->dft_foreground) {
bg_pix = fg_pix;
fg_pix = hi_pix;
}
#endif
EXCHANGE(fg_pix, bg_pix, tmp)
} else { /* normal video */
if (screen->reversecursorGC) {
currentGC = screen->reversecursorGC;
} else {
if (flags & (BOLD | BLINK)) {
currentGC = ReverseBoldGC(screen);
} else {
currentGC = ReverseGC(screen);
}
}
}
if (screen->cursorcolor == term->dft_foreground) {
XSetBackground(screen->display, currentGC, fg_pix);
}
XSetForeground(screen->display, currentGC, bg_pix);
} else { /* not selected */
if (reversed) { /* text is reverse video */
#if OPT_HIGHLIGHT_COLOR
if (hi_pix != screen->foreground
&& hi_pix != fg_pix
&& hi_pix != bg_pix
&& hi_pix != term->dft_foreground) {
bg_pix = fg_pix;
fg_pix = hi_pix;
}
#endif
currentGC = ReverseGC(screen);
XSetForeground(screen->display, currentGC, bg_pix);
XSetBackground(screen->display, currentGC, fg_pix);
} else { /* normal video */
currentGC = NormalGC(screen);
XSetForeground(screen->display, currentGC, fg_pix);
XSetBackground(screen->display, currentGC, bg_pix);
}
}
TRACE(("ShowCursor calling drawXtermText cur(%d,%d)\n",
screen->cur_row, screen->cur_col));
drawXtermText(screen, flags, currentGC,
x = CurCursorX(screen, screen->cur_row, cursor_col),
y = CursorY(screen, screen->cur_row),
curXtermChrSet(screen->cur_row),
PAIRED_CHARS(&clo, &chi), 1, 0);
#if OPT_WIDE_CHARS
if (c1l || c1h) {
drawXtermText(screen, flags, currentGC,
x, y,
curXtermChrSet(screen->cur_row),
PAIRED_CHARS(&c1l, &c1h), 1, iswide(base));
if (c2l || c2h)
drawXtermText(screen, flags, currentGC,
x, y,
curXtermChrSet(screen->cur_row),
PAIRED_CHARS(&c2l, &c2h), 1, iswide(base));
}
#endif
if (!screen->select && !screen->always_highlight) {
screen->box->x = x;
screen->box->y = y;
XDrawLines(screen->display, VWindow(screen),
screen->cursoroutlineGC ? screen->cursoroutlineGC
: currentGC,
screen->box, NBOX, CoordModePrevious);
}
screen->cursor_state = ON;
}
/*
* hide cursor at previous cursor position in screen.
*/
void
HideCursor(void)
{
register TScreen *screen = &term->screen;
GC currentGC;
register int flags;
register int fg_bg = 0;
int x, y;
Char clo;
Boolean in_selection;
#if OPT_WIDE_CHARS
Char chi = 0;
Char c1h = 0;
Char c1l = 0;
Char c2h = 0;
Char c2l = 0;
int base;
#endif
int cursor_col;
if (screen->cursor_state == OFF) /* FIXME */
return;
if (screen->cursor_row - screen->topline > screen->max_row)
return;
cursor_col = screen->cursor_col;
#ifndef NO_ACTIVE_ICON
if (IsIcon(screen)) {
screen->cursor_state = OFF;
return;
}
#endif /* NO_ACTIVE_ICON */
#if OPT_WIDE_CHARS
base =
#endif
clo = SCRN_BUF_CHARS(screen, screen->cursor_row)[cursor_col];
flags = SCRN_BUF_ATTRS(screen, screen->cursor_row)[cursor_col];
if_OPT_WIDE_CHARS(screen, {
int my_col;
chi = SCRN_BUF_WIDEC(screen, screen->cursor_row)[cursor_col];
if (clo == HIDDEN_LO && chi == HIDDEN_HI) {
/* if cursor points to non-initial part of wide character,
* back it up
*/
--cursor_col;
clo = SCRN_BUF_CHARS(screen, screen->cursor_row)[cursor_col];
chi = SCRN_BUF_WIDEC(screen, screen->cursor_row)[cursor_col];
}
my_col = cursor_col;
base = (chi << 8) | clo;
if (iswide(base))
my_col += 1;
c1l = SCRN_BUF_COM1L(screen, screen->cursor_row)[my_col];
c1h = SCRN_BUF_COM1H(screen, screen->cursor_row)[my_col];
c2l = SCRN_BUF_COM2L(screen, screen->cursor_row)[my_col];
c2h = SCRN_BUF_COM2H(screen, screen->cursor_row)[my_col];
});
if_OPT_EXT_COLORS(screen, {
fg_bg = (SCRN_BUF_FGRND(screen, screen->cursor_row)[cursor_col] << 8)
| (SCRN_BUF_BGRND(screen, screen->cursor_row)[cursor_col]);
});
if_OPT_ISO_TRADITIONAL_COLORS(screen, {
fg_bg = SCRN_BUF_COLOR(screen, screen->cursor_row)[cursor_col];
});
if (screen->cursor_row > screen->endHRow ||
(screen->cursor_row == screen->endHRow &&
screen->cursor_col >= screen->endHCol) ||
screen->cursor_row < screen->startHRow ||
(screen->cursor_row == screen->startHRow &&
screen->cursor_col < screen->startHCol))
in_selection = False;
else
in_selection = True;
currentGC = updatedXtermGC(screen, flags, fg_bg, in_selection);
if (clo == 0
#if OPT_WIDE_CHARS
&& chi == 0
#endif
) {
clo = ' ';
}
TRACE(("HideCursor calling drawXtermText cur(%d,%d)\n",
screen->cursor_row, screen->cursor_col));
drawXtermText(screen, flags, currentGC,
x = CurCursorX(screen, screen->cursor_row, cursor_col),
y = CursorY(screen, screen->cursor_row),
curXtermChrSet(screen->cursor_row),
PAIRED_CHARS(&clo, &chi), 1, 0);
#if OPT_WIDE_CHARS
if (c1l || c1h) {
drawXtermText(screen, flags, currentGC,
x, y,
curXtermChrSet(screen->cur_row),
PAIRED_CHARS(&c1l, &c1h), 1, iswide(base));
if (c2l || c2h)
drawXtermText(screen, flags, currentGC,
x, y,
curXtermChrSet(screen->cur_row),
PAIRED_CHARS(&c2l, &c2h), 1, iswide(base));
}
#endif
screen->cursor_state = OFF;
resetXtermGC(screen, flags, in_selection);
}
#if OPT_BLINK_CURS
static void
StartBlinking(TScreen * screen)
{
if (screen->cursor_blink
&& screen->cursor_timer == 0) {
unsigned long interval = (screen->cursor_state == ON ?
screen->cursor_on : screen->cursor_off);
if (interval == 0) /* wow! */
interval = 1; /* let's humor him anyway */
screen->cursor_timer = XtAppAddTimeOut(app_con,
interval,
BlinkCursor,
screen);
}
}
static void
StopBlinking(TScreen * screen)
{
if (screen->cursor_timer)
XtRemoveTimeOut(screen->cursor_timer);
screen->cursor_timer = 0;
}
/*
* Blink the cursor by alternately showing/hiding cursor. We leave the timer
* running all the time (even though that's a little inefficient) to make the
* logic simple.
*/
static void
BlinkCursor(XtPointer closure, XtIntervalId * id GCC_UNUSED)
{
TScreen *screen = (TScreen *) closure;
screen->cursor_timer = 0;
if (screen->cursor_state == ON) {
if (screen->select || screen->always_highlight) {
HideCursor();
if (screen->cursor_state == OFF)
screen->cursor_state = BLINKED_OFF;
}
} else if (screen->cursor_state == BLINKED_OFF) {
screen->cursor_state = OFF;
ShowCursor();
if (screen->cursor_state == OFF)
screen->cursor_state = BLINKED_OFF;
}
StartBlinking(screen);
}
#endif /* OPT_BLINK_CURS */
/*
* Implement soft or hard (full) reset of the VTxxx emulation. There are a
* couple of differences from real DEC VTxxx terminals (to avoid breaking
* applications which have come to rely on xterm doing this):
*
* + autowrap mode should be reset (instead it's reset to the resource
* default).
* + the popup menu offers a choice of resetting the savedLines, or not.
* (but the control sequence does this anyway).
*/
void
VTReset(Bool full, Bool saved)
{
register TScreen *screen = &term->screen;
if (saved) {
screen->savedlines = 0;
ScrollBarDrawThumb(screen->scrollWidget);
}
/* make cursor visible */
screen->cursor_set = ON;
/* reset scrolling region */
screen->top_marg = 0;
screen->bot_marg = screen->max_row;
bitclr(&term->flags, ORIGIN);
if_OPT_ISO_COLORS(screen, {
reset_SGR_Colors();
});
/* Reset character-sets to initial state */
resetCharsets(screen);
/* Reset DECSCA */
bitclr(&term->flags, PROTECTED);
screen->protected_mode = OFF_PROTECT;
if (full) { /* RIS */
/* reset the mouse mode */
screen->send_mouse_pos = MOUSE_OFF;
waitingForTrackInfo = FALSE;
eventMode = NORMAL;
TabReset(term->tabs);
term->keyboard.flags = MODE_SRM;
#if OPT_INITIAL_ERASE
if (term->keyboard.reset_DECBKM == 1)
term->keyboard.flags |= MODE_DECBKM;
else if (term->keyboard.reset_DECBKM == 2)
#endif
if (term->screen.backarrow_key)
term->keyboard.flags |= MODE_DECBKM;
TRACE(("full reset DECBKM %s\n",
(term->keyboard.flags & MODE_DECBKM) ? "on" : "off"));
update_appcursor();
update_appkeypad();
update_decbkm();
show_8bit_control(False);
reset_decudk();
FromAlternate(screen);
ClearScreen(screen);
screen->cursor_state = OFF;
if (term->flags & REVERSE_VIDEO)
ReverseVideo(term);
term->flags = term->initflags;
update_reversevideo();
update_autowrap();
update_reversewrap();
update_autolinefeed();
screen->jumpscroll = !(term->flags & SMOOTHSCROLL);
update_jumpscroll();
if (screen->c132 && (term->flags & IN132COLUMNS)) {
Dimension junk;
XtMakeResizeRequest(
(Widget) term,
(Dimension) 80 * FontWidth(screen)
+ 2 * screen->border + ScrollbarWidth(screen),
(Dimension) FontHeight(screen)
* (screen->max_row + 1) + 2 * screen->border,
&junk, &junk);
XSync(screen->display, FALSE); /* synchronize */
if (XtAppPending(app_con))
xevents();
}
CursorSet(screen, 0, 0, term->flags);
CursorSave(term);
} else { /* DECSTR */
/*
* There's a tiny difference, to accommodate usage of xterm.
* We reset autowrap to the resource values rather than turning
* it off.
*/
term->keyboard.flags &= ~(MODE_DECCKM | MODE_KAM | MODE_DECKPAM);
bitcpy(&term->flags, term->initflags, WRAPAROUND | REVERSEWRAP);
bitclr(&term->flags, INSERT | INVERSE | BOLD | BLINK | UNDERLINE | INVISIBLE);
if_OPT_ISO_COLORS(screen, {
reset_SGR_Colors();
});
update_appcursor();
update_autowrap();
update_reversewrap();
CursorSave(term);
screen->sc[screen->alternate != False].row =
screen->sc[screen->alternate != False].col = 0;
}
longjmp(vtjmpbuf, 1); /* force ground state in parser */
}
/*
* set_character_class - takes a string of the form
*
* low[-high]:val[,low[-high]:val[...]]
*
* and sets the indicated ranges to the indicated values.
*/
static int
set_character_class(register char *s)
{
register int i; /* iterator, index into s */
int len; /* length of s */
int acc; /* accumulator */
int low, high; /* bounds of range [0..127] */
int base; /* 8, 10, 16 (octal, decimal, hex) */
int numbers; /* count of numbers per range */
int digits; /* count of digits in a number */
static char *errfmt = "%s: %s in range string \"%s\" (position %d)\n";
if (!s || !s[0])
return -1;
base = 10; /* in case we ever add octal, hex */
low = high = -1; /* out of range */
for (i = 0, len = strlen(s), acc = 0, numbers = digits = 0;
i < len; i++) {
Char c = s[i];
if (isspace(c)) {
continue;
} else if (isdigit(c)) {
acc = acc * base + (c - '0');
digits++;
continue;
} else if (c == '-') {
low = acc;
acc = 0;
if (digits == 0) {
fprintf(stderr, errfmt, ProgramName, "missing number", s, i);
return (-1);
}
digits = 0;
numbers++;
continue;
} else if (c == ':') {
if (numbers == 0)
low = acc;
else if (numbers == 1)
high = acc;
else {
fprintf(stderr, errfmt, ProgramName, "too many numbers",
s, i);
return (-1);
}
digits = 0;
numbers++;
acc = 0;
continue;
} else if (c == ',') {
/*
* now, process it
*/
if (high < 0) {
high = low;
numbers++;
}
if (numbers != 2) {
fprintf(stderr, errfmt, ProgramName, "bad value number",
s, i);
} else if (SetCharacterClassRange(low, high, acc) != 0) {
fprintf(stderr, errfmt, ProgramName, "bad range", s, i);
}
low = high = -1;
acc = 0;
digits = 0;
numbers = 0;
continue;
} else {
fprintf(stderr, errfmt, ProgramName, "bad character", s, i);
return (-1);
} /* end if else if ... else */
}
if (low < 0 && high < 0)
return (0);
/*
* now, process it
*/
if (high < 0)
high = low;
if (numbers < 1 || numbers > 2) {
fprintf(stderr, errfmt, ProgramName, "bad value number", s, i);
} else if (SetCharacterClassRange(low, high, acc) != 0) {
fprintf(stderr, errfmt, ProgramName, "bad range", s, i);
}
return (0);
}
/* ARGSUSED */
static void
HandleKeymapChange(Widget w,
XEvent * event GCC_UNUSED,
String * params,
Cardinal * param_count)
{
static XtTranslations keymap, original;
static XtResource key_resources[] =
{
{XtNtranslations, XtCTranslations, XtRTranslationTable,
sizeof(XtTranslations), 0, XtRTranslationTable, (XtPointer) NULL}
};
char mapName[1000];
char mapClass[1000];
char *pmapName;
char *pmapClass;
size_t len;
if (*param_count != 1)
return;
if (original == NULL)
original = w->core.tm.translations;
if (strcmp(params[0], "None") == 0) {
XtOverrideTranslations(w, original);
return;
}
len = strlen(params[0]) + 7;
pmapName = (char *) MyStackAlloc(len, mapName);
pmapClass = (char *) MyStackAlloc(len, mapClass);
if (pmapName == NULL
|| pmapClass == NULL)
SysError(ERROR_KMMALLOC1);
(void) sprintf(pmapName, "%sKeymap", params[0]);
(void) strcpy(pmapClass, pmapName);
if (islower(CharOf(pmapClass[0])))
pmapClass[0] = toupper(pmapClass[0]);
XtGetSubresources(w, (XtPointer) & keymap, pmapName, pmapClass,
key_resources, (Cardinal) 1, NULL, (Cardinal) 0);
if (keymap != NULL)
XtOverrideTranslations(w, keymap);
MyStackFree(pmapName, mapName);
MyStackFree(pmapClass, mapClass);
}
/* ARGSUSED */
static void
HandleBell(Widget w GCC_UNUSED,
XEvent * event GCC_UNUSED,
String * params, /* [0] = volume */
Cardinal * param_count) /* 0 or 1 */
{
int percent = (*param_count) ? atoi(params[0]) : 0;
Bell(XkbBI_TerminalBell, percent);
}
/* ARGSUSED */
static void
HandleVisualBell(Widget w GCC_UNUSED,
XEvent * event GCC_UNUSED,
String * params GCC_UNUSED,
Cardinal * param_count GCC_UNUSED)
{
VisualBell();
}
/* ARGSUSED */
static void
HandleIgnore(Widget w,
XEvent * event,
String * params GCC_UNUSED,
Cardinal * param_count GCC_UNUSED)
{
/* do nothing, but check for funny escape sequences */
(void) SendMousePosition(w, event);
}
/* ARGSUSED */
static void
DoSetSelectedFont(Widget w GCC_UNUSED,
XtPointer client_data GCC_UNUSED,
Atom * selection GCC_UNUSED,
Atom * type,
XtPointer value,
unsigned long *length GCC_UNUSED,
int *format)
{
char *val = (char *) value;
int len;
if (*type != XA_STRING || *format != 8) {
Bell(XkbBI_MinorError, 0);
return;
}
len = strlen(val);
if (len > 0) {
if (val[len - 1] == '\n')
val[len - 1] = '\0';
/* Do some sanity checking to avoid sending a long selection
back to the server in an OpenFont that is unlikely to succeed.
XLFD allows up to 255 characters and no control characters;
we are a little more liberal here. */
if (len > 1000 || strchr(val, '\n'))
return;
if (!xtermLoadFont(&term->screen,
VT_FONTSET(val,
NULL,
NULL,
NULL),
True,
fontMenu_fontsel))
Bell(XkbBI_MinorError, 0);
}
}
void
FindFontSelection(char *atom_name, Bool justprobe)
{
static AtomPtr *atoms;
static int atomCount = 0;
AtomPtr *pAtom;
int a;
Atom target;
if (!atom_name)
atom_name = "PRIMARY";
for (pAtom = atoms, a = atomCount; a; a--, pAtom++) {
if (strcmp(atom_name, XmuNameOfAtom(*pAtom)) == 0)
break;
}
if (!a) {
atoms = (AtomPtr *) XtRealloc((char *) atoms,
sizeof(AtomPtr) * (atomCount + 1));
*(pAtom = &atoms[atomCount++]) = XmuMakeAtom(atom_name);
}
target = XmuInternAtom(XtDisplay(term), *pAtom);
if (justprobe) {
term->screen.menu_font_names[fontMenu_fontsel] =
XGetSelectionOwner(XtDisplay(term), target) ? _Font_Selected_ : 0;
} else {
XtGetSelectionValue((Widget) term, target, XA_STRING,
DoSetSelectedFont, NULL,
XtLastTimestampProcessed(XtDisplay(term)));
}
return;
}
void
set_cursor_gcs(TScreen * screen)
{
XGCValues xgcv;
XtGCMask mask;
Pixel cc = screen->cursorcolor;
Pixel fg = screen->foreground;
Pixel bg = term->core.background_pixel;
GC new_cursorGC = NULL;
GC new_cursorFillGC = NULL;
GC new_reversecursorGC = NULL;
GC new_cursoroutlineGC = NULL;
/*
* Let's see, there are three things that have "color":
*
* background
* text
* cursorblock
*
* And, there are four situation when drawing a cursor, if we decide
* that we like have a solid block of cursor color with the letter
* that it is highlighting shown in the background color to make it
* stand out:
*
* selected window, normal video - background on cursor
* selected window, reverse video - foreground on cursor
* unselected window, normal video - foreground on background
* unselected window, reverse video - background on foreground
*
* Since the last two are really just normalGC and reverseGC, we only
* need two new GC's. Under monochrome, we get the same effect as
* above by setting cursor color to foreground.
*/
#if OPT_ISO_COLORS
/*
* If we're using ANSI colors, the functions manipulating the SGR code will
* use the same GC's. To avoid having the cursor change color, we use the
* Xlib calls rather than the Xt calls.
*
* Use the colorMode value to determine which we'll do (the VWindow may
* not be set before the widget's realized, so it's tested separately).
*/
if (screen->colorMode) {
if (VWindow(screen) != 0 && (cc != bg) && (cc != fg)) {
/* we might have a colored foreground/background later */
xgcv.font = screen->fnt_norm->fid;
mask = (GCForeground | GCBackground | GCFont);
xgcv.foreground = fg;
xgcv.background = cc;
new_cursorGC = XCreateGC(screen->display, VWindow(screen), mask, &xgcv);
xgcv.foreground = cc;
xgcv.background = fg;
new_cursorFillGC =
XCreateGC(screen->display, VWindow(screen), mask, &xgcv);
if (screen->always_highlight) {
new_reversecursorGC = (GC) 0;
new_cursoroutlineGC = (GC) 0;
} else {
xgcv.foreground = bg;
xgcv.background = cc;
new_reversecursorGC =
XCreateGC(screen->display, VWindow(screen), mask, &xgcv);
xgcv.foreground = cc;
xgcv.background = bg;
new_cursoroutlineGC =
XCreateGC(screen->display, VWindow(screen), mask, &xgcv);
}
}
} else
#endif
if (cc != fg && cc != bg) {
/* we have a colored cursor */
xgcv.font = screen->fnt_norm->fid;
mask = (GCForeground | GCBackground | GCFont);
xgcv.foreground = fg;
xgcv.background = cc;
new_cursorGC = XtGetGC((Widget) term, mask, &xgcv);
xgcv.foreground = cc;
xgcv.background = fg;
new_cursorFillGC = XtGetGC((Widget) term, mask, &xgcv);
if (screen->always_highlight) {
new_reversecursorGC = (GC) 0;
new_cursoroutlineGC = (GC) 0;
} else {
xgcv.foreground = bg;
xgcv.background = cc;
new_reversecursorGC = XtGetGC((Widget) term, mask, &xgcv);
xgcv.foreground = cc;
xgcv.background = bg;
new_cursoroutlineGC = XtGetGC((Widget) term, mask, &xgcv);
}
}
#if OPT_ISO_COLORS
if (screen->colorMode) {
if (screen->cursorGC)
XFreeGC(screen->display, screen->cursorGC);
if (screen->fillCursorGC)
XFreeGC(screen->display, screen->fillCursorGC);
if (screen->reversecursorGC)
XFreeGC(screen->display, screen->reversecursorGC);
if (screen->cursoroutlineGC)
XFreeGC(screen->display, screen->cursoroutlineGC);
} else
#endif
{
if (screen->cursorGC)
XtReleaseGC((Widget) term, screen->cursorGC);
if (screen->fillCursorGC)
XtReleaseGC((Widget) term, screen->fillCursorGC);
if (screen->reversecursorGC)
XtReleaseGC((Widget) term, screen->reversecursorGC);
if (screen->cursoroutlineGC)
XtReleaseGC((Widget) term, screen->cursoroutlineGC);
}
screen->cursorGC = new_cursorGC;
screen->fillCursorGC = new_cursorFillGC;
screen->reversecursorGC = new_reversecursorGC;
screen->cursoroutlineGC = new_cursoroutlineGC;
}
|