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
|
/************************************************************************
* This program is Copyright (C) 1986-1996 by Jonathan Payne. JOVE is *
* provided to you without charge, and with no warranty. You may give *
* away copies of JOVE, including sources, provided that this notice is *
* included in all the files. *
************************************************************************/
/* (C) 1986, 1987, 1988 Ken Mitchum. This code is intended only for use with Jove. */
/* In 1995 December, D. Hugh Redelmeier hacked on the code to make
* it work again. The environment was Think C 5.0 under System 7.1.
*
* Obligatory excuses:
* - Hugh is not a Mac expert
* - Think C 5.0 is quite obsolete (1991)
* - The only goal was to get the code working, not working well.
*
* Known issues:
* - the keyboard routines were designed for the Mac Plus keyboard.
* + "Command" is taken as "Control" and ` is taken as ESC.
* + There should be support for a distinct Command keymap
* with Mac-like default bindings.
* - "macify" ought to be extended to find-file and perhaps
* other commands
* - perhaps there are newer MacOS facilities that ought to be
* exploited. Apple Events?
* - the hacky way the command keystrokes are described in About Jove
* ought to be improved.
* - Highlighting ought to be supported.
* - Mouse support ought to be better. For example, selecting text
* ought to be at least as well done as under XTerm!
* - [supposition] Because double-clicking is supported, nothing
* is done for a single click until the double-click timeout
* happens. Since the double-click action is a superset of
* the single-click action, the single click action ought to
* be immediately performed and then augmented if a double-click
* happens.
* - see also comments containing ???
*/
#include "tune.h"
#ifdef MAC /* the body is the rest of this file */
#include "jove.h"
#include <Controls.h>
#include <Desk.h>
#include <Dialogs.h>
#include <Errors.h>
#include <Events.h>
#include <Files.h>
#include <Fonts.h>
#include <Lists.h>
#include <LoMem.h>
#include <Menus.h>
#include <Quickdraw.h>
#include <Resources.h>
#include <SegLoad.h>
#include <StandardFile.h>
#include <ToolUtils.h>
#include <Types.h>
#include <Windows.h>
#include <errno.h>
#include <pascal.h>
#include "mac.h"
#include "ask.h"
#include "chars.h"
#include "disp.h"
#include "extend.h"
#include "fp.h" /* for flushscreen() */
#include "commands.h"
#include "fmt.h"
#include "marks.h"
#include "misc.h"
#include "move.h"
#include "screen.h"
#include "scandir.h"
#include "term.h"
#include "vars.h"
#include "version.h"
#include "wind.h"
extern struct menu Menus[NMENUS]; /* from menumaps.txt => menumaps.c */
private EventRecord the_Event;
private void SetBounds proto((void));
private void Set_std proto((void));
private void Reset_std proto((void));
private bool findtext proto((void));
/* tn.h Modified for variable screen size 11/21/87. K. Mitchum */
#define SCREENSIZE (wc->w_rows * ROWSIZE)
#define FONT monaco
#define TEXTSIZE 9
#define HEIGHT 11
#define WIDTH 6
#define DESCENT 2
#define TWIDTH CO * WIDTH
#define THEIGHT LI * HEIGHT
/* window specs */
#define SCROLLWIDTH 16 /* width of scroll bar control in pixels */
#define WINDWIDTH (wc->w_width - SCROLLWIDTH + 1) /* local coordinates */
#define WINDHEIGHT (wc->w_height) /* local coordinates */
#define MAXROW ILI
#define MAXCOL (CO - 1)
/* for keyboard routines */
#define MCHARS 32 /* length of circular buffer -- must be a power of two */
#define NCHMASK (MCHARS - 1) /* mask for modulo MCHARS */
/***************************************************/
private void
putcurs proto((unsigned row, unsigned col, bool vis)),
curset proto((bool desired)),
dellines proto((int n, int bot)),
inslines proto((int n, int bot));
private Rect LimitRect; /* bounds we can't move past */
struct wind_config {
int w_width; /* pixel width of the Mac window */
int w_height;
int w_rows; /* rows of characters which fit the window */
int w_cols;
} wc_std, wc_user, *wc;
private WindowPtr theScreen;
bool
Windchange,
EventCmd,
Keyonly,
Bufchange,
Modechange;
bool
Macmode = NO; /* VAR: use Mac file selector */
/* Initialization Routines. */
void
getTERM()
{
}
/* For each binding, mark the command with the binding.
* We use it for "About Jove ...".
* ??? This is faster than using find_binds, but it has problems:
* - it only notes the last binding of each command
* - it only reflects the three listed keymaps
* - it requires a wart on struct cmd
* - it is MAC-only
*/
private void
InitMapBinds(km, kmc)
data_obj **km;
char kmc;
{
ZXchar i;
for (i = 0; i < NCHARS; i++) {
if (*km != NULL && obj_type(*km) == COMMAND) {
struct cmd *c = (struct cmd *) *km;
c->c_map = kmc;
c->c_key = i;
}
km += 1;
}
}
private void
InitBinds()
{
InitMapBinds(MainKeys, F_MAINMAP);
InitMapBinds(EscKeys, F_PREF1MAP);
InitMapBinds(CtlxKeys, F_PREF2MAP);
}
private WindowPtr window;
private Rect r;
private CursHandle cross;
private void InitSysMenu proto((void));
void
InitEvents()
{
window = theScreen;
InitSysMenu();
SetRect(&r, window->portRect.left,
window->portRect.top,
window->portRect.right - SCROLLWIDTH,
window->portRect.bottom - SCROLLWIDTH);
cross = GetCursor(crossCursor);
}
private void tn_init proto((void));
private int getdir proto((void));
void
MacInit()
{
tn_init();
getdir();
strcpy(TmpDir, gethome());
strcpy(ShareDir, TmpDir);
InitBinds();
}
void
ttysetattr(n)
bool n; /* also used as subscript! */
{
}
/* Surrogate unix-style file i/o routines for Jove. These replace the
routines distributed in the libraries. They work with Jove, but may
not be general enough for other purposes. */
#define NFILES 10
private int cur_vol; /* Disk or volume number */
private long cur_dir; /* Directory number */
private int cur_vref; /* ugh.. Vref for volume + directory */
struct ftab {
bool inuse;
int refnum; /* Mac file reference number */
} ft[NFILES];
private void
fsetup(p)
HParmBlkPtr p;
{
byte_zero(p, sizeof(HParamBlockRec));
p->fileParam.ioVRefNum = cur_vol;
p->fileParam.ioDirID = cur_dir;
/* p->fileParam.ioFVersNum = 0; */
}
private void
isetup(p)
IOParam *p;
{
byte_zero(p, sizeof(IOParam));
p->ioVRefNum = cur_vol;
}
/* Kludge to convert Macintosh error codes to something like Unix. */
private int
cvt_err(err) /* some of these don't make sense... */
int err;
{
switch(err) {
case noErr:
errno = 0;
return 0;
case dirFulErr:
case dskFulErr:
errno = ENOSPC;
break;
/* case nsvErr: */
/* case mFulErr: */
/* case tmfoErr: */
/* case fnfErr: */
default:
errno = ENOENT;
break;
case ioErr:
errno = EIO;
break;
case bdNamErr:
case opWrErr:
case paramErr:
errno = EINVAL;
break;
case fnOpnErr: /* dubious... */
case rfNumErr:
errno = EBADF;
break;
case eofErr: /* ditto */
case posErr:
errno = /* no longer defined: ESPIPE */ EIO;
break;
case wPrErr:
errno = EROFS;
break;
case fLckdErr:
case permErr:
errno = EACCES;
break;
case fBsyErr:
errno = EBUSY;
break;
case dupFNErr:
errno = EEXIST;
break;
case gfpErr:
case volOffLinErr:
case volOnLinErr:
case nsDrvErr:
errno = ENODEV;
break;
case noMacDskErr:
case extFSErr:
errno = EIO;
break;
case fsRnErr:
case badMDBErr:
case wrPermErr:
errno = /* no longer defined: EPERM */ EACCES;
break;
}
return -1;
}
private StringPtr
cvt_fnm(file)
const char *file;
{
static char nm[255];
char *t;
if (*file == '/') {
strcpy(nm, file + 1); /* full path */
} else {
if (strchr(file + 1, '/') != NULL)
strcpy(nm, "/"); /* make a partial pathname */
else
nm[0] = '\0';
strcat(nm, file);
}
for (t = nm; (t = strchr(t, '/')) != NULL; )
*t++ = ':';
return CtoPstr(nm);
}
private int do_creat proto((HParmBlkPtr p, StringPtr nm));
int
creat(name, perm) /* permission mode is irrelevant on a Mac */
const char *name;
int perm;
{
int fd, err;
StringPtr nm;
HParamBlockRec p;
nm = cvt_fnm(name); /* convert filename to Mac type name */
for (fd = 0; ft[fd].inuse; fd++) {
if (fd == NFILES-1) {
errno = EMFILE;
return -1;
}
}
fsetup(&p); /* try to delete it, whether it is there or not. */
p.fileParam.ioNamePtr = nm;
if ((err = PBHDelete(&p, 0)) != noErr && err != fnfErr)
return cvt_err(err);
if (do_creat(&p, nm) != 0)
return -1;
ft[fd].inuse = YES;
ft[fd].refnum = p.ioParam.ioRefNum;
return fd + 1;
}
#ifdef USE_PROTOTYPES
int
open(const char *path, int flags, ...)
#else
int
open(path, flags)
const char *path;
int flags;
#endif
{
int fd, err;
StringPtr nm;
HParamBlockRec p;
nm = cvt_fnm(path); /* convert filename to Mac type name */
for (fd = 0; ft[fd].inuse; fd++) {
if (fd == NFILES-1) {
errno = EMFILE;
return -1;
}
}
fsetup(&p);
switch (flags & 3) {
case 0: /* O_RDONLY */
p.ioParam.ioPermssn = fsRdPerm;
break;
case 1: /* O_WRONLY */
p.ioParam.ioPermssn = fsWrPerm;
break;
case 2: /* O_RDWR */
p.ioParam.ioPermssn = fsRdWrPerm;
break;
}
p.ioParam.ioNamePtr = nm;
p.ioParam.ioMisc = 0;
if ((err = PBHOpen(&p, 0)) != noErr)
return cvt_err(err);
ft[fd].refnum = p.ioParam.ioRefNum;
p.ioParam.ioPosMode = fsFromStart;
p.ioParam.ioPosOffset = 0;
if ((err = PBSetFPos((ParamBlockRec *) &p, 0)) != noErr)
return cvt_err(err);
ft[fd].inuse = YES;
errno = 0;
return fd + 1;
}
private int
do_creat(p, nm)
HParmBlkPtr p;
StringPtr nm;
{
int err;
fsetup(p);
p->fileParam.ioNamePtr = nm;
if ((err = PBHCreate(p, 0)) != noErr)
return cvt_err(err);
fsetup(p);
p->fileParam.ioNamePtr = nm;
p->fileParam.ioFDirIndex = 0;
if ((err = PBHGetFInfo(p, 0)) != noErr)
return cvt_err(err);
p->fileParam.ioDirID = cur_dir;
p->fileParam.ioFlFndrInfo.fdType = 'TEXT';
p->fileParam.ioFlFndrInfo.fdCreator = 'JV01';
p->fileParam.ioFlFndrInfo.fdFlags = 0;
p->fileParam.ioFVersNum = 0;
if ((err = PBHSetFInfo(p, 0)) != noErr)
return cvt_err(err);
fsetup(p);
p->ioParam.ioNamePtr = nm;
p->ioParam.ioPermssn = fsRdWrPerm;
p->ioParam.ioMisc = 0;
if (cvt_err(PBHOpen(p, 0)))
return -1;
return 0;
}
int
close(fd)
int fd;
{
int err;
HParamBlockRec p;
if (!ft[--fd].inuse) {
errno = EBADF;
return -1;
}
fsetup(&p);
p.ioParam.ioRefNum = ft[fd].refnum;
ft[fd].inuse = NO;
if (cvt_err(PBClose((ParamBlockRec *) &p, 0)) < 0)
return -1;
fsetup(&p);
p.ioParam.ioNamePtr = NULL;
if (cvt_err(PBFlushVol((ParamBlockRec *) &p, 0)) < 0)
return -1;
return 0;
}
private SSIZE_T con_read proto((char *buf, size_t size));
/* Raw UNIX-like read */
SSIZE_T
read(fd, ubuf, n)
int fd;
UnivPtr ubuf;
size_t n;
{
char *buf = ubuf; /* char * is more useful */
int err;
IOParam p;
if (fd == 0) {
return con_read(buf, n);
} else {
if (!ft[--fd].inuse) {
errno = EBADF;
return -1;
}
isetup(&p);
p.ioRefNum = ft[fd].refnum;
p.ioBuffer = buf;
p.ioReqCount = n;
p.ioPosMode = fsFromMark;
p.ioPosOffset = 0;
if ((err = PBRead((ParamBlockRec *)&p, 0)) != noErr && err != eofErr)
return cvt_err(err);
errno = 0;
return p.ioActCount;
}
}
/* Raw UNIX-like write */
SSIZE_T
write(fd, ubuf, n)
int fd;
UnivConstPtr ubuf;
size_t n;
{
const char *buf = ubuf; /* char * is more convenient */
if (fd == 0) {
writetext((unsigned char *)buf, n);
return n;
} else {
IOParam p;
int err;
const char *ebuf = buf + n;
if (!ft[--fd].inuse) {
errno = EBADF;
return -1;
}
isetup(&p);
p.ioRefNum = ft[fd].refnum;
p.ioPosMode = fsFromMark;
p.ioReqCount = n;
p.ioBuffer = (Ptr)buf;
p.ioPosOffset = 0L; /* bidirectional */
if ((err = PBWrite((ParamBlockRec *)&p, 0)) != noErr)
return cvt_err(err);
return p.ioActCount;
}
}
long
lseek(fd, offset, whence)
int fd;
long offset;
int whence;
{
int err;
long cur_mark, leof, new_mark;
IOParam p;
if (!ft[--fd].inuse) {
errno = EBADF;
return -1;
}
isetup(&p);
p.ioRefNum = ft[fd].refnum;
if ((err = PBGetFPos((ParamBlockRec *)&p, 0)) != noErr)
return cvt_err(err);
cur_mark = p.ioPosOffset;
isetup(&p);
p.ioRefNum = ft[fd].refnum;
if ((err = PBGetEOF((ParamBlockRec *)&p, 0)) != noErr)
return cvt_err(err);
leof = (long) p.ioMisc;
switch(whence) {
case 0:
new_mark = offset;
break;
case 1:
new_mark = offset + cur_mark;
break;
case 2:
new_mark = offset + leof;
break;
default:
errno = EINVAL;
return -1;
}
if (new_mark > leof) {
/* need more space in file -- grow it */
isetup(&p);
p.ioRefNum = ft[fd].refnum;
p.ioMisc = (Ptr) new_mark;
if ((err = PBSetEOF((ParamBlockRec *)&p, 0)) != noErr)
return cvt_err(err);
}
isetup(&p);
p.ioRefNum = ft[fd].refnum;
p.ioPosOffset = new_mark;
p.ioPosMode = fsFromStart;
if ((err = PBSetFPos((ParamBlockRec *)&p, 0)) != noErr)
return cvt_err(err);
errno = 0;
return p.ioPosOffset;
}
/* delete file, if it exists */
int
unlink(name)
const char *name;
{
int fd, err;
HParamBlockRec p;
fsetup(&p);
p.fileParam.ioNamePtr = cvt_fnm(name);
if ((err = PBHDelete(&p, 0)) != noErr && err != fnfErr)
return cvt_err(err);
return 0;
}
/* Console read routine */
private ZXchar rawgetc proto((void));
private SSIZE_T
con_read(buf, size)
char *buf;
size_t size;
{
size_t n;
ZXchar p;
n = 0;
do {
p = rawgetc();
*buf++ = p;
n++;
} while (rawchkc() && n <= size);
return n;
}
void
dobell(n) /* declared in term.h */
int n;
{
while (--n >= 0)
SysBeep(5);
flushscreen();
}
/* Simplified stat() routine emulates what is needed most. */
int
stat(fname, buf)
const char *fname;
struct stat *buf;
{
CInfoPBRec p;
StringPtr nm;
nm = cvt_fnm(fname);
byte_zero(&p, sizeof(CInfoPBRec));
p.hFileInfo.ioCompletion = 0;
p.hFileInfo.ioNamePtr = nm;
p.hFileInfo.ioFVersNum = 0;
p.hFileInfo.ioFDirIndex = 0;
p.hFileInfo.ioVRefNum = cur_vol;
p.hFileInfo.ioDirID = cur_dir;
switch (PBGetCatInfo(&p, 0)) {
case noErr:
errno = 0;
buf->st_dev = p.hFileInfo.ioVRefNum + 1; /* don't want 0 */
buf->st_ino = p.hFileInfo.ioDirID;
buf->st_size = p.hFileInfo.ioFlLgLen;
buf->st_mtime = p.hFileInfo.ioFlMdDat;
buf->st_mode = (p.hFileInfo.ioFlAttrib & 0x10) ? S_IFDIR : S_IFREG;
return 0;
case nsvErr:
case paramErr:
case bdNamErr:
case fnfErr:
errno = ENOENT;
break;
case ioErr:
errno = EIO;
break;
default:
errno = ENOENT;
break;
}
return -1;
}
/* Directory related routines. Jove keeps track of the true Volume (disk)
number and directory number, and avoids "Working Directory Reference
Numbers", which are confusing. */
private int
getdir() /* call this only once, during startup. */
{
WDPBRec p;
p.ioCompletion = 0;
p.ioNamePtr = NULL;
if (PBHGetVol(&p, 0) != noErr)
return -1; /* BIG trouble (but caller never checks returned value!) */
cur_vol = p.ioWDVRefNum;
cur_dir = p.ioWDDirID;
SFSaveDisk = 0 - cur_vol; /* these are for SF dialogs */
CurDirStore = cur_dir;
return 0;
}
private int
setdir(vol, dir)
int vol;
long dir;
{
WDPBRec p;
p.ioCompletion = 0;
p.ioNamePtr = NULL;
p.ioVRefNum = vol;
p.ioWDDirID = dir;
if (PBHSetVol(&p, 0) != noErr)
return -1;
cur_vol = vol;
cur_dir = dir;
SFSaveDisk = 0 - vol; /* these are for SF dialogs */
CurDirStore = dir;
return 0;
}
private bool
lookupdir(dir, d)
const char *dir; /* UNIX-like pathname for directory */
CInfoPBPtr d; /* info from directory */
{
char
nm[FILESIZE + 1],
*t;
if (strcmp(dir, ".") == 0)
getcwd(nm, sizeof(nm) - 1);
else
strcpy(nm, dir);
for (t = nm; (t = strchr(t, '/')) != NULL; )
*t++ = ':';
t = nm; /* get rid of initial slashes */
while (*t == ':')
t++;
strcat(t, ":"); /* force trailing ':', signifying directory */
byte_zero(d, sizeof(*d));
/* d->dirInfo.ioCompletion = 0; */
d->dirInfo.ioNamePtr = CtoPstr(t);
d->dirInfo.ioVRefNum = cur_vol;
/* d->dirInfo.ioFDirIndex = 0; */
/* d->dirInfo.ioDrDirID = 0; */
PBGetCatInfo(d, 0);
return d->dirInfo.ioResult == noErr
&& (d->dirInfo.ioFlAttrib & 0x10) != 0;
}
int
chdir(dir)
const char *dir;
{
CInfoPBRec d;
if (strcmp(dir, "/") == 0 /* There is no root... */
|| !lookupdir(dir, &d)
|| setdir(d.dirInfo.ioVRefNum, d.dirInfo.ioDrDirID) < 0)
return -1;
return 0;
}
/* Scandir returns the number of entries or -1 if the directory cannot
be opened or malloc fails.
Note: if we ever support RECOVER, this code will have to be moved
to scandir.c */
int
jscandir(dir, nmptr, qualify, sorter)
char *dir;
char ***nmptr;
bool (*qualify) ptrproto((char *));
int (*sorter) ptrproto((UnivConstPtr, UnivConstPtr));
{
long DirID;
char **ourarray;
unsigned int nalloc = 10,
nentries = 0,
index = 1;
if (strcmp(dir, "/") == 0) {
/* we are enumerating volumes */
DirID = 0;
} else {
/* we are enumerating the contents of a volume or directory */
CInfoPBRec d;
if (!lookupdir(dir, &d))
return -1;
DirID = d.dirInfo.ioDrDirID;
}
ourarray = (char **) emalloc(nalloc * sizeof (char *));
for (;;) {
Str32 name; /* 31 is limit, but we might add a '/' */
if (DirID == 0) {
/* we are enumerating volumes */
ParamBlockRec d;
byte_zero(&d, sizeof(d));
d.volumeParam.ioCompletion = 0;
d.volumeParam.ioNamePtr = name;
d.volumeParam.ioVRefNum = 0;
d.volumeParam.ioVolIndex = index++;
if (PBGetVInfo(&d, 0) != noErr)
break; /* we are done, then */
PtoCstr(name);
#ifdef DIRECTORY_ADD_SLASH
/* I *think* this has got to be a volume */
strcat((char *)name, "/");
#endif
} else {
/* we are enumerating the contents of a volume or directory */
CInfoPBRec d;
byte_zero(&d, sizeof(d));
d.dirInfo.ioCompletion = 0;
d.dirInfo.ioNamePtr = name;
d.dirInfo.ioVRefNum = cur_vol;
d.dirInfo.ioFDirIndex = index++;
d.dirInfo.ioDrDirID = DirID; /* .ioDirID == .ioDrDirID */
if (PBGetCatInfo(&d, 0) != noErr)
break; /* we are done, then */
PtoCstr(name);
#ifdef DIRECTORY_ADD_SLASH
if (d.dirInfo.ioFlAttrib & 0x10) /* see Inside Mac IV-122 */
strcat((char *)name, "/");
#endif
}
if (qualify != NULL && !(*qualify)((char *) name))
continue;
/* note: test ensures one space left in ourarray for NULL */
if (nentries+1 == nalloc)
ourarray = (char **) erealloc((char *) ourarray, (nalloc += 10) * sizeof (char *));
ourarray[nentries++] = copystr((char *)name);
}
ourarray[nentries] = NULL;
if (sorter != NULL)
qsort((char *) ourarray, nentries, sizeof (char **), sorter);
*nmptr = ourarray;
return nentries;
}
char *
getcwd(buf, size)
char *buf;
size_t size;
{
CInfoPBRec d;
Str31 nm;
char *p = buf + size; /* build from right */
if (p == buf)
return NULL; /* not even room for NUL */
*--p = '\0';
for (d.dirInfo.ioDrDirID = cur_dir; ; d.dirInfo.ioDrDirID = d.dirInfo.ioDrParID) {
d.dirInfo.ioCompletion = 0;
d.dirInfo.ioNamePtr = nm;
d.dirInfo.ioVRefNum = cur_vol;
d.dirInfo.ioFDirIndex = -1;
PBGetCatInfo(&d, 0);
if (d.dirInfo.ioResult != noErr)
return NULL;
if (p - buf <= Length(nm))
return NULL; /* insufficient room for / and name */
p -= Length(nm);
memcpy((UnivPtr)p, (UnivPtr) (nm+1), Length(nm));
*--p = '/';
if (d.dirInfo.ioDrDirID == 2)
break; /* home directory */
}
strcpy(buf, p); /* left justify */
return buf;
}
char *
gethome() /* this will be startup directory */
{
static char *ret = NULL;
char space[FILESIZE];
if (ret == NULL)
ret = copystr(getcwd(space, sizeof(space)));
return ret;
}
/* Routines that put up and manipulate the "About Jove" dialog. */
/* (ORIGINALLY IN) about_j.c. */
#define DLOGNAME "\pABOUT_JDLOG"
#define DONE_ITEM 1
#define LIST_ITEM 2
#define DWIDTH 460 /* there should be an easy way to get this */
#define DHEIGHT 240 /* from the resource file! */
WindowPtr makedisplay();
ListHandle makelist();
private WindowPtr theWindow;
private ListHandle theList;
private Rect theListRect;
private EventRecord theEvent;
private void
do_list proto((void)),
do_events proto((void));
private WindowPtr
makedisplay proto((void));
private ListHandle
makelist proto((void));
private void
about_j()
{
WindowPtr OldWindow;
GetPort(&OldWindow);
if ((theWindow = makedisplay()) == 0)
return;
SetPort(theWindow);
if (theList = makelist()) {
LActivate(1, theList);
do_list();
ShowWindow(theWindow);
do_events();
}
SetPort(OldWindow);
LDispose(theList);
DisposDialog(theWindow);
}
private WindowPtr
makedisplay()
{
static short dlogid = 0;
DialogPtr theDialog;
Handle theHandle;
Handle theResource;
Str255 buf;
ResType resType;
short itemType;
Rect theRect;
short dh, dv; /* to center dialog on the screen */
Str255 nostring;
if (dlogid == 0) {
if ((theResource = GetNamedResource('DLOG', DLOGNAME)) == NULL)
return (WindowPtr)NULL;
itemType = 'DLOG';
GetResInfo(theResource, &dlogid, &resType, buf);
}
theDialog = GetNewDialog(dlogid, 0L, (WindowPtr) -1);
nostring[0] = 0; /* set length of Pascal String to 0 */
ParamText(
"\pMacJove - Copyright (C) 1986-1996 J. Payne, K. Gegenfurtner,",
"\pK. Mitchum. Portions (C) THINK Technologies, Inc.",
nostring, nostring);
dh = qd.screenBits.bounds.left + (qd.screenBits.bounds.right - DWIDTH) / 2;
dv = qd.screenBits.bounds.top + (qd.screenBits.bounds.bottom - DHEIGHT) / 2;
MoveWindow((WindowPtr)theDialog, dh, dv, 0);
ShowWindow((WindowPtr)theDialog);
GetDItem(theDialog, LIST_ITEM, &itemType, &theHandle, &theRect);
theListRect = theRect;
theListRect.right -= 15;
((WindowPtr)theDialog)->txFont = FONT;
((WindowPtr)theDialog)->txSize = TEXTSIZE;
return (WindowPtr) theDialog;
}
private void
do_display() /* draw necessary controls, lines */
{
Rect rViewF; /* framing rect for list */
int offset;
rViewF = theListRect;
rViewF.left--;
rViewF.top--;
rViewF.right++;
rViewF.bottom++;
FrameRect(&rViewF);
DrawControls(theWindow);
}
private ListHandle
makelist()
{
Point csize;
Rect dataBounds, rView; /* list boundaries */
csize.h = csize.v = 0;
SetRect(&dataBounds, 0, 0, 1, 0);
return LNew(&theListRect, &dataBounds, csize, 0, theWindow, 0, 0, 0, 1);
}
private void
printbind(f, buf)
const struct cmd *f;
char *buf;
{
char c;
if (f->c_map == 0 || (c = f->c_key) == 0x7f) {
strcpy(buf, " ");
return;
}
switch(f->c_map) {
case F_MAINMAP:
strcpy(buf, " ");
break;
case F_PREF1MAP:
strcpy(buf, " ESC ");
break;
case F_PREF2MAP:
strcpy(buf, " ^X ");
break;
}
if (c < ' ') {
buf[5] = '^'; /* control char */
c |= 0x40;
} else {
buf[5] = ' ';
}
if ('a' <= c && c <= 'z')
c &= 0x5f;
buf[6] = c;
buf[7] = ' ';
buf[8] = '\0';
}
private void
do_list()
{
int row, col;
const struct cmd *f;
char buf[255];
Point theCell;
theCell.h = 0;
for (f = commands, row = 0; f->Name; f++, row++) {
LAddRow(1, row, theList);
theCell.v = row;
printbind(f, buf);
strcat(buf, f->Name);
LSetCell(buf, strlen(buf), theCell, theList);
}
}
private pascal Boolean
ProcFilter(theDialog, event, itemHit)
DialogPtr theDialog;
EventRecord *event;
short *itemHit;
{
theEvent = *event;
if (theEvent.what == keyDown && theEvent.message & charCodeMask == '\r') {
*itemHit = 1;
return YES;
}
if (theEvent.what == activateEvt && (WindowPtr) theEvent.message == theWindow) {
LDoDraw(1, theList);
LActivate(1, theList);
}
if (theEvent.what == updateEvt && (WindowPtr) theEvent.message == theWindow) {
BeginUpdate(theWindow);
do_display();
DrawDialog(theWindow);
LUpdate(theWindow->visRgn, theList);
EndUpdate(theWindow);
}
return NO;
}
void
do_events()
{
short item;
bool done = NO;
Point p;
while (!done) {
ModalDialog(ProcFilter, &item);
switch(item) {
case DONE_ITEM:
done = YES;
/* ??? fall through? -- DHR */
case LIST_ITEM:
p = theEvent.where;
GlobalToLocal(&p);
LClick(p, theEvent.modifiers, theList);
break;
}
}
}
/* Window and Control related routines. */
/* (ORIGINALLY IN) tcon.c.
control handler routines for Jove. K. Mitchum 12/86 */
#define MINC 0
#define MAXC 100
#define INITC 0
#define EVENTLIST (mDownMask | keyDownMask )
private Point p;
private bool wc_adjust proto((int, int, struct wind_config *, int));
private void
MakeScrollBar proto((Window *w)),
AdjustScrollBar proto((Window *w)),
drawfluff proto((void));
void
docontrols() /* called from redisplay routines */
{
Window *w;
int top;
w = fwind;
top = 0;
do {
if (w->w_control != NULL)
HideControl(w->w_control);
w = w->w_next;
} while (w != fwind);
w = fwind;
do {
w->w_topline = top;
if (w->w_control != NULL)
AdjustScrollBar(w);
else
MakeScrollBar(w);
ShowControl(w->w_control);
top += w->w_height;
w = w->w_next;
} while (w != fwind);
Windchange = NO;
drawfluff();
}
private void
MakeScrollBar(w) /* set up control */
Window *w;
{
Rect BarRect;
int wheight, wtop;
WindowPtr window = theScreen;
wheight = w->w_height;
wtop = w->w_topline;
SetRect(&BarRect, window->portRect.right - SCROLLWIDTH + 1,
window->portRect.top -2 + wtop * HEIGHT,
window->portRect.right +1,
window->portRect.top + ((wheight + wtop) * HEIGHT + 1));
w->w_control = NewControl(window, &BarRect, "\psbar", 1, INITC,
MINC, MAXC, scrollBarProc, (long)w);
}
private void
AdjustScrollBar(w) /* redo existing control */
Window *w;
{
ControlHandle handle = w->w_control;;
if (handle != NULL) {
int wtop = w->w_topline;
int wheight = w->w_height;
WindowPtr window = (*handle)->contrlOwner;
SizeControl(handle, SCROLLWIDTH, wheight * HEIGHT + 1);
MoveControl(handle, window->portRect.right - SCROLLWIDTH + 1,
window->portRect.top - 1 + wtop * HEIGHT);
}
}
private int ltoc proto((void)); /* calculate ctlvalue for line position */
void
SetScrollBar(w) /* set value of the bar */
Window *w;
{
SetCtlValue(w->w_control, ltoc());
}
private void
drawfluff() /* draw controls and dividers */
{
Window *w = fwind;
DrawControls(theScreen);
DrawGrowIcon(theScreen);
}
void
RemoveScrollBar(w)
Window *w;
{
if (w->w_control != NULL)
DisposeControl(w->w_control);
w->w_control = NULL;
}
private pascal void
DScroll(control, part)
ControlHandle control;
int part;
{
DownScroll();
redisplay();
}
private pascal void
UScroll(control, part)
ControlHandle control;
int part;
{
UpScroll();
redisplay();
}
private pascal void
NPage(control, part)
ControlHandle control;
int part;
{ NextPage();
redisplay();
}
private pascal void
PPage(control, part)
ControlHandle control;
int part;
{ PrevPage();
redisplay();
}
private long npos; /* number of lines in buffer */
private int
ltoc() /* calculate ctlvalue for line position */
{
long ipos = LinesTo(curbuf->b_first, curline) + 1;
npos = ipos + LinesTo(curline, (LinePtr)NULL) - 1;
return (int) ((ipos * MAXC) / npos);
}
private LinePtr
ctol(ctlv) /* find buffer line for ctlvalue */
int ctlv;
{
return next_line(curbuf->b_first, (int) ((npos * ctlv)/MAXC));
}
private void
doWind(event, window)
EventRecord *event;
WindowPtr window;
{
p = event->where;
GlobalToLocal(&p);
if (event->what == mouseDown) {
ControlHandle whichControl;
Window
*jwind,
*cwind;
bool notcurwind = NO;
int cpart; /* control part */
if ((cpart = FindControl(p, window, &whichControl)) == 0)
return;
if ((jwind = (Window *) (*whichControl)->contrlRfCon) != curwind) {
notcurwind = YES;
cwind = curwind;
SetWind(jwind);
}
switch (cpart) {
case inUpButton:
TrackControl(whichControl, p, (ProcPtr) DScroll);
break;
case inDownButton:
TrackControl(whichControl, p, (ProcPtr) UScroll);
break;
case inPageUp:
TrackControl(whichControl, p, (ProcPtr) PPage);
break;
case inPageDown:
TrackControl(whichControl, p, (ProcPtr) NPage);
break;
case inThumb:
if (TrackControl(whichControl, p, (ProcPtr)NULL)) {
int newval = GetCtlValue(whichControl);
if (newval == MAXC)
Eof();
else if (newval == MINC)
Bof();
else
SetLine(ctol(newval));
}
break;
}
if (notcurwind) {
SetWind(cwind);
redisplay();
}
redisplay(); /* again, to set the cursor */
} else {
if (findtext())
redisplay();
}
}
#define std_state(w) (*((WStateData **)((WindowPeek)((w)))->dataHandle))->stdState
#define user_state(w) (*((WStateData **)((WindowPeek)((w)))->dataHandle))->userState
private void
doDrag(event, window)
EventRecord *event;
WindowPtr window;
{
Rect old_std = std_state(window);
DragWindow(window, event->where, &LimitRect);
if (wc == &wc_std) {
wc_user = wc_std;
user_state(theScreen) = std_state(theScreen);
ZoomWindow(window, 7, 1);
wc = &wc_user;
Reset_std();
}
}
private void
doGrow(event, window)
EventRecord *event;
WindowPtr window;
{
long size;
/* zero means user didn't change anything */
if ((size = GrowWindow(window, event->where, &LimitRect)) != 0) {
if (wc == &wc_std) {
wc_user = wc_std;
user_state(theScreen) = std_state(theScreen);
ZoomWindow(window, 7, 1);
wc = &wc_user;
Reset_std();
}
if (wc_adjust(LoWord(size), HiWord(size), wc, 0)) {
EraseRect(&window->portRect);
SizeWindow(window, wc->w_width, wc->w_height, YES);
win_reshape(0); /* no signals here... */
}
}
}
private void
doZoomIn(event, window)
EventRecord *event;
WindowPtr window;
{
if (TrackBox(window, event->where, 7)) {
EraseRect(&window->portRect);
ZoomWindow(window, 7, 1);
wc = &wc_user;
win_reshape(0); /* we do our own toggle, not ZoomWindow() */
}
}
private void
doZoomOut(event, window)
EventRecord *event;
WindowPtr window;
{
if (TrackBox(window, event->where, 8)) {
EraseRect(&window->portRect);
ZoomWindow(window, 8, 1);
wc = &wc_std;
win_reshape(0); /* we do our own toggle, not ZoomWindow() */
}
}
private void
doGoAway(event, window)
EventRecord *event;
WindowPtr window;
{
if (TrackGoAway(window, event->where))
Leave();
}
private Window *
rtowind(row) /* return jove window row is in */
int row;
{
Window *w = fwind;
do {
if ((w->w_topline <= row) && ((w->w_height + w->w_topline) > row))
return w;
w = w->w_next;
} while (w != fwind);
return NULL;
}
private LinePtr
windtol(w, row) /* return line for row in window */
Window *w;
int row;
{
LinePtr l = w->w_top;
while (row-- && l != NULL)
l = l->l_next;
return l;
}
private int ptoxy proto((Point, int *, int *)); /* convert Point to terminal x, y coordinate */
private bool
findtext() /* locate and move the point to match the mouse */
{
int row, col;
int offset;
long ticks;
EventRecord event;
Window *w;
LinePtr l;
ticks = Ticks;
ptoxy(p, &row, &col);
if ((w = rtowind(row)) == NULL)
return NO;
if (w != curwind)
SetWind(w);
offset = PhysScreen[row].s_offset; /* account for horizontal scrolling and */
offset += SIWIDTH(offset) + W_NUMWIDTH(w); /* line number */
row -= w->w_topline; /* now have row number in window */
if (row >= w->w_height -1)
return NO;
if ((l = windtol(w, row)) == NULL)
return NO;
if (l->l_dline == NULL_DADDR)
return NO;
this_cmd = LINECMD;
SetLine(l); /* Curline is in linebuf now */
col -= offset;
if (col < 0)
col = 0;
curchar = how_far(curline, col);
do {
if (GetNextEvent(mUpMask, &event) && (event.when < ticks + DoubleTime)) {
set_mark();
break;
}
} while ((Ticks - ticks) < DoubleTime);
return YES;
}
private int
ptoxy(p, row, col) /* convert Point to terminal x, y coordinate */
Point p;
int *row, *col;
{
*row = (p.v / HEIGHT);
*col = (p.h / WIDTH );
if ((*row > MAXROW) || (*col > MAXCOL))
return JMP_ERROR;
return 0;
}
/* Event-related routines. The Event loop is CheckEvents(), and is called
whenever a console read occurs or a call to charp(). During certain
activities, such as ask(), etc. non-keyboard events are ignored.
This is set by the variable Keyonly. As an update or activate event
generates a call to redisplay(), it is important that redisplay() and
related routines NOT check for keyboard characters. */
/* (ORIGINALLY IN) tevent.c
event handler for Jove. K Mitchum 12/86 */
#define SYS_ID 100
#define NOFUNC ((void (*) ptrproto((EventRecord *event)))NULL)
#define NEVENTS 16
private void
doMouse proto((EventRecord *event)),
dokeyDown proto((EventRecord *event)),
doUpdate proto((EventRecord *event)),
doActivate proto((EventRecord *event));
private void p_refresh proto((void));
private MenuHandle SysMenu;
private void (*eventlist[]) ptrproto((EventRecord *event)) =
{
NOFUNC, /* nullEvent */
doMouse, /* mouseDown */
doMouse, /* mouseUp */
dokeyDown, /* keyDown */
NOFUNC, /* keyUp */
dokeyDown, /* autoKey */
doUpdate, /* updateEvt */
NOFUNC, /* diskEvt */
doActivate, /* activateEvt */
NOFUNC, /* not used */
NOFUNC, /* networkEvt = 10 */
NOFUNC, /* driverEvt */
NOFUNC, /* app1Evt */
NOFUNC, /* app2Evt */
NOFUNC, /* app3Evt */
NOFUNC /* app4Ev */
};
private void
SetBufMenu proto((void)),
MarkModes proto((void));
private void
CheckEvents()
{
EventRecord theEvent;
static long time = 0;
static void (*fptr) ptrproto((EventRecord *event));
if (FrontWindow() == window) {
Point Mousep;
GetMouse(&Mousep);
if (PtInRect(Mousep, &r))
SetCursor(*cross);
else
SetCursor(&qd.arrow);
}
SystemTask();
if (EventCmd && !Keyonly)
return;
if (Bufchange)
SetBufMenu();
if (Modechange)
MarkModes();
while (GetNextEvent(everyEvent, &theEvent)) {
if ((theEvent.what < NEVENTS) && (fptr = eventlist[theEvent.what])) {
(*fptr)(&theEvent);
}
SystemTask();
}
if (TimeDisplayed && (Ticks - time) > 3600) {
time = Ticks;
UpdModLine = YES;
redisplay();
}
}
private void InitLocalMenus proto((void));
private void
InitSysMenu()
{
SysMenu = NewMenu(SYS_ID, "\p\24");
AppendMenu(SysMenu, "\pAbout Jove");
AddResMenu(SysMenu, 'DRVR');
InsertMenu(SysMenu, 0);
InitLocalMenus();
DrawMenuBar();
}
private void
doWind proto((EventRecord *event, WindowPtr window)),
doGoAway proto((EventRecord *event, WindowPtr window)),
doSysMenu proto((EventRecord *event, WindowPtr window)),
doSysClick proto((EventRecord *event, WindowPtr window)),
doDrag proto((EventRecord *event, WindowPtr window)),
doGrow proto((EventRecord *event, WindowPtr window)),
doZoomIn proto((EventRecord *event, WindowPtr window)),
doZoomOut proto((EventRecord *event, WindowPtr window));
#define NMEVENTS 9
private void (*mouselist[]) ptrproto((EventRecord *event, WindowPtr window)) =
{
(void (*) ptrproto((EventRecord *event, WindowPtr window)))NULL, /* inDesk */
doSysMenu, /* inMenuBar */
doSysClick, /* inSysWindow */
doWind, /* inContent */
doDrag, /* inDrag */
doGrow, /* inGrow */
doGoAway, /* inGoAway */
doZoomIn, /* inZoomIn */
doZoomOut /* inZoomOut */
};
private void
doMouse(event)
EventRecord *event;
{
if (Keyonly) {
if (event->what == mouseDown)
SysBeep(2);
} else {
WindowPtr theWindow;
int wpart = FindWindow(event->where, &theWindow);
void (*fptr) ptrproto((EventRecord *event, WindowPtr window));
if (wpart < NMEVENTS && (fptr = mouselist[wpart]) != NULL)
(*fptr)(event, theWindow);
}
}
private void ProcMenu proto((int menuno, int itemno));
private void
doSysMenu(event, window)
EventRecord *event;
WindowPtr window;
{
long result = MenuSelect(event->where);
int Menu = (result >> 16) & 0xffff;
int Item = result & 0xffff;
if (Item == 0)
return; /* no choice made */
if (Menu == SYS_ID) { /* apple menu */
Str255 Name;
GrafPtr Port;
if (Item == 1) {
about_j();
} else {
GetItem(SysMenu, Item, Name);
GetPort(&Port);
OpenDeskAcc(Name);
SetPort(Port);
}
} else {
ProcMenu(Menu, Item);
}
HiliteMenu(0);
EventCmd = YES;
menus_on();
}
private void
doSysClick(event, window)
EventRecord *event;
WindowPtr window;
{
SystemClick(event, window);
}
private void
doUpdate(event)
EventRecord *event;
{
WindowPtr
theWindow = (WindowPtr) event->message,
oldPort;
GetPort(&oldPort);
SetPort(theWindow);
BeginUpdate(theWindow);
p_refresh();
drawfluff();
EndUpdate(theWindow);
SetPort(oldPort);
}
private void
doActivate(event)
EventRecord *event;
{
WindowPtr theWindow = (WindowPtr) event->message;
ControlHandle control;
int hilite;
SetPort(theWindow);
hilite = (event->modifiers & activeFlag)? 0 : 255;
for (control = (ControlHandle) (((WindowPeek) theWindow)->controlList)
; (control != 0); control = (*control)->nextControl)
{
HiliteControl(control, hilite);
}
}
/* Keyboard routines. */
/* Keycodes (from Inside MacIntosh I-251). This table is ONLY used when
* we are trying to make the Option key work as a Meta key. When we are
* doing this, the system-supplied character is wrong, so we retranslate
* the key code to a character code.
*
* Since we only use this table when the character generated by an
* option-modified key is greater than DEL, and since the Option
* modifier does not so affect keypad keys, we need not provide for
* them in this table.
*
* ??? This may need to be updated to reflect keyboards newer than the Mac+!
*/
#define NOKEY '?'
private char nsh_keycodes[] = {
'a','s','d','f','h', /* 00 - 04 */
'g','z','x','c','v', /* 05 - 09 */
NOKEY,'b','q','w','e', /* 0A - 0E */
'r','y','t','1','2', /* 0F - 13 */
'3','4','6','5','=', /* 14 - 18 */
'9','7','-','8','0', /* 19 - 1D */
']','O','u','[','i', /* 1E - 22 */
'p',CR,'l','j','\'', /* 23 - 27 */
'k',';','\\',',','/', /* 28 - 2C */
'n','m','.','\t',NOKEY, /* 2D - 31 */
'`',DEL /* 32 - 33*/
};
private char sh_keycodes[] = {
'A','S','D','F','H', /* 00 - 04 */
'G','Z','X','C','V', /* 05 - 09 */
NOKEY,'B','Q','W','E', /* 0A - 0E */
'R','Y','T','!','@', /* 0F - 13 */
'#','$','^','%','+', /* 14 - 18 */
'(','&','_','*',')', /* 19 - 1D */
'}','O','U','{','I', /* 1E - 22 */
'P',CR,'L','J','\'', /* 23 - 27 */
'K',';','|','<','?', /* 28 - 2C */
'N','M','>','\t',NOKEY, /* 2D - 31 */
'~',DEL /* 32 - 33 */
};
/* (ORIGINALLY IN) tkey.c
keyboard routines for Macintosh. K Mitchum 12/86 */
jmp_buf auxjmp;
private nchars = 0;
private char charbuf[MCHARS];
/* The following kludges a meta key out of the option key by
sending an escape sequence back to the dispatch routines. This is
not elegant but it works, and doesn't alter escape sequences for
those that prefer them. To remap the control or meta keys,
see mackeys.h. */
private void
dokeyDown(event)
EventRecord *event;
{
unsigned mods;
int c;
static int cptr = 0;
if (MCHARS - nchars < 2)
return;
c = event->message & charCodeMask;
mods = event->modifiers;
if (MetaKey && (mods & optionKey)) {
/* Treat the Option key as a Meta key.
* We have to "undo" the normal option key effect.
* This means that, if the character is greater than DEL
* and the code is known to our table, we retranslate the
* code into a character.
* This seems pretty dubious. I wonder if "KeyTrans" would
* be a better tool.
*/
int code = (event->message & keyCodeMask) >> 8;
if (c > DEL && code < elemsof(sh_keycodes))
c = ((mods & shiftKey)? sh_keycodes : nsh_keycodes)[code];
/* jam an ESC prefix */
charbuf[cptr++] = ESC;
cptr &= NCHMASK;
nchars++;
}
if (mods & (cmdKey | controlKey)) {
/* control key (command key is treated as a control key too) */
if (c == '@' || c == '2' || c == ' ')
c = '\0'; /* so we have a null char */
if (c != '`')
c = CTL(c); /* make a control char */
} else if (c == '`') {
c = ESC; /* for those used to escapes */
}
charbuf[cptr++] = c;
cptr &= NCHMASK;
nchars++;
}
private ZXchar
rawgetc()
{
static int cptr = 0;
ZXchar c;
if (EventCmd)
longjmp(auxjmp, 1);
while (nchars <= 0) {
nchars = 0;
if (EventCmd)
longjmp(auxjmp, 1);
CheckEvents(); /* ugh! WAIT for a character */
}
nchars--;
c = ZXRC(charbuf[cptr++]);
cptr &= NCHMASK; /* zero if necessary */
return c;
}
bool
rawchkc()
{
if (EventCmd)
longjmp(auxjmp, 1);
if (nchars == 0)
CheckEvents(); /* this should NOT be necessary! */
return nchars > 0;
}
/* Routines for calling the standard file dialogs, when macify is YES.
If the user changes the directory using the file dialogs, Jove's notion
of the current directory is updated. */
/* (ORIGINALLY IN) tmacf.c. K. Mitchum 12/86.
Macify routines for jove. */
int CurrentVol; /* see tfile.c */
#define TYPES (-1)
private Point px = {100, 100};
private unsigned char pmess[] = "\pSave file as: ";
private pascal Boolean
Ffilter(p)
ParmBlkPtr p;
{
Boolean r;
char *name;
if (p->fileParam.ioFlFndrInfo.fdType == 'APPL')
return YES;
/* Filter out our tempfiles.
* ??? the test doesn't check to see if the directories match.
*/
name = PtoCstr(p->fileParam.ioNamePtr);
r = strcmp(name, ".joveXXX") == 0
#ifdef ABBREV
|| strcmp(name, ".jabbXXX") == 0
#endif
#ifdef RECOVER
|| strcmp(name, ".jrecXXX") == 0
#endif
;
CtoPstr(name);
return r;
}
private void
check_dir()
{
if (cur_vol != 0 - SFSaveDisk || cur_dir != CurDirStore) {
char space[FILESIZE];
setdir(0 - SFSaveDisk, CurDirStore);
UpdModLine = YES; /* make sure jove knows the change */
Modechange = YES;
setCWD(getcwd(space, sizeof(space)));
}
}
char *
gfile(namebuf) /* return a filename to get */
char *namebuf;
{
SFReply frec;
char ans[FILESIZE];
SFSaveDisk = 0 - cur_vol; /* in case a Desk Accessory changed them */
CurDirStore = cur_dir;
SFGetFile(px, 0L, Ffilter, TYPES, 0L, 0L, &frec);
check_dir(); /* see if any change, set if so */
if (frec.good) {
EventRecord theEvent;
do; while (GetNextEvent(updateMask, &theEvent) == 0);
doUpdate(&theEvent);
strcpy(ans, PtoCstr(frec.fName));
CtoPstr((char *)frec.fName);
PathParse(ans, namebuf);
return namebuf;
}
return NULL;
}
char *
pfile(namebuf)
char *namebuf;
{
SFReply frec;
StringPtr nm;
SFSaveDisk = 0 - cur_vol; /* in case a Desk Accessory changed them */
CurDirStore = cur_dir;
strncpy(namebuf, filename(curbuf), FILESIZE-1);
nm = cvt_fnm(namebuf);
SFPutFile(px, pmess, nm, 0L, &frec);
check_dir(); /* see if any change, set if so */
if (frec.good) {
EventRecord theEvent;
char *h, *p;
do; while (GetNextEvent(updateMask, &theEvent) == 0);
doUpdate(&theEvent);
h = PtoCstr(frec.fName);
while (*h == ':')
h++; /* convert to unix style */
for (p = h; (p = strchr(p, ':')) != NULL; )
*p++ = '/';
PathParse(h, namebuf);
return namebuf;
}
return NULL;
}
/* getArgs() returns an argument list based on documents clicked on by the user. */
int
getArgs(avp)
char ***avp;
{
int argc, old_vol;
short nargs, type;
long old_dir;
char **argv;
char *pathname;
AppFile p;
WDPBRec d;
old_vol = cur_vol;
old_dir = cur_dir;
CountAppFiles(&type, &nargs);
if (nargs > 0) { /* files to open... */
argv = (char **) emalloc((nargs + 2) * sizeof(char *));
for (argc = 1; argc <= nargs; argc++) {
GetAppFiles(argc, &p);
if (type == 0) {
char space[FILESIZE];
PtoCstr((StringPtr)p.fName);
d.ioCompletion = 0;
d.ioNamePtr = NULL;
d.ioVRefNum = p.vRefNum;
d.ioWDIndex = 0;
PBGetWDInfo(&d, 0);
cur_vol = d.ioWDVRefNum;
cur_dir = d.ioWDDirID;
pathname = getcwd(space, sizeof(space));
argv[argc] = emalloc(strlen((char *)p.fName) + strlen(pathname) + 2);
strcpy(argv[argc], pathname);
strcat(argv[argc], "/");
strcat(argv[argc], (char *)p.fName);
}
ClrAppFiles(argc);
}
if (type != 0)
argc = 1;
} else {
argv = (char **) emalloc(2 * sizeof(char*));
argc = 1;
}
argv[0] = "jove";
argv[argc] = NULL;
*avp = argv;
cur_dir = old_dir;
cur_vol = old_vol;
return argc;
}
char *
mktemp(name)
char *name;
{
return name; /* what, me check? */
}
/* Menu routines. The menus items are set up in a similar manner as keys, and
are bound prior to runtime. See menumaps.txt, which must be run through
setmaps. Unlike keys, menu items may be bound to variables, and to
buffers. Buffer binding is only done at runtime. */
private void
InitMenu proto((struct menu *M)),
make_edits proto((int menu));
private void
InitLocalMenus()
{
int i;
for (i = 0; i < NMENUS; i++) {
InitMenu(&Menus[i]);
if (i == 0)
make_edits(Menus[i].menu_id + 1);
}
}
private void
InitMenu(M)
struct menu *M;
{
int i;
StringPtr ps;
if (M->menu_id == 0)
return;
M->Mn = NewMenu(M->menu_id, ps=CtoPstr(M->Name));
PtoCstr(ps);
for (i = 0; i < NMENUITEMS; i++) {
data_obj *d = M->m[i];
if (d == NULL)
break; /* last item... */
switch (d->Type & TYPEMASK) {
case STRING:
AppendMenu(M->Mn, ps=CtoPstr(d->Name));
PtoCstr(ps);
break;
case VARIABLE:
AppendMenu(M->Mn, ps=CtoPstr(d->Name));
PtoCstr(ps);
if ((((struct variable *)d)->v_flags & V_TYPEMASK) == V_BOOL
&& *(bool *)(((struct variable *)d)->v_value))
CheckItem(M->Mn, i + 1, YES);
break;
case COMMAND:
AppendMenu(M->Mn, ps=CtoPstr(d->Name));
PtoCstr(ps);
break;
}
}
InsertMenu(M->Mn, 0);
}
private void MacSetVar proto((struct variable *vp, int mnu, int itm));
private void
ProcMenu(menuno, itemno)
int menuno, itemno;
{
int i;
data_obj *d;
for (i = 0; i < NMENUS; i++) {
if (Menus[i].menu_id == menuno) {
itemno--;
d = Menus[i].m[itemno];
switch(d->Type & TYPEMASK) {
case COMMAND:
ExecCmd((data_obj *) d);
break;
case BUFFER:
SetABuf(curbuf);
tiewind(curwind, (Buffer *) d);
SetBuf((Buffer *) d);
break;
case VARIABLE:
MacSetVar((struct variable *) d, i, itemno);
break;
}
break;
}
}
}
private void
make_edits(menu) /* add dummy edit menu */
int menu;
{
MenuHandle M;
int item;
char *fname;
M = NewMenu((menu), "\pEdit");
AppendMenu(M,
"\pUndo/Z;(-;Cut/X;Copy/C;Paste/V;Clear;Select All;(-;Show Clipboard");
InsertMenu(M, 0);
DisableItem(M, 0);
}
void
menus_off()
{
int i;
if (Keyonly || EventCmd)
return;
#ifdef MENU_DISABLE /* NOBODY likes this, but it's here if you want it... */
DisableItem(SysMenu, 0);
for (i = 0; i < NMENUS; i++)
if (Menus[i].Mn)
DisableItem(Menus[i].Mn, 0);
DrawMenuBar();
#endif
Keyonly = YES;
}
void
menus_on()
{
int i;
if (!Keyonly)
return;
#ifdef MENU_DISABLE
EnableItem(SysMenu, 0);
for (i = 0; i < NMENUS; i++)
if (Menus[i].Mn)
EnableItem(Menus[i].Mn, 0);
DrawMenuBar();
#endif
Keyonly = NO;
}
private char *
BufMPrint(b, i)
Buffer *b;
int i;
{
char *p;
char *nm = filename(b);
char t[35];
if (strlen(nm) > 30) {
strcpy(t, "...");
strcat(t, nm + strlen(nm) - 30);
} else {
strcpy(t, nm);
}
nm = t;
while (*nm) {
switch(*nm) { /* ugh... these are metacharacter for Menus */
case '/':
*nm = ':';
break;
case '^':
case '!':
case '<':
case '(':
case ';':
*nm = '.';
break; /* that will confuse everybody */
}
nm++;
}
p = sprint("%-2d %-11s \"%-s\"", i, b->b_name, t);
return p;
}
private void
SetBufMenu()
{
Buffer *b;
int i, j, stop;
struct menu *M;
Bufchange = NO;
for (i = 0; i < NMENUS; i++) {
if (strcmp(Menus[i].Name, "Buffer") == 0) {
M = &Menus[i];
for (j = 0; j < NMENUITEMS; j++) {
data_obj *d = Menus[i].m[j];
if (d == NULL)
break;
if ((d->Type & TYPEMASK) == BUFFER) {
for (i = j, b = world; i < NMENUITEMS && b != NULL; i++, b = b->b_next) {
if (M->m[i] == NULL)
AppendMenu(M->Mn, CtoPstr(BufMPrint(b, i-j+1))); /* add the item */
else
SetItem(M->Mn, i + 1, CtoPstr(BufMPrint(b, i-j+1))); /* or change it */
M->m[i] = (data_obj *) b;
}
stop = i;
/* out of buffers? */
for (; i < NMENUITEMS && M->m[i]; i++) {
DelMenuItem(M->Mn, stop + 1); /* take off last item */
M->m[i] = NULL;
}
break;
}
}
break;
}
}
}
private void
MacSetVar(vp, mnu, itm) /* Set a variable from the menu */
struct variable *vp;
int mnu, itm;
{
if ((vp->v_flags & V_TYPEMASK) == V_BOOL) {
/* toggle the value */
*((bool *) vp->v_value) = !*((bool *) vp->v_value);
MarkVar(vp, mnu, itm);
} else {
char prompt[128];
swritef(prompt, sizeof(prompt), "Set %s: ", vp->Name);
vset_aux(vp, prompt);
}
}
private void
MarkModes()
{
int mnu, itm;
data_obj *d;
Modechange = NO;
for (mnu = 0; mnu < NMENUS; mnu++) {
for (itm = 0; itm < NMENUITEMS; itm++) {
if ((d = Menus[mnu].m[itm]) == NULL)
break;
if ((d->Type & (MAJOR_MODE | MINOR_MODE))
|| ((d->Type & TYPEMASK) == BUFFER))
{
bool checked;
if (d->Type & (MAJOR_MODE))
checked = curbuf->b_major == (d->Type >> 8);
else if (d->Type & (MINOR_MODE))
checked = (curbuf->b_minor & (d->Type >> 8)) != 0;
else
checked = d == (data_obj *) curbuf;
CheckItem(Menus[mnu].Mn, itm + 1, checked);
}
}
}
}
void
MarkVar(vp, mnu, itm) /* mark a boolean menu item */
const struct variable *vp;
int mnu, itm;
{
if (mnu == -1) { /* we don't know the item... slow */
for (mnu = 0; ; mnu++) {
if (mnu >= NMENUS)
return; /* not found */
for (itm = 0; (itm < NMENUITEMS); itm++) {
if ((struct variable *) (Menus[mnu].m[itm]) == vp)
break;
}
if (itm < NMENUITEMS)
break;
}
}
CheckItem(Menus[mnu].Mn, itm + 1, *(bool *)vp->v_value);
}
/* Screen routines and driver. The Macinitosh Text Edit routines are not utilized,
as they are slow and cumbersome for a terminal emulator. Instead, direct QuickDraw
calls are used. The fastest output is obtained writing a line at a time, rather
than on a character basis, so the major output routine is writechr(), which takes
a pascal-style string as an argument. See do_sputc() in screen.c. */
void
Placur(line, col)
int line, col;
{
CapCol = col;
CapLine = line;
putcurs(line, col, YES);
}
void
NPlacur(line, col)
int line, col;
{
CapCol = col;
CapLine = line;
putcurs(line, col, NO);
}
void
i_lines(top, bottom, num)
int top, bottom, num;
{
Placur(bottom - num + 1, 0);
dellines(num, bottom);
Placur(top, 0);
inslines(num, bottom);
}
void
d_lines(top, bottom, num)
int top, bottom, num;
{
Placur(top, 0);
dellines(num, bottom);
Placur(bottom + 1 - num, 0);
inslines(num, bottom);
}
/* (ORIGINALLY IN) tn.c */
/* window driver for MacIntosh using windows. */
/* K. Mitchum 9/86 */
/*#define VARFONT*/
#ifdef VARFONT
private height, width, theight, twidth, descent;
#else
# define height HEIGHT
# define width WIDTH
# define theight THEIGHT
# define twidth TWIDTH
# define descent DESCENT
#endif
private int trow, tcol;
private bool cursvis;
#ifdef NEVER
private bool insert;
#endif
private Rect cursor_rect;
private char *p_scr, *p_curs; /* physical screen and cursor */
private int p_size;
private Rect vRect;
private WindowRecord myWindowRec;
#define active() SetPort(theScreen)
#define maxadjust(r) OffsetRect((r), 0, 2)
private char *
conv_p_curs(row, col)
int row,
col;
{
return p_scr + (row * (CO)) + col;
}
#ifdef NEVER
private void
INSmode(new)
bool new;
{
insert = new;
}
#endif
void
SO_effect(new)
bool new;
{
theScreen->txMode = new? notSrcCopy : srcCopy;
}
private void init_slate proto((void));
private void
tn_init()
{
#ifdef NEVER
INSmode(NO);
#endif
init_slate();
SO_off();
ShowPen();
}
void
clr_page() /* clear and home function */
{
Rect r;
memset(p_scr, ' ', p_size);
active();
SetRect(&r, 0, 0, WINDWIDTH, WINDHEIGHT);
EraseRect(&r);
putcurs(0, 0, NO); /* ??? "NO" guess by DHR */
drawfluff();
}
private void
putcurs(row, col, vis)
unsigned row, col;
bool vis;
{
active();
curset(NO);
trow = row;
tcol = col;
curset(vis);
}
private void
curset(invert)
bool invert;
{
int
colpix = tcol * width,
rowpix = trow * height;
if (trow == MAXROW)
rowpix += 2; /* leave space for 2 pixel rule */
p_curs = conv_p_curs(trow, tcol);
MoveTo(colpix, rowpix + height - descent);
DrawChar(*p_curs);
cursvis = invert;
if (invert) {
SetRect(&cursor_rect, colpix, rowpix,
colpix + width - 1, rowpix + height - 1);
InvertRect(&cursor_rect);
}
MoveTo(colpix, rowpix + height - descent);
}
void
clr_eoln()
{
Rect r;
active();
SetRect(&r, tcol * width, trow * height, WINDWIDTH, (trow +1) * height);
if (trow == MAXROW)
maxadjust(&r);
EraseRect(&r);
memset(p_curs, ' ', CO - tcol);
curset(YES);
}
#ifdef NEVER
private void
delchars()
{
Rect r;
RgnHandle updateRgn;
active();
curset(NO);
updateRgn = NewRgn();
SetRect(&r, tcol * width, trow * height, twidth - width, (trow+1) * height);
if (trow == MAXROW)
maxadjust(&r);
ScrollRect(&r, -width, 0, updateRgn);
DisposeRgn(updateRgn);
BlockMove(p_curs + 1, p_curs, (long) (MAXCOL - tcol));
*conv_p_curs(trow, MAXCOL) = ' ';
curset(YES);
}
#endif /* NEVER */
private void
dellines(n, bot)
int n, bot;
{
RgnHandle updateRgn = NewRgn();
Rect r;
long len;
active();
curset(NO);
SetRect(&r, 0, ((trow) * height), WINDWIDTH, ((bot + 1) * height));
ScrollRect(&r, 0, 0 - (n * height), updateRgn);
DisposeRgn(updateRgn);
len = ((bot - trow - n + 1) * CO);
BlockMove(conv_p_curs(trow + n, 0), conv_p_curs(trow, 0), len);
memset(conv_p_curs(bot - n + 1, 0), ' ', n * CO);
putcurs(trow, 0, YES); /* ??? "YES" guess by DHR */
}
private void
inslines(n, bot)
int n, bot;
{
RgnHandle updateRgn = NewRgn();
Rect r;
long len;
active();
curset(NO);
SetRect(&r, 0, trow * height, WINDWIDTH, (bot +1) * height);
ScrollRect(&r, 0, (n * height), updateRgn);
DisposeRgn(updateRgn);
len = ((bot - trow - n +1) * CO);
BlockMove(conv_p_curs(trow, 0), conv_p_curs(trow + n, 0), len);
memset(conv_p_curs(trow, 0), ' ', (n * CO));
putcurs(trow, 0, YES); /* ??? "YES" guess by DHR */
}
void
writetext(str, len)
const unsigned char *str;
size_t len;
{
active();
curset(NO);
#ifdef NEVER
if (insert) {
RgnHandle updateRgn = NewRgn();
Rect r;
SetRect(&r, tcol * width, trow * height, twidth - width * len, (trow +1) * height -1);
if (trow == MAXROW)
maxadjust(&r);
ScrollRect(&r, width * len, 0, updateRgn);
DisposeRgn(updateRgn);
}
#endif
DrawText(str, (short)0, (short)len);
#ifdef NEVER
if (insert)
BlockMove(p_curs, p_curs + len, (long) (CO - tcol - len));
#endif
memcpy((UnivPtr)p_curs, (UnivPtr)str, len);
putcurs(trow, tcol+len <= MAXCOL? tcol+len : MAXCOL, YES); /* ??? "YES" guess by DHR */
}
private Rect myBoundsRect;
private void
init_slate()
{
FontInfo f;
char *Name = "Jove ";
char *Title;
InitGraf(&qd.thePort);
InitWindows();
InitCursor();
InitFonts();
InitMenus();
InitDialogs((ProcPtr)NULL); /* no restart proc */
/* figure limiting rectangle for window moves */
SetRect(&LimitRect,
qd.screenBits.bounds.left + 3,
qd.screenBits.bounds.top + 20,
qd.screenBits.bounds.right - 3,
qd.screenBits.bounds.bottom -3);
Set_std();
SetBounds();
/* initialize char array for updates */
p_scr = emalloc(p_size = wc_std.w_cols * wc_std.w_rows); /* only once */
p_curs = p_scr;
Title = sprint("%s%s", Name, jversion);
theScreen = NewWindow(&myWindowRec, &myBoundsRect, CtoPstr(Title),
1, 8, (WindowPtr) -1, 1, 0L);
/* figure an initial window configuration and adjust it */
wc = &wc_std;
wc_user = wc_std; /* initially, only one configuration to toggle */
user_state(theScreen) = std_state(theScreen);
SetPort(theScreen);
theScreen->txFont = FONT;
theScreen->txSize = TEXTSIZE;
#ifdef VARFONT
GetFontInfo(&f);
height = f.ascent+f.descent+f.leading;
width = f.widMax;
twidth = width * wc->w_cols;
theight = height * wc->w_rows;
descent = f.descent;
#endif
theScreen->txMode = srcCopy;
theScreen->pnMode = patCopy;
PenNormal();
}
private void
p_refresh()
{
int lineno;
for (lineno = 0; lineno < LI; lineno++) {
char *curs = conv_p_curs(lineno, 0);
MoveTo(0, (lineno+1) * height - descent + (lineno == MAXROW? 2 : 0));
/* The following kludgy line is to get SO right. It depends on:
* - !defined(HIGHLIGHTING)
* - this routine not being called at an inauspicious time
* i.e. in the middle of a SO output.
* - the fact that the last line will non-SO so that the text
* mode will be left non-SO.
*/
SO_effect(Screen[lineno].s_effects);
DrawText(curs, (short)0, (short)CO);
}
curset(cursvis);
}
private bool
wc_adjust(w, h, wcf, init) /* adjust window config to look nice */
int w, h;
struct wind_config *wcf;
int init;
{
static int LIMIT_R, LIMIT_C;
int rows, cols;
if (init) {
LIMIT_R = (h - 4) / HEIGHT;
LIMIT_C = (w - SCROLLWIDTH - 1) / WIDTH + 1;
}
if ((w < WIDTH * 40) ||(h < HEIGHT * 10) /* too small */
|| ((rows = (h - 4) / HEIGHT) > LIMIT_R) /* too big */
|| ((cols = (w - SCROLLWIDTH - 1) / WIDTH + 1) > LIMIT_C))
return NO;
wcf->w_rows = rows;
wcf->w_cols = cols;
wcf->w_width = wcf->w_cols * WIDTH + 1 + SCROLLWIDTH;
wcf->w_height = wcf->w_rows * HEIGHT + 4;
return YES;
}
private int
getCO() /* so that jove knows params */
{
return wc->w_cols;
}
private int
getLI()
{
return wc->w_rows;
}
void
ttsize()
{
/* ??? We really ought to wait until the screen is big enough:
* at least three lines high (one line each for buffer, mode,
* and message) and at least twelve columns wide (eight for
* line number, one for content, two for overflow indicators,
* and one blank at end).
*/
/* ??? This should be made more like UNIX version */
CO = getCO();
if (CO > MAXCOLS)
CO = MAXCOLS;
LI = getLI();
Windchange = YES;
clr_page();
ILI = LI - 1;
}
private void
SetBounds()
{
SetRect(&myBoundsRect,
qd.screenBits.bounds.left + 3,
qd.screenBits.bounds.top + 40,
qd.screenBits.bounds.left + 3 + wc_std.w_width,
qd.screenBits.bounds.top + 40 + wc_std.w_height);
}
private void
Set_std()
{
(void) wc_adjust(qd.screenBits.bounds.right - qd.screenBits.bounds.left - 6,
qd.screenBits.bounds.bottom - qd.screenBits.bounds.top - 42,
&wc_std, 1);
}
private void
Reset_std()
{
Set_std();
std_state(theScreen) = myBoundsRect;
}
#endif /* MAC */
|