Hash :
60c9c198
Author :
Date :
2006-10-30T09:48:28
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
/*
* OpenBIOS - free your system!
* ( FCode tokenizer )
*
* scanner.c - simple scanner for forth files.
*
* This program is part of a free implementation of the IEEE 1275-1994
* Standard for Boot (Initialization Configuration) Firmware.
*
* Copyright (C) 2001-2005 by Stefan Reinauer <stepan@openbios.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*
*/
/* **************************************************************************
* Modifications made in 2005 by IBM Corporation
* (C) Copyright 2005 IBM Corporation. All Rights Reserved.
* Modifications Author: David L. Paktor dlpaktor@us.ibm.com
**************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef __GLIBC__
#define __USE_XOPEN_EXTENDED
#endif
#include <string.h>
#include <time.h>
#include <ctype.h>
#include "macros.h"
#include "stack.h"
#include "stream.h"
#include "emit.h"
#include "toke.h"
#include "dictionary.h"
#include "vocabfuncts.h"
#include "scanner.h"
#include "errhandler.h"
#include "tokzesc.h"
#include "conditl.h"
#include "flowcontrol.h"
#include "usersymbols.h"
#include "clflags.h"
#include "devnode.h"
#include "tracesyms.h"
#include "nextfcode.h"
#include "parselocals.h"
/* **************************************************************************
*
* Some VERY IMPORTANT global variables follow
*
**************************************************************************** */
u8 *statbuf=NULL; /* The word just read from the input stream */
u8 base=0x0a; /* The numeric-interpretation base */
/* pci data */
bool pci_is_last_image=TRUE;
u16 pci_image_rev=0x0001; /* Vendor's Image, NOT PCI Data Structure Rev */
u16 pci_vpd=0x0000;
/* Having to do with the state of the tokenization */
bool offs16 = TRUE; /* We are using 16-bit branch- (etc) -offsets */
bool in_tokz_esc = FALSE; /* TRUE if in "Tokenizer Escape" mode */
bool incolon = FALSE; /* TRUE if inside a colon definition */
bool haveend = FALSE; /* TRUE if the "end" code was read. */
int do_loop_depth = 0; /* How deep we are inside DO ... LOOP variants */
/* State of headered-ness for name-creation */
headeredness hdr_flag = FLAG_HEADERLESS ; /* Init'l default state */
/* Used for error-checking of IBM-style Locals */
int lastcolon; /* Location in output stream of latest colon-definition. */
/* Used for error reporting */
char *last_colon_defname = NULL; /* Name of last colon-definition */
char *last_colon_filename = NULL; /* File where last colon-def'n made */
unsigned int last_colon_lineno; /* Line number of last colon-def'n */
bool report_multiline = TRUE; /* False to suspend multiline warning */
unsigned int last_colon_abs_token_no;
/* Shared phrases */
char *in_tkz_esc_mode = "in Tokenizer-Escape mode.\n";
char *wh_defined = ", which is defined as a ";
/* **************************************************************************
* Local variables
**************************************************************************** */
static u16 last_colon_fcode; /* FCode-number assigned to last colon-def'n */
/* Used for RECURSE */
static bool do_not_overload = TRUE ; /* False to suspend dup-name-test */
static bool got_until_eof = FALSE ; /* TRUE to signal "unterminated" */
static unsigned int last_colon_do_depth = 0;
/* Local variables having to do with: */
/* ... the state of the tokenization */
static bool is_instance = FALSE; /* Is "instance" is in effect? */
static char *instance_filename = NULL; /* File where "instance" invoked */
static unsigned int instance_lineno; /* Line number of "instance" */
static bool fcode_started = FALSE ; /* Only 1 fcode_starter per block. */
static bool first_fc_starter = TRUE; /* Only once per tokenization... */
/* ... with the state of the input stream, */
static bool need_to_pop_source;
/* ... with the use of the return stack, */
static int ret_stk_depth = 0; /* Return-Stack-Usage-Depth counter */
/* ... and with control of error-messaging. */
/* Should a warning about a dangling "instance"
* be issued at the next device-node change?
*/
static bool dev_change_instance_warning = TRUE;
/* Has a gap developed between "instance" and its application? */
static bool instance_definer_gap = FALSE;
/* **************************************************************************
*
* Function name: skip_ws
* Synopsis: Advance the PC past all whitespace.
* Protect against pointer over-runs
*
* Inputs:
* Parameters: NONE
* Global Variables:
* pc Input-source Scanning pointer
* end End of input-source buffer
*
* Outputs:
* Returned Value: TRUE if PC reached END before non-blank char
* Global Variables:
* pc Advanced to first non-blank char, or to END
* lineno Incremented if encountered new-line along the way
*
* Error Detection:
* Return a TRUE if End of input-source buffer reached before
* non-blank character. Not necessarily an error; allow
* calling routine to decide...
*
**************************************************************************** */
static bool skip_ws(void)
{
bool retval = TRUE;
char ch_tmp;
for ( ; pc < end; pc++ )
{
ch_tmp = *pc;
if ( (ch_tmp != '\t') && (ch_tmp != ' ') && (ch_tmp != '\n' ) )
{
retval = FALSE;
break;
}
if ( ch_tmp == '\n') lineno++;
}
return ( retval );
}
/* **************************************************************************
*
* Function name: skip_until
* Synopsis: Advance the PC to the given character.
* Do not copy anything into statbuf.
* Protect against pointer over-runs
*
* Inputs:
* Parameters:
* lim_ch Limiting Character
* Global Variables:
* pc Input-source Scanning pointer
* end End of input-source buffer
*
* Outputs:
* Returned Value: TRUE if PC reached END before finding LIM_CH
* Global Variables:
* pc Advanced to first occurrence of LIM_CH, or to END
* lineno Incremented if encountered new-line along the way
*
* Error Detection:
* Return a TRUE if End of input-source buffer reached before
* desired character. Not necessarily an error; allow calling
* routine to decide...
*
**************************************************************************** */
bool skip_until( char lim_ch)
{
bool retval = TRUE;
char ch_tmp;
for ( ; pc < end; pc++ )
{
ch_tmp = *pc;
if ( ch_tmp == lim_ch )
{
retval = FALSE;
break;
}
if ( ch_tmp == '\n') lineno++;
}
return ( retval );
}
/* **************************************************************************
*
* Function name: get_until
* Synopsis: Return, in statbuf, the string from PC to the first
* occurrence of the given delimiter-character..
*
* Inputs:
* Parameters:
* needle The given delimiter-character
* Global Variables:
* pc Input-source Scanning Pointer
*
* Outputs:
* Returned Value: Length of the string obtained
* Global Variables:
* statbuf The string obtained from the input stream;
* does not include the delimiter-character.
* pc Bumped past the delimiter-character, unless
* it's a new-line, in which case leave it
* to be handled by get_word()
* Local Static Variables:
* got_until_eof Pass this as a signal that the end of the
* buffer was reached before the delimiter;
* Testing whether PC has reached END is
* not a sufficient indication.
*
* Error Detection:
* If string overflows statbuf allocation, ERROR, and
* return "no string" (i.e., length = 0).
* Otherwise, if delimiter not found before eof, keep string.
* Protection against PC pointer-over-run past END is
* provided by skip_until() . Reaching END will be
* handled by calling routine; pass indication along
* via Local Static Variable.
*
* Process Explanation:
* Skip the delimiter-character from further input, unless it's a
* new-line which will be skipped anyway. Let skip_until()
* and get_word() handle incrementing line-number counters.
* If skip_until() indicated reaching end-of-file, don't bump PC
*
* Revision History:
* Updated Thu, 14 Jul 2005 by David L. Paktor
* More robust testing for when PC exceeds END
* Involved replacing firstchar()
*
**************************************************************************** */
static signed long get_until(char needle)
{
u8 *safe;
unsigned long len = 0;
safe=pc;
got_until_eof = skip_until(needle);
len = pc - safe;
if (len >= GET_BUF_MAX )
{
tokenization_error( TKERROR,
"get_until buffer overflow. Max is %d.\n", GET_BUF_MAX-1 );
len = GET_BUF_MAX-1;
}
memcpy(statbuf, safe, len);
statbuf[len]=0;
if ( INVERSE(got_until_eof) )
{
if ( needle != '\n' ) pc++;
}
return len;
}
/* **************************************************************************
*
* We are going to use a fairly sophisticated mechanism to
* make a smooth transition between processing the body
* of a Macro, a User-defined Symbol or an FLOADed file
* and the resumption of processing the source file, so
* that the end-of-file will only be seen at the end of
* the primary input file (the one from the command-line).
* This mechanism will be tied in with the get_word() routine
*
* We are going to define a private data-structure in which
* we will save the state of the current source file,
* and from which, of course, we will recover it. Its
* fields will be:
* A pointer to the next structure in the list.
* The saved values of START END and PC
* The saved values of INAME and LINENO
* A flag indicating that get-word should "pause"
* before popping the source-stream because
* the input file will be changing.
* A place from which to save and recover the state of
* whether we're testing for "Multi-line" strings;
* to prevent undeserved "Multi-line" warnings
* during Macro processing.
* A pointer to a "resumption" routine, to call
* when resuming processing the source file;
* the routine takes a pointer parameter
* and has no return value. The pointer
* may be NULL if no routine is needed.
* The pointer to pass as the parameter to the
* resumption routine.
*
**************************************************************************** */
typedef struct source_state
{
struct source_state *next;
u8 *old_start;
u8 *old_pc;
u8 *old_end;
char *old_iname;
unsigned int old_lineno;
bool pause_before_pop;
bool sav_rep_multlin;
void (*resump_func)();
_PTR resump_param;
} source_state_t ;
static source_state_t *saved_source = NULL;
/* **************************************************************************
*
* Function name: push_source
* Synopsis: Save the state of the current source file, in the
* source_state data-structure LIFO linked-list.
*
* Inputs:
* Parameters:
* res_func Pointer to routine to call when resuming
* processing the saved source file.
* res_param Parameter to pass to res_func.
* Either or both pointers may be NULL.
* file_chg TRUE if input file is going to change.
* Global Variables:
* start Points to current input buffer
* end Points to end of current input buffer
* pc Input point in current buffer
* iname Name of current source file
* lineno Line number in current source file
* report_multiline Whether we're testing for "Multi-line"
* Local Static Variables:
* saved_source Pointer to the source_state data-structure
*
* Outputs:
* Returned Value: NONE
* Local Static Variables:
* saved_source Points to new source_state entry
* Memory Allocated
* for the new source_state entry
* When Freed?
* When resuming processing the source file, by drop_source().
*
* Process Explanation:
* The calling routine will establish the new input buffer via
* a call to init_inbuf() or the like.
*
**************************************************************************** */
void push_source( void (*res_func)(), _PTR res_parm, bool file_chg )
{
source_state_t *new_sav_src;
new_sav_src = safe_malloc( sizeof(source_state_t), "pushing Source state");
new_sav_src->next = saved_source;
new_sav_src->old_start = start;
new_sav_src->old_pc = pc;
new_sav_src->old_end = end;
new_sav_src->old_iname = iname;
new_sav_src->old_lineno = lineno;
new_sav_src->pause_before_pop = file_chg;
new_sav_src->sav_rep_multlin = report_multiline;
new_sav_src->resump_func = res_func;
new_sav_src->resump_param = res_parm;
saved_source = new_sav_src;
}
/* **************************************************************************
*
* Function name: drop_source
* Synopsis: Remove last saved state of source processing
* from the source_state LIFO linked-list,
* without (or after) restoring.
*
* Inputs:
* Parameters: NONE
* Local Static Variables:
* saved_source Pointer to the source_state data-structure
*
* Outputs:
* Returned Value: NONE
* Local Static Variables:
* saved_source Points to previous source_state entry
* Memory Freed
* Saved source_state entry that was just "dropped"
*
* Error Detection:
* None. Called only when linked-list is known not to be at end.
*
**************************************************************************** */
static void drop_source( void)
{
source_state_t *former_sav_src = saved_source;
saved_source = saved_source->next ;
free( former_sav_src);
}
/* **************************************************************************
*
* Function name: pop_source
* Synopsis: Restore the state of source processing as it was
* last saved in the source_state linked-list.
*
* Inputs:
* Parameters: NONE
* Local Static Variables:
* saved_source Pointer to the source_state data-structure
* need_to_pop_source If TRUE, don't check before popping.
*
* Outputs:
* Returned Value: TRUE if reached end of linked-list
* Global Variables:
* start Points to restored input buffer
* end Points to end of restored input buffer
* pc Input point in restored buffer
* iname Name of restored source file
* lineno Line number in restored source file
* report_multiline Restored to saved value.
* Local Static Variables:
* saved_source Points to previous source_state entry
* need_to_pop_source TRUE if postponed popping till next time
* Memory Freed
* Saved source-state entry that was just "popped"
*
* Process Explanation:
* First check the need_to_pop_source flag.
* If it is set, we will clear it and go ahead and pop.
* If it is not set, we will check the pause_before_pop field
* of the top entry in the source_state linked-list.
* If the pause_before_pop field is set, we will set the
* need_to_pop_source flag and return.
* If it is not, we will go ahead and pop.
* If we are going to go ahead and pop, we will call the
* "Resume-Processing" routine (if it's not NULL) before
* we restore the saved source state.
*
**************************************************************************** */
static bool pop_source( void )
{
bool retval = TRUE;
if ( saved_source != NULL )
{
retval = FALSE;
if ( need_to_pop_source )
{
need_to_pop_source = FALSE;
}else{
if ( saved_source->pause_before_pop )
{
need_to_pop_source = TRUE;
return( retval);
}
}
if ( saved_source->resump_func != NULL )
{
saved_source->resump_func( saved_source->resump_param);
}
report_multiline = saved_source->sav_rep_multlin;
lineno = saved_source->old_lineno ;
iname = saved_source->old_iname ;
end = saved_source->old_end ;
pc = saved_source->old_pc ;
start = saved_source->old_start ;
drop_source();
}
return( retval);
}
/* **************************************************************************
*
* Function name: get_word
* Synopsis: Gather the next "word" (aka Forth Token) from the
* input stream.
* A Forth Token is, of course, a string of characters
* delimited by white-space (blank, tab or new-line).
* Do not increment line-number counters here; leave
* the delimiter after the word unconsumed.
*
* Inputs:
* Parameters: NONE
* Global Variables:
* pc Input-stream Scanning Pointer
* Local Static Variables:
* need_to_pop_source If TRUE, pop_source() as first step
*
* Outputs:
* Returned Value: Length of "word" gotten;
* 0 if reached end of file.
* -1 if reached end of primary input
* (I.e., end of all source)
* Global Variables:
* statbuf Copy of "gotten" word
* pc Advanced to end of "gotten" word,
* (i.e., the next word is "consumed")
* unless returning zero.
* abs_token_no Incremented, if valid "word" (token)
* was gotten.
*
* Process Explanation:
* Skip whitespace to the start of the token,
* then skip printable characters to the end of the token.
* That part's easy, but what about when skipping whitespace
* brings you to the end of the input stream?
* First, look at the need_to_pop_source flag. If it's set,
* we came to the end of the input stream the last time
* through. Now we need to pop_source() first.
* Next, we start skipping whitespace; this detects when we've
* reached the end of the input stream. If we have,
* then we need to pop_source() again.
* If pop_source() returned a TRUE, we've reached the end
* of the primary input file. Return -1.
* If pop_source() turned the need_to_pop_source flag
* to TRUE again, then we need to "pause" until the
* next time through; return zero.
* Otherwise, we proceed with collecting the token as described.
*
* Revision History:
* Updated Thu, 23 Feb 2006 by David L. Paktor
* Tied this routine in with a more sophisticated mechanism that
* makes a smooth transition between processing the body of
* a Macro, a User-defined Symbol or an FLOADed file, and
* the resumption of processing the source file, so that the
* end-of-file will only be seen at the end of the primary
* input file (the one that came from the command-line)
* Updated Fri, 24 Feb 2006 by David L. Paktor
* This is trickier than I thought. Added a global indicator
* of whether a file-boundary was crossed while getting
* the word; previously, that was indicated by a return
* value of zero, which now means something else...
* The flag, closed_stream , will be cleared every time this
* routine is entered, and set whenever close_stream() is
* entered.
* Updated Tue, 28 Feb 2006 at 10:13 PST by David L. Paktor
* Trickier still. On crossing a file-boundary, must not
* consume the first word in the resumed file, for one
* call; instead, return zero. Consume it on the next
* call. The closed_stream flag is now irrelevant and
* has gone away.
*
**************************************************************************** */
signed long get_word( void)
{
size_t len;
u8 *str;
bool keep_skipping;
bool pop_result;
if ( need_to_pop_source )
{
pop_result = pop_source();
}
do {
keep_skipping = skip_ws();
if ( keep_skipping )
{
pop_result = pop_source();
if ( pop_result || need_to_pop_source )
{
statbuf[0] = 0;
if ( pop_result )
{
return -1;
}
return 0;
}
}
} while ( keep_skipping );
str=pc;
while ( (str < end) && *str && *str!='\n' && *str!='\t' && *str!=' ')
str++;
len=(size_t)(str-pc);
if (len >= GET_BUF_MAX )
{
tokenization_error ( FATAL,
"get_word buffer overflow. Max is %d.", GET_BUF_MAX-1 );
}
memcpy(statbuf, pc, len);
statbuf[len]=0;
#ifdef DEBUG_SCANNER
printf("%s:%d: debug: read token '%s', length=%ld\n",
iname, lineno, statbuf, len);
#endif
pc+=len;
abs_token_no++;
return len;
}
/* **************************************************************************
*
* Function name: get_word_in_line
* Synopsis: Get the next word on the same line as the current
* line of input. If the end of line was reached
* before a word was found, print an error message
* and return an indication.
*
* Inputs:
* Parameters:
* func_nam Name of the function expecting the same-line
* input; for use in the Error Message.
* If NULL, do not issue Error Message
* Global Variables:
* pc Input character pointer. Saved for comparison
* lineno Current input line number. Saved for comparison
*
* Outputs:
* Returned Value: TRUE = success. Word was acquired on same line.
* Global Variables:
* statbuf Advanced to the next word in the input stream.
* pc Advanced if no error; restored otherwise.
*
* Error Detection:
* If no next word is gotten (i.e., we're at end-of-file), or if
* one is gotten but not on the same line, the routine will
* return FALSE; if func_nam is not NULL, an ERROR Message
* will be issued.
* Also, the values of PC LINENO and ABS_TOKEN_NO will be reset
* to the positions they had when this routine was entered.
*
**************************************************************************** */
bool get_word_in_line( char *func_nam)
{
signed long wlen;
bool retval = TRUE;
u8 *save_pc = pc;
unsigned int save_lineno = lineno;
unsigned int save_abs_token_no = abs_token_no;
/* Copy of function name, for error message */
char func_cpy[FUNC_CPY_BUF_SIZE+1];
/* Do this first, in the likely event that func_nam was statbuf */
if ( func_nam != NULL )
{
strncpy( func_cpy, func_nam, FUNC_CPY_BUF_SIZE);
func_cpy[FUNC_CPY_BUF_SIZE] = 0; /* Guarantee a null terminator */
}
wlen = get_word();
if ( ( lineno != save_lineno ) || ( wlen <= 0 ) )
{
abs_token_no = save_abs_token_no;
lineno = save_lineno;
pc = save_pc;
retval = FALSE;
if ( func_nam != NULL )
{
tokenization_error ( TKERROR,
"Operator %s expects its target on the same line\n",
strupr(func_cpy));
}
}
return ( retval );
}
/* **************************************************************************
*
* Function name: get_rest_of_line
* Synopsis: Get all the remaining text on the same line as
* the current line of input. If there is no text
* (not counting whitespace) before the end of line,
* return an indication.
*
* Inputs:
* Parameters: NONE
* Global Variables:
* pc Input character pointer. Saved for restoration
* lineno Current input line number. Saved for comparison
*
* Outputs:
* Returned Value: TRUE = success. Text was acquired on same line.
* Global Variables:
* statbuf Contains the text found in the input stream.
* pc Advanced to end of line or of whitespace, if
* no error; restored otherwise.
* lineno Preserved if no error; otherwise, restored.
* abs_token_no Restored if error; otherwise, advanced as normal.
*
* Error Detection:
* Routine will return FALSE if no text is gotten on the same line.
*
**************************************************************************** */
bool get_rest_of_line( void)
{
bool retval = FALSE;
u8 *save_pc = pc;
unsigned int save_lineno = lineno;
unsigned int save_abs_token_no = abs_token_no;
if ( INVERSE( skip_ws() ) )
{
if ( lineno == save_lineno )
{
signed long wlen = get_until('\n');
if ( wlen > 0 ) retval = TRUE;
}else{
abs_token_no = save_abs_token_no;
lineno = save_lineno;
pc = save_pc;
}
}
return( retval);
}
/* **************************************************************************
*
* Function name: warn_unterm
* Synopsis: Message for "Unterminated ..." something
* Show saved line-number, where the "something" started,
* and the definition, if any, in which it occurred.
*
* Inputs:
* Parameters:
* severity Type of error/warning message to display
* usually either WARNING or TKERROR
* something String to print after "Unterminated"
* saved_lineno Line-Number where the "something" started
* Global Variables:
* lineno Saved, then restored.
* last_colon_defname Used only if unterm_is_colon is TRUE;
* Local Static Variables:
* unterm_is_colon See 07 Mar 2006 entry under Rev'n History
*
* Outputs:
* Returned Value: NONE
* Global Variables:
* lineno Saved, then restored.
* Local Static Variables:
* unterm_is_colon Reset to FALSE
* Printout:
* Warning or Error message
*
* Revision History:
* Updated Mon, 06 Mar 2006 by David L. Paktor
* Added call to in_last_colon()
* Updated Tue, 07 Mar 2006 by David L. Paktor
* Call to in_last_colon() works okay in most cases except for
* when the "something" is a Colon Definition; there, it
* results in the phrase: ... Definition in definition of ...
* which is awkward. To eliminate that, I am introducing
* a Local Static Variable flag called unterm_is_colon
* which will be set only in the appropriate place and
* re-cleared here. It's a retro-fit, of course; it could
* have been a parameter had the need for it occurred when
* this routine was first constructed...
*
**************************************************************************** */
static bool unterm_is_colon = FALSE;
void warn_unterm( int severity, char *something, unsigned int saved_lineno)
{
unsigned int tmp = lineno;
lineno = saved_lineno;
if ( unterm_is_colon )
{
tokenization_error( severity, "Unterminated %s of %s\n",
something, strupr( last_colon_defname) );
unterm_is_colon = FALSE;
}else{
tokenization_error( severity, "Unterminated %s", something);
in_last_colon( TRUE);
}
lineno = tmp;
}
/* **************************************************************************
*
* Function name: warn_if_multiline
* Synopsis: Test for "Multi-line ..." something and issue WARNING
* Show saved line-number, where the "something" started
*
* Inputs:
* Parameters:
* something String to print after "Unterminated"
* start_lineno Line-Number where the "something" started
* Global Variables:
* lineno Line-Number where we are now
* iname Input file name, to satisfy ...where_started()
* (Not crossing any actual file boundary.)
* report_multiline TRUE = go ahead with the message
*
* Outputs:
* Returned Value: NONE
* Global Variables:
* report_multiline Restored to TRUE.
*
* Error Detection:
* Only issue message if the current lineno doesn't equal
* the start_lineno
*
* Process Explanation:
* The directive "multi-line" allows the user to specify that
* the next "Multi-line ..." something is intentional, and
* will cause its warning to be suppressed. It remains in
* effect until it's "used"; afterwards, it's reset.
*
**************************************************************************** */
void warn_if_multiline( char *something, unsigned int start_lineno )
{
if ( report_multiline && ( start_lineno != lineno ) )
{
tokenization_error( WARNING, "Multi-line %s, started", something);
where_started( iname, start_lineno);
}
report_multiline = TRUE;
}
/* **************************************************************************
*
* Function name: string_remark
* Synopsis: Suspend string parsing past end of line and
* whitespace at start of the new line.
*
* Inputs:
* Parameters:
* errmsg_txt Text to be used for error-message.
* Global Variables:
* pc Input-source Scanning pointer
*
* Outputs:
* Returned Value: NONE
* Global Variables:
* pc Will point to first non-blank in new line
*
* Error Detection:
* The return value of the skip_until() or skip_ws() routine
* will indicate if PC goes past END. Issue a WARNING.
* The calling routine will handle things from there.
*
**************************************************************************** */
static void string_remark(char *errmsg_txt)
{
unsigned int sav_lineno = lineno;
bool eof = skip_until('\n');
if ( ! eof )
{
eof = skip_ws();
}
if ( eof )
{
warn_unterm(WARNING, errmsg_txt, sav_lineno);
}
}
/* Convert the given string to a number in the supplied base */
/* Allow -- and ignore -- embedded periods. */
/* The endptr param represents a pointer that will be updated
* with the address of the first non-numeric character encountered,
* (unless it is a NULL, in which case it is ignored).
*/
/* There is no test for a completely invalid string;
* the calling routine is responsible for ascertaining
* the validity of the string being passed.
*/
static long parse_number(u8 *start, u8 **endptr, int lbase)
{
long val = 0;
bool negative = FALSE ;
int curr;
u8 *nptr=start;
curr = *nptr;
if (curr == '-')
{
negative = TRUE ;
nptr++;
}
for (curr = *nptr; (curr = *nptr); nptr++) {
if ( curr == '.' )
continue;
if ( curr >= '0' && curr <= '9')
curr -= '0';
else if (curr >= 'a' && curr <= 'f')
curr += 10 - 'a';
else if (curr >= 'A' && curr <= 'F')
curr += 10 - 'A';
else
break;
if (curr >= lbase)
break;
val *= lbase;
val += curr;
}
#ifdef DEBUG_SCANNER
if (curr)
printf( "%s:%d: warning: couldn't parse number '%s' (%d/%d)\n",
iname, lineno, start,curr,lbase);
#endif
if (endptr)
*endptr=nptr;
if (negative)
{
val = -val;
}
return val;
}
/* **************************************************************************
*
* Function name: add_byte_to_string
* Synopsis: Add the given byte (or character) to the string
* being accumulated in statbuf, but protect
* against a buffer overflow.
*
* Inputs:
* Parameters:
* nu_byte The given character to be added
* walk Pointer to pointer to the position
* in statbuf where the character
* is to be placed
* Global Variables:
* statbuf Buffer where the string is accumulated
* Macros:
* GET_BUF_MAX Size of the buffer
*
* Outputs:
* Returned Value: NONE
* Supplied Pointers:
* **walk Given character is placed here
* *walk Incremented in any case
*
* Error Detection:
* If walk has reached end of string buffer, do not place
* the character, but continue to increment walk .
* Calling routine will detect overflow.
*
**************************************************************************** */
static void add_byte_to_string( u8 nu_byte, u8 **walk )
{
if ( *walk - statbuf < GET_BUF_MAX )
{
**walk = nu_byte;
}
(*walk)++;
}
/* **************************************************************************
*
* Function name: c_string_escape
* Synopsis: Process C-style escape syntax in strings
*
* Inputs:
* Parameters:
* walk Pointer to pointer to area into
* which to put acquired values
* Global Variables:
* pc Input-source Scanning pointer
*
* Outputs:
* Returned Value: NONE
* Global Variables:
* pc Point to last character processed.
* Supplied Pointers:
* *walk Advanced by number of bytes acquired
*
* Error Detection:
* WARNING conditions. See under "Process Explanation" below.
*
* Process Explanation:
* Start with PC pointing to the first character to process
* i.e., after the backslash.
* We recognize newline, tab and numbers
* A digit-string in the current base can be converted to a number.
* The first non-numeric character ends the numeric sequence
* and gets swallowed up.
* If the number exceeds the size of a byte, use the truncated
* value and issue a WARNING.
* If the first character in the "digit"-string was non-numeric,
* use the character literally and issue a WARNING.
* If the character that ended the numeric sequence is a quote,
* it might be the end of the string, or the start of a
* special-character or even of an "( ... ) hex-sequence,
* so don't swallow it up.
*
* Still to be done:
* Better protection against PC pointer-over-run past END.
* Currently, this works, but it's held together by threads:
* Because init_stream forces a null-byte at the end of
* the input buffer, parse_number() exits immediately upon
* encountering it. This situation could be covered more
* robustly...
*
**************************************************************************** */
static void c_string_escape( u8 **walk)
{
char c = *pc;
u8 val;
/* We will come out of this "switch" statement
* with a value for val and a decision
* as to whether to write it.
*/
bool write_val = TRUE;
switch (c)
{
case 'n':
/* newline */
val = '\n';
break;
case 't':
/* tab */
val = '\t';
break;
default:
/* Digit-string? Convert it to a number, using the current base.
* The first non-numeric character ends the numeric sequence
* and gets swallowed up.
* If the number exceeds the size of a byte, use the truncated
* value and issue a WARNING.
* If the first character in the "digit"-string was non-numeric,
* use the character literally and issue a WARNING.
*/
/*
* If the sequence ender is a quote, it might be the end of
* the string, or the start of a special-character or even
* of an "( ... ) hex-sequence, so don't swallow it up.
*/
{
long lval;
u8 *sav_pc = pc;
lval=parse_number(pc, &pc, base);
val = (u8)lval;
#ifdef DEBUG_SCANNER
if (verbose)
printf( "%s:%d: debug: escape code "
"0x%x\n",iname, lineno, val);
#endif
if ( lval > 0x0ff )
{
tokenization_error ( WARNING,
"Numeric String after \\ overflows byte. "
"Using 0x%02x.\n", val);
}
if ( pc == sav_pc )
{
/* NOTE: Here, PC hasn't been advanced past its
* saved value, so we can count on C remaining
* unchanged since the start of the routine.
*/
/* Don't use the null-byte at the end of the buffer */
if ( ( pc >= end )
/* or a sequence-ending quote. */
|| ( c == '"' ) )
{
write_val = FALSE;
}else{
/* In the WARNING message, print the character
* if it's printable or show it in hex
* if it's not.
*/
if ( (c > 0x20 ) && ( c <= 0x7e) )
{
tokenization_error ( WARNING,
"Unrecognized character, %c, "
"after \\ in string. "
"Using it literally.\n", c);
}else{
tokenization_error ( WARNING,
"Unrecognized character, 0x%02x, "
"after \\ in string. "
"Using it literally.\n", c);
}
val = c;
}
}
/* NOTE: Here, however, PC may have been advanced... */
/* Don't swallow the sequence-ender if it's a quote. */
if ( *pc == '"' )
{
pc--;
}
} /* End of the "default" clause */
} /* End of the "switch" statement */
if ( write_val ) add_byte_to_string( val, walk );
}
/* **************************************************************************
*
* Function name: get_sequence
* Synopsis: Process the Hex-Number option in strings
* Protect against PC pointer-over-run past END.
*
* Inputs:
* Parameters:
* **walk Pointer to pointer to area into which
* to put acquired values
* Global Variables:
* pc Input-source Scanning pointer
* end End of input-source buffer
*
* Outputs:
* Returned Value: TRUE = "Normal Completion" (I.e., not EOF)
* Global Variables:
* pc Points at terminating close-paren, or END
* lineno Input File Line-Number Counter, may be incr'd
* Supplied Pointers:
* *walk Advanced by number of values acquired
*
* Error Detection:
* End-of-file encountered before end of hex-sequence:
* Issue a Warning, conclude processing, return FALSE.
*
* Process Explanation:
* SETUP and RULES:
* Start with PC pointing to the first character
* after the '(' (Open-Paren)
* Bytes are gathered from digits in pairs, except
* when separated they are treated singly.
* Allow a backslash in the middle of the sequence
* to skip to the end of the line and past the
* whitespace at the start of the next line,
* i.e., it acts as a comment-escape.
*
* INITIALIZE:
* PV_indx = 0
* Set return-indicator to "Abnormal Completion"
* Ready_to_Parse = FALSE
* Stuff NULL into PVAL[2]
* WHILE PC is less than END
* Pick up character at PC into Next_Ch
* IF Next_Ch is close-paren :
* Set return-indicator to "Normal Completion".
* Done! Break out of loop.
* ENDIF
* IF comment-escape behavior (controlled by means of a
* command-line switch) is allowed
* IF Next_Ch is backslash :
* Skip to end-of line, skip whitespace.
* If that makes PC reach END : WARNING message.
* (Don't need to break out of loop;
* normal test will terminate.)
* CONTINUE Loop.
* (Don't increment PC; PC is already at right place).
* ENDIF
* ENDIF
* IF Next_Ch is a valid Hex-Digit character :
* Stuff it into PVAL[PV_indx]
* IF (PV_indx is 0) :
* Increment PV_indx
* ELSE
* Set Ready_to_Parse to TRUE
* ENDIF
* ELSE
* IF Next_Ch is a New-Line, increment Line Number counter
* IF (PV_indx is 1) :
* Stuff NULL into PVAL[1]
* Set Ready_to_Parse to TRUE
* ENDIF
* ENDIF
* IF Ready_to_Parse
* Parse PVAL
* Stuff into WALK
* Reset PV_indx to zero
* Reset Ready_to_Parse to FALSE
* ENDIF
* Increment PC
* REPEAT
* Return with Normal/Abnormal completion indicator
*
**************************************************************************** */
static bool get_sequence(u8 **walk)
{
int pv_indx = 0;
bool retval = FALSE; /* "Abnormal Completion" indicator */
bool ready_to_parse = FALSE;
char next_ch;
char pval[3];
#ifdef DEBUG_SCANNER
printf("%s:%d: debug: hex field:", iname, lineno);
#endif
pval[2]=0;
while ( pc < end )
{
next_ch = *pc;
if ( next_ch == ')' )
{
retval = TRUE;
break;
}
if ( hex_remark_escape )
{
if ( next_ch == '\\' )
{
string_remark("string hex-sequence remark");
continue;
}
}
if ( isxdigit(next_ch) )
{
pval[pv_indx] = next_ch;
if ( pv_indx == 0 )
{
pv_indx++;
}else{
ready_to_parse = TRUE;
}
}else{
if ( next_ch == '\n' ) lineno++ ;
if ( pv_indx != 0 )
{
pval[1] = 0;
ready_to_parse = TRUE;
}
}
if ( ready_to_parse )
{
u8 val = parse_number(pval, NULL, 16);
*((*walk)++)=val;
#ifdef DEBUG_SCANNER
printf(" %02x",val);
#endif
pv_indx = 0;
ready_to_parse = FALSE;
}
pc++;
}
#ifdef DEBUG_SCANNER
printf("\n");
#endif
return ( retval );
}
/* **************************************************************************
*
* Return the length of the string.
* Pack the string, without the terminating '"' (Quote), into statbuf
* Protect against PC pointer-over-run past END.
* Enable Quote-Backslash as a String-Remark Escape.
* Allowability of Quote-Backslash as a String-Remark is under control
* of a command-line switch (string_remark_escape ).
* Allowability of C-style escape characters is under control
* of a command-line switch ( c_style_string_escape ).
*
* Truncate string to size of Forth Packed-String (i.e., uses leading
* count-byte, so limited to 255, number that one byte can express)
* unless the string is being gathered for a Message or is being
* consumed for purposes of ignoring it, in either of which case
* that limit need not be enforced. Parameter "pack_str" controls
* this: TRUE if limit needs to be enforced.
*
* Issue WARNING if string length gets truncated.
* Issue WARNING if string crosses line.
* The issuance of the Multi-line WARNING is under control of a
* one-shot directive similar to OVERLOAD , called MULTI-LINE
*
* Still to be decided:
* Do we want to bring the allowability of strings crossing
* lines under control of a command-line switch?
*
************************************************************************** */
static signed long get_string( bool pack_str)
{
u8 *walk;
unsigned long len;
char c;
bool run = TRUE;
unsigned long start_lineno = lineno; /* For warning message */
/*
* Bump past the single whitespace character that delimits
* the command -- e.g., ." or " or suchlike -- that
* starts the string. Allow new-line to be a command-
* -delimiting whitespace character. Regard any sub-
* sequent whitespace characters as part of the string
*/
if ( *pc == '\n' ) lineno++;
pc++;
got_until_eof = TRUE ;
walk=statbuf;
while (run) {
switch ((c=*pc))
{
/* Standard use of '"' (Quote) for special-char escape */
case '\"':
/* Skip the '"' (Quote) */
pc++;
/* End of the buffer also ends the string cleanly */
if ( pc >= end )
{
run = FALSE;
got_until_eof = FALSE ;
break;
}
/* Pick up the next char after the '"' (Quote) */
c=*pc;
switch (c)
{
case '(':
pc++; /* skip the '(' */
run = get_sequence(&walk);
break;
case 'n':
add_byte_to_string( '\n', &walk);
break;
case 'r':
add_byte_to_string( '\r', &walk);
break;
case 't':
add_byte_to_string( '\t', &walk);
break;
case 'f':
add_byte_to_string( '\f', &walk);
break;
case 'l':
add_byte_to_string( '\n', &walk);
break;
case 'b':
add_byte_to_string( 0x08, &walk);
break;
case '!':
add_byte_to_string( 0x07, &walk);
break;
case '^':
pc++; /* Skip the up-arrow (Caret) */
add_byte_to_string( *pc & 0x1f , &walk);
break;
/* We're done after any of the whitespace
* characters follows a quote.
*/
case ' ':
case '\t':
/* Advance past the terminating whitespace
* character, except newline.
* Let get_word() handle that.
*/
pc++;
case '\n':
run=FALSE;
got_until_eof = FALSE ;
break;
default:
/* Control allowability of Quote-Backslash
* as a String-Remark by means of a
* command-line switch.
*/
if ( string_remark_escape )
{
if ( c == '\\' )
{
string_remark("string-escape remark");
/* The first non-blank in the new line
* has not been processed yet.
* Back up to allow it to be.
*/
pc--;
break;
}
}
add_byte_to_string( c, &walk);
}
break;
case '\n':
/* Allow strings to cross lines. Include the
* newline in the string. Account for it.
*/
lineno++;
default:
/* Control allowability of C-style escape-character
* syntax by means of a command-line switch.
*/
if ( c_style_string_escape )
{
if ( c == '\\' )
{
pc++;
c_string_escape(&walk );
break;
}
}
add_byte_to_string( c, &walk);
}
/* Advance past the char processed, unless we're done. */
if ( run ) pc++;
/* Done if we hit end of file before string was concluded */
if ( pc >= end )
{
run = FALSE;
if ( got_until_eof )
{
warn_unterm( WARNING, "string", start_lineno);
/* Prevent multiple messages for one error */
got_until_eof = FALSE;
}
}
}
warn_if_multiline( "string", start_lineno);
len = walk - statbuf;
if (len >= GET_BUF_MAX )
{
tokenization_error ( TKERROR,
"get_string buffer overflow. Max is %d\n.", GET_BUF_MAX-1 );
len = GET_BUF_MAX-1;
}
#ifdef DEBUG_SCANNER
if (verbose)
printf("%s:%d: debug: scanned string: '%s'\n",
iname, lineno, statbuf);
#endif
if ( pack_str && (len > STRING_LEN_MAX) )
{
tokenization_error ( WARNING,
"String length being truncated to %d.\n", STRING_LEN_MAX );
len = STRING_LEN_MAX;
}
statbuf[len] = 0;
return len ;
}
/* **************************************************************************
*
* Function name: handle_user_message
* Synopsis: Collect a user-generated tokenization-time message;
* either print it or discard it. Shared code
* for user_message() and skip_user_message()
*
* Inputs:
* Parameters:
* delim End-of-string delimiter character.
* If it's a double-quote ("), we will use
* the get-string() routine, with all
* its options, to collect the message.
* Otherwise, we'll capture plain text from
* the input stream.
* print_it TRUE if we should print the message
* Local Static Variables:
* got_until_eof TRUE if reached end of buffer before delim.
* Global Variables:
* lineno Save, then restore.
*
* Outputs:
* Returned Value: NONE
* Global Variables:
* statbuf The string will be collected in here
*
* Printout (if print_it is TRUE):
* The string, with new-line tacked on, will be printed from
* the tokenization_error() routine as a MESSAGE.
* The line-number will be shown as of the origin of the message
*
* Error Detection:
* Error-reports will be printed regardless of print_it param.
* If delimiter was not found, show "Unterminated" warning message.
* If delimiter was " (double-quote), the get_string() routine
* already checked for a multi-line construct; if delimiter is
* a new-line, then a multi-line construct is impossible.
* otherwise, we will do the multi-line check here.
*
**************************************************************************** */
static void handle_user_message( char delim, bool print_it )
{
signed long wlen;
unsigned int start_lineno = lineno;
unsigned int multiline_start = lineno; /* For warning message */
bool check_multiline = FALSE;
const char *ug_msg = "user-generated message";
if ( delim == '"' )
{
wlen = get_string( FALSE);
}else{
/*
* When the message-delimiter is a new-line, and the
* command-delimiter was a new-line, it means the
* string length is zero; we won't bump the PC.
* Otherwise, we will honor the convention we extend
* to .( whereby, if the command is delimited
* by a new-line, we allow the string to begin
* on the next line.
*/
if ( delim == '\n' )
{
if ( *pc != '\n') pc++;
}else{
if ( *pc == '\n' ) lineno++;
pc++;
multiline_start = lineno;
check_multiline = TRUE;
}
wlen = get_until( delim );
}
if ( print_it )
{
unsigned int tmp_lineno = lineno;
lineno = start_lineno;
/* Don't add a new-line to body of the message.
* Routine already takes care of that.
* Besides, buffer might be full...
*/
tokenization_error( MESSAGE, statbuf);
lineno = tmp_lineno;
}
if ( got_until_eof ) /* Crude but effective retrofit... */
{
warn_unterm(WARNING, (char *)ug_msg, start_lineno);
}else{
if ( check_multiline )
{
warn_if_multiline( (char *)ug_msg, multiline_start);
}
}
}
/* **************************************************************************
*
* Function name: user_message
* Synopsis: Collect a user-generated message and
* print it at tokenization-time.
*
* Tokenizer directive (either mode):
* Synonyms String Delimiter
* [MESSAGE] #MESSAGE [#MESSAGE] end-of-line
* #MESSAGE" "
* "Tokenizer-Escape" mode directive String Delimiter
* .( )
* ." "
*
* Inputs:
* Parameter is the "parameter field" of the TIC entry, which
* was initialized to the end-of-string delimiter character.
*
* Outputs:
* Returned Value: NONE
* Printout: User-message, parsed from input.
*
* Extraneous Remarks:
* We would have preferred to simply use the "character value"
* aspect of the union, but we found portability issues
* between big- and little- -endian processors, so we still
* have to recast its type here.
*
**************************************************************************** */
void user_message( tic_param_t pfield )
{
char delim = (char)pfield.deflt_elem ;
handle_user_message( delim, TRUE);
}
/* **************************************************************************
*
* Function name: skip_user_message
* Synopsis: Collect a user-generated message and discard it.
* Used when ignoring a Conditional section.
*
* Tokenizer directive (either mode):
* Synonyms String Delimiter
* [MESSAGE] #MESSAGE [#MESSAGE] end-of-line
* #MESSAGE" "
* "Tokenizer-Escape" mode directive String Delimiter
* .( )
* ." "
*
* Inputs:
* Parameters:
* pfield "Parameter field" of the TIC entry, which
* was initialized to the delimiter.
*
* Outputs:
* Returned Value: NONE
* Printout: NONE
*
**************************************************************************** */
void skip_user_message( tic_param_t pfield )
{
char delim = (char)pfield.deflt_elem ;
handle_user_message( delim, FALSE);
}
/* **************************************************************************
*
* Function name: get_number
* Synopsis: If the word retrieved from the input stream is a
* valid number (under the current base) convert it.
* Return an indication if it was not.
*
* Inputs:
* Parameters:
* *result Pointer to place to return the number
* Global Variables:
* statbuf The word just read that is to be converted.
* base The current numeric-interpretation base.
*
* Outputs:
* Returned Value: TRUE = Input was a valid number
* Supplied Pointers:
* *result The converted number, if valid
* otherwise undefined
*
* Revision History:
* Updated Mon, 28 Mar 2005 by David L. Paktor
* Always use the current base.
* Reversed sense of return-flag.
*
**************************************************************************** */
bool get_number( long *result)
{
u8 *until;
long val;
bool retval = FALSE ;
val = parse_number(statbuf, &until, base);
#ifdef DEBUG_SCANNER
printf("%s:%d: debug: parsing number: base 0x%x, val 0x%lx, "
"processed %ld of %ld bytes\n", iname, lineno,
base, val,(size_t)(until-statbuf), strlen((char *)statbuf));
#endif
/* If number-parsing ended before the end of the input word,
* then the input word was not a valid number.
*/
if (until==(statbuf+strlen((char *)statbuf)))
{
*result=val;
retval = TRUE;
}
return ( retval );
}
/* **************************************************************************
*
* Function name: deliver_number
* Synopsis: Deliver the supplied number according to the
* state of the tokenizer:
* In normal tokenization mode, emit it as an
* FCode literal.
* In "Tokenizer-Escape" mode, push it onto
* the Data Stack.
*
* Inputs:
* Parameters:
* numval The number, verified to be valid.
* Global Variables:
* in_tokz_esc TRUE if tokenizer is in "Tokenizer Escape" mode.
*
* Outputs:
* Returned Value: NONE
* Items Pushed onto Data-Stack:
* Top: The number, if in_tokz_esc was TRUE
* FCode Output buffer:
* If in_tokz_esc was FALSE, a b(lit) token will be written,
* followed by the number.
*
**************************************************************************** */
static void deliver_number( long numval)
{
if ( in_tokz_esc )
{
dpush( numval );
} else {
emit_literal(numval);
}
}
/* **************************************************************************
*
* Function name: handle_number
* Synopsis: Convert the word just retrieved from the input stream
* to a number.
* Indicate whether the string was a valid number and
* deliver it, as appropriate.
*
* Inputs:
* Parameters: NONE
* Global Variables:
* statbuf The word that was just read, and to be converted.
*
* Outputs:
* Returned Value: TRUE = Input string was a valid number
* If input string was a valid number, the converted number will
* be delivered, as appropriate, by deliver_number().
*
**************************************************************************** */
static bool handle_number( void )
{
bool retval ;
long numval;
retval = get_number( &numval );
if ( retval )
{
deliver_number( numval );
}
return ( retval );
}
/* **************************************************************************
*
* Function name: ascii_right_number
* Synopsis: Convert a character sequence to a number, justified
* toward the right (i.e., the low-order bytes) and
* deliver it, as appropriate.
*
* Inputs:
* Parameters:
* in_str The input string
*
* Outputs:
* Returned Value: NONE
* The converted number will be delivered by deliver_number().
*
* Process Explanation:
* The last four characters in the sequence will become the number.
* If there are fewer than four, they will fill the low-order part
* of the number.
* Example: PCIR is converted to h# 50434952
* CPU is converted to h# 00435055
* and
* LotsOfStuff is equivalent to a# tuff
* and is converted to h# 74756666
*
**************************************************************************** */
static void ascii_right_number( char *in_str)
{
u8 nxt_ch;
char *str_ptr = in_str;
long numval = 0;
for ( nxt_ch = (u8)*str_ptr ;
( nxt_ch = (u8)*str_ptr ) != 0 ;
str_ptr++ )
{
numval = ( numval << 8 ) + nxt_ch ;
}
deliver_number( numval );
}
/* **************************************************************************
*
* Function name: ascii_left_number
* Synopsis: Similar to ascii_right_number() except justified
* toward the left (i.e., the high-order bytes).
*
*
* Inputs:
* Parameters:
* in_str The input string
*
* Outputs:
* Returned Value: NONE
* The converted number will be delivered by deliver_number().
*
* Process Explanation:
* If there are fewer than four characters in the sequence, they
* will fill the high-order part of the number.
* CPU is converted to h# 43505500
* In all other respects, similar to ascii_right_number()
*
**************************************************************************** */
static void ascii_left_number( char *in_str)
{
u8 nxt_ch;
char *str_ptr = in_str;
long numval = 0;
int shift_amt = 24;
bool shift_over = FALSE ;
for ( nxt_ch = (u8)*str_ptr ;
( nxt_ch = (u8)*str_ptr ) != 0 ;
str_ptr++ )
{
if ( shift_over ) numval <<= 8;
if ( shift_amt == 0 ) shift_over = TRUE ;
numval += ( nxt_ch << shift_amt );
if ( shift_amt > 0 ) shift_amt -= 8;
}
deliver_number( numval );
}
/* **************************************************************************
*
* Function name: init_scanner
* Synopsis: Allocate memory the Scanner will need.
* Only need to call once per program run.
*
**************************************************************************** */
void init_scanner(void)
{
statbuf=safe_malloc(GET_BUF_MAX, "initting scanner");
}
/* **************************************************************************
*
* Function name: exit_scanner
* Synopsis: Free up memory the Scanner used
*
**************************************************************************** */
void exit_scanner(void)
{
free(statbuf);
}
/* **************************************************************************
*
* Function name: set_hdr_flag
* Synopsis: Set the state of the "headered-ness" flag to the
* value given, unless over-ridden by one or both
* of the "always-..." Command-Line Flags
*
* Inputs:
* Parameters:
* new_flag New setting
* Global Variables:
* always_headers Override HEADERLESS and make HEADERS
* always_external Override HEADERLESS and HEADERS;
* make EXTERNAL
*
* Outputs:
* Returned Value: None
* Global Variables:
* hdr_flag Adjusted to new setting
*
* Process Explanation:
* If always_headers is TRUE, and new_flag is not FLAG_EXTERNAL
* then set to FLAG_HEADERS
* If always_external is TRUE, set to FLAG_EXTERNAL, regardless.
* (Note: always_external over-rides always_headers).
* Otherwise, set to new_flag
*
**************************************************************************** */
static void set_hdr_flag( headeredness new_flag)
{
headeredness new_state = new_flag;
switch ( new_flag)
{
case FLAG_HEADERLESS:
{
if ( always_headers )
{ new_state = FLAG_HEADERS;
}
/* No break. Intentional... */
}
case FLAG_HEADERS:
{
if ( always_external )
{ new_state = FLAG_EXTERNAL;
}
/* No break. Intentional... */
}
case FLAG_EXTERNAL:
break; /* Satisfy compiler's error-checking... */
/* No default needed here... */
}
hdr_flag = new_state;
}
/* **************************************************************************
*
* Function name: init_scan_state
* Synopsis: Initialize various state variables for each time
* a new tokenization scan is started.
*
* Inputs:
* Parameters: NONE
*
* Outputs:
* Returned Value: NONE
* Global Variables: Initialized to:
* base 0x0a (I.e., base = "decimal")
* nextfcode By reset_fcode_ranges()
* pci_is_last_image TRUE
* incolon FALSE
* Local Static Variables:
* hdr_flag FLAG_HEADERLESS (unless over-ridden)
* is_instance FALSE
* last_colon_filename NULL
* instance_filename NULL
* dev_change_instance_warning TRUE
* instance_definer_gap FALSE
* need_to_pop_source FALSE
* first_fc_starter TRUE
* ret_stk_depth 0
* Memory Freed
* Copies of input-file name in last_colon_filename and
* instance_filename , if allocated.
*
**************************************************************************** */
void init_scan_state( void)
{
base = 0x0a;
pci_is_last_image = TRUE;
incolon = FALSE;
is_instance = FALSE;
set_hdr_flag( FLAG_HEADERLESS);
reset_fcode_ranges();
first_fc_starter = TRUE;
if ( last_colon_filename != NULL ) free( last_colon_filename);
if ( instance_filename != NULL ) free( instance_filename);
last_colon_filename = NULL;
instance_filename = NULL;
dev_change_instance_warning = TRUE;
instance_definer_gap = FALSE;
need_to_pop_source = FALSE;
ret_stk_depth = 0;
}
/* **************************************************************************
*
* Function name: collect_input_filename
* Synopsis: Save a copy of the current input file name in the
* given variable, for error-reporting purposes
*
* Inputs:
* Parameters:
* saved_nam Pointer to pointer for copy of name
* Global Variables:
* iname Current input file name
* Local Static Variables:
*
* Outputs:
* Returned Value: NONE
* Supplied Pointers:
* *saved_nam Copy of name
* Memory Allocated
* For copy of input file name
* When Freed?
* Subsequent call to this routine with same pointer
* (Last copy made will be freed if starting a new tokenization,
* otherwise, will persist until end of program.)
* Memory Freed
* Previous copy in same pointer.
*
* Process Explanation:
* If there is a previous copy, and it still matches the current
* input-file name, we don't need to free or re-allocate.
*
**************************************************************************** */
static void collect_input_filename( char **saved_nam)
{
bool update_lcfn = TRUE; /* Need to re-allocate? */
if ( *saved_nam != NULL )
{
if ( strcmp( *saved_nam, iname) == 0 )
{
/* Last collected filename unchanged from iname */
update_lcfn = FALSE;
}else{
free( *saved_nam);
}
}
if ( update_lcfn )
{
*saved_nam = strdup(iname);
}
}
/* **************************************************************************
*
* Function name: test_in_colon
* Synopsis: Error-check whether a word is being used in the
* correct state, relative to being inside a colon
* definition; issue a message if it's not.
*
* Inputs:
* Parameters:
* wname The name of the word in question
* sb_in_colon TRUE if the name should be used inside
* a colon-definition only; FALSE if
* it may only be used outside of a
* colon-definition.
* severity Type of error/warning message to call.
* usually either WARNING or TKERROR
* use_instead Word the error-message should suggest be
* used "instead". This may be a NULL,
* in which case the "suggestion" part
* of the message will simply be omitted.
* Global Variables:
* incolon State of the tokenization; TRUE if inside
* a colon definition
*
* Outputs:
* Returned Value: TRUE if no error.
* Printout: Error messages as indicated.
*
* Error Detection:
* If the state, relative to being inside a colon-definition,
* is not what the parameter says it should be, issue a
* message of the indicated severity, and return FALSE.
*
**************************************************************************** */
static bool test_in_colon ( char *wname,
bool sb_in_colon, /* "Should Be IN colon" */
int severity,
char *use_instead)
{
bool is_wrong;
bool retval = TRUE ;
is_wrong = BOOLVAL(( sb_in_colon != FALSE ) != ( incolon != FALSE )) ;
if ( is_wrong )
{
char *ui_pt1 = "";
char *ui_pt2 = "";
char *ui_pt3 = "";
retval = FALSE;
if ( use_instead != NULL )
{
ui_pt1 = " Use ";
ui_pt2 = use_instead;
ui_pt3 = " instead.";
}
tokenization_error ( severity, "The word %s should not be used "
"%sside of a colon definition.%s%s%s\n", strupr(wname),
sb_in_colon ? "out" : "in", ui_pt1, ui_pt2, ui_pt3 );
}
return ( retval );
}
/* **************************************************************************
*
* Function name: must_be_deep_in_do
* Synopsis: Check that the statement in question is called
* from inside the given depth of structures
* of the DO ... LOOP -type (i.e., any combination
* of DO or ?DO and LOOP or +LOOP ).
* Show an error if it is not.
*
**************************************************************************** */
static void must_be_deep_in_do( int how_deep )
{
int functional_depth = do_loop_depth;
if ( incolon )
{
functional_depth -= last_colon_do_depth;
}
if ( functional_depth < how_deep )
{
char deep_do[64] = "";
int indx;
bool prefix = FALSE;
for ( indx = 0; indx < how_deep ; indx ++ )
{
strcat( deep_do, "DO ... ");
}
for ( indx = 0; indx < how_deep ; indx ++ )
{
if ( prefix )
{
strcat( deep_do, " ... ");
}
strcat( deep_do, "LOOP");
prefix = TRUE;
}
tokenization_error( TKERROR,
"%s outside of %s structure", strupr(statbuf), deep_do);
in_last_colon( TRUE);
}
}
/* **************************************************************************
*
* Function name: bump_ret_stk_depth
* Synopsis: Increment or decrement the Return-Stack-Usage-Depth
* counter.
*
* Inputs:
* Parameters:
* bump Amount by which to increment;
* negative number to decrement.
* Local Static Variables:
* ret_stk_depth The Return-Stack-Usage-Depth counter
*
* Outputs:
* Returned Value: NONE
* Local Static Variables:
* ret_stk_depth Incremented or decremented
*
* Process Explanation:
* This simple-seeming function is actually a place-holder
* for future expansion. Proper error-detection of
* Return-Stack usage is considerably more complex than
* what we are implementing here, and is deferred for a
* later revision.
*
* Still to be done:
* Full detection of whether the Return-Stack has been cleared
* when required, including analysis of Return-Stack usage
* within Flow-Control constructs, and before Loop elements...
*
* Extraneous Remarks:
* Some FORTHs use a Loop-Control stack separate from the Return-
* -Stack, but others use the Return-Stack to keep LOOP-control
* elements. An FCode program must be portable between different
* environments, and so must adhere to the restrictions listed
* in the ANSI Spec:
*
* 3.2.3.3 Return stack
* . . . . . .
* A program may use the return stack for temporary storage during the
* execution of a definition subject to the following restrictions:
* A program shall not access values on the return stack (using R@,
* R>, 2R@ or 2R>) that it did not place there using >R or 2>R;
* A program shall not access from within a do-loop values placed
* on the return stack before the loop was entered;
* All values placed on the return stack within a do-loop shall
* be removed before I, J, LOOP, +LOOP, UNLOOP, or LEAVE is
* executed;
* All values placed on the return stack within a definition
* shall be removed before the definition is terminated
* or before EXIT is executed.
*
**************************************************************************** */
static void bump_ret_stk_depth( int bump)
{
ret_stk_depth += bump;
}
/* **************************************************************************
*
* Function name: ret_stk_balance_rpt
* Synopsis: Display a Message if usage of the Return-Stack
* appears to be out of balance.
*
* Inputs:
* Parameters:
* before_what Phrase to use in Message;
* if NULL, use statbuf...
* clear_it TRUE if this call should also clear the
* Return-Stack-Usage-Depth counter
* Global Variables:
* statbuf Word currently being processed
* Local Static Variables:
* ret_stk_depth The Return-Stack-Usage-Depth counter
*
* Outputs:
* Returned Value: NONE
* Local Static Variables:
* ret_stk_depth May be cleared
*
* Error Detection:
* Based simply on whether the Return-Stack-Usage-Depth counter
* is zero. This is a weak and uncertain implementation;
* therefore, the Message will be a WARNING phrased with
* some equivocation.
*
* Process Explanation:
* Proper detection of Return-Stack usage errors is considerably
* more complex, and is deferred for a future revision.
*
* Still to be done:
* Correct analysis of Return-Stack usage around Flow-Control
* constructs. Consider, for instance, the following:
*
* blablabla >R yadayada IF R> gubble ELSE flubble R> THEN
*
* It is, in fact, correct, but the present scheme would
* tag it as a possible error. Conversely, something like:
*
* blablabla >R yadayada IF R> gubble THEN
*
* would not get tagged, even though it is actually an error.
*
* The current simple scheme also does not cover Return-Stack
* usage within Do-Loops or before Loop elements like I and
* J or UNLOOP or LEAVE. Implementing something like that
* would probably need to be integrated in with Flow-Control
* constructs, and will be noted in flowcontrol.c
*
**************************************************************************** */
static void ret_stk_balance_rpt( char *before_what, bool clear_it)
{
if ( ret_stk_depth != 0 )
{
char *what_flow = ret_stk_depth < 0 ? "deficit" : "excess" ;
char *what_phr = before_what != NULL ? before_what : strupr(statbuf);
tokenization_error( WARNING,
"Possible Return-Stack %s before %s", what_flow, what_phr);
in_last_colon( TRUE);
if ( clear_it )
{
ret_stk_depth = 0;
}
}
}
/* **************************************************************************
*
* Function name: ret_stk_access_rpt
* Synopsis: Display a Message if an attempt to access a value
* on the Return-Stack appears to occur before
* one was placed there.
*
* Inputs:
* Parameters: NONE
* Global Variables:
* statbuf Word currently being processed
* Local Static Variables:
* ret_stk_depth The Return-Stack-Usage-Depth counter
*
* Outputs:
* Returned Value: NONE
*
* Error Detection:
* Equivocal WARNING, based simply on whether the Return-Stack-
* -Usage-Depth counter not positive.
*
* Process Explanation:
* Proper detection is deferred...
*
* Still to be done:
* Correct analysis of Return-Stack usage...
*
**************************************************************************** */
static void ret_stk_access_rpt( void)
{
if ( ret_stk_depth <= 0 )
{
tokenization_error( WARNING,
"Possible Return-Stack access attempt by %s "
"without value having been placed there",
strupr(statbuf) );
in_last_colon( TRUE);
}
}
/* **************************************************************************
*
* Function name: encode_file
* Synopsis: Input a (presumably binary) file and encode it
* as a series of strings which will be accumulated
* and encoded in a manner appropriate for a property.
*
* Associated Tokenizer directive: encode-file
*
* Error Detection:
* Handled by support routines.
*
**************************************************************************** */
static void encode_file( const char *filename )
{
FILE *f;
size_t s;
int num_encoded=0;
tokenization_error( INFO, "ENCODing File %s\n", filename );
f = open_expanded_file( filename, "rb", "encoding");
if( f != NULL )
{
while( (s=fread(statbuf, 1, STRING_LEN_MAX, f)) )
{
emit_token("b(\")");
emit_string(statbuf, s);
emit_token("encode-bytes");
if( num_encoded )
emit_token("encode+");
num_encoded += s;
}
fclose( f );
tokenization_error ( INFO, "ENCODed %d bytes.\n", num_encoded);
}
}
/* **************************************************************************
*
* Function name: check_name_length
* Synopsis: If the length of a user-defined name exceeds the
* ANSI-specified maximum of 31 characters, issue
* a message. This is a hard-coded limit.
* Although our Tokenizer can handle longer names,
* they will cause big problems when encountered
* by an FCode interpreter.
* If the name is going to be included in the binary
* output, the message severity must be an ERROR.
* Otherwise, if the name is HEADERLESS, the severity
* can be reduced to a Warning; if the name is only
* defined in "Tokenizer Escape" mode the message
* severity can be further reduced to an Advisory.
*
* Inputs:
* Parameters:
* wlen Length of the newly-created word
* Global Variables:
* in_tokz_esc TRUE if in "Tokenizer Escape" mode.
* Local Static Variables:
* hdr_flag State of headered-ness for name-creation
*
* Outputs:
* Returned Value: NONE
* Global Variables:
* Printout: ERROR message if applicable.
*
* Error Detection:
* The whole point of this routine.
*
* Revision History:
* Updated Wed, 20 Jul 2005 by David L. Paktor
* Escalated from merely an informative warning to a TKERROR
* Updated Fri, 21 Oct 2005 by David L. Paktor
* Adjust severity if name doesn't go into the FCode anyway...
*
**************************************************************************** */
void check_name_length( signed long wlen )
{
if ( wlen > 31 )
{
int severity = TKERROR;
if ( in_tokz_esc )
{ severity = INFO;
}else{
if (hdr_flag == FLAG_HEADERLESS)
{ severity = WARNING;
}
}
tokenization_error( severity,
"ANSI Forth does not permit definition of names "
"longer than 31 characters.\n" );
}
}
/* **************************************************************************
*
* Function name: definer_name
* Synopsis: Given a defining-word internal token, return
* a printable string for the definer, for use
* in an error-message.
*
* Inputs:
* Parameters:
* definer Internal token for the defining-word
* reslt_ptr Pointer to string-pointer that takes
* the result, if successful
*
* Outputs:
* Returned Value: TRUE if definer was recognized
* Supplied Pointers:
* *reslt_ptr If successful, points to printable string;
* otherwise, left unchanged.
*
*
**************************************************************************** */
bool definer_name(fwtoken definer, char **reslt_ptr)
{
bool retval = TRUE;
switch (definer)
{
case VARIABLE:
*reslt_ptr = "VARIABLE";
break;
case DEFER:
*reslt_ptr = "DEFER";
break;
case VALUE:
*reslt_ptr = "VALUE";
break;
case BUFFER:
*reslt_ptr = "BUFFER";
break;
case CONST:
*reslt_ptr = "CONSTANT";
break;
case COLON:
*reslt_ptr = "COLON";
break;
case CREATE:
*reslt_ptr = "CREATE";
break;
case FIELD:
*reslt_ptr = "FIELD";
break;
case MACRO_DEF:
*reslt_ptr = "MACRO";
break;
case ALIAS:
*reslt_ptr = "ALIAS";
break;
case LOCAL_VAL:
*reslt_ptr = "Local Value name";
break;
default:
retval = FALSE;
}
return ( retval);
}
/* **************************************************************************
*
* Function name: as_a_what
* Synopsis: Add the phrase "as a[n] <DEF'N_TYPE>" for the given
* definition-type to the given string buffer.
*
* Inputs:
* Parameters:
* definer Internal token for the defining-word
* as_what The string buffer to which to add.
*
* Outputs:
* Returned Value: TRUE if an assigned name was found
* for the given definer and text
* was added to the buffer.
* Supplied Pointers:
* *as_what Text is added to this buffer.
*
* Process Explanation:
* The calling routine is responsible to make sure the size of
* the buffer is adequate. Allow 25 for this routine.
* The added text will not have spaces before or after; if any
* are needed, they, too, are the responsibility of the
* calling routine. The return value gives a helpful clue.
*
* Extraneous Remarks:
* We define a Macro -- kept in scanner.h --that will give the
* recommended length for the buffer passed to this routine.
* It will be called AS_WHAT_BUF_SIZE
*
**************************************************************************** */
bool as_a_what( fwtoken definer, char *as_what)
{
char *defn_type_name;
bool retval = definer_name(definer, &defn_type_name);
if ( retval )
{
strcat( as_what, "as a");
/* Handle article preceding definer name
* that starts with a vowel.
*/
/* HACK: Only one definer name -- ALIAS --
* begins with a vowel. Take advantage
* of that...
* Otherwise, we'd need to do something involving
* strchr( "AEIOU", defn_type_name[0] )
*/
if ( definer == ALIAS ) strcat( as_what, "n" );
strcat( as_what, " ");
strcat( as_what, defn_type_name);
}
return( retval);
}
/* **************************************************************************
*
* Function name: lookup_word
* Synopsis: Find the TIC-entry for the given word in the Current
* mode -- relative to "Tokenizer-Escape" -- and
* Scope into which definitions are being entered.
* Optionally, prepare text for various Message types.
*
* Inputs:
* Parameters:
* stat_name Word to look up
* where_pt1 Pointer to result-display string, part 1
* NULL if not preparing text
* where_pt2 Pointer to result-display string, part 2
* NULL if not preparing text
* Global Variables:
* in_tokz_esc TRUE if in "Tokenizer Escape" mode.
* scope_is_global TRUE if "global" scope is in effect
* current_device_node Current dev-node data-struct
* ibm_locals TRUE if IBM-style Locals are enabled
*
* Outputs:
* Returned Value: Pointer to TIC-entry; NULL if not found
* Supplied Pointers:
* *where_pt1 Result display string, part 1 of 2
* *where_pt2 Result display string, part 2 of 2
*
* Process Explanation:
* We will set the two-part result-display string in this routine
* because only here do we know in which vocabulary the word
* was found.
* Pre-load the two parts of the result-display string.
* If we are in "Tokenizer Escape" mode, look up the word: first,
* in the "Tokenizer Escape" Vocabulary, or, if not found,
* among the "Shared" words.
* Otherwise, we're in Normal" mode. Look it up: first, among the
* Locals, if IBM-style Locals are enabled (it can possibly be
* one if "Tokenizer Escape" mode was entered during a colon-
* -definition); then, if it was not found and if "Device"
* scope is in effect, look in the current device-node; then,
* if not found, in the "core" vocabulary.
* Load the second part of the result-display string with the
* appropriate phrase for whereever it was found.
* Then adjust the first part of the result-display string with
* the definer, if known.
*
* The two strings will be formatted to be printed adjacently,
* without any additional spaces in the printf() format.
* The first part of the result-display string will not start with
* a space, but will have an intermediate space if necessary.
* The second part of the result-display string will not start
* with a space, and will contain the terminating new-line
* if appropriate. It might or might not have been built
* with a call to in_what_node().
*
* If the calling routine displays the result-display strings,
* it should follow-up with a call to show_node_start()
* This will be harmless if in_what_node() was not used
* in the construction of the result-display string.
* If the calling routine is NOT going to display the result strings,
* it should pass NULLs for the string-pointer pointers.
*
* The second part of the string consists of pre-coded phrases;
* therefore, we can directly assign the pointer.
* The first part of the string, however, has developed into
* something constructed "on the fly". Earlier, it, too,
* had been a directly-assignable pointer; all the callers
* to this routine expect that. Rather than change all the
* callers, we will assign a local buffer for it.
*
* Extraneous Remarks:
* We had to add the rule allowing where_pt1 or where_pt2 to be
* NULL after we introduced the in_what_node() function.
* We had cases where residue from a lookup for processing
* showed up later in an unrelated Message. The NULL rule
* should prevent that.
*
**************************************************************************** */
static char lookup_where_pt1_buf[AS_WHAT_BUF_SIZE];
tic_hdr_t *lookup_word( char *stat_name, char **where_pt1, char **where_pt2 )
{
tic_hdr_t *found = NULL;
bool trail_space = TRUE;
bool doing_lookup = BOOLVAL( ( where_pt1 != NULL )
&& ( where_pt2 != NULL ) );
char *temp_where_pt2 = "in the core vocabulary.\n";
lookup_where_pt1_buf[0] = 0; /* Init'lz part-1 buffer */
/* "Core vocab" refers both to shared fwords and built-in tokens. */
/* Distinguish between "Normal" and "Tokenizer Escape" mode */
if ( in_tokz_esc )
{ /* "Tokenizer Escape" mode. */
found = lookup_tokz_esc( stat_name);
if ( found != NULL )
{
temp_where_pt2 = in_tkz_esc_mode;
}else{
/* "Core vocabulary". */
found = lookup_shared_word( stat_name);
}
}else{
/* "Normal" tokenization mode */
if ( ibm_locals )
{
found = lookup_local( stat_name);
if ( doing_lookup && ( found != NULL ) )
{
trail_space = FALSE;
temp_where_pt2 = ".\n";
}
}
if ( found == NULL )
{
found = lookup_in_dev_node( stat_name);
if ( found != NULL )
{
if ( doing_lookup )
{
temp_where_pt2 = in_what_node( current_device_node);
}
}else{
/* "Core vocabulary". */
found = lookup_core_word( stat_name);
}
}
}
if ( ( doing_lookup ) && ( found != NULL ) )
{
if ( as_a_what( found->fword_defr, lookup_where_pt1_buf) )
{
if ( trail_space )
{
strcat(lookup_where_pt1_buf, " ");
}
}
*where_pt1 = lookup_where_pt1_buf;
*where_pt2 = temp_where_pt2;
}
return( found);
}
/* **************************************************************************
*
* Function name: word_exists
* Synopsis: Check whether a given word is already defined in the
* Current mode -- relative to "Tokenizer-Escape" --
* and Scope into which definitions are being entered.
* Used for error-reporting.
*
* Inputs:
* Parameters:
* stat_name Word to look up
* where_pt1 Pointer to string, part 1 of 2,
* to display in result
* where_pt2 Pointer to string, part 2 of 2,
* to display in result
*
* Outputs:
* Returned Value: TRUE if the name exists.
* Supplied Pointers:
* *where_pt1 Result display string, part 1 of 2
* *where_pt2 Result display string, part 2 of 2
*
* Process Explanation:
* If the calling routine displays the result-display strings,
* it should follow-up with a call to show_node_start()
*
* Extraneous Remarks:
* This used to be a much heftier routine; now it's just
* a wrapper around lookup_word() .
*
**************************************************************************** */
bool word_exists( char *stat_name, char **where_pt1, char **where_pt2 )
{
bool retval = FALSE;
tic_hdr_t *found = lookup_word( stat_name, where_pt1, where_pt2 );
if ( found != NULL )
{
retval = TRUE;
}
return( retval);
}
/* **************************************************************************
*
* Function name: warn_if_duplicate
* Synopsis: Check whether a given word is already defined in
* the current mode and issue a warning if it is.
*
* Inputs:
* Parameters:
* stat_name Word to check
* Global Variables:
* verbose_dup_warning Whether to run the check at all.
* Local Static Variables:
* do_not_overload FALSE if OVERLOAD is in effect.
*
* Outputs:
* Returned Value: NONE
* Local Static Variables:
* do_not_overload Restored to TRUE
* Printout:
* Warning message if a duplicate.
*
* Error Detection:
* None. This is merely an informative warning.
*
* Process Explanation:
* "Current mode" -- meaning, whether the tokenizer is operating
* in "Tokenizer Escape" mode or in normal tokenization mode --
* will be recognized by the word_exists() function.
*
* Extraneous Remarks:
* The OVERLOAD directive is our best shot at creating a more
* fine-grained way to temporarily bypass this test when
* deliberately overloading a name. It would be nice to have
* a mechanism, comparable to the classic
* WARNING @ WARNING OFF ..... WARNING !
* that could be applied to a range of definitions, but:
* (1) That would require more of a true FORTH infrastructure;
* hence, more effort than I am willing to invest, at
* this juncture, for such a small return,
* and
* (2) Most intentional-overloading ranges only cover a
* single definition anyway.
*
**************************************************************************** */
void warn_if_duplicate( char *stat_name)
{
if ( verbose_dup_warning && do_not_overload )
{
char *where_pt1;
char *where_pt2;
if ( word_exists( stat_name, &where_pt1, &where_pt2) )
{
tokenization_error( WARNING,
"Duplicate definition: %s already exists %s%s",
stat_name, where_pt1, where_pt2 );
show_node_start();
}
}
do_not_overload = TRUE;
}
/* **************************************************************************
*
* Function name: glob_not_allowed
* Synopsis: Print a Message that "XXX is not allowed."
* because Global Scope is in effect.
* Used from several places...
*
* Inputs:
* Parameters:
* severity Severity of the Message
* not_ignoring FALSE = "Ignoring", for the part of the
* message about "How It's being Handled"
* Global Variables:
* statbuf Disallowed word currently being processed
*
* Outputs:
* Returned Value: NONE
* Printout: Message of given severity.
*
**************************************************************************** */
static void glob_not_allowed( int severity, bool not_ignoring)
{
tokenization_error( severity, "Global Scope is in effect; "
"%s not allowed. %s.\n",
strupr(statbuf),
not_ignoring ?
"Attempting to compensate.." :
"Ignoring" );
}
/* **************************************************************************
*
* Function name: not_in_dict
* Synopsis: Print the message "XXX is not in dictionary."
* Used from several places...
*
* Inputs:
* Parameters:
* stat_name Word that could not be processed
*
* Outputs:
* Returned Value: NONE
* Printout: Error message.
*
**************************************************************************** */
static void not_in_dict( char *stat_name)
{
tokenization_error ( TKERROR,
"Word %s is not in dictionary.\n", stat_name);
}
/* **************************************************************************
*
* Function name: tokenized_word_error
* Synopsis: Report an error when a word could not be processed
* by the tokenizer. Messages will vary...
*
* Inputs:
* Parameters:
* stat_name Word that could not be processed
* Global Variables:
* in_tokz_esc TRUE if tokenizer is in "Tokenizer Escape" mode.
*
* Outputs:
* Returned Value: NONE
* Printout:
* Error message.
* Possible Advisory about where the word might be found.
* Trace-Note, if the word was on the Trace-List
*
* Error Detection:
* Error was detected by the calling routine...
*
* Process Explanation:
* If the tokenizer is in "Tokenizer Escape" mode, the word might
* be one that can be used in normal tokenization mode;
* Conversely, if the tokenizer is in normal-tokenization mode,
* the word might be one that can be used in the "Escape" mode.
* Or, the word is completely unknown.
* Recognizing the current mode is handled by word_exists()
* However, we need to test for the *converse* of the current mode,
* so before we call word_exists() we are going to save and
* invert the setting of in_tokz_esc (and afterwards, of
* course, restore it...)
*
**************************************************************************** */
static void tokenized_word_error( char *stat_name)
{
char *where_pt1;
char *where_pt2;
bool found_somewhere;
bool sav_in_tokz_esc = in_tokz_esc;
in_tokz_esc = INVERSE(sav_in_tokz_esc);
traced_name_error( stat_name);
found_somewhere = word_exists( stat_name, &where_pt1, &where_pt2);
if ( found_somewhere )
{
tokenization_error ( TKERROR, "The word %s is %s recognized "
"in tokenizer-escape mode.\n",
stat_name, sav_in_tokz_esc ? "not" : "only" );
} else {
not_in_dict( stat_name);
}
if ( INVERSE(exists_in_ancestor( stat_name)) )
{
if ( found_somewhere && sav_in_tokz_esc )
{
tokenization_error(INFO,
"%s is defined %s%s", stat_name, where_pt1, where_pt2 );
show_node_start();
}
}
in_tokz_esc = sav_in_tokz_esc;
}
/* **************************************************************************
*
* Function name: unresolved_instance
* Synopsis: Print the "unresolved instance" message
*
* Inputs:
* Parameters:
* severity Severity of the Message
* Local Static Variables:
* instance_filename File where "instance" invoked
* instance_lineno Line number where "instance" invoked
*
* Outputs:
* Returned Value: NONE
* Printout: Message.
*
* Error Detection:
* Error was detected by the calling routine...
*
**************************************************************************** */
static void unresolved_instance( int severity)
{
tokenization_error( severity, "Unresolved \"INSTANCE\"" );
just_where_started( instance_filename, instance_lineno );
}
/* **************************************************************************
*
* Function name: modified_by_instance
* Synopsis: Print the "[not] modified by instance" message
*
* Inputs:
* Parameters:
* definer Internal token for the defining-word
* was_modded FALSE if "not modified..."
* Local Static Variables:
* instance_filename File where "instance" invoked
* instance_lineno Line number where "instance" invoked
*
* Outputs:
* Returned Value: NONE
* Printout: WARNING message.
*
* Error Detection:
* Error was detected by the calling routine...
*
**************************************************************************** */
static void modified_by_instance( fwtoken definer, bool was_modded)
{
char *was_not = was_modded ? "was" : "not" ;
char *defn_type_name;
/* No need to check the return value */
definer_name(definer, &defn_type_name);
tokenization_error ( WARNING,
"%s definition %s modified by \"INSTANCE\"",
defn_type_name, was_not );
just_where_started( instance_filename, instance_lineno );
}
/* **************************************************************************
*
* Function name: validate_instance
* Synopsis: If "instance" is in effect, check whether it is
* appropriate to the defining-word being called.
*
* Inputs:
* Parameters:
* definer Internal token for the defining-word
* Local Static Variables:
* is_instance TRUE if "instance" is in effect.
* instance_definer_gap TRUE if invalid definer(s) invoked
* since "instance" went into effect.
*
* Outputs:
* Returned Value: NONE
* Local Static Variables:
* is_instance Reset to FALSE if definer was valid.
* instance_definer_gap TRUE if definer was not valid;
* FALSE if definer was valid.
*
* Error Detection:
* If "instance" is in effect, the only defining-words that are
* valid are: value variable defer or buffer: Attempts
* to use any other defining-word will be reported with a
* WARNING, but "instance" will remain in effect.
* If an invalid defining-word was invoked since "instance" went
* into effect, then, when it is finally applied to a valid
* definer, issue a WARNING.
*
* Process Explanation:
* Implicit in the Standard is the notion that, once INSTANCE has
* been executed, it remains in effect until a valid defining-
* word is encountered. We will do the same.
*
**************************************************************************** */
static void validate_instance(fwtoken definer)
{
if ( is_instance )
{
bool is_error = TRUE ;
switch ( definer)
{
case VALUE:
case VARIABLE:
case DEFER:
case BUFFER:
is_error = FALSE;
/* No default needed, likewise, no breaks; */
/* but some compilers get upset without 'em... */
default:
break;
}
if( is_error )
{
modified_by_instance(definer, FALSE );
instance_definer_gap = TRUE;
}else{
if ( instance_definer_gap )
{
modified_by_instance(definer, TRUE );
}
is_instance = FALSE;
instance_definer_gap = FALSE;
}
}
}
/* **************************************************************************
*
* Function name: create_word
* Synopsis:
*
* Inputs:
* Parameters:
* definer Internal token for the defining-word
* Global Variables:
* control_stack_depth Number of "Control Stack" entries in effect
* nextfcode FCode-number to be assigned to the new name
* statbuf Symbol last read from the input stream
* pc Input-source Scanning pointer
* hdr_flag State of headered-ness for name-creation
* force_tokens_case If TRUE, force token-names' case in FCode
* force_lower_case_tokens
* If force_tokens_case is TRUE, this
* determines which case to force
* iname Input-source file name; for error-reporting
* lineno Input-source Line number; also for err-rep't
*
* Outputs:
* Returned Value: TRUE if successful
* Global Variables:
* nextfcode Incremented (by bump_fcode() )
* statbuf Advanced to next symbol; must be re-read
* pc Advanced, then restored to previous value
* define_token Normally TRUE. Made FALSE if the definition
* occurs inside a control-structure, (which
* is an Error); we allow the definition to
* proceed (so as to avoid "cascade" errors
* and catch other errors normally) but we
* suppress adding its token to the vocab,
* "hiding" it and "revealing" it (because
* there's nothing to hide).
* NOTE: Make this a Global. Use it in the routines it controls...
* Memory Allocated
* Copy of the name being defined, by support routine.
* Copy of input-source file name, for error-reporting
* When Freed?
* Copy of name being defined is freed when Current Device Vocab
* is "finished", or at end of tokenization.
* Copy of input-source file name is freed at end of this routine.
*
* Error Detection:
* ERROR if already inside a colon-definition. Discontinue
* processing and return FALSE.
* ERROR if inside a control-structure. Continue processing,
* though, to catch other errors, and even return TRUE;
* except: leave the new token undefined.
* Warning on duplicate name (subject to command-line control)
* Message if name is excessively long; Warning if headerless.
* FATAL if the value of nextfcode is larger than the legal
* maximum for an FCode, (0x0fff).
*
* Revision History:
* Updated Thu, 24 Mar 2005 by David L. Paktor
* Optional warning when name about to be created is a
* duplicate of an existing name.
* Updated Wed, 30 Mar 2005 by David L. Paktor
* Warning when name length exceeds ANSI-specified max (31 chars).
* Updated Tue, 05 Apr 2005 by David L. Paktor
* Add "definer" parameter and call to add_definer() . Part
* of the mechanism to forbid attempts to use the TO
* directive to change values of CONSTANTs in particular
* and of inappropriate targets in general.
* Updated Fri, 06 May 2005 by David L. Paktor
* Error-detection of DO ... LOOP and BEGIN ... imbalance
* Error-detection of nextfcode exceeding legal maximum (0x0fff).
* Updated Wed, 20 Jul 2005 by David L. Paktor
* Put Duplicate-Name-Test under command-line control...
* Updated Wed, 24 Aug 2005 by David L. Paktor
* Error-detection via clear_control_structs() routine.
* Updated Tue, 10 Jan 2006 by David L. Paktor
* Convert to tic_hdr_t type vocabulary.
* Updated Thu, 20 Apr 2006 by David L. Paktor
* Allow creation of new definition within body of a flow-control
* structure. (Remove error-detection via clear_control_structs)
* Updated Tue, 13 Jun 2006 by David L. Paktor
* Move detection of out-of-bounds nextfcode to assigning_fcode()
* routine, which also detects Overlapping Ranges error.
* Updated Thu, 27 Jun 2006 by David L. Paktor
* Report Error for attempt to create def'n inside control structure.
*
* Extraneous Remarks:
* We must not set incolon to TRUE (if we are creating a colon
* definition) until *AFTER* this routine has been called, due
* to the initial error-checking. If we need to detect whether
* we are creating a colon definition, we can do so by testing
* whether the parameter, DEFINER, equals COLON .
*
**************************************************************************** */
static bool create_word(fwtoken definer)
{
signed long wlen;
bool retval = FALSE;
char *defn_type_name;
/* If already inside a colon, ERROR and discontinue processing */
/* If an alias to a definer is used, show the name of the alias */
if ( test_in_colon(statbuf, FALSE, TKERROR, NULL) )
{
char defn_type_buffr[32] = "";
unsigned int old_lineno = lineno; /* For error message */
define_token = TRUE;
{ /* Set up definition-type text for error-message */
/* No need to check the return value */
definer_name(definer, &defn_type_name);
strcat( defn_type_buffr, defn_type_name);
strcat( defn_type_buffr, " definition");
}
/* If in a control-structure, ERROR but continue processing */
if ( control_stack_depth != 0 )
{
announce_control_structs( TKERROR, defn_type_buffr, 0);
/* Leave the new token undefined. */
define_token = FALSE;
}
/* Get the name of the new token */
wlen = get_word();
#ifdef DEBUG_SCANNER
printf("%s:%d: debug: defined new word %s, fcode no 0x%x\n",
iname, lineno, name, nextfcode);
#endif
if ( wlen <= 0 )
{
warn_unterm( TKERROR, defn_type_buffr, old_lineno);
}else{
bool emit_token_name = TRUE;
/* Other Error or Warnings as applicable */
validate_instance( definer);
/* Bump FCode; error-check as applicable */
assigning_fcode();
/* Define the new token, unless disallowed */
add_to_current( statbuf, nextfcode, definer);
check_name_length( wlen);
/* Emit appropriate FCodes: Type of def'n, */
switch ( hdr_flag )
{
case FLAG_HEADERS:
emit_token("named-token");
break;
case FLAG_EXTERNAL:
emit_token("external-token");
break;
default: /* FLAG_HEADERLESS */
emit_token("new-token");
emit_token_name = FALSE;
}
/* Emit name of token, if applicable */
if ( emit_token_name )
{
if ( force_tokens_case )
{
if ( force_lower_case_tokens )
{
strlwr( statbuf);
}else{
strupr( statbuf);
}
}
emit_string((u8 *)statbuf, wlen);
}
/* Emit the new token's FCode */
emit_fcode(nextfcode);
/* Prepare FCode Assignment Counter for next definition */
bump_fcode();
/* Declare victory */
retval = TRUE;
}
}
return( retval);
}
/* **************************************************************************
*
* Function name: cannot_apply
* Synopsis: Print error message of the form:
* "Cannot apply <func> to <targ>, which is a <def'n>"
*
* Inputs:
* Parameters:
* func_nam The name of the function
* targ_nam The name of the target
* defr The numeric-code of the definer-type
*
* Outputs:
* Returned Value: NONE
* Printout:
* The error message is the entire printout of this routine
*
* Error Detection:
* Error was detected by calling routine
*
* Process Explanation:
* The calling routine already looked up the definer for its
* own purposes, so we don't need to do that again here.
*
* Still to be done:
* If the definer-name is not found, we might still look up
* the target name in the various vocabularies and use
* a phrase for those. E.g., if it is a valid token,
* we could say it's defined as a "primitive". (I'm
* not sure what we'd say about an FWord...)
*
**************************************************************************** */
static void cannot_apply( char *func_nam, char *targ_nam, fwtoken defr)
{
char *defr_name = "" ;
char *defr_phrase = wh_defined ;
if ( ! definer_name(defr, &defr_name) )
{
defr_phrase = "";
}
tokenization_error ( TKERROR ,
"Cannot apply %s to %s %s%s.\n",
func_nam, targ_nam, defr_phrase, defr_name );
}
/* **************************************************************************
*
* Function name: lookup_with_definer
* Synopsis: Return pointer to data-structure of named word,
* if it's valid in Current context, and supply its
* definer. If it's not valid in Current context,
* see if it might be a Local, and supply that definer.
*
* Inputs:
* Parameters:
* stat_name Name to look up
* *definr Pointer to place to put the definer.
*
* Outputs:
* Returned Value: Pointer to data-structure, or
* NULL if not in Current context.
* Supplied Pointers:
* *definr Definer; possibly LOCAL_VAL
*
* Process Explanation:
* If the name is not found in the Current context, and does not
* exist as a Local, *definr will remain unchanged.
*
* Extraneous Remarks:
* This is an odd duck^H^H^H^H^H^H^H^H^H^H^H^H a highly-specialized
* routine created to meet some corner-case needs engendered by
* the conversion to tic_hdr_t vocabularies all around, combined
* with an obsessive urge to preserve a high level of detail in
* our error-messages.
*
**************************************************************************** */
static tic_hdr_t *lookup_with_definer( char *stat_name, fwtoken *definr )
{
tic_hdr_t *retval = lookup_current( stat_name);
if ( retval != NULL )
{
*definr = retval->fword_defr;
}else{
if ( exists_as_local( stat_name) ) *definr = LOCAL_VAL;
}
return ( retval );
}
/* **************************************************************************
*
* Function name: validate_to_target
* Synopsis: Print a message if the intended target
* of the TO directive is not valid
*
* Inputs:
* Parameters: NONE
* Global Variables:
* statbuf Next symbol to be read from the input stream
* pc Input-source Scanning pointer
*
* Outputs:
* Returned Value: TRUE = Allow b(to) token to be output.
* Global Variables:
* statbuf Advanced to next symbol; must be re-read
* pc Advanced, then restored to previous value
*
* Error Detection:
* If next symbol is not a valid target of TO , issue ERROR
* message. Restored pc will cause the next symbol to
* be processed by ordinary means.
* Allow b(to) token to be output in selected cases. Even if
* user has set the "Ignore Errors" flag, certain targets are
* still too risky to be allowed to follow a b(to) token;
* if "Ignore Errors" is not set, output won't get created
* anyway.
* Issue ERROR in the extremely unlikely case that "to" is the
* last word in the Source.
*
* Process Explanation:
* Valid targets for a TO directive are words defined by:
* DEFER, VALUE and arguably VARIABLE. We will also allow
* CONSTANT, but will still issue an Error message.
* After the check, restore pc ; this was only a look-ahead.
* Also restore lineno and abs_token_no
*
* Extraneous Remarks:
* Main part of the mechanism to detect attempts to use the TO
* directive to change the values of CONSTANTs in particular
* and of inappropriate targets in general.
*
**************************************************************************** */
static bool validate_to_target( void )
{
signed long wlen;
tic_hdr_t *test_entry;
u8 *saved_pc = pc;
char *cmd_cpy = strupr( strdup( statbuf)); /* For error message */
unsigned int saved_lineno = lineno;
unsigned int saved_abs_token_no = abs_token_no;
fwtoken defr = UNSPECIFIED ;
bool targ_err = TRUE ;
bool retval = FALSE ;
wlen = get_word();
if ( wlen <= 0 )
{
warn_unterm( TKERROR, cmd_cpy, saved_lineno);
}else{
test_entry = lookup_with_definer( statbuf, &defr);
if ( test_entry != NULL )
{
switch (defr)
{
case VARIABLE:
tokenization_error( WARNING,
"Applying %s to a VARIABLE (%s) is "
"not recommended; use ! instead.\n",
cmd_cpy, statbuf);
case DEFER:
case VALUE:
targ_err = FALSE ;
case CONST:
retval = TRUE ;
/* No default needed, likewise, no breaks; */
/* but some compilers get upset without 'em... */
default:
break;
}
}
if ( targ_err )
{
cannot_apply(cmd_cpy, strupr(statbuf), defr );
}
pc = saved_pc;
lineno = saved_lineno;
abs_token_no = saved_abs_token_no;
}
free( cmd_cpy);
return( retval);
}
/* **************************************************************************
*
* Function name: you_are_here
* Synopsis: Display a generic Advisory of the Source command
* or directive encountered and being processed
*
* Inputs:
* Parameters: NONE
* Global Variables:
* statbuf The command being processed
*
* Outputs:
* Returned Value: NONE
* Printout:
* Advisory message
*
**************************************************************************** */
static void you_are_here( void)
{
tokenization_error( INFO,
"%s encountered; processing...\n",
strupr(statbuf) );
}
/* **************************************************************************
*
* Function name: fcode_starter
* Synopsis: Respond to one of the "FCode Starter" words
*
* Inputs:
* Parameters:
* token_name The FCode-token for this "Starter" word
* spread The separation between tokens.
* is_offs16 Whether we are using a 16-bit number
* for branch- (and suchlike) -offsets,
* or the older-style 8-bit offset numbers.
* Global Variables:
* iname Input-File name, used to set ifile_name
* field of current_device_node
* lineno Current Input line number, used to set
* line_no field of current_device_node
* Local Static Variables:
* fcode_started If this is TRUE, we have an Error.
* first_fc_starter Control calling reset_fcode_ranges() ;
* only on the first fcode_starter of
* a tokenization.
*
* Outputs:
* Returned Value: NONE
* Global Variables:
* offs16 Global "16-bit-offsets" flag
* current_device_node The ifile_name and line_no fields will be
* loaded with the current input file name
* and line number. This node will be the
* top-level device-node.
* FCode Ranges will be reset the first time per tokenization
* that this routine is entered.
* A new FCode Range will be started every time after that.
* Local Static Variables:
* fcode_started Set to TRUE. We invoke the starter only
* once per image-block.
* first_fc_starter Reset to FALSE if not already
* Memory Allocated
* Duplicate of Input-File name
* When Freed?
* In fcode_ender()
*
* Error Detection:
* Spread of other than 1 -- Warning message.
* "FCode Starter" previously encountered -- Warning and ignore.
*
* Question under consideration:
* Do we want directives -- such as definitions of constants --
* supplied before the "FCode Starter", to be considered as
* taking place in "Tokenizer Escape" mode? That would mean
* the "Starter" functions must be recognized in "Tokenizer
* Escape" mode. Many ramifications to be thought through...
* I think I'm coming down strongly on the side of "No". The user
* who wants to do that can very well invoke "Tokenizer Escape"
* mode explicitly.
*
**************************************************************************** */
static void fcode_starter( const char *token_name, int spread, bool is_offs16)
{
you_are_here();
if ( spread != 1 )
{
tokenization_error( WARNING, "spread of %d not supported.\n", spread);
}
if ( fcode_started )
{
tokenization_error( WARNING,
"Only one \"FCode Starter\" permitted per tokenization. "
"Ignoring...\n");
} else {
emit_fcodehdr(token_name);
offs16 = is_offs16;
fcode_started = TRUE;
current_device_node->ifile_name = strdup(iname);
current_device_node->line_no = lineno;
if ( first_fc_starter )
{
reset_fcode_ranges();
first_fc_starter = FALSE;
}else{
set_next_fcode( nextfcode);
}
}
}
/* **************************************************************************
*
* Function name: fcode_end_err_check
* Synopsis: Do error-checking at end of tokenization,
* whether due to FCODE-END or end-of-file,
* and reset the indicators we check.
*
* Inputs:
* Parameters: NONE
* Global Variables:
* Data-Stack depth Is anything left on the stack?
*
* Outputs:
* Returned Value: NONE
* Global Variables:
* Data-Stack Reset to empty
*
* Error Detection:
* Unresolved control structures detected by clear_control_structs()
* If anything is left on the stack, it indicates some incomplete
* condition; we will treat it as a Warning.
*
**************************************************************************** */
static void fcode_end_err_check( void)
{
bool stack_imbal = BOOLVAL( stackdepth() != 0 );
if ( stack_imbal )
{
tokenization_error( WARNING,
"Stack imbalance before end of tokenization.\n");
}
clear_stack();
clear_control_structs("End of tokenization");
}
/* **************************************************************************
*
* Function name: fcode_ender
* Synopsis: Respond to one of the "FCode Ender" words:
* The FCode-token for "End0" or "End1"
* has already been written to the
* FCode Output buffer.
* Finish the FCode header: fill in its
* checksum and length.
* Reset the token names defined in "normal" mode
* (Does not reset the FCode-token number)
*
* Associated FORTH words: END0, END1
* Associated Tokenizer directive: FCODE-END
*
* Inputs:
* Parameters: NONE
* Global Variables:
* incolon If TRUE, a colon def'n has not been completed
* last_colon_filename For error message.
* last_colon_lineno For error message.
* scope_is_global For error detection
* is_instance For error detection
*
* Outputs:
* Returned Value: NONE
* Global Variables:
* haveend Set to TRUE
* fcode_started Reset to FALSE. Be ready to start anew.
* FCode-defined tokens, aliases and macros -- i.e., those
* *NOT* defined in tokenizer-escape mode -- are reset.
* (Also, command-line-defined symbols are preserved).
* Vocabularies will be reset
* Device-node data structures will be deleted
* Top-level device-node ifile_name and line_no fields
* will be reset.
* Memory Freed
* Duplicate of Input-File name, in top-level device-node.
* Printout:
* Advisory message giving current value of nextfcode
* (the "FCode-token Assignment Counter")
*
* Error Detection:
* ERROR if a Colon definition has not been completed.
* ERROR if "instance" is still in effect
* WARNING if Global-Scope has not been terminated; compensate.
*
* Extraneous Remarks:
* In order to accommodate odd cases, such as multiple FCode blocks
* within a single PCI header, this routine does not automatically
* reset nextfcode to h# 0800
*
**************************************************************************** */
void fcode_ender(void)
{
if ( incolon )
{
char *tmp_iname = iname;
iname = last_colon_filename;
unterm_is_colon = TRUE;
warn_unterm( TKERROR, "Colon Definition", last_colon_lineno);
iname = tmp_iname;
}
haveend = TRUE;
if ( is_instance )
{
unresolved_instance( TKERROR);
}
if ( scope_is_global )
{
tokenization_error( WARNING ,
"No DEVICE-DEFINITIONS directive encountered before end. "
"Compensating...\n");
resume_device_scope();
}
fcode_end_err_check();
reset_normal_vocabs();
finish_fcodehdr();
fcode_started = FALSE;
if ( current_device_node->ifile_name != default_top_dev_ifile_name )
{
free( current_device_node->ifile_name );
current_device_node->ifile_name = default_top_dev_ifile_name;
current_device_node->line_no = 0;
}
}
/* **************************************************************************
*
* Function name: get_token
* Synopsis: Read the next word in the input stream and retrieve
* its FCode-token number. If it's not a symbol to
* which a single token is assigned (e.g., if it's
* a macro), report an error.
*
* Associated FORTH words: ['] '
* Associated Tokenizer directive: F[']
*
* Inputs:
* Parameters:
* *tok_entry Place to put the pointer to token entry
* Global Variables:
* statbuf The command being processed
* pc Input stream character pointer
*
* Outputs:
* Returned Value: TRUE if successful (i.e., no error)
* Supplied Pointers:
* *tok_entry The token entry, if no error.
* Unchanged if error.
* Global Variables:
* statbuf The next word in the input stream
* pc Restored to previous value if error
* Other Effects:
* Display Invocation Message if entry found and is being Traced
*
* Error Detection:
* The next word in the input stream is expected to be on the
* same line as the directive. The get_word_in_line()
* routine will check for that.
* If the next word in the input stream is a known symbol, but
* not one for which a single-token FCode number is assigned,
* report an ERROR and restore PC to its previous value. The
* supplied pointer tok_entry will remain unaltered.
*
**************************************************************************** */
static bool get_token(tic_hdr_t **tok_entry)
{
bool retval = FALSE;
tic_hdr_t *found;
u8 *save_pc;
/* Copy of command being processed, for error message */
char cmnd_cpy[FUNC_CPY_BUF_SIZE+1];
strncpy( cmnd_cpy, statbuf, FUNC_CPY_BUF_SIZE);
cmnd_cpy[FUNC_CPY_BUF_SIZE] = 0; /* Guarantee null terminator. */
save_pc = pc;
if ( get_word_in_line( statbuf) )
{
fwtoken defr = UNSPECIFIED;
/* We need to scan the newest definitions first; they
* might supercede standard ones. We need, though,
* to bypass built-in FWords that need to trigger
* some tokenizer internals before emitting their
* synonymous FCode Tokens, (e.g., version1 , end0 ,
* and start{0-4}); if we find one of those, we will
* need to search again, specifically within the list
* of FCode Tokens.
*/
found = lookup_with_definer( statbuf, &defr);
if ( found != NULL )
{
/* Built-in FWords can be uniquely identified by their
* definer, BI_FWRD_DEFN . The definer for "shared"
* FWords is COMMON_FWORD but there are none of
* those that might be synonymous with legitimate
* FCode Tokens, nor are any likely ever to be...
*/
if ( defr == BI_FWRD_DEFN )
{
found = lookup_token( statbuf);
retval = BOOLVAL( found != NULL );
}else{
retval = entry_is_token( found);
}
}
handle_invocation( found);
if ( retval)
{
*tok_entry = found;
}else{
cannot_apply( cmnd_cpy, strupr(statbuf), defr );
pc = save_pc;
}
}
return ( retval );
}
static void base_change ( int new_base )
{
if ( incolon && ( INVERSE( in_tokz_esc) ) )
{
emit_literal(new_base );
emit_token("base");
emit_token("!");
} else {
base = new_base;
}
}
static void base_val (int new_base)
{
u8 *old_pc;
char base_cmnd[FUNC_CPY_BUF_SIZE+1];
strncpy( base_cmnd, statbuf, FUNC_CPY_BUF_SIZE);
base_cmnd[FUNC_CPY_BUF_SIZE] = 0; /* Guarantee NULL terminator */
old_pc=pc;
if ( get_word_in_line( statbuf) )
{
u8 basecpy=base;
base = new_base;
if ( ! handle_number() )
{
/* We did get a word on the line, but it's not a valid number */
tokenization_error( WARNING ,
"Applying %s to non-numeric value. Ignoring.\n",
strupr(base_cmnd) );
pc = old_pc;
}
base=basecpy;
}
}
/* **************************************************************************
*
* Function name: eval_string
* Synopsis: Prepare to tokenize a string, artificially generated
* by this program or created as a user-defined
* Macro. When done, resume at existing source.
* Keep the file-name and line-number unchanged.
*
* Inputs:
* Parameters:
* inp_bufr String (or buffer) to evaluate
*
* Outputs:
* Returned Value: NONE
* Global Variables, changed by call to init_inbuf():
* start Points to given string
* pc ditto
* end Points to end of given string
*
* Revision History:
* Updated Thu, 23 Feb 2006 by David L. Paktor
* This routine no longer calls its own instance of tokenize()
* It has become the gateway to the mechanism that makes a
* smooth transition between the body of the Macro, User-
* defined Symbol or internally-generated string and the
* resumption of processing the source file.
* A similar (but more complicated) transition when processing
* an FLOADed file will be handled elsewhere.
* Updated Fri, 24 Feb 2006 by David L. Paktor
* In order to support Macro-recursion protection, this routine
* is no longer the gateway for Macros; they will have to
* call push_source() directly.
*
**************************************************************************** */
void eval_string( char *inp_bufr)
{
push_source( NULL, NULL, FALSE);
init_inbuf( inp_bufr, strlen(inp_bufr));
}
/* **************************************************************************
*
* Function name: finish_or_new_device
* Synopsis: Handle the shared logic for the NEW-DEVICE and
* FINISH-DEVICE commands.
*
* Inputs:
* Parameters:
* finishing_device TRUE for FINISH-DEVICE,
* FALSE for NEW-DEVICE
* Global Variables:
* incolon TRUE if inside a colon definition
* noerrors TRUE if ignoring errors
* scope_is_global TRUE if "global scope" in effect
* Local Static Variables:
* is_instance TRUE if "instance" is in effect
* dev_change_instance_warning TRUE if warning hasn't been issued
*
* Outputs:
* Returned Value: NONE
* Local Static Variables:
* dev_change_instance_warning FALSE if warning is issued
* instance_definer_gap TRUE if "instance" is in effect
*
* Error Detection:
* NEW-DEVICE and FINISH-DEVICE should not be used outside of
* a colon-definition if global-scope is in effect. Error
* message; no further action unless we are ignoring errors.
* Issue a WARNING if INSTANCE wasn't resolved before the current
* device-node is changed. Try not to be too repetitive...
*
* Process Explanation:
* The words NEW-DEVICE and FINISH-DEVICE may be incorporated into
* a colon-definition, whether the word is defined in global-
* or device- -scope. Such an incorporation does not effect
* a change in the device-node vocabulary; simply emit the token.
* If we are in interpretation mode, though, we need to check for
* errors before changing the device-node vocabulary:
* If global-scope is in effect, we need to check whether we are
* ignoring errors; if so, we will compensate by switching to
* device-scope.
* If "instance" is in effect, it's "dangling". It will remain
* in effect through a device-node change, but this is very
* bad style and deserves a WARNING, but only one for each
* occurrence. It would be unaesthetic, to say the least,
* to have multiple messages for the same dangling "instance"
* in a "finish-device new-device" sequence.
* We must be careful about the order we do things, because of
* the messages printed as a side-effect of the node change...
*
* Extraneous Remarks:
* I will violate strict structure here.
*
**************************************************************************** */
static void finish_or_new_device( bool finishing_device )
{
if ( INVERSE( incolon ) )
{
if ( INVERSE( is_instance) )
{
/* Arm warning for next time: */
dev_change_instance_warning = TRUE;
}else{
/* Dangling "instance" */
instance_definer_gap = TRUE;
/* Warn only once. */
if ( dev_change_instance_warning )
{
unresolved_instance( WARNING);
dev_change_instance_warning = FALSE;
}
}
/* Note: "Instance" cannot be in effect during "global" scope */
if ( scope_is_global )
{
glob_not_allowed( TKERROR, noerrors );
if ( noerrors )
{
resume_device_scope();
}else{
return;
}
}
if ( finishing_device )
{
finish_device_vocab();
}else{
new_device_vocab();
}
}
emit_token( finishing_device ? "finish-device" : "new-device" );
}
/* **************************************************************************
*
* Function name: abort_quote
* Synopsis: Optionally implement the ABORT" function as
* though it were a macro. Control whether to allow
* it, and which style to support, via switches set
* on the command-line at run-time.
*
* Inputs:
* Parameters:
* tok Numeric-code associated with the
* FORTH word that was just read.
* Global Variables:
* enable_abort_quote Whether to allow ABORT"
* sun_style_abort_quote SUN-style versus Apple-style
* abort_quote_throw Whether to use -2 THROW vs ABORT
*
* Outputs:
* Returned Value: TRUE if it was handled
* Global Variables:
* report_multiline Reset to FALSE.
* Printout:
* ADVISORY: ABORT" in fcode is not defined by IEEE 1275-1994
*
* Error Detection:
* Performed by other routines. If user selected not to
* allow ABORT" , it will simply be treated as an
* unknown word.
* The string following it, however, will still be consumed.
*
* Process Explanation:
* If the supplied tok was not ABORTTXT , then return FALSE.
* If the enable_abort_quote flag is FALSE, consume the
* string following the Abort" token, but be careful to
* leave the Abort" token in statbuf, as it will be used
* for the error message.
* Otherwise, create and prepare for processing the appropriate Macro:
* For Apple Style, we push the specified string onto the stack
* and do -2 THROW (and hope the stack unwinds correctly).
* For Sun Style, we test the condition on top of the stack,
* and if it's true, print the specified string before we
* do the -2 THROW.
* We perform the underlying operations directly: placing an "IF"
* (if Sun Style), then placing the string. This bypasses
* any issues of double-parsing, as well as of doubly checking
* for a multi-line string.
* Finally, we perform the operational equivalents of the remainder
* of the command sequence.
*
* Extraneous Remarks:
* I would have preferred not to have to directly perform the under-
* lying operations, and instead simply prepare the entire command
* sequence in a buffer, but I needed to handle the case where
* quote-escaped quotes are included in the string: If the string
* were simply to be reproduced into the buffer, the quote-escaped
* quotes would appear as plain quote-marks and terminate the
* string parsing prematurely, leaving the rest of the string
* to be treated as code instead of text...
* Also, the introduction of the variability of whether to do the
* -2 THROW or to compile-in the token for ABORT makes the
* buffer-interpretation scheme somewhat too messy for my tastes.
*
**************************************************************************** */
static bool abort_quote( fwtoken tok)
{
bool retval = FALSE;
if ( tok == ABORTTXT )
{
if ( ! enable_abort_quote )
{
/* ABORT" is not enabled; we'd better consume the string */
char *save_statbuf;
signed long wlen;
save_statbuf = strdup( (char *)statbuf);
wlen = get_string( FALSE);
strcpy( statbuf, save_statbuf);
free( save_statbuf);
}else{
/* ABORT" is not to be used in FCODE drivers
* but Apple drivers do use it. Therefore we
* allow it. We push the specified string to
* the stack, do -2 THROW and hope that THROW
* will correctly unwind the stack.
* Presumably, Apple Source supplies its own
* IF ... THEN
*/
char *abort_string;
signed long wlen;
retval = TRUE;
tokenization_error (INFO, "ABORT\" in fcode not "
"defined by IEEE 1275-1994\n");
test_in_colon("ABORT\"", TRUE, TKERROR, NULL);
wlen=get_string( TRUE);
if ( sun_style_abort_quote ) emit_if();
emit_token("b(\")");
emit_string(statbuf, wlen);
if ( sun_style_abort_quote ) emit_token("type");
if ( abort_quote_throw )
{
emit_literal( -2);
emit_token("throw");
}else{
emit_token("abort");
}
if ( sun_style_abort_quote ) emit_then();
/* Sun Style */
abort_string = " type -2 THROW THEN:" ;
}
}
return( retval );
}
/* **************************************************************************
*
* Function name: create_alias
* Synopsis: Create an alias, as specified by the user
*
* Associated FORTH word: ALIAS
*
* Inputs:
* Parameters: NONE
* Global Variables:
* incolon Colon-def'n-in-progress indicator
* in_tokz_esc "Tokenizer Escape" mode indicator
* Input Stream
* Two words will be read.
*
* Outputs:
* Returned Value: NONE
* Memory Allocated
* The two words will be copied into freshly-allocated memory
* that will be passed to the create_..._alias() routine.
* When Freed?
* When Current Device Vocabulary is "finished", or at end
* of tokenization, or upon termination of program.
* If not able to create alias, the copies will be freed here.
*
* Error Detection:
* If the ALIAS command was given during colon-definition, that
* can be handled by this tokenizer, but it is not supported
* by IEEE 1275-1994. Issue a WARNING.
* If the word to which an alias is to be created does not exist
* in the appropriate mode -- relative to "Tokenizer-Escape" --
* that is an ERROR.
* If "instance" is in effect, the ALIAS command is an ERROR.
* Duplicate-name Warning is handled by support-routine.
*
* Process Explanation:
* Get two words -- the new name and the "old" word -- from the
* same line of input as the ALIAS command.
* Determine whether or not we are in "Tokenizer-Escape" mode.
* Subsequent searches will take place in that same mode.
* If the "new" name already exists, issue a warning.
* In each vocabulary applicable to the current mode -- i.e.,
* "Tokenizer-Escape" or "Normal" -- (except: cannot
* make aliases to "Locals"):
* Try using the create_..._alias() routine.
* If it succeeds, we are done.
* IMPORTANT: The order in which we try the vocabularies MUST
* match the order in which tokenize_one_word() searches them.
* If all the attempts failed, the "old" word does not exist;
* declare an ERROR and free up the memory that was allocated.
*
* Extraneous Remarks:
* With the separation of the tokenizer[ state, this
* function has become too complicated to keep as a
* simple CASE in the big SWITCH statement anymore...
*
* I had earlier thought that it was sufficient to create a
* macro linking the "new" name to the "old" word. There
* were too many cases, though, where that didn't work.
* This is cleaner.
*
* I will not be adhering to the strict rules of structure in
* this routine, as it would get me nested too deeply...
*
* Revision History:
* Updated Tue, 10 Jan 2006 by David L. Paktor
* Convert to tic_hdr_t type vocabularies.
* Updated Fri, 22 Sep 2006 by David L. Paktor
* Move the warn_if_duplicate() call to the calling routine.
* Updated Wed, 11 Oct 2006 by David L. Paktor
* Move the Tracing and Duplicate-Warning message functions
* into support routine.
*
**************************************************************************** */
static void create_alias( void )
{
char *new_alias ;
validate_instance(ALIAS);
if ( incolon )
{
tokenization_error ( WARNING,
"ALIAS during colon-definition "
"is not supported by IEEE 1275-1994\n");
}
if ( get_word_in_line( "ALIAS") )
{
new_alias = strdup((char *)statbuf);
if (get_word_in_line( "ALIAS") )
{
char *old_name = strdup((char *)statbuf) ;
/*
* Here is where we begin trying the create_..._alias()
* routines for the vocabularies.
*/
/*
* Distinguish between "Normal" tokenization mode
* and "Tokenizer Escape" mode
*/
if ( in_tokz_esc )
{
if ( create_tokz_esc_alias( new_alias, old_name) )
return;
/*
* Handle the classes of operatives that are common between
* "Tokenizer Escape" mode and "Normal" tokenization mode.
* Those classes include selected non-fcode forth constructs
* and Conditional-Compilation Operators.
*/
{
tic_hdr_t *found = lookup_shared_word( old_name);
if ( found != NULL )
{
if ( create_core_alias( new_alias, old_name) )
return;
}
}
}else{
/* "Normal" tokenization mode */
/* Can create aliases for "Locals", why not? */
if ( create_local_alias( new_alias, old_name) )
return;
/*
* All other classes of operatives -- non-fcode forth
* constructs, Standard and user-defined fcode
* tokens, Macros, and Conditional-Compilation
* Operators, -- are included in the "currently
* active" vocabulary.
*/
if ( create_current_alias( new_alias, old_name) )
return;
} /* End of separate handling for normal-tokenization mode
* versus "Tokenizer-Escape" mode
*/
/* It's not a word, a macro or any of that other stuff. */
trace_create_failure( new_alias, old_name, 0);
tokenized_word_error(old_name);
free(old_name);
}
free (new_alias);
}
}
/* **************************************************************************
*
* Function name: string_err_check
* Synopsis: Error-check after processing or Ignoring
* simple strings
*
* Inputs:
* Parameters:
* is_paren TRUE if string is Dot-Paren .(
* FALSE if Ess-Quote ( s" )
* sav_lineno Saved Line Number, for Unterminated Error
* strt_lineno Start Line Number, for Multiline Warning
* Global Variables:
* noerrors TRUE if ignoring errors
* Local Static Variables:
* got_until_eof TRUE if reached end of buffer before delim.
*
* Outputs:
* Returned Value: TRUE if did not reach end of buffer, or,
* if ignoring errors, TRUE anyway.
*
* Error Detection:
* Multi-line warning, "Unterminated" Error messages, as apppropriate
*
**************************************************************************** */
static bool string_err_check( bool is_paren,
unsigned int sav_lineno,
unsigned int strt_lineno )
{
bool retval = noerrors ;
char *item_typ = is_paren ?
"Dot-Paren" : "Ess-Quote" ;
if ( got_until_eof ) /* Crude retrofit... */
{
warn_unterm( TKERROR, item_typ, sav_lineno );
}else{
retval = TRUE;
warn_if_multiline( item_typ, strt_lineno );
}
return( retval);
}
/* **************************************************************************
*
* Function name: handle_internal
* Synopsis: Perform the functions associated with FORTH words
* that do not map directly to a single token. This
* is the functions that will go into the FUNCT field
* of entries in the "FWords" and "Shared Words" lists.
*
* Inputs:
* Parameters:
* pfield Param-field of the tic_hdr_t -type entry
* associated with the FORTH-Word (FWord)
* just read that is being "handled".
* Global Variables:
* statbuf The word that was just read.
*
* Outputs:
* Returned Value: NONE
* Global Variables:
* statbuf More words may be read.
*
* Error Detection:
* Too numerous to list here...
*
* Process Explanation:
* Recast the type of the param-field of a tic_hdr_t -type
* entry and rename it "tok".
* The "tok" will be used as the control-expression for a
* SWITCH statement with a large number of CASE labels.
* Both "FWords" and "shared_words" list entries will
* be processed by this routine.
*
* Revision History:
* Updated Wed, 20 Jul 2005 by David L. Paktor
* Put handling of ABORT" under control of a run-time
* command-line switch.
* Put decision to support IBM-style Locals under control
* of a run-time command-line switch.
* Updated Tue, 17 Jan 2006 by David L. Paktor
* Convert to handler for tic_hdr_t type vocab entries.
*
* Extraneous Remarks:
* We would prefer to keep this function private, so we will
* declare its prototype here and in the one other file
* where we need it, namely, dictionary.c, rather than
* exporting it widely in a .h file.
*
**************************************************************************** */
void handle_internal( tic_param_t pfield);
void handle_internal( tic_param_t pfield)
{
fwtoken tok = pfield.fw_token;
signed long wlen;
unsigned int sav_lineno = lineno; /* For error message */
bool handy_toggle = TRUE ; /* Various uses... */
bool handy_toggle_too = TRUE ; /* Various other uses... */
char *handy_string = "";
int handy_int = 0;
#ifdef DEBUG_SCANNER
printf("%s:%d: debug: tokenizing control word '%s'\n",
iname, lineno, statbuf);
#endif
switch (tok) {
case BEGIN:
emit_begin();
break;
case BUFFER:
if ( create_word(tok) )
{
emit_token("b(buffer:)");
}
break;
case CONST:
if ( create_word(tok) )
{
emit_token("b(constant)");
}
break;
case COLON:
{
/* Collect error- -detection or -reporting items,
* but don't commit until we're sure the
* creation was a success.
*/
u16 maybe_last_colon_fcode = nextfcode ;
unsigned int maybe_last_colon_lineno = lineno;
unsigned int maybe_last_colon_abs_token_no = abs_token_no;
unsigned int maybe_last_colon_do_depth = do_loop_depth;
/* last_colon_defname
* has to wait until after call to create_word()
*/
if ( create_word(tok) )
{
last_colon_fcode = maybe_last_colon_fcode;
last_colon_lineno = maybe_last_colon_lineno;
last_colon_abs_token_no = maybe_last_colon_abs_token_no;
last_colon_do_depth = maybe_last_colon_do_depth;
collect_input_filename( &last_colon_filename);
/* Now we can get last_colon_defname */
if ( last_colon_defname != NULL )
{
free( last_colon_defname);
}
last_colon_defname = strdup(statbuf);
emit_token("b(:)");
incolon=TRUE;
hide_last_colon();
lastcolon = opc;
}
}
break;
case SEMICOLON:
if ( test_in_colon("SEMICOLON", TRUE, TKERROR, NULL) )
{
ret_stk_balance_rpt( "termination,", TRUE);
/* Clear Control Structures just back to where
* the current Colon-definition began.
*/
clear_control_structs_to_limit(
"End of colon-definition", last_colon_abs_token_no);
if ( ibm_locals )
{
finish_locals();
forget_locals();
}
emit_token("b(;)");
incolon=FALSE;
reveal_last_colon();
}
break;
case CREATE:
if ( create_word(tok) )
{
emit_token("b(create)");
}
break;
case DEFER:
if ( create_word(tok) )
{
emit_token("b(defer)");
}
break;
case ALLOW_MULTI_LINE:
report_multiline = FALSE;
break;
case OVERLOAD:
if ( test_in_colon(statbuf, FALSE, WARNING, NULL) )
{
do_not_overload = FALSE;
}
break;
case DEFINED:
if (get_word_in_line( statbuf) )
{
eval_user_symbol(statbuf);
}
break;
case CL_FLAG:
if (get_word_in_line( statbuf) )
{
set_cl_flag( statbuf, TRUE);
}
break;
case SHOW_CL_FLAGS:
show_all_cl_flag_settings( TRUE);
break;
case FIELD:
if ( create_word(tok) )
{
emit_token("b(field)");
}
break;
case VALUE:
if ( create_word(tok) )
{
emit_token("b(value)");
}
break;
case VARIABLE:
if ( create_word(tok) )
{
emit_token("b(variable)");
}
break;
case AGAIN:
emit_again();
break;
case ALIAS:
create_alias();
break;
case CONTROL:
if ( get_word_in_line( statbuf) )
{
emit_literal(statbuf[0]&0x1f);
}
break;
case DO:
emit_token("b(do)");
mark_do();
break;
case CDO:
emit_token("b(?do)");
mark_do();
break;
case ELSE:
emit_else();
break;
case CASE:
emit_case();
break;
case ENDCASE:
emit_endcase();
break;
case NEW_DEVICE:
handy_toggle = FALSE;
case FINISH_DEVICE:
finish_or_new_device( handy_toggle );
break;
case FLITERAL:
{
u32 val;
val = dpop();
emit_literal(val);
}
break;
case OF:
emit_of();
break;
case ENDOF:
emit_endof();
break;
case EXTERNAL:
set_hdr_flag( FLAG_EXTERNAL );
break;
case HEADERLESS:
set_hdr_flag( FLAG_HEADERLESS );
break;
case HEADERS:
set_hdr_flag( FLAG_HEADERS );
break;
case DECIMAL:
/* in a definition this is expanded as macro "10 base !" */
base_change ( 0x0a );
break;
case HEX:
base_change ( 0x10 );
break;
case OCTAL:
base_change ( 0x08 );
break;
case OFFSET16:
if (!offs16)
{
tokenization_error(INFO, "Switching to 16-bit offsets.\n");
}else{
tokenization_error(WARNING,
"Call of OFFSET16 is redundant.\n");
}
emit_token("offset16");
offs16=TRUE;
break;
case IF:
emit_if();
break;
/* **************************************************************************
*
* Still to be done:
* Correct analysis of Return-Stack usage within Do-Loops
* or before Loop Elements like I and J or UNLOOP or LEAVE.
*
**************************************************************************** */
case UNLOOP:
emit_token("unloop");
must_be_deep_in_do(1);
break;
case LEAVE:
emit_token("b(leave)");
must_be_deep_in_do(1);
break;
case LOOP_I:
emit_token("i");
must_be_deep_in_do(1);
break;
case LOOP_J:
emit_token("j");
must_be_deep_in_do(2);
break;
case LOOP:
emit_token("b(loop)");
resolve_loop();
break;
case PLUS_LOOP:
emit_token("b(+loop)");
resolve_loop();
break;
case INSTANCE:
{
bool set_instance_state = FALSE;
bool emit_instance = TRUE;
/* We will treat "instance" in a colon-definition as
* an error, but allow it to be emitted if we're
* ignoring errors; if we're not ignoring errors,
* there's no output anyway...
*/
if ( test_in_colon(statbuf, FALSE, TKERROR, NULL) )
{ /* We are in interpretation (not colon) state. */
/* "Instance" not allowed during "global" scope */
if ( scope_is_global )
{
glob_not_allowed( WARNING, FALSE );
emit_instance = FALSE;
}else{
set_instance_state = TRUE;
}
}
if ( emit_instance )
{
if ( set_instance_state )
{
/* "Instance" isn't cumulative.... */
if ( is_instance )
{
unresolved_instance( WARNING);
}
collect_input_filename( &instance_filename);
instance_lineno = lineno;
is_instance = TRUE;
dev_change_instance_warning = TRUE;
}
emit_token("instance");
}
}
break;
case GLOB_SCOPE:
if ( test_in_colon(statbuf, FALSE, TKERROR, NULL) )
{
if ( INVERSE( is_instance) )
{
enter_global_scope();
}else{
tokenization_error( TKERROR,
"Global Scope not allowed. "
"\"Instance\" is in effect; issued" );
just_where_started( instance_filename,
instance_lineno );
}
}
break;
case DEV_SCOPE:
if ( test_in_colon(statbuf, FALSE, TKERROR, NULL) )
{
resume_device_scope();
}
break;
case TICK: /* ' */
test_in_colon(statbuf, FALSE, WARNING, "[']");
case BRACK_TICK: /* ['] */
{
tic_hdr_t *token_entry;
if ( get_token( &token_entry) )
{
emit_token("b(')");
/* Emit the token; warning or whatever comes gratis */
token_entry->funct( token_entry->pfield);
}
}
break;
case F_BRACK_TICK: /* F['] <name>
* emits the token-number for <name>
* Mainly useful to compute the argument
* to get-token or set-token
*/
{
tic_hdr_t *token_entry;
if ( get_token( &token_entry) )
{
/* "Obsolete" warning doesn't come gratis here... */
token_entry_warning( token_entry);
/* In Tokenizer-Escape mode, push the token */
if ( in_tokz_esc )
{
dpush( token_entry->pfield.deflt_elem);
}else{
emit_literal( token_entry->pfield.deflt_elem);
}
}
}
break;
case CHAR:
handy_toggle = FALSE;
case CCHAR:
test_in_colon(statbuf, handy_toggle, WARNING,
handy_toggle ? "CHAR" : "[CHAR]" );
case ASCII:
if ( get_word_in_line( statbuf) )
{
emit_literal(statbuf[0]);
}
break;
case UNTIL:
emit_until();
break;
case WHILE:
emit_while();
break;
case REPEAT:
emit_repeat();
break;
case THEN:
emit_then();
break;
case IS:
tokenization_error ( INFO,
"Substituting TO for deprecated IS\n");
case TO:
if ( validate_to_target() )
{
emit_token("b(to)");
}
break;
case FLOAD:
if ( get_word_in_line( statbuf) )
{
bool stream_ok ;
push_source( close_stream, NULL, TRUE) ;
tokenization_error( INFO, "FLOADing %s\n", statbuf );
stream_ok = init_stream( statbuf );
if ( INVERSE( stream_ok) )
{
drop_source();
}
}
break;
case STRING: /* Double-Quote ( " ) string */
handy_toggle = FALSE;
case PSTRING: /* Dot-Quote ( ." ) string */
wlen=get_string( TRUE);
emit_token("b(\")");
emit_string(statbuf, wlen);
if ( handy_toggle )
{
emit_token("type");
}
break;
case SSTRING: /* Ess-Quote ( s" ) string */
handy_toggle = FALSE;
case PBSTRING: /* Dot-Paren .( string */
if (*pc++=='\n') lineno++;
{
unsigned int strt_lineno = lineno;
wlen = get_until( handy_toggle ? ')' : '"' );
if ( string_err_check( handy_toggle,
sav_lineno, strt_lineno) )
{
emit_token("b(\")");
emit_string(statbuf, wlen);
if ( handy_toggle )
{
emit_token("type");
}
}
}
break;
case FUNC_NAME:
if ( in_tokz_esc )
{
if ( incolon )
{
tokenization_error( P_MESSAGE, "Currently" );
}else{
tokenization_error( P_MESSAGE, "After" );
}
in_last_colon( incolon);
}else{
emit_token("b(\")");
emit_string( last_colon_defname,
strlen( last_colon_defname) );
/* if ( hdr_flag == FLAG_HEADERLESS ) { WARNING } */
}
break;
case IFILE_NAME:
emit_token("b(\")");
emit_string( iname, strlen( iname) );
break;
case ILINE_NUM:
emit_literal( lineno);
break;
case HEXVAL:
base_val (0x10);
break;
case DECVAL:
base_val (0x0a);
break;
case OCTVAL:
base_val (8);
break;
case ASC_LEFT_NUM:
handy_toggle = FALSE;
case ASC_NUM:
if (get_word_in_line( statbuf) )
{
if ( handy_toggle )
{
ascii_right_number( statbuf);
} else {
ascii_left_number( statbuf);
}
}
break;
case CONDL_ENDER: /* Conditional directives out of context */
case CONDL_ELSE:
tokenization_error ( TKERROR,
"No conditional preceding %s directive\n",
strupr(statbuf) );
break;
case PUSH_FCODE:
tokenization_error( INFO,
"FCode-token Assignment Counter of 0x%x "
"has been saved on stack.\n", nextfcode );
dpush( (long)nextfcode );
break;
case POP_FCODE:
pop_next_fcode();
break;
case RESET_FCODE:
tokenization_error( INFO,
"Encountered %s. Resetting FCode-token "
"Assignment Counter. ", strupr(statbuf) );
list_fcode_ranges( FALSE);
reset_fcode_ranges();
break;
case EXIT:
if ( test_in_colon( statbuf, TRUE, TKERROR, NULL)
|| noerrors )
{
ret_stk_balance_rpt( NULL, FALSE);
if ( ibm_locals )
{
finish_locals ();
}
emit_token("exit");
}
break;
case ESCAPETOK:
enter_tokz_esc();
break;
case VERSION1:
case FCODE_V1:
fcode_starter( "version1", 1, FALSE) ;
tokenization_error( INFO, "Using version1 header "
"(8-bit offsets).\n");
break;
case START1:
case FCODE_V2:
case FCODE_V3: /* Full IEEE 1275 */
fcode_starter( "start1", 1, TRUE);
break;
case START0:
fcode_starter( "start0", 0, TRUE);
break;
case START2:
fcode_starter( "start2", 2, TRUE);
break;
case START4:
fcode_starter( "start4", 4, TRUE);
break;
case END1:
tokenization_error( WARNING,
"Appearance of END1 in FCode source code "
"is not intended by IEEE 1275-1994\n");
handy_toggle = FALSE;
case END0:
case FCODE_END:
if ( handy_toggle )
{
you_are_here();
}
emit_token( handy_toggle ? "end0" : "end1" );
fcode_ender();
FFLUSH_STDOUT
break;
case RECURSE:
if ( test_in_colon(statbuf, TRUE, TKERROR, NULL ) )
{
emit_fcode(last_colon_fcode);
}
break;
case RECURSIVE:
if ( test_in_colon(statbuf, TRUE, TKERROR, NULL ) )
{
reveal_last_colon();
}
break;
case RET_STK_FETCH:
/* handy_toggle controls reloading other "handy_"s
* handy_toggle_too controls calling ret_stk_access_rpt()
* handy_int, if non-zero, passed to bump_ret_stk_depth()
*/
/* First in series doesn't need to check handy_toggle */
handy_string = "r@";
/* Will call ret_stk_access_rpt() */
/* handy_toggle_too is already TRUE */
/* Will not call bump_ret_stk_depth() */
/* handy_int is already zero */
handy_toggle = FALSE;
case RET_STK_FROM:
if ( handy_toggle )
{
handy_string = "r>";
/* Will call ret_stk_access_rpt() */
/* handy_toggle_too is already TRUE */
/* Will call bump_ret_stk_depth( -1) */
handy_int = -1;
handy_toggle = FALSE;
}
case RET_STK_TO:
if ( handy_toggle )
{
handy_string = ">r";
/* Will not call ret_stk_access_rpt() */
handy_toggle_too = FALSE;
/* Will call bump_ret_stk_depth( 1) */
handy_int = 1;
/* Last in series doesn't need to reset handy_toggle */
}
/* handy_toggle is now free for other use */
handy_toggle = allow_ret_stk_interp;
if ( ! handy_toggle )
{
handy_toggle = test_in_colon(statbuf, TRUE, TKERROR, NULL );
}
if ( handy_toggle || noerrors )
{
if ( handy_toggle_too )
{
ret_stk_access_rpt();
}
if ( handy_int != 0 )
{
bump_ret_stk_depth( handy_int);
}
emit_token( handy_string);
}
break;
case PCIHDR:
emit_pcihdr();
break;
case PCIEND:
finish_pcihdr();
reset_fcode_ranges();
FFLUSH_STDOUT
break;
case PCIREV:
pci_image_rev = dpop();
tokenization_error( INFO,
"PCI header revision=0x%04x%s\n", pci_image_rev,
big_end_pci_image_rev ?
". Will be saved in Big-Endian format."
: "" );
break;
case NOTLAST:
handy_toggle = FALSE;
case ISLAST:
dpush(handy_toggle);
case SETLAST:
{
u32 val = dpop();
bool new_pili = BOOLVAL( (val != 0) );
if ( pci_is_last_image != new_pili )
{
tokenization_error( INFO,
new_pili ?
"Last image for PCI header.\n" :
"PCI header not last image.\n" );
pci_is_last_image = new_pili;
}
}
break;
case SAVEIMG:
if (get_word_in_line( statbuf) )
{
free(oname);
oname = strdup( statbuf );
tokenization_error( INFO,
"Output is redirected to file: %s\n", oname);
}
break;
case RESETSYMBS:
tokenization_error( INFO,
"Resetting symbols defined in %s mode.\n",
in_tokz_esc ? "tokenizer-escape" : "\"normal\"");
if ( in_tokz_esc )
{
reset_tokz_esc();
}else{
reset_normal_vocabs();
}
break;
case FCODE_DATE:
handy_toggle = FALSE;
case FCODE_TIME:
{
time_t tt;
char temp_buffr[32];
tt=time(NULL);
if ( handy_toggle )
{
strftime(temp_buffr, 32, "%T %Z", localtime(&tt));
}else{
strftime(temp_buffr, 32, "%m/%d/%Y", localtime(&tt));
}
if ( in_tokz_esc )
{
tokenization_error( MESSAGE, temp_buffr);
}else{
emit_token("b(\")");
emit_string((u8 *)temp_buffr, strlen(temp_buffr) );
}
}
break;
case ENCODEFILE:
if (get_word_in_line( statbuf) )
{
encode_file( (char*)statbuf );
}
break;
default:
/* IBM-style Locals, under control of a switch */
if ( ibm_locals )
{
bool found_it = TRUE;
switch (tok) {
case CURLY_BRACE:
declare_locals( FALSE);
break;
case DASH_ARROW:
assign_local();
break;
default:
found_it = FALSE;
}
if ( found_it ) break;
}
/* Down here, we have our last chance to recognize a token.
* If abort_quote is disallowed, we will still consume
* the string. In case the string spans more than one
* line, we want to make sure the line number displayed
* in the error-message is the one on which the disallowed
* abort_quote token appeared, not the one where the
* string ended; therefore, we might need to be able to
* "fake-out" the line number...
*/
{
bool fake_out_lineno = FALSE;
unsigned int save_lineno = lineno;
unsigned int true_lineno;
if ( abort_quote( tok) )
{ break;
}else{
if ( tok == ABORTTXT ) fake_out_lineno = TRUE;
}
true_lineno = lineno;
if ( fake_out_lineno ) lineno = save_lineno;
tokenization_error ( TKERROR,
"Unimplemented control word '%s'\n", strupr(statbuf) );
if ( fake_out_lineno ) lineno = true_lineno;
}
}
}
/* **************************************************************************
*
* Function name: skip_string
* Synopsis: When Ignoring, skip various kinds of strings. Maps
* to string-handlers in handle_internal()...
*
* Associated FORTH words: Double-Quote ( " ) string
* Dot-Quote ( ." ) string
* Ess-Quote ( s" ) string
* Dot-Paren .( string
* ABORT" (even if not enabled)
* { (Local-Values declaration) and -> (Local-Values assignment)
* are also handled if ibm_locals is enabled.
*
* Inputs:
* Parameters:
* pfield Param-field of the entry associated with
* the FWord that is being Ignored.
* Global Variables:
* statbuf The word that was just read.
* pc Input-stream pointer
* lineno Line-number, used for errors and warnings
* ibm_locals TRUE if IBM-style Locals are enabled
*
* Outputs:
* Returned Value: NONE
*
* Error Detection:
* Multi-line warnings, "Unterminated" Errors
* handled by called routines
*
* Extraneous Remarks:
* We would prefer to keep this function private, too, so we
* will declare its prototype here and in the one other
* file where we need it, namely, dictionary.c, rather
* than exporting it widely in a .h file.
*
**************************************************************************** */
void skip_string( tic_param_t pfield);
void skip_string( tic_param_t pfield)
{
fwtoken tok = pfield.fw_token;
unsigned int sav_lineno = lineno;
bool handy_toggle = TRUE ; /* Various uses... */
switch (tok) {
case STRING: /* Double-Quote ( " ) string */
case PSTRING: /* Dot-Quote ( ." ) string */
case ABORTTXT: /* ABORT", even if not enabled */
get_string( FALSE); /* Don't truncate; ignoring anyway */
/* Will handle multi-line warnings, etc. */
break;
case SSTRING: /* Ess-Quote ( s" ) string */
handy_toggle = FALSE;
case PBSTRING: /* Dot-Paren .( string */
if (*pc++=='\n') lineno++;
{
unsigned int strt_lineno = lineno;
get_until( handy_toggle ? ')' : '"' );
string_err_check( handy_toggle, sav_lineno, strt_lineno );
}
break;
default:
/* IBM-style Locals, under control of a switch */
if ( ibm_locals )
{
bool found_it = TRUE;
switch (tok) {
case CURLY_BRACE:
declare_locals( TRUE);
break;
case DASH_ARROW:
get_word();
break;
default:
found_it = FALSE;
}
if ( found_it ) break;
}
tokenization_error ( FATAL, "Program Error. "
"Unimplemented skip-string word '%s'\n", strupr(statbuf) );
}
}
/* **************************************************************************
*
* Function name: process_remark
* Synopsis: The active function for remarks (backslash-space)
* and comments (enclosed within parens)
*
* Associated FORTH word(s): \ (
*
* Inputs:
* Parameters:
* TIC entry "parameter field", init'd to delimiter character.
*
* Outputs:
* Returned Value: NONE
*
* Error Detection:
* Warning if end-of-file encountered before delimiter.
* Warning if multi-line parentheses-delimited comment.
*
* Process Explanation:
* Skip until the delimiter.
* If end-of-file was encountered, issue Warning.
* Otherwise, and if delimiter was not new-line,
* check for multi-line with Warning.
*
**************************************************************************** */
void process_remark( tic_param_t pfield )
{
char until_char = (char)pfield.deflt_elem ;
unsigned int start_lineno = lineno;
#ifdef DEBUG_SCANNER
get_until(until_char);
printf ("%s:%d: debug: stack diagram: %s)\n",
iname, lineno, statbuf);
#else
if ( skip_until( until_char) )
{
if ( until_char == '\n' )
{
/* Don't need any saved line number here ... */
tokenization_error ( WARNING,
"Unterminated remark.\n");
}else{
warn_unterm( WARNING, "comment", start_lineno);
}
}else{
if ( until_char != '\n' )
{
pc++;
warn_if_multiline( "comment", start_lineno);
}
}
#endif /* DEBUG_SCANNER */
}
/* **************************************************************************
*
* Function name: filter_comments
* Synopsis: Process remarks and comments in special conditions
*
* Inputs:
* Parameters:
* inword Current word just parsed
*
* Outputs:
* Returned Value: TRUE if Current word is a Comment-starter.
* Comment will be processed
*
* Process Explanation:
* We want to be able to recognize any alias the user may have
* defined to a comment-delimiter, in whatever applicable
* vocabulary it might be.
* The active-function of any such alias will, of necessity, be
* the process_remark() routine, defined just above.
* We will search for the TIC-entry of the given word; if we don't
* find it, it's not a comment-delimiter. If we do find it,
* and it is one, we invoke its active-function and return TRUE.
* We also want to permit the "allow-multiline-comments" directive
* to be processed in the context that calls this routine, so
* we will check for that condition, too.
*
**************************************************************************** */
bool filter_comments( u8 *inword)
{
bool retval = FALSE;
tic_hdr_t *found = lookup_word( inword, NULL, NULL );
if ( found != NULL )
{
if ( found->funct == process_remark )
{
found->funct( found->pfield);
retval = TRUE;
}else{
/* Permit the "allow-multiline-comments" directive */
if ( found->funct == handle_internal )
{
if ( found->pfield.fw_token == ALLOW_MULTI_LINE )
{
/* Make sure any intended side-effects occur... */
found->funct( found->pfield);
retval = TRUE;
}
}
}
}
return ( retval );
}
/* **************************************************************************
*
* Function name: tokenize_one_word
* Synopsis: Tokenize the currently-obtained word
* along with whatever it consumes.
*
* Inputs:
* Parameters:
* wlen Length of symbol just retrieved from the input stream
* This is not really used here any more; it's
* left over from an earlier implementation.
* Global Variables:
* statbuf The symbol (word) just retrieved from input stream.
* in_tokz_esc TRUE if "Tokenizer-Escape" mode is in effect; a
* different set of vocabularies from "Normal"
* mode will be checked (along with those that
* are common to both modes).
* ibm_locals Controls whether to check for IBM-style Locals;
* set by means of a command-line switch.
*
* Outputs:
* Returned Value: NONE
* Global Variables:
* statbuf May be incremented
* in_tokz_esc May be set if the word just retrieved is
* the tokenizer[ directive.
* tic_found
*
* Error Detection:
* If the word could neither be identified nor processed as a number,
* that is an ERROR; pass it to tokenized_word_error for a
* message.
*
* Process Explanation:
* Look for the word in each of the various lists and vocabularies
* in which it might be found, as appropriate to the current
* state of activity.
* If found, process it accordingly.
* If not found, try to process it as a number.
* If cannot process it as a number, declare an error.
*
* Revision History:
* Updated Tue, 10 Jan 2006 by David L. Paktor
* Convert to tic_hdr_t type vocabularies.
* Updated Mon, 03 Apr 2006 by David L. Paktor
* Replaced bulky "Normal"-vs-"Escape" block with a call
* to lookup_word . Attend to a small but important
* side-effect of the "handle_<vocab>" routines that
* feeds directly into the protection against self-
* -recursion in a user-defined Macro: Set the global
* variable tic_found to the entry, just before we
* execute it, and we're good to go...
*
* Extraneous Remarks:
* We trade off the strict rules of structure for simplicity
* of coding.
*
**************************************************************************** */
void tokenize_one_word( signed long wlen )
{
/* The shared lookup routine now handles everything. */
tic_hdr_t *found = lookup_word( statbuf, NULL, NULL );
if ( found != NULL )
{
tic_found = found;
if ( found->tracing)
{
invoking_traced_name( found);
}
found->funct( found->pfield);
return ;
}
/* It's not a word in any of our current contexts.
* Is it a number?
*/
if ( handle_number() )
{
return ;
}
/* Could not identify - give a shout. */
tokenized_word_error( statbuf );
}
/* **************************************************************************
*
* Function name: tokenize
* Synopsis: Tokenize the current input stream.
* May be called recursively for macros and such.
*
* Revision History:
* Updated Thu, 24 Mar 2005 by David L. Paktor
* Factor-out comment-filtration; apply to gather_locals
* Factor-out tokenizing a single word (for conditionals)
* Separate actions of "Tokenizer-Escape" mode.
*
**************************************************************************** */
void tokenize(void)
{
signed long wlen = 0;
while ( wlen >= 0 )
{
wlen = get_word();
if ( wlen > 0 )
{
tokenize_one_word( wlen );
}
}
}