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
|
/*
| ee (easy editor)
|
| An easy to use, simple screen oriented editor.
|
| written by Hugh Mahon
|
| THIS MATERIAL IS PROVIDED "AS IS". THERE ARE
| NO WARRANTIES OF ANY KIND WITH REGARD TO THIS
| MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND
| FITNESS FOR A PARTICULAR PURPOSE. Neither
| Hewlett-Packard nor Hugh Mahon shall be liable
| for errors contained herein, nor for
| incidental or consequential damages in
| connection with the furnishing, performance or
| use of this material. Neither Hewlett-Packard
| nor Hugh Mahon assumes any responsibility for
| the use or reliability of this software or
| documentation. This software and
| documentation is totally UNSUPPORTED. There
| is no support contract available. Hewlett-
| Packard has done NO Quality Assurance on ANY
| of the program or documentation. You may find
| the quality of the materials inferior to
| supported materials.
|
| This software is not a product of Hewlett-Packard, Co., or any
| other company. No support is implied or offered with this software.
| You've got the source, and you're on your own.
|
| This software may be distributed under the terms of Larry Wall's
| Artistic license, a copy of which is included in this distribution.
|
| This notice must be included with this software and any derivatives.
|
| This editor was purposely developed to be simple, both in
| interface and implementation. This editor was developed to
| address a specific audience: the user who is new to computers
| (especially UNIX).
|
| ee is not aimed at technical users; for that reason more
| complex features were intentionally left out. In addition,
| ee is intended to be compiled by people with little computer
| experience, which means that it needs to be small, relatively
| simple in implementation, and portable.
|
| This software and documentation contains
| proprietary information which is protected by
| copyright. All rights are reserved.
|
| $Header: /home/hugh/sources/old_ae/RCS/ee.c,v 1.89 1996/02/25 05:07:40 hugh Exp $
|
*/
char *ee_copyright_message =
"Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995 Hugh Mahon ";
char *ee_long_notice[] = {
"This software and documentation contains",
"proprietary information which is protected by",
"copyright. All rights are reserved."
};
char *version = "@(#) ee, version 1.2.6 $Revision: 1.89 $";
#ifdef NCURSE
#include "new_curse.h"
#else
#include <curses.h>
#endif
#include <signal.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <pwd.h>
#ifdef HAS_SYS_WAIT
#include <sys/wait.h>
#endif
#ifdef HAS_STDLIB
#include <stdlib.h>
#endif
#ifdef HAS_STDARG
#include <stdarg.h>
#endif
#ifdef HAS_UNISTD
#include <unistd.h>
#endif
#ifdef HAS_CTYPE
#include <ctype.h>
#endif
#ifndef NO_CATGETS
#include <locale.h>
#include <nl_types.h>
nl_catd catalog;
#else
#define catgetlocal(a, b) (b)
#endif /* NO_CATGETS */
#ifndef SIGCHLD
#define SIGCHLD SIGCLD
#endif
#define TAB 9
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
/*
| defines for type of data to show in info window
*/
#define CONTROL_KEYS 1
#define COMMANDS 2
struct text {
char *line; /* line of characters */
int line_number; /* line number */
int line_length; /* actual number of characters in the line */
int max_length; /* maximum number of characters the line handles */
struct text *next_line; /* next line of text */
struct text *prev_line; /* previous line of text */
};
struct text *first_line; /* first line of current buffer */
struct text *dlt_line; /* structure for info on deleted line */
struct text *curr_line; /* current line cursor is on */
struct text *tmp_line; /* temporary line pointer */
struct text *srch_line; /* temporary pointer for search routine */
struct files { /* structure to store names of files to be edited*/
char *name; /* name of file */
struct files *next_name;
};
struct files *top_of_stack = NULL;
int d_wrd_len; /* length of deleted word */
int position; /* offset in bytes from begin of line */
int scr_pos; /* horizontal position */
int scr_vert; /* vertical position on screen */
int scr_horz; /* horizontal position on screen */
int tmp_vert, tmp_horz;
int input_file; /* indicate to read input file */
int recv_file; /* indicate reading a file */
int edit; /* continue executing while true */
int gold; /* 'gold' function key pressed */
int fildes; /* file descriptor */
int case_sen; /* case sensitive search flag */
int last_line; /* last line for text display */
int last_col; /* last column for text display */
int horiz_offset = 0; /* offset from left edge of text */
int clear_com_win; /* flag to indicate com_win needs clearing */
int text_changes = FALSE; /* indicate changes have been made to text */
int get_fd; /* file descriptor for reading a file */
int info_window = TRUE; /* flag to indicate if help window visible */
int info_type = CONTROL_KEYS; /* flag to indicate type of info to display */
int expand_tabs = TRUE; /* flag for expanding tabs */
int right_margin = 0; /* the right margin */
int observ_margins = TRUE; /* flag for whether margins are observed */
int shell_fork;
int temp_stdin; /* temporary storage for stdin */
int temp_stdout; /* temp storage for stdout descriptor */
int temp_stderr; /* temp storage for stderr descriptor */
int pipe_out[2]; /* pipe file desc for output */
int pipe_in[2]; /* pipe file descriptors for input */
int out_pipe; /* flag that info is piped out */
int in_pipe; /* flag that info is piped in */
int formatted = FALSE; /* flag indicating paragraph formatted */
int auto_format = FALSE; /* flag for auto_format mode */
int restricted = FALSE; /* flag to indicate restricted mode */
int nohighlight = FALSE; /* turns off highlighting */
int eightbit = TRUE; /* eight bit character flag */
int local_LINES = 0; /* copy of LINES, to detect when win resizes */
int local_COLS = 0; /* copy of COLS, to detect when win resizes */
int curses_initialized = FALSE; /* flag indicating if curses has been started*/
int emacs_keys_mode = FALSE; /* mode for if emacs key binings are used */
char *point; /* points to current position in line */
char *srch_str; /* pointer for search string */
char *u_srch_str; /* pointer to non-case sensitive search */
char *srch_1; /* pointer to start of suspect string */
char *srch_2; /* pointer to next character of string */
char *srch_3;
char *in_file_name = NULL; /* name of input file */
char *tmp_file; /* temporary file name */
char d_char; /* deleted character */
char *d_word; /* deleted word */
char *d_line; /* deleted line */
char in_string[513]; /* buffer for reading a file */
char *print_command = "lp"; /* string to use for the print command */
char *start_at_line = NULL; /* move to this line at start of session*/
int in; /* input character */
FILE *temp_fp; /* temporary file pointer */
FILE *bit_bucket; /* file pointer to /dev/null */
char *table[] = {
"^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "\t", "^J",
"^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U",
"^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_"
};
WINDOW *com_win;
WINDOW *text_win;
WINDOW *help_win;
WINDOW *info_win;
#if defined(__STDC__) || defined(__cplusplus)
#define P_(s) s
#else
#define P_(s) ()
#endif
/*
| The following structure allows menu items to be flexibly declared.
| The first item is the string describing the selection, the second
| is the address of the procedure to call when the item is selected,
| and the third is the argument for the procedure.
|
| For those systems with i18n, the string should be accompanied by a
| catalog number. The 'int *' should be replaced with 'void *' on
| systems with that type.
|
| The first menu item will be the title of the menu, with NULL
| parameters for the procedure and argument, followed by the menu items.
|
| If the procedure value is NULL, the menu item is displayed, but no
| procedure is called when the item is selected. The number of the
| item will be returned. If the third (argument) parameter is -1, no
| argument is given to the procedure when it is called.
*/
struct menu_entries {
char *item_string;
int (*procedure)P_((struct menu_entries *));
struct menu_entries *ptr_argument;
int (*iprocedure)P_((int));
void (*nprocedure)P_((void));
unsigned int argument;
};
int main P_((int argc, char *argv[]));
char *resiz_line P_((int factor, struct text *rline, int rpos));
void insert P_((int character));
void delete P_((int disp));
void scanline P_((char *pos));
int tabshift P_((int temp_int));
int out_char P_((WINDOW *window, int character, int column));
int len_char P_((int character, int column));
void draw_line P_((int vertical, int horiz, char *ptr, int t_pos, int length));
void insert_line P_((int disp));
struct text *txtalloc P_((void));
struct files *name_alloc P_((void));
char *next_word P_((char *string));
void prev_word P_((void));
void control P_((void));
void emacs_control P_((void));
void bottom P_((void));
void top P_((void));
void nextline P_((void));
void prevline P_((void));
void left P_((int disp));
void right P_((int disp));
void find_pos P_((void));
void up P_((void));
void down P_((void));
void function_key P_((void));
void print_buffer P_((void));
void command_prompt P_((void));
void command P_((char *cmd_str1));
int scan P_((char *line, int offset, int column));
char *get_string P_((char *prompt, int advance));
int compare P_((char *string1, char *string2, int sensitive));
void goto_line P_((char *cmd_str));
void midscreen P_((int line, char *pnt));
void get_options P_((int numargs, char *arguments[]));
void check_fp P_((void));
void get_file P_((char *file_name));
void get_line P_((int length, char *in_string, int *append));
void draw_screen P_((void));
void finish P_((void));
int quit P_((int noverify));
void edit_abort P_((int arg));
void delete_text P_((void));
int write_file P_((char *file_name));
int search P_((int display_message));
void search_prompt P_((void));
void del_char P_((void));
void undel_char P_((void));
void del_word P_((void));
void undel_word P_((void));
void del_line P_((void));
void undel_line P_((void));
void adv_word P_((void));
void move_rel P_((char *direction, int lines));
void eol P_((void));
void bol P_((void));
void adv_line P_((void));
void sh_command P_((char *string));
void set_up_term P_((void));
void resize_check P_((void));
int menu_op P_((struct menu_entries *));
void paint_menu P_((struct menu_entries menu_list[], int max_width, int max_height, int list_size, int top_offset, WINDOW *menu_win, int off_start, int vert_size));
void help P_((void));
void paint_info_win P_((void));
void no_info_window P_((void));
void create_info_window P_((void));
int file_op P_((int arg));
void shell_op P_((void));
void leave_op P_((void));
void redraw P_((void));
int Blank_Line P_((struct text *test_line));
void Format P_((void));
void ee_init P_((void));
void dump_ee_conf P_((void));
void echo_string P_((char *string));
void spell_op P_((void));
void ispell_op P_((void));
int first_word_len P_((struct text *test_line));
void Auto_Format P_((void));
void modes_op P_((void));
char *is_in_string P_((char *string, char *substring));
char *resolve_name P_((char *name));
int restrict_mode P_((void));
int unique_test P_((char *string, char *list[]));
void strings_init P_((void));
#undef P_
/*
| allocate space here for the strings that will be in the menu
*/
struct menu_entries modes_menu[] = {
{"", NULL, NULL, NULL, NULL, 0},
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, dump_ee_conf, -1},
{NULL, NULL, NULL, NULL, NULL, -1}
};
char *mode_strings[10];
#define NUM_MODES_ITEMS 9
struct menu_entries config_dump_menu[] = {
{"", NULL, NULL, NULL, NULL, 0},
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, NULL, -1},
{NULL, NULL, NULL, NULL, NULL, -1}
};
struct menu_entries leave_menu[] = {
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, finish, -1},
{"", NULL, NULL, quit, NULL, TRUE},
{NULL, NULL, NULL, NULL, NULL, -1}
};
#define READ_FILE 1
#define WRITE_FILE 2
#define SAVE_FILE 3
struct menu_entries file_menu[] = {
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, file_op, NULL, READ_FILE},
{"", NULL, NULL, file_op, NULL, WRITE_FILE},
{"", NULL, NULL, file_op, NULL, SAVE_FILE},
{"", NULL, NULL, NULL, print_buffer, -1},
{NULL, NULL, NULL, NULL, NULL, -1}
};
struct menu_entries search_menu[] = {
{"", NULL, NULL, NULL, NULL, 0},
{"", NULL, NULL, NULL, search_prompt, -1},
{"", NULL, NULL, search, NULL, TRUE},
{NULL, NULL, NULL, NULL, NULL, -1}
};
struct menu_entries spell_menu[] = {
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, spell_op, -1},
{"", NULL, NULL, NULL, ispell_op, -1},
{NULL, NULL, NULL, NULL, NULL, -1}
};
struct menu_entries misc_menu[] = {
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, Format, -1},
{"", NULL, NULL, NULL, shell_op, -1},
{"", menu_op, spell_menu, NULL, NULL, -1},
{NULL, NULL, NULL, NULL, NULL, -1}
};
struct menu_entries main_menu[] = {
{"", NULL, NULL, NULL, NULL, -1},
{"", NULL, NULL, NULL, leave_op, -1},
{"", NULL, NULL, NULL, help, -1},
{"", menu_op, file_menu, NULL, NULL, -1},
{"", NULL, NULL, NULL, redraw, -1},
{"", NULL, NULL, NULL, modes_op, -1},
{"", menu_op, search_menu, NULL, NULL, -1},
{"", menu_op, misc_menu, NULL, NULL, -1},
{NULL, NULL, NULL, NULL, NULL, -1}
};
char *help_text[22];
char *control_keys[5];
char *emacs_help_text[22];
char *emacs_control_keys[5];
char *command_strings[5];
char *commands[30];
char *init_strings[20];
#define MENU_WARN 1
#define max_alpha_char 36
/*
| Declarations for strings for localization
*/
char *com_win_message; /* to be shown in com_win if no info window */
char *no_file_string;
char *ascii_code_str;
char *printer_msg_str;
char *command_str;
char *file_write_prompt_str;
char *file_read_prompt_str;
char *char_str;
char *unkn_cmd_str;
char *non_unique_cmd_msg;
char *line_num_str;
char *line_len_str;
char *current_file_str;
char *usage0;
char *usage1;
char *usage2;
char *usage3;
char *usage4;
char *file_is_dir_msg;
char *new_file_msg;
char *cant_open_msg;
char *open_file_msg;
char *file_read_fin_msg;
char *reading_file_msg;
char *read_only_msg;
char *file_read_lines_msg;
char *save_file_name_prompt;
char *file_not_saved_msg;
char *changes_made_prompt;
char *yes_char;
char *file_exists_prompt;
char *create_file_fail_msg;
char *writing_file_msg;
char *file_written_msg;
char *searching_msg;
char *str_not_found_msg;
char *search_prompt_str;
char *exec_err_msg;
char *continue_msg;
char *menu_cancel_msg;
char *menu_size_err_msg;
char *press_any_key_msg;
char *shell_prompt;
char *formatting_msg;
char *shell_echo_msg;
char *spell_in_prog_msg;
char *margin_prompt;
char *restricted_msg;
char *ON;
char *OFF;
char *HELP;
char *WRITE;
char *READ;
char *LINE;
char *FILE_str;
char *CHARACTER;
char *REDRAW;
char *RESEQUENCE;
char *AUTHOR;
char *VERSION;
char *CASE;
char *NOCASE;
char *EXPAND;
char *NOEXPAND;
char *Exit_string;
char *QUIT_string;
char *INFO;
char *NOINFO;
char *MARGINS;
char *NOMARGINS;
char *AUTOFORMAT;
char *NOAUTOFORMAT;
char *Echo;
char *PRINTCOMMAND;
char *RIGHTMARGIN;
char *HIGHLIGHT;
char *NOHIGHLIGHT;
char *EIGHTBIT;
char *NOEIGHTBIT;
char *EMACS_string;
char *NOEMACS_string;
char *conf_dump_err_msg;
char *conf_dump_success_msg;
char *conf_not_saved_msg;
char *ree_no_file_msg;
char *cancel_string;
char *menu_too_lrg_msg;
char *more_above_str, *more_below_str;
#ifndef __STDC__
#ifndef HAS_STDLIB
extern char *malloc();
extern char *realloc();
extern char *getenv();
FILE *fopen(); /* declaration for open function */
#endif /* HAS_STDLIB */
#endif /* __STDC__ */
int
main(argc, argv) /* beginning of main program */
int argc;
char *argv[];
{
int counter;
for (counter = 1; counter < 24; counter++)
signal(counter, SIG_IGN);
signal(SIGCHLD, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGINT, edit_abort);
d_char = 0;
d_word = malloc(150);
*d_word = (char) NULL;
d_line = NULL;
dlt_line = txtalloc();
dlt_line->line = d_line;
curr_line = first_line = txtalloc();
curr_line->line = point = malloc(10);
curr_line->line_length = 1;
curr_line->max_length = 10;
curr_line->prev_line = NULL;
curr_line->next_line = NULL;
curr_line->line_number = 1;
srch_str = NULL;
u_srch_str = NULL;
position = 1;
scr_pos =0;
scr_vert = 0;
scr_horz = 0;
bit_bucket = fopen("/dev/null", "w");
edit = TRUE;
gold = case_sen = FALSE;
shell_fork = TRUE;
strings_init();
ee_init();
if (argc > 0 )
get_options(argc, argv);
set_up_term();
if (right_margin == 0)
right_margin = COLS - 1;
if (top_of_stack == NULL)
{
if (restrict_mode())
{
wmove(com_win, 0, 0);
werase(com_win);
wprintw(com_win, ree_no_file_msg);
wrefresh(com_win);
edit_abort(0);
}
wprintw(com_win, no_file_string);
wrefresh(com_win);
}
else
check_fp();
clear_com_win = TRUE;
while(edit)
{
wrefresh(text_win);
in = wgetch(text_win);
if (in == -1)
exit(0);
resize_check();
if (clear_com_win)
{
clear_com_win = FALSE;
wmove(com_win, 0, 0);
werase(com_win);
if (!info_window)
{
wprintw(com_win, "%s", com_win_message);
}
wrefresh(com_win);
}
if (in > 255)
function_key();
else if ((in == '\10') || (in == 127))
delete(TRUE);
else if ((in > 31) || (in == 9))
insert(in);
else if ((in >= 0) && (in <= 31))
{
if (emacs_keys_mode)
emacs_control();
else
control();
}
}
return(0);
}
char *
resiz_line(factor, rline, rpos) /* resize the line to length + factor*/
int factor; /* resize factor */
struct text *rline; /* position in line */
int rpos;
{
char *rpoint;
int resiz_var;
rline->max_length += factor;
rpoint = rline->line = realloc(rline->line, rline->max_length );
for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++)
rpoint++;
return(rpoint);
}
void
insert(character) /* insert character into line */
int character; /* new character */
{
int counter;
int value;
char *temp; /* temporary pointer */
char *temp2; /* temporary pointer */
if ((character == '\011') && (expand_tabs))
{
counter = len_char('\011', scr_horz);
for (; counter > 0; counter--)
insert(' ');
if (auto_format)
Auto_Format();
return;
}
text_changes = TRUE;
if ((curr_line->max_length - curr_line->line_length) < 5)
point = resiz_line(10, curr_line, position);
curr_line->line_length++;
temp = point;
counter = position;
while (counter < curr_line->line_length) /* find end of line */
{
counter++;
temp++;
}
temp++; /* increase length of line by one */
while (point < temp)
{
temp2=temp - 1;
*temp= *temp2; /* shift characters over by one */
temp--;
}
*point = character; /* insert new character */
wclrtoeol(text_win);
if (((character >= 0) && (character < ' ')) || (character >= 127)) /* check for TAB character*/
{
scr_pos = scr_horz += out_char(text_win, character, scr_horz);
point++;
position++;
}
else
{
waddch(text_win, character);
scr_pos = ++scr_horz;
point++;
position ++;
}
if ((observ_margins) && (right_margin < scr_pos))
{
counter = position;
while (scr_pos > right_margin)
prev_word();
if (scr_pos == 0)
{
while (position < counter)
right(TRUE);
}
else
{
counter -= position;
insert_line(TRUE);
for (value = 0; value < counter; value++)
right(TRUE);
}
}
if ((scr_horz - horiz_offset) > last_col)
{
horiz_offset += 8;
midscreen(scr_vert, point);
}
if ((auto_format) && (character == ' ') && (!formatted))
Auto_Format();
else if ((character != ' ') && (character != '\t'))
formatted = FALSE;
draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
}
void
delete(disp) /* delete character */
int disp;
{
char *tp;
char *temp2;
struct text *temp_buff;
int temp_vert;
int temp_pos;
if (point != curr_line->line) /* if not at beginning of line */
{
text_changes = TRUE;
temp2 = tp = point;
tp--;
point--;
if ((*tp >= '\000') && (*tp < ' ')) /* check for TAB */
scanline(tp);
else
--scr_horz;
scr_pos = scr_horz;
if (in == 8)
d_char = *point; /* save deleted character */
temp_pos = --position;
curr_line->line_length--;
while (temp_pos <= curr_line->line_length)
{
temp_pos++;
*tp= *temp2;
tp++;
temp2++;
}
if (scr_horz < horiz_offset)
{
horiz_offset -= 8;
midscreen(scr_vert, point);
}
}
else if (curr_line->prev_line != NULL)
{
text_changes = TRUE;
left(disp); /* go to previous line */
temp_buff = curr_line->next_line;
point = resiz_line(temp_buff->line_length, curr_line, position);
if (temp_buff->next_line != NULL)
temp_buff->next_line->prev_line = curr_line;
curr_line->next_line = temp_buff->next_line;
temp2 = temp_buff->line;
if (in == 8)
d_char = '\n';
tp = point;
temp_pos = 1;
while (temp_pos < temp_buff->line_length)
{
curr_line->line_length++;
temp_pos++;
*tp = *temp2;
tp++;
temp2++;
}
*tp = (char) NULL;
free(temp_buff->line);
free(temp_buff);
temp_buff = curr_line;
temp_vert = scr_vert;
scr_pos = scr_horz;
if (scr_vert < last_line)
{
wmove(text_win, scr_vert + 1, 0);
wdeleteln(text_win);
}
while ((temp_buff != NULL) && (temp_vert < last_line))
{
temp_buff = temp_buff->next_line;
temp_vert++;
}
if ((temp_vert == last_line) && (temp_buff != NULL))
{
tp = temp_buff->line;
wmove(text_win, last_line,0);
wclrtobot(text_win);
draw_line(last_line, 0, tp, 1, temp_buff->line_length);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
}
}
draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
formatted = FALSE;
}
void
scanline(pos) /* find the proper horizontal position for the pointer */
char *pos;
{
int temp;
char *ptr;
ptr = curr_line->line;
temp = 0;
while (ptr < pos)
{
if ((*ptr >= 0) && (*ptr <= 8))
temp += 2;
else if (*ptr == 9)
temp += tabshift(temp);
else if ((*ptr >= 10) && (*ptr <= 31))
temp += 2;
else if ((*ptr >= 32) && (*ptr < 127))
temp++;
else if (*ptr == 127)
temp += 2;
else if (!eightbit)
temp += 5;
else
temp++;
ptr++;
}
scr_horz = temp;
if ((scr_horz - horiz_offset) > last_col)
{
horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
midscreen(scr_vert, point);
}
else if (scr_horz < horiz_offset)
{
horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
midscreen(scr_vert, point);
}
}
int
tabshift(temp_int) /* give the number of spaces to shift */
int temp_int;
{
int leftover;
leftover = ((temp_int + 1) % 8);
if (leftover == 0)
return (1);
else
return (9 - leftover);
}
int
out_char(window, character, column) /* output non-printing character */
WINDOW *window;
char character;
int column;
{
int i1, i2;
char *string;
char string2[8];
if (character == TAB)
{
i1 = tabshift(column);
for (i2 = 0;
(i2 < i1) && (((column+i2+1)-horiz_offset) < last_col); i2++)
{
waddch(window, ' ');
}
return(i1);
}
else if ((character >= '\0') && (character < ' '))
{
string = table[(int) character];
}
else if ((character < 0) || (character >= 127))
{
if (character == 127)
string = "^?";
else if (!eightbit)
{
sprintf(string2, "<%d>", (character < 0) ? (character + 256) : character);
string = string2;
}
else
{
waddch(window, (unsigned char)character );
return(1);
}
}
else
{
waddch(window, (unsigned char)character);
return(1);
}
for (i2 = 0; (string[i2] != (char) NULL) && (((column+i2+1)-horiz_offset) < last_col); i2++)
waddch(window, string[i2]);
return(strlen(string));
}
int
len_char(character, column) /* return the length of the character */
char character;
int column; /* the column must be known to provide spacing for tabs */
{
int length;
if (character == '\t')
length = tabshift(column);
else if ((character >= 0) && (character < 32))
length = 2;
else if ((character >= 32) && (character <= 126))
length = 1;
else if (character == 127)
length = 2;
else if (((character > 126) || (character < 0)) && (!eightbit))
length = 5;
else
length = 1;
return(length);
}
void
draw_line(vertical, horiz, ptr, t_pos, length) /* redraw line from current position */
int vertical; /* current vertical position on screen */
int horiz; /* current horizontal position on screen */
char *ptr; /* pointer to line */
int t_pos; /* current position (offset in bytes) from bol */
int length; /* length (in bytes) of line */
{
int d; /* partial length of special or tab char to display */
char *temp; /* temporary pointer to position in line */
int abs_column; /* offset in screen units from begin of line */
int column; /* horizontal position on screen */
int row; /* vertical position on screen */
int posit; /* temporary position indicator within line */
abs_column = horiz;
column = horiz - horiz_offset;
row = vertical;
temp = ptr;
d = 0;
posit = t_pos;
if (column < 0)
{
wmove(text_win, row, 0);
wclrtoeol(text_win);
}
while (column < 0)
{
d = len_char(*temp, abs_column);
abs_column += d;
column += d;
posit++;
temp++;
}
wmove(text_win, row, column);
wclrtoeol(text_win);
while ((posit < length) && (column <= last_col))
{
if ((*temp < 32) || (*temp == 127))
{
column += len_char(*temp, abs_column);
abs_column += out_char(text_win, *temp, abs_column);
}
else
{
abs_column++;
column++;
waddch(text_win, *temp);
}
posit++;
temp++;
}
if (column < last_col)
wclrtoeol(text_win);
wmove(text_win, vertical, (horiz - horiz_offset));
}
void
insert_line(disp) /* insert new line */
int disp;
{
int temp_pos;
int temp_pos2;
char *temp;
char *extra;
struct text *temp_nod;
text_changes = TRUE;
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
wclrtoeol(text_win);
temp_nod= txtalloc();
temp_nod->line = extra= malloc(10);
temp_nod->line_length = 1;
temp_nod->max_length = 10;
temp_nod->line_number = curr_line->line_number + 1;
temp_nod->next_line = curr_line->next_line;
if (temp_nod->next_line != NULL)
temp_nod->next_line->prev_line = temp_nod;
temp_nod->prev_line = curr_line;
curr_line->next_line = temp_nod;
temp_pos2 = position;
temp = point;
if (temp_pos2 < curr_line->line_length)
{
temp_pos = 1;
while (temp_pos2 < curr_line->line_length)
{
if ((temp_nod->max_length - temp_nod->line_length)< 5)
extra = resiz_line(10, temp_nod, temp_pos);
temp_nod->line_length++;
temp_pos++;
temp_pos2++;
*extra= *temp;
extra++;
temp++;
}
temp=point;
*temp = (char) NULL;
temp = resiz_line((1 - temp_nod->line_length), curr_line, position);
curr_line->line_length = 1 + temp - curr_line->line;
}
curr_line->line_length = position;
curr_line = temp_nod;
*extra = (char) NULL;
position = 1;
point= curr_line->line;
if (disp)
{
if (scr_vert < last_line)
{
scr_vert++;
wclrtoeol(text_win);
wmove(text_win, scr_vert, 0);
winsertln(text_win);
}
else
{
wmove(text_win, 0,0);
wdeleteln(text_win);
wmove(text_win, last_line,0);
wclrtobot(text_win);
}
scr_pos = scr_horz = 0;
if (horiz_offset)
{
horiz_offset = 0;
midscreen(scr_vert, point);
}
draw_line(scr_vert, scr_horz, point, position,
curr_line->line_length);
}
}
struct text *txtalloc() /* allocate space for line structure */
{
return((struct text *) malloc(sizeof( struct text)));
}
struct files *name_alloc() /* allocate space for file name list node */
{
return((struct files *) malloc(sizeof( struct files)));
}
char *next_word(string) /* move to next word in string */
char *string;
{
while ((*string != (char) NULL) && ((*string != 32) && (*string != 9)))
string++;
while ((*string != (char) NULL) && ((*string == 32) || (*string == 9)))
string++;
return(string);
}
void
prev_word() /* move to start of previous word in text */
{
if (position != 1)
{
if ((position != 1) && ((point[-1] == ' ') || (point[-1] == '\t')))
{ /* if at the start of a word */
while ((position != 1) && ((*point != ' ') && (*point != '\t')))
left(TRUE);
}
while ((position != 1) && ((*point == ' ') || (*point == '\t')))
left(TRUE);
while ((position != 1) && ((*point != ' ') && (*point != '\t')))
left(TRUE);
if ((position != 1) && ((*point == ' ') || (*point == '\t')))
right(TRUE);
}
else
left(TRUE);
}
void
control() /* use control for commands */
{
char *string;
if (in == 1) /* control a */
{
string = get_string(ascii_code_str, TRUE);
if (*string != (char) NULL)
{
in = atoi(string);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
insert(in);
}
free(string);
}
else if (in == 2) /* control b */
bottom();
else if (in == 3) /* control c */
{
command_prompt();
}
else if (in == 4) /* control d */
down();
else if (in == 5) /* control e */
search_prompt();
else if (in == 6) /* control f */
undel_char();
else if (in == 7) /* control g */
bol();
else if (in == 8) /* control h */
delete(TRUE);
else if (in == 9) /* control i */
;
else if (in == 10) /* control j */
insert_line(TRUE);
else if (in == 11) /* control k */
del_char();
else if (in == 12) /* control l */
left(TRUE);
else if (in == 13) /* control m */
insert_line(TRUE);
else if (in == 14) /* control n */
move_rel("d", max(5, (last_line - 5)));
else if (in == 15) /* control o */
eol();
else if (in == 16) /* control p */
move_rel("u", max(5, (last_line - 5)));
else if (in == 17) /* control q */
;
else if (in == 18) /* control r */
right(TRUE);
else if (in == 19) /* control s */
;
else if (in == 20) /* control t */
top();
else if (in == 21) /* control u */
up();
else if (in == 22) /* control v */
undel_word();
else if (in == 23) /* control w */
del_word();
else if (in == 24) /* control x */
search(TRUE);
else if (in == 25) /* control y */
del_line();
else if (in == 26) /* control z */
undel_line();
else if (in == 27) /* control [ (escape) */
{
menu_op(main_menu);
}
}
/*
| Emacs control-key bindings
*/
void
emacs_control()
{
char *string;
if (in == 1) /* control a */
bol();
else if (in == 2) /* control b */
left(TRUE);
else if (in == 3) /* control c */
{
command_prompt();
}
else if (in == 4) /* control d */
del_char();
else if (in == 5) /* control e */
eol();
else if (in == 6) /* control f */
right(TRUE);
else if (in == 7) /* control g */
move_rel("u", max(5, (last_line - 5)));
else if (in == 8) /* control h */
delete(TRUE);
else if (in == 9) /* control i */
;
else if (in == 10) /* control j */
undel_char();
else if (in == 11) /* control k */
del_line();
else if (in == 12) /* control l */
undel_line();
else if (in == 13) /* control m */
insert_line(TRUE);
else if (in == 14) /* control n */
down();
else if (in == 15) /* control o */
{
string = get_string(ascii_code_str, TRUE);
if (*string != (char) NULL)
{
in = atoi(string);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
insert(in);
}
free(string);
}
else if (in == 16) /* control p */
up();
else if (in == 17) /* control q */
;
else if (in == 18) /* control r */
undel_word();
else if (in == 19) /* control s */
;
else if (in == 20) /* control t */
top();
else if (in == 21) /* control u */
bottom();
else if (in == 22) /* control v */
move_rel("d", max(5, (last_line - 5)));
else if (in == 23) /* control w */
del_word();
else if (in == 24) /* control x */
search(TRUE);
else if (in == 25) /* control y */
search_prompt();
else if (in == 26) /* control z */
adv_word();
else if (in == 27) /* control [ (escape) */
{
menu_op(main_menu);
}
}
void
bottom() /* go to bottom of file */
{
while (curr_line->next_line != NULL)
curr_line = curr_line->next_line;
point = curr_line->line;
if (horiz_offset)
horiz_offset = 0;
position = 1;
midscreen(last_line, point);
scr_pos = scr_horz;
}
void
top() /* go to top of file */
{
while (curr_line->prev_line != NULL)
curr_line = curr_line->prev_line;
point = curr_line->line;
if (horiz_offset)
horiz_offset = 0;
position = 1;
midscreen(0, point);
scr_pos = scr_horz;
}
void
nextline() /* move pointers to start of next line */
{
curr_line = curr_line->next_line;
point = curr_line->line;
position = 1;
if (scr_vert == last_line)
{
wmove(text_win, 0,0);
wdeleteln(text_win);
wmove(text_win, last_line,0);
wclrtobot(text_win);
draw_line(last_line,0,point,1,curr_line->line_length);
}
else
scr_vert++;
}
void
prevline() /* move pointers to start of previous line*/
{
curr_line = curr_line->prev_line;
point = curr_line->line;
position = 1;
if (scr_vert == 0)
{
winsertln(text_win);
draw_line(0,0,point,1,curr_line->line_length);
}
else
scr_vert--;
while (position < curr_line->line_length)
{
position++;
point++;
}
}
void
left(disp) /* move left one character */
int disp;
{
if (point != curr_line->line) /* if not at begin of line */
{
point--;
position--;
scanline(point);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
scr_pos = scr_horz;
}
else if (curr_line->prev_line != NULL)
{
if (!disp)
{
curr_line = curr_line->prev_line;
point = curr_line->line + curr_line->line_length;
position = curr_line->line_length;
return;
}
position = 1;
prevline();
scanline(point);
scr_pos = scr_horz;
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
}
}
void
right(disp) /* move right one character */
int disp;
{
if (position < curr_line->line_length)
{
point++;
position++;
scanline(point);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
scr_pos = scr_horz;
}
else if (curr_line->next_line != NULL)
{
if (!disp)
{
curr_line = curr_line->next_line;
point = curr_line->line;
position = 1;
return;
}
nextline();
scr_pos = scr_horz = 0;
if (horiz_offset)
{
horiz_offset = 0;
midscreen(scr_vert, point);
}
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
position = 1;
}
}
void
find_pos() /* move to the same column as on other line */
{
scr_horz = 0;
position = 1;
while ((scr_horz < scr_pos) && (position < curr_line->line_length))
{
if (*point == 9)
scr_horz += tabshift(scr_horz);
else if ((*point >= '\0') && (*point < ' '))
scr_horz += 2;
else
scr_horz++;
position++;
point++;
}
if ((scr_horz - horiz_offset) > last_col)
{
horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
midscreen(scr_vert, point);
}
else if (scr_horz < horiz_offset)
{
horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
midscreen(scr_vert, point);
}
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
}
void
up() /* move up one line */
{
if (curr_line->prev_line != NULL)
{
prevline();
point = curr_line->line;
find_pos();
}
}
void
down() /* move down one line */
{
if (curr_line->next_line != NULL)
{
nextline();
find_pos();
}
}
void
function_key() /* process function key */
{
if (in == KEY_LEFT)
left(TRUE);
else if (in == KEY_RIGHT)
right(TRUE);
else if ( in == KEY_HOME)
top();
else if ( in == KEY_UP)
up();
else if (in == KEY_DOWN)
down();
else if (in == KEY_NPAGE)
move_rel("d", max( 5, (last_line - 5)));
else if (in == KEY_PPAGE)
move_rel("u", max(5, (last_line - 5)));
else if (in == KEY_DL)
del_line();
else if (in == KEY_DC)
del_char();
else if (in == KEY_BACKSPACE)
delete(TRUE);
else if (in == KEY_IL)
{ /* insert a line before current line */
insert_line(TRUE);
left(TRUE);
}
else if (in == KEY_F(1))
gold = !gold;
else if (in == KEY_F(2))
{
if (gold)
{
gold = FALSE;
undel_line();
}
else
undel_char();
}
else if (in == KEY_F(3))
{
if (gold)
{
gold = FALSE;
undel_word();
}
else
del_word();
}
else if (in == KEY_F(4))
{
if (gold)
{
gold = FALSE;
paint_info_win();
midscreen(scr_vert, point);
}
else
adv_word();
}
else if (in == KEY_F(5))
{
if (gold)
{
gold = FALSE;
search_prompt();
}
else
search(TRUE);
}
else if (in == KEY_F(6))
{
if (gold)
{
gold = FALSE;
bottom();
}
else
top();
}
else if (in == KEY_F(7))
{
if (gold)
{
gold = FALSE;
eol();
}
else
bol();
}
else if (in == KEY_F(8))
{
if (gold)
{
gold = FALSE;
command_prompt();
}
else
adv_line();
}
}
void
print_buffer()
{
char buffer[256];
sprintf(buffer, ">!%s", print_command);
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, printer_msg_str, print_command);
wrefresh(com_win);
command(buffer);
}
void
command_prompt()
{
char *cmd_str;
int result;
info_type = COMMANDS;
paint_info_win();
cmd_str = get_string(command_str, TRUE);
if ((result = unique_test(cmd_str, commands)) != 1)
{
werase(com_win);
wmove(com_win, 0, 0);
if (result == 0)
wprintw(com_win, unkn_cmd_str, cmd_str);
else
wprintw(com_win, non_unique_cmd_msg);
wrefresh(com_win);
info_type = CONTROL_KEYS;
paint_info_win();
if (cmd_str != NULL)
free(cmd_str);
return;
}
command(cmd_str);
wrefresh(com_win);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
info_type = CONTROL_KEYS;
paint_info_win();
if (cmd_str != NULL)
free(cmd_str);
}
void
command(cmd_str1) /* process commands from keyboard */
char *cmd_str1;
{
char *cmd_str2 = NULL;
char *cmd_str = cmd_str1;
clear_com_win = TRUE;
if (compare(cmd_str, HELP, FALSE))
help();
else if (compare(cmd_str, WRITE, FALSE))
{
if (restrict_mode())
{
return;
}
cmd_str = next_word(cmd_str);
if (*cmd_str == (char) NULL)
{
cmd_str = cmd_str2 = get_string(file_write_prompt_str, TRUE);
}
tmp_file = resolve_name(cmd_str);
write_file(tmp_file);
if (tmp_file != cmd_str)
free(tmp_file);
}
else if (compare(cmd_str, READ, FALSE))
{
if (restrict_mode())
{
return;
}
cmd_str = next_word(cmd_str);
if (*cmd_str == (char) NULL)
{
cmd_str = cmd_str2 = get_string(file_read_prompt_str, TRUE);
}
tmp_file = cmd_str;
recv_file = TRUE;
tmp_file = resolve_name(cmd_str);
check_fp();
if (tmp_file != cmd_str)
free(tmp_file);
}
else if (compare(cmd_str, LINE, FALSE))
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, line_num_str, curr_line->line_number);
wprintw(com_win, line_len_str, curr_line->line_length);
}
else if (compare(cmd_str, FILE_str, FALSE))
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
if (in_file_name == NULL)
wprintw(com_win, no_file_string);
else
wprintw(com_win, current_file_str, in_file_name);
}
else if ((*cmd_str >= '0') && (*cmd_str <= '9'))
goto_line(cmd_str);
else if (compare(cmd_str, CHARACTER, FALSE))
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
if (*point >= '\0')
wprintw(com_win, char_str, *point);
else
wprintw(com_win, char_str, (*point + 256));
}
else if (compare(cmd_str, REDRAW, FALSE))
redraw();
else if (compare(cmd_str, RESEQUENCE, FALSE))
{
tmp_line = first_line->next_line;
while (tmp_line != NULL)
{
tmp_line->line_number = tmp_line->prev_line->line_number + 1;
tmp_line = tmp_line->next_line;
}
}
else if (compare(cmd_str, AUTHOR, FALSE))
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, "written by Hugh Mahon");
}
else if (compare(cmd_str, VERSION, FALSE))
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, "%s", version);
}
else if (compare(cmd_str, CASE, FALSE))
case_sen = TRUE;
else if (compare(cmd_str, NOCASE, FALSE))
case_sen = FALSE;
else if (compare(cmd_str, EXPAND, FALSE))
expand_tabs = TRUE;
else if (compare(cmd_str, NOEXPAND, FALSE))
expand_tabs = FALSE;
else if (compare(cmd_str, Exit_string, FALSE))
finish();
else if (compare(cmd_str, QUIT_string, FALSE))
quit(0);
else if (*cmd_str == '!')
{
cmd_str++;
if ((*cmd_str == ' ') || (*cmd_str == 9))
cmd_str = next_word(cmd_str);
sh_command(cmd_str);
}
else if ((*cmd_str == '<') && (!in_pipe))
{
in_pipe = TRUE;
shell_fork = FALSE;
cmd_str++;
if ((*cmd_str == ' ') || (*cmd_str == '\t'))
cmd_str = next_word(cmd_str);
command(cmd_str);
in_pipe = FALSE;
shell_fork = TRUE;
}
else if ((*cmd_str == '>') && (!out_pipe))
{
out_pipe = TRUE;
cmd_str++;
if ((*cmd_str == ' ') || (*cmd_str == '\t'))
cmd_str = next_word(cmd_str);
command(cmd_str);
out_pipe = FALSE;
}
else
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, unkn_cmd_str, cmd_str);
}
if (cmd_str2 != NULL)
free(cmd_str2);
}
int
scan(line, offset, column) /* determine horizontal position for get_string */
char *line;
int offset;
int column;
{
char *stemp;
int i;
int j;
stemp = line;
i = 0;
j = column;
while (i < offset)
{
i++;
j += len_char(*stemp, j);
stemp++;
}
return(j);
}
char *
get_string(prompt, advance) /* read string from input on command line */
char *prompt; /* string containing user prompt message */
int advance; /* if true, skip leading spaces and tabs */
{
char *string;
char *tmp_string;
char *nam_str;
char *g_point;
int tmp_int;
int g_horz, g_position, g_pos;
int esc_flag;
g_point = tmp_string = malloc(512);
wmove(com_win,0,0);
wclrtoeol(com_win);
waddstr(com_win, prompt);
wrefresh(com_win);
nam_str = tmp_string;
clear_com_win = TRUE;
g_horz = g_position = scan(prompt, strlen(prompt), 0);
g_pos = 0;
do
{
esc_flag = FALSE;
in = wgetch(com_win);
if (in == -1)
exit(0);
if (((in == 8) || (in == 127) || (in == KEY_BACKSPACE)) && (g_pos > 0))
{
tmp_int = g_horz;
g_pos--;
g_horz = scan(g_point, g_pos, g_position);
tmp_int = tmp_int - g_horz;
for (; 0 < tmp_int; tmp_int--)
{
if ((g_horz+tmp_int) < (last_col - 1))
{
waddch(com_win, '\010');
waddch(com_win, ' ');
waddch(com_win, '\010');
}
}
nam_str--;
}
else if ((in != 8) && (in != 127) && (in != '\n') && (in != '\r') && (in < 256))
{
if (in == '\026') /* control-v, accept next character verbatim */
{ /* allows entry of ^m, ^j, and ^h */
esc_flag = TRUE;
in = wgetch(com_win);
if (in == -1)
exit(0);
}
*nam_str = in;
g_pos++;
if (((in < ' ') || (in > 126)) && (g_horz < (last_col - 1)))
g_horz += out_char(com_win, in, g_horz);
else
{
g_horz++;
if (g_horz < (last_col - 1))
waddch(com_win, in);
}
nam_str++;
}
wrefresh(com_win);
if (esc_flag)
in = (char) NULL;
} while ((in != '\n') && (in != '\r'));
*nam_str = (char) NULL;
nam_str = tmp_string;
if (((*nam_str == ' ') || (*nam_str == 9)) && (advance))
nam_str = next_word(nam_str);
string = malloc(strlen(nam_str) + 1);
strcpy(string, nam_str);
free(tmp_string);
wrefresh(com_win);
return(string);
}
int
compare(string1, string2, sensitive) /* compare two strings */
char *string1;
char *string2;
int sensitive;
{
char *strng1;
char *strng2;
int tmp;
int equal;
strng1 = string1;
strng2 = string2;
tmp = 0;
if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == (char) NULL) || (*strng2 == (char) NULL))
return(FALSE);
equal = TRUE;
while (equal)
{
if (sensitive)
{
if (*strng1 != *strng2)
equal = FALSE;
}
else
{
if (toupper(*strng1) != toupper(*strng2))
equal = FALSE;
}
strng1++;
strng2++;
if ((*strng1 == (char) NULL) || (*strng2 == (char) NULL) || (*strng1 == ' ') || (*strng2 == ' '))
break;
tmp++;
}
return(equal);
}
void
goto_line(cmd_str)
char *cmd_str;
{
int number;
int i;
char *ptr;
char *direction;
struct text *t_line;
ptr = cmd_str;
i= 0;
while ((*ptr >='0') && (*ptr <= '9'))
{
i= i * 10 + (*ptr - '0');
ptr++;
}
number = i;
i = 0;
t_line = curr_line;
while ((t_line->line_number > number) && (t_line->prev_line != NULL))
{
i++;
t_line = t_line->prev_line;
direction = "u";
}
while ((t_line->line_number < number) && (t_line->next_line != NULL))
{
i++;
direction = "d";
t_line = t_line->next_line;
}
if ((i < 30) && (i > 0))
{
move_rel(direction, i);
}
else
{
curr_line = t_line;
point = curr_line->line;
position = 1;
midscreen((last_line / 2), point);
scr_pos = scr_horz;
}
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, line_num_str, curr_line->line_number);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
}
void
midscreen(line, pnt) /* put current line in middle of screen */
int line;
char *pnt;
{
struct text *mid_line;
int i;
line = min(line, last_line);
mid_line = curr_line;
for (i = 0; ((i < line) && (curr_line->prev_line != NULL)); i++)
curr_line = curr_line->prev_line;
scr_vert = scr_horz = 0;
wmove(text_win, 0, 0);
draw_screen();
scr_vert = i;
curr_line = mid_line;
scanline(pnt);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
}
void
get_options(numargs, arguments) /* get arguments from command line */
int numargs;
char *arguments[];
{
char *buff;
int count;
struct files *temp_names;
char *name;
char *ptr;
/*
| see if editor was invoked as 'ree' (restricted mode)
*/
if (!(name = strrchr(arguments[0], '/')))
name = arguments[0];
else
name++;
if (!strcmp(name, "ree"))
restricted = TRUE;
top_of_stack = NULL;
input_file = FALSE;
recv_file = FALSE;
count = 1;
while (count < numargs)
{
buff = arguments[count];
if (!strcmp("-i", buff))
{
info_window = FALSE;
}
else if (!strcmp("-e", buff))
{
expand_tabs = FALSE;
}
else if (!strcmp("-h", buff))
{
nohighlight = TRUE;
}
else if (!strcmp("-?", buff))
{
fprintf(stderr, usage0, arguments[0]);
fprintf(stderr, usage1);
fprintf(stderr, usage2);
fprintf(stderr, usage3);
fprintf(stderr, usage4);
exit(1);
}
else if (*buff == '+')
{
buff++;
start_at_line = buff;
}
else
{
if (top_of_stack == NULL)
{
temp_names = top_of_stack = name_alloc();
}
else
{
temp_names->next_name = name_alloc();
temp_names = temp_names->next_name;
}
ptr = temp_names->name = malloc(strlen(buff) + 1);
while (*buff != (char) NULL)
{
*ptr = *buff;
buff++;
ptr++;
}
*ptr = (char) NULL;
temp_names->next_name = NULL;
input_file = TRUE;
recv_file = TRUE;
}
count++;
}
}
void
check_fp() /* open or close files according to flags */
{
int line_num;
int temp;
struct stat buf;
clear_com_win = TRUE;
tmp_vert = scr_vert;
tmp_horz = scr_horz;
tmp_line = curr_line;
if (input_file)
{
in_file_name = tmp_file = top_of_stack->name;
top_of_stack = top_of_stack->next_name;
}
temp = stat(tmp_file, &buf);
buf.st_mode &= ~07777;
if ((temp != -1) && (buf.st_mode != 0100000) && (buf.st_mode != 0))
{
wprintw(com_win, file_is_dir_msg, tmp_file);
wrefresh(com_win);
if (input_file)
{
quit(0);
return;
}
else
return;
}
if ((get_fd = open(tmp_file, O_RDONLY)) == -1)
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
if (input_file)
wprintw(com_win, new_file_msg, tmp_file);
else
wprintw(com_win, cant_open_msg, tmp_file);
wrefresh(com_win);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
wrefresh(text_win);
recv_file = FALSE;
input_file = FALSE;
return;
}
else
get_file(tmp_file);
recv_file = FALSE;
line_num = curr_line->line_number;
scr_vert = tmp_vert;
scr_horz = tmp_horz;
if (input_file)
curr_line= first_line;
else
curr_line = tmp_line;
point = curr_line->line;
draw_screen();
if (input_file)
{
input_file = FALSE;
if (start_at_line != NULL)
{
line_num = atoi(start_at_line) - 1;
move_rel("d", line_num);
line_num = 0;
start_at_line = NULL;
}
}
else
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
text_changes = TRUE;
if ((tmp_file != NULL) && (*tmp_file != (char) NULL))
wprintw(com_win, file_read_fin_msg, tmp_file);
}
wrefresh(com_win);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
wrefresh(text_win);
}
void
get_file(file_name) /* read specified file into current buffer */
char *file_name;
{
int can_read; /* file has at least one character */
int length; /* length of line read by read */
int append; /* should text be appended to current line */
struct text *temp_line;
char ro_flag = FALSE;
if (recv_file) /* if reading a file */
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, reading_file_msg, file_name);
if (access(file_name, 2)) /* check permission to write */
{
if ((errno == ENOTDIR) || (errno == EACCES) || (errno == EROFS) || (errno == ETXTBSY) || (errno == EFAULT))
{
wprintw(com_win, read_only_msg);
ro_flag = TRUE;
}
}
wrefresh(com_win);
}
if (curr_line->line_length > 1) /* if current line is not blank */
{
insert_line(FALSE);
left(FALSE);
append = FALSE;
}
else
append = TRUE;
can_read = FALSE; /* test if file has any characters */
while (((length = read(get_fd, in_string, 512)) != 0) && (length != -1))
{
can_read = TRUE; /* if set file has at least 1 character */
get_line(length, in_string, &append);
}
if ((can_read) && (curr_line->line_length == 1))
{
temp_line = curr_line->prev_line;
temp_line->next_line = curr_line->next_line;
if (temp_line->next_line != NULL)
temp_line->next_line->prev_line = temp_line;
if (curr_line->line != NULL)
free(curr_line->line);
free(curr_line);
curr_line = temp_line;
}
if (input_file) /* if this is the file to be edited display number of lines */
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, file_read_lines_msg, in_file_name, curr_line->line_number);
if (ro_flag)
wprintw(com_win, read_only_msg);
wrefresh(com_win);
}
else if (can_read) /* not input_file and file is non-zero size */
text_changes = TRUE;
if (recv_file) /* if reading a file */
{
in = EOF;
}
}
void
get_line(length, in_string, append) /* read string and split into lines */
int length; /* length of string read by read */
char *in_string; /* string read by read */
int *append; /* TRUE if must append more text to end of current line */
{
char *str1;
char *str2;
int num; /* offset from start of string */
int char_count; /* length of new line (or added portion */
int temp_counter; /* temporary counter value */
struct text *tline; /* temporary pointer to new line */
int first_time; /* if TRUE, the first time through the loop */
str2 = in_string;
num = 0;
first_time = TRUE;
while (num < length)
{
if (!first_time)
{
if (num < length)
{
str2++;
num++;
}
}
else
first_time = FALSE;
str1 = str2;
char_count = 1;
/* find end of line */
while ((*str2 != '\n') && (num < length))
{
str2++;
num++;
char_count++;
}
if (!(*append)) /* if not append to current line, insert new one */
{
tline = txtalloc(); /* allocate data structure for next line */
tline->line_number = curr_line->line_number + 1;
tline->next_line = curr_line->next_line;
tline->prev_line = curr_line;
curr_line->next_line = tline;
if (tline->next_line != NULL)
tline->next_line->prev_line = tline;
curr_line = tline;
curr_line->line = point = (char *) malloc(char_count);
curr_line->line_length = char_count;
curr_line->max_length = char_count;
}
else
{
point = resiz_line(char_count, curr_line, curr_line->line_length);
curr_line->line_length += (char_count - 1);
}
for (temp_counter = 1; temp_counter < char_count; temp_counter++)
{
*point = *str1;
point++;
str1++;
}
*point = (char) NULL;
*append = FALSE;
if ((num == length) && (*str2 != '\n'))
*append = TRUE;
}
}
void
draw_screen() /* redraw the screen from current postion */
{
struct text *temp_line;
char *line_out;
int temp_vert;
temp_line = curr_line;
temp_vert = scr_vert;
wclrtobot(text_win);
while ((temp_line != NULL) && (temp_vert <= last_line))
{
line_out = temp_line->line;
draw_line(temp_vert, 0, line_out, 1, temp_line->line_length);
temp_vert++;
temp_line = temp_line->next_line;
}
wmove(text_win, temp_vert, 0);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
}
void
finish() /* prepare to exit edit session */
{
char *file_name = in_file_name;
/*
| changes made here should be reflected in the 'save'
| portion of file_op()
*/
if ((file_name == NULL) || (*file_name == (char) NULL))
file_name = get_string(save_file_name_prompt, TRUE);
if ((file_name == NULL) || (*file_name == (char) NULL))
{
wmove(com_win, 0, 0);
wprintw(com_win, file_not_saved_msg);
wclrtoeol(com_win);
wrefresh(com_win);
clear_com_win = TRUE;
return;
}
tmp_file = resolve_name(file_name);
if (tmp_file != file_name)
{
free(file_name);
file_name = tmp_file;
}
if (write_file(file_name))
{
text_changes = FALSE;
quit(0);
}
}
int
quit(noverify) /* exit editor */
int noverify;
{
char *ans;
touchwin(text_win);
wrefresh(text_win);
if ((text_changes) && (!noverify))
{
ans = get_string(changes_made_prompt, TRUE);
if (toupper(*ans) == toupper(*yes_char))
text_changes = FALSE;
else
return(0);
free(ans);
}
if (top_of_stack == NULL)
{
if (info_window)
wrefresh(info_win);
wrefresh(com_win);
resetty();
endwin();
putchar('\n');
exit(0);
}
else
{
delete_text();
recv_file = TRUE;
input_file = TRUE;
check_fp();
}
return(0);
}
void
edit_abort(arg)
int arg;
{
wrefresh(com_win);
resetty();
endwin();
putchar('\n');
exit(1);
}
void
delete_text()
{
while (curr_line->next_line != NULL)
curr_line = curr_line->next_line;
while (curr_line != first_line)
{
free(curr_line->line);
curr_line = curr_line->prev_line;
free(curr_line->next_line);
}
curr_line->next_line = NULL;
*curr_line->line = (char) NULL;
curr_line->line_length = 1;
curr_line->line_number = 1;
point = curr_line->line;
scr_pos = scr_vert = scr_horz = 0;
position = 1;
}
int
write_file(file_name)
char *file_name;
{
char cr;
char *tmp_point;
struct text *out_line;
int lines, charac;
int temp_pos;
int write_flag = TRUE;
charac = lines = 0;
if ((in_file_name == NULL) || strcmp(in_file_name, file_name))
{
if ((temp_fp = fopen(file_name, "r")))
{
tmp_point = get_string(file_exists_prompt, TRUE);
if (toupper(*tmp_point) == toupper(*yes_char))
write_flag = TRUE;
else
write_flag = FALSE;
fclose(temp_fp);
free(tmp_point);
}
}
clear_com_win = TRUE;
if (write_flag)
{
if ((temp_fp = fopen(file_name, "w")) == NULL)
{
clear_com_win = TRUE;
wmove(com_win,0,0);
wclrtoeol(com_win);
wprintw(com_win, create_file_fail_msg, file_name);
wrefresh(com_win);
return(FALSE);
}
else
{
wmove(com_win,0,0);
wclrtoeol(com_win);
wprintw(com_win, writing_file_msg, file_name);
wrefresh(com_win);
cr = '\n';
out_line = first_line;
while (out_line != NULL)
{
temp_pos = 1;
tmp_point= out_line->line;
while (temp_pos < out_line->line_length)
{
putc(*tmp_point, temp_fp);
tmp_point++;
temp_pos++;
}
charac += out_line->line_length;
out_line = out_line->next_line;
putc(cr, temp_fp);
lines++;
}
fclose(temp_fp);
wmove(com_win,0,0);
wclrtoeol(com_win);
wprintw(com_win, file_written_msg, file_name, lines, charac);
wrefresh(com_win);
return(TRUE);
}
}
else
return(FALSE);
}
int
search(display_message) /* search for string in srch_str */
int display_message;
{
int lines_moved;
int iter;
int found;
if ((srch_str == NULL) || (*srch_str == (char) NULL))
return(FALSE);
if (display_message)
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, searching_msg);
wrefresh(com_win);
clear_com_win = TRUE;
}
lines_moved = 0;
found = FALSE;
srch_line = curr_line;
srch_1 = point;
if (position < curr_line->line_length)
srch_1++;
iter = position + 1;
while ((!found) && (srch_line != NULL))
{
while ((iter < srch_line->line_length) && (!found))
{
srch_2 = srch_1;
if (case_sen) /* if case sensitive */
{
srch_3 = srch_str;
while ((*srch_2 == *srch_3) && (*srch_3 != (char) NULL))
{
found = TRUE;
srch_2++;
srch_3++;
} /* end while */
}
else /* if not case sensitive */
{
srch_3 = u_srch_str;
while ((toupper(*srch_2) == *srch_3) && (*srch_3 != (char) NULL))
{
found = TRUE;
srch_2++;
srch_3++;
}
} /* end else */
if (!((*srch_3 == (char) NULL) && (found)))
{
found = FALSE;
if (iter < srch_line->line_length)
srch_1++;
iter++;
}
}
if (!found)
{
srch_line = srch_line->next_line;
if (srch_line != NULL)
srch_1 = srch_line->line;
iter = 1;
lines_moved++;
}
}
if (found)
{
if (display_message)
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wrefresh(com_win);
}
if (lines_moved == 0)
{
while (position < iter)
right(TRUE);
}
else
{
if (lines_moved < 30)
{
move_rel("d", lines_moved);
while (position < iter)
right(TRUE);
}
else
{
curr_line = srch_line;
point = srch_1;
position = iter;
scanline(point);
scr_pos = scr_horz;
midscreen((last_line / 2), point);
}
}
}
else
{
if (display_message)
{
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, str_not_found_msg, srch_str);
wrefresh(com_win);
}
wmove(text_win, scr_vert,(scr_horz - horiz_offset));
}
return(found);
}
void
search_prompt() /* prompt and read search string (srch_str) */
{
if (srch_str != NULL)
free(srch_str);
if ((u_srch_str != NULL) && (*u_srch_str != (char) NULL))
free(u_srch_str);
srch_str = get_string(search_prompt_str, FALSE);
gold = FALSE;
srch_3 = srch_str;
srch_1 = u_srch_str = malloc(strlen(srch_str) + 1);
while (*srch_3 != (char) NULL)
{
*srch_1 = toupper(*srch_3);
srch_1++;
srch_3++;
}
*srch_1 = (char) NULL;
search(TRUE);
}
void
del_char() /* delete current character */
{
in = 8; /* backspace */
if (position < curr_line->line_length) /* if not end of line */
{
position++;
point++;
scanline(point);
delete(TRUE);
}
else
{
right(FALSE);
delete(FALSE);
}
}
void
undel_char() /* undelete last deleted character */
{
if (d_char == '\n') /* insert line if last del_char deleted eol */
insert_line(TRUE);
else
{
in = d_char;
insert(in);
}
}
void
del_word() /* delete word in front of cursor */
{
int tposit;
int difference;
char *d_word2;
char *d_word3;
char tmp_char;
if (d_word != NULL)
free(d_word);
d_word = malloc(curr_line->line_length);
tmp_char = d_char;
d_word3 = point;
d_word2 = d_word;
tposit = position;
while ((tposit < curr_line->line_length) &&
((*d_word3 != ' ') && (*d_word3 != '\t')))
{
tposit++;
*d_word2 = *d_word3;
d_word2++;
d_word3++;
}
while ((tposit < curr_line->line_length) &&
((*d_word3 == ' ') || (*d_word3 == '\t')))
{
tposit++;
*d_word2 = *d_word3;
d_word2++;
d_word3++;
}
*d_word2 = (char) NULL;
d_wrd_len = difference = d_word2 - d_word;
d_word2 = point;
while (tposit < curr_line->line_length)
{
tposit++;
*d_word2 = *d_word3;
d_word2++;
d_word3++;
}
curr_line->line_length -= difference;
*d_word2 = (char) NULL;
draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
d_char = tmp_char;
text_changes = TRUE;
formatted = FALSE;
}
void
undel_word() /* undelete last deleted word */
{
int temp;
int tposit;
char *tmp_old_ptr;
char *tmp_space;
char *tmp_ptr;
char *d_word_ptr;
/*
| resize line to handle undeleted word
*/
if ((curr_line->max_length - (curr_line->line_length + d_wrd_len)) < 5)
point = resiz_line(d_wrd_len, curr_line, position);
tmp_ptr = tmp_space = malloc(curr_line->line_length + d_wrd_len);
d_word_ptr = d_word;
temp = 1;
/*
| copy d_word contents into temp space
*/
while (temp <= d_wrd_len)
{
temp++;
*tmp_ptr = *d_word_ptr;
tmp_ptr++;
d_word_ptr++;
}
tmp_old_ptr = point;
tposit = position;
/*
| copy contents of line from curent position to eol into
| temp space
*/
while (tposit < curr_line->line_length)
{
temp++;
tposit++;
*tmp_ptr = *tmp_old_ptr;
tmp_ptr++;
tmp_old_ptr++;
}
curr_line->line_length += d_wrd_len;
tmp_old_ptr = point;
*tmp_ptr = (char) NULL;
tmp_ptr = tmp_space;
tposit = 1;
/*
| now copy contents from temp space back to original line
*/
while (tposit < temp)
{
tposit++;
*tmp_old_ptr = *tmp_ptr;
tmp_ptr++;
tmp_old_ptr++;
}
*tmp_old_ptr = (char) NULL;
free(tmp_space);
draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
}
void
del_line() /* delete from cursor to end of line */
{
char *dl1;
char *dl2;
int tposit;
if (d_line != NULL)
free(d_line);
d_line = malloc(curr_line->line_length);
dl1 = d_line;
dl2 = point;
tposit = position;
while (tposit < curr_line->line_length)
{
*dl1 = *dl2;
dl1++;
dl2++;
tposit++;
}
dlt_line->line_length = 1 + tposit - position;
*dl1 = (char) NULL;
*point = (char) NULL;
curr_line->line_length = position;
wclrtoeol(text_win);
if (curr_line->next_line != NULL)
{
right(FALSE);
delete(FALSE);
}
text_changes = TRUE;
}
void
undel_line() /* undelete last deleted line */
{
char *ud1;
char *ud2;
int tposit;
insert_line(TRUE);
left(TRUE);
point = resiz_line(dlt_line->line_length, curr_line, position);
curr_line->line_length += dlt_line->line_length - 1;
ud1 = point;
ud2 = d_line;
tposit = 1;
while (tposit < dlt_line->line_length)
{
tposit++;
*ud1 = *ud2;
ud1++;
ud2++;
}
*ud1 = (char) NULL;
draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
}
void
adv_word() /* advance to next word */
{
while ((position < curr_line->line_length) && ((*point != 32) && (*point != 9)))
right(TRUE);
while ((position < curr_line->line_length) && ((*point == 32) || (*point == 9)))
right(TRUE);
}
void
move_rel(direction, lines) /* move relative to current line */
char *direction;
int lines;
{
int i;
char *tmp;
if (*direction == 'u')
{
scr_pos = 0;
while (position > 1)
left(TRUE);
for (i = 0; i < lines; i++)
{
up();
}
if ((last_line > 5) && ( scr_vert < 4))
{
tmp = point;
tmp_line = curr_line;
for (i= 0;(i<5)&&(curr_line->prev_line != NULL); i++)
{
up();
}
scr_vert = scr_vert + i;
curr_line = tmp_line;
point = tmp;
scanline(point);
}
}
else
{
if ((position != 1) && (curr_line->next_line != NULL))
{
nextline();
scr_pos = scr_horz = 0;
if (horiz_offset)
{
horiz_offset = 0;
midscreen(scr_vert, point);
}
}
else
adv_line();
for (i = 1; i < lines; i++)
{
down();
}
if ((last_line > 10) && (scr_vert > (last_line - 5)))
{
tmp = point;
tmp_line = curr_line;
for (i=0; (i<5) && (curr_line->next_line != NULL); i++)
{
down();
}
scr_vert = scr_vert - i;
curr_line = tmp_line;
point = tmp;
scanline(point);
}
}
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
}
void
eol() /* go to end of line */
{
if (position < curr_line->line_length)
{
while (position < curr_line->line_length)
right(TRUE);
}
else if (curr_line->next_line != NULL)
{
right(TRUE);
while (position < curr_line->line_length)
right(TRUE);
}
}
void
bol() /* move to beginning of line */
{
if (point != curr_line->line)
{
while (point != curr_line->line)
left(TRUE);
}
else if (curr_line->prev_line != NULL)
{
scr_pos = 0;
up();
}
}
void
adv_line() /* advance to beginning of next line */
{
if ((point != curr_line->line) || (scr_pos > 0))
{
while (position < curr_line->line_length)
right(TRUE);
right(TRUE);
}
else if (curr_line->next_line != NULL)
{
scr_pos = 0;
down();
}
}
void
sh_command(string) /* execute shell command */
char *string; /* string containing user command */
{
char *temp_point;
char *last_slash;
char *path; /* directory path to executable */
int parent; /* zero if child, child's pid if parent */
int value;
int return_val;
struct text *line_holder;
if (restrict_mode())
{
return;
}
if (!(path = getenv("SHELL")))
path = "/bin/sh";
last_slash = temp_point = path;
while (*temp_point != (char) NULL)
{
if (*temp_point == '/')
last_slash = ++temp_point;
else
temp_point++;
}
/*
| if in_pipe is true, then output of the shell operation will be
| read by the editor, and curses doesn't need to be turned off
*/
if (!in_pipe)
{
keypad(com_win, FALSE);
keypad(text_win, FALSE);
echo();
nl();
noraw();
resetty();
#ifndef NCURSE
endwin();
#endif
}
if (in_pipe)
{
pipe(pipe_in); /* create a pipe */
parent = fork();
if (!parent) /* if the child */
{
/*
| child process which will fork and exec shell command (if shell output is
| to be read by editor)
*/
in_pipe = FALSE;
/*
| redirect stdout to pipe
*/
temp_stdout = dup(1);
close(1);
dup(pipe_in[1]);
/*
| redirect stderr to pipe
*/
temp_stderr = dup(2);
close(2);
dup(pipe_in[1]);
close(pipe_in[1]);
/*
| child will now continue down 'if (!in_pipe)'
| path below
*/
}
else /* if the parent */
{
/*
| prepare editor to read from the pipe
*/
signal(SIGCHLD, SIG_IGN);
line_holder = curr_line;
tmp_vert = scr_vert;
close(pipe_in[1]);
get_fd = pipe_in[0];
get_file("");
close(pipe_in[0]);
scr_vert = tmp_vert;
scr_horz = scr_pos = 0;
position = 1;
curr_line = line_holder;
point = curr_line->line;
out_pipe = FALSE;
signal(SIGCHLD, SIG_DFL);
/*
| since flag "in_pipe" is still TRUE, the path which waits for the child
| process to die will be avoided.
| (the pipe is closed, no more output can be expected)
*/
}
}
if (!in_pipe)
{
signal(SIGINT, SIG_IGN);
if (out_pipe)
{
pipe(pipe_out);
}
/*
| fork process which will exec command
*/
parent = fork();
if (!parent) /* if the child */
{
if (shell_fork)
putchar('\n');
if (out_pipe)
{
/*
| prepare the child process (soon to exec a shell command) to read from the
| pipe (which will be output from the editor's buffer)
*/
close(0);
dup(pipe_out[0]);
close(pipe_out[0]);
close(pipe_out[1]);
}
for (value = 1; value < 24; value++)
signal(value, SIG_DFL);
execl(path, last_slash, "-c", string, NULL);
printf(exec_err_msg, path);
exit(-1);
}
else /* if the parent */
{
if (out_pipe)
{
/*
| output the contents of the buffer to the pipe (to be read by the
| process forked and exec'd above as stdin)
*/
close(pipe_out[0]);
line_holder = first_line;
while (line_holder != NULL)
{
write(pipe_out[1], line_holder->line, (line_holder->line_length-1));
write(pipe_out[1], "\n", 1);
line_holder = line_holder->next_line;
}
close(pipe_out[1]);
out_pipe = FALSE;
}
do
{
return_val = wait((int *) 0);
}
while ((return_val != parent) && (return_val != -1));
/*
| if this process is actually the child of the editor, exit. Here's how it
| works:
| The editor forks a process. If output must be sent to the command to be
| exec'd another process is forked, and that process (the child's child)
| will exec the command. In this case, "shell_fork" will be FALSE. If no
| output is to be performed to the shell command, "shell_fork" will be TRUE.
| If this is the editor process, shell_fork will be true, otherwise this is
| the child of the edit process.
*/
if (!shell_fork)
exit(0);
}
signal(SIGINT, edit_abort);
}
if (shell_fork)
{
printf(continue_msg);
fflush(stdout);
while ((in = getchar()) != '\n')
;
}
if (!in_pipe)
{
fixterm();
noecho();
nonl();
raw();
keypad(text_win, TRUE);
keypad(com_win, TRUE);
if (info_window)
clearok(info_win, TRUE);
}
redraw();
}
void
set_up_term() /* set up the terminal for operating with ae */
{
if (!curses_initialized)
{
initscr();
savetty();
noecho();
raw();
nonl();
curses_initialized = TRUE;
}
if (((LINES > 15) && (COLS >= 80)) && info_window)
last_line = LINES - 8;
else
{
info_window = FALSE;
last_line = LINES - 2;
}
idlok(stdscr, TRUE);
com_win = newwin(1, COLS, (LINES - 1), 0);
keypad(com_win, TRUE);
idlok(com_win, TRUE);
wrefresh(com_win);
if (!info_window)
text_win = newwin((LINES - 1), COLS, 0, 0);
else
text_win = newwin((LINES - 7), COLS, 6, 0);
keypad(text_win, TRUE);
idlok(text_win, TRUE);
wrefresh(text_win);
help_win = newwin((LINES - 1), COLS, 0, 0);
keypad(help_win, TRUE);
idlok(help_win, TRUE);
if (info_window)
{
info_type = CONTROL_KEYS;
info_win = newwin(6, COLS, 0, 0);
werase(info_win);
paint_info_win();
}
last_col = COLS - 1;
local_LINES = LINES;
local_COLS = COLS;
}
void
resize_check()
{
if ((LINES == local_LINES) && (COLS == local_COLS))
return;
if (info_window)
delwin(info_win);
delwin(text_win);
delwin(com_win);
delwin(help_win);
set_up_term();
redraw();
wrefresh(text_win);
}
static char item_alpha[] = "abcdefghijklmnopqrstuvwxyz0123456789 ";
int
menu_op(menu_list)
struct menu_entries menu_list[];
{
WINDOW *temp_win;
int max_width, max_height;
int x_off, y_off;
int counter;
int length;
int input;
int temp;
int list_size;
int top_offset; /* offset from top where menu items start */
int vert_pos; /* vertical position */
int vert_size; /* vertical size for menu list item display */
int off_start = 1; /* offset from start of menu items to start display */
/*
| determine number and width of menu items
*/
list_size = 1;
while (menu_list[list_size + 1].item_string != NULL)
list_size++;
max_width = 0;
for (counter = 0; counter <= list_size; counter++)
{
if ((length = strlen(menu_list[counter].item_string)) > max_width)
max_width = length;
}
max_width += 3;
max_width = max(max_width, strlen(cancel_string));
max_width = max(max_width, max(strlen(more_above_str), strlen(more_below_str)));
max_width += 6;
/*
| make sure that window is large enough to handle menu
| if not, print error message and return to calling function
*/
if (max_width > COLS)
{
wmove(com_win, 0, 0);
werase(com_win);
wprintw(com_win, menu_too_lrg_msg);
wrefresh(com_win);
clear_com_win = TRUE;
return(0);
}
top_offset = 0;
if (list_size > LINES)
{
max_height = LINES;
if (max_height > 11)
vert_size = max_height - 8;
else
vert_size = max_height;
}
else
{
vert_size = list_size;
max_height = list_size;
}
if (LINES >= (vert_size + 8))
{
if (menu_list[0].argument != MENU_WARN)
max_height = vert_size + 8;
else
max_height = vert_size + 7;
top_offset = 4;
}
x_off = (COLS - max_width) / 2;
y_off = (LINES - max_height - 1) / 2;
temp_win = newwin(max_height, max_width, y_off, x_off);
keypad(temp_win, TRUE);
paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size);
counter = 1;
vert_pos = 0;
do
{
if (off_start > 2)
wmove(temp_win, (1 + counter + top_offset - off_start), 3);
else
wmove(temp_win, (counter + top_offset - off_start), 3);
wrefresh(temp_win);
in = wgetch(temp_win);
input = in;
if (input == -1)
exit(0);
if (((tolower(input) >= 'a') && (tolower(input) <= 'z')) ||
((input >= '0') && (input <= '9')))
{
if ((tolower(input) >= 'a') && (tolower(input) <= 'z'))
{
temp = 1 + tolower(input) - 'a';
}
else if ((input >= '0') && (input <= '9'))
{
temp = (2 + 'z' - 'a') + (input - '0');
}
if (temp <= list_size)
{
input = '\n';
counter = temp;
}
}
else
{
switch (input)
{
case ' ': /* space */
case '\004': /* ^d, down */
case KEY_RIGHT:
case KEY_DOWN:
counter++;
if (counter > list_size)
counter = 1;
break;
case '\010': /* ^h, backspace*/
case '\025': /* ^u, up */
case 127: /* ^?, delete */
case KEY_BACKSPACE:
case KEY_LEFT:
case KEY_UP:
counter--;
if (counter == 0)
counter = list_size;
break;
case '\033': /* escape key */
if (menu_list[0].argument != MENU_WARN)
counter = 0;
break;
case '\014': /* ^l */
case '\022': /* ^r, redraw */
paint_menu(menu_list, max_width, max_height,
list_size, top_offset, temp_win,
off_start, vert_size);
break;
default:
break;
}
}
if (((list_size - off_start) >= (vert_size - 1)) &&
(counter > (off_start + vert_size - 3)) &&
(off_start > 1))
{
if (counter == list_size)
off_start = (list_size - vert_size) + 2;
else
off_start++;
paint_menu(menu_list, max_width, max_height,
list_size, top_offset, temp_win, off_start,
vert_size);
}
else if ((list_size != vert_size) &&
(counter > (off_start + vert_size - 2)))
{
if (counter == list_size)
off_start = 2 + (list_size - vert_size);
else if (off_start == 1)
off_start = 3;
else
off_start++;
paint_menu(menu_list, max_width, max_height,
list_size, top_offset, temp_win, off_start,
vert_size);
}
else if (counter < off_start)
{
if (counter <= 2)
off_start = 1;
else
off_start = counter;
paint_menu(menu_list, max_width, max_height,
list_size, top_offset, temp_win, off_start,
vert_size);
}
}
while ((input != '\r') && (input != '\n') && (counter != 0));
werase(temp_win);
wrefresh(temp_win);
delwin(temp_win);
if ((menu_list[counter].procedure != NULL) ||
(menu_list[counter].iprocedure != NULL) ||
(menu_list[counter].nprocedure != NULL))
{
if (menu_list[counter].argument != -1)
(*menu_list[counter].iprocedure)(menu_list[counter].argument);
else if (menu_list[counter].ptr_argument != NULL)
(*menu_list[counter].procedure)(menu_list[counter].ptr_argument);
else
(*menu_list[counter].nprocedure)();
}
if (info_window)
paint_info_win();
redraw();
return(counter);
}
void
paint_menu(menu_list, max_width, max_height, list_size, top_offset, menu_win,
off_start, vert_size)
struct menu_entries menu_list[];
int max_width, max_height, list_size, top_offset;
WINDOW *menu_win;
int off_start, vert_size;
{
int counter, temp_int;
werase(menu_win);
/*
| output top and bottom portions of menu box only if window
| large enough
*/
if (max_height > vert_size)
{
wmove(menu_win, 1, 1);
if (!nohighlight)
wstandout(menu_win);
waddch(menu_win, '+');
for (counter = 0; counter < (max_width - 4); counter++)
waddch(menu_win, '-');
waddch(menu_win, '+');
wmove(menu_win, (max_height - 2), 1);
waddch(menu_win, '+');
for (counter = 0; counter < (max_width - 4); counter++)
waddch(menu_win, '-');
waddch(menu_win, '+');
wstandend(menu_win);
wmove(menu_win, 2, 3);
waddstr(menu_win, menu_list[0].item_string);
wmove(menu_win, (max_height - 3), 3);
if (menu_list[0].argument != MENU_WARN)
waddstr(menu_win, cancel_string);
}
if (!nohighlight)
wstandout(menu_win);
for (counter = 0; counter < (vert_size + top_offset); counter++)
{
if (top_offset == 4)
{
temp_int = counter + 2;
}
else
temp_int = counter;
wmove(menu_win, temp_int, 1);
waddch(menu_win, '|');
wmove(menu_win, temp_int, (max_width - 2));
waddch(menu_win, '|');
}
wstandend(menu_win);
if (list_size > vert_size)
{
if (off_start >= 3)
{
temp_int = 1;
wmove(menu_win, top_offset, 3);
waddstr(menu_win, more_above_str);
}
else
temp_int = 0;
for (counter = off_start;
((temp_int + counter - off_start) < (vert_size - 1));
counter++)
{
wmove(menu_win, (top_offset + temp_int +
(counter - off_start)), 3);
if (list_size > 1)
wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
waddstr(menu_win, menu_list[counter].item_string);
}
wmove(menu_win, (top_offset + (vert_size - 1)), 3);
if (counter == list_size)
{
if (list_size > 1)
wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
wprintw(menu_win, menu_list[counter].item_string);
}
else
wprintw(menu_win, more_below_str);
}
else
{
for (counter = 1; counter <= list_size; counter++)
{
wmove(menu_win, (top_offset + counter - 1), 3);
if (list_size > 1)
wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
waddstr(menu_win, menu_list[counter].item_string);
}
}
}
void
help()
{
int counter;
werase(help_win);
clearok(help_win, TRUE);
for (counter = 0; counter < 22; counter++)
{
wmove(help_win, counter, 0);
waddstr(help_win, (emacs_keys_mode) ?
emacs_help_text[counter] : help_text[counter]);
}
wrefresh(help_win);
werase(com_win);
wmove(com_win, 0, 0);
wprintw(com_win, press_any_key_msg);
wrefresh(com_win);
counter = wgetch(com_win);
if (counter == -1)
exit(0);
werase(com_win);
wmove(com_win, 0, 0);
werase(help_win);
wrefresh(help_win);
wrefresh(com_win);
redraw();
}
void
paint_info_win()
{
int counter;
if (!info_window)
return;
werase(info_win);
for (counter = 0; counter < 5; counter++)
{
wmove(info_win, counter, 0);
wclrtoeol(info_win);
if (info_type == CONTROL_KEYS)
waddstr(info_win, (emacs_keys_mode) ?
emacs_control_keys[counter] : control_keys[counter]);
else if (info_type == COMMANDS)
waddstr(info_win, command_strings[counter]);
}
wmove(info_win, 5, 0);
if (!nohighlight)
wstandout(info_win);
waddstr(info_win, "===============================================================================");
wstandend(info_win);
wrefresh(info_win);
}
void
no_info_window()
{
if (!info_window)
return;
delwin(info_win);
delwin(text_win);
info_window = FALSE;
last_line = LINES - 2;
text_win = newwin((LINES - 1), COLS, 0, 0);
keypad(text_win, TRUE);
idlok(text_win, TRUE);
clearok(text_win, TRUE);
midscreen(scr_vert, point);
wrefresh(text_win);
clear_com_win = TRUE;
}
void
create_info_window()
{
if (info_window)
return;
last_line = LINES - 8;
delwin(text_win);
text_win = newwin((LINES - 7), COLS, 6, 0);
keypad(text_win, TRUE);
idlok(text_win, TRUE);
werase(text_win);
info_window = TRUE;
info_win = newwin(6, COLS, 0, 0);
werase(info_win);
info_type = CONTROL_KEYS;
midscreen(min(scr_vert, last_line), point);
clearok(info_win, TRUE);
paint_info_win();
wrefresh(text_win);
clear_com_win = TRUE;
}
int
file_op(arg)
int arg;
{
char *string;
int flag;
if (restrict_mode())
{
return(0);
}
if (arg == READ_FILE)
{
string = get_string(file_read_prompt_str, TRUE);
recv_file = TRUE;
tmp_file = resolve_name(string);
check_fp();
if (tmp_file != string)
free(tmp_file);
free(string);
}
else if (arg == WRITE_FILE)
{
string = get_string(file_write_prompt_str, TRUE);
tmp_file = resolve_name(string);
write_file(tmp_file);
if (tmp_file != string)
free(tmp_file);
free(string);
}
else if (arg == SAVE_FILE)
{
/*
| changes made here should be reflected in finish()
*/
if (in_file_name)
flag = TRUE;
else
flag = FALSE;
string = in_file_name;
if ((string == NULL) || (*string == (char) NULL))
string = get_string(save_file_name_prompt, TRUE);
if ((string == NULL) || (*string == (char) NULL))
{
wmove(com_win, 0, 0);
wprintw(com_win, file_not_saved_msg);
wclrtoeol(com_win);
wrefresh(com_win);
clear_com_win = TRUE;
return(0);
}
if (!flag)
{
tmp_file = resolve_name(string);
if (tmp_file != string)
{
free(string);
string = tmp_file;
}
}
if (write_file(string))
{
in_file_name = string;
text_changes = FALSE;
}
else if (!flag)
free(string);
}
return(0);
}
void
shell_op()
{
char *string;
if (((string = get_string(shell_prompt, TRUE)) != NULL) &&
(*string != (char) NULL))
{
sh_command(string);
free(string);
}
}
void
leave_op()
{
if (text_changes)
{
menu_op(leave_menu);
}
else
quit(TRUE);
}
void
redraw()
{
if (info_window)
{
clearok(info_win, TRUE);
paint_info_win();
}
else
clearok(text_win, TRUE);
midscreen(scr_vert, point);
}
/*
| The following routines will "format" a paragraph (as defined by a
| block of text with blank lines before and after the block).
*/
int
Blank_Line(test_line) /* test if line has any non-space characters */
struct text *test_line;
{
char *line;
int length;
if (test_line == NULL)
return(TRUE);
length = 1;
line = test_line->line;
/*
| To handle troff/nroff documents, consider a line with a
| period ('.') in the first column to be blank. To handle mail
| messages with included text, consider a line with a '>' blank.
*/
if ((*line == '.') || (*line == '>'))
return(TRUE);
while (((*line == ' ') || (*line == '\t')) && (length < test_line->line_length))
{
length++;
line++;
}
if (length != test_line->line_length)
return(FALSE);
else
return(TRUE);
}
void
Format() /* format the paragraph according to set margins */
{
int string_count;
int offset;
int temp_case;
int status;
int tmp_af;
int counter;
char *line;
char *tmp_srchstr;
char *temp1, *temp2;
char *temp_dword;
char temp_d_char = d_char;
/*
| if observ_margins is not set, or the current line is blank,
| do not format the current paragraph
*/
if ((!observ_margins) || (Blank_Line(curr_line)))
return;
/*
| save the currently set flags, and clear them
*/
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, formatting_msg);
wrefresh(com_win);
/*
| get current position in paragraph, so after formatting, the cursor
| will be in the same relative position
*/
tmp_af = auto_format;
auto_format = FALSE;
offset = position;
if (position != 1)
prev_word();
temp_dword = d_word;
d_word = NULL;
temp_case = case_sen;
case_sen = TRUE;
tmp_srchstr = srch_str;
temp2 = srch_str = (char *) malloc(1 + curr_line->line_length - position);
if ((*point == ' ') || (*point == '\t'))
adv_word();
offset -= position;
counter = position;
line = temp1 = point;
while ((*temp1 != (char) NULL) && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
{
*temp2 = *temp1;
temp2++;
temp1++;
counter++;
}
*temp2 = (char) NULL;
if (position != 1)
bol();
while (!Blank_Line(curr_line->prev_line))
bol();
string_count = 0;
status = TRUE;
while ((line != point) && (status))
{
status = search(FALSE);
string_count++;
}
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, formatting_msg);
wrefresh(com_win);
/*
| now get back to the start of the paragraph to start formatting
*/
if (position != 1)
bol();
while (!Blank_Line(curr_line->prev_line))
bol();
observ_margins = FALSE;
/*
| Start going through lines, putting spaces at end of lines if they do
| not already exist. Append lines together to get one long line, and
| eliminate spacing at begin of lines.
*/
while (!Blank_Line(curr_line->next_line))
{
eol();
left(TRUE);
if (*point != ' ')
{
right(TRUE);
insert(' ');
}
else
right(TRUE);
del_char();
if ((*point == ' ') || (*point == '\t'))
del_word();
}
/*
| Now there is one long line. Eliminate extra spaces within the line
| after the first word (so as not to blow away any indenting the user
| may have put in).
*/
bol();
adv_word();
while (position < curr_line->line_length)
{
if ((*point == ' ') && (*(point + 1) == ' '))
del_char();
else
right(TRUE);
}
/*
| Now make sure there are two spaces after a '.'.
*/
bol();
while (position < curr_line->line_length)
{
if ((*point == '.') && (*(point + 1) == ' '))
{
right(TRUE);
insert(' ');
insert(' ');
while (*point == ' ')
del_char();
}
right(TRUE);
}
observ_margins = TRUE;
bol();
wmove(com_win, 0, 0);
wclrtoeol(com_win);
wprintw(com_win, formatting_msg);
wrefresh(com_win);
/*
| create lines between margins
*/
while (position < curr_line->line_length)
{
while ((scr_pos < right_margin) && (position < curr_line->line_length))
right(TRUE);
if (position < curr_line->line_length)
{
prev_word();
if (position == 1)
adv_word();
insert_line(TRUE);
}
}
/*
| go back to begin of paragraph, put cursor back to original position
*/
bol();
while (!Blank_Line(curr_line->prev_line))
bol();
/*
| find word cursor was in
*/
while ((status) && (string_count > 0))
{
search(FALSE);
string_count--;
}
/*
| offset the cursor to where it was before from the start of the word
*/
while (offset > 0)
{
offset--;
right(TRUE);
}
/*
| reset flags and strings to what they were before formatting
*/
if (d_word != NULL)
free(d_word);
d_word = temp_dword;
case_sen = temp_case;
free(srch_str);
srch_str = tmp_srchstr;
d_char = temp_d_char;
auto_format = tmp_af;
midscreen(scr_vert, point);
werase(com_win);
wrefresh(com_win);
}
char *init_name[3] = {
"/usr/local/lib/init.ee",
NULL,
".init.ee"
};
void
ee_init() /* check for init file and read it if it exists */
{
FILE *init_file;
char *string;
char *str1;
char *str2;
char *home;
int counter;
int temp_int;
string = getenv("HOME");
str1 = home = malloc(strlen(string)+10);
strcpy(home, string);
strcat(home, "/.init.ee");
init_name[1] = home;
string = malloc(512);
for (counter = 0; counter < 3; counter++)
{
if (!(access(init_name[counter], 4)))
{
init_file = fopen(init_name[counter], "r");
while ((str2 = fgets(string, 512, init_file)) != NULL)
{
str1 = str2 = string;
while (*str2 != '\n')
str2++;
*str2 = (char) NULL;
if (unique_test(string, init_strings) != 1)
continue;
if (compare(str1, CASE, FALSE))
case_sen = TRUE;
else if (compare(str1, NOCASE, FALSE))
case_sen = FALSE;
else if (compare(str1, EXPAND, FALSE))
expand_tabs = TRUE;
else if (compare(str1, NOEXPAND, FALSE))
expand_tabs = FALSE;
else if (compare(str1, INFO, FALSE))
info_window = TRUE;
else if (compare(str1, NOINFO, FALSE))
info_window = FALSE;
else if (compare(str1, MARGINS, FALSE))
observ_margins = TRUE;
else if (compare(str1, NOMARGINS, FALSE))
observ_margins = FALSE;
else if (compare(str1, AUTOFORMAT, FALSE))
{
auto_format = TRUE;
observ_margins = TRUE;
}
else if (compare(str1, NOAUTOFORMAT, FALSE))
auto_format = FALSE;
else if (compare(str1, Echo, FALSE))
{
str1 = next_word(str1);
if (*str1 != (char) NULL)
echo_string(str1);
}
else if (compare(str1, PRINTCOMMAND, FALSE))
{
str1 = next_word(str1);
print_command = malloc(strlen(str1)+1);
strcpy(print_command, str1);
}
else if (compare(str1, RIGHTMARGIN, FALSE))
{
str1 = next_word(str1);
if ((*str1 >= '0') && (*str1 <= '9'))
{
temp_int = atoi(str1);
if (temp_int > 0)
right_margin = temp_int;
}
}
else if (compare(str1, HIGHLIGHT, FALSE))
nohighlight = FALSE;
else if (compare(str1, NOHIGHLIGHT, FALSE))
nohighlight = TRUE;
else if (compare(str1, EIGHTBIT, FALSE))
eightbit = TRUE;
else if (compare(str1, NOEIGHTBIT, FALSE))
eightbit = FALSE;
else if (compare(str1, EMACS_string, FALSE))
emacs_keys_mode = TRUE;
else if (compare(str1, NOEMACS_string, FALSE))
emacs_keys_mode = FALSE;
}
fclose(init_file);
}
}
free(string);
free(home);
}
/*
| Save current configuration to .init.ee file in the current directory.
*/
void
dump_ee_conf()
{
FILE *init_file;
FILE *old_init_file = NULL;
char *file_name = ".init.ee";
char *home_dir = "~/.init.ee";
char buffer[512];
struct stat buf;
char *string;
int length;
int option = 0;
if (restrict_mode())
{
return;
}
option = menu_op(config_dump_menu);
werase(com_win);
wmove(com_win, 0, 0);
if (option == 0)
{
wprintw(com_win, conf_not_saved_msg);
wrefresh(com_win);
return;
}
else if (option == 2)
file_name = resolve_name(home_dir);
/*
| If a .init.ee file exists, move it to .init.ee.old.
*/
if (stat(file_name, &buf) != -1)
{
sprintf(buffer, "%s.old", file_name);
unlink(buffer);
link(file_name, buffer);
unlink(file_name);
old_init_file = fopen(buffer, "r");
}
init_file = fopen(file_name, "w");
if (init_file == NULL)
{
wprintw(com_win, conf_dump_err_msg);
wrefresh(com_win);
return;
}
if (old_init_file != NULL)
{
/*
| Copy non-configuration info into new .init.ee file.
*/
while ((string = fgets(buffer, 512, old_init_file)) != NULL)
{
length = strlen(string);
string[length - 1] = (char) NULL;
if (unique_test(string, init_strings) == 1)
{
if (compare(string, Echo, FALSE))
{
fprintf(init_file, "%s\n", string);
}
}
else
fprintf(init_file, "%s\n", string);
}
fclose(old_init_file);
}
fprintf(init_file, "%s\n", case_sen ? CASE : NOCASE);
fprintf(init_file, "%s\n", expand_tabs ? EXPAND : NOEXPAND);
fprintf(init_file, "%s\n", info_window ? INFO : NOINFO );
fprintf(init_file, "%s\n", observ_margins ? MARGINS : NOMARGINS );
fprintf(init_file, "%s\n", auto_format ? AUTOFORMAT : NOAUTOFORMAT );
fprintf(init_file, "%s %s\n", PRINTCOMMAND, print_command);
fprintf(init_file, "%s %d\n", RIGHTMARGIN, right_margin);
fprintf(init_file, "%s\n", nohighlight ? NOHIGHLIGHT : HIGHLIGHT );
fprintf(init_file, "%s\n", eightbit ? EIGHTBIT : NOEIGHTBIT );
fprintf(init_file, "%s\n", emacs_keys_mode ? EMACS_string : NOEMACS_string );
fclose(init_file);
wprintw(com_win, conf_dump_success_msg, file_name);
wrefresh(com_win);
if ((option == 2) && (file_name != home_dir))
{
free(file_name);
}
}
void
echo_string(string) /* echo the given string */
char *string;
{
char *temp;
int Counter;
temp = string;
while (*temp != (char) NULL)
{
if (*temp == '\\')
{
temp++;
if (*temp == 'n')
putchar('\n');
else if (*temp == 't')
putchar('\t');
else if (*temp == 'b')
putchar('\b');
else if (*temp == 'r')
putchar('\r');
else if (*temp == 'f')
putchar('\f');
else if ((*temp == 'e') || (*temp == 'E'))
putchar('\033'); /* escape */
else if (*temp == '\\')
putchar('\\');
else if (*temp == '\'')
putchar('\'');
else if ((*temp >= '0') && (*temp <= '9'))
{
Counter = 0;
while ((*temp >= '0') && (*temp <= '9'))
{
Counter = (8 * Counter) + (*temp - '0');
temp++;
}
putchar(Counter);
temp--;
}
temp++;
}
else
{
putchar(*temp);
temp++;
}
}
fflush(stdout);
}
void
spell_op() /* check spelling of words in the editor */
{
if (restrict_mode())
{
return;
}
top(); /* go to top of file */
insert_line(FALSE); /* create two blank lines */
insert_line(FALSE);
top();
command(shell_echo_msg);
adv_line();
wmove(com_win, 0, 0);
wprintw(com_win, spell_in_prog_msg);
wrefresh(com_win);
command("<>!spell"); /* send contents of buffer to command 'spell'
and read the results back into the editor */
}
void
ispell_op()
{
char name[128];
char string[256];
int pid;
if (restrict_mode())
{
return;
}
pid = getpid();
sprintf(name, "/tmp/ee.%d", pid);
if (write_file(name))
{
sprintf(string, "ispell %s", name);
sh_command(string);
delete_text();
tmp_file = name;
recv_file = TRUE;
check_fp();
unlink(name);
}
}
int
first_word_len(test_line)
struct text *test_line;
{
int counter;
char *pnt;
if (test_line == NULL)
return(0);
pnt = test_line->line;
if ((pnt == NULL) || (*pnt == (char) NULL) ||
(*pnt == '.') || (*pnt == '>'))
return(0);
if ((*pnt == ' ') || (*pnt == '\t'))
{
pnt = next_word(pnt);
}
if (*pnt == (char) NULL)
return(0);
counter = 0;
while ((*pnt != (char) NULL) && ((*pnt != ' ') && (*pnt != '\t')))
{
pnt++;
counter++;
}
while ((*pnt != (char) NULL) && ((*pnt == ' ') || (*pnt == '\t')))
{
pnt++;
counter++;
}
return(counter);
}
void
Auto_Format() /* format the paragraph according to set margins */
{
int string_count;
int offset;
int temp_case;
int word_len;
int temp_dwl;
int tmp_d_line_length;
int leave_loop = FALSE;
int status;
int counter;
char *line;
char *tmp_srchstr;
char *temp1, *temp2;
char *temp_dword;
char temp_d_char = d_char;
char *tmp_d_line;
/*
| if observ_margins is not set, or the current line is blank,
| do not format the current paragraph
*/
if ((!observ_margins) || (Blank_Line(curr_line)))
return;
/*
| get current position in paragraph, so after formatting, the cursor
| will be in the same relative position
*/
tmp_d_line = d_line;
tmp_d_line_length = dlt_line->line_length;
d_line = NULL;
auto_format = FALSE;
offset = position;
if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == (char) NULL)))
prev_word();
temp_dword = d_word;
temp_dwl = d_wrd_len;
d_wrd_len = 0;
d_word = NULL;
temp_case = case_sen;
case_sen = TRUE;
tmp_srchstr = srch_str;
temp2 = srch_str = (char *) malloc(1 + curr_line->line_length - position);
if ((*point == ' ') || (*point == '\t'))
adv_word();
offset -= position;
counter = position;
line = temp1 = point;
while ((*temp1 != (char) NULL) && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
{
*temp2 = *temp1;
temp2++;
temp1++;
counter++;
}
*temp2 = (char) NULL;
if (position != 1)
bol();
while (!Blank_Line(curr_line->prev_line))
bol();
string_count = 0;
status = TRUE;
while ((line != point) && (status))
{
status = search(FALSE);
string_count++;
}
/*
| now get back to the start of the paragraph to start checking
*/
if (position != 1)
bol();
while (!Blank_Line(curr_line->prev_line))
bol();
/*
| Start going through lines, putting spaces at end of lines if they do
| not already exist. Check line length, and move words to the next line
| if they cross the margin. Then get words from the next line if they
| will fit in before the margin.
*/
while (!leave_loop)
{
if (position != curr_line->line_length)
eol();
left(TRUE);
if (*point != ' ')
{
right(TRUE);
insert(' ');
}
else
right(TRUE);
/*
| fill line if first word on next line will fit
| in the line without crossing the margin
*/
while ((curr_line->next_line != NULL) &&
((word_len = first_word_len(curr_line->next_line)) > 0)
&& ((scr_pos + word_len) < right_margin))
{
adv_line();
if ((*point == ' ') || (*point == '\t'))
adv_word();
del_word();
if (position != 1)
bol();
if (Blank_Line(curr_line))
{
del_line();
}
/*
| go to end of previous line
*/
left(TRUE);
undel_word();
eol();
/*
| make sure there's a space at the end of the line
*/
left(TRUE);
if (*point != ' ')
{
right(TRUE);
insert(' ');
}
else
right(TRUE);
}
/*
| make sure line does not cross right margin
*/
while (right_margin <= scr_pos)
{
prev_word();
if (position != 1)
{
del_word();
if (Blank_Line(curr_line->next_line))
insert_line(TRUE);
else
adv_line();
if ((*point == ' ') || (*point == '\t'))
adv_word();
undel_word();
if (position != 1)
bol();
left(TRUE);
}
}
if (!Blank_Line(curr_line->next_line))
adv_line();
else
leave_loop = TRUE;
}
/*
| go back to begin of paragraph, put cursor back to original position
*/
bol();
while (!Blank_Line(curr_line->prev_line))
bol();
/*
| find word cursor was in
*/
status = TRUE;
while ((status) && (string_count > 0))
{
status = search(FALSE);
string_count--;
}
/*
| offset the cursor to where it was before from the start of the word
*/
while (offset > 0)
{
offset--;
right(TRUE);
}
if ((string_count > 0) && (offset < 0))
{
while (offset < 0)
{
offset++;
left(TRUE);
}
}
/*
| reset flags and strings to what they were before formatting
*/
if (d_word != NULL)
free(d_word);
d_word = temp_dword;
d_wrd_len = temp_dwl;
case_sen = temp_case;
free(srch_str);
srch_str = tmp_srchstr;
d_char = temp_d_char;
auto_format = TRUE;
dlt_line->line_length = tmp_d_line_length;
d_line = tmp_d_line;
formatted = TRUE;
midscreen(scr_vert, point);
}
void
modes_op()
{
int ret_value;
int counter;
char *string;
do
{
sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1],
(expand_tabs ? ON : OFF));
sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2],
(case_sen ? ON : OFF));
sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3],
(observ_margins ? ON : OFF));
sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4],
(auto_format ? ON : OFF));
sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5],
(eightbit ? ON : OFF));
sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6],
(info_window ? ON : OFF));
sprintf(modes_menu[7].item_string, "%s %s", mode_strings[7],
(emacs_keys_mode ? ON : OFF));
sprintf(modes_menu[8].item_string, "%s %d", mode_strings[8],
right_margin);
ret_value = menu_op(modes_menu);
switch (ret_value)
{
case 1:
expand_tabs = !expand_tabs;
break;
case 2:
case_sen = !case_sen;
break;
case 3:
observ_margins = !observ_margins;
break;
case 4:
auto_format = !auto_format;
if (auto_format)
observ_margins = TRUE;
break;
case 5:
eightbit = !eightbit;
redraw();
wnoutrefresh(text_win);
break;
case 6:
if (info_window)
no_info_window();
else
create_info_window();
break;
case 7:
emacs_keys_mode = !emacs_keys_mode;
if (info_window)
paint_info_win();
break;
case 8:
string = get_string(margin_prompt, TRUE);
if (string != NULL)
{
counter = atoi(string);
if (counter > 0)
right_margin = counter;
free(string);
}
break;
default:
break;
}
}
while (ret_value != 0);
}
char *
is_in_string(string, substring) /* a strchr() look-alike for systems without
strchr() */
char * string, *substring;
{
char *full, *sub;
for (sub = substring; (sub != NULL) && (*sub != (char)NULL); sub++)
{
for (full = string; (full != NULL) && (*full != (char)NULL);
full++)
{
if (*sub == *full)
return(full);
}
}
return(NULL);
}
/*
| handle names of the form "~/file", "~user/file",
| "$HOME/foo", "~/$FOO", etc.
*/
char *
resolve_name(name)
char *name;
{
char long_buffer[1024];
char short_buffer[128];
char *buffer;
char *slash;
char *tmp;
char *start_of_var;
int offset;
int index;
int counter;
struct passwd *user;
if (name[0] == '~')
{
if (name[1] == '/')
{
index = getuid();
user = (struct passwd *) getpwuid(index);
slash = name + 1;
}
else
{
slash = strchr(name, '/');
if (slash == NULL)
return(name);
*slash = (char) NULL;
user = (struct passwd *) getpwnam((name + 1));
*slash = '/';
}
if (user == NULL)
{
return(name);
}
buffer = malloc(strlen(user->pw_dir) + strlen(slash) + 1);
strcpy(buffer, user->pw_dir);
strcat(buffer, slash);
}
else
buffer = name;
if (is_in_string(buffer, "$"))
{
tmp = buffer;
index = 0;
while ((*tmp != (char) NULL) && (index < 1024))
{
while ((*tmp != (char) NULL) && (*tmp != '$') &&
(index < 1024))
{
long_buffer[index] = *tmp;
tmp++;
index++;
}
if ((*tmp == '$') && (index < 1024))
{
counter = 0;
start_of_var = tmp;
tmp++;
if (*tmp == '{') /* } */ /* bracketed variable name */
{
tmp++; /* { */
while ((*tmp != (char) NULL) &&
(*tmp != '}') &&
(counter < 128))
{
short_buffer[counter] = *tmp;
counter++;
tmp++;
} /* { */
if (*tmp == '}')
tmp++;
}
else
{
while ((*tmp != (char) NULL) &&
(*tmp != '/') &&
(*tmp != '$') &&
(counter < 128))
{
short_buffer[counter] = *tmp;
counter++;
tmp++;
}
}
short_buffer[counter] = (char) NULL;
if ((slash = getenv(short_buffer)) != NULL)
{
offset = strlen(slash);
if ((offset + index) < 1024)
strcpy(&long_buffer[index], slash);
index += offset;
}
else
{
while ((start_of_var != tmp) && (index < 1024))
{
long_buffer[index] = *start_of_var;
start_of_var++;
index++;
}
}
}
}
if (index == 1024)
return(buffer);
else
long_buffer[index] = (char) NULL;
if (name != buffer)
free(buffer);
buffer = malloc(index + 1);
strcpy(buffer, long_buffer);
}
return(buffer);
}
int
restrict_mode()
{
if (!restricted)
return(FALSE);
wmove(com_win, 0, 0);
wprintw(com_win, restricted_msg);
wclrtoeol(com_win);
wrefresh(com_win);
clear_com_win = TRUE;
return(TRUE);
}
/*
| The following routine tests the input string against the list of
| strings, to determine if the string is a unique match with one of the
| valid values.
*/
int
unique_test(string, list)
char *string;
char *list[];
{
int counter;
int num_match;
int result;
num_match = 0;
counter = 0;
while (list[counter] != NULL)
{
result = compare(string, list[counter], FALSE);
if (result)
num_match++;
counter++;
}
return(num_match);
}
#ifndef NO_CATGETS
/*
| Get the catalog entry, and if it got it from the catalog,
| make a copy, since the buffer will be overwritten by the
| next call to catgets().
*/
char *
catgetlocal(number, string)
int number;
char *string;
{
char *temp1;
char *temp2;
temp1 = catgets(catalog, 1, number, string);
if (temp1 != string)
{
temp2 = malloc(strlen(temp1) + 1);
strcpy(temp2, temp1);
temp1 = temp2;
}
return(temp1);
}
#endif /* NO_CATGETS */
/*
| The following is to allow for using message catalogs which allow
| the software to be 'localized', that is, to use different languages
| all with the same binary. For more information, see your system
| documentation, or the X/Open Internationalization Guide.
*/
void
strings_init()
{
int counter;
#ifndef NO_CATGETS
setlocale(LC_ALL, "");
catalog = catopen("ee", 0);
#endif /* NO_CATGETS */
modes_menu[0].item_string = catgetlocal( 1, "modes menu");
mode_strings[1] = catgetlocal( 2, "tabs to spaces ");
mode_strings[2] = catgetlocal( 3, "case sensitive search");
mode_strings[3] = catgetlocal( 4, "margins observed ");
mode_strings[4] = catgetlocal( 5, "auto-paragraph format");
mode_strings[5] = catgetlocal( 6, "eightbit characters ");
mode_strings[6] = catgetlocal( 7, "info window ");
mode_strings[8] = catgetlocal( 8, "right margin ");
leave_menu[0].item_string = catgetlocal( 9, "leave menu");
leave_menu[1].item_string = catgetlocal( 10, "save changes");
leave_menu[2].item_string = catgetlocal( 11, "no save");
file_menu[0].item_string = catgetlocal( 12, "file menu");
file_menu[1].item_string = catgetlocal( 13, "read a file");
file_menu[2].item_string = catgetlocal( 14, "write a file");
file_menu[3].item_string = catgetlocal( 15, "save file");
file_menu[4].item_string = catgetlocal( 16, "print editor contents");
search_menu[0].item_string = catgetlocal( 17, "search menu");
search_menu[1].item_string = catgetlocal( 18, "search for ...");
search_menu[2].item_string = catgetlocal( 19, "search");
spell_menu[0].item_string = catgetlocal( 20, "spell menu");
spell_menu[1].item_string = catgetlocal( 21, "use 'spell'");
spell_menu[2].item_string = catgetlocal( 22, "use 'ispell'");
misc_menu[0].item_string = catgetlocal( 23, "miscellaneous menu");
misc_menu[1].item_string = catgetlocal( 24, "format paragraph");
misc_menu[2].item_string = catgetlocal( 25, "shell command");
misc_menu[3].item_string = catgetlocal( 26, "check spelling");
main_menu[0].item_string = catgetlocal( 27, "main menu");
main_menu[1].item_string = catgetlocal( 28, "leave editor");
main_menu[2].item_string = catgetlocal( 29, "help");
main_menu[3].item_string = catgetlocal( 30, "file operations");
main_menu[4].item_string = catgetlocal( 31, "redraw screen");
main_menu[5].item_string = catgetlocal( 32, "settings");
main_menu[6].item_string = catgetlocal( 33, "search");
main_menu[7].item_string = catgetlocal( 34, "miscellaneous");
help_text[0] = catgetlocal( 35, "Control keys: ");
help_text[1] = catgetlocal( 36, "^a ascii code ^i tab ^r right ");
help_text[2] = catgetlocal( 37, "^b bottom of text ^j newline ^t top of text ");
help_text[3] = catgetlocal( 38, "^c command ^k delete char ^u up ");
help_text[4] = catgetlocal( 39, "^d down ^l left ^v undelete word ");
help_text[5] = catgetlocal( 40, "^e search prompt ^m newline ^w delete word ");
help_text[6] = catgetlocal( 41, "^f undelete char ^n next page ^x search ");
help_text[7] = catgetlocal( 42, "^g begin of line ^o end of line ^y delete line ");
help_text[8] = catgetlocal( 43, "^h backspace ^p prev page ^z undelete line ");
help_text[9] = catgetlocal( 44, "^[ (escape) menu ");
help_text[10] = catgetlocal( 45, " ");
help_text[11] = catgetlocal( 46, "Commands: ");
help_text[12] = catgetlocal( 47, "help : get this info file : print file name ");
help_text[13] = catgetlocal( 48, "read : read a file char : ascii code of char ");
help_text[14] = catgetlocal( 49, "write : write a file case : case sensitive search ");
help_text[15] = catgetlocal( 50, "exit : leave and save nocase : case insensitive search ");
help_text[16] = catgetlocal( 51, "quit : leave, no save !cmd : execute \"cmd\" in shell ");
help_text[17] = catgetlocal( 52, "line : display line # 0-9 : go to line \"#\" ");
help_text[18] = catgetlocal( 53, "expand : expand tabs noexpand: do not expand tabs ");
help_text[19] = catgetlocal( 54, " ");
help_text[20] = catgetlocal( 55, " ee [-i] [-e] [-h] [file(s)] ");
help_text[21] = catgetlocal( 56, " -i : no information window -e : do not expand tabs -h : no highlight ");
control_keys[0] = catgetlocal( 57, "^[ (escape) menu ^e search prompt ^y delete line ^u up ^p prev page ");
control_keys[1] = catgetlocal( 58, "^a ascii code ^x search ^z undelete line ^d down ^n next page ");
control_keys[2] = catgetlocal( 59, "^b bottom of text ^g begin of line ^w delete word ^l left ");
control_keys[3] = catgetlocal( 60, "^t top of text ^o end of line ^v undelete word ^r right ");
control_keys[4] = catgetlocal( 61, "^c command ^k delete char ^f undelete char ");
command_strings[0] = catgetlocal( 62, "help : get help info |file : print file name |line : print line # ");
command_strings[1] = catgetlocal( 63, "read : read a file |char : ascii code of char |0-9 : go to line \"#\"");
command_strings[2] = catgetlocal( 64, "write: write a file |case : case sensitive search |exit : leave and save ");
command_strings[3] = catgetlocal( 65, "!cmd : shell \"cmd\" |nocase: ignore case in search |quit : leave, no save");
command_strings[4] = catgetlocal( 66, "expand: expand tabs |noexpand: do not expand tabs ");
com_win_message = catgetlocal( 67, " press Escape (^[) for menu");
no_file_string = catgetlocal( 68, "no file");
ascii_code_str = catgetlocal( 69, "ascii code: ");
printer_msg_str = catgetlocal( 70, "sending contents of buffer to \"%s\" ");
command_str = catgetlocal( 71, "command: ");
file_write_prompt_str = catgetlocal( 72, "name of file to write: ");
file_read_prompt_str = catgetlocal( 73, "name of file to read: ");
char_str = catgetlocal( 74, "character = %d");
unkn_cmd_str = catgetlocal( 75, "unknown command \"%s\"");
non_unique_cmd_msg = catgetlocal( 76, "entered command is not unique");
line_num_str = catgetlocal( 77, "line %d ");
line_len_str = catgetlocal( 78, "length = %d");
current_file_str = catgetlocal( 79, "current file is \"%s\" ");
usage0 = catgetlocal( 80, "usage: %s [-i] [-e] [-h] [+line_number] [file(s)]\n");
usage1 = catgetlocal( 81, " -i turn off info window\n");
usage2 = catgetlocal( 82, " -e do not convert tabs to spaces\n");
usage3 = catgetlocal( 83, " -h do not use highlighting\n");
file_is_dir_msg = catgetlocal( 84, "file \"%s\" is a directory");
new_file_msg = catgetlocal( 85, "new file \"%s\"");
cant_open_msg = catgetlocal( 86, "can't open \"%s\"");
open_file_msg = catgetlocal( 87, "file \"%s\", %d lines");
file_read_fin_msg = catgetlocal( 88, "finished reading file \"%s\"");
reading_file_msg = catgetlocal( 89, "reading file \"%s\"");
read_only_msg = catgetlocal( 90, ", read only");
file_read_lines_msg = catgetlocal( 91, "file \"%s\", %d lines");
save_file_name_prompt = catgetlocal( 92, "enter name of file: ");
file_not_saved_msg = catgetlocal( 93, "no filename entered: file not saved");
changes_made_prompt = catgetlocal( 94, "changes have been made, are you sure? (y/n [n]) ");
yes_char = catgetlocal( 95, "y");
file_exists_prompt = catgetlocal( 96, "file already exists, overwrite? (y/n) [n] ");
create_file_fail_msg = catgetlocal( 97, "unable to create file \"%s\"");
writing_file_msg = catgetlocal( 98, "writing file \"%s\"");
file_written_msg = catgetlocal( 99, "\"%s\" %d lines, %d characters");
searching_msg = catgetlocal( 100, " ...searching");
str_not_found_msg = catgetlocal( 101, "string \"%s\" not found");
search_prompt_str = catgetlocal( 102, "search for: ");
exec_err_msg = catgetlocal( 103, "could not exec %s\n");
continue_msg = catgetlocal( 104, "press return to continue ");
menu_cancel_msg = catgetlocal( 105, "press Esc to cancel");
menu_size_err_msg = catgetlocal( 106, "menu too large for window");
press_any_key_msg = catgetlocal( 107, "press any key to continue ");
shell_prompt = catgetlocal( 108, "shell command: ");
formatting_msg = catgetlocal( 109, "...formatting paragraph...");
shell_echo_msg = catgetlocal( 110, "<!echo 'list of unrecognized words'; echo -=-=-=-=-=-");
spell_in_prog_msg = catgetlocal( 111, "sending contents of edit buffer to 'spell'");
margin_prompt = catgetlocal( 112, "right margin is: ");
restricted_msg = catgetlocal( 113, "restricted mode: unable to perform requested operation");
ON = catgetlocal( 114, "ON");
OFF = catgetlocal( 115, "OFF");
HELP = catgetlocal( 116, "HELP");
WRITE = catgetlocal( 117, "WRITE");
READ = catgetlocal( 118, "READ");
LINE = catgetlocal( 119, "LINE");
FILE_str = catgetlocal( 120, "FILE");
CHARACTER = catgetlocal( 121, "CHARACTER");
REDRAW = catgetlocal( 122, "REDRAW");
RESEQUENCE = catgetlocal( 123, "RESEQUENCE");
AUTHOR = catgetlocal( 124, "AUTHOR");
VERSION = catgetlocal( 125, "VERSION");
CASE = catgetlocal( 126, "CASE");
NOCASE = catgetlocal( 127, "NOCASE");
EXPAND = catgetlocal( 128, "EXPAND");
NOEXPAND = catgetlocal( 129, "NOEXPAND");
Exit_string = catgetlocal( 130, "EXIT");
QUIT_string = catgetlocal( 131, "QUIT");
INFO = catgetlocal( 132, "INFO");
NOINFO = catgetlocal( 133, "NOINFO");
MARGINS = catgetlocal( 134, "MARGINS");
NOMARGINS = catgetlocal( 135, "NOMARGINS");
AUTOFORMAT = catgetlocal( 136, "AUTOFORMAT");
NOAUTOFORMAT = catgetlocal( 137, "NOAUTOFORMAT");
Echo = catgetlocal( 138, "ECHO");
PRINTCOMMAND = catgetlocal( 139, "PRINTCOMMAND");
RIGHTMARGIN = catgetlocal( 140, "RIGHTMARGIN");
HIGHLIGHT = catgetlocal( 141, "HIGHLIGHT");
NOHIGHLIGHT = catgetlocal( 142, "NOHIGHLIGHT");
EIGHTBIT = catgetlocal( 143, "EIGHTBIT");
NOEIGHTBIT = catgetlocal( 144, "NOEIGHTBIT");
/*
| additions
*/
mode_strings[7] = catgetlocal( 145, "emacs key bindings ");
emacs_help_text[0] = help_text[0];
emacs_help_text[1] = catgetlocal( 146, "^a beginning of line ^i tab ^r restore word ");
emacs_help_text[2] = catgetlocal( 147, "^b back 1 char ^j undel char ^t top of text ");
emacs_help_text[3] = catgetlocal( 148, "^c command ^k delete line ^u bottom of text ");
emacs_help_text[4] = catgetlocal( 149, "^d delete char ^l undelete line ^v next page ");
emacs_help_text[5] = catgetlocal( 150, "^e end of line ^m newline ^w delete word ");
emacs_help_text[6] = catgetlocal( 151, "^f forward 1 char ^n next line ^x search ");
emacs_help_text[7] = catgetlocal( 152, "^g go back 1 page ^o ascii char insert ^y search prompt ");
emacs_help_text[8] = catgetlocal( 153, "^h backspace ^p prev line ^z next word ");
emacs_help_text[9] = help_text[9];
emacs_help_text[10] = help_text[10];
emacs_help_text[11] = help_text[11];
emacs_help_text[12] = help_text[12];
emacs_help_text[13] = help_text[13];
emacs_help_text[14] = help_text[14];
emacs_help_text[15] = help_text[15];
emacs_help_text[16] = help_text[16];
emacs_help_text[17] = help_text[17];
emacs_help_text[18] = help_text[18];
emacs_help_text[19] = help_text[19];
emacs_help_text[20] = help_text[20];
emacs_help_text[21] = help_text[21];
emacs_control_keys[0] = catgetlocal( 154, "^[ (escape) menu ^y search prompt ^k delete line ^p prev li ^g prev page");
emacs_control_keys[1] = catgetlocal( 155, "^o ascii code ^x search ^l undelete line ^n next li ^v next page");
emacs_control_keys[2] = catgetlocal( 156, "^u end of file ^a begin of line ^w delete word ^b back 1 char ");
emacs_control_keys[3] = catgetlocal( 157, "^t top of text ^e end of line ^r restore word ^f forward 1 char ");
emacs_control_keys[4] = catgetlocal( 158, "^c command ^d delete char ^j undelete char ^z next word ");
EMACS_string = catgetlocal( 159, "EMACS");
NOEMACS_string = catgetlocal( 160, "NOEMACS");
usage4 = catgetlocal( 161, " +# put cursor at line #\n");
conf_dump_err_msg = catgetlocal( 162, "unable to open .init.ee for writing, no configuration saved!");
conf_dump_success_msg = catgetlocal( 163, "ee configuration saved in file %s");
modes_menu[9].item_string = catgetlocal( 164, "save editor configuration");
config_dump_menu[0].item_string = catgetlocal( 165, "save ee configuration");
config_dump_menu[1].item_string = catgetlocal( 166, "save in current directory");
config_dump_menu[2].item_string = catgetlocal( 167, "save in home directory");
conf_not_saved_msg = catgetlocal( 168, "ee configuration not saved");
ree_no_file_msg = catgetlocal( 169, "must specify a file when invoking ree");
cancel_string = catgetlocal( 170, "press Esc to cancel");
menu_too_lrg_msg = catgetlocal( 180, "menu too large for window");
more_above_str = catgetlocal( 181, "^^more^^");
more_below_str = catgetlocal( 182, "VVmoreVV");
commands[0] = HELP;
commands[1] = WRITE;
commands[2] = READ;
commands[3] = LINE;
commands[4] = FILE_str;
commands[5] = REDRAW;
commands[6] = RESEQUENCE;
commands[7] = AUTHOR;
commands[8] = VERSION;
commands[9] = CASE;
commands[10] = NOCASE;
commands[11] = EXPAND;
commands[12] = NOEXPAND;
commands[13] = Exit_string;
commands[14] = QUIT_string;
commands[15] = "<";
commands[16] = ">";
commands[17] = "!";
commands[18] = "0";
commands[19] = "1";
commands[20] = "2";
commands[21] = "3";
commands[22] = "4";
commands[23] = "5";
commands[24] = "6";
commands[25] = "7";
commands[26] = "8";
commands[27] = "9";
commands[28] = CHARACTER;
commands[29] = NULL;
init_strings[0] = CASE;
init_strings[1] = NOCASE;
init_strings[2] = EXPAND;
init_strings[3] = NOEXPAND;
init_strings[4] = INFO;
init_strings[5] = NOINFO;
init_strings[6] = MARGINS;
init_strings[7] = NOMARGINS;
init_strings[8] = AUTOFORMAT;
init_strings[9] = NOAUTOFORMAT;
init_strings[10] = Echo;
init_strings[11] = PRINTCOMMAND;
init_strings[12] = RIGHTMARGIN;
init_strings[13] = HIGHLIGHT;
init_strings[14] = NOHIGHLIGHT;
init_strings[15] = EIGHTBIT;
init_strings[16] = NOEIGHTBIT;
init_strings[17] = EMACS_string;
init_strings[18] = NOEMACS_string;
init_strings[19] = NULL;
/*
| allocate space for strings here for settings menu
*/
for (counter = 1; counter < NUM_MODES_ITEMS; counter++)
{
modes_menu[counter].item_string = malloc(80);
}
#ifndef NO_CATGETS
catclose(catalog);
#endif /* NO_CATGETS */
}
|