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
|
/*
* input.c: does the actual input line stuff... keeps the appropriate stuff
* on the input line, handles insert/delete of characters/words... the whole
* ball o wax
*
* Written By Michael Sandrof
*
* Copyright(c) 1990
*
* See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT
*/
#include "irc.h"
static char cvsrevision[] = "$Id: input.c,v 1.1.1.1 2003/04/11 01:09:07 dan Exp $";
CVS_REVISION(input_c)
#include <pwd.h>
#include "struct.h"
#include "alias.h"
#include "commands.h"
#include "exec.h"
#include "history.h"
#include "bsdglob.h"
#include "hook.h"
#include "input.h"
#include "ircaux.h"
#include "keys.h"
#include "screen.h"
#include "server.h"
#include "ircterm.h"
#include "list.h"
#include "vars.h"
#include "misc.h"
#include "screen.h"
#include "output.h"
#include "chelp.h"
#include "dcc.h"
#include "cdcc.h"
#include "whowas.h"
#include "tcl_bx.h"
#include "window.h"
#include "status.h"
#include "hash2.h"
#ifdef TRANSLATE
#include "translat.h"
#endif
#ifdef WANT_HEBREW
#include "hebrew.h"
#endif
#define MAIN_SOURCE
#include "modval.h"
#include <sys/ioctl.h>
void get_history (int);
static char new_nick[NICKNAME_LEN+1] = "";
static char *input_lastmsg = NULL;
extern NickTab *BX_getnextnick (int, char *, char *, char *);
extern int extended_handled;
extern char *BX_getchannick (char *, char *);
extern int foreground;
NickTab *tabkey_array = NULL, *autoreply_array = NULL;
const int WIDTH = 10;
/* input_prompt: contains the current, unexpanded input prompt */
static char *input_prompt = NULL;
enum I_STATE {
STATE_NORMAL = 0,
STATE_COMPLETE,
STATE_TABKEY,
STATE_TABKEYNEXT,
STATE_CNICK,
STATE_CNICKNEXT
} in_completion = STATE_NORMAL;
/* These are sanity macros. The file was completely unreadable before
* i put these in here. I make no apologies for them.
*/
#define current_screen last_input_screen
#define INPUT_CURSOR current_screen->input_cursor
#define INPUT_BUFFER current_screen->input_buffer
#define MIN_POS current_screen->buffer_min_pos
#define THIS_POS current_screen->buffer_pos
#define THIS_CHAR INPUT_BUFFER[THIS_POS]
#define MIN_CHAR INPUT_BUFFER[MIN_POS]
#define PREV_CHAR INPUT_BUFFER[THIS_POS-1]
#define NEXT_CHAR INPUT_BUFFER[THIS_POS+1]
#define ADD_TO_INPUT(x) strmcat(INPUT_BUFFER, (x), INPUT_BUFFER_SIZE);
#define INPUT_ONSCREEN current_screen->input_visible
#define INPUT_VISIBLE INPUT_BUFFER[INPUT_ONSCREEN]
#define ZONE current_screen->input_zone_len
#define START_ZONE current_screen->input_start_zone
#define END_ZONE current_screen->input_end_zone
#define INPUT_PROMPT current_screen->input_prompt
#define INPUT_PROMPT_LEN current_screen->input_prompt_len
#define INPUT_LINE current_screen->input_line
#define BUILT_IN_KEYBINDING(x) void x (char key, char *string)
#define HOLDLAST current_screen->current_window->screen_hold
Display *get_screen_hold(Window *win)
{
return win->screen_hold;
}
static int safe_puts (register char *str, int len, int echo)
{
int i = 0;
while (*str && i < len)
{
term_putchar(*str);
str++; i++;
}
return i;
}
/* cursor_to_input: move the cursor to the input line, if not there already */
extern void BX_cursor_to_input (void)
{
Screen *oldscreen = last_input_screen;
Screen *screen;
if (!foreground)
return;
for (screen = screen_list; screen; screen = screen->next)
{
if (screen->alive && is_cursor_in_display(screen))
{
output_screen = screen;
last_input_screen = screen;
term_move_cursor(INPUT_CURSOR, INPUT_LINE);
cursor_not_in_display(screen);
term_flush();
}
}
output_screen = last_input_screen = oldscreen;
}
/*
* update_input: does varying amount of updating on the input line depending
* upon the position of the cursor and the update flag. If the cursor has
* move toward one of the edge boundaries on the screen, update_cursor()
* flips the input line to the next (previous) line of text. The update flag
* may be:
*
* NO_UPDATE - only do the above bounds checking.
*
* UPDATE_JUST_CURSOR - do bounds checking and position cursor where is should
* be.
*
* UPDATE_FROM_CURSOR - does all of the above, and makes sure everything from
* the cursor to the right edge of the screen is current (by redrawing it).
*
* UPDATE_ALL - redraws the entire line
*/
extern void BX_update_input (int update)
{
int old_zone;
char *ptr, *ptr_free;
int len,
free_it = 0,
echo = 1,
max;
char *prompt;
Screen *os = last_input_screen;
Screen *ns;
Window *saved_current_window = current_window;
#ifdef WANT_HEBREW
void BX_set_input_heb (char *str);
char prehebbuff[2000];
#endif
if (dumb_mode || !foreground)
return;
for (ns = screen_list; ns; ns = ns->next)
{
last_input_screen = ns;
current_window = ns->current_window;
#ifdef WANT_HEBREW
/*
* crisk: hebrew thingy
*/
if (get_int_var(HEBREW_TOGGLE_VAR))
{
update = UPDATE_ALL;
strcpy(prehebbuff, get_input());
hebrew_process(get_input());
}
#endif
cursor_to_input();
if (last_input_screen && last_input_screen->promptlist)
prompt = last_input_screen->promptlist->prompt;
else
prompt = input_prompt;
if (prompt)
{
char *loc;
int i;
extern int in_chelp;
loc = alloca(strlen(prompt)+200);
for (i = 0; prompt[i]; i++)
{
if (prompt[i] == '$')
loc[i++] = '$';
loc[i] = prompt[i];
}
loc[i] = 0;
in_chelp++;
prompt = convert_output_format(loc, NULL, NULL);
in_chelp--;
}
if (prompt && update != NO_UPDATE)
{
int args_used;
if (is_valid_process(get_target_by_refnum(0)) != -1)
ptr = (char *)get_prompt_by_refnum(0);
else
{
ptr = expand_alias(prompt, empty_string, &args_used, NULL);
free_it = 1;
}
if (last_input_screen->promptlist)
term_echo(last_input_screen->promptlist->echo);
ptr_free = ptr;
ptr = (char *)strip_ansi(ptr);
strcat(ptr, ALL_OFF_STR); /* Yes, we can do this */
if (free_it)
new_free(&ptr_free);
free_it = 1;
if ((ptr && !INPUT_LINE) || (!ptr && INPUT_LINE) ||
strcmp(ptr, last_input_screen->input_buffer))
{
if (last_input_screen->input_prompt_malloc)
new_free(&INPUT_PROMPT);
last_input_screen->input_prompt_malloc = free_it;
INPUT_PROMPT = ptr;
len = strlen(INPUT_PROMPT);
INPUT_PROMPT_LEN = output_with_count(INPUT_PROMPT, 0, 0);
update = UPDATE_ALL;
}
else
{
if (free_it)
new_free(&ptr);
}
}
/*
*
* HAS THE SCREEN CHANGED SIZE SINCE THE LAST TIME?
*
*/
/*
* If the screen has resized, then we need to re-compute the
* side-to-side scrolling effect.
*/
if ((last_input_screen->li != last_input_screen->old_li) ||
(last_input_screen->co != last_input_screen->old_co))
{
/*
* The input line is always the bottom line
*/
INPUT_LINE = last_input_screen->li - 1;
/*
* The "zone" is the range in which when you type, the
* input line does not scroll. Its WIDTH chars in from
* either side.
*/
ZONE = last_input_screen->co - (WIDTH * 2);
if (ZONE < 10)
ZONE = 10; /* Take that! */
START_ZONE = WIDTH;
END_ZONE = last_input_screen->co - WIDTH;
last_input_screen->old_co = last_input_screen->co;
last_input_screen->old_li = last_input_screen->li;
}
/*
* About zones:
* The input line is divided into "zones". A "zone" is set above,
* and is the width of the screen minus 20 (by default). The input
* line, as displayed, is therefore composed of the current "zone",
* plus 10 characters from the previous zone, plus 10 characters
* from the next zone. When the cursor moves to an adjacent zone,
* (by going into column 9 from the right or left of the edge), the
* input line is redrawn. There is one catch. The first "zone"
* includes the first ten characters of the input line.
*/
old_zone = START_ZONE;
/*
* The BEGINNING of the current "zone" is a calculated value:
* The number of characters since the origin of the input buffer
* is the number of printable chars in the input prompt plus the
* current position in the input buffer. We subtract from that
* the WIDTH delta to take off the first delta, which doesnt
* count towards the width of the zone. Then we divide that by
* the size of the zone, to get an integer, then we multiply it
* back. This gives us the first character on the screen. We
* add WIDTH to the result in order to get the start of the zone
* itself.
* The END of the current "zone" is just the beginning plus the width.
* If we have moved to an adjacent "zone" since last time, we want to
* completely redraw the input line.
*/
START_ZONE = ((INPUT_PROMPT_LEN + THIS_POS - WIDTH) / ZONE) * ZONE + WIDTH;
END_ZONE = START_ZONE + ZONE;
if (old_zone != START_ZONE)
update = UPDATE_ALL;
/*
* Now that we know where the "zone" is in the input buffer, we can
* easily calculate where where we want to start displaying stuff
* from the INPUT_BUFFER. If we're in the first "zone", then we will
* output from the beginning of the buffer. If we're not in the first
* "zone", then we will begin to output from 10 characters to the
* left of the zone, after adjusting for the length of the prompt.
*/
if (START_ZONE == WIDTH)
INPUT_ONSCREEN = 0;
else
INPUT_ONSCREEN = START_ZONE - WIDTH - INPUT_PROMPT_LEN;
/*
* And the cursor is simply how many characters away THIS_POS is
* from the first column on the screen.
*/
if (INPUT_ONSCREEN == 0)
INPUT_CURSOR = INPUT_PROMPT_LEN + THIS_POS;
else
INPUT_CURSOR = THIS_POS - INPUT_ONSCREEN;
/*
* If the cursor moved, or if we're supposed to do a full update,
* then redrwa the entire input line.
*/
if (update == UPDATE_ALL)
{
term_move_cursor(0, INPUT_LINE);
/*
* If the input line is NOT empty, and we're starting the
* display at the beginning of the input buffer, then we
* output the prompt first.
*/
if (INPUT_ONSCREEN == 0 && INPUT_PROMPT && *INPUT_PROMPT)
{
/*
* Forcibly turn on echo.
*/
int echo = term_echo(1);
/*
* Crop back the input prompt so it does not extend
* past the end of the zone.
*/
if (INPUT_PROMPT_LEN > (last_input_screen->co - WIDTH))
INPUT_PROMPT_LEN = last_input_screen->co - WIDTH - 1;
/*
* Output the prompt.
*/
output_with_count(INPUT_PROMPT, 0, 1);
/*
* Turn the echo back to what it was before,
* and output the rest of the input buffer.
*/
term_echo(echo);
safe_puts(INPUT_BUFFER, last_input_screen->co - INPUT_PROMPT_LEN, echo);
}
/*
* Otherwise we just output whatever we have.
*/
else if (echo)
safe_puts(&(INPUT_VISIBLE), last_input_screen->co, echo);
/*
* Clear the rest of the input line and reset the cursor
* to the current input position.
*/
term_clear_to_eol();
}
else if (update == UPDATE_FROM_CURSOR)
{
/*
* Move the cursor to where its supposed to be,
* Figure out how much we can output from here,
* and then output it.
*/
#ifdef __EMXPM__
int echo = term_echo(1);
#endif
term_move_cursor(INPUT_CURSOR, INPUT_LINE);
max = last_input_screen->co - (THIS_POS - INPUT_ONSCREEN);
if (INPUT_ONSCREEN == 0 && INPUT_PROMPT && *INPUT_PROMPT)
max -= INPUT_PROMPT_LEN;
if ((len = strlen(&(THIS_CHAR))) > max)
len = max;
safe_puts(&(THIS_CHAR), len, echo);
term_clear_to_eol();
}
term_move_cursor(INPUT_CURSOR, INPUT_LINE);
term_echo(1);
term_flush();
#ifdef WANT_HEBREW
/*
* crisk: hebrew thingy
*/
if (get_int_var(HEBREW_TOGGLE_VAR))
BX_set_input_heb(prehebbuff);
#endif
}
last_input_screen = os;
current_window = saved_current_window;
}
void change_input_prompt (int direction)
{
if (!last_input_screen->promptlist)
{
strcpy(INPUT_BUFFER, last_input_screen->saved_input_buffer);
THIS_POS = last_input_screen->saved_buffer_pos;
MIN_POS = last_input_screen->saved_min_buffer_pos;
*last_input_screen->saved_input_buffer = '\0';
last_input_screen->saved_buffer_pos = 0;
last_input_screen->saved_min_buffer_pos = 0;
update_input(UPDATE_ALL);
}
else if (direction == -1)
update_input(UPDATE_ALL);
else if (!last_input_screen->promptlist->next)
{
strcpy(last_input_screen->saved_input_buffer, INPUT_BUFFER);
last_input_screen->saved_buffer_pos = THIS_POS;
last_input_screen->saved_min_buffer_pos = MIN_POS;
*INPUT_BUFFER = '\0';
THIS_POS = MIN_POS = 0;
update_input(UPDATE_ALL);
}
}
/* input_move_cursor: moves the cursor left or right... got it? */
extern void input_move_cursor (int dir)
{
cursor_to_input();
if (dir)
{
if (THIS_CHAR)
{
THIS_POS++;
term_cursor_right();
}
}
else
{
if (THIS_POS > MIN_POS)
{
THIS_POS--;
term_cursor_left();
}
}
update_input(NO_UPDATE);
}
/*
* set_input: sets the input buffer to the given string, discarding whatever
* was in the input buffer before
*/
void BX_set_input (char *str)
{
strmcpy(INPUT_BUFFER + MIN_POS, str, INPUT_BUFFER_SIZE - MIN_POS);
THIS_POS = strlen(INPUT_BUFFER);
}
#ifdef WANT_HEBREW
/*
* eilon: same as the above just without the cursor reposition.
* this allows input buffer "traveling" in Hebrew mode
*/
void BX_set_input_heb (char *str)
{
strmcpy(INPUT_BUFFER + MIN_POS, str, INPUT_BUFFER_SIZE - MIN_POS);
}
#endif
/*
* get_input: returns a pointer to the input buffer. Changing this will
* actually change the input buffer. This is a bad way to change the input
* buffer tho, cause no bounds checking won't be done
*/
char *BX_get_input (void)
{
return (&(MIN_CHAR));
}
/* init_input: initialized the input buffer by clearing it out */
extern void init_input (void)
{
*INPUT_BUFFER = (char) 0;
THIS_POS = MIN_POS;
}
/* get_input_prompt: returns the current input_prompt */
extern char *BX_get_input_prompt (void)
{
return input_prompt;
}
/*
* set_input_prompt: sets a prompt that will be displayed in the input
* buffer. This prompt cannot be backspaced over, etc. It's a prompt.
* Setting the prompt to null uses no prompt
*/
void BX_set_input_prompt (Window *win, char *prompt, int unused)
{
if (prompt)
malloc_strcpy(&input_prompt, prompt);
else if (input_prompt)
malloc_strcpy(&input_prompt, empty_string);
else
return;
update_input(UPDATE_ALL);
}
/*
* Why did i put these in this file? I dunno. But i do know that the ones
* in edit.c didnt have to be here, and i knew the ones that were here DID
* have to be here, so i just moved them all to here, so that they would all
* be in the same place. Easy enough. (jfn, june 1995)
*/
/*
* input_forward_word: move the input cursor forward one word in the input
* line
*/
BUILT_IN_KEYBINDING(input_forward_word)
{
cursor_to_input();
while ((my_isspace(THIS_CHAR) || ispunct((unsigned char)THIS_CHAR)) && (THIS_CHAR))
THIS_POS++;
while (!(ispunct((unsigned char)THIS_CHAR) || my_isspace(THIS_CHAR)) && (THIS_CHAR))
THIS_POS++;
update_input(UPDATE_JUST_CURSOR);
}
/* input_backward_word: move the cursor left on word in the input line */
BUILT_IN_KEYBINDING(input_backward_word)
{
cursor_to_input();
while ((THIS_POS > MIN_POS) && (my_isspace(PREV_CHAR) || ispunct((unsigned char)PREV_CHAR)))
THIS_POS--;
while ((THIS_POS > MIN_POS) && !(ispunct((unsigned char)PREV_CHAR) || my_isspace(PREV_CHAR)))
THIS_POS--;
update_input(UPDATE_JUST_CURSOR);
}
/* inPut_delete_character: deletes a character from the input line */
BUILT_IN_KEYBINDING(input_delete_character)
{
int pos;
cursor_to_input();
in_completion = STATE_NORMAL;
if (!THIS_CHAR)
return;
ov_strcpy(&THIS_CHAR, &NEXT_CHAR);
if (!(termfeatures & TERM_CAN_DELETE))
update_input(UPDATE_FROM_CURSOR);
else
{
term_delete(1);
pos = INPUT_ONSCREEN + last_input_screen->co - 1;
if (pos < strlen(INPUT_BUFFER))
{
term_move_cursor(last_input_screen->co - 1, INPUT_LINE);
term_putchar(INPUT_BUFFER[pos]);
term_move_cursor(INPUT_CURSOR, INPUT_LINE);
}
update_input(NO_UPDATE);
}
}
/* input_backspace: does a backspace in the input buffer */
BUILT_IN_KEYBINDING(input_backspace)
{
cursor_to_input();
if (THIS_POS > MIN_POS)
{
char *ptr = NULL;
int pos;
ptr = LOCAL_COPY(&THIS_CHAR);
strcpy(&(PREV_CHAR), ptr);
THIS_POS--;
term_cursor_left();
if (THIS_CHAR)
{
if (!(termfeatures & TERM_CAN_DELETE))
update_input(UPDATE_FROM_CURSOR);
else
{
term_delete(1);
pos = INPUT_ONSCREEN + last_input_screen->co - 1;
/*
* If the prompt is visible right now,
* then we have to cope with that.
*/
if (START_ZONE == WIDTH)
pos -= INPUT_PROMPT_LEN;
if (pos < strlen(INPUT_BUFFER))
{
term_move_cursor(last_input_screen->co - 1, INPUT_LINE);
term_putchar(INPUT_BUFFER[pos]);
}
update_input(UPDATE_JUST_CURSOR);
}
}
else
{
term_putchar(' ');
#ifndef __EMX__
term_cursor_left();
update_input(NO_UPDATE);
#else
update_input(UPDATE_FROM_CURSOR);
#endif
}
}
if (THIS_POS == MIN_POS)
HOLDLAST = NULL;
in_completion = STATE_NORMAL;
*new_nick = 0;
}
/*
* input_beginning_of_line: moves the input cursor to the first character in
* the input buffer
*/
BUILT_IN_KEYBINDING(input_beginning_of_line)
{
cursor_to_input();
THIS_POS = MIN_POS;
update_input(UPDATE_JUST_CURSOR);
}
/*
* input_beginning_of_line: moves the input cursor to the first character in
* the input buffer
*/
BUILT_IN_KEYBINDING(new_input_beginning_of_line)
{
cursor_to_input();
THIS_POS = MIN_POS;
update_input(UPDATE_JUST_CURSOR);
extended_handled = 1;
}
/*
* input_end_of_line: moves the input cursor to the last character in the
* input buffer
*/
BUILT_IN_KEYBINDING(input_end_of_line)
{
cursor_to_input();
THIS_POS = strlen(INPUT_BUFFER);
update_input(UPDATE_JUST_CURSOR);
}
BUILT_IN_KEYBINDING(input_delete_to_previous_space)
{
int old_pos;
char c;
cursor_to_input();
old_pos = THIS_POS;
c = THIS_CHAR;
while (!my_isspace(THIS_CHAR) && THIS_POS >= MIN_POS)
THIS_POS--;
if (THIS_POS < old_pos)
{
strcpy(&(NEXT_CHAR), &(INPUT_BUFFER[old_pos]));
THIS_POS++;
}
update_input(UPDATE_FROM_CURSOR);
}
/*
* input_delete_previous_word: deletes from the cursor backwards to the next
* space character.
*/
BUILT_IN_KEYBINDING(input_delete_previous_word)
{
int old_pos;
char c;
cursor_to_input();
old_pos = THIS_POS;
while ((THIS_POS > MIN_POS) && (my_isspace(PREV_CHAR) || ispunct((unsigned char)PREV_CHAR)))
THIS_POS--;
while ((THIS_POS > MIN_POS) && !(ispunct((unsigned char)PREV_CHAR) || my_isspace(PREV_CHAR)))
THIS_POS--;
c = INPUT_BUFFER[old_pos];
INPUT_BUFFER[old_pos] = (char) 0;
malloc_strcpy(&cut_buffer, &THIS_CHAR);
INPUT_BUFFER[old_pos] = c;
strcpy(&(THIS_CHAR), &(INPUT_BUFFER[old_pos]));
update_input(UPDATE_FROM_CURSOR);
}
/*
* input_delete_next_word: deletes from the cursor to the end of the next
* word
*/
BUILT_IN_KEYBINDING(input_delete_next_word)
{
int pos;
char *ptr = NULL,
c;
cursor_to_input();
pos = THIS_POS;
while ((my_isspace(INPUT_BUFFER[pos]) || ispunct((unsigned char)INPUT_BUFFER[pos])) && INPUT_BUFFER[pos])
pos++;
while (!(ispunct((unsigned char)INPUT_BUFFER[pos]) || my_isspace(INPUT_BUFFER[pos])) && INPUT_BUFFER[pos])
pos++;
c = INPUT_BUFFER[pos];
INPUT_BUFFER[pos] = (char) 0;
malloc_strcpy(&cut_buffer, &(THIS_CHAR));
INPUT_BUFFER[pos] = c;
malloc_strcpy(&ptr, &(INPUT_BUFFER[pos]));
strcpy(&(THIS_CHAR), ptr);
new_free(&ptr);
update_input(UPDATE_FROM_CURSOR);
}
/*
* input_add_character: adds the character c to the input buffer, repecting
* the current overwrite/insert mode status, etc
*/
BUILT_IN_KEYBINDING(input_add_character)
{
int display_flag = NO_UPDATE;
if (last_input_screen->promptlist)
term_echo(last_input_screen->promptlist->echo);
cursor_to_input();
if (THIS_POS >= INPUT_BUFFER_SIZE)
{
term_echo(1);
return;
}
if (get_int_var(INSERT_MODE_VAR))
{
if (THIS_CHAR)
{
char *ptr = NULL;
ptr = alloca(strlen(&(THIS_CHAR)) + 1);
strcpy(ptr, &(THIS_CHAR));
THIS_CHAR = key;
NEXT_CHAR = 0;
ADD_TO_INPUT(ptr);
if (termfeatures & TERM_CAN_INSERT)
term_insert(key);
else
{
term_putchar(key);
if (NEXT_CHAR)
display_flag = UPDATE_FROM_CURSOR;
else
display_flag = NO_UPDATE;
}
}
else
{
THIS_CHAR = key;
NEXT_CHAR = 0;
term_putchar(key);
}
}
else
{
if (THIS_CHAR == 0)
NEXT_CHAR = 0;
THIS_CHAR = key;
term_putchar(key);
}
if (!THIS_POS)
HOLDLAST = current_window->display_ip;
THIS_POS++;
#ifdef GUI
gui_flush();
#endif
update_input(display_flag);
if (in_completion == STATE_COMPLETE && key == ' ' && input_lastmsg)
{
new_free(&input_lastmsg);
*new_nick = 0;
in_completion = STATE_NORMAL;
}
term_echo(1);
}
/* input_clear_to_eol: erases from the cursor to the end of the input buffer */
BUILT_IN_KEYBINDING(input_clear_to_eol)
{
cursor_to_input();
malloc_strcpy(&cut_buffer, &(THIS_CHAR));
THIS_CHAR = 0;
term_clear_to_eol();
update_input(NO_UPDATE);
}
/*
* input_clear_to_bol: clears from the cursor to the beginning of the input
* buffer
*/
BUILT_IN_KEYBINDING(input_clear_to_bol)
{
char *ptr = NULL;
cursor_to_input();
malloc_strcpy(&cut_buffer, &(MIN_CHAR));
cut_buffer[THIS_POS - MIN_POS] = (char) 0;
malloc_strcpy(&ptr, &(THIS_CHAR));
MIN_CHAR = (char) 0;
ADD_TO_INPUT(ptr);
new_free(&ptr);
THIS_POS = MIN_POS;
term_move_cursor(INPUT_PROMPT_LEN, INPUT_LINE);
term_clear_to_eol();
update_input(UPDATE_FROM_CURSOR);
}
/*
* input_clear_line: clears entire input line
*/
BUILT_IN_KEYBINDING(input_clear_line)
{
cursor_to_input();
malloc_strcpy(&cut_buffer, INPUT_BUFFER + MIN_POS);
MIN_CHAR = (char) 0;
THIS_POS = MIN_POS;
term_move_cursor(INPUT_PROMPT_LEN, INPUT_LINE);
term_clear_to_eol();
update_input(NO_UPDATE);
}
/*
* input_transpose_characters: swaps the positions of the two characters
* before the cursor position
*/
BUILT_IN_KEYBINDING(input_transpose_characters)
{
cursor_to_input();
if (last_input_screen->buffer_pos > MIN_POS)
{
u_char c1[3] = { 0 };
int pos, end_of_line = 0;
if (THIS_CHAR)
pos = THIS_POS;
else if (strlen(get_input()) > MIN_POS + 2)
{
pos = THIS_POS - 1;
end_of_line = 1;
}
else
return;
c1[0] = INPUT_BUFFER[pos];
c1[1] = INPUT_BUFFER[pos] = INPUT_BUFFER[pos - 1];
INPUT_BUFFER[pos - 1] = c1[0];
term_cursor_left();
if (end_of_line)
term_cursor_left();
term_putchar(c1[0]);
term_putchar(c1[1]);
if (!end_of_line)
term_cursor_left();
update_input(NO_UPDATE);
}
}
BUILT_IN_KEYBINDING(refresh_inputline)
{
update_input(UPDATE_ALL);
}
/*
* input_yank_cut_buffer: takes the contents of the cut buffer and inserts it
* into the input line
*/
BUILT_IN_KEYBINDING(input_yank_cut_buffer)
{
char *ptr = NULL;
if (cut_buffer)
{
malloc_strcpy(&ptr, &(THIS_CHAR));
/* Ooops... */
THIS_CHAR = 0;
ADD_TO_INPUT(cut_buffer);
ADD_TO_INPUT(ptr);
new_free(&ptr);
update_input(UPDATE_FROM_CURSOR);
THIS_POS += strlen(cut_buffer);
if (THIS_POS > INPUT_BUFFER_SIZE)
THIS_POS = INPUT_BUFFER_SIZE;
update_input(UPDATE_JUST_CURSOR);
}
}
/* used with input_move_cursor */
#define RIGHT 1
#define LEFT 0
/* BIND functions: */
BUILT_IN_KEYBINDING(forward_character)
{
input_move_cursor(RIGHT);
}
BUILT_IN_KEYBINDING(backward_character)
{
input_move_cursor(LEFT);
}
BUILT_IN_KEYBINDING(backward_history)
{
get_history(PREV);
}
BUILT_IN_KEYBINDING(forward_history)
{
get_history(NEXT);
}
BUILT_IN_KEYBINDING(toggle_insert_mode)
{
int tog = get_int_var(INSERT_MODE_VAR);
tog ^= 1;
set_int_var(INSERT_MODE_VAR, tog);
}
BUILT_IN_KEYBINDING(input_msgreply)
{
char *cmdchar;
char *line, *cmd, *t;
char *snick;
NickTab *nick = NULL;
int got_space = 0;
if (!(cmdchar = get_string_var(CMDCHARS_VAR)))
cmdchar = DEFAULT_CMDCHARS;
t = line = m_strdup(get_input());
if (t)
got_space = strchr(t, ' ') ? 1 : 0;
cmd = next_arg(line, &line);
snick = next_arg(line, &line);
if ((cmd && *cmd == *cmdchar && got_space) || !cmd)
{
if (cmd && *cmd == *cmdchar)
cmd++;
if (in_completion == STATE_NORMAL && snick)
strncpy(new_nick, snick, sizeof(new_nick)-1);
if ((nick = getnextnick(0, new_nick, input_lastmsg, snick)))
{
if (nick->nick && *(nick->nick))
{
snick = nick->nick;
malloc_strcpy(&input_lastmsg, nick->nick);
}
}
if (nick)
{
char *tmp = NULL;
input_clear_line('\0', NULL);
if (fget_string_var(FORMAT_NICK_MSG_FSET))
malloc_strcpy(&tmp, stripansicodes(convert_output_format(fget_string_var(FORMAT_NICK_MSG_FSET), "%s%s %s %s", cmdchar, nick->type ? nick->type:cmd?cmd:"msg", nick->nick, line?line:empty_string)));
else
malloc_sprintf(&tmp, "%s%s %s %s", cmdchar, nick->type?nick->type:cmd?cmd:"msg", nick->nick, line?line:empty_string);
set_input(tmp);
new_free(&tmp);
} else
command_completion(0, NULL);
}
else
command_completion(0, NULL);
update_input(UPDATE_ALL);
new_free(&t);
}
BUILT_IN_KEYBINDING(input_msgreplyback)
{
#if 0
char *tmp = NULL;
char *cmdchar;
tmp = gettabkey(-1, 0, NULL);
if (tmp && *tmp)
{
char *tmp1 = NULL;
input_clear_line('\0', NULL);
if (!(cmdchar = get_string_var(CMDCHARS_VAR)))
cmdchar = DEFAULT_CMDCHARS;
if (fget_string_var(FORMAT_NICK_MSG_FSET))
malloc_strcpy(&tmp1, stripansicodes(convert_output_format(fget_string_var(FORMAT_NICK_MSG_FSET), "%cmsg %s", *cmdchar, tmp)));
else
malloc_sprintf(&tmp1, "%cmsg %s ", *cmdchar, tmp);
set_input(tmp1);
new_free(&tmp1);
}
#endif
}
void add_autonick_input(char *nick, char *line)
{
char *tmp1 = NULL;
input_clear_line('\0', NULL);
if ((do_hook(REPLY_AR_LIST, "%s", nick)))
{
if (fget_string_var(FORMAT_NICK_AUTO_FSET))
malloc_strcpy(&tmp1, stripansicodes(convert_output_format(fget_string_var(FORMAT_NICK_AUTO_FSET), "%s %s", nick, line?line:empty_string)));
else
malloc_sprintf(&tmp1, "%s\002:\002 %s" , nick, line);
set_input(tmp1);
new_free(&tmp1);
}
update_input(UPDATE_ALL);
}
BUILT_IN_KEYBINDING(input_autoreply)
{
char *tmp = NULL, *q;
char *nick = NULL;
char *line = NULL;
q = line = m_strdup(&last_input_screen->input_buffer[MIN_POS]);
if ((nick = next_arg(line, &line)))
{
if ((tmp = strrchr(nick, ':')))
*tmp = 0;
if ((tmp = strrchr(nick, '\002')))
*tmp = 0;
}
if (!input_lastmsg)
{
NickTab *t;
t = gettabkey(1, 1, nick);
if (*new_nick && !tmp)
t = gettabkey(1,1,new_nick);
if (t)
tmp = t->nick;
}
if (tmp && *tmp)
{
add_autonick_input(tmp, line);
strcpy(new_nick, tmp);
}
else
{
tmp = getchannick(input_lastmsg, nick);
if (*new_nick && !tmp)
tmp = getchannick(input_lastmsg, new_nick);
if (tmp)
{
add_autonick_input(tmp, line);
strcpy(new_nick, tmp);
}
}
malloc_strcpy(&input_lastmsg, nick);
in_completion = STATE_COMPLETE;
new_free(&q);
}
BUILT_IN_KEYBINDING(input_autoreplyback)
{
#if 0
char *tmp = NULL;
tmp = gettabkey(-1, 1, NULL);
if (tmp && *tmp)
{
char *tmp1 = NULL;
input_clear_line('\0', NULL);
if ((do_hook(AR_REPLY_LIST, "%s", tmp)))
{
if (fget_int_var(FORMAT_NICK_AUTO_FSET))
malloc_strcpy(&tmp1, stripansicodes(convert_output_format(fget_string_var(FORMAT_NICK_AUTO_FSET), "%s", tmp)));
else
malloc_sprintf(&tmp1, "%s\002:\002", tmp);
set_input(tmp1);
new_free(&tmp1);
}
}
#endif
}
NickList *BX_lookup_nickcompletion(ChannelList *chan, char *possible)
{
NickList *nick, *ntmp = NULL, *bestmatch = NULL;
for (nick = next_nicklist(chan, NULL); nick; nick = next_nicklist(chan, nick))
{
if (!my_stricmp(possible, nick->nick))
bestmatch = ntmp = nick;
else if (!my_strnicmp(possible, nick->nick, strlen(possible)))
ntmp = nick;
else if (!ntmp && my_strnstr(nick->nick, possible, strlen(possible)))
ntmp = nick;
}
return bestmatch ? bestmatch : ntmp;
}
BUILT_IN_KEYBINDING(send_line)
{
int server;
WaitPrompt *OldPrompt;
server = from_server;
from_server = get_window_server(0);
unhold_a_window(last_input_screen->current_window);
if (last_input_screen->promptlist && last_input_screen->promptlist->type == WAIT_PROMPT_LINE)
{
OldPrompt = last_input_screen->promptlist;
(*OldPrompt->func)(OldPrompt->data, get_input());
set_input(empty_string);
last_input_screen->promptlist = OldPrompt->next;
new_free(&OldPrompt->data);
new_free(&OldPrompt->prompt);
new_free((char **)&OldPrompt);
change_input_prompt(-1);
}
else
{
char *line,
*cmdchar,
*tmp = NULL;
line = get_input();
if (!(cmdchar = get_string_var(CMDCHARS_VAR)))
cmdchar = "/";
malloc_strcpy(&tmp, line);
if (line && (*line != *cmdchar) && get_int_var(NICK_COMPLETION_VAR) && !query_nick())
{
char auto_comp_char;
char *p;
if (!(auto_comp_char = (char)get_int_var(NICK_COMPLETION_CHAR_VAR)))
auto_comp_char = ':';
/* possible nick completion */
if ((p = strchr(tmp, auto_comp_char)) && do_hook(NICK_COMP_LIST, "%s", line))
{
ChannelList *chan;
NickList *nick;
char *channel;
*p++ = 0;
if (*tmp && *p && (strlen(tmp) >= get_int_var(NICK_COMPLETION_LEN_VAR) && (channel = get_current_channel_by_refnum(0))))
{
chan = lookup_channel(channel, from_server, 0);
nick = lookup_nickcompletion(chan, tmp);
if (nick)
{
if (fget_string_var(FORMAT_NICK_COMP_FSET))
malloc_strcpy(&tmp, stripansicodes(convert_output_format(fget_string_var(FORMAT_NICK_COMP_FSET), "%s %s", nick->nick, p)));
else
malloc_sprintf(&tmp, "%s\002%c\002%s", nick->nick, auto_comp_char, p);
} else
malloc_strcpy(&tmp, line);
} else
malloc_strcpy(&tmp, line);
}
}
set_input(empty_string);
update_input(UPDATE_ALL);
reset_display_target();
#ifdef WANT_TCL
if (!check_tcl_input(tmp) && do_hook(INPUT_LIST, "%s", tmp))
#else
if (do_hook(INPUT_LIST, "%s", tmp))
#endif
{
if (get_int_var(INPUT_ALIASES_VAR))
parse_line(NULL, tmp, empty_string, 1, 0, 1);
else
parse_line(NULL, tmp, NULL, 1, 0, 1);
}
new_free(&tmp);
}
new_free(&input_lastmsg);
*new_nick = 0;
in_completion = STATE_NORMAL;
HOLDLAST = NULL;
from_server = server;
}
#define METAX(x) \
BUILT_IN_KEYBINDING( meta ## x ## _char ) \
{ last_input_screen->meta_hit = (x); }
METAX(39) METAX(38) METAX(37) METAX(36) METAX(35)
METAX(34) METAX(33) METAX(32) METAX(31) METAX(30)
METAX(29) METAX(28) METAX(27) METAX(26) METAX(25)
METAX(24) METAX(23) METAX(22) METAX(21) METAX(20)
METAX(19) METAX(18) METAX(17) METAX(16) METAX(15)
METAX(14) METAX(13) METAX(12) METAX(11) METAX(10)
METAX(9) METAX(8) METAX(7) METAX(6) METAX(5)
METAX(3) METAX(2) METAX(1)
BUILT_IN_KEYBINDING(meta4_char)
{
if (last_input_screen->meta_hit == 4)
last_input_screen->meta_hit = 0;
else
last_input_screen->meta_hit = 4;
}
BUILT_IN_KEYBINDING(quote_char)
{
last_input_screen->quote_hit = 1;
}
/* These four functions are boomerang functions, which allow the highlight
* characters to be bound by simply having these functions put in the
* appropriate characters when you press any key to which you have bound
* that highlight character. >;-)
*/
BUILT_IN_KEYBINDING(insert_bold)
{
input_add_character (BOLD_TOG, string);
}
BUILT_IN_KEYBINDING(insert_reverse)
{
input_add_character (REV_TOG, string);
}
BUILT_IN_KEYBINDING(insert_underline)
{
input_add_character (UND_TOG, string);
}
BUILT_IN_KEYBINDING(highlight_off)
{
input_add_character (ALL_OFF, string);
}
BUILT_IN_KEYBINDING(insert_blink)
{
input_add_character (BLINK_TOG, string);
}
BUILT_IN_KEYBINDING(insert_altcharset)
{
input_add_character (ALT_TOG, string);
}
/* type_text: the BIND function TYPE_TEXT */
BUILT_IN_KEYBINDING(type_text)
{
if (!string)
return;
for (; *string; string++)
input_add_character(*string, empty_string);
}
/*
* clear_screen: the CLEAR_SCREEN function for BIND. Clears the screen and
* starts it if it is held
*/
BUILT_IN_KEYBINDING(clear_screen)
{
hold_mode(NULL, OFF, 1);
clear_window_by_refnum(0);
}
/* parse_text: the bindable function that executes its string */
BUILT_IN_KEYBINDING(parse_text)
{
parse_line(NULL, string, empty_string, 0, 0, 1);
}
/*
* edit_char: handles each character for an input stream. Not too difficult
* to work out.
*/
void edit_char (u_char key)
{
void (*func) (char, char *) = NULL;
char *ptr = NULL;
u_char extended_key;
WaitPrompt *oldprompt;
int xxx_return = 0;
if (dumb_mode)
{
#ifdef TIOCSTI
ioctl(0, TIOCSTI, &key);
#else
say("Sorry, your system doesnt support 'faking' user input...");
#endif
return;
}
/* were we waiting for a keypress? */
if (last_input_screen->promptlist && last_input_screen->promptlist->type == WAIT_PROMPT_KEY)
{
unsigned char key_[2] = "\0";
key_[0] = key;
oldprompt = last_input_screen->promptlist;
last_input_screen->promptlist = oldprompt->next;
(*oldprompt->func)(oldprompt->data, key_);
new_free(&oldprompt->data);
new_free(&oldprompt->prompt);
new_free((char **)&oldprompt);
set_input(empty_string);
change_input_prompt(-1);
xxx_return = 1;
}
if (last_input_screen->promptlist &&
last_input_screen->promptlist->type == WAIT_PROMPT_DUMMY)
{
oldprompt = last_input_screen->promptlist;
(*oldprompt->func)(oldprompt->data, NULL);
last_input_screen->promptlist = oldprompt->next;
new_free(&oldprompt->data);
new_free(&oldprompt->prompt);
new_free((char **)&oldprompt);
}
if (xxx_return)
return;
#if __bsdi__
if (key & 0x80)
{
if (meta_mode)
{
edit_char('\033');
key &= ~0x80;
}
else if (!term_eight_bit())
key &= ~0x80;
}
#endif
#ifdef TRANSLATE
if (translation)
extended_key = transFromClient[key];
else
#endif
extended_key = key;
#ifdef __EMX__
if (key == 0)
key = 27;
#endif
/* did we just hit the quote character? */
if (last_input_screen->quote_hit)
{
last_input_screen->quote_hit = 0;
input_add_character(extended_key, empty_string);
}
else
{
int m = last_input_screen->meta_hit;
int i;
if ((i = get_binding(m, key, &func, &ptr)))
last_input_screen->meta_hit = i;
else if (last_input_screen->meta_hit != 4)
last_input_screen->meta_hit = 0;
if (func)
func(extended_key, SAFE(ptr));
}
}
#ifdef GUI
BUILT_IN_KEYBINDING(paste_to_input)
{
/* Try calling this directly ... */
parse_line(NULL, "//pmpaste -input", NULL, 0, 0, 1);
}
#endif
BUILT_IN_KEYBINDING(my_scrollback)
{
scrollback_backwards(key, string);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(my_scrollforward)
{
scrollback_forwards(key, string);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(my_scrollend)
{
scrollback_end(key, string);
extended_handled = 1;
}
#ifdef WANT_CHELP
BUILT_IN_KEYBINDING(do_chelp)
{
chelp(NULL, "INDEX", NULL, NULL);
extended_handled = 1;
}
#endif
#ifdef WANT_CDCC
BUILT_IN_KEYBINDING(cdcc_plist)
{
l_plist(NULL, NULL);
extended_handled = 1;
}
#endif
BUILT_IN_KEYBINDING(dcc_plist)
{
dcc_glist(NULL, NULL);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(toggle_cloak)
{
if (get_int_var(CLOAK_VAR) == 1 || get_int_var(CLOAK_VAR) == 2)
set_int_var(CLOAK_VAR, 0);
else
set_int_var(CLOAK_VAR, 1);
put_it("CTCP Cloaking is now [\002%s\002]", on_off(get_int_var(CLOAK_VAR)));
extended_handled = 1;
}
extern int in_window_command;
static void handle_swap(int windownum)
{
char *p = NULL;
malloc_sprintf(&p, "SWAP %d", windownum);
windowcmd(NULL, p, NULL, NULL);
set_channel_window(current_window, get_current_channel_by_refnum(current_window->refnum), current_window->server);
new_free(&p);
set_input_prompt(current_window, get_string_var(INPUT_PROMPT_VAR), 0);
target_window = NULL;
update_input(UPDATE_ALL);
update_all_windows();
}
BUILT_IN_KEYBINDING(window_swap1)
{
handle_swap(1);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(window_swap2)
{
handle_swap(2);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(window_swap3)
{
handle_swap(3);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(window_swap4)
{
handle_swap(4);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(window_swap5)
{
handle_swap(5);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(window_swap6)
{
handle_swap(6);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(window_swap7)
{
handle_swap(7);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(window_swap8)
{
handle_swap(8);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(window_swap9)
{
handle_swap(9);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(window_swap10)
{
handle_swap(10);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(channel_chops)
{
users("chops", "-ops", NULL, NULL);
extended_handled = 1;
}
BUILT_IN_KEYBINDING(channel_nonops)
{
users("nops", "-nonops", NULL, NULL);
extended_handled = 1;
}
#ifdef WANT_CHELP
BUILT_IN_KEYBINDING(w_help)
{
chelp(NULL, "WINDOW", NULL, NULL);
}
#endif
BUILT_IN_KEYBINDING(change_to_split)
{
extern char *last_split_server;
if (!last_split_server)
return;
servercmd(NULL, last_split_server, NULL, NULL);
}
BUILT_IN_KEYBINDING(join_last_invite)
{
if (invite_channel)
{
if (!in_join_list(invite_channel, from_server))
{
win_create(JOIN_NEW_WINDOW_VAR, 0);
send_to_server("JOIN %s", invite_channel);
new_free(&invite_channel);
}
else
bitchsay("Already joining %s", invite_channel);
}
else
bitchsay("You haven't been invited to a channel yet");
}
BUILT_IN_KEYBINDING(wholeft)
{
show_wholeft(NULL);
}
static int oiwc;
static int osu;
BUILT_IN_KEYBINDING(window_key_balance)
{
oiwc = in_window_command;
osu = status_update_flag;
in_window_command = 1;
set_display_target(NULL, LOG_CURRENT);
rebalance_windows(current_window->screen);
in_window_command = oiwc;
status_update_flag = osu;
update_all_windows();
update_all_status(current_window, NULL, 0);
reset_display_target();
}
BUILT_IN_KEYBINDING(window_grow_one)
{
oiwc = in_window_command;
osu = status_update_flag;
in_window_command = 1;
set_display_target(NULL, LOG_CURRENT);
resize_window(1, current_window, 1);
in_window_command = oiwc;
status_update_flag = osu;
update_all_windows();
update_all_status(current_window, NULL, 0);
reset_display_target();
}
BUILT_IN_KEYBINDING(window_key_hide)
{
oiwc = in_window_command;
osu = status_update_flag;
in_window_command = 1;
set_display_target(NULL, LOG_CURRENT);
hide_window(current_window);
in_window_command = oiwc;
status_update_flag = osu;
update_all_windows();
update_all_status(current_window, NULL, 0);
reset_display_target();
}
BUILT_IN_KEYBINDING(window_key_kill)
{
oiwc = in_window_command;
osu = status_update_flag;
in_window_command = 1;
set_display_target(NULL, LOG_CURRENT);
delete_window(current_window);
in_window_command = oiwc;
status_update_flag = osu;
update_all_windows();
update_all_status(current_window, NULL, 0);
reset_display_target();
}
BUILT_IN_KEYBINDING(window_key_list)
{
oiwc = in_window_command;
osu = status_update_flag;
in_window_command = 1;
set_display_target(NULL, LOG_CURRENT);
window_list(current_window, NULL, NULL);
in_window_command = oiwc;
status_update_flag = osu;
reset_display_target();
}
BUILT_IN_KEYBINDING(window_key_move)
{
oiwc = in_window_command;
osu = status_update_flag;
in_window_command = 1;
set_display_target(NULL, LOG_CURRENT);
move_window(current_window, 1);
in_window_command = oiwc;
status_update_flag = osu;
update_all_windows();
update_all_status(current_window, NULL, 0);
reset_display_target();
}
BUILT_IN_KEYBINDING(window_shrink_one)
{
oiwc = in_window_command;
osu = status_update_flag;
in_window_command = 1;
set_display_target(NULL, LOG_CURRENT);
resize_window(1, current_window, -1);
in_window_command = oiwc;
status_update_flag = osu;
update_all_windows();
update_all_status(current_window, NULL, 0);
reset_display_target();
}
BUILT_IN_KEYBINDING(dcc_ostats)
{
set_display_target(NULL, LOG_CURRENT);
extended_handled = 1;
dcc_stats(NULL, NULL);
reset_display_target();
}
BUILT_IN_KEYBINDING(cpu_saver_on)
{
cpu_saver = 1;
update_all_status(current_window, NULL, 0);
}
BUILT_IN_KEYBINDING(input_unclear_screen)
{
hold_mode(NULL, OFF, 1);
unclear_window_by_refnum(0);
}
BUILT_IN_KEYBINDING(ignore_last_nick)
{
NickTab *nick;
char *tmp1;
if ((nick = gettabkey(1, 0, NULL)))
{
set_input(empty_string);
tmp1 = m_sprintf("%sig %s", get_string_var(CMDCHARS_VAR), nick->nick);
set_input(tmp1);
new_free(&tmp1);
}
update_input(UPDATE_ALL);
}
BUILT_IN_KEYBINDING(nick_completion)
{
char *q, *line;
int i = -1;
char *nick = NULL, *tmp;
q = line = m_strdup(&last_input_screen->input_buffer[MIN_POS]);
if (in_completion == STATE_NORMAL)
{
i = word_count(line);
nick = extract(line, i-1, i);
}
if (nick)
line[strlen(line)-strlen(nick)] = 0;
else
*line = 0;
if ((tmp = getchannick(input_lastmsg, nick && *nick ? nick : NULL)))
{
malloc_strcat(&q, tmp);
set_input(q);
update_input(UPDATE_ALL);
malloc_strcpy(&input_lastmsg, tmp);
in_completion = STATE_COMPLETE;
}
new_free(&q);
new_free(&nick);
}
char *BX_getchannick (char *oldnick, char *nick)
{
ChannelList *chan;
char *channel, *tnick = NULL;
NickList *cnick;
channel = get_current_channel_by_refnum(0);
if (channel)
{
if (!(chan = lookup_channel(channel, from_server, 0)) || !(cnick = next_nicklist(chan, NULL)))
{
in_completion = STATE_NORMAL;
return NULL;
}
/*
* we've never been here before so return first nick
* user hasn't entered anything on the line.
*/
if (!oldnick && !nick && cnick)
{
in_completion = STATE_CNICK;
return cnick->nick;
}
/*
* user has been here before so we attempt to find the correct
* first nick to start from.
*/
if (oldnick)
{
/* find the old nick so we have a frame of reference */
for(cnick = next_nicklist(chan, NULL); cnick; cnick = next_nicklist(chan, cnick))
{
if (!my_strnicmp(cnick->nick, oldnick, strlen(oldnick)))
{
tnick = cnick->nick;
if ((cnick = next_nicklist(chan, cnick)))
tnick = cnick->nick;
break;
}
}
}
/*
* if the user has put something on the line
* we attempt to pattern match here.
*/
if (nick && in_completion == STATE_NORMAL)
{
/*
* if oldnick was the last one in the channel
* cnick will be NULL;
*/
if (!cnick)
{
cnick = next_nicklist(chan, NULL);
tnick = cnick->nick;
}
/* we have a new nick */
else if (next_nicklist(chan, cnick))
{
/*
* if there's more than one nick, start
* scanning.
*/
for (; cnick; cnick = next_nicklist(chan, cnick))
{
#if 1
if (!my_strnicmp(cnick->nick, nick, strlen(nick)) || my_strnstr(cnick->nick, nick, strlen(nick)))
#else
if (!my_strnicmp(cnick->nick, nick, strlen(nick)))
#endif
{
tnick = cnick->nick;
break;
}
}
#if 1
/* Same as before, make sure bx gets its try w/o ours interfering... */
if (!tnick)
{
for (; cnick; cnick = next_nicklist(chan, cnick))
{
if (my_strnstr(cnick->nick, nick, strlen(nick)))
{
tnick = cnick->nick;
break;
}
}
}
#endif
}
else
tnick = cnick->nick;
}
else if (in_completion == STATE_CNICK)
{
/*
* else we've been here before so
* attempt to continue through the nicks
*/
if (!cnick)
cnick = next_nicklist(chan, NULL);
tnick = cnick->nick;
}
}
if (tnick)
in_completion = STATE_CNICK;
return tnick;
}
/*
* set which to 1 to access autoreply array.
* 0 for msglist array
*/
void BX_addtabkey(char *nick, char *type, int which)
{
NickTab *tmp, *new;
tmp = (which == 1) ? autoreply_array : tabkey_array;
if (!tmp || !(new = (NickTab *)remove_from_list((List **)&tmp, nick)))
{
new = (NickTab *)new_malloc(sizeof(NickTab));
malloc_strcpy(&new->nick, nick);
if (type)
malloc_strcpy(&new->type, type);
}
/*
* most recent nick is at the top of the list
*/
new->next = tmp;
tmp = new;
if (which == 1)
autoreply_array = tmp;
else
tabkey_array = tmp;
}
NickTab *BX_gettabkey(int direction, int which, char *nick)
{
NickTab *tmp, *new;
new = tmp = (which == 1) ? autoreply_array : tabkey_array;
if (nick)
{
for (; tmp; tmp = tmp->next)
if (!my_strnicmp(nick, tmp->nick, strlen(nick)))
return tmp;
return NULL;
}
tmp = new;
if (!tmp)
return NULL;
switch(direction)
{
case 1:
default:
{
/*
* need at least two nicks in the list
*/
if (new->next)
{
/*
* reset top of array
*/
if (which == 1)
autoreply_array = new->next;
else
tabkey_array = new->next;
/*
* set the current nick next pointer to NULL
* and then reset top of list.
*/
new->next = NULL;
if (which == 1)
tmp = autoreply_array;
else
tmp = tabkey_array;
/*
* find the last nick in the list
* so we can make the old top pointer
* point to the item
*/
while (tmp)
if (tmp->next)
tmp = tmp->next;
else
break;
/* set the pointer and then return. */
tmp->next = new;
}
break;
}
case -1:
{
if (new && new->next)
{
tmp = new;
while(tmp)
if (tmp->next && tmp->next->next)
tmp = tmp->next;
else
break;
/*
* tmp now points at last two items in list
* now just swap some pointers.
*/
new = tmp->next;
tmp->next = NULL;
if (which == 1)
{
new->next = autoreply_array;
autoreply_array = new;
} else {
new->next = tabkey_array;
tabkey_array = new;
}
}
break;
}
}
if (new && new->nick)
return new;
return NULL;
}
NickTab *BX_getnextnick(int which, char *input_nick, char *oldnick, char *nick)
{
ChannelList *chan;
NickList *cnick = NULL;
NickTab *tmp = (which == 1) ? autoreply_array : tabkey_array;
int server = from_server;
static NickTab sucks = { NULL };
if (tmp && (in_completion == STATE_NORMAL || in_completion == STATE_TABKEY))
{
if (!oldnick && !nick && tmp)
{
in_completion = STATE_TABKEY;
return tmp;
}
if (oldnick)
{
for (; tmp; tmp = tmp->next)
{
if (!my_strnicmp(oldnick, tmp->nick, strlen(oldnick)))
break;
}
/* nick was not in the list. oops didn't come from here */
if (!tmp && in_completion == STATE_TABKEY)
tmp = (which == 1) ? autoreply_array : tabkey_array;
else if (tmp)
tmp = tmp->next;
}
if (nick && in_completion != STATE_TABKEY)
{
if (tmp && tmp->next)
{
for (; tmp; tmp = tmp->next)
if (!my_strnicmp(nick, tmp->nick, strlen(nick)))
break;
}
}
if (tmp)
{
in_completion = STATE_TABKEY;
return tmp;
}
}
if ((chan = prepare_command(&server, NULL, 3)))
{
cnick = next_nicklist(chan, NULL);
/*
* we've never been here before so return first nick
* user hasn't entered anything on the line.
*/
if (!oldnick && !nick && cnick)
{
in_completion = STATE_CNICK;
sucks.nick = cnick->nick;
return &sucks;
}
/*
* user has been here before so we attempt to find the correct
* first nick to start from.
*/
if (oldnick)
{
/* find the old nick so we have a frame of reference */
for (; cnick; cnick = next_nicklist(chan, cnick))
{
if (!my_strnicmp(cnick->nick, oldnick, strlen(oldnick)))
{
cnick = next_nicklist(chan, cnick);
break;
}
}
}
/*
* if the user has put something on the line
* we attempt to pattern match here.
*/
if (input_nick)
{
/*
* if oldnick was the last one in the channel
* cnick will be NULL;
*/
if (!cnick && oldnick)
cnick = next_nicklist(chan, NULL);
/* we have a new nick */
else if (cnick)
{
/*
* if there's more than one nick, start
* scanning.
*/
for (;cnick; cnick = next_nicklist(chan, cnick))
{
if (!my_strnicmp(cnick->nick, input_nick, strlen(input_nick)) || !strcasecmp(cnick->nick, input_nick))
break;
}
}
}
else if (in_completion == STATE_CNICK)
{
/*
* else we've been here before so
* attempt to continue through the nicks
*/
/*
if (!cnick)
cnick = chan->nicks;
*/
}
}
if (!cnick)
in_completion = STATE_NORMAL;
else
in_completion = STATE_CNICK;
if (cnick)
sucks.nick = cnick->nick;
return sucks.nick ? &sucks : NULL;
}
#ifdef WANT_TABKEY
#define TABDEBUG
struct _name_type {
char name[10];
int len;
};
struct _name_type
name_type[] = {
{"MP3", 3},
{"DCC", 3},
{"EXEC",4},
{"LS", 2},
{"LOAD",4},
{"SERVER",6},
{"CDCC",4},
{"MSG", 1},
{"KB", 2},
{"CD", 2},
{ "", 0}};
enum tab_types { MP3 = 0, DCC, EXEC, LS, LOAD, SERVER, CDCC, IMSG, KB, CHDIR};
typedef struct _ext_name_type {
struct _ext_name_type *next;
char *name;
int len;
enum completion type;
} Ext_Name_Type;
Ext_Name_Type *ext_completion = NULL;
char *get_home_dir(char *possible, int *count)
{
#ifdef HAVE_GETPWENT
struct passwd *pw;
char *booya = NULL;
int len = 0;
char *q;
char str[BIG_BUFFER_SIZE+1];
(*count) = 0;
if (possible)
{
possible++;
len = strlen(possible);
}
while ((pw = getpwent()))
{
*str = 0;
if ((q = strrchr(pw->pw_dir, '/')))
q++;
if (possible && *possible && q && strncmp(possible, q, len))
continue;
if (q && *q)
{
strmopencat(str, BIG_BUFFER_SIZE, "~", q, NULL);
m_s3cat(&booya, space, str);
}
else
m_s3cat(&booya, space, pw->pw_dir);
(*count)++;
}
endpwent();
if (*count)
return booya;
#endif
return NULL;
}
char *get_completions(enum completion type, char *possible, int *count, char **suggested)
{
char *booya = NULL;
char *path = NULL;
char *path2, *freeme;
glob_t globbers;
int numglobs = 0, i;
int globtype = GLOB_MARK;
#if defined(__EMX__) || defined(WINNT)
if (possible && *possible)
convert_unix(possible);
#endif
switch(type)
{
case SERVER_COMPLETION:
{
for (i = 0; i < server_list_size(); i++)
{
if (possible && my_strnicmp(possible, get_server_name(i), strlen(possible)))
continue;
m_s3cat(&booya, space, get_server_name(i));
(*count)++;
}
return booya;
}
case TABKEY_COMPLETION:
{
NickTab *n = tabkey_array;
*count = 0;
if (possible)
{
if (*possible == '#' || *possible == '&')
{
ChannelList *chan;
for (chan = get_server_channels(current_window->server); chan; chan = chan->next)
{
if (my_strnicmp(possible, chan->channel, strlen(possible)))
continue;
m_s3cat(&booya, space, chan->channel);
(*count)++;
}
}
else
{
for ( ; n; n = n->next)
{
if (possible && my_strnicmp(possible, n->nick, strlen(possible)))
continue;
m_s3cat(&booya, space, n->nick);
(*count)++;
}
if (*count == 1 && !strcmp(possible, booya))
{
new_free(&booya);
(*count) = 0;
possible = NULL;
}
}
}
if (((*count) == 0) || ((*count) == 1))
{
/*
* nothing specified for a match.
* so grab the first one, if available.
* or, only one match was available.
*/
if (possible && count == 0)
possible = NULL;
if ((n = gettabkey(1, 0, possible)) && !booya)
{
(*count) = 1;
booya = m_strdup(n->nick);
if (suggested)
*suggested = n->type;
}
}
return booya;
}
case COM_COMPLETION:
command_completion(0, NULL);
return NULL;
case CHAN_COMPLETION:
{
NickList *cnick = NULL;
ChannelList *chan = NULL;
int server = from_server;
chan = prepare_command(&server, NULL, 3);
if (possible && (*possible == '#' || *possible == '&'))
{
int len = strlen(possible);
for (chan = get_server_channels(current_window->server); chan; chan = chan->next)
{
if ((len == 1) || (len >= 2 && !my_strnicmp(possible, chan->channel, len)))
{
(*count)++;
m_s3cat(&booya, space, chan->channel);
}
}
}
else if (chan)
{
cnick = next_nicklist(chan, NULL);
for (; cnick; cnick = next_nicklist(chan, cnick))
{
if (possible && my_strnicmp(cnick->nick, possible, strlen(possible)))
continue;
(*count)++;
m_s3cat(&booya, space, cnick->nick);
}
}
if (!booya)
{
for (chan = get_server_channels(current_window->server); chan; chan = chan->next)
{
cnick = next_nicklist(chan, NULL);
for (; cnick; cnick = next_nicklist(chan, cnick))
{
if (possible && my_strnicmp(cnick->nick, possible, strlen(possible)))
continue;
(*count)++;
m_s3cat(&booya, space, cnick->nick);
}
}
}
return booya;
}
case LOAD_COMPLETION:
{
if (!possible)
path = m_sprintf("~/.BitchX/");
else
{
if (*possible == '/' || *possible == '~' || *possible == '.')
path = m_sprintf("%s*", possible);
else
path = m_sprintf("~/%s*", possible);
}
break;
}
case EXEC_COMPLETION:
{
if (!possible)
#if !defined(__EMX__) && !defined(WINNT)
path = m_sprintf("/usr/bin/*");
#elif defined(__EMX__)
path = m_sprintf("C:/OS2/*.EXE");
#elif defined(WINNT) /* Might need something for WinNT itself C:/WINNT/SYSTEM32/ *.EXE */
path = m_sprintf("C:/WINDOWS/COMMAND/*.EXE");
#endif
else
{
if (*possible == '~' && (*(possible+1) != '/'))
{
if ((booya = get_home_dir(possible, count)))
return booya;
}
#if defined(__EMX__) || defined(WINNT)
if (*possible == '/' || *possible == '~' || *possible == '.' || (strlen(possible) > 3 && *(possible+1) == ':' && *(possible+2) == '/'))
path = m_sprintf("%s*.EXE", possible);
else
path = m_sprintf("~/%s*.EXE", possible);
#else
if (*possible == '/' || *possible == '~' || *possible == '.')
path = m_sprintf("%s*", possible);
else
path = m_sprintf("~/%s*", possible);
#endif
}
break;
}
case CDCC_COMPLETION:
case DCC_COMPLETION:
{
char *dl = get_string_var(DCC_DLDIR_VAR);
if (!possible)
path = m_sprintf("%s%s%s", dl, strrchr(dl, '/')?empty_string:"/", "*");
else
{
if (*possible == '~' && (*(possible+1) != '/'))
{
if ((booya = get_home_dir(possible, count)))
return booya;
}
#if defined(__EMX__) || defined(WINNT)
if (*possible == '/' || *possible == '~' || *possible == '.' || (strlen(possible) > 3 && *(possible+1) == ':' && *(possible+2) == '/'))
#else
if (*possible == '/' || *possible == '~' || *possible == '.')
#endif
path = m_sprintf("%s*", possible);
else
path = m_sprintf("~/%s*", possible);
}
break;
}
case FILE_COMPLETION:
{
globtype |= GLOB_TILDE;
if (!possible)
path = m_sprintf("~/*");
else if (*possible == '~' && (*(possible+1) != '/'))
{
if ((booya = get_home_dir(possible, count)))
return booya;
path = m_strdup(possible);
}
else if (*possible == '/' || *possible == '~' || *possible == '.')
path = m_sprintf("%s*", possible);
else
path = m_sprintf("~/%s*", possible);
#if 0
path = m_sprintf("%s%s%s", possible, strrchr(possible, '/') ? empty_string: "/", strchr(possible, '*')?empty_string:"*");
#endif
break;
}
default:
return NULL;
}
#ifdef NEED_GLOB
#define glob bsd_glob
#define globfree bsd_globfree
#endif
freeme = path2 = expand_twiddle(path);
if (!path2)
path2 = path;
memset(&globbers, 0, sizeof(glob_t));
numglobs = glob(path2, globtype, NULL, &globbers);
for (i = 0; i < globbers.gl_pathc; i++)
{
if (strchr(globbers.gl_pathv[i], ' '))
{
int len = strlen(globbers.gl_pathv[i])+4;
char *b = alloca(len+1);
*b = 0;
strmopencat(b, len, "\"", globbers.gl_pathv[i], "\"", NULL);
m_s3cat(&booya, space, b);
}
else
m_s3cat(&booya, space, globbers.gl_pathv[i]);
(*count)++;
}
globfree(&globbers);
new_free(&freeme);
new_free(&path);
return booya;
}
/*
* this is an oddball routine that attempts to figure out where
* the last char is in the completes array, that is equal in all
* the array conditions. when found it sets the input prompt to the
* command [inp] and the greatest amount of chars found common in all
* array elements.
*/
void set_input_best(enum completion type, char *inp, char *old, int count, char **completes)
{
int i,
c,
j = 0,
match = 0;
char buffer[BIG_BUFFER_SIZE+1];
match = strlen(old);
if (count == 2)
{
#if !defined(__EMX__) && !defined(WINNT)
if (type == CHAN_COMPLETION || type == NICK_COMPLETION || type == TABKEY_COMPLETION)
i = strieq(completes[0], completes[1]);
else
#endif
i = streq(completes[0], completes[1]);
completes[0][i] = 0;
}
else
{
int getout;
i = match - 1;
while (1)
{
getout = 0;
c = 1;
for (j = 1; j < count; j++)
{
if (!completes[0][i] || !completes[j][i])
break;
#if defined(__EMX__) || defined(WINNT)
if (toupper(completes[0][i]) == toupper(completes[j][i]))
c++;
#else
if (type == CHAN_COMPLETION || type == NICK_COMPLETION || type == TABKEY_COMPLETION)
{
if (toupper(completes[0][i]) == toupper(completes[j][i]))
c++;
else
{
getout = 1;
break;
}
}
else
{
if (completes[0][i] == completes[j][i])
c++;
else
{
getout = 1;
break;
}
}
#endif
}
if ((c != count) || getout)
break;
i++;
}
if (i)
completes[0][i] = 0;
}
if (old && *old)
{
if (strchr(completes[0], ' '))
sprintf(buffer, "%s%s\"%s\"", inp, space, i ? completes[0] : old);
else
sprintf(buffer, "%s%s%s", inp, space, i ? completes[0] : old);
}
else
strcpy(buffer, completes[0]);
if (strcmp(buffer, get_input()))
set_input(buffer);
if (strchr(completes[0], ' '))
THIS_POS = strlen(INPUT_BUFFER) - 1;
}
BUILT_IN_KEYBINDING(tab_completion)
{
int count = 0,
wcount = 0;
enum completion type = NO_COMPLETION;
char *inp = NULL;
char *possible = NULL, *old_pos = NULL;
char *cmdchar;
char *suggested = NULL;
int got_space = 0;
char *get = NULL;
Ext_Name_Type *extcomp = ext_completion;
/*
* is this the != second word, then just complete from the
* channel nicks. if it is the second word, grab the first word, and
* this is used to determine what type of nick completion will be
* done.
*/
inp = alloca(strlen(get_input())+2);
strcpy(inp, get_input() ? get_input() : empty_string);
if (*inp && inp[strlen(inp)-1] == ' ')
got_space = 1;
wcount = word_count(inp);
if (!(cmdchar = get_string_var(CMDCHARS_VAR)))
cmdchar = "/";
switch(wcount)
{
case 0:
{
type = TABKEY_COMPLETION;
break;
}
case 1:
{
if (*inp != *cmdchar)
{
type = CHAN_COMPLETION;
possible = m_strdup(get_input());
break;
}
else if (!got_space)
{
type = COM_COMPLETION;
break;
}
}
default:
{
char *p, *old_p;
int i, got_comp = 0;
old_p = p = extract(inp, 0, 0);
if (wcount > 1)
old_pos = possible = extract(inp, wcount-1, EOS);
if ((*p == *cmdchar))
p++;
if (possible && (*possible == '"'))
{
possible++;
if (*possible)
chop(possible, 1);
else
possible = NULL;
}
if (type == NO_COMPLETION)
type = CHAN_COMPLETION;
for (i = 0; *p && name_type[i].len; i++)
{
if (!my_strnicmp(p, name_type[i].name, name_type[i].len/*strlen(p)*/))
{
got_comp = 1;
switch(i)
{
case IMSG:
case KB:
type = TABKEY_COMPLETION;
break;
case DCC:
if (wcount <= 3 && !got_space)
type = TABKEY_COMPLETION;
else
type = DCC_COMPLETION;
if (wcount == 3 && got_space)
{
new_free(&old_pos);
possible = NULL;
}
break;
case EXEC:
type = EXEC_COMPLETION;
break;
case CHDIR:
case MP3:
case LS:
type = FILE_COMPLETION;
break;
case LOAD:
type = LOAD_COMPLETION;
break;
case SERVER:
type = SERVER_COMPLETION;
break;
case CDCC:
if (wcount == 2 || wcount == 3)
type = CDCC_COMPLETION;
break;
}
break;
}
}
if (!got_comp)
{
for (extcomp = ext_completion; extcomp; extcomp = extcomp->next)
{
if (!my_strnicmp(p, extcomp->name, extcomp->len))
{
type = extcomp->type;
break;
}
}
}
new_free(&old_p);
break;
}
}
#ifdef TABDEBUG1
put_it("type = %s", type == TABKEY_COMPLETION ? "TABKEY":
type == CHAN_COMPLETION? "CHAN" :
type == COM_COMPLETION? "COMMAND":
type == EXEC_COMPLETION? "EXEC":
type == FILE_COMPLETION? "FILE":
type == DCC_COMPLETION? "DCC":
"NO_COMPLETION");
#endif
do_more_tab:
count = 0;
if ((get = get_completions(type, possible, &count, &suggested)))
{
char buffer[BIG_BUFFER_SIZE+1];
char *p = NULL;
char *old = NULL;
*buffer = 0;
if (count == 1)
{
if (wcount > 1)
p = extract(get_input(), 0, wcount - 2);
else if (suggested && *suggested)
p = m_3dup("/", suggested, "");
if (type == TABKEY_COMPLETION)
snprintf(buffer, BIG_BUFFER_SIZE, "%s %s%s%s ", (p && *p == '/') ? p : "/m", get, (p && (*p != '/'))?space:empty_string, (p && (*p != '/'))?p:empty_string);
else
{
if (wcount == 1 && got_space)
snprintf(buffer, BIG_BUFFER_SIZE, "%s %s ", get_input(), get);
else
snprintf(buffer, BIG_BUFFER_SIZE, "%s%s%s ", p ? p : get, p ? space : empty_string, p ? get : empty_string);
}
if ((type == CDCC_COMPLETION || type == LOAD_COMPLETION || type == FILE_COMPLETION || type == DCC_COMPLETION) || ((type == EXEC_COMPLETION) && (get[strlen(get)-1] == '/')))
chop(buffer, 1);
set_input(buffer);
if (strchr(get, ' '))
THIS_POS = strlen(INPUT_BUFFER) - 1;
new_free(&p);
}
else
{
char **completes = NULL;
int c = 0, matches = count;
completes = RESIZE(completes, char *, count+1);
if (wcount > 1)
{
if (!got_space)
{
old = inp;
old = last_arg(&inp);
if ((*old == '"'))
{
old++;
chop(old, 1);
}
}
}
switch(type)
{
case LOAD_COMPLETION:
case DCC_COMPLETION:
case FILE_COMPLETION:
case CDCC_COMPLETION:
{
char *n, *use = get;
bitchsay("Found %d files/dirs", count);
n = new_next_arg(use, &use);
while (n && *n)
{
put_it("%s", n);
completes[c++] = n;
n = new_next_arg(use, &use);
}
break;
}
case EXEC_COMPLETION:
{
char *n, *q, *use = get;
char path[BIG_BUFFER_SIZE+1];
*path = 0;
memset(path, 0, sizeof(path));
n = new_next_arg(use, &use);
if ((q = strrchr(n, '/')) && *(q+1))
{
strncpy(path, n, q - n + 1);
bitchsay("path = %s", path);
}
count = 0;
while (n && *n)
{
if ((q = strrchr(n, '/')) && *(q+1))
q++;
else
q = n;
strmcat(buffer, q, BIG_BUFFER_SIZE);
strmcat(buffer, space, BIG_BUFFER_SIZE);
if (++count == 4)
{
put_it("%s", convert_output_format(fget_string_var(FORMAT_COMPLETE_FSET),"%s", buffer));
count = 0;
*buffer = 0;
}
completes[c++] = n;
n = new_next_arg(use, &use);
}
if (count)
put_it("%s", convert_output_format(fget_string_var(FORMAT_COMPLETE_FSET),"%s", buffer));
break;
}
case SERVER_COMPLETION:
case TABKEY_COMPLETION:
case CHAN_COMPLETION:
{
char *n, *use = get;
n = new_next_arg(use, &use);
count = 0;
while (n && *n)
{
strmcat(buffer, n, BIG_BUFFER_SIZE);
strmcat(buffer, space, BIG_BUFFER_SIZE);
if (++count == 4)
{
put_it("%s", convert_output_format(fget_string_var(FORMAT_COMPLETE_FSET),"%s", buffer));
count = 0;
*buffer = 0;
}
completes[c++] = n;
n = new_next_arg(use, &use);
}
if (count)
put_it("%s", convert_output_format(fget_string_var(FORMAT_COMPLETE_FSET),"%s", buffer));
break;
}
case NO_COMPLETION:
break;
default:
put_it("get = %s[%d]", get, count);
}
if (old && c)
set_input_best(type, inp, old, matches, completes);
new_free((char **)&completes);
}
update_input(UPDATE_ALL);
}
else if (type == TABKEY_COMPLETION)
{
if (get_current_channel_by_refnum(0))
{
type = CHAN_COMPLETION;
goto do_more_tab;
}
}
new_free(&get);
new_free(&old_pos);
return;
}
int BX_add_completion_type(char *name, int len, enum completion type)
{
Ext_Name_Type *new;
if (!find_in_list((List **)&ext_completion, name, 0))
{
new = (Ext_Name_Type *)new_malloc(sizeof(Ext_Name_Type));
new->name = m_strdup(name);
new->len = len;
new->type = type;
add_to_list((List **)&ext_completion, (List *)new);
return 1;
}
return 0;
}
#endif
/*
* type: The TYPE command. This parses the given string and treats each
* character as though it were typed in by the user. Thus key bindings
* are used for each character parsed. Special case characters are control
* character sequences, specified by a ^ follow by a legal control key.
* Thus doing "/TYPE ^B" will be as tho ^B were hit at the keyboard,
* probably moving the cursor backward one character.
*
* This was moved from keys.c, because it certainly does not belong there,
* and this seemed a reasonable place for it to go for now.
*/
BUILT_IN_COMMAND(type)
{
int c;
char key;
while (*args)
{
if (*args == '^')
{
switch (*(++args))
{
case '?':
{
key = '\177';
args++;
break;
}
default:
{
c = *(args++);
if (islower(c))
c = toupper(c);
if (c < 64)
{
say("Invalid key sequence: ^%c", c);
return;
}
key = c - 64;
break;
}
}
}
else if (*args == '\\')
{
key = *++args;
args++;
}
else
key = *(args++);
edit_char(key);
}
}
|