1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976
|
#if(0)
FTANGLE v1.53.1.13, created with UNIX on "Thursday, January 2, 1997 at 0:57." \
COMMAND LINE: "Web/ftangle Web/common -A -# --F -= 1.60/Web/common.c"\
RUN TIME: "Wednesday, January 1, 1997 at 20:33."\
WEB FILE: "Web/common.web"\
CHANGE FILE: (none)
#endif
#define _COMMON_h
#define COMMON_FCNS_ \
#define VERSION "1.60-beta"/* For development, use |$REVISION| here. */
#define RELEASE_DATE "January 1, 1997" \
#define normal 0 /* ordinary identifiers have |normal| ilk */
#define roman 1 /* normal index entries have |roman| ilk */
#define wildcard 2 /* user-formatted index entries have |wildcard| ilk */
#define typewriter 3 /* `typewriter type' entries have |typewriter| ilk */ \
#define is_reserved(a)(a->ilk>typewriter)/* tells if a name is a reserved word */ \
#define append_xref(c)if(xref_ptr==xmem_end) \
OVERFLW("cross-references","r"); \
else \
{ \
(++xref_ptr)->num= c; \
xref_ptr->Language= (boolean)language; \
} \
#define def_flag 10240 /* must be strictly larger than |max_modules| */ \
#define xref equiv_or_xref /* The trouble with this is that |xref| is a \
|xref_pointer| whereas |equiv_or_xref| is |ASCII|. This means that \
lots of casting needs to be done to keep the compiler happy. Hence \
the previous |typedef|. */ \
#define app(a)*(tok_ptr++)= a /* Ordinary token */
#define APP_ID app(id_flag+PTR_DIFF(sixteen_bits,id_lookup(id_first,id_loc,normal),name_dir))
#define app1(a)app(tok_flag+PTR_DIFF(sixteen_bits,(a)->trans,tok_start))/* Store translation \
as token list; should translate to the following: */
#define trans trans_plus.Trans /* translation texts of scraps */
#define no_math 2
#define yes_math 1
#define maybe_math 0 \
#define id_flag 10240 /* Signifies an identifier. */
#define res_flag 2*id_flag /* Signifies a reserved word. */
#define mod_flag ((sixteen_bits)(3*(sixteen_bits)id_flag)) \
/* Signifies a module name. */
#define tok_flag ((sixteen_bits)(4*(sixteen_bits)id_flag))/* signifies a token list. */
#define inner_tok_flag ((sixteen_bits)(5*(sixteen_bits)id_flag)) \
/* Signifies a token list in `\Cb'. */ \
\
#define freeze_text *(++text_ptr)= tok_ptr \
#define cur_end cur_state.end_field /* Current ending location in |tok_mem|. */
#define cur_byte cur_state.byte_field /* Location of next output byte in |tok_mem|. */
#define cur_name cur_state.name_field /* Pointer to current name being expanded. */
#define cur_repl cur_state.repl_field /* Pointer to current replacement text. */
#define cur_mod cur_state.mod_field /* Current module number being expanded. */ \
#define cur_language cur_state.language /* Current language. */
#define cur_global_language cur_state.global_params.Language \
/* Global language for this level. */ \
\
/* Current flags. */
#define cur_params cur_state.params /* Local flags. */
#define cur_global_params cur_state.global_params /* Global flags. */ \
\
/* Current macro buffer params. */
#define macrobuf cur_state.macro_buf
#define cur_mp cur_state.mp
#define macrobuf_end cur_state.macro_buf_end \
#define STKLEN 20000U /* Borland needs this number; Microsoft requires it from \
the compiler line. */ \
#define first_text_char 0 /* Lowest interesting value of an |outer_char|. */
#define last_text_char 0377 /* Highest interesting value of an |outer_char|. */ \
#define TOO_LONG \
{ \
\
fatal(ERR_C,OC("Input line too long; "),OC("please use the `-ybs...' option to increase buffer size from \
its present value of %lu characters."),buf_size); \
} \
#define N_WORK 3
#define N_END (N_WORK+2) \
#define IS_POINT(c) \
(c=='!'&&(point_comments||(c1= getc(cur0_prms->File),ungetc(c1,cur0_prms->File),c1=='!'))) \
#define MARK(type,delim,len)mark_cmnt(type,delim,len,p) \
#define BLANK_OUT(d)MEMSET((d)->pos,040,(d)->len) \
#define is_C_style_cmnt (C_style_cmnt= ((short_cmnt= Cpp_comments&&*lp== \
057&&*(lp+1)==057))||(*lp==057&&*(lp+1)==052)) \
#define start_comment (is_C_style_cmnt||(*lp==(char)begin_comment0) \
||(*lp==(char)begin_comment1)) \
#define start_Rcomment ((R_style_cmnt= BOOLEAN(*lp==cmnt_char&& \
*(lp+1)!=cmnt_char&&*(lp-1)!=cmnt_char&& \
!(*(lp-1)==0100)))||is_C_style_cmnt) \
#define k0 cur0_prms->K0
#define found_at cur0_prms->Found_at
#define at_line cur0_prms->At_line \
#define LINES_DONT_MATCH (change_limit-change_buffer!=limit-cur_buffer|| \
STRNCMP(cur_buffer,change_buffer,PTR_DIFF(size_t,limit,cur_buffer))) \
#define change_params prms[incl_depth].input_params \
#define ABORT_ON_ERROR YES
#define DONT_ABORT_ON_ERROR NO \
#define FCLOSE(file_ptr)if(file_ptr!=stdin)fclose(file_ptr);file_ptr= NULL \
#define MAX_SIZE_T ((BUF_SIZE)(size_t)(~(0L)))/* Maximum argument to |calloc|. */ \
#define PTR_BASE "[%p,%p) "/* To style file? */ \
#define SHOW_MEM 0 /* Don't display by default. */ \
#define BP_MARKER 1 \
#define PROPER_END(end) \
end= (np+1)->byte_start; \
if(*end==BP_MARKER&&np!=npmax)end= ((BP*)end)->byte_start \
#define MAX_ID_LENGTH 32 /* Truncated identifiers can't be longer than this. */ \
#define hash_size 353 /* should be prime */ \
#define stringg (eight_bits)02 /* Extended ASCII alpha should not appear. (The funny \
spelling is to avoid conflict with the VAX' \.{stdlib}.) */
#define constant (eight_bits)03 /* Numerical constant. */
#define begin_Xmeta or_or
#define end_Xmeta star_star
#define cdir (eight_bits)06 /* Brackets compiler directive.. */
#define colon_colon (eight_bits)011 /* \Cpp\ and \Fortran--90: `$\WCF$'. */ \
#define join (eight_bits)0177 /* |ASCII| delete will not appear. */ \
#define ID0 0200 /* $128 =$ end of the 7-bit ASCII codes. */
#define TOKEN1(a)((a)<ID0)/* Is |a|~a single-byte token? */ \
#define MACRO_ARGUMENT 0377 /* See the related definition and discussion of \
|MOD0|. */
#define BASE2 0400 /* |0xFF + 1 = 0x100 = 256| */ \
#define MODULE_NAME 10240 /* |024000= 10240 = (0250-0200)*0400| */
#define MODULE_NUM 20480 /* |050000 = 20480 = (0320-0200)*0400| */
#define LINE_NUM 53248L /* |0150000==0320*0400| */ \
#define IDENTIFIER(left,right) \
((sixteen_bits)(((left)-ID0)*BASE2+(sixteen_bits)(right))) \
/* Construct two-byte token out of its constituents. */ \
#define LEFT(a,id)((eight_bits)(((a)/BASE2+(id))))/* Make left-hand byte out of \
|sixteen_bits|. */
#define RIGHT(a)((eight_bits)(((a)%BASE2)))/* Make right-hand byte. */ \
#define ignore 0 /* Control code of no interest to \.{TANGLE}. */ \
#define begin_comment0 (eight_bits)0376 /* Sent from |input_ln|; marker for long comment. */
#define begin_comment1 (eight_bits)0375 /* As above; marker for short comment. */ \
#define module_number (eight_bits)0201 /* Code returned by |get_output| for mod.\ numbers. */
#define identifier (eight_bits)0202 /* Code returned by |get_output| for identifiers. */
#define id_keyword (eight_bits)0203 /* As above, but for expandable keyword. */ \
#define L_switch (eight_bits)0257 /* Control code for `\.{@L}'. */
#define begin_FORTRAN (eight_bits)0260
#define begin_RATFOR (eight_bits)0261
#define begin_C (eight_bits)0262
#define begin_LITERAL (eight_bits)0263 \
#define verbatim (eight_bits)0264 /* Can't be~|02| as for \.{fweave}, because \
|stringg| is defined to be that. */ \
#define invisible_cmnt (eight_bits)0265 /* Control code for `\.{@\%}'. */
#define compiler_directive (eight_bits)0266 /* No longer used. */
#define Compiler_Directive (eight_bits)0267 /* Control code for `\.{@?}'. */
#define no_index (eight_bits)0300 /* Control code for `\.{@-}'. */
#define yes_index (eight_bits)0301 /* Control code for `\.{@+}'. */ \
#define ascii_constant (eight_bits)0302 /* Control code for `\.{@'}'. */
#define begin_vcmnt (eight_bits)0303 /* Control code for `\.{@\slashstar}'. */
#define big_line_break (eight_bits)0304 /* Control code for `\.{@\#}'. */ \
#define begin_bp (eight_bits)0305
#define insert_bp (eight_bits)0306 \
#define begin_meta (eight_bits)017 /* Control code for |"@("|. */
#define end_meta (eight_bits)027 \
#define TeX_string (eight_bits)0307
#define xref_roman (eight_bits)0310
#define xref_typewriter (eight_bits)0311
#define xref_wildcard (eight_bits)0312 \
#define control_text (eight_bits)0313 /* Control code for `\.{@t}', `\.{@\^}', etc. */ \
#define begin_nuweb (eight_bits)0314
#define no_mac_expand (eight_bits)0315 /* Control code for `\.{@\~}' */
#define set_line_info (eight_bits)0316 /* Expt'l control code for `\.{@Q}'. */ \
#define formatt (eight_bits)0320 /* Control code for `\.{@f}'. */ \
#define limbo_text (eight_bits)0323 /* Control code for `\.{@l}'. */
#define op_def (eight_bits)0324 /* Control code for `\.{@v}'. */
#define macro_def (eight_bits)0325 /* Control code for `\.{@W}'. */ \
#define ignore_defn (eight_bits)0327 /* Stuff to here should be ignored when scanning defn. */ \
#define new_output_file (eight_bits)0331 /* Control code for `\.{@o}'. */ \
#define definition (eight_bits)0332 /* Control code for `\.{@d}'. */
#define undefinition (eight_bits)0333 /* Control code for `\.{@u}'. */
#define WEB_definition (eight_bits)0334 /* Control code for `\.{@m}'. */ \
#define m_ifdef (eight_bits)0335
#define m_ifndef (eight_bits)0336
#define m_if (eight_bits)0337
#define m_else (eight_bits)0340
#define m_elif (eight_bits)0341
#define m_endif (eight_bits)0342
#define m_for (eight_bits)0343
#define m_endfor (eight_bits)0344
#define m_line (eight_bits)0345
#define m_undef (eight_bits)0346 \
#define end_of_buffer (eight_bits)0347 \
#define begin_code (eight_bits)0350 /* Control code for `\.{@a}'. */
#define module_name (eight_bits)0351 /* Control code for `\.{@<}'. */ \
#define new_module (eight_bits)0352 /* Control code for `\.{@\ }' and `\.{@*}'. */ \
#define MAX_ERR_BUF 160 \
#define WEAVE_LINE0 OC("{\"")
#define TANGLE_LINE0 OC(" COMMAND LINE: \"") \
#define WEAVE_LINE1 OC("\"} ")
#define TANGLE_LINE1 OC("\"") \
#define ESCAPE_LENGTH 256 \
#define MAX_INI_ARGS 100 /* Max \# of arguments in the ini file. */
#define T_SIZE 200 /* Buffer length for |fgets|. */
#define INI_CMNT_CHAR '%' \
#define BEFORE_CHAR '-'
#define MIDDLE_CHAR '0'
#define AFTER_CHAR '&' \
#define HOME OC("HOME")/* The Unix-standard name for the top-level directory. */
#define ENV_INI OC("FWEB_INI")/* Default root name to use. */
#define ENV_INCLUDES OC("FWEB_INCLUDES")/* The include path for \FWEB\ files. */
#define ENV_HDR_INCLUDES OC("FWEB_HDR_INCLUDES")/* \.{gcc -I} options. */ \
#define AUX_LEN 200
#define MAX_MOD_NAMES 3 /* No more than this many names in one error message. */ \
#define NMOD_TEMP 200 \
#define THE_FILE_NAME (a_file_name?pa:(outer_char HUGE*)"stdin") \
#define ARG_BUFFER_SIZE 500
#define COPY_TO_ARG_BUFFER(c)if(pa<arg_buffer_end)*pa++= c; \
else OVERFLW("arg buffer bytes","")
#define MAX_ARGS 100 \
#define STARTING_DO_NUM UL(90000L) \
#define NOT(flag)BOOLEAN((!flag)^not) \
#define G_RATIO 2.0
#define MIN_G_RATIO 0.0 /* This value definitively turns off the computed |goto|. */ \
#define MARGINAL_CASES 5L
#define MIN_MARGINAL_CASES 1 \
#define MAX_SPREAD UL(128L)
#define MIN_MAX_SPREAD 1 \
#define SPRM_LEN 1500 \
#define NEVER_USED 1
#define MULTIPLE_USES 2
#define ALL_WARNINGS (NEVER_USED|MULTIPLE_USES) \
#define LANGUAGE_SEPARATOR '='/* Separates language from file name. */ \
#define DFLT_FNAME_LENGTH 20 \
#define UPDATE_TERMINAL fflush(stdout)/* Empty the terminal output buffer. */ \
#define new_line putchar('\n')
#define putxchar putchar \
#define TIMING_PREC 10 /* Check that |cpu <= wall| by multiplying seconds by \
this number, then truncating. */ \
#ifndef part
#define part 0 /* Standard value, when the files aren't split. */
#else
#if(part != 1 && part != 2 && part != 3)
#define part 1 /* Should issue error message here. */
#endif
#endif /* |part| */
#if(part == 0 || part == 1)
#define part1_or_extern
#define SET1(stuff) = stuff
#define TSET1(stuff) = stuff
#else
#define part1_or_extern extern
#define SET1(stuff)
#define TSET1(stuff)
#endif
#include "typedefs.h"
#include "map.h"
#ifdef ibmpc /* \.{Machine-dependent}: For initializing the stack size. */
#ifdef borland
extern unsigned _stklen= STKLEN;
#endif
#endif
IN_COMMON ASCII xord[last_text_char+1];/* Converts input chars.\ to |ASCII|. */
#ifdef scramble_ASCII
ASCII xxord[last_text_char+1];/* For scrambling. */
#endif
IN_COMMON outer_char xchr[0200];/* Converts output chars.\ from |ASCII|. */
extern DOTS dots0[],mcmds[];/* These are put into \.{typedefs.web} so we can \
make use of the various \.{@d}s. */
IN_COMMON BUF_SIZE delta_dots;/* Expand the table in increments of this size. */
IN_COMMON BUF_SIZE ndots;/* The current total size. */
IN_COMMON DOTS HUGE*dots,HUGE*dots_end,HUGE*next_dot;/* The dynamic array. */
IN_COMMON BUF_SIZE buf_size;/* Holds input line. */
IN_COMMON ASCII HUGE*loc;
/* Points to the next character to be read from the buffer. */
typedef enum{START,END}DELIM_TYPE;
typedef enum{NO_CMNT,SHORT_CMNT,LONG_CMNT}CMNT_TYPE;
typedef struct
{
CMNT_TYPE type;
DELIM_TYPE delim;
eight_bits len;/* Length of the delimiter; either~$0$, $1$, or~$2$. */
ASCII HUGE*pos;/* Start of the delimiter. */
}CMNT_DATA;
IN_COMMON CMNT_DATA posns[50],HUGE*pcmnt CSET(posns);
IN_COMMON ASCII HUGE*pk;
IN_COMMON ASCII HUGE*lp,HUGE*semi_pos;
IN_COMMON boolean found_text,text,C_style_cmnt,short_cmnt,R_style_cmnt;
IN_COMMON ASCII HUGE*last_pos;
IN_COMMON ASCII cmnt_char;
IN_COMMON sixteen_bits module_count;/* The current module number. */
IN_COMMON BUF_SIZE max_modules;/* Greater than the total number of modules. */
IN_COMMON boolean HUGE*chngd_module;/* Dynamic array: Is the module changed? */
IN_COMMON boolean prn_where CSET(NO);
/* Tells \.{TANGLE} to print line and file info */
IN_COMMON boolean return_toggle CSET(NO);
/* Switch used for sending back an `\.{@i}' when |toggle_includes| \
is on. */
IN_COMMON boolean toggling CSET(NO);/* In the middle of a toggle include? */
IN_COMMON boolean popped CSET(NO);/* After popping the stack? */
IN_COMMON boolean no_more_input CSET(NO);
/* Temporary replacement for |input_has_ended|. */
IN_COMMON int tracing;/* For debugging \.{WEAVE}. */
/* Ideally, the following numbers should be large enough to handle both \
\FTANGLE\ and \FWEAVE. In the comments, we show some characteristic \
statistics. */
/* \.{Machine-dependent:} Machines with limited memory. */
#if SMALL_MEMORY
#define DFLT_BYTES 10000 /* \.{fweave fweave} $\approx$ 23,300. */
#define DFLT_BUF_SIZE 1500
#define DFLT_C_BUF_SIZE 200
#define DFLT_FMT_SIZE 200
#define DFLT_MSG_SIZE 1000
#define DFLT_DELTA_DOTS 20
#define DFLT_MAX_LBLS 20
#define DFLT_LINE_LENGTH 80
#define DFLT_LONGEST_NAME 1000
#define DFLT_MAX_EXPR_CHARS 500
#define DFLT_MAX_IFILES 10
#define DFLT_MAX_INCLUDE_DEPTH 10
#define DFLT_MAX_KEYWORDS 15
#define DFLT_MAX_MARGS 20
#define DFLT_MAX_MODULES 400
#define DFLT_MBUF_SIZE 32767
#define DFLT_MAX_NAMES 1000 /* \.{fweave fweave} $\approx$ 3,300. */
#define DFLT_MAX_REFS 2500 /* \.{fweave ftangle} $\approx$ 5,850. */
#define DFLT_SBUF_LEN 300
#define DFLT_STACK_SIZE_T 50
#define DFLT_STACK_SIZE_W 210 /* \.{fweave fweave} $\approx$ 200. */
#define DFLT_MAX_SCRAPS 1000 /* \.{fweave fweave} $\approx$ 900. */
#define DFLT_MAX_TOKS_T 50000L /* \.{ftangle fweave} $\approx$ 92,000. */
#define DFLT_MAX_TOKS_W 6000 /* \.{fweave fweave} $\approx$ 6,700. */
#define DFLT_MAX_DTOKS 2500
#define DFLT_MAX_TEXTS 2500 /* \.{fweave fweave} $\approx$ 4,500. */
#define DFLT_MAX_DTEXTS 100
#define DFLT_NUM_FILES 15
#define DFLT_OP_ENTRIES 147
#define DFLT_X_BUF_SIZE 80
#else /* Large limits. */
#define DFLT_BYTES 90000L
#define DFLT_BUF_SIZE 1500
#define DFLT_C_BUF_SIZE 255
#define DFLT_FMT_SIZE 500
#define DFLT_MSG_SIZE 2000
#define DFLT_DELTA_DOTS 20
#define DFLT_MAX_LBLS 20
#define DFLT_LINE_LENGTH 80
#define DFLT_LONGEST_NAME 10000
#define DFLT_MAX_EXPR_CHARS 500
#define DFLT_MAX_IFILES 100
#define DFLT_MAX_INCLUDE_DEPTH 10
#define DFLT_MAX_KEYWORDS 20
#define DFLT_MAX_MARGS 20
#define DFLT_MAX_MODULES 2000
#define DFLT_MBUF_SIZE 50000L
#define DFLT_MAX_NAMES 4000
#define DFLT_MAX_REFS 20000
#define DFLT_SBUF_LEN 300
#define DFLT_STACK_SIZE_T 50
#define DFLT_STACK_SIZE_W 400
#define DFLT_MAX_SCRAPS 10000
#define DFLT_MAX_TOKS_T 150000L
#define DFLT_MAX_TOKS_W 25000
#define DFLT_MAX_DTOKS 25000
#define DFLT_MAX_TEXTS 10239
#define DFLT_MAX_DTEXTS 500
#define DFLT_NUM_FILES 15
#define DFLT_OP_ENTRIES 157
#define DFLT_X_BUF_SIZE 80
#endif /* Limited memory. */
IN_COMMON name_pointer name_ptr;/* First unused position in |byte_start|. */
IN_COMMON ASCII HUGE*byte_ptr;/* First unused position in |byte_mem|. */
IN_COMMON ASCII HUGE*pformat,HUGE*pdefault,HUGE*pdata,
HUGE*pbp,HUGE*pinclude,HUGE*ppragma,HUGE*pcontains;
IN_COMMON outer_char outp_buf[MAX_OUTPUT_LINE_LENGTH];
/* FORTRAN's output buffer. */
IN_COMMON int nbuf_length CSET(72);
IN_COMMON outer_char wbprefix[MAX_FILE_NAME_LENGTH];
/* Possible directory prefix for the web file name. */
/* Signifies the end of a directory prefix. */
IN_COMMON outer_char prefix_end_char CSET(PREFIX_END_CHAR);
IN_COMMON boolean all_std CSET(NO);/* Do we route all output to |stdout|? */
IN_COMMON STMT_LBL max_stmt CSET(STARTING_DO_NUM);
IN_COMMON int not;/* For the negations of options. */
IN_COMMON double g_ratio CSET(G_RATIO);
IN_COMMON unsigned short marginal_cases CSET(MARGINAL_CASES);
IN_COMMON CASE_TYPE max_spread CSET(MAX_SPREAD);
IN_COMMON CONST char*day[]
#if(part == 0 || part == 1)
= {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
#endif /* |part == 1| */
;
IN_COMMON CONST char*month[]
#if(part == 0 || part == 1)
= {"January","February","March","April","May","June","July",
"August","September","October","November","December"}
#endif /* |part == 1| */
;
#if TIMING
IN_COMMON clock_t clock0;
IN_COMMON TIME_T time0;
#if NEW_DIFFTIME
double diff_time FCN((t1,t0))
TIME_T t1 C0("")
TIME_T t0 C1("")
{
#if HAVE_GETTIMEOFDAY
return(double)(t1.tv_sec-t0.tv_sec)
+1.0e-6*(double)(t1.tv_usec-t0.tv_usec);
#else
#if HAVE_SYS_TIMEB_H
return(double)t1.time-(double)t0.time
+1.0e-3*((double)t1.millitm-(double)t0.millitm);/* \
Without the casts, this line didn't work right on the DECstation. I think \
it has to do with the |unsigned short| type of |millitm|; a compiler bug \
with type promotion. */
#else
return t1-t0;
#endif /* |HAVE_SYS_TIMEB_H| */
#endif
}
#endif /* |NEW_DIFFTIME| */
#endif /* |TIMING| */
typedef struct xref_info0
{
sixteen_bits num;/* module number plus zero or |def_flag| */
struct xref_info0 HUGE*xlink;/* pointer to the previous \
cross-reference */
boolean Language;/* Language in force for this module. */
}xref_info;
typedef xref_info HUGE*xref_pointer;
typedef ASCII HUGE*XREF_POINTER;/* For assignments like |name_dir->xref = \
(XREF_POINTER)xref_ptr|. See the comment \
immediately below about~|xref|. */
typedef sixteen_bits Token;
typedef Token HUGE*token_pointer;
typedef token_pointer HUGE*text_pointer;
typedef struct
{
eight_bits cat;/* Category. It would be nice to |enum| this, but \
that would turn it into an |int|, which could be as much as four times \
bigger. */
eight_bits mathness;
union
{
text_pointer Trans;
}trans_plus;
}scrap;
typedef scrap HUGE*scrap_pointer;
typedef struct{
eight_bits HUGE*end_field;/* Ending location of replacement text. */
eight_bits HUGE*byte_field;/* Present location within replacement text. */
name_pointer name_field;/* |byte_start| index for text being output. */
text_pointer repl_field;/* |tok_start| index for text being output. */
sixteen_bits mod_field;/* Module number, or zero if not a module. */
PARAMS global_params,params;/* Various flags. */
eight_bits HUGE*macro_buf,HUGE*mp,HUGE*macro_buf_end;
/* Current macro buffer. */
}output_state;
typedef output_state HUGE*stack_pointer;
#if(0)
IN_COMMON boolean truncate_ids;/* Truncate identifers? */
IN_COMMON unsigned short tr_max[];/* Truncate to this length. */
IN_COMMON name_pointer npmax;/* |name_ptr - 1|. */
#endif
/* Back-pointer structure points back to the original name in |name_dir|. */
typedef struct Bp
{
ASCII c;/* Dummy byte that always remains~|BP_MARKER|. */
LANGUAGE Language;
CONST ASCII HUGE*byte_start,HUGE*byte_end;/* Points to original, \
untruncated name. */
struct Bp HUGE*next;/* Links to next back-pointer structure, in \
case a truncated name came from more than one original name. */
struct Trunc HUGE*Root;
}BP;
/* Info about a truncated identifier. */
typedef struct Trunc
{
boolean Language;/* All languages associated with this name. */
size_t num[NUM_LANGUAGES];
/* \# of instances of the truncated name. */
ASCII HUGE*id,HUGE*id_end;/* Truncated variable name. */
BP HUGE*first,HUGE*last;/* First and last back-pointer structures. */
struct Trunc HUGE*next;/* Next structure in truncated chain. */
}TRUNC;
typedef struct
{
outer_char*secno;/* The \LaTeX\ section number. */
sixteen_bits pageno,modno0;
boolean subpage_flag;/* |YES| if more than one section per page. */
}SECT_INFO;
IN_COMMON SECT_INFO HUGE*sect_info;
IN_COMMON outer_char HUGE*HUGE*mod_names;
IN_COMMON outer_char HUGE*HUGE*next_mod_name,HUGE*HUGE*last_mod_name;
IN_COMMON long start_line CSET(1);
/* Must be |long|; a negative value is used as a flag. */
IN_COMMON long end_line CSET(LONG_MAX);
IN_COMMON int stored_line_length;
IN_COMMON ASCII HUGE*stored_line;/* Allocated dynamically. */
IN_COMMON outer_char last_include_file[MAX_FILE_NAME_LENGTH]CSET(""),
this_include_file[MAX_FILE_NAME_LENGTH]CSET("");
/* The shorter length here is primarily to keep the stack under control. \
Now that |N_MSGBUF| is used dynamically, maybe this statement isn't \
necessary. */
#ifdef SMALL_MEMORY
#define N_MSGBUF 2000
#else
#define N_MSGBUF 10000
#endif
EXTERN boolean change_exists;/* has any module changed? */
#ifndef COMMON_FCNS_
IN_COMMON BUF_SIZE max_modules;/* Size allocated in \.{common.web}. */
#endif
EXTERN BUF_SIZE max_refs;
EXTERN xref_info HUGE*xmem;/* contains cross-reference information */
EXTERN xref_pointer xmem_end;
EXTERN xref_pointer xref_ptr;/* the largest occupied position in |xmem| */
EXTERN sixteen_bits xref_switch,mod_xref_switch;/* either zero or |def_flag|. */
EXTERN boolean defd_switch;/* Set by `\.{@[}'. */
EXTERN NAME_TYPE defd_type SET(NEVER_DEFINED);
EXTERN boolean typd_switch;/* Set by `\.{@]}'. */
EXTERN boolean index_short;/* Set by `\.{@+}'. */
EXTERN long max_toks;/* number of symbols in \cee\ texts being parsed; \
must be less than |@r 65536 == 2^16|. */
EXTERN Token HUGE*tok_mem;/* Dynamic array of tokens. */
EXTERN token_pointer tok_m_end;/* End of |tok_mem|. */
EXTERN long max_texts;/* number of phrases in \cee\ texts being parsed; \
must be less than |ID_FLAG|. */
EXTERN token_pointer HUGE*tok_start;/* Dynamic directory into |tok_mem|. */
EXTERN text_pointer tok_end;/* End of |tok_start|. */
EXTERN token_pointer tok_ptr;/* First unused position in |tok_mem|. */
EXTERN text_pointer text_ptr;/* First unused position in |tok_start|. */
EXTERN token_pointer mx_tok_ptr;/* Largest value of |tok_ptr|. */
EXTERN text_pointer mx_text_ptr;/* Largest value of |text_ptr|. */
EXTERN long max_scraps;/* Length of the next array. */
EXTERN scrap HUGE*scrp_info;/* Dynamic memory array for scraps */
EXTERN scrap_pointer scrp_end;/* end of |scrap_info|. */
EXTERN scrap_pointer pp;/* current position for reducing productions */
EXTERN scrap_pointer scrp_base;/* beginning of the current scrap sequence */
EXTERN scrap_pointer scrp_ptr;/* ending of the current scrap sequence */
EXTERN scrap_pointer lo_ptr;/* last scrap that has been examined */
EXTERN scrap_pointer hi_ptr;/* first scrap that has not been examined */
EXTERN scrap_pointer mx_scr_ptr;/* largest value assumed by |scrap_ptr| */
#ifndef COMMON_FCNS_
IN_COMMON int tracing;/* Can be used to show parsing details. */
#endif
EXTERN output_state cur_state;/* |cur_end|, |cur_byte|, |cur_name|, \
|cur_repl|, |cur_mod|, |cur_global_language|, and |cur_language|. */
EXTERN long stck_size;/* Number of simultaneous levels of macro expansion. */
EXTERN output_state HUGE*stack;/* Dynamic array: Info for non-current levels. */
EXTERN stack_pointer stck_end;/* End of |stack|. */
EXTERN stack_pointer stck_ptr;/* First unused loc.\ in the output state stack. */
IN_COMMON ASCII string_char;
IN_COMMON boolean in_char_string;
IN_COMMON INPUT_PARAMS change_params0
#if(part == 0 || part == 1)
= {FORTRAN,OUTER,NO}
#endif
;
IN_COMMON BUF_SIZE max_ifiles;
IN_COMMON outer_char**ifiles;/* Dynamic array of unique include file names. */
IN_COMMON int num_ifiles;/* Current number of include file names. */
IN_COMMON BUF_SIZE max_keywords;
IN_COMMON RCS HUGE*rcs;/* Dynamic array of RCS-like keywords. */
IN_COMMON unsigned num_keywords;/* Current number of RCS-like keywords. */
#ifndef C_TYPES
#include SFILE(y_type.h)
#endif /* |C_TYPES| */
IN_COMMON BUF_SIZE total_mem CSET(0);
/* Current total dynamically allocated memory. */
IN_COMMON BUF_SIZE max_mem CSET(0);/* The maximum bytes that were allocated. */
IN_COMMON boolean show_mem CSET(SHOW_MEM);
IN_COMMON BUF_SIZE show_size CSET(10000);/* Display for |nbytes >= show_size|. */
IN_COMMON MEM mem[]
#if(part == 0 || part == 1)
= {
{"b",1,
1000,DFLT_BYTES,ULONG_MAX},/* |"b"|. |max_bytes|: the \
number of bytes in identifiers, index entries, and module names. */
{"bs",1,
500,DFLT_BUF_SIZE,2000},/* |"bs"|. |change_buffer| etc. */
{"cb",1,
10,DFLT_C_BUF_SIZE,1000},/* |"cb"|. |C_buf_size|: see |C_putc|. */
{"cf",1,
100,DFLT_FMT_SIZE,UL(65536L)},/* |"cf"|.|cmd_fsize|: see |out_cmd|. */
{"cg",1,
100,DFLT_MSG_SIZE,UL(65536L)},/* |"cg"|. |cmd_size|: see |out_cmd| */
{"d",sizeof(DOTS),
20,DFLT_DELTA_DOTS,255},/* |"d"|. |delta_dots|: Number of \
additional entries to reallocate for |dots| if necessary. */
{"dt",sizeof(eight_bits),
1000,DFLT_MAX_DTOKS,ULONG_MAX},/* |"dt"|. |max_dtoks|. */
{"dx",sizeof(text),
100,DFLT_MAX_DTEXTS,10239},/* |"dx"|. |dtexts_max|. */
{"id",sizeof(INPUT_PRMS),
1,DFLT_MAX_INCLUDE_DEPTH,100},/* |"id"|. |prms| (open files). */
{"if",sizeof(outer_char*),
1,DFLT_MAX_IFILES,10000},/* |"if"|. |max_ifiles|. */
{"kt",sizeof(output_state),
10,DFLT_STACK_SIZE_T,100},/* |"kt"|. Tangle's |stck_size|. */
{"kw",sizeof(output_state),
50,DFLT_STACK_SIZE_W,1000},/* |"kw"|. Weave's |stck_size|. */
{"lb",sizeof(BEGUN),
5,DFLT_MAX_LBLS,255},/* |"lb"|. |max_lbls|. */
{"ll",1,
60,DFLT_LINE_LENGTH,255},/* |"ll"|. |line_length| for \
\FWEAVE's output. */
{"ln",1,
3*MAX_FILE_NAME_LENGTH,DFLT_LONGEST_NAME,UL(50000L)},
/* |"ln"|. |longest_name|: module names and strings shouldn't be longer \
than this. */
{"lx",1,
25,DFLT_MAX_EXPR_CHARS,UL(65536L)},/* |"lx"|. |max_expr_chars|. */
{"m",sizeof(boolean),
100,DFLT_MAX_MODULES,10239},/* |"m"|. |max_modules|: \
larger than the max number of modules. */
{"ma",sizeof(sixteen_bits),
1,DFLT_MAX_MARGS,255},/* |"ma"|. |max_margs|. */
{"mb",1,
5000,DFLT_MBUF_SIZE,ULONG_MAX},/* |"mb"|. |mbuf_size|. */
{"n",sizeof(NAME_INFO)+sizeof(name_pointer),
500,DFLT_MAX_NAMES,10239},/* |"n"|. |max_names|: \
number of identifiers, strings, module names; must be less than 10240. */
{"nf",sizeof(OPEN_FILE),
1,DFLT_NUM_FILES,256},/* |"nf"|. |num_files|. */
{"op",sizeof(OPERATOR),
142,DFLT_OP_ENTRIES,256},/* |"op"|. \
|op_entries| */
{"r",sizeof(xref_info),
500,DFLT_MAX_REFS,UL(65536L)},/* |"r"|. |max_refs|: number of \
cross-references; must be less than 65536. */
{"rk",sizeof(RCS),
11,DFLT_MAX_KEYWORDS,UL(65536L)},/* |"rk"|. |max_keywords|. */
{"s",sizeof(scrap),
1000,DFLT_MAX_SCRAPS,ULONG_MAX},/* |"s"|. |max_scraps|. */
{"sb",sizeof(outer_char),
100,DFLT_SBUF_LEN,ULONG_MAX},/* |"sb"|. |sbuf_len|. */
{"tt",sizeof(eight_bits),
10000,DFLT_MAX_TOKS_T,ULONG_MAX},/* |"tt"|. Tangle's \
|max_toks|: Total for the entire code; can be big. */
{"tw",sizeof(sixteen_bits),1000,
DFLT_MAX_TOKS_W,UL(65536L)},/* |"tw"|. Weave's |max_toks|: \
number of symbols in code texts being parsed; must be less than 65536. */
{"x",sizeof(text),
500,DFLT_MAX_TEXTS,10239},/* |"x"|. |max_texts|. */
{"xb",1,
10,DFLT_X_BUF_SIZE,1000},/* |"xb"|. |X_buf_size|: see |C_putc|. */
{"",0,0,0}
}
#endif /* |part == 1| */
;
IN_COMMON size_t sizeof_mem CSET(sizeof(mem));
IN_COMMON boolean info_option CSET(NO);
IN_COMMON boolean see_rsrvd CSET(NO);
IN_COMMON RSRVD rsrvd
#if(part == 0 || part == 1)
= {NULL,NO,NO,NO}
#endif /* |part == 1| */
;
IN_COMMON outer_char HUGE*style_args CSET(NULL);
IN_STYLE ASCII HUGE*at_codes;
IN_COMMON CONST char*origin_name[]
#if(part == 0 || part == 1)
= {"","COMMON","FTANGLE","FWEAVE","RATFOR","MACROS","STYLE"}
#endif /* |part == 1| */
;
IN_COMMON boolean found_web,found_change;/* Have these names been seen? */
IN_COMMON outer_char wbflnm0[MAX_FILE_NAME_LENGTH];
/* The root name of the web file. */
IN_COMMON outer_char
HUGE*ini_args[MAX_INI_ARGS],/* Arguments read from the ini file. */
HUGE*HUGE*new_args,/* The new list of all arguments; allocated \
dynamically. */
HUGE*HUGE*pn;/* Pointer to the current new argument being processed. */
IN_COMMON outer_char HUGE*HUGE*pn0;/* Marks end of ini args. */
IN_COMMON FILE*ini_file CSET(NULL);/* The ini file \.{.fweb}. */
IN_COMMON INCL_PATHS incl;
IN_COMMON INCL_PATHS hdr_incl;
IN_COMMON outer_char style_file_name[MAX_FILE_NAME_LENGTH]
CSET(STYLE_FILE_NAME);
IN_COMMON boolean renamed_style CSET(NO);
IN_COMMON boolean doing_cmd_line;/* Command line or optional arguments? */
IN_COMMON boolean cmd_prms;/* Stuff from ini file or from command line? */
IN_COMMON ASCII HUGE*fbuffer,HUGE*flimit,HUGE*floc;/* Saved position \
of current file. */
IN_COMMON BUF_SIZE starting_memory CSET(ULONG_MAX);
/* Set at first call to |mem_avail|. */
IN_COMMON outer_char*extra_args;
/* Extra arguments for preprocessor; used in conjunction with \.{-H}. */
IN_COMMON boolean mod_warning_flag CSET(ALL_WARNINGS);
/* For pc's, the file is split into two compilable parts using the \
compiler-line macro |part|, which must equal either~1 or~2. */
#if(part != 2)
SRTN
common_init(VOID)
{
IN_RATFOR SRTN is_Rat_present PROTO((VOID));
struct tm*t= the_localtime();/* Initialize the time. */
#if(TRANSLATE_ASCII || DEBUG_XCHR)
translate_ASCII= YES;/* Force it for the cases that really need it. */
#endif
banner();/* Start-up banner. */
is_Rat_present();/* Find out if the \Ratfor\ package was linked on. */
{
STRNCPY(xchr," !\"#$%&'()*+,-./0123456789\
:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ",
sizeof(xchr));
/* Interesting ``invisible'' things to output. */
xchr[tab_mark]= '\t';
xchr[012]= '\n';
/* nothing needs to be done */
;
{
int i;/* to invert the correspondence */
/* Initialize to |ASCII| blanks. */
for(i= first_text_char;i<=last_text_char;i++)
{
xord[i]= 040;
#ifdef scramble_ASCII
xxord[i]= 040;
#endif
}
/* The |NUL| and |DEL| characters are left alone! */
for(i= 1;i<0177;i++)
{
xord[(eight_bits)XCHR_[i]]= (ASCII)i;
#ifdef scramble_ASCII
xxord[(eight_bits)wt_style.xchr[i]]= i;
#endif
}
#ifdef scramble_ASCII
for(i= 0177;i<=0377;i++)
xxord[(eight_bits)wt_style.xchr[i]]= i;
#endif
#if(DEBUG_XCHR)
for(i= 0177;i<=0377;i++)
xord[(eight_bits)XCHR_[i]]= (ASCII)i;
#endif
}
;
}
{
int k;
for(k= 0;k<128;k++)
TeX[k]= TeX_other;
for(k= 0101;k<=0132;k++)
TeX[k]= TeX_letter;
for(k= 0141;k<=0172;k++)
TeX[k]= TeX_letter;
TeX[0134]= TeX_escape;
TeX[0173]= TeX_bgroup;
TeX[0175]= TeX_egroup;
TeX[044]= TeX_math_shift;
TeX[046]= TeX_alignment_tab;
TeX[012]= TeX_eol;
TeX[043]= TeX_parameter;
TeX[0136]= TeX_superscript;
TeX[0137]= TeX_subscript;
TeX[0]= TeX_ignored;
TeX[040]= TeX[tab_mark]= TeX_space;
TeX[0176]= TeX_active;
TeX[045]= TeX_comment;
TeX[0177]= TeX_invalid;
}
;
{
ALLOC(INPUT_PRMS,prms,"id",max_include_depth,1);
}
hash= GET_MEM("hash",hash_size,name_pointer);
hash_end= hash+hash_size-1;
for(h= hash;h<=hash_end;*h++= NULL);
pformat= x__to_ASCII(OC("format"));
pdata= x__to_ASCII(OC("data"));
pdefault= x__to_ASCII(OC("default"));
pbp= x__to_ASCII(OC("_BP"));
pinclude= x__to_ASCII(OC("include"));
ppragma= x__to_ASCII(OC("pragma"));
conv_bi(incl_likes);
conv_bi(WEB_incl_likes);
conv_bi(non_labels);
conv_dot(dots0);
conv_dot(mcmds);
SET_VAL(mbuf_size,"mb");
;
predefine_macros();/* Must be done before parsing the command line, so \
the user can undefine or override stuff if desired. */
{
params.uses= 0;/* For safety. */
#define FSET(flag) = flag
active_brackets FSET(ACTIVE_BRACKETS);/* Special array handling? */
all_cmnts_verbatim FSET(ALL_CMNTS_VERBATIM);/* Should \.{TANGLE} copy \
all comments? */
all_includes FSET(ALL_INCLUDES);/* Cross-reference all include files? */
auto_app_semi FSET(AUTO_APP_SEMI);/* For \.{WEAVE}, automatically \
append a pseudo-semi to the end of \.{WEB} macro definitions? */
auto_line FSET(AUTO_LINE);/* Auto-insert line nums after \.{@\%}? */
/* Append automatic semicolon? */
params.Auto_semi[LN(FORTRAN)]= YES;
params.Auto_semi[LN(FORTRAN_90)]
= params.Auto_semi[LN(RATFOR)]
= params.Auto_semi[LN(RATFOR_90)]
= params.Auto_semi[LN(C)]
= params.Auto_semi[LN(C_PLUS_PLUS)]
= params.Auto_semi[LN(LITERAL)]
= params.Auto_semi[LN(TEX)]
= NO;
params.Beeps FSET(BEEPS);
/* Do we label |do|s and |if|s with the block number? */
params.Block_nums[LN(C)]
= params.Block_nums[LN(C_PLUS_PLUS)]
= params.Block_nums[LN(LITERAL)]
= params.Block_nums[LN(TEX)]
= NO;
params.Block_nums[LN(FORTRAN)]
= params.Block_nums[LN(FORTRAN_90)]
= params.Block_nums[LN(RATFOR)]
= params.Block_nums[LN(RATFOR_90)]
= BLOCK_NUMS;
bslash_continued_strings FSET(BSLASH_CONTINUED_STRINGS);/* Do the \
continuations of strings require a starting backslash? */
chk_ifelse FSET(CHK_IFELSE);/* Protect parenthesized strings? */
chk_stmts FSET(CHK_STMTS);/* Check statement syntax in \Ratfor? */
compare_outfiles FSET(COMPARE_OUTFILES);/* Compare new vs.\ old output. */
compound_assignments FSET(COMPOUND_ASSIGNMENTS);/* Do we allow things \
like \.{+=}? */
Cpp FSET(NO);/* Do we recognize \.{C++}? */
dbg_output FSET(DBG_OUTPUT);/* Print output characters? */
deferred_macros FSET(DEFERRED_MACROS);/* Allow deferred macros? */
defn_mask.outer_macros FSET(PRN_OUTER_MACROS);
defn_mask.formats FSET(PRN_fORMATS);
defn_mask.Formats FSET(PRN_FORMATS);
defn_mask.limbo FSET(PRN_LIMBO);
defn_mask.macros FSET(PRN_MACROS);
defn_mask.v FSET(PRN_V);
defn_mask.w FSET(PRN_W);
dot_constants FSET(DOT_CONSTANTS);/* Recognize dot constants? */
params.CPP_comments[LN(C)]
= params.CPP_comments[LN(C_PLUS_PLUS)]
= params.CPP_comments[LN(LITERAL)]
= params.CPP_comments[LN(TEX)]
= CPP_COMMENTS;
/* For \Fortran\ and \Ratfor, the \.{//}~is preempted for concatenation. \
Therefore, its use for short comments must be turned on explicitly. */
params.CPP_comments[LN(FORTRAN)]
= params.CPP_comments[LN(FORTRAN_90)]
= params.CPP_comments[LN(RATFOR)]
= params.CPP_comments[LN(RATFOR_90)]
= NO;
Fortran88 FSET(FORTRAN88);/* Turn on stuff for Fortran-88? */
Fortran_label FSET(FORTRAN_LABEL);/* Label on same line? */
params.Free_form_input[LN(FORTRAN)]
= params.Free_form_input[LN(FORTRAN_90)]
= params.Free_form_input[LN(LITERAL)]
= params.Free_form_input[LN(TEX)]
= NO;
params.Free_form_input[LN(RATFOR)]
= params.Free_form_input[LN(RATFOR_90)]
= params.Free_form_input[LN(C)]
= params.Free_form_input[LN(C_PLUS_PLUS)]
= YES;
keep_trailing_comments FSET(KEEP_TRAILING_COMMENTS);/* For \TeX. */
params.In_escape[LN(FORTRAN)]
= params.In_escape[LN(FORTRAN_90)]
= '&';
params.In_escape[LN(RATFOR)]
= params.In_escape[LN(RATFOR_90)]
= params.In_escape[LN(C)]
= params.In_escape[LN(C_PLUS_PLUS)]
= params.In_escape[LN(LITERAL)]
= params.In_escape[LN(TEX)]
= '\\';
in_escape FSET(IN_ESCAPE);/* Default continuation character. */
index_hidden FSET(INDEX_HIDDEN);/* Index skipped includes files. */
index_one FSET(INDEX_ONE);/* Index single-character identifiers? */
input_macros FSET(INPUT_MACROS);/* Generate the default ``\.{\\input \
fwebmac.tx}'' line? */
lc_keywords FSET(LC_KEYWORDS);/* Lower-case \Fortran\ keywords? */
line_info FSET(LINE_INFO);/* Should \FTANGLE\ print out line info? */
lowercase_tokens FSET(LOWERCASE_TOKENS);/* Output lower-case tokens? */
m4 FSET(M4_);
makeindex FSET(MAKEINDEX);/* Output a \.{makeindex} file? */
no_xref FSET(NO_XREF);/* Should \.{WEAVE} print an index? */
number_dos FSET(NUMBER_DOS);
nuweb_mode FSET(NUWEB_MODE);/* Emulate \.{nuweb}? */
overload_ops FSET(OVERLOAD_OPS);/* Is operator overloading allowed? */
params.Point_comments[LN(C)]
= params.Point_comments[LN(C_PLUS_PLUS)]
= params.Point_comments[LN(TEX)]
= params.Point_comments[LN(LITERAL)]
= NO;
params.Point_comments[LN(FORTRAN)]
= params.Point_comments[LN(FORTRAN_90)]
= params.Point_comments[LN(RATFOR)]
= params.Point_comments[LN(RATFOR_90)]
= POINT_COMMENTS;/* Does \.! signify a Fortran comment? */
prn_contents FSET(PRN_CONTENTS);/* Print the table of contents? */
prn_index FSET(PRN_INDEX);/* Print the index? */
prn_input_lines FSET(NO);/* Used in |input_ln| to print out the \
lines sent back. */
prn_input_addresses FSET(NO);/* Print out the buffer addresses. */
prn_modules FSET(PRN_MODULES);/* Print the module list? */
prn_semis FSET(PRN_SEMIS);/* Print semicolons in \Fortran\ output? */
quoted_includes FSET(QUOTED_INCLUDES);
/* Cross-reference quoted include files? */
Ratfor77 FSET(RATFOR77);/* Expand \Ratfor\ code directly to \
\Fortran-77? */
read_iformats FSET(READ_IFORMATS);/* Read include files for formats. */
params.Reverse_indices[LN(C)]
= params.Reverse_indices[LN(C_PLUS_PLUS)]
= params.Reverse_indices[LN(TEX)]
= params.Reverse_indices[LN(LITERAL)]
= NO;
params.Reverse_indices[LN(FORTRAN)]
= params.Reverse_indices[LN(FORTRAN_90)]
= params.Reverse_indices[LN(RATFOR)]
= params.Reverse_indices[LN(RATFOR_90)]
= REVERSE_INDICES;/* C-style indexing in \Fortran? */
rmv_files FSET(RMV_FILES);/* Remove temporary files related to \.{-H}? */
skip_ifiles FSET(SKIP_IFILES);/* \.{-j} --- skip files already included. */
skip_includes FSET(SKIP_INCLUDES);/* For \.{WEAVE}, don't read in \.{@I} \
commands. (Uppercase '\.{I}' only.) */
statistics FSET(STATISTICS);/* Print statistics about memory usage? */
stop_the_scan FSET(YES);/* */
subscript_fcns FSET(YES);/* Module references on functions? */
suppress_cmds FSET(YES);/* ??? */
toggle_includes FSET(TOGGLE_INCLUDES);/* For \.{WEAVE}, read in \
\.{@I} commands, but don't print them out. */
top_version FSET(TOP_VERSION);/* Header info at top of output? */
translate_ASCII FSET(TRANSLATE_ASCII0);/* Do we bother with the \
|xchr|--|xord| conversions? */
translate_brackets FSET(TRANSLATE_BRACKETS);/* Do we translate \
brackets to parentheses in \Fortran? */
truncate_ids FSET(NO);/* Shorten identifiers? */
try_extensions FSET(TRY_EXTENSIONS);/* Try various file names. */
TeX_processor FSET(TEX_PROCESSOR);/* Default \TeX\ processor. */
xref_unnamed FSET(XREF_UNNAMED);/* Xref unnamed stuff. */
#undef FSET
#if(TRANSLATE_ASCII || DEBUG_XCHR)
translate_ASCII= YES;/* Force it for the cases that really need it. */
#endif
/* The following ensures that |ini_language| will work right. (It \
references |global_params|.) */
global_params= params;
}
{
{
int k;
/* We initialize the \It{local} name list; it's set to global later after \
everything else is set. */
new_fname(&tex_fname,NULL,NULL);
new_fname(&fwebmac,NULL,NULL);
for(k= 0;k<NUM_LANGUAGES;k++)
new_fname(params.outp_nm+k,NULL,NULL);
}
scan_args();
/* If there's no \WEB\ file, it must be an info option. */
if(found_web)
{
ini_input_prms(WEB_FILE,(outer_char HUGE*)"",ABORT_ON_ERROR);
/* Opens both input and change file. */
{
outer_char temp1[100],temp2[1000],
full_web_name[ESCAPE_LENGTH],esc_full_web_name[ESCAPE_LENGTH],
full_change_name[ESCAPE_LENGTH],esc_full_change_name[ESCAPE_LENGTH];
int n1,n2;
BUF_SIZE old_size;
/* Run time */
n1= program==tangle?
nsprintf(temp1,OC("\n RUN TIME: \"%s, %s at %s.\""),3,the_day(t),the_cdate(t),the_time(t))
:
nsprintf(temp1,OC(""),0);
#if(VMS)
fgetname(web_file,full_web_name);
fgetname(change_file,full_change_name);
#else
STRCPY(full_web_name,web_file_name);
STRCPY(full_change_name,change_file_name);
#endif /* |VMS| */
esc_file_name(esc_full_web_name,ESCAPE_LENGTH,full_web_name);
esc_file_name(esc_full_change_name,ESCAPE_LENGTH,full_change_name);
n2=
nsprintf(temp2,OC(program==tangle?
"\n WEB FILE: \"%s\"\n CHANGE FILE: %c%s%c":
" {\"%s\"} {%c%s%c} "),4,esc_full_web_name,*esc_full_change_name?'"':'(',*esc_full_change_name?esc_full_change_name:OC("none"),*esc_full_change_name?'"':')');
old_size= STRLEN(cmd_ln_buf)+1;
cmd_ln_buf= (outer_char HUGE*)REALLOC(cmd_ln_buf,old_size+n1+n2,old_size);
STRCAT(cmd_ln_buf,temp1);
STRCAT(cmd_ln_buf,temp2);
}
;
if(program==weave)open_tex_file();
}
/* In case no explicit language commands are given, either on the command \
line or in the file, before encountering the first module, pick a default. */
if(language==NO_LANGUAGE)
ini_language(XORD(*LANGUAGE_CODE(GLOBAL_LANGUAGE)));
global_params= params;/* Freeze the params after arguments have been read. */
}
;
/* The next two have to be done after reading the command line. */
{
DOTS HUGE*d;
ALLOC(DOTS,dots,"d",delta_dots,0);
ndots= delta_dots;/* Initialize total size. */
dots_end= dots+ndots;
next_dot= dots;/* Current pointer. */
/* Fill the table with the initial values. */
for(d= dots0;d->len!=0;d++)
{
if(dot_code(dots,d->symbol,d->symbol+d->len,d->code)!=d->code)
confusion(OC("dots allocation"),OC("Invalid dot code"));
}
}
{
BUF_SIZE cur_prms_units;
alloc(OC("id"),&cur_prms_units,0,-1);/* What is current allocation? */
if(cur_prms_units!=DFLT_MAX_INCLUDE_DEPTH)
prms= (INPUT_PRMS*)REALLOC(prms,
(cur_prms_units+1)*sizeof(INPUT_PRMS),
(DFLT_MAX_INCLUDE_DEPTH+1)*sizeof(INPUT_PRMS));
}
ALLOC(boolean,chngd_module,"m",max_modules,0);
{
ALLOC(outer_char*,ifiles,"if",max_ifiles,0);
}
{
ALLOC(RCS,rcs,"rk",max_keywords,0);
}
ALLOC(ASCII,byte_mem,"b",max_bytes,0);/* Characters of names. */
byte_end= byte_mem+max_bytes-1;/* End of |byte_mem|. */
ALLOC(NAME_INFO,name_dir,"n",max_names,0);
/* Information about names. */
name_end= name_dir+max_names-1;/* End of |name_dir|. */
ALLOC(ASCII,mod_text,"ln",longest_name,1);
mod_end= mod_text+longest_name;/* End of |mod_text|. */
ALLOC(SECT_INFO,sect_info,"m",max_modules,0);
{
if(program==tangle)
{
ALLOC(sixteen_bits,args,"ma",max_margs,1);
max_margs++;/* So the user thinks this is really the max \#. */
}
}
CAST(name_pointer,name_dir)->byte_start= byte_ptr= byte_mem;/* position zero \
in both arrays */
name_ptr= name_dir+1;/* |name_dir[0]| will not be used */
CAST(name_pointer,name_ptr)->byte_start= byte_mem;/* this makes name 0 of \
length zero */
root= NULL;
;
{
if(rsrvd.args)see_reserved(&rsrvd);
if(style_args)see_style(style_args,NO);
if(!found_web&&info_option&&!at_codes)
wrap_up();
}
more_includes(&incl,wt_style.Idir);
if(found_web)
read_aux();/* Process the \.{.aux} file. */
}
ASCII HUGE*
x__to_ASCII FCN((p0))
CONST outer_char HUGE*p0 C1("Character string to translate.")
{
if(translate_ASCII)
{
ASCII HUGE*buffer,HUGE*p;
CONST outer_char HUGE*q;
buffer= GET_MEM("x__to_ASCII arg",STRLEN(p0)+1,ASCII);
for(p= buffer,q= p0;*q;p++,q++)
*p= XORD(*q);
*p= '\0';
return buffer;
}
else
return(ASCII HUGE*)p0;
}
ASCII HUGE*
x_to_ASCII FCN((p0))
CONST outer_char HUGE*p0 C1("Character string to translate.")
{
static size_t bufsiz= 0;
static ASCII HUGE*buffer= NULL;
if(translate_ASCII)
{
ASCII HUGE*p;
CONST outer_char HUGE*q;
while(bufsiz<=STRLEN(p0)+1)
{
if(buffer==NULL)
buffer= GET_MEM("x_to_ASCII_buf",bufsiz= 32,ASCII);
/* Some systems don't like a |NULL| argument to |realloc|. */
else
{
buffer= (ASCII HUGE*)REALLOC(buffer,bufsiz+32,bufsiz);
bufsiz+= 32;
}
if(buffer==NULL)
fatal(ERR_C,OC("!! No more memory (x_to_ASCII)"),OC(""));
}
for(p= buffer,q= p0;*q;p++,q++)
*p= XORD(*q);
*p= '\0';
return buffer;
}
else
return(ASCII HUGE*)p0;
}
ASCII HUGE*
to_ASCII FCN((p0))
outer_char HUGE*p0 C1("Character string to translate.")
{
ASCII HUGE*p;
if(translate_ASCII)
for(p= (ASCII HUGE*)p0;*p;p++)*p= XORD(*p);
return(ASCII HUGE*)p0;
}
outer_char HUGE*
to_outer FCN((p0))
ASCII HUGE*p0 C1("Internal string to translate to outer world.")
{
outer_char HUGE*p;
if(translate_ASCII)
for(p= (outer_char HUGE*)p0;*p;p++)*p= XCHR(*(ASCII HUGE*)p);
return(outer_char HUGE*)p0;
}
boolean
is_include_like(VOID)
{
/* Check for \.{m4} built-in. */
if(m4&&is_in(incl_likes,id_first,id_loc))return YES;
/* The \.{WEB} functions behave as built-ins for \.{WEAVE}, but as macros \
for \.{TANGLE}. */
if(program==tangle)return NO;
if(!(*id_first==044||*id_first==0137))return NO;/* Speed up |is_in|. */
return is_in(WEB_incl_likes,id_first,id_loc);
}
SRTN conv_bi FCN((b))
BUILT_IN HUGE*b C1("")
{
for(;b->n!=0;b++)
b->name= x__to_ASCII((outer_char*)b->name);
}
SRTN
conv_dot FCN((d))
DOTS HUGE*d C1("")
{
for(;d->code!=0;d++)
d->symbol= x__to_ASCII((outer_char*)d->symbol);
}
boolean
is_in FCN((b0,p0,p1))
CONST BUILT_IN b0[]C0("Array of built-ins.")
CONST ASCII HUGE*p0 C0("Start of text.")
CONST ASCII HUGE*p1 C1("End of text.")
{
CONST BUILT_IN HUGE*b;
for(b= b0;b->n!=0;b++)
if(web_strcmp(b->name,b->name+b->n,p0,p1)==EQUAL)
return YES;
return NO;
}
ASCII HUGE*
uppercase FCN((p,n))
ASCII HUGE*p C0("Start of text.")
int n C1("Number of bytes to convert in place.")
{
int k;
for(k= 0;k<n;++k)
p[k]= A_TO_UPPER(p[k]);/* Convert $n$~bytes in place. */
return p;/* Return beginning address of string. */
}
boolean
is_dot(VOID)
{
ASCII HUGE*p;
int n;
ASCII temp[MAX_DOT_LENGTH];/* For converting the putative constant to \
upper case. */
/* Scan to the end of the dot constant (all of which are alphabetic). */
for(p= loc,n= 0;n<MAX_DOT_LENGTH;n++,p++)
if(*p==056||!isAlpha(*p))break;
if(*p!=056||p==loc)return NO;/* It wasn't stopped by a period, or \
the scan didn't even get started, so it \
can't be a dot constant. */
STRNCPY(temp,loc,n);
return BOOLEAN(CHOICE(dot_code(dots,uppercase(temp,n),temp+n,dot_const),
YES,NO));
}
eight_bits
dot_code FCN((d0,p0,p1,new_code))
DOTS HUGE*d0 C0("|DOTS| array.")
CONST ASCII HUGE*p0 C0("Start of text.")
CONST ASCII HUGE*p1 C0("End of text.")
eight_bits new_code C1("May we extend the table or not?")
{
DOTS HUGE*d;
re_dot:
for(d= d0;d<next_dot;d++)
if(web_strcmp(d->symbol,d->symbol+d->len,p0,p1)==EQUAL)
{
/* Check for an overloaded operator. If so, remember the details. */
if(d->code==dot_const)
{
STRCPY(dot_op.name+1,d->symbol);
dot_op.cat= d->cat;
dot_op.num= (eight_bits)(d-dots);
}
return d->code;
}
/* Didn't find the dot constant or operator in the table. Enlarge the table \
if necessary. */
if(!new_code)return NO;/* One can add to |dots|, but not |mcmds|. */
if(next_dot==dots_end)
{
if((dots= (DOTS HUGE*)REALLOC(dots,
(ndots+delta_dots)*sizeof(DOTS),ndots*sizeof(DOTS)))==NULL)
OVERFLW("dot operators","d");
next_dot= dots+ndots;/* Next available position. */
ndots+= delta_dots;/* New total length. */
dots_end= dots+ndots;/* Upper bound. */
}
/* Add operator to table. */
next_dot->len= PTR_DIFF(short,p1,p0);
next_dot->symbol= GET_MEM("next_dot->symbol",next_dot->len+1,ASCII);
STRNCPY(next_dot->symbol,p0,next_dot->len);
next_dot->code= new_code;/* Mark as overloaded, or initialize. */
next_dot->cat= 1;/* ??? */
d0= next_dot++;
next_dot->len= 0;
goto re_dot;
}
eight_bits
is_mcmd FCN((d0,p0,p1))
DOTS HUGE*d0 C0("|DOTS| array.")
CONST ASCII HUGE*p0 C0("Start of text.")
CONST ASCII HUGE*p1 C1("End of text.")
{
DOTS HUGE*d;
for(d= d0;d->code;d++)
if(web_strcmp(d->symbol,d->symbol+d->len,p0,p1)==EQUAL)
return d->code;
return 0;/* Not a preprocessor command. */
}
boolean
input_ln FCN((p0))
INPUT_PRMS0 HUGE*p0 C1("Which structure describes the current file?")
{
cur0_prms= p0;/* Address of current parameters. */
limit= cur_buffer;/* Initialize the top to the bottom. |limit| points to \
first unfilled position. */
cur_line++;/* A separate line count is kept for each file (including the \
change file). */
/* |column_mode| and |parsing_mode| may be redundant. But don't mess with \
these. */
if(!nuweb_mode&&FORTRAN_LIKE(language)&&column_mode&&parsing_mode==OUTER)
switch(language)
{
case FORTRAN:
case FORTRAN_90:
if(!rd_Fortran())
return NO;
break;
case RATFOR:
case RATFOR_90:
if(!rd_Ratfor())
return NO;
if(limit==cur_buffer)
goto empty_line;
break;
default:
confusion(OC("input_ln"),OC("Invalid FORTRAN_LIKE language %i"),language);
}
else
if(!rd_free_form())
return NO;
/* Take care of an empty line: kill the semicolon. (This is a bit shaky.) */
if(column_mode&&FORTRAN_LIKE(language)&&
PTR_DIFF(size_t,limit,cur_buffer)==2&&
((!auto_semi&&(cur_buffer[1]==073||cur_buffer[1]==040))||
(auto_semi&&cur_buffer[1]==073&&(cur_buffer[0]=='C'||
cur_buffer[0]==0143||cur_buffer[0]==052))))
empty_line:
limit= cur_buffer;
#if(DEBUG)
{
register ASCII HUGE*k;
if(prn_input_lines&&cur_line>=(LINE_NUMBER)start_line
&&cur_line<(LINE_NUMBER)end_line)
{
if(prn_input_addresses)
printf("%lu->%lu (%u) ",
(unsigned long)cur_buffer,(unsigned long)limit,
PTR_DIFF(unsigned,limit,cur_buffer));
printf("%c[%d%s:%u]: \"",
(language==global_language?' ':*LANGUAGE_CODE(language)),
incl_depth,
(changing?"*":""),
cur_line);
for(k= cur_buffer;k<limit;++k)
switch(*k)
{
case(ASCII)begin_comment0:
printf("</*>");
break;
case(ASCII)begin_comment1:
printf("<//>");
break;
case interior_semi:
printf("<;>");
break;
default:
putchar(XCHR(*k));
break;
}
puts("\"");
}
}
;
#endif
return YES;/* Successful read */
}
boolean
rd_free_form(VOID)
{
register int c= '\0';/* The character read. */
register ASCII HUGE*k;/* Where next character goes. */
{
if(num_in_buffer!=0)
{
STRNCPY(cur_buffer,k0,num_in_buffer);/* Move line to beginning of buffer. */
k0= cur_buffer;/* For |scan_for_cmnts| */
limit= cur_buffer+num_in_buffer-N_END;/* Reposition the end of buffer. */
num_in_buffer= 0;/* We've now cleaned out the buffer. */
}
else
{
if(feof(cur0_prms->File))
return NO;/* We have hit end-of-file. */
{
k= cur_buffer;/* beginning of buffer */
while(k<=buffer_end&&(c= getc(cur0_prms->File))!=EOF&&c!='\n')
if((*(k++)= XORD(c))!=040)limit= k;/* Update first unfilled \
position; |k|~is now pointing to next position to fill, and the last one \
wasn't blank. */
if(k>buffer_end)
if((c= getc(cur0_prms->File))!=EOF&&c!='\n')
{
ungetc(c,cur0_prms->File);loc= cur_buffer;TOO_LONG;
}
if(c==EOF&&limit==cur_buffer)
return NO;/* There was nothing after the last newline. */
}
;
}
}
return YES;
}
boolean
rd_Fortran(VOID)
{
register int c= '\0';/* The character read. */
register ASCII HUGE*k;/* Where next character goes. */
boolean first_line= YES;
/* We're starting afresh; initialize flags. */
last_was_continued= NO;
scanning_C_cmnt= NO;
string_char= '\0';
in_char_string= NO;
/* Keep reading lines until we sense a non-comment, non-continuation line. \
Leave the latter waiting in the buffer starting at~|k0|. */
for(k= limit;;k= k0= (limit+= N_END),first_line= NO,cur_line++)
if(num_in_buffer==0)
{
int i;
if(feof(cur0_prms->File))
{
if(first_line)return NO;/* We have hit end-of-file. */
else goto concatenate_cmnts;/* Don't lose the last line. */
}
k0= limit;/* Set the start of this line to the end of the old one. */
{
while(k<=buffer_end&&(c= getc(cur0_prms->File))!=EOF&&c!='\n')
if(c=='\t'&&k<=buffer_end-6)
for(i= 0;i<6;++i)*(k++)= 040;/* Translate tab \
character. (Don't update |limit|.) */
else
{
boolean escaped_char= NO;
outer_char c1;/* For looking ahead for \.{!!}. */
if(c==';')
c= XCHR(interior_semi);
else if(point_comments&&(*k0!=0100)&&
(escaped_char= BOOLEAN(c=='\\')))
{
c= getc(cur0_prms->File);/* What's coming up next? */
/* If it's not an escaped point, just copy the escape sequence. */
if(c!='!')
{
ungetc(c,cur0_prms->File);
c= '\\';
}
}
/* A point that's not escaped begins a short comment. */
if((*(k++)= CHOICE(IS_POINT(c)&&!escaped_char,
(ASCII)begin_comment1,XORD(c)))!=040)
limit= k;/* Ignore trailing blanks. */
}
if(k>buffer_end)
if((c= getc(cur0_prms->File))!=EOF&&c!='\n')
{
ungetc(c,cur0_prms->File);loc= cur_buffer;TOO_LONG;
}
if(c==EOF&&limit==cur_buffer)return NO;/* there was nothing after \
the last newline */
}
;/* |limit| is positioned after the last char.\ read. */
/* We will allow two extra characters at the end, in case we need to put \
end-of-comment markers there; we also need two bytes for Tangle's workspace. */
MEMSET(limit,040,N_END);
num_in_buffer= 0;/* There's nothing waiting. */
/* If we've read into a |new_module| command in column~1, \
prepare to switch out of column mode. */
at_line= BOOLEAN(*k0==0100&&*(k0+1)!=057);
if(at_line&&(*(k0+1)==052||*(k0+1)==040))found_at= YES;
/* If we were appending, then we must delay shifting out of column mode until \
we process the first part of the buffer. However, if we're actually at the \
beginning of the buffer, then we must shift out of column mode immediately. */
if(found_at&&k0==cur_buffer)goto out_of_column_mode;
if(first_line&&at_line)break;
/* Now we look at the line we just put into the buffer. Usually, we should \
look at that to see whether it's a continuation or a comment line, because if \
so we keep on reading. However, if it's a command line, or if we're in the \
middle of handling a trailing C~comment which didn't end on the previous \
line, then this line should not be treated in column mode. */
if(scanning_C_cmnt)
{
scan_for_cmnts();
continue;
}
if(!(at_line||scanning_C_cmnt))
{
boolean is_cmnt= NO,Fortran_cmnt= NO,C_cmnt= NO;
ASCII HUGE*p= k0;/* Points to the comment character. */
/* Did we get a comment line? */
switch(*k0)
{
case 0103:
case 0143:
case 052:
case(ASCII)begin_comment0:
case(ASCII)begin_comment1:
is_cmnt= Fortran_cmnt= YES;
break;
default:
/* Skip over white space at beginning of line. */
for(;p<limit;p++)if(*p!=040)break;
if((*p==057&&(*(p+1)==052
||(*(p+1)==057&&Cpp_comments)))
||*p==(ASCII)begin_comment0
||*p==(ASCII)begin_comment1)is_cmnt= C_cmnt= YES;
break;
}
if(is_cmnt)
{
if(limit==k0+1)
{/* Null comment line. */
limit= k0;
if(!first_line)goto last_of_read;
else goto concatenate_cmnts;
}
if(k0>cur_buffer)MEMSET(k0-N_END,040,N_END);
if(Fortran_cmnt)*p= begin_comment1;
/* If the last line was empty, we don't want to read any further; leave this \
comment waiting in the buffer. */
if(last_was_empty)
{
num_in_buffer= PTR_DIFF(size_t,limit,k0)+N_END;
comment_in_buffer= YES;
limit= cur_buffer;
break;/* Break out of the |for| loop which reads lines. */
}
scan_for_cmnts();
continue;/* Go back and read more lines. */
}
/* If we're this far, it's not a comment. Check for continuation line \
(neither blank nor |'0'| in column~6). If \
so, shift it over to abut it with previous stuff in buffer. */
if(limit-k0>=5&&!(k0[5]==040||k0[5]==060))
{
register ASCII HUGE*l;
boolean stuff_in_1_5;
if(first_line)
{/* Error: Continuation line not expected. */
scan_for_cmnts();
continue;
}
/* We don't allow anything in columns 1--5 for a continuation line. That's \
a FORTRAN rule, and it helps us to catch a possible continuation of a \
C-style comment. */
stuff_in_1_5= NO;
for(l= k0;l<k0+5;++l)
if(*l!=040)
{
stuff_in_1_5= YES;
break;
}
/* If there's stuff in columns 1--5, it's not a continuation line. \
Otherwise, it's a continuation line; abut it with the code in the previous \
line. */
if(stuff_in_1_5)goto neither_cmnt_nor_continuation;
*l= 040;/* Delete the continuation symbol. */
scan_for_cmnts();
continue;/* Keep on reading. */
}
}
/* If we get to here, it's neither a comment nor a continuation. If this line \
was the first in the buffer, we must continue to read more. (However, \
if this line is null, then we do not read any more, because we don't want to \
concatenate a null comment to the previous line.) Otherwise, we're \
done reading and we should leave this line waiting in the buffer. */
neither_cmnt_nor_continuation:
if(first_line)
if(limit==cur_buffer)/* Quit on null first line. */
{
comment_in_buffer= NO;
num_in_buffer= 0;
break;
}
else
{
scan_for_cmnts();
continue;/* We must read some more to see if next is \
continuation. */
}
{
last_of_read:
if(!first_line)
{
num_in_buffer= PTR_DIFF(size_t,limit,k0)+N_END;
limit= MAX(k0-N_WORK,cur_buffer);
}
else limit+= N_WORK;
concatenate_cmnts:
anlz_cmnts();/* Concatenate comments appropriately, and set |scanning_C_cmnt|. */
cur_line--;
break;/* Break out of |for| loop. */
}
;
}
else
{
{
STRNCPY(cur_buffer,k0,num_in_buffer);/* Move line to beginning of buffer. */
k0= cur_buffer;/* For |scan_for_cmnts| */
limit= cur_buffer+num_in_buffer-N_END;/* Reposition the end of buffer. */
num_in_buffer= 0;/* We've now cleaned out the buffer. */
}
;
/* If what was waiting was a control line, we must shift out of column mode. */
if(found_at)
{
out_of_column_mode:
found_at= column_mode= last_was_empty= NO;
break;/* Break out of |for| loop which reads lines. The finish-read \
material is moot. */
}
if(at_line)
{
last_was_empty= NO;
break;
}
/* Finally, we give special treatment to empty lines. */
last_was_empty= BOOLEAN(limit==cur_buffer);
scan_for_cmnts();
}/* Go back to the |for| loop which reads lines. */
/* Except for new module, throw away all stuff after \.{@}~command in \
column~1. */
if(*cur_buffer==0100&&!(limit==cur_buffer+1||*(cur_buffer+1)==052||
*(cur_buffer+1)==040))
for(k= cur_buffer+2;k<limit;++k)
if(*k==073)
{
*k= 040;
break;
}
return YES;
}
SRTN
mark_cmnt FCN((type0,delim0,length0,pos0))
CMNT_TYPE type0 C0("")
DELIM_TYPE delim0 C0("")
eight_bits length0 C0("")
ASCII HUGE*pos0 C1("")
{
pcmnt->type= type0;
pcmnt->delim= delim0;
pcmnt->len= length0;
pcmnt->pos= pos0;
if(type0==LONG_CMNT)
scanning_C_cmnt= BOOLEAN(delim0==START);
pcmnt++;
pcmnt->type= NO_CMNT;
pcmnt->delim= START;
pcmnt->len= 0;
pcmnt->pos= limit;
}
SRTN
scan_for_cmnts(VOID)
{
register ASCII HUGE*p;
for(p= k0;p<limit;p++)
switch(*p)
{
case(ASCII)begin_comment0:
if(scanning_C_cmnt)
break;
MARK(LONG_CMNT,START,1);
break;
case(ASCII)begin_comment1:
if(scanning_C_cmnt)
break;
MARK(SHORT_CMNT,START,1);
p= limit;
MARK(SHORT_CMNT,END,0);
break;
case 047:
case 042:
if(!scanning_C_cmnt)
{
if(!in_char_string)
{
in_char_string= YES;
string_char= *p;
break;
}
if(string_char==*p&&p[1]==string_char)
{
p++;
break;
}
in_char_string= NO;
}
break;
case 057:
if(in_char_string||scanning_C_cmnt)
break;
if(*(p+1)==057&&Cpp_comments)
{
MARK(SHORT_CMNT,START,2);
p= limit;
MARK(SHORT_CMNT,END,0);
}
else if(*(p+1)==052)
{
MARK(LONG_CMNT,START,2);
p++;
}
break;
case 052:
if(in_char_string)
break;
if(scanning_C_cmnt&&*(p+1)==057)
{
MARK(LONG_CMNT,END,2);
p++;
}
break;
}
}
SRTN
anlz_cmnts(VOID)
{
CMNT_DATA*d;
boolean found_text= NO;
ASCII HUGE*l;
pcmnt->pos= limit;
for(d= posns+1;d<pcmnt;d+= 2)
{
found_text= NO;
for(l= d->pos+d->len;l<(d+1)->pos;l++)
if(*l!=040)
{
found_text= YES;
break;
}
if(found_text)
{
if(d->type==SHORT_CMNT)
{
BLANK_OUT(d-1);
*((d-1)->pos)= begin_comment0;
*(d->pos)= 052;
*(d->pos+1)= 057;
}
}
else if(d->type==(d+1)->type)
{
BLANK_OUT(d);
BLANK_OUT(d+1);
d->type= (d+1)->type= NO_CMNT;
}
}
{
boolean text_after= NO;
if(pcmnt>posns)
{/* There's at least one comment. */
if(!scanning_C_cmnt)
for(l= limit-1;l>(pcmnt-1)->pos+(pcmnt-1)->len;l--)
if(*l!=040)
{/* There's text after the comment. */
text_after= YES;
*(l+1)= 073;
break;
}
if(!text_after)
{
pcmnt-= 2;
if(pcmnt<posns)
{
err0_print(ERR_C,OC("Fortran comment didn't end; missing */?"),0);
pcmnt= posns;
}
while(pcmnt->type==NO_CMNT)
{
pcmnt--;
if(pcmnt<posns)
confusion(OC("Insert an automatic semicolon"),OC("Invalid comment structure"));
}
while(pcmnt>=posns)
{
ASCII HUGE*lmin;
if(pcmnt==posns)
lmin= cur_buffer;
else
lmin= (pcmnt-1)->pos+(pcmnt-1)->len;
for(l= pcmnt->pos-1;l>=lmin;l--)
{
if(*l!=040)
{/* There's text before the comment. */
semi_pos= pcmnt->pos;
{
*(semi_pos+1)= (ASCII)(((pcmnt+1)->type==LONG_CMNT?begin_comment0:
begin_comment1));/* If the comment was started by \
|begin_comment0| or |begin_comment1|, this overwrites the character \
after that. (We \
have to make room for the semicolon.) If we want to cure this, we \
must do more copying. */
if(semi_pos>cur_buffer&&*(semi_pos-1)==0100)/* A verbatim comment. */
{
*(semi_pos--)= 0100;
}
*semi_pos= 073;/* This overwrites the beginning of the comment marker, \
or the previous~\.{@} if there was one. */
for(lp= semi_pos-1;lp>cur_buffer;lp--)
{
if(*lp==040)continue;
if(*lp==057&&*(--lp)==0100)
{
*semi_pos= 040;
*lp= 073;*(lp+1)= 0100;*(lp+2)= 057;
}
break;
}
;
}
goto done_auto_insert;
}
}
pcmnt-= 2;
}
}
}
else
{/* No comments at all. */
for(l= limit-1;l>=cur_buffer;l--)
if(*l!=040)
{
*(l+1)= 073;
break;
}
}
done_auto_insert:
;
}
pcmnt= posns;/* Reset. */
}
boolean
rd_Ratfor(VOID)
{
register int c= '\0';/* The character read. */
register ASCII HUGE*k;/* Where next character goes. */
boolean found_semi;
string_char= '\0';
in_char_string= NO;
{
if(num_in_buffer!=0)
{
STRNCPY(cur_buffer,k0,num_in_buffer);/* Move line to beginning of buffer. */
k0= cur_buffer;/* For |scan_for_cmnts| */
limit= cur_buffer+num_in_buffer-N_END;/* Reposition the end of buffer. */
num_in_buffer= 0;/* We've now cleaned out the buffer. */
}
else
{
if(feof(cur0_prms->File))
return NO;/* We have hit end-of-file. */
{
k= cur_buffer;/* beginning of buffer */
while(k<=buffer_end&&(c= getc(cur0_prms->File))!=EOF&&c!='\n')
if((*(k++)= XORD(c))!=040)limit= k;/* Update first unfilled \
position; |k|~is now pointing to next position to fill, and the last one \
wasn't blank. */
if(k>buffer_end)
if((c= getc(cur0_prms->File))!=EOF&&c!='\n')
{
ungetc(c,cur0_prms->File);loc= cur_buffer;TOO_LONG;
}
if(c==EOF&&limit==cur_buffer)
return NO;/* There was nothing after the last newline. */
}
;
}
}
/* If we've read into a |new_module| command in column~1, \
switch out of column mode. */
if(*cur_buffer==0100&&(limit==cur_buffer+1
||*(cur_buffer+1)==052||*(cur_buffer+1)==040))
column_mode= NO;
else
{
last_was_continued= continuing_line;
continuing_line= NO;
if(limit==cur_buffer)
return YES;
limit[0]= limit[1]= limit[2]= limit[3]= 040;
cmnt_char= 043;
found_semi= found_text= text= NO;/* Start off assuming we're in comment \
mode. */
semi_pos= NULL;/* |semi_pos| will record the position of a prospective \
comment, to be begun by a semicolon. */
/* Scan the line. */
if(!free_form_input&&!(*cur_buffer==0100&&*(cur_buffer+1)==043))
{
for(lp= cur_buffer;;)
if(!skip_Rtext()||!skp_cmnt())break;
switch(*last_pos)
{
case 053:case 055:case 052:case 075:case 0173:case 0175:
case 0136:case 046:case 0174:case 050:case 072:
case 076:case 074:case 0133:case 054:case 0134:
continuing_line= YES;
break;/* Line is continued. */
/* Ratfor's continuation character. */
case 0137:
if(last_pos>cur_buffer)
{
ASCII c;
c= *(last_pos-1);
if(isAlpha(c)||isDigit(c)||
c==0137||c==044)
goto not_continuation;
}
*last_pos= 040;
continuing_line= YES;
break;
default:
not_continuation:
if(!auto_semi)break;
/* If the last construction is a comment (|!text|) and there was actually \
some text (|semi_pos!=NULL|), \
replace ``\.{\slashstar}'' by |';'| and |begin_comment0| or \
|begin_comment1|. */
if(!text&&semi_pos!=NULL)
{
*(semi_pos+1)= (ASCII)(((pcmnt+1)->type==LONG_CMNT?begin_comment0:
begin_comment1));/* If the comment was started by \
|begin_comment0| or |begin_comment1|, this overwrites the character \
after that. (We \
have to make room for the semicolon.) If we want to cure this, we \
must do more copying. */
if(semi_pos>cur_buffer&&*(semi_pos-1)==0100)/* A verbatim comment. */
{
*(semi_pos--)= 0100;
}
*semi_pos= 073;/* This overwrites the beginning of the comment marker, \
or the previous~\.{@} if there was one. */
for(lp= semi_pos-1;lp>cur_buffer;lp--)
{
if(*lp==040)continue;
if(*lp==057&&*(--lp)==0100)
{
*semi_pos= 040;
*lp= 073;*(lp+1)= 0100;*(lp+2)= 057;
}
break;
}
;
}
else if(found_text&&limit>cur_buffer)*limit++= 073;
/* Line ended. */
break;
}
}
}
;
return YES;
}
boolean skip_Rtext(VOID)
{
static ASCII blank= 040;
if(scanning_C_cmnt)return YES;/* Make sure |skp_cmnt| is the first to be \
executed. */
/* Start scanning at the current position. Skip over white space. */
for(;lp<limit;++lp)
if(!(*lp==040||*lp==tab_mark))break;
if(lp>=limit)return NO;/* The line was all white space. */
;
last_pos= ␣
/* If we haven't found a comment, set mode to text. */
if(!start_Rcomment)
{
found_text= text= YES;
}
/* Scan to a comment. */
for(;lp<limit;lp++)
{
if(start_Rcomment)
{
if(R_style_cmnt)
{
*lp= cmnt_char= begin_comment0;
*limit++= 052;*limit++= 057;
}
if(++lp<limit)return YES;
}
if(*lp!=040&&*lp!=tab_mark)
last_pos= lp;/* Remember last non-blank position. */
}
return NO;
}
boolean skp_cmnt(VOID)
{
/* If the last mode was text, remember the position for a possible semi. */
if(text)semi_pos= lp-1;
text= NO;/* We're in comment mode. */
scanning_C_cmnt= NO;/* Flag used to handle the next line properly if the \
comment runs over. */
/* Scan to end of comment. */
if(C_style_cmnt)
{
if(short_cmnt)
{
lp= limit;
return YES;
}
for(++lp;lp<limit;lp++)
{
if(*lp==(ASCII)begin_comment0||*lp==(ASCII)begin_comment1)
{
*lp= 0143;
continue;
}
if(*lp==052&&*(lp+1)==057)
{
lp+= 2;/* Position after end of comment. */
if(lp<=limit)return YES;
}
}
scanning_C_cmnt= YES;
}
else
{
for(++lp;lp<limit;lp++)
if(*lp==(ASCII)begin_comment1)
*lp= 041;
*(limit-2)= 052;*(limit-1)= 057;
}
return NO;
}
SRTN
prime_the_change_buffer(VOID)
{
INPUT_PARAMS input_params;/* Saves incoming state. */
input_params.Language= language;
input_params.Parsing_mode= parsing_mode;
input_params.Column_mode= column_mode;
language= change_params.Language;
parsing_mode= change_params.Parsing_mode;
column_mode= change_params.Column_mode;
change_limit= NULL;/* This value will be used if the change file ends. */
WHILE()
{
ASCII c;
if(!input_ln(CHANGE_FILE))
{
change_limit= NULL;
goto done_priming;
}
if(limit<cur_buffer+2)continue;
/* There can't be an \.{@}~command. */
if(cur_buffer[0]!=0100)continue;
/* Skip lines that don't start with~\.{@}. */
if((cur_buffer[1]>=0130&&cur_buffer[1]<=0132)||cur_buffer[1]==0111)
cur_buffer[1]+= 0172-0132;
;
if(cur_buffer[1]==0151)
{
loc= cur_buffer+2;
err0_print(ERR_C,OC("Sorry, no includes allowed in change file"),0);
}
;
if((c= cur_buffer[1])==0170)break;/* Found beginning of a change. */
if(c==0171||c==0172)
{
loc= cur_buffer+2;/* Skip erroneous change. */
err0_print(ERR_C,OC("Where is the matching @x?"),0);
}
else
{
if(c==0154)
if(limit==cur_buffer+2)
err0_print(ERR_C,OC("Missing language character after @L"),0);
else c= cur_buffer[2];
switch(c)
{
case 0143:case 0103
:
language= change_params.Language=
(cur_buffer[2]==053)?C_PLUS_PLUS:C;
column_mode= change_params.Column_mode= NO;
continue;
case 0162:case 0122
:
if(!RAT_OK("Language change ignored"))continue;
language= change_params.Language=
(cur_buffer[2]==071)?RATFOR_90:RATFOR;
continue;
case 0156:case 0116
:
language= change_params.Language=
(cur_buffer[2]==071)?FORTRAN_90:FORTRAN;
continue;
case 0166:case 0126
:
language= change_params.Language= LITERAL;continue;
case 0170:case 0130
:
language= change_params.Language= TEX;continue;
case 0133:
column_mode= change_params.Column_mode= YES;continue;
case 0135:
column_mode= change_params.Column_mode= NO;continue;
default:
loc= cur_buffer+2;
err0_print(ERR_C,OC("Invalid @ command in change file"),0);
continue;
}
}
}
;
do
{
if(!input_ln(CHANGE_FILE))
{
err0_print(ERR_C,OC("Change file ended after @x"),0);
change_limit= NULL;
goto done_priming;
}
}
while(limit==cur_buffer);
;
done_priming:
language= input_params.Language;
parsing_mode= input_params.Parsing_mode;
column_mode= input_params.Column_mode;
/* After we're done priming the change buffer, we will next read from the \
input file. */
changing= NO;
cur0_prms= cur_prms.web;
}
SRTN
chk_change(VOID)/* Switches to |change_file| if the buffers match. */
{
int n= 0;/* The number of discrepancies found. */
if(LINES_DONT_MATCH)return;/* Didn't match a change. */
WHILE()
{
changing= YES;prn_where= YES;
if(!input_ln(CHANGE_FILE))
{
err0_print(ERR_C,OC("Change file ended before @y"),0);
change_limit= NULL;changing= NO;prn_where= YES;
return;
}
if(limit>cur_buffer+1&&cur_buffer[0]==0100)
{
if((cur_buffer[1]>=0130&&cur_buffer[1]<=0132)||cur_buffer[1]==0111)
cur_buffer[1]+= 0172-0132;
;
if(cur_buffer[1]==0151)
{
loc= cur_buffer+2;
err0_print(ERR_C,OC("Sorry, no includes allowed in change file"),0);
}
;
if(cur_buffer[1]==0170||cur_buffer[1]==0172)
{
loc= cur_buffer+2;
err0_print(ERR_C,OC("Where is the matching @y?"),0);
}
else if(cur_buffer[1]==0171)
{
if(n>0)
{
loc= cur_buffer+2;
err0_print(ERR_C,OC("Hmm... some of the preceding lines failed to match"),0);
}
return;
}
}
;
changing= NO;prn_where= YES;
while(!input_ln(INPUT_FILE))
{/* Pop the stack or quit. */
if(incl_depth==WEB_FILE)
{
err0_print(ERR_C,OC("WEB file ended during a change"),0);
input_has_ended= YES;return;
}
incl_depth--;prn_where= YES;
}
if(LINES_DONT_MATCH)n++;
}
}
#endif /* Part 1 */
#if(part != 1)
SRTN
rst_input(VOID)
{
FCLOSE(prms[WEB_FILE].web.File);
FCLOSE(prms[WEB_FILE].change.File);
ini_input_prms(WEB_FILE,(outer_char HUGE*)"",ABORT_ON_ERROR);
limit= cur_buffer;loc= cur_buffer+1;cur_buffer[0]= 040
;
{
cur0_prms= cur_prms.change;
changing= YES;
change_params= change_params0;/* Reset to default values. */
prime_the_change_buffer();
limit= cur_buffer;loc= cur_buffer+1;cur_buffer[0]= 040
;
}
incl_depth= WEB_FILE;
input_has_ended= NO;
}
boolean
ini_input_prms FCN((ilevel,path,quit_on_error))
int ilevel C0("Present level of input files.")
outer_char HUGE*path C0("Colon-delimited path list")
boolean quit_on_error C1("Abort flag.")
{
INPUT_PRMS HUGE*p= &prms[ilevel];
CUR_PRMS old_prms;
boolean web_level= BOOLEAN(ilevel==WEB_FILE);
old_prms= cur_prms;/* Save state in case of error. */
/* Initialize this here in case of error messages. */
cur_prms.web= &p->web;
cur_prms.change= &p->change;
/* Initialize both input and change files; abort if error. */
if(!(ini0_input_prms(cur_prms.web,path,OC("input"),quit_on_error,
(SEQUENCES*)(web_level?wt_style.input_ext.web:
wt_style.input_ext.hweb))&&
ini0_input_prms(cur_prms.change,path,OC("change"),quit_on_error,
(SEQUENCES*)(web_level?wt_style.input_ext.change:
wt_style.input_ext.hchange))))
{
cur_prms= old_prms;/* Restore old state if error. */
return NO;
}
/* For definiteness we set |cur0_prms| to the web input file. */
cur0_prms= cur_prms.web;
loc= cur_buffer;
/* Remember the name of the include file, for use by \WEAVE. */
STRCPY(this_include_file,web_level?
(CONST outer_char*)"":p->web.File_name);
return YES;
}
boolean
ini0_input_prms FCN((p0,path,file_type,quit_on_error,extensions))
INPUT_PRMS0 HUGE*p0 C0("")
outer_char HUGE*path C0("")
outer_char file_type[]C0("")
boolean quit_on_error C0("")
SEQUENCES*extensions C1("")
{
cur0_prms= p0;/* In case of error messages. */
/* If we've never opened this level before, allocate appropriate space. */
if(p0->Buffer==NULL)
{
ALLOC(ASCII,p0->Buffer,"bs",buf_size,0);
p0->Buffer_end= p0->Buffer+buf_size-2;
}
/* Initialize location pointers and flags. */
loc= p0->Limit= p0->Buffer;
p0->Line= 0;
p0->Num_in_buffer= 0;
p0->Scanning_C_cmnt= p0->Last_was_empty
= p0->Continuing_line= p0->Last_was_continued= NO;
/* --- Open file (but not if it's already open) --- */
if(!p0->File&&
(p0->File= xopen(p0->File_name,path,extensions,OC("r")))==NULL)
{
if(quit_on_error)
{
fatal(ERR_C,OC(""),OC("Can't open %s%s file %s."),*p0->File_name?"":"(null) ",(char*)file_type,*p0->File_name?p0->File_name:wt_style.null_file_name);
}
else
{
err0_print(ERR_C,OC("Can't open include %s file \"%s\""),2,file_type,p0->File_name);
}
return NO;/* Couldn't open file. */
}
return YES;/* Opened file successfully. */
}
FILE*
xopen FCN((file_name,path,extensions,iomode))
outer_char*file_name C0("")
outer_char HUGE*path C0("")
SEQUENCES*extensions C0("")
CONST outer_char*iomode C1("")
{
outer_char HUGE*p1;
FILE*file_ptr;
outer_char total_name[2*MAX_FILE_NAME_LENGTH];
outer_char prefix_end_str[2];
if(!*file_name)
return FOPEN(wt_style.null_file_name,iomode);
if(*iomode=='r'&&STRCMP(file_name,"stdin")==0)
return stdin;
else if(*iomode=='w'&&STRCMP(file_name,"stdout")==0)
return stdout;
/* If at this point there's still a path attached to |file_name| (probably \
occurs only with the \.{-H} option), we just try to open the file. \
If there's no path, we just try to look in the present directory. */
if(file_name[0]==prefix_end_char||!(path&&*path))
return x0open(file_name,extensions,iomode);
prefix_end_str[0]= prefix_end_char;
prefix_end_str[1]= '\0';
/* Hunt through the path. */
while((p1= (outer_char HUGE*)STRCHR(path,':'))!=NULL)
{
*p1= '\0';
STRCPY(total_name,path);
*p1= ':';
if(*(p1-1)!=prefix_end_char)
STRCAT(total_name,prefix_end_str);
STRCAT(total_name,file_name);
if((file_ptr= x0open(total_name,extensions,iomode))!=NULL)
return file_ptr;
path= p1+1;
}
return NULL;/* Couldn't open any file. */
}
FILE*
x0open FCN((file_name,extensions,iomode))
outer_char*file_name C0("")
SEQUENCES*extensions C0("")
CONST outer_char*iomode C1("")
{
int k;
/* If it has a dot in it, it's always interpreted literally. If it didn't \
have a dot, then if the `\.{-e}'~option isn't in effect it will already \
have had the `\.{.web}' extension added to it, so it will now have a dot. \
(So presumably the last option of the \&{if} is redundant?) */
if(STRCHR(file_name,wt_style.ext_delimiter)!=NULL||!try_extensions)
return FOPEN(file_name,iomode);
/* At this point, the file name didn't have a dot and the `\.{-e}'~option \
is in effect. Make trial file names from the list of extensions and try to \
open them one at a time until one matches. */
for(k= 0;k<extensions->n;k++)
{
outer_char full_name[MAX_FILE_NAME_LENGTH];
FILE*file_ptr;
if(
nsprintf(full_name,OC("%s%c%s"),3,file_name,wt_style.ext_delimiter,extensions->string[k])>=
MAX_FILE_NAME_LENGTH)OVERFLW("Extended file name","");
file_ptr= FOPEN(full_name,iomode);
if(file_ptr)
{
STRCPY(file_name,full_name);/* If we don't do this, the \
information messages aren't as informative as they could be. */
return file_ptr;/* Opened a file successfully. */
}
}
return NULL;/* Failed to open the file. */
}
boolean
get_line(VOID)
{
if(return_toggle)
{
return_toggle= NO;
if(popped&&no_more_input)
{
input_has_ended= YES;
return NO;
}
STRNCPY(cur_buffer,stored_line,stored_line_length);
FREE_MEM(stored_line,"stored_line",stored_line_length,ASCII);
limit= cur_buffer+stored_line_length;
*limit= 040;
if(popped)
{
popped= NO;
goto popped_stack;
}
else if(toggling)
goto push_stack;
else
goto process_line;
}
restart:
if(changing)
chngd_module[module_count]= YES;
else
{
popped= NO;
if(cur_prms.web->Line==0)
if(ignored_cmnts())goto fin_read;
else goto pop_or_quit;
while(!input_ln(INPUT_FILE))
{/* pop the stack or quit */
pop_or_quit:
prn_where= YES;
if(incl_depth==WEB_FILE){input_has_ended= YES;break;}
else
{/* Tidy up the include level we're about to leave. */
if(cur_prms.web->File!=prms[incl_depth-1].web.File)
{FCLOSE(cur_prms.web->File);}
if(cur_prms.change->File!=prms[incl_depth-1].change.File)
{FCLOSE(cur_prms.change->File);}
else prms[incl_depth-1].change= *cur_prms.change;
cur0_prms->File= NULL;
CLR_PRINTF(include_file,(")"));/* Tell the terminal we're \
finished with this web input file. */
/* Pop the stack here. */
incl_depth--;
cur_prms.web= &prms[incl_depth].web;
cur_prms.change= &prms[incl_depth].change;
if(incl_depth==WEB_FILE&&toggle_includes&&toggling)
{
toggling= NO;
return_toggle= YES;
}
STRCPY(this_include_file,(incl_depth==WEB_FILE)?
(CONST outer_char*)"":cur_file_name);
}
}
fin_read:
if(return_toggle)
{
no_more_input= input_has_ended;
input_has_ended= NO;
popped= YES;
{
return_toggle= YES;
stored_line_length= PTR_DIFF(size_t,limit,cur_buffer);
stored_line= GET_MEM("stored_line",stored_line_length+1,ASCII);/* We \
allocate one extra so we don't have to handle the special case of a \
zero-length line, for which |FREE_MEM| would complain. */
STRNCPY(stored_line,cur_buffer,stored_line_length);
loc= cur_buffer+2;
get_fname(prms[1].web.File_name);/* For \.{@I} bug. */
loc= limit= cur_buffer;
*limit++= 0100;*limit++= '\001';*limit= 040;
/* |toggle_output| is \.{@\\001}. */
return YES;
}
}
popped_stack:
if(!input_has_ended)
if(limit==change_limit-change_buffer+cur_buffer)
if(cur_buffer[0]==change_buffer[0])
if(change_limit>change_buffer)chk_change();
}
;
if(changing)
{
{
if(!input_ln(CHANGE_FILE))
{
err0_print(ERR_C,OC("Change file ended without @z"),0);
cur_buffer[0]= 0100;cur_buffer[1]= 0172;limit= cur_buffer+2;
}
if(limit>cur_buffer+1)/* check if the change has ended */
if(cur_buffer[0]==0100)
{
if((cur_buffer[1]>=0130&&cur_buffer[1]<=0132)||cur_buffer[1]==0111)
cur_buffer[1]+= 0172-0132;
;
if(cur_buffer[1]==0151)
{
loc= cur_buffer+2;
err0_print(ERR_C,OC("Sorry, no includes allowed in change file"),0);
}
;
if(cur_buffer[1]==0170||cur_buffer[1]==0171)
{
loc= cur_buffer+2;
err0_print(ERR_C,OC("Where is the matching @z?"),0);
}
else if(cur_buffer[1]==0172)
{
prime_the_change_buffer();prn_where= YES;
}
}
}
;
if(!changing)
{
chngd_module[module_count]= YES;goto restart;
}
}
process_line:
loc= cur_buffer;*limit= 040;
if(return_toggle)
{
return_toggle= YES;
stored_line_length= PTR_DIFF(size_t,limit,cur_buffer);
stored_line= GET_MEM("stored_line",stored_line_length+1,ASCII);/* We \
allocate one extra so we don't have to handle the special case of a \
zero-length line, for which |FREE_MEM| would complain. */
STRNCPY(stored_line,cur_buffer,stored_line_length);
loc= cur_buffer+2;
get_fname(prms[1].web.File_name);/* For \.{@I} bug. */
loc= limit= cur_buffer;
*limit++= 0100;*limit++= '\001';*limit= 040;
/* |toggle_output| is \.{@\\001}. */
return YES;
}
if(*cur_buffer==0100)
switch(*(cur_buffer+1))
{
case 0151:
case 0111:
if(*(cur_buffer+1)==0111&&(skip_includes||
(program==weave&&toggle_includes&&CUR_FILE==WEB_FILE)))
{
if(skip_includes)
{/* Include commands are being skipped altogether. */
loc= limit+1;/* Turn whole line into null. */
goto restart;
}
else if(toggle_includes&&CUR_FILE==WEB_FILE)
{/* Include files are read, but not printed. */
toggling= YES;
{
return_toggle= YES;
stored_line_length= PTR_DIFF(size_t,limit,cur_buffer);
stored_line= GET_MEM("stored_line",stored_line_length+1,ASCII);/* We \
allocate one extra so we don't have to handle the special case of a \
zero-length line, for which |FREE_MEM| would complain. */
STRNCPY(stored_line,cur_buffer,stored_line_length);
loc= cur_buffer+2;
get_fname(prms[1].web.File_name);/* For \.{@I} bug. */
loc= limit= cur_buffer;
*limit++= 0100;*limit++= '\001';*limit= 040;
/* |toggle_output| is \.{@\\001}. */
return YES;
}
}
}
else
{
boolean found_include;
push_stack:
loc= cur_buffer+2;/* Position after \.{@i}. */
if(++incl_depth>=(int)max_include_depth)
{
incl_depth--;
err0_print(ERR_C,OC("Too many nested includes; %d allowed. \
Increase with `-yid'."),1,max_include_depth);
goto restart;
}
/* Look for the name of a \WEB\ file to include. */
if(!(found_include= get_fname(cur_file_name)))
err0_print(ERR_C,OC("Include file name not given"),0);
else
{/* Found a \WEB\ file name; now look for change file name. */
if(skip_ifiles)
{
int j;
for(j= 0;j<num_ifiles;j++)
if(STRCMP(ifiles[j],cur_file_name)==0)
{
incl_depth--;
goto restart;
}
if(num_ifiles==(int)max_ifiles)
OVERFLW("unique include file names","if");
if(phase==1)
{
ifiles[num_ifiles]= GET_MEM("ifile",STRLEN(cur_file_name)+1,outer_char);
STRCPY(ifiles[num_ifiles],cur_file_name);
}
num_ifiles++;
}
if(!get_fname(change_file_name))
{/* No change file name specified; obtain it from the \
last level. */
INPUT_PRMS*p_lower= &prms[incl_depth-1];
INPUT_PRMS0*p0_lower= &p_lower->change;
STRCPY(change_file_name,p0_lower->File_name);
change_file= p0_lower->File;
change_params= p_lower->input_params;
}
}
if(found_include)
{
if(ini_input_prms(CUR_FILE,incl.list,DONT_ABORT_ON_ERROR))
{
if(cur_prms.change->File!=prms[incl_depth-1].change.File)
{
cur0_prms= cur_prms.change;
changing= YES;
change_params= change_params0;/* Reset to default values. */
prime_the_change_buffer();
limit= cur_buffer;loc= cur_buffer+1;cur_buffer[0]= 040
;
}
/* New change file. */
else*cur_prms.change= prms[incl_depth-1].change;
/* Still using the old change file. */
cur_line= 0;
prn_where= YES;
CLR_PRINTF(include_file,(" (%s",(char*)cur_file_name));
/* Tell the terminal where we're reading from. */
}
else
{/* Failed to open include file. */
incl_depth--;
}
}
goto restart;
}
break;
}
return(boolean)(!input_has_ended);
}
boolean
get_fname FCN((file_name))
outer_char HUGE*file_name C1("")
{
ASCII HUGE*j;
outer_char HUGE*k;
skip_white:
/* Skip over leading white space and optional quotes. */
while(loc<=limit&&(*loc==040||*loc==011||*loc==042))loc++;
/* If we've hit the end of the buffer, we're done, and we didn't find \
anything. */
if(loc>=limit)return NO;
{
if(*loc==057)
{
if(*(loc+1)==057)
{/* Short comment */
loc= limit+1;
return NO;
}
if(*(loc+1)==052)
{/* Long comment */
for(loc+= 2;loc<=limit;loc++)
if(*loc==052&&*(loc+1)==057)
{
loc+= 2;
goto skip_white;
}
err0_print(ERR_C,OC("Can't continue comments on @i lines"),0);
}
}
}
k= file_name;j= loc;
/* Terminate scan by white space or quotes. */
while(*loc!=040&&*loc!=011&&*loc!=042)*k++= XCHR(*loc++);
TERMINATE(k,0);
/* On certain systems, underscores aren't allowed in file names. */
add_prefix(file_name);/* Attach a directory prefix. */
return YES;
}
SRTN
add_prefix FCN((file_name))
outer_char HUGE*file_name C1("")
{
outer_char temp[MAX_FILE_NAME_LENGTH];
xpnd_file_name(file_name);/* Expand possible environmental prefix. */
if(*wbprefix&&STRRCHR(file_name,prefix_end_char)==NULL)
{
if(
nsprintf(temp,OC("%s%s"),2,wbprefix,file_name)>=
MAX_FILE_NAME_LENGTH)OVERFLW("Path/file_name","");
STRCPY(file_name,temp);
}
}
SRTN
xpnd_file_name FCN((name))
outer_char HUGE*name C1("")
{
outer_char temp[MAX_FILE_NAME_LENGTH],env_prefix[MAX_FILE_NAME_LENGTH];
outer_char*pc,*px,*qx;
CONST char*separator;
int n;
boolean expanded;
#ifdef vms
return;/* VAX/VMS does its own expansions of logical names. */
#else
#if !HAVE_GETENV
err0_print(ERR_C,OC("Sorry, this machine doesn't support environment variables"),0);
return;
#else
/* Is there a logical name prefix? */
if((pc= OC(STRCHR(name,':')))==NULL)return;
/* Isolate the prefix. */
STRNCPY(env_prefix,name,n= PTR_DIFF(int,pc,name));
TERMINATE(env_prefix,n);
/* Recursively expand the prefix. |px|~will have the last non-null name. */
expanded= NO;
for(px= env_prefix;px;px= qx)
{
if((qx= GETENV(px))==NULL)break;
if(STRCMP(qx,env_prefix)==0)
{
err0_print(ERR_C,OC("Infinite recursion in definition of \
environmental variable \"%s\""),1,px= env_prefix);
expanded= NO;
break;
}
expanded= YES;/* At least one expansion of the logical name was \
made. */
}
/* If the prefix wasn't expandable, or if it turned into an infinite \
recursion, do nothing. */
if(!expanded)return;
/* Otherwise, |px|~has the last expansion of the name. */
separator=
#ifdef ibmpc
"\\"
#else
"/"
#endif /* |ibmpc| */
;
if(
nsprintf(temp,OC("%s%s%s"),3,px,separator,pc+1)>=
MAX_FILE_NAME_LENGTH)
OVERFLW("Expandable file name","");
STRCPY(name,temp);
#endif /* |HAVE_GETENV| */
#endif /* |vms| */
}
boolean
ignored_cmnts(VOID)
{
boolean limbo_material;
/* Read the first line of file. */
if(!input_ln(INPUT_FILE))
return NO;
/* Check for possible limbo material. If so, skip all lines up to \
an~`\.{@x}'. */
limbo_material= BOOLEAN(cur_buffer[0]==0100&&cur_buffer[1]==0172);
if(limbo_material)
do
{
if(!input_ln(INPUT_FILE))
{
CLR_PRINTF(warning,("\n! File ended during \
skip_limbo. Limbo material that begins with @z must be terminated by \
@x."));
return NO;
}
if(phase==1)
find_keywords(cur_buffer,limit);
}
while(!(cur_buffer[0]==0100&&cur_buffer[1]==0170));
/* If there was limbo material, at this point the line beginning \
with~`\.{@x}' is in the buffer. The next operation is to read another \
line, which starts the proper part of the include file. If there was no \
limbo material, the first line of the file is already in the buffer. Thus, \
after the following operation we'll always have the first proper line of \
the file in the buffer. */
if(limbo_material&&!input_ln(INPUT_FILE))
return NO;
return YES;/* Successfully skipped comments. */
}
SRTN
find_keywords FCN((p,p_end))
ASCII HUGE*p C0("Start of line to search")
ASCII HUGE*p_end C1("End of line")
{
ASCII HUGE*pk,HUGE*pk_end,HUGE*ptext,HUGE*ptext_end;
*p_end= '\0';
pk= (ASCII HUGE*)STRCHR(p,044);
if(!pk)
return;/* No starting \.{'\$'}. */
pk_end= (ASCII HUGE*)STRCHR(pk,072);
if(!pk_end)
return;/* No intermediate \.{':'}. */
if(pk_end[1]!=040)
return;/* There must be at least one blank after the \.{':'}. */
ptext_end= (ASCII HUGE*)STRCHR(pk_end+1,044);
if(!ptext_end)
return;/* No ending \.{'\$'}. */
if(ptext_end[-1]!=040)
return;/* There must be at least one blank before the \.{'\$'}. */
/* Strip blanks from start of text. */
for(ptext= pk_end+2;*ptext==040;ptext++)
;
/* Strip blanks from end of text. */
for(ptext_end--;*ptext_end==040;ptext_end--)
;
add_keyword(pk+1,pk_end,ptext,ptext_end+1);
}
SRTN
add_keyword FCN((pk,pk_end,pt,pt_end))
ASCII HUGE*pk C0("Start of keyword")
ASCII HUGE*pk_end C0("End of keyword")
ASCII HUGE*pt C0("Start of text")
ASCII HUGE*pt_end C1("End of text")
{
RCS HUGE*prcs;
unsigned k;
*pk_end= *pt_end= '\0';
for(k= 0;k<num_keywords;k++)
if(STRCMP(pk,rcs[k].keyword)==0)
{
outer_char temp[256];
STRCPY(temp,pk);
to_outer(temp);
printf("\n! Duplicate RCS-like keyword `%s' ignored (l. %u).",
temp,cur_line);
mark_harmless;
return;
}
if(num_keywords==(unsigned)max_keywords)
OVERFLW("RCS-like keywords","rk");
prcs= &rcs[num_keywords++];
prcs->keyword= GET_MEM("keyword",STRLEN(pk)+1,ASCII);
prcs->txt= GET_MEM("RCS text",STRLEN(pt)+1,ASCII);
STRCPY(prcs->keyword,pk);
STRCPY(prcs->txt,pt);
}
SRTN
chk_complete(VOID)
{
if(change_limit!=NULL)
{/* |changing| is |NO| */
STRNCPY(cur_buffer,change_buffer,
PTR_DIFF(size_t,change_limit,change_buffer)+1);
loc= limit= PTR_DIFF(size_t,change_limit,change_buffer)+cur_buffer;
changing= YES;
err0_print(ERR_C,OC("Change file entry did not match"),0);
}
}
void HUGE*
get_mem0 FCN((why,nunits,nsize))
CONST outer_char why[]C0("Reason for request")
BUF_SIZE nunits C0("Number of units to allocate.")
size_t nsize C1("Size of each unit.")
{
void HUGE*p;/* With certain compilers such as the |SGI|, |void| is \
translated into |char|; see \.{proto.hweb}. */
BUF_SIZE nbytes;
if(nunits==0)
return NULL;/* Should this ever happen? */
if(nsize==0)
confusion(OC("get_mem0"),OC("Nsize = 0 requested"));
#if !NON_ANSI_CALLOC
/* For ANSI, the prototype for |calloc| is |void *calloc(size_t,size_t)|. */
if(nunits>MAX_SIZE_T)
{
err0_print(ERR_C,OC("get_mem0: Can't request %lu units; used max of %lu"),2,nunits,MAX_SIZE_T);
nunits= MAX_SIZE_T;
}
#endif /* |ANSI_CALLOC| */
if((p= (void HUGE*)CALLOC(nunits,nsize))==NULL)
{
FREE(byte_mem);/* Kludge to try to make it go out gracefully. */
fatal(ERR_C,OC("\n!!! NO MORE MEMORY"),OC(" (\"%s\")!!! \
[Requesting %lu unit(s) of size %lu byte(s); \
allocated %lu bytes so far.] \
Try using the -y option to reduce the sizes of internal tables."),(char*)why,nunits,(BUF_SIZE)nsize,total_mem);
}
/* Keep track of total allocation. */
nbytes= nunits*nsize;
total_mem+= nbytes;
max_mem= MAX(max_mem,total_mem);
#ifdef mac
lmemset(p,0,nbytes);/* For |lmalloc|, must zero explicitly. */
#endif
if(show_mem&&nbytes>=show_size)
show_alloc('+',why,nunits,(BUF_SIZE)nsize,nbytes,p,total_mem);
return p;/* The allocated memory area. */
}
SRTN
show_alloc FCN((c,why,nunits,nsize,nbytes,p,total_mem))
outer_char c C0("Either plus or minus")
CONST outer_char why[]C0("Reason for request")
BUF_SIZE nunits C0("Number of units")
BUF_SIZE nsize C0("Size of each unit.")
BUF_SIZE nbytes C0("Bytes allocated")
void HUGE*p C0("Start of allocated area")
BUF_SIZE total_mem C1("Total bytes currently allocated")
{
printf("\"%s\": %c(%lu x %lu) = %c%lu ",
(char*)why,c,nunits,nsize,c,nbytes);
ptr_range(p,nbytes);
printf("(%lu total)\n",total_mem);
}
SRTN
ptr_range FCN((p,nbytes))
void HUGE*p C0("Start of the allocated space.")
BUF_SIZE nbytes C1("Length of the allocation")
{
static char ptr_string[]=
#ifdef ibmpc
PTR_BASE
#else
""
#endif
;
printf(ptr_string,p,(char HUGE*)p+nbytes);
}
SRTN
free_mem0 FCN((p,why,nunits,nsize))
void HUGE*p C0("Pointer to deallocate")
CONST outer_char why[]C0("Reason for request")
BUF_SIZE nunits C0("Number of units to deallocate.")
size_t nsize C1("Size of each unit.")
{
BUF_SIZE nbytes;
/* If things are working correctly, |p|~should have been previously \
allocated. */
if(p==NULL)
confusion(OC("free_mem0"),OC("Attempting to deallocate NULL pointer"));
/* Keep track of total allocation. */
nbytes= nunits*nsize;
total_mem-= nbytes;
if(show_mem&&nbytes>=show_size)
show_alloc('-',why,nunits,(BUF_SIZE)nsize,nbytes,p,total_mem);
FREE(p);
}
MEM HUGE*
msearch FCN((abbrev,nunits))
CONST outer_char abbrev[]C0("Abbreviation for desired object.")
BUF_SIZE nunits C1("Value.")
{
MEM HUGE*m;
for(m= mem;*m->abbrev;m++)
if(STRCMP(m->abbrev,abbrev)==0)
{
if(nunits==0L)return m;/* Special case: just find it. */
if(nunits<m->min)
{
CLR_PRINTF(warning,
("! Warning (msearch:%s): nunits (%lu) < min (%lu); min used.\n",
(char*)abbrev,nunits,m->min));
mark_harmless;
nunits= m->min;
}
else if(nunits>m->max)
{
CLR_PRINTF(warning,
("! Warning (dynamic buffer %s): nunits (%lu) > max (%lu); max used.\n",
(char*)abbrev,nunits,m->max));
mark_harmless;
nunits= m->max;
}
m->nunits= nunits;/* Override the default value. */
return m;
}
CLR_PRINTF(warning,
("! Invalid alloc abbreviation \"%s[%lu]\"\n",(char*)abbrev,nunits));
mark_harmless;
return m;
}
void HUGE*
alloc FCN((abbrev,pnunits,nsize,dn))
CONST outer_char abbrev[]C0("Abbreviation for desired object.")
BUF_SIZE HUGE*pnunits C0("Pointer to returned \# of units.")
size_t nsize C0("Size of object.")
int dn C1("Incremental number of units to allocate.")
{
MEM HUGE*m= find_abbrev(abbrev);
*pnunits= m->nunits;
/* |dn| is used as a flag; if it's negative, we just obtain the number of \
units. */
if(dn<0)
return NULL;
else
return get_mem0(abbrev,(*pnunits)+dn,nsize);
}
MEM HUGE*find_abbrev FCN((abbrev))
CONST outer_char abbrev[]C1("")
{
MEM HUGE*m;
for(m= mem;*m->abbrev;m++)
if(STRCMP(m->abbrev,abbrev)==0)
return m;
confusion(OC("find_abbrev"),OC("Bad alloc abbreviation \"%s\""),abbrev);
return NULL;
}
#ifdef mcc
void HUGE*
hrealloc FCN((old_ptr,new_size,old_size))
void HUGE*old_ptr C0("Old buf previously allocated with |halloc|.")
BUF_SIZE new_size C0("New size in bytes.")
BUF_SIZE old_size C1("Old size in bytes.")
{
void HUGE*new_ptr;
BUF_SIZE num_to_copy;
size_t ncopied;
new_ptr= GET_MEM("hrealloc",new_size,char);
if(new_ptr==NULL)
return NULL;
num_to_copy= MIN(old_size,new_size);
ncopied= (size_t)num_to_copy;
if((BUF_SIZE)ncopied!=num_to_copy)
confusion(OC("hrealloc"),OC("trying to copy %lu bytes; more than size_t"),num_to_copy);
memcpy(new_ptr,old_ptr,ncopied);
FREE_MEM(old_ptr,"old_ptr",old_size,char);
return new_ptr;
}
#endif /* |mcc| */
unsigned
prn_id FCN((np))
name_pointer np C1("")
{
ASCII_write(*np->byte_start==BP_MARKER?
((BP*)np->byte_start)->Root->id:np->byte_start,Length(np));
return PTR_DIFF(unsigned,np,name_dir);
}
int
Length FCN((np))
name_pointer np C1("")
{
int n;
BP HUGE*bp;
TRUNC HUGE*s;
CONST ASCII HUGE*p0;
CONST ASCII HUGE*p1;
p0= np->byte_start;
bp= (BP*)p0;
if(*(char*)bp==BP_MARKER)
{
s= bp->Root;
n= PTR_DIFF(int,s->id_end,s->id);
}
else
{
p1= (np+1)->byte_start;
PROPER_END(p1);
n= PTR_DIFF(int,p1,p0);
}
return n;
}
name_pointer
id_lookup FCN((first,last,t))
CONST ASCII HUGE*first C0("First character of string.")
CONST ASCII HUGE*last C0("last character of string plus one.")
eight_bits t C1("The |ilk|; used by \.{WEAVE} only.")
{
CONST ASCII HUGE*i= first;/* position in |cur_buffer| */
int h;/* hash code */
int l;/* length of the given identifier */
name_pointer p;/* where the identifier is being sought */
WORD_TYPE word_type0= ORDINARY_ID;
if(last==NULL)
{
word_type0= word_type;
for(last= first;*last!='\0';last++)
;/* Find end of identifier. */
}
l= PTR_DIFF(int,last,first);/* compute the length */
h= *i;
while(++i<last)h= (h+h+*i)%hash_size;
;
p= hash[h];
while(p&&!names_match(p,first,l,t))p= p->link;
if(p==NULL)
{
p= name_ptr;/* the current identifier is new */
p->link= hash[h];hash[h]= p;/* insert |p| at beginning of hash \
list */
}
;
if(p==name_ptr)
{
if(byte_ptr+l>byte_end)OVERFLW("bytes","b");
if(name_ptr>=name_end)OVERFLW("names","n");
STRNCPY(byte_ptr,first,l);
(++name_ptr)->byte_start= byte_ptr+= l;
if(program==weave)
ini_p(p,t);
}
;
if(!(p->Language&(boolean)language))
p->ilk= t;
p->Language|= (boolean)language;/* Record language usage. This line is \
dangerous if one is using |id_lookup| for a query from a routine for a \
language other than the current one; see |ini_special_tokens|. */
switch(word_type0)
{
case RESERVED_WD:
p->reserved_word|= (boolean)language;
break;
case INTRINSIC_FCN:
p->intrinsic_word|= (boolean)language;
break;
case KEYWD:
p->keyword|= (boolean)language;
break;
default:;/* Avoids warning about unused |enum|. */
}
return p;
}
sixteen_bits
find_n FCN((n))
sixteen_bits n C1("")
{
name_pointer np;
CONST ASCII HUGE*end;
outer_char HUGE*s;
size_t len;
np= name_dir+n;
if(np>=name_ptr)
{
printf("!! n = %u exceeds nmax = %u.\n",n,
PTR_DIFF(unsigned,name_ptr,name_dir)-1);
return 0;
}
PROPER_END(end);
len= PTR_DIFF(size_t,end,np->byte_start);/* Length of the $n$th identifier. */
s= GET_MEM("find_n",len+1,outer_char);/* Allocate temporary area. */
STRNCPY(s,np->byte_start,len);
TERMINATE(s,len);
/* Convert from |ASCII| to the outer world; print info about id. */
to_outer((ASCII HUGE*)s);
id_info(np,(long)n,(CONST outer_char*)s,NULL);
FREE_MEM(s,"find_n",len+1,outer_char);
return n;
}
sixteen_bits
find_s FCN((s))
CONST outer_char*s C1("")
{
int h,l;
name_pointer p;
ASCII HUGE*a;
CONST ASCII HUGE*first,HUGE*last;
CONST ASCII HUGE*i;
sixteen_bits n= 0;
l= STRLEN(s);
a= GET_MEM("find_s",l+1,ASCII);
STRCPY(a,s);
i= first= to_ASCII((outer_char*)a);
last= first+l;
h= *i;
while(++i<last)h= (h+h+*i)%hash_size;
p= hash[h];
while(p&&!(STRNCMP(first,p->byte_start,l)==0))p= p->link;
if(p==NULL)
{CLR_PRINTF(warning,("%cId \"%s\" is not in name_dir!\n",
beep(1),(char*)s));}
else
id_info(p,(long)(n= (sixteen_bits)(p-name_dir)),s,NULL);
FREE_MEM(a,"find_s",l+1,ASCII);
return n;
}
sixteen_bits
find_id FCN((a0,a1))
eight_bits a0 C0("")
eight_bits a1 C1("")
{
return find_n(IDENTIFIER(a0,a1));
}
SRTN
id_info FCN((np,n,s,prsrvd))
name_pointer np C0("")
long n C0("")
CONST outer_char*s C0("")
CONST RSRVD HUGE*prsrvd C1("")
{
if(n>=0)
printf(_Xx("Id %ld (0x%lx):"),n,n);
if(!prsrvd
||(prsrvd->reserveds&&np->reserved_word)
||(prsrvd->intrinsics&&np->intrinsic_word)
||(prsrvd->keywords&&np->keyword))
printf(" \"%s\"\n",(char*)s);
if(!prsrvd)
pr_lan("Language ",np->Language);
if(!prsrvd||prsrvd->reserveds)
pr_lan("reserved ",np->reserved_word);
if(!prsrvd||prsrvd->intrinsics)
pr_lan("intrinsic",np->intrinsic_word);
if(!prsrvd||prsrvd->keywords)
pr_lan("keyword ",np->keyword);
}
SRTN
pr_lan FCN((name,b))
CONST char*name C0("")
boolean b C1("")
{
unsigned k;/* For scanning over the 8 possibilities. */
boolean first= YES;
if(b==0)
return;/* Not turned on at all. */
printf(" %s = { ",name);
for(k= 1;k<=256;k<<= 1)
if(k&b)
{
printf("%s%s",first?"":", ",
languages[lan_num((LANGUAGE)k)]);
first= NO;
}
if(first)
printf("(none)");
printf(" }");
puts("");
}
BUF_SIZE
prn_nd(VOID)
{
BUF_SIZE k,n= name_ptr-name_dir;
for(k= 0;k<n;k++)
{
printf("[%lu]: ",k);
prn_id(name_dir+k);
putchar('\n');
}
return n;
}
name_pointer
mod_lookup FCN((k,l))
CONST ASCII HUGE*k C0("First character of name.")
CONST ASCII HUGE*l C1("Last character of name.")
{
LEXI c= GREATER;/* comparison between two names */
name_pointer p= root;/* current node of the search tree */
name_pointer q= name_dir;/* father of node |p| */
while(p)
{
c= web_strcmp(k,l+1,p->byte_start,(p+1)->byte_start);
q= p;
switch(c)
{
case LESS:p= p->llink;continue;
case GREATER:p= p->rlink;continue;
case EQUAL:return p;
default:
err0_print(ERR_C,OC("Incompatible section names"),0);
return NULL;
}
}
return install_node(q,c,k,PTR_DIFF(int,l,k)+1);
}
LEXI
web_strcmp FCN((j,j1,k,k1))/* fuller comparison than |strcmp| */
CONST ASCII HUGE*j C0("Beginning of first string.")
CONST ASCII HUGE*j1 C0("End of first string plus one.")
CONST ASCII HUGE*k C0("Beginning of second string.")
CONST ASCII HUGE*k1 C1("End of second string plus one.")
{
while(k<k1&&j<j1&&*j==*k)k++,j++;
if(k==k1)if(j==j1)return EQUAL;
else return EXTENSION;
else if(j==j1)return PREFIX;
else if(*j<*k)return LESS;
else return GREATER;
}
name_pointer
install_node FCN((parent,c,j,name_len))/* install a new node in the tree */
name_pointer parent C0("Parent of new node.")
int c C0("Right or left?")
CONST ASCII HUGE*j C0("Where replacement text starts.")
int name_len C1("length of replacement text.")
{
name_pointer node= name_ptr;/* new node */
if(byte_ptr+name_len>byte_end)OVERFLW("bytes","b");
if(name_ptr==name_end)OVERFLW("names","n");
if(c==LESS)parent->llink= node;else parent->rlink= node;
node->llink= node->rlink= NULL;
ini_node(node);
STRNCPY(byte_ptr,j,name_len);
(++name_ptr)->byte_start= byte_ptr+= name_len;
return node;
}
name_pointer
prefix_lookup FCN((k,l))/* finds module name given a prefix */
CONST ASCII HUGE*k C0("First char of prefix.")
CONST ASCII HUGE*l C1("Last char of prefix.")
{
LEXI c= GREATER;/* comparison between two names */
short count= 0;/* the number of hits */
name_pointer p= root;/* current node of the search tree */
name_pointer q= NULL;
/* another place to resume the search after one is done */
name_pointer r= NULL;/* extension found */
while(p){
c= web_strcmp(k,l+1,p->byte_start,(p+1)->byte_start);
switch(c){
case LESS:p= p->llink;break;
case GREATER:p= p->rlink;break;
default:r= p;count++;q= p->rlink;p= p->llink;
}
if(p==NULL){
p= q;q= NULL;
}
}
if(count==0)
err0_print(ERR_C,OC("Name does not match"),0);
else if(count>1)
err0_print(ERR_C,OC("Ambiguous prefix"),0);
return r;/* the result will be |NULL| if there was no match */
}
unsigned
find_prefix FCN((s))
outer_char s[]C1("")
{
name_pointer r;
to_ASCII(s);
r= prefix_lookup((ASCII HUGE*)s,(ASCII HUGE*)(s+STRLEN(s)));
return r?prn_id(r):0;
}
SRTN
err0_print FCN(VA_ALIST((err_origin,fmt,n VA_ARGS)))
VA_DCL(
ERR_ORIGIN err_origin C0("Where the error came from")
CONST outer_char*fmt C0("Format of error message.")
int n C2("Number of arguments to the string."))
{
VA_LIST(arg_ptr)
ASCII HUGE*k,HUGE*l;/* pointers into |cur_buffer| */
char temp[500];
boolean prn_input_buffer;
#if(NUM_VA_ARGS == 1)
ERR_ORIGIN err_origin;
CONST outer_char*fmt;
int n;
#endif
VA_START(arg_ptr,n);
#if(NUM_VA_ARGS == 1)
err_origin= va_arg(arg_ptr,ERR_ORIGIN);
fmt= va_arg(arg_ptr,outer_char*);
va_arg(arg_ptr,int);
#endif
prn_input_buffer= BOOLEAN(err_origin!=ERR_NULL);
if(prn_input_buffer&&err_origin!=ERR_S)putchar('\n');
set_color(RED);
if(prn_input_buffer)
{
sprintf(temp,"! (%s): %s",origin_name[err_origin],(char*)fmt);
vprintf(temp,arg_ptr);
}
else
vprintf((char*)fmt,arg_ptr);
va_end(arg_ptr);
if(prn_input_buffer)
{
outer_char last_char= fmt[STRLEN(fmt)-1];
if(*fmt&&last_char!='?'&&last_char!='!')
printf(".");
/* Sometimes the third argument to |fatal| is empty, \
so the period isn't necessary; or the phrase ends \
with a question mark or exclamation point. */
if(err_origin==ERR_S)
{
CONST outer_char HUGE*k,HUGE*l;
IN_STYLE boolean from_sprm;
printf(" (l. %u of %s file ",s_line,"style");
CLR_PRINTF(in_file,("%s)\n",
from_sprm?"parameter buffer":(char*)style_file_name));
l= MIN(sloc,slimit);
for(k= sbuf;k<l;k++)
putchar(*k>127?' ':(*k=='\t'?' ':*k));
/* Print the characters already read. */
putchar('\n');/* Separate already read from not yet read. */
for(k= sbuf;k<l;k++)
putchar(' ');/* Space out the next line. */
for(k= l;k<slimit;k++)
putchar(*k>127?' ':*k);/* Print the part not yet read. */
putchar('\n');
}
else
{
if(cur0_prms)
{
if(changing)
{
printf(" (l. %u of %s file ",change_line,"change");
CLR_PRINTF(in_file,("%s)\n",(char*)change_file_name));
}
else if(incl_depth==WEB_FILE)
printf(" (l. %u)\n",cur_line);
else
{
printf(" (l. %u of %s file ",cur_line,"include");
CLR_PRINTF(in_file,("%s)\n",(char*)cur_file_name));
}
l= MIN(loc,limit);
if(l>cur_buffer&&cur_buffer!=NULL)
{
if((BUF_SIZE)(l-cur_buffer)>buf_size)
{
CLR_PRINTF(error,
("! TROUBLE IN ERROR ROUTINE. PLEASE REPORT THIS!\n"));
mark_error;
l= cur_buffer+MAX_ERR_BUF;
}
for(k= cur_buffer;k<l;k++)
if(*k==011)
putchar(' ');
else
putchar(*k>127?' ':XCHR(*k));
/* print the characters already read */
putchar('\n');/* Separate already read from not yet read. */
for(k= cur_buffer;k<l;k++)putchar(' ');/* Space out the next line. */
}
if(l!=NULL)
{
if((BUF_SIZE)(limit-l)>buf_size)
{
puts("! TROUBLE IN ERROR ROUTINE. PLEASE REPORT THIS!");
l= limit-MAX_ERR_BUF;
}
for(k= l;k<limit;k++)
putchar(*k>127?' ':XCHR(*k));
/* print the part not yet read */
}
if(limit!=NULL)
if(*limit==0174)putchar('|');/* End of code text in module names. */
putchar(' ');/* To separate the message from future asterisks. */
err_happened= YES;
}
}
}
fflush(stdout);mark_error;
mfree();/* Free up any |mod_trans| allocations. */
}
int
fatal FCN(VA_ALIST((err_origin,s1,fmt VA_ARGS)))
VA_DCL(
ERR_ORIGIN err_origin C0("Where the error came from")
CONST outer_char s1[]C0("Basic message.")
CONST outer_char fmt[]C2("Elaboration."))
{
VA_LIST(arg_ptr)
#if(NUM_VA_ARGS == 1)
ERR_ORIGIN err_origin;
CONST outer_char s1[];
CONST outer_char fmt[];
#endif
char temp[500];
VA_START(arg_ptr,fmt);
#if(NUM_VA_ARGS == 1)
err_origin= va_arg(arg_ptr,ERR_ORIGIN);
s1= va_arg(arg_ptr,outer_char*);
fmt= va_arg(arg_ptr,outer_char*);
#endif
printf("\n");
if(err_origin!=ERR_NULL)
{
CLR_PRINTF(fatal,("! (%s): ",origin_name[err_origin]));
}
CLR_PRINTF(fatal,((char*)s1));
vsprintf((char*)temp,(CONST char*)fmt,arg_ptr);
err0_print(ERR_NULL,temp,0);
history= fatal_message;
va_end(arg_ptr);
return wrap_up();/* It never really returns, but the compiler doesn't \
know that. */
}
int
confusion FCN(VA_ALIST((where,fmt0 VA_ARGS)))
VA_DCL(
CONST outer_char where[]C0("")
CONST outer_char fmt0[]C2(""))
{
outer_char fmt[200],temp[200];
VA_LIST(arg_ptr)
#if(NUM_VA_ARGS == 1)
CONST outer_char where[];
CONST outer_char fmt0[];
#endif
VA_START(arg_ptr,fmt0);
#if(NUM_VA_ARGS == 1)
where= va_arg(arg_ptr,outer_char*);
fmt0= va_arg(arg_ptr,outer_char*);
#endif
if(
nsprintf(fmt,OC("\n At %s: %s."),2,where,fmt0)>=(int)(200))OVERFLW("fmt","");
vsprintf((char*)temp,(CONST char*)fmt,arg_ptr);
beep(3);
return
fatal(ERR_NULL,OC("\n!!! \
I'M CONFUSED; this shouldn't happen. PLEASE REPORT THIS!!! "),OC(temp));
}
SRTN
overflow FCN((s,abbrev))
CONST outer_char s[]C0("Condition that caused overflow.")
CONST outer_char abbrev[]C1("Abbreviation for buffer.")
{
if(*abbrev=='\0')
{
fatal(ERR_NULL,OC("!!! Sorry, CAPACITY EXCEEDED: "),OC("%s contents too long."),(char*)s);
}
else
{
MEM HUGE*m= msearch(abbrev,0L);
fatal(ERR_NULL,OC("!!! Sorry, CAPACITY EXCEEDED: "),OC("Too many %s. Current number is %lu, absolute max is \
%lu. Use command-line option \"-y%s...\" to override default."),(char*)s,m->nunits,m->max,(char*)abbrev);
}
}
SRTN
new_sprm FCN((name,value))
CONST outer_char name[]C0("Name of parameter.")
int value C1("Integer value of parameters.")
{
char temp[100];
sprintf(temp,"Please increase style-file parameter `%s' from current value \
of %i;",name,value);
OVERFLW(temp,"");
}
#if(VMS)
#include stsdef /* Return codes. */
#endif /* |VMS| */
int
wrap_up()
{
/* --- Finish up --- */
if(statistics)
see_statistics();/* Invoked by command-line option~\.{-s}. \
(\FTANGLE\ and \FWEAVE\ each has its own version of \
|see_statistics|.) */
putchar('\n');
#if TIMING
prn_time();
#endif /* |TIMING| */
{
CLR_PRINTF(info,("[%s:",program==tangle?"FTANGLE":"FWEAVE"));
printf(" ");
switch(history)
{
case spotless:
CLR_PRINTF(info,("No errors were found."));break;
case harmless_message:
CLR_PRINTF(warning,
("%cDid you see the warning message(s) above?",beep(1)));
break;
case error_message:
CLR_PRINTF(error,
("%cPardon me, but I think I spotted something wrong.",beep(1)));
break;
case fatal_message:
CLR_PRINTF(fatal,("%cThat was a fatal error, my friend.",beep(2)));
break;
}/* There are no other cases. */
CLR_PRINTF(info,("]\n"));
set_color(NORMAL);
}
{
if(cur_prms.web&&cur_prms.web->File)
fclose(cur_prms.web->File);
if(cur_prms.change&&cur_prms.change->File)
fclose(cur_prms.change->File);
cls_files();/* Do stuff specific to \FTANGLE\ or \FWEAVE. */
}
#if(VMS)
switch(history)
{
case spotless:exit(STS$K_SUCCESS|STS$M_INHIB_MSG);
case harmless_message:exit(STS$K_INFO|STS$M_INHIB_MSG);
case error_message:exit(STS$K_ERROR|STS$M_INHIB_MSG);
case fatal_message:exit(STS$K_SEVERE|STS$M_INHIB_MSG);
}
#else
switch(history)
{
case spotless:
case harmless_message:
exit(0);
default:
exit(1);
}
#endif /* |VMS| */
return-1;/* Never really does this. */
}
char
beep FCN((n))
int n C1("")
{
if(beeps)
{
for(--n;n>0;n--)
printf("\007");
fflush(stdout);
return '\007';/* (Some compilers didn't understand \.{'\\a'}.) */
}
else
return '!';
}
SRTN
out_error FCN((fcn))
CONST outer_char fcn[]C1("")
{
fatal(ERR_C,OC("Output error"),OC("from %s (quota exceeded?)."),fcn);
}
boolean
verify FCN(VA_ALIST((fmt VA_ARGS)))
VA_DCL(
CONST outer_char fmt[]C2(""))
{
VA_LIST(arg_ptr)
outer_char buf[80];
VA_START(arg_ptr,fmt);
#if(NUM_VA_ARGS==1)
{
char*fmt0= va_arg(arg_ptr,char*);
va_arg(arg_ptr,int);
vprintf(out,fmt0,arg_ptr);
}
#else
vprintf((CONST char*)fmt,arg_ptr);
#endif;
va_end(arg_ptr);
printf(" [yes/no]? "),fflush(stdout);
WHILE()
{
gets(buf);
if(STRCMP(buf,"yes")==0||STRCMP(buf,"no")==0)
break;
printf(">>> Please answer ``yes'' or ``no'': ");
fflush(stdout);
}
return(STRCMP(buf,"yes")==0);
}
SRTN
scan_args(VOID)
{
outer_char wbflnm[MAX_FILE_NAME_LENGTH];
/* Build the command line in a buffer. */
cmd_ln_buf= cmd_line(argc,argv);
/* Add the arguments from the ini file \.{.fweb}. This resets |argc| and \
|argv|, and also ignores |argv[0]| from the command line. */
set_args(&argc,&argv);
/* Process all the arguments in order from left to right. */
do_args(YES,argc,argv,&found_web,wbflnm,&found_change);
if(statistics)
mem_avail(0);/* How much memory is available at start? */
{
outer_char HUGE*dot_pos;
outer_char HUGE*p= NULL;
if(STRLEN(wbflnm)>MAX_FILE_NAME_LENGTH-5)
too_long();
if(STRCMP(wbflnm,"stdin")==0)STRCPY(web_file_name,wbflnm);
else
{
p= OC(STRRCHR(wbflnm,prefix_end_char));/* Is there a path? */
if((dot_pos= OC(STRCHR(p?p+1:wbflnm,wt_style.ext_delimiter)))==NULL
&&!try_extensions)
{/* Attach ``\.{.web}'' as a default. */
if(
nsprintf(web_file_name,OC("%s%cweb"),2,wbflnm,wt_style.ext_delimiter)>=(int)(MAX_FILE_NAME_LENGTH))OVERFLW("web_file_name","");
}
else{/* There's a dot, or we're trying extensions; treat the \
name as is. */
if(
nsprintf(web_file_name,OC("%s"),1,wbflnm)>=(int)(MAX_FILE_NAME_LENGTH))OVERFLW("web_file_name","");
if(!try_extensions)
TERMINATE(dot_pos,0);/* string now ends where the \
dot was */
}
}
{
if(p)
{/* Path was specified. */
STRNCPY(wbprefix,wbflnm,
PTR_DIFF(size_t,p,(outer_char HUGE*)wbflnm)+1);/* Path. */
STRCPY(wbflnm0,p+1);/* Root name. */
}
else
{/* No path specification. */
TERMINATE(wbprefix,0);/* No path. */
STRCPY(wbflnm0,wbflnm);/* Root name. */
}
}
}
{
read_sty(style_file_name,renamed_style);/* See \.{style.web}. */
{
DOT_DELIMITER HUGE*d= &wt_style.dot_delimiter;
d->begin= XORD(d->begin);
d->end= XORD(d->end);
if(program==tangle)
{
t_style.ASCII_fcn= x__to_ASCII((outer_char*)t_style.ASCII_fcn);
}
}
}
{
int k;
/* \WEAVE's output file. */
xpn_name(&tex_fname,MAX_FILE_NAME_LENGTH,tex_fname,wbflnm0);
if(*tex_fname=='\0')new_fname(&tex_fname,wbflnm0,OC("tex"));
/* \TANGLE's output files. */
for(k= 0;k<NUM_LANGUAGES;k++)
xpn_name(params.outp_nm+k,MAX_FILE_NAME_LENGTH,
params.outp_nm[k],wbflnm0);
set_name(C,wt_style.output_ext.C_);
set_name(C_PLUS_PLUS,wt_style.output_ext.Cpp_);
set_name(LITERAL,wt_style.output_ext.V_);
set_name(FORTRAN,wt_style.output_ext.N_);
set_name(FORTRAN_90,wt_style.output_ext.N90_);
set_name(RATFOR,wt_style.output_ext.R_);
set_name(RATFOR_90,wt_style.output_ext.R90_);
set_name(TEX,wt_style.output_ext.X_);
}
;
if(!(found_web||info_option))usage("!! Missing webfile name.\n",YES);
if(!found_change)*change_file_name= '\0';/* This means null file. */
}
outer_char HUGE*
cmd_line FCN((num_args,args))
int num_args C0("Number of arguments on command line.")
outer_char*args[]C1("Array of pointers to arguments.")
{
int k,len,l0,l1;
outer_char HUGE*buf,HUGE*b,HUGE*line0,HUGE*line1;
outer_char p[ESCAPE_LENGTH];/* The escaped argument. */
if(program==tangle)
{
line0= TANGLE_LINE0;
line1= TANGLE_LINE1;
}
else
{
line0= WEAVE_LINE0;
line1= WEAVE_LINE1;
}
/* Determine required buffer length. */
for(k= 0,len= 0;k<num_args;len+= STRLEN(args[k++])+1);
l0= STRLEN(line0);
l1= STRLEN(line1);
buf= GET_MEM("buf",2*(len+l0+l1),outer_char);
STRCPY(buf,line0);
b= buf+l0;
while(num_args-->0)
{
int n= esc_file_name(p,ESCAPE_LENGTH,*(args++));
STRNCPY(b,p,n);
b+= n;
*b++= ' ';
}
STRCPY(--b,line1);/* Kill off final blank. */
return buf;
}
SRTN
set_args FCN((pargc,pargv))
int HUGE*pargc C0("Pointer to the arg count; new value returned.")
outer_char HUGE*HUGE**pargv C1("Ptr to the array of ptrs; returned.")
{
int k,n;
outer_char HUGE*buffer,HUGE*b,/* Put one line from ini file into here. */
HUGE*temp,HUGE*t,/* Extract the argument into here. */
HUGE*HUGE*a,/* The current ini arg. */
HUGE*pc;/* Pointer to possible comment character in ini line. */
boolean blank;
/* Allocate temporary buffers. */
buffer= GET_MEM("buffer",T_SIZE,outer_char);
temp= GET_MEM("temp",T_SIZE,outer_char);
/* We start by assuming there is no ini file, hence no argument. */
k= 0;
{
outer_char ini_file_name[MAX_FILE_NAME_LENGTH];
outer_char*p_root,ini_root[MAX_FILE_NAME_LENGTH];
#if HAVE_GETENV /* \.{Machine-dependent}: Understands |getenv|. */
p_root= GETENV(ENV_INI);
if(p_root)
STRCPY(ini_root,p_root);
else
STRCPY(ini_root,OC(FWEB_INI));
more_includes(&incl,GETENV(ENV_INCLUDES));/* Included \FWEB\ files. */
more_includes(&hdr_incl,GETENV(ENV_HDR_INCLUDES));
/* Included C files to be scanned by preprocessor. */
#else
STRCPY(ini_root,OC(FWEB_INI));
#endif /* |HAVE_GETENV| */
ini_file= FOPEN(mk_fname(ini_file_name,MAX_FILE_NAME_LENGTH,
HOME,YES,ini_root),"r");
}
/* If there is an ini file, then put the arguments into an array. */
if(ini_file)
{
for(a= ini_args;k<MAX_INI_ARGS;)
{
if(FGETS(buffer,T_SIZE,ini_file)==NULL)break;/* Read one line \
(including newline). */
/* Extract the string, disgarding the newline. If the line is blank, do \
nothing. */
blank= YES;
for(t= temp,b= buffer;*b;)
{
if(*b=='\n')break;
if(!isspace(*b))blank= NO;
*t++= *b++;
}
*t= '\0';
if(blank)continue;
/* Kill off any trailing comment. */
if((pc= OC(STRCHR(temp,INI_CMNT_CHAR)))!=NULL)TERMINATE(pc,0);
if(pc==temp)continue;/* The line was entirely a comment. */
*a= GET_MEM("ini arg",STRLEN(temp)+1,outer_char);/* Space for the \
argument. */
STRCPY(*a++,temp);/* Store ini argument. */
k++;
}
FCLOSE(ini_file);
}
/* Allocate space for all the arguments, both ini and command-line. (We \
don't count |argv[0]| from command line.) */
pn= new_args= GET_MEM("new_args",n= *pargc-1+k,outer_char HUGE*);
acopy(BEFORE_CHAR,ini_args,k);
/* Put those starting with '\.+' or '\.-' first. */
pn0= pn;/* Mark end of the ini stuff. */
acopy(MIDDLE_CHAR,(outer_char HUGE**)(*pargv),*pargc);
/* Then the command-line arguments. */
acopy(AFTER_CHAR,ini_args,k);/* Then the rest. */
/* Return the new number and array of arguments. */
*pargc= n;
*pargv= new_args;
FREE_MEM(buffer,"buffer",T_SIZE,char);
FREE_MEM(temp,"temp",T_SIZE,char);
}
SRTN
more_includes FCN((pincl,incl_list0))
INCL_PATHS*pincl C0("Structure to fill")
outer_char*incl_list0 C1("")
{
unsigned n;
BUF_SIZE old_size;
if(!incl_list0)
return;
/* Strip off useless opening colon. */
while(*incl_list0==':')
incl_list0++;
if((n= STRLEN(incl_list0))==0)
return;
old_size= incl.size;
pincl->size+= n+2;/* Allow for trailing colon and null byte. */
if(!pincl->list)
{/* List hasn't been allocated yet. */
pincl->list= GET_MEM("incl_list",pincl->size,outer_char);
STRCPY(pincl->list,incl_list0);
pincl->num= chr_cnt(pincl->list,':');/* Count number of entries. */
}
else
{/* Add more to the list. */
pincl->list= (outer_char HUGE*)REALLOC(pincl->list,pincl->size,
old_size);
if(pincl->list==NULL)
fatal(ERR_NULL,OC("!! NO MORE MEMORY"),OC(" (more_includes)"));
STRCAT(pincl->list,incl_list0);
pincl->num+= chr_cnt(incl_list0,':');
}
/* Ensure list ends in a colon. */
if(pincl->list[n-1]!=':')
{
pincl->list[n]= ':';
pincl->num++;
}
}
int
chr_cnt FCN((s,c))
outer_char*s C0("String to be searched for occurrences of |c|")
outer_char c C1("Search character")
{
int n;
for(n= 0;*s;s++)
if(*s==c)
n++;
return n;
}
char*
mk_fname FCN((buffer,buf_len,env_var,print_msg,file_name))
outer_char*buffer C0("Put result here.")
unsigned buf_len C0("Length of |buffer|.")
CONST outer_char*env_var C0("Variable that holds directory name.")
boolean print_msg C0("Flag for not recognizing |env_var|.")
CONST outer_char*file_name C1("The raw file name.")
{
outer_char*directory;/* Will hold result of |getenv|. */
#if HAVE_GETENV /* \.{Machine-dependent}: Understands |getenv|. */
if((directory= GETENV(env_var))==NULL)
{
if(print_msg)
printf("! I can't find environment \
variable \"%s\", so I'll look for file \"%s\" \
in directory \"%s\".\n",
(char*)env_var,(char*)file_name,
*wbprefix?(char*)wbprefix:".");
if(buf_chk(file_name,buf_len,
STRLEN(file_name)+STRLEN(wbprefix)))
return(char*)wt_style.null_file_name;
STRCPY(buffer,wbprefix);
STRCAT(buffer,file_name);
}
else
{/* Got a directory from the environment variable. */
if(buf_chk(file_name,buf_len,
STRLEN(directory)+1+STRLEN(file_name)))
return(char*)wt_style.null_file_name;
/* For Unix, home is of the form \
\.{/u/krommes}; for VMS, it's like \.{ux3:[krommes]}. */
#if !UNIX_PATH
if(
nsprintf(buffer,OC("%s%s"),2,directory,file_name)>=(int)(buf_len))OVERFLW("buffer","");
#else
if(
nsprintf(buffer,OC("%s%c%s"),3,directory,prefix_end_char,file_name)>=(int)(buf_len))OVERFLW("buffer","");
#endif /* |!UNIX_PATH| */
}
#else /* Doesn't understand |getenv|. */
if(buf_chk(file_name,buf_len,STRLEN(file_name)))
return(char*)wt_style.null_file_name;
STRCPY(buffer,file_name);
#endif /* |CAN_GETENV| */
return(char*)buffer;
}
boolean
buf_chk FCN((file_name,buf_len,needed))
CONST outer_char*file_name C0("Raw file name")
unsigned buf_len C0("Max space available")
unsigned needed C1("Requested")
{
if(needed>=buf_len)
{
printf("\n! Buffer too small to make complete file name from \
\"%s\"; opened \"%s\"\n",(char*)file_name,(char*)wt_style.null_file_name);
return YES;
}
return NO;
}
SRTN
acopy FCN((c,a,n))
outer_char c C0("Starting symbol.")
outer_char HUGE**a C0("Old array.")
int n C1("Number of arguments to be looked at.")
{
boolean is_before= BOOLEAN(c==BEFORE_CHAR||c=='+');
boolean is_middle= BOOLEAN(c==MIDDLE_CHAR);
boolean is_after= BOOLEAN(c==AFTER_CHAR);
int k;
/* Disgard the zeroth argument from the command line. */
if(is_middle)
{
k= 1;
a++;
}
else
k= 0;
/* Look at all the arguments; copy them if appropriate. */
for(;k<n;k++,a++)
{
boolean before_entry= BOOLEAN((*a)[0]==BEFORE_CHAR||(*a)[0]=='+');
/* The following somewhat inscrutable logic puts file names and ``after'' \
entries from \.{.fweb} into the ``after'' list. */
if((!is_before&&!before_entry)||(!is_after&&before_entry))
{
*pn= GET_MEM("*pn",STRLEN(*a)+1,outer_char);
STRCPY(*pn,*a);
if((*pn)[0]=='+'||(*pn)[0]==AFTER_CHAR)
(*pn)[0]= BEFORE_CHAR;
pn++;
}
}
}
SRTN
set_name FCN((l,output_ext))
LANGUAGE l C0("")
outer_char*output_ext C1("")
{
int k;
if(*params.outp_nm[k= lan_num(l)]=='\0')
new_fname(params.outp_nm+k,wbflnm0,output_ext);
}
outer_char HUGE*
xpn_name FCN((pout_name,buf_len,in_name,wbflnm0))
outer_char HUGE*HUGE*pout_name C0("The expanded result")
int buf_len C0("Length of above buffer")
CONST outer_char*in_name C0("File name possibly having a \.\#.")
CONST outer_char wbflnm0[]C1("Basic name of the web file.")
{
size_t n;/* Length of the root name. */
outer_char HUGE*t,HUGE*t0= NULL;
boolean buffered= BOOLEAN(*pout_name==in_name);
if(buffered)t= t0= GET_MEM("xpn buffer",buf_len,outer_char);
else t= *pout_name;
for(;*in_name;in_name++)
if(*in_name=='#')
{
n= STRLEN(wbflnm0);
STRNCPY(t,wbflnm0,n);
t+= n;
}
else*t++= *in_name;
TERMINATE(t,0);
if(buffered)
{
new_fname(pout_name,t0,NULL);
FREE_MEM(t0,"xpn buffer",buf_len,outer_char);
}
return*pout_name;
}
SRTN
read_aux(VOID)
{
outer_char aux_file_name[MAX_FILE_NAME_LENGTH];
FILE*fa;
outer_char buffer[AUX_LEN];
int aline= 0;/* Counts line in the \.{.aux} file. */
sixteen_bits modno,modno0;
outer_char smodno[10],smodno0[10],spageno[10],ssecno[100];
int n;
SECT_INFO*ps;/* Points to current info structure. */
int pmcount= 1;/* Number of sections per page. */
long modno_ref= -1;/* Last reference module number. It's |long| to deal \
with the possibility of 16-bit integers, where |-1| would be the \
maximum module number. */
next_mod_name= mod_names= GET_MEM("mod_names",MAX_MOD_NAMES,
outer_char HUGE*);
last_mod_name= mod_names+MAX_MOD_NAMES;
if(TeX_processor!=LaTeX_p)
return;
{
outer_char*dot_pos;/* For finding extension in file name. */
dot_pos= OC(STRCHR(tex_fname,wt_style.ext_delimiter));
if(dot_pos==NULL)
n= STRLEN(tex_fname);
else
n= PTR_DIFF(int,dot_pos,tex_fname);
STRNCPY(aux_file_name,tex_fname,n);
if(
nsprintf(aux_file_name+n,OC("%caux"),1,wt_style.ext_delimiter)>=(int)(MAX_FILE_NAME_LENGTH))OVERFLW("aux_file_name+n","");
fa= FOPEN(aux_file_name,"r");
if(!fa)
{
printf("(No %s file.)\n",(char*)aux_file_name);
return;
}
else
reading(aux_file_name,YES);
}
modno= 0;/* In case there's nothing in the \.{.aux} file. */
while(FGETS(buffer,AUX_LEN,fa))
{
aline++;
if(STRNCMP(buffer,"\\Newlabel",9)!=0)
continue;
{
#if(!ANSI_SSCANF)
{
err0_print(ERR_C,OC("Sorry, non-ANSI sscanf; can't read .aux file"),0);
return;
}
#endif
n= sscanf((char*)(buffer+9),"%*c%[^}]%*3c%[^}]%*2c%[^}]%*3c%[^}]",
(char*)smodno,(char*)ssecno,(char*)spageno,(char*)smodno0);
if(n!=4)
{
err0_print(ERR_C,OC("Invalid \\Newlabel format in %s file, line %d"),2,aux_file_name,aline);
return;
}
modno= (sixteen_bits)ATOI(smodno);
if(modno>=max_modules)
OVERFLW("sections","m");
ps= sect_info+modno;
ps->secno= GET_MEM("ps->secno",STRLEN(ssecno)+1,outer_char);
STRCPY(ps->secno,ssecno);
ps->pageno= (sixteen_bits)ATOI(spageno);
ps->modno0= modno0= (sixteen_bits)ATOI(smodno0);
/* Check to see whether there was more than one section on a page. */
sect_info[modno-1].subpage_flag= YES;
if((long)modno0==modno_ref)
pmcount++;/* More than one section on page. */
else
{/* Start of new page. */
if(pmcount==1)
sect_info[modno-1].subpage_flag= NO;
modno_ref= (long)modno0;
pmcount= 1;
}
}
}
sect_info[modno].subpage_flag= BOOLEAN(pmcount!=1);
fclose(fa);
}
outer_char HUGE*
mod_trans FCN((prefix,modno))
outer_char*prefix C0("")
sixteen_bits modno C1("")
{
outer_char HUGE*mod_temp= GET_MEM("mod_temp",NMOD_TEMP,outer_char);
SECT_INFO*ps= sect_info+modno;
if(ps->secno)
{
outer_char c,letter[2];
letter[1]= '\0';
c= (ps->subpage_flag?
XCHR(modno-ps->modno0+0141-1):'\0');
if(c)
{
if(XORD(c)>0172)
c= '?';
else if(c==0140)
c= '\0';
}
letter[0]= c;
if(
nsprintf(mod_temp,OC("%s %d (sect. %s, p. %d%s)"),5,prefix,modno,ps->secno,ps->pageno,letter)>=(int)(NMOD_TEMP))OVERFLW("mod_temp","");
}
else
{
if(
nsprintf(mod_temp,OC("%s %d"),2,prefix,modno)>=(int)(NMOD_TEMP))OVERFLW("mod_temp","");
}
if(next_mod_name==last_mod_name)
confusion(OC("mod_trans"),OC("too many unfreed mod names"));
return*(next_mod_name++)= mod_temp;
}
SRTN
mfree(VOID)
{
if(!mod_names)
return;/* For errors happening during the command line. */
/* Don't mess with this next construction; tricky on some systems. The form \
|for(--next_mod_name; next_mod_name >= mod_names; next_mod_name--)| doesn't \
always work. */
while(next_mod_name>mod_names)
{
next_mod_name--;
FREE(*next_mod_name);
}
}
int
lan_num FCN((Language))
LANGUAGE Language C1("")
{
proper_language:
switch(Language)
{
case C:return 0;
case RATFOR:return 1;
case FORTRAN:return 2;
case TEX:return 3;
case LITERAL:return 4;
case C_PLUS_PLUS:return 5;
case RATFOR_90:return 6;
case FORTRAN_90:return 7;
case NO_LANGUAGE:Language= GLOBAL_LANGUAGE;goto proper_language;
default:Language= global_language;goto proper_language;
}
}
LANGUAGE
lan_enum FCN((num))
int num C1("Integer index of the language.")
{
switch(num)
{
case 0:return C;
case 1:return RATFOR;
case 2:return FORTRAN;
case 3:return TEX;
case 4:return LITERAL;
case 5:return C_PLUS_PLUS;
case 6:return RATFOR_90;
case 7:return FORTRAN_90;
default:return NO_LANGUAGE;
}
}
int
lan_index FCN((Language))
LANGUAGE Language C1("")
{
proper_language:
switch(Language)
{
case C:return 0;
case RATFOR:
case FORTRAN:return 1;
case TEX:return 2;
case LITERAL:return 3;
case C_PLUS_PLUS:return 4;
case RATFOR_90:
case FORTRAN_90:return 5;
case NO_LANGUAGE:Language= GLOBAL_LANGUAGE;goto proper_language;
default:Language= global_language;goto proper_language;
}
}
SRTN
do_args FCN((doing_cmd_line0,argc,argv,pfound_web,wbflnm,pfound_change))
boolean doing_cmd_line0 C0("")
int argc C0("")
outer_char HUGE*argv[]C0("")
boolean HUGE*pfound_web C0("")
outer_char wbflnm[]C0("")
boolean HUGE*pfound_change C1("")
{
boolean a_file_name;/* Is an actual file name supplied from the command line? */
outer_char HUGE*dot_pos;/* Position of |'.'| (or more generally, \
|wt_style.ext_delimiter|) in the argument */
IN_STYLE outer_char HUGE*sprm_ptr0,HUGE*sprm_ptr;
doing_cmd_line= doing_cmd_line0;
cmd_prms= NO;
*pfound_web= *pfound_change= NO;
while(argc-->0)
{
if(!cmd_prms&&argv==pn0)
{/* Note beginning of command-line parameters. */
cmd_prms= YES;
sprm_ptr0= sprm_ptr;
}
pa= *(argv++);/* Beginning of current argument string. */
/* Arguments that don't begin with a hyphen, or that are just a single \
hyphen with no trailing stuff, mean file names. */
if((a_file_name= BOOLEAN(*pa!='-'))||*(pa+1)=='\0')
{
if(doing_cmd_line)
{
if(!*pfound_web)
{
STRCPY(wbflnm,THE_FILE_NAME);
*pfound_web= YES;
}
else if(!*pfound_change)
{
if(a_file_name&&STRLEN(pa)>MAX_FILE_NAME_LENGTH-5)
too_long();
/* For VMS, should skip over brackets here. */
if(a_file_name&&(dot_pos= OC(STRCHR(pa,wt_style.ext_delimiter)))==NULL
&&!try_extensions)
{
if(
nsprintf(change_file_name,OC("%s%cch"),2,pa,wt_style.ext_delimiter)>=(int)(MAX_FILE_NAME_LENGTH))OVERFLW("change_file_name","");
}
else
{
if(
nsprintf(change_file_name,OC("%s"),1,THE_FILE_NAME)>=(int)(MAX_FILE_NAME_LENGTH))OVERFLW("change_file_name","");
}
*pfound_change= YES;
}
else
{
printf("! Warning: Ignoring multiple change file \"%s\".\n",
(char*)THE_FILE_NAME);
mark_harmless;
continue;
}
;
}
else
{
printf("\n! File name \"%s\" is not allowed as optional argument; \
ignored.\n",pa);
mark_harmless;
}
}
else
{
outer_char mc;
outer_char cmd_symbol;/* The character after the hyphen. */
pa++;/* |pa| now points to the character after the hyphen. */
if(*pa=='-')
{/* Second hyphen means negate. */
not= YES;
pa++;/* Skip second hyphen. */
}
else
not= NO;
reswitch:
switch(cmd_symbol= *pa++)
{/* |pa| now positioned after command symbol---e.g., to optional \
argument. */
case '1':
case '2':
tracing= cmd_symbol-'0';break;
case '@':
{
if(!at_codes)
{
at_codes= GET_MEM("at_codes",200,ASCII);/* 200 is KLUDGE! */
at_codes[0]= '\0';
}
STRCAT(at_codes,to_ASCII(pa));
info_option= YES;
}
break;
case 'a':
case 'A':
{
#if(TRANSLATE_ASCII || DEBUG_XCHR)
translate_ASCII= YES;/* Force it for the cases that really need it. */
#else
translate_ASCII= NOT(TRANSLATE_ASCII0);
#endif
}
break;
case 'b':
{
params.Block_nums[LN(FORTRAN)]
= params.Block_nums[LN(FORTRAN_90)]
= params.Block_nums[LN(RATFOR)]
= params.Block_nums[LN(RATFOR_90)]
= NOT(BLOCK_NUMS);
}
break;
case 'B':
beeps= NOT(BEEPS);
break;
case 'c':case 'C'
:
{
cant_negate(pa-2);
Cpp= BOOLEAN(*pa=='+');/* The commands \.{-c+} or \.{-c++} turn on \
knowledge of \.{C++}. */
if(Cpp)while(*pa=='+')pa++;/* Skip the pluses. */
switch(*pa)
{
case '{':
set_filter(Cpp?C_PLUS_PLUS:C);
break;
case '\0':
ini_language(XORD(*LANGUAGE_CODE(C)));
break;
default:
break;
}
}
break;
case 'D':
{
if(*pa=='[')
{
for(++pa;*pa!=']';pa++)
switch(*pa)
{
case 'i':
case 'I':
rsrvd.intrinsics= YES;
break;
case 'k':
case 'K':
rsrvd.keywords= YES;
break;
case 'r':
case 'R':
rsrvd.reserveds= YES;
break;
case '\0':
err0_print(ERR_C,OC("Missing ']' inserted after optional argument \
list to `-D'"),0);
break;
default:
err0_print(ERR_C,OC("Optional argument to `-D' must be one of \
'i', 'k', or 'r'"),0);
break;
}
pa++;/* Advance past the \.{']'}. */
}
else
{
if(!(*pa=='\0'||*pa=='*'||isalpha(*pa)))
{
err0_print(ERR_C,OC("Either nothing, a letter, '*', or '[' \
must follow `-D'; option ignored"),0);
break;
}
rsrvd.reserveds= rsrvd.intrinsics= rsrvd.keywords= YES;
}
rsrvd.args= pa;/* Points to `\.{*}' or letters to match. */
info_option= YES;
}
break;
case 'd':
number_dos= NOT(NUMBER_DOS);/* NOTE: falls through to next case! */
case ':':
{
cant_negate(pa-2);
max_stmt= STARTING_DO_NUM;
if(*pa)
{/* Optional starting line number specified. */
max_stmt= ATOL(pa);
if(max_stmt>99999L)
err0_print(ERR_C,OC("Starting DO number must be < 99999; assuming %lu"),1,max_stmt= STARTING_DO_NUM);
}
}
break;
case 'e':
try_extensions= NOT(TRY_EXTENSIONS);break;
case 'E':
{
cant_negate(pa-2);
if(*pa)wt_style.ext_delimiter= *pa;
else
err0_print(ERR_C,OC("Missing character after -E option; option ignored"),0);
}
break;
case 'f':
subscript_fcns= NOT(SUBSCRIPT_FCNS);break;
case 'F':
compare_outfiles= NOT(COMPARE_OUTFILES);break;
case 'g':
dbg_output= NOT(DBG_OUTPUT);break;
case 'h':
cant_negate(pa-2);
help();
break;
case 'H':
{
outer_char HUGE*p= pa;
more_H:
switch(*p++)
{
case 'r':
rmv_files= NOT(RMV_FILES);/* For debugging. */
goto more_H;
case 'x':
quoted_includes= NOT(QUOTED_INCLUDES);
goto more_H;
case 'X':
all_includes= NOT(ALL_INCLUDES);
goto more_H;
case '\0':
read_iformats= NOT(READ_IFORMATS);
break;
default:
bad_option();
break;
}
}
break;
case 'i':
{
switch(*pa)
{
case 'x':
index_hidden= NOT(INDEX_HIDDEN);/* Falls through. */
case '\0':
toggle_includes= NOT(TOGGLE_INCLUDES);break;
case '!':
skip_includes= NOT(SKIP_INCLUDES);break;
default:
bad_option();break;
}
}
break;
case 'I':
{
more_includes(read_iformats?&hdr_incl:&incl,pa);
/* Add to include path list. */
}
break;
case 'j':
skip_ifiles= NOT(SKIP_IFILES);break;
case 'k':
lc_keywords= NOT(LC_KEYWORDS);break;
case 'l':
{
prn_input_lines= BOOLEAN(YES^not);
if(*pa)
if(isdigit(*pa)||*pa=='-')
{
outer_char*colon_pos;
start_line= ATOL(pa);
if((colon_pos= OC(STRCHR(pa,':')))==NULL)
end_line= LONG_MAX;
else end_line= ATOL(colon_pos+1);
}
else
{
printf("! Option `-l' must be followed by integer.\n");
mark_harmless;
}
/* Negative line numbers are undocumented; they're for the developer. */
if(start_line<0)
{
start_line= -start_line;
prn_input_addresses= YES;
}
}
break;
case 'L':
{
switch(*pa)
{
case 'c':case 'C'
:
case 'n':case 'N'
:
case 'r':case 'R'
:
goto reswitch;
case 'v':case 'V'
:
cant_negate(pa-2);
switch(*(pa+1))
{
case '{':
set_filter(LITERAL);
break;
case '\0':
ini_language(XORD(*LANGUAGE_CODE(LITERAL)));
break;
default:
bad_lcmd("argument",pa-2);
break;
}
break;
case 'x':case 'X'
:
cant_negate(pa-2);
switch(*(pa+1))
{
case '{':
set_filter(TEX);
break;
case '\0':
ini_language(XORD(*LANGUAGE_CODE(TEX)));
break;
default:
bad_lcmd("argument",pa-2);
break;
}
break;
default:
bad_lcmd("command",pa-2);
break;
}
}
break;
case 'm':
case 'M':
{
switch(*pa)
{
case '4':
/* Recognize \.{m4} definitions. */
cant_negate(pa-2);
m4= !M4_;
break;
case ';':
/* Automatically append pseudo-semi to \.{WEB} macro definition. */
auto_app_semi= NOT(AUTO_APP_SEMI);
break;
case '\0':
err0_print(ERR_C,OC("Missing id for 'm' option"),0);
break;
default:
if(not)goto undefine_macro;
define_macro:
mc= *pa;
if(!(isalpha(mc)||mc=='_'||mc=='$'))
err0_print(ERR_C,OC("Macro definition may not start with \
'%c'; -m option ignored"),1,mc);
else SAVE_MACRO(pa);/* Macro definition. */
break;
}
}
break;
case 'N':
nuweb_mode= NOT(NUWEB_MODE);
break;
case 'n':
FR_args(FORTRAN);
break;
case 'o':
overload_ops= NOT(OVERLOAD_OPS);
break;
case 'p':
{
IN_STYLE outer_char HUGE*sprm_buf,HUGE*sprm_ptr,HUGE*sprm_end;
int n= STRLEN(pa);
size_t nbuf,nused;
if(!sprm_buf)
{/* Allocate the style-parameter buffer. */
sprm_ptr= sprm_buf= GET_MEM("sprm_buf",SPRM_LEN,outer_char);
sprm_end= sprm_buf+SPRM_LEN;
nbuf= SPRM_LEN;
}
if(sprm_ptr+(n+2)>=sprm_end)
{/* Reallocate a larger buffer. */
BUF_SIZE old_size;
nused= PTR_DIFF(size_t,sprm_ptr,sprm_buf);
old_size= nbuf;
nbuf= PTR_DIFF(size_t,sprm_end,sprm_buf)+SPRM_LEN;
if((sprm_buf= (outer_char HUGE*)REALLOC(sprm_buf,
nbuf*sizeof(outer_char),old_size*sizeof(outer_char)))==NULL)
OVERFLW("sprm_buf",0);
sprm_ptr= sprm_buf+nused;
sprm_end= sprm_ptr+nbuf;
}
/* Add a line (terminated with space and newline). */
STRCPY(sprm_ptr,pa);
sprm_ptr+= n;
*sprm_ptr++= ' ';
*sprm_ptr++= '\n';
}
break;
case 'P':
{
switch(*pa)
{
default:
err0_print(ERR_C,OC("'%c' is invalid option for -X; must be either 'L' \
(LaTeX) or 'T' (TeX). LaTeX is assumed"),1,*pa);/* Falls through to \LaTeX\ case. */
case '\0':
case 'L':
TeX_processor= LaTeX_p;
break;
case 'T':
TeX_processor= TeX_p;
break;
}
}
break;
case 'q':
free_form_input= NOT(FREE_FORM_INPUT);
Ratfor77= NOT(RATFOR77);
break;
case 'r':case 'R'
:
if(!RAT_OK("Language command ignored"))
break;
FR_args(RATFOR);
break;
case 's':
{
statistics= NOT(STATISTICS);
/* The format ``\.{-sm100}'' says to display memory allocations for sizes \
$>= 100$ bytes. */
if(*pa)
if(*pa=='m')
{
pa++;/* |pa| positioned to byte size. */
show_mem= NOT(SHOW_MEM);
if(isdigit(*pa))show_size= ATOL(pa);
}
else
{
printf("! Option \"%s\" is invalid.\n",(char*)(pa-2));
mark_harmless;
}
}
break;
case 't':
{
cant_negate(pa-2);
ntrunc();
}
break;
case 'T':
{
outer_char HUGE*p= pa;
while(*p)
switch(*p++)
{
case 'D':
deferred_macros= NOT(DEFERRED_MACROS);
break;
case 'v':
top_version= NOT(TOP_VERSION);
break;
case '%':
keep_trailing_comments= NOT(KEEP_TRAILING_COMMENTS);
break;
case '#':
auto_line= NOT(AUTO_LINE);
break;
default:
bad_option();
break;
}
}
break;
case 'u':
{
if(not)
goto define_macro;
undefine_macro:
if(*pa=='\0')
err0_print(ERR_C,OC("Missing identifier for `-u' option"),0);
else
save_macro(OC("#undef"),pa);
}
break;
case 'U':
lowercase_tokens= NOT(LOWERCASE_TOKENS);
break;
case 'v':
all_cmnts_verbatim= NOT(ALL_CMNTS_VERBATIM);
break;
case 'w':
if(*pa)
new_fname(&fwebmac,pa,NULL);
else
input_macros= NOT(INPUT_MACROS);
break;
case 'W':
{
outer_char HUGE*p= pa;
int n,n_old;
while(*p)
switch(*p++)
{
case '@':
if(!*p)
mod_warning_flag= ALL_WARNINGS;
else
mod_warning_flag= atoi(p++);
break;
case '1':
index_one= NOT(INDEX_ONE);
break;
case '[':
active_brackets= NOT(ACTIVE_BRACKETS);
break;
case 'H':
n= STRLEN(p);
n_old= STRLEN(extra_args);
if(!extra_args)
{
extra_args= GET_MEM("extra_args",n+1,outer_char);
STRCPY(extra_args,p);
}
else
{
if((extra_args= (outer_char*)REALLOC(extra_args,
(n_old+n+1)*sizeof(outer_char),
n_old*sizeof(outer_char)))==NULL)
OVERFLW("extra_args",0);
STRCAT(extra_args,p);
}
p+= n;
break;
case 'd':
defn_mask.outer_macros= NOT(PRN_OUTER_MACROS);
break;
case 'f':
defn_mask.formats= NOT(PRN_fORMATS);
break;
case 'F':
defn_mask.Formats= NOT(PRN_FORMATS);
break;
case 'l':
defn_mask.limbo= NOT(PRN_LIMBO);
break;
case 'm':
defn_mask.macros= NOT(PRN_MACROS);
break;
case 'v':
defn_mask.v= NOT(PRN_V);
break;
case 'w':
case 'W':
defn_mask.w= NOT(PRN_W);
break;
default:
bad_option();
break;
}
}
break;
case 'x':
flags3(BOOLEAN(not));
break;
case 'X':
if(*pa=='I')
{
makeindex= NOT(MAKEINDEX);
break;
}
flags3(BOOLEAN(!not));
break;
case 'y':
{
outer_char abbrev[80],HUGE*a;
BUF_SIZE nunits;
MEM HUGE*m,HUGE*mmin= NULL,HUGE*mmax= NULL;
boolean query_mode= NO;
cant_negate(pa-2);
if(!*pa)
{/* Query everything. */
mmin= mem;
mmax= mmin+(sizeof_mem/sizeof(MEM)-1);
query_mode= YES;
puts("Default memory allocation parameters:");
}
else
{/* Abbreviation specified. */
abbrev[0]= abbrev[1]= '\0';/* Ensure the abbreviation gets \
terminated properly. */
for(a= abbrev;isalpha(*pa);)
*a++= *pa++;
TERMINATE(abbrev,2);/* Max of two character abbreviation. */
if(!isdigit(*pa))
{/* Assume it's a question. */
mmin= msearch(abbrev,0L);
mmax= mmin+1;
query_mode= YES;
}
}
if(query_mode)
for(m= mmin;m<mmax;m++)
printf(" \"%-s\"%s x %d byte(s):\
min = %lu, current = %lu [%lu byte(s)], max = %lu.\n",
(char*)m->abbrev,m->abbrev[1]?"":" ",
m->bytes,
m->min,m->nunits,(m->nunits)*(m->bytes),m->max);
else
{/* Change setting. */
nunits= ATOL(pa);
msearch(abbrev,nunits);/* Set the value. */
}
info_option= YES;
}
break;
case 'z':
{
cant_negate(pa-2);
if(STRLEN(pa)<MAX_FILE_NAME_LENGTH)
{
if(STRCMP(pa,".")==0)
{/* Read default file in current directory. */
if(
nsprintf(style_file_name,OC(".%c%s"),2,PREFIX_END_CHAR,STYLE_FILE_NAME)>=
MAX_FILE_NAME_LENGTH)OVERFLW("./style_file_name","");
}
else
STRCPY(style_file_name,pa);
renamed_style= YES;
}
else
err0_print(ERR_C,OC("Style file name too long; must be less \
than %d characters"),1,MAX_FILE_NAME_LENGTH);
}
break;
case 'Z':
prn_style_defaults= BOOLEAN(!not);
style_args= pa;
info_option= YES;
break;
case '.':
dot_constants= NOT(DOT_CONSTANTS);
break;
case '\\':
bslash_continued_strings= NOT(BSLASH_CONTINUED_STRINGS);
break;
case '?':
chk_stmts= NOT(CHK_STMTS);
break;
case '[':
translate_brackets= NOT(TRANSLATE_BRACKETS);
break;
case '(':
case ')':
chk_ifelse= NOT(CHK_IFELSE);break;
case '>':
case '=':
cant_negate(pa-2);
if(doing_cmd_line||phase==2)
redirect_output();
break;
case '/':
params.CPP_comments[LN(FORTRAN)]
= params.CPP_comments[LN(FORTRAN_90)]
= params.CPP_comments[LN(RATFOR)]
= params.CPP_comments[LN(RATFOR_90)]
= BOOLEAN(YES^not);
break;
case '!':
params.Point_comments[LN(FORTRAN)]
= params.Point_comments[LN(FORTRAN_90)]
= params.Point_comments[LN(RATFOR)]
= params.Point_comments[LN(RATFOR_90)]
= BOOLEAN(YES^not);
break;
case '+':
compound_assignments= NOT(COMPOUND_ASSIGNMENTS);break;
case '#':
line_info= NOT(LINE_INFO);break;
default:
bad_option();
break;
}
}
;
}
}
SRTN
opt_args FCN((l))
ASCII l C1("")
{
ASCII arg_buffer[ARG_BUFFER_SIZE],*pa= arg_buffer,
*arg_buffer_end= arg_buffer+ARG_BUFFER_SIZE;
int argc;
outer_char HUGE*args[MAX_ARGS];
ini_language(l);/* Set language and initialize flags. */
if(!IS_WHITE(*loc))
{
if(*loc!=0133)
{/* Unbracketed command, as in \.{@c++}. */
*pa++= 055;/* Make it an honest command. */
*pa++= l;/* Don't forget the language. */
WHILE()
{
if(IS_WHITE(*loc)||*loc==0133)break;
if(*loc==0174&&parsing_mode==INNER)
{
err0_print(ERR_C,OC("WARNING: Code mode ended during \
unbracketed optional argument. Should there be white space after \
language command?"),0);
break;
}
COPY_TO_ARG_BUFFER(*loc++);
}
}
/* We allow bracketed commands to follow unbracketed ones. */
if(*loc==0133)
{
COPY_TO_ARG_BUFFER(040);
for(loc++;;)
{/* Skip the opening bracket; copy contents. */
if(*loc==0135)
{
loc++;/* Skip the ending bracket. */
break;
}
COPY_TO_ARG_BUFFER(*loc++);
}
}
TERMINATE(pa,0);/* Terminate |arg_buffer|. */
argc= to_args(to_outer(arg_buffer),args,MAX_ARGS);
do_args(NO,argc,args,&found_web,(outer_char*)NULL,&found_change);
}
fin_language();/* Do any further flag setup. */
}
SRTN
ini_language FCN((l))
ASCII l C1("Basic language code")
{
/* First we set the language. */
switch(l)
{
case 0143:case 0103
:
language= (Cpp?C_PLUS_PLUS:C);
break;
case 0162:case 0122
:
if(!RAT_OK("Invalid @r command; language set to C"))language= C;
else language= (Fortran88?RATFOR_90:RATFOR);
break;
case 0156:case 0116
:
language= (Fortran88?FORTRAN_90:FORTRAN);
break;
case 0166:case 0126
:
language= LITERAL;
break;
case 0170:case 0130
:
language= TEX;
break;
}
/* The following is for checking an override of the command-line language \
in the limbo section. */
if(doing_cmd_line)cmd_language= language;
ini0_language();
}
SRTN
ini0_language(VOID)
{
/* Set the output language. */
out_language= OUT_LANGUAGE(language);
/* Storing these numbers cuts down on the overhead of function calls. It \
also enables us to use the macros in the following |switch| properly. */
language_index= (short)lan_index(language);/* Maybe no longer used. */
language_num= (short)lan_num(language);
index_flag= YES;/* Most languages will cross-reference. */
switch(language)
{
case C:
Cpp= NO;
break;
case C_PLUS_PLUS:
Cpp= YES;/* Just a shorthand for |language==CPP|. */
break;
case FORTRAN:
case FORTRAN_90:
free_form_input= global_params.Free_form_input[language_num];
/* This can be turned on by the \.{-n\\} or \.{-n\&} options. */
auto_semi= global_params.Auto_semi[language_num];
break;
case RATFOR:
case RATFOR_90:
if(nuweb_mode)
err0_print(ERR_C,OC("SORRY, but Ratfor doesn't work yet with the N \
mode!"),0);
auto_semi= global_params.Auto_semi[language_num];
if(auto_semi)free_form_input= NO;
break;
case LITERAL:
nuweb_mode= YES;
line_info= NO;
index_flag= NO;
break;
case TEX:
break;
default:
break;
}
}
SRTN
fin_language(VOID)
{
ini_reserved(language);
switch(language)
{
case C:
break;
case RATFOR:
break;
case FORTRAN:
break;
case LITERAL:
break;
case TEX:
break;
default:
break;
}
frz_params();/* Make any local parameters. */
/* Output file name. For |program == weave|, |out_file == tex_file| by a \
macro definition in \.{typedefs.hweb}. */
if(program==tangle)
out_file= params.outp_file[lan_num(out_language)];
}
SRTN
frz_params(VOID)
{
cont_char= XORD(in_escape);/* Current continuation character (in |ASCII|). */
free_90= BOOLEAN(Fortran88&&free_form_input);
free_Fortran= BOOLEAN((language==FORTRAN_90)&&free_90);
if(is_FORTRAN_(language))
auto_semi= BOOLEAN(!free_Fortran);
if(program==tangle&&free_90)
switch(language)
{
case FORTRAN_90:
case RATFOR_90:
begin_comment_char[lan_num(FORTRAN_90)]=
(outer_char)CHOICE(free_90,'!','C');
break;
default:;
}
}
int
to_args FCN((p,args,max_args))
outer_char HUGE*p C0("")
outer_char HUGE*args[]C0("")
int max_args C1("")
{
int n;
for(n= 0;*p;p++)
{
if(n>=max_args)
{
err0_print(ERR_C,OC("Too many command-line or optional \
arguments; must be < %d"),1,max_args);
break;
}
while(isspace(*p))p++;/* Skip leading white space. */
args[n++]= p;/* Record start and count. */
for(p++;*p;p++)
if(isspace(*p)||!*p)break;/* Find end of argument. */
if(!*p)break;/* Get out at end of line. */
TERMINATE(p,0);/* Mark end of argument. */
}
return n;/* Number of arguments found. */
}
SRTN
help(VOID)
{
if(!*pa)
{
printf("! For help, please use options\n\n\
`-@' (query control codes),\n\
`-D' (query reserved words),\n\
`-y' (query memory allocations),\n\
`-Z' (query style-file parameters)\n\n\
or see the info(1) entry for FWEB."),fflush(stdout);
}
#if(HAVE_INFO)
{
outer_char temp[500],buf[500],*pmenus;
if(*pa)
pmenus= pa;/* There were command-line arguments. */
else
{/* No command-line arguments. Offer to enter \.{info}. */
printf(" To enter `info FWEB' now, type\n\n\
`?', for the top-level FWEB directory;\n\
`node-name' or `-n node-name', to go to a specific node like `Macros'; or\n\
a space-separated list of FWEB menu items.\n\n\
Type `q' to exit info. To abort now, hit Enter: "),fflush(stdout);
gets(buf);
pmenus= buf;
}
if(STRLEN(pmenus)>0)
{
if(*pmenus=='?'||*pmenus=='.')
pmenus++;
sprintf(temp,"info -f FWEB %s",pmenus);
system(temp);
}
}
#endif /* |HAVE_INFO| */
usage("",NO);/* In lieu of anything better. */
}
SRTN
FR_args FCN((Language))
LANGUAGE Language C1("")
{
int lnum;
cant_negate(pa-2);
if(isdigit(*pa))
switch(*pa++)
{/* Options \.{-n7} or \.{-n9}. */
case '7':
Fortran88= NO;
ini_language(XORD(*LANGUAGE_CODE(Language)));
break;
case '9':
Fortran88= YES;
ini_language(XORD(*LANGUAGE_CODE(Language)));
break;
default:
bad_loption(Language);break;
}
else
{
lnum= lan_num(language);/* We need to set this so that we can \
access the language arrays properly. ??? |language| ??? Used to be |Language| */
switch(*pa++)
{
case '\\':
case '&':
/* Set the continuation character; for \Fortran, turn on \
free-form syntax. */
if(is_FORTRAN_(Language))
params.Free_form_input[lnum]= NOT(FREE_FORTRAN);
params.In_escape[lnum]= *(pa-1);/* Continuation character. */
break;
case ';':
params.Auto_semi[lnum]= BOOLEAN(YES^not);
break;
case ':':
if(is_FORTRAN_(Language))
Fortran_label= NOT(FORTRAN_LABEL);
break;
case '!':
params.Point_comments[lnum]= BOOLEAN(YES^not);
break;
case '/':
params.CPP_comments[lnum]= BOOLEAN(YES^not);
break;
case ')':
params.Reverse_indices[lnum]= BOOLEAN(YES^not);
break;
case 'b':
case 'B':
params.Block_nums[lnum]= NOT(BLOCK_NUMS);break;
case 'g':
case 'G':
{
if(is_RATFOR_(Language))
{
if(!RAT_OK("'g' command ignored"))break;
{
while(*pa)
if(isalpha(*pa))
switch(*pa++)
{
case 'r':
case 'R':
g_ratio= STRTOD(pa,&pa);
if(g_ratio<MIN_G_RATIO)
{
err0_print(ERR_C,OC(
"Invalid 'g' option: %s must be >= %.1f"),2,"g_ratio",MIN_G_RATIO);
g_ratio= G_RATIO;
};
break;
case 'm':
case 'M':
marginal_cases=
(unsigned short)STRTOL(pa,&pa,10);
if(marginal_cases<MIN_MARGINAL_CASES)
{
err0_print(ERR_C,OC("Invalid 'g' option: %s must be >= %d"),2,"marginal_cases",MIN_MARGINAL_CASES);
marginal_cases= MARGINAL_CASES;
};
break;
case 's':
case 'S':
max_spread= STRTOL(pa,&pa,10);
if(max_spread<MIN_MAX_SPREAD)
{
err0_print(ERR_C,OC("Invalid 'g' option: %s must be >= %d"),2,"max_spread",MIN_MAX_SPREAD);
max_spread= MAX_SPREAD;
};
break;
default:
err0_print(ERR_C,OC("Invalid 'g' option: \
parameter type '%c'"),1,*(pa-1));
break;
}
}
;
}
else bad_loption(Language);
}
break;
case 'k':
suppress_cmds= BOOLEAN(YES^not);
{
if(!*pa)STRCPY(abbrev_cmds,"*");
else STRNCPY(abbrev_cmds,pa,NUM_RATFOR_CMDS);
}
break;
case 'K':
suppress_cmds= BOOLEAN(NO^not);
{
if(!*pa)STRCPY(abbrev_cmds,"*");
else STRNCPY(abbrev_cmds,pa,NUM_RATFOR_CMDS);
}
break;
case 'p':
if(is_FORTRAN_(Language))prn_semis= NOT(PRN_SEMIS);
break;
case '{':
pa--;
set_filter(Language);
break;
case '\0':
/* Specify the language. Note that the other commands don't. */
ini_language(XORD(*LANGUAGE_CODE(Language)));
break;
default:
bad_loption(Language);
break;
}
}
}
SRTN
save_macro FCN((cmd,t))
CONST outer_char HUGE*cmd C0("Name of the ``at'' command to put first.")
outer_char HUGE*t C1("Text of the definition.")
{
eight_bits HUGE*p;
boolean replace_equals= BOOLEAN(STRCMP(cmd,"m")==0);/* For macros, if an \
equals sign appears before a space, it will be turned into a space. */
if(program==weave)return;
p= mp;
/* Place command such as \.{@m} into buffer. */
*mp++= '@';
while(*cmd)
*mp++= *cmd++;/* Copy text of command. */
*mp++= ' ';
while(*t)
{
if(replace_equals)
if(*t=='=')
{
*t= ' ';
replace_equals= NO;
}
else if(*t==' ')replace_equals= NO;
*mp++= *t++;
}
*mp++= ' ';
*mp= '@';*(mp+1)= 'm';
/* After we've built it, convert to internal notation. */
for(;p<mp+2;p++)
*p= XORD(*p);
}
SRTN
divert FCN((buffer,end,stop))
ASCII HUGE*buffer C0("Start of the buffer.")
ASCII HUGE*end C0("End of the buffer.")
boolean stop C1("Stop when end is reached?")
{
stop_the_scan= stop;
fbuffer= cur_buffer;
flimit= limit;
floc= loc;
cur_buffer= loc= buffer;
limit= end;
from_buffer= YES;
}
SRTN undivert(VOID)
{
cur_buffer= fbuffer;
limit= flimit;
loc= floc;
from_buffer= NO;
}
SRTN
mem_avail FCN((at_end))
int at_end C1("0 for beginning, 1 for end")
{
if(at_end)
printf("\n Allocated maximum of %lu bytes dynamically; \
ended with %lu bytes.\n",max_mem,total_mem);
#if PRINT_AVAILABLE_MEMORY
printf(" Available memory: %lu bytes.\n",CORE_LEFT);
if(!at_end)
{
starting_memory= CORE_LEFT;/* Used in |smin0|. */
putchar('\n');
}
#endif
}
SRTN
stat0 FCN((name,size,num,max_num,abs_max_num,abbrev,ctrl_chars))
CONST outer_char*name C0("")
size_t size C0("")
BUF_SIZE num C0("")
BUF_SIZE max_num C0("")
BUF_SIZE abs_max_num C0("")
CONST outer_char*abbrev C0("")
CONST outer_char*ctrl_chars C1("")
{
printf(" %s [\"%s\"] x %u byte(s): %lu [%lu byte(s)] of %lu <= %lu%s\n",
(char*)name,(char*)abbrev,(unsigned)size,num,num*size,max_num,
abs_max_num,(char*)ctrl_chars);
}
BUF_SIZE
smin0 FCN((abs_max_num))
BUF_SIZE abs_max_num C1("")
{
return MIN(starting_memory,abs_max_num);
}
SRTN
ntrunc(VOID)
{
LANGUAGE l;
truncate_ids= NO;
if(!*pa)goto bad_t_option;
while(*pa)
{
if(isdigit(*pa))
l= (language==NO_LANGUAGE)?GLOBAL_LANGUAGE:language;
else switch(*pa++)
{
case 'c':case 'C'
:
l= lcase(C,'\0',C_PLUS_PLUS,'+',&pa);
break;
case 'r':case 'R'
:
l= lcase(RATFOR,'7',RATFOR_90,'9',&pa);
break;
case 'n':case 'N'
:
l= lcase(FORTRAN,'7',FORTRAN_90,'9',&pa);
break;
case 'v':case 'V'
:
l= LITERAL;break;
case 'x':case 'X'
:
l= TEX;break;
default:
bad_t_option:
err0_print(ERR_C,OC("Invalid -t option. Example: `-tn=6{_}'"),0);
return;
}
/* Skip over optional equals sign. */
if(*pa==LANGUAGE_SEPARATOR)pa++;
/* Set the maximum identifier length for language~|l|. */
truncate_ids=
BOOLEAN(CHOICE((tr_max[lan_num(l)]= (unsigned short)ATOI(pa))!=0,
YES,NO));
while(isdigit(*pa))pa++;/* Skip over the integer. */
if(*pa=='{')set_filter(l);
}
}
LANGUAGE
lcase FCN((l0,c0,l1,c1,pp))
LANGUAGE l0 C0("")
outer_char c0 C0("")
LANGUAGE l1 C0("")
outer_char c1 C0("")
outer_char HUGE*HUGE*pp C1("")
{
if(c0&&**pp==c0)
{
while(**pp==c0)(*pp)++;
return l0;
}
if(c1&&**pp==c1)
{
while(**pp==c1)(*pp)++;
return l1;
}
return l0;
}
SRTN
set_filter FCN((Language))
LANGUAGE Language C1("")
{
if(!*pa)return;/* In case there's no argument following the language cmd. */
if(*pa=='{')pa++;
filter_char[lan_num(Language)]= (char*)pa;/* Repoint to the string of \
characters following this command. */
/* Remove the closing bracket from the list. */
for(;*pa;pa++)
if(*pa=='}')
{
*pa++= '\0';
return;
}
}
SRTN
flags3 FCN((not))
boolean not C1("")
{
prn_contents= BOOLEAN(PRN_CONTENTS^not);
prn_index= BOOLEAN(PRN_INDEX^not);
prn_modules= BOOLEAN(PRN_MODULES^not);
xref_unnamed= BOOLEAN(XREF_UNNAMED^not);
if(!(*pa))
{/* No argument. Assume nothing is to be printed. */
*pa= '*';
*(pa+1)= '\0';
}
for(;*pa;pa++)
switch(*pa)
{
case '*':
case '/':
prn_contents= NOT(PRN_CONTENTS);
prn_index= NOT(PRN_INDEX);
prn_modules= NOT(PRN_MODULES);
break;
case 'c':
prn_contents= NOT(PRN_CONTENTS);
break;
case 'i':
prn_index= NOT(PRN_INDEX);
break;
case 'm':
prn_modules= NOT(PRN_MODULES);
break;
case 'u':
xref_unnamed= NOT(XREF_UNNAMED);
break;
default:
err0_print(ERR_C,OC("'%c' is invalid argument for `-x' or `-X'; \
must be element of set {*cim}"),1,*pa);
break;
}
no_xref= BOOLEAN(!(prn_index||prn_modules));
}
SRTN
redirect_output(VOID)
{
int k;
if(*pa=='\0')
{/* Empty argument; send stuff to |stdout|. */
new_fname(&tex_fname,OC("stdout"),NULL);
for(k= 0;k<NUM_LANGUAGES;k++)
new_fname(params.outp_nm+k,OC("stdout"),NULL);
}
else if(phase==2&&program==weave)
return;
else
{
outer_char c,HUGE*pname;
outer_char HUGE*q= (outer_char HUGE*)STRCHR(pa,LANGUAGE_SEPARATOR);
/* Is there an '='? */
if(q==pa)
{/* ``\.{->=new\_name}'' */
c= LANGUAGE_SEPARATOR;
pname= q+1;/* Point to file name. */
}
else if(q)
{/* ``\.{->c=new\_name}'' */
c= *pa++;/* Language symbol. */
pname= q;/* Point to \.=. */
}
else
{/* ``\.{->new\_name}'' */
c= LANGUAGE_SEPARATOR;
pname= pa;/* Point to file name. */
}
switch(c)
{
case 'c':case 'C'
:
set_fname(lcase(C,'\0',C_PLUS_PLUS,'+',&pa),pname,YES);
break;
case 'r':case 'R'
:
if(!RAT_OK("Redirection ignored"))break;
set_fname(lcase(RATFOR,'7',RATFOR_90,'9',&pa),pname,YES);
break;
case 'n':case 'N'
:
set_fname(lcase(FORTRAN,'7',FORTRAN_90,'9',&pa),pname,YES);
break;
case 'v':case 'V'
:
set_fname(LITERAL,pname,YES);
break;
case 'x':case 'X'
:
set_fname(TEX,pname,YES);
break;
case LANGUAGE_SEPARATOR:
#if 0 /* Don't want to do this; it screws up module labeling for \FWEAVE. */
new_fname(&tex_fname,pname,NULL);
#endif
for(k= 0;k<NUM_LANGUAGES;k++)
new_fname(params.outp_nm+k,pname,NULL);
break;
default:
err0_print(ERR_C,OC("Syntax error in output redirection \
command \"->\". Language must be one of 'c', 'r', 'n', `m', or `x', not '%c'"),1,*(pa-1));
break;
}
}
}
SRTN
set_fname FCN((l,s,check))
LANGUAGE l C0("Language")
outer_char HUGE*s C0("Remainder of command-line argument to parse")
boolean check C1("Do we check for beginning colon?")
{
if(program==weave)
err0_print(ERR_C,OC("Can't redirect FWEAVE's TeX output by individual \
languages. Use \"->\" or \"-%cname.ext\""),1,LANGUAGE_SEPARATOR);
if(check)
if(*s++!=LANGUAGE_SEPARATOR)
{
err0_print(ERR_C,OC("Expected '%c' after language in \"->\"; \
command ignored"),1,LANGUAGE_SEPARATOR);
return;
}
/* If the name begins with a '\.\#', it's filled in later with |wbflnm0|. */
new_fname(params.outp_nm+lan_num(l),*s?s:(outer_char HUGE*)"stdout",NULL);
}
SRTN
cant_negate FCN((s))
outer_char HUGE*s C1("")
{
if(not)
{
printf("! Can't negate option \"%s\"'; ignoring extra hyphen.\n",
(char*)s);
mark_harmless;
}
}
SRTN
bad_lcmd FCN((type,pa0))
CONST char*type C0("")
CONST outer_char HUGE*pa0 C1("")
{
err0_print(ERR_C,OC("Invalid language %s \"%s\""),2,type,pa0);
}
SRTN
bad_loption FCN((Language))
LANGUAGE Language C1("")
{
printf("! Invalid language option \"%s\" for %s.\n",
(char*)(pa-3),is_FORTRAN_(Language)?"Fortran":"Ratfor");
mark_harmless;
}
SRTN
usage FCN((msg,is_fatal))
CONST char*msg C0("")
boolean is_fatal C1("Fatal?")
{
if(is_fatal)
{
char c= wt_style.ext_delimiter;
fatal(ERR_NULL,OC(msg),OC("!! Usage: %s webfile[%cweb] \
[changefile[%cch]] [-option...]\n"),program==tangle?"ftangle":"fweave",c,c);
}
else
wrap_up();
}
SRTN
too_long(VOID)
{
fatal(ERR_NULL,OC("!! Filename too long: "),OC("%s."),(CONST outer_char*)pa);
}
SRTN
bad_option(VOID)
{
printf("! Unknown option \"%s\" ignored.\n",(char*)(pa-2));
mark_harmless;
}
SRTN
chk_override FCN((language0))
LANGUAGE language0 C1("")
{
if(language!=language0&&cmd_language!=NO_LANGUAGE&&cmd_language!=
language)
err0_print(ERR_C,OC("WARNING: Command-line language %s overridden in limbo by %s"),2,languages[lan_num(cmd_language)],languages[lan_num(language)]);
}
SRTN
new_fname FCN((pname,name,ext))
outer_char HUGE*HUGE*pname C0("")
outer_char*name C0("")
outer_char*ext C1("")
{
outer_char temp[MAX_FILE_NAME_LENGTH];
/* An empty |name| means allocate some space. */
if(!name)
*pname= GET_MEM("pname",DFLT_FNAME_LENGTH+1,outer_char);
else
{/* Otherwise, we possibly allocate the space and construct the \
name. */
char ext_delimiter[2];
FILE*temp_file_ptr;
ext_delimiter[0]= (char)wt_style.ext_delimiter;
ext_delimiter[1]= '\0';
if(
nsprintf(temp,OC("%s%s%s"),3,name,ext?
ext_delimiter:"",ext?ext:(outer_char*)"")>=(int)(MAX_FILE_NAME_LENGTH))OVERFLW("temp","");
/* Previously we used to reallocate the file name here. However, that \
leads to an egregious error, since if the block is actually moved the old \
pointers are still around on the stack and in various other hiding places. \
Now, we just allocate a new area if the name is new. */
was_opened(temp,0,pname,&temp_file_ptr);
}
}
unsigned
esc_file_name FCN((esc_name,max_length,name))
outer_char*esc_name C0("Put answer into here")
unsigned max_length C0("Maximum length of |esc_name|.")
outer_char*name C1("Put escapes into this name")
{
outer_char*pt,*pn;
unsigned n;
max_length--;/* Allow room for the final null. */
for(pt= esc_name,pn= name,n= 0;*pn;)
{
if(program==weave)
switch(*pn)
{
case '\\':case '$':case '#':case '%':
case '^':case '~':case '&':case '_':
if(n<max_length)
{
n++;
*pt++= '\\';
}
}
if(n<max_length)
{
n++;
*pt++= *pn++;
}
}
TERMINATE(pt,0);
return n;
}
SRTN
ASCII_file_write FCN((file_ptr,p0,n))
FILE*file_ptr C0("Standard file pointer.")
CONST ASCII HUGE*p0 C0("Start of the buffer.")
size_t n C1("Number of characters to write.")
{
CONST ASCII HUGE*p,HUGE*p1= p0+n;
ASCII atemp[1000],HUGE*a,HUGE*a1;
size_t n_out;
if(n==0)
return;
/* Translate any special characters into something readable. */
for(p= p0,a1= atemp;p<p1;a1++,p++)
switch(*p)
{
case interior_semi:
*a1= 073;
break;
case MACRO_ARGUMENT:
*a1++= 0133;
*a1++= 0133;
*a1++= (ASCII)(060+*(++p));
*a1++= 0135;
*a1= 0135;
break;
default:
*a1= *p;
break;
}
n= PTR_DIFF(size_t,a1,atemp);
/* Might be bigger than incoming~|n| because of macro arg. */
if(translate_ASCII)
{/* Convert to the outer world. */
outer_char temp[1000];
outer_char HUGE*t;
for(a= atemp,t= temp;a<a1;)
*t++= XCHR(*a++);
n_out= FWRITE(temp,n,file_ptr);
}
else
n_out= FWRITE(atemp,n,file_ptr);
if(n_out!=1)
{
fatal(ERR_NULL,OC("! WRITE ERROR: "),OC("nbytes = %u, %u items written\n%s"),(unsigned)n,(unsigned)n_out,strerror(errno));
}
}
#if !HAVE_STRERROR
char*
strerror FCN((errnum))
int errnum C1("")
{
static char temp[50];
sprintf(temp,"(strerror() is not available; errno = %d).",errnum);
return temp;
}
#endif /* |!HAVE_STRERROR| */
struct tm*
the_localtime(VOID)
{
time_t the_tm;
time_t time PROTO((time_t*tp));
time(&the_tm);
return localtime(&the_tm);
}
CONST outer_char*
the_day FCN((t))
CONST struct tm*t C1("")
{
return OC(day[t->tm_wday]);
}
#define NDATE 20
CONST outer_char*
the_cdate FCN((t))
CONST struct tm*t C1("")
{
static outer_char date_buf[NDATE];
if(
nsprintf(date_buf,OC("%s %d, %d"),3,month[t->tm_mon],t->tm_mday,1900+t->tm_year)>=NDATE)
OVERFLW("Date","");
return(CONST outer_char*)date_buf;
}
#undef NDATE
#define NTIME 8
CONST outer_char*
the_time FCN((t))
CONST struct tm*t C1("")
{
static outer_char time_buf[NTIME];
if(
nsprintf(time_buf,OC("%d:%02d"),2,t->tm_hour,t->tm_min)>=NTIME)
OVERFLW("Time","");
return(CONST outer_char*)time_buf;
}
#undef NTIME
#if TIMING
SRTN
ini_timer(VOID)
{
TIME(&time0);
clock0= clock();
}
#endif /* |TIMING| */
#if TIMING
SRTN
prn_time(VOID)
{
TIME_T time1;
double cpu,wall;
char less_than= NO;
char format[100];/* We build the format for the time output here. */
cpu= (clock()-clock0)/(double)(CLOCKS_PER_SEC);
TIME(&time1);
/* Because the real time is in units of seconds, we might get~0, so we'll \
be fancy and print an inequality in that case. */
if((wall= DIFFTIME(time1,time0))==0.0)
{
wall= 1.0;
less_than= YES;
}
SET_COLOR(timing);
/* --- CPU time --- */
sprintf(format,"CPU = %%.%df sec.",TIMING_WIDTH);
printf(format,cpu);
if(cpu>=60.0)printf(" (%.2f min.)",cpu/60.0);
/* --- WALL CLOCK time --- */
sprintf(format,"; REAL %%s %%.%df sec.",TIMING_WIDTH);
printf(format,less_than?"<=":"=",wall);
if(wall>=60.0)printf(" (%.2f min.).",wall/60.0);
/* --- PERCENTAGE CPU UTILIZATION --- */
printf(" CPU/REAL = %.1f%%.\n",100.0*(cpu/wall));
/* Debugging message: Check for compatibility. Because the timing routines \
may not be perfectly compatible through all decimal places, we check only \
that |cpu <= wall| to an accuracy of tenths of seconds. */
SET_COLOR(ordinary);
}
#endif /* |TIMING| */
SRTN
ini_program FCN((program0))
PROGRAM program0 C1("")
{
program= program0;/* Set global flag. */
the_system= OC(THE_SYSTEM);/* |THE_SYSTEM| is defined in \.{os.hweb}. */
local_banner= OC(LOCAL_BANNER);/* See \.{os.hweb} and \.{custom.web}. */
ini_style();/* Default style file initializations. */
}
SRTN
banner(VOID)
{
printf("This is %s",DEBUG_XCHR?"ScRaMbLeD ":"");
printf("%s",program==tangle?"FTANGLE":"FWEAVE");
printf(" [%s version %s (%s)]. %s\n",
(char*)the_system,(char*)version,(char*)release_date,
(char*)local_banner);
}
SRTN
reading FCN((in_name,emit_newline))
CONST outer_char*in_name C0("")
boolean emit_newline C1("")
{
CLR_PRINTF(info,("Reading"));putchar(' ');
CLR_PRINTF(in_file,("%s",(char*)in_name));
CLR_PRINTF(info,("..."));
if(emit_newline)
putchar('\n');
}
SRTN
writing FCN((print_write,out_name))
boolean print_write C0("")
CONST outer_char*out_name C1("")
{
if(print_write)
{CLR_PRINTF(info,("\nWriting"));putchar(' ');}
CLR_PRINTF(out_file,("%s",(char*)out_name));
CLR_PRINTF(info,("..."));
fflush(stdout);
}
SRTN
progress(VOID)
{
if(*(loc-1)==052)
{/* Found a starred section. */
if(err_happened)
{
putchar('\n');
err_happened= NO;
}
else putchar(' ');
CLR_PRINTF(module_num,("*%d",module_count));
}
UPDATE_TERMINAL;
}
int
nsprintf FCN(VA_ALIST((s,fmt,n VA_ARGS)))
VA_DCL(
outer_char*s C0("")
CONST outer_char*fmt C0("")
int n C2(""))
{
int num_char;
VA_LIST(arg_ptr)
#if(NUM_VA_ARGS == 1)
outer_char*s;
CONST outer_char*fmt;
int n;
#endif
VA_START(arg_ptr,n);
#if(NUM_VA_ARGS == 1)
s= va_arg(arg_ptr,outer_char*);
fmt= va_arg(arg_ptr,outer_char*);
va_arg(arg_ptr,int);
#endif
#if ANSI_SPRINTF
num_char=
#endif
vsprintf((char*)s,(CONST char*)fmt,arg_ptr);
#if !ANSI_SPRINTF
num_char= (int)STRLEN(s);
#endif
va_end(arg_ptr);
return num_char;
}
#endif /* Part 2 */
|