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
|
/*
* Gnu.xs --- GNU Readline wrapper module
*
* $Id: Gnu.xs,v 1.114 2010/05/02 10:34:41 hiroo Exp $
*
* Copyright (c) 2010 Hiroo Hayashi. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the same terms as Perl itself.
*/
#ifdef __cplusplus
extern "C" {
#endif
#define PERLIO_NOT_STDIO 0
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#ifdef __cplusplus
}
#endif
#include <stdio.h>
#ifdef __CYGWIN__
#include <sys/termios.h>
#endif /* __CYGWIN__ */
#include <readline/readline.h>
#include <readline/history.h>
/*
* Perl 5.005 requires an ANSI C Compiler. Good news.
* But I should still support legacy C compilers now.
*/
/* Adapted from BSD /usr/include/sys/cdefs.h. */
#if defined (__STDC__)
# if !defined (PARAMS)
# define PARAMS(protos) protos
# endif
#else /* !__STDC__ */
# if !defined (PARAMS)
# define PARAMS(protos) ()
# endif
#endif /* !__STDC__ */
/*
* In Readline 4.2 many variables, function arguments, and function
* return values are now declared `const' where appropriate.
*/
#if (RL_READLINE_VERSION < 0x0402)
#define CONST
#else /* (RL_READLINE_VERSION >= 0x0402) */
#define CONST const
#endif /* (RL_READLINE_VERSION >= 0x0402) */
typedef char * t_xstr; /* string which must be xfreed */
/*
* compatibility definitions
*/
/* rl_last_func() is defined in rlprivate.h */
extern Function *rl_last_func;
/* features introduced by GNU Readline 2.2 */
#if (RL_READLINE_VERSION < 0x0202)
static int rl_unbind_function_in_map(){ return 0; }
static int rl_unbind_command_in_map(){ return 0; }
#endif /* (RL_READLINE_VERSION < 0x0202) */
/* features introduced by GNU Readline 4.0 */
#if (RL_VERSION_MAJOR < 4)
extern void rl_extend_line_buffer PARAMS((int));
extern char **rl_funmap_names PARAMS((void));
/* documented by Readline 4.2 but already implemented by 2.0. */
extern int rl_add_funmap_entry PARAMS((CONST char *, Function *));
/* dummy variable/function definition */
static int rl_erase_empty_line = 0;
static int rl_catch_signals = 1;
static int rl_catch_sigwinch = 1;
static Function *rl_pre_input_hook;
static VFunction *rl_completion_display_matches_hook;
static VFunction *rl_prep_term_function;
static VFunction *rl_deprep_term_function;
static void rl_cleanup_after_signal(){}
static void rl_free_line_state(){}
static void rl_reset_after_signal(){}
static void rl_resize_terminal(){}
static void rl_prep_terminal(){}
static void rl_deprep_terminal(){}
static int rl_execute_next(){ return 0; }
static void rl_display_match_list(){}
/*
* Before GNU Readline Library Version 4.0, rl_save_prompt() was
* _rl_save_prompt and rl_restore_prompt() was _rl_restore_prompt().
*/
extern void _rl_save_prompt PARAMS((void));
extern void _rl_restore_prompt PARAMS((void));
static void rl_save_prompt() { _rl_save_prompt(); }
static void rl_restore_prompt() { _rl_restore_prompt(); }
#endif /* (RL_VERSION_MAJOR < 4) */
/* features introduced by GNU Readline 4.1 */
#if (RL_READLINE_VERSION < 0x0401)
static int rl_already_prompted = 0;
static int rl_num_chars_to_read = 0;
static int rl_gnu_readline_p = 0;
static int rl_on_new_line_with_prompt(){ return 0; }
#endif /* (RL_READLINE_VERSION < 0x0401) */
/* features introduced by GNU Readline 4.2 */
#if (RL_READLINE_VERSION < 0x0402)
static int rl_set_prompt(){ return 0; }
static int rl_clear_pending_input(){ return 0; }
static int rl_set_keyboard_input_timeout(){ return 0; }
static int rl_alphabetic(){ return 0; }
static int rl_set_paren_blink_timeout(){ return 0; }
static void rl_set_screen_size(int row, int col){}
static void rl_get_screen_size(int *row, int *col){}
typedef int rl_command_func_t PARAMS((int, int));
typedef char *rl_compentry_func_t PARAMS((const char *, int));
static char *rl_executing_macro = NULL;
static int rl_explicit_arg = 0;
static int rl_numeric_arg = 0;
static int rl_editing_mode = 0;
static int rl_readline_state = 0;
static Function *rl_directory_rewrite_hook = NULL;
static char *history_word_delimiters = " \t\n;&()|<>";
/* Provide backwards-compatible entry points for old function names
which are rename from readline-4.2. */
static void
rl_free_undo_list ()
{
free_undo_list ();
}
static int
rl_crlf ()
{
return crlf ();
}
static void
rl_tty_set_default_bindings (keymap)
Keymap keymap;
{
#if (RL_VERSION_MAJOR >= 4)
rltty_set_default_bindings (keymap);
#endif /* (RL_VERSION_MAJOR >= 4) */
}
static int
rl_ding ()
{
return ding ();
}
static char **
rl_completion_matches (s, f)
char *s;
rl_compentry_func_t *f;
{
return completion_matches (s, (CPFunction *)f);
}
static char *
rl_username_completion_function (s, i)
const char *s;
int i;
{
return username_completion_function ((char *)s, i);
}
static char *
rl_filename_completion_function (s, i)
const char *s;
int i;
{
return filename_completion_function ((char *)s, i);
}
#endif /* (RL_READLINE_VERSION >= 0x0402) */
#if (RL_READLINE_VERSION < 0x0403)
/* features introduced by GNU Readline 4.2a */
static int rl_readline_version = RL_READLINE_VERSION;
extern char *rl_get_termcap PARAMS((const char *));
/* features introduced by GNU Readline 4.3 */
static int rl_completion_suppress_append = 0;
static int rl_completion_mark_symlink_dirs = 0;
static void rl_replace_line(){}
static int rl_completion_mode(){ return 0; }
#endif /* (RL_READLINE_VERSION < 0x0403) */
#if (RL_VERSION_MAJOR < 5)
/* features introduced by GNU Readline 5.0 */
static int history_write_timestamps = 0;
static int rl_completion_quote_character = 0;
static int rl_completion_suppress_quote = 0;
static int rl_completion_found_quote = 0;
static Function *rl_completion_word_break_hook = NULL;
static int rl_bind_key_if_unbound_in_map(){ return 0; }
static int rl_bind_keyseq_in_map(){ return 0; }
static int rl_bind_keyseq_if_unbound_in_map(){ return 0; }
static void rl_tty_unset_default_bindings(){}
static void add_history_time(){}
static time_t history_get_time(){ return 0; }
#endif /* (RL_VERSION_MAJOR < 5) */
#if (RL_READLINE_VERSION < 0x0501)
/* features introduced by GNU Readline 5.1 */
static int rl_prefer_env_winsize = 0;
static char *rl_variable_value(CONST char * v){ return NULL; }
static void rl_reset_screen_size(){}
#endif /* (RL_READLINE_VERSION < 0x0501) */
#if (RL_VERSION_MAJOR < 6)
/* features introduced by GNU Readline 6.0 */
static char *rl_display_prompt = NULL;
static int rl_sort_completion_matches = 0;
static int rl_completion_invoking_key = 0;
/*
NOT IMPLEMENTED YET !!!FIXIT!!!
static int rl_save_state(struct readline_state *sp){ return 0; }
static int rl_restore_state(struct readline_state *sp){ return 0; }
*/
static void rl_echo_signal_char(int sig){}
#endif /* (RL_VERSION_MAJOR < 6) */
#if 0 /* comment out until GNU Readline 6.2 will be released. */
#if (RL_READLINE_VERSION < 0x0601)
/* features introduced by GNU Readline 6.1 */
/* Convenience function that discards, then frees, MAP. */
void
rl_free_keymap (map)
Keymap map;
{
rl_discard_keymap (map);
free ((char *)map);
}
#endif /* (RL_READLINE_VERSION < 0x0601) */
#endif
/*
* utility/dummy functions
*/
/* from GNU Readline:xmalloc.h */
#ifndef PTR_T
#ifdef __STDC__
# define PTR_T void *
#else
# define PTR_T char *
#endif
#endif /* !PTR_T */
/* from GNU Readline:xmalloc.c */
extern PTR_T xmalloc PARAMS((int));
extern char *tgetstr PARAMS((const char *, char **));
extern int tputs PARAMS((const char *, int, int (*)(int)));
/*
* Using xfree() in GNU Readline Library causes problem with Solaris
* 2.5. It seems that the DLL mechanism of Solaris 2.5 links another
* xfree() that does not do NULL argument check.
* I choose this as default since some other OSs may have same problem.
* usemymalloc=n is required.
*/
#ifdef OS2_USEDLL
/* from GNU Readline:xmalloc.c */
extern PTR_T xfree PARAMS((PTR_T));
#else /* not OS2_USEDLL */
static void
xfree (string)
PTR_T string;
{
if (string)
free (string);
}
#endif /* not OS2_USEDLL */
static char *
dupstr(s) /* duplicate string */
CONST char * s;
{
/*
* Use xmalloc(), because allocated block will be freed in the GNU
* Readline Library routine.
* Don't make a macro, because the variable 's' is evaluated twice.
*/
int len = strlen(s) + 1;
char *d = xmalloc(len);
Copy(s, d, len, char); /* Is Copy() better than strcpy() in XS? */
return d;
}
/*
* for tputs XS routine
*/
static char *tputs_ptr;
static int
tputs_char(c)
int c;
{
return *tputs_ptr++ = c;
}
/*
* return name of FUNCTION.
* I asked Chet Ramey to add this function in readline/bind.c. But he
* did not, since he could not find any reasonable excuse.
*/
static const char *
rl_get_function_name (function)
rl_command_func_t *function;
{
register int i;
rl_initialize_funmap ();
for (i = 0; funmap[i]; i++)
if (funmap[i]->function == function)
return ((const char *)funmap[i]->name); /* cast is for oldies */
return NULL;
}
/*
* from readline-4.0:complete.c
* Redefine here since the function defined as static in complete.c.
* This function is used for default value for rl_filename_quoting_function.
*/
static char * rl_quote_filename PARAMS((char *s, int rtype, char *qcp));
static char *
rl_quote_filename (s, rtype, qcp)
char *s;
int rtype;
char *qcp;
{
char *r;
r = xmalloc (strlen (s) + 2);
*r = *rl_completer_quote_characters;
strcpy (r + 1, s);
if (qcp)
*qcp = *rl_completer_quote_characters;
return r;
}
/*
* string variable table for _rl_store_str(), _rl_fetch_str()
*/
static struct str_vars {
char **var;
int accessed;
int read_only;
} str_tbl[] = {
/* When you change length of rl_line_buffer, you must call
rl_extend_line_buffer(). See _rl_store_rl_line_buffer() */
{ &rl_line_buffer, 0, 0 }, /* 0 */
{ &rl_prompt, 0, 1 }, /* 1 */
{ (char **)&rl_library_version, 0, 1 }, /* 2 */
{ (char **)&rl_terminal_name, 0, 0 }, /* 3 */
{ (char **)&rl_readline_name, 0, 0 }, /* 4 */
{ (char **)&rl_basic_word_break_characters, 0, 0 }, /* 5 */
{ (char **)&rl_basic_quote_characters, 0, 0 }, /* 6 */
{ (char **)&rl_completer_word_break_characters, 0, 0 }, /* 7 */
{ (char **)&rl_completer_quote_characters, 0, 0 }, /* 8 */
{ (char **)&rl_filename_quote_characters, 0, 0 }, /* 9 */
{ (char **)&rl_special_prefixes, 0, 0 }, /* 10 */
{ &history_no_expand_chars, 0, 0 }, /* 11 */
{ &history_search_delimiter_chars, 0, 0 }, /* 12 */
{ &rl_executing_macro, 0, 0 }, /* 13 */
{ &history_word_delimiters, 0, 0 }, /* 14 */
{ &rl_display_prompt, 0, 0 } /* 15 */
};
/*
* integer variable table for _rl_store_int(), _rl_fetch_int()
*/
static struct int_vars {
int *var;
int charp;
int read_only;
} int_tbl[] = {
{ &rl_point, 0, 0 }, /* 0 */
{ &rl_end, 0, 0 }, /* 1 */
{ &rl_mark, 0, 0 }, /* 2 */
{ &rl_done, 0, 0 }, /* 3 */
{ &rl_pending_input, 0, 0 }, /* 4 */
{ &rl_completion_query_items, 0, 0 }, /* 5 */
{ &rl_completion_append_character, 0, 0 }, /* 6 */
{ &rl_ignore_completion_duplicates, 0, 0 }, /* 7 */
{ &rl_filename_completion_desired, 0, 0 }, /* 8 */
{ &rl_filename_quoting_desired, 0, 0 }, /* 9 */
{ &rl_inhibit_completion, 0, 0 }, /* 10 */
{ &history_base, 0, 0 }, /* 11 */
{ &history_length, 0, 0 }, /* 12 */
#if (RL_READLINE_VERSION >= 0x0402)
{ &history_max_entries, 0, 1 }, /* 13 */
#else /* (RL_READLINE_VERSION < 0x0402) */
{ &max_input_history, 0, 1 }, /* 13 */
#endif /* (RL_READLINE_VERSION < 0x0402) */
{ &history_write_timestamps, 0, 0 }, /* 14 */
{ (int *)&history_expansion_char, 1, 0 }, /* 15 */
{ (int *)&history_subst_char, 1, 0 }, /* 16 */
{ (int *)&history_comment_char, 1, 0 }, /* 17 */
{ &history_quotes_inhibit_expansion, 0, 0 }, /* 18 */
{ &rl_erase_empty_line, 0, 0 }, /* 19 */
{ &rl_catch_signals, 0, 0 }, /* 20 */
{ &rl_catch_sigwinch, 0, 0 }, /* 21 */
{ &rl_already_prompted, 0, 0 }, /* 22 */
{ &rl_num_chars_to_read, 0, 0 }, /* 23 */
{ &rl_dispatching, 0, 0 }, /* 24 */
{ &rl_gnu_readline_p, 0, 1 }, /* 25 */
{ &rl_readline_state, 0, 0 }, /* 26 */
{ &rl_explicit_arg, 0, 0 }, /* 27 */
{ &rl_numeric_arg, 0, 0 }, /* 28 */
{ &rl_editing_mode, 0, 0 }, /* 29 */
{ &rl_attempted_completion_over, 0, 0 }, /* 30 */
{ &rl_completion_type, 0, 0 }, /* 31 */
{ &rl_readline_version, 0, 1 }, /* 32 */
{ &rl_completion_suppress_append, 0, 0 }, /* 33 */
{ &rl_completion_quote_character, 0, 0 }, /* 34 */
{ &rl_completion_suppress_quote, 0, 0 }, /* 35 */
{ &rl_completion_found_quote, 0, 0 }, /* 36 */
{ &rl_completion_mark_symlink_dirs, 0, 0 }, /* 37 */
{ &rl_prefer_env_winsize, 0, 0 }, /* 38 */
{ &rl_sort_completion_matches, 0, 0 }, /* 39 */
{ &rl_completion_invoking_key, 1, 0 } /* 40 */
};
/*
* PerlIO variables for _rl_store_iostream(), _rl_fetch_iostream()
*/
static PerlIO *instreamPIO = NULL;
static PerlIO *outstreamPIO = NULL;
/*
* function pointer variable table for _rl_store_function(),
* _rl_fetch_funtion()
*/
static int startup_hook_wrapper PARAMS((void));
static int event_hook_wrapper PARAMS((void));
static int getc_function_wrapper PARAMS((PerlIO *));
static void redisplay_function_wrapper PARAMS((void));
static char *completion_entry_function_wrapper PARAMS((const char *, int));;
static char **attempted_completion_function_wrapper PARAMS((char *, int, int));
static char *filename_quoting_function_wrapper PARAMS((char *text, int match_type,
char *quote_pointer));
static char *filename_dequoting_function_wrapper PARAMS((char *text,
int quote_char));
static int char_is_quoted_p_wrapper PARAMS((char *text, int index));
static void ignore_some_completions_function_wrapper PARAMS((char **matches));
static int directory_completion_hook_wrapper PARAMS((char **textp));
static int history_inhibit_expansion_function_wrapper PARAMS((char *str, int i));
static int pre_input_hook_wrapper PARAMS((void));
static void completion_display_matches_hook_wrapper PARAMS((char **matches,
int len, int max));
static char *completion_word_break_hook_wrapper PARAMS((void));
static int prep_term_function_wrapper PARAMS((int meta_flag));
static int deprep_term_function_wrapper PARAMS((void));
static int directory_rewrite_hook_wrapper PARAMS((char **));
enum { STARTUP_HOOK, EVENT_HOOK, GETC_FN, REDISPLAY_FN,
CMP_ENT, ATMPT_COMP,
FN_QUOTE, FN_DEQUOTE, CHAR_IS_QUOTEDP,
IGNORE_COMP, DIR_COMP, HIST_INHIBIT_EXP,
PRE_INPUT_HOOK, COMP_DISP_HOOK, COMP_WD_BRK_HOOK,
PREP_TERM, DEPREP_TERM, DIR_REWRITE
};
static struct fn_vars {
Function **rlfuncp; /* GNU Readline Library variable */
Function *defaultfn; /* default function */
Function *wrapper; /* wrapper function */
SV *callback; /* Perl function */
} fn_tbl[] = {
{ &rl_startup_hook, NULL, startup_hook_wrapper, NULL }, /* 0 */
{ &rl_event_hook, NULL, event_hook_wrapper, NULL }, /* 1 */
{ &rl_getc_function, rl_getc, getc_function_wrapper, NULL }, /* 2 */
{
(Function **)&rl_redisplay_function, /* 3 */
(Function *)rl_redisplay,
(Function *)redisplay_function_wrapper,
NULL
},
{
(Function **)&rl_completion_entry_function, /* 4 */
NULL,
(Function *)completion_entry_function_wrapper,
NULL
},
{
(Function **)&rl_attempted_completion_function, /* 5 */
NULL,
(Function *)attempted_completion_function_wrapper,
NULL
},
{
(Function **)&rl_filename_quoting_function, /* 6 */
(Function *)rl_quote_filename,
(Function *)filename_quoting_function_wrapper,
NULL
},
{
(Function **)&rl_filename_dequoting_function, /* 7 */
NULL,
(Function *)filename_dequoting_function_wrapper,
NULL
},
{
(Function **)&rl_char_is_quoted_p, /* 8 */
NULL,
(Function *)char_is_quoted_p_wrapper,
NULL
},
{
(Function **)&rl_ignore_some_completions_function, /* 9 */
NULL,
(Function *)ignore_some_completions_function_wrapper,
NULL
},
{
(Function **)&rl_directory_completion_hook, /* 10 */
NULL,
(Function *)directory_completion_hook_wrapper,
NULL
},
{
(Function **)&history_inhibit_expansion_function, /* 11 */
NULL,
(Function *)history_inhibit_expansion_function_wrapper,
NULL
},
{ &rl_pre_input_hook, NULL, pre_input_hook_wrapper, NULL }, /* 12 */
{
(Function **)&rl_completion_display_matches_hook, /* 13 */
NULL,
(Function *)completion_display_matches_hook_wrapper,
NULL
},
{
(Function **)&rl_completion_word_break_hook, /* 14 */
NULL,
(Function *)completion_word_break_hook_wrapper,
NULL
},
{
(Function **)&rl_prep_term_function, /* 15 */
(Function *)rl_prep_terminal,
(Function *)prep_term_function_wrapper,
NULL
},
{
(Function **)&rl_deprep_term_function, /* 16 */
(Function *)rl_deprep_terminal,
(Function *)deprep_term_function_wrapper,
NULL
},
{
(Function **)&rl_directory_rewrite_hook, /* 17 */
NULL,
(Function *)directory_rewrite_hook_wrapper,
NULL
}
};
/*
* Perl function wrappers
*/
/*
* for rl_voidfunc_t : void fn(void)
*/
static int
voidfunc_wrapper(type)
int type;
{
dSP;
int count;
int ret;
SV *svret;
ENTER;
SAVETMPS;
PUSHMARK(sp);
count = perl_call_sv(fn_tbl[type].callback, G_SCALAR);
SPAGAIN;
if (count != 1)
croak("Gnu.xs:voidfunc_wrapper: Internal error\n");
svret = POPs;
ret = SvIOK(svret) ? SvIV(svret) : -1;
PUTBACK;
FREETMPS;
LEAVE;
return ret;
}
/*
* for rl_vintfunc_t : void fn(int)
*/
static int
vintfunc_wrapper(type, arg)
int type;
int arg;
{
dSP;
int count;
int ret;
SV *svret;
ENTER;
SAVETMPS;
PUSHMARK(sp);
XPUSHs(sv_2mortal(newSViv(arg)));
PUTBACK;
count = perl_call_sv(fn_tbl[type].callback, G_SCALAR);
SPAGAIN;
if (count != 1)
croak("Gnu.xs:vintfunc_wrapper: Internal error\n");
svret = POPs;
ret = SvIOK(svret) ? SvIV(svret) : -1;
PUTBACK;
FREETMPS;
LEAVE;
return ret;
}
/*
* for rl_icppfunc_t : int fn(char **)
*/
static int
icppfunc_wrapper(type, arg)
int type;
char **arg;
{
dSP;
int count;
SV *sv;
int ret;
char *rstr;
ENTER;
SAVETMPS;
if (arg && *arg) {
sv = sv_2mortal(newSVpv(*arg, 0));
} else {
sv = &PL_sv_undef;
}
PUSHMARK(sp);
XPUSHs(sv);
PUTBACK;
count = perl_call_sv(fn_tbl[type].callback, G_SCALAR);
SPAGAIN;
if (count != 1)
croak("Gnu.xs:icppfunc_wrapper: Internal error\n");
ret = POPi;
rstr = SvPV(sv, PL_na);
if (strcmp(*arg, rstr) != 0) {
xfree(*arg);
*arg = dupstr(rstr);
}
PUTBACK;
FREETMPS;
LEAVE;
return ret;
}
#if 0
/*
* for rl_icpfunc_t : int fn(char *)
*/
static int
icpfunc_wrapper(type, text)
int type;
char *text;
{
dSP;
int count;
int ret;
ENTER;
SAVETMPS;
PUSHMARK(sp);
if (text) {
XPUSHs(sv_2mortal(newSVpv(text, 0)));
} else {
XPUSHs(&PL_sv_undef);
}
PUTBACK;
count = perl_call_sv(fn_tbl[type].callback, G_SCALAR);
SPAGAIN;
if (count != 1)
croak("Gnu.xs:icpfunc_wrapper: Internal error\n");
ret = POPi; /* warns unless integer */
PUTBACK;
FREETMPS;
LEAVE;
return ret;
}
#endif
/*
* for rl_cpvfunc_t : (char *)fn(void)
*/
static char *
cpvfunc_wrapper(type)
int type;
{
dSP;
int count;
char *str;
SV *svret;
ENTER;
SAVETMPS;
PUSHMARK(sp);
count = perl_call_sv(fn_tbl[type].callback, G_SCALAR);
SPAGAIN;
if (count != 1)
croak("Gnu.xs:cpvfunc_wrapper: Internal error\n");
svret = POPs;
str = SvOK(svret) ? dupstr(SvPV(svret, PL_na)) : NULL;
PUTBACK;
FREETMPS;
LEAVE;
return str;
}
/*
* for rl_linebuf_func_t : int fn(char *, int)
*/
static int
icpintfunc_wrapper(type, text, index)
int type;
char *text;
int index;
{
dSP;
int count;
int ret;
ENTER;
SAVETMPS;
PUSHMARK(sp);
if (text) {
XPUSHs(sv_2mortal(newSVpv(text, 0)));
} else {
XPUSHs(&PL_sv_undef);
}
XPUSHs(sv_2mortal(newSViv(index)));
PUTBACK;
count = perl_call_sv(fn_tbl[type].callback, G_SCALAR);
SPAGAIN;
if (count != 1)
croak("Gnu.xs:icpintfunc_wrapper: Internal error\n");
ret = POPi; /* warns unless integer */
PUTBACK;
FREETMPS;
LEAVE;
return ret;
}
static int
startup_hook_wrapper() { return voidfunc_wrapper(STARTUP_HOOK); }
static int
event_hook_wrapper() { return voidfunc_wrapper(EVENT_HOOK); }
static int
getc_function_wrapper(fp)
PerlIO *fp;
{
/*
* 'PerlIO *fp' is ignored. Use rl_instream instead in the getc_function.
* How can I pass 'PerlIO *fp'?
*/
return voidfunc_wrapper(GETC_FN);
}
static void
redisplay_function_wrapper() { voidfunc_wrapper(REDISPLAY_FN); }
/*
* call a perl function as rl_completion_entry_function
* for rl_compentry_func_t : (char *)fn(const char *, int)
*/
static char *
completion_entry_function_wrapper(text, state)
const char *text;
int state;
{
dSP;
int count;
SV *match;
char *str;
ENTER;
SAVETMPS;
PUSHMARK(sp);
if (text) {
XPUSHs(sv_2mortal(newSVpv(text, 0)));
} else {
XPUSHs(&PL_sv_undef);
}
XPUSHs(sv_2mortal(newSViv(state)));
PUTBACK;
count = perl_call_sv(fn_tbl[CMP_ENT].callback, G_SCALAR);
SPAGAIN;
if (count != 1)
croak("Gnu.xs:completion_entry_function_wrapper: Internal error\n");
match = POPs;
str = SvOK(match) ? dupstr(SvPV(match, PL_na)) : NULL;
PUTBACK;
FREETMPS;
LEAVE;
return str;
}
/*
* call a perl function as rl_attempted_completion_function
* for rl_completion_func_t : (char **)fn(const char *, int, int)
*/
static char **
attempted_completion_function_wrapper(text, start, end)
char *text;
int start;
int end;
{
dSP;
int count;
char **matches;
ENTER;
SAVETMPS;
PUSHMARK(sp);
if (text) {
XPUSHs(sv_2mortal(newSVpv(text, 0)));
} else {
XPUSHs(&PL_sv_undef);
}
if (rl_line_buffer) {
XPUSHs(sv_2mortal(newSVpv(rl_line_buffer, 0)));
} else {
XPUSHs(&PL_sv_undef);
}
XPUSHs(sv_2mortal(newSViv(start)));
XPUSHs(sv_2mortal(newSViv(end)));
PUTBACK;
count = perl_call_sv(fn_tbl[ATMPT_COMP].callback, G_ARRAY);
SPAGAIN;
/* cf. ignore_some_completions_function_wrapper() */
if (count > 0) {
int i;
int dopack = -1;
/*
* The returned array may contain some undef items.
* Pack the array in such case.
*/
matches = (char **)xmalloc (sizeof(char *) * (count + 1));
matches[count] = NULL;
for (i = count - 1; i >= 0; i--) {
SV *v = POPs;
if (SvOK(v)) {
matches[i] = dupstr(SvPV(v, PL_na));
} else {
matches[i] = NULL;
if (i != 0)
dopack = i; /* lowest index of hole */
}
}
/* pack undef items */
if (dopack > 0) { /* don't pack matches[0] */
int j = dopack;
for (i = dopack; i < count; i++) {
if (matches[i])
matches[j++] = matches[i];
}
matches[count = j] = NULL;
}
if (count == 2) { /* only one match */
xfree(matches[0]);
matches[0] = matches[1];
matches[1] = NULL;
} else if (count == 1 && !matches[0]) { /* in case of a list of undef */
xfree(matches);
matches = NULL;
}
} else {
matches = NULL;
}
PUTBACK;
FREETMPS;
LEAVE;
return matches;
}
/*
* call a perl function as rl_filename_quoting_function
* for rl_quote_func_t : (char *)fn(char *, int, char *)
*/
static char *
filename_quoting_function_wrapper(text, match_type, quote_pointer)
char *text;
int match_type;
char *quote_pointer;
{
dSP;
int count;
SV *replacement;
char *str;
ENTER;
SAVETMPS;
PUSHMARK(sp);
if (text) {
XPUSHs(sv_2mortal(newSVpv(text, 0)));
} else {
XPUSHs(&PL_sv_undef);
}
XPUSHs(sv_2mortal(newSViv(match_type)));
if (quote_pointer) {
XPUSHs(sv_2mortal(newSVpv(quote_pointer, 0)));
} else {
XPUSHs(&PL_sv_undef);
}
PUTBACK;
count = perl_call_sv(fn_tbl[FN_QUOTE].callback, G_SCALAR);
SPAGAIN;
if (count != 1)
croak("Gnu.xs:filename_quoting_function_wrapper: Internal error\n");
replacement = POPs;
str = SvOK(replacement) ? dupstr(SvPV(replacement, PL_na)) : NULL;
PUTBACK;
FREETMPS;
LEAVE;
return str;
}
/*
* call a perl function as rl_filename_dequoting_function
* for rl_dequote_func_t : (char *)fn(char *, int)
*/
static char *
filename_dequoting_function_wrapper(text, quote_char)
char *text;
int quote_char;
{
dSP;
int count;
SV *replacement;
char *str;
ENTER;
SAVETMPS;
PUSHMARK(sp);
if (text) {
XPUSHs(sv_2mortal(newSVpv(text, 0)));
} else {
XPUSHs(&PL_sv_undef);
}
XPUSHs(sv_2mortal(newSViv(quote_char)));
PUTBACK;
count = perl_call_sv(fn_tbl[FN_DEQUOTE].callback, G_SCALAR);
SPAGAIN;
if (count != 1)
croak("Gnu.xs:filename_dequoting_function_wrapper: Internal error\n");
replacement = POPs;
str = SvOK(replacement) ? dupstr(SvPV(replacement, PL_na)) : NULL;
PUTBACK;
FREETMPS;
LEAVE;
return str;
}
/*
* call a perl function as rl_char_is_quoted_p
*/
static int
char_is_quoted_p_wrapper(text, index)
char *text;
int index;
{
return icpintfunc_wrapper(CHAR_IS_QUOTEDP, text, index);
}
/*
* call a perl function as rl_ignore_some_completions_function
* for rl_compignore_func_t : int fn(char **)
*/
static void
ignore_some_completions_function_wrapper(matches)
char **matches;
{
dSP;
int count, i, only_one_match;
only_one_match = matches[1] == NULL ? 1 : 0;
ENTER;
SAVETMPS;
PUSHMARK(sp);
/* matches[0] is the maximal matching substring. So it may NULL, even rest
* of matches[] has values. */
if (matches[0]) {
XPUSHs(sv_2mortal(newSVpv(matches[0], 0)));
/* xfree(matches[0]);*/
} else {
XPUSHs(&PL_sv_undef);
}
for (i = 1; matches[i]; i++) {
XPUSHs(sv_2mortal(newSVpv(matches[i], 0)));
xfree(matches[i]);
}
/*xfree(matches);*/
PUTBACK;
count = perl_call_sv(fn_tbl[IGNORE_COMP].callback, G_ARRAY);
SPAGAIN;
if (only_one_match) {
if (count == 0) { /* no match */
xfree(matches[0]);
matches[0] = NULL;
} /* else only one match */
} else if (count > 0) {
int i;
int dopack = -1;
/*
* The returned array may contain some undef items.
* Pack the array in such case.
*/
matches[count] = NULL;
for (i = count - 1; i > 0; i--) { /* don't pop matches[0] */
SV *v = POPs;
if (SvOK(v)) {
matches[i] = dupstr(SvPV(v, PL_na));
} else {
matches[i] = NULL;
dopack = i; /* lowest index of undef */
}
}
/* pack undef items */
if (dopack > 0) { /* don't pack matches[0] */
int j = dopack;
for (i = dopack; i < count; i++) {
if (matches[i])
matches[j++] = matches[i];
}
matches[count = j] = NULL;
}
if (count == 1) { /* no match */
xfree(matches[0]);
matches[0] = NULL;
} else if (count == 2) { /* only one match */
xfree(matches[0]);
matches[0] = matches[1];
matches[1] = NULL;
}
} else { /* no match */
xfree(matches[0]);
matches[0] = NULL;
}
PUTBACK;
FREETMPS;
LEAVE;
}
/*
* call a perl function as rl_directory_completion_hook
*/
static int
directory_completion_hook_wrapper(textp)
char **textp;
{
return icppfunc_wrapper(DIR_COMP, textp);
}
/*
* call a perl function as history_inhibit_expansion_function
*/
static int
history_inhibit_expansion_function_wrapper(text, index)
char *text;
int index;
{
return icpintfunc_wrapper(HIST_INHIBIT_EXP, text, index);
}
static int
pre_input_hook_wrapper() { return voidfunc_wrapper(PRE_INPUT_HOOK); }
#if (RL_VERSION_MAJOR >= 4)
/*
* call a perl function as rl_completion_display_matches_hook
* for rl_compdisp_func_t : void fn(char **, int, int)
*/
static void
completion_display_matches_hook_wrapper(matches, len, max)
char **matches;
int len;
int max;
{
dSP;
int i;
AV *av_matches;
/* copy C matches[] array into perl array */
av_matches = newAV();
/* matches[0] is the maximal matching substring. So it may NULL, even rest
* of matches[] has values. */
if (matches[0]) {
av_push(av_matches, sv_2mortal(newSVpv(matches[0], 0)));
} else {
av_push(av_matches, &PL_sv_undef);
}
for (i = 1; matches[i]; i++)
if (matches[i]) {
av_push(av_matches, sv_2mortal(newSVpv(matches[i], 0)));
} else {
av_push(av_matches, &PL_sv_undef);
}
PUSHMARK(sp);
XPUSHs(sv_2mortal(newRV_inc((SV *)av_matches))); /* push reference of array */
XPUSHs(sv_2mortal(newSViv(len)));
XPUSHs(sv_2mortal(newSViv(max)));
PUTBACK;
perl_call_sv(fn_tbl[COMP_DISP_HOOK].callback, G_DISCARD);
}
#else /* (RL_VERSION_MAJOR < 4) */
static void
completion_display_matches_hook_wrapper(matches, len, max)
char **matches;
int len;
int max;
{
/* dummy */
}
#endif /* (RL_VERSION_MAJOR < 4) */
static char *
completion_word_break_hook_wrapper()
{
return cpvfunc_wrapper(COMP_WD_BRK_HOOK);
}
static int
prep_term_function_wrapper(meta_flag)
int meta_flag;
{
return vintfunc_wrapper(PREP_TERM, meta_flag);
}
static int
deprep_term_function_wrapper() { return voidfunc_wrapper(DEPREP_TERM); }
/*
* call a perl function as rl_directory_completion_hook
*/
static int
directory_rewrite_hook_wrapper(dirname)
char **dirname;
{
return icppfunc_wrapper(DIR_REWRITE, dirname);
}
/*
* If you need more custom functions, define more funntion_wrapper_xx()
* and add entry on fntbl[].
*/
static int function_wrapper PARAMS((int count, int key, int id));
static int fw_00(c, k) int c; int k; { return function_wrapper(c, k, 0); }
static int fw_01(c, k) int c; int k; { return function_wrapper(c, k, 1); }
static int fw_02(c, k) int c; int k; { return function_wrapper(c, k, 2); }
static int fw_03(c, k) int c; int k; { return function_wrapper(c, k, 3); }
static int fw_04(c, k) int c; int k; { return function_wrapper(c, k, 4); }
static int fw_05(c, k) int c; int k; { return function_wrapper(c, k, 5); }
static int fw_06(c, k) int c; int k; { return function_wrapper(c, k, 6); }
static int fw_07(c, k) int c; int k; { return function_wrapper(c, k, 7); }
static int fw_08(c, k) int c; int k; { return function_wrapper(c, k, 8); }
static int fw_09(c, k) int c; int k; { return function_wrapper(c, k, 9); }
static int fw_10(c, k) int c; int k; { return function_wrapper(c, k, 10); }
static int fw_11(c, k) int c; int k; { return function_wrapper(c, k, 11); }
static int fw_12(c, k) int c; int k; { return function_wrapper(c, k, 12); }
static int fw_13(c, k) int c; int k; { return function_wrapper(c, k, 13); }
static int fw_14(c, k) int c; int k; { return function_wrapper(c, k, 14); }
static int fw_15(c, k) int c; int k; { return function_wrapper(c, k, 15); }
static struct fnnode {
Function *wrapper; /* C wrapper function */
SV *pfn; /* Perl function */
} fntbl[] = {
{ fw_00, NULL },
{ fw_01, NULL },
{ fw_02, NULL },
{ fw_03, NULL },
{ fw_04, NULL },
{ fw_05, NULL },
{ fw_06, NULL },
{ fw_07, NULL },
{ fw_08, NULL },
{ fw_09, NULL },
{ fw_10, NULL },
{ fw_11, NULL },
{ fw_12, NULL },
{ fw_13, NULL },
{ fw_14, NULL },
{ fw_15, NULL }
};
static int
function_wrapper(count, key, id)
int count;
int key;
int id;
{
dSP;
PUSHMARK(sp);
XPUSHs(sv_2mortal(newSViv(count)));
XPUSHs(sv_2mortal(newSViv(key)));
PUTBACK;
perl_call_sv(fntbl[id].pfn, G_DISCARD);
return 0;
}
static SV *callback_handler_callback = NULL;
static void
callback_handler_wrapper(line)
char *line;
{
dSP;
PUSHMARK(sp);
if (line) {
XPUSHs(sv_2mortal(newSVpv(line, 0)));
} else {
XPUSHs(&PL_sv_undef);
}
PUTBACK;
perl_call_sv(callback_handler_callback, G_DISCARD);
}
/*
* make separate name space for low level XS functions and their methods
*/
MODULE = Term::ReadLine::Gnu PACKAGE = Term::ReadLine::Gnu::XS
########################################################################
#
# Gnu Readline Library
#
########################################################################
#
# 2.1 Basic Behavior
#
# The function name "readline()" is reserved for a method name.
t_xstr
rl_readline(prompt = NULL)
CONST char * prompt
PROTOTYPE: ;$
CODE:
RETVAL = readline(prompt);
OUTPUT:
RETVAL
#
# 2.4 Readline Convenience Functions
#
#
# 2.4.1 Naming a Function
#
rl_command_func_t *
rl_add_defun(name, fn, key = -1)
CONST char * name
SV * fn
int key
PROTOTYPE: $$;$
CODE:
{
int i;
int nentry = sizeof(fntbl)/sizeof(struct fnnode);
/* search an empty slot */
for (i = 0; i < nentry; i++)
if (! fntbl[i].pfn)
break;
if (i >= nentry) {
warn("Gnu.xs:rl_add_defun: custom function table is full. The maximum number of custum function is %d.\n",
nentry);
XSRETURN_UNDEF;
}
fntbl[i].pfn = newSVsv(fn);
/* rl_add_defun() always returns 0. */
rl_add_defun(dupstr(name), fntbl[i].wrapper, key);
RETVAL = fntbl[i].wrapper;
}
OUTPUT:
RETVAL
#
# 2.4.2 Selection a Keymap
#
Keymap
rl_make_bare_keymap()
PROTOTYPE:
Keymap
_rl_copy_keymap(map)
Keymap map
PROTOTYPE: $
CODE:
RETVAL = rl_copy_keymap(map);
OUTPUT:
RETVAL
Keymap
rl_make_keymap()
PROTOTYPE:
Keymap
_rl_discard_keymap(map)
Keymap map
PROTOTYPE: $
CODE:
rl_discard_keymap(map);
RETVAL = map;
OUTPUT:
RETVAL
# comment out until GNU Readline 6.2 will be released.
#void
#rl_free_keymap(map)
# Keymap map
# PROTOTYPE: $
Keymap
rl_get_keymap()
PROTOTYPE:
Keymap
_rl_set_keymap(map)
Keymap map
PROTOTYPE: $
CODE:
rl_set_keymap(map);
RETVAL = map;
OUTPUT:
RETVAL
Keymap
rl_get_keymap_by_name(name)
CONST char * name
PROTOTYPE: $
# Do not free the string returned.
char *
rl_get_keymap_name(map)
Keymap map
PROTOTYPE: $
#
# 2.4.3 Binding Keys
#
int
_rl_bind_key(key, function, map = rl_get_keymap())
int key
rl_command_func_t * function
Keymap map
PROTOTYPE: $$;$
CODE:
RETVAL = rl_bind_key_in_map(key, function, map);
OUTPUT:
RETVAL
int
_rl_bind_key_if_unbound(key, function, map = rl_get_keymap())
int key
rl_command_func_t * function
Keymap map
PROTOTYPE: $$;$
CODE:
RETVAL = rl_bind_key_if_unbound_in_map(key, function, map);
OUTPUT:
RETVAL
int
_rl_unbind_key(key, map = rl_get_keymap())
int key
Keymap map
PROTOTYPE: $;$
CODE:
RETVAL = rl_unbind_key_in_map(key, map);
OUTPUT:
RETVAL
# rl_unbind_function_in_map() and rl_unbind_command_in_map() are introduced
# by readline-2.2.
int
_rl_unbind_function(function, map = rl_get_keymap())
rl_command_func_t * function
Keymap map
PROTOTYPE: $;$
CODE:
RETVAL = rl_unbind_function_in_map(function, map);
OUTPUT:
RETVAL
int
_rl_unbind_command(command, map = rl_get_keymap())
CONST char * command
Keymap map
PROTOTYPE: $;$
CODE:
RETVAL = rl_unbind_command_in_map(command, map);
OUTPUT:
RETVAL
int
_rl_bind_keyseq(keyseq, function, map = rl_get_keymap())
const char *keyseq
rl_command_func_t * function
Keymap map
PROTOTYPE: $$;$
CODE:
RETVAL = rl_bind_keyseq_in_map(keyseq, function, map);
OUTPUT:
RETVAL
# rl_set_key() is introduced by readline-4.2 and equivalent with
# rl_generic_bind(ISFUNC, keyseq, (char *)function, map).
int
_rl_set_key(keyseq, function, map = rl_get_keymap())
CONST char * keyseq
rl_command_func_t * function
Keymap map
PROTOTYPE: $$;$
CODE:
#if (RL_READLINE_VERSION >= 0x0402)
RETVAL = rl_set_key(keyseq, function, map);
#else
RETVAL = rl_generic_bind(ISFUNC, keyseq, (char *)function, map);
#endif
OUTPUT:
RETVAL
int
_rl_bind_keyseq_if_unbound(keyseq, function, map = rl_get_keymap())
const char *keyseq
rl_command_func_t * function
Keymap map
PROTOTYPE: $$;$
CODE:
RETVAL = rl_bind_keyseq_if_unbound_in_map(keyseq, function, map);
OUTPUT:
RETVAL
int
_rl_generic_bind_function(keyseq, function, map = rl_get_keymap())
CONST char * keyseq
rl_command_func_t * function
Keymap map
PROTOTYPE: $$;$
CODE:
RETVAL = rl_generic_bind(ISFUNC, keyseq, (char *)function, map);
OUTPUT:
RETVAL
int
_rl_generic_bind_keymap(keyseq, keymap, map = rl_get_keymap())
CONST char * keyseq
Keymap keymap
Keymap map
PROTOTYPE: $$;$
CODE:
RETVAL = rl_generic_bind(ISKMAP, keyseq, (char *)keymap, map);
OUTPUT:
RETVAL
int
_rl_generic_bind_macro(keyseq, macro, map = rl_get_keymap())
CONST char * keyseq
CONST char * macro
Keymap map
PROTOTYPE: $$;$
CODE:
RETVAL = rl_generic_bind(ISMACR, keyseq, dupstr(macro), map);
OUTPUT:
RETVAL
void
rl_parse_and_bind(line)
char * line
PROTOTYPE: $
CODE:
{
char *s = dupstr(line);
rl_parse_and_bind(s); /* Some NULs may be inserted in "s". */
xfree(s);
}
int
rl_read_init_file(filename = NULL)
CONST char * filename
PROTOTYPE: ;$
#
# 2.4.4 Associating Function Names and Bindings
#
int
_rl_call_function(function, count = 1, key = -1)
rl_command_func_t * function
int count
int key
PROTOTYPE: $;$$
CODE:
RETVAL = (*function)(count, key);
OUTPUT:
RETVAL
rl_command_func_t *
rl_named_function(name)
CONST char * name
PROTOTYPE: $
# Do not free the string returned.
const char *
rl_get_function_name(function)
rl_command_func_t * function
PROTOTYPE: $
void
rl_function_of_keyseq(keyseq, map = rl_get_keymap())
CONST char * keyseq
Keymap map
PROTOTYPE: $;$
PPCODE:
{
int type;
rl_command_func_t *p = rl_function_of_keyseq(keyseq, map, &type);
SV *sv;
if (p) {
sv = sv_newmortal();
switch (type) {
case ISFUNC:
sv_setref_pv(sv, "rl_command_func_tPtr", (void*)p);
break;
case ISKMAP:
sv_setref_pv(sv, "Keymap", (void*)p);
break;
case ISMACR:
if (p) {
sv_setpv(sv, (char *)p);
}
break;
default:
warn("Gnu.xs:rl_function_of_keyseq: illegal type `%d'\n", type);
XSRETURN_EMPTY; /* return NULL list */
}
EXTEND(sp, 2);
PUSHs(sv);
PUSHs(sv_2mortal(newSViv(type)));
} else
; /* return NULL list */
}
void
_rl_invoking_keyseqs(function, map = rl_get_keymap())
rl_command_func_t * function
Keymap map
PROTOTYPE: $;$
PPCODE:
{
char **keyseqs;
keyseqs = rl_invoking_keyseqs_in_map(function, map);
if (keyseqs) {
int i, count;
/* count number of entries */
for (count = 0; keyseqs[count]; count++)
;
EXTEND(sp, count);
for (i = 0; i < count; i++) {
PUSHs(sv_2mortal(newSVpv(keyseqs[i], 0)));
xfree(keyseqs[i]);
}
xfree((char *)keyseqs);
} else {
/* return null list */
}
}
void
rl_function_dumper(readable = 0)
int readable
PROTOTYPE: ;$
void
rl_list_funmap_names()
PROTOTYPE:
# return list of all function name. (Term::Readline::Gnu specific function)
void
rl_get_all_function_names()
PROTOTYPE:
PPCODE:
{
int i, count;
/* count number of entries */
for (count = 0; funmap[count]; count++)
;
EXTEND(sp, count);
for (i = 0; i < count; i++) {
PUSHs(sv_2mortal(newSVpv(funmap[i]->name, 0)));
}
}
void
rl_funmap_names()
PROTOTYPE:
PPCODE:
{
const char **funmap;
/* don't free returned memory */
funmap = (const char **)rl_funmap_names();/* cast is for oldies */
if (funmap) {
int i, count;
/* count number of entries */
for (count = 0; funmap[count]; count++)
;
EXTEND(sp, count);
for (i = 0; i < count; i++) {
PUSHs(sv_2mortal(newSVpv(funmap[i], 0)));
}
} else {
/* return null list */
}
}
int
_rl_add_funmap_entry(name, function)
CONST char * name
rl_command_func_t * function
PROTOTYPE: $$
CODE:
RETVAL = rl_add_funmap_entry(name, function);
OUTPUT:
RETVAL
#
# 2.4.5 Allowing Undoing
#
int
rl_begin_undo_group()
PROTOTYPE:
int
rl_end_undo_group()
PROTOTYPE:
void
rl_add_undo(what, start, end, text)
int what
int start
int end
char * text
PROTOTYPE: $$$$
CODE:
/* rl_free_undo_list will free the duplicated memory */
rl_add_undo((enum undo_code)what, start, end, dupstr(text));
void
rl_free_undo_list()
PROTOTYPE:
int
rl_do_undo()
PROTOTYPE:
int
rl_modifying(start = 0, end = rl_end)
int start
int end
PROTOTYPE: ;$$
#
# 2.4.6 Redisplay
#
void
rl_redisplay()
PROTOTYPE:
int
rl_forced_update_display()
PROTOTYPE:
int
rl_on_new_line()
PROTOTYPE:
int
rl_on_new_line_with_prompt()
PROTOTYPE:
int
rl_reset_line_state()
PROTOTYPE:
int
rl_show_char(i)
int i
PROTOTYPE: $
int
_rl_message(text)
const char * text
PROTOTYPE: $
CODE:
RETVAL = rl_message(text);
OUTPUT:
RETVAL
int
rl_crlf()
PROTOTYPE:
int
rl_clear_message()
PROTOTYPE:
void
rl_save_prompt()
PROTOTYPE:
void
rl_restore_prompt()
PROTOTYPE:
int
rl_expand_prompt(prompt)
# should be defined as 'const char *'
char * prompt
int
rl_set_prompt(prompt)
const char * prompt
#
# 2.4.7 Modifying Text
#
int
rl_insert_text(text)
CONST char * text
PROTOTYPE: $
int
rl_delete_text(start = 0, end = rl_end)
int start
int end
PROTOTYPE: ;$$
t_xstr
rl_copy_text(start = 0, end = rl_end)
int start
int end
PROTOTYPE: ;$$
int
rl_kill_text(start = 0, end = rl_end)
int start
int end
PROTOTYPE: ;$$
# rl_push_macro_input() is documented by readline-4.2 but it has been
# implemented from 2.2.1.
void
rl_push_macro_input(macro)
CONST char * macro
PROTOTYPE: $
CODE:
rl_push_macro_input(dupstr(macro));
#
# 2.4.8 Character Input
#
int
rl_read_key()
PROTOTYPE:
int
rl_getc(stream)
FILE * stream
PROTOTYPE: $
int
rl_stuff_char(c)
int c
PROTOTYPE: $
int
rl_execute_next(c)
int c
PROTOTYPE: $
int
rl_clear_pending_input()
PROTOTYPE:
int
rl_set_keyboard_input_timeout(usec)
int usec
PROTOTYPE: $
#
# 2.4.9 Terminal Management
#
void
rl_prep_terminal(meta_flag)
int meta_flag
PROTOTYPE: $
void
rl_deprep_terminal()
PROTOTYPE:
void
_rl_tty_set_default_bindings(kmap = rl_get_keymap())
Keymap kmap
PROTOTYPE: ;$
CODE:
rl_tty_set_default_bindings(kmap);
void
_rl_tty_unset_default_bindings(kmap = rl_get_keymap())
Keymap kmap
PROTOTYPE: ;$
CODE:
rl_tty_unset_default_bindings(kmap);
int
rl_reset_terminal(terminal_name = NULL)
CONST char * terminal_name
PROTOTYPE: ;$
#
# 2.4.10 Utility Functions
#
void
rl_replace_line(text, clear_undo = 0)
const char *text
int clear_undo
PROTOTYPE: $$
int
rl_initialize()
PROTOTYPE:
CODE:
{
RETVAL = rl_initialize();
/*
* Perl optionally maintains its own envirnment variable array
* using its own memory management functions. On the other hand
* the GNU Readline Library sets variables, $LINES and $COLUMNS,
* by using the C library function putenv() in
* rl_initialize(). When Perl frees the memory for the variables
* during the destruction (perl.c:perl_destruct()), it may cause
* segmentation faults.
*
* CPAN ticket #37194
* https://rt.cpan.org/Public/Bug/Display.html?id=37194
*
* To solve the problem, make a copy of the whole environment
* variable array which might be reallocated by rl_initialize().
*/
/* from perl.c:perl_destruct() */
#if defined(USE_ENVIRON_ARRAY) && !defined(PERL_USE_SAFE_PUTENV) \
&& !defined(PERL_DARWIN)
if (environ != PL_origenviron && !PL_use_safe_putenv
# ifdef USE_ITHREADS
/* only main thread can free environ[0] contents */
&& PL_curinterp == aTHX
# endif
) {
int i, len;
char *s;
char **tmpenv;
for (i = 0; environ[i]; i++)
;
/*
* We cannot use New*() which uses safemalloc() instead of
* safesysmalloc().
*/
tmpenv = (char **)safesysmalloc((i+1)*sizeof(char *));
for (i = 0; environ[i]; i++) {
len = strlen(environ[i]);
s = (char*)safesysmalloc((len+1)*sizeof(char));
Copy(environ[i], s, len+1, char);
tmpenv[i] = s;
}
tmpenv[i] = NULL;
environ = tmpenv;
}
#endif
}
OUTPUT:
RETVAL
int
rl_ding()
PROTOTYPE:
int
rl_alphabetic(c)
int c
PROTOTYPE: $
void
rl_display_match_list(pmatches, plen = -1, pmax = -1)
SV * pmatches
int plen
int pmax
PROTOTYPE: $;$$
CODE:
{
unsigned int len, max, i;
STRLEN l;
char **matches;
AV *av_matches;
SV **pvp;
if (SvTYPE(SvRV(pmatches)) != SVt_PVAV) {
warn("Gnu.xs:_rl_display_match_list: the 1st arguments must be a reference of an array\n");
return;
}
av_matches = (AV *)SvRV(ST(0));
/* index zero contains possible match and is ignored */
if ((len = av_len(av_matches) + 1 - 1) == 0)
return;
matches = (char **)xmalloc (sizeof(char *) * (len + 2));
max = 0;
for (i = 1; i <= len; i++) {
pvp = av_fetch(av_matches, i, 0);
if (SvPOKp(*pvp)) {
matches[i] = dupstr(SvPV(*pvp, l));
if (l > max)
max = l;
}
}
matches[len + 1] = NULL;
rl_display_match_list(matches,
plen < 0 ? len : plen,
pmax < 0 ? max : pmax);
for (i = 1; i <= len; i++)
xfree(matches[i]);
xfree(matches);
}
#
# 2.4.11 Miscellaneous Functions
#
# rl_macro_bind() is documented by readline-4.2 but it has been implemented
# from 2.2.1.
# It is equivalent with
# rl_generic_bind(ISMACR, keyseq, (char *)macro_keys, map).
int
_rl_macro_bind(keyseq, macro, map = rl_get_keymap())
CONST char * keyseq
CONST char * macro
Keymap map
PROTOTYPE: $$;$
CODE:
RETVAL = rl_macro_bind(keyseq, macro, map);
OUTPUT:
RETVAL
# rl_macro_dumper is documented by Readline 4.2,
# but have been implemented for 2.2.1.
void
rl_macro_dumper(readable = 0)
int readable
PROTOTYPE: ;$
# rl_variable_bind() is documented by readline-4.2 but it has been implemented
# from 2.2.1.
int
rl_variable_bind(name, value)
CONST char * name
CONST char * value
PROTOTYPE: $$
# rl_variable_dumper is documented by Readline 4.2,
# but have been implemented for 2.2.1.
# Do not free the string returned.
char *
rl_variable_value(variable)
CONST char * variable
PROTOTYPE: $
void
rl_variable_dumper(readable = 0)
int readable
PROTOTYPE: ;$
int
rl_set_paren_blink_timeout(usec)
int usec
PROTOTYPE: $
# rl_get_termcap() is documented by readline-4.2 but it has been implemented
# from 2.2.1.
# Do not free the string returned.
char *
rl_get_termcap(cap)
CONST char * cap
PROTOTYPE: $
#
# 2.4.12 Alternate Interface
#
void
rl_callback_handler_install(prompt, lhandler)
const char * prompt
SV * lhandler
PROTOTYPE: $$
CODE:
{
static char *cb_prompt = NULL;
int len = strlen(prompt) + 1;
/* The value of prompt may be used after return from this routine. */
if (cb_prompt) {
Safefree(cb_prompt);
}
New(0, cb_prompt, len, char);
Copy(prompt, cb_prompt, len, char);
/*
* Don't remove braces. The definition of SvSetSV() of
* Perl 5.003 has a problem.
*/
if (callback_handler_callback) {
SvSetSV(callback_handler_callback, lhandler);
} else {
callback_handler_callback = newSVsv(lhandler);
}
rl_callback_handler_install(cb_prompt, callback_handler_wrapper);
}
void
rl_callback_read_char()
PROTOTYPE:
void
rl_callback_handler_remove()
PROTOTYPE:
#
# 2.5 Readline Signal Handling
#
void
rl_cleanup_after_signal()
PROTOTYPE:
void
rl_free_line_state()
PROTOTYPE:
void
rl_reset_after_signal()
PROTOTYPE:
void
rl_echo_signal_char(sig)
int sig
PROTOTYPE: $
void
rl_resize_terminal()
PROTOTYPE:
void
rl_set_screen_size(rows, cols)
int rows
int cols
PROTOTYPE: $$
void
rl_get_screen_size()
PROTOTYPE:
PPCODE:
{
int rows, cols;
rl_get_screen_size(&rows, &cols);
EXTEND(sp, 2);
PUSHs(sv_2mortal(newSViv(rows)));
PUSHs(sv_2mortal(newSViv(cols)));
}
void
rl_reset_screen_size()
PROTOTYPE:
int
rl_set_signals()
PROTOTYPE:
int
rl_clear_signals()
PROTOTYPE:
#
# 2.6 Custom Completers
#
int
rl_complete_internal(what_to_do = TAB)
int what_to_do
PROTOTYPE: ;$
int
_rl_completion_mode(function)
rl_command_func_t * function
PROTOTYPE: $
CODE:
RETVAL = rl_completion_mode(function);
OUTPUT:
RETVAL
void
rl_completion_matches(text, fn = NULL)
CONST char * text
SV * fn
PROTOTYPE: $;$
PPCODE:
{
char **matches;
if (SvTRUE(fn)) {
/* use completion_entry_function temporarily */
Function *rlfunc_save = *(fn_tbl[CMP_ENT].rlfuncp);
SV *callback_save = fn_tbl[CMP_ENT].callback;
fn_tbl[CMP_ENT].callback = newSVsv(fn);
matches = rl_completion_matches(text,
completion_entry_function_wrapper);
SvREFCNT_dec(fn_tbl[CMP_ENT].callback);
fn_tbl[CMP_ENT].callback = callback_save;
*(fn_tbl[CMP_ENT].rlfuncp) = rlfunc_save;
} else
matches = rl_completion_matches(text, NULL);
/*
* Without the next line the Perl internal stack is broken
* under some condition. Perl bug or undocumented feature
* !!!?
*/
SPAGAIN; sp -= 2;
if (matches) {
int i, count;
/* count number of entries */
for (count = 0; matches[count]; count++)
;
EXTEND(sp, count);
for (i = 0; i < count; i++) {
PUSHs(sv_2mortal(newSVpv(matches[i], 0)));
xfree(matches[i]);
}
xfree((char *)matches);
} else {
/* return null list */
}
}
t_xstr
rl_filename_completion_function(text, state)
const char * text
int state
PROTOTYPE: $$
t_xstr
rl_username_completion_function(text, state)
const char * text
int state
PROTOTYPE: $$
########################################################################
#
# Gnu History Library
#
########################################################################
#
# 2.3.1 Initializing History and State Management
#
void
using_history()
PROTOTYPE:
# history_get_history_state() and history_set_history_state() are useless
# and too dangerous to be used in Perl code
# void
# history_get_history_state()
# PROTOTYPE:
# PPCODE:
# {
# HISTORY_STATE *state;
#
# state = history_get_history_state();
# EXTEND(sp, 4);
# PUSHs(sv_2mortal(newSViv(state->offset)));
# PUSHs(sv_2mortal(newSViv(state->length)));
# PUSHs(sv_2mortal(newSViv(state->size)));
# PUSHs(sv_2mortal(newSViv(state->flags)));
# xfree((char *)state);
# }
#
# 2.3.2 History List Management
#
void
add_history(string)
CONST char * string
PROTOTYPE: $
void
add_history_time(string)
CONST char * string
PROTOTYPE: $
HIST_ENTRY *
remove_history(which)
int which
PROTOTYPE: $
OUTPUT:
RETVAL
CLEANUP:
if (RETVAL) {
xfree(RETVAL->line);
#if (RL_VERSION_MAJOR >= 5)
xfree(RETVAL->timestamp);
#endif /* (RL_VERSION_MAJOR >= 5) */
xfree(RETVAL->data);
xfree((char *)RETVAL);
}
# free_history_entry() is introduced by GNU Readline Library 5.0.
# Since Term::ReadLine::Gnu does not support the member 'data' of HIST_ENTRY
# structure, remove_history() covers it.
# The 3rd parameter (histdata_t) is not supported. Does anyone use it?
HIST_ENTRY *
replace_history_entry(which, line)
int which
CONST char * line
PROTOTYPE: $$
CODE:
RETVAL = replace_history_entry(which, line, (char *)NULL);
OUTPUT:
RETVAL
CLEANUP:
if (RETVAL) {
xfree(RETVAL->line);
#if (RL_VERSION_MAJOR >= 5)
xfree(RETVAL->timestamp);
#endif /* (RL_VERSION_MAJOR >= 5) */
xfree(RETVAL->data);
xfree((char *)RETVAL);
}
void
clear_history()
PROTOTYPE:
int
stifle_history(i)
SV * i
PROTOTYPE: $
CODE:
{
if (SvOK(i)) {
int max = SvIV(i);
stifle_history(max);
RETVAL = max;
} else {
RETVAL = unstifle_history();
}
}
OUTPUT:
RETVAL
int
unstifle_history()
PROTOTYPE:
int
history_is_stifled()
PROTOTYPE:
#
# 2.3.3 Information about the History List
#
# history_list() is implemented as a perl function in Gnu.pm.
int
where_history()
PROTOTYPE:
HIST_ENTRY *
current_history()
PROTOTYPE:
HIST_ENTRY *
history_get(offset)
int offset
PROTOTYPE: $
# To keep compatibility, I cannot make a function whose argument
# is "HIST_ENTRY *".
time_t
history_get_time(offset)
int offset
PROTOTYPE: $
CODE:
{
HIST_ENTRY *he = history_get(offset);
if (he)
RETVAL = history_get_time(he);
else
RETVAL = 0;
}
OUTPUT:
RETVAL
int
history_total_bytes()
PROTOTYPE:
#
# 2.3.4 Moving Around the History List
#
int
history_set_pos(pos)
int pos
PROTOTYPE: $
HIST_ENTRY *
previous_history()
PROTOTYPE:
HIST_ENTRY *
next_history()
PROTOTYPE:
#
# 2.3.5 Searching the History List
#
int
history_search(string, direction = -1)
CONST char * string
int direction
PROTOTYPE: $;$
int
history_search_prefix(string, direction = -1)
CONST char * string
int direction
PROTOTYPE: $;$
int
history_search_pos(string, direction = -1, pos = where_history())
CONST char * string
int direction
int pos
PROTOTYPE: $;$$
#
# 2.3.6 Managing the History File
#
int
read_history_range(filename = NULL, from = 0, to = -1)
CONST char * filename
int from
int to
PROTOTYPE: ;$$$
int
write_history(filename = NULL)
CONST char * filename
PROTOTYPE: ;$
int
append_history(nelements, filename = NULL)
int nelements
CONST char * filename
PROTOTYPE: $;$
int
history_truncate_file(filename = NULL, nlines = 0)
CONST char * filename
int nlines
PROTOTYPE: ;$$
#
# 2.3.7 History Expansion
#
void
history_expand(line)
# should be defined as 'const char *'
char * line
PROTOTYPE: $
PPCODE:
{
char *expansion;
int result;
result = history_expand(line, &expansion);
EXTEND(sp, 2);
PUSHs(sv_2mortal(newSViv(result)));
PUSHs(sv_2mortal(newSVpv(expansion, 0)));
xfree(expansion);
}
void
_get_history_event(string, cindex, qchar = 0)
CONST char * string
int cindex
int qchar
PROTOTYPE: $$;$
PPCODE:
{
char *text;
text = get_history_event(string, &cindex, qchar);
EXTEND(sp, 2);
if (text) { /* don't free `text' */
PUSHs(sv_2mortal(newSVpv(text, 0)));
} else {
PUSHs(&PL_sv_undef);
}
PUSHs(sv_2mortal(newSViv(cindex)));
}
void
history_tokenize(text)
CONST char * text
PROTOTYPE: $
PPCODE:
{
char **tokens;
tokens = history_tokenize(text);
if (tokens) {
int i, count;
/* count number of entries */
for (count = 0; tokens[count]; count++)
;
EXTEND(sp, count);
for (i = 0; i < count; i++) {
PUSHs(sv_2mortal(newSVpv(tokens[i], 0)));
xfree(tokens[i]);
}
xfree((char *)tokens);
} else {
/* return null list */
}
}
#define DALLAR '$' /* define for xsubpp bug */
t_xstr
_history_arg_extract(line, first = 0 , last = DALLAR)
CONST char * line
int first
int last
PROTOTYPE: $;$$
CODE:
RETVAL = history_arg_extract(first, last, line);
OUTPUT:
RETVAL
#
# GNU Readline/History Library Variable Access Routines
#
MODULE = Term::ReadLine::Gnu PACKAGE = Term::ReadLine::Gnu::Var
void
_rl_store_str(pstr, id)
const char * pstr
int id
PROTOTYPE: $$
CODE:
{
size_t len;
ST(0) = sv_newmortal();
if (id < 0 || id >= sizeof(str_tbl)/sizeof(struct str_vars)) {
warn("Gnu.xs:_rl_store_str: Illegal `id' value: `%d'", id);
XSRETURN_UNDEF;
}
if (str_tbl[id].read_only) {
warn("Gnu.xs:_rl_store_str: store to read only variable");
XSRETURN_UNDEF;
}
/*
* Use xmalloc() and xfree() instead of New() and Safefree(),
* because this block may be reallocated by the GNU Readline Library.
*/
if (str_tbl[id].accessed && *str_tbl[id].var) {
/*
* First time a variable is used by this routine,
* it may be a static area. So it cannot be freed.
*/
xfree(*str_tbl[id].var);
*str_tbl[id].var = NULL;
}
str_tbl[id].accessed = 1;
len = strlen(pstr) + 1;
*str_tbl[id].var = xmalloc(len);
Copy(pstr, *str_tbl[id].var, len, char);
/* return variable value */
if (*str_tbl[id].var) {
sv_setpv(ST(0), *str_tbl[id].var);
}
}
void
_rl_store_rl_line_buffer(pstr)
const char * pstr
PROTOTYPE: $
CODE:
{
size_t len;
ST(0) = sv_newmortal();
if (pstr) {
len = strlen(pstr);
/*
* Old manual did not document this function, but can be
* used.
*/
rl_extend_line_buffer(len + 1);
Copy(pstr, rl_line_buffer, len + 1, char);
/* rl_line_buffer is not NULL here */
sv_setpv(ST(0), rl_line_buffer);
/* fix rl_end and rl_point */
rl_end = len;
if (rl_point > len)
rl_point = len;
}
}
void
_rl_fetch_str(id)
int id
PROTOTYPE: $
CODE:
{
ST(0) = sv_newmortal();
if (id < 0 || id >= sizeof(str_tbl)/sizeof(struct str_vars)) {
warn("Gnu.xs:_rl_fetch_str: Illegal `id' value: `%d'", id);
} else {
if (*(str_tbl[id].var)) {
sv_setpv(ST(0), *(str_tbl[id].var));
}
}
}
void
_rl_store_int(pint, id)
int pint
int id
PROTOTYPE: $$
CODE:
{
ST(0) = sv_newmortal();
if (id < 0 || id >= sizeof(int_tbl)/sizeof(struct int_vars)) {
warn("Gnu.xs:_rl_store_int: Illegal `id' value: `%d'", id);
XSRETURN_UNDEF;
}
if (int_tbl[id].read_only) {
warn("Gnu.xs:_rl_store_int: store to read only variable");
XSRETURN_UNDEF;
}
/* set C variable */
if (int_tbl[id].charp)
*((char *)(int_tbl[id].var)) = (char)pint;
else
*(int_tbl[id].var) = pint;
/* return variable value */
sv_setiv(ST(0), pint);
}
void
_rl_fetch_int(id)
int id
PROTOTYPE: $
CODE:
{
ST(0) = sv_newmortal();
if (id < 0 || id >= sizeof(int_tbl)/sizeof(struct int_vars)) {
warn("Gnu.xs:_rl_fetch_int: Illegal `id' value: `%d'", id);
/* return undef */
} else {
sv_setiv(ST(0),
int_tbl[id].charp ? (int)*((char *)(int_tbl[id].var))
: *(int_tbl[id].var));
}
}
PerlIO *
_rl_store_iostream(stream, id)
PerlIO *stream
int id
PROTOTYPE: $$
CODE:
{
switch (id) {
case 0:
#if 0 /* PerlIO_releaseFILE must be called only before closing FILE *. */
if (instreamPIO != NULL)
PerlIO_releaseFILE(instreamPIO, rl_instream);
#endif
rl_instream = PerlIO_findFILE(stream);
RETVAL = instreamPIO = stream;
break;
case 1:
#if 0 /* PerlIO_releaseFILE must be called only before closing FILE *. */
if (outstreamPIO != NULL)
PerlIO_releaseFILE(outstreamPIO, rl_outstream);
#endif
rl_outstream = PerlIO_findFILE(stream);
/*
* Debian-specific addition fixing a segfault with "PERLIO=stdio"
* see http://bugs.debian.org/350991
*/
if (!rl_outstream)
rl_outstream = stdout;
RETVAL = outstreamPIO = stream;
#ifdef __CYGWIN__
{
/* Cygwin b20.1 library converts NL to CR-NL
automatically. But it does not do it on a file
stream made by Perl. Set terminal attribute
explicitly */
struct termios tio;
tcgetattr(fileno(rl_outstream), &tio);
tio.c_iflag |= ICRNL;
tio.c_oflag |= ONLCR;
tcsetattr(fileno(rl_outstream), TCSADRAIN, &tio);
}
#endif /* __CYGWIN__ */
break;
default:
warn("Gnu.xs:_rl_store_iostream: Illegal `id' value: `%d'", id);
XSRETURN_UNDEF;
break;
}
PerlIO_debug("TRG:store_iostream id %d fd %d\n",
id, PerlIO_fileno(RETVAL));
}
OUTPUT:
RETVAL
PerlIO *
_rl_fetch_iostream(id)
int id
PROTOTYPE: $
CODE:
{
switch (id) {
case 0:
if (instreamPIO == NULL)
RETVAL = instreamPIO = PerlIO_importFILE(rl_instream, NULL);
else
RETVAL = instreamPIO;
break;
case 1:
if (outstreamPIO == NULL)
RETVAL = outstreamPIO = PerlIO_importFILE(rl_outstream, NULL);
else
RETVAL = outstreamPIO;
break;
default:
warn("Gnu.xs:_rl_fetch_iostream: Illegal `id' value: `%d'", id);
XSRETURN_UNDEF;
break;
}
PerlIO_debug("TRG:fetch_iostream id %d fd %d\n",
id, PerlIO_fileno(RETVAL));
}
OUTPUT:
RETVAL
Keymap
_rl_fetch_keymap(id)
int id
PROTOTYPE: $
CODE:
{
switch (id) {
case 0:
RETVAL = rl_executing_keymap;
break;
case 1:
RETVAL = rl_binding_keymap;
break;
default:
warn("Gnu.xs:_rl_fetch_keymap: Illegal `id' value: `%d'", id);
XSRETURN_UNDEF;
break;
}
}
OUTPUT:
RETVAL
void
_rl_store_function(fn, id)
SV * fn
int id
PROTOTYPE: $$
CODE:
{
/*
* If "fn" is undef, default value of the GNU Readline
* Library is set.
*/
ST(0) = sv_newmortal();
if (id < 0 || id >= sizeof(fn_tbl)/sizeof(struct fn_vars)) {
warn("Gnu.xs:_rl_store_function: Illegal `id' value: `%d'", id);
XSRETURN_UNDEF;
}
if (SvTRUE(fn)) {
/*
* Don't remove braces. The definition of SvSetSV() of
* Perl 5.003 has a problem.
*/
if (fn_tbl[id].callback) {
SvSetSV(fn_tbl[id].callback, fn);
} else {
fn_tbl[id].callback = newSVsv(fn);
}
*(fn_tbl[id].rlfuncp) = fn_tbl[id].wrapper;
} else {
if (fn_tbl[id].callback) {
SvSetSV(fn_tbl[id].callback, &PL_sv_undef);
}
*(fn_tbl[id].rlfuncp) = fn_tbl[id].defaultfn;
}
/* return variable value */
sv_setsv(ST(0), fn);
}
void
_rl_fetch_function(id)
int id
PROTOTYPE: $
CODE:
{
ST(0) = sv_newmortal();
if (id < 0 || id >= sizeof(fn_tbl)/sizeof(struct fn_vars)) {
warn("Gnu.xs:_rl_fetch_function: Illegal `id' value: `%d'", id);
/* return undef */
} else if (fn_tbl[id].callback && SvTRUE(fn_tbl[id].callback)) {
sv_setsv(ST(0), fn_tbl[id].callback);
}
}
Function *
_rl_fetch_last_func()
PROTOTYPE:
CODE:
RETVAL = rl_last_func;
OUTPUT:
RETVAL
MODULE = Term::ReadLine::Gnu PACKAGE = Term::ReadLine::Gnu::XS
void
tgetstr(id)
const char * id
PROTOTYPE: $
CODE:
ST(0) = sv_newmortal();
if (id) {
/*
* The magic number `2032' is derived from bash
* terminal.c:_rl_init_terminal_io().
*/
char buffer[2032];
char *bp = buffer;
char *t;
t = tgetstr(id, &bp); /* don't free returned string */
if (t) {
char buf[2032];
/* call tputs() to apply padding information */
tputs_ptr = buf;
tputs(t, 1, tputs_char);
*tputs_ptr = '\0';
sv_setpv(ST(0), buf);
}
}
#
# Local Variables:
# c-default-style: "gnu"
# End:
#
|