1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818
|
/* $EPIC: window.c,v 1.97 2005/02/23 04:23:57 jnelson Exp $ */
/*
* window.c: Handles the organzation of the logical viewports (``windows'')
* for irc. This includes keeping track of what windows are open, where they
* are, and what is on them.
*
* Copyright (c) 1990 Michael Sandroff.
* Copyright (c) 1991, 1992 Troy Rollo.
* Copyright (c) 1992-1996 Matthew Green.
* Copyright 1997, 2003 EPIC Software Labs.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notices, the above paragraph (the one permitting redistribution),
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The names of the author(s) may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* Sigh */
#define __need_putchar_x__
#include "irc.h"
#include "screen.h"
#include "window.h"
#include "vars.h"
#include "server.h"
#include "list.h"
#include "term.h"
#include "names.h"
#include "ircaux.h"
#include "input.h"
#include "status.h"
#include "output.h"
#include "log.h"
#include "hook.h"
#include "parse.h"
#include "commands.h"
#include "exec.h"
#include "functions.h"
static const char *onoff[] = { "OFF", "ON" };
/* Resize relatively or absolutely? */
#define RESIZE_REL 1
#define RESIZE_ABS 2
/* used by the update flag to determine what needs updating */
#define REDRAW_DISPLAY 1 << 0
#define UPDATE_STATUS 1 << 1
#define REDRAW_STATUS 1 << 2
/*
* The current window. This replaces the old notion of "curr_scr_win"
* which had the arbitrary restriction that you could not easily operate
* on a window that was not on the current screen, and switching between
* screens (or to a hidden window) was impossible. We no longer have any
* concept of "current screen", opting instead to use "last_input_screen"
* for handling input events, and "current_window" for everything else.
* current_window is set when you do an input event, so all those places
* that presumed curr_scr_win still work by referencing current_window.
*/
Window *current_window = NULL;
/*
* All of the hidden windows. These windows are not on any screen, and
* therefore are not visible.
*/
Window *invisible_list = (Window *) 0;
/*
* This is used to note who the currently processed message was from.
* Since each window has (through /window add) the ability to "grab" all
* of the output from a given nickname, we store the nickname here and then
* refer to it when anything is outputted.
*/
const char *who_from = (char *) 0;
/*
* This is the lastlog level that any output should be sent out at. This
* determines what window output ultimately ends up in.
*/
int who_level = LOG_CRAP;
/*
* This is set to 1 if output is to be dispatched normally. This is set to
* 0 if all output is to be suppressed (such as when the system wants to add
* and alias and doesnt want to blab to the user, or when you use ^ to
* suppress the output of a command.)
*/
unsigned window_display = 1;
/*
* Each time a window is made the current window, it grabs this value and
* increments it. We use this value to track "current window"-ness in
* various contexts.
*/
unsigned current_window_priority = 1;
static void remove_from_invisible_list (Window *);
static void swap_window (Window *, Window *);
static Window *get_next_window (Window *);
static Window *get_previous_window (Window *);
static void revamp_window_levels (Window *);
static void clear_window (Window *);
static void resize_window_display (Window *);
static Window *window_next (Window *, char **);
static Window *window_previous (Window *, char **);
static void set_screens_current_window (Screen *, Window *);
static void remove_window_from_screen (Window *window, int hide);
static Window *window_discon (Window *window, char **args);
static void window_scrollback_start (Window *window);
static void window_scrollback_end (Window *window);
static void window_scrollback_backward (Window *window);
static void window_scrollback_forward (Window *window);
static void window_scrollback_backwards_lines (Window *window, int);
static void window_scrollback_forwards_lines (Window *window, int);
static void window_scrollback_to_string (Window *window, regex_t *str);
static void window_scrollforward_to_string (Window *window, regex_t *str);
int change_line (Window *window, const unsigned char *str);
int add_to_display (Window *window, const unsigned char *str);
static Display *new_display_line (Display *prev, Window *w);
static int count_fixed_windows (Screen *s);
/* * * * * * * * * * * CONSTRUCTOR AND DESTRUCTOR * * * * * * * * * * * */
/*
* new_window: This creates a new window on the screen. It does so by either
* splitting the current window, or if it can't do that, it splits the
* largest window. The new window is added to the window list and made the
* current window
*/
Window *new_window (Screen *screen)
{
Window * new_w;
Window * tmp = NULL;
unsigned new_refnum = 1;
int i;
if (dumb_mode && current_window)
return NULL;
new_w = (Window *) new_malloc(sizeof(Window));
tmp = NULL;
while (traverse_all_windows(&tmp))
{
if (tmp->refnum == new_refnum)
{
new_refnum++;
tmp = NULL;
}
}
new_w->refnum = new_refnum;
new_w->name = NULL;
if (current_window)
new_w->server = current_window->server;
else
new_w->server = NOSERV;
new_w->last_server = NOSERV;
new_w->priority = -1; /* Filled in later */
new_w->top = 0; /* Filled in later */
new_w->bottom = 0; /* Filled in later */
new_w->cursor = -1; /* Force a clear-screen */
new_w->noscrollcursor = -1;
new_w->absolute_size = 0;
new_w->old_size = 1; /* Filled in later */
new_w->update = 0;
new_w->miscflags = 0;
new_w->beep_always = 0;
new_w->change_line = -1;
new_w->scroll = 1;
new_w->skip = 0;
new_w->swappable = 1;
new_w->scrolladj = 1;
new_w->notify_level = real_notify_level();
if (!current_window) /* First window ever */
new_w->window_level = LOG_ALL;
else
new_w->window_level = LOG_NONE;
new_w->prompt = NULL; /* Filled in later */
for (i = 0; i < 3; i++)
{
new_w->status.line[i].raw = NULL;
new_w->status.line[i].format = NULL;
new_w->status.line[i].count = 0;
new_w->status.line[i].result = NULL;
}
new_w->status.double_status = 0;
new_w->status.special = NULL;
rebuild_a_status(new_w);
new_w->top_of_scrollback = NULL; /* Filled in later */
new_w->display_ip = NULL; /* Filled in later */
new_w->display_buffer_size = 0;
new_w->display_buffer_max = get_int_var(SCROLLBACK_VAR);
new_w->display_size = 1; /* Filled in later */
new_w->display_counter = 1;
new_w->scrolling_top_of_display = NULL; /* Filled in later */
new_w->scrolling_distance_from_display_ip = -1; /* Filled in later */
new_w->holding_top_of_display = NULL; /* Filled in later */
new_w->holding_distance_from_display_ip = -1; /* Filled in later */
new_w->scrollback_top_of_display = NULL; /* Filled in later */
new_w->scrollback_distance_from_display_ip = -1; /* Filled in later */
new_w->hold_interval = 10;
new_w->hold_slider = get_int_var(HOLD_SLIDER_VAR);
new_w->waiting_channel = NULL;
new_w->bind_channel = NULL;
new_w->query_nick = NULL;
new_w->nicks = NULL;
new_w->lastlog_oldest = NULL;
new_w->lastlog_newest = NULL;
new_w->lastlog_level = real_lastlog_level();
new_w->lastlog_size = 0;
new_w->lastlog_max = get_int_var(LASTLOG_VAR);
new_w->log = 0;
new_w->logfile = NULL;
new_w->log_fp = NULL;
new_w->screen = screen;
new_w->next = new_w->prev = NULL;
new_w->deceased = 0;
/* Initialize the scrollback */
new_w->top_of_scrollback = new_display_line(NULL, new_w);
new_w->top_of_scrollback->line = NULL;
new_w->top_of_scrollback->next = NULL;
new_w->display_buffer_size = 1;
new_w->display_ip = new_w->top_of_scrollback;
new_w->scrolling_top_of_display = new_w->top_of_scrollback;
new_w->old_size = 1;
if (screen)
{
/*
* Add_to_window_list sets the location and size of the window
*/
if (add_to_window_list(screen, new_w))
set_screens_current_window(screen, new_w);
else
{
new_free((char **)&new_w);
return NULL;
}
}
else
add_to_invisible_list(new_w);
resize_window_display(new_w);
/*
* Offer it to the user. I dont know if this will break stuff
* or not.
*/
do_hook(WINDOW_CREATE_LIST, "%d", new_w->refnum);
return (new_w);
}
/*
* delete_window: There are two important aspects to deleting a window.
* The first aspect is window management. We must release the window
* from its screen (or from the invisible list) so that it is not possible
* for the user to reference the window in any way. We also want to
* re-apportion the window's visible area to other windows on the screen.
* The second aspect is purging the window's private data. Ideally, we
* want these things to take place in this order.
*/
void delete_window (Window *window)
{
char buffer[BIG_BUFFER_SIZE + 1];
int oldref;
int i;
int invisible = 0;
int fixed_wins;
int fixed;
if (!window)
window = current_window;
if (!window->screen)
invisible = 1;
if (window->screen)
fixed_wins = count_fixed_windows(window->screen);
else
fixed_wins = 0;
if (window->absolute_size && window->skip)
fixed = 1;
else
fixed = 0;
/*
* If this is a hidden window and the client is not going down,
* you cannot kill this window if:
*
* 1) This is a fixed window and it is the only window.
* 2) This is the only non-fixed window (unless a swap can occur)
*/
if (dead == 0 && window->screen)
{
if ((fixed && window->screen->visible_windows == 1) ||
(!fixed && window->screen->visible_windows - fixed_wins <= 1
&& !invisible_list))
{
say("You can't kill the last window!");
return;
}
}
/* Let the script have a stab at this first. */
do_hook(WINDOW_BEFOREKILL_LIST, "%d", window->refnum);
/*
* Mark this window as deceased. This is important later.
*/
window->deceased = 1;
/*
* If the client is exiting and this is the last window on the
* screen, we need to do some extra cleanup on the screen that
* otherwise we would not dare to perform. We also want to do some
* extra sanity checking to make sure nothing bad has happened
* elsewhere.
*/
if ((dead == 1) && window->screen &&
(window->screen->visible_windows == 1))
{
if (window->screen->window_list != window ||
window->next != NULL ||
(window->screen->current_window &&
window->screen->current_window != window))
{
panic("My screen says there is only one "
"window on it, and I don't agree.");
}
else
{
window->deceased = 1;
window->screen->window_list = NULL;
window->screen->visible_windows = 0;
window->screen->current_window = NULL;
window->screen = NULL;
if (current_window == window)
current_window = NULL;
}
/*
* This 'goto' saves me from making the next 75 lines part
* of a big (ultimately unnecesary) 'else' clause, requiring
* me to indent it yet again and break up the lines and make
* it less readable. Don't bug me about this.
*/
goto delete_window_contents;
}
/* Move this window's channels anywhere else. */
/*
* Ugh. We've already marked the window as deceased, so it
* officially no longer exists; on top of this, 'swap_window'
* is a sequence point, so channels must be capable of syncing
* up before that. The ref checks will fail if there are any
* channels on this window, because the window is dead, and so
* we need to move the channels away before the sequence point.
* I hope this explanation makes sense. ;-)
*/
reassign_window_channels(window->refnum);
/*
* At this point, we know there must be one of three cases:
* 1) The window is an invisible window
* 2) The window is on a screen with other windows.
* 3) The window is last window on screen, with an invisible window.
*
* We handle each of these three cases seperately. If any other
* situation arises, we panic, because that means I forgot something
* and that *is* a bug.
*/
if (invisible)
remove_from_invisible_list(window);
else if (fixed || window->screen->visible_windows > fixed_wins + 1)
remove_window_from_screen(window, 0);
else if (invisible_list)
{
window->swappable = 1;
swap_window(window, NULL);
}
else
{
yell("I don't know how to kill window [%d]", window->refnum);
return;
}
/*
* This is done for the sake of invisible windows; but it is a safe
* sanity check and can be done for any window, visible or invisible.
* Basically, we have to be sure that we find some way to make sure
* that the 'current_window' pointer is not pointing at what we are
* about to delete (or else the client will crash.)
*/
if (window == current_window)
{
if (window == last_input_screen->current_window)
{
if (window->screen != last_input_screen)
panic("I am not on that screen");
else
make_window_current(last_input_screen->window_list);
}
else
make_window_current(NULL);
}
if (window == current_window)
panic("window == current_window -- this is wrong.");
/*
* OK! Now we have completely unlinked this window from whatever
* window chain it was on before, be it a screen, or be it the
* invisible window list. The screens have been updated, and the
* only place this window exists is in our 'window' pointer. We
* can now safely go about the business of eliminating what it is
* pointing to.
*/
delete_window_contents:
/* Save a copy of the refnum for /on window_kill later. */
if (window->name)
strlcpy(buffer, window->name, sizeof buffer);
else
strlcpy(buffer, ltoa(window->refnum), sizeof buffer);
oldref = window->refnum;
/*
* Clean up after the window's internal data.
*/
/* Status bars... */
for (i = 0; i < 3; i++)
{
new_free(&window->status.line[i].raw);
new_free(&window->status.line[i].format);
new_free(&window->status.line[i].result);
window->status.double_status = 0;
new_free(&window->status.special);
}
/* Various things... */
new_free(&window->query_nick);
new_free(&window->waiting_channel);
new_free(&window->bind_channel);
new_free(&window->logfile);
new_free(&window->name);
/* The logical display */
{
Display *next;
while (window->top_of_scrollback)
{
next = window->top_of_scrollback->next;
new_free(&window->top_of_scrollback->line);
new_free((char **)&window->top_of_scrollback);
window->display_buffer_size--;
window->top_of_scrollback = next;
}
window->display_ip = NULL;
if (window->display_buffer_size != 0)
panic("display_buffer_size is %d, should be 0",
window->display_buffer_size);
}
/* The lastlog... */
while (window->lastlog_size)
remove_from_lastlog(window);
/* The nick list... */
{
WNickList *next;
while (window->nicks)
{
next = window->nicks->next;
new_free(&window->nicks->nick);
new_free((char **)&window->nicks);
window->nicks = next;
}
}
/*
* Nuke the window, check server connections, and re-adjust window
* levels for whoever is left. Don't check the levels if we are
* going down, as its a wasted point.
*/
#if 1
{Window *owd = window; new_free((char **)&owd);}
#else
new_free((char **)&window);
#endif
if (dead == 0)
window_check_servers();
do_hook(WINDOW_KILL_LIST, "%d %s", oldref, buffer);
}
/*
* This should only ever be called by irc_exit(). DONT CALL THIS ELSEWHERE!
*/
void delete_all_windows (void)
{
Window *win;
for (win = NULL; traverse_all_windows(&win); win = NULL)
delete_window(win);
}
/* * * * * * * * * * * ITERATE OVER WINDOWS * * * * * * * * * * * * * * * */
/*
* traverse_all_windows: Based on the old idea by phone that there should
* be a way to iterate the window list without having to keep a static
* data member in the function. So now this is "thread safe".
*
* To initialize, *ptr should be NULL. The function will return 1 each time
* *ptr is set to the next valid window. When the function returns 0, then
* you have iterated all windows.
*/
int traverse_all_windows (Window **ptr)
{
/*
* If this is the first time through...
*/
if (!*ptr)
{
Screen *screen = screen_list;
while (screen && (!screen->alive || !screen->window_list))
screen = screen->next;
if (!screen && !invisible_list)
return 0;
else if (!screen)
*ptr = invisible_list;
else
*ptr = screen->window_list;
}
/*
* As long as there is another window on this screen, keep going.
*/
else if ((*ptr)->next)
*ptr = (*ptr)->next;
/*
* If there are no more windows on this screen, but we do belong to
* a screen (eg, we're not invisible), try the next screen
*/
else if ((*ptr)->screen)
{
/*
* Skip any dead screens
*/
Screen *ns = (*ptr)->screen->next;
while (ns && (!ns->alive || !ns->window_list))
ns = ns->next;
/*
* If there are no other screens, then if there is a list
* of hidden windows, try that. Otherwise we're done.
*/
if (!ns && !invisible_list)
return 0;
else if (!ns)
*ptr = invisible_list;
else
*ptr = ns->window_list;
}
/*
* Otherwise there are no other windows, and we're not on a screen
* (eg, we're hidden), so we're all done here.
*/
else
return 0;
/*
* If we get here, we're in business!
*/
return 1;
}
/* * * * * * * * * * * * * * * * WINDOW LISTS * * * * * * * * * * * * * * * */
/*
* Handle the client's list of invisible windows.
*/
static void remove_from_invisible_list (Window *window)
{
Window *w;
/* Purely a sanity check */
for (w = invisible_list; w && w != window; w = w->next)
;
if (!w)
panic("This window is _not_ invisible");
/*
* Unlink it from the list
*/
if (window->prev)
window->prev->next = window->next;
else
invisible_list = window->next;
if (window->next)
window->next->prev = window->prev;
}
void add_to_invisible_list (Window *window)
{
/*
* Because this blows away window->next, it is implicitly
* assumed that you have already removed the window from
* its screen.
*/
if ((window->next = invisible_list) != NULL)
invisible_list->prev = window;
invisible_list = window;
window->prev = (Window *) 0;
if (window->screen)
window->columns = window->screen->co;
else
window->columns = current_term->TI_cols; /* Whatever */
window->screen = (Screen *) 0;
}
/*
* add_to_window_list: This inserts the given window into the visible window
* list (and thus adds it to the displayed windows on the screen). The
* window is added by splitting the current window. If the current window is
* too small, the next largest window is used. The added window is returned
* as the function value or null is returned if the window couldn't be added
*/
Window *add_to_window_list (Screen *screen, Window *new_w)
{
Window *biggest = (Window *) 0,
*tmp;
if (screen == NULL)
panic("Cannot add window [%d] to NULL screen.", new_w->refnum);
screen->visible_windows++;
new_w->screen = screen;
new_w->miscflags &= ~WINDOW_NOTIFIED;
/*
* If this is the first window to go on the screen
*/
if (!screen->current_window)
{
screen->window_list_end = screen->window_list = new_w;
if (dumb_mode)
{
new_w->display_size = 24;
set_screens_current_window(screen, new_w);
return new_w;
}
recalculate_windows(screen);
}
/*
* This is not the first window on this screen.
*/
else
{
/* split current window, or find a better window to split */
if ((screen->current_window->display_size < 4) ||
get_int_var(ALWAYS_SPLIT_BIGGEST_VAR))
{
int size = 0;
for (tmp = screen->window_list; tmp; tmp = tmp->next)
{
if (tmp->absolute_size)
continue;
if (tmp->display_size > size)
{
size = tmp->display_size;
biggest = tmp;
}
}
if (!biggest /* || size < 4 */)
{
say("Not enough room for another window!");
screen->visible_windows--;
return NULL;
}
}
else
biggest = screen->current_window;
if ((new_w->prev = biggest->prev) != NULL)
new_w->prev->next = new_w;
else
screen->window_list = new_w;
new_w->next = biggest;
biggest->prev = new_w;
biggest->display_size /= 2;
new_w->display_size = biggest->display_size;
recalculate_windows(screen);
}
return (new_w);
}
/*
* remove_window_from_screen: this removes the given window from the list of
* visible windows. It closes up the hole created by the windows abnsense in
* a nice way. The window passed to this function *must* be visible.
*
* If 'hide' is 1, then the window is added to the invisible list before
* the current window is reset -- this avoids a possible panic in the
* /on switch_windows thrown there. If 'hide' is 0, then the window is
* just unlinked and we assume the caller will gc it.
*/
static void remove_window_from_screen (Window *window, int hide)
{
Screen *s;
if (!((s = window->screen)))
panic("This window is not on a screen");
/*
* We used to go to greath lengths to figure out how to fill
* in the space vacated by this window. Now we dont sweat that.
* we just blow away the window and then recalculate the entire
* screen.
*/
if (window->prev)
window->prev->next = window->next;
else
s->window_list = window->next;
if (window->next)
window->next->prev = window->prev;
else
s->window_list_end = window->prev;
if (!--s->visible_windows)
return;
if (hide)
add_to_invisible_list(window);
if (s->current_window == window)
set_screens_current_window(s, NULL);
if (s->last_window_refnum == window->refnum)
s->last_window_refnum = s->current_window->refnum;
if (s->current_window == window)
make_window_current(last_input_screen->window_list);
else
make_window_current(NULL);
recalculate_windows(s);
}
/* * * * * * * * * * * * SIZE AND LOCATION PRIMITIVES * * * * * * * * * * * */
/*
* recalculate_window_positions: This runs through the window list and
* re-adjusts the top and bottom fields of the windows according to their
* current positions in the window list. This doesn't change any sizes of
* the windows
*/
void recalculate_window_positions (Screen *screen)
{
Window *tmp;
int top;
if (!screen)
return; /* Window is hidden. Dont bother */
top = 0;
for (tmp = screen->window_list; tmp; tmp = tmp->next)
{
tmp->top = top;
tmp->bottom = top + tmp->display_size;
top += tmp->display_size + 1 + tmp->status.double_status;
window_body_needs_redraw(tmp);
window_statusbar_needs_redraw(tmp);
}
}
/*
* swap_window: This swaps the given window with the current window. The
* window passed must be invisible. Swapping retains the positions of both
* windows in their respective window lists, and retains the dimensions of
* the windows as well
*/
static void swap_window (Window *v_window, Window *window)
{
int check_hidden = 1;
int recalculate_everything = 0;
/*
* v_window -- window to be swapped out
* window -- window to be swapped in
*/
/* Find any invisible window to swap in. Prefer swappable ones */
if (!window)
{
for (window = invisible_list; window; window = window->next)
if (window->swappable)
break;
}
if (!window && invisible_list)
{
check_hidden = 0;
window = invisible_list;
}
if (!window)
{
say("The window to be swapped in does not exist.");
return;
}
if (window->screen || !v_window->screen)
{
say("You can only SWAP a hidden window with a visible window.");
return;
}
if (!v_window->swappable)
{
if (v_window->name)
say("Window %s is not swappable", v_window->name);
else
say("Window %d is not swappable", v_window->refnum);
return;
}
if (check_hidden && !window->swappable)
{
if (window->name)
say("Window %s is not swappable", window->name);
else
say("Window %d is not swappable", window->refnum);
return;
}
/*
* Put v_window on invisible list
*/
v_window->screen->last_window_refnum = v_window->refnum;
/*
* Take window off invisible list
*/
remove_from_invisible_list(window);
/*
* Give the window to be swapped in the same geometry as the window
* to be swapped out, mark it as being visible, give it its screen,
* and if the window being swapped out is curr_win, then the window
* to be swapped in will be curr_win.
*/
window->top = v_window->top;
window->display_size = v_window->display_size +
v_window->status.double_status -
window->status.double_status;
window->bottom = window->top + window->display_size;
window->screen = v_window->screen;
if (window->display_size < 0)
{
window->display_size = 0;
recalculate_everything = 1;
}
if (v_window->screen->current_window == v_window)
{
v_window->screen->current_window = window;
window->priority = current_window_priority++;
}
/*
* Put the window to be swapped into the screen list
*/
if ((window->prev = v_window->prev))
window->prev->next = window;
else
window->screen->window_list = window;
if ((window->next = v_window->next))
window->next->prev = window;
else
window->screen->window_list_end = window;
/*
* Hide the window to be swapped out
*/
if (!v_window->deceased)
add_to_invisible_list(v_window);
if (recalculate_everything)
recalculate_windows(window->screen);
recalculate_window_cursor_and_display_ip(window);
resize_window_display(window);
/*
* And recalculate the window's positions.
*/
window_body_needs_redraw(window);
window_statusbar_needs_redraw(window);
window->miscflags &= ~WINDOW_NOTIFIED;
/*
* Transfer current_window if the current window is being swapped out
*/
if (v_window == current_window)
make_window_current(window);
}
/*
* move_window: This moves a window offset positions in the window list. This
* means, of course, that the window will move on the screen as well
*/
static void move_window (Window *window, int offset)
{
Window *tmp,
*last;
int win_pos,
pos;
if (offset == 0)
return;
last = (Window *) 0;
if (!window->screen)
return; /* Whatever */
for (win_pos = 0, tmp = window->screen->window_list; tmp;
tmp = tmp->next, win_pos++)
{
if (window == tmp)
break;
last = tmp;
}
if (!tmp)
return;
if (!last)
window->screen->window_list = tmp->next;
else
last->next = tmp->next;
if (tmp->next)
tmp->next->prev = last;
else
window->screen->window_list_end = last;
win_pos = (offset + win_pos) % window->screen->visible_windows;
if (win_pos < 0)
win_pos = window->screen->visible_windows + win_pos;
last = NULL;
for (pos = 0, tmp = window->screen->window_list;
pos != win_pos; tmp = tmp->next, pos++)
last = tmp;
if (!last)
window->screen->window_list = window;
else
last->next = window;
if (tmp)
tmp->prev = window;
else
window->screen->window_list_end = window;
window->prev = last;
window->next = tmp;
recalculate_window_positions(window->screen);
}
/*
* move_window_to: This moves a given window to the Nth absolute position
* on the screen. All the other windows move accordingly.
*/
static void move_window_to (Window *window, int offset)
{
Window *w;
Screen *s;
int i;
if (offset <= 0)
return;
if (!(s = window->screen))
return; /* Whatever */
if (s->visible_windows == 1)
return; /* Whatever */
if (offset > s->visible_windows)
offset = s->visible_windows;
/* Unlink the window from the screen */
if (window->prev)
window->prev->next = window->next;
else
s->window_list = window->next;
if (window->next)
window->next->prev = window->prev;
else
s->window_list_end = window->prev;
/* Now figure out where it goes */
for (w = s->window_list, i = 1; i < offset; i++)
w = w->next;
/* Now relink it where it belongs */
if (w)
{
if (w->prev)
{
w->prev->next = window;
window->prev = w->prev;
}
else
{
s->window_list = window;
window->prev = NULL;
}
}
else
{
s->window_list_end->next = window;
window->prev = s->window_list_end;
s->window_list_end = window;
}
window->next = w;
set_screens_current_window(s, window);
make_window_current(window);
recalculate_window_positions(s);
}
/*
* resize_window: if 'how' is RESIZE_REL, then this will increase or decrease
* the size of the given window by offset lines (positive offset increases,
* negative decreases). If 'how' is RESIZE_ABS, then this will set the
* absolute size of the given window.
* Obviously, with a fixed terminal size, this means that some other window
* is going to have to change size as well. Normally, this is the next
* window in the window list (the window below the one being changed) unless
* the window is the last in the window list, then the previous window is
* changed as well
*/
static void resize_window (int how, Window *window, int offset)
{
Window *other;
int after,
window_size,
other_size;
if (!window)
window = current_window;
if (!window->screen)
{
say("You cannot change the size of hidden windows!");
return;
}
if (how == RESIZE_ABS)
{
offset -= window->display_size;
how = RESIZE_REL;
}
after = 1;
other = window;
do
{
if (other->next)
other = other->next;
else
{
other = window->screen->window_list;
after = 0;
}
if (other == window)
{
say("Can't change the size of this window!");
return;
}
if (other->absolute_size)
continue;
}
while (other->display_size < offset);
window_size = window->display_size + offset;
other_size = other->display_size - offset;
if ((window_size < 0) || (other_size < 0))
{
say("Not enough room to resize this window!");
return;
}
window->display_size = window_size;
other->display_size = other_size;
recalculate_windows(window->screen);
}
/*
* resize_display: After determining that the window has changed sizes, this
* goes through and adjusts the top of the display. If the window grew, then
* this will *back up* the top of the display (yes, this is the right thing
* to do!), and if the window shrank, then it will move forward the top of
* the display. We dont worry too much about the economy of redrawing.
* If a window is resized, it gets redrawn.
*/
void resize_window_display (Window *window)
{
int cnt = 0, i;
Display *tmp;
if (dumb_mode)
return;
/*
* Find out how much the window has changed by
*/
cnt = window->display_size - window->old_size;
tmp = window->scrolling_top_of_display;
/*
* If it got bigger, move the scrolling_top_of_display back.
*/
if (cnt > 0)
{
/*
* If "SCROLLADJUST" is off, then do not push back the top of
* display to reveal what has previously scrolled off (for
* ircII compatability
*/
if (window->scrolladj)
{
for (i = 0; i < cnt; i++)
{
if (!tmp || !tmp->prev)
break;
tmp = tmp->prev;
}
}
}
/*
* If it got smaller, then move the scrolling_top_of_display up
*/
else if (cnt < 0)
{
/* Use any whitespace we may have lying around */
cnt += (window->old_size - window->scrolling_distance_from_display_ip);
for (i = 0; i > cnt; i--)
{
if (tmp == window->display_ip)
break;
tmp = tmp->next;
}
}
window->scrolling_top_of_display = tmp;
recalculate_window_cursor_and_display_ip(window);
/*
* Mark the window for redraw and store the new window size.
*/
window_body_needs_redraw(window);
window_statusbar_needs_redraw(window);
window->old_size = window->display_size;
return;
}
/* * * * * * * * * * * * WINDOW UPDATING AND RESIZING * * * * * * * * * */
/*
* THese three functions are the one and only functions that are authorized
* to be used to declare that something needs to be updated on the screen.
*/
/*
* statusbar_needs_update
*/
void window_statusbar_needs_update (Window *w)
{
w->update |= UPDATE_STATUS;
}
/*
* statusbar_needs_redraw
*/
void window_statusbar_needs_redraw (Window *w)
{
w->update |= REDRAW_STATUS;
}
/*
* window_body_needs_redraw
*/
void window_body_needs_redraw (Window *w)
{
w->cursor = -1;
}
/*
* redraw_all_windows: This basically clears and redraws the entire display
* portion of the screen. All windows and status lines are draws. This does
* nothing for the input line of the screen. Only visible windows are drawn
*/
void redraw_all_windows (void)
{
Window *tmp = NULL;
if (dumb_mode)
return;
while (traverse_all_windows(&tmp)) {
window_body_needs_redraw(tmp);
window_statusbar_needs_redraw(tmp);
}
}
/*
* update_all_status: This performs a logical "update_window_status" on
* every window for the current screen.
*/
void update_all_status (void)
{
Window *window;
window = NULL;
while (traverse_all_windows(&window))
window_statusbar_needs_update(window);
}
/*
* update_all_windows: This goes through each visible window and draws the
* necessary portions according the the update field of the window.
*/
void update_all_windows (void)
{
Window *tmp = NULL;
static int recursion = 0;
static int do_input_too = 0;
static int restart;
if (recursion)
{
restart = 1;
return;
}
recursion++;
while (traverse_all_windows(&tmp))
{
if (restart)
{
restart = 0;
tmp = NULL;
continue;
}
/*
* This should always be done, even for hidden windows
* ... i think.
*/
if (tmp->display_size != tmp->old_size)
resize_window_display(tmp);
/* Never try to update/redraw an invisible window */
if (!tmp->screen)
continue;
if (tmp->cursor == -1 ||
(tmp->scroll &&
tmp->cursor < tmp->scrolling_distance_from_display_ip &&
tmp->cursor < tmp->display_size))
repaint_window_body(tmp);
if (tmp->update & REDRAW_STATUS)
{
if (!make_status(tmp, 1))
tmp->update &= ~REDRAW_STATUS;
do_input_too = 1;
}
else if (tmp->update & UPDATE_STATUS)
{
if (!make_status(tmp, 0))
tmp->update &= ~UPDATE_STATUS;
do_input_too = 1;
}
}
if (do_input_too)
{
do_input_too = 0;
update_input(UPDATE_JUST_CURSOR);
}
tmp = NULL;
while (traverse_all_windows(&tmp))
{
if (tmp->cursor > tmp->display_size)
panic("uaw: window [%d]'s cursor [%d] is off the display [%d]", tmp->refnum, tmp->cursor, tmp->display_size);
}
recursion--;
}
/****************************************************************************/
/*
* Rebalance_windows: this is called when you want all the windows to be
* rebalanced, except for those who have a set size.
*/
void rebalance_windows (Screen *screen)
{
Window *tmp;
int each, extra;
int window_resized = 0, window_count = 0;
if (dumb_mode)
return;
/*
* Two passes -- first figure out how much we need to balance,
* and how many windows there are to balance
*/
for (tmp = screen->window_list; tmp; tmp = tmp->next)
{
if (tmp->absolute_size)
continue;
window_resized += tmp->display_size;
window_count++;
}
if (window_count == 0)
{
yell("All the windows on this screen are fixed!");
return;
}
each = window_resized / window_count;
extra = window_resized % window_count;
/*
* And then go through and fix everybody
*/
for (tmp = screen->window_list; tmp; tmp = tmp->next)
{
if (tmp->absolute_size)
;
else
{
tmp->display_size = each;
if (extra)
tmp->display_size++, extra--;
}
}
recalculate_window_positions(screen);
}
/*
* recalculate_windows: this is called when the terminal size changes (as
* when an xterm window size is changed). It recalculates the sized and
* positions of all the windows. The net change in space is distributed
* proportionally across the windows as closely as possible.
*/
void recalculate_windows (Screen *screen)
{
int old_li = 1;
int excess_li = 0;
Window *tmp;
int window_count = 0;
int window_resized = 0;
int offset;
if (dumb_mode)
return;
/*
* If its a new window, just set it and be done with it.
*/
if (!screen->current_window)
{
screen->window_list->top = 0;
screen->window_list->display_size = screen->li - 2;
screen->window_list->bottom = screen->li - 2;
old_li = screen->li;
return;
}
/*
* Expanding the screen takes two passes. In the first pass,
* We figure out how many windows will be resized. If none can
* be rebalanced, we add the whole shebang to the last one.
*/
for (tmp = screen->window_list; tmp; tmp = tmp->next)
{
old_li += tmp->display_size + tmp->status.double_status + 1;
if (tmp->absolute_size && (window_count || tmp->next))
continue;
window_resized += tmp->display_size;
window_count++;
}
excess_li = screen->li - old_li;
for (tmp = screen->window_list; tmp; tmp = tmp->next)
{
if (tmp->absolute_size && tmp->next)
;
else
{
/*
* The number of lines this window gets is:
* The number of lines available for resizing times
* the percentage of the resizeable screen the window
* covers.
*/
if (tmp->next && window_resized)
offset = (tmp->display_size * excess_li) /
window_resized;
else
offset = excess_li;
tmp->display_size += offset;
if (tmp->display_size < 0)
tmp->display_size = 1;
excess_li -= offset;
resize_window_display(tmp);
recalculate_window_cursor_and_display_ip(tmp);
}
}
recalculate_window_positions(screen);
}
/* * * * * * * * LOCATION AND COMPOSITION OF WINDOWS ON SCREEN * * * * * * */
/*
* goto_window: This will switch the current window to the N'th window
* from the top of the screen. The "which" has nothing to do with the
* window's refnum, only its location on the screen.
*/
static void goto_window (Screen *s, int which)
{
Window *tmp;
int i;
if (!s || which == 0)
return;
if ((which < 0) || (which > s->visible_windows))
{
say("GOTO: Illegal value");
return;
}
tmp = s->window_list;
for (i = 1; i < which; i++)
tmp = tmp->next;
set_screens_current_window(s, tmp);
make_window_current(tmp);
}
/*
* hide_window: sets the given window to invisible and recalculates remaing
* windows to fill the entire screen
*/
void hide_window (Window *window)
{
if (!window->screen)
{
if (window->name)
say("Window %s is already hidden", window->name);
else
say("Window %d is already hidden", window->refnum);
return;
}
if (!window->swappable)
{
if (window->name)
say("Window %s can't be hidden", window->name);
else
say("Window %d can't be hidden", window->refnum);
return;
}
if (window->screen->visible_windows -
count_fixed_windows(window->screen) <= 1)
{
say("You can't hide the last window.");
return;
}
if (window->screen)
remove_window_from_screen(window, 1);
}
/*
* swap_last_window: This swaps the current window with the last window
* that was hidden.
* This is a keybinding.
*/
void swap_last_window (char dumb, char *dumber)
{
if (!invisible_list || !current_window->screen)
return;
swap_window(current_window, invisible_list);
message_from((char *) 0, LOG_CRAP);
update_all_windows();
}
/*
* next_window: This switches the current window to the next visible window
* This is a keybinding.
*/
void next_window (char dumb, char *dumber)
{
Window *w;
if (!last_input_screen)
return;
if (last_input_screen->visible_windows == 1)
return;
w = get_next_window(last_input_screen->current_window);
make_window_current(w);
/* XXX This is dangerous -- 'make_window_current' might nuke 'w'! */
set_screens_current_window(last_input_screen, w);
update_all_windows();
}
/*
* swap_next_window: This swaps the current window with the next hidden
* window.
* This is a keybinding.
*/
void swap_next_window (char dumb, char *dumber)
{
window_next(current_window, NULL);
update_all_windows();
}
/*
* previous_window: This switches the current window to the previous visible
* window
* This is a keybinding
*/
void previous_window (char dumb, char *dumber)
{
Window *w;
if (!last_input_screen)
return;
if (last_input_screen->visible_windows == 1)
return;
w = get_previous_window(last_input_screen->current_window);
make_window_current(w);
/* XXX This is dangerous -- 'make_window_current' might nuke 'w'! */
set_screens_current_window(last_input_screen, w);
update_all_windows();
}
/*
* swap_previous_window: This swaps the current window with the next
* hidden window.
* This is a keybinding
*/
void swap_previous_window (char dumb, char *dumber)
{
window_previous(current_window, NULL);
update_all_windows();
}
/* show_window: This makes the given window visible. */
static void show_window (Window *window)
{
if (!window->swappable)
{
if (window->name)
say("Window %s can't be made visible", window->name);
else
say("Window %d can't be made visible", window->refnum);
return;
}
if (!window->screen)
{
remove_from_invisible_list(window);
if (!(window->screen = current_window->screen))
window->screen = last_input_screen; /* What the hey */
if (!add_to_window_list(window->screen, window))
{
/* Ooops. this is an error. ;-) */
add_to_invisible_list(window);
return;
}
}
make_window_current(window);
/* XXX This is dangerous -- 'make_window_current' might nuke 'w'! */
set_screens_current_window(window->screen, window);
return;
}
/* * * * * * * * * * * * * GETTING WINDOWS AND WINDOW INFORMATION * * * * */
/*
* get_window_by_desc: Given either a refnum or a name, find that window
*/
Window *get_window_by_desc (const char *stuff)
{
Window *w = NULL; /* bleh */
/*
while (*stuff == '#')
stuff++;
*/
if ((w = get_window_by_name(stuff)))
return w;
if (is_number(stuff) && (w = get_window_by_refnum(my_atol(stuff))))
return w;
return NULL;
}
/*
* get_window_by_refnum: Given a reference number to a window, this returns a
* pointer to that window if a window exists with that refnum, null is
* returned otherwise. The "safe" way to reference a window is throught the
* refnum, since a window might be delete behind your back and and Window
* pointers might become invalid.
*/
Window *get_window_by_refnum (unsigned refnum)
{
Window *tmp = NULL;
if (refnum == 0)
return current_window;
while (traverse_all_windows(&tmp))
{
if (tmp->refnum == refnum)
return tmp;
}
return NULL;
}
/*
* get_window_by_name: returns a pointer to a window with a matching logical
* name or null if no window matches
*/
Window *get_window_by_name (const char *name)
{
Window *tmp = NULL;
while (traverse_all_windows(&tmp))
{
if (tmp->name && (my_stricmp(tmp->name, name) == 0))
return (tmp);
}
return NULL;
}
/*
* DON'T EVEN THINK OF CALLING THIS FUNCTION IF YOU KNOW WHAT IS GOOD
* FOR YOU! Well, if you do feel like calling it, you better make sure
* to make a copy of it immediately, because the ltoa() return value will
* soon point to someone else's number... ;-)
*/
char * get_refnum_by_window (const Window *w)
{
return ltoa(w->refnum);
}
int get_winref_by_servref (int servref)
{
Window *tmp = NULL;
Window *best = NULL;
while (traverse_all_windows(&tmp))
{
if (tmp->server != servref && tmp->last_server != servref)
continue;
if (best == NULL || best->priority < tmp->priority)
best = tmp;
}
if (best)
return best->refnum;
else
return -1;
}
/*
* get_next_window: This overly complicated function attempts to find the
* next non "skippable" window. The reason for the complication is that it
* needs to be able to deal with wrapping over to the top of the screen,
* if the next window is at the bottom, or isnt selectable, YGTI.
*/
static Window *get_next_window (Window *w)
{
Window *last = w;
Window *new_w = w;
if (!w || !w->screen)
last = new_w = w = current_window;
do
{
if (new_w->next)
new_w = new_w->next;
else
new_w = w->screen->window_list;
}
while (new_w && new_w->skip && new_w != last);
return new_w;
}
/*
* get_previous_window: this returns the previous *visible* window in the
* window list. This automatically wraps to the last window in the window
* list
*/
static Window *get_previous_window (Window *w)
{
Window *last = w;
Window *new_w = w;
if (!w || !w->screen)
last = new_w = w = current_window;
do
{
if (new_w->prev)
new_w = new_w->prev;
else
new_w = w->screen->window_list_end;
}
while (new_w->skip && new_w != last);
return new_w;
}
/*
* get_visible_by_refnum: Returns 1 if the specified window is visible.
*/
int is_window_visible (char *arg)
{
Window *win;
if ((win = get_window_by_desc(arg)))
{
if (win->screen)
return 1;
else
return 0;
}
return -1;
}
/*
* XXXX i have no idea if this belongs here.
*/
char * get_status_by_refnum (unsigned refnum, int line)
{
Window *the_window;
if ((the_window = get_window_by_refnum(refnum)))
{
if (line > the_window->status.double_status)
return NULL;
return denormalize_string(the_window->status.line[line].result);
}
else
return NULL;
}
/* * * * * * * * * * * * * INPUT PROMPT * * * * * * * * * * * * * * */
/*
* set_prompt_by_refnum: changes the prompt for the given window. A window
* prompt will be used as the target in place of the query user or current
* channel if it is set
*/
void set_prompt_by_refnum (unsigned refnum, char *prompt)
{
Window *tmp;
if (!(tmp = get_window_by_refnum(refnum)))
tmp = current_window;
malloc_strcpy(&tmp->prompt, prompt);
update_input(UPDATE_JUST_CURSOR);
}
/* get_prompt_by_refnum: returns the prompt for the given window refnum */
char *get_prompt_by_refnum (unsigned refnum)
{
Window *tmp;
if (!(tmp = get_window_by_refnum(refnum)))
tmp = current_window;
return tmp->prompt ? tmp->prompt : empty_string;
}
/* * * * * * * * * * * * * * * TARGETS AND QUERIES * * * * * * * * * * * */
/*
* get_target_by_refnum: returns the target for the window with the given
* refnum (or for the current window). The target is either the query nick
* or current channel for the window
*/
const char *get_target_by_refnum (unsigned refnum)
{
Window *tmp;
const char * cc;
if (!(tmp = get_window_by_refnum(refnum)))
if (!(tmp = last_input_screen->current_window))
return NULL;
if (tmp->query_nick)
return tmp->query_nick;
if ((cc = get_echannel_by_refnum(refnum)))
return cc;
return NULL;
}
/* query_nick: Returns the query nick for the current channel */
const char *query_nick (void)
{
return current_window->query_nick;
}
/* * * * * * * * * * * * * * CHANNELS * * * * * * * * * * * * * * * * * */
/* get_echannel_by_refnum: returns the current channel for window refnum */
const char *get_echannel_by_refnum (unsigned refnum)
{
Window *tmp;
if ((tmp = get_window_by_refnum(refnum)) == (Window *) 0)
panic("get_echannel_by_refnum: invalid window [%d]", refnum);
return window_current_channel(tmp->refnum, tmp->server);
}
int get_winref_by_bound_channel (const char *channel, int server)
{
Window *tmp = NULL;
while (traverse_all_windows(&tmp))
{
if (tmp->server != server)
continue;
if (tmp->bind_channel && !my_stricmp(tmp->bind_channel, channel))
return tmp->refnum;
}
return -1;
}
const char * get_bound_channel_by_refnum (unsigned refnum)
{
Window *tmp;
if (!(tmp = get_window_by_refnum(refnum)))
return NULL;
return tmp->bind_channel;
}
void unbind_channel (const char *channel, int server)
{
Window *tmp = NULL;
while (traverse_all_windows(&tmp))
{
if (tmp->server == server && tmp->bind_channel &&
!my_stricmp(tmp->bind_channel, channel))
{
new_free(&tmp->bind_channel);
tmp->bind_channel = NULL;
return;
}
}
}
int is_window_waiting_for_channel (unsigned refnum, const char *chan)
{
Window *tmp;
if (!(tmp = get_window_by_refnum(refnum)))
return 0;
if (chan == NULL)
{
if (tmp->waiting_channel)
return 1;
else
return 0;
}
if (tmp->waiting_channel && !my_stricmp(chan, tmp->waiting_channel))
return 1;
return 0;
}
void move_waiting_channel (unsigned oldref, unsigned newref)
{
Window *oldw, *neww;
if (!(oldw = get_window_by_refnum(oldref)))
panic("move_waiting_channel: Old Window [%d] doesn't exist",
oldref);
if (!(neww = get_window_by_refnum(newref)))
panic("move_waiting_channel: New Window [%d] doesn't exist",
newref);
if (oldw->server != neww->server)
panic("move_waiting_channel: window [%d:%d] and [%d:%d] "
"are on different servers.",
oldref, get_window_server(oldref),
newref, get_window_server(newref));
if (oldw->waiting_channel)
{
neww->waiting_channel = oldw->waiting_channel;
oldw->waiting_channel = NULL;
}
}
/*
* This is called whenever you're not going to reconnect and
* destroy_server_channels() is called.
*/
void destroy_waiting_channels (int server)
{
Window *tmp = NULL;
while (traverse_all_windows(&tmp))
{
if (tmp->server != server)
continue;
new_free(&tmp->waiting_channel);
}
}
/* * * * * * * * * * * * * * * * * * SERVERS * * * * * * * * * * * * * */
/*
* get_window_server: returns the server index for the window with the given
* refnum
*/
int get_window_server (unsigned int refnum)
{
Window *tmp;
if ((tmp = get_window_by_refnum(refnum)) == (Window *) 0)
tmp = current_window;
return (tmp->server);
}
/*
* get_window_oldserver: returns the last server the window was connected to.
*/
int get_window_oldserver (unsigned refnum)
{
Window *tmp;
if (!(tmp = get_window_by_refnum(refnum)))
tmp = current_window;
return tmp->last_server;
}
/*
* Changes any windows that are currently using "old_server" to instead
* use "new_server". This is only ever called by connect_to_new_server.
*/
void change_window_server (int old_server, int new_server)
{
Window *tmp = NULL;
/*
* Only do this if we're moving servers.
*/
if (old_server != new_server)
{
/* Move any active windows first... */
while (traverse_all_windows(&tmp))
{
if (tmp->server != old_server)
continue;
tmp->server = new_server;
#if 0
/*
* Unless we are disconnecting, deleting
* current_channel and waiting_channel is not
* our responsibility. But if we are disconnecting
* then if we don't do it, nobody can.
*/
if (new_server == NOSERV)
window_discon(tmp, NULL); /* XXXh */
#endif
}
}
/*
* Always try to reclaim any lost windows lying around.
*/
tmp = NULL;
while (traverse_all_windows(&tmp))
{
if (tmp->server != NOSERV)
continue;
if (tmp->last_server != old_server)
continue;
tmp->server = new_server;
tmp->last_server = NOSERV;
}
if (old_server == primary_server)
primary_server = new_server;
window_check_servers();
}
/*
* windows_connected_to_server: This returns the number of windows that
* are actively connected to a server. This is used by /window server
*/
static int windows_connected_to_server (int server)
{
Window *tmp = NULL;
int count = 0;
while (traverse_all_windows(&tmp))
{
if (tmp->server == server)
count++;
}
return count;
}
/*
* window_check_servers: this checks the validity of the open servers vs the
* current window list. Every open server must have at least one window
* associated with it. If a window is associated with a server that's no
* longer open, that window's server is set to the primary server. If an
* open server has no assicatiate windows, that server is closed. If the
* primary server is no more, a new primary server is picked from the open
* servers
*/
void window_check_servers (void)
{
Window *tmp;
int cnt, max, i, connected;
int prime = NOSERV;
connected_to_server = 0;
max = server_list_size();
for (i = 0; i < max; i++)
{
connected = is_server_open(i);
cnt = 0;
tmp = NULL;
while (traverse_all_windows(&tmp))
{
if (tmp->server == i)
{
/*
* Generally, closed server connections have
* their window's moved to new servers
* gracefully. In this case, something
* really died. We just make this window
* not connected to any server and save the
* last server so connect_to_new_server can
* glum this window up next time.
*/
if (!connected)
{
tmp->last_server = i;
tmp->server = NOSERV;
}
else
{
prime = tmp->server;
cnt++;
}
}
}
if (cnt)
connected_to_server++;
else if (connected)
{
set_server_save_channels(i, 0);
close_server(i, "No windows for this server");
}
}
if (dead)
return;
if (!is_server_open(primary_server))
{
tmp = NULL;
while (traverse_all_windows(&tmp))
{
if (tmp->server == primary_server)
tmp->server = prime;
}
primary_server = prime;
}
update_all_status();
cursor_to_input();
}
/*
* This is a debugging function that is used to determine the referential
* integrity of all of the channels to all of the windows. The basic notion
* is that it is a bug if any of the following conditions exist:
*
* 1) There exists some window W, such that its named current channel E
* does not exist.
* 2) There exists some window W, such that its named current channel E
* is not connected to window W.
* 3) There exists some channel E, such that it is not connected to any
* window. (repairable)
* 4) There exists some channel E, such that its connected window W is
* not connected to the same server as E.
* 5) There exists some channel E, such that its connected window W
* does not exist.
* 6) There exists some channel E, connected to window W, such that W
* has no current channel. (repairable)
* 7) There exists some channel E, such that it's server is not open and
* its "saved" option is not asserted.
*/
void window_check_channels (void)
{
/* Tests #3 through #5 are done in names.c */
channel_check_windows();
}
/* * * * * * * * * * LEVELS * * * * * * * * * */
/*
* set_level_by_refnum: This sets the window level given a refnum. It
* revamps the windows levels as well using revamp_window_levels()
*/
void set_level_by_refnum (unsigned refnum, int level)
{
Window *tmp;
if (!(tmp = get_window_by_refnum(refnum)))
tmp = current_window;
tmp->window_level = level;
revamp_window_levels(tmp);
}
/*
* revamp_window_levels: Given a level setting for the current window, this
* makes sure that that level setting is unused by any other window. Thus
* only one window in the system can be set to a given level. This only
* revamps levels for windows with servers matching the given window
* it also makes sure that only one window has the level `DCC', as this is
* not dependant on a server.
*/
static void revamp_window_levels (Window *window)
{
Window *tmp = NULL;
int got_dcc;
got_dcc = (LOG_DCC & window->window_level) ? 1 : 0;
while (traverse_all_windows(&tmp))
{
if (tmp == window)
continue;
if (LOG_DCC & tmp->window_level)
{
if (got_dcc)
tmp->window_level &= ~LOG_DCC;
got_dcc = 1;
}
if (window->server == tmp->server)
tmp->window_level ^= (tmp->window_level & window->window_level);
}
}
/*
* message_to: This allows you to specify a window (by refnum) as a
* destination for messages. Used by EXEC routines quite nicely
*/
void message_to (int refnum)
{
to_window = (refnum != -1) ? get_window_by_refnum((unsigned)refnum) : NULL;
}
/*
* save_message_from: this is used to save (for later restoration) the
* who_from variable. This is needed when a function (do_hook) is about
* to call another function (parse_line) it knows will change who_from.
* The values are saved on the stack so it will be recursive-safe.
*
* NO CHEATING when you call this function to get the value of who_from! ;-)
*/
void save_message_from (const char **saved_who_from, int *saved_who_level)
{
*saved_who_from = who_from;
*saved_who_level = who_level;
}
/* restore_message_from: restores a previously saved who_from variable */
void restore_message_from (const char *saved_who_from, int saved_who_level)
{
who_from = saved_who_from;
who_level = saved_who_level;
}
/*
* message_from: With this you can set the who_from variable and the
* who_level variable, used by the display routines to decide which
* window messages should go to.
*/
void message_from (const char *who, int level)
{
#ifdef NO_CHEATING
malloc_strcpy(&who_from, who);
#else
who_from = who;
#endif
set_lastlog_msg_level(level);
who_level = level;
}
/*
* message_from_level: Like set_lastlog_msg_level, except for message_from.
* this is needed by XECHO, because we could want to output things in more
* than one level.
*/
int message_from_level (int level)
{
int temp;
temp = who_level;
who_level = level;
return temp;
}
/* * * * * * * * * * * CLEARING WINDOWS * * * * * * * * * * */
static void clear_window (Window *window)
{
if (dumb_mode)
return;
window->scrolling_top_of_display = window->display_ip;
if (window->miscflags & WINDOW_NOTIFIED)
window->miscflags &= ~WINDOW_NOTIFIED;
recalculate_window_cursor_and_display_ip(window);
window_body_needs_redraw(window);
window_statusbar_needs_redraw(window);
}
void clear_all_windows (int visible, int hidden, int unhold)
{
Window *tmp = NULL;
while (traverse_all_windows(&tmp))
{
if (visible && !hidden && !tmp->screen)
continue;
if (!visible && hidden && tmp->screen)
continue;
clear_window(tmp);
}
}
/*
* clear_window_by_refnum: just like clear_window(), but it uses a refnum. If
* the refnum is invalid, the current window is cleared.
*/
void clear_window_by_refnum (unsigned refnum, int unhold)
{
Window *tmp;
if (!(tmp = get_window_by_refnum(refnum)))
tmp = current_window;
clear_window(tmp);
}
static void unclear_window (Window *window)
{
int i;
if (dumb_mode)
return;
window->scrolling_top_of_display = window->display_ip;
for (i = 0; i < window->display_size; i++)
{
if (window->scrolling_top_of_display == window->top_of_scrollback)
break;
window->scrolling_top_of_display = window->scrolling_top_of_display->prev;
}
recalculate_window_cursor_and_display_ip(window);
window_body_needs_redraw(window);
window_statusbar_needs_redraw(window);
}
void unclear_all_windows (int visible, int hidden, int unhold)
{
Window *tmp = NULL;
while (traverse_all_windows(&tmp))
{
if (visible && !hidden && !tmp->screen)
continue;
if (!visible && hidden && tmp->screen)
continue;
unclear_window(tmp);
}
}
void unclear_window_by_refnum (unsigned refnum, int unhold)
{
Window *tmp;
if (!(tmp = get_window_by_refnum(refnum)))
tmp = current_window;
unclear_window(tmp);
}
/*
* This returns 1 if 'w' is holding something. This means the
* window has output that has never been displayed ("held").
* For compatability with ircII, we "unhold" windows that are
* "holding", but we do the check before running a command and
* do the unhold after running it. This is confusing, but it's
* the way ircII has always done it, so there you have it.
*/
int window_is_holding (Window *w)
{
if (w->holding_distance_from_display_ip > w->display_size)
return 1;
else
return 0;
}
/*
* After running a command (from the SEND_LINE keybinding), if the window
* had output that was never displayed ("holding"), then display the next
* screenfull of output. Unholding should only be done on windows that
* were holding *before* the command is run in SEND_LINE.
*/
int unhold_a_window (Window *w)
{
int slider, i;
if (!w->holding_top_of_display)
return 0; /* ok, whatever */
slider = (w->hold_slider * w->display_size) / 100;
for (i = 0; i < slider; i++)
{
if (w->holding_top_of_display == w->display_ip)
break;
w->holding_top_of_display = w->holding_top_of_display->next;
}
recalculate_window_cursor_and_display_ip(w);
window_body_needs_redraw(w);
window_statusbar_needs_update(w);
return 0;
}
/* * * * * * * * * * * * * * * SCROLLING * * * * * * * * * * * * * * */
/*
* set_scroll_lines: called by /SET SCROLL_LINES to check the scroll lines
* value
*/
void set_scroll_lines (const void *stuff)
{
int size = *(const int *)stuff;
if (size == 0)
{
say("You cannot turn SCROLL off. Gripe at me.");
return;
}
else if (size > current_window->display_size)
{
say("Maximum lines that may be scrolled is %d",
current_window->display_size);
set_int_var(SCROLL_LINES_VAR, current_window->display_size);
}
}
/* * * * * * * * * UNSORTED * * * * * * * */
/*
* set_continued_line: checks the value of CONTINUED_LINE for validity,
* altering it if its no good
*/
void set_continued_line (const void *stuff)
{
const char *value = (const char *)stuff;
if (value && (strlen(value) > (size_t)(current_term->TI_cols / 2)))
{
char *chg = LOCAL_COPY(value);
chg[current_term->TI_cols / 2] = 0;
set_string_var(CONTINUED_LINE_VAR, chg);
}
}
/* current_refnum: returns the reference number for the current window */
unsigned current_refnum (void)
{
return current_window->refnum;
}
int number_of_windows_on_screen (Window *w)
{
return w->screen->visible_windows;
}
/*
* set_lastlog_size: sets up a lastlog buffer of size given. If the lastlog
* has gotten larger than it was before, all previous lastlog entry remain.
* If it get smaller, some are deleted from the end.
*/
void set_scrollback_size (const void *stuff)
{
int size = *(const int *)stuff;
Window *window = NULL;
while (traverse_all_windows(&window))
{
if (size < window->display_size * 2)
window->display_buffer_max = window->display_size * 2;
else
window->display_buffer_max = size;
}
}
/*
* is_window_name_unique: checks the given name vs the names of all the
* windows and returns true if the given name is unique, false otherwise
*/
static int is_window_name_unique (char *name)
{
Window *tmp = NULL;
if (name)
{
while (traverse_all_windows(&tmp))
{
if (tmp->name && (my_stricmp(tmp->name, name) == 0))
return (0);
}
}
return (1);
}
char *get_nicklist_by_window (Window *win)
{
WNickList *nick = win->nicks;
char *stuff = NULL;
size_t stuffclue = 0;
for (; nick; nick = nick->next)
malloc_strcat_wordlist_c(&stuff, space, nick->nick, &stuffclue);
if (!stuff)
return malloc_strdup(empty_string);
else
return stuff;
}
#define WIN_FORM "%-4s %*.*s %*.*s %*.*s %-9.9s %-10.10s %s%s"
static void list_a_window (Window *window, int len)
{
int cnw = get_int_var(CHANNEL_NAME_WIDTH_VAR);
const char *chan = get_echannel_by_refnum(window->refnum);
if (cnw == 0)
cnw = 12; /* Whatever */
say(WIN_FORM, ltoa(window->refnum),
12, 12, get_server_nickname(window->server),
len, len, window->name ? window->name : "<None>",
cnw, cnw, chan ? chan : "<None>",
window->query_nick ? window->query_nick : "<None>",
get_server_itsname(window->server),
bits_to_lastlog_level(window->window_level),
window->screen ? empty_string : " Hidden");
}
int get_geom_by_winref (const char *desc, int *co, int *li)
{
Window *win = get_window_by_desc(desc);
if (!win || !win->screen)
return -1;
*co = win->screen->co;
*li = win->screen->li;
return 0;
}
/* below is stuff used for parsing of WINDOW command */
/*
* get_window: this parses out any window (visible or not) and returns a
* pointer to it
*/
static Window *get_window (const char *name, char **args)
{
char *arg;
Window *win;
if ((arg = next_arg(*args, args)))
{
if ((win = get_window_by_desc(arg)))
return win;
say("%s: No such window: %s", name, arg);
}
else
say("%s: Please specify a window refnum or name", name);
return NULL;
}
/*
* get_invisible_window: parses out an invisible window by reference number.
* Returns the pointer to the window, or null. The args can also be "LAST"
* indicating the top of the invisible window list (and thus the last window
* made invisible)
*/
static Window *get_invisible_window (const char *name, char **args)
{
char *arg;
Window *tmp;
if ((arg = next_arg(*args, args)) != NULL)
{
if (my_strnicmp(arg, "LAST", strlen(arg)) == 0)
{
if (invisible_list == (Window *) 0)
say("%s: There are no hidden windows", name);
return (invisible_list);
}
if ((tmp = get_window(name, &arg)) != NULL)
{
if (!tmp->screen)
{
return (tmp);
}
else
{
if (tmp->name)
say("%s: Window %s is not hidden!",
name, tmp->name);
else
say("%s: Window %d is not hidden!",
name, tmp->refnum);
}
}
}
else
say("%s: Please specify a window refnum or LAST", name);
return ((Window *) 0);
}
/* get_number: parses out an integer number and returns it */
static int get_number (const char *name, char **args)
{
char *arg;
if ((arg = next_arg(*args, args)) != NULL)
return (my_atol(arg));
else
say("%s: You must specify the number of lines", name);
return 0;
}
/*
* get_boolean: parses either ON, OFF, or TOGGLE and sets the var
* accordingly. Returns 0 if all went well, -1 if a bogus or missing value
* was specified
*/
static int get_boolean (const char *name, char **args, int *var)
{
char *arg;
int newval;
newval = *var;
if (!(arg = next_arg(*args, args)) || do_boolean(arg, &newval))
{
say("Value for %s must be ON, OFF, or TOGGLE", name);
return (-1);
}
/* The say() MUST BE DONE BEFORE THE ASSIGNMENT! */
say("Window %s is %s", name, onoff[newval]);
*var = newval;
return (0);
}
/*
* /WINDOW ADD nick<,nick>
* Adds a list of one or more nicknames to the current list of usupred
* targets for the current window. These are matched up with the nick
* argument for message_from().
*/
static Window *window_add (Window *window, char **args)
{
char *ptr;
WNickList *new_w;
char *arg = next_arg(*args, args);
if (!arg)
say("ADD: Add nicknames to be redirected to this window");
else while (arg)
{
if ((ptr = strchr(arg, ',')))
*ptr++ = 0;
if (!find_in_list((List **)&window->nicks, arg, !USE_WILDCARDS))
{
say("Added %s to window name list", arg);
new_w = (WNickList *)new_malloc(sizeof(WNickList));
new_w->nick = malloc_strdup(arg);
add_to_list((List **)&(window->nicks), (List *)new_w);
}
else
say("%s already on window name list", arg);
arg = ptr;
}
return window;
}
/*
* /WINDOW BACK
* Changes the current window pointer to the window that was most previously
* the current window. If that window is now hidden, then it is swapped with
* the current window.
*/
static Window *window_back (Window *window, char **args)
{
Window *tmp;
tmp = get_window_by_refnum(last_input_screen->last_window_refnum);
if (!tmp)
tmp = last_input_screen->window_list;
make_window_current(tmp);
/* XXX This is dangerous, 'make_window_current' might nuke 'tmp' */
if (tmp->screen)
set_screens_current_window(tmp->screen, tmp);
else
{
swap_window(window, tmp);
message_from((char *) 0, LOG_CRAP);
}
return window;
}
/*
* /WINDOW BALANCE
* Causes all of the windows on the current screen to be adjusted so that
* the largest window on the screen is no more than one line larger than
* the smallest window on the screen.
*/
static Window *window_balance (Window *window, char **args)
{
if (window->screen)
rebalance_windows(window->screen);
else
yell("Cannot balance invisible windows!");
return window;
}
/*
* /WINDOW BEEP_ALWAYS ON|OFF
* Indicates that when this window is HIDDEN (sorry, thats not what it seems
* like it should do, but that is what it does), beeps to this window should
* not be suppressed like they normally are for hidden windows. In all cases,
* the current window is notified when a beep occurs if this window is hidden.
*/
static Window *window_beep_always (Window *window, char **args)
{
if (get_boolean("BEEP_ALWAYS", args, &window->beep_always))
return NULL;
return window;
}
/*
* /WINDOW BIND <#channel>
* Indicates that the window should be "bound" to the specified channel.
* "binding" a channel to a window means that the channel will always
* belong to this window, no matter what. For example, if a channel is
* bound to a window, you can do a /join #channel in any window, and it
* will always "join" in this window. This is especially useful when
* you are disconnected from a server, because when you reconnect, the client
* often loses track of which channel went to which window. Binding your
* channels gives the client a hint where channels belong.
*
* You can rebind a channel to a new window, even after it has already
* been bound elsewhere.
*/
static Window *window_bind (Window *window, char **args)
{
char *arg;
Window *w = NULL;
const char *chan;
if ((arg = next_arg(*args, args)))
{
if (!is_channel(arg))
{
say("BIND: %s is not a valid channel name", arg);
return NULL;
}
/*
* If its already bound, no point in continuing.
*/
if (window->bind_channel && !my_stricmp(window->bind_channel, arg))
{
say("Window is already bound to channel %s", arg);
return window;
}
/*
* If the window is bound to something else, let the user
* know about that.
*/
if (window->bind_channel)
{
say("Unbinding channel %s from this window",
window->bind_channel);
window->bind_channel = NULL;
}
/*
* You must either bind the current channel to a window, or
* you must be binding to a window without a current channel
*/
chan = get_echannel_by_refnum(window->refnum);
if (chan)
{
if (!my_stricmp(chan, arg))
malloc_strcpy(&window->bind_channel, arg);
else
say("You may only /WINDOW BIND the current channel for this window");
return window;
}
/*
* So we know this window doesnt have a current channel.
* So we have to find the window where it IS the current
* channel (if it is at all)
*/
while (traverse_all_windows(&w))
{
/*
* If we have found a window where this channel
* is the current channel, then we make it so that
* it is the current channel here.
* Also, move_channel_to_window transfer cancels the
* channels' bound status on the old window.
*/
chan = get_echannel_by_refnum(w->refnum);
if (chan && !my_stricmp(chan, arg) &&
w->server == window->server)
{
move_channel_to_window(arg, window->server,
w->refnum, window->refnum);
}
}
/*
* Now we mark this channel as being bound here.
* and as being our current channel.
*/
malloc_strcpy(&window->bind_channel, arg);
say("Window is bound to channel %s", arg);
if (im_on_channel(arg, window->server))
{
move_channel_to_window(arg, window->server,
0, window->refnum);
say("Current channel for window now %s", arg);
}
}
else if ((arg = window->bind_channel))
say("Window is bound to channel %s", arg);
else
say("Window is not bound to any channel");
return window;
}
/*
* /WINDOW CHANNEL <#channel>
* Directs the client to make a specified channel the current channel for
* the window -- it will JOIN the channel if you are not already on it.
* If the channel you wish to activate is bound to a different window, you
* will be notified. If you are already on the channel in another window,
* then the channel's window will be switched. If you do not specify a
* channel, or if you specify the channel "0", then the window will drop its
* connection to whatever channel it is in. You can only join a channel if
* that channel is not bound to a different window.
*/
static Window *window_channel (Window *window, char **args)
{
char *sarg,
*arg,
*arg2 = NULL,
*arg3 = NULL;
Window *w = NULL;
const char *carg;
const char *chan;
/* Fix by Jason Brand, Nov 6, 2000 */
if (window->server == NOSERV)
{
say("This window is not connected to a server.");
return NULL;
}
if ((sarg = new_next_arg(*args, args)))
{
if (!(carg = next_arg(sarg, &sarg)))
{
say("Huh?");
return window;
}
if (!my_strnicmp(carg, "-i", 2))
{
if (!(carg = get_server_invite_channel(window->server)))
{
say("You have not been invited to a channel!");
return window;
}
}
if (!is_channel(carg))
{
say("CHANNEL: %s is not a valid channel name", carg);
return NULL;
}
/*
* We do some chicanery here. :/
* For some complicated reasons, new_next_arg skips over
* backslashed quotation marks. Usually what happens down
* the line is that the backslash eventually gets unescaped.
* Well, not here. So we have to do this manually. This is
* a quick, and nasty hack, but i will re-assess the
* situation later and improve what is being done here.
*/
arg = malloc_strcat_ues(&arg2, carg, empty_string);
sarg = malloc_strcat_ues(&arg3, sarg, empty_string);
while (traverse_all_windows(&w))
{
if (w == window || w->server != window->server)
continue; /* Not us! */
if (w->bind_channel &&
!my_stricmp(arg, w->bind_channel))
{
say("Channel %s is already bound elsewhere", arg);
new_free(&arg2);
new_free(&arg3);
return window;
}
chan = get_echannel_by_refnum(w->refnum);
if (chan && !my_stricmp(arg, chan))
move_channel_to_window(arg, w->server,
w->refnum, window->refnum);
}
message_from(arg, LOG_CRAP);
if (im_on_channel(arg, window->server))
{
move_channel_to_window(arg, window->server,
0, window->refnum);
say("You are now talking to channel %s",
check_channel_type(arg));
}
#if 0 /* What to do here? */
else if (arg[0] == '0' && arg[1] == 0)
set_channel_by_refnum(window->refnum, NULL);
#endif
else
{
/*
* This needs to be done first in case anyone has any weird
* ideas about doing a /wait in the /on send_to_server.
*/
malloc_strcpy(&window->waiting_channel, arg);
if (sarg)
send_to_aserver(window->server,"JOIN %s %s", arg, sarg);
else
send_to_aserver(window->server,"JOIN %s", arg);
}
new_free(&arg2);
new_free(&arg3);
}
message_from(NULL, LOG_CRAP);
return window;
}
/* WINDOW CLEAR -- should be obvious, right? */
static Window *window_clear (Window *window, char **args)
{
clear_window(window);
return window;
}
/*
* /WINDOW CREATE
* This directs the client to open up a new physical screen and create a
* new window in it. This feature depends on the external "wserv" utility
* and requires a multi-processing system, since it actually runs the new
* screen in a seperate process. Please note that the external screen is
* not actually controlled by the client, but rather by "wserv" which acts
* as a pass-through filter on behalf of the client.
*
* Since the external screen is outside the client's process, it is not really
* possible for the client to know when the external screen is resized, or
* what that new size would be. For this reason, you should not resize any
* screen when you have external screens open. If you do, the client will
* surely become confused and the output will probably be garbled. You can
* restore some sanity by making sure that ALL external screens have the same
* geometry, and then redrawing each screen.
*/
static Window *window_create (Window *window, char **args)
{
#ifdef WINDOW_CREATE
Window *tmp;
if ((tmp = (Window *)create_additional_screen()))
window = tmp;
else
#endif
say("Cannot create new screen!");
return window;
}
/*
* /WINDOW DELETE
* This directs the client to close the current external physical screen
* and to re-parent any windows onto other screens. You are not allowed
* to delete the "main" window because that window belongs to the process
* group of the client itself.
*/
static Window *window_delete (Window *window, char **args)
{
#ifdef WINDOW_CREATE
kill_screen(window->screen);
#endif
return current_window;
}
/*
* /WINDOW DESCRIBE
* Directs the client to tell you a bit about the current window.
* This is the 'default' argument to the /window command.
*/
static Window *window_describe (Window *window, char **args)
{
const char *chan;
if (window->name)
say("Window %s (%u)",
window->name, window->refnum);
else
say("Window %u", window->refnum);
say("\tServer: %d - %s",
window->server,
get_server_name(window->server));
say("\tScreen: %p", window->screen);
say("\tGeometry Info: [%d %d %d %d %d %d %d %d]",
window->top, window->bottom,
0, window->display_size,
window->cursor,
window->scrolling_distance_from_display_ip,
window->holding_distance_from_display_ip,
window->scrollback_distance_from_display_ip);
say("\tCO, LI are [%d %d]", current_term->TI_cols, current_term->TI_lines);
chan = get_echannel_by_refnum(window->refnum);
say("\tCurrent channel: %s", chan ? chan : "<None>");
if (window->waiting_channel)
say("\tWaiting channel: %s",
window->waiting_channel);
if (window->bind_channel)
say("\tBound channel: %s",
window->bind_channel);
say("\tQuery User: %s",
window->query_nick ?
window->query_nick : "<None>");
say("\tPrompt: %s",
window->prompt ?
window->prompt : "<None>");
say("\tSecond status line is %s",
onoff[window->status.double_status]);
say("\tLogging is %s",
onoff[window->log]);
if (window->logfile)
say("\tLogfile is %s", window->logfile);
else
say("\tNo logfile given");
say("\tNotification is %s",
onoff[window->miscflags & WINDOW_NOTIFY]);
say("\tHold mode is %s",
onoff[window->holding_top_of_display ? 1 : 0]);
say("\tWindow level is %s",
bits_to_lastlog_level(window->window_level));
say("\tLastlog level is %s",
bits_to_lastlog_level(window->lastlog_level));
say("\tNotify level is %s",
bits_to_lastlog_level(window->notify_level));
if (window->nicks)
{
WNickList *tmp;
say("\tName list:");
for (tmp = window->nicks; tmp; tmp = tmp->next)
say("\t %s", tmp->nick);
}
return window;
}
/*
* /WINDOW DISCON
* This disassociates a window with all servers.
*/
static Window *window_discon (Window *window, char **args)
{
reassign_window_channels(window->refnum);
new_free(&window->bind_channel);
new_free(&window->waiting_channel);
window->last_server = window->server;
window->server = NOSERV; /* XXX This shouldn't be set here. */
window_check_servers();
return window;
}
/*
* /WINDOW DOUBLE ON|OFF
* This directs the client to enable or disable the supplimentary status bar.
* When the "double status bar" is enabled, the status formats are taken from
* /set STATUS_FORMAT1 or STATUS_FORMAT2. When it is disabled, the format is
* taken from /set STATUS_FORMAT.
*/
static Window *window_double (Window *window, char **args)
{
int current = window->status.double_status;
if (get_boolean("DOUBLE", args, &window->status.double_status))
return NULL;
window->display_size += current - window->status.double_status;
if (window->display_size < 0)
{
window->display_size = 0;
if (window->screen)
recalculate_windows(window->screen);
}
recalculate_window_positions(window->screen);
return window;
}
/*
* WINDOW ECHO <text>
*
* Text must either be surrounded with double-quotes (")'s or it is assumed
* to terminate at the end of the argument list. This sends the given text
* to the current window.
*/
static Window *window_echo (Window *window, char **args)
{
const char *to_echo;
Window *old_to_window;
if (**args == '"')
to_echo = new_next_arg(*args, args);
else
to_echo = *args, *args = NULL;
/* Calling add_to_window() directly is a hack. */
old_to_window = to_window;
to_window = window;
add_to_screen(to_echo);
to_window = old_to_window;
return window;
}
/*
* /WINDOW FIXED (ON|OFF)
*
* When this is ON, then this window will never be used as the implicit
* partner for a window resize. That is to say, if you /window grow another
* window, this window will not be considered for the corresponding shrink.
* You may /window grow a fixed window, but if you do not have other nonfixed
* windows, the grow will fail.
*/
static Window *window_fixed (Window *window, char **args)
{
if (get_boolean("FIXED", args, &window->absolute_size))
return NULL;
return window;
}
/*
* /WINDOW FLUSH
*
* Does the window part of the /flush command.
*/
static Window *window_flush (Window *window, char **args)
{
flush_scrollback_after(window);
return window;
}
/*
* /WINDOW GOTO refnum
* This switches the current window selection to the window as specified
* by the numbered refnum.
*/
static Window *window_goto (Window *window, char **args)
{
goto_window(window->screen, get_number("GOTO", args));
from_server = get_window_server(0);
return current_window;
}
/*
* /WINDOW GROW lines
* This directs the client to expand the specified window by the specified
* number of lines. The number of lines should be a positive integer, and
* the window's growth must not cause another window to be smaller than
* the minimum of 3 lines.
*/
static Window *window_grow (Window *window, char **args)
{
resize_window(RESIZE_REL, window, get_number("GROW", args));
return window;
}
/*
* /WINDOW HIDE
* This directs the client to remove the specified window from the current
* (visible) screen and place the window on the client's invisible list.
* A hidden window has no "screen", and so can not be seen, and does not
* have a size. It can be unhidden onto any screen.
*/
static Window *window_hide (Window *window, char **args)
{
hide_window(window);
return current_window;
}
/*
* /WINDOW HIDE_OTHERS
* This directs the client to place *all* windows on the current screen,
* except for the current window, onto the invisible list.
*/
static Window *window_hide_others (Window *window, char **args)
{
Window *tmp, *next;
if (window->screen)
tmp = window->screen->window_list;
else
tmp = invisible_list;
while (tmp)
{
next = tmp->next;
if (tmp != window)
hide_window(tmp);
tmp = next;
}
return window;
}
/*
* /WINDOW HOLD_INTERVAL
* This determines how frequently the status bar should update the "HELD"
* value when you are in holding mode. The default is 10, so that your
* status bar isn't constantly flickering every time a new line comes in.
* But if you want better responsiveness, this is the place to change it.
*/
static Window *window_hold_interval (Window *window, char **args)
{
char *arg = next_arg(*args, args);
if (arg)
{
int size = my_atol(arg);
if (size <= 0)
{
say("Hold interval must be a positive value!");
return window;
}
window->hold_interval = size;
}
say("Window hold interval notification is %d", window->hold_interval);
return window;
}
/*
* /WINDOW HOLD_MODE
* This arranges for the window to "hold" any output bound for it once
* a full page of output has been completed. Setting the global value of
* HOLD_MODE is truly bogus and should be changed. XXXX
*/
static Window *window_hold_mode (Window *window, char **args)
{
int hold_mode;
int slider;
int i;
if (window->holding_top_of_display)
hold_mode = 1;
else
hold_mode = 0;
if (get_boolean("HOLD_MODE", args, &hold_mode))
return NULL;
if (hold_mode && !window->holding_top_of_display)
{
window->holding_top_of_display = window->scrolling_top_of_display;
slider = (window->hold_slider * window->display_size) / 100;
for (i = 0; i < slider; i++)
{
if (window->holding_top_of_display == window->display_ip)
break;
window->holding_top_of_display = window->holding_top_of_display->next;
}
recalculate_window_cursor_and_display_ip(window);
window_body_needs_redraw(window);
window_statusbar_needs_update(window);
}
if (!hold_mode && window->holding_top_of_display)
{
window->holding_top_of_display = NULL;
recalculate_window_cursor_and_display_ip(window);
window_body_needs_redraw(window);
window_statusbar_needs_update(window);
}
return window;
}
/*
* /WINDOW HOLD_SLIDER
* This determines how far up the hold pointer should move when you hit
* the return key (unhold action)
*/
static Window *window_hold_slider (Window *window, char **args)
{
char *arg = next_arg(*args, args);
if (arg)
{
int size = my_atol(arg);
if (size < 0 || size > 100)
{
say("Hold slider must be 0 to 100!");
return window;
}
window->hold_slider = size;
}
say("Window hold slider is %d", window->hold_slider);
return window;
}
/*
* /WINDOW KILL
* This arranges for the current window to be destroyed. Once a window
* is killed, it cannot be recovered. Because every server must have at
* least one window "connected" to it, if you kill the last window for a
* server, the client will drop your connection to that server automatically.
*/
static Window *window_kill (Window *window, char **args)
{
delete_window(window);
return current_window;
}
/*
* /WINDOW KILL_OTHERS
* This arranges for all windows on the current screen, other than the
* current window to be destroyed. Obviously, the current window will be
* the only window left on the screen. Connections to servers other than
* the server for the current window will be implicitly closed.
*/
static Window *window_kill_others (Window *window, char **args)
{
Window *tmp, *next;
if (window->screen)
tmp = window->screen->window_list;
else
tmp = invisible_list;
while (tmp)
{
next = tmp->next;
if (tmp != window)
delete_window(tmp);
tmp = next;
}
return window;
}
/*
* /WINDOW KILLSWAP
* This arranges for the current window to be replaced by the last window
* to be hidden, and also destroys the current window.
*/
static Window *window_killswap (Window *window, char **args)
{
if (invisible_list)
{
swap_window(window, invisible_list);
delete_window(window);
}
else
say("There are no hidden windows!");
return current_window;
}
/*
* /WINDOW LAST
* This changes the current window focus to the window that was most recently
* the current window *but only if that window is still visible*. If the
* window is no longer visible (having been HIDDEN), then the next window
* following the current window will be made the current window.
*/
static Window *window_last (Window *window, char **args)
{
set_screens_current_window(window->screen, NULL);
return current_window;
}
/*
* /WINDOW LASTLOG <size>
* This changes the size of the window's lastlog buffer. The default value
* for a window's lastlog is the value of /set LASTLOG, but each window may
* be independantly tweaked with this command.
*/
static Window *window_lastlog (Window *window, char **args)
{
char *arg = next_arg(*args, args);
if (arg)
{
int size = my_atol(arg);
if (window->lastlog_size > size)
{
int i, diff;
diff = window->lastlog_size - size;
for (i = 0; i < diff; i++)
remove_from_lastlog(window);
}
window->lastlog_max = size;
}
say("Lastlog size is %d", window->lastlog_max);
return window;
}
/*
* /WINDOW LASTLOG_LEVEL <level-description>
* This changes the types of lines that will be placed into this window's
* lastlog. It is useful to note that the window's lastlog will contain
* a subset (possibly a complete subset) of the lines that have appeared
* in the window. This setting allows you to control which lines are
* "thrown away" by the window.
*/
static Window *window_lastlog_level (Window *window, char **args)
{
char *arg = next_arg(*args, args);;
if (arg)
window->lastlog_level = parse_lastlog_level(arg);
say("Lastlog level is %s", bits_to_lastlog_level(window->lastlog_level));
return window;
}
/*
* /WINDOW LEVEL <level-description>
* This changes the types of output that will appear in the specified window.
* Note that for the given set of windows connected to a server, each level
* may only appear once in that set. When you add a level to a given window,
* then it will be removed from whatever window currently holds it. The
* exception to this is the "DCC" level, which may only be set to one window
* for the entire client.
*/
static Window *window_level (Window *window, char **args)
{
char *arg;
int add = 0;
int newlevel = 0;
if ((arg = next_arg(*args, args)))
{
if (*arg == '+')
add = 1, arg++;
else if (*arg == '-')
add = -1, arg++;
newlevel = parse_lastlog_level(arg);
if (add == 1)
window->window_level |= newlevel;
else if (add == 0)
window->window_level = newlevel;
else if (add == -1)
window->window_level &= ~newlevel;
revamp_window_levels(window);
}
say("Window level is %s", bits_to_lastlog_level(window->window_level));
return window;
}
/*
* /WINDOW LIST
* This lists all of the windows known to the client, and a breif summary
* of their current state.
*/
static Window *window_list (Window *window, char **args)
{
Window *tmp = NULL;
int len = 6;
int cnw = get_int_var(CHANNEL_NAME_WIDTH_VAR);
if (cnw == 0)
cnw = 12; /* Whatever */
tmp = NULL;
while (traverse_all_windows(&tmp))
{
if (tmp->name && (strlen(tmp->name) > (size_t)len))
len = strlen(tmp->name);
}
say(WIN_FORM, "Ref",
12, 12, "Nick",
len, len, "Name",
cnw, cnw, "Channel",
"Query",
"Server",
"Level",
empty_string);
tmp = NULL;
while (traverse_all_windows(&tmp))
list_a_window(tmp, len);
return window;
}
/*
* /WINDOW LOG ON|OFF
* This sets the current state of the logfile for the given window. When the
* logfile is on, then any lines that appear on the window are written to the
* logfile 'as-is'. The name of the logfile can be controlled with
* /WINDOW LOGFILE. The default logfile name is <windowname>.<target|refnum>
*/
static Window *window_log (Window *window, char **args)
{
char *logfile;
int add_ext = 1;
char buffer[BIG_BUFFER_SIZE + 1];
if (get_boolean("LOG", args, &window->log))
return NULL;
if ((logfile = window->logfile))
add_ext = 0;
else if (!(logfile = get_string_var(LOGFILE_VAR)))
logfile = empty_string;
strlcpy(buffer, logfile, sizeof buffer);
if (add_ext)
{
const char *title = empty_string;
strlcat(buffer, ".", sizeof buffer);
if ((title = get_echannel_by_refnum(window->refnum)))
strlcat(buffer, title, sizeof buffer);
else if ((title = window->query_nick))
strlcat(buffer, title, sizeof buffer);
else
{
strlcat(buffer, "Window_", sizeof buffer);
strlcat(buffer, ltoa(window->refnum), sizeof buffer);
}
}
do_log(window->log, buffer, &window->log_fp);
if (!window->log_fp)
window->log = 0;
return window;
}
/*
* /WINDOW LOGFILE <filename>
* This sets the current value of the log filename for the given window.
* When you activate the log (with /WINDOW LOG ON), then any output to the
* window also be written to the filename specified.
*/
static Window *window_logfile (Window *window, char **args)
{
char *arg = next_arg(*args, args);
if (arg)
{
malloc_strcpy(&window->logfile, arg);
say("Window LOGFILE set to %s", arg);
}
else if (window->logfile)
say("Window LOGFILE is %s", window->logfile);
else
say("Window LOGFILE is not set.");
return window;
}
static Window *window_move (Window *window, char **args)
{
move_window(window, get_number("MOVE", args));
return window;
}
static Window *window_move_to (Window *window, char **args)
{
move_window_to(window, get_number("MOVE", args));
return window;
}
static Window *window_name (Window *window, char **args)
{
char *arg;
if ((arg = new_next_arg(*args, args)))
{
/* /window name - unsets the window name */
if (!strcmp(arg, "-"))
new_free(&window->name);
/* /window name to existing name -- ignore this. */
else if (window->name && (my_stricmp(window->name, arg) == 0))
return window;
else if (is_window_name_unique(arg))
{
malloc_strcpy(&window->name, arg);
window_statusbar_needs_update(window);
}
else
say("%s is not unique!", arg);
}
else
say("You must specify a name for the window!");
return window;
}
static Window *window_new (Window *window, char **args)
{
Window *tmp;
if ((tmp = new_window(window->screen)))
window = tmp;
make_window_current(window);
/* XXX This is dangerous -- 'make_window_current' might nuke 'window' */
return window;
}
static Window *window_new_hide (Window *window, char **args)
{
new_window(NULL);
return window;
}
static Window *window_next (Window *window, char **args)
{
Window *tmp;
Window *next = NULL;
Window *smallest = NULL;
smallest = window;
for (tmp = invisible_list; tmp; tmp = tmp->next)
{
if (!tmp->swappable)
continue;
if (tmp->refnum < smallest->refnum)
smallest = tmp;
if ((tmp->refnum > window->refnum)
&& (!next || (tmp->refnum < next->refnum)))
next = tmp;
}
if (!next)
next = smallest;
if (next == NULL || next == window)
{
say("There are no hidden windows");
return NULL;
}
swap_window(window, next);
message_from((char *) 0, LOG_CRAP);
return current_window;
}
static Window *window_noserv (Window *window, char **args)
{
/* This is just like /window discon but last_server is set to NOSERV */
reassign_window_channels(window->refnum);
new_free(&window->bind_channel);
new_free(&window->waiting_channel);
window->last_server = NOSERV;
window->server = NOSERV; /* XXX This shouldn't be set here. */
window_check_servers();
return window;
}
static Window *window_notify (Window *window, char **args)
{
window->miscflags ^= WINDOW_NOTIFY;
say("Notification when hidden set to %s",
window->miscflags & WINDOW_NOTIFY ? on : off);
return window;
}
static Window *window_notify_list (Window *window, char **args)
{
window->miscflags ^= WINDOW_NOTIFIED;
say("Notify list status set to %s",
window->miscflags & WINDOW_NOTIFIED ? on : off);
return window;
}
static Window *window_notify_level (Window *window, char **args)
{
char *arg;
if ((arg = next_arg(*args, args)))
window->notify_level = parse_lastlog_level(arg);
say("Window notify level is %s", bits_to_lastlog_level(window->notify_level));
return window;
}
static Window *window_number (Window *window, char **args)
{
Window *tmp;
char *arg;
int i;
if ((arg = next_arg(*args, args)))
{
if (window_current_channel(window->refnum, window->server))
{
say("You cannot change the number of a window with a channel");
return window;
}
if ((i = my_atol(arg)) > 0)
{
if ((tmp = get_window_by_refnum(i)))
tmp->refnum = window->refnum;
window->refnum = i;
}
else
say("Window number must be greater than 0");
}
else
say("Window number missing");
return window;
}
/*
* /WINDOW POP
* This changes the current window focus to the most recently /WINDOW PUSHed
* window that still exists. If the window is hidden, then it will be made
* visible. Any windows that are found along the way that have been since
* KILLed will be ignored.
*/
static Window *window_pop (Window *window, char **args)
{
int refnum;
WindowStack *tmp;
Window *win = NULL;
while (window->screen->window_stack)
{
refnum = window->screen->window_stack->refnum;
tmp = window->screen->window_stack->next;
new_free((char **)&window->screen->window_stack);
window->screen->window_stack = tmp;
win = get_window_by_refnum(refnum);
if (!win)
continue;
if (win->screen)
set_screens_current_window(win->screen, win);
else
show_window(win);
}
if (!window->screen->window_stack && !win)
say("The window stack is empty!");
return win;
}
static Window *window_previous (Window *window, char **args)
{
Window *tmp;
Window *previous = NULL, *largest;
largest = window;
for (tmp = invisible_list; tmp; tmp = tmp->next)
{
if (!tmp->swappable)
continue;
if (tmp->refnum > largest->refnum)
largest = tmp;
if ((tmp->refnum < window->refnum)
&& (!previous || tmp->refnum > previous->refnum))
previous = tmp;
}
if (!previous)
previous = largest;
if (previous == NULL || previous == window)
{
say("There are no hidden windows to swap in");
return NULL;
}
swap_window(window, previous);
message_from((char *) 0, LOG_CRAP);
return current_window;
}
static Window *window_prompt (Window *window, char **args)
{
char *arg;
if ((arg = next_arg(*args, args)))
{
malloc_strcpy(&window->prompt, arg);
window_statusbar_needs_update(window);
}
else
say("You must specify a prompt for the window!");
return window;
}
static Window *window_push (Window *window, char **args)
{
WindowStack *new_ws;
new_ws = (WindowStack *) new_malloc(sizeof(WindowStack));
new_ws->refnum = window->refnum;
new_ws->next = window->screen->window_stack;
window->screen->window_stack = new_ws;
return window;
}
Window *window_query (Window *window, char **args)
{
WNickList *tmp;
const char *nick;
char *a;
Window *sw;
/*
* Nuke the old query list
*/
if ((nick = window->query_nick))
{
say("Ending conversation with %s", window->query_nick);
window_statusbar_needs_update(window);
a = LOCAL_COPY(nick);
while (a && *a)
{
nick = next_in_comma_list(a, &a);
if ((tmp = (WNickList *)remove_from_list(
(List **)&window->nicks, nick)))
{
new_free(&tmp->nick);
new_free((char **)&tmp);
}
}
new_free(&window->query_nick);
}
if ((nick = new_next_arg(*args, args)))
{
if (!strcmp(nick, "."))
{
if (!(nick = get_server_sent_nick(window->server)))
say("You have not messaged anyone yet");
}
else if (!strcmp(nick, ","))
{
if (!(nick = get_server_recv_nick(window->server)))
say("You have not recieved a message yet");
}
else if (!strcmp(nick, "*") &&
!(nick = get_echannel_by_refnum(0)))
{
say("You are not on a channel");
}
else if (*nick == '%')
{
if (!is_valid_process(nick))
nick = NULL;
}
if (!nick)
return window;
/*
* Create the new query list
* Ugh. Make sure this goes to the RIGHT WINDOW!
*/
sw = to_window;
to_window = window;
say("Starting conversation with %s", nick);
to_window = sw;
malloc_strcpy(&window->query_nick, nick);
window_statusbar_needs_update(window);
a = LOCAL_COPY(nick);
while (a && *a)
{
nick = next_in_comma_list(a, &a);
tmp = (WNickList *)new_malloc(sizeof(WNickList));
tmp->nick = malloc_strdup(nick);
add_to_list((List **)&window->nicks, (List *)tmp);
}
}
return window;
}
/*
* /WINDOW REBIND <#channel>
* The channel will be "bound" to this window unconditionally. This is
* the same as /window bind, except that <#channel> does not need to be
* the current channel of this window. It may be bound elsewhere, for
* example. This function will handle all of that for you. This function
* will not fail unless you goof up the argument.
*
* Note: This operation is intentionally silent -- Please do not add a
* whole bunch of says and yells in here. The primary purpose of this
* function is to be used in things like /on connect where all the output
* just gets in the way and gives the user no useful information.
*/
static Window *window_rebind (Window *window, char **args)
{
char *arg;
Window *w = NULL;
if (!(arg = next_arg(*args, args)))
{
say("REBIND: requires a channel argument");
return NULL;
}
if (!is_channel(arg))
{
say("REBIND: %s is not a valid channel name", arg);
return NULL;
}
/*
* If its already bound, just accept it and stop here.
*/
if (window->bind_channel && !my_stricmp(window->bind_channel, arg))
return window;
/*
* Unbind whatever is currently bound to the window...
*/
if (window->bind_channel)
new_free(&window->bind_channel);
/*
* Go a-hunting to see if any other window claims this channel.
* If they do, forcibly take it from them.
*/
while (traverse_all_windows(&w))
{
/*
* If we have found a window where this channel
* is the current channel, then we make it so that
* it is the current channel here. This informs
* the channel that it now belongs to us.
* This also unbinds it from the old window.
*/
const char *chan = get_echannel_by_refnum(w->refnum);
if (chan && !my_stricmp(arg, chan) &&
w->server == window->server)
move_channel_to_window(arg, w->server,
w->refnum, window->refnum);
}
/*
* Now lay claim to the channel as belonging to us.
* and as being our current channel. Tell ourselves
* (and the user) that we own this channel now.
*/
malloc_strcpy(&window->bind_channel, arg);
if (im_on_channel(arg, window->server))
move_channel_to_window(arg, window->server,
0, window->refnum);
return window;
}
/*
* /WINDOW REJOIN <#channel>[,<#channel>]
* Here's the plan:
*
* For each channel, assuming from_server:
* - If we are already on the channel:
* - If the current window is connected to from_server:
* -> Move the channel to the current window.
* - If the current window is NOT connected to from_server:
* -> Do nothing.
* - If we are NOT already on the channel:
* - If there is a window that looks like it owns this channel:
* -> Join the channel in that window.
* - If there is NOT a window that looks like it owns this channel:
* - If the current window is connected to from_server:
* -> Join the channel in the current window
* - If the current window is NOT connected to from_server:
* -> Find a window connected to from_server and join channel there.
* -endif
*
* /WINDOW REJOIN is a terminal verb: it always slurps up all of the rest
* of the command as it's arguments and returns NULL and you cannot do any
* more operations after it is finished.
*
* If this function looks insane, it's because I wrote it after a long
* day of coding in java, and so I am, in fact, commitable right now.
*/
Window *window_rejoin (Window *window, char **args)
{
char * channels;
const char * chan;
char * keys = NULL;
char * newchan = NULL;
/* First off, we have to be connected to join */
if (from_server == NOSERV || !is_server_registered(from_server))
{
say("You are not connected to a server.");
return window;
}
/* And the user must want to join something */
/* Get the channels, and the keys. */
if (!(channels = new_next_arg(*args, args)))
{
say("REJOIN: Must provide a channel argument");
return window;
}
keys = new_next_arg(*args, args);
/* Iterate over each channel name in the list. */
while (*channels && (chan = next_in_comma_list(channels, &channels)))
{
/* Handle /join -i, which joins last invited channel */
if (!my_strnicmp(chan, "-i", 2))
{
if (!(chan = get_server_invite_channel(window->server)))
{
say("You have not been invited to a channel!");
continue;
}
}
/* Handle /join 0, which parts all current channels */
if (!strcmp(chan, "0"))
{
send_to_server("JOIN 0");
continue;
}
/* Sanity check the channel for the user */
if (!is_channel(chan))
{
say("CHANNEL: %s is not a valid channel name", chan);
continue;
}
/*
* Now comes all the fun! THere are a whole bunch of
* cases we could deal with right now -- see the comment
* block above the function for the particulars, but
* basically if we are ON the channel, we want to move it
* to the current window for the user. This lets /join
* act like /window channel. But if we are NOT on the
* channel, then we want to find if there is any window
* that thinks it owns it -- this lets the user do a /join
* in /on connect, and have everything go to the right window.
* If nobody owns the channel, then we take it. If we can't
* take it (wrong server) then we find somebody else to take
* it. If we can't find somebody else, then we're screwed.
*/
/* If we're on the channel... */
if (im_on_channel(chan, from_server))
{
/* And i'm on the right server, grab the channel */
if (window->server == from_server)
{
Window *other;
other = get_window_by_refnum(get_channel_winref(chan, from_server));
move_channel_to_window(chan, from_server,
other->refnum, window->refnum);
say("You are now talking to channel %s",
check_channel_type(chan));
}
/* Otherwise, Do not move the channel */
}
/* I am NOT on the channel. */
else
{
Window *owner = NULL;
Window *w = NULL;
Window *anybody = NULL;
/* Go hunt for the owner. */
while (traverse_all_windows(&w))
{
if (w->server != from_server)
continue;
if (w->bind_channel &&
!my_stricmp(w->bind_channel, chan))
{
owner = w;
break;
}
if (w->waiting_channel &&
!my_stricmp(w->waiting_channel, chan))
{
owner = w;
break;
}
/* Take anybody on this server... */
if (anybody == NULL)
anybody = w;
}
/* If there is no owner, then we get first crack. */
if (!owner && window->server == from_server)
owner = window;
/* If there is still no owner, take anybody. */
if (!owner && anybody)
owner = anybody;
/* If there is still no owner, we messed up. */
if (!owner)
panic("There are no windows for this server, "
"and there should be.");
malloc_strcpy(&owner->waiting_channel, chan);
malloc_strcat_wordlist(&newchan, ",", chan);
}
}
if (newchan)
{
if (keys)
send_to_server("JOIN %s %s", newchan, keys);
else
send_to_server("JOIN %s", newchan);
new_free(&newchan);
}
message_from(NULL, LOG_CRAP);
return window;
}
static Window *window_refnum (Window *window, char **args)
{
Window *tmp;
if ((tmp = get_window("REFNUM", args)))
{
window = tmp;
make_window_current(tmp);
/* XXX This is dangerous -- 'make_window_current' might nuke 'tmp' */
if (tmp->screen)
{
set_screens_current_window(tmp->screen, tmp);
window = tmp;
}
}
else
window = NULL;
return window;
}
static Window *window_refnum_or_swap (Window *window, char **args)
{
Window *tmp;
if (!(tmp = get_window("REFNUM_OR_SWAP", args)))
return NULL;
if (tmp->screen)
{
make_window_current(tmp);
/* XXX This is dangerous -- 'make_window_current' might nuke 'tmp' */
set_screens_current_window(tmp->screen, tmp);
}
else
swap_window(window, tmp);
return tmp;
}
static Window *window_refresh (Window *window, char **args)
{
update_all_status();
update_all_windows();
return window;
}
static Window *window_remove (Window *window, char **args)
{
char *arg;
if ((arg = next_arg(*args, args)))
{
char *ptr;
WNickList *new_nl;
while (arg)
{
if ((ptr = strchr(arg, ',')) != NULL)
*ptr++ = 0;
if ((new_nl = (WNickList *)remove_from_list((List **)&(window->nicks), arg)))
{
say("Removed %s from window name list", new_nl->nick);
new_free(&new_nl->nick);
new_free((char **)&new_nl);
}
else
say("%s is not on the list for this window!", arg);
arg = ptr;
}
}
else
say("REMOVE: Do something! Geez!");
return window;
}
/* This is a NO-OP now -- every window is a scratch window */
static Window *window_scratch (Window *window, char **args)
{
int scratch = 0;
if (get_boolean("SCRATCH", args, &scratch))
return NULL;
return window;
}
/* XXX - Need to come back and fix this... */
Window *window_scroll (Window *window, char **args)
{
int scroll = 0;
if (get_boolean("SCROLL", args, &scroll))
return NULL;
#if 0
if (!(window->scroll = scroll))
{
while (window->display_buffer_size < window->display_size)
add_to_display(window, empty_string);
window->noscrollcursor = 0;
unclear_window(window);
}
#endif
return window;
}
static Window *window_scrolladj (Window *window, char **args)
{
if (get_boolean("SCROLLADJ", args, &window->scrolladj))
return NULL;
return window;
}
static Window *window_scrollback (Window *window, char **args)
{
int val;
if (args && *args && **args)
{
val = get_number("SCROLLBACK", args);
if (val < window->display_size * 2)
window->display_buffer_max = window->display_size * 2;
else
window->display_buffer_max = val;
}
say("Window scrollback size set to %d", window->display_buffer_max);
return window;
}
static Window *window_scroll_backward (Window *window, char **args)
{
int val;
if (args && *args && **args)
{
val = get_number("SCROLL_BACKWARD", args);
if (val == 0)
window_scrollback_backward(window);
else
window_scrollback_backwards_lines(window, val);
}
else
window_scrollback_backward(window);
return window;
}
static Window *window_scroll_end (Window *window, char **args)
{
window_scrollback_end(window);
return window;
}
static Window *window_scroll_forward (Window *window, char **args)
{
int val;
if (args && *args && **args)
{
val = get_number("SCROLL_FORWARD", args);
if (val == 0)
window_scrollback_forward(window);
else
window_scrollback_forwards_lines(window, val);
}
else
window_scrollback_forward(window);
return window;
}
static Window *window_scroll_start (Window *window, char **args)
{
window_scrollback_start(window);
return window;
}
regex_t *last_regex = NULL;
static int new_search_term (const char *arg)
{
int errcode;
if (last_regex)
regfree(last_regex);
else
last_regex = new_malloc(sizeof(*last_regex));
errcode = regcomp(last_regex, arg,
REG_EXTENDED | REG_ICASE | REG_NOSUB);
if (errcode != 0)
{
char errstr[1024];
regerror(errcode, last_regex, errstr, sizeof(errstr));
say("The regex [%s] isn't acceptable because [%s]",
arg, errstr);
return -1;
}
return 0;
}
static Window *window_search_back (Window *window, char **args)
{
char *arg;
if ((arg = new_next_arg(*args, args)))
{
if (new_search_term(arg))
return window;
}
if (last_regex)
window_scrollback_to_string(window, last_regex);
else
say("Need to know what to search for");
return window;
}
static Window *window_search_forward (Window *window, char **args)
{
char *arg;
if ((arg = new_next_arg(*args, args)))
{
if (new_search_term(arg))
return window;
}
if (last_regex)
window_scrollforward_to_string(window, last_regex);
else
say("Need to know what to search for");
return window;
}
static Window *window_skip (Window *window, char **args)
{
if (get_boolean("SKIP", args, &window->skip))
return NULL;
return window;
}
Window *window_server (Window *window, char **args)
{
char * arg;
int newconn;
if ((arg = next_arg(*args, args)))
{
int i = find_server_refnum(arg, NULL);
if (windows_connected_to_server(window->server) > 1)
{
clear_reconnect_counts(); /* ?? */
newconn = 1;
}
else
newconn = 0;
if (!connect_to_new_server(i, window->server, 1))
{
/*
* First find a new home for all our channels.
* This is a must since we're moving to a
* different server, and we don't want the channels
* on one server to point to a window on another
* server.
*/
reassign_window_channels(window->refnum);
/*
* Associate ourselves with the new server.
*/
window->server = i;
window->last_server = NOSERV;
/*
* Set the window's lastlog level that is
* in /set new_server_lastlog_level
*/
set_level_by_refnum(window->refnum,
new_server_lastlog_level);
/*
* And blow away any old channel information
* which we surely cannot use now.
*/
new_free(&window->bind_channel);
new_free(&window->waiting_channel);
}
/*
* Now make sure everything seems coherent.
* If we were the last window attached to that server,
* then window_check_servers() will close up that server
* for us and garbage collect any channels lying around.
*/
window_check_servers();
}
else
say("SERVER: You must specify a server");
return window;
}
static Window *window_show (Window *window, char **args)
{
Window *tmp;
if ((tmp = get_window("SHOW", args)))
{
show_window(tmp);
window = current_window;
}
return window;
}
static Window *window_show_all (Window *window, char **args)
{
while (invisible_list)
show_window(invisible_list);
return window;
}
static Window *window_shrink (Window *window, char **args)
{
resize_window(RESIZE_REL, window, -get_number("SHRINK", args));
return window;
}
static Window *window_size (Window *window, char **args)
{
char * ptr = *args;
int number;
number = parse_number(args);
if (ptr == *args)
say("Window size is %d", window->display_size);
else
resize_window(RESIZE_ABS, window, number);
return window;
}
/*
* This lists the windows that are on the stack, cleaning up any
* bogus entries on the way.
*/
static Window *window_stack (Window *window, char **args)
{
WindowStack *last, *tmp, *crap;
Window *win = NULL;
size_t len = 4;
while (traverse_all_windows(&win))
{
if (win->name && (strlen(win->name) > len))
len = strlen(win->name);
}
say("Window stack:");
last = NULL;
tmp = window->screen->window_stack;
while (tmp)
{
if ((win = get_window_by_refnum(tmp->refnum)) != NULL)
{
list_a_window(win, len);
last = tmp;
tmp = tmp->next;
}
else
{
crap = tmp->next;
new_free((char **)&tmp);
if (last)
last->next = crap;
else
window->screen->window_stack = crap;
tmp = crap;
}
}
return window;
}
static Window *window_status_format (Window *window, char **args)
{
char *arg;
arg = new_next_arg(*args, args);
malloc_strcpy(&window->status.line[0].raw, arg);
window_statusbar_needs_redraw(window);
rebuild_a_status(window);
return window;
}
static Window *window_status_format1 (Window *window, char **args)
{
char *arg;
arg = new_next_arg(*args, args);
malloc_strcpy(&window->status.line[1].raw, arg);
window_statusbar_needs_redraw(window);
rebuild_a_status(window);
return window;
}
static Window *window_status_format2 (Window *window, char **args)
{
char *arg;
arg = new_next_arg(*args, args);
malloc_strcpy(&window->status.line[2].raw, arg);
window_statusbar_needs_redraw(window);
rebuild_a_status(window);
return window;
}
static Window *window_status_special (Window *window, char **args)
{
char *arg;
arg = new_next_arg(*args, args);
malloc_strcpy(&window->status.special, arg);
window_statusbar_needs_redraw(window);
return window;
}
static Window *window_swap (Window *window, char **args)
{
Window *tmp;
if ((tmp = get_invisible_window("SWAP", args)))
swap_window(window, tmp);
return current_window;
}
static Window *window_swappable (Window *window, char **args)
{
if (get_boolean("SWAPPABLE", args, &window->swappable))
return NULL;
window_statusbar_needs_update(window);
return window;
}
static Window *window_unbind (Window *window, char **args)
{
char *arg;
if ((arg = next_arg(*args, args)))
{
if (get_winref_by_bound_channel(arg, window->server) > 0)
{
say("Channel %s is no longer bound", arg);
unbind_channel(arg, from_server);
}
else
say("Channel %s is not bound", arg);
}
else
{
say("Channel %s is no longer bound", window->bind_channel);
new_free(&window->bind_channel);
}
return window;
}
typedef Window *(*window_func) (Window *, char **args);
typedef struct window_ops_T {
const char *command;
window_func func;
} window_ops;
static const window_ops options [] = {
{ "ADD", window_add },
{ "BACK", window_back },
{ "BALANCE", window_balance },
{ "BEEP_ALWAYS", window_beep_always },
{ "BIND", window_bind },
{ "CHANNEL", window_channel },
{ "CLEAR", window_clear },
{ "CREATE", window_create },
{ "DELETE", window_delete },
{ "DESCRIBE", window_describe }, /* * */
{ "DISCON", window_discon },
{ "DOUBLE", window_double },
{ "ECHO", window_echo },
{ "FIXED", window_fixed },
{ "FLUSH", window_flush },
{ "GOTO", window_goto },
{ "GROW", window_grow },
{ "HIDE", window_hide },
{ "HIDE_OTHERS", window_hide_others },
{ "HOLD_INTERVAL", window_hold_interval },
{ "HOLD_MODE", window_hold_mode },
{ "HOLD_SLIDER", window_hold_slider },
{ "KILL", window_kill },
{ "KILL_OTHERS", window_kill_others },
{ "KILLSWAP", window_killswap },
{ "LAST", window_last },
{ "LASTLOG", window_lastlog },
{ "LASTLOG_LEVEL", window_lastlog_level },
{ "LEVEL", window_level },
{ "LIST", window_list },
{ "LOG", window_log },
{ "LOGFILE", window_logfile },
{ "MOVE", window_move },
{ "MOVE_TO", window_move_to },
{ "NAME", window_name },
{ "NEW", window_new },
{ "NEW_HIDE", window_new_hide }, /* * */
{ "NEXT", window_next },
{ "NOSERV", window_noserv },
{ "NOTIFIED", window_notify_list },
{ "NOTIFY", window_notify },
{ "NOTIFY_LEVEL", window_notify_level },
{ "NUMBER", window_number },
{ "POP", window_pop },
{ "PREVIOUS", window_previous },
{ "PROMPT", window_prompt },
{ "PUSH", window_push },
{ "QUERY", window_query },
{ "REBIND", window_rebind },
{ "REFNUM", window_refnum },
{ "REFNUM_OR_SWAP", window_refnum_or_swap },
{ "REFRESH", window_refresh },
{ "REJOIN", window_rejoin },
{ "REMOVE", window_remove },
{ "SCRATCH", window_scratch },
{ "SCROLL", window_scroll },
{ "SCROLLADJ", window_scrolladj },
{ "SCROLLBACK", window_scrollback }, /* * */
{ "SCROLL_BACKWARD", window_scroll_backward },
{ "SCROLL_END", window_scroll_end },
{ "SCROLL_FORWARD", window_scroll_forward },
{ "SCROLL_START", window_scroll_start },
{ "SEARCH_BACK", window_search_back },
{ "SEARCH_FORWARD", window_search_forward },
{ "SERVER", window_server },
{ "SHOW", window_show },
{ "SHOW_ALL", window_show_all }, /* * */
{ "SHRINK", window_shrink },
{ "SIZE", window_size },
{ "SKIP", window_skip },
{ "STACK", window_stack },
{ "STATUS_FORMAT", window_status_format },
{ "STATUS_FORMAT1", window_status_format1 },
{ "STATUS_FORMAT2", window_status_format2 },
{ "STATUS_SPECIAL", window_status_special },
{ "SWAP", window_swap },
{ "SWAPPABLE", window_swappable },
{ "UNBIND", window_unbind },
{ NULL, NULL }
};
BUILT_IN_COMMAND(windowcmd)
{
char *arg;
int nargs = 0;
Window *window;
int old_status_update;
int winref;
old_status_update = permit_status_update(0);
message_from(NULL, LOG_CURRENT);
window = current_window;
while ((arg = next_arg(args, &args)))
{
int i;
int len = strlen(arg);
if (*arg == '-' || *arg == '/') /* Ignore - or / */
arg++, len--;
for (i = 0; options[i].func ; i++)
{
if (!my_strnicmp(arg, options[i].command, len))
{
winref = window ? (int)window->refnum : -1;
window = options[i].func(window, &args);
nargs++;
if (!window)
args = NULL;
do_hook(WINDOW_COMMAND_LIST, "%d %d",
winref, window ? (int)window->refnum : -1);
break;
}
}
if (!options[i].func)
{
Window *s_window;
if ((s_window = get_window_by_desc(arg)))
{
nargs++;
window = s_window;
}
else
yell("WINDOW: Invalid option: [%s]", arg);
}
}
if (!nargs)
window_describe(current_window, NULL);
permit_status_update(old_status_update);
message_from(NULL, LOG_CRAP);
window_check_channels();
update_all_windows();
}
/********************** SCROLLBACK BUFFER MAINTAINANCE **********************/
/*
* XXXX Dont you DARE touch this XXXX
*
* Most of the time, a delete_display_line() is followed somewhat
* immediately by a new_display_line(). So most of the time we just
* cache that one item and re-use it. That saves us thousands of
* malloc()s. In the cases where its not, then we just do things the
* normal way.
*/
static Display *recycle = NULL;
static size_t display_line_count = 1;
void delete_display_line (Display *stuff)
{
if (recycle == stuff)
panic("recycle == stuff is bogus");
if (recycle)
{
new_free((char **)&recycle->line);
new_free((char **)&recycle);
}
recycle = stuff;
#if 0
new_free(&stuff->line);
#endif
*(stuff->line) = 0;
}
/*
* CAUTION: The return value of this function may or may not have 'line'
* set to NULL. Therefore, you MUST call malloc_strcpy() to initialize
* the 'line' field. You will cause memory leaks if you fail to do this!
* By not free()ing line, we save a free()/malloc() if the new original line
* had enough space to hold the new line. We let malloc_strcpy() do the
* dirty work there.
*/
static Display *new_display_line (Display *prev, Window *w)
{
Display *stuff;
if (recycle)
{
stuff = recycle;
recycle = NULL;
}
else
{
stuff = (Display *)new_malloc(sizeof(Display));
stuff->line = NULL;
}
#if 0
stuff->line = NULL;
#endif
stuff->count = w->display_counter++;
stuff->prev = prev;
stuff->next = NULL;
return stuff;
}
/*
* This function adds an item to the window's scrollback. If the item
* should be displayed on the screen, then 1 is returned. If the item is
* not to be displayed, then 0 is returned. This function handles all
* the hold_mode stuff.
*/
int add_to_scrollback (Window *window, const unsigned char *str)
{
/*
* If this is a scratch window, do that somewhere else
*/
if (window->change_line != -1)
return change_line(window, str);
return add_to_display(window, str);
}
int add_to_display (Window *window, const unsigned char *str)
{
int scroll;
int i;
/* Add to the display list */
window->display_ip->next = new_display_line(window->display_ip, window);
malloc_strcpy(&window->display_ip->line, str);
window->display_ip = window->display_ip->next;
window->display_buffer_size++;
/* Adjust the top of screen values */
window->scrolling_distance_from_display_ip++;
if (window->scrollback_top_of_display)
window->scrollback_distance_from_display_ip++;
if (window->holding_top_of_display)
window->holding_distance_from_display_ip++;
/* Check to see what happens in hold mode */
if (window->holding_top_of_display)
{
size_t lines_held;
lines_held = window->holding_distance_from_display_ip - window->display_size;
if (lines_held > 0)
window_statusbar_needs_update(window);
}
/* Check to see what happens in scrollback mode */
if (window->scrollback_top_of_display)
{
size_t lines_held;
lines_held = window->scrollback_distance_from_display_ip - window->display_size;
if (lines_held > 0)
window_statusbar_needs_update(window);
}
/* Logically scroll the normal top of display pointer */
while (window->scrolling_distance_from_display_ip >
window->display_size)
{
if ((scroll = get_int_var(SCROLL_LINES_VAR)) <= 0)
scroll = 1;
for (i = 0; i < scroll; i++)
{
window->scrolling_top_of_display =
window->scrolling_top_of_display->next;
window->scrolling_distance_from_display_ip--;
}
}
return 1;
}
int trim_scrollback (Window *window)
{
/* Do not trim the scrollback if we are in scrollback mode */
if (window->scrollback_top_of_display)
return 0;
/* Do not trim the scrollback if we are holding stuff. */
if (window->holding_distance_from_display_ip > window->display_size)
return 0;
/*
* Before outputting the line, we snip back the top of the
* display buffer. (The fact that we do this only when we get
* to here is what keeps whats currently on the window always
* active -- once we get out of hold mode or scrollback mode, then
* we truncate the display buffer at that point.)
*/
while (window->display_buffer_size > window->display_buffer_max)
{
Display *next = window->top_of_scrollback->next;
delete_display_line(window->top_of_scrollback);
window->top_of_scrollback = next;
window->display_buffer_size--;
}
/* Ok. Go ahead and print it */
return 1;
}
int flush_scrollback_after (Window *window)
{
Display *curr_line, *next_line;
int count;
if (!(curr_line = window->holding_top_of_display))
{
say("/WINDOW FLUSH doesn't do anything unless you're in hold mode");
return 0;
}
for (count = 1; count < window->display_size; count++)
{
if (curr_line == window->display_ip)
return 0;
curr_line = curr_line->next;
}
next_line = curr_line->next;
curr_line->next = window->display_ip;
window->display_ip->prev = curr_line;
curr_line = next_line;
while (curr_line != window->display_ip)
{
next_line = curr_line->next;
delete_display_line(curr_line);
window->display_buffer_size--;
curr_line = next_line;
}
window->scrolling_top_of_display = window->holding_top_of_display;
recalculate_window_cursor_and_display_ip(window);
return 1;
}
/* * * * * * * * * * * Scrollback functionality * * * * * * * * * * */
static void window_scrollback_start (Window *window)
{
if (window->display_buffer_size <= window->display_size)
{
term_beep();
return;
}
window->scrollback_top_of_display = window->top_of_scrollback;
recalculate_window_cursor_and_display_ip(window);
window_body_needs_redraw(window);
window_statusbar_needs_update(window);
}
/*
* Cancel out scrollback and holding stuff so you're left pointing at the
* "standard" place. Doesn't turn hold mode off, obviously.
*/
static void window_scrollback_end (Window *window)
{
if (window->scrollback_top_of_display)
window->scrollback_top_of_display = NULL;
if (window->holding_top_of_display)
window->holding_top_of_display = window->display_ip;
recalculate_window_cursor_and_display_ip(window);
window_body_needs_redraw(window);
window_statusbar_needs_update(window);
}
/*
* Scroll backwards from the last scrollback point, the last hold point,
* or the standard place.
*/
static void window_scrollback_backwards_lines (Window *window, int lines)
{
Display *new_top;
int new_lines;
if (window->scrollback_top_of_display == window->top_of_scrollback)
{
term_beep();
return;
}
if (window->scrollback_top_of_display == NULL)
{
if (window->holding_distance_from_display_ip > window->scrolling_distance_from_display_ip)
window->scrollback_top_of_display = window->holding_top_of_display;
else
window->scrollback_top_of_display = window->scrolling_top_of_display;
}
new_top = window->scrollback_top_of_display;
for (new_lines = 0; new_lines < lines; new_lines++)
{
if (new_top == window->top_of_scrollback)
break;
new_top = new_top->prev;
}
window->scrollback_top_of_display = new_top;
recalculate_window_cursor_and_display_ip(window);
window_body_needs_redraw(window);
window_statusbar_needs_update(window);
}
/*
* Scroll the scrollback (or hold mode) forward.
*/
static void window_scrollback_forwards_lines (Window *window, int lines)
{
Display *new_top;
int unholding;
int new_lines = 0;
if (window->scrollback_top_of_display)
{
new_top = window->scrollback_top_of_display;
unholding = 0;
}
else if (window->holding_top_of_display)
{
new_top = window->holding_top_of_display;
unholding = 1;
}
else
{
term_beep();
return;
}
for (new_lines = 0; new_lines < lines; new_lines++)
{
if (new_top == window->display_ip)
break;
new_top = new_top->next;
}
if (!unholding)
window->scrollback_top_of_display = new_top;
else
window->holding_top_of_display = new_top;
recalculate_window_cursor_and_display_ip(window);
window_body_needs_redraw(window);
window_statusbar_needs_update(window);
}
static void window_scrollback_to_string (Window *window, regex_t *preg)
{
Display *new_top;
if (window->scrollback_top_of_display)
new_top = window->scrollback_top_of_display;
else if (window->holding_distance_from_display_ip > window->scrolling_distance_from_display_ip)
new_top = window->holding_top_of_display;
else
new_top = window->scrolling_top_of_display;
while (new_top != window->top_of_scrollback)
{
/* Always move up a line before searching */
new_top = new_top->prev;
if (regexec(preg, new_top->line, 0, NULL, 0) == 0)
{
window->scrollback_top_of_display = new_top;
recalculate_window_cursor_and_display_ip(window);
window_body_needs_redraw(window);
window_statusbar_needs_update(window);
return;
}
}
term_beep();
}
static void window_scrollforward_to_string (Window *window, regex_t *preg)
{
Display *new_top;
if (window->scrollback_top_of_display)
new_top = window->scrollback_top_of_display;
else if (window->holding_distance_from_display_ip > window->scrolling_distance_from_display_ip)
new_top = window->holding_top_of_display;
else
new_top = window->scrolling_top_of_display;
while (new_top->next != window->display_ip)
{
/* Always move up a line before searching */
new_top = new_top->next;
if (regexec(preg, new_top->line, 0, NULL, 0) == 0)
{
window->scrollback_top_of_display = new_top;
recalculate_window_cursor_and_display_ip(window);
window_body_needs_redraw(window);
window_statusbar_needs_update(window);
return;
}
}
term_beep();
}
/* * * * * * * * */
static void window_scrollback_forward (Window *window)
{
int ratio = get_int_var(SCROLLBACK_RATIO_VAR);
int lines;
if (ratio < 1)
ratio = 1;
if (ratio > 100)
ratio = 100;
if ((lines = window->display_size * ratio / 100) < 1)
lines = 1;
window_scrollback_forwards_lines(window, lines);
}
static void window_scrollback_backward (Window *window)
{
int ratio = get_int_var(SCROLLBACK_RATIO_VAR);
int lines;
if (ratio < 1)
ratio = 1;
if (ratio > 100)
ratio = 100;
if ((lines = window->display_size * ratio / 100) < 1)
lines = 1;
window_scrollback_backwards_lines(window, lines);
}
void scrollback_forwards (char dumb, char *dumber)
{
window_scrollback_forward(current_window);
}
void scrollback_backwards (char dumb, char *dumber)
{
window_scrollback_backward(current_window);
}
void scrollback_end (char dumb, char *dumber)
{
window_scrollback_end(current_window);
}
void scrollback_start (char dumb, char *dumber)
{
window_scrollback_start(current_window);
}
/* HOLD MODE STUFF */
void unstop_all_windows (char dumb, char *dumber)
{
Window *tmp = NULL;
char my_off[4];
char * ptr;
while (traverse_all_windows(&tmp))
{
strcpy(my_off, "OFF");
ptr = my_off;
window_hold_mode(tmp, (char **)&ptr);
}
update_all_windows();
}
/* toggle_stop_screen: the BIND function TOGGLE_STOP_SCREEN */
void toggle_stop_screen (char unused, char *not_used)
{
char toggle[7], *p = toggle;
strlcpy(toggle, "TOGGLE", sizeof toggle);
window_hold_mode(current_window, (char **)&p);
update_all_windows();
}
/**************************************************************************/
/*
* Miscelaneous -- these probably belong somewhere else, but until then,
* theyre here.
*/
/*
* The "Window Cursor" tells the output routines where the next line of
* output to this window should go. "Window Top" is offset of the window's
* first line on the physical screen. So by adding "Window Top" to "Window
* Cursor", we know where to put the next line.
*
* However, as a special idiom, if "Window Cursor" is equal to the "Window
* Display Size", it points at the status bar; this is a special case which
* is always to be interpreted in one of two ways:
*
* "Window Scrollback Point" is not set: Scroll window before output
* "Window Scrollback Point" is set: Do not do any on output.
*
* In all cases where "Window Cursor" is less than "Window Display Size",
* output will occur.
*
* This function also recalculates "Window Distance From Top Of Display To
* the Insertion Point" which is used to decide whether to do output
* supression in hold mode and other places.
*/
void recalculate_window_cursor_and_display_ip (Window *window)
{
Display *tmp;
window->cursor = 0;
window->display_buffer_size = 0;
window->scrolling_distance_from_display_ip = -1;
window->holding_distance_from_display_ip = -1;
window->scrollback_distance_from_display_ip = -1;
window->display_counter = 1;
/* Recount and resequence the scrollback */
for (tmp = window->top_of_scrollback;; tmp = tmp->next)
{
window->display_buffer_size++;
tmp->count = window->display_counter++;
if (tmp == window->display_ip)
break;
}
/* Calculate the distances to the bottom of scrollback */
if (window->holding_top_of_display)
window->holding_distance_from_display_ip =
window->display_ip->count -
window->holding_top_of_display->count;
if (window->scrollback_top_of_display)
window->scrollback_distance_from_display_ip =
window->display_ip->count -
window->scrollback_top_of_display->count;
window->scrolling_distance_from_display_ip =
window->display_ip->count -
window->scrolling_top_of_display->count;
/* Auto-detect when scrollback should be turned off */
if (window->scrollback_distance_from_display_ip <=
window->holding_distance_from_display_ip ||
window->scrollback_distance_from_display_ip <=
window->scrolling_distance_from_display_ip)
{
window->scrollback_top_of_display = NULL;
window->scrollback_distance_from_display_ip = -1;
}
/* Figure out where the cursor is */
if (window->holding_distance_from_display_ip >= window->display_size)
window->cursor = window->display_size;
else if (window->scrolling_distance_from_display_ip >= window->display_size)
window->cursor = window->display_size;
else
window->cursor = window->scrolling_distance_from_display_ip;
}
/*
* This is used to set the current_window for the given screen. It handles
* last_window_refnum and making sure the window's status bar is updated
* (for the STATUS_WINDOW thing), and arranging for the windows to be updated.
* Its a bad idea to directly assign screen->current_window!
*/
static void set_screens_current_window (Screen *screen, Window *window)
{
if (!window)
{
window = get_window_by_refnum(screen->last_window_refnum);
/* Cant use a window that is now on a different screen */
/* Check check a window that doesnt exist, too! */
if (window && window->screen != screen)
window = NULL;
}
if (!window)
window = screen->window_list;
if (window->deceased)
panic("This window is dead.");
if (window->screen != screen)
panic("The window is not on that screen.");
if (!screen)
panic("Cannot set the invisible screen's current window.");
if (screen->current_window != window)
{
if (screen->current_window)
{
window_statusbar_needs_update(screen->current_window);
screen->last_window_refnum = screen->current_window->refnum;
}
screen->current_window = window;
window_statusbar_needs_update(screen->current_window);
}
if (current_window != window)
make_window_current(window);
window->priority = current_window_priority++;
#if 0 /* Can we get away with not doing this? */
update_all_windows();
#endif
}
void make_window_current_by_refnum (int refnum)
{
Window *new_win;
if (refnum == -1)
return;
if ((new_win = get_window_by_refnum(refnum)))
make_window_current(new_win);
else
say("Window [%d] doesnt exist any more. Punting.", refnum);
}
/*
* This is used to make the specified window the current window. This
* is preferable to directly doing the assign, because it can deal with
* finding a current window if the old one has gone away.
*/
void make_window_current (Window *window)
{
Window *old_current_window = current_window;
int old_screen, old_window;
int new_screen, new_winref;
if (!window)
current_window = last_input_screen->current_window;
else if (current_window != window)
current_window = window;
if (current_window == NULL)
current_window = last_input_screen->window_list;
if (current_window == NULL)
panic("make_window_current(NULL) -- can't find another window");
if (current_window->deceased)
panic("This window is dead and cannot be made current");
if (current_window == old_current_window)
return;
if (!old_current_window)
old_screen = old_window = -1;
else if (!old_current_window->screen)
old_screen = -1, old_window = old_current_window->refnum;
else
old_screen = old_current_window->screen->screennum,
old_window = old_current_window->refnum;
new_winref = current_window->refnum;
if (!current_window->screen)
new_screen = -1;
else
new_screen = current_window->screen->screennum;
do_hook(SWITCH_WINDOWS_LIST, "%d %d %d %d",
old_screen, old_window,
new_screen, new_winref);
}
/**************************************************************************/
/*
* This puts the given string into a scratch window. It ALWAYS suppresses
* any further action (by returning a FAIL, so rite() is not called).
*/
int change_line (Window *window, const unsigned char *str)
{
Display *my_line;
int cnt;
int chg_line;
chg_line = window->change_line;
window->change_line = -1;
/* Must have been asked to change a line */
if (chg_line == -1)
panic("This is not a scratch window.");
/* Outputting to a 0 size window is a no-op. */
if (window->display_size == 0)
return 0;
/* Must be within the bounds of the size of the window */
if (chg_line >= window->display_size)
panic("change_line is too big.");
/* Make sure that the line exists that we want to change */
while (window->scrolling_distance_from_display_ip <= chg_line)
add_to_display(window, empty_string);
/* Now find the line we want to change */
my_line = window->scrolling_top_of_display;
if (my_line == window->display_ip)
panic("Can't change line [%d] -- doesn't exist",
chg_line);
for (cnt = 0; cnt < chg_line; cnt++)
{
my_line = my_line->next;
if (my_line == window->display_ip)
panic("Can't change line [%d] -- doesn't exist",
chg_line);
}
/*
* Now change the line, move the logical cursor, and then let
* the caller (window_disp) output the new line.
*/
malloc_strcpy(&my_line->line, str);
window->cursor = chg_line;
return 1; /* Express a success */
}
void check_window_cursor (Window *window)
{
#if 0
if (window->scroll && window->cursor < window->display_size &&
window->cursor < window->scrolling_distance_from_display_ip)
{
recalculate_window_cursor_and_display_ip(window);
}
/* XXX This is a hack that covers up a bug elsewhere. */
if (window->hold_mode == 0 && window->autohold == 0 &&
window->distance_from_display_ip > window->display_size)
{
window_scrollback_end(window);
#if 0
yell("Unheld this window for you -- let #epic on efnet know!");
#endif
}
#endif
}
/* Used by function_windowctl */
/*
* $windowctl(REFNUMS)
* $windowctl(REFNUM window-desc)
* $windowctl(MAX)
* $windowctl(GET 0 [LIST])
* $windowctl(SET 0 [ITEM] [VALUE])
*
* [LIST] and [ITEM] are one of the following:
* REFNUM Unique integer that identifies one window
* NAME A name given to the window by user
* SERVER The server this window sends msgs to
* LAST_SERVER If disconnected, the last server connected.
* PRIORITY The "current window" priority on this server.
* VISIBLE Whether this window is on a screen or not
* TOP
* BOTTOM
* CURSOR
* NOSCROLLCURSOR
* ABSOLUTE_SIZE
* SCROLL
* CHANGE_LINE
* OLD_SIZE
* UPDATE
* MISCFLAGS
* BEEP_ALWAYS
* NOTIFY_LEVEL
* WINDOW_LEVEL
* SKIP
* COLUMNS
* PROMPT
* STATUS_FORMAT
* STATUS_FORMAT1
* STATUS_FORMAT2
* DISPLAY_BUFFER_SIZE
* DISPLAY_BUFFER_MAX
* DISPLAY_SIZE
* HOLD_MODE
* AUTOHOLD
* LINES_HELD
* HOLD_INTERVAL
* LAST_LINES_HELD
* DISTANCE_FROM_DISPLAY_IP
* WAITING_CHANNEL
* BIND_CHANNEL
* QUERY_NICK
* NICKLIST
* LASTLOG_LEVEL
* LASTLOG_SIZE
* LASTLOG_MAX
* LOGGING
* LOGFILE
* DECEASED
*/
char *windowctl (char *input)
{
int refnum, len;
char *listc;
char *ret = NULL;
Window *w;
GET_STR_ARG(listc, input);
len = strlen(listc);
if (!my_strnicmp(listc, "REFNUM", len)) {
char *windesc;
GET_STR_ARG(windesc, input);
if (!(w = get_window_by_desc(windesc)))
RETURN_EMPTY;
RETURN_INT(w->refnum);
} else if (!my_strnicmp(listc, "REFNUMS", len)) {
w = NULL;
while (traverse_all_windows(&w))
malloc_strcat_wordlist(&ret, space, ltoa(w->refnum));
RETURN_MSTR(ret);
} else if (!my_strnicmp(listc, "NEW", len)) {
} else if (!my_strnicmp(listc, "GET", len)) {
GET_INT_ARG(refnum, input);
if (!(w = get_window_by_refnum(refnum)))
RETURN_EMPTY;
GET_STR_ARG(listc, input);
len = strlen(listc);
if (!my_strnicmp(listc, "REFNUM", len)) {
RETURN_INT(w->refnum);
} else if (!my_strnicmp(listc, "NAME", len)) {
RETURN_STR(w->name);
} else if (!my_strnicmp(listc, "SERVER", len)) {
RETURN_INT(w->server);
} else if (!my_strnicmp(listc, "LAST_SERVER", len)) {
RETURN_INT(w->last_server);
} else if (!my_strnicmp(listc, "PRIORITY", len)) {
RETURN_INT(w->priority);
} else if (!my_strnicmp(listc, "VISIBLE", len)) {
RETURN_INT(w->screen ? 1 : 0);
} else if (!my_strnicmp(listc, "TOP", len)) {
RETURN_INT(w->top);
} else if (!my_strnicmp(listc, "BOTTOM", len)) {
RETURN_INT(w->bottom);
} else if (!my_strnicmp(listc, "CURSOR", len)) {
RETURN_INT(w->cursor);
} else if (!my_strnicmp(listc, "NOSCROLLCURSOR", len)) {
RETURN_INT(w->noscrollcursor);
} else if (!my_strnicmp(listc, "FIXED", len)) {
RETURN_INT(w->absolute_size);
} else if (!my_strnicmp(listc, "SCROLL", len)) {
RETURN_INT(w->scroll);
} else if (!my_strnicmp(listc, "CHANGE_LINE", len)) {
RETURN_INT(w->change_line);
} else if (!my_strnicmp(listc, "OLD_SIZE", len)) {
RETURN_INT(w->old_size);
} else if (!my_strnicmp(listc, "UPDATE", len)) {
RETURN_INT(w->update);
} else if (!my_strnicmp(listc, "MISCFLAGS", len)) {
RETURN_INT(w->miscflags);
} else if (!my_strnicmp(listc, "BEEP_ALWAYS", len)) {
RETURN_INT(w->beep_always);
} else if (!my_strnicmp(listc, "NOTIFY_LEVEL", len)) {
RETURN_STR(bits_to_lastlog_level(w->notify_level));
} else if (!my_strnicmp(listc, "WINDOW_LEVEL", len)) {
RETURN_STR(bits_to_lastlog_level(w->window_level));
} else if (!my_strnicmp(listc, "SKIP", len)) {
RETURN_INT(w->skip);
} else if (!my_strnicmp(listc, "COLUMNS", len)) {
RETURN_INT(w->columns);
} else if (!my_strnicmp(listc, "PROMPT", len)) {
RETURN_STR(w->prompt);
} else if (!my_strnicmp(listc, "DOUBLE", len)) {
RETURN_INT(w->status.double_status);
} else if (!my_strnicmp(listc, "STATUS_FORMAT", len)) {
RETURN_STR(w->status.line[0].raw);
} else if (!my_strnicmp(listc, "STATUS_FORMAT1", len)) {
RETURN_STR(w->status.line[1].raw);
} else if (!my_strnicmp(listc, "STATUS_FORMAT2", len)) {
RETURN_STR(w->status.line[2].raw);
} else if (!my_strnicmp(listc, "STATUS_LINE", len)) {
RETURN_STR(w->status.line[0].result);
} else if (!my_strnicmp(listc, "STATUS_LINE1", len)) {
RETURN_STR(w->status.line[1].result);
} else if (!my_strnicmp(listc, "STATUS_LINE2", len)) {
RETURN_STR(w->status.line[2].result);
} else if (!my_strnicmp(listc, "DISPLAY_BUFFER_SIZE", len)) {
RETURN_INT(w->display_buffer_size);
} else if (!my_strnicmp(listc, "DISPLAY_BUFFER_MAX", len)) {
RETURN_INT(w->display_buffer_max);
} else if (!my_strnicmp(listc, "SCROLLING_DISTANCE", len)) {
RETURN_INT(w->scrolling_distance_from_display_ip);
} else if (!my_strnicmp(listc, "HOLDING_DISTANCE", len)) {
RETURN_INT(w->holding_distance_from_display_ip);
} else if (!my_strnicmp(listc, "SCROLLBACK_DISTANCE", len)) {
RETURN_INT(w->scrollback_distance_from_display_ip);
} else if (!my_strnicmp(listc, "DISPLAY_COUNTER", len)) {
RETURN_INT(w->display_counter);
} else if (!my_strnicmp(listc, "HOLD_SLIDER", len)) {
RETURN_INT(w->hold_slider);
} else if (!my_strnicmp(listc, "HOLD_INTERVAL", len)) {
RETURN_INT(w->hold_interval);
} else if (!my_strnicmp(listc, "LAST_LINES_HELD", len)) {
RETURN_INT(w->last_lines_held);
} else if (!my_strnicmp(listc, "WAITING_CHANNEL", len)) {
RETURN_STR(w->waiting_channel);
} else if (!my_strnicmp(listc, "BIND_CHANNEL", len)) {
RETURN_STR(w->bind_channel);
} else if (!my_strnicmp(listc, "QUERY_NICK", len)) {
RETURN_STR(w->query_nick);
} else if (!my_strnicmp(listc, "NICKLIST", len)) {
RETURN_MSTR(get_nicklist_by_window(w));
} else if (!my_strnicmp(listc, "LASTLOG_LEVEL", len)) {
RETURN_STR(bits_to_lastlog_level(w->lastlog_level));
} else if (!my_strnicmp(listc, "LASTLOG_SIZE", len)) {
RETURN_INT(w->lastlog_size);
} else if (!my_strnicmp(listc, "LASTLOG_MAX", len)) {
RETURN_INT(w->lastlog_max);
} else if (!my_strnicmp(listc, "LOGGING", len)) {
RETURN_INT(w->log);
} else if (!my_strnicmp(listc, "LOGFILE", len)) {
RETURN_STR(w->logfile);
} else if (!my_strnicmp(listc, "SWAPPABLE", len)) {
RETURN_INT(w->swappable);
} else if (!my_strnicmp(listc, "SCROLLADJ", len)) {
RETURN_INT(w->swappable);
} else if (!my_strnicmp(listc, "DECEASED", len)) {
RETURN_INT(w->deceased);
}
} else if (!my_strnicmp(listc, "SET", len)) {
GET_INT_ARG(refnum, input);
if (!(w = get_window_by_refnum(refnum)))
RETURN_EMPTY;
GET_STR_ARG(listc, input);
len = strlen(listc);
#if 0
if (!my_strnicmp(listc, "REFNUM", len)) {
} else if (!my_strnicmp(listc, "NAME", len)) {
} else if (!my_strnicmp(listc, "SERVER", len)) {
} else if (!my_strnicmp(listc, "LAST_SERVER", len)) {
} else if (!my_strnicmp(listc, "PRIORITY", len)) {
} else if (!my_strnicmp(listc, "TOP", len)) {
} else if (!my_strnicmp(listc, "BOTTOM", len)) {
} else if (!my_strnicmp(listc, "CURSOR", len)) {
} else if (!my_strnicmp(listc, "NOSCROLLCURSOR", len)) {
} else if (!my_strnicmp(listc, "FIXED", len)) {
} else if (!my_strnicmp(listc, "SCROLL", len)) {
} else if (!my_strnicmp(listc, "CHANGE_LINE", len)) {
} else if (!my_strnicmp(listc, "OLD_SIZE", len)) {
} else if (!my_strnicmp(listc, "UPDATE", len)) {
} else if (!my_strnicmp(listc, "MISCFLAGS", len)) {
} else if (!my_strnicmp(listc, "BEEP_ALWAYS", len)) {
} else if (!my_strnicmp(listc, "NOTIFY_LEVEL", len)) {
} else if (!my_strnicmp(listc, "WINDOW_LEVEL", len)) {
} else if (!my_strnicmp(listc, "SKIP", len)) {
} else if (!my_strnicmp(listc, "COLUMNS", len)) {
} else if (!my_strnicmp(listc, "PROMPT", len)) {
} else if (!my_strnicmp(listc, "STATUS_FORMAT", len)) {
} else if (!my_strnicmp(listc, "STATUS_FORMAT1", len)) {
} else if (!my_strnicmp(listc, "STATUS_FORMAT2", len)) {
} else if (!my_strnicmp(listc, "STATUS_LINE", len)) {
} else if (!my_strnicmp(listc, "STATUS_LINE1", len)) {
} else if (!my_strnicmp(listc, "STATUS_LINE2", len)) {
} else if (!my_strnicmp(listc, "DISPLAY_BUFFER_SIZE", len)) {
} else if (!my_strnicmp(listc, "DISPLAY_BUFFER_MAX", len)) {
} else if (!my_strnicmp(listc, "DISPLAY_BUFFER_SIZE", len)) {
} else if (!my_strnicmp(listc, "DISPLAY_BUFFER_MAX", len)) {
} else if (!my_strnicmp(listc, "SCROLLING_DISTANCE", len)) {
} else if (!my_strnicmp(listc, "HOLDING_DISTANCE", len)) {
} else if (!my_strnicmp(listc, "SCROLLBACK_DISTANCE", len)) {
} else if (!my_strnicmp(listc, "DISPLAY_COUNTER", len)) {
} else if (!my_strnicmp(listc, "HOLD_SLIDER", len)) {
} else if (!my_strnicmp(listc, "HOLD_INTERVAL", len)) {
} else if (!my_strnicmp(listc, "LAST_LINES_HELD", len)) {
} else if (!my_strnicmp(listc, "WAITING_CHANNEL", len)) {
} else if (!my_strnicmp(listc, "BIND_CHANNEL", len)) {
} else if (!my_strnicmp(listc, "QUERY_NICK", len)) {
} else if (!my_strnicmp(listc, "NICKLIST", len)) {
} else if (!my_strnicmp(listc, "LASTLOG_LEVEL", len)) {
} else if (!my_strnicmp(listc, "LASTLOG_SIZE", len)) {
} else if (!my_strnicmp(listc, "LASTLOG_MAX", len)) {
} else if (!my_strnicmp(listc, "LOGGING", len)) {
} else if (!my_strnicmp(listc, "LOGFILE", len)) {
} else if (!my_strnicmp(listc, "SWAPPABLE", len)) {
} else if (!my_strnicmp(listc, "SCROLLADJ", len)) {
} else if (!my_strnicmp(listc, "DECEASED", len)) {
}
#endif
} else
RETURN_EMPTY;
update_all_status();
update_all_windows();
RETURN_EMPTY;
}
static int count_fixed_windows (Screen *s)
{
int count = 0;
Window *w;
for (w = s->window_list; w; w = w->next)
if (w->absolute_size && w->skip)
count++;
return count;
}
|