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
|
/***********************************************************************/
/* EXECUTE.C - */
/* This file contains all functions that actually execute one or other */
/* commands. */
/***********************************************************************/
/*
* THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
* Copyright (C) 1991-1997 Mark Hessling
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
*
* The Free Software Foundation, Inc.
* 675 Mass Ave,
* Cambridge, MA 02139 USA.
*
*
* If you make modifications to this software that you feel increases
* it usefulness for the rest of the community, please email the
* changes, enhancements, bug fixes as well as any and all ideas to me.
* This software is going to be maintained and enhanced as deemed
* necessary by the community.
*
* Mark Hessling Email: M.Hessling@qut.edu.au
* PO Box 203 Phone: +617 3802 0800
* Bellara http://www.gu.edu.au/gext/the/markh.html
* QLD 4507 **** Maintainer PDCurses & REXX/SQL ****
* Australia ************* Author of THE ************
*/
/*
$Id: execute.c 2.1 1995/06/24 16:29:52 MH Rel MH $
*/
#include <the.h>
#include <proto.h>
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_change_command(CHARTYPE *params,bool selective)
#else
short execute_change_command(params,selective)
CHARTYPE *params;
bool selective;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern CHARTYPE *rec;
extern unsigned short rec_len;
extern VIEW_DETAILS *vd_mark;
extern CHARTYPE last_change_command[MAX_COMMAND_LENGTH];
/*--------------------------- local data ------------------------------*/
LINETYPE num_lines=0L,long_n=0L,long_m=0L;
LINE *curr=NULL;
CHARTYPE *old_str=NULL,*new_str=NULL;
short rc=0,selective_rc=RC_OK;
short direction=DIRECTION_FORWARD;
long number_changes=0L,number_of_changes=0L,number_of_occ=0L;
short start_col=0,real_start=0,real_end=0,loc=0;
LINETYPE true_line=0L,last_true_line=0L,number_lines=0L;
LINETYPE num_actual_lines=0L,abs_num_lines=0L,i=0L;
LINETYPE num_file_lines=0L;
short len_old_str=0,len_new_str=0;
TARGET target;
CHARTYPE message[50];
bool lines_based_on_scope=FALSE;
CHARTYPE *save_params=NULL;
short save_target_type=TARGET_RELATIVE;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_change_command");
#endif
/*---------------------------------------------------------------------*/
/* Save the parameters for later... */
/*---------------------------------------------------------------------*/
if ((save_params = (CHARTYPE *)my_strdup(params)) == NULL)
{
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
/*---------------------------------------------------------------------*/
/* Validate the parameters that have been supplied. Up to 4 parameters */
/* may be supplied. The first is the string to change and its new */
/* value, the second is the target, the third is the number of times */
/* to change the value on one line and lastly is which occurrence to */
/* change first. */
/*---------------------------------------------------------------------*/
initialise_target(&target);
rc = split_change_params(params,&old_str,&new_str,&target,&long_n,&long_m);
if (rc != RC_OK)
{
free_target(&target);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
num_lines = target.num_lines;
true_line = target.true_line;
if (target.rt == NULL)
lines_based_on_scope = TRUE;
else
{
lines_based_on_scope = (target.rt[0].target_type == TARGET_BLOCK_CURRENT) ? FALSE : TRUE;
save_target_type = target.rt[0].target_type;
}
free_target(&target);
/*---------------------------------------------------------------------*/
/* Check for any hex strings in both old_str and new_str. */
/*---------------------------------------------------------------------*/
if (CURRENT_VIEW->hex)
{
if ((len_old_str = convert_hex_strings(old_str)) == (-1))
{
display_error(32,old_str,FALSE);
(*the_free)(save_params);
#ifdef TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
if ((len_new_str = convert_hex_strings(new_str)) == (-1))
{
display_error(32,new_str,FALSE);
(*the_free)(save_params);
#ifdef TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
}
else
{
len_old_str = strlen((DEFCHAR *)old_str);
len_new_str = strlen((DEFCHAR *)new_str);
}
/*---------------------------------------------------------------------*/
/* Save the last change command... */
/*---------------------------------------------------------------------*/
strcpy((DEFCHAR *)last_change_command,(DEFCHAR *)save_params);
(*the_free)(save_params);
/*---------------------------------------------------------------------*/
/* If the number of lines is zero, don't make any changes. Exit with */
/* no rows changed. */
/*---------------------------------------------------------------------*/
if (num_lines == 0L)
{
display_error(36,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_NO_LINES_CHANGED);
}
if (num_lines < 0)
{
direction = DIRECTION_BACKWARD;
abs_num_lines = -num_lines;
}
else
{
direction = DIRECTION_FORWARD;
abs_num_lines = num_lines;
}
if (true_line != CURRENT_VIEW->focus_line)
{
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
/* pre_process_line(CURRENT_VIEW,true_line,(LINE *)NULL);*/
}
number_lines = 0L;
number_changes = 0L;
number_of_changes = 0L;
number_of_occ = 0L;
start_col = 0;
last_true_line = true_line;
curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,true_line,CURRENT_FILE->number_lines);
for (i=0L,num_actual_lines=0L;;i++)
{
if (lines_based_on_scope)
{
if (num_actual_lines == abs_num_lines)
break;
}
else
{
if (abs_num_lines == i)
break;
}
rc = processable_line(CURRENT_VIEW,true_line,curr);
switch(rc)
{
case LINE_SHADOW:
break;
/* case LINE_TOF_EOF: MH12 */
case LINE_TOF:
case LINE_EOF:
num_actual_lines++;
break;
default:
pre_process_line(CURRENT_VIEW,true_line,curr);
loc = 0;
number_of_changes = number_of_occ = 0L;
while(loc != (-1))
{
if (save_target_type == TARGET_BLOCK_CURRENT)
{
real_end = min(rec_len+len_old_str,MARK_VIEW->mark_end_col-1);
real_start = max(start_col,MARK_VIEW->mark_start_col-1);
}
else
{
real_end = min(rec_len+len_old_str,CURRENT_VIEW->zone_end-1);
real_start = max(start_col,CURRENT_VIEW->zone_start-1);
}
if (rec_len < real_start && blank_field(old_str))
{
loc = 0;
rec_len = real_start+1;
}
else
{
loc = memfind(rec+real_start,old_str,(real_end-real_start+1),
len_old_str,
(CURRENT_VIEW->case_change == CASE_IGNORE) ? TRUE : FALSE,
CURRENT_VIEW->arbchar_status,
CURRENT_VIEW->arbchar_single,
CURRENT_VIEW->arbchar_multiple);
}
if (loc != (-1))
{
start_col = loc+real_start;
if (number_of_changes <= long_n-1 && number_of_occ >= long_m-1)
{
/* the following block is done for change or confirm of sch */
if (!selective)
{
memdeln(rec,start_col,rec_len,len_old_str);
rec_len = (LENGTHTYPE)max((LINETYPE)start_col,(LINETYPE)rec_len - (LINETYPE)len_old_str);
meminsmem(rec,new_str,len_new_str,start_col,max_line_length,rec_len);
rec_len += len_new_str;
if (rec_len > max_line_length)
{
rec_len = max_line_length;
loc = (-1);
}
start_col += len_new_str;
number_changes++;
number_of_changes++;
}
else
{
/* selective */
selective_rc = selective_change(old_str,len_old_str,new_str,len_new_str,
true_line,last_true_line,start_col);
last_true_line = true_line;
switch(selective_rc)
{
case QUITOK:
case RC_OK:
start_col += len_new_str;
number_changes++;
number_of_changes++;
if (rec_len > max_line_length)
{
rec_len = max_line_length;
loc = (-1);
}
break;
case SKIP:
start_col += len_old_str;
break;
case QUIT:
break;
}
if (selective_rc == QUIT || selective_rc == QUITOK)
break;
}
number_of_occ++;
}
else
{
start_col += len_old_str;
number_of_occ++;
}
if (number_of_changes > long_n-1)
/* || number_of_occ > long_n-1)*/
loc = (-1);
}
} /* end while */
if (number_of_changes != 0L) /* changes made */
{
post_process_line(CURRENT_VIEW,true_line,curr,FALSE);
number_lines++;
}
num_actual_lines++;
break;
}
if (selective_rc == QUIT || selective_rc == QUITOK)
break;
start_col = 0;
if (direction == DIRECTION_FORWARD)
curr = curr->next;
else
curr = curr->prev;
true_line += (LINETYPE)(direction);
num_file_lines += (LINETYPE)(direction);
if (curr == NULL)
break;
}
/*---------------------------------------------------------------------*/
/* If no changes were made, display error message and return. */
/*---------------------------------------------------------------------*/
if (number_changes == 0L)
{
display_error(36,(CHARTYPE *)"",FALSE);
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
#ifdef TRACE
trace_return();
#endif
return(RC_NO_LINES_CHANGED);
}
/*---------------------------------------------------------------------*/
/* Increment the alteration count here, once irrespective of the number*/
/* of lines changed. */
/*---------------------------------------------------------------------*/
increment_alt(CURRENT_FILE);
/*---------------------------------------------------------------------*/
/* If STAY is OFF, change the current and focus lines by the number */
/* of lines calculated from the target. */
/*---------------------------------------------------------------------*/
if (selective)
{
if (!CURRENT_VIEW->stay) /* stay is off */
{
CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line = true_line;
}
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
build_screen(current_screen);
display_screen(current_screen);
}
else
{
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
resolve_current_and_focus_lines(CURRENT_VIEW,last_true_line,num_file_lines,direction,TRUE,FALSE);
}
sprintf((DEFCHAR *)message,"%ld occurrence(s) changed on %ld line(s)",number_changes,number_lines);
display_error(0,message,TRUE);
#ifdef TRACE
trace_return();
#endif
if (CURRENT_TOF || CURRENT_BOF)
return(RC_TOF_EOF_REACHED);
else
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short selective_change(CHARTYPE *old_str,short len_old_str,CHARTYPE *new_str,
short len_new_str,LINETYPE true_line,LINETYPE last_true_line,short start_col)
#else
short selective_change(old_str,len_old_str,new_str,len_new_str,true_line,last_true_line,start_col)
CHARTYPE *old_str;
short len_old_str;
CHARTYPE *new_str;
short len_new_str;
LINETYPE true_line;
LINETYPE last_true_line;
short start_col;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern unsigned short rec_len;
extern CHARTYPE *rec;
/*--------------------------- local data ------------------------------*/
register short i=0;
short y=0,x=0,rc=RC_OK;
int key=0;
bool changed=FALSE;
bool line_displayed=FALSE;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: selective_change");
#endif
getyx(CURRENT_WINDOW_FILEAREA,y,x);
/* move cursor to old string a la cmatch */
/* display message */
/* accept key - C next, - N change, - Q to quit */
CURRENT_VIEW->focus_line = true_line;
/*---------------------------------------------------------------------*/
/* Check if the true_line is in the currently displayed window. */
/* If not, then change the current_line to the true_line. */
/*---------------------------------------------------------------------*/
line_displayed = FALSE;
for (i=0;i<CURRENT_SCREEN.rows[WINDOW_FILEAREA];i++)
{
if (CURRENT_SCREEN.sl[i].line_number == true_line
&& CURRENT_SCREEN.sl[i].line_type == LINE_LINE)
{
line_displayed = TRUE;
y = i;
break;
}
}
if (!line_displayed)
{
CURRENT_VIEW->current_line = CURRENT_VIEW->focus_line;
y = CURRENT_VIEW->current_row;
}
if (start_col >= CURRENT_VIEW->verify_col-1
&& start_col <= (CURRENT_SCREEN.cols[WINDOW_FILEAREA]+(CURRENT_VIEW->verify_col-1))-1)
x = start_col-(CURRENT_VIEW->verify_col-1);
else
{
x = CURRENT_SCREEN.cols[WINDOW_FILEAREA] / 2;
CURRENT_VIEW->verify_col = max(1,start_col-(short)x);
x = (start_col-(CURRENT_VIEW->verify_col-1));
}
key = 0;
changed = FALSE;
while(key == 0)
{
build_screen(current_screen);
display_screen(current_screen);
if (changed)
display_prompt((CHARTYPE *)"Press 'N' for next,'C' to undo 'Q' to quit");
else
display_prompt((CHARTYPE *)"Press 'N' for next,'C' to change 'Q' to quit");
wmove(CURRENT_WINDOW_FILEAREA,y,x);
wrefresh(CURRENT_WINDOW_FILEAREA);
key = my_getch(stdscr);
clear_msgline();
switch(key)
{
case 'N':
case 'n':
if (changed)
rc = RC_OK;
else
rc = SKIP;
break;
case 'C':
case 'c':
if (changed)
{
memdeln(rec,start_col,rec_len,len_new_str);
rec_len -= len_new_str;
meminsmem(rec,old_str,len_old_str,start_col,max_line_length,rec_len);
rec_len += len_old_str;
}
else
{
memdeln(rec,start_col,rec_len,len_old_str);
rec_len -= len_old_str;
meminsmem(rec,new_str,len_new_str,start_col,max_line_length,rec_len);
rec_len += len_new_str;
}
changed = (changed) ? FALSE : TRUE;
key = 0;
break;
case 'Q':
case 'q':
if (changed)
rc = QUITOK;
else
rc = QUIT;
break;
default:
key = 0;
break;
}
}
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short insert_new_line(CHARTYPE *line,unsigned short len,LINETYPE num_lines,
LINETYPE true_line,bool start_left_col,bool make_current,
bool inc_alt,CHARTYPE select,bool move_cursor)
#else
short insert_new_line(line,len,num_lines,true_line,start_left_col,make_current,inc_alt,select,move_cursor)
CHARTYPE *line;
unsigned short len;
LINETYPE num_lines;
LINETYPE true_line;
bool start_left_col;
bool make_current;
bool inc_alt;
CHARTYPE select;
bool move_cursor;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern short compatible_feel;
/*--------------------------- local data ------------------------------*/
register short i=0;
LINE *curr=NULL,*save_curr=NULL;
unsigned short x=0,y=0;
short new_col=0;
bool on_bottom_of_file=FALSE,on_bottom_of_screen=FALSE;
short number_focus_rows=0;
bool leave_cursor=FALSE;
LINETYPE new_focus_line=0L,new_current_line=0L;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: insert_new_line");
#endif
if (!CURRENT_VIEW->scope_all)
true_line = find_last_not_in_scope(CURRENT_VIEW,NULL,true_line,DIRECTION_FORWARD);
/*---------------------------------------------------------------------*/
/* If we are on the 'Bottom of File' line reduce the true_line by 1 */
/* so that the new line is added before the bottom line. */
/*---------------------------------------------------------------------*/
if (true_line == CURRENT_FILE->number_lines+1L)
true_line--;
/*---------------------------------------------------------------------*/
/* Find the current LINE pointer for the true_line. */
/* This is the line after which the line(s) are to be added. */
/*---------------------------------------------------------------------*/
curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,true_line,CURRENT_FILE->number_lines);
/*---------------------------------------------------------------------*/
/* Insert into the linked list the number of lines specified. All lines*/
/* will contain a blank line and a length of zero. */
/*---------------------------------------------------------------------*/
save_curr = curr;
for (i=0;i<num_lines;i++)
{
if ((curr = add_line(CURRENT_FILE->first_line,curr,line,len,select,TRUE)) == NULL)
{
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
}
/*---------------------------------------------------------------------*/
/* Fix the positioning of the marked block (if there is one and it is */
/* in the current view) and any pending prefix commands. */
/*---------------------------------------------------------------------*/
adjust_marked_lines(TRUE,true_line,num_lines);
adjust_pending_prefix(CURRENT_VIEW,TRUE,true_line,num_lines);
/*---------------------------------------------------------------------*/
/* Increment the number of lines counter for the current file and the */
/* number of alterations, only if requested to do so. */
/*---------------------------------------------------------------------*/
if (inc_alt)
increment_alt(CURRENT_FILE);
CURRENT_FILE->number_lines += num_lines;
/*---------------------------------------------------------------------*/
/* Sort out focus and current line. */
/*---------------------------------------------------------------------*/
if (move_cursor)
{
switch(CURRENT_VIEW->current_window)
{
case WINDOW_COMMAND:
CURRENT_VIEW->focus_line = true_line + 1L;
if (make_current)
CURRENT_VIEW->current_line = true_line + 1L;
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
break;
case WINDOW_FILEAREA:
case WINDOW_PREFIX:
build_screen(current_screen);
getyx(CURRENT_WINDOW,y,x);
calculate_scroll_values(&number_focus_rows,&new_focus_line,
&new_current_line,
&on_bottom_of_screen,&on_bottom_of_file,
&leave_cursor,DIRECTION_FORWARD);
new_col = x;
if (CURRENT_VIEW->current_window == WINDOW_FILEAREA)
{
if (!start_left_col)
{
if (CURRENT_VIEW->newline_aligned)
{
new_col = memne(save_curr->line,' ',save_curr->length);
if (new_col == (-1))
new_col = 0;
/*---------------------------------------------------------------------*/
/* Special case when right margin is > than screen width... */
/*---------------------------------------------------------------------*/
if (CURRENT_VIEW->verify_start != CURRENT_VIEW->verify_col)
{
/*---------------------------------------------------------------------*/
/* If the new column position will be on the same page... */
/*---------------------------------------------------------------------*/
if (CURRENT_VIEW->verify_col < new_col
&& CURRENT_VIEW->verify_col + CURRENT_SCREEN.screen_cols > new_col)
new_col = (new_col - CURRENT_VIEW->verify_col) + 1;
else
{
x = CURRENT_SCREEN.cols[WINDOW_FILEAREA] / 2;
CURRENT_VIEW->verify_col = max(1,new_col - (short)x + 2);
new_col = (CURRENT_VIEW->verify_col == 1) ? new_col : x - 1;
}
}
}
else
{
new_col = 0;
CURRENT_VIEW->verify_col = 1;
}
}
}
/*---------------------------------------------------------------------*/
/* Move the cursor to where it should be and display the page. */
/*---------------------------------------------------------------------*/
if (on_bottom_of_screen)
{
CURRENT_VIEW->current_line = new_current_line;
CURRENT_VIEW->focus_line = new_focus_line;
wmove(CURRENT_WINDOW,y-((leave_cursor) ? 0 : 1),new_col);
}
else
{
/*---------------------------------------------------------------------*/
/* We are in the middle of the window, so just move the cursor down */
/* 1 line. */
/*---------------------------------------------------------------------*/
wmove(CURRENT_WINDOW,y+number_focus_rows,new_col);
CURRENT_VIEW->focus_line = new_focus_line;
if (compatible_feel == COMPAT_XEDIT)
CURRENT_VIEW->current_line = new_current_line;
}
break;
}
}
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
build_screen(current_screen);
display_screen(current_screen);
#ifdef TRACE
trace_return();
#endif
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_os_command(CHARTYPE *cmd,bool quiet,bool pause)
#else
short execute_os_command(cmd,quiet,pause)
CHARTYPE *cmd;
bool quiet;
bool pause;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern CHARTYPE *temp_cmd;
extern bool curses_started;
#ifdef XCURSES
extern CHARTYPE xterm_program[MAX_FILE_NAME+1];
#endif
/*--------------------------- local data ------------------------------*/
#if defined(DOS) || defined(OS2) || defined(WIN32)
#define SHELL "COMSPEC"
#else
#define SHELL "SHELL"
#endif
short rc=0;
#ifdef XCURSES
bool save_curses_started=curses_started;
#endif
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_os_command");
#endif
#ifdef MSWIN
quiet = 1;
pause = 0;
#endif
#ifdef XCURSES
curses_started=FALSE;
#endif
if (!quiet && curses_started)
{
attrset(A_NORMAL);
#if 0
touchwin(stdscr);
wmove(stdscr,0,0);
addch(' ');
#else
clear();
#endif
wmove(stdscr,1,0);
wrefresh(stdscr); /* clear screen */
suspend_curses();
}
if (allocate_temp_space(strlen((DEFCHAR *)cmd),TEMP_TEMP_CMD) != RC_OK)
{
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
if (strcmp((DEFCHAR *)cmd,"") == 0)
#ifdef XCURSES
{
strcpy((DEFCHAR *)temp_cmd,(DEFCHAR *)xterm_program);
strcat((DEFCHAR *)temp_cmd," &");
}
#else
strcpy((DEFCHAR *)temp_cmd,getenv(SHELL));
#endif
else
strcpy((DEFCHAR *)temp_cmd,(DEFCHAR *)cmd);
#ifdef UNIX
if (strcmp((DEFCHAR *)temp_cmd,"") == 0) /* no SHELL env variable set */
{
printf("No SHELL environment variable set - using /bin/sh\n");
fflush(stdout);
strcpy((DEFCHAR *)temp_cmd,"/bin/sh");
}
#endif
if (quiet)
{
#ifdef UNIX
strcat((DEFCHAR *)temp_cmd," > /dev/null");
#endif
#if defined(DOS) || defined(OS2) || defined(WIN32)
strcat((DEFCHAR *)temp_cmd," > nul:");
#endif
}
rc = system((DEFCHAR *)temp_cmd);
#ifndef XCURSES
if (pause)
{
printf("\n\n%s",HIT_ANY_KEY);
fflush(stdout);
}
#endif
if (!quiet && curses_started)
{
resume_curses();
if (pause)
(void)my_getch(stdscr);
#if defined(HAVE_BROKEN_SYSVR4_CURSES)
{
short x=0,y=0;
getyx(CURRENT_WINDOW,y,x);
force_curses_background();
wmove(CURRENT_WINDOW,y,x);
refresh();
}
#endif
restore_THE();
}
if (curses_started)
draw_cursor(TRUE);
#ifdef XCURSES
curses_started = save_curses_started;
#endif
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_makecurr(LINETYPE line)
#else
short execute_makecurr(line)
LINETYPE line;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
/*--------------------------- local data ------------------------------*/
unsigned short y=0,x=0;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_makecurr");
#endif
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
CURRENT_VIEW->current_line = line;
if (CURRENT_VIEW->current_window == WINDOW_PREFIX)
getyx(CURRENT_WINDOW,y,x);
else
getyx(CURRENT_WINDOW_FILEAREA,y,x);
build_screen(current_screen);
display_screen(current_screen);
y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,
CURRENT_VIEW->current_row);
if (CURRENT_VIEW->current_window == WINDOW_PREFIX)
wmove(CURRENT_WINDOW,y,x);
else
wmove(CURRENT_WINDOW_FILEAREA,y,x);
#ifdef TRACE
trace_return();
#endif
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_shift_command(short shift_left,short num_cols,LINETYPE true_line,LINETYPE num_lines,bool lines_based_on_scope,short target_type,bool sos)
#else
short execute_shift_command(shift_left,num_cols,true_line,num_lines,lines_based_on_scope,target_type,sos)
short shift_left,num_cols;
LINETYPE true_line,num_lines;
bool lines_based_on_scope;
short target_type;
bool sos;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern VIEW_DETAILS *vd_mark;
extern bool curses_started;
/*-------------------------- external data ----------------------------*/
extern unsigned short trec_len;
extern CHARTYPE *trec;
/*--------------------------- local data ------------------------------*/
unsigned short y=0,x=0;
LINE *curr=NULL;
LINETYPE abs_num_lines=(num_lines < 0L ? -num_lines : num_lines);
LINETYPE num_file_lines=0L,i=0L;
LINETYPE num_actual_lines=0L;
LENGTHTYPE left_col=0;
register short j=0;
short actual_cols=0;
short rc=RC_OK;
short direction=(num_lines < 0L ? DIRECTION_BACKWARD : DIRECTION_FORWARD);
bool adjust_alt=FALSE;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_shift_command");
#endif
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
getyx(CURRENT_WINDOW_FILEAREA,y,x);
else
getyx(CURRENT_WINDOW,y,x);
curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,true_line,CURRENT_FILE->number_lines);
for (i=0L,num_actual_lines=0L;;i++)
{
if (lines_based_on_scope)
{
if (num_actual_lines == abs_num_lines)
break;
}
else
{
if (abs_num_lines == num_file_lines)
break;
}
rc = processable_line(CURRENT_VIEW,true_line+(LINETYPE)(i*direction),curr);
switch(rc)
{
case LINE_SHADOW:
break;
/* case LINE_TOF_EOF: MH12 */
case LINE_TOF:
case LINE_EOF:
num_actual_lines++;
break;
default:
memset(trec,' ',max_line_length);
memcpy(trec,curr->line,curr->length);
trec_len = curr->length;
if (target_type == TARGET_BLOCK_CURRENT)
{
if (MARK_VIEW->mark_type == M_LINE)
left_col = CURRENT_VIEW->zone_start-1;
else
left_col = MARK_VIEW->mark_start_col-1;
}
else
left_col = CURRENT_VIEW->zone_start-1;
if (shift_left)
{
actual_cols = min(num_cols,max(0,trec_len-left_col));
memdeln(trec,left_col,trec_len,actual_cols);
trec_len -= actual_cols;
}
else
{
for (j=0;j<num_cols;j++)
meminschr(trec,' ',left_col,max_line_length,trec_len++);
trec_len = min(trec_len,max_line_length);
actual_cols = num_cols;
}
/*---------------------------------------------------------------------*/
/* Set a flag to cause alteration counts to be incremented. */
/*---------------------------------------------------------------------*/
if (actual_cols != 0)
{
adjust_alt = TRUE;
/*---------------------------------------------------------------------*/
/* Add the old line contents to the line recovery list. */
/*---------------------------------------------------------------------*/
add_to_recovery_list(curr->line,curr->length);
/*---------------------------------------------------------------------*/
/* Realloc the dynamic memory for the line if the line is now longer. */
/*---------------------------------------------------------------------*/
if (trec_len > curr->length)
/* what if realloc fails ?? */
curr->line = (CHARTYPE *)(*the_realloc)((void *)curr->line,(trec_len+1)*sizeof(CHARTYPE));
/*---------------------------------------------------------------------*/
/* Copy the contents of trec into the line. */
/*---------------------------------------------------------------------*/
memcpy(curr->line,trec,trec_len);
curr->length = trec_len;
*(curr->line+trec_len) = '\0';
curr->changed_flag = TRUE;
}
num_actual_lines++;
break;
}
/*---------------------------------------------------------------------*/
/* Proceed to the next record, even if the current record not in scope.*/
/*---------------------------------------------------------------------*/
if (direction == DIRECTION_BACKWARD)
curr = curr->prev;
else
curr = curr->next;
num_file_lines += (LINETYPE)direction;
if (curr == NULL)
break;
}
/*---------------------------------------------------------------------*/
/* Increment the alteration counters once if any line has changed... */
/*---------------------------------------------------------------------*/
if (adjust_alt)
increment_alt(CURRENT_FILE);
/*---------------------------------------------------------------------*/
/* Display the new screen... */
/*---------------------------------------------------------------------*/
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
resolve_current_and_focus_lines(CURRENT_VIEW,true_line,num_file_lines,direction,TRUE,sos);
#if 0
if (!CURRENT_VIEW->stay /* stay is off */
&& num_lines != 0L)
CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line = true_line+num_lines-(LINETYPE)direction;
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
build_screen(current_screen);
display_screen(current_screen);
if (CURRENT_VIEW->current_window != WINDOW_COMMAND
&& curses_started)
{
getyx(CURRENT_WINDOW,y,x);
y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,
CURRENT_VIEW->current_row);
wmove(CURRENT_WINDOW,y,x);
}
#endif
#ifdef TRACE
trace_return();
#endif
if (CURRENT_TOF || CURRENT_BOF)
return(RC_TOF_EOF_REACHED);
else
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
static bool change_case(CHARTYPE *str,short start,short end,CHARTYPE which_case)
#else
static bool change_case(str,start,end,which_case)
CHARTYPE *str;
short start,end;
CHARTYPE which_case;
#endif
/*---------------------------------------------------------------------*/
/* Returns TRUE if a lines was changed, FALSE otherwise. */
/* This function MUST proceed execute_change_case(). */
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
/*--------------------------- local data ------------------------------*/
register short i=0;
bool altered=FALSE;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: change_case");
#endif
for (i=start;i<end+1;i++)
{
switch(which_case)
{
case CASE_UPPER:
if (islower(*(str+i)))
{
*(str+i) = toupper(*(str+i));
altered = TRUE;
}
break;
case CASE_LOWER:
if (isupper(*(str+i)))
{
*(str+i) = tolower(*(str+i));
altered = TRUE;
}
break;
}
}
#ifdef TRACE
trace_return();
#endif
return(altered);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_change_case(CHARTYPE *params,CHARTYPE which_case)
#else
short execute_change_case(params,which_case)
CHARTYPE *params;
CHARTYPE which_case;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern bool curses_started;
extern VIEW_DETAILS *vd_mark;
/*--------------------------- local data ------------------------------*/
LINETYPE num_lines=0L,true_line=0L,num_actual_lines=0L,i=0L,num_file_lines=0L;
unsigned short x=0,y=0;
short direction=0;
LINE *curr=NULL;
LENGTHTYPE start_col=0,end_col=0;
short rc=RC_OK;
TARGET target;
short target_type=TARGET_NORMAL|TARGET_BLOCK_CURRENT|TARGET_ALL;
bool lines_based_on_scope=TRUE;
bool adjust_alt=FALSE;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_change_case");
#endif
/*---------------------------------------------------------------------*/
/* Validate the parameters that have been supplied. */
/* Valid values are: a target or "block". */
/* If no parameter is supplied, 1 is assumed. */
/*---------------------------------------------------------------------*/
if (strcmp("",(DEFCHAR *)params) == 0)
params = (CHARTYPE *)"1";
initialise_target(&target);
if ((rc = validate_target(params,&target,target_type,get_true_line(TRUE),TRUE,TRUE)) != RC_OK)
{
free_target(&target);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
/*---------------------------------------------------------------------*/
/* Determine in which direction we are working. */
/*---------------------------------------------------------------------*/
if (target.num_lines < 0L)
{
direction = DIRECTION_BACKWARD;
num_lines = target.num_lines * (-1L);
}
else
{
direction = DIRECTION_FORWARD;
num_lines = target.num_lines;
}
true_line = target.true_line;
/*---------------------------------------------------------------------*/
/* If the target is BLOCK set the left and right margins to be the */
/* margins of the BOX BLOCK, otherwise use ZONE settings. */
/*---------------------------------------------------------------------*/
start_col = CURRENT_VIEW->zone_start-1;
end_col = CURRENT_VIEW->zone_end-1;
if (target.rt[0].target_type == TARGET_BLOCK_CURRENT)
{
num_lines = MARK_VIEW->mark_end_line-MARK_VIEW->mark_start_line+1L;
true_line = MARK_VIEW->mark_start_line;
direction = DIRECTION_FORWARD;
lines_based_on_scope = FALSE;
if (MARK_VIEW->mark_type != M_LINE)
{
start_col = MARK_VIEW->mark_start_col-1;
end_col = MARK_VIEW->mark_end_col-1;
}
}
/*---------------------------------------------------------------------*/
/* Find the current LINE pointer for the true_line. */
/* This is the first line to change. */
/*---------------------------------------------------------------------*/
curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,true_line,CURRENT_FILE->number_lines);
/*---------------------------------------------------------------------*/
/* Change the case for the target lines and columns... */
/*---------------------------------------------------------------------*/
for (i=0L,num_actual_lines=0L;;i++)
{
if (lines_based_on_scope)
{
if (num_actual_lines == num_lines)
break;
}
else
{
if (num_lines == i)
break;
}
rc = processable_line(CURRENT_VIEW,true_line+(LINETYPE)(i*direction),curr);
switch(rc)
{
case LINE_SHADOW:
break;
/* case LINE_TOF_EOF: MH12 */
case LINE_TOF:
case LINE_EOF:
num_actual_lines++;
break;
default:
add_to_recovery_list(curr->line,curr->length);
if (change_case(curr->line,start_col,min(curr->length-1,end_col),which_case))
{
adjust_alt = TRUE;
curr->changed_flag = TRUE;
}
num_actual_lines++;
break;
}
/*---------------------------------------------------------------------*/
/* Proceed to the next record, even if the current record not in scope.*/
/*---------------------------------------------------------------------*/
if (direction == DIRECTION_FORWARD)
curr = curr->next;
else
curr = curr->prev;
num_file_lines += (LINETYPE)direction;
if (curr == NULL)
break;
}
/*---------------------------------------------------------------------*/
/* Increment the alteration counts if any lines changed... */
/*---------------------------------------------------------------------*/
if (adjust_alt)
increment_alt(CURRENT_FILE);
/*---------------------------------------------------------------------*/
/* Display the new screen... */
/*---------------------------------------------------------------------*/
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
resolve_current_and_focus_lines(CURRENT_VIEW,true_line,num_file_lines,direction,TRUE,FALSE);
#ifdef TRACE
trace_return();
#endif
if (CURRENT_TOF || CURRENT_BOF)
return(RC_TOF_EOF_REACHED);
else
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short rearrange_line_blocks(CHARTYPE command,CHARTYPE source,
LINETYPE start_line,LINETYPE end_line,LINETYPE dest_line,
short num_occ,VIEW_DETAILS *src_view,VIEW_DETAILS *dst_view,
bool lines_based_on_scope,LINETYPE *lines_affected)
#else
short rearrange_line_blocks(command,source,start_line,end_line,dest_line,num_occ,
src_view,dst_view,lines_based_on_scope,lines_affected)
CHARTYPE command,source;
LINETYPE start_line,end_line,dest_line;
short num_occ;
VIEW_DETAILS *src_view,*dst_view;
bool lines_based_on_scope;
LINETYPE *lines_affected;
#endif
/***********************************************************************/
/* Parameters: */
/* command: the command being executed; COPY,DELETE,DUPLICATE,MOVE */
/* source: where the command is executed; COMMAND, PREFIX, BLOCK */
/* start_line: the first line (or only line) number to be acted on */
/* end_line: the last line number to be acted on */
/* dest_line: the destination line for copy,move and duplicate. For */
/* delete this is not applicable. */
/* num_occ: the number of times to execute the command; only for DUP*/
/* lines_affected: number of "real" lines affected by copy operation */
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern bool curses_started;
extern VIEW_DETAILS *vd_mark;
extern CHARTYPE display_screens;
/*--------------------------- local data ------------------------------*/
register short j=0,k=0;
short rc=RC_OK;
static unsigned short y=0,x=0;
bool dst_inside_src=FALSE,lines_added=FALSE,reset_block=FALSE;
bool dest_in_block=FALSE;
short direction=0;
LINETYPE num_lines=0L,off=0L,adjust_line=dest_line,num_actual_lines=0L;
LINETYPE i=0L,num_pseudo_lines=0L;
LINE *curr_src=NULL,*curr_dst=NULL;
LINE *save_curr_src=NULL,*save_curr_dst=NULL;
FILE_DETAILS *src_file=NULL,*dst_file=NULL;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: rearrange_line_blocks");
#endif
src_file = src_view->file_for_view;
dst_file = dst_view->file_for_view;
if (source == SOURCE_BLOCK)
reset_block = FALSE;
else
reset_block = TRUE;
/*---------------------------------------------------------------------*/
/* This block of commands is for copying lines... */
/*---------------------------------------------------------------------*/
switch(command)
{
case COMMAND_COPY:
case COMMAND_OVERLAY_COPY:
case COMMAND_MOVE_COPY_SAME:
case COMMAND_MOVE_COPY_DIFF:
case COMMAND_DUPLICATE:
lines_added = TRUE;
switch(source)
{
case SOURCE_BLOCK:
case SOURCE_BLOCK_RESET:
if (src_view == dst_view
&& dest_line >= start_line
&& dest_line < end_line)
dest_in_block = TRUE;
break;
case SOURCE_PREFIX:
if (dest_line >= start_line
&& dest_line < end_line)
dest_in_block = TRUE;
break;
default:
break;
}
/*---------------------------------------------------------------------*/
/* If the destination line is within the marked block then we have to */
/* handle the processing of the src_curr pointer differently. */
/*---------------------------------------------------------------------*/
if (dest_in_block)
{
dst_inside_src = TRUE;
off = dest_line - start_line;
}
else
dst_inside_src = FALSE;
num_lines = end_line - start_line + 1L;
save_curr_src = lll_find(src_file->first_line,src_file->last_line,start_line,src_file->number_lines);
save_curr_dst = lll_find(dst_file->first_line,dst_file->last_line,dest_line,dst_file->number_lines);
for (k=0;k<num_occ;k++)
{
curr_src = save_curr_src;
curr_dst = save_curr_dst;
for (i=0L,num_actual_lines=0L;;i++)
{
if (lines_based_on_scope)
{
if (num_actual_lines == num_lines)
break;
}
else
{
if (num_lines == i)
break;
}
rc = processable_line(src_view,start_line+i,curr_src);
switch(rc)
{
case LINE_SHADOW:
break;
/* case LINE_TOF_EOF: MH12 */
case LINE_TOF:
case LINE_EOF:
num_actual_lines++;
num_pseudo_lines++;
break;
default:
if ((curr_dst = add_line(dst_file->first_line,curr_dst,
curr_src->line,curr_src->length,
dst_view->display_low,TRUE)) == NULL)
/* curr_src->select)) == NULL)*/
{
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
/*---------------------------------------------------------------------*/
/* If moving lines within the same file, move any line name with the */
/* line also. */
/*---------------------------------------------------------------------*/
if (command == COMMAND_MOVE_COPY_SAME)
{
if (curr_src->name != (CHARTYPE *)NULL)
{
curr_dst->name = curr_src->name;
curr_src->name = (CHARTYPE *)NULL;
}
}
num_actual_lines++;
break;
}
if (dst_inside_src && i == off)
for (j=0;j<off+1;j++)
curr_src = curr_src->next;
curr_src = curr_src->next;
}
}
dst_file->number_lines += (num_actual_lines-num_pseudo_lines)*num_occ;
*lines_affected = (num_actual_lines-num_pseudo_lines)*num_occ;
break;
default:
break;
}
/*---------------------------------------------------------------------*/
/* This block of commands is for deleting lines... */
/*---------------------------------------------------------------------*/
switch(command)
{
case COMMAND_DELETE:
case COMMAND_OVERLAY_DELETE:
case COMMAND_MOVE_DELETE_SAME:
case COMMAND_MOVE_DELETE_DIFF:
lines_added = FALSE;
if (start_line > end_line)
{
direction = DIRECTION_BACKWARD;
num_lines = start_line - end_line + 1L;
}
else
{
direction = DIRECTION_FORWARD;
num_lines = end_line - start_line + 1L;
}
curr_dst = lll_find(dst_file->first_line,dst_file->last_line,start_line,dst_file->number_lines);
for (i=0L,num_actual_lines=0L;;i++)
{
if (lines_based_on_scope)
{
if (num_actual_lines == num_lines)
break;
}
else
{
if (num_lines == i)
break;
}
rc = processable_line(dst_view,start_line+i,curr_dst);
switch(rc)
{
/* case LINE_TOF_EOF: MH12 */
case LINE_TOF:
case LINE_EOF:
num_actual_lines++; /* this is meant to fall through */
num_pseudo_lines++;
case LINE_SHADOW:
if (direction == DIRECTION_FORWARD)
curr_dst = curr_dst->next;
else
curr_dst = curr_dst->prev;
break;
default:
if (command != COMMAND_MOVE_DELETE_SAME)
add_to_recovery_list(curr_dst->line,curr_dst->length);
curr_dst = delete_line(dst_file->first_line,curr_dst,direction);
num_actual_lines++;
}
if (curr_dst == NULL)
break;
}
dst_file->number_lines -= (num_actual_lines-num_pseudo_lines)*num_occ;
break;
default:
break;
}
/*---------------------------------------------------------------------*/
/* Increment alteration count for all but COMMAND_MOVE_COPY_SAME... */
/*---------------------------------------------------------------------*/
if (command != COMMAND_MOVE_COPY_SAME
&& command != COMMAND_OVERLAY_COPY
&& (num_actual_lines-num_pseudo_lines) != 0)
increment_alt(dst_file);
/*---------------------------------------------------------------------*/
/* This block of commands is for sorting out cursor position... */
/*---------------------------------------------------------------------*/
if (curses_started)
getyx(CURRENT_WINDOW,y,x);
switch(command)
{
case COMMAND_COPY:
case COMMAND_OVERLAY_COPY:
case COMMAND_MOVE_COPY_SAME:
case COMMAND_MOVE_COPY_DIFF:
case COMMAND_DUPLICATE:
if (source == SOURCE_COMMAND
&& CURRENT_VIEW->current_window == WINDOW_COMMAND
&& CURRENT_VIEW->stay)
break;
#if PRE_23_BEHAVIOUR
if (IN_VIEW(dst_view,dest_line))
{
dst_view->focus_line = dest_line+1L;
}
if (dst_view->current_window != WINDOW_COMMAND
&& dst_view == CURRENT_SCREEN.screen_view)
{
if (y == CURRENT_SCREEN.rows[WINDOW_FILEAREA]-1)/* on bottom line of window */
{
dst_view->current_line = dst_view->focus_line;
y = dst_view->current_row;
}
else
y = get_row_for_focus_line(current_screen,dst_view->focus_line,
dst_view->current_row);
}
#else
if (command == COMMAND_DUPLICATE)
{
dst_view->focus_line = dest_line+1L;
if (dst_view == CURRENT_SCREEN.screen_view)
{
unsigned short last_focus_row=0;
find_last_focus_line(&last_focus_row);
if (dest_line >= CURRENT_SCREEN.sl[last_focus_row].line_number)
{
dst_view->current_line = dst_view->focus_line;
y = dst_view->current_row;
}
else
{
y = get_row_for_focus_line(current_screen,dst_view->focus_line,
dst_view->current_row);
}
}
}
else
{
if (IN_VIEW(dst_view,dest_line))
{
dst_view->focus_line = dest_line+1L;
}
if (dst_view->current_window != WINDOW_COMMAND
&& dst_view == CURRENT_SCREEN.screen_view)
{
unsigned short last_focus_row=0;
find_last_focus_line(&last_focus_row);
if (y == last_focus_row)
{
dst_view->current_line = dst_view->focus_line;
y = dst_view->current_row;
}
else
y = get_row_for_focus_line(current_screen,dst_view->focus_line,
dst_view->current_row);
}
}
#endif
break;
case COMMAND_DELETE:
case COMMAND_OVERLAY_DELETE:
case COMMAND_MOVE_DELETE_SAME:
case COMMAND_MOVE_DELETE_DIFF:
if (dst_view->focus_line >= start_line
&& dst_view->focus_line <= end_line)
{
if (IN_VIEW(dst_view,dest_line))
{
if (dst_view->current_line > dst_file->number_lines+1L)
{
#if 0
dst_view->current_line -= (num_actual_lines-num_pseudo_lines);
#else
/*
* This is better than before, but the cursor still ends up NOT on the
* focus line ?????
*/
dst_view->current_line = dst_file->number_lines+1L;
dst_view->focus_line = dst_view->current_line;
#endif
}
else
dst_view->focus_line = dest_line;
}
else
{
if (dest_line > dst_file->number_lines)
dst_view->focus_line = dst_view->current_line = dst_file->number_lines;
else
dst_view->focus_line = dst_view->current_line = dest_line;
}
}
else
{
dest_line = (dst_view->focus_line < start_line ? dst_view->focus_line : dst_view->focus_line - num_lines);
if (IN_VIEW(dst_view,dest_line))
{
if (dst_view->current_line > dst_file->number_lines+1L)
dst_view->current_line -= (num_actual_lines-num_pseudo_lines);
dst_view->focus_line = dest_line;
}
else
{
if (dest_line > dst_file->number_lines)
dst_view->focus_line = dst_view->current_line = dst_file->number_lines;
else
dst_view->focus_line = dst_view->current_line = dest_line;
}
}
if (dst_file->number_lines == 0L)
dst_view->focus_line = dst_view->current_line = 0L;
if (dst_view->current_window != WINDOW_COMMAND
&& dst_view == CURRENT_SCREEN.screen_view)
{
y = get_row_for_focus_line(current_screen,dst_view->focus_line,
dst_view->current_row);
}
/*---------------------------------------------------------------------*/
/* This is set here so that the adjust_pending_prefix command will work*/
/*---------------------------------------------------------------------*/
if (direction == DIRECTION_BACKWARD)
adjust_line = end_line;
else
adjust_line = start_line;
dst_view->current_line = find_next_in_scope(dst_view,NULL,dst_view->current_line,DIRECTION_FORWARD);
break;
default:
break;
}
/*---------------------------------------------------------------------*/
/* This block of commands is for adjusting prefix and block lines... */
/*---------------------------------------------------------------------*/
switch(source)
{
case SOURCE_BLOCK:
case SOURCE_BLOCK_RESET:
adjust_pending_prefix(dst_view,lines_added,adjust_line,(num_actual_lines-num_pseudo_lines)*num_occ);
if (command == COMMAND_MOVE_DELETE_SAME)
adjust_marked_lines(lines_added,adjust_line,(num_actual_lines-num_pseudo_lines)*num_occ);
else
switch(command)
{
case COMMAND_MOVE_DELETE_DIFF:
src_view->marked_line = src_view->marked_col = FALSE;
break;
case COMMAND_OVERLAY_DELETE:
break;
default:
if (command == COMMAND_COPY
&& src_view != dst_view)
src_view->marked_line = src_view->marked_col = FALSE;
/*---------------------------------------------------------------------*/
/* The following does a 'reset block' in the current view. */
/*---------------------------------------------------------------------*/
if (reset_block)
{
dst_view->marked_line = dst_view->marked_col = FALSE;
MARK_VIEW = (VIEW_DETAILS *)NULL;
}
else
{
if (command == COMMAND_OVERLAY_DELETE)
dst_view->mark_start_line = dest_line;
else
dst_view->mark_start_line = dest_line + 1L;
dst_view->mark_end_line = dest_line + (num_actual_lines-num_pseudo_lines);
dst_view->marked_col = FALSE;
dst_view->mark_type = M_LINE;
dst_view->focus_line = dst_view->mark_start_line;
MARK_VIEW = dst_view;
}
break;
}
break;
case SOURCE_PREFIX:
case SOURCE_COMMAND:
adjust_marked_lines(lines_added,adjust_line,(num_actual_lines-num_pseudo_lines)*num_occ);
adjust_pending_prefix(dst_view,lines_added,adjust_line,(num_actual_lines-num_pseudo_lines)*num_occ);
break;
}
if (command != COMMAND_MOVE_DELETE_DIFF)
pre_process_line(CURRENT_VIEW,dst_view->focus_line,(LINE *)NULL);
if ((source == SOURCE_BLOCK
|| source == SOURCE_BLOCK_RESET)
&& display_screens > 1)
{
build_screen(other_screen);
display_screen(other_screen);
}
if (command != COMMAND_MOVE_DELETE_DIFF
&& command != COMMAND_MOVE_COPY_SAME
&& command != COMMAND_OVERLAY_COPY
&& command != COMMAND_OVERLAY_DELETE)
{
build_screen(current_screen);
display_screen(current_screen);
}
if (dst_view->current_window != WINDOW_COMMAND
&& dst_view == CURRENT_SCREEN.screen_view)
{
if (curses_started)
wmove(CURRENT_WINDOW,y,x);
}
#ifdef TRACE
trace_return();
#endif
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_set_point(CHARTYPE *name,LINETYPE true_line,bool point_on)
#else
short execute_set_point(name,true_line,point_on)
CHARTYPE *name;
LINETYPE true_line;
bool point_on;
#endif
/***********************************************************************/
/* Parameters: */
/* name: the name of the line to be processed */
/* true_line: the line number of the line */
/* point_on: indicates if the line name is to be turned on or off */
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
/*--------------------------- local data ------------------------------*/
LINE *curr=NULL;
LINETYPE dummy=0L;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_set_point");
#endif
if (point_on)
{
/*---------------------------------------------------------------------*/
/* Find a line that already has the same name. If one exists, remove */
/* the name. */
/*---------------------------------------------------------------------*/
if ((curr = find_named_line(name,&dummy,FALSE)) != (LINE *)NULL)
{
(*the_free)(curr->name);
curr->name = (CHARTYPE *)NULL;
}
/*---------------------------------------------------------------------*/
/* Allocate space for the name and attach it to the true_line. */
/*---------------------------------------------------------------------*/
curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,true_line,CURRENT_FILE->number_lines);
if ((curr->name=(CHARTYPE *)(*the_malloc)(strlen((DEFCHAR *)name)+1)) == NULL)
{
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
strcpy((DEFCHAR *)curr->name,(DEFCHAR *)name);
}
else
{
/*---------------------------------------------------------------------*/
/* Find a line that already has the same name. If one exists, remove */
/* the name otherwise display an error. */
/*---------------------------------------------------------------------*/
if ((curr = find_named_line(name,&dummy,FALSE)) != (LINE *)NULL)
{
(*the_free)(curr->name);
curr->name = (CHARTYPE *)NULL;
}
else
{
display_error(60,name,FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
}
#ifdef TRACE
trace_return();
#endif
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_wrap_word(unsigned short col)
#else
short execute_wrap_word(col)
unsigned short col;
#endif
/***********************************************************************/
/* Parameters: col - current column position within rec */
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern bool INSERTMODEx;
extern unsigned short rec_len;
extern CHARTYPE *rec;
/*--------------------------- local data ------------------------------*/
register short i=0;
short col_break=0,cursor_offset=0;
LINE *curr=NULL,*next_line=NULL;
bool newline=FALSE,cursor_wrap=FALSE;
CHARTYPE *buf=NULL,*word_to_wrap=NULL;
short next_line_start=0,length_word=0,last_col=0;
short rc=RC_OK;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_wrap_word");
#endif
/*---------------------------------------------------------------------*/
/* This function is called when the length of the focus line exceeds */
/* the right margin. If the cursor is positioned in the last word of */
/* the line, the cursor moves with that word to the next line. */
/* If the combined length of the word to be wrapped and a space and the*/
/* line following the focus line exceeds the right margin, a new line */
/* is inserted with the word being wrapped, otherwise the word to be */
/* wrapped is prepended to the following line. */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Find the current LINE pointer for the focus_line. */
/*---------------------------------------------------------------------*/
curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,CURRENT_VIEW->focus_line,CURRENT_FILE->number_lines);
/*---------------------------------------------------------------------*/
/* Determine where to start splitting the line in relation to end of */
/* line... */
/*---------------------------------------------------------------------*/
col_break = memreveq(rec,' ',rec_len);
/*---------------------------------------------------------------------*/
/* If there is no word break, don't attempt any wrap. */
/*---------------------------------------------------------------------*/
if (col_break == (-1))
{
#ifdef TRACE
trace_return();
#endif
return(RC_OK);
}
/*---------------------------------------------------------------------*/
/* Actual column to break on is 1 character to right of last space. */
/*---------------------------------------------------------------------*/
col_break++;
/*---------------------------------------------------------------------*/
/* Make a null terminated string out of current line so we can grab the*/
/* word to be wrapped. */
/*---------------------------------------------------------------------*/
rec[rec_len] = '\0';
/*---------------------------------------------------------------------*/
/* Point to word to wrap and determine its length. */
/*---------------------------------------------------------------------*/
length_word = rec_len - col_break;
word_to_wrap = (CHARTYPE *)rec+col_break;
/*---------------------------------------------------------------------*/
/* If the position of the cursor is before the word to wrap leave the */
/* cursor where it is. */
/*---------------------------------------------------------------------*/
if (col >= col_break)
{
cursor_wrap = TRUE;
cursor_offset = col - col_break - 1;
}
else
cursor_wrap = FALSE;
/*---------------------------------------------------------------------*/
/* Now we have to work out if a new line is to added or we prepend to */
/* the following line... */
/*---------------------------------------------------------------------*/
if (curr->next->next == NULL) /* next line bottom of file */
newline = TRUE;
else
{
next_line = curr->next;
if (!in_scope(CURRENT_VIEW,next_line))
newline = TRUE;
else
{
next_line_start = memne(next_line->line,' ',next_line->length);
if (next_line_start != CURRENT_VIEW->margin_left-1) /* next line doesn't start in left margin */
newline = TRUE;
else
{
if (next_line->length + length_word + 1 > CURRENT_VIEW->margin_right)
newline = TRUE;
}
}
}
/*---------------------------------------------------------------------*/
/* Save the word to be wrapped... */
/*---------------------------------------------------------------------*/
buf = (CHARTYPE *)(*the_malloc)(length_word+CURRENT_VIEW->margin_left);
if (buf == NULL)
{
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
memcpy(buf,word_to_wrap,length_word);
/*---------------------------------------------------------------------*/
/* Remove the word to be wrapped from the focus line buffer; rec... */
/*---------------------------------------------------------------------*/
for (i=col_break;i<rec_len+1;i++)
rec[i] = ' ';
last_col = memrevne(rec,' ',max_line_length);
rec_len = (last_col == (-1)) ? 0 : last_col + 1;
/*---------------------------------------------------------------------*/
/* We now should know if a new line is to added or not. */
/*---------------------------------------------------------------------*/
if (newline)
{
for (i=0;i<CURRENT_VIEW->margin_left-1;i++)
(void)meminschr(buf,' ',0,MAX_LENGTH_OF_LINE,i+length_word);
curr = add_line(CURRENT_FILE->first_line,curr,buf,length_word+CURRENT_VIEW->margin_left-1,curr->select,TRUE);
CURRENT_FILE->number_lines++;
}
else
{
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line+1L,(LINE *)NULL);
(void)meminschr(rec,' ',CURRENT_VIEW->margin_left-1,MAX_LENGTH_OF_LINE,rec_len++);
(void)meminsmem(rec,buf,length_word,CURRENT_VIEW->margin_left-1,
MAX_LENGTH_OF_LINE,rec_len);
rec_len += length_word;
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line+1L,(LINE *)NULL,TRUE);
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
}
(*the_free)(buf);
/*---------------------------------------------------------------------*/
/* We now should know if the cursor is to wrap or stay where it is. */
/*---------------------------------------------------------------------*/
if (cursor_wrap)
{
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
build_screen(current_screen);
cursor_down(TRUE);
rc = Sos_firstchar((CHARTYPE *)"");
for (i=0;i<cursor_offset+1;i++)
rc = cursor_right(TRUE,FALSE);
}
else
{
if (INSERTMODEx)
rc = cursor_right(TRUE,FALSE);
}
build_screen(current_screen);
display_screen(current_screen);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_split_join(short action,bool aligned,bool cursorarg)
#else
short execute_split_join(action,aligned,cursorarg)
short action;
bool aligned;
bool cursorarg;
#endif
/***********************************************************************/
/* Parameters: action - split, join or spltjoin */
/* aligned - whether to align text or not */
/* cursor - whether to split focus line at cursor or */
/* command line at current column */
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern unsigned short rec_len;
extern CHARTYPE *rec;
extern bool curses_started;
extern short compatible_feel;
/*--------------------------- local data ------------------------------*/
register short i=0;
short num_cols=0,num_blanks_focus=0,num_blanks_next=0;
unsigned short x=0,y=0;
LINE *curr=NULL;
LINETYPE true_line=0L;
LENGTHTYPE col=0;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_split_join");
#endif
/*---------------------------------------------------------------------*/
/* Determine line and column to use. */
/*---------------------------------------------------------------------*/
if (CURRENT_VIEW->current_window == WINDOW_COMMAND
|| cursorarg == FALSE)
{
col = CURRENT_VIEW->current_column-1;
true_line = CURRENT_VIEW->current_line;
}
else
{
if (curses_started)
{
getyx(CURRENT_WINDOW_FILEAREA,y,x);
col = (x+CURRENT_VIEW->verify_col-1);
true_line = CURRENT_VIEW->focus_line;
}
else
{
col = 0;
true_line = CURRENT_VIEW->current_line;
}
}
/*---------------------------------------------------------------------*/
/* Reject the command if true_line is top or bottom of file. */
/*---------------------------------------------------------------------*/
if (VIEW_TOF(CURRENT_VIEW,true_line) || VIEW_BOF(CURRENT_VIEW,true_line))
{
display_error(38,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_INVALID_ENVIRON);
}
/*---------------------------------------------------------------------*/
/* If this function called from SPLTJOIN(), then determine if SPLIT */
/* or JOIN is required. */
/*---------------------------------------------------------------------*/
if (action == SPLTJOIN_SPLTJOIN)
action = (col >= rec_len) ? SPLTJOIN_JOIN : SPLTJOIN_SPLIT;
/*---------------------------------------------------------------------*/
/* Copy any changes in the focus line to the linked list. */
/*---------------------------------------------------------------------*/
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
/*---------------------------------------------------------------------*/
/* Find the current LINE pointer for the true line. */
/*---------------------------------------------------------------------*/
curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,true_line,CURRENT_FILE->number_lines);
getyx(CURRENT_WINDOW,y,x);
switch(action)
{
case SPLTJOIN_SPLIT:
memset(rec,' ',max_line_length);
if (col < curr->length)
{
memcpy(rec,curr->line+col,curr->length-col);
rec_len = curr->length-col;
}
else
rec_len = 0;
curr->changed_flag = TRUE;
/*---------------------------------------------------------------------*/
/* Calculate the number of leading blanks on the current line so that */
/* the new line can have this many blanks prepended to align properly. */
/*---------------------------------------------------------------------*/
if (aligned)
{
num_cols = memne(curr->line,' ',curr->length);
if (num_cols == (-1))
num_cols = 0;
for (i=0;i<num_cols;i++)
meminschr(rec,' ',0,max_line_length,rec_len++);
rec_len = min(rec_len,max_line_length);
}
add_line(CURRENT_FILE->first_line,curr,(rec),rec_len,curr->select,TRUE);
CURRENT_FILE->number_lines++;
if (CURRENT_VIEW->current_window == WINDOW_COMMAND
|| cursorarg == FALSE)
{
if (curr->length > col)
{
curr->length = col;
*(curr->line+(col)) = '\0';
increment_alt(CURRENT_FILE);
}
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
}
else
{
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
Sos_delend((CHARTYPE *)"");
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
}
break;
case SPLTJOIN_JOIN:
if (curr->next->next == NULL)
{
/*---------------------------------------------------------------------*/
/* Trying to join with the bottom of file line. */
/*---------------------------------------------------------------------*/
#ifdef TRACE
trace_return();
#endif
return(RC_INVALID_ENVIRON);
}
/*---------------------------------------------------------------------*/
/* Calculate the number of leading blanks for the focus line and also */
/* for the line to be joined. To align the join properly, we have to */
/* remove up the number of leading blanks in the focus line from the */
/* beginning of the line to be joined. */
/*---------------------------------------------------------------------*/
if (aligned)
{
num_blanks_focus = memne(curr->line,' ',curr->length);
if (num_blanks_focus == (-1))
num_blanks_focus = 0;
num_blanks_next = memne(curr->next->line,' ',curr->length);
if (num_blanks_next == (-1))
num_blanks_next = 0;
num_cols = min(num_blanks_focus,num_blanks_next);
}
else
num_cols = 0;
if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->current_line,(LINE *)NULL);
meminsmem(rec,curr->next->line+num_cols,curr->next->length-num_cols,
col,max_line_length,col);
if (col+curr->next->length-num_cols > max_line_length)
{
display_error(0,(CHARTYPE*)"Truncated",FALSE);
}
rec_len = min(max_line_length,col+curr->next->length-num_cols);
post_process_line(CURRENT_VIEW,true_line,(LINE *)NULL,TRUE);
curr = delete_line(CURRENT_FILE->first_line,curr->next,DIRECTION_BACKWARD);
if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
/*---------------------------------------------------------------------*/
/* If on the bottom line, use the previous line. */
/*---------------------------------------------------------------------*/
if (CURRENT_BOF)
{
CURRENT_VIEW->current_line--;
y++;
}
/*---------------------------------------------------------------------*/
/* Decrement the number of lines counter for the current file and move */
/* the cursor to the appropriate line. */
/*---------------------------------------------------------------------*/
CURRENT_FILE->number_lines--;
if (CURRENT_VIEW->current_window == WINDOW_FILEAREA)
wmove(CURRENT_WINDOW,y,x);
break;
}
/*
* Determine new current line if cursorarg == false
*/
if (CURRENT_VIEW->current_window == WINDOW_COMMAND
|| cursorarg == FALSE)
{
CURRENT_VIEW->current_line++;
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
{
build_screen(current_screen);
if (!line_in_view(current_screen,CURRENT_VIEW->focus_line)
&& compatible_feel == COMPAT_XEDIT)
{
cursor_cmdline(1);
}
else
{
y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,
CURRENT_VIEW->current_row);
wmove(CURRENT_WINDOW,y,x);
}
}
}
/*---------------------------------------------------------------------*/
/* Fix the positioning of the marked block (if there is one and it is */
/* in the current view) and any pending prefix commands. */
/*---------------------------------------------------------------------*/
adjust_marked_lines((action==SPLTJOIN_SPLIT)?TRUE:FALSE,true_line,1L);
adjust_pending_prefix(CURRENT_VIEW,(action==SPLTJOIN_SPLIT)?TRUE:FALSE,true_line,1L);
build_screen(current_screen);
display_screen(current_screen);
#ifdef TRACE
trace_return();
#endif
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_put(CHARTYPE *params,bool putdel)
#else
short execute_put(params,putdel)
CHARTYPE *params;
bool putdel;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern CHARTYPE *tempfilename;
extern CHARTYPE sp_path[MAX_FILE_NAME+1] ;
extern CHARTYPE sp_fname[MAX_FILE_NAME+1] ;
extern VIEW_DETAILS *vd_mark;
extern CHARTYPE *temp_cmd;
extern bool curses_started;
/*--------------------------- local data ------------------------------*/
LINETYPE num_lines=0L,true_line=0L,num_file_lines=0L;
bool append=FALSE;
CHARTYPE *filename=NULL;
short rc=RC_OK;
LENGTHTYPE start_col=0,end_col=max_line_length;
bool lines_based_on_scope = TRUE;
TARGET target;
short target_type=TARGET_NORMAL|TARGET_BLOCK_CURRENT|TARGET_ALL|TARGET_SPARE;
short direction=DIRECTION_FORWARD;
int y=0,x=0;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_put");
#endif
/*---------------------------------------------------------------------*/
/* If there are no arguments, default to "1"... */
/*---------------------------------------------------------------------*/
if (strcmp("",(DEFCHAR *)params) == 0)
params = (CHARTYPE *)"1";
/*---------------------------------------------------------------------*/
/* Validate first argument as a target... */
/*---------------------------------------------------------------------*/
initialise_target(&target);
if ((rc = validate_target(params,&target,target_type,get_true_line(TRUE),TRUE,TRUE)) != RC_OK)
{
free_target(&target);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/*---------------------------------------------------------------------*/
/* If there is no second argument, no filename supplied... */
/*---------------------------------------------------------------------*/
if (target.spare == (-1))
{
append = FALSE;
filename = tempfilename;
}
else
{
if ((rc = splitpath(strtrunc(target.rt[target.spare].string))) != RC_OK)
{
display_error(10,strtrunc(target.rt[target.spare].string),FALSE);
free_target(&target);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
strcpy((DEFCHAR *)temp_cmd,(DEFCHAR *)sp_path);
strcat((DEFCHAR *)temp_cmd,(DEFCHAR *)sp_fname);
filename = temp_cmd;
append = TRUE;
}
true_line = target.true_line;
num_lines = target.num_lines;
/*---------------------------------------------------------------------*/
/* Determine in which direction we are working. */
/*---------------------------------------------------------------------*/
direction = (target.num_lines < 0L) ? DIRECTION_BACKWARD : DIRECTION_FORWARD;
/*---------------------------------------------------------------------*/
/* If the marked block is a BOX block, set up the left and right column*/
/* values. */
/*---------------------------------------------------------------------*/
if (target.rt[0].target_type == TARGET_BLOCK_CURRENT)
{
lines_based_on_scope = FALSE;
if (MARK_VIEW->mark_type == M_BOX)
{
start_col = MARK_VIEW->mark_start_col-1;
end_col = MARK_VIEW->mark_end_col-1;
}
}
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
if ((rc = save_file(CURRENT_FILE,
filename,
TRUE,
num_lines,
true_line,
&num_file_lines,
append,
start_col,
end_col,
FALSE,
lines_based_on_scope)) != RC_OK)
{
free_target(&target);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/*---------------------------------------------------------------------*/
/* If we are executing a putd command, delete the target... */
/*---------------------------------------------------------------------*/
if (putdel)
rc = DeleteLine(target.string);
else
{
/*---------------------------------------------------------------------*/
/* If STAY is OFF, change the current and focus lines by the number */
/* of lines calculated from the target. This is only applicable for */
/* PUT and NOT for PUTDEL. */
/*---------------------------------------------------------------------*/
resolve_current_and_focus_lines(CURRENT_VIEW,true_line,num_file_lines,direction,FALSE,FALSE);
}
free_target(&target);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_macro(CHARTYPE *params,bool error_on_not_found,short *macrorc)
#else
short execute_macro(params,error_on_not_found,macrorc)
CHARTYPE *params;
bool error_on_not_found;
short *macrorc;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern bool in_macro;
extern bool rexx_support;
extern CHARTYPE number_of_files;
extern CHARTYPE display_screens;
extern LINETYPE original_screen_line;
extern LINETYPE original_screen_column;
extern LINETYPE original_file_line;
extern LINETYPE original_file_column;
/*--------------------------- local data ------------------------------*/
short rc=RC_OK;
short errnum=0;
FILE *fp=NULL;
#define MAC_PARAMS 2
CHARTYPE *word[MAC_PARAMS+1];
CHARTYPE strip[MAC_PARAMS];
unsigned short num_params=0;
CHARTYPE *macroname=NULL;
bool save_in_macro=in_macro;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_macro");
#endif
/*---------------------------------------------------------------------*/
/* Validate the parameters. At least 1 must be present, the filename. */
/*---------------------------------------------------------------------*/
strip[0]=STRIP_BOTH;
strip[1]=STRIP_NONE;
num_params = param_split(params,word,MAC_PARAMS,WORD_DELIMS,TEMP_PARAM,strip);
if (num_params == 0)
{
display_error(3,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
/*---------------------------------------------------------------------*/
/* Allocate some space for macroname... */
/*---------------------------------------------------------------------*/
if ((macroname = (CHARTYPE *)(*the_malloc)((MAX_FILE_NAME+1)*sizeof(CHARTYPE))) == NULL)
{
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
/*---------------------------------------------------------------------*/
/* Find the fully qualified file name for the supplied macro name. */
/*---------------------------------------------------------------------*/
rc = get_valid_macro_file_name(word[0],macroname,&errnum);
/*---------------------------------------------------------------------*/
/* Validate the return code... */
/*---------------------------------------------------------------------*/
switch(rc)
{
/*---------------------------------------------------------------------*/
/* If RC_OK, continue to process the macro... */
/*---------------------------------------------------------------------*/
case RC_OK:
break;
/*---------------------------------------------------------------------*/
/* If RC_FILE_NOT_FOUND and IMPOS is not on, display an error and exit.*/
/* If IMPOS is on, just return without displaying an error. */
/*---------------------------------------------------------------------*/
case RC_FILE_NOT_FOUND:
if (error_on_not_found)
display_error(errnum,macroname,FALSE);
(*the_free)(macroname);
#ifdef TRACE
trace_return();
#endif
return(rc);
break;
/*---------------------------------------------------------------------*/
/* All other cases, display error and return. */
/*---------------------------------------------------------------------*/
default:
(*the_free)(macroname);
display_error(errnum,macroname,FALSE);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/*---------------------------------------------------------------------*/
/* Set in_macro = TRUE to stop multiple show_page()s being performed. */
/*---------------------------------------------------------------------*/
in_macro = TRUE;
/*---------------------------------------------------------------------*/
/* Save the values of the cursor position... */
/*---------------------------------------------------------------------*/
get_cursor_position(&original_screen_line,&original_screen_column,
&original_file_line,&original_file_column);
/*---------------------------------------------------------------------*/
/* If REXX is supported, process the macro as a REXX macro... */
/*---------------------------------------------------------------------*/
if (rexx_support)
{
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
rc = execute_macro_file(macroname,word[1],macrorc);
if (rc != RC_OK)
{
display_error(54,(CHARTYPE *)"",FALSE);
rc = RC_SYSTEM_ERROR;
}
(*the_free)(macroname);
}
else
{
/*---------------------------------------------------------------------*/
/* ...otherwise, process the file as a non-REXX macro file... */
/*---------------------------------------------------------------------*/
if ((fp = fopen((DEFCHAR *)macroname,"r")) == NULL)
{
rc = RC_ACCESS_DENIED;
display_error(8,macroname,FALSE);
}
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
if (rc == RC_OK)
{
rc = execute_command_file(fp);
fclose(fp);
}
(*the_free)(macroname);
if (rc == RC_SYSTEM_ERROR)
display_error(53,(CHARTYPE *)"",FALSE);
if (rc == RC_NOREXX_ERROR)
display_error(52,(CHARTYPE *)"",FALSE);
}
/*---------------------------------------------------------------------*/
/* Set in_macro = FALSE to indicate we are out of the macro and do a */
/* show_page() now as long as there are still file(s) in the ring. */
/*---------------------------------------------------------------------*/
in_macro = save_in_macro;
if (number_of_files > 0)
{
if (display_screens > 1)
{
build_screen(other_screen);
display_screen(other_screen);
}
build_screen(current_screen);
display_screen(current_screen);
}
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_set_on_off(CHARTYPE *inparams,bool *flag)
#else
short execute_set_on_off(inparams,flag)
CHARTYPE *inparams;
bool *flag;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
/*--------------------------- local data ------------------------------*/
short rc=RC_OK;
CHARTYPE *params=NULL;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_set_on_off");
#endif
/*---------------------------------------------------------------------*/
/* Strip the leading and trailing spaces from parameters... */
/*---------------------------------------------------------------------*/
if ((params = (CHARTYPE *)my_strdup(inparams)) == NULL)
{
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
params = MyStrip(params,STRIP_BOTH,' ');
/*---------------------------------------------------------------------*/
/* Validate the parameter. It must be ON or OFF. */
/*---------------------------------------------------------------------*/
if (equal((CHARTYPE *)"off",params,3))
*flag = FALSE;
else
if (equal((CHARTYPE *)"on",params,2))
*flag = TRUE;
else
{
display_error(1,(CHARTYPE *)inparams,FALSE);
#ifdef TRACE
trace_return();
#endif
rc = RC_INVALID_OPERAND;
}
(*the_free)(params);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_set_row_position(CHARTYPE *inparams,short *base,short *off)
#else
short execute_set_row_position(inparams,base,off)
CHARTYPE *inparams;
short *base,*off;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
/*--------------------------- local data ------------------------------*/
short rc=RC_OK;
CHARTYPE *params=NULL,*save_param_ptr=NULL;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_set_row_position");
#endif
/*---------------------------------------------------------------------*/
/* Strip the leading and trailing spaces from parameters... */
/*---------------------------------------------------------------------*/
if ((params = save_param_ptr = (CHARTYPE *)my_strdup(inparams)) == NULL)
{
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
params = MyStrip(params,STRIP_BOTH,' ');
/*---------------------------------------------------------------------*/
/* Parse the position parameter... */
/*---------------------------------------------------------------------*/
if (*params == 'M'
|| *params == 'm')
{
*base = POSITION_MIDDLE;
params++;
if (blank_field(params))
*off = 0;
else
{
if ((*params != '-'
&& *params != '+')
|| ((*off = atoi((DEFCHAR *)params)) == 0))
{
display_error(1,inparams,FALSE);
(*the_free)(save_param_ptr);
#ifdef TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
}
}
else
{
if ((*off = atoi((DEFCHAR *)params)) == 0)
{
display_error(1,inparams,FALSE);
(*the_free)(save_param_ptr);
#ifdef TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
*base = (*off > 0) ? POSITION_TOP : POSITION_BOTTOM;
}
(*the_free)(save_param_ptr);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short processable_line(VIEW_DETAILS *view,LINETYPE true_line,LINE *curr)
#else
short processable_line(view,true_line,curr)
VIEW_DETAILS *view;
LINETYPE true_line;
LINE *curr;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: processable_line");
#endif
#if 0
/* MH12 */
if (VIEW_TOF(view,true_line)
|| VIEW_BOF(view,true_line))
{
#ifdef TRACE
trace_return();
#endif
return(LINE_TOF_EOF);
}
#endif
if (VIEW_TOF(view,true_line))
{
#ifdef TRACE
trace_return();
#endif
return(LINE_TOF);
}
if (VIEW_BOF(view,true_line))
{
#ifdef TRACE
trace_return();
#endif
return(LINE_EOF);
}
if (in_scope(view,curr)
|| view->scope_all)
{
#ifdef TRACE
trace_return();
#endif
return(LINE_LINE);
}
#ifdef TRACE
trace_return();
#endif
return(LINE_SHADOW);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_expand_compress(CHARTYPE *params,bool expand,bool inc_alt,bool use_tabs,bool add_to_recovery)
#else
short execute_expand_compress(params,expand,inc_alt,use_tabs,add_to_recovery)
CHARTYPE *params;
bool expand,inc_alt,use_tabs,add_to_recovery;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern bool curses_started;
extern VIEW_DETAILS *vd_mark;
/*--------------------------- local data ------------------------------*/
LINETYPE i=0L,num_actual_lines=0L;
LINETYPE num_lines=0L,true_line=0L,num_file_lines=0L;
unsigned short x=0,y=0;
short direction=0,rc=RC_OK;
LINE *curr=NULL;
TARGET target;
short target_type=TARGET_NORMAL|TARGET_BLOCK_CURRENT|TARGET_ALL;
bool lines_based_on_scope=FALSE;
bool adjust_alt=FALSE;
/*--------------------------- processing ------------------------------*/
/*---------------------------------------------------------------------*/
/* Validate the parameters that have been supplied. */
/* If no parameter is supplied, 1 is assumed. */
/*---------------------------------------------------------------------*/
true_line = get_true_line(TRUE);
if (strcmp("",(DEFCHAR *)params) == 0)
params = (CHARTYPE *)"1";
initialise_target(&target);
if ((rc = validate_target(params,&target,target_type,true_line,TRUE,TRUE)) != RC_OK)
{
free_target(&target);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/*---------------------------------------------------------------------*/
/* If a BOX BLOCK target requested, return an error... */
/*---------------------------------------------------------------------*/
if (target.rt[0].target_type == TARGET_BLOCK_CURRENT)
{
switch(MARK_VIEW->mark_type)
{
case M_BOX:
case M_COLUMN:
case M_WORD:
display_error(48,(CHARTYPE *)"",FALSE);
rc = RC_INVALID_OPERAND;
break;
case M_STREAM:
display_error(49,(CHARTYPE *)"",FALSE);
rc = RC_INVALID_OPERAND;
break;
default:
break;
}
if (MARK_VIEW->mark_type != M_LINE)
{
free_target(&target);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
}
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
/*---------------------------------------------------------------------*/
/* Determine in which direction we are working. */
/*---------------------------------------------------------------------*/
if (target.num_lines < 0L)
{
direction = DIRECTION_BACKWARD;
num_lines = -target.num_lines;
}
else
{
direction = DIRECTION_FORWARD;
num_lines = target.num_lines;
}
true_line = target.true_line;
lines_based_on_scope = (target.rt[0].target_type == TARGET_BLOCK_CURRENT) ? FALSE : TRUE;
free_target(&target);
/*---------------------------------------------------------------------*/
/* Find the current LINE pointer for the true_line. */
/* This is the first line to change. */
/*---------------------------------------------------------------------*/
curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,true_line,CURRENT_FILE->number_lines);
/*---------------------------------------------------------------------*/
/* Convert all tabs in the current line to spaces. */
/*---------------------------------------------------------------------*/
for (i=0L,num_actual_lines=0L;;i++)
{
if (lines_based_on_scope)
{
if (num_actual_lines == num_lines)
break;
}
else
{
if (num_lines == i)
break;
}
rc = processable_line(CURRENT_VIEW,true_line+(LINETYPE)(i*direction),curr);
switch(rc)
{
case LINE_SHADOW:
break;
/* case LINE_TOF_EOF: MH12 */
case LINE_TOF:
case LINE_EOF:
num_actual_lines++;
break;
default:
rc = tabs_convert(curr,expand,use_tabs,add_to_recovery);
if (rc == RC_FILE_CHANGED)
adjust_alt = TRUE;
else
if (rc != RC_OK)
{
#ifdef TRACE
trace_return();
#endif
return(rc);
}
num_actual_lines++;
}
if (direction == DIRECTION_FORWARD)
curr = curr->next;
else
curr = curr->prev;
num_file_lines += (LINETYPE)direction;
if (curr == NULL)
break;
}
/*---------------------------------------------------------------------*/
/* Increment the number of alterations count if required... */
/*---------------------------------------------------------------------*/
if (inc_alt
&& adjust_alt)
increment_alt(CURRENT_FILE);
/*---------------------------------------------------------------------*/
/* If STAY is OFF, change the current and focus lines by the number */
/* of lines calculated from the target. */
/*---------------------------------------------------------------------*/
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
resolve_current_and_focus_lines(CURRENT_VIEW,true_line,num_file_lines,direction,TRUE,FALSE);
#ifdef TRACE
trace_return();
#endif
if (CURRENT_TOF || CURRENT_BOF)
return(RC_TOF_EOF_REACHED);
else
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_select(CHARTYPE *params,bool relative,short off)
#else
short execute_select(params,relative,off)
CHARTYPE *params;
bool relative;
short off;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
/*--------------------------- local data ------------------------------*/
LINETYPE i=0L,num_actual_lines=0L;
LINETYPE num_lines=0L,true_line=0L;
short direction=0,rc=RC_OK;
LINE *curr=NULL;
TARGET target;
short target_type=TARGET_NORMAL|TARGET_BLOCK_CURRENT|TARGET_ALL;
bool lines_based_on_scope=FALSE;
/*--------------------------- processing ------------------------------*/
/*---------------------------------------------------------------------*/
/* Validate the parameters that have been supplied. */
/* If no parameter is supplied, 1 is assumed. */
/*---------------------------------------------------------------------*/
true_line = get_true_line(TRUE);
initialise_target(&target);
if ((rc = validate_target(params,&target,target_type,true_line,TRUE,TRUE)) != RC_OK)
{
free_target(&target);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
/*---------------------------------------------------------------------*/
/* Determine in which direction we are working. */
/*---------------------------------------------------------------------*/
if (target.num_lines < 0L)
{
direction = DIRECTION_BACKWARD;
num_lines = -target.num_lines;
}
else
{
direction = DIRECTION_FORWARD;
num_lines = target.num_lines;
}
true_line = target.true_line;
lines_based_on_scope = (target.rt[0].target_type == TARGET_BLOCK_CURRENT) ? FALSE : TRUE;
/*---------------------------------------------------------------------*/
/* Find the current LINE pointer for the true_line. */
/* This is the first line to change. */
/*---------------------------------------------------------------------*/
curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,true_line,CURRENT_FILE->number_lines);
/*---------------------------------------------------------------------*/
/* Convert all tabs in the current line to spaces. */
/*---------------------------------------------------------------------*/
for (i=0L,num_actual_lines=0L;;i++)
{
if (lines_based_on_scope)
{
if (num_actual_lines == num_lines)
break;
}
else
{
if (num_lines == i)
break;
}
rc = processable_line(CURRENT_VIEW,true_line+(LINETYPE)(i*direction),curr);
switch(rc)
{
case LINE_SHADOW:
break;
case LINE_TOF:
case LINE_EOF:
num_actual_lines++;
break;
default:
if (relative)
{
if (((short)curr->select + off) > 255)
curr->select = 255;
else
if (((short)curr->select + off) < 0)
curr->select = 0;
else
curr->select += off;
}
else
curr->select = off;
num_actual_lines++;
}
if (direction == DIRECTION_FORWARD)
curr = curr->next;
else
curr = curr->prev;
if (curr == NULL)
break;
}
free_target(&target);
#ifdef TRACE
trace_return();
#endif
if (CURRENT_TOF || CURRENT_BOF)
return(RC_TOF_EOF_REACHED);
else
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_move_cursor(LENGTHTYPE col)
#else
short execute_move_cursor(col)
LENGTHTYPE col;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
/*--------------------------- local data ------------------------------*/
short y=0,x=0;
COLTYPE new_screen_col=0;
LENGTHTYPE new_verify_col=0;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_move_cursor");
#endif
/*---------------------------------------------------------------------*/
/* Don't do anything for PREFIX window... */
/*---------------------------------------------------------------------*/
if (CURRENT_VIEW->current_window == WINDOW_PREFIX)
{
#ifdef TRACE
trace_return();
#endif
return(RC_OK);
}
getyx(CURRENT_WINDOW,y,x);
calculate_new_column(x,CURRENT_VIEW->verify_col,col,&new_screen_col,&new_verify_col);
if (CURRENT_VIEW->verify_col != new_verify_col
&& CURRENT_VIEW->current_window == WINDOW_FILEAREA)
{
CURRENT_VIEW->verify_col = new_verify_col;
build_screen(current_screen);
display_screen(current_screen);
}
wmove(CURRENT_WINDOW,y,new_screen_col);
#ifdef TRACE
trace_return();
#endif
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_find_command(CHARTYPE *str,short target_type)
#else
short execute_find_command(str,target_type)
CHARTYPE *str;
short target_type;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern short compatible_feel;
/*--------------------------- local data ------------------------------*/
short rc=RC_OK;
LENGTHTYPE save_zone_start=CURRENT_VIEW->zone_start;
LENGTHTYPE save_zone_end=CURRENT_VIEW->zone_end;
bool save_arbchar_status=CURRENT_VIEW->arbchar_status;
bool save_hex=CURRENT_VIEW->hex;
bool negative=FALSE,wrapped=FALSE;
CHARTYPE save_arbchar_single=CURRENT_VIEW->arbchar_single;
TARGET target;
LINETYPE true_line=0L;
LINETYPE save_focus_line=CURRENT_VIEW->focus_line;
LINETYPE save_current_line=CURRENT_VIEW->current_line;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_find_command");
#endif
if (strcmp((DEFCHAR *)str,"") == 0) /* argument supplied */
{
display_error(1,str,FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
initialise_target(&target);
/*---------------------------------------------------------------------*/
/* Force the ZONE settings to start at 1 and end at parameter length. */
/* Ensure ARBCHAR and HEX will be ignored in the search... */
/*---------------------------------------------------------------------*/
CURRENT_VIEW->zone_start = 1;
CURRENT_VIEW->zone_end = strlen((DEFCHAR *)str);
CURRENT_VIEW->arbchar_status = TRUE;
CURRENT_VIEW->arbchar_single = find_unique_char(str);
CURRENT_VIEW->hex = FALSE;
rc = validate_target(str,&target,target_type,get_true_line(TRUE),TRUE,FALSE);
if (rc == RC_TARGET_NOT_FOUND
&& CURRENT_VIEW->wrap)
{
wrapped = TRUE;
negative = target.rt[0].negative;
free_target(&target);
initialise_target(&target);
true_line = (negative ? CURRENT_FILE->number_lines+1 : 0L);
CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line = true_line;
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
rc = validate_target(str,&target,target_type,true_line,TRUE,FALSE);
}
/*---------------------------------------------------------------------*/
/* Put ZONE, ARBCHAR and HEX back the way they were... */
/*---------------------------------------------------------------------*/
CURRENT_VIEW->zone_start = save_zone_start;
CURRENT_VIEW->zone_end = save_zone_end;
CURRENT_VIEW->arbchar_status = save_arbchar_status;
CURRENT_VIEW->arbchar_single = save_arbchar_single;
CURRENT_VIEW->hex = save_hex;
/*---------------------------------------------------------------------*/
/* Check for target not found... */
/*---------------------------------------------------------------------*/
if (rc == RC_TARGET_NOT_FOUND)
{
if (wrapped)
{
CURRENT_VIEW->focus_line = save_focus_line;
CURRENT_VIEW->current_line = save_current_line;
}
display_error(34,(CHARTYPE *)"",FALSE);
free_target(&target);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/*---------------------------------------------------------------------*/
/* Target found, so advance the cursor... */
/*---------------------------------------------------------------------*/
/* post_process_line(CURRENT_VIEW,save_focus_line,(LINE *)NULL,TRUE);*/
if (wrapped)
{
CURRENT_VIEW->focus_line = save_focus_line;
CURRENT_VIEW->current_line = save_current_line;
build_screen(current_screen);
if (CURRENT_VIEW->current_window == WINDOW_COMMAND
|| compatible_feel == COMPAT_XEDIT)
CURRENT_VIEW->current_line = true_line;
else
CURRENT_VIEW->focus_line = true_line;
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
}
rc = advance_current_or_focus_line(target.num_lines);
free_target(&target);
if (wrapped)
display_error(0,(CHARTYPE*)"Wrapped...",FALSE);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_modify_command(CHARTYPE *str)
#else
short execute_modify_command(str)
CHARTYPE *str;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern VALUE item_values[18];
extern CHARTYPE *temp_cmd;
/*--------------------------- local data ------------------------------*/
register short i=0;
short itemno=0;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_modify_command");
#endif
if ((itemno = find_item(str,QUERY_MODIFY)) == (-1))
{
display_error(1,str,FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
itemno = get_item_values(itemno,(CHARTYPE *)"",QUERY_MODIFY,0L,NULL,0L);
strcpy((DEFCHAR *)temp_cmd,"set");
for (i=0;i<itemno+1;i++)
{
strcat((DEFCHAR *)temp_cmd," ");
strcat((DEFCHAR *)temp_cmd,(DEFCHAR *)item_values[i].value);
}
#ifdef TRACE
trace_return();
#endif
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
LENGTHTYPE calculate_rec_len(short action,LENGTHTYPE current_rec_len,LENGTHTYPE start_col,LINETYPE num_cols)
#else
LENGTHTYPE calculate_rec_len(action,current_rec_len,start_col,num_cols)
short action;
LENGTHTYPE current_rec_len,start_col;
LINETYPE num_cols;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
/*--------------------------- local data ------------------------------*/
LENGTHTYPE new_rec_len=0;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: calcualte_rec_len");
#endif
switch(action)
{
case ADJUST_DELETE:
if (num_cols > 0)
{
if (start_col < current_rec_len)
new_rec_len = (LENGTHTYPE)(LINETYPE)current_rec_len -
(min((LINETYPE)current_rec_len - (LINETYPE)start_col,num_cols));
}
else
{
new_rec_len = current_rec_len;
}
break;
case ADJUST_INSERT:
new_rec_len = current_rec_len;
break;
case ADJUST_OVERWRITE:
new_rec_len = current_rec_len;
break;
}
#ifdef TRACE
trace_return();
#endif
return(new_rec_len);
}
/***********************************************************************/
#ifdef HAVE_PROTO
static short set_editv(CHARTYPE *var,CHARTYPE *val,bool editv_file,bool rexx_var)
#else
static short set_editv(var,val,editv_file,rexx_var)
CHARTYPE *var;
CHARTYPE *val;
bool editv_file;
bool rexx_var;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern LINE *editv;
/*--------------------------- local data ------------------------------*/
short rc=RC_OK;
LINE *curr=NULL;
int len_var=0,len_val=0;
CHARTYPE *value=NULL;
LINE *first=NULL;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: set_editv");
#endif
first = (editv_file)?CURRENT_FILE->editv:editv;
if (rexx_var)
{
rc = get_rexx_variable(var,&value,&len_val);
if (rc != RC_OK)
{
#ifdef TRACE
trace_return();
#endif
return(rc);
}
}
else
{
if (val == NULL)
value = (CHARTYPE*)"";
else
value = val;
len_val = strlen((DEFCHAR*)value);
}
var = make_upper(var);
len_var = strlen((DEFCHAR*)var);
curr = lll_locate(first,var);
if (curr) /* found an existing variable */
{
if (len_val > curr->length)
{
curr->line = (CHARTYPE *)(*the_realloc)(curr->line,(len_val+1)*sizeof(CHARTYPE));
if (curr->line == NULL)
{
if (rexx_var && value)
(*the_free)(value);
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
}
if (len_val == 0) /* need to delete the entry */
{
if (editv_file)
lll_del(&(CURRENT_FILE->editv),NULL,curr,DIRECTION_FORWARD);
else
lll_del(&editv,NULL,curr,DIRECTION_FORWARD);
}
else
strcpy((DEFCHAR*)curr->line,(DEFCHAR*)value);
}
else
{
curr = lll_add(first,NULL,sizeof(LINE));
if (curr == NULL)
{
if (rexx_var && value)
(*the_free)(value);
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
/*---------------------------------------------------------------------*/
/* As the current variable is always inserted as the start of the LL */
/* we must set the first pointer to the current variable each time. */
/*---------------------------------------------------------------------*/
if (editv_file)
CURRENT_FILE->editv = curr;
else
editv = curr;
curr->line = (CHARTYPE *)(*the_malloc)((len_val+1)*sizeof(CHARTYPE));
if (curr->line == NULL)
{
if (rexx_var && value)
(*the_free)(value);
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
strcpy((DEFCHAR*)curr->line,(DEFCHAR*)value);
curr->length = len_val;
curr->name = (CHARTYPE *)(*the_malloc)((len_var+1)*sizeof(CHARTYPE));
if (curr->name == NULL)
{
if (rexx_var && value)
(*the_free)(value);
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
strcpy((DEFCHAR*)curr->name,(DEFCHAR*)var);
}
if (rexx_var && value)
(*the_free)(value);
#ifdef TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short execute_editv(short editv_type,bool editv_file,CHARTYPE *params)
#else
short execute_editv(editv_type,editv_file,params)
short editv_type;
bool editv_file;
CHARTYPE *params;
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern LINE *editv;
extern short terminal_lines;
/*--------------------------- local data ------------------------------*/
#define EDITV_PARAMS 2
CHARTYPE *word[EDITV_PARAMS+1];
CHARTYPE strip[EDITV_PARAMS];
CHARTYPE *p=NULL,*str=NULL;
unsigned short num_params=0;
LINE *curr=NULL,*first=NULL;
int key=0,lineno=0;
short rc=RC_OK;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("execute.c: execute_editv");
#endif
first = (editv_file)?CURRENT_FILE->editv:editv;
switch(editv_type)
{
case EDITV_SETL:
strip[0] = STRIP_BOTH;
strip[1] = STRIP_NONE;
num_params = param_split(params,word,EDITV_PARAMS,WORD_DELIMS,TEMP_PARAM,strip);
if (num_params == 0)
{
display_error(3,(CHARTYPE *)"",FALSE);
#ifdef TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
rc = set_editv(word[0],word[1],editv_file,FALSE);
break;
case EDITV_SET:
p = (CHARTYPE *)strtok((DEFCHAR *)params," ");
while(p != NULL)
{
p = make_upper(p);
str = (CHARTYPE *)strtok(NULL," ");
rc = set_editv(p,str,editv_file,FALSE);
if (str == NULL)
break;
p = (CHARTYPE *)strtok(NULL," ");
}
break;
case EDITV_PUT:
p = (CHARTYPE *)strtok((DEFCHAR *)params," ");
while(p != NULL)
{
p = make_upper(p);
rc = set_editv(p,NULL,editv_file,TRUE);
p = (CHARTYPE *)strtok(NULL," ");
}
break;
case EDITV_GET:
p = (CHARTYPE *)strtok((DEFCHAR *)params," ");
while(p != NULL)
{
p = make_upper(p);
curr = lll_locate(first,p);
if (curr
&& curr->line)
str = curr->line;
else
str = (CHARTYPE *)"";
if (set_rexx_variable(p,str,strlen((DEFCHAR*)str),-1) != RC_OK)
break;
p = (CHARTYPE *)strtok(NULL," ");
}
break;
case EDITV_LIST:
wclear(stdscr);
if (blank_field(params))
{
curr = first;
while (curr != NULL)
{
if (curr->line)
str = curr->line;
else
str = (CHARTYPE *)"";
attrset(A_BOLD);
mvaddstr(lineno,0,(DEFCHAR *)curr->name);
attrset(A_NORMAL);
mvaddstr(lineno,12,(DEFCHAR *)str);
lineno++;
curr = curr->next;
}
}
else
{
p = (CHARTYPE *)strtok((DEFCHAR *)params," ");
while(p != NULL)
{
p = make_upper(p);
curr = lll_locate(first,p);
if (curr
&& curr->line)
str = curr->line;
else
str = (CHARTYPE *)"";
attrset(A_BOLD);
mvaddstr(lineno,0,(DEFCHAR *)p);
attrset(A_NORMAL);
mvaddstr(lineno,12,(DEFCHAR *)str);
lineno++;
p = (CHARTYPE *)strtok(NULL," ");
}
}
mvaddstr(terminal_lines-2,0,HIT_ANY_KEY);
refresh();
while(1)
{
key = my_getch(stdscr);
#if defined(XCURSES)
if (key == KEY_SF || key == KEY_SR)
continue;
#endif
#if defined(KEY_MOUSE)
if (key == KEY_MOUSE)
continue;
#endif
#ifdef CAN_RESIZE
if (is_termresized())
continue;
#endif
break;
}
THERefresh((CHARTYPE *)"");
restore_THE();
break;
}
#ifdef TRACE
trace_return();
#endif
return(rc);
}
|