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
|
/*-
* Copyright (c) 1998, 2002-2008 Kiyoshi Matsui <kmatsui@t3.rim.or.jp>
* All rights reserved.
*
* Some parts of this code are derived from the public domain software
* DECUS cpp (1984,1985) written by Martin Minow.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* S U P P O R T . C
* S u p p o r t R o u t i n e s
*
* The common routines used by several source files are placed here.
*/
/*
* The following are global functions.
*
* get_unexpandable() Gets the next unexpandable token in the line, expanding
* macros.
* Called from #if, #line and #include processing routines.
* skip_nl() Skips over a line.
* skip_ws() Skips over white spaces but not skip over the end of the line.
* skip_ws() skips also COM_SEP and TOK_SEP.
* scan_token() Reads the next token of any type into the specified output
* pointer, advances the pointer, returns the type of token.
* scan_quote() Reads a string literal, character constant or header-name from
* the input stream, writes out to the specified buffer and
* returns the advanced output pointer.
* get_ch() Reads the next byte from the current input stream, handling
* end of (macro/file) input and embedded comments appropriately.
* cnv_trigraph() Maps trigraph sequence to C character.
* cnv_digraph() Maps digraph sequence to C character.
* id_operator() See whether the identifier is an operator in C++.
* unget_ch() Pushs last gotten character back on the input stream.
* unget_string() Pushs sequence on the input stream.
* save_string() Saves a string in malloc() memory.
* get_file() Initializes a new FILEINFO structure, called when #include
* opens a new file, or from unget_string().
* xmalloc() Gets a specified number of bytes from heap memory.
* If malloc() returns NULL, exits with a message.
* xrealloc() realloc(). If it fails, exits with a message.
* get_src_location() Trace back line-column datum into pre-line-splicing
* phase. A function for -K option.
* cfatal(), cerror(), cwarn()
* These routines format print messages to the user.
* mcpp_fputc(), mcpp_fputs(), mcpp_fprintf()
* Wrap library functions to support alternate output to memory
* buffer.
*/
#if PREPROCESSED
#include "mcpp.H"
#else
#include "system.H"
#include "internal.H"
#endif
static void scan_id( int c);
/* Scan an identifier */
static char * scan_number( int c, char * out, char * out_end);
/* Scan a preprocessing number */
static char * scan_number_prestd( int c, char * out, char * out_end);
/* scan_number() for pre-Standard mode */
#if OK_UCN
static char * scan_ucn( int cnt, char * out);
/* Scan an UCN sequence */
#endif
static char * scan_op( int c, char * out);
/* Scan an operator or a punctuator */
static char * parse_line( void);
/* Parse a logical line and convert comments */
static char * read_a_comment( char * sp, size_t * sizp);
/* Read over a comment */
static char * get_line( int in_comment);
/* Get a logical line from file, handle line-splicing */
static char * at_eof( int in_comment);
/* Check erroneous end of file */
static void do_msg( const char * severity, const char * format
, const char * arg1, long arg2, const char * arg3);
/* Putout diagnostic message */
static char * cat_line( int del_bsl);
/* Splice the line */
static void put_line( char * out, FILE * fp);
/* Put out a logical line */
static void dump_token( int token_type, const char * cp);
/* Dump a token and its type */
#define EXP_MAC_IND_MAX 16
/* Information of current expanding macros for diagnostic */
static struct {
const char * name; /* Name of the macro just expanded */
int to_be_freed; /* Name should be freed later */
} expanding_macro[ EXP_MAC_IND_MAX];
static int exp_mac_ind = 0; /* Index into expanding_macro[] */
static int in_token = FALSE; /* For token scanning functions */
static int in_string = FALSE; /* For get_ch() and parse_line()*/
static int squeezews = FALSE;
#define MAX_CAT_LINE 256
/* Information on line catenated by <backslash><newline> */
/* and by line-crossing comment. This is for -K option. */
typedef struct catenated_line {
long start_line; /* Starting line of catenation */
long last_line; /* Ending line of catanation */
size_t len[ MAX_CAT_LINE + 1];
/* Length of successively catenated lines */
} CAT_LINE;
static CAT_LINE bsl_cat_line;
/* Datum on the last catenated line by <backslash><newline> */
static CAT_LINE com_cat_line;
/* Datum on the last catenated line by a line-crossing comment */
#if MCPP_LIB
static int use_mem_buffers = FALSE;
void init_support( void)
{
in_token = in_string = squeezews = FALSE;
bsl_cat_line.len[ 0] = com_cat_line.len[ 0] = 0;
clear_exp_mac();
}
typedef struct mem_buf {
char * buffer;
char * entry_pt;
size_t size;
size_t bytes_avail;
} MEMBUF;
static MEMBUF mem_buffers[ NUM_OUTDEST];
void mcpp_use_mem_buffers(
int tf
)
{
int i;
use_mem_buffers = tf ? TRUE : FALSE;
for (i = 0; i < NUM_OUTDEST; ++i) {
if (mem_buffers[ i].buffer)
/* Free previously allocated memory buffer */
free( mem_buffers[ i].buffer);
if (use_mem_buffers) {
/* Output to memory buffers instead of files */
mem_buffers[ i].buffer = NULL;
mem_buffers[ i].entry_pt = NULL;
mem_buffers[ i].size = 0;
mem_buffers[ i].bytes_avail = 0;
}
}
}
int using_mem_buffers( void)
{
return use_mem_buffers;
}
#define BUF_INCR_SIZE (NWORK * 2)
#define MAX( a, b) (((a) > (b)) ? (a) : (b))
static char * append_to_buffer(
MEMBUF * mem_buf_p,
const char * string,
size_t length
)
{
if (mem_buf_p->bytes_avail < length + 1) { /* Need to allocate more memory */
size_t size = MAX( BUF_INCR_SIZE, length);
if (mem_buf_p->buffer == NULL) { /* 1st append */
mem_buf_p->size = size;
mem_buf_p->bytes_avail = size;
mem_buf_p->buffer = xmalloc( mem_buf_p->size);
mem_buf_p->entry_pt = mem_buf_p->buffer;
} else {
mem_buf_p->size += size;
mem_buf_p->bytes_avail += size;
mem_buf_p->buffer = xrealloc( mem_buf_p->buffer, mem_buf_p->size);
mem_buf_p->entry_pt = mem_buf_p->buffer + mem_buf_p->size
- mem_buf_p->bytes_avail;
}
}
/* Append the string to the tail of the buffer */
memcpy( mem_buf_p->entry_pt, string, length);
mem_buf_p->entry_pt += length;
mem_buf_p->entry_pt[ 0] = '\0'; /* Terminate the string buffer */
mem_buf_p->bytes_avail -= length;
return mem_buf_p->buffer;
}
static int mem_putc(
int c,
OUTDEST od
)
{
char string[ 1];
string[ 0] = (char) c;
if (append_to_buffer( &(mem_buffers[ od]), string, 1) != NULL)
return 0;
else
return !0;
}
static int mem_puts(
const char * s,
OUTDEST od
)
{
if (append_to_buffer( &(mem_buffers[od]), s, strlen(s)) != NULL)
return 0;
else
return !0;
}
char * mcpp_get_mem_buffer(
OUTDEST od
)
{
return mem_buffers[ od].buffer;
}
#endif /* MCPP_LIB */
#define DEST2FP(od) \
(od == OUT) ? fp_out : \
((od == ERR) ? fp_err : \
((od == DBG) ? fp_debug : \
(NULL)))
/*
* The following mcpp_*() wrapper functions are intended to centralize
* the output generated by MCPP. They support memory buffer alternates to
* each of the primary output streams: out, err, debug. The memory buffer
* output option would be used in a setup where MCPP has been built as a
* function call - i.e. mcpp_lib_main().
*/
int mcpp_lib_fputc(
int c,
OUTDEST od
)
{
#if MCPP_LIB
if (use_mem_buffers) {
return mem_putc( c, od);
} else {
#endif
FILE * stream = DEST2FP( od);
return (stream != NULL) ? fputc( c, stream) : EOF;
#if MCPP_LIB
}
#endif
}
int (* mcpp_fputc)( int c, OUTDEST od) = mcpp_lib_fputc;
int mcpp_lib_fputs(
const char * s,
OUTDEST od
)
{
#if MCPP_LIB
if (use_mem_buffers) {
return mem_puts( s, od);
} else {
#endif
FILE * stream = DEST2FP( od);
return (stream != NULL) ? fputs( s, stream) : EOF;
#if MCPP_LIB
}
#endif
}
int (* mcpp_fputs)( const char * s, OUTDEST od) = mcpp_lib_fputs;
#include <stdarg.h>
int mcpp_lib_fprintf(
OUTDEST od,
const char * format,
...
)
{
va_list ap;
FILE * stream = DEST2FP( od);
if (stream != NULL) {
int rc;
va_start( ap, format);
#if MCPP_LIB
if (use_mem_buffers) {
static char mem_buffer[ NWORK];
rc = vsprintf( mem_buffer, format, ap);
if (rc != 0) {
rc = mem_puts( mem_buffer, od);
}
} else {
#endif
rc = vfprintf( stream, format, ap);
#if MCPP_LIB
}
#endif
va_end( ap);
return rc;
} else {
return EOF;
}
}
int (* mcpp_fprintf)( OUTDEST od, const char * format, ...) = mcpp_lib_fprintf;
#if MCPP_LIB
void mcpp_reset_def_out_func( void)
{
mcpp_fputc = mcpp_lib_fputc;
mcpp_fputs = mcpp_lib_fputs;
mcpp_fprintf = mcpp_lib_fprintf;
}
void mcpp_set_out_func(
int (* func_fputc)( int c, OUTDEST od),
int (* func_fputs)( const char * s, OUTDEST od),
int (* func_fprintf)( OUTDEST od, const char * format, ...)
)
{
mcpp_fputc = func_fputc;
mcpp_fputs = func_fputs;
mcpp_fprintf = func_fprintf;
}
#endif
int get_unexpandable(
int c, /* First char of token */
int diag /* Flag of diagnosis */
)
/*
* Get the next unexpandable token in the line, expanding macros.
* Return the token type. The token is written in work_buf[].
* The once expanded macro is never expanded again.
* Called only from the routines processing #if (#elif, #assert), #line and
* #include directives in order to diagnose some subtle macro expansions.
*/
{
DEFBUF * defp = NULL;
FILEINFO * file;
FILE * fp = NULL;
LINE_COL line_col = { 0L, 0};
int token_type = NO_TOKEN;
int has_pragma;
while (c != EOS && c != '\n' /* In a line */
&& (fp = infile->fp /* Preserve current state */
, (token_type
= scan_token( c, (workp = work_buf, &workp), work_end))
== NAM) /* Identifier */
&& fp != NULL /* In source ! */
&& (defp = is_macro( NULL)) != NULL) { /* Macro */
expand_macro( defp, work_buf, work_end, line_col, & has_pragma);
/* Expand macro */
if (has_pragma)
cerror( "_Pragma operator found in directive line" /* _E_ */
, NULL, 0L, NULL);
file = unget_string( work_buf, defp->name); /* Stack to re-read */
c = skip_ws(); /* Skip TOK_SEP */
if (file != infile && macro_line != MACRO_ERROR && (warn_level & 1)) {
/* This diagnostic is issued even if "diag" is FALSE. */
cwarn( "Macro \"%s\" is expanded to 0 token" /* _W1_ */
, defp->name, 0L, NULL);
if (! option_flags.no_source_line)
dump_a_def( " macro", defp, FALSE, TRUE, fp_err);
}
}
if (c == '\n' || c == EOS) {
unget_ch();
return NO_TOKEN;
}
if (diag && fp == NULL && defp && (warn_level & 1)) {
char tmp[ NWORK + 16];
char * tmp_end = tmp + NWORK;
char * tmp_p;
file = unget_string( infile->buffer, defp->name); /* To diagnose */
c = get_ch();
while (file == infile) { /* Search the expanded macro */
if (scan_token( c, (tmp_p = tmp, &tmp_p), tmp_end) != NAM) {
c = get_ch();
continue;
}
if (standard && str_eq( identifier, "defined")) {
cwarn( "Macro \"%s\" is expanded to \"defined\"" /* _W1_ */
, defp->name, 0L, NULL);
break;
}
if (! standard && str_eq( identifier, "sizeof")) {
cwarn( "Macro \"%s\" is expanded to \"sizeof\"" /* _W1_ */
, defp->name, 0L, NULL);
break;
}
c = get_ch();
}
if (file == infile) {
infile->bptr += strlen( infile->bptr);
get_ch();
}
unget_ch();
if (token_type == OPE) {
unget_string( work_buf, NULL); /* Set again 'openum' */
scan_token( get_ch(), (workp = work_buf, &workp), work_end);
}
}
return token_type;
}
void skip_nl( void)
/*
* Skip to the end of the current input line.
*/
{
insert_sep = NO_SEP;
while (infile && infile->fp == NULL) { /* Stacked text */
infile->bptr += strlen( infile->bptr);
get_ch(); /* To the parent */
}
if (infile)
infile->bptr += strlen( infile->bptr); /* Source line */
}
int skip_ws( void)
/*
* Skip over horizontal whitespaces.
*/
{
int c;
do {
c = get_ch();
} while (char_type[ c] & HSP);
return c;
}
#define MBMASK 0xFF /* Mask to hide multibyte char */
int scan_token(
int c, /* The first character of the token */
char ** out_pp, /* Pointer to pointer to output buf */
char * out_end /* End of output buffer */
)
/*
* Scan the next token of any type.
* The token is written out to the specified buffer and the output pointer
* is advanced. Token is terminated by EOS. Return the type of token.
* If the token is an identifier, the token is also in identifier[].
* If the token is a operator or punctuator, return OPE.
* If 'c' is token separator, then return SEP.
* If 'c' is not the first character of any known token and not a token
* separator, return SPE.
* In POST_STD mode, inserts token separator (a space) between any tokens of
* source.
*/
{
char * out = *out_pp; /* Output pointer */
int ch_type; /* Type of character */
int token_type = 0; /* Type of token */
int ch;
if (standard)
in_token = TRUE; /* While a token is scanned */
c = c & UCHARMAX;
ch_type = char_type[ c] & MBMASK;
switch (ch_type) {
case LET: /* Probably an identifier */
switch (c) {
case 'L':
if (! standard)
goto ident;
ch = get_ch();
if (char_type[ ch] & QUO) { /* char_type[ ch] == QUO */
if (ch == '"')
token_type = WSTR; /* Wide-char string literal */
else
token_type = WCHR; /* Wide-char constant */
c = ch;
*out++ = 'L';
break; /* Fall down to "case QUO:" */
} else {
unget_ch();
} /* Fall through */
default: /* An identifier */
ident:
scan_id( c);
out = stpcpy( out, identifier);
token_type = NAM;
break;
}
if (token_type == NAM)
break;
/* Else fall through -- i.e. WSTR, WCHR */
case QUO: /* String or character constant */
out = scan_quote( c, out, out_end, FALSE);
if (token_type == 0) { /* Without prefix L */
if (c == '"')
token_type = STR;
else
token_type = CHR;
} /* Else WSTR or WCHR */
break;
case DOT:
ch = get_ch();
unget_ch();
if ((char_type[ ch] & DIG) == 0) /* Operator '.' or '...' */
goto operat;
/* Else fall through */
case DIG: /* Preprocessing number */
out = (standard ? scan_number( c, out, out_end)
: scan_number_prestd( c, out, out_end));
token_type = NUM;
break;
case PUNC:
operat: out = scan_op( c, out); /* Operator or punctuator */
token_type = OPE; /* Number is set in global "openum" */
break;
default: /* Special tokens or special characters */
#if OK_UCN
if (mcpp_mode == STD && c == '\\' && stdc2) {
ch = get_ch();
unget_ch();
if (ch == 'U' || ch == 'u')
goto ident; /* Universal-Characte-Name */
}
#endif
#if OK_MBIDENT
if (mcpp_mode == STD && (char_type[ c] & mbchk) && stdc3) {
char * bptr = infile->bptr;
mb_read( c, &infile->bptr, &out);
infile->bptr = bptr;
out = *out_pp;
goto ident; /* An identifier with multi-byte characters */
/* Mbchar cheking has been done in scan_quote() and others. */
}
#endif
if ((standard && (c == CAT || c == ST_QUOTE)) || (char_type[ c] & SPA))
token_type = SEP; /* Token separator or magic char*/
else
token_type = SPE;
/* Unkown token ($, @, multi-byte character or Latin */
*out++ = c;
*out = EOS;
break;
}
if (out_end < out)
cfatal( "Buffer overflow scanning token \"%s\"" /* _F_ */
, *out_pp, 0L, NULL);
if (mcpp_debug & TOKEN)
dump_token( token_type, *out_pp);
if (mcpp_mode == POST_STD && token_type != SEP && infile->fp != NULL
&& (char_type[ *infile->bptr & UCHARMAX] & SPA) == 0)
insert_sep = INSERT_SEP; /* Insert token separator */
*out_pp = out;
in_token = FALSE; /* Token scanning has been done */
return token_type;
}
static void scan_id(
int c /* First char of id */
)
/*
* Reads the next identifier and put it into identifier[].
* The caller has already read the first character of the identifier.
*/
{
static char * const limit = &identifier[ IDMAX];
static int dollar_diagnosed = FALSE; /* Flag of diagnosing '$' */
#if OK_UCN
int uc2 = 0, uc4 = 0; /* Count of UCN16, UCN32 */
#endif
#if OK_MBIDENT
int mb = 0; /* Count of MBCHAR */
#endif
size_t len; /* Length of identifier */
char * bp = identifier;
if (c == IN_SRC) { /* Magic character */
*bp++ = c;
if ((mcpp_debug & MACRO_CALL) && ! in_directive) {
*bp++ = get_ch(); /* Its 2-bytes */
*bp++ = get_ch(); /* argument */
}
c = get_ch();
}
do {
if (bp < limit)
*bp++ = c;
#if OK_UCN
if (mcpp_mode == STD && c == '\\' && stdc2) {
int cnt;
char * tp = bp;
if ((c = get_ch()) == 'u') {
cnt = 4;
} else if (c == 'U') {
cnt = 8;
} else {
unget_ch();
bp--;
break;
}
*bp++ = c;
if ((bp = scan_ucn( cnt, bp)) == NULL) /* Error */
return;
if (cnt == 4)
uc2++;
else if (cnt == 8)
uc4++;
if (limit <= tp) /* Too long identifier */
bp = tp; /* Back the pointer */
goto next_c;
}
#endif /* OK_UCN */
#if OK_MBIDENT
if (mcpp_mode == STD && (char_type[ c] & mbchk) && stdc3) {
len = mb_read( c, &infile->bptr, &bp);
if (len & MB_ERROR) {
if (infile->fp)
cerror(
"Illegal multi-byte character sequence." /* _E_ */
, NULL, 0L, NULL);
} else {
mb += len;
}
}
#endif /* OK_MBIDENT */
#if OK_UCN
next_c:
#endif
c = get_ch();
} while ((char_type[ c] & (LET | DIG)) /* Letter or digit */
#if OK_UCN
|| (mcpp_mode == STD && c == '\\' && stdc2)
#endif
#if OK_MBIDENT
|| (mcpp_mode == STD && (char_type[ c] & mbchk) && stdc3)
#endif
);
unget_ch();
*bp = EOS;
if (bp >= limit && (warn_level & 1)) /* Limit of token */
cwarn( "Too long identifier truncated to \"%s\"" /* _W1_ */
, identifier, 0L, NULL);
len = bp - identifier;
#if IDMAX > IDLEN90MIN
/* UCN16, UCN32, MBCHAR are counted as one character for each. */
#if OK_UCN
if (mcpp_mode == STD)
len -= (uc2 * 5) - (uc4 * 9);
#endif
#if OK_MBIDENT
if (mcpp_mode == STD)
len -= mb;
#endif
if (standard && infile->fp && len > std_limits.id_len && (warn_level & 4))
cwarn( "Identifier longer than %.0s%ld characters \"%s\"" /* _W4_ */
, NULL, (long) std_limits.id_len, identifier);
#endif /* IDMAX > IDLEN90MIN */
if (option_flags.dollar_in_name && dollar_diagnosed == FALSE
&& (warn_level & 2) && strchr( identifier, '$') != NULL) {
cwarn( "'$' in identifier \"%s\"", identifier, 0L, NULL); /* _W2_ */
dollar_diagnosed = TRUE; /* Diagnose only once */
}
}
char * scan_quote(
int delim, /* ', " or < (header-name) */
char * out, /* Output buffer */
char * out_end, /* End of output buffer */
int diag /* Diagnostic should be output */
)
/*
* Scan off a string literal or character constant to the output buffer.
* Report diagnosis if the quotation is terminated by newline or character
* constant is empty (provided 'diag' is TRUE).
* Return the next output pointer or NULL (on error).
*/
{
const char * const skip_line = ", skipped the line"; /* _E_ */
const char * const unterm_string
= "Unterminated string literal%s";
const char * const unterm_char
= "Unterminated character constant %s%.0ld%s";
const char * const empty_const
= "Empty character constant %s%.0ld%s";
const char * skip;
size_t len;
int c;
char * out_p = out;
/* Set again in case of called from routines other than scan_token(). */
if (standard)
in_token = TRUE;
*out_p++ = delim;
if (delim == '<')
delim = '>';
scan:
while ((c = get_ch()) != EOS) {
#if MBCHAR
if (char_type[ c] & mbchk) {
/* First of multi-byte character (or shift-sequence) */
char * bptr = infile->bptr;
len = mb_read( c, &infile->bptr, (*out_p++ = c, &out_p));
if (len & MB_ERROR) {
if (infile->fp != NULL && compiling && diag) {
if (warn_level & 1) {
char * buf;
size_t chlen;
buf = xmalloc( chlen = infile->bptr - bptr + 2);
memcpy( buf, bptr, chlen - 1);
buf[ chlen - 1] = EOS;
cwarn(
"Illegal multi-byte character sequence \"%s\" in quotation", /* _W1_ */
buf, 0L, NULL);
free( buf);
}
}
continue;
} else { /* Valid multi-byte character (or sequence) */
goto chk_limit;
}
}
#endif
if (c == delim) {
break;
} else if (c == '\\' && delim != '>') { /* In string literal */
#if OK_UCN
if (mcpp_mode == STD && stdc2) {
int cnt;
char * tp;
*out_p++ = c;
if ((c = get_ch()) == 'u') {
cnt = 4;
} else if (c == 'U') {
cnt = 8;
} else {
goto escape;
}
*out_p++ = c;
if ((tp = scan_ucn( cnt, out_p)) != NULL)
out_p = tp;
/* Else error */
continue; /* Error or not, anyway continue */
}
#endif /* OK_UCN */
*out_p++ = c; /* Escape sequence */
c = get_ch();
escape:
#if MBCHAR
if (char_type[ c] & mbchk) {
/* '\\' followed by multi-byte char */
unget_ch();
continue;
}
#endif
if (! standard && c == '\n') { /* <backslash><newline> */
out_p--; /* Splice the lines */
if (cat_line( TRUE) == NULL) /* End of file */
break;
c = get_ch();
}
} else if (mcpp_mode == POST_STD && c == ' ' && delim == '>'
&& infile->fp == NULL) {
continue; /* Skip space possibly inserted by macro expansion */
} else if (c == '\n') {
break;
}
if (diag && iscntrl( c) && ((char_type[ c] & SPA) == 0)
&& (warn_level & 1))
cwarn(
"Illegal control character %.0s0x%02x in quotation" /* _W1_ */
, NULL, (long) c, NULL);
*out_p++ = c;
chk_limit:
if (out_end < out_p) {
*out_end = EOS;
cfatal( "Too long quotation", NULL, 0L, NULL); /* _F_ */
}
}
if (c == '\n' || c == EOS)
unget_ch();
if (c == delim)
*out_p++ = delim;
*out_p = EOS;
if (diag) { /* At translation phase 3 */
skip = (infile->fp == NULL) ? NULL : skip_line;
if (c != delim) {
if (mcpp_mode == OLD_PREP /* Implicit closing of quote*/
&& (delim == '"' || delim == '\''))
goto done;
if (delim == '"') {
if (mcpp_mode != POST_STD && option_flags.lang_asm) {
/* STD, KR */
/* Concatenate the unterminated string to the next line */
if (warn_level & 1)
cwarn( unterm_string
, ", catenated to the next line" /* _W1_ */
, 0L, NULL);
if (cat_line( FALSE) != NULL)
goto scan; /* Splice the lines */
/* Else end of file */
} else {
cerror( unterm_string, skip, 0L, NULL); /* _E_ */
}
} else if (delim == '\'') {
if (mcpp_mode != POST_STD && option_flags.lang_asm) {
/* STD, KR */
if (warn_level & 1)
cwarn( unterm_char, NULL, (long)delim, NULL); /* _W1_ */
goto done;
} else {
cerror( unterm_char, NULL, (long)delim, skip); /* _E_ */
}
} else {
cerror( "Unterminated header name %s%.0ld%s" /* _E_ */
, out, 0L, skip);
}
out_p = NULL;
} else if (delim == '\'' && out_p - out <= 2) {
if (mcpp_mode != POST_STD && option_flags.lang_asm) {
/* STD, KR */
if (warn_level & 1)
cwarn( empty_const, NULL, (long)delim, skip); /* _W1_ */
} else {
cerror( empty_const, NULL, (long)delim, skip); /* _E_ */
out_p = NULL;
goto done;
}
} else if (mcpp_mode == POST_STD && delim == '>' && (warn_level & 2)) {
cwarn(
"Header-name enclosed by <, > is an obsolescent feature %s" /* _W2_ */
, out, 0L, skip);
}
#if NWORK-2 > SLEN90MIN
if (standard && out_p - out > std_limits.str_len && (warn_level & 4))
cwarn( "Quotation longer than %.0s%ld bytes" /* _W4_ */
, NULL, std_limits.str_len, NULL);
#endif
}
done:
in_token = FALSE;
return out_p;
}
static char * cat_line(
int del_bsl /* Delete the <backslash><newline> ? */
)
/*
* If del_bsl == TRUE:
* Delete <backslash><newline> sequence in string literal.
* FALSE: Overwrite the <newline> with <backslash>'n'.
* Return NULL on end of file. Called only from scan_quote().
* This routine is never called in POST_STD mode.
*/
{
size_t len;
char * save1, * save2;
if (del_bsl) { /* Delete the <backslash><newline> */
infile->bptr -= 2;
len = infile->bptr - infile->buffer;
} else { /* Overwrite the <newline> with <backslash>'n' */
strcpy( infile->bptr, "\\n");
len = strlen( infile->buffer);
}
save1 = save_string( infile->buffer);
save2 = get_line( FALSE); /* infile->buffer is overwritten */
if (save2 == NULL) {
free( save1);
return NULL;
}
save2 = save_string( infile->buffer);
memcpy( infile->buffer, save1, len);
strcpy( infile->buffer + len, save2); /* Catenate */
free( save1);
free( save2);
if (! del_bsl)
len -= 2;
infile->bptr = infile->buffer + len;
return infile->bptr;
}
static char * scan_number(
int c, /* First char of number */
char * out, /* Output buffer */
char * out_end /* Limit of output buffer */
)
/*
* Read a preprocessing number.
* By scan_token() we know already that the first c is from 0 to 9 or dot,
* and if c is dot then the second character is digit.
* Returns the advanced output pointer.
* Note: preprocessing number permits non-numeric forms such as 3E+xy,
* which are used in stringization or token-concatenation.
*/
{
char * out_p = out; /* Current output pointer */
do {
*out_p++ = c;
if (c == 'E' || c == 'e' /* Sign should follow 'E', 'e', */
|| (stdc3 && (c == 'P' || c == 'p'))
/* 'P' or 'p'. */
) {
c = get_ch();
if (c == '+' || c == '-') {
*out_p++ = c;
c = get_ch();
}
#if OK_UCN
} else if (mcpp_mode == STD && c == '\\' && stdc3) {
int cnt;
char * tp;
if ((c = get_ch()) == 'u') {
cnt = 4;
} else if (c == 'U') {
cnt = 8;
} else {
unget_ch();
out_p--;
break;
}
*out_p++ = c;
if ((tp = scan_ucn( cnt, out_p)) == NULL) /* Error */
break;
else
out_p = tp;
c = get_ch();
#endif /* OK_UCN */
#if OK_MBIDENT
} else if (mcpp_mode == STD && (char_type[ c] & mbchk) && stdc3) {
len = mb_read( c, &infile->bptr, &out_p);
if (len & MB_ERROR) {
if (infile->fp)
cerror(
"Illegal multi-byte character sequence." /* _E_ */
, NULL, 0L, NULL);
}
#endif /* OK_MBIDENT */
} else {
c = get_ch();
}
} while ((char_type[ c] & (DIG | DOT | LET)) /* Digit, dot or letter */
#if OK_UCN
|| (mcpp_mode == STD && c == '\\' && stdc3)
#endif
#if OK_MBIDENT
|| (mcpp_mode == STD && (char_type[ c] & mbchk) && stdc3)
#endif
);
*out_p = EOS;
if (out_end < out_p)
cfatal( "Too long pp-number token \"%s\"" /* _F_ */
, out, 0L, NULL);
unget_ch();
return out_p;
}
/* Original version of DECUS CPP with slight modifications, */
/* too exact for Standard preprocessing. */
static char * scan_number_prestd(
int c, /* First char of number */
char * out, /* Output buffer */
char * out_end /* Limit of output buffer */
)
/*
* Process a number. We know that c is from 0 to 9 or dot.
* Algorithm from Dave Conroy's Decus C.
* Returns the advanced output pointer.
*/
{
char * const out_s = out; /* For diagnostics */
int radix; /* 8, 10, or 16 */
int expseen; /* 'e' seen in floater */
int octal89; /* For bad octal test */
int dotflag; /* TRUE if '.' was seen */
expseen = FALSE; /* No exponent seen yet */
octal89 = FALSE; /* No bad octal yet */
radix = 10; /* Assume decimal */
if ((dotflag = (c == '.')) != FALSE) { /* . something? */
*out++ = '.'; /* Always out the dot */
if ((char_type[(c = get_ch())] & DIG) == 0) {
/* If not a float numb, */
goto nomore; /* All done for now */
}
} /* End of float test */
else if (c == '0') { /* Octal or hex? */
*out++ = c; /* Stuff initial zero */
radix = 8; /* Assume it's octal */
c = get_ch(); /* Look for an 'x' */
if (c == 'x' || c == 'X') { /* Did we get one? */
radix = 16; /* Remember new radix */
*out++ = c; /* Stuff the 'x' */
c = get_ch(); /* Get next character */
}
}
while (1) { /* Process curr. char. */
/*
* Note that this algorithm accepts "012e4" and "03.4"
* as legitimate floating-point numbers.
*/
if (radix != 16 && (c == 'e' || c == 'E')) {
if (expseen) /* Already saw 'E'? */
break; /* Exit loop, bad nbr. */
expseen = TRUE; /* Set exponent seen */
radix = 10; /* Decimal exponent */
*out++ = c; /* Output the 'e' */
if ((c = get_ch()) != '+' && c != '-')
continue;
}
else if (radix != 16 && c == '.') {
if (dotflag) /* Saw dot already? */
break; /* Exit loop, two dots */
dotflag = TRUE; /* Remember the dot */
radix = 10; /* Decimal fraction */
}
else { /* Check the digit */
switch (c) {
case '8': case '9': /* Sometimes wrong */
octal89 = TRUE; /* Do check later */
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
break; /* Always ok */
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
if (radix == 16) /* Alpha's are ok only */
break; /* if reading hex. */
default: /* At number end */
goto done; /* Break from for loop */
} /* End of switch */
} /* End general case */
*out++ = c; /* Accept the character */
c = get_ch(); /* Read another char */
} /* End of scan loop */
if (out_end < out) /* Buffer overflow */
goto nomore;
/*
* When we break out of the scan loop, c contains the first
* character (maybe) not in the number. If the number is an
* integer, allow a trailing 'L' for long. If not those, push
* the trailing character back on the input stream.
* Floating point numbers accept a trailing 'L' for "long double".
*/
done:
if (! (dotflag || expseen)) { /* Not floating point */
/*
* We know that dotflag and expseen are both zero, now:
* dotflag signals "saw 'L'".
*/
for (;;) {
switch (c) {
case 'l':
case 'L':
if (dotflag)
goto nomore;
dotflag = TRUE;
break;
default:
goto nomore;
}
*out++ = c; /* Got 'L' . */
c = get_ch(); /* Look at next, too. */
}
}
nomore: *out = EOS;
if (out_end < out)
goto overflow;
unget_ch(); /* Not part of a number */
if (octal89 && radix == 8 && (warn_level & 1))
cwarn( "Illegal digit in octal number \"%s\"" /* _W1_ */
, out_s, 0L, NULL);
return out;
overflow:
cfatal( "Too long number token \"%s\"", out_s, 0L, NULL); /* _F_ */
return out;
}
#if OK_UCN
static char * scan_ucn(
int cnt, /* Bytes of sequence */
char * out /* Output buffer */
)
/*
* Scan an UCN sequence and put the sequence to 'out'.
* Return the advanced pointer or NULL on failure.
* This routine is never called in POST_STD mode.
*/
{
uexpr_t value; /* Value of UCN */
int i, c;
value = 0L;
for (i = 0; i < cnt; i++) {
c = get_ch();
if (! isxdigit( c)) {
if (infile->fp)
cerror( "Illegal UCN sequence" /* _E_ */
, NULL, 0L, NULL);
*out = EOS;
unget_ch();
return NULL;
}
c = tolower( c);
*out++ = c;
c = (isdigit( c) ? (c - '0') : (c - 'a' + 10));
value = (value << 4) | c;
}
if (infile->fp /* In source */
&& ((value >= 0L && value <= 0x9FL
&& value != 0x24L && value != 0x40L && value != 0x60L)
/* Basic source character */
|| (stdc3 && (value >= 0xD800L && value <= 0xDFFFL))))
/* Reserved for special chars */
cerror( "UCN cannot specify the value %.0s\"%08lx\"" /* _E_ */
, NULL, (long) value, NULL);
return out;
}
#endif /* OK_UCN */
static char * scan_op(
int c, /* First char of the token */
char * out /* Output buffer */
)
/*
* Scan C operator or punctuator into the specified buffer.
* Return the advanced output pointer.
* The code-number of the operator is stored to global variable 'openum'.
* Note: '#' is not an operator nor a punctuator in other than directive line,
* nevertheless is handled as a punctuator in this cpp for convenience.
*/
{
int c2, c3, c4;
*out++ = c;
switch (c) {
case '~': openum = OP_COM; break;
case '(': openum = OP_LPA; break;
case ')': openum = OP_RPA; break;
case '?': openum = OP_QUE; break;
case ';': case '[': case ']': case '{':
case '}': case ',':
openum = OP_1;
break;
default:
openum = OP_2; /* Tentative guess */
}
if (openum != OP_2) { /* Single byte operators */
*out = EOS;
return out;
}
c2 = get_ch(); /* Possibly two bytes ops */
*out++ = c2;
switch (c) {
case '=':
openum = ((c2 == '=') ? OP_EQ : OP_1); /* ==, = */
break;
case '!':
openum = ((c2 == '=') ? OP_NE : OP_NOT); /* !=, ! */
break;
case '&':
switch (c2) {
case '&': openum = OP_ANA; break; /* && */
case '=': /* openum = OP_2; */ break; /* &= */
default : openum = OP_AND; break; /* & */
}
break;
case '|':
switch (c2) {
case '|': openum = OP_ORO; break; /* || */
case '=': /* openum = OP_2; */ break; /* |= */
default : openum = OP_OR; break; /* | */
}
break;
case '<':
switch (c2) {
case '<': c3 = get_ch();
if (c3 == '=') {
openum = OP_3; /* <<= */
*out++ = c3;
} else {
openum = OP_SL; /* << */
unget_ch();
}
break;
case '=': openum = OP_LE; break; /* <= */
case ':': /* <: i.e. [ */
if (mcpp_mode == STD && option_flags.dig)
openum = OP_LBRCK_D;
else
openum = OP_LT;
break;
case '%': /* <% i.e. { */
if (mcpp_mode == STD && option_flags.dig)
openum = OP_LBRACE_D;
else
openum = OP_LT;
break;
default : openum = OP_LT; break; /* < */
}
break;
case '>':
switch (c2) {
case '>': c3 = get_ch();
if (c3 == '=') {
openum = OP_3; /* >>= */
*out++ = c3;
} else {
openum = OP_SR; /* >> */
unget_ch();
}
break;
case '=': openum = OP_GE; break; /* >= */
default : openum = OP_GT; break; /* > */
}
break;
case '#':
if (standard && (in_define || macro_line)) /* in #define or macro */
openum = ((c2 == '#') ? OP_CAT : OP_STR); /* ##, # */
else
openum = OP_1; /* # */
break;
case '+':
switch (c2) {
case '+': /* ++ */
case '=': /* openum = OP_2; */ break; /* += */
default : openum = OP_ADD; break; /* + */
}
break;
case '-':
switch (c2) {
case '-': /* -- */
case '=': /* -= */
/* openum = OP_2; */
break;
case '>':
if (cplus_val) {
if ((c3 = get_ch()) == '*') { /* ->* */
openum = OP_3;
*out++ = c3;
} else {
/* openum = OP_2; */
unget_ch();
}
} /* else openum = OP_2; */ /* -> */
/* else openum = OP_2; */
break;
default : openum = OP_SUB; break; /* - */
}
break;
case '%':
switch (c2) {
case '=': break; /* %= */
case '>': /* %> i.e. } */
if (mcpp_mode == STD && option_flags.dig)
openum = OP_RBRACE_D;
else
openum = OP_MOD;
break;
case ':':
if (mcpp_mode == STD && option_flags.dig) {
if ((c3 = get_ch()) == '%') {
if ((c4 = get_ch()) == ':') { /* %:%: i.e. ## */
openum = OP_DSHARP_D;
*out++ = c3;
*out++ = c4;
} else {
unget_ch();
unget_ch();
openum = OP_SHARP_D; /* %: i.e. # */
}
} else {
unget_ch();
openum = OP_SHARP_D; /* %: i.e. # */
}
if (in_define) { /* in #define */
if (openum == OP_DSHARP_D)
openum = OP_CAT;
else
openum = OP_STR;
}
} else {
openum = OP_MOD;
}
break;
default : openum = OP_MOD; break; /* % */
}
break;
case '*':
if (c2 != '=') /* * */
openum = OP_MUL;
/* else openum = OP_2; */ /* *= */
break;
case '/':
if (c2 != '=') /* / */
openum = OP_DIV;
/* else openum = OP_2; */ /* /= */
break;
case '^':
if (c2 != '=') /* ^ */
openum = OP_XOR;
/* else openum = OP_2; */ /* ^= */
break;
case '.':
if (standard) {
if (c2 == '.') {
c3 = get_ch();
if (c3 == '.') {
openum = OP_ELL; /* ... */
*out++ = c3;
break;
} else {
unget_ch();
openum = OP_1;
}
} else if (cplus_val && c2 == '*') { /* .* */
/* openum = OP_2 */ ;
} else { /* . */
openum = OP_1;
}
} else {
openum = OP_1;
}
break;
case ':':
if (cplus_val && c2 == ':') /* :: */
/* openum = OP_2 */ ;
else if (mcpp_mode == STD && c2 == '>' && option_flags.dig)
openum = OP_RBRCK_D; /* :> i.e. ] */
else /* : */
openum = OP_COL;
break;
default: /* Never reach here */
cfatal( "Bug: Punctuator is mis-implemented %.0s0lx%x" /* _F_ */
, NULL, (long) c, NULL);
openum = OP_1;
break;
}
switch (openum) {
case OP_STR:
if (mcpp_mode == STD && c == '%') break; /* %: */
case OP_1:
case OP_NOT: case OP_AND: case OP_OR: case OP_LT:
case OP_GT: case OP_ADD: case OP_SUB: case OP_MOD:
case OP_MUL: case OP_DIV: case OP_XOR: case OP_COM:
case OP_COL: /* Any single byte operator or punctuator */
unget_ch();
out--;
break;
default: /* Two or more bytes operators or punctuators */
break;
}
*out = EOS;
return out;
}
int id_operator(
const char * name
)
/*
* Check whether the name is identifier-like operator in C++.
* Return the operator number if matched, return 0 if not matched.
* Note: these identifiers are defined as macros in <iso646.h> in C95.
* This routine is never called in POST_STD mode.
*/
{
typedef struct id_op {
const char * name;
int op_num;
} ID_OP;
ID_OP id_ops[] = {
{ "and", OP_ANA},
{ "and_eq", OP_2},
{ "bitand", OP_AND},
{ "bitor", OP_OR},
{ "compl", OP_COM},
{ "not", OP_NOT},
{ "not_eq", OP_NE},
{ "or", OP_ORO},
{ "or_eq", OP_2},
{ "xor", OP_XOR},
{ "xor_eq", OP_2},
{ NULL, 0},
};
ID_OP * id_p = id_ops;
while (id_p->name != NULL) {
if (str_eq( name, id_p->name))
return id_p->op_num;
id_p++;
}
return 0;
}
void expanding(
const char * name, /* The name of (nested) macro just expanded. */
int to_be_freed /* The name should be freed later. */
)
/*
* Remember used macro name for diagnostic.
*/
{
if (exp_mac_ind < EXP_MAC_IND_MAX - 1) {
exp_mac_ind++;
} else {
clear_exp_mac();
exp_mac_ind++;
}
expanding_macro[ exp_mac_ind].name = name;
expanding_macro[ exp_mac_ind].to_be_freed = to_be_freed;
}
void clear_exp_mac( void)
/*
* Initialize expanding_macro[] freeing names registered in
* name_to_be_freed[].
*/
{
int i;
for (i = 1; i < EXP_MAC_IND_MAX; i++) {
if (expanding_macro[ i].to_be_freed) {
free( (void *) expanding_macro[ i].name);
expanding_macro[ i].to_be_freed = FALSE;
}
}
exp_mac_ind = 0;
}
int get_ch( void)
/*
* Return the next character from a macro or the current file.
* Always return the value representable by unsigned char.
*/
{
int len;
int c;
FILEINFO * file;
/*
* 'in_token' is set to TRUE while scan_token() is executed (and
* scan_id(), scan_quote(), scan_number(), scan_ucn() and scan_op()
* via scan_token()) in Standard mode to simplify tokenization.
* Any token cannot cross "file"s.
*/
if (in_token)
return (*infile->bptr++ & UCHARMAX);
if ((file = infile) == NULL)
return CHAR_EOF; /* End of all input */
if (mcpp_mode == POST_STD && file->fp) { /* In a source file */
switch (insert_sep) {
case NO_SEP:
break;
case INSERT_SEP: /* Insert a token separator */
insert_sep = INSERTED_SEP; /* Remember this fact */
return ' '; /* for unget_ch(). */
case INSERTED_SEP: /* Has just inserted */
insert_sep = NO_SEP; /* Clear the flag */
break;
}
}
if (! standard && squeezews) {
if (*file->bptr == ' ')
file->bptr++; /* Squeeze white spaces */
squeezews = FALSE;
}
if (mcpp_debug & GETC) {
mcpp_fprintf( DBG, "get_ch(%s) '%c' line %ld, bptr = %d, buffer"
, file->fp ? cur_fullname : file->real_fname ? file->real_fname
: file->filename ? file->filename : "NULL"
, *file->bptr & UCHARMAX
, src_line, (int) (file->bptr - file->buffer));
dump_string( NULL, file->buffer);
dump_unget( "get entrance");
}
/*
* Read a character from the current input logical line or macro.
* At EOS, either finish the current macro (freeing temporary storage)
* or get another logical line by parse_line().
* At EOF, exit the current file (#included) or, at EOF from the MCPP input
* file, return CHAR_EOF to finish processing.
* The character is converted to int with no sign-extension.
*/
if ((c = (*file->bptr++ & UCHARMAX)) != EOS) {
if (standard)
return c; /* Just a character */
if (! in_string && c == '\\' && *file->bptr == '\n'
&& in_define /* '\\''\n' is deleted in #define line, */
/* provided the '\\' is not the 2nd byte of mbchar. */
&& ! last_is_mbchar( file->buffer, strlen( file->buffer) - 2
&& ! keep_spaces)
) {
if (*(file->bptr - 2) == ' ')
squeezews = TRUE;
} else {
return c;
}
}
/*
* Nothing in current line or macro. Get next line (if input from a
* file), or do end of file/macro processing, and reenter get_ch() to
* restart from the top.
*/
if (file->fp && /* In source file */
parse_line() != NULL) /* Get line from file */
return get_ch();
/*
* Free up space used by the (finished) file or macro and restart
* input from the parent file/macro, if any.
*/
infile = file->parent; /* Unwind file chain */
free( file->buffer); /* Free buffer */
if (infile == NULL) { /* If at end of input */
free( file->filename);
free( file->src_dir);
free( file); /* full_fname is the same with filename for main file*/
return CHAR_EOF; /* Return end of file */
}
if (file->fp) { /* Source file included */
free( file->filename); /* Free filename */
free( file->src_dir); /* Free src_dir */
fclose( file->fp); /* Close finished file */
/* Do not free file->real_fname and file->full_fname */
cur_fullname = infile->full_fname;
cur_fname = infile->real_fname; /* Restore current fname*/
if (infile->pos != 0L) { /* Includer was closed */
infile->fp = fopen( cur_fullname, "r");
fseek( infile->fp, infile->pos, SEEK_SET);
} /* Re-open the includer and restore the file-position */
len = (int) (infile->bptr - infile->buffer);
infile->buffer = xrealloc( infile->buffer, NBUFF);
/* Restore full size buffer to get the next line */
infile->bptr = infile->buffer + len;
src_line = infile->line; /* Reset line number */
inc_dirp = infile->dirp; /* Includer's directory */
#if MCPP_LIB
mcpp_set_out_func( infile->last_fputc, infile->last_fputs,
infile->last_fprintf);
#endif
include_nest--;
src_line++; /* Next line to #include*/
sharp( NULL, infile->include_opt ? 1 : (file->include_opt ? 0 : 2));
/* Need a #line now. Marker depends on include_opt. */
/* The file of include_opt should be marked as 1. */
/* Else if returned from include_opt file, it is the */
/* main input file, and should not be marked. */
/* Else, it is normal includer file, and marked as 2. */
src_line--;
newlines = 0; /* Clear the blank lines*/
if (mcpp_debug & MACRO_CALL) /* Should be re-initialized */
com_cat_line.last_line = bsl_cat_line.last_line = 0L;
} else if (file->filename) { /* Expanding macro */
if (macro_name) /* file->filename should be freed later */
expanding( file->filename, TRUE);
else
free( file->filename);
}
free( file); /* Free file space */
return get_ch(); /* Get from the parent */
}
static char * parse_line( void)
/*
* ANSI (ISO) C: translation phase 3.
* Parse a logical line.
* Check illegal control characters.
* Check unterminated string literal, character constant or comment.
* Convert each comment to one space (or spaces of the comment length on
* 'keep_spaces' mode)..
* Squeeze succeding white spaces other than <newline> (including comments) to
* one space (unless keep_spaces == TRUE).
* The lines might be spliced by comments which cross the lines.
*/
{
char * temp; /* Temporary buffer */
char * limit; /* Buffer end */
char * tp; /* Current pointer into temporary buffer */
char * sp; /* Pointer into input buffer */
size_t com_size;
int c;
if ((sp = get_line( FALSE)) == NULL) /* Next logical line */
return NULL; /* End of a file */
if (in_asm) { /* In #asm block */
while (char_type[ *sp++ & UCHARMAX] & SPA)
;
if (*--sp == '#') /* Directive line */
infile->bptr = sp;
return infile->bptr; /* Don't tokenize */
}
tp = temp = xmalloc( (size_t) NBUFF);
limit = temp + NBUFF - 2;
while (char_type[ c = *sp++ & UCHARMAX] & HSP) {
if (mcpp_mode != POST_STD)
/* Preserve line top horizontal white spaces */
/* as they are for human-readability */
*tp++ = c;
/* Else skip the line top spaces */
}
sp--;
while ((c = *sp++ & UCHARMAX) != '\n') {
switch (c) {
case '/':
switch (*sp++) {
case '*': /* Start of a comment */
com_start:
if ((sp = read_a_comment( sp, &com_size)) == NULL) {
free( temp); /* End of file with un- */
return NULL; /* terminated comment */
}
if (keep_spaces && mcpp_mode != OLD_PREP) {
if (tp + com_size >= limit - 1) /* Too long comment */
com_size = limit - tp - 1; /* Truncate */
while (com_size--)
*tp++ = ' '; /* Spaces of the comment length */
break;
}
switch (mcpp_mode) {
case POST_STD:
if (temp < tp && *(tp - 1) != ' ')
*tp++ = ' '; /* Squeeze white spaces */
break;
case OLD_PREP:
if (temp == tp
|| ! (char_type[ *(tp - 1) & UCHARMAX] & HSP))
*tp++ = COM_SEP; /* Convert to magic character */
break;
default:
if (temp == tp ||
! (char_type[ *(tp - 1) & UCHARMAX] & HSP))
*tp++ = ' '; /* Squeeze white spaces */
break;
}
break;
case '/': /* // */
if (! standard)
goto not_comment;
/* Comment when C++ or __STDC_VERSION__ >= 199901L */
/* Need not to convert to a space because '\n' follows */
if (! stdc2 && (warn_level & 2))
cwarn( "Parsed \"//\" as comment" /* _W2_ */
, NULL, 0L, NULL);
if (keep_comments) {
sp -= 2;
while (*sp != '\n') /* Until end of line */
mcpp_fputc( *sp++, OUT);
mcpp_fputc('\n', OUT);
wrong_line = TRUE;
}
goto end_line;
default: /* Not a comment */
not_comment:
*tp++ = '/';
sp--; /* To re-read */
break;
}
break;
case '\r': /* Vertical white spaces*/
/* Note that [CR+LF] is already converted to [LF]. */
case '\f':
case '\v':
if (warn_level & 4)
cwarn( "Converted %.0s0x%02lx to a space" /* _W4_ */
, NULL, (long) c, NULL);
case '\t': /* Horizontal space */
case ' ':
if (keep_spaces) {
if (c == '\t')
*tp++ = '\t';
else
*tp++ = ' '; /* Convert to ' ' */
} else if (temp == tp
|| ! (char_type[ *(tp - 1) & UCHARMAX] & HSP)) {
*tp++ = ' '; /* Squeeze white spaces */
} else if (mcpp_mode == OLD_PREP && tp > temp
&& *(tp - 1) == COM_SEP) {
*(tp - 1) = ' '; /* Replace COM_SEP with ' ' */
}
break;
case '"': /* String literal */
case '\'': /* Character constant */
infile->bptr = sp;
if (standard) {
tp = scan_quote( c, tp, limit, TRUE);
} else {
in_string = TRUE; /* Enable line splicing by scan_quote() */
tp = scan_quote( c, tp, limit, TRUE); /* (not by get_ch())*/
in_string = FALSE;
}
if (tp == NULL) {
free( temp); /* Unbalanced quotation */
return parse_line(); /* Skip the line */
}
sp = infile->bptr;
break;
default:
if (iscntrl( c)) {
cerror( /* Skip the control character */
"Illegal control character %.0s0x%02x, skipped the character" /* _E_ */
, NULL, (long) c, NULL);
} else { /* Any valid character */
*tp++ = c;
}
break;
}
if (limit < tp) {
*tp = EOS;
cfatal( "Too long line spliced by comments" /* _F_ */
, NULL, 0L, NULL);
}
}
end_line:
if (temp < tp && (char_type[ *(tp - 1) & UCHARMAX] & HSP))
tp--; /* Remove trailing white space */
*tp++ = '\n';
*tp = EOS;
infile->bptr = strcpy( infile->buffer, temp); /* Write back to buffer */
free( temp);
if (macro_line != 0 && macro_line != MACRO_ERROR) { /* Expanding macro */
temp = infile->buffer;
while (char_type[ *temp & UCHARMAX] & HSP)
temp++;
if (*temp == '#' /* This line starts with # token */
|| (mcpp_mode == STD && *temp == '%' && *(temp + 1) == ':'))
if (warn_level & 1)
cwarn(
"Macro started at line %.0s%ld swallowed directive-like line" /* _W1_ */
, NULL, macro_line, NULL);
}
return infile->buffer;
}
static char * read_a_comment(
char * sp, /* Source */
size_t * sizp /* Size of the comment */
)
/*
* Read over a comment (which may cross the lines).
*/
{
int c;
char * saved_sp;
int cat_line = 0; /* Number of catenated lines */
if (keep_spaces) {
saved_sp = sp - 2; /* '-2' for beginning / and * */
*sizp = 0;
}
if (keep_comments) /* If writing comments */
mcpp_fputs( "/*", OUT); /* Write the initializer*/
c = *sp++;
while (1) { /* Eat a comment */
if (keep_comments)
mcpp_fputc( c, OUT);
switch (c) {
case '/':
if ((c = *sp++) != '*') /* Don't let comments */
continue; /* nest. */
if (warn_level & 1)
cwarn( "\"/*\" within comment", NULL, 0L, NULL); /* _W1_ */
if (keep_comments)
mcpp_fputc( c, OUT);
/* Fall into * stuff */
case '*':
if ((c = *sp++) != '/') /* If comment doesn't */
continue; /* end, look at next. */
if (keep_comments) { /* Put out comment */
mcpp_fputc( c, OUT); /* terminator, too. */
mcpp_fputc( '\n', OUT); /* Append '\n' to avoid */
/* trouble on some other tools such as rpcgen. */
wrong_line = TRUE;
}
if (keep_spaces) /* Save the length */
*sizp = *sizp + (sp - saved_sp);
if ((mcpp_debug & MACRO_CALL) && compiling) {
if (cat_line) {
cat_line++;
com_cat_line.len[ cat_line] /* Catenated length */
= com_cat_line.len[ cat_line - 1]
+ strlen( infile->buffer) - 1;
/* '-1' for '\n' */
com_cat_line.last_line = src_line;
}
}
return sp; /* End of comment */
case '\n': /* Line-crossing comment*/
if (keep_spaces) /* Save the length */
*sizp = *sizp + (sp - saved_sp) - 1; /* '-1' for '\n' */
if ((mcpp_debug & MACRO_CALL) && compiling) {
/* Save location informations */
if (cat_line == 0) /* First line of catenation */
com_cat_line.start_line = src_line;
if (cat_line >= MAX_CAT_LINE - 1) {
*sizp = 0; /* Discard the too long comment */
cat_line = 0;
if (warn_level & 4)
cwarn(
"Too long comment, discarded up to here" /* _W4_ */
, NULL, 0L, NULL);
}
cat_line++;
com_cat_line.len[ cat_line]
= com_cat_line.len[ cat_line - 1]
+ strlen( infile->buffer) - 1;
}
if ((saved_sp = sp = get_line( TRUE)) == NULL)
return NULL; /* End of file within comment */
/* Never happen, because at_eof() supplement closing*/
wrong_line = TRUE; /* We'll need a #line later */
break;
default: /* Anything else is */
break; /* just a character */
} /* End switch */
c = *sp++;
} /* End comment loop */
return sp; /* Never reach here */
}
static char * mcpp_fgets(
char * s,
int size,
FILE * stream
)
{
return fgets( s, size, stream);
}
static char * get_line(
int in_comment
)
/*
* ANSI (ISO) C: translation phase 1, 2.
* Get the next logical line from source file.
* Convert [CR+LF] to [LF].
*/
{
#if COMPILER == INDEPENDENT
#define cr_warn_level 1
#else
#define cr_warn_level 2
#endif
static int cr_converted;
int converted = FALSE;
int len; /* Line length - alpha */
char * ptr;
int cat_line = 0; /* Number of catenated lines */
if (infile == NULL) /* End of a source file */
return NULL;
ptr = infile->bptr = infile->buffer;
if ((mcpp_debug & MACRO_CALL) && src_line == 0) /* Initialize */
com_cat_line.last_line = bsl_cat_line.last_line = 0L;
while (mcpp_fgets( ptr, (int) (infile->buffer + NBUFF - ptr), infile->fp)
!= NULL) {
/* Translation phase 1 */
src_line++; /* Gotten next physical line */
if (standard && src_line == std_limits.line_num + 1
&& (warn_level & 1))
cwarn( "Line number %.0s\"%ld\" got beyond range" /* _W1_ */
, NULL, src_line, NULL);
if (mcpp_debug & (TOKEN | GETC)) { /* Dump it to DBG */
mcpp_fprintf( DBG, "\n#line %ld (%s)", src_line, cur_fullname);
dump_string( NULL, ptr);
}
len = strlen( ptr);
if (len == 0)
cwarn( "null character ignored", NULL, 0L, NULL);
if (NBUFF - 1 <= ptr - infile->buffer + len
&& *(ptr + len - 1) != '\n') {
/* The line does not yet end, though the buffer is full. */
if (NBUFF - 1 <= len)
cfatal( "Too long source line" /* _F_ */
, NULL, 0L, NULL);
else
cfatal( "Too long logical line" /* _F_ */
, NULL, 0L, NULL);
}
if (*(ptr + len - 1) != '\n') /* Unterminated source line */
break;
if (len >= 2 && *(ptr + len - 2) == '\r') { /* [CR+LF] */
*(ptr + len - 2) = '\n';
*(ptr + --len) = EOS;
if (! cr_converted && (warn_level & cr_warn_level)) {
cwarn( "Converted [CR+LF] to [LF]" /* _W1_ _W2_ */
, NULL, 0L, NULL);
cr_converted = TRUE;
}
}
if (standard) {
if (option_flags.trig)
converted = cnv_trigraph( ptr);
if (mcpp_mode == POST_STD && option_flags.dig)
converted += cnv_digraph( ptr);
if (converted)
len = strlen( ptr);
/* Translation phase 2 */
len -= 2;
if (len >= 0) {
if ((*(ptr + len) == '\\') && ! last_is_mbchar( ptr, len)) {
/* <backslash><newline> (not MBCHAR) */
ptr = infile->bptr += len; /* Splice the lines */
wrong_line = TRUE;
if ((mcpp_debug & MACRO_CALL) && compiling) {
/* Save location informations */
if (cat_line == 0) /* First line of catenation */
bsl_cat_line.start_line = src_line;
if (cat_line < MAX_CAT_LINE)
/* Record the catenated length */
bsl_cat_line.len[ ++cat_line]
= strlen( infile->buffer) - 2;
/* Else ignore */
}
continue;
}
}
#if NBUFF-2 > SLEN90MIN
if (ptr - infile->buffer + len + 2 > std_limits.str_len + 1
&& (warn_level & 4)) /* +1 for '\n' */
cwarn( "Logical source line longer than %.0s%ld bytes" /* _W4_ */
, NULL, std_limits.str_len, NULL);
#endif
}
if ((mcpp_debug & MACRO_CALL) && compiling) {
if (cat_line && cat_line < MAX_CAT_LINE) {
bsl_cat_line.len[ ++cat_line] = strlen( infile->buffer) - 1;
/* Catenated length: '-1' for '\n' */
bsl_cat_line.last_line = src_line;
}
}
return infile->bptr = infile->buffer; /* Logical line */
}
/* End of a (possibly included) source file */
if (ferror( infile->fp))
cfatal( "File read error", NULL, 0L, NULL); /* _F_ */
if ((ptr = at_eof( in_comment)) != NULL) /* Check at end of file */
return ptr; /* Partial line supplemented */
if (option_flags.z) {
no_output--; /* End of included file */
keep_comments = option_flags.c && compiling && !no_output;
}
return NULL;
}
#define TRIOFFSET 10
int cnv_trigraph(
char * in
)
/*
* Perform in-place trigraph replacement on a physical line. This was added
* to the C90. In an input text line, the sequence ??[something] is
* transformed to a character (which might not appear on the input keyboard).
*/
{
const char * const tritext = "=(/)'<!>-\0#[\\]^{|}~";
/* ^ ^
* +----------+
* this becomes this
*/
int count = 0;
const char * tp;
while ((in = strchr( in, '?')) != NULL) {
if (*++in != '?')
continue;
while (*++in == '?')
;
if ((tp = strchr( tritext, *in)) == NULL)
continue;
*(in - 2) = *(tp + TRIOFFSET);
in--;
memmove( in, in + 2, strlen( in + 1));
count++;
}
if (count && (warn_level & 16))
cwarn( "%.0s%ld trigraph(s) converted" /* _W16_ */
, NULL, (long) count, NULL);
return count;
}
int cnv_digraph(
char * in
)
/*
* Perform in-place digraph replacement on a physical line.
* Called only in POST_STD mode.
*/
{
int count = 0;
int i;
int c1, c2;
while ((i = strcspn( in, "%:<")), (c1 = *(in + i)) != '\0') {
in += i + 1;
c2 = *in;
switch (c1) {
case '%' :
switch (c2) {
case ':' : *(in - 1) = '#'; break;
case '>' : *(in - 1) = '}'; break;
default : continue;
}
break;
case ':' :
switch (c2) {
case '>' : *(in - 1) = ']'; break;
default : continue;
}
break;
case '<' :
switch (c2) {
case '%' : *(in - 1) = '{'; break;
case ':' : *(in - 1) = '['; break;
default : continue;
}
break;
}
memmove( in, in + 1, strlen( in));
count++;
}
if (count && (warn_level & 16))
cwarn( "%.0s%ld digraph(s) converted" /* _W16_ */
, NULL, (long) count, NULL);
return count;
}
static char * at_eof(
int in_comment
)
/*
* Check the partial line, unterminated comment, unbalanced #if block,
* uncompleted macro call at end of a file or at end of input.
* Supplement the line terminator, if possible.
* Return the supplemented line or NULL on unrecoverable error.
*/
{
const char * const format
= "End of %s with %.0ld%s"; /* _E_ _W1_ */
const char * const unterm_if_format
= "End of %s within #if (#ifdef) section started at line %ld"; /* _E_ _W1_ */
const char * const unterm_macro_format
= "End of %s within macro call started at line %ld";/* _E_ _W1_ */
const char * const input
= infile->parent ? "file" : "input"; /* _E_ _W1_ */
const char * const no_newline
= "no newline, supplemented newline"; /* _W1_ */
const char * const unterm_com
= "unterminated comment, terminated the comment"; /* _W1_ */
const char * const backsl = "\\, deleted the \\"; /* _W1_ */
const char * const unterm_asm_format
= "End of %s with unterminated #asm block started at line %ld"; /* _E_ _W1_ */
size_t len;
char * cp;
cp = infile->buffer;
len = strlen( cp);
if (len && *(cp += (len - 1)) != '\n') {
*++cp = '\n'; /* Supplement <newline> */
*++cp = EOS;
if (mcpp_mode != OLD_PREP && (warn_level & 1))
cwarn( format, input, 0L, no_newline);
return infile->bptr = infile->buffer;
}
if (standard && infile->buffer < infile->bptr) {
/* No line after <backslash><newline> */
cp = infile->bptr;
*cp++ = '\n'; /* Delete the \\ */
*cp = EOS;
if (warn_level & 1)
cwarn( format, input, 0L, backsl);
return infile->bptr = infile->buffer;
}
if (in_comment) { /* End of file within a comment */
if (mcpp_mode != OLD_PREP && (warn_level & 1))
cwarn( format, input, 0L, unterm_com);
/* The partial comment line has been already read by */
/* read_a_comment(), so supplement the next line. */
strcpy( infile->buffer, "*/\n");
return infile->bptr = infile->buffer;
}
if (infile->initif < ifptr) {
IFINFO * ifp = infile->initif + 1;
if (standard) {
cerror( unterm_if_format, input, ifp->ifline, NULL);
ifptr = infile->initif; /* Clear information of */
compiling = ifptr->stat; /* erroneous grouping */
} else if (mcpp_mode == KR && (warn_level & 1)) {
cwarn( unterm_if_format, input, ifp->ifline, NULL);
}
}
if (macro_line != 0 && macro_line != MACRO_ERROR
&& ((mcpp_mode == STD && in_getarg) || ! standard)) {
if (standard) {
cerror( unterm_macro_format, input, macro_line, NULL);
macro_line = MACRO_ERROR;
} else if (warn_level & 1) {
cwarn( unterm_macro_format, input, macro_line, NULL);
}
}
if (in_asm && mcpp_mode == KR && (warn_level & 1))
cwarn( unterm_asm_format, input, in_asm, NULL);
return NULL;
}
void unget_ch( void)
/*
* Back the pointer to reread the last character. Fatal error (code bug)
* if we back too far. unget_ch() may be called, without problems, at end of
* file. Only one character may be ungotten. If you need to unget more,
* call unget_string().
*/
{
if (in_token) {
infile->bptr--;
return;
}
if (infile != NULL) {
if (mcpp_mode == POST_STD && infile->fp) {
switch (insert_sep) {
case INSERTED_SEP: /* Have just read an inserted separator */
insert_sep = INSERT_SEP;
return;
case INSERT_SEP:
cfatal( "Bug: unget_ch() just after scan_token()" /* _F_ */
, NULL, 0L, NULL);
break;
default:
break;
}
}
--infile->bptr;
if (infile->bptr < infile->buffer) /* Shouldn't happen */
cfatal( "Bug: Too much pushback", NULL, 0L, NULL); /* _F_ */
}
if (mcpp_debug & GETC)
dump_unget( "after unget");
}
FILEINFO * unget_string(
const char * text, /* Text to unget */
const char * name /* Name of the macro, if any*/
)
/*
* Push a string back on the input stream. This is done by treating
* the text as if it were a macro or a file.
*/
{
FILEINFO * file;
size_t size;
if (text)
size = strlen( text) + 1;
else
size = 1;
file = get_file( name, NULL, NULL, size, FALSE);
if (text)
memcpy( file->buffer, text, size);
else
*file->buffer = EOS;
return file;
}
char * save_string(
const char * text
)
/*
* Store a string into free memory.
*/
{
char * result;
size_t size;
size = strlen( text) + 1;
result = xmalloc( size);
memcpy( result, text, size);
return result;
}
FILEINFO * get_file(
const char * name, /* File or macro name */
const char * src_dir, /* Source file directory*/
char * fullname, /* Full path list */
size_t bufsize, /* Line buffer size */
int include_opt /* Specified by -include opt (for GCC) */
)
/*
* Common FILEINFO buffer initialization for a new file or macro.
*/
{
FILEINFO * file;
file = (FILEINFO *) xmalloc( sizeof (FILEINFO));
file->buffer = xmalloc( bufsize);
file->bptr = file->buffer; /* Initialize line ptr */
file->buffer[ 0] = EOS; /* Force first read */
file->line = 0L; /* (Not used just yet) */
file->fp = NULL; /* No file yet */
file->pos = 0L; /* No pos to remember */
file->parent = infile; /* Chain files together */
file->initif = ifptr; /* Initial ifstack */
file->include_opt = include_opt; /* Specified by -include*/
file->dirp = NULL; /* No include dir yet */
file->real_fname = name; /* Save file/macro name */
file->full_fname = fullname; /* Full path list */
if (name) {
file->filename = xmalloc( strlen( name) + 1);
strcpy( file->filename, name); /* Copy for #line */
} else {
file->filename = NULL;
}
if (src_dir) {
file->src_dir = xmalloc( strlen( src_dir) + 1);
strcpy( file->src_dir, src_dir);
} else {
file->src_dir = NULL;
}
#if MCPP_LIB
file->last_fputc = mcpp_lib_fputc;
file->last_fputs = mcpp_lib_fputs;
file->last_fprintf = mcpp_lib_fprintf;
#endif
if (infile != NULL) { /* If #include file */
infile->line = src_line; /* Save current line */
#if MCPP_LIB
infile->last_fputc = mcpp_fputc;
infile->last_fputs = mcpp_fputs;
infile->last_fprintf = mcpp_fprintf;
#endif
}
infile = file; /* New current file */
return file; /* All done. */
}
static const char * const out_of_memory
= "Out of memory (required size is %.0s0x%lx bytes)"; /* _F_ */
char *
(xmalloc)(
size_t size
)
/*
* Get a block of free memory.
*/
{
char * result;
if ((result = (char *) malloc( size)) == NULL) {
if (mcpp_debug & MEMORY)
print_heap();
cfatal( out_of_memory, NULL, (long) size, NULL);
}
return result;
}
char * (xrealloc)(
char * ptr,
size_t size
)
/*
* Reallocate malloc()ed memory.
*/
{
char * result;
if ((result = (char *) realloc( ptr, size)) == NULL && size != 0) {
/* 'size != 0' is necessary to cope with some */
/* implementation of realloc( ptr, 0) which returns NULL. */
if (mcpp_debug & MEMORY)
print_heap();
cfatal( out_of_memory, NULL, (long) size, NULL);
}
return result;
}
LINE_COL * get_src_location(
LINE_COL * p_line_col /* Line and column on phase 4 */
)
/*
* Convert line-column datum of just after translation phase 3 into that of
* phase 2, tracing back line splicing by a comment and <backslash><newline>.
* Note: This conversion does not give correct datum on a line catenated by
* both of <backslash><newline> and line-crossing-comment at the same time.
*
* com_cat_line and bsl_cat_line have data only on last catenated line.
* com_cat_line.len[] and bsl_cat_line.len[] have the length of catenated
* line, and len[ 0] is always 0, followed by len[ 1], len[ 2], ..., as
* accumulated length of successively catenated lines.
*/
{
long line;
size_t col;
size_t * cols;
CAT_LINE * l_col_p;
int i;
line = p_line_col->line;
col = p_line_col->col;
for (i = 0; i <= 1; i++) {
l_col_p = i ? & bsl_cat_line : & com_cat_line;
if (l_col_p->last_line != line)
continue;
/* Else just catenated line */
cols = l_col_p->len + 1;
while (*cols < col)
cols++;
if (col <= *cols) {
cols--;
col -= *cols;
}
line = l_col_p->start_line + (cols - l_col_p->len);
}
p_line_col->line = line;
p_line_col->col = col + 1;
/* col internally start at 0, output start at 1 */
return p_line_col;
}
static void put_line(
char * out,
FILE * fp
)
/*
* Put out a logical source line.
* This routine is called only in OLD_PREP mode.
*/
{
int c;
while ((c = *out++) != EOS) {
if (c != COM_SEP) /* Skip 0-length comment */
mcpp_fputc( c, FP2DEST( fp));
}
}
static void do_msg(
const char * severity, /* "fatal", "error", "warning" */
const char * format, /* Format for the error message */
const char * arg1, /* String arg. for the message */
long arg2, /* Integer argument */
const char * arg3 /* Second string argument */
)
/*
* Print filenames, macro names, line numbers and error messages.
* Also print macro definitions on macro expansion problems.
*/
{
FILEINFO * file;
DEFBUF * defp;
int i;
size_t slen;
const char * arg_s[ 2];
char * arg_t[ 2];
char * tp;
const char * sp;
int c;
int ind;
fflush( fp_out); /* Synchronize output and diagnostics */
arg_s[ 0] = arg1; arg_s[ 1] = arg3;
for (i = 0; i < 2; i++) { /* Convert special characters to visible */
sp = arg_s[ i];
if (sp != NULL)
slen = strlen( sp) + 1;
else
slen = 1;
tp = arg_t[ i] = (char *) malloc( slen);
/* Don't use xmalloc() so as not to cause infinite recursion */
if (sp == NULL || *sp == EOS) {
*tp = EOS;
continue;
}
while ((c = *sp++) != EOS) {
switch (c) {
case TOK_SEP:
if (mcpp_mode == OLD_PREP) /* COM_SEP */
break; /* Skip magic characters */
/* Else fall through */
case RT_END:
case CAT:
case ST_QUOTE:
case DEF_MAGIC:
if (! standard)
*tp++ = ' ';
break; /* Skip the magic characters*/
case IN_SRC:
if (! standard)
*tp++ = ' ';
if ((mcpp_debug & MACRO_CALL) && ! in_directive)
sp += 2; /* Skip two more bytes */
break;
case MAC_INF:
if (mcpp_mode != STD) {
*tp++ = ' ';
/* Illegal control character, convert to a space*/
} else {
switch (*sp++) { /* Skip the magic characters*/
case MAC_ARG_START :
sp++;
/* Fall through */
case MAC_CALL_START :
sp += 2;
break;
case MAC_ARG_END :
if (! option_flags.v)
break;
else
sp++;
/* Fall through */
case MAC_CALL_END :
if (option_flags.v)
sp += 2;
break;
}
}
break;
case '\n':
*tp++ = ' '; /* Convert '\n' to a space */
break;
default:
*tp++ = c;
break;
}
}
if (*(sp - 2) == '\n')
tp--;
*tp = EOS;
}
/* Print source location and diagnostic */
file = infile;
while (file != NULL && (file->fp == NULL || file->fp == (FILE *)-1))
file = file->parent; /* Skip macro */
if (file != NULL) {
file->line = src_line;
mcpp_fprintf( ERR, "%s:%ld: %s: ", cur_fullname, src_line, severity);
}
mcpp_fprintf( ERR, format, arg_t[ 0], arg2, arg_t[ 1]);
mcpp_fputc( '\n', ERR);
if (option_flags.no_source_line)
goto free_arg;
/* Print source line, includers and expanding macros */
file = infile;
if (file != NULL && file->fp != NULL) {
if (mcpp_mode == OLD_PREP) {
mcpp_fputs( " ", ERR);
put_line( file->buffer, fp_err);
} else {
mcpp_fprintf( ERR, " %s", file->buffer);
/* Current source line */
}
file = file->parent;
}
while (file != NULL) { /* Print #includes, too */
if (file->fp == NULL) { /* Macro */
if (file->filename) {
defp = look_id( file->filename);
if ((defp->nargs > DEF_NOARGS_STANDARD)
&& ! (file->parent && file->parent->filename
&& str_eq( file->filename, file->parent->filename)))
/* If the name is not duplicate of parent */
dump_a_def( " macro", defp, FALSE, TRUE, fp_err);
}
} else { /* Source file */
if (file->buffer[ 0] == '\0')
strcpy( file->buffer, "\n");
if (mcpp_mode != OLD_PREP) {
mcpp_fprintf( ERR, " from %s: %ld: %s",
file->line ? file->full_fname /* Full-path-list */
: "<stdin>", /* Included by -include */
file->line, /* Current line number */
file->buffer); /* The source line */
} else {
mcpp_fprintf( ERR, " from %s: %ld: ", file->full_fname
, file->line);
put_line( file->buffer, fp_err);
}
}
file = file->parent;
}
if (! macro_name)
goto free_arg;
/* Additional information of macro definitions */
expanding_macro[ 0].name = macro_name;
for (ind = 0; ind <= exp_mac_ind; ind++) {
int ind_done;
for (ind_done = 0; ind_done < ind; ind_done++)
if (str_eq( expanding_macro[ ind].name
, expanding_macro[ ind_done].name))
break; /* Already reported */
if (ind_done < ind)
continue;
for (file = infile; file; file = file->parent)
if (file->fp == NULL && file->filename
&& str_eq( expanding_macro[ ind].name, file->filename))
break; /* Already reported */
if (file)
continue;
if ((defp = look_id( expanding_macro[ ind].name)) != NULL) {
if (defp->nargs <= DEF_NOARGS_STANDARD)
continue; /* Standard predefined */
dump_a_def( " macro", defp, FALSE, TRUE, fp_err);
/* Macro already read over */
}
}
free_arg:
for (i = 0; i < 2; i++)
free( arg_t[ i]);
}
void cfatal(
const char * format,
const char * arg1,
long arg2,
const char * arg3
)
/*
* A real disaster.
*/
{
do_msg( "fatal error", format, arg1, arg2, arg3);
longjmp( error_exit, -1);
}
void cerror(
const char * format,
const char * arg1,
long arg2,
const char * arg3
)
/*
* Print a error message.
*/
{
do_msg( "error", format, arg1, arg2, arg3);
errors++;
}
void cwarn(
const char * format,
const char * arg1,
long arg2,
const char * arg3
)
/*
* Maybe an error.
*/
{
do_msg( "warning", format, arg1, arg2, arg3);
}
void dump_string(
const char * why,
const char * text
)
/*
* Dump text readably.
* Bug: macro argument number may be putout as a control character or any
* other character, just after MAC_PARM has been read away.
*/
{
const char * cp;
const char * chr;
int c, c1, c2;
if (why != NULL)
mcpp_fprintf( DBG, " (%s)", why);
mcpp_fputs( " => ", DBG);
if (text == NULL) {
mcpp_fputs( "NULL", DBG);
return;
}
for (cp = text; (c = *cp++ & UCHARMAX) != EOS; ) {
chr = NULL;
switch (c) {
case MAC_PARM:
c = *cp++ & UCHARMAX; /* Macro parameter number */
mcpp_fprintf( DBG, "<%d>", c);
break;
case MAC_INF:
if (! (mcpp_mode == STD && (mcpp_debug & MACRO_CALL)))
goto no_magic;
/* Macro informations inserted by -K option */
c2 = *cp++ & UCHARMAX;
if (option_flags.v || c2 == MAC_CALL_START
|| c2 == MAC_ARG_START) {
c = ((*cp++ & UCHARMAX) - 1) * UCHARMAX;
c += (*cp++ & UCHARMAX) - 1;
}
switch (c2) {
case MAC_CALL_START:
mcpp_fprintf( DBG, "<MAC%d>", c);
break;
case MAC_CALL_END:
if (option_flags.v)
mcpp_fprintf( DBG, "<MAC_END%d>", c);
else
chr = "<MAC_END>";
break;
case MAC_ARG_START:
c1 = *cp++ & UCHARMAX;
mcpp_fprintf( DBG, "<MAC%d:ARG%d>", c, c1 - 1);
break;
case MAC_ARG_END:
if (option_flags.v) {
c1 = *cp++ & UCHARMAX;
mcpp_fprintf( DBG, "<ARG_END%d-%d>", c, c1 - 1);
} else {
chr = "<ARG_END>";
}
break;
}
break;
case DEF_MAGIC:
if (standard) {
chr = "<MAGIC>";
break;
} /* Else fall through */
case CAT:
if (standard) {
chr = "##";
break;
} /* Else fall through */
case ST_QUOTE:
if (standard) {
chr = "#";
break;
} /* Else fall through */
case RT_END:
if (standard) {
chr = "<RT_END>";
break;
} /* Else fall through */
case IN_SRC:
if (standard) {
if ((mcpp_debug & MACRO_CALL) && ! in_directive) {
int num;
num = ((*cp++ & UCHARMAX) - 1) * UCHARMAX;
num += (*cp++ & UCHARMAX) - 1;
mcpp_fprintf( DBG, "<SRC%d>", num);
} else {
chr = "<SRC>";
}
} else { /* Control character */
mcpp_fprintf( DBG, "<^%c>", c + '@');
}
break;
case TOK_SEP:
if (mcpp_mode == STD) {
chr = "<TSEP>";
break;
} else if (mcpp_mode == OLD_PREP) { /* COM_SEP */
chr = "<CSEP>";
break;
} /* Else fall through */
default:
no_magic:
if (c < ' ')
mcpp_fprintf( DBG, "<^%c>", c + '@');
else
mcpp_fputc( c, DBG);
break;
}
if (chr)
mcpp_fputs( chr, DBG);
}
mcpp_fputc( '\n', DBG);
}
void dump_unget(
const char * why
)
/*
* Dump all ungotten junk (pending macros and current input lines).
*/
{
const FILEINFO * file;
mcpp_fputs( "dump of pending input text", DBG);
if (why != NULL) {
mcpp_fputs( "-- ", DBG);
mcpp_fputs( why, DBG);
}
mcpp_fputc( '\n', DBG);
for (file = infile; file != NULL; file = file->parent)
dump_string( file->real_fname ? file->real_fname
: file->filename ? file->filename : "NULL", file->bptr);
}
static void dump_token(
int token_type,
const char * cp /* Token */
)
/*
* Dump a token.
*/
{
static const char * const t_type[]
= { "NAM", "NUM", "STR", "WSTR", "CHR", "WCHR", "OPE", "SPE"
, "SEP", };
mcpp_fputs( "token", DBG);
dump_string( t_type[ token_type - NAM], cp);
}
|