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
|
/* SC A Spreadsheet Calculator
* Command routines
*
* original by James Gosling, September 1982
* modifications by Mark Weiser and Bruce Israel,
* University of Maryland
*
* More mods Robert Bond, 12/86
*
* $Revision: 7.13 $
*/
#include <sys/types.h>
#include <sys/wait.h>
#if defined(BSD42) || defined(BSD43)
#include <strings.h>
#else
#ifndef SYSIII
#include <string.h>
#endif
#endif
#include <curses.h>
#include <time.h>
#if defined(BSD42) || defined(BSD43) || defined(VMS)
#include <sys/file.h>
#else
#include <fcntl.h>
#endif
#include "sc.h"
#include <signal.h>
#include <errno.h>
#include <stdlib.h>
#ifndef MSDOS
#include <unistd.h>
#endif
void syncref(register struct enode *e);
void unspecial(FILE *f, char *str, int delim);
/* a linked list of free [struct ent]'s, uses .next as the pointer */
extern struct ent *freeents;
/* a linked list of free [struct enodes]'s, uses .e.o.left as the pointer */
extern struct enode *freeenodes;
#define DEFCOLDELIM ':'
extern char *scext;
extern char *ascext;
extern char *tbl0ext;
extern char *tblext;
extern char *latexext;
extern char *slatexext;
extern char *texext;
extern int Vopt;
extern struct go_save gs;
int macrofd;
int cslop;
/* copy the current row (currow) and place the cursor in the new row */
void
duprow()
{
int c1, c2, coltmp = curcol;
struct frange *fr;
fr = find_frange(currow, curcol);
c1 = fr ? fr->or_left->col : 0;
c2 = fr ? fr->or_right->col : maxcol;
if (currow >= maxrows - 1 || (!fr && maxrow >= maxrows - 1) ||
(fr && fr->or_right->row >= maxrows - 1)) {
if (!growtbl(GROWROW, 0, 0))
return;
}
modflg++;
insertrow(1, 1);
for (curcol = c1; curcol <= c2; curcol++) {
register struct ent *p = *ATBL(tbl, currow - 1, curcol);
if (p) {
register struct ent *n;
n = lookat(currow, curcol);
(void) copyent(n, p, 1, 0);
}
}
for (curcol = c1; curcol <= c2; curcol++) {
register struct ent *p = *ATBL(tbl, currow, curcol);
if (p && (p->flags & is_valid) && !p->expr)
break;
}
curcol = coltmp;
}
/* copy the current column (curcol) and place the cursor in the new column */
void
dupcol()
{
int rowtmp = currow;
if (curcol >= maxcols - 1 || maxcol >= maxcols - 1) {
if (!growtbl(GROWCOL, 0, 0))
return;
}
modflg++;
insertcol(1, 1);
for (currow = 0; currow <= maxrow; currow++) {
register struct ent *p = *ATBL(tbl, currow, curcol - 1);
if (p) {
register struct ent *n;
n = lookat(currow, curcol);
copyent(n, p, 0, 1);
}
}
for (currow = 0; currow <= maxrow; currow++) {
register struct ent *p = *ATBL(tbl, currow, curcol);
if (p && (p -> flags & is_valid) && !p -> expr)
break;
}
currow = rowtmp;
}
/* Insert 'arg' rows. The row(s) will be inserted before currow if delta
* is 0; after if it is 1.
*/
void
insertrow(int arg, int delta)
{
int r, c, i;
struct ent **tmprow, **pp;
int lim = maxrow - currow + 1;
struct frange *fr;
if (currow > maxrow)
maxrow = currow;
maxrow += arg;
lim = maxrow - lim + delta;
if ((maxrow >= maxrows) && !growtbl(GROWROW, maxrow, 0))
return;
if ((fr = find_frange(currow + delta, curcol))) {
move_area(currow + arg + delta, fr->or_left->col, currow + delta,
fr->or_left->col, fr->or_right->row, fr->or_right->col);
flush_saved();
if (!delta && fr->ir_left->row == currow + arg)
fr->ir_left = lookat(fr->ir_left->row - arg, fr->ir_left->col);
if (delta && fr->ir_right->row == currow)
fr->ir_right = lookat(fr->ir_right->row + arg, fr->ir_right->col);
for (i=0; i < 27; i++) { /* update all marked cells */
if (savedrow[i] >= currow + delta &&
savedcol[i] >= fr->or_left->col &&
savedcol[i] <= fr->or_right->col)
savedrow[i] += arg;
if (savedstrow[i] >= currow + delta &&
savedstcol[i] >= fr->or_left->col &&
savedstcol[i] <= fr->or_right->col)
savedstrow[i] += arg;
}
if (gs.g_row >= currow + delta &&
gs.g_col >= fr->or_left->col &&
gs.g_col <= fr->or_right->col)
gs.g_row += arg;
if (gs.g_lastrow >= currow + delta &&
gs.g_lastcol >= fr->or_left->col &&
gs.g_lastcol <= fr->or_right->col)
gs.g_lastrow += arg;
if (gs.strow >= currow + delta &&
gs.stcol >= fr->or_left->col &&
gs.stcol <= fr->or_right->col)
gs.strow += arg;
} else {
/*
* save the last active row+1, shift the rows downward, put the last
* row in place of the first
*/
tmprow = tbl[maxrow];
for (r = maxrow; r > lim; r--) {
row_hidden[r] = row_hidden[r-arg];
row_hidden[r-arg] = row_hidden[r-1];
tbl[r] = tbl[r-arg];
tbl[r-arg] = tbl[r-1];
pp = ATBL(tbl, r, 0);
for (c = 0; c < maxcols; c++, pp++)
if (*pp)
(*pp)->row = r;
}
tbl[r] = tmprow; /* the last row was never used.... */
for (i=0; i < 27; i++) { /* update all marked cells */
if (savedrow[i] >= currow + delta)
savedrow[i] += arg;
if (savedstrow[i] >= currow + delta)
savedstrow[i] += arg;
}
if (gs.g_row >= currow + delta)
gs.g_row += arg;
if (gs.g_lastrow >= currow + delta)
gs.g_lastrow += arg;
if (gs.strow >= currow + delta)
gs.strow += arg;
for (r = 0; r <= maxrow; r++) {
for (c = 0; c <= maxcol; c++) {
pp = ATBL(tbl, r, c);
if (*pp) {
if ((*pp)->nrow >= currow + delta)
((*pp)->nrow) += arg;
if ((*pp)->nlastrow >= currow + delta)
((*pp)->nlastrow) += arg;
}
}
}
}
fix_ranges(currow + arg * (1 - delta), -1, currow + arg * (1 - delta), -1,
delta?0:arg, delta?arg:0);
currow += delta;
FullUpdate++;
modflg++;
}
/* Insert 'arg' cols. The col(s) will be inserted before curcol if delta
* is 0; after if it is 1.
*/
void
insertcol(int arg, int delta)
{
int r, c;
register struct ent **pp;
int lim = maxcol - curcol - delta + 1;
struct frange *fr;
if (curcol + delta > maxcol)
maxcol = curcol + delta;
maxcol += arg;
if ((maxcol >= maxcols) && !growtbl(GROWCOL, 0, maxcol))
return;
for (c = maxcol; c >= curcol + delta + arg; c--) {
fwidth[c] = fwidth[c-arg];
precision[c] = precision[c-arg];
realfmt[c] = realfmt[c-arg];
col_hidden[c] = col_hidden[c-arg];
}
for (c = curcol + delta; c - curcol - delta < arg; c++) {
fwidth[c] = DEFWIDTH;
precision[c] = DEFPREC;
realfmt[c] = DEFREFMT;
col_hidden[c] = FALSE;
}
for (r=0; r <= maxrow; r++) {
pp = ATBL(tbl, r, maxcol);
for (c = lim; --c >= 0; pp--)
if ((pp[0] = pp[-arg]))
pp[0]->col += arg;
pp = ATBL(tbl, r, curcol + delta);
for (c = curcol + delta; c - curcol - delta < arg; c++, pp++)
*pp = (struct ent *)0;
}
/* Update all marked cells. */
for (c=0; c < 27; c++) {
if (savedcol[c] >= curcol + delta)
savedcol[c] += arg;
if (savedstcol[c] >= curcol + delta)
savedstcol[c] += arg;
}
if (gs.g_col >= curcol + delta)
gs.g_col += arg;
if (gs.g_lastcol >= curcol + delta)
gs.g_lastcol += arg;
if (gs.stcol >= curcol + delta)
gs.stcol += arg;
/* Update note links. */
for (r = 0; r <= maxrow; r++) {
for (c = 0; c <= maxcol; c++) {
pp = ATBL(tbl, r, c);
if (*pp) {
if ((*pp)->ncol >= curcol + delta)
((*pp)->ncol) += arg;
if ((*pp)->nlastcol >= curcol + delta)
((*pp)->nlastcol) += arg;
}
}
}
if (!delta && (fr = find_frange(currow, curcol)) &&
fr->ir_left->col == curcol + arg)
fr->ir_left = lookat(fr->ir_left->row, fr->ir_left->col - arg);
if (delta && (fr = find_frange(currow, curcol)) &&
fr->ir_right->col == curcol)
fr->ir_right = lookat(fr->ir_right->row, fr->ir_right->col + arg);
fix_ranges(-1, curcol + arg * (1 - delta), -1, curcol + arg * (1 - delta),
delta?0:arg, delta?arg:0);
curcol += delta;
FullUpdate++;
modflg++;
}
/* delete 'arg' rows starting at currow (deletes from currow downward) */
void
deleterow(register int arg)
{
int rs = maxrow - currow + 1;
int i;
char buf[50];
struct frange *fr;
if ((fr = find_frange(currow, curcol)))
rs = fr->or_right->row - currow + 1;
if (rs - arg < 0) {
rs = rs > 0 ? rs : 0;
(void) sprintf(buf, "Can't delete %d row%s %d row%s left", arg,
(arg != 1 ? "s," : ","), rs, (rs != 1 ? "s" : ""));
error(buf);
return;
}
if (fr) {
if (any_locked_cells(currow, fr->or_left->col,
currow + arg - 1, fr->or_right->col))
error("Locked cells encountered. Nothing changed");
else {
FullUpdate++;
modflg++;
flush_saved();
sync_refs();
erase_area(currow, fr->or_left->col, currow + arg - 1,
fr->or_right->col);
fix_ranges(currow, -1, currow + arg - 1, -1, -1, -1);
if (currow + arg > fr->or_right->row)
fr->or_right = lookat(currow - 1, fr->or_right->col);
else {
move_area(currow, fr->or_left->col, currow + arg,
fr->or_left->col, fr->or_right->row, fr->or_right->col);
flush_saved();
}
if (currow + arg > fr->ir_right->row && fr->ir_right->row >= currow)
fr->ir_right = lookat(currow - 1, fr->ir_right->col);
/* Update all marked cells. */
for (i=0; i < 27; i++) {
if (savedcol[i] >= fr->or_left->col &&
savedcol[i] <= fr->or_right->col) {
if (savedrow[i] >= currow && savedrow[i] < currow + arg)
savedrow[i] = savedcol[i] = -1;
if (savedrow[i] >= currow + arg)
savedrow[i] -= arg;
}
if (savedstcol[i] >= fr->or_left->col &&
savedstcol[i] <= fr->or_right->col) {
if (savedstrow[i] >= currow && savedstrow[i] < currow + arg)
savedstrow[i] = currow;
if (savedstrow[i] >= currow + arg)
savedstrow[i] -= arg;
}
}
if (gs.g_col >= fr->or_left->col &&
gs.g_col <= fr->or_right->col) {
if (gs.g_row >= currow && gs.g_row < currow + arg)
gs.g_row = currow;
if (gs.g_row >= currow + arg)
gs.g_row -= arg;
}
if (gs.g_lastcol >= fr->or_left->col &&
gs.g_lastcol <= fr->or_right->col) {
if (gs.g_lastrow >= currow && gs.g_lastrow < currow + arg)
gs.g_lastrow = currow - 1;
if (gs.g_lastrow >= currow + arg)
gs.g_lastrow -= arg;
}
if (gs.g_row > gs.g_lastrow)
gs.g_row = gs.g_col = -1;
if (gs.stcol >= fr->or_left->col &&
gs.stcol <= fr->or_right->col) {
if (gs.strow >= currow && gs.strow < currow + arg)
gs.strow = currow;
if (gs.strow >= currow + arg)
gs.strow -= arg;
}
}
} else {
if (any_locked_cells(currow, 0, currow + arg - 1, maxcol))
error("Locked cells encountered. Nothing changed");
else {
flush_saved();
sync_refs();
erase_area(currow, 0, currow + arg - 1, maxcol);
fix_ranges(currow, -1, currow + arg - 1, -1, -1, -1);
closerow(currow, arg);
}
}
}
void
yankrow(int arg)
{
int rs = maxrow - currow + 1;
char buf[50];
struct frange *fr;
if ((fr = find_frange(currow, curcol)))
rs = fr->or_right->row - currow + 1;
if (rs - arg < 0) {
rs = rs > 0 ? rs : 0;
(void) sprintf(buf, "Can't yank %d row%s %d row%s left", arg,
(arg != 1 ? "s," : ","), rs, (rs != 1 ? "s" : ""));
error(buf);
return;
}
if (fr) {
sync_refs();
flush_saved();
yank_area(currow, fr->or_left->col, currow + arg - 1,
fr->or_right->col);
} else {
sync_refs();
flush_saved();
yank_area(currow, 0, currow + arg - 1, maxcol);
}
}
void
yankcol(int arg)
{
int cs = maxcol - curcol + 1;
char buf[50];
if (cs - arg < 0) {
cs = cs > 0 ? cs : 0;
(void) sprintf(buf, "Can't yank %d column%s %d column%s left", arg,
(arg != 1 ? "s," : ","), cs, (cs != 1 ? "s" : ""));
error(buf);
return;
}
sync_refs();
flush_saved();
yank_area(0, curcol, maxrow, curcol + arg - 1);
}
void
erase_area(int sr, int sc, int er, int ec)
{
int r, c;
struct ent **pp;
if (sr > er) {
r = sr; sr = er; er = r;
}
if (sc > ec) {
c = sc; sc = ec; ec = c;
}
if (sr < 0)
sr = 0;
if (sc < 0)
sc = 0;
checkbounds(&er, &ec);
/* Do a lookat() for the upper left and lower right cells of the range
* being erased to make sure they are included in the delete buffer so
* that pulling cells always works correctly even if the cells at one
* or more edges of the range are all empty.
*/
(void) lookat(sr, sc);
(void) lookat(er, ec);
dbidx++;
for (r = sr; r <= er; r++) {
for (c = sc; c <= ec; c++) {
pp = ATBL(tbl, r, c);
if (*pp && !((*pp)->flags&is_locked)) {
free_ent(*pp);
*pp = NULL;
}
}
}
}
void
yank_area(int sr, int sc, int er, int ec)
{
int r, c;
if (sr > er) {
r = sr; sr = er; er = r;
}
if (sc > ec) {
c = sc; sc = ec; ec = c;
}
if (sr < 0)
sr = 0;
if (sc < 0)
sc = 0;
checkbounds(&er, &ec);
r = currow;
currow = sr;
c = curcol;
curcol = sc;
erase_area(sr, sc, er, ec);
pullcells('m');
currow = r;
curcol = c;
}
void
move_area(int dr, int dc, int sr, int sc, int er, int ec)
{
struct ent *p;
struct ent **pp;
int deltar, deltac;
int r, c;
if (sr > er) {
r = sr; sr = er; er = r;
}
if (sc > ec) {
c = sc; sc = ec; ec = c;
}
if (sr < 0)
sr = 0;
if (sc < 0)
sc = 0;
checkbounds(&er, &ec);
r = currow;
currow = sr;
c = curcol;
curcol = sc;
/* First we erase the source range, which puts the cells on the delete
* buffer stack. The pullcells(0) then makes a copy in the original
* location, which we then erase, putting the copy on the delete buffer
* stack, too.
*/
erase_area(sr, sc, er, ec);
pullcells(0);
erase_area(sr, sc, er, ec);
currow = r;
curcol = c;
deltar = dr - sr;
deltac = dc - sc;
/* Now we erase the destination range, which adds it to the delete buffer
* stack, but then we flush it off. We then move the original source
* range from the stack to the destination range, adjusting the addresses
* as we go, which leaves only the copy on the stack for future pulls.
*/
erase_area(dr, dc, er + deltar, ec + deltac);
flush_saved();
for (p = delbuf[dbidx - 1]; p; p = p->next) {
pp = ATBL(tbl, p->row + deltar, p->col + deltac);
*pp = p;
p->row += deltar;
p->col += deltac;
p->flags &= ~is_deleted;
}
delbuf[dbidx - 1] = delbuf[dbidx];
delbuf[dbidx--] = NULL;
}
/*
* deletes the expression associated w/ a cell and turns it into a constant
* containing whatever was on the screen
*/
void
valueize_area(int sr, int sc, int er, int ec)
{
int r, c;
struct ent *p;
if (sr > er) {
r = sr; sr = er; er= r;
}
if (sc > ec) {
c = sc; sc = ec; ec= c;
}
if (sr < 0)
sr = 0;
if (sc < 0)
sc = 0;
checkbounds(&er, &ec);
for (r = sr; r <= er; r++) {
for (c = sc; c <= ec; c++) {
p = *ATBL(tbl, r, c);
if (p && p->flags&is_locked) {
error(" Cell %s%d is locked", coltoa(c), r);
continue;
}
if (p && p->expr) {
efree(p->expr);
p->expr = (struct enode *)0;
p->flags &= ~is_strexpr;
}
}
}
}
void
pullcells(int to_insert)
{
struct ent *p, *n;
struct ent **pp;
int deltar, deltac;
int minrow, mincol;
int mxrow, mxcol;
int numrows, numcols;
struct frange *fr;
if (dbidx < 0) {
error("No data to pull");
return;
}
minrow = maxrows;
mincol = maxcols;
mxrow = 0;
mxcol = 0;
for (p = delbuf[dbidx]; p; p = p->next) {
if (p->row < minrow)
minrow = p->row;
if (p->row > mxrow)
mxrow = p->row;
if (p->col < mincol)
mincol = p->col;
if (p->col > mxcol)
mxcol = p->col;
}
numrows = mxrow - minrow + 1;
numcols = mxcol - mincol + 1;
deltar = currow - minrow;
deltac = curcol - mincol;
if (to_insert == 'r') {
insertrow(numrows, 0);
if (fr = find_frange(currow, curcol))
deltac = fr->or_left->col - mincol;
else
deltac = 0;
} else if (to_insert == 'c') {
insertcol(numcols, 0);
deltar = 0;
} else if (to_insert == 'x') { /* Do an exchange. */
struct ent *tmp;
/* Save the original contents of the destination range in preparation
* for the exchange.
*/
erase_area(minrow + deltar, mincol + deltac, mxrow + deltar,
mxcol + deltac);
tmp = delbuf[dbidx];
delbuf[dbidx] = delbuf[dbidx - 1];
delbuf[dbidx - 1] = tmp;
}
FullUpdate++;
modflg++;
/* First copy the cells from the delete buffer into the destination
* range.
*/
for (p = delbuf[dbidx]; p; p = p->next) {
if (to_insert == 't')
/* Transpose rows and columns while pulling. */
n = lookat(minrow + deltar + p->col - mincol,
mincol + deltac + p->row - minrow);
else
n = lookat(p->row + deltar, p->col + deltac);
(void) clearent(n);
copyent(n, p, 0, 0);
n->flags = p->flags & ~is_deleted;
}
/* Now exchange them so that the original cells from the delete buffer
* are in the destination range instead of the copies. When doing a
* "pull exchange" ("px" or "pullxchg"), exchange the original contents
* of the destination range with the contents of the delete buffer
* instead. Don't do this if called from move_area() or when transposing.
*/
if (to_insert && to_insert != 't') {
if (to_insert == 'x') {
struct ent *tmp = delbuf[dbidx];
delbuf[dbidx] = delbuf[dbidx - 1];
delbuf[dbidx - 1] = tmp;
} else
erase_area(minrow + deltar, mincol + deltac, mxrow + deltar,
mxcol + deltac);
for (p = delbuf[dbidx - 1]; p; p = p->next) {
pp = ATBL(tbl, p->row + deltar, p->col + deltac);
*pp = p;
p->row += deltar;
p->col += deltac;
p->flags &= ~is_deleted;
}
delbuf[dbidx - 1] = delbuf[dbidx];
delbuf[dbidx--] = NULL;
sync_refs();
/*
* Now change the cell addresses in the delete buffer to match
* where the original cells came from.
*/
for (p = delbuf[dbidx]; p; p = p->next) {
p->row -= deltar;
p->col -= deltac;
}
}
}
void
colshow_op()
{
register int i,j;
for (i=0; i<maxcols; i++)
if (col_hidden[i])
break;
for(j=i; j<maxcols; j++)
if (!col_hidden[j])
break;
j--;
if (i>=maxcols)
error("No hidden columns to show");
else {
(void) sprintf(line,"show %s:", coltoa(i));
(void) sprintf(line + strlen(line),"%s",coltoa(j));
linelim = strlen(line);
}
}
void
rowshow_op()
{
register int i,j;
for (i=0; i<maxrows; i++)
if (row_hidden[i])
break;
for(j=i; j<maxrows; j++)
if (!row_hidden[j]) {
break;
}
j--;
if (i>=maxrows)
error("No hidden rows to show");
else {
(void)sprintf(line,"show %d:%d", i, j);
linelim = strlen(line);
}
}
/*
* Given a row/column command letter, emit a small menu, then read a qualifier
* character for a row/column command and convert it to 'r' (row), 'c'
* (column), or 0 (unknown). If ch is 'p', three extra qualifiers, 'm', 'x',
* and 't', are allowed. If ch is 'Z', an extra qualifier 'Z' is allowed.
*/
#define SHOWROWS 2
#define SHOWCOLS 3
int
get_rcqual(int ch)
{
int c;
error("%sow/column: r: row c: column%s",
#ifdef KEY_IC
(ch == KEY_IC) ? "Insert r" :
#endif
(ch == 'i') ? "Insert r" :
(ch == 'o') ? "Open r" :
(ch == 'a') ? "Append r" :
(ch == 'd') ? "Delete r" :
(ch == 'y') ? "Yank r" :
(ch == 'p') ? "Pull r" :
(ch == 'v') ? "Values r" :
(ch == 'Z') ? "Zap r" :
(ch == 's') ? "Show r" : "R",
(ch == 'p') ? " m: merge x: exchange t: transpose" : "");
(void) refresh();
switch (c = nmgetch())
{
case 'r': return ('r');
case 'c': return ('c');
case 'm': return ((ch == 'p') ? 'm' : 0);
case 'x': return ((ch == 'p') ? 'x' : 0);
case 't': return ((ch == 'p') ? 't' : 0);
case 'Z': return ((ch == 'Z') ? 'Z' : 0);
case ESC:
case ctl('g'): return (ESC);
case 'd': if (ch == 'd') {
ungetch('x');
return (ESC);
} else
return (0);
case 'y': if (ch == 'y') {
flush_saved();
yank_area(currow, curcol, currow, curcol);
return (ESC);
} else
return (0);
case 'v': if (ch == 'v') {
valueize_area(currow, curcol, currow, curcol);
return (ESC);
} else
return (0);
case KEY_UP:
case KEY_DOWN:
case KEY_PPAGE:
case KEY_NPAGE:
case 'j':
case 'k':
case 'J':
case 'K':
case ctl('f'):
case ctl('b'):
case ctl('n'):
case ctl('p'): if (ch == 'd')
(void) sprintf(line,"deleterow [range] ");
else if (ch == 'y')
(void) sprintf(line,"yankrow [range] ");
else
return (0);
edit_mode();
write_line('A');
startshow();
showrange = SHOWROWS;
showsr = currow;
ungetch(c);
return (ESC);
case KEY_BACKSPACE:
case KEY_LEFT:
case KEY_RIGHT:
case ' ':
case 'h':
case 'l':
case 'H':
case 'L': if (ch == 'd')
(void) sprintf(line,"deletecol [range] ");
else if (ch == 'y')
(void) sprintf(line,"yankcol [range] ");
else
return (0);
edit_mode();
write_line('A');
startshow();
showrange = SHOWCOLS;
showsc = curcol;
ungetch(c);
return (ESC);
default: return (0);
}
/*NOTREACHED*/
}
/* delete numrow rows, starting with rs */
void
closerow(int rs, int numrow)
{
register struct ent **pp;
int r, c, i;
struct ent **tmprow;
if (rs + numrow - 1 > maxrow) return;
r = rs;
/*
* Rows are dealt with in numrow groups, each group of rows spaced numrow
* rows apart.
*/
for (i = 0; i < numrow; i++) {
r = rs + i;
/* save the first row of the group and empty it out */
tmprow = tbl[r];
pp = ATBL(tbl, r, 0);
for (c = maxcol + 1; --c >= 0; pp++) {
if (*pp) {
free_ent(*pp);
*pp = (struct ent *)0;
}
}
/* move the rows, put the deleted, but now empty, row at the end */
for (; r + numrow < maxrows - 1; r += numrow) {
row_hidden[r] = row_hidden[r + numrow];
tbl[r] = tbl[r + numrow];
pp = ATBL(tbl, r, 0);
for (c = 0; c < maxcols; c++, pp++)
if (*pp)
(*pp)->row = r;
}
tbl[r] = tmprow;
}
/* Update all marked cells. */
for (i=0; i < 27; i++) {
if (savedrow[i] >= rs && savedrow[i] < rs + numrow)
savedrow[i] = savedcol[i] = -1;
if (savedrow[i] >= rs + numrow)
savedrow[i] -= numrow;
if (savedstrow[i] >= rs && savedstrow[i] < rs + numrow)
savedstrow[i] = rs;
if (savedstrow[i] >= rs + numrow)
savedstrow[i] -= numrow;
}
if (gs.g_row >= rs && gs.g_row < rs + numrow)
gs.g_row = rs;
if (gs.g_row >= rs + numrow)
gs.g_row -= numrow;
if (gs.g_lastrow >= rs && gs.g_lastrow < rs + numrow)
gs.g_lastrow = rs - 1;
if (gs.g_lastrow >= rs + numrow)
gs.g_lastrow -= numrow;
if (gs.g_row > gs.g_lastrow)
gs.g_row = gs.g_col = -1;
if (gs.strow >= rs && gs.strow < rs + numrow)
gs.strow = rs;
if (gs.strow >= rs + numrow)
gs.strow -= numrow;
maxrow -= numrow;
/* Update note links. */
for (r = 0; r <= maxrow; r++) {
for (c = 0; c <= maxcol; c++) {
pp = ATBL(tbl, r, c);
if (*pp) {
if ((*pp)->nrow >= rs && (*pp)->nrow < rs + numrow)
(*pp)->nrow = rs;
if ((*pp)->nrow >= rs + numrow)
((*pp)->nrow) -= numrow;
if ((*pp)->nlastrow >= rs && (*pp)->nlastrow < rs + numrow)
(*pp)->nlastrow = rs - 1;
if ((*pp)->nlastrow >= rs + numrow)
((*pp)->nlastrow) -= numrow;
if ((*pp)->nlastrow < (*pp)->nrow)
(*pp)->nrow = (*pp)->ncol = -1;
}
}
}
FullUpdate++;
modflg++;
}
/* delete group of columns (1 or more) */
void
closecol(int arg)
{
int r, c, i;
register struct ent **pp;
register struct ent *q;
int cs = maxcol - curcol + 1;
char buf[50];
if (cs - arg < 0) {
cs = cs > 0 ? cs : 0;
(void) sprintf(buf, "Can't delete %d column%s %d column%s left", arg,
(arg != 1 ? "s," : ","), cs, (cs != 1 ? "s" : ""));
error(buf);
return;
}
if (any_locked_cells(0, curcol, maxrow, curcol + arg - 1)) {
error("Locked cells encountered. Nothing changed");
return;
}
flush_saved();
sync_refs();
erase_area(0, curcol, maxrow, curcol + arg - 1);
fix_ranges(-1, curcol, -1, curcol + arg - 1, -1, -1);
/* clear then copy the block left */
cs = maxcols - arg - 1;
for (r=0; r<=maxrow; r++) {
for (c = curcol; c - curcol < arg; c++)
if ((q = *ATBL(tbl, r, c)))
free_ent(q);
pp = ATBL(tbl, r, curcol);
for (c=curcol; c <= cs; c++, pp++) {
if (c > cs)
*pp = (struct ent *)0;
else if ((pp[0] = pp[arg]))
pp[0]->col -= arg;
}
c = arg;
for (; --c >= 0; pp++)
*pp = (struct ent *)0;
}
for (i = curcol; i < maxcols - arg - 1; i++) {
fwidth[i] = fwidth[i+arg];
precision[i] = precision[i+arg];
realfmt[i] = realfmt[i+arg];
col_hidden[i] = col_hidden[i+arg];
}
for (; i < maxcols - 1; i++) {
fwidth[i] = DEFWIDTH;
precision[i] = DEFPREC;
realfmt[i] = DEFREFMT;
col_hidden[i] = FALSE;
}
/* Update all marked cells. */
for (i=0; i < 27; i++) {
if (savedcol[i] >= curcol && savedcol[i] < curcol + arg)
savedrow[i] = savedcol[i] = -1;
if (savedcol[i] >= curcol + arg)
savedcol[i] -= arg;
if (savedstcol[i] >= curcol && savedstcol[i] < curcol + arg)
savedstcol[i] = curcol;
if (savedstcol[i] >= curcol + arg)
savedstcol[i] -= arg;
}
if (gs.g_col >= curcol && gs.g_col < curcol + arg)
gs.g_col = curcol;
if (gs.g_col >= curcol + arg)
gs.g_col -= arg;
if (gs.g_lastcol >= curcol && gs.g_lastcol < curcol + arg)
gs.g_lastcol = curcol - 1;
if (gs.g_lastcol >= curcol + arg)
gs.g_lastcol -= arg;
if (gs.g_col > gs.g_lastcol)
gs.g_row = gs.g_col = -1;
if (gs.stcol >= curcol && gs.stcol < curcol + arg)
gs.stcol = curcol;
if (gs.stcol >= curcol + arg)
gs.stcol -= arg;
maxcol -= arg;
/* Update note links. */
for (r = 0; r <= maxrow; r++) {
for (c = 0; c <= maxcol; c++) {
pp = ATBL(tbl, r, c);
if (*pp) {
if ((*pp)->ncol >= curcol && (*pp)->ncol < curcol + arg)
(*pp)->ncol = curcol;
if ((*pp)->ncol >= curcol + arg)
((*pp)->ncol) -= arg;
if ((*pp)->nlastcol >= curcol && (*pp)->nlastcol < curcol + arg)
(*pp)->nlastcol = curcol - 1;
if ((*pp)->nlastcol >= curcol + arg)
((*pp)->nlastcol) -= arg;
if ((*pp)->nlastcol < (*pp)->ncol)
(*pp)->nrow = (*pp)->ncol = -1;
}
}
}
FullUpdate++;
modflg++;
}
void
doend(int rowinc, int colinc)
{
register struct ent *p;
int r, c;
/* Remember the current position */
savedrow[0] = currow;
savedcol[0] = curcol;
savedstrow[0] = strow;
savedstcol[0] = stcol;
if (VALID_CELL(p, currow, curcol)) {
r = currow + rowinc;
c = curcol + colinc;
if (r >= 0 && r < maxrows &&
c >= 0 && c < maxcols &&
!VALID_CELL(p, r, c)) {
currow = r;
curcol = c;
}
}
if (!VALID_CELL(p, currow, curcol)) {
switch (rowinc) {
case -1:
while (!VALID_CELL(p, currow, curcol) && currow > 0)
currow--;
break;
case 1:
while (!VALID_CELL(p, currow, curcol) && currow < maxrows-1)
currow++;
break;
case 0:
switch (colinc) {
case -1:
while (!VALID_CELL(p, currow, curcol) && curcol > 0)
curcol--;
break;
case 1:
while (!VALID_CELL(p, currow, curcol) && curcol < maxcols-1)
curcol++;
break;
}
break;
}
rowsinrange = 1;
colsinrange = fwidth[curcol];
error (""); /* clear line */
return;
}
switch (rowinc) {
case -1:
while (VALID_CELL(p, currow, curcol) && currow > 0)
currow--;
break;
case 1:
while (VALID_CELL(p, currow, curcol) && currow < maxrows-1)
currow++;
break;
case 0:
switch (colinc) {
case -1:
while (VALID_CELL(p, currow, curcol) && curcol > 0)
curcol--;
break;
case 1:
while (VALID_CELL(p, currow, curcol) && curcol < maxcols-1)
curcol++;
break;
}
break;
}
if (!VALID_CELL(p, currow, curcol)) {
currow -= rowinc;
curcol -= colinc;
}
rowsinrange = 1;
colsinrange = fwidth[curcol];
}
/* Modified 9/17/90 THA to handle more formats */
void
doformat(int c1, int c2, int w, int p, int r)
{
register int i;
int crows = 0;
int ccols = c2;
if (c1 >= maxcols && !growtbl(GROWCOL, 0, c1)) c1 = maxcols-1 ;
if (c2 >= maxcols && !growtbl(GROWCOL, 0, c2)) c2 = maxcols-1 ;
if (usecurses && w > COLS - rescol - 2) {
error("Format too large - Maximum = %d", COLS - rescol - 2);
w = COLS - rescol - 2;
}
if (p > w) {
error("Precision too large");
p = w;
}
checkbounds(&crows, &ccols);
if (ccols < c2) {
error("Format statement failed to create implied column %d", c2);
return;
}
for (i = c1; i <= c2; i++)
fwidth[i] = w, precision[i] = p, realfmt[i] = r;
rowsinrange = 1;
colsinrange = fwidth[curcol];
FullUpdate++;
modflg++;
}
void
print_options(FILE *f)
{
if (
autocalc &&
!autoinsert &&
!cslop &&
!optimize &&
!rndtoeven &&
propagation == 10 &&
calc_order == BYROWS &&
!numeric &&
prescale == 1.0 &&
!extfunc &&
showcell &&
showtop &&
tbl_style == 0 &&
craction == 0 &&
pagesize == 0 &&
rowlimit == -1 &&
collimit == -1 &&
!color &&
!colorneg &&
!colorerr
)
return; /* No reason to do this */
(void) fprintf(f, "set");
if (!autocalc)
(void) fprintf(f," !autocalc");
if (autoinsert)
(void) fprintf(f," autoinsert");
if (cslop)
(void) fprintf(f," cslop");
if (optimize)
(void) fprintf(f," optimize");
if (rndtoeven)
(void) fprintf(f, " rndtoeven");
if (propagation != 10)
(void) fprintf(f, " iterations = %d", propagation);
if (calc_order != BYROWS )
(void) fprintf(f, " bycols");
if (numeric)
(void) fprintf(f, " numeric");
if (prescale != 1.0)
(void) fprintf(f, " prescale");
if (extfunc)
(void) fprintf(f, " extfun");
if (!showcell)
(void) fprintf(f, " !cellcur");
if (!showtop)
(void) fprintf(f, " !toprow");
if (tbl_style)
(void) fprintf(f, " tblstyle = %s", tbl_style == TBL ? "tbl" :
tbl_style == LATEX ? "latex" :
tbl_style == SLATEX ? "slatex" :
tbl_style == TEX ? "tex" :
tbl_style == FRAME ? "frame" : "0" );
if (craction)
(void) fprintf(f, " craction = %d", craction);
if (pagesize)
(void) fprintf(f, " pagesize = %d", pagesize);
if (rowlimit >= 0)
(void) fprintf(f, " rowlimit = %d", rowlimit);
if (collimit >= 0)
(void) fprintf(f, " collimit = %d", collimit);
if (color)
(void) fprintf(f," color");
if (colorneg)
(void) fprintf(f," colorneg");
if (colorerr)
(void) fprintf(f," colorerr");
(void) fprintf(f, "\n");
}
void
printfile(char *fname, int r0, int c0, int rn, int cn)
{
FILE *f;
static char *pline = NULL; /* only malloc once, malloc is slow */
static unsigned fbufs_allocated = 0;
int plinelim;
int pid;
int fieldlen, nextcol;
long namelen;
int row, col;
register struct ent **pp;
char file[256];
char path[1024];
char *tpp;
/* printfile will be the [path/]file ---> [path/]file.out */
if (*fname == '\0') {
strcpy(path, curfile);
#ifdef MSDOS
namelen = 12;
if ((tpp = strrchr(path, '\\')) == NULL) {
#else
if ((tpp = strrchr(path, '/')) == NULL) {
namelen = pathconf(".", _PC_NAME_MAX);
#endif
tpp = path;
} else {
#ifndef MSDOS
*tpp = '\0';
namelen = pathconf(path, _PC_NAME_MAX);
*tpp = '/';
#endif
tpp++;
}
strcpy(file, tpp);
if (!strcmp(file + strlen(file) - 3, ".sc"))
file[strlen(file) - 3] = '\0';
else if (scext != NULL && file[strlen(file) - strlen(scext) - 1] == '.'
&& !strcmp(file + strlen(file) - strlen(scext), scext))
file[strlen(file) - strlen(scext)] = '\0';
if (ascext == NULL)
file[namelen - 4] = '\0';
else
file[namelen - strlen(ascext) - 1] = '\0';
sprintf(tpp, "%s.%s", file, ascext == NULL ? "asc" : ascext);
fname = path;
}
if ((strcmp(fname, curfile) == 0) &&
!yn_ask("Confirm that you want to destroy the data base: (y,n)")) {
return;
}
if (!pline && (pline = scxmalloc((unsigned)(FBUFLEN *
++fbufs_allocated))) == (char *)NULL) {
error("Malloc failed in printfile()");
return;
}
if ((f = openfile(fname, &pid, NULL)) == (FILE *)0) {
error("Can't create file \"%s\"", fname);
return;
}
for (row = r0; row <= rn; row++) {
int c = 0;
if (row_hidden[row])
continue;
pline[plinelim=0] = '\0';
for (pp = ATBL(tbl, row, col=c0); col<=cn;
pp += nextcol-col, col = nextcol, c += fieldlen) {
nextcol = col+1;
if (col_hidden[col]) {
fieldlen = 0;
continue;
}
fieldlen = fwidth[col];
if (*pp) {
char *s;
/*
* dynamically allocate pline, making sure we are not
* attempting to write 'out of bounds'.
*/
while (c > (fbufs_allocated * FBUFLEN)) {
if ((pline = scxrealloc ((char *)pline,
(unsigned)(FBUFLEN * ++fbufs_allocated))) == NULL) {
error ("Realloc failed in printfile()");
return;
}
}
while (plinelim<c) pline[plinelim++] = ' ';
plinelim = c;
if ((*pp)->flags&is_valid) {
while(plinelim + fwidth[col] >
(fbufs_allocated * FBUFLEN)) {
if((pline = ((char *)scxrealloc
((char *)pline,
(unsigned)(FBUFLEN * ++fbufs_allocated))))
== NULL) {
error("Realloc failed in printfile()");
return;
}
}
if ((*pp)->cellerror)
(void) sprintf(pline+plinelim, "%*s",
fwidth[col], ((*pp)->cellerror == CELLERROR ?
"ERROR " : "INVALID "));
else {
char *cfmt;
cfmt = (*pp)->format ? (*pp)->format :
(realfmt[col] >= 0 && realfmt[col] < COLFORMATS &&
colformat[realfmt[col]]) ?
colformat[realfmt[col]] : 0;
if (cfmt) {
char field[FBUFLEN];
if (*cfmt == ctl('d')) {
time_t v = (time_t) ((*pp)->v);
strftime(field, sizeof(field), cfmt + 1,
localtime(&v));
sprintf(pline+plinelim, "%-*s", fwidth[col],
field);
} else {
format(cfmt, precision[col], (*pp)->v, field,
sizeof(field));
(void) sprintf(pline+plinelim, "%*s", fwidth[col],
field);
}
} else {
char field[FBUFLEN];
(void) engformat(realfmt[col], fwidth[col],
precision[col], (*pp) -> v,
field, sizeof(field));
(void) sprintf(pline+plinelim, "%*s", fwidth[col],
field);
}
}
plinelim += strlen(pline+plinelim);
}
if ((s = (*pp)->label)) {
int slen;
char *start, *last;
register char *fp;
struct ent *nc;
/*
* Figure out if the label slops over to a blank field.
* A string started with backslash is defining repetition
* char
*/
slen = strlen(s);
if (*s == '\\' && *(s+1) != '\0')
slen = fwidth[col];
while (slen > fieldlen && nextcol <= cn &&
!((nc = lookat(row,nextcol))->flags & is_valid) &&
!(nc->label)) {
if (!col_hidden[nextcol])
fieldlen += fwidth[nextcol];
nextcol++;
}
if (slen > fieldlen)
slen = fieldlen;
while(c + fieldlen + 2 > (fbufs_allocated * FBUFLEN)) {
if((pline = ((char *)scxrealloc
((char *)pline,
(unsigned)(FBUFLEN * ++fbufs_allocated))))
== NULL) {
error ("scxrealloc failed in printfile()");
return;
}
}
/* Now justify and print */
start = (*pp)->flags & is_leftflush ? pline + c
: pline + c + fieldlen - slen;
if( (*pp)->flags & is_label )
start = pline + (c + ((fwidth[col]>slen)?(fwidth[col]-slen)/2:0));
last = pline + c + fieldlen;
fp = plinelim < c ? pline + plinelim : pline + c;
while (fp < start)
*fp++ = ' ';
if( *s == '\\' && *(s+1)!= '\0' ) {
char *strt;
strt = ++s;
while(slen--) {
*fp++ = *s++; if( *s == '\0' ) s = strt;
}
}
else
while (slen--)
*fp++ = *s++;
if (!((*pp)->flags & is_valid) || fieldlen != fwidth[col])
while(fp < last)
*fp++ = ' ';
if (plinelim < fp - pline)
plinelim = fp - pline;
}
}
}
pline[plinelim++] = '\n';
pline[plinelim] = '\0';
(void) fputs (pline, f);
}
closefile(f, pid, 0);
}
void
tblprintfile(char *fname, int r0, int c0, int rn, int cn)
{
FILE *f;
int pid;
long namelen;
int row, col;
register struct ent **pp;
char coldelim = DEFCOLDELIM;
char file[256];
char path[1024];
char *tpp;
/* tblprintfile will be the [path/]file ---> [path/]file.out */
if (*fname == '\0') {
strcpy(path, curfile);
#ifdef MSDOS
namelen = 12;
if ((tpp = strrchr(path, '\\')) == NULL) {
#else
if ((tpp = strrchr(path, '/')) == NULL) {
namelen = pathconf(".", _PC_NAME_MAX);
#endif
tpp = path;
} else {
#ifndef MSDOS
*tpp = '\0';
namelen = pathconf(path, _PC_NAME_MAX);
*tpp = '/';
#endif
tpp++;
}
strcpy(file, tpp);
if (!strcmp(file + strlen(file) - 3, ".sc"))
file[strlen(file) - 3] = '\0';
else if (scext != NULL && file[strlen(file) - strlen(scext) - 1] == '.'
&& !strcmp(file + strlen(file) - strlen(scext), scext))
file[strlen(file) - strlen(scext)] = '\0';
if (tbl_style == 0) {
if (tbl0ext == NULL)
file[namelen - 4] = '\0';
else
file[namelen - strlen(tbl0ext) - 1] = '\0';
sprintf(tpp, "%s.%s", file, tbl0ext == NULL ? "cln" : tbl0ext);
}
else if (tbl_style == TBL) {
if (tblext == NULL)
file[namelen - 4] = '\0';
else
file[namelen - strlen(tblext) - 1] = '\0';
sprintf(tpp, "%s.%s", file, tblext == NULL ? "tbl" : tblext);
}
else if (tbl_style == LATEX) {
if (latexext == NULL)
file[namelen - 4] = '\0';
else
file[namelen - strlen(latexext) - 1] = '\0';
sprintf(tpp, "%s.%s", file, latexext == NULL ? "lat" : latexext);
}
else if (tbl_style == SLATEX) {
if (slatexext == NULL)
file[namelen - 4] = '\0';
else
file[namelen - strlen(slatexext) - 1] = '\0';
sprintf(tpp, "%s.%s", file, slatexext == NULL ? "stx" : slatexext);
}
else if (tbl_style == TEX) {
if (texext == NULL)
file[namelen - 4] = '\0';
else
file[namelen - strlen(texext) - 1] = '\0';
sprintf(tpp, "%s.%s", file, texext == NULL ? "tex" : texext);
}
fname = path;
}
if ((strcmp(fname, curfile) == 0) &&
!yn_ask("Confirm that you want to destroy the data base: (y,n)"))
return;
if ((f = openfile(fname, &pid, NULL)) == (FILE *)0) {
error ("Can't create file \"%s\"", fname);
return;
}
if ( tbl_style == TBL ) {
fprintf(f,".\\\" ** %s spreadsheet output \n.TS\n",progname);
fprintf(f,"tab(%c);\n",coldelim);
for (col=c0;col<=cn; col++) fprintf(f," n");
fprintf(f, ".\n");
}
else if ( tbl_style == LATEX ) {
fprintf(f,"%% ** %s spreadsheet output\n\\begin{tabular}{",progname);
for (col=c0;col<=cn; col++) fprintf(f,"c");
fprintf(f, "}\n");
coldelim = '&';
}
else if ( tbl_style == SLATEX ) {
fprintf(f,"%% ** %s spreadsheet output\n!begin<tabular><",progname);
for (col=c0;col<=cn; col++) fprintf(f,"c");
fprintf(f, ">\n");
coldelim = '&';
}
else if ( tbl_style == TEX ) {
fprintf(f,"{\t%% ** %s spreadsheet output\n\\settabs %d \\columns\n",
progname, cn-c0+1);
coldelim = '&';
}
else if ( tbl_style == FRAME ) {
fprintf(f,"<MIFFile 3.00> # generated by the sc spreadsheet calculator\n");
fprintf(f,"<Tbls\n");
fprintf(f," <Tbl \n");
fprintf(f," <TblID 1> # This table's ID is 1\n");
fprintf(f," <TblFormat \n");
fprintf(f," <TblTag `Format A'> # Table Format Catalog\n");
fprintf(f," > # end of TblFormat\n");
fprintf(f," <TblNumColumns %d> # Has %d columns\n",cn-c0+1,cn-c0+1);
fprintf(f," <TblTitleContent\n");
fprintf(f," <Para\n");
fprintf(f," <PgfTag `TableTitle'> # Forces lookup in Paragraph Format Catalog\n");
fprintf(f," <ParaLine\n");
fprintf(f," <String `%s'>\n",fname);
fprintf(f," > # end of ParaLine\n");
fprintf(f," > # end of Para\n");
fprintf(f," > # end of TblTitleContent\n");
fprintf(f," <TblH # The heading\n");
fprintf(f," <Row # The heading row\n");
for (col=c0; col <= cn; col++) {
fprintf(f," <Cell <CellContent <Para # Cell in column \n");
fprintf(f," <PgfTag `CellHeading'> # in Paragraph Format Catalog\n");
fprintf(f," <ParaLine <String `%c'>>\n",'A'+col);
fprintf(f," >>> # end of Cell\n");
}
fprintf(f," > # end of Row\n");
fprintf(f," > # end of TblH\n");
fprintf(f," <TblBody # The body\n");
}
for (row=r0; row<=rn; row++) {
if ( tbl_style == TEX )
(void) fprintf (f, "\\+");
else if (tbl_style == FRAME) {
fprintf(f," <Row # The next body row\n");
}
for (pp = ATBL(tbl, row, col=c0); col<=cn; col++, pp++) {
if ( tbl_style == FRAME ) {
fprintf(f," <Cell <CellContent <Para\n");
fprintf(f," <PgfTag `CellBody'> # in Paragraph Format Catalog\n");
fprintf(f," <ParaLine <String `");
}
if (*pp) {
char *s;
if ((*pp)->flags&is_valid) {
if ((*pp)->cellerror) {
(void) fprintf (f, "%*s",
fwidth[col],
((*pp)->cellerror == CELLERROR ? "ERROR" : "INVALID"));
} else if ((*pp)->format) {
char field[FBUFLEN];
if (*((*pp)->format) == ctl('d')) {
time_t v = (time_t) ((*pp)->v);
strftime(field, sizeof(field), ((*pp)->format)+1,
localtime(&v));
} else
format((*pp)->format, precision[col], (*pp)->v,
field, sizeof(field));
unspecial(f, field, coldelim);
} else {
char field[FBUFLEN];
(void) engformat(realfmt[col], fwidth[col],
precision[col], (*pp) -> v,
field, sizeof(field));
unspecial(f, field, coldelim);
}
}
if ((s = (*pp)->label)) {
unspecial(f, s, coldelim);
}
}
if (tbl_style == FRAME) {
fprintf(f, "'>>\n");
fprintf(f," >>> # end of Cell\n");
}
if (col < cn)
if (tbl_style != FRAME)
(void) fprintf(f,"%c", coldelim);
}
if (tbl_style == LATEX) {
if (row < rn) (void) fprintf (f, "\\\\");
}
else if (tbl_style == SLATEX) {
if (row < rn) (void) fprintf(f, "!!");
}
else if (tbl_style == TEX) {
(void) fprintf (f, "\\cr");
}
else if (tbl_style == FRAME) {
fprintf(f," > # end of Row\n");
}
(void) fprintf(f,"\n");
}
if (tbl_style == TBL)
(void) fprintf (f,".TE\n.\\\" ** end of %s spreadsheet output\n", progname);
else if (tbl_style == LATEX)
(void) fprintf(f,"\\end{tabular}\n%% ** end of %s spreadsheet output\n", progname);
else if (tbl_style == SLATEX)
(void) fprintf (f,"!end<tabular>\n%% ** end of %s spreadsheet output\n", progname);
else if (tbl_style == TEX)
(void) fprintf (f,"}\n%% ** end of %s spreadsheet output\n", progname);
else if (tbl_style == FRAME) {
fprintf(f," > # end of TblBody\n");
fprintf(f," ># end of Tbl\n");
fprintf(f,"> # end of Tbls\n");
fprintf(f,"<TextFlow <Para \n");
fprintf(f," <PgfTag Body> \n");
fprintf(f," <ParaLine <ATbl 1>> # Reference to table ID 1\n");
fprintf(f,">>\n");
}
closefile(f, pid, 0);
}
/* unspecial (backquote) things that are special chars in a table */
void
unspecial(FILE *f, char *str, int delim)
{
if (*str == '\\') str++; /* delete wheeling string operator, OK? */
while (*str) {
if (((tbl_style == LATEX) || (tbl_style == SLATEX) ||
(tbl_style == TEX)) &&
((*str == delim) || (*str == '$') || (*str == '#') ||
(*str == '%') || (*str == '{') || (*str == '}') ||
(*str == '&')))
putc('\\', f);
putc(*str, f);
str++;
}
}
struct enode *
copye(register struct enode *e, int Rdelta, int Cdelta)
{
register struct enode *ret;
if (e == (struct enode *)0)
ret = (struct enode *)0;
else if (e->op & REDUCE) {
int newrow, newcol;
if (freeenodes) {
ret = freeenodes;
freeenodes = ret->e.o.left;
} else
ret = (struct enode *) scxmalloc((unsigned) sizeof (struct enode));
ret->op = e->op;
newrow=e->e.r.left.vf & FIX_ROW ? e->e.r.left.vp->row :
e->e.r.left.vp->row+Rdelta;
newcol=e->e.r.left.vf & FIX_COL ? e->e.r.left.vp->col :
e->e.r.left.vp->col+Cdelta;
ret->e.r.left.vp = lookat(newrow, newcol);
ret->e.r.left.vf = e->e.r.left.vf;
newrow=e->e.r.right.vf & FIX_ROW ? e->e.r.right.vp->row :
e->e.r.right.vp->row+Rdelta;
newcol=e->e.r.right.vf & FIX_COL ? e->e.r.right.vp->col :
e->e.r.right.vp->col+Cdelta;
ret->e.r.right.vp = lookat(newrow, newcol);
ret->e.r.right.vf = e->e.r.right.vf;
} else {
if (freeenodes) {
ret = freeenodes;
freeenodes = ret->e.o.left;
} else
ret = (struct enode *) scxmalloc((unsigned) sizeof (struct enode));
ret->op = e->op;
switch (ret->op) {
case 'v':
{
int newrow, newcol;
newrow=e->e.v.vf & FIX_ROW ? e->e.v.vp->row :
e->e.v.vp->row+Rdelta;
newcol=e->e.v.vf & FIX_COL ? e->e.v.vp->col :
e->e.v.vp->col+Cdelta;
ret->e.v.vp = lookat(newrow, newcol);
ret->e.v.vf = e->e.v.vf;
break;
}
case 'k':
ret->e.k = e->e.k;
break;
case 'f':
ret->e.o.right = copye(e->e.o.right,0,0);
ret->e.o.left = (struct enode *)0;
break;
case '$':
ret->e.s = scxmalloc((unsigned) strlen(e->e.s)+1);
(void) strcpy(ret->e.s, e->e.s);
break;
default:
ret->e.o.right = copye(e->e.o.right,Rdelta,Cdelta);
ret->e.o.left = copye(e->e.o.left,Rdelta,Cdelta);
break;
}
}
return ret;
}
/*
* sync_refs and syncref are used to remove references to
* deleted struct ents. Note that the deleted structure must still
* be hanging around before the call, but not referenced by an entry
* in tbl. Thus the free_ent calls in sc.c
*/
void
sync_refs()
{
int i, j;
register struct ent *p;
sync_ranges();
for (i=0; i<=maxrow; i++)
for (j=0; j<=maxcol; j++)
if ((p = *ATBL(tbl, i, j)) && p->expr)
syncref(p->expr);
}
void
syncref(register struct enode *e)
{
if (e == (struct enode *)0)
return;
else if (e->op & REDUCE) {
e->e.r.right.vp = lookat(e->e.r.right.vp->row, e->e.r.right.vp->col);
e->e.r.left.vp = lookat(e->e.r.left.vp->row, e->e.r.left.vp->col);
} else {
switch (e->op) {
case 'v':
if (!(e->e.v.vp->flags & is_cleared))
e->e.v.vp = lookat(e->e.v.vp->row, e->e.v.vp->col);
else {
e->op = ERR_;
e->e.o.left = NULL;
e->e.o.right = NULL;
}
break;
case 'k':
break;
case '$':
break;
default:
syncref(e->e.o.right);
syncref(e->e.o.left);
break;
}
}
}
/* mark a row as hidden */
void
hiderow(int arg)
{
register int r1;
register int r2;
r1 = currow;
r2 = r1 + arg - 1;
if (r1 < 0 || r1 > r2) {
error("Invalid range");
return;
}
if (r2 >= maxrows-1) {
if (!growtbl(GROWROW, arg+1, 0)) {
error("You can't hide the last row");
return;
}
}
FullUpdate++;
modflg++;
while (r1 <= r2)
row_hidden[r1++] = 1;
}
/* mark a column as hidden */
void
hidecol(int arg)
{
int c1;
int c2;
c1 = curcol;
c2 = c1 + arg - 1;
if (c1 < 0 || c1 > c2) {
error ("Invalid range");
return;
}
if (c2 >= maxcols-1) {
if ((arg >= ABSMAXCOLS-1) || !growtbl(GROWCOL, 0, arg+1)) {
error("You can't hide the last col");
return;
}
}
FullUpdate++;
modflg++;
while (c1 <= c2)
col_hidden[c1++] = TRUE;
}
/* mark a row as not-hidden */
void
showrow(int r1, int r2)
{
if (r1 < 0 || r1 > r2) {
error ("Invalid range");
return;
}
if (r2 > maxrows-1) {
r2 = maxrows-1;
}
FullUpdate++;
modflg++;
while (r1 <= r2)
row_hidden[r1++] = 0;
}
/* mark a column as not-hidden */
void
showcol(int c1, int c2)
{
if (c1 < 0 || c1 > c2) {
error ("Invalid range");
return;
}
if (c2 > maxcols-1) {
c2 = maxcols-1;
}
FullUpdate++;
modflg++;
while (c1 <= c2)
col_hidden[c1++] = FALSE;
}
/* Open the input or output file, setting up a pipe if needed */
FILE *
openfile(char *fname, int *rpid, int *rfd)
{
int pipefd[4];
int pid;
FILE *f;
char *efname;
while (*fname && (*fname == ' ')) /* Skip leading blanks */
fname++;
if (*fname != '|') { /* Open file if not pipe */
*rpid = 0;
if (rfd != NULL)
*rfd = 1; /* Set to stdout just in case */
efname = findhome(fname);
#ifdef DOBACKUPS
if (rfd == NULL && !backup_file(efname) &&
(yn_ask("Could not create backup copy. Save anyway?: (y,n)") != 1))
return (0);
#endif
return (fopen(efname, rfd == NULL ? "w" : "r"));
}
#if defined(MSDOS)
error("Piping not available under MS-DOS\n");
return (0);
#else
fname++; /* Skip | */
efname = findhome(fname);
if (pipe(pipefd) < 0 || (rfd != NULL && pipe(pipefd+2) < 0)) {
error("Can't make pipe to child");
*rpid = 0;
return (0);
}
deraw(rfd==NULL);
#ifdef VMS
fprintf(stderr, "No son tasks available yet under VMS--sorry\n");
#else /* VMS */
if ((pid=fork()) == 0) { /* if child */
(void) close(0); /* close stdin */
(void) close(pipefd[1]);
(void) dup(pipefd[0]); /* connect to first pipe */
if (rfd != NULL) { /* if opening for read */
(void) close(1); /* close stdout */
(void) close(pipefd[2]);
(void) dup(pipefd[3]); /* connect to second pipe */
}
(void) signal(SIGINT, SIG_DFL); /* reset */
(void) execl("/bin/sh", "sh", "-c", efname, 0);
exit (-127);
} else { /* else parent */
*rpid = pid;
if ((f = fdopen(pipefd[(rfd==NULL?1:2)], rfd==NULL?"w":"r")) == NULL) {
(void) kill(pid, 9);
error("Can't fdopen %sput", rfd==NULL?"out":"in");
(void) close(pipefd[1]);
if (rfd != NULL)
(void) close(pipefd[3]);
*rpid = 0;
return (0);
}
}
(void) close(pipefd[0]);
if (rfd != NULL) {
(void) close(pipefd[3]);
*rfd = pipefd[1];
}
#endif /* VMS */
return (f);
#endif /* MSDOS */
}
/* close a file opened by openfile(), if process wait for return */
void
closefile(FILE *f, int pid, int rfd)
{
int temp;
(void) fclose(f);
#ifndef MSDOS
if (pid) {
while (pid != wait(&temp)) /**/;
if (rfd==0) {
(void) printf("Press any key to continue ");
(void) fflush(stdout);
cbreak();
(void) nmgetch();
goraw();
} else {
close(rfd);
if (usecurses) {
#ifdef VMS
VMS_read_raw = 1;
#else /* VMS */
#if SYSV2 || SYSV3
fixterm();
#else /* SYSV2 || SYSV3 */
cbreak();
nonl();
noecho ();
#endif /* SYSV2 || SYSV3 */
kbd_again();
#endif /* VMS */
if (color && has_colors())
bkgdset(COLOR_PAIR(1) | ' ');
}
}
}
#endif /* MSDOS */
if (brokenpipe) {
error("Broken pipe");
brokenpipe = FALSE;
}
}
void
copyent(register struct ent *n, register struct ent *p, int dr, int dc)
{
if (!n || !p) {
error("internal error");
return;
}
n->v = p->v;
n->flags = p->flags;
n->expr = copye(p->expr, dr, dc);
n->label = (char *)0;
if (p->label) {
n->label = scxmalloc((unsigned) (strlen(p->label) + 1));
(void) strcpy(n->label, p->label);
}
n->format = 0;
if (p->format) {
n->format = scxmalloc((unsigned) (strlen(p->format) + 1));
(void) strcpy(n->format, p->format);
}
}
void
write_fd(register FILE *f, int r0, int c0, int rn, int cn)
{
register struct ent **pp;
int r, c;
(void) fprintf(f, "# This data file was generated by the Spreadsheet ");
(void) fprintf(f, "Calculator.\n");
(void) fprintf(f, "# You almost certainly shouldn't edit it.\n\n");
print_options(f);
for (c = 0; c < COLFORMATS; c++)
if (colformat[c])
(void) fprintf (f, "format %d = \"%s\"\n", c, colformat[c]);
for (c = c0; c < cn; c++)
if (fwidth[c] != DEFWIDTH || precision[c] != DEFPREC ||
realfmt[c] != DEFREFMT)
(void) fprintf (f, "format %s %d %d %d\n", coltoa(c), fwidth[c],
precision[c], realfmt[c]);
for (c = c0; c < cn; c++)
if (col_hidden[c])
(void) fprintf(f, "hide %s\n", coltoa(c));
for (r = r0; r <= rn; r++)
if (row_hidden[r])
(void) fprintf(f, "hide %d\n", r);
write_ranges(f);
write_franges(f);
write_colors(f, 0);
write_cranges(f);
if (mdir)
(void) fprintf(f, "mdir \"%s\"\n", mdir);
if (autorun)
(void) fprintf(f, "autorun \"%s\"\n", autorun);
for (c = 0; c < FKEYS; c++)
if (fkey[c])
(void) fprintf(f, "fkey %d = \"%s\"\n", c + 1, fkey[c]);
write_cells(f, r0, c0, rn, cn, r0, c0);
for (r = r0; r <= rn; r++) {
pp = ATBL(tbl, r, c0);
for (c = c0; c <= cn; c++, pp++)
if (*pp) {
if ((*pp)->flags&is_locked)
(void) fprintf(f, "lock %s%d\n", coltoa((*pp)->col),
(*pp)->row);
if ((*pp)->nrow >= 0) {
(void) fprintf(f, "addnote %s ",
v_name((*pp)->row, (*pp)->col));
(void) fprintf(f, "%s\n", r_name((*pp)->nrow, (*pp)->ncol,
(*pp)->nlastrow, (*pp)->nlastcol));
}
}
}
/* xxx
if (rndtoeven)
fprintf(f, "set rndtoeven\n");
*/
/*
* Don't try to combine these into a single fprintf(). v_name() has
* a single buffer that is overwritten on each call, so the first part
* needs to be written to the file before making the second call.
*/
fprintf(f, "goto %s", v_name(currow, curcol));
fprintf(f, " %s\n", v_name(strow, stcol));
}
void
write_cells(register FILE *f, int r0, int c0, int rn, int cn, int dr, int dc)
{
register struct ent **pp;
int r, c, rs, cs, mf;
mf = modflg;
if (dr != r0 || dc != c0) {
yank_area(r0, c0, rn, cn);
rn += dr - r0;
cn += dc - c0;
rs = currow;
cs = curcol;
currow = dr;
curcol = dc;
pullcells('x');
}
if (Vopt) valueize_area(dr, dc, rn, cn);
for (r = dr; r <= rn; r++) {
pp = ATBL(tbl, r, dc);
for (c = dc; c <= cn; c++, pp++)
if (*pp) {
if ((*pp)->label) {
edits(r, c);
(void) fprintf(f, "%s\n", line);
}
if ((*pp)->flags&is_valid) {
editv(r, c);
(void) fprintf(f, "%s\n", line);
}
if ((*pp)->format) {
editfmt(r, c);
(void) fprintf(f, "%s\n",line);
}
}
}
if (dr != r0 || dc != c0) {
pullcells('x');
currow = rs;
curcol = cs;
flush_saved();
}
modflg = mf;
}
int
writefile(char *fname, int r0, int c0, int rn, int cn)
{
register FILE *f;
char save[PATHLEN];
char tfname[PATHLEN];
long namelen;
char *tpp;
int pid;
#if !defined(VMS) && !defined(MSDOS) && defined(CRYPT_PATH)
if (Crypt) {
return (cwritefile(fname, r0, c0, rn, cn));
}
#endif /* VMS */
if (*fname == '\0')
if (isatty(STDOUT_FILENO) || *curfile != '\0')
fname = curfile;
else {
write_fd(stdout, r0, c0, rn, cn);
return (0);
}
#ifdef MSDOS
namelen = 12;
#else
if ((tpp = strrchr(fname, '/')) == NULL)
namelen = pathconf(".", _PC_NAME_MAX);
else {
*tpp = '\0';
namelen = pathconf(fname, _PC_NAME_MAX);
*tpp = '/';
}
#endif /* MSDOS */
(void) strcpy(tfname, fname);
for (tpp = tfname; *tpp != '\0'; tpp++)
if (*tpp == '\\' && *(tpp + 1) == '"')
(void) memmove(tpp, tpp + 1, strlen(tpp));
if (scext != NULL) {
if (strlen(tfname) > 3 && !strcmp(tfname + strlen(tfname) - 3, ".sc"))
tfname[strlen(tfname) - 3] = '\0';
else if (strlen(tfname) > strlen(scext) + 1 &&
tfname[strlen(tfname) - strlen(scext) - 1] == '.' &&
!strcmp(tfname + strlen(tfname) - strlen(scext), scext))
tfname[strlen(tfname) - strlen(scext) - 1] = '\0';
tfname[namelen - strlen(scext) - 1] = '\0';
strcat(tfname, ".");
strcat(tfname, scext);
}
(void) strcpy(save, tfname);
for (tpp = save; *tpp != '\0'; tpp++)
if (*tpp == '"') {
(void) memmove(tpp + 1, tpp, strlen(tpp) + 1);
*tpp++ = '\\';
}
if ((f = openfile(tfname, &pid, NULL)) == NULL) {
error("Can't create file \"%s\"", save);
return (-1);
}
if (usecurses) {
error("Writing file \"%s\"...", save);
refresh();
}
write_fd(f, r0, c0, rn, cn);
closefile(f, pid, 0);
if (!pid) {
(void) strcpy(curfile, save);
modflg = 0;
error("File \"%s\" written.", curfile);
}
return (0);
}
void
readfile(char *fname, int eraseflg)
{
register FILE *f;
char save[PATHLEN];
int tempautolabel;
int pid = 0;
int rfd = STDOUT_FILENO, savefd;
tempautolabel = autolabel; /* turn off auto label when */
autolabel = 0; /* reading a file */
if (*fname == '*' && mdir) {
(void) strcpy(save, mdir);
(void) strcat(save, fname);
} else {
if (*fname == '\0')
fname = curfile;
(void) strcpy(save, fname);
}
#if !defined(VMS) && !defined(MSDOS) && defined(CRYPT_PATH)
if (Crypt) {
if (*save == '-' && strlen(fname) == 1)
error("Can't use encryption in a pipeline.");
else
if (*save == '|')
error("Can't use encryption with advanced macros.");
else
creadfile(save, eraseflg);
autolabel = tempautolabel;
return;
}
#endif /* VMS */
if (eraseflg && strcmp(fname, curfile) && modcheck(" first")) return;
#ifndef MSDOS
if (fname[0] == '-' && fname[1] == '\0') {
f = stdin;
*save = '\0';
} else {
#endif /* MSDOS */
if ((f = openfile(save, &pid, &rfd)) == NULL) {
error("Can't read file \"%s\"", save);
autolabel = tempautolabel;
return;
} else if (eraseflg) {
if (usecurses) {
error("Reading file \"%s\"", save);
refresh();
}
}
#ifndef MSDOS
}
if (*fname == '|')
*save = '\0';
#endif /* MSDOS */
if (eraseflg) erasedb();
loading++;
savefd = macrofd;
macrofd = rfd;
while (!brokenpipe && fgets(line, sizeof(line), f)) {
#ifndef MSDOS
if (line[0] == '|' && pid != 0) {
line[0] = ' ';
}
#endif /* MSDOS */
linelim = 0;
if (line[0] != '#') (void) yyparse();
}
macrofd = savefd;
--loading;
closefile(f, pid, rfd);
#ifndef MSDOS
if (f == stdin) {
freopen("/dev/tty", "r", stdin);
goraw();
}
#endif /* MSDOS */
linelim = -1;
if (eraseflg) {
(void) strcpy(curfile, save);
modflg = 0;
cellassign = 0;
if (autorun) readfile(autorun, 0);
EvalAll();
}
autolabel = tempautolabel;
}
/* erase the database (tbl, etc.) */
void
erasedb()
{
int r, c;
char *home;
for (c = 0; c<=maxcol; c++) {
fwidth[c] = DEFWIDTH;
precision[c] = DEFPREC;
realfmt[c] = DEFREFMT;
}
for (r = 0; r<=maxrow; r++) {
register struct ent **pp = ATBL(tbl, r, 0);
for (c=0; c++<=maxcol; pp++)
if (*pp) {
if ((*pp)->expr) efree((*pp) -> expr);
if ((*pp)->label) scxfree((char *)((*pp) -> label));
(*pp)->next = freeents; /* save [struct ent] for reuse */
freeents = *pp;
*pp = (struct ent *)0;
}
}
for (dbidx = 3; dbidx >= 0; )
delbuf[dbidx--] = NULL;
maxrow = 0;
maxcol = 0;
clean_range();
clean_frange();
clean_crange();
propagation = 10;
calc_order = BYROWS;
prescale = 1.0;
tbl_style = 0;
craction = 0;
rowlimit = collimit = -1;
autocalc=showcell=showtop=1;
autoinsert=optimize=numeric=extfunc=color=colorneg=colorerr=cslop=0;
currow=curcol=strow=stcol=0;
if (usecurses && has_colors())
color_set(0, NULL);
/* unset all marks */
for (c = 1; c < 27; c++)
savedrow[c] = savedcol[c] = savedstrow[c] = savedstcol[c] = -1;
/* set location to return to with `` or '' */
savedrow[0] = currow;
savedcol[0] = curcol;
savedstrow[0] = strow;
savedstcol[0] = stcol;
if (mdir) {
scxfree(mdir);
mdir = NULL;
}
if (autorun) {
scxfree(autorun);
autorun = NULL;
}
for (c = 0; c < FKEYS; c++)
if (fkey[c]) {
scxfree(fkey[c]);
fkey[c] = NULL;
}
#ifndef MSDOS
/*
* Load $HOME/.scrc if present.
*/
if ((home = getenv("HOME"))) {
strcpy(curfile, home);
strcat(curfile, "/.scrc");
if ((c = open(curfile, O_RDONLY)) > -1) {
close(c);
readfile(curfile, 0);
}
}
/*
* Load ./.scrc if present and $HOME/.scrc contained `set scrc'.
*/
if (scrc && strcmp(home, getcwd(curfile, PATHLEN)) &&
(c = open(".scrc", O_RDONLY)) > -1) {
close(c);
readfile(".scrc", 0);
}
#endif /* MSDOS */
*curfile = '\0';
FullUpdate++;
}
/* moves curcol back one displayed column */
void
backcol(int arg)
{
while (--arg >= 0) {
if (curcol)
curcol--;
else
{error ("At column A"); break;}
while(col_hidden[curcol] && curcol)
curcol--;
}
rowsinrange = 1;
colsinrange = fwidth[curcol];
}
/* moves curcol forward one displayed column */
void
forwcol(int arg)
{
while (--arg>=0) {
if (curcol < maxcols - 1)
curcol++;
else
if (!growtbl(GROWCOL, 0, arg)) /* get as much as needed */
break;
else
curcol++;
while (col_hidden[curcol] && (curcol < maxcols - 1))
curcol++;
}
rowsinrange = 1;
colsinrange = fwidth[curcol];
}
/* moves currow forward one displayed row */
void
forwrow(int arg)
{
while (--arg>=0) {
if (currow < maxrows - 1)
currow++;
else
if (!growtbl(GROWROW, arg, 0)) /* get as much as needed */
break;
else
currow++;
while (row_hidden[currow]&&(currow<maxrows-1))
currow++;
}
rowsinrange = 1;
colsinrange = fwidth[curcol];
}
/* moves currow backward one displayed row */
void
backrow(int arg)
{
while (--arg>=0) {
if (currow)
currow--;
else
{error("At row zero"); break;}
while (row_hidden[currow] && currow)
currow--;
}
rowsinrange = 1;
colsinrange = fwidth[curcol];
}
void
markcell()
{
int c;
error("Mark cell:");
if ((c=nmgetch()) == ESC || c == ctl('g')) {
error("");
return;
}
if ((c -= ('a' - 1)) < 1 || c > 26) {
error("Invalid character for mark (must be a-z)");
return;
}
error("");
savedrow[c] = currow;
savedcol[c] = curcol;
savedstrow[c] = strow;
savedstcol[c] = stcol;
}
void
dotick(int tick)
{
int c;
/* Remember the current position */
int tmprow = currow;
int tmpcol = curcol;
int tmpstrow = strow;
int tmpstcol = stcol;
error("Go to marked cell:");
if ((c = nmgetch()) == ESC || c == ctl('g')) {
error("");
return;
}
if ((c -= ('a' - 1)) < 1 || c > 26) {
if (tick == '`' || tick == '\'')
c = 0;
else {
error("Invalid character for mark (must be a-z, ` or \')");
return;
}
}
if (savedrow[c] == -1) {
error("Mark not set");
return;
}
error("");
currow = savedrow[c];
curcol = savedcol[c];
rowsinrange = 1;
colsinrange = fwidth[curcol];
if (tick == '`') {
strow = savedstrow[c];
stcol = savedstcol[c];
gs.stflag = 1;
} else
gs.stflag = 0;
savedrow[0] = tmprow;
savedcol[0] = tmpcol;
savedstrow[0] = tmpstrow;
savedstcol[0] = tmpstcol;
FullUpdate++;
}
void
gotonote()
{
register struct ent *p;
p = lookat(currow, curcol);
if (p->nrow == -1)
error("No note attached");
else
moveto(p->nrow, p->ncol, p->nlastrow, p->nlastcol, -1, -1);
}
/*
* Show a cell's label string or expression value. May overwrite value if
* there is one already displayed in the cell. Created from old code in
* update(), copied with minimal changes.
*/
void
showstring(char *string, /* to display */
int dirflush, /* or rightflush or centered */
int hasvalue, /* is there a numeric value? */
int row, int col, /* spreadsheet location */
int *nextcolp, /* value returned through it */
int mxcol, /* last column displayed? */
int *fieldlenp, /* value returned through it */
int r, int c, /* screen row and column */
struct frange *fr, /* frame range we're currently in, if any */
int frightcols, /* number of frame columns to the right */
int flcols, int frcols) /* width of left and right sides of frame */
{
int nextcol = *nextcolp;
int fieldlen = *fieldlenp;
char field[FBUFLEN];
int slen;
char *start, *last;
register char *fp;
struct ent *nc;
struct crange *cr;
cr = find_crange(row, col);
/* This figures out if the label is allowed to
slop over into the next blank field */
slen = strlen(string);
if (*string == '\\' && *(string+1) != '\0')
slen = fwidth[col];
if (c + fieldlen == rescol + flcols && nextcol < stcol)
nextcol = stcol;
if (frightcols &&
c + fieldlen + fwidth[nextcol] >= COLS - 1 - frcols &&
nextcol < fr->or_right->col - frightcols + 1)
nextcol = fr->or_right->col - frightcols + 1;
while ((slen > fieldlen) && (nextcol <= mxcol) &&
!((nc = lookat(row, nextcol))->flags & is_valid) && !(nc->label) &&
(cslop || find_crange(row, nextcol) == cr)) {
if (!col_hidden[nextcol])
fieldlen += fwidth[nextcol];
nextcol++;
if (c + fieldlen == rescol + flcols && nextcol < stcol)
nextcol = stcol;
if (frightcols &&
c + fieldlen + fwidth[nextcol] >= COLS - 1 - frcols &&
nextcol < fr->or_right->col - frightcols + 1)
nextcol = fr->or_right->col - frightcols + 1;
}
if (slen > fieldlen)
slen = fieldlen;
/* Now justify and print */
start = (dirflush&is_leftflush) ? field : field + fieldlen - slen;
if (dirflush & is_label)
start = field + ((slen<fwidth[col])?(fieldlen-slen)/2:0);
last = field+fieldlen;
fp = field;
if (slen)
while (fp < start)
*fp++ = ' ';
if (*string == '\\' && *(string+1) != '\0') {
char *strt;
strt = ++string;
while (slen--) {
*fp++ = *string++;
if (*string == '\0')
string = strt;
}
}
else
while (slen--)
*fp++ = *string++;
if ((!hasvalue) || fieldlen != fwidth[col])
while (fp < last)
*fp++ = ' ';
*fp = '\0';
#ifdef VMS
mvaddstr(r, c, field); /* this is a macro */
#else
(void) mvaddstr(r, c, field);
#endif
*nextcolp = nextcol;
*fieldlenp = fieldlen;
}
int
etype(register struct enode *e)
{
if (e == (struct enode *)0)
return NUM;
switch (e->op) {
case UPPER: case LOWER: case CAPITAL:
case O_SCONST: case '#': case DATE: case FMT: case STINDEX:
case EXT: case SVAL: case SUBSTR:
return (STR);
case '?':
case IF:
return (etype(e->e.o.right->e.o.left));
case 'f':
return (etype(e->e.o.right));
case O_VAR: {
register struct ent *p;
p = e->e.v.vp;
if (p->expr)
return (p->flags & is_strexpr ? STR : NUM);
else if (p->label)
return (STR);
else
return (NUM);
}
default:
return (NUM);
}
}
/* return 1 if yes given, 0 otherwise */
int
yn_ask(char *msg)
{ char ch;
(void) move(0, 0);
(void) clrtoeol();
(void) addstr(msg);
(void) refresh();
while ((ch = nmgetch()) != 'y' && ch != 'Y' && ch != 'n' && ch != 'N') {
if (ch == ctl('g') || ch == ESC)
return (-1);
}
if (ch == 'y' || ch == 'Y')
return (1);
else
return (0);
}
/* expand a ~ in a path to your home directory */
#if !defined(MSDOS) && !defined(VMS)
#include <pwd.h>
#endif
char *
findhome(char *path)
{
static char *HomeDir = NULL;
if (*path == '~') {
char *pathptr;
char tmppath[PATHLEN];
if (HomeDir == NULL) {
HomeDir = getenv("HOME");
if (HomeDir == NULL)
HomeDir = "/";
}
pathptr = path + 1;
if ((*pathptr == '/') || (*pathptr == '\0'))
strcpy(tmppath, HomeDir);
#if !defined(MSDOS) && !defined(VMS)
else {
struct passwd *pwent;
char *namep;
char name[50];
namep = name;
while ((*pathptr != '\0') && (*pathptr != '/'))
*(namep++) = *(pathptr++);
*namep = '\0';
if ((pwent = getpwnam(name)) == NULL) {
(void) sprintf(path, "Can't find user %s", name);
return (NULL);
}
strcpy(tmppath, pwent->pw_dir);
}
#endif
strcat(tmppath, pathptr);
strcpy(path, tmppath);
}
return (path);
}
#ifdef DOBACKUPS
#include <sys/stat.h>
/*
* make a backup copy of a file, use the same mode and name in the format
* [path/]#file~
* return 1 if we were successful, 0 otherwise
*/
int
backup_file(char *path)
{
struct stat statbuf;
char fname[PATHLEN];
char tpath[PATHLEN];
#ifdef sequent
static char *buf = NULL;
static unsigned buflen = 0;
#else
char buf[BUFSIZ];
#endif
char *tpp;
int infd, outfd;
int count;
/* tpath will be the [path/]file ---> [path/]#file~ */
strcpy(tpath, path);
if ((tpp = strrchr(tpath, '/')) == NULL)
tpp = tpath;
else
tpp++;
strcpy(fname, tpp);
(void) sprintf(tpp, "#%s~", fname);
if (stat(path, &statbuf) == 0)
{
/* if we know the optimum block size, use it */
#ifdef sequent
if ((statbuf.st_blksize > buflen) || (buf == NULL))
{ buflen = statbuf.st_blksize;
if ((buf = scxrealloc(buf, buflen)) == (char *)0)
{ buflen = 0;
return(0);
}
}
#endif
if ((infd = open(path, O_RDONLY, 0)) < 0)
return (0);
if ((outfd = open(tpath, O_TRUNC|O_WRONLY|O_CREAT,
statbuf.st_mode)) < 0)
return (0);
#ifdef sequent
while ((count = read(infd, buf, statbuf.st_blksize)) > 0)
#else
while ((count = read(infd, buf, sizeof(buf))) > 0)
#endif
{ if (write(outfd, buf, count) != count)
{ count = -1;
break;
}
}
close(infd);
close(outfd);
return ((count < 0) ? 0 : 1);
}
else
if (errno == ENOENT)
return (1);
return (0);
}
#endif
|