1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 10368 10369 10370 10371 10372 10373 10374 10375 10376 10377 10378 10379 10380 10381 10382 10383 10384 10385 10386 10387 10388 10389 10390 10391 10392 10393 10394 10395 10396 10397 10398 10399 10400 10401 10402 10403 10404 10405 10406 10407 10408 10409 10410 10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 10473 10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 10592 10593 10594 10595 10596 10597 10598 10599 10600 10601 10602 10603 10604 10605 10606 10607 10608 10609 10610 10611 10612 10613 10614 10615 10616 10617 10618 10619 10620 10621 10622 10623 10624 10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 10648 10649 10650 10651 10652 10653 10654 10655 10656 10657 10658 10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 10689 10690 10691 10692 10693 10694 10695 10696 10697 10698 10699 10700 10701 10702 10703 10704 10705 10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 10745 10746 10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 10774 10775 10776 10777 10778 10779 10780 10781 10782 10783 10784 10785 10786 10787 10788 10789 10790 10791 10792 10793 10794 10795 10796 10797 10798 10799 10800 10801 10802 10803 10804 10805 10806 10807 10808 10809 10810 10811 10812 10813 10814 10815 10816 10817 10818 10819 10820 10821 10822 10823 10824 10825 10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 10838 10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857 10858 10859 10860 10861 10862 10863 10864 10865 10866 10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 10880 10881 10882 10883 10884 10885 10886 10887 10888 10889 10890 10891 10892 10893 10894 10895 10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 10911 10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 10967 10968 10969 10970 10971 10972 10973 10974 10975 10976 10977 10978 10979 10980 10981 10982 10983 10984 10985 10986 10987 10988 10989 10990 10991 10992 10993 10994 10995 10996 10997 10998 10999 11000 11001 11002 11003 11004 11005 11006 11007 11008 11009 11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 11028 11029 11030 11031 11032 11033 11034 11035 11036 11037 11038 11039 11040 11041 11042 11043 11044 11045 11046 11047 11048 11049 11050 11051 11052 11053 11054 11055 11056 11057 11058 11059 11060 11061 11062 11063 11064 11065 11066 11067 11068 11069 11070 11071 11072 11073 11074 11075 11076 11077 11078 11079 11080 11081 11082 11083 11084 11085 11086 11087 11088 11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 11102 11103 11104 11105 11106 11107 11108 11109 11110 11111 11112 11113 11114 11115 11116 11117 11118 11119 11120 11121 11122 11123 11124 11125 11126 11127 11128 11129 11130 11131 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 11149 11150 11151 11152 11153 11154 11155 11156 11157 11158 11159 11160 11161 11162 11163 11164 11165 11166 11167 11168 11169 11170 11171 11172 11173 11174 11175 11176 11177 11178 11179 11180 11181 11182 11183 11184 11185 11186 11187 11188 11189 11190 11191 11192 11193 11194 11195 11196 11197 11198 11199 11200 11201 11202 11203 11204 11205 11206 11207 11208 11209 11210 11211 11212 11213 11214 11215 11216 11217 11218 11219 11220 11221 11222 11223 11224 11225 11226 11227 11228 11229 11230 11231 11232 11233 11234 11235 11236 11237 11238 11239 11240 11241 11242 11243 11244 11245 11246 11247 11248 11249 11250 11251 11252 11253 11254 11255 11256 11257 11258 11259 11260 11261 11262 11263 11264 11265 11266 11267 11268 11269 11270 11271 11272 11273 11274 11275 11276 11277
|
/* C Compatible Compiler Preprocessor (CCCP)
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000 Free Software Foundation, Inc.
Written by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
Modfied for use as cxref-cpp by Andrew M. Bishop 2004.
Changes marked with 'AMB' in the code.
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; either version 2, or (at your option) any
later version.
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, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "system.h"
#include <signal.h>
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
#endif
typedef unsigned char U_CHAR;
#include "pcp.h"
#include "intl.h"
#include "prefix.h"
#ifdef MULTIBYTE_CHARS
#include "mbchar.h"
#include <locale.h>
#endif /* MULTIBYTE_CHARS */
#ifndef GET_ENV_PATH_LIST
#define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
#endif
#ifndef STANDARD_INCLUDE_DIR
# define STANDARD_INCLUDE_DIR "/usr/include"
#endif
/* By default, colon separates directories in a path. */
#ifndef PATH_SEPARATOR
# define PATH_SEPARATOR ':'
#endif
/* By default, a slash separates directory names. */
#ifndef DIR_SEPARATOR
# define DIR_SEPARATOR '/'
#endif
/* By default, the suffix for object files is ".o". */
#ifdef OBJECT_SUFFIX
# define HAVE_OBJECT_SUFFIX
#else
# define OBJECT_SUFFIX ".o"
#endif
/* VMS-specific definitions */
#ifdef VMS
#include <descrip.h>
#include <ssdef.h>
#include <syidef.h>
#define open(fname,mode,prot) VMS_open (fname,mode,prot)
#define fopen(fname,mode) VMS_fopen (fname,mode)
#define freopen(fname,mode,ofile) VMS_freopen (fname,mode,ofile)
#define fstat(fd,stbuf) VMS_fstat (fd,stbuf)
static int VMS_fstat (), VMS_stat ();
static int VMS_open ();
static FILE *VMS_fopen ();
static FILE *VMS_freopen ();
static int hack_vms_include_specification ();
#define INO_T_EQ(a, b) (!bcmp((char *) &(a), (char *) &(b), sizeof (a)))
#define INO_T_HASH(a) 0
#define INCLUDE_LEN_FUDGE 12 /* leave room for VMS syntax conversion */
#endif /* VMS */
/* Windows does not natively support inodes, and neither does MSDOS. */
#if (defined (_WIN32) && ! defined (__CYGWIN__) && ! defined (_UWIN)) \
|| defined (__MSDOS__)
#define INO_T_EQ(a, b) 0
#endif
#ifndef INO_T_EQ
#define INO_T_EQ(a, b) ((a) == (b))
#endif
#ifndef INO_T_HASH
#define INO_T_HASH(a) (a)
#endif
#ifndef INCLUDE_LEN_FUDGE
#define INCLUDE_LEN_FUDGE 0
#endif
/* External declarations. */
extern char *version_string;
HOST_WIDEST_INT parse_escape PROTO((char **, HOST_WIDEST_INT));
HOST_WIDEST_INT parse_c_expression PROTO((char *, int));
/* Name under which this program was invoked. */
static char *progname;
/* Nonzero means use extra default include directories for C++. */
static int cplusplus;
/* Nonzero means handle cplusplus style comments */
static int cplusplus_comments;
/* Nonzero means handle #import, for objective C. */
static int objc;
/* Nonzero means this is an assembly file, and allow
unknown directives, which could be comments. */
static int lang_asm;
/* Current maximum length of directory names in the search path
for include files. (Altered as we get more of them.) */
static int max_include_len;
/* Nonzero means turn NOTREACHED into #pragma NOTREACHED etc */
static int for_lint = 0;
/* Nonzero means copy comments into the output file. */
static int put_out_comments = 0;
/* Nonzero means don't process the ANSI trigraph sequences. */
static int no_trigraphs = 0;
/* Nonzero means print the names of included files rather than
the preprocessed output. 1 means just the #include "...",
2 means #include <...> as well. */
static int print_deps = 0;
/* Nonzero if missing .h files in -M output are assumed to be generated
files and not errors. */
static int print_deps_missing_files = 0;
/* Nonzero means print names of header files (-H). */
static int print_include_names = 0;
/* Nonzero means don't output line number information. */
static int no_line_directives;
/* Nonzero means output the text in failing conditionals,
inside #failed ... #endfailed. */
static int output_conditionals;
/* dump_only means inhibit output of the preprocessed text
and instead output the definitions of all user-defined
macros in a form suitable for use as input to cccp.
dump_names means pass #define and the macro name through to output.
dump_definitions means pass the whole definition (plus #define) through
*/
static enum {dump_none, dump_only, dump_names, dump_definitions}
dump_macros = dump_none;
/* Nonzero means pass all #define and #undef directives which we actually
process through to the output stream. This feature is used primarily
to allow cc1 to record the #defines and #undefs for the sake of
debuggers which understand about preprocessor macros, but it may
also be useful with -E to figure out how symbols are defined, and
where they are defined. */
static int debug_output = 0;
/* Nonzero means pass #include lines through to the output,
even if they are ifdefed out. */
static int dump_includes;
/* Nonzero indicates special processing used by the pcp program. The
special effects of this mode are:
Inhibit all macro expansion, except those inside #if directives.
Process #define directives normally, and output their contents
to the output file.
Output preconditions to pcp_outfile indicating all the relevant
preconditions for use of this file in a later cpp run.
*/
static FILE *pcp_outfile;
/* Nonzero means we are inside an IF during a -pcp run. In this mode
macro expansion is done, and preconditions are output for all macro
uses requiring them. */
static int pcp_inside_if;
/* Nonzero means never to include precompiled files.
This is 1 since there's no way now to make precompiled files,
so it's not worth testing for them. */
static int no_precomp = 1;
/* Nonzero means give all the error messages the ANSI standard requires. */
int pedantic;
/* Nonzero means try to make failure to fit ANSI C an error. */
static int pedantic_errors;
/* Nonzero means don't print warning messages. -w. */
static int inhibit_warnings = 0;
/* Nonzero means warn if slash-star appears in a slash-star comment,
or if newline-backslash appears in a slash-slash comment. */
static int warn_comments;
/* Nonzero means warn if a macro argument is (or would be)
stringified with -traditional. */
static int warn_stringify;
/* Nonzero means warn if there are any trigraphs. */
static int warn_trigraphs;
/* Nonzero means warn if undefined identifiers are evaluated in an #if. */
static int warn_undef;
/* Nonzero means warn if #import is used. */
static int warn_import = 1;
/* Nonzero means turn warnings into errors. */
static int warnings_are_errors;
/* Nonzero means try to imitate old fashioned non-ANSI preprocessor. */
int traditional;
/* Nonzero for the 1989 C Standard, including corrigenda and amendments. */
int c89;
/* Nonzero for the 199x C Standard. */
int c9x;
/* Nonzero causes output not to be done,
but directives such as #define that have side effects
are still obeyed. */
static int no_output;
/* Nonzero means we should look for header.gcc files that remap file names. */
static int remap;
/* Nonzero means this file was included with a -imacros or -include
command line and should not be recorded as an include file. */
static int no_record_file;
/* Nonzero means that we have finished processing the command line options.
This flag is used to decide whether or not to issue certain errors
and/or warnings. */
static int done_initializing = 0;
/* Line where a newline was first seen in a string constant. */
static int multiline_string_line = 0;
/* I/O buffer structure.
The `fname' field is nonzero for source files and #include files
and for the dummy text used for -D and -U.
It is zero for rescanning results of macro expansion
and for expanding macro arguments. */
#define INPUT_STACK_MAX 400
static struct file_buf {
char *fname;
/* Filename specified with #line directive. */
char *nominal_fname;
/* The length of nominal_fname, which may contain embedded NULs. */
size_t nominal_fname_len;
/* Include file description. */
struct include_file *inc;
/* Record where in the search path this file was found.
For #include_next. */
struct file_name_list *dir;
int lineno;
int length;
U_CHAR *buf;
U_CHAR *bufp;
/* Macro that this level is the expansion of.
Included so that we can reenable the macro
at the end of this level. */
struct hashnode *macro;
/* Value of if_stack at start of this file.
Used to prohibit unmatched #endif (etc) in an include file. */
struct if_stack *if_stack;
/* Object to be freed at end of input at this level. */
U_CHAR *free_ptr;
/* True if this is a system header file; see is_system_include. */
char system_header_p;
} instack[INPUT_STACK_MAX];
static int last_error_tick; /* Incremented each time we print it. */
static int input_file_stack_tick; /* Incremented when the status changes. */
/* Current nesting level of input sources.
`instack[indepth]' is the level currently being read. */
static int indepth = -1;
#define CHECK_DEPTH(code) \
if (indepth >= (INPUT_STACK_MAX - 1)) \
{ \
error_with_line (line_for_error (instack[indepth].lineno), \
"macro or `#include' recursion too deep"); \
code; \
}
/* Current depth in #include directives that use <...>. */
static int system_include_depth = 0;
typedef struct file_buf FILE_BUF;
/* The output buffer. Its LENGTH field is the amount of room allocated
for the buffer, not the number of chars actually present. To get
that, subtract outbuf.buf from outbuf.bufp. */
#define OUTBUF_SIZE 10 /* initial size of output buffer */
static FILE_BUF outbuf;
/* Grow output buffer OBUF points at
so it can hold at least NEEDED more chars. */
#define check_expand(OBUF, NEEDED) \
(((OBUF)->length - ((OBUF)->bufp - (OBUF)->buf) <= (NEEDED)) \
? grow_outbuf ((OBUF), (NEEDED)) : 0)
struct file_name_list
{
struct file_name_list *next;
/* If the following is 1, it is a C-language system include
directory. */
int c_system_include_path;
/* Mapping of file names for this directory. */
struct file_name_map *name_map;
/* Non-zero if name_map is valid. */
int got_name_map;
/* The include directory status. */
struct stat st;
/* The include prefix: "" denotes the working directory,
otherwise fname must end in '/'.
The actual size is dynamically allocated. */
char fname[1];
};
#define GCC_INCLUDE_DIR "." /* Not used - AMB */
#define INCLUDE_DEFAULTS { { 0, 0, 0, 0, 0 } } /* No built-in include dirs - AMB */
/* #include "file" looks in source file dir, then stack. */
/* #include <file> just looks in the stack. */
/* -I directories are added to the end, then the defaults are added. */
/* The */
static struct default_include {
char *fname; /* The name of the directory. */
char *component; /* The component containing the directory */
int cplusplus; /* Only look here if we're compiling C++. */
int cxx_aware; /* Includes in this directory don't need to
be wrapped in extern "C" when compiling
C++. */
int included; /* Set if the directory is acceptable. */
} include_defaults_array[]
#ifdef INCLUDE_DEFAULTS
= INCLUDE_DEFAULTS;
#else
= {
/* Pick up GNU C++ specific include files. */
{ GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, 0 },
#ifdef CROSS_COMPILE
/* This is the dir for fixincludes. Put it just before
the files that we fix. */
{ GCC_INCLUDE_DIR, "GCC", 0, 0, 0 },
/* For cross-compilation, this dir name is generated
automatically in Makefile.in. */
{ CROSS_INCLUDE_DIR, "GCC", 0, 0, 0 },
#ifdef TOOL_INCLUDE_DIR
/* This is another place that the target system's headers might be. */
{ TOOL_INCLUDE_DIR, "BINUTILS", 0, 0, 0 },
#endif
#else /* not CROSS_COMPILE */
#ifdef LOCAL_INCLUDE_DIR
/* This should be /usr/local/include and should come before
the fixincludes-fixed header files. */
{ LOCAL_INCLUDE_DIR, 0, 0, 1, 0 },
#endif
#ifdef TOOL_INCLUDE_DIR
/* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
{ TOOL_INCLUDE_DIR, "BINUTILS", 0, 0, 0 },
#endif
/* This is the dir for fixincludes. Put it just before
the files that we fix. */
{ GCC_INCLUDE_DIR, "GCC", 0, 0, 0 },
/* Some systems have an extra dir of include files. */
#ifdef SYSTEM_INCLUDE_DIR
{ SYSTEM_INCLUDE_DIR, 0, 0, 0, 0 },
#endif
#ifndef STANDARD_INCLUDE_COMPONENT
#define STANDARD_INCLUDE_COMPONENT 0
#endif
{ STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0, 0 },
#endif /* not CROSS_COMPILE */
{ 0, 0, 0, 0, 0 }
};
#endif /* no INCLUDE_DEFAULTS */
/* The code looks at the defaults through this pointer, rather than through
the constant structure above. This pointer gets changed if an environment
variable specifies other defaults. */
static struct default_include *include_defaults = include_defaults_array;
static struct file_name_list *include = 0; /* First dir to search */
/* First dir to search for <file> */
/* This is the first element to use for #include <...>.
If it is 0, use the entire chain for such includes. */
static struct file_name_list *first_bracket_include = 0;
/* This is the first element in the chain that corresponds to
a directory of system header files. */
static struct file_name_list *first_system_include = 0;
static struct file_name_list *last_include = 0; /* Last in chain */
/* Chain of include directories to put at the end of the other chain. */
static struct file_name_list *after_include = 0;
static struct file_name_list *last_after_include = 0; /* Last in chain */
/* Chain to put at the start of the system include files. */
static struct file_name_list *before_system = 0;
static struct file_name_list *last_before_system = 0; /* Last in chain */
/* Directory prefix that should replace `/usr' in the standard
include file directories. */
static char *include_prefix;
/* File to include that contains the gcc definitions for cxref-cpp - AMB */
static char *cxref_cpp_defines=CXREF_CPP_DEFINES;
/* Maintain and search list of included files. */
struct include_file {
struct include_file *next; /* for include_hashtab */
struct include_file *next_ino; /* for include_ino_hashtab */
char *fname;
/* If the following is the empty string, it means #pragma once
was seen in this include file, or #import was applied to the file.
Otherwise, if it is nonzero, it is a macro name.
Don't include the file again if that macro is defined. */
U_CHAR *control_macro;
/* Nonzero if the dependency on this include file has been output. */
int deps_output;
struct stat st;
};
/* Hash tables of files already included with #include or #import.
include_hashtab is by full name; include_ino_hashtab is by inode number. */
#define INCLUDE_HASHSIZE 61
static struct include_file *include_hashtab[INCLUDE_HASHSIZE];
static struct include_file *include_ino_hashtab[INCLUDE_HASHSIZE];
/* Global list of strings read in from precompiled files. This list
is kept in the order the strings are read in, with new strings being
added at the end through stringlist_tailp. We use this list to output
the strings at the end of the run.
*/
static STRINGDEF *stringlist;
static STRINGDEF **stringlist_tailp = &stringlist;
/* Structure returned by create_definition */
typedef struct macrodef MACRODEF;
struct macrodef
{
struct definition *defn;
U_CHAR *symnam;
int symlen;
};
enum sharp_token_type {
NO_SHARP_TOKEN = 0, /* token not present */
SHARP_TOKEN = '#', /* token spelled with # only */
WHITE_SHARP_TOKEN, /* token spelled with # and white space */
PERCENT_COLON_TOKEN = '%', /* token spelled with %: only */
WHITE_PERCENT_COLON_TOKEN /* token spelled with %: and white space */
};
/* Structure allocated for every #define. For a simple replacement
such as
#define foo bar ,
nargs = -1, the `pattern' list is null, and the expansion is just
the replacement text. Nargs = 0 means a functionlike macro with no args,
e.g.,
#define getchar() getc (stdin) .
When there are args, the expansion is the replacement text with the
args squashed out, and the reflist is a list describing how to
build the output from the input: e.g., "3 chars, then the 1st arg,
then 9 chars, then the 3rd arg, then 0 chars, then the 2nd arg".
The chars here come from the expansion. Whatever is left of the
expansion after the last arg-occurrence is copied after that arg.
Note that the reflist can be arbitrarily long---
its length depends on the number of times the arguments appear in
the replacement text, not how many args there are. Example:
#define f(x) x+x+x+x+x+x+x would have replacement text "++++++" and
pattern list
{ (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL }
where (x, y) means (nchars, argno). */
typedef struct definition DEFINITION;
struct definition {
int nargs;
int length; /* length of expansion string */
int predefined; /* True if the macro was builtin or */
/* came from the command line */
U_CHAR *expansion;
int line; /* Line number of definition */
char *file; /* File of definition */
size_t file_len; /* Length of file (which can contain NULs) */
char rest_args; /* Nonzero if last arg. absorbs the rest */
struct reflist {
struct reflist *next;
enum sharp_token_type stringify; /* set if a # operator before arg */
enum sharp_token_type raw_before; /* set if a ## operator before arg */
enum sharp_token_type raw_after; /* set if a ## operator after arg */
char rest_args; /* Nonzero if this arg. absorbs the rest */
int nchars; /* Number of literal chars to copy before
this arg occurrence. */
int argno; /* Number of arg to substitute (origin-0) */
} *pattern;
union {
/* Names of macro args, concatenated in reverse order
with comma-space between them.
The only use of this is that we warn on redefinition
if this differs between the old and new definitions. */
U_CHAR *argnames;
} args;
};
/* different kinds of things that can appear in the value field
of a hash node. Actually, this may be useless now. */
union hashval {
char *cpval;
DEFINITION *defn;
KEYDEF *keydef;
};
/*
* special extension string that can be added to the last macro argument to
* allow it to absorb the "rest" of the arguments when expanded. Ex:
* #define wow(a, b...) process (b, a, b)
* { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
* { wow (one, two); } -> { process (two, one, two); }
* if this "rest_arg" is used with the concat token '##' and if it is not
* supplied then the token attached to with ## will not be outputted. Ex:
* #define wow (a, b...) process (b ## , a, ## b)
* { wow (1, 2); } -> { process (2, 1, 2); }
* { wow (one); } -> { process (one); {
*/
static char rest_extension[] = "...";
#define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
/* This is the implicit parameter name when using variable number of
parameters for macros using the ISO C 9x extension. */
static char va_args_name[] = "__VA_ARGS__";
#define VA_ARGS_NAME_LENGTH (sizeof (va_args_name) - 1)
/* The structure of a node in the hash table. The hash table
has entries for all tokens defined by #define directives (type T_MACRO),
plus some special tokens like __LINE__ (these each have their own
type, and the appropriate code is run when that type of node is seen.
It does not contain control words like "#define", which are recognized
by a separate piece of code. */
/* different flavors of hash nodes --- also used in keyword table */
enum node_type {
T_DEFINE = 1, /* the `#define' keyword */
T_INCLUDE, /* the `#include' keyword */
T_INCLUDE_NEXT, /* the `#include_next' keyword */
T_IMPORT, /* the `#import' keyword */
T_IFDEF, /* the `#ifdef' keyword */
T_IFNDEF, /* the `#ifndef' keyword */
T_IF, /* the `#if' keyword */
T_ELSE, /* `#else' */
T_PRAGMA, /* `#pragma' */
T_ELIF, /* `#elif' */
T_UNDEF, /* `#undef' */
T_LINE, /* `#line' */
T_ERROR, /* `#error' */
T_WARNING, /* `#warning' */
T_ENDIF, /* `#endif' */
T_SCCS, /* `#sccs', used on system V. */
T_IDENT, /* `#ident', used on system V. */
T_ASSERT, /* `#assert', taken from system V. */
T_UNASSERT, /* `#unassert', taken from system V. */
T_SPECLINE, /* special symbol `__LINE__' */
T_DATE, /* `__DATE__' */
T_FILE, /* `__FILE__' */
T_BASE_FILE, /* `__BASE_FILE__' */
T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
T_VERSION, /* `__VERSION__' */
T_SIZE_TYPE, /* `__SIZE_TYPE__' */
T_PTRDIFF_TYPE, /* `__PTRDIFF_TYPE__' */
T_WCHAR_TYPE, /* `__WCHAR_TYPE__' */
T_USER_LABEL_PREFIX_TYPE, /* `__USER_LABEL_PREFIX__' */
T_REGISTER_PREFIX_TYPE, /* `__REGISTER_PREFIX__' */
T_IMMEDIATE_PREFIX_TYPE, /* `__IMMEDIATE_PREFIX__' */
T_TIME, /* `__TIME__' */
T_CONST, /* Constant value, used by `__STDC__' */
T_MACRO, /* macro defined by `#define' */
T_DISABLED, /* macro temporarily turned off for rescan */
T_SPEC_DEFINED, /* special `defined' macro for use in #if statements */
T_PCSTRING, /* precompiled string (hashval is KEYDEF *) */
T_UNUSED /* Used for something not defined. */
};
struct hashnode {
struct hashnode *next; /* double links for easy deletion */
struct hashnode *prev;
struct hashnode **bucket_hdr; /* also, a back pointer to this node's hash
chain is kept, in case the node is the head
of the chain and gets deleted. */
enum node_type type; /* type of special token */
int length; /* length of token, for quick comparison */
U_CHAR *name; /* the actual name */
union hashval value; /* pointer to expansion, or whatever */
};
typedef struct hashnode HASHNODE;
/* Some definitions for the hash table. The hash function MUST be
computed as shown in hashf () below. That is because the rescan
loop computes the hash value `on the fly' for most tokens,
in order to avoid the overhead of a lot of procedure calls to
the hashf () function. Hashf () only exists for the sake of
politeness, for use when speed isn't so important. */
#define HASHSIZE 1403
static HASHNODE *hashtab[HASHSIZE];
#define HASHSTEP(old, c) ((old << 2) + c)
#define MAKE_POS(v) (v & 0x7fffffff) /* make number positive */
/* We let tm.h override the types used here, to handle trivial differences
such as the choice of unsigned int or long unsigned int for size_t.
When machines start needing nontrivial differences in the size type,
it would be best to do something here to figure out automatically
from other information what type to use. */
/* The string value for __SIZE_TYPE__. */
#ifndef SIZE_TYPE
#define SIZE_TYPE "long unsigned int"
#endif
/* The string value for __PTRDIFF_TYPE__. */
#ifndef PTRDIFF_TYPE
#define PTRDIFF_TYPE "long int"
#endif
/* The string value for __WCHAR_TYPE__. */
#ifndef WCHAR_TYPE
#define WCHAR_TYPE "int"
#endif
char * wchar_type = WCHAR_TYPE;
#undef WCHAR_TYPE
/* The string value for __USER_LABEL_PREFIX__ */
#ifndef USER_LABEL_PREFIX
#define USER_LABEL_PREFIX ""
#endif
char * user_label_prefix = USER_LABEL_PREFIX;
#undef USER_LABEL_PREFIX
/* The string value for __REGISTER_PREFIX__ */
#ifndef REGISTER_PREFIX
#define REGISTER_PREFIX ""
#endif
/* The string value for __IMMEDIATE_PREFIX__ */
#ifndef IMMEDIATE_PREFIX
#define IMMEDIATE_PREFIX ""
#endif
/* In the definition of a #assert name, this structure forms
a list of the individual values asserted.
Each value is itself a list of "tokens".
These are strings that are compared by name. */
struct tokenlist_list {
struct tokenlist_list *next;
struct arglist *tokens;
};
struct assertion_hashnode {
struct assertion_hashnode *next; /* double links for easy deletion */
struct assertion_hashnode *prev;
/* also, a back pointer to this node's hash
chain is kept, in case the node is the head
of the chain and gets deleted. */
struct assertion_hashnode **bucket_hdr;
int length; /* length of token, for quick comparison */
U_CHAR *name; /* the actual name */
/* List of token-sequences. */
struct tokenlist_list *value;
};
typedef struct assertion_hashnode ASSERTION_HASHNODE;
/* Some definitions for the hash table. The hash function MUST be
computed as shown in hashf below. That is because the rescan
loop computes the hash value `on the fly' for most tokens,
in order to avoid the overhead of a lot of procedure calls to
the hashf function. hashf only exists for the sake of
politeness, for use when speed isn't so important. */
#define ASSERTION_HASHSIZE 37
static ASSERTION_HASHNODE *assertion_hashtab[ASSERTION_HASHSIZE];
/* Nonzero means inhibit macroexpansion of what seem to be
assertion tests, in rescan. For #if. */
static int assertions_flag;
/* `struct directive' defines one #-directive, including how to handle it. */
#define DO_PROTO PROTO((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *))
struct directive {
int length; /* Length of name */
int (*func) DO_PROTO; /* Function to handle directive */
char *name; /* Name of directive */
enum node_type type; /* Code which describes which directive. */
};
#define IS_INCLUDE_DIRECTIVE_TYPE(t) \
((int) T_INCLUDE <= (int) (t) && (int) (t) <= (int) T_IMPORT)
/* These functions are declared to return int instead of void since they
are going to be placed in the table and some old compilers have trouble with
pointers to functions returning void. */
static int do_assert DO_PROTO;
static int do_define DO_PROTO;
static int do_elif DO_PROTO;
static int do_else DO_PROTO;
static int do_endif DO_PROTO;
static int do_error DO_PROTO;
static int do_ident DO_PROTO;
static int do_if DO_PROTO;
static int do_include DO_PROTO;
static int do_line DO_PROTO;
static int do_pragma DO_PROTO;
#ifdef SCCS_DIRECTIVE
static int do_sccs DO_PROTO;
#endif
static int do_unassert DO_PROTO;
static int do_undef DO_PROTO;
static int do_warning DO_PROTO;
static int do_xifdef DO_PROTO;
/* Here is the actual list of #-directives, most-often-used first. */
static struct directive directive_table[] = {
{ 6, do_define, "define", T_DEFINE},
{ 2, do_if, "if", T_IF},
{ 5, do_xifdef, "ifdef", T_IFDEF},
{ 6, do_xifdef, "ifndef", T_IFNDEF},
{ 5, do_endif, "endif", T_ENDIF},
{ 4, do_else, "else", T_ELSE},
{ 4, do_elif, "elif", T_ELIF},
{ 4, do_line, "line", T_LINE},
{ 7, do_include, "include", T_INCLUDE},
{ 12, do_include, "include_next", T_INCLUDE_NEXT},
{ 6, do_include, "import", T_IMPORT},
{ 5, do_undef, "undef", T_UNDEF},
{ 5, do_error, "error", T_ERROR},
{ 7, do_warning, "warning", T_WARNING},
#ifdef SCCS_DIRECTIVE
{ 4, do_sccs, "sccs", T_SCCS},
#endif
{ 6, do_pragma, "pragma", T_PRAGMA},
{ 5, do_ident, "ident", T_IDENT},
{ 6, do_assert, "assert", T_ASSERT},
{ 8, do_unassert, "unassert", T_UNASSERT},
{ -1, 0, "", T_UNUSED},
};
/* When a directive handler is called,
this points to the # (or the : of the %:) that started the directive. */
U_CHAR *directive_start;
/* table to tell if char can be part of a C identifier. */
U_CHAR is_idchar[256];
/* table to tell if char can be first char of a c identifier. */
U_CHAR is_idstart[256];
/* table to tell if c is horizontal space. */
static U_CHAR is_hor_space[256];
/* table to tell if c is horizontal or vertical space. */
U_CHAR is_space[256];
#define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
#define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
static int errors = 0; /* Error counter for exit code */
/* Name of output file, for error messages. */
static char *out_fname;
/* Nonzero to ignore \ in string constants. Use to treat #line 1 "A:\file.h
as a non-form feed. If you want it to be a form feed, you must use
# 1 "\f". */
static int ignore_escape_flag = 1;
/* Stack of conditionals currently in progress
(including both successful and failing conditionals). */
struct if_stack {
struct if_stack *next; /* for chaining to the next stack frame */
char *fname; /* copied from input when frame is made */
size_t fname_len; /* similarly */
int lineno; /* similarly */
int if_succeeded; /* true if a leg of this if-group
has been passed through rescan */
U_CHAR *control_macro; /* For #ifndef at start of file,
this is the macro name tested. */
enum node_type type; /* type of last directive seen in this group */
};
typedef struct if_stack IF_STACK_FRAME;
static IF_STACK_FRAME *if_stack = NULL;
/* Buffer of -M output. */
static char *deps_buffer;
/* Number of bytes allocated in above. */
static int deps_allocated_size;
/* Number of bytes used. */
static int deps_size;
/* Number of bytes since the last newline. */
static int deps_column;
/* Nonzero means -I- has been seen,
so don't look for #include "foo" the source-file directory. */
static int ignore_srcdir;
static int safe_read PROTO((int, char *, int));
static void safe_write PROTO((int, char *, int));
static void eprint_string PROTO((const char *, size_t));
int main PROTO((int, char **));
static void path_include PROTO((char *));
static U_CHAR *index0 PROTO((U_CHAR *, int, size_t));
static void trigraph_pcp PROTO((FILE_BUF *));
static void newline_fix PROTO((U_CHAR *));
static void name_newline_fix PROTO((U_CHAR *));
static char *get_lintcmd PROTO((U_CHAR *, U_CHAR *, U_CHAR **, int *, int *));
static void rescan PROTO((FILE_BUF *, int));
static FILE_BUF expand_to_temp_buffer PROTO((U_CHAR *, U_CHAR *, int, int));
static int handle_directive PROTO((FILE_BUF *, FILE_BUF *));
static struct tm *timestamp PROTO((void));
static void special_symbol PROTO((HASHNODE *, FILE_BUF *));
static int is_system_include PROTO((char *));
static char *base_name PROTO((char *));
static int absolute_filename PROTO((char *));
static size_t simplify_filename PROTO((char *));
static char *read_filename_string PROTO((int, FILE *));
static struct file_name_map *read_name_map PROTO((char *));
static int open_include_file PROTO((char *, struct file_name_list *, U_CHAR *, struct include_file **));
static char *remap_include_file PROTO((char *, struct file_name_list *));
static int lookup_ino_include PROTO((struct include_file *));
static void finclude PROTO((int, struct include_file *, FILE_BUF *, int, struct file_name_list *));
static void record_control_macro PROTO((struct include_file *, U_CHAR *));
static char *check_precompiled PROTO((int, struct stat *, char *, char **));
static int check_preconditions PROTO((char *));
static void pcfinclude PROTO((U_CHAR *, U_CHAR *, FILE_BUF *));
static void pcstring_used PROTO((HASHNODE *));
static void write_output PROTO((void));
static void pass_thru_directive PROTO((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *));
static MACRODEF create_definition PROTO((U_CHAR *, U_CHAR *, FILE_BUF *));
static int check_macro_name PROTO((U_CHAR *, int));
static int compare_defs PROTO((DEFINITION *, DEFINITION *));
static int comp_def_part PROTO((int, U_CHAR *, int, U_CHAR *, int, int));
static DEFINITION *collect_expansion PROTO((U_CHAR *, U_CHAR *, int, struct arglist *));
int check_assertion PROTO((U_CHAR *, int, int, struct arglist *));
static int compare_token_lists PROTO((struct arglist *, struct arglist *));
static struct arglist *read_token_list PROTO((U_CHAR **, U_CHAR *, int *));
static void free_token_list PROTO((struct arglist *));
static ASSERTION_HASHNODE *assertion_install PROTO((U_CHAR *, int, int));
static ASSERTION_HASHNODE *assertion_lookup PROTO((U_CHAR *, int, int));
static void delete_assertion PROTO((ASSERTION_HASHNODE *));
static void do_once PROTO((void));
static HOST_WIDEST_INT eval_if_expression PROTO((U_CHAR *, int));
static void conditional_skip PROTO((FILE_BUF *, int, enum node_type, U_CHAR *, FILE_BUF *));
static void skip_if_group PROTO((FILE_BUF *, int, FILE_BUF *));
static void validate_else PROTO((U_CHAR *, U_CHAR *));
static U_CHAR *skip_to_end_of_comment PROTO((FILE_BUF *, int *, int));
static U_CHAR *skip_quoted_string PROTO((U_CHAR *, U_CHAR *, int, int *, int *, int *));
static char *quote_string PROTO((char *, char *, size_t));
static U_CHAR *skip_paren_group PROTO((FILE_BUF *));
/* Last arg to output_line_directive. */
enum file_change_code {same_file, enter_file, leave_file};
static void output_line_directive PROTO((FILE_BUF *, FILE_BUF *, int, enum file_change_code));
static void macroexpand PROTO((HASHNODE *, FILE_BUF *));
struct argdata;
static int macarg PROTO((struct argdata *, int));
static U_CHAR *macarg1 PROTO((U_CHAR *, U_CHAR *, struct hashnode *, int *, int *, int *, int));
static int discard_comments PROTO((U_CHAR *, int, int));
static int change_newlines PROTO((U_CHAR *, int));
static char *my_strerror PROTO((int));
static void notice PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1;
static void vnotice PROTO((const char *, va_list));
void error PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1;
void verror PROTO((const char *, va_list));
static void error_from_errno PROTO((char *));
void warning PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1;
static void vwarning PROTO((const char *, va_list));
static void error_with_line PVPROTO((int, const char *, ...)) ATTRIBUTE_PRINTF_2;
static void verror_with_line PROTO((int, const char *, va_list));
static void vwarning_with_line PROTO((int, const char *, va_list));
static void warning_with_line PVPROTO((int, const char *, ...)) ATTRIBUTE_PRINTF_2;
void pedwarn PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1;
void pedwarn_with_line PVPROTO((int, const char *, ...)) ATTRIBUTE_PRINTF_2;
static void pedwarn_with_file_and_line PVPROTO((const char *, size_t, int, const char *, ...)) ATTRIBUTE_PRINTF_4;
static void pedwarn_strange_white_space PROTO((int));
static void print_containing_files PROTO((void));
static int line_for_error PROTO((int));
static int grow_outbuf PROTO((FILE_BUF *, int));
static HASHNODE *install PROTO((U_CHAR *, int, enum node_type, char *, int));
HASHNODE *lookup PROTO((U_CHAR *, int, int));
static void delete_macro PROTO((HASHNODE *));
static int hashf PROTO((U_CHAR *, int, int));
static void dump_single_macro PROTO((HASHNODE *, FILE *));
static void dump_all_macros PROTO((void));
static void dump_defn_1 PROTO((U_CHAR *, int, int, FILE *));
static void dump_arg_n PROTO((DEFINITION *, int, FILE *));
static void initialize_char_syntax PROTO((void));
static void initialize_builtins PROTO((FILE_BUF *, FILE_BUF *));
static void make_definition PROTO((char *));
static void make_undef PROTO((char *, FILE_BUF *));
static void make_assertion PROTO((const char *, const char *));
static struct file_name_list *new_include_prefix PROTO((struct file_name_list *, const char *, const char *, const char *));
static void append_include_chain PROTO((struct file_name_list *, struct file_name_list *));
static int quote_string_for_make PROTO((char *, const char *));
static void deps_output PROTO((const char *, int));
void fatal PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
void fancy_abort PROTO((void)) ATTRIBUTE_NORETURN;
static void perror_with_name PROTO((char *));
static void pfatal_with_name PROTO((char *)) ATTRIBUTE_NORETURN;
static void pipe_closed PROTO((int)) ATTRIBUTE_NORETURN;
static void memory_full PROTO((void)) ATTRIBUTE_NORETURN;
static void print_help PROTO((void));
/* Missing prototypes below break these functions on 64 bit machines
where sizeof(PTR)!=sizeof(default return=int) (amd64,ia64). No gcc
warning as always invoked with a cast. CM 20041101*/
PTR xmalloc PROTO((size_t));
PTR xrealloc PROTO((PTR,size_t));
PTR xcalloc PROTO((size_t,size_t));
char * xstrdup PROTO((const char *));
/* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
retrying if necessary. If MAX_READ_LEN is defined, read at most
that bytes at a time. Return a negative value if an error occurs,
otherwise return the actual number of bytes read,
which may be < LEN if CRs have been skipped, though we try not to do
that. */
static int
safe_read (desc, ptr, len)
int desc;
char *ptr;
int len;
{
int left, rcount, nchars;
char *rptr;
left = len;
while (left > 0) {
rcount = left;
#ifdef MAX_READ_LEN
if (rcount > MAX_READ_LEN)
rcount = MAX_READ_LEN;
#endif
nchars = read (desc, ptr, rcount);
if (nchars < 0)
{
#ifdef EINTR
if (errno == EINTR)
continue;
#endif
return nchars;
}
if (nchars == 0)
break;
/* CRLF pairs, found with Unix when processing DOS files,
throw off backslash-newline removal.
Therefore, CRs are thrown away here. */
left -= nchars;
rptr = ptr;
while(nchars--)
{
if(*rptr == '\r' && *(rptr+1) == '\n')
left++;
else
*ptr++ = *rptr;
rptr++;
}
}
return len - left;
}
/* Write LEN bytes at PTR to descriptor DESC,
retrying if necessary, and treating any real error as fatal.
If MAX_WRITE_LEN is defined, write at most that many bytes at a time. */
static void
safe_write (desc, ptr, len)
int desc;
char *ptr;
int len;
{
int wcount, written;
while (len > 0) {
wcount = len;
#ifdef MAX_WRITE_LEN
if (wcount > MAX_WRITE_LEN)
wcount = MAX_WRITE_LEN;
#endif
written = write (desc, ptr, wcount);
if (written < 0)
{
#ifdef EINTR
if (errno == EINTR)
continue;
#endif
pfatal_with_name (out_fname);
}
ptr += written;
len -= written;
}
}
/* Print a string to stderr, with extra handling in case it contains
embedded NUL characters. Any present are written as is.
Using fwrite for this purpose produces undesireable results on VMS
when stderr happens to be a record oriented file, such as a batch log
file, rather than a stream oriented one. */
static void
eprint_string (string, length)
const char *string;
size_t length;
{
size_t segment_length;
do {
fprintf(stderr, "%s", string);
length -= (segment_length = strlen(string));
if (length > 0)
{
fputc('\0', stderr);
length -= 1;
/* Advance past the portion which has already been printed. */
string += segment_length + 1;
}
} while (length > 0);
}
static void
print_help ()
{
printf ("Usage: %s [switches] input output\n", progname);
printf ("Switches:\n");
printf (" -include <file> Include the contents of <file> before other files\n");
printf (" -imacros <file> Accept definition of marcos in <file>\n");
printf (" -iprefix <path> Specify <path> as a prefix for next two options\n");
printf (" -iwithprefix <dir> Add <dir> to the end of the system include paths\n");
printf (" -iwithprefixbefore <dir> Add <dir> to the end of the main include paths\n");
printf (" -isystem <dir> Add <dir> to the start of the system include paths\n");
printf (" -idirafter <dir> Add <dir> to the end of the system include paths\n");
printf (" -I <dir> Add <dir> to the end of the main include paths\n");
printf (" -nostdinc Do not search the system include directories\n");
printf (" -nostdinc++ Do not search the system include directories for C++\n");
printf (" -o <file> Put output into <file>\n");
printf (" -pedantic Issue all warnings demanded by strict ANSI C\n");
printf (" -traditional Follow K&R pre-processor behaviour\n");
printf (" -trigraphs Support ANSI C trigraphs\n");
printf (" -lang-c Assume that the input sources are in C\n");
printf (" -lang-c89 Assume that the input is C89; depricated\n");
printf (" -lang-c++ Assume that the input sources are in C++\n");
printf (" -lang-objc Assume that the input sources are in ObjectiveC\n");
printf (" -lang-objc++ Assume that the input sources are in ObjectiveC++\n");
printf (" -lang-asm Assume that the input sources are in assembler\n");
printf (" -lang-chill Assume that the input sources are in Chill\n");
printf (" -std=<std name> Specify the conformance standard; one of:\n");
printf (" gnu89, gnu9x, c89, c9x, iso9899:1990,\n");
printf (" iso9899:199409, iso9899:199x\n");
printf (" -+ Allow parsing of C++ style features\n");
printf (" -w Inhibit warning messages\n");
printf (" -Wtrigraphs Warn if trigraphs are encountered\n");
printf (" -Wno-trigraphs Do not warn about trigraphs\n");
printf (" -Wcomment{s} Warn if one comment starts inside another\n");
printf (" -Wno-comment{s} Do not warn about comments\n");
printf (" -Wtraditional Warn if a macro argument is/would be turned into\n");
printf (" a string if -traditional is specified\n");
printf (" -Wno-traditional Do not warn about stringification\n");
printf (" -Wundef Warn if an undefined macro is used by #if\n");
printf (" -Wno-undef Do not warn about testing undefined macros\n");
printf (" -Wimport Warn about the use of the #import directive\n");
printf (" -Wno-import Do not warn about the use of #import\n");
printf (" -Werror Treat all warnings as errors\n");
printf (" -Wno-error Do not treat warnings as errors\n");
printf (" -Wall Enable all preprocessor warnings\n");
printf (" -M Generate make dependencies\n");
printf (" -MM As -M, but ignore system header files\n");
printf (" -MD As -M, but put output in a .d file\n");
printf (" -MMD As -MD, but ignore system header files\n");
printf (" -MG Treat missing header file as generated files\n");
printf (" -g Include #define and #undef directives in the output\n");
printf (" -D<macro> Define a <macro> with string '1' as its value\n");
printf (" -D<macro>=<val> Define a <macro> with <val> as its value\n");
printf (" -A<question> (<answer>) Assert the <answer> to <question>\n");
printf (" -U<macro> Undefine <macro> \n");
printf (" -u or -undef Do not predefine any macros\n");
printf (" -v Display the version number\n");
printf (" -H Print the name of header files as they are used\n");
printf (" -C Do not discard comments\n");
printf (" -dM Display a list of macro definitions active at end\n");
printf (" -dD Preserve macro definitions in output\n");
printf (" -dN As -dD except that only the names are preserved\n");
printf (" -dI Include #include directives in the output\n");
printf (" -ifoutput Describe skipped code blocks in output \n");
printf (" -P Do not generate #line directives\n");
printf (" -$ Do not include '$' in identifiers\n");
printf (" -remap Remap file names when including files.\n");
printf (" -h or --help Display this information\n");
}
int
main (argc, argv)
int argc;
char **argv;
{
struct stat st;
char *in_fname;
char *cp;
int f, i;
FILE_BUF *fp;
char **pend_files;
char **pend_defs;
char **pend_undefs;
char **pend_assertions;
char **pend_includes;
/* Record the option used with each element of pend_assertions.
This is preparation for supporting more than one option for making
an assertion. */
char **pend_assertion_options;
int no_standard_includes = 0;
int no_standard_cplusplus_includes = 0;
int missing_newline = 0;
/* Non-0 means don't output the preprocessed program. */
int inhibit_output = 0;
/* Non-0 means -v, so print the full set of include dirs. */
int verbose = 0;
/* File name which deps are being written to.
This is 0 if deps are being written to stdout. */
char *deps_file = 0;
/* Fopen file mode to open deps_file with. */
char *deps_mode = "a";
/* Stream on which to print the dependency information. */
FILE *deps_stream = 0;
/* Target-name to write with the dependency information. */
char *deps_target = 0;
#if defined (RLIMIT_STACK) && defined (HAVE_GETRLIMIT) && defined (HAVE_SETRLIMIT)
/* Get rid of any avoidable limit on stack size. */
{
struct rlimit rlim;
/* Set the stack limit huge so that alloca (particularly stringtab
in dbxread.c) does not fail. */
getrlimit (RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max;
setrlimit (RLIMIT_STACK, &rlim);
}
#endif
#ifdef SIGPIPE
signal (SIGPIPE, pipe_closed);
#endif
#ifdef HAVE_LC_MESSAGES
setlocale (LC_MESSAGES, "");
#endif
(void) bindtextdomain (PACKAGE, localedir);
(void) textdomain (PACKAGE);
progname = base_name (argv[0]);
#ifdef VMS
{
/* Remove extension from PROGNAME. */
char *p;
char *s = progname = xstrdup (progname);
if ((p = rindex (s, ';')) != 0) *p = '\0'; /* strip version number */
if ((p = rindex (s, '.')) != 0 /* strip type iff ".exe" */
&& (p[1] == 'e' || p[1] == 'E')
&& (p[2] == 'x' || p[2] == 'X')
&& (p[3] == 'e' || p[3] == 'E')
&& !p[4])
*p = '\0';
}
#endif
/* Do not invoke xmalloc before this point, since locale and
progname need to be set first, in case a diagnostic is issued. */
pend_files = (char **) xmalloc (argc * sizeof (char *));
pend_defs = (char **) xmalloc (argc * sizeof (char *));
pend_undefs = (char **) xmalloc (argc * sizeof (char *));
pend_assertions = (char **) xmalloc (argc * sizeof (char *));
pend_includes = (char **) xmalloc (argc * sizeof (char *));
pend_assertion_options = (char **) xmalloc (argc * sizeof (char *));
in_fname = NULL;
out_fname = NULL;
/* Initialize is_idchar. */
initialize_char_syntax ();
no_line_directives = 0;
no_trigraphs = 1;
dump_macros = dump_none;
no_output = 0;
cplusplus = 0;
cplusplus_comments = 1;
bzero ((char *) pend_files, argc * sizeof (char *));
bzero ((char *) pend_defs, argc * sizeof (char *));
bzero ((char *) pend_undefs, argc * sizeof (char *));
bzero ((char *) pend_assertions, argc * sizeof (char *));
bzero ((char *) pend_includes, argc * sizeof (char *));
#ifdef MULTIBYTE_CHARS
/* Change to the native locale for multibyte conversions. */
setlocale (LC_CTYPE, "");
literal_codeset = getenv ("LANG");
#endif
/* Process switches and find input file name. */
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-') {
if (out_fname != NULL)
{
print_help ();
fatal ("Too many arguments");
}
else if (in_fname != NULL)
out_fname = argv[i];
else
in_fname = argv[i];
} else {
switch (argv[i][1]) {
case 'i':
if (!strcmp (argv[i], "-include")) {
int temp = i;
if (i + 1 == argc)
fatal ("Filename missing after `-include' option");
else
simplify_filename (pend_includes[temp] = argv[++i]);
}
if (!strcmp (argv[i], "-imacros")) {
int temp = i;
if (i + 1 == argc)
fatal ("Filename missing after `-imacros' option");
else
simplify_filename (pend_files[temp] = argv[++i]);
}
if (!strcmp (argv[i], "-iprefix")) {
if (i + 1 == argc)
fatal ("Filename missing after `-iprefix' option");
else
include_prefix = argv[++i];
}
if (!strcmp (argv[i], "-ifoutput")) {
output_conditionals = 1;
}
if (!strcmp (argv[i], "-isystem")) {
struct file_name_list *dirtmp;
if (! (dirtmp = new_include_prefix (NULL_PTR, NULL_PTR,
"", argv[++i])))
break;
dirtmp->c_system_include_path = 1;
if (before_system == 0)
before_system = dirtmp;
else
last_before_system->next = dirtmp;
last_before_system = dirtmp; /* Tail follows the last one */
}
/* Add directory to end of path for includes,
with the default prefix at the front of its name. */
if (!strcmp (argv[i], "-iwithprefix")) {
struct file_name_list *dirtmp;
char *prefix;
if (include_prefix != 0)
prefix = include_prefix;
else {
prefix = xstrdup (GCC_INCLUDE_DIR);
/* Remove the `include' from /usr/local/lib/gcc.../include. */
if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
prefix[strlen (prefix) - 7] = 0;
}
if (! (dirtmp = new_include_prefix (NULL_PTR, NULL_PTR,
prefix, argv[++i])))
break;
if (after_include == 0)
after_include = dirtmp;
else
last_after_include->next = dirtmp;
last_after_include = dirtmp; /* Tail follows the last one */
}
/* Add directory to main path for includes,
with the default prefix at the front of its name. */
if (!strcmp (argv[i], "-iwithprefixbefore")) {
struct file_name_list *dirtmp;
char *prefix;
if (include_prefix != 0)
prefix = include_prefix;
else {
prefix = xstrdup (GCC_INCLUDE_DIR);
/* Remove the `include' from /usr/local/lib/gcc.../include. */
if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
prefix[strlen (prefix) - 7] = 0;
}
dirtmp = new_include_prefix (NULL_PTR, NULL_PTR, prefix, argv[++i]);
append_include_chain (dirtmp, dirtmp);
}
/* Add directory to end of path for includes. */
if (!strcmp (argv[i], "-idirafter")) {
struct file_name_list *dirtmp;
if (! (dirtmp = new_include_prefix (NULL_PTR, NULL_PTR,
"", argv[++i])))
break;
if (after_include == 0)
after_include = dirtmp;
else
last_after_include->next = dirtmp;
last_after_include = dirtmp; /* Tail follows the last one */
}
break;
case 'o':
if (out_fname != NULL)
fatal ("Output filename specified twice");
if (i + 1 == argc)
fatal ("Filename missing after -o option");
out_fname = argv[++i];
if (!strcmp (out_fname, "-"))
out_fname = "";
break;
case 'p':
if (!strcmp (argv[i], "-pedantic"))
pedantic = 1;
else if (!strcmp (argv[i], "-pedantic-errors")) {
pedantic = 1;
pedantic_errors = 1;
} else if (!strcmp (argv[i], "-pcp")) {
char *pcp_fname;
if (i + 1 == argc)
fatal ("Filename missing after -pcp option");
pcp_fname = argv[++i];
pcp_outfile
= ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
? fopen (pcp_fname, "w")
: stdout);
if (pcp_outfile == 0)
pfatal_with_name (pcp_fname);
no_precomp = 1;
}
break;
case 't':
if (!strcmp (argv[i], "-traditional")) {
traditional = 1;
cplusplus_comments = 0;
} else if (!strcmp (argv[i], "-trigraphs")) {
no_trigraphs = 0;
}
break;
case 'l':
if (! strcmp (argv[i], "-lang-c"))
cplusplus = 0, cplusplus_comments = 1, c89 = 0, c9x = 1, objc = 0;
else if (! strcmp (argv[i], "-lang-c89"))
cplusplus = 0, cplusplus_comments = 0, c89 = 1, c9x = 0, objc = 0;
else if (! strcmp (argv[i], "-lang-c++"))
cplusplus = 1, cplusplus_comments = 1, c89 = 0, c9x = 0, objc = 0;
else if (! strcmp (argv[i], "-lang-objc"))
cplusplus = 0, cplusplus_comments = 1, c89 = 0, c9x = 0, objc = 1;
else if (! strcmp (argv[i], "-lang-objc++"))
cplusplus = 1, cplusplus_comments = 1, c89 = 0, c9x = 0, objc = 1;
else if (! strcmp (argv[i], "-lang-asm"))
lang_asm = 1;
else if (! strcmp (argv[i], "-lint"))
for_lint = 1;
break;
case '+':
cplusplus = 1, cplusplus_comments = 1;
break;
case 's':
if (!strcmp (argv[i], "-std=iso9899:1990")
|| !strcmp (argv[i], "-std=iso9899:199409")
|| !strcmp (argv[i], "-std=c89")
|| !strcmp (argv[i], "-std=gnu89"))
cplusplus = 0, cplusplus_comments = 0, c89 = 1, c9x = 0, objc = 0;
else if (!strcmp (argv[i], "-std=iso9899:199x")
|| !strcmp (argv[i], "-std=c9x")
|| !strcmp (argv[i], "-std=gnu9x"))
cplusplus = 0, cplusplus_comments = 1, c89 = 0, c9x = 1, objc = 0;
break;
case 'w':
inhibit_warnings = 1;
break;
case 'W':
if (!strcmp (argv[i], "-Wtrigraphs"))
warn_trigraphs = 1;
else if (!strcmp (argv[i], "-Wno-trigraphs"))
warn_trigraphs = 0;
else if (!strcmp (argv[i], "-Wcomment"))
warn_comments = 1;
else if (!strcmp (argv[i], "-Wno-comment"))
warn_comments = 0;
else if (!strcmp (argv[i], "-Wcomments"))
warn_comments = 1;
else if (!strcmp (argv[i], "-Wno-comments"))
warn_comments = 0;
else if (!strcmp (argv[i], "-Wtraditional"))
warn_stringify = 1;
else if (!strcmp (argv[i], "-Wno-traditional"))
warn_stringify = 0;
else if (!strcmp (argv[i], "-Wundef"))
warn_undef = 1;
else if (!strcmp (argv[i], "-Wno-undef"))
warn_undef = 0;
else if (!strcmp (argv[i], "-Wimport"))
warn_import = 1;
else if (!strcmp (argv[i], "-Wno-import"))
warn_import = 0;
else if (!strcmp (argv[i], "-Werror"))
warnings_are_errors = 1;
else if (!strcmp (argv[i], "-Wno-error"))
warnings_are_errors = 0;
else if (!strcmp (argv[i], "-Wall"))
{
warn_trigraphs = 1;
warn_comments = 1;
}
break;
case 'f':
if (!strcmp (argv[i], "-fleading-underscore"))
user_label_prefix = "_";
else if (!strcmp (argv[i], "-fno-leading-underscore"))
user_label_prefix = "";
break;
case 'M':
/* The style of the choices here is a bit mixed.
The chosen scheme is a hybrid of keeping all options in one string
and specifying each option in a separate argument:
-M|-MM|-MD file|-MMD file [-MG]. An alternative is:
-M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
-M[M][G][D file]. This is awkward to handle in specs, and is not
as extensible. */
/* ??? -MG must be specified in addition to one of -M or -MM.
This can be relaxed in the future without breaking anything.
The converse isn't true. */
/* -MG isn't valid with -MD or -MMD. This is checked for later. */
if (!strcmp (argv[i], "-MG"))
{
print_deps_missing_files = 1;
break;
}
if (!strcmp (argv[i], "-M"))
print_deps = 2;
else if (!strcmp (argv[i], "-MM"))
print_deps = 1;
else if (!strcmp (argv[i], "-MD"))
print_deps = 2;
else if (!strcmp (argv[i], "-MMD"))
print_deps = 1;
/* For -MD and -MMD options, write deps on file named by next arg. */
if (!strcmp (argv[i], "-MD")
|| !strcmp (argv[i], "-MMD")) {
if (i + 1 == argc)
fatal ("Filename missing after %s option", argv[i]);
i++;
deps_file = argv[i];
deps_mode = "w";
} else {
/* For -M and -MM, write deps on standard output
and suppress the usual output. */
deps_stream = stdout;
inhibit_output = 1;
}
break;
case 'd':
{
char *p = argv[i] + 2;
char c;
while ((c = *p++)) {
/* Arg to -d specifies what parts of macros to dump */
switch (c) {
case 'M':
dump_macros = dump_only;
no_output = 1;
break;
case 'N':
dump_macros = dump_names;
break;
case 'D':
dump_macros = dump_definitions;
break;
case 'I':
dump_includes = 1;
break;
}
}
}
break;
case 'g':
if (argv[i][2] == '3')
debug_output = 1;
break;
case '-':
if (strcmp (argv[i], "--help") != 0)
return i;
print_help ();
exit (0);
break;
case 'v':
notice ("GNU CPP version %s", version_string);
#ifdef TARGET_VERSION
TARGET_VERSION;
#endif
fprintf (stderr, "\n");
verbose = 1;
break;
case 'H':
print_include_names = 1;
break;
case 'D':
if (argv[i][2] != 0)
pend_defs[i] = argv[i] + 2;
else if (i + 1 == argc)
fatal ("Macro name missing after -D option");
else
i++, pend_defs[i] = argv[i];
break;
case 'A':
{
char *p;
if (argv[i][2] != 0)
p = argv[i] + 2;
else if (i + 1 == argc)
fatal ("Assertion missing after -A option");
else
p = argv[++i];
if (!strcmp (p, "-")) {
/* -A- eliminates all predefined macros and assertions.
Let's include also any that were specified earlier
on the command line. That way we can get rid of any
that were passed automatically in from GCC. */
int j;
for (j = 0; j < i; j++)
pend_defs[j] = pend_assertions[j] = 0;
} else {
pend_assertions[i] = p;
pend_assertion_options[i] = "-A";
}
}
break;
case 'U': /* JF #undef something */
if (argv[i][2] != 0)
pend_undefs[i] = argv[i] + 2;
else if (i + 1 == argc)
fatal ("Macro name missing after -U option");
else
pend_undefs[i] = argv[i+1], i++;
break;
case 'C':
put_out_comments = 1;
break;
case 'E': /* -E comes from cc -E; ignore it. */
break;
case 'P':
no_line_directives = 1;
break;
case '$': /* Don't include $ in identifiers. */
is_idchar['$'] = is_idstart['$'] = 0;
break;
case 'I': /* Add directory to path for includes. */
{
struct file_name_list *dirtmp;
if (! ignore_srcdir && !strcmp (argv[i] + 2, "-")) {
ignore_srcdir = 1;
/* Don't use any preceding -I directories for #include <...>. */
first_bracket_include = 0;
}
else {
dirtmp = new_include_prefix (last_include, NULL_PTR, "",
argv[i][2] ? argv[i] + 2 : argv[++i]);
append_include_chain (dirtmp, dirtmp);
}
}
break;
/* Option for runtime cxref-cpp configuration file - AMB */
case 'c':
if (!strcmp (argv[i], "-cxref-cpp-defines")) {
if (i + 1 == argc)
fatal ("Filename missing after `-cxref-cpp-defines' option");
else
cxref_cpp_defines = argv[i+1], i++;
}
break;
/* Option for runtime cxref-cpp configuration file - AMB */
case 'n':
if (!strcmp (argv[i], "-nostdinc"))
/* -nostdinc causes no default include directories.
You must specify all include-file directories with -I. */
no_standard_includes = 1;
else if (!strcmp (argv[i], "-nostdinc++"))
/* -nostdinc++ causes no default C++-specific include directories. */
no_standard_cplusplus_includes = 1;
else if (!strcmp (argv[i], "-noprecomp"))
no_precomp = 1;
break;
case 'r':
if (!strcmp (argv[i], "-remap"))
remap = 1;
break;
case '\0': /* JF handle '-' as file name meaning stdin or stdout */
if (in_fname == NULL) {
in_fname = "";
break;
} else if (out_fname == NULL) {
out_fname = "";
break;
} /* else fall through into error */
default:
fatal ("Invalid option `%s'", argv[i]);
}
}
}
/* Add dirs from CPATH after dirs from -I. */
/* There seems to be confusion about what CPATH should do,
so for the moment it is not documented. */
/* Some people say that CPATH should replace the standard include dirs,
but that seems pointless: it comes before them, so it overrides them
anyway. */
GET_ENV_PATH_LIST (cp, "CPATH");
if (cp && ! no_standard_includes)
path_include (cp);
/* Initialize output buffer */
outbuf.buf = (U_CHAR *) xmalloc (OUTBUF_SIZE);
outbuf.bufp = outbuf.buf;
outbuf.length = OUTBUF_SIZE;
/* Do partial setup of input buffer for the sake of generating
early #line directives (when -g is in effect). */
fp = &instack[++indepth];
if (in_fname == NULL)
in_fname = "";
fp->nominal_fname = fp->fname = in_fname;
fp->nominal_fname_len = strlen (in_fname);
fp->lineno = 0;
/* In C++, wchar_t is a distinct basic type, and we can expect
__wchar_t to be defined by cc1plus. */
if (cplusplus)
wchar_type = "__wchar_t";
/* Install __LINE__, etc. Must follow initialize_char_syntax
and option processing. */
initialize_builtins (fp, &outbuf);
/* Start of setup for the cxref paths and definitions from runtime config - AMB */
{
int fd;
struct stat sbuf;
char *buf,*p;
struct include_file *inc;
if(stat(cxref_cpp_defines,&sbuf)<0)
{perror_with_name(cxref_cpp_defines); exit(FATAL_EXIT_CODE);}
if(!S_ISREG(sbuf.st_mode))
{perror_with_name(cxref_cpp_defines); exit(FATAL_EXIT_CODE);}
fd=open_include_file(cxref_cpp_defines, NULL_PTR, NULL_PTR, &inc);
if(fd==-1)
{perror_with_name(cxref_cpp_defines); exit(FATAL_EXIT_CODE);}
buf=(char *)xmalloc(sbuf.st_size+2); /* AMB - remove gcc-4.0 warning */
if(safe_read(fd,buf,sbuf.st_size)<0)
{perror_with_name(cxref_cpp_defines); exit(FATAL_EXIT_CODE);}
p=buf;
while(!strncmp(p,"//",2))
{
char *oldp=p;
while(*p && (*p!='\r' && *p!='\n')) p++;
while(*p && (*p=='\r' || *p=='\n')) *p++=0;
if(!strncmp(oldp,"// -",4) && *(oldp+=4))
switch(*oldp)
{
case 'A':
make_assertion("-A",oldp+1);
break;
case 'D':
make_definition(oldp+1);
break;
case 'I': /* treat like -isystem */
{
struct file_name_list *dirtmp;
dirtmp = new_include_prefix(NULL_PTR,NULL_PTR,"",oldp+1);
if(!dirtmp)
fatal ("File %s specifies invalid -I path",cxref_cpp_defines);
dirtmp->c_system_include_path = 1;
if (before_system == 0)
before_system = dirtmp;
else
last_before_system->next = dirtmp;
last_before_system = dirtmp; /* Tail follows the last one */
}
break;
default:
;
}
}
free(buf);
lseek(fd,0,SEEK_SET);
no_output++; no_record_file++;
finclude(fd,inc,&outbuf,0,NULL_PTR);
no_output--; no_record_file--;
}
/* End of setup for the cxref paths and definitions from runtime config - AMB */
/* Now handle the command line options. */
/* Do -U's, -D's and -A's in the order they were seen. */
for (i = 1; i < argc; i++) {
if (pend_undefs[i]) {
if (debug_output)
output_line_directive (fp, &outbuf, 0, same_file);
make_undef (pend_undefs[i], &outbuf);
}
if (pend_defs[i]) {
if (debug_output)
output_line_directive (fp, &outbuf, 0, same_file);
make_definition (pend_defs[i]);
}
if (pend_assertions[i])
make_assertion (pend_assertion_options[i], pend_assertions[i]);
}
done_initializing = 1;
{ /* Read the appropriate environment variable and if it exists
replace include_defaults with the listed path. */
char *epath = 0;
switch ((objc << 1) + cplusplus)
{
case 0:
GET_ENV_PATH_LIST (epath, "C_INCLUDE_PATH");
break;
case 1:
GET_ENV_PATH_LIST (epath, "CPLUS_INCLUDE_PATH");
break;
case 2:
GET_ENV_PATH_LIST (epath, "OBJC_INCLUDE_PATH");
break;
case 3:
GET_ENV_PATH_LIST (epath, "OBJCPLUS_INCLUDE_PATH");
break;
}
/* If the environment var for this language is set,
add to the default list of include directories. */
if (epath) {
int num_dirs;
char *startp, *endp;
for (num_dirs = 1, startp = epath; *startp; startp++)
if (*startp == PATH_SEPARATOR)
num_dirs++;
include_defaults
= (struct default_include *) xmalloc ((num_dirs
* sizeof (struct default_include))
+ sizeof (include_defaults_array));
startp = endp = epath;
num_dirs = 0;
while (1) {
char c = *endp++;
if (c == PATH_SEPARATOR || !c) {
endp[-1] = 0;
include_defaults[num_dirs].fname
= startp == endp ? "." : xstrdup (startp);
endp[-1] = c;
include_defaults[num_dirs].component = 0;
include_defaults[num_dirs].cplusplus = cplusplus;
include_defaults[num_dirs].cxx_aware = 1;
num_dirs++;
if (!c)
break;
startp = endp;
}
}
/* Put the usual defaults back in at the end. */
bcopy ((char *) include_defaults_array,
(char *) &include_defaults[num_dirs],
sizeof (include_defaults_array));
}
}
append_include_chain (before_system, last_before_system);
first_system_include = before_system;
/* Unless -fnostdinc,
tack on the standard include file dirs to the specified list */
if (!no_standard_includes) {
struct default_include *p = include_defaults;
char *specd_prefix = include_prefix;
char *default_prefix = xstrdup (GCC_INCLUDE_DIR);
int default_len = 0;
/* Remove the `include' from /usr/local/lib/gcc.../include. */
if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
default_len = strlen (default_prefix) - 7;
default_prefix[default_len] = 0;
}
/* Search "translated" versions of GNU directories.
These have /usr/local/lib/gcc... replaced by specd_prefix. */
if (specd_prefix != 0 && default_len != 0)
for (p = include_defaults; p->fname; p++) {
/* Some standard dirs are only for C++. */
if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) {
/* Does this dir start with the prefix? */
if (!strncmp (p->fname, default_prefix, default_len)) {
/* Yes; change prefix and add to search list. */
struct file_name_list *new
= new_include_prefix (NULL_PTR, NULL_PTR, specd_prefix,
p->fname + default_len);
if (new) {
new->c_system_include_path = !p->cxx_aware;
append_include_chain (new, new);
if (first_system_include == 0)
first_system_include = new;
p->included = 1;
}
}
}
}
/* Search ordinary names for GNU include directories. */
for (p = include_defaults; p->fname; p++) {
/* Some standard dirs are only for C++. */
if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) {
struct file_name_list *new
= new_include_prefix (NULL_PTR, p->component, "", p->fname);
if (new) {
new->c_system_include_path = !p->cxx_aware;
append_include_chain (new, new);
if (first_system_include == 0)
first_system_include = new;
p->included = 1;
}
}
}
}
/* Tack the after_include chain at the end of the include chain. */
append_include_chain (after_include, last_after_include);
if (first_system_include == 0)
first_system_include = after_include;
/* With -v, print the list of dirs to search. */
if (verbose) {
struct file_name_list *p;
notice ("#include \"...\" search starts here:\n");
for (p = include; p; p = p->next) {
if (p == first_bracket_include)
notice ("#include <...> search starts here:\n");
if (!p->fname[0])
fprintf (stderr, " .\n");
else if (!strcmp (p->fname, "/") || !strcmp (p->fname, "//"))
fprintf (stderr, " %s\n", p->fname);
else
/* Omit trailing '/'. */
fprintf (stderr, " %.*s\n", (int) strlen (p->fname) - 1, p->fname);
}
notice ("End of search list.\n");
{
struct default_include * d;
notice ("The following default directories have been omitted from the search path:\n");
for (d = include_defaults; d->fname; d++)
if (! d->included)
fprintf (stderr, " %s\n", d->fname);
notice ("End of omitted list.\n");
}
}
/* -MG doesn't select the form of output and must be specified with one of
-M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
inhibit compilation. */
if (print_deps_missing_files && (print_deps == 0 || !inhibit_output))
fatal ("-MG must be specified with one of -M or -MM");
/* Either of two environment variables can specify output of deps.
Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
where OUTPUT_FILE is the file to write deps info to
and DEPS_TARGET is the target to mention in the deps. */
if (print_deps == 0
&& (getenv ("SUNPRO_DEPENDENCIES") != 0
|| getenv ("DEPENDENCIES_OUTPUT") != 0)) {
char *spec = getenv ("DEPENDENCIES_OUTPUT");
char *s;
char *output_file;
if (spec == 0) {
spec = getenv ("SUNPRO_DEPENDENCIES");
print_deps = 2;
}
else
print_deps = 1;
s = spec;
/* Find the space before the DEPS_TARGET, if there is one. */
/* This should use index. (mrs) */
while (*s != 0 && *s != ' ') s++;
if (*s != 0) {
deps_target = s + 1;
output_file = xmalloc (s - spec + 1);
bcopy (spec, output_file, s - spec);
output_file[s - spec] = 0;
}
else {
deps_target = 0;
output_file = spec;
}
deps_file = output_file;
deps_mode = "a";
}
/* For -M, print the expected object file name
as the target of this Make-rule. */
if (print_deps) {
deps_allocated_size = 200;
deps_buffer = xmalloc (deps_allocated_size);
deps_buffer[0] = 0;
deps_size = 0;
deps_column = 0;
if (deps_target) {
deps_output (deps_target, ':');
} else if (*in_fname == 0) {
deps_output ("-", ':');
} else {
char *p, *q;
int len;
q = base_name (in_fname);
/* Copy remainder to mungable area. */
p = (char *) alloca (strlen(q) + 8);
strcpy (p, q);
/* Output P, but remove known suffixes. */
len = strlen (p);
q = p + len;
if (len >= 2
&& p[len - 2] == '.'
&& index("cCsSm", p[len - 1]))
q = p + (len - 2);
else if (len >= 3
&& p[len - 3] == '.'
&& p[len - 2] == 'c'
&& p[len - 1] == 'c')
q = p + (len - 3);
else if (len >= 4
&& p[len - 4] == '.'
&& p[len - 3] == 'c'
&& p[len - 2] == 'x'
&& p[len - 1] == 'x')
q = p + (len - 4);
else if (len >= 4
&& p[len - 4] == '.'
&& p[len - 3] == 'c'
&& p[len - 2] == 'p'
&& p[len - 1] == 'p')
q = p + (len - 4);
/* Supply our own suffix. */
strcpy (q, OBJECT_SUFFIX);
deps_output (p, ':');
deps_output (in_fname, ' ');
}
}
/* Scan the -imacros files before the main input.
Much like #including them, but with no_output set
so that only their macro definitions matter. */
no_output++; no_record_file++;
for (i = 1; i < argc; i++)
if (pend_files[i]) {
struct include_file *inc;
int fd = open_include_file (pend_files[i], NULL_PTR, NULL_PTR, &inc);
if (fd < 0) {
perror_with_name (pend_files[i]);
return FATAL_EXIT_CODE;
}
finclude (fd, inc, &outbuf, 0, NULL_PTR);
}
no_output--; no_record_file--;
/* Copy the entire contents of the main input file into
the stacked input buffer previously allocated for it. */
/* JF check for stdin */
if (in_fname == NULL || *in_fname == 0) {
in_fname = "";
f = 0;
} else if ((f = open (in_fname, O_RDONLY, 0666)) < 0)
goto perror;
if (fstat (f, &st) != 0)
pfatal_with_name (in_fname);
fp->nominal_fname = fp->fname = in_fname;
fp->nominal_fname_len = strlen (in_fname);
fp->lineno = 1;
fp->system_header_p = 0;
/* JF all this is mine about reading pipes and ttys */
if (! S_ISREG (st.st_mode)) {
/* Read input from a file that is not a normal disk file.
We cannot preallocate a buffer with the correct size,
so we must read in the file a piece at the time and make it bigger. */
int size;
int bsize;
int cnt;
if (S_ISDIR (st.st_mode))
fatal ("Input file `%s' is a directory", in_fname);
bsize = 2000;
size = 0;
fp->buf = (U_CHAR *) xmalloc (bsize + 2);
for (;;) {
cnt = safe_read (f, (char *) fp->buf + size, bsize - size);
if (cnt < 0) goto perror; /* error! */
if (cnt == 0) break; /* End of file */
size += cnt;
bsize *= 2;
fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
}
fp->length = size;
} else {
/* Read a file whose size we can determine in advance.
For the sake of VMS, st.st_size is just an upper bound. */
size_t s = (size_t) st.st_size;
if (s != st.st_size || s + 2 < s)
memory_full ();
fp->buf = (U_CHAR *) xmalloc (s + 2);
fp->length = safe_read (f, (char *) fp->buf, s);
if (fp->length < 0) goto perror;
}
fp->bufp = fp->buf;
fp->if_stack = if_stack;
/* Make sure data ends with a newline. And put a null after it. */
if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n')
/* Backslash-newline at end is not good enough. */
|| (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) {
fp->buf[fp->length++] = '\n';
missing_newline = 1;
}
fp->buf[fp->length] = '\0';
/* Unless inhibited, convert trigraphs in the input. */
if (!no_trigraphs)
trigraph_pcp (fp);
/* Now that we know the input file is valid, open the output. */
if (!out_fname || !strcmp (out_fname, ""))
out_fname = "stdout";
else if (! freopen (out_fname, "w", stdout))
pfatal_with_name (out_fname);
output_line_directive (fp, &outbuf, 0, same_file);
/* Scan the -include files before the main input. */
no_record_file++;
for (i = 1; i < argc; i++)
if (pend_includes[i]) {
struct include_file *inc;
int fd = open_include_file (pend_includes[i], NULL_PTR, NULL_PTR, &inc);
if (fd < 0) {
perror_with_name (pend_includes[i]);
return FATAL_EXIT_CODE;
}
finclude (fd, inc, &outbuf, 0, NULL_PTR);
}
no_record_file--;
/* Scan the input, processing macros and directives. */
rescan (&outbuf, 0);
if (missing_newline)
fp->lineno--;
if (pedantic && missing_newline)
pedwarn ("file does not end in newline");
/* Now we have processed the entire input
Write whichever kind of output has been requested. */
if (dump_macros == dump_only)
dump_all_macros ();
else if (! inhibit_output) {
write_output ();
}
if (print_deps) {
/* Don't actually write the deps file if compilation has failed. */
if (errors == 0) {
if (deps_file && ! (deps_stream = fopen (deps_file, deps_mode)))
pfatal_with_name (deps_file);
fputs (deps_buffer, deps_stream);
putc ('\n', deps_stream);
if (deps_file) {
if (ferror (deps_stream) || fclose (deps_stream) != 0)
fatal ("I/O error on output");
}
}
}
if (pcp_outfile && pcp_outfile != stdout
&& (ferror (pcp_outfile) || fclose (pcp_outfile) != 0))
fatal ("I/O error on `-pcp' output");
if (ferror (stdout) || fclose (stdout) != 0)
fatal ("I/O error on output");
if (errors)
exit (FATAL_EXIT_CODE);
exit (SUCCESS_EXIT_CODE);
perror:
pfatal_with_name (in_fname);
return 0;
}
/* Given a colon-separated list of file names PATH,
add all the names to the search path for include files. */
static void
path_include (path)
char *path;
{
char *p;
p = path;
if (*p)
while (1) {
char *q = p;
char c;
struct file_name_list *dirtmp;
/* Find the end of this name. */
while ((c = *q++) != PATH_SEPARATOR && c)
continue;
q[-1] = 0;
dirtmp = new_include_prefix (last_include, NULL_PTR,
"", p == q ? "." : p);
q[-1] = c;
append_include_chain (dirtmp, dirtmp);
/* Advance past this name. */
p = q;
if (! c)
break;
}
}
/* Return the address of the first character in S that equals C.
S is an array of length N, possibly containing '\0's, and followed by '\0'.
Return 0 if there is no such character. Assume that C itself is not '\0'.
If we knew we could use memchr, we could just invoke memchr (S, C, N),
but unfortunately memchr isn't autoconfigured yet. */
static U_CHAR *
index0 (s, c, n)
U_CHAR *s;
int c;
size_t n;
{
char *p = (char *) s;
for (;;) {
char *q = index (p, c);
if (q)
return (U_CHAR *) q;
else {
size_t l = strlen (p);
if (l == n)
return 0;
l++;
p += l;
n -= l;
}
}
}
/* Pre-C-Preprocessor to translate ANSI trigraph idiocy in BUF
before main CCCP processing. Name `pcp' is also in honor of the
drugs the trigraph designers must have been on.
Using an extra pass through the buffer takes a little extra time,
but is infinitely less hairy than trying to handle trigraphs inside
strings, etc. everywhere, and also makes sure that trigraphs are
only translated in the top level of processing. */
static void
trigraph_pcp (buf)
FILE_BUF *buf;
{
register U_CHAR c, *fptr, *bptr, *sptr, *lptr;
int len;
fptr = bptr = sptr = buf->buf;
lptr = fptr + buf->length;
while ((sptr = index0 (sptr, '?', (size_t) (lptr - sptr))) != NULL) {
if (*++sptr != '?')
continue;
switch (*++sptr) {
case '=':
c = '#';
break;
case '(':
c = '[';
break;
case '/':
c = '\\';
break;
case ')':
c = ']';
break;
case '\'':
c = '^';
break;
case '<':
c = '{';
break;
case '!':
c = '|';
break;
case '>':
c = '}';
break;
case '-':
c = '~';
break;
case '?':
sptr--;
continue;
default:
continue;
}
len = sptr - fptr - 2;
/* BSD doc says bcopy () works right for overlapping strings. In ANSI
C, this will be memmove (). */
if (bptr != fptr && len > 0)
bcopy ((char *) fptr, (char *) bptr, len);
bptr += len;
*bptr++ = c;
fptr = ++sptr;
}
len = buf->length - (fptr - buf->buf);
if (bptr != fptr && len > 0)
bcopy ((char *) fptr, (char *) bptr, len);
buf->length -= fptr - bptr;
buf->buf[buf->length] = '\0';
if (warn_trigraphs && fptr != bptr)
warning_with_line (0, "%lu trigraph(s) encountered",
(unsigned long) (fptr - bptr) / 2);
}
/* Move all backslash-newline pairs out of embarrassing places.
Exchange all such pairs following BP
with any potentially-embarrassing characters that follow them.
Potentially-embarrassing characters are / and *
(because a backslash-newline inside a comment delimiter
would cause it not to be recognized). */
static void
newline_fix (bp)
U_CHAR *bp;
{
register U_CHAR *p = bp;
/* First count the backslash-newline pairs here. */
while (p[0] == '\\' && p[1] == '\n')
p += 2;
/* What follows the backslash-newlines is not embarrassing. */
if (*p != '/' && *p != '*')
return;
/* Copy all potentially embarrassing characters
that follow the backslash-newline pairs
down to where the pairs originally started. */
while (*p == '*' || *p == '/')
*bp++ = *p++;
/* Now write the same number of pairs after the embarrassing chars. */
while (bp < p) {
*bp++ = '\\';
*bp++ = '\n';
}
}
/* Like newline_fix but for use within a directive-name.
Move any backslash-newlines up past any following symbol constituents. */
static void
name_newline_fix (bp)
U_CHAR *bp;
{
register U_CHAR *p = bp;
/* First count the backslash-newline pairs here. */
while (p[0] == '\\' && p[1] == '\n')
p += 2;
/* What follows the backslash-newlines is not embarrassing. */
if (!is_idchar[*p])
return;
/* Copy all potentially embarrassing characters
that follow the backslash-newline pairs
down to where the pairs originally started. */
while (is_idchar[*p])
*bp++ = *p++;
/* Now write the same number of pairs after the embarrassing chars. */
while (bp < p) {
*bp++ = '\\';
*bp++ = '\n';
}
}
/* Look for lint commands in comments.
When we come in here, ibp points into a comment. Limit is as one expects.
scan within the comment -- it should start, after lwsp, with a lint command.
If so that command is returned as a (constant) string.
Upon return, any arg will be pointed to with argstart and will be
arglen long. Note that we don't parse that arg since it will just
be printed out again. */
static char *
get_lintcmd (ibp, limit, argstart, arglen, cmdlen)
register U_CHAR *ibp;
register U_CHAR *limit;
U_CHAR **argstart; /* point to command arg */
int *arglen, *cmdlen; /* how long they are */
{
HOST_WIDEST_INT linsize;
register U_CHAR *numptr; /* temp for arg parsing */
*arglen = 0;
*argstart=NULL; /* AMB - remove gcc-4.0 warning */
SKIP_WHITE_SPACE (ibp);
if (ibp >= limit) return NULL;
linsize = limit - ibp;
/* Oh, I wish C had lexical functions... hell, I'll just open-code the set */
if ((linsize >= 10) && !bcmp (ibp, "NOTREACHED", 10)) {
*cmdlen = 10;
return "NOTREACHED";
}
if ((linsize >= 8) && !bcmp (ibp, "ARGSUSED", 8)) {
*cmdlen = 8;
return "ARGSUSED";
}
if ((linsize >= 11) && !bcmp (ibp, "LINTLIBRARY", 11)) {
*cmdlen = 11;
return "LINTLIBRARY";
}
if ((linsize >= 7) && !bcmp (ibp, "VARARGS", 7)) {
*cmdlen = 7;
ibp += 7; linsize -= 7;
if ((linsize == 0) || ! ISDIGIT (*ibp)) return "VARARGS";
/* OK, read a number */
for (numptr = *argstart = ibp; (numptr < limit) && ISDIGIT (*numptr);
numptr++);
*arglen = numptr - *argstart;
return "VARARGS";
}
return NULL;
}
/*
* The main loop of the program.
*
* Read characters from the input stack, transferring them to the
* output buffer OP.
*
* Macros are expanded and push levels on the input stack.
* At the end of such a level it is popped off and we keep reading.
* At the end of any other kind of level, we return.
* #-directives are handled, except within macros.
*
* If OUTPUT_MARKS is nonzero, keep Newline markers found in the input
* and insert them when appropriate. This is set while scanning macro
* arguments before substitution. It is zero when scanning for final output.
* There are three types of Newline markers:
* * Newline - follows a macro name that was not expanded
* because it appeared inside an expansion of the same macro.
* This marker prevents future expansion of that identifier.
* When the input is rescanned into the final output, these are deleted.
* These are also deleted by ## concatenation.
* * Newline Space (or Newline and any other whitespace character)
* stands for a place that tokens must be separated or whitespace
* is otherwise desirable, but where the ANSI standard specifies there
* is no whitespace. This marker turns into a Space (or whichever other
* whitespace char appears in the marker) in the final output,
* but it turns into nothing in an argument that is stringified with #.
* Such stringified arguments are the only place where the ANSI standard
* specifies with precision that whitespace may not appear.
*
* During this function, IP->bufp is kept cached in IBP for speed of access.
* Likewise, OP->bufp is kept in OBP. Before calling a subroutine
* IBP, IP and OBP must be copied back to memory. IP and IBP are
* copied back with the RECACHE macro. OBP must be copied back from OP->bufp
* explicitly, and before RECACHE, since RECACHE uses OBP.
*/
static void
rescan (op, output_marks)
FILE_BUF *op;
int output_marks;
{
/* Character being scanned in main loop. */
register U_CHAR c;
/* Length of pending accumulated identifier. */
register int ident_length = 0;
/* Hash code of pending accumulated identifier. */
register int hash = 0;
/* Current input level (&instack[indepth]). */
FILE_BUF *ip;
/* Pointer for scanning input. */
register U_CHAR *ibp;
/* Pointer to end of input. End of scan is controlled by LIMIT. */
register U_CHAR *limit;
/* Pointer for storing output. */
register U_CHAR *obp;
/* REDO_CHAR is nonzero if we are processing an identifier
after backing up over the terminating character.
Sometimes we process an identifier without backing up over
the terminating character, if the terminating character
is not special. Backing up is done so that the terminating character
will be dispatched on again once the identifier is dealt with. */
int redo_char = 0;
/* 1 if within an identifier inside of which a concatenation
marker (Newline -) has been seen. */
int concatenated = 0;
/* While scanning a comment or a string constant,
this records the line it started on, for error messages. */
int start_line;
/* Record position of last `real' newline. */
U_CHAR *beg_of_line;
/* Pop the innermost input stack level, assuming it is a macro expansion. */
#define POPMACRO \
do { ip->macro->type = T_MACRO; \
if (ip->free_ptr) free (ip->free_ptr); \
--indepth; } while (0)
/* Reload `rescan's local variables that describe the current
level of the input stack. */
#define RECACHE \
do { ip = &instack[indepth]; \
ibp = ip->bufp; \
limit = ip->buf + ip->length; \
op->bufp = obp; \
check_expand (op, limit - ibp); \
beg_of_line = 0; \
obp = op->bufp; } while (0)
if (no_output && instack[indepth].fname != 0)
skip_if_group (&instack[indepth], 1, NULL);
obp = op->bufp;
RECACHE;
beg_of_line = ibp;
/* Our caller must always put a null after the end of
the input at each input stack level. */
if (*limit != 0)
abort ();
while (1) {
c = *ibp++;
*obp++ = c;
switch (c) {
case '\\':
if (*ibp == '\n' && !ip->macro) {
/* At the top level, always merge lines ending with backslash-newline,
even in middle of identifier. But do not merge lines in a macro,
since backslash might be followed by a newline-space marker. */
++ibp;
++ip->lineno;
--obp; /* remove backslash from obuf */
break;
}
/* If ANSI, backslash is just another character outside a string. */
if (!traditional)
goto randomchar;
/* Otherwise, backslash suppresses specialness of following char,
so copy it here to prevent the switch from seeing it.
But first get any pending identifier processed. */
if (ident_length > 0)
goto specialchar;
if (ibp < limit)
*obp++ = *ibp++;
break;
case '%':
if (ident_length || ip->macro || traditional)
goto randomchar;
while (*ibp == '\\' && ibp[1] == '\n') {
ibp += 2;
++ip->lineno;
}
if (*ibp != ':')
break;
/* Treat this %: digraph as if it were #. */
/* Fall through. */
case '#':
if (assertions_flag) {
if (ident_length)
goto specialchar;
/* Copy #foo (bar lose) without macro expansion. */
obp[-1] = '#'; /* In case it was '%'. */
SKIP_WHITE_SPACE (ibp);
while (is_idchar[*ibp])
*obp++ = *ibp++;
SKIP_WHITE_SPACE (ibp);
if (*ibp == '(') {
ip->bufp = ibp;
skip_paren_group (ip);
bcopy ((char *) ibp, (char *) obp, ip->bufp - ibp);
obp += ip->bufp - ibp;
ibp = ip->bufp;
}
break;
}
/* If this is expanding a macro definition, don't recognize
preprocessing directives. */
if (ip->macro != 0)
goto randomchar;
/* If this is expand_into_temp_buffer,
don't recognize them either. Warn about them
only after an actual newline at this level,
not at the beginning of the input level. */
if (! ip->fname) {
if (ip->buf != beg_of_line)
warning ("preprocessing directive not recognized within macro arg");
goto randomchar;
}
if (ident_length)
goto specialchar;
/* # keyword: a # must be first nonblank char on the line */
if (beg_of_line == 0)
goto randomchar;
{
U_CHAR *bp;
/* Scan from start of line, skipping whitespace, comments
and backslash-newlines, and see if we reach this #.
If not, this # is not special. */
bp = beg_of_line;
/* If -traditional, require # to be at beginning of line. */
if (!traditional) {
while (1) {
if (is_hor_space[*bp])
bp++;
else if (*bp == '\\' && bp[1] == '\n')
bp += 2;
else if (*bp == '/' && bp[1] == '*') {
bp += 2;
while (1)
{
if (*bp == '*')
{
if (bp[1] == '/')
{
bp += 2;
break;
}
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (bp, limit - bp);
if (length > 1)
bp += (length - 1);
#endif
}
bp++;
}
}
/* There is no point in trying to deal with C++ // comments here,
because if there is one, then this # must be part of the
comment and we would never reach here. */
else break;
}
if (c == '%') {
if (bp[0] != '%')
break;
while (bp[1] == '\\' && bp[2] == '\n')
bp += 2;
if (bp + 1 != ibp)
break;
/* %: appears at start of line; skip past the ':' too. */
bp++;
ibp++;
}
}
if (bp + 1 != ibp)
goto randomchar;
}
/* This # can start a directive. */
--obp; /* Don't copy the '#' */
ip->bufp = ibp;
op->bufp = obp;
if (! handle_directive (ip, op)) {
#ifdef USE_C_ALLOCA
alloca (0);
#endif
/* Not a known directive: treat it as ordinary text.
IP, OP, IBP, etc. have not been changed. */
if (no_output && instack[indepth].fname) {
/* If not generating expanded output,
what we do with ordinary text is skip it.
Discard everything until next # directive. */
skip_if_group (&instack[indepth], 1, 0);
RECACHE;
beg_of_line = ibp;
break;
}
*obp++ = '#'; /* Copy # (even if it was originally %:). */
/* Don't expand an identifier that could be a macro directive.
(Section 3.8.3 of the ANSI C standard) */
SKIP_WHITE_SPACE (ibp);
if (is_idstart[*ibp])
{
*obp++ = *ibp++;
while (is_idchar[*ibp])
*obp++ = *ibp++;
}
goto randomchar;
}
#ifdef USE_C_ALLOCA
alloca (0);
#endif
/* A # directive has been successfully processed. */
/* If not generating expanded output, ignore everything until
next # directive. */
if (no_output && instack[indepth].fname)
skip_if_group (&instack[indepth], 1, 0);
obp = op->bufp;
RECACHE;
beg_of_line = ibp;
break;
case '\"': /* skip quoted string */
case '\'':
/* A single quoted string is treated like a double -- some
programs (e.g., troff) are perverse this way */
/* Handle any pending identifier;
but the L in L'...' or L"..." is not an identifier. */
if (ident_length) {
if (! (ident_length == 1 && hash == HASHSTEP (0, 'L')))
goto specialchar;
ident_length = hash = 0;
}
start_line = ip->lineno;
/* Skip ahead to a matching quote. */
while (1) {
if (ibp >= limit) {
if (ip->macro != 0) {
/* try harder: this string crosses a macro expansion boundary.
This can happen naturally if -traditional.
Otherwise, only -D can make a macro with an unmatched quote. */
POPMACRO;
RECACHE;
continue;
}
if (!traditional) {
error_with_line (line_for_error (start_line),
"unterminated string or character constant");
if (multiline_string_line) {
error_with_line (multiline_string_line,
"possible real start of unterminated constant");
multiline_string_line = 0;
}
}
break;
}
*obp++ = *ibp;
switch (*ibp++) {
case '\n':
++ip->lineno;
++op->lineno;
/* Traditionally, end of line ends a string constant with no error.
So exit the loop and record the new line. */
if (traditional) {
beg_of_line = ibp;
goto while2end;
}
if (c == '\'') {
error_with_line (line_for_error (start_line),
"unterminated character constant");
goto while2end;
}
if (multiline_string_line == 0) {
if (pedantic)
pedwarn_with_line (line_for_error (start_line),
"string constant runs past end of line");
multiline_string_line = ip->lineno - 1;
}
break;
case '\\':
if (*ibp == '\n') {
/* Backslash newline is replaced by nothing at all, but
keep the line counts correct. But if we are reading
from a macro, keep the backslash newline, since backslash
newlines have already been processed. */
if (ip->macro)
*obp++ = '\n';
else
--obp;
++ibp;
++ip->lineno;
} else {
/* ANSI stupidly requires that in \\ the second \
is *not* prevented from combining with a newline. */
if (!ip->macro) {
while (*ibp == '\\' && ibp[1] == '\n') {
ibp += 2;
++ip->lineno;
}
}
*obp++ = *ibp++;
}
break;
case '\"':
case '\'':
if (ibp[-1] == c)
goto while2end;
break;
#ifdef MULTIBYTE_CHARS
default:
{
int length;
--ibp;
length = local_mblen (ibp, limit - ibp);
if (length > 0)
{
--obp;
bcopy (ibp, obp, length);
obp += length;
ibp += length;
}
else
++ibp;
}
break;
#endif
}
}
while2end:
break;
case '/':
if (ip->macro != 0)
goto randomchar;
if (*ibp == '\\' && ibp[1] == '\n')
newline_fix (ibp);
if (*ibp != '*'
&& !(cplusplus_comments && *ibp == '/'))
goto randomchar;
if (ident_length)
goto specialchar;
if (*ibp == '/') {
/* C++ style comment... */
start_line = ip->lineno;
/* Comments are equivalent to spaces. */
if (! put_out_comments)
obp[-1] = ' ';
{
U_CHAR *before_bp = ibp;
while (++ibp < limit) {
if (*ibp == '\n')
{
if (put_out_comments) {
bcopy ((char *) before_bp, (char *) obp, ibp - before_bp);
obp += ibp - before_bp;
}
break;
}
if (*ibp == '\\')
{
if (ibp + 1 < limit && ibp[1] == '\n')
{
if (warn_comments)
warning ("multiline `//' comment");
++ip->lineno;
/* Copy the newline into the output buffer, in order to
avoid the pain of a #line every time a multiline comment
is seen. */
if (!put_out_comments)
*obp++ = '\n';
++op->lineno;
++ibp;
}
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (ibp, limit - ibp);
if (length > 1)
ibp += (length - 1);
#endif
}
}
break;
}
}
/* Ordinary C comment. Skip it, optionally copying it to output. */
start_line = ip->lineno;
++ibp; /* Skip the star. */
/* If this cpp is for lint, we peek inside the comments: */
if (for_lint) {
U_CHAR *argbp;
int cmdlen, arglen;
char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
if (lintcmd != NULL) {
op->bufp = obp;
check_expand (op, cmdlen + arglen + 14);
obp = op->bufp;
/* I believe it is always safe to emit this newline: */
obp[-1] = '\n';
bcopy ("#pragma lint ", (char *) obp, 13);
obp += 13;
bcopy (lintcmd, (char *) obp, cmdlen);
obp += cmdlen;
if (arglen != 0) {
*(obp++) = ' ';
bcopy (argbp, (char *) obp, arglen);
obp += arglen;
}
/* OK, now bring us back to the state we were in before we entered
this branch. We need #line because the #pragma's newline always
messes up the line count. */
op->bufp = obp;
output_line_directive (ip, op, 0, same_file);
check_expand (op, limit - ibp + 2);
obp = op->bufp;
*(obp++) = '/';
}
}
/* Comments are equivalent to spaces.
Note that we already output the slash; we might not want it.
For -traditional, a comment is equivalent to nothing. */
if (! put_out_comments) {
if (traditional)
obp--;
else
obp[-1] = ' ';
}
else
*obp++ = '*';
{
U_CHAR *before_bp = ibp;
for (;;) {
switch (*ibp++) {
case '*':
if (ibp[-2] == '/' && warn_comments)
warning ("`/*' within comment");
if (*ibp == '\\' && ibp[1] == '\n')
newline_fix (ibp);
if (*ibp == '/')
goto comment_end;
break;
case '\n':
++ip->lineno;
/* Copy the newline into the output buffer, in order to
avoid the pain of a #line every time a multiline comment
is seen. */
if (!put_out_comments)
*obp++ = '\n';
++op->lineno;
break;
case 0:
if (limit < ibp) {
error_with_line (line_for_error (start_line),
"unterminated comment");
goto limit_reached;
}
break;
#ifdef MULTIBYTE_CHARS
default:
{
int length;
length = local_mblen (ibp, limit - ibp);
if (length > 1)
ibp += (length - 1);
}
break;
#endif
}
}
comment_end:
ibp++;
if (put_out_comments) {
bcopy ((char *) before_bp, (char *) obp, ibp - before_bp);
obp += ibp - before_bp;
}
}
break;
case '$':
if (! is_idchar['$'])
goto randomchar;
if (pedantic)
pedwarn ("`$' in identifier");
goto letter;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
/* If digit is not part of identifier, it starts a number,
which means that following letters are not an identifier.
"0x5" does not refer to an identifier "x5".
So copy all alphanumerics that follow without accumulating
as an identifier. Periods also, for sake of "3.e7". */
if (ident_length == 0) {
for (;;) {
if (!ip->macro) {
while (ibp[0] == '\\' && ibp[1] == '\n') {
++ip->lineno;
ibp += 2;
}
}
c = *ibp++;
if (!is_idchar[c] && c != '.') {
--ibp;
break;
}
*obp++ = c;
/* A sign can be part of a preprocessing number
if it follows an `e' or `p'. */
if (c == 'e' || c == 'E' || c == 'p' || c == 'P') {
if (!ip->macro) {
while (ibp[0] == '\\' && ibp[1] == '\n') {
++ip->lineno;
ibp += 2;
}
}
if (*ibp == '+' || *ibp == '-') {
*obp++ = *ibp++;
/* But traditional C does not let the token go past the sign,
and C89 does not allow `p'. */
if (traditional || (c89 && (c == 'p' || c == 'P')))
break;
}
}
}
break;
}
/* fall through */
case '_':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
letter:
ident_length++;
/* Compute step of hash function, to avoid a proc call on every token */
hash = HASHSTEP (hash, c);
break;
case '\n':
if (ip->fname == 0 && *ibp == '-') {
/* Newline - inhibits expansion of preceding token.
If expanding a macro arg, we keep the newline -.
In final output, it is deleted.
We recognize Newline - in macro bodies and macro args. */
if (! concatenated) {
ident_length = 0;
hash = 0;
}
ibp++;
if (!output_marks) {
obp--;
} else {
/* If expanding a macro arg, keep the newline -. */
*obp++ = '-';
}
break;
}
/* If reprocessing a macro expansion, newline is a special marker. */
else if (ip->macro != 0) {
/* Newline White is a "funny space" to separate tokens that are
supposed to be separate but without space between.
Here White means any whitespace character.
Newline - marks a recursive macro use that is not
supposed to be expandable. */
if (is_space[*ibp]) {
/* Newline Space does not prevent expansion of preceding token
so expand the preceding token and then come back. */
if (ident_length > 0)
goto specialchar;
/* If generating final output, newline space makes a space. */
if (!output_marks) {
obp[-1] = *ibp++;
/* And Newline Newline makes a newline, so count it. */
if (obp[-1] == '\n')
op->lineno++;
} else {
/* If expanding a macro arg, keep the newline space.
If the arg gets stringified, newline space makes nothing. */
*obp++ = *ibp++;
}
} else abort (); /* Newline followed by something random? */
break;
}
/* If there is a pending identifier, handle it and come back here. */
if (ident_length > 0)
goto specialchar;
beg_of_line = ibp;
/* Update the line counts and output a #line if necessary. */
++ip->lineno;
++op->lineno;
if (ip->lineno != op->lineno) {
op->bufp = obp;
output_line_directive (ip, op, 1, same_file);
check_expand (op, limit - ibp);
obp = op->bufp;
}
break;
/* Come here either after (1) a null character that is part of the input
or (2) at the end of the input, because there is a null there. */
case 0:
if (ibp <= limit)
/* Our input really contains a null character. */
goto randomchar;
limit_reached:
/* At end of a macro-expansion level, pop it and read next level. */
if (ip->macro != 0) {
obp--;
ibp--;
/* If traditional, and we have an identifier that ends here,
process it now, so we get the right error for recursion. */
if (traditional && ident_length
&& ! is_idchar[*instack[indepth - 1].bufp]) {
redo_char = 1;
goto randomchar;
}
POPMACRO;
RECACHE;
break;
}
/* If we don't have a pending identifier,
return at end of input. */
if (ident_length == 0) {
obp--;
ibp--;
op->bufp = obp;
ip->bufp = ibp;
goto ending;
}
/* If we do have a pending identifier, just consider this null
a special character and arrange to dispatch on it again.
The second time, IDENT_LENGTH will be zero so we will return. */
/* Fall through */
specialchar:
/* Handle the case of a character such as /, ', " or null
seen following an identifier. Back over it so that
after the identifier is processed the special char
will be dispatched on again. */
ibp--;
obp--;
redo_char = 1;
default:
randomchar:
if (ident_length > 0) {
register HASHNODE *hp;
/* We have just seen an identifier end. If it's a macro, expand it.
IDENT_LENGTH is the length of the identifier
and HASH is its hash code.
The identifier has already been copied to the output,
so if it is a macro we must remove it.
If REDO_CHAR is 0, the char that terminated the identifier
has been skipped in the output and the input.
OBP-IDENT_LENGTH-1 points to the identifier.
If the identifier is a macro, we must back over the terminator.
If REDO_CHAR is 1, the terminating char has already been
backed over. OBP-IDENT_LENGTH points to the identifier. */
if (!pcp_outfile || pcp_inside_if) {
for (hp = hashtab[MAKE_POS (hash) % HASHSIZE]; hp != NULL;
hp = hp->next) {
if (hp->length == ident_length) {
int obufp_before_macroname;
int op_lineno_before_macroname;
register int i = ident_length;
register U_CHAR *p = hp->name;
register U_CHAR *q = obp - i;
int disabled;
if (! redo_char)
q--;
do { /* All this to avoid a strncmp () */
if (*p++ != *q++)
goto hashcollision;
} while (--i);
/* We found a use of a macro name.
see if the context shows it is a macro call. */
/* Back up over terminating character if not already done. */
if (! redo_char) {
ibp--;
obp--;
}
/* Save this as a displacement from the beginning of the output
buffer. We can not save this as a position in the output
buffer, because it may get realloc'ed by RECACHE. */
obufp_before_macroname = (obp - op->buf) - ident_length;
op_lineno_before_macroname = op->lineno;
if (hp->type == T_PCSTRING) {
pcstring_used (hp); /* Mark the definition of this key
as needed, ensuring that it
will be output. */
break; /* Exit loop, since the key cannot have a
definition any longer. */
}
/* Record whether the macro is disabled. */
disabled = hp->type == T_DISABLED;
/* This looks like a macro ref, but if the macro was disabled,
just copy its name and put in a marker if requested. */
if (disabled) {
#if 0
/* This error check caught useful cases such as
#define foo(x,y) bar (x (y,0), y)
foo (foo, baz) */
if (traditional)
error ("recursive use of macro `%s'", hp->name);
#endif
if (output_marks) {
op->bufp = obp;
check_expand (op, limit - ibp + 2);
obp = op->bufp;
*obp++ = '\n';
*obp++ = '-';
}
break;
}
/* If macro wants an arglist, verify that a '(' follows.
first skip all whitespace, copying it to the output
after the macro name. Then, if there is no '(',
decide this is not a macro call and leave things that way. */
if ((hp->type == T_MACRO || hp->type == T_DISABLED)
&& hp->value.defn->nargs >= 0)
{
U_CHAR *old_ibp = ibp;
U_CHAR *old_obp = obp;
int old_iln = ip->lineno;
int old_oln = op->lineno;
while (1) {
/* Scan forward over whitespace, copying it to the output. */
if (ibp == limit && ip->macro != 0) {
POPMACRO;
RECACHE;
old_ibp = ibp;
old_obp = obp;
old_iln = ip->lineno;
old_oln = op->lineno;
}
else if (is_space[*ibp]) {
*obp++ = *ibp++;
if (ibp[-1] == '\n') {
if (ip->macro == 0) {
/* Newline in a file. Count it. */
++ip->lineno;
++op->lineno;
} else if (!output_marks) {
/* A newline mark, and we don't want marks
in the output. If it is newline-hyphen,
discard it entirely. Otherwise, it is
newline-whitechar, so keep the whitechar. */
obp--;
if (*ibp == '-')
ibp++;
else {
if (*ibp == '\n')
++op->lineno;
*obp++ = *ibp++;
}
} else {
/* A newline mark; copy both chars to the output. */
*obp++ = *ibp++;
}
}
}
else if (ip->macro)
break;
else if (*ibp == '/') {
/* If a comment, copy it unchanged or discard it. */
if (ibp[1] == '\\' && ibp[2] == '\n')
newline_fix (ibp + 1);
if (ibp[1] == '*') {
if (put_out_comments) {
*obp++ = '/';
*obp++ = '*';
} else if (! traditional) {
*obp++ = ' ';
}
for (ibp += 2; ibp < limit; ibp++) {
/* We need not worry about newline-marks,
since they are never found in comments. */
if (ibp[0] == '*') {
if (ibp[1] == '\\' && ibp[2] == '\n')
newline_fix (ibp + 1);
if (ibp[1] == '/') {
ibp += 2;
if (put_out_comments) {
*obp++ = '*';
*obp++ = '/';
}
break;
}
}
else if (*ibp == '\n') {
/* Newline in a file. Count it. */
++ip->lineno;
++op->lineno;
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (ibp, limit - ibp);
if (length > 1)
{
if (put_out_comments)
{
bcopy (ibp, obp, length - 1);
obp += length - 1;
}
ibp += (length - 1);
}
#endif
}
if (put_out_comments)
*obp++ = *ibp;
}
} else if (ibp[1] == '/' && cplusplus_comments) {
if (put_out_comments) {
*obp++ = '/';
*obp++ = '/';
} else if (! traditional) {
*obp++ = ' ';
}
for (ibp += 2; ; ibp++)
{
if (*ibp == '\n')
break;
if (*ibp == '\\' && ibp[1] == '\n')
{
if (put_out_comments)
*obp++ = *ibp++;
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (ibp, limit - ibp);
if (length > 1)
{
if (put_out_comments)
{
bcopy (ibp, obp, length - 1);
obp += length - 1;
}
ibp += (length - 1);
}
#endif
}
if (put_out_comments)
*obp++ = *ibp;
}
} else
break;
}
else if (ibp[0] == '\\' && ibp[1] == '\n') {
ibp += 2;
++ip->lineno;
}
else break;
}
if (*ibp != '(') {
/* It isn't a macro call.
Put back the space that we just skipped. */
ibp = old_ibp;
obp = old_obp;
ip->lineno = old_iln;
op->lineno = old_oln;
/* Exit the for loop. */
break;
}
}
/* This is now known to be a macro call.
Discard the macro name from the output,
along with any following whitespace just copied,
but preserve newlines if not outputting marks since this
is more likely to do the right thing with line numbers. */
obp = op->buf + obufp_before_macroname;
if (output_marks)
op->lineno = op_lineno_before_macroname;
else {
int newlines = op->lineno - op_lineno_before_macroname;
while (0 < newlines--)
*obp++ = '\n';
}
/* Prevent accidental token-pasting with a character
before the macro call. */
if (!traditional && obp != op->buf) {
switch (obp[-1]) {
case '!': case '%': case '&': case '*':
case '+': case '-': case '.': case '/':
case ':': case '<': case '=': case '>':
case '^': case '|':
/* If we are expanding a macro arg, make a newline marker
to separate the tokens. If we are making real output,
a plain space will do. */
if (output_marks)
*obp++ = '\n';
*obp++ = ' ';
}
}
/* Expand the macro, reading arguments as needed,
and push the expansion on the input stack. */
ip->bufp = ibp;
op->bufp = obp;
macroexpand (hp, op);
/* Reexamine input stack, since macroexpand has pushed
a new level on it. */
obp = op->bufp;
RECACHE;
break;
}
hashcollision:
;
} /* End hash-table-search loop */
}
ident_length = hash = 0; /* Stop collecting identifier */
redo_char = 0;
concatenated = 0;
} /* End if (ident_length > 0) */
} /* End switch */
} /* End per-char loop */
/* Come here to return -- but first give an error message
if there was an unterminated successful conditional. */
ending:
if (if_stack != ip->if_stack)
{
char *str;
switch (if_stack->type)
{
case T_IF:
str = "if";
break;
case T_IFDEF:
str = "ifdef";
break;
case T_IFNDEF:
str = "ifndef";
break;
case T_ELSE:
str = "else";
break;
case T_ELIF:
str = "elif";
break;
default:
abort ();
}
error_with_line (line_for_error (if_stack->lineno),
"unterminated `#%s' conditional", str);
}
if_stack = ip->if_stack;
}
/*
* Rescan a string into a temporary buffer and return the result
* as a FILE_BUF. Note this function returns a struct, not a pointer.
*
* OUTPUT_MARKS nonzero means keep Newline markers found in the input
* and insert such markers when appropriate. See `rescan' for details.
* OUTPUT_MARKS is 1 for macroexpanding a macro argument separately
* before substitution; it is 0 for other uses.
*/
static FILE_BUF
expand_to_temp_buffer (buf, limit, output_marks, assertions)
U_CHAR *buf, *limit;
int output_marks, assertions;
{
register FILE_BUF *ip;
FILE_BUF obuf;
int length = limit - buf;
U_CHAR *buf1;
int odepth = indepth;
int save_assertions_flag = assertions_flag;
assertions_flag = assertions;
if (length < 0)
abort ();
/* Set up the input on the input stack. */
buf1 = (U_CHAR *) alloca (length + 1);
{
register U_CHAR *p1 = buf;
register U_CHAR *p2 = buf1;
while (p1 != limit)
*p2++ = *p1++;
}
buf1[length] = 0;
/* Set up to receive the output. */
obuf.length = length * 2 + 100; /* Usually enough. Why be stingy? */
obuf.bufp = obuf.buf = (U_CHAR *) xmalloc (obuf.length);
obuf.nominal_fname = 0;
obuf.inc = 0;
obuf.dir = 0;
obuf.fname = 0;
obuf.macro = 0;
obuf.if_stack = 0;
obuf.free_ptr = 0;
obuf.system_header_p = 0;
CHECK_DEPTH ({return obuf;});
++indepth;
ip = &instack[indepth];
ip->fname = 0;
ip->nominal_fname = 0;
ip->nominal_fname_len = 0;
ip->inc = 0;
ip->system_header_p = 0;
ip->macro = 0;
ip->free_ptr = 0;
ip->length = length;
ip->buf = ip->bufp = buf1;
ip->if_stack = if_stack;
ip->lineno = obuf.lineno = 1;
/* Scan the input, create the output. */
rescan (&obuf, output_marks);
/* Pop input stack to original state. */
--indepth;
if (indepth != odepth)
abort ();
/* Record the output. */
obuf.length = obuf.bufp - obuf.buf;
assertions_flag = save_assertions_flag;
return obuf;
}
/*
* Process a # directive. Expects IP->bufp to point after the '#', as in
* `#define foo bar'. Passes to the directive handler
* (do_define, do_include, etc.): the addresses of the 1st and
* last chars of the directive (starting immediately after the #
* keyword), plus op and the keyword table pointer. If the directive
* contains comments it is copied into a temporary buffer sans comments
* and the temporary buffer is passed to the directive handler instead.
* Likewise for backslash-newlines.
*
* Returns nonzero if this was a known # directive.
* Otherwise, returns zero, without advancing the input pointer.
*/
static int
handle_directive (ip, op)
FILE_BUF *ip, *op;
{
register U_CHAR *bp, *cp;
register struct directive *kt;
register int ident_length;
U_CHAR *resume_p;
/* Nonzero means we must copy the entire directive
to get rid of comments or backslash-newlines. */
int copy_directive = 0;
U_CHAR *ident, *after_ident;
bp = ip->bufp;
/* Record where the directive started. do_xifdef needs this. */
directive_start = bp - 1;
ignore_escape_flag = 1;
/* Skip whitespace and \-newline. */
while (1) {
if (is_hor_space[*bp]) {
if (*bp != ' ' && *bp != '\t' && pedantic)
pedwarn_strange_white_space (*bp);
bp++;
} else if (*bp == '/') {
if (bp[1] == '\\' && bp[2] == '\n')
newline_fix (bp + 1);
if (! (bp[1] == '*' || (cplusplus_comments && bp[1] == '/')))
break;
ip->bufp = bp + 2;
skip_to_end_of_comment (ip, &ip->lineno, 0);
bp = ip->bufp;
} else if (*bp == '\\' && bp[1] == '\n') {
bp += 2; ip->lineno++;
} else break;
}
/* Now find end of directive name.
If we encounter a backslash-newline, exchange it with any following
symbol-constituents so that we end up with a contiguous name. */
cp = bp;
while (1) {
if (is_idchar[*cp])
cp++;
else {
if (*cp == '\\' && cp[1] == '\n')
name_newline_fix (cp);
if (is_idchar[*cp])
cp++;
else break;
}
}
ident_length = cp - bp;
ident = bp;
after_ident = cp;
/* A line of just `#' becomes blank. */
if (ident_length == 0 && *after_ident == '\n') {
ip->bufp = after_ident;
return 1;
}
if (ident_length == 0 || !is_idstart[*ident]) {
U_CHAR *p = ident;
while (is_idchar[*p]) {
if (*p < '0' || *p > '9')
break;
p++;
}
/* Handle # followed by a line number. */
if (p != ident && !is_idchar[*p]) {
static struct directive line_directive_table[] = {
{ 4, do_line, "line", T_LINE},
};
if (pedantic)
pedwarn ("`#' followed by integer");
after_ident = ident;
kt = line_directive_table;
ignore_escape_flag = 0;
goto old_linenum;
}
/* Avoid error for `###' and similar cases unless -pedantic. */
if (p == ident) {
while (*p == '#' || is_hor_space[*p]) p++;
if (*p == '\n') {
if (pedantic && !lang_asm)
warning ("invalid preprocessing directive");
return 0;
}
}
if (!lang_asm)
error ("invalid preprocessing directive name");
return 0;
}
/*
* Decode the keyword and call the appropriate expansion
* routine, after moving the input pointer up to the next line.
*/
for (kt = directive_table; kt->length > 0; kt++) {
if (kt->length == ident_length && !bcmp (kt->name, ident, ident_length)) {
register U_CHAR *buf;
register U_CHAR *limit;
int unterminated;
int junk;
int *already_output;
/* Nonzero means do not delete comments within the directive.
#define needs this when -traditional. */
int keep_comments;
old_linenum:
limit = ip->buf + ip->length;
unterminated = 0;
already_output = 0;
keep_comments = traditional && kt->type == T_DEFINE;
/* #import is defined only in Objective C, or when on the NeXT. */
if (kt->type == T_IMPORT
&& !(objc || lookup ((U_CHAR *) "__NeXT__", -1, -1)))
break;
/* Find the end of this directive (first newline not backslashed
and not in a string or comment).
Set COPY_DIRECTIVE if the directive must be copied
(it contains a backslash-newline or a comment). */
buf = bp = after_ident;
while (bp < limit) {
register U_CHAR c = *bp++;
switch (c) {
case '\\':
if (bp < limit) {
if (*bp == '\n') {
ip->lineno++;
copy_directive = 1;
bp++;
} else if (traditional)
bp++;
}
break;
case '"':
/* "..." is special for #include. */
if (IS_INCLUDE_DIRECTIVE_TYPE (kt->type)) {
while (bp < limit && *bp != '\n') {
if (*bp == '"') {
bp++;
break;
}
if (*bp == '\\' && bp[1] == '\n') {
ip->lineno++;
copy_directive = 1;
bp++;
}
bp++;
}
break;
}
/* Fall through. */
case '\'':
bp = skip_quoted_string (bp - 1, limit, ip->lineno, &ip->lineno, ©_directive, &unterminated);
/* Don't bother calling the directive if we already got an error
message due to unterminated string. Skip everything and pretend
we called the directive. */
if (unterminated) {
if (traditional) {
/* Traditional preprocessing permits unterminated strings. */
ip->bufp = bp;
goto endloop1;
}
ip->bufp = bp;
return 1;
}
break;
/* <...> is special for #include. */
case '<':
if (! IS_INCLUDE_DIRECTIVE_TYPE (kt->type))
break;
while (bp < limit && *bp != '>' && *bp != '\n') {
if (*bp == '\\' && bp[1] == '\n') {
ip->lineno++;
copy_directive = 1;
bp++;
}
bp++;
}
break;
case '/':
if (*bp == '\\' && bp[1] == '\n')
newline_fix (bp);
if (*bp == '*'
|| (cplusplus_comments && *bp == '/')) {
U_CHAR *obp = bp - 1;
ip->bufp = bp + 1;
skip_to_end_of_comment (ip, &ip->lineno, 0);
bp = ip->bufp;
/* No need to copy the directive because of a comment at the end;
just don't include the comment in the directive. */
if (!put_out_comments) {
U_CHAR *p;
for (p = bp; *p == ' ' || *p == '\t'; p++)
continue;
if (*p == '\n') {
bp = obp;
goto endloop1;
}
}
/* Don't remove the comments if -traditional. */
if (! keep_comments)
copy_directive++;
}
break;
case '\f':
case '\r':
case '\v':
if (pedantic)
pedwarn_strange_white_space (c);
break;
case '\n':
--bp; /* Point to the newline */
ip->bufp = bp;
goto endloop1;
}
}
ip->bufp = bp;
endloop1:
resume_p = ip->bufp;
/* BP is the end of the directive.
RESUME_P is the next interesting data after the directive.
A comment may come between. */
/* If a directive should be copied through, and -C was given,
pass it through before removing comments. */
if (!no_output && put_out_comments
&& ((kt->type == T_DEFINE || kt->type == T_UNDEF)
? dump_macros == dump_definitions
: IS_INCLUDE_DIRECTIVE_TYPE (kt->type) ? dump_includes
: kt->type == T_PRAGMA)) {
int len;
/* Output directive name. */
check_expand (op, kt->length + 2);
/* Make sure # is at the start of a line */
if (op->bufp > op->buf && op->bufp[-1] != '\n') {
op->lineno++;
*op->bufp++ = '\n';
}
*op->bufp++ = '#';
bcopy (kt->name, op->bufp, kt->length);
op->bufp += kt->length;
/* Output arguments. */
len = (bp - buf);
check_expand (op, len);
bcopy (buf, (char *) op->bufp, len);
op->bufp += len;
/* Take account of any (escaped) newlines just output. */
while (--len >= 0)
if (buf[len] == '\n')
op->lineno++;
already_output = &junk;
} /* Don't we need a newline or #line? */
if (copy_directive) {
register U_CHAR *xp = buf;
/* Need to copy entire directive into temp buffer before dispatching */
cp = (U_CHAR *) alloca (bp - buf + 5); /* room for directive plus
some slop */
buf = cp;
/* Copy to the new buffer, deleting comments
and backslash-newlines (and whitespace surrounding the latter). */
while (xp < bp) {
register U_CHAR c = *xp++;
*cp++ = c;
switch (c) {
case '\n':
abort (); /* A bare newline should never part of the line. */
break;
/* <...> is special for #include. */
case '<':
if (! IS_INCLUDE_DIRECTIVE_TYPE (kt->type))
break;
while (xp < bp && c != '>') {
c = *xp++;
if (c == '\\' && xp < bp && *xp == '\n')
xp++;
else
*cp++ = c;
}
break;
case '\\':
if (*xp == '\n') {
xp++;
cp--;
if (cp != buf && is_hor_space[cp[-1]]) {
while (cp - 1 != buf && is_hor_space[cp[-2]])
cp--;
SKIP_WHITE_SPACE (xp);
} else if (is_hor_space[*xp]) {
*cp++ = *xp++;
SKIP_WHITE_SPACE (xp);
}
} else if (traditional && xp < bp) {
*cp++ = *xp++;
}
break;
case '\'':
case '\"':
{
int backslash_newlines_p = 0;
register U_CHAR *bp1
= skip_quoted_string (xp - 1, bp, ip->lineno,
NULL_PTR, &backslash_newlines_p,
NULL_PTR);
if (backslash_newlines_p)
while (xp != bp1)
{
/* With something like:
#define X "a\
b"
we should still remove the backslash-newline
pair as part of phase two. */
if (xp[0] == '\\' && xp[1] == '\n')
xp += 2;
else
*cp++ = *xp++;
}
else
/* This is the same as the loop above, but taking
advantage of the fact that we know there are no
backslash-newline pairs. */
while (xp != bp1)
*cp++ = *xp++;
}
break;
case '/':
if (*xp == '*'
|| (cplusplus_comments && *xp == '/')) {
ip->bufp = xp + 1;
/* If we already copied the directive through,
already_output != 0 prevents outputting comment now. */
skip_to_end_of_comment (ip, already_output, 0);
if (keep_comments)
while (xp != ip->bufp)
*cp++ = *xp++;
/* Delete or replace the slash. */
else if (traditional)
cp--;
else
cp[-1] = ' ';
xp = ip->bufp;
}
}
}
/* Null-terminate the copy. */
*cp = 0;
} else
cp = bp;
ip->bufp = resume_p;
/* Some directives should be written out for cc1 to process,
just as if they were not defined. And sometimes we're copying
directives through. */
if (!no_output && already_output == 0
&& (kt->type == T_DEFINE ? (int) dump_names <= (int) dump_macros
: IS_INCLUDE_DIRECTIVE_TYPE (kt->type) ? dump_includes
: kt->type == T_PRAGMA)) {
int len;
/* Output directive name. */
check_expand (op, kt->length + 1);
*op->bufp++ = '#';
bcopy (kt->name, (char *) op->bufp, kt->length);
op->bufp += kt->length;
if (kt->type == T_DEFINE && dump_macros == dump_names) {
/* Output `#define name' only. */
U_CHAR *xp = buf;
U_CHAR *yp;
SKIP_WHITE_SPACE (xp);
yp = xp;
while (is_idchar[*xp]) xp++;
len = (xp - yp);
check_expand (op, len + 1);
*op->bufp++ = ' ';
bcopy (yp, (char *) op->bufp, len);
} else {
/* Output entire directive. */
len = (cp - buf);
check_expand (op, len);
bcopy (buf, (char *) op->bufp, len);
}
op->bufp += len;
} /* Don't we need a newline or #line? */
/* Call the appropriate directive handler. buf now points to
either the appropriate place in the input buffer, or to
the temp buffer if it was necessary to make one. cp
points to the first char after the contents of the (possibly
copied) directive, in either case. */
(*kt->func) (buf, cp, op, kt);
check_expand (op, ip->length - (ip->bufp - ip->buf));
return 1;
}
}
/* It is deliberate that we don't warn about undefined directives.
That is the responsibility of cc1. */
return 0;
}
static struct tm *
timestamp ()
{
static struct tm *timebuf;
if (!timebuf) {
time_t t = time ((time_t *) 0);
timebuf = localtime (&t);
}
return timebuf;
}
static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
};
/*
* expand things like __FILE__. Place the expansion into the output
* buffer *without* rescanning.
*/
static void
special_symbol (hp, op)
HASHNODE *hp;
FILE_BUF *op;
{
char *buf;
int i, len;
int true_indepth;
FILE_BUF *ip = NULL;
struct tm *timebuf;
int paren = 0; /* For special `defined' keyword */
if (pcp_outfile && pcp_inside_if
&& hp->type != T_SPEC_DEFINED && hp->type != T_CONST)
error ("Predefined macro `%s' used inside `#if' during precompilation",
hp->name);
for (i = indepth; i >= 0; i--)
if (instack[i].fname != NULL) {
ip = &instack[i];
break;
}
if (ip == NULL) {
error ("cccp error: not in any file?!");
return; /* the show must go on */
}
switch (hp->type) {
case T_FILE:
case T_BASE_FILE:
{
FILE_BUF *p = hp->type == T_FILE ? ip : &instack[0];
char *string = p->nominal_fname;
if (string)
{
size_t string_len = p->nominal_fname_len;
buf = (char *) alloca (3 + 4 * string_len);
quote_string (buf, string, string_len);
}
else
buf = "\"\"";
break;
}
case T_INCLUDE_LEVEL:
true_indepth = 0;
for (i = indepth; i >= 0; i--)
if (instack[i].fname != NULL)
true_indepth++;
buf = (char *) alloca (12); /* Eight bytes ought to be more than enough */
sprintf (buf, "%d", true_indepth - 1);
break;
case T_VERSION:
buf = (char *) alloca (3 + strlen (version_string));
sprintf (buf, "\"%s\"", version_string);
break;
#ifndef NO_BUILTIN_SIZE_TYPE
case T_SIZE_TYPE:
buf = SIZE_TYPE;
break;
#endif
#ifndef NO_BUILTIN_PTRDIFF_TYPE
case T_PTRDIFF_TYPE:
buf = PTRDIFF_TYPE;
break;
#endif
case T_WCHAR_TYPE:
buf = wchar_type;
break;
case T_USER_LABEL_PREFIX_TYPE:
buf = user_label_prefix;
break;
case T_REGISTER_PREFIX_TYPE:
buf = REGISTER_PREFIX;
break;
case T_IMMEDIATE_PREFIX_TYPE:
buf = IMMEDIATE_PREFIX;
break;
case T_CONST:
buf = hp->value.cpval;
#ifdef STDC_0_IN_SYSTEM_HEADERS
if (ip->system_header_p
&& hp->length == 8 && bcmp (hp->name, "__STDC__", 8) == 0
&& !lookup ((U_CHAR *) "__STRICT_ANSI__", -1, -1))
buf = "0";
#endif
if (pcp_inside_if && pcp_outfile)
/* Output a precondition for this macro use */
fprintf (pcp_outfile, "#define %s %s\n", hp->name, buf);
break;
case T_SPECLINE:
buf = (char *) alloca (10);
sprintf (buf, "%d", ip->lineno);
break;
case T_DATE:
case T_TIME:
buf = (char *) alloca (20);
timebuf = timestamp ();
if (hp->type == T_DATE)
sprintf (buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon],
timebuf->tm_mday, timebuf->tm_year + 1900);
else
sprintf (buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min,
timebuf->tm_sec);
break;
case T_SPEC_DEFINED:
buf = " 0 "; /* Assume symbol is not defined */
ip = &instack[indepth];
SKIP_WHITE_SPACE (ip->bufp);
if (*ip->bufp == '(') {
paren++;
ip->bufp++; /* Skip over the paren */
SKIP_WHITE_SPACE (ip->bufp);
}
if (!is_idstart[*ip->bufp])
goto oops;
if (ip->bufp[0] == 'L' && (ip->bufp[1] == '\'' || ip->bufp[1] == '"'))
goto oops;
if ((hp = lookup (ip->bufp, -1, -1))) {
if (pcp_outfile && pcp_inside_if
&& (hp->type == T_CONST
|| (hp->type == T_MACRO && hp->value.defn->predefined)))
/* Output a precondition for this macro use. */
fprintf (pcp_outfile, "#define %s\n", hp->name);
buf = " 1 ";
}
else
if (pcp_outfile && pcp_inside_if) {
/* Output a precondition for this macro use */
U_CHAR *cp = ip->bufp;
fprintf (pcp_outfile, "#undef ");
while (is_idchar[*cp]) /* Ick! */
fputc (*cp++, pcp_outfile);
putc ('\n', pcp_outfile);
}
while (is_idchar[*ip->bufp])
++ip->bufp;
SKIP_WHITE_SPACE (ip->bufp);
if (paren) {
if (*ip->bufp != ')')
goto oops;
++ip->bufp;
}
break;
oops:
error ("`defined' without an identifier");
break;
default:
error ("cccp error: invalid special hash type"); /* time for gdb */
abort ();
}
len = strlen (buf);
check_expand (op, len);
bcopy (buf, (char *) op->bufp, len);
op->bufp += len;
return;
}
/* Routines to handle #directives */
/* Handle #include and #import.
This function expects to see "fname" or <fname> on the input. */
static int
do_include (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
struct directive *keyword;
{
U_CHAR *importing = keyword->type == T_IMPORT ? (U_CHAR *) "" : (U_CHAR *) 0;
int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
static int import_warning = 0;
char *fname; /* Dynamically allocated fname buffer */
char *pcftry;
char *pcfname;
char *fbeg, *fend; /* Beginning and end of fname */
U_CHAR *fin;
struct file_name_list *search_start = include; /* Chain of dirs to search */
struct file_name_list *dsp; /* First in chain, if #include "..." */
struct file_name_list *searchptr = 0;
size_t flen;
int f = -3; /* file number */
struct include_file *inc = 0;
int retried = 0; /* Have already tried macro
expanding the include line*/
int angle_brackets = 0; /* 0 for "...", 1 for <...> */
#ifdef VMS
int vaxc_include = 0; /* 1 for token without punctuation */
#endif
int pcf = -1;
char *pcfbuf;
char *pcfbuflimit;
int pcfnum;
if (pedantic && !instack[indepth].system_header_p)
{
if (importing)
pedwarn ("ANSI C does not allow `#import'");
if (skip_dirs)
pedwarn ("ANSI C does not allow `#include_next'");
}
if (importing && warn_import && !inhibit_warnings
&& !instack[indepth].system_header_p && !import_warning) {
import_warning = 1;
warning ("using `#import' is not recommended");
notice ("The fact that a certain header file need not be processed more than once\n\
should be indicated in the header file, not where it is used.\n\
The best way to do this is with a conditional of this form:\n\
\n\
#ifndef _FOO_H_INCLUDED\n\
#define _FOO_H_INCLUDED\n\
... <real contents of file> ...\n\
#endif /* Not _FOO_H_INCLUDED */\n\
\n\
Then users can use `#include' any number of times.\n\
GNU C automatically avoids processing the file more than once\n\
when it is equipped with such a conditional.\n");
}
get_filename:
fin = buf;
SKIP_WHITE_SPACE (fin);
/* Discard trailing whitespace so we can easily see
if we have parsed all the significant chars we were given. */
while (limit != fin && is_hor_space[limit[-1]]) limit--;
fbeg = fend = (char *) alloca (limit - fin);
switch (*fin++) {
case '\"':
{
FILE_BUF *fp;
/* Copy the operand text, concatenating the strings. */
{
for (;;) {
for (;;) {
if (fin == limit)
goto invalid_include_file_name;
*fend = *fin++;
if (*fend == '"')
break;
fend++;
}
if (fin == limit)
break;
/* If not at the end, there had better be another string. */
/* Skip just horiz space, and don't go past limit. */
while (fin != limit && is_hor_space[*fin]) fin++;
if (fin != limit && *fin == '\"')
fin++;
else
goto fail;
}
}
/* We have "filename". Figure out directory this source
file is coming from and put it on the front of the list. */
/* If -I- was specified, don't search current dir, only spec'd ones. */
if (ignore_srcdir) break;
for (fp = &instack[indepth]; fp >= instack; fp--)
{
int n;
char *nam;
if ((nam = fp->nominal_fname) != NULL) {
/* Found a named file. Figure out dir of the file,
and put it in front of the search list. */
dsp = ((struct file_name_list *)
alloca (sizeof (struct file_name_list)
+ fp->nominal_fname_len));
strcpy (dsp->fname, nam);
simplify_filename (dsp->fname);
nam = base_name (dsp->fname);
*nam = 0;
#ifdef VMS
/* for hack_vms_include_specification(), a local
dir specification must start with "./" on VMS. */
if (nam == dsp->fname)
{
*nam++ = '.';
*nam++ = '/';
*nam = 0;
}
#endif
/* But for efficiency's sake, do not insert the dir
if it matches the search list's first dir. */
dsp->next = search_start;
if (!search_start || strcmp (dsp->fname, search_start->fname)) {
search_start = dsp;
n = nam - dsp->fname;
if (n + INCLUDE_LEN_FUDGE > max_include_len)
max_include_len = n + INCLUDE_LEN_FUDGE;
}
dsp[0].got_name_map = 0;
break;
}
}
break;
}
case '<':
while (fin != limit && *fin != '>')
*fend++ = *fin++;
if (*fin == '>' && fin + 1 == limit) {
angle_brackets = 1;
/* If -I-, start with the first -I dir after the -I-. */
search_start = first_bracket_include;
break;
}
goto fail;
default:
#ifdef VMS
/*
* Support '#include xyz' like VAX-C to allow for easy use of all the
* decwindow include files. It defaults to '#include <xyz.h>' (so the
* code from case '<' is repeated here) and generates a warning.
* (Note: macro expansion of `xyz' takes precedence.)
*/
/* Note: The argument of ISALPHA() can be evaluated twice, so do
the pre-decrement outside of the macro. */
if (retried && (--fin, ISALPHA(*(U_CHAR *) (fin)))) {
while (fin != limit && (!ISSPACE(*fin)))
*fend++ = *fin++;
warning ("VAX-C-style include specification found, use '#include <filename.h>' !");
vaxc_include = 1;
if (fin == limit) {
angle_brackets = 1;
/* If -I-, start with the first -I dir after the -I-. */
search_start = first_bracket_include;
break;
}
}
#endif
fail:
if (! retried) {
/* Expand buffer and then remove any newline markers.
We can't just tell expand_to_temp_buffer to omit the markers,
since it would put extra spaces in include file names. */
FILE_BUF trybuf;
U_CHAR *src;
int errors_before_expansion = errors;
trybuf = expand_to_temp_buffer (buf, limit, 1, 0);
if (errors != errors_before_expansion) {
free (trybuf.buf);
goto invalid_include_file_name;
}
src = trybuf.buf;
buf = (U_CHAR *) alloca (trybuf.bufp - trybuf.buf + 1);
limit = buf;
while (src != trybuf.bufp) {
switch ((*limit++ = *src++)) {
case '\n':
limit--;
src++;
break;
case '\'':
case '\"':
{
U_CHAR *src1 = skip_quoted_string (src - 1, trybuf.bufp, 0,
NULL_PTR, NULL_PTR, NULL_PTR);
while (src != src1)
*limit++ = *src++;
}
break;
}
}
*limit = 0;
free (trybuf.buf);
retried = 1;
goto get_filename;
}
invalid_include_file_name:
error ("`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
return 0;
}
/* For #include_next, skip in the search path
past the dir in which the containing file was found. */
if (skip_dirs) {
FILE_BUF *fp;
for (fp = &instack[indepth]; fp >= instack; fp--)
if (fp->fname != NULL) {
/* fp->dir is null if the containing file was specified
with an absolute file name. In that case, don't skip anything. */
if (fp->dir)
search_start = fp->dir->next;
break;
}
}
*fend = 0;
flen = simplify_filename (fbeg);
if (flen == 0)
{
error ("empty file name in `#%s'", keyword->name);
return 0;
}
/* Allocate this permanently, because it gets stored in the definitions
of macros. */
fname = xmalloc (max_include_len + flen + 1);
/* + 1 above for terminating null. */
system_include_depth += angle_brackets;
/* If specified file name is absolute, just open it. */
if (absolute_filename (fbeg)) {
strcpy (fname, fbeg);
f = open_include_file (fname, NULL_PTR, importing, &inc);
} else {
struct bypass_dir {
struct bypass_dir *next;
char *fname;
struct file_name_list *searchptr;
} **bypass_slot = 0;
/* Search directory path, trying to open the file.
Copy each filename tried into FNAME. */
for (searchptr = search_start; searchptr; searchptr = searchptr->next) {
if (searchptr == first_bracket_include) {
/* Go to bypass directory if we know we've seen this file before. */
static struct bypass_dir *bypass_hashtab[INCLUDE_HASHSIZE];
struct bypass_dir *p;
bypass_slot = &bypass_hashtab[hashf ((U_CHAR *) fbeg, flen,
INCLUDE_HASHSIZE)];
for (p = *bypass_slot; p; p = p->next)
if (!strcmp (fbeg, p->fname)) {
searchptr = p->searchptr;
bypass_slot = 0;
break;
}
}
#ifdef VMS
/* Change this 1/2 Unix 1/2 VMS file specification into a
full VMS file specification */
if (searchptr->fname[0])
{
strcpy (fname, searchptr->fname);
if (fname[strlen (fname) - 1] == ':')
{
char *slashp;
slashp = strchr (fbeg, '/');
/* start at root-dir of logical device if no path given. */
if (slashp == 0)
strcat (fname, "[000000]");
}
strcat (fname, fbeg);
/* Fix up the filename */
hack_vms_include_specification (fname, vaxc_include);
}
else
{
/* This is a normal VMS filespec, so use it unchanged. */
strcpy (fname, fbeg);
/* if it's '#include filename', add the missing .h */
if (vaxc_include && index(fname,'.')==NULL)
strcat (fname, ".h");
}
#else
strcpy (fname, searchptr->fname);
strcat (fname, fbeg);
#endif /* VMS */
f = open_include_file (fname, searchptr, importing, &inc);
if (f != -1) {
if (bypass_slot && searchptr != first_bracket_include) {
/* This is the first time we found this include file,
and we found it after first_bracket_include.
Record its location so that we can bypass to here next time. */
struct bypass_dir *p
= (struct bypass_dir *) xmalloc (sizeof (struct bypass_dir));
p->next = *bypass_slot;
p->fname = fname + strlen (searchptr->fname);
p->searchptr = searchptr;
*bypass_slot = p;
}
break;
}
#ifdef VMS
/* Our VMS hacks can produce invalid filespecs, so don't worry
about errors other than EACCES. */
if (errno == EACCES)
break;
#else
if (errno != ENOENT && errno != ENOTDIR)
break;
#endif
}
}
if (f < 0) {
if (f == -2) {
/* The file was already included. */
/* If generating dependencies and -MG was specified, we assume missing
files are leaf files, living in the same directory as the source file
or other similar place; these missing files may be generated from
other files and may not exist yet (eg: y.tab.h). */
} else if (print_deps_missing_files
&& (system_include_depth != 0) < print_deps)
{
/* If it was requested as a system header file,
then assume it belongs in the first place to look for such. */
if (angle_brackets)
{
if (search_start) {
char *p = (char *) alloca (strlen (search_start->fname)
+ strlen (fbeg) + 1);
strcpy (p, search_start->fname);
strcat (p, fbeg);
deps_output (p, ' ');
}
}
else
{
/* Otherwise, omit the directory, as if the file existed
in the directory with the source. */
deps_output (fbeg, ' ');
}
}
/* If -M was specified, and this header file won't be added to the
dependency list, then don't count this as an error, because we can
still produce correct output. Otherwise, we can't produce correct
output, because there may be dependencies we need inside the missing
file, and we don't know what directory this missing file exists in. */
else if (0 < print_deps && print_deps <= (system_include_depth != 0))
warning ("No include path in which to find %s", fbeg);
else if (f != -3)
error_from_errno (fbeg);
else
error ("No include path in which to find %s", fbeg);
} else {
/* Actually process the file. */
pcftry = (char *) alloca (strlen (fname) + 30);
pcfbuf = 0;
pcfnum = 0;
if (!no_precomp)
{
do {
sprintf (pcftry, "%s%d", fname, pcfnum++);
pcf = open (pcftry, O_RDONLY, 0666);
if (pcf != -1)
{
struct stat s;
if (fstat (pcf, &s) != 0)
pfatal_with_name (pcftry);
if (! INO_T_EQ (inc->st.st_ino, s.st_ino)
|| inc->st.st_dev != s.st_dev)
{
pcfbuf = check_precompiled (pcf, &s, fname, &pcfbuflimit);
/* Don't need it any more. */
close (pcf);
}
else
{
/* Don't need it at all. */
close (pcf);
break;
}
}
} while (pcf != -1 && !pcfbuf);
}
/* Actually process the file */
if (pcfbuf) {
pcfname = xmalloc (strlen (pcftry) + 1);
strcpy (pcfname, pcftry);
pcfinclude ((U_CHAR *) pcfbuf, (U_CHAR *) fname, op);
}
else
finclude (f, inc, op, is_system_include (fname), searchptr);
}
system_include_depth -= angle_brackets;
return 0;
}
/* Return nonzero if the given FILENAME is an absolute pathname which
designates a file within one of the known "system" include file
directories. We assume here that if the given FILENAME looks like
it is the name of a file which resides either directly in a "system"
include file directory, or within any subdirectory thereof, then the
given file must be a "system" include file. This function tells us
if we should suppress pedantic errors/warnings for the given FILENAME.
The value is 2 if the file is a C-language system header file
for which C++ should (on most systems) assume `extern "C"'. */
static int
is_system_include (filename)
register char *filename;
{
struct file_name_list *searchptr;
for (searchptr = first_system_include; searchptr;
searchptr = searchptr->next)
if (! strncmp (searchptr->fname, filename, strlen (searchptr->fname)))
return searchptr->c_system_include_path + 1;
return 0;
}
/* Yield the non-directory suffix of a file name. */
static char *
base_name (fname)
char *fname;
{
char *s = fname;
char *p;
#if defined (__MSDOS__) || defined (_WIN32)
if (ISALPHA (s[0]) && s[1] == ':') s += 2;
#endif
#ifdef VMS
if ((p = rindex (s, ':'))) s = p + 1; /* Skip device. */
if ((p = rindex (s, ']'))) s = p + 1; /* Skip directory. */
if ((p = rindex (s, '>'))) s = p + 1; /* Skip alternate (int'n'l) dir. */
if (s != fname)
return s;
#endif
if ((p = rindex (s, '/'))) s = p + 1;
#ifdef DIR_SEPARATOR
if ((p = rindex (s, DIR_SEPARATOR))) s = p + 1;
#endif
return s;
}
/* Yield nonzero if FILENAME is absolute (i.e. not relative). */
static int
absolute_filename (filename)
char *filename;
{
#if defined (__MSDOS__) \
|| (defined (_WIN32) && !defined (__CYGWIN__) && !defined (_UWIN))
if (ISALPHA (filename[0]) && filename[1] == ':') filename += 2;
#endif
#if defined (__CYGWIN__)
/* At present, any path that begins with a drive spec is absolute. */
if (ISALPHA (filename[0]) && filename[1] == ':') return 1;
#endif
#ifdef VMS
if (index (filename, ':') != 0) return 1;
#endif
if (filename[0] == '/') return 1;
#ifdef DIR_SEPARATOR
if (filename[0] == DIR_SEPARATOR) return 1;
#endif
return 0;
}
/* Returns whether or not a given character is a directory separator.
Used by simplify_filename. */
static inline
int
is_dir_separator(ch)
char ch;
{
return (ch == DIR_SEPARATOR)
#if defined (DIR_SEPARATOR_2)
|| (ch == DIR_SEPARATOR_2)
#endif
;
}
/* Remove unnecessary characters from FILENAME in place,
to avoid unnecessary filename aliasing.
Return the length of the resulting string.
Do only the simplifications allowed by Posix.
It is OK to miss simplifications on non-Posix hosts,
since this merely leads to suboptimal results. */
static size_t
simplify_filename (filename)
char *filename;
{
register char *from = filename;
register char *to = filename;
char *to0;
/* Remove redundant initial /s. */
if (is_dir_separator (*from))
{
*to++ = DIR_SEPARATOR;
if (is_dir_separator (*++from))
{
if (is_dir_separator (*++from))
{
/* 3 or more initial /s are equivalent to 1 /. */
while (is_dir_separator (*++from))
continue;
}
else
{
/* On some hosts // differs from /; Posix allows this. */
*to++ = DIR_SEPARATOR;
}
}
}
to0 = to;
for (;;)
{
#ifndef VMS
if (from[0] == '.' && from[1] == '/')
from += 2;
else
#endif
{
/* Copy this component and trailing DIR_SEPARATOR, if any. */
while (!is_dir_separator (*to++ = *from++))
{
if (!to[-1])
{
/* Trim . component at end of nonempty name. */
to -= filename <= to - 3 && to[-3] == DIR_SEPARATOR && to[-2] == '.';
/* Trim unnecessary trailing /s. */
while (to0 < --to && to[-1] == DIR_SEPARATOR)
continue;
*to = 0;
return to - filename;
}
}
#if defined(DIR_SEPARATOR_2)
/* Simplify to one directory separator. */
to[-1] = DIR_SEPARATOR;
#endif
}
/* Skip /s after a /. */
while (is_dir_separator (*from))
from++;
}
}
/* The file_name_map structure holds a mapping of file names for a
particular directory. This mapping is read from the file named
FILE_NAME_MAP_FILE in that directory. Such a file can be used to
map filenames on a file system with severe filename restrictions,
such as DOS. The format of the file name map file is just a series
of lines with two tokens on each line. The first token is the name
to map, and the second token is the actual name to use. */
struct file_name_map
{
struct file_name_map *map_next;
char *map_from;
char *map_to;
};
#define FILE_NAME_MAP_FILE "header.gcc"
/* Read a space delimited string of unlimited length from a stdio
file. */
static char *
read_filename_string (ch, f)
int ch;
FILE *f;
{
char *alloc, *set;
int len;
len = 20;
set = alloc = xmalloc (len + 1);
if (! is_space[ch])
{
*set++ = ch;
while ((ch = getc (f)) != EOF && ! is_space[ch])
{
if (set - alloc == len)
{
len *= 2;
alloc = xrealloc (alloc, len + 1);
set = alloc + len / 2;
}
*set++ = ch;
}
}
*set = '\0';
ungetc (ch, f);
return alloc;
}
/* Read the file name map file for DIRNAME.
If DIRNAME is empty, read the map file for the working directory;
otherwise DIRNAME must end in '/'. */
static struct file_name_map *
read_name_map (dirname)
char *dirname;
{
/* This structure holds a linked list of file name maps, one per
directory. */
struct file_name_map_list
{
struct file_name_map_list *map_list_next;
char *map_list_name;
struct file_name_map *map_list_map;
};
static struct file_name_map_list *map_list;
register struct file_name_map_list *map_list_ptr;
char *name;
FILE *f;
size_t dirlen;
for (map_list_ptr = map_list; map_list_ptr;
map_list_ptr = map_list_ptr->map_list_next)
if (! strcmp (map_list_ptr->map_list_name, dirname))
return map_list_ptr->map_list_map;
map_list_ptr = ((struct file_name_map_list *)
xmalloc (sizeof (struct file_name_map_list)));
map_list_ptr->map_list_name = xstrdup (dirname);
map_list_ptr->map_list_map = NULL;
dirlen = strlen (dirname);
name = (char *) alloca (dirlen + strlen (FILE_NAME_MAP_FILE) + 1);
strcpy (name, dirname);
strcat (name, FILE_NAME_MAP_FILE);
f = fopen (name, "r");
if (!f)
map_list_ptr->map_list_map = NULL;
else
{
int ch;
while ((ch = getc (f)) != EOF)
{
char *from, *to;
struct file_name_map *ptr;
size_t tolen;
if (is_space[ch])
continue;
from = read_filename_string (ch, f);
while ((ch = getc (f)) != EOF && is_hor_space[ch])
;
to = read_filename_string (ch, f);
simplify_filename (from);
tolen = simplify_filename (to);
ptr = ((struct file_name_map *)
xmalloc (sizeof (struct file_name_map)));
ptr->map_from = from;
/* Make the real filename absolute. */
if (absolute_filename (to))
ptr->map_to = to;
else
{
ptr->map_to = xmalloc (dirlen + tolen + 1);
strcpy (ptr->map_to, dirname);
strcat (ptr->map_to, to);
free (to);
}
ptr->map_next = map_list_ptr->map_list_map;
map_list_ptr->map_list_map = ptr;
while ((ch = getc (f)) != '\n')
if (ch == '\r')
continue;
if (ch == EOF)
break;
}
fclose (f);
}
map_list_ptr->map_list_next = map_list;
map_list = map_list_ptr;
return map_list_ptr->map_list_map;
}
/* Try to open include file FILENAME. SEARCHPTR is the directory
being tried from the include file search path.
IMPORTING is "" if we are importing, null otherwise.
Return -2 if found, either a matching name or a matching inode.
Otherwise, open the file and return a file descriptor if successful
or -1 if unsuccessful.
Unless unsuccessful, put a descriptor of the included file into *PINC.
This function maps filenames on file systems based on information read by
read_name_map. */
static int
open_include_file (filename, searchptr, importing, pinc)
char *filename;
struct file_name_list *searchptr;
U_CHAR *importing;
struct include_file **pinc;
{
char *fname = remap ? remap_include_file (filename, searchptr) : filename;
int fd = -2;
/* Look up FNAME in include_hashtab. */
struct include_file **phead = &include_hashtab[hashf ((U_CHAR *) fname,
strlen (fname),
INCLUDE_HASHSIZE)];
struct include_file *inc, *head = *phead;
for (inc = head; inc; inc = inc->next)
if (!strcmp (fname, inc->fname))
break;
if (!inc
|| ! inc->control_macro
|| (inc->control_macro[0] && ! lookup (inc->control_macro, -1, -1))) {
fd = open (fname, O_RDONLY, 0);
if (fd < 0)
{
#ifdef VMS
/* if #include <dir/file> fails, try again with hacked spec. */
if (!hack_vms_include_specification (fname, 0))
return fd;
fd = open (fname, O_RDONLY, 0);
if (fd < 0)
#endif
return fd;
}
if (!inc) {
/* FNAME was not in include_hashtab; insert a new entry. */
inc = (struct include_file *) xmalloc (sizeof (struct include_file));
inc->next = head;
inc->fname = fname;
inc->control_macro = 0;
inc->deps_output = 0;
if (fstat (fd, &inc->st) != 0)
pfatal_with_name (fname);
*phead = inc;
/* Look for another file with the same inode and device. */
if (lookup_ino_include (inc)
&& inc->control_macro
&& (!inc->control_macro[0] || lookup (inc->control_macro, -1, -1))) {
close (fd);
fd = -2;
}
}
/* For -M, add this file to the dependencies. */
if (! inc->deps_output && (system_include_depth != 0) < print_deps) {
inc->deps_output = 1;
deps_output (fname, ' ');
}
/* Handle -H option. */
if (print_include_names)
fprintf (stderr, "%*s%s\n", indepth, "", fname);
}
if (importing)
inc->control_macro = importing;
*pinc = inc;
return fd;
}
/* Return the remapped name of the include file FILENAME.
SEARCHPTR is the directory being tried from the include file path. */
static char *
remap_include_file (filename, searchptr)
char *filename;
struct file_name_list *searchptr;
{
register struct file_name_map *map;
register char *from;
if (searchptr)
{
if (! searchptr->got_name_map)
{
searchptr->name_map = read_name_map (searchptr->fname);
searchptr->got_name_map = 1;
}
/* Check the mapping for the directory we are using. */
from = filename + strlen (searchptr->fname);
for (map = searchptr->name_map; map; map = map->map_next)
if (! strcmp (map->map_from, from))
return map->map_to;
}
from = base_name (filename);
if (from != filename || !searchptr)
{
/* Try to find a mapping file for the particular directory we are
looking in. Thus #include <sys/types.h> will look up sys/types.h
in /usr/include/header.gcc and look up types.h in
/usr/include/sys/header.gcc. */
char *dir = (char *) alloca (from - filename + 1);
bcopy (filename, dir, from - filename);
dir[from - filename] = '\0';
for (map = read_name_map (dir); map; map = map->map_next)
if (! strcmp (map->map_from, from))
return map->map_to;
}
return filename;
}
/* Insert INC into the include file table, hashed by device and inode number.
If a file with different name but same dev+ino was already in the table,
return 1 and set INC's control macro to the already-known macro. */
static int
lookup_ino_include (inc)
struct include_file *inc;
{
int hash = ((unsigned) (inc->st.st_dev + INO_T_HASH (inc->st.st_ino))
% INCLUDE_HASHSIZE);
struct include_file *i = include_ino_hashtab[hash];
inc->next_ino = i;
include_ino_hashtab[hash] = inc;
for (; i; i = i->next_ino)
if (INO_T_EQ (inc->st.st_ino, i->st.st_ino)
&& inc->st.st_dev == i->st.st_dev) {
inc->control_macro = i->control_macro;
return 1;
}
return 0;
}
/* Process file descriptor F, which corresponds to include file INC,
with output to OP.
SYSTEM_HEADER_P is 1 if this file resides in any one of the known
"system" include directories (as decided by the `is_system_include'
function above).
DIRPTR is the link in the dir path through which this file was found,
or 0 if the file name was absolute. */
static void
finclude (f, inc, op, system_header_p, dirptr)
int f;
struct include_file *inc;
FILE_BUF *op;
int system_header_p;
struct file_name_list *dirptr;
{
char *fname = inc->fname;
int i;
FILE_BUF *fp; /* For input stack frame */
int missing_newline = 0;
CHECK_DEPTH (return;);
fp = &instack[indepth + 1];
bzero ((char *) fp, sizeof (FILE_BUF));
fp->nominal_fname = fp->fname = fname;
fp->nominal_fname_len = strlen (fname);
fp->inc = inc;
fp->length = 0;
fp->lineno = 1;
fp->if_stack = if_stack;
fp->system_header_p = system_header_p;
fp->dir = dirptr;
if (S_ISREG (inc->st.st_mode)) {
size_t s = (size_t) inc->st.st_size;
if (s != inc->st.st_size || s + 2 < s)
memory_full ();
fp->buf = (U_CHAR *) xmalloc (s + 2);
fp->bufp = fp->buf;
/* Read the file contents, knowing that s is an upper bound
on the number of bytes we can read. */
fp->length = safe_read (f, (char *) fp->buf, s);
if (fp->length < 0) goto nope;
}
else if (S_ISDIR (inc->st.st_mode)) {
error ("directory `%s' specified in #include", fname);
close (f);
return;
} else {
/* Cannot count its file size before reading.
First read the entire file into heap and
copy them into buffer on stack. */
int bsize = 2000;
int st_size = 0;
fp->buf = (U_CHAR *) xmalloc (bsize + 2);
for (;;) {
i = safe_read (f, (char *) fp->buf + st_size, bsize - st_size);
if (i < 0)
goto nope; /* error! */
if (i == 0)
break; /* End of file */
st_size += i;
bsize *= 2;
fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
}
fp->bufp = fp->buf;
fp->length = st_size;
}
if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n')
/* Backslash-newline at end is not good enough. */
|| (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) {
fp->buf[fp->length++] = '\n';
missing_newline = 1;
}
fp->buf[fp->length] = '\0';
/* Close descriptor now, so nesting does not use lots of descriptors. */
close (f);
/* Must do this before calling trigraph_pcp, so that the correct file name
will be printed in warning messages. */
indepth++;
input_file_stack_tick++;
if (!no_trigraphs)
trigraph_pcp (fp);
output_line_directive (fp, op, 0, enter_file);
rescan (op, 0);
if (missing_newline)
fp->lineno--;
if (pedantic && missing_newline)
pedwarn ("file does not end in newline");
indepth--;
input_file_stack_tick++;
output_line_directive (&instack[indepth], op, 0, leave_file);
free (fp->buf);
return;
nope:
perror_with_name (fname);
close (f);
free (fp->buf);
}
/* Record that inclusion of the include file INC
should be controlled by the macro named MACRO_NAME.
This means that trying to include the file again
will do something if that macro is defined. */
static void
record_control_macro (inc, macro_name)
struct include_file *inc;
U_CHAR *macro_name;
{
if (!inc->control_macro || inc->control_macro[0])
inc->control_macro = macro_name;
}
/* Load the specified precompiled header into core, and verify its
preconditions. PCF indicates the file descriptor to read, which must
be a regular file. *ST is its file status.
FNAME indicates the file name of the original header.
*LIMIT will be set to an address one past the end of the file.
If the preconditions of the file are not satisfied, the buffer is
freed and we return 0. If the preconditions are satisfied, return
the address of the buffer following the preconditions. The buffer, in
this case, should never be freed because various pieces of it will
be referred to until all precompiled strings are output at the end of
the run. */
static char *
check_precompiled (pcf, st, fname, limit)
int pcf;
struct stat *st;
char *fname ATTRIBUTE_UNUSED;
char **limit;
{
int length = 0;
char *buf;
char *cp;
if (pcp_outfile)
return 0;
if (S_ISREG (st->st_mode))
{
size_t s = (size_t) st->st_size;
if (s != st->st_size || s + 2 < s)
memory_full ();
buf = xmalloc (s + 2);
length = safe_read (pcf, buf, s);
if (length < 0)
goto nope;
}
else
abort ();
if (length > 0 && buf[length-1] != '\n')
buf[length++] = '\n';
buf[length] = '\0';
*limit = buf + length;
/* File is in core. Check the preconditions. */
if (!check_preconditions (buf))
goto nope;
for (cp = buf; *cp; cp++)
;
#ifdef DEBUG_PCP
fprintf (stderr, "Using preinclude %s\n", fname);
#endif
return cp + 1;
nope:
#ifdef DEBUG_PCP
fprintf (stderr, "Cannot use preinclude %s\n", fname);
#endif
free (buf);
return 0;
}
/* PREC (null terminated) points to the preconditions of a
precompiled header. These are a series of #define and #undef
lines which must match the current contents of the hash
table. */
static int
check_preconditions (prec)
char *prec;
{
MACRODEF mdef;
char *lineend;
while (*prec) {
lineend = index (prec, '\n');
if (*prec++ != '#') {
error ("Bad format encountered while reading precompiled file");
return 0;
}
if (!strncmp (prec, "define", 6)) {
HASHNODE *hp;
prec += 6;
mdef = create_definition ((U_CHAR *) prec, (U_CHAR *) lineend, NULL_PTR);
if (mdef.defn == 0)
abort ();
if ((hp = lookup (mdef.symnam, mdef.symlen, -1)) == NULL
|| (hp->type != T_MACRO && hp->type != T_CONST)
|| (hp->type == T_MACRO
&& !compare_defs (mdef.defn, hp->value.defn)
&& (mdef.defn->length != 2
|| mdef.defn->expansion[0] != '\n'
|| mdef.defn->expansion[1] != ' ')))
return 0;
} else if (!strncmp (prec, "undef", 5)) {
char *name;
int len;
prec += 5;
while (is_hor_space[(U_CHAR) *prec])
prec++;
name = prec;
while (is_idchar[(U_CHAR) *prec])
prec++;
len = prec - name;
if (lookup ((U_CHAR *) name, len, -1))
return 0;
} else {
error ("Bad format encountered while reading precompiled file");
return 0;
}
prec = lineend + 1;
}
/* They all passed successfully */
return 1;
}
/* Process the main body of a precompiled file. BUF points to the
string section of the file, following the preconditions. LIMIT is one
character past the end. NAME is the name of the file being read
in. OP is the main output buffer. */
static void
pcfinclude (buf, name, op)
U_CHAR *buf, *name;
FILE_BUF *op;
{
FILE_BUF tmpbuf;
int nstrings;
U_CHAR *cp = buf;
/* First in the file comes 4 bytes indicating the number of strings, */
/* in network byte order. (MSB first). */
nstrings = *cp++;
nstrings = (nstrings << 8) | *cp++;
nstrings = (nstrings << 8) | *cp++;
nstrings = (nstrings << 8) | *cp++;
/* Looping over each string... */
while (nstrings--) {
U_CHAR *string_start;
U_CHAR *endofthiskey;
STRINGDEF *str;
int nkeys;
/* Each string starts with a STRINGDEF structure (str), followed */
/* by the text of the string (string_start) */
/* First skip to a longword boundary */
/* ??? Why a 4-byte boundary? On all machines? */
/* NOTE: This works correctly even if size_t
is narrower than a pointer.
Do not try risky measures here to get another type to use!
Do not include stddef.h--it will fail! */
if ((size_t) cp & 3)
cp += 4 - ((size_t) cp & 3);
/* Now get the string. */
str = (STRINGDEF *) (GENERIC_PTR) cp;
string_start = cp += sizeof (STRINGDEF);
for (; *cp; cp++) /* skip the string */
;
/* We need to macro expand the string here to ensure that the
proper definition environment is in place. If it were only
expanded when we find out it is needed, macros necessary for
its proper expansion might have had their definitions changed. */
tmpbuf = expand_to_temp_buffer (string_start, cp++, 0, 0);
/* Lineno is already set in the precompiled file */
str->contents = tmpbuf.buf;
str->len = tmpbuf.length;
str->writeflag = 0;
str->filename = name;
str->output_mark = outbuf.bufp - outbuf.buf;
str->chain = 0;
*stringlist_tailp = str;
stringlist_tailp = &str->chain;
/* Next comes a fourbyte number indicating the number of keys
for this string. */
nkeys = *cp++;
nkeys = (nkeys << 8) | *cp++;
nkeys = (nkeys << 8) | *cp++;
nkeys = (nkeys << 8) | *cp++;
/* If this number is -1, then the string is mandatory. */
if (nkeys == -1)
str->writeflag = 1;
else
/* Otherwise, for each key, */
for (; nkeys--; free (tmpbuf.buf), cp = endofthiskey + 1) {
KEYDEF *kp = (KEYDEF *) (GENERIC_PTR) cp;
HASHNODE *hp;
/* It starts with a KEYDEF structure */
cp += sizeof (KEYDEF);
/* Find the end of the key. At the end of this for loop we
advance CP to the start of the next key using this variable. */
endofthiskey = cp + strlen ((char *) cp);
kp->str = str;
/* Expand the key, and enter it into the hash table. */
tmpbuf = expand_to_temp_buffer (cp, endofthiskey, 0, 0);
tmpbuf.bufp = tmpbuf.buf;
while (is_hor_space[*tmpbuf.bufp])
tmpbuf.bufp++;
if (!is_idstart[*tmpbuf.bufp]
|| tmpbuf.bufp == tmpbuf.buf + tmpbuf.length) {
str->writeflag = 1;
continue;
}
hp = lookup (tmpbuf.bufp, -1, -1);
if (hp == NULL) {
kp->chain = 0;
install (tmpbuf.bufp, -1, T_PCSTRING, (char *) kp, -1);
}
else if (hp->type == T_PCSTRING) {
kp->chain = hp->value.keydef;
hp->value.keydef = kp;
}
else
str->writeflag = 1;
}
}
/* This output_line_directive serves to switch us back to the current
input file in case some of these strings get output (which will
result in line directives for the header file being output). */
output_line_directive (&instack[indepth], op, 0, enter_file);
}
/* Called from rescan when it hits a key for strings. Mark them all
used and clean up. */
static void
pcstring_used (hp)
HASHNODE *hp;
{
KEYDEF *kp;
for (kp = hp->value.keydef; kp; kp = kp->chain)
kp->str->writeflag = 1;
delete_macro (hp);
}
/* Write the output, interspersing precompiled strings in their
appropriate places. */
static void
write_output ()
{
STRINGDEF *next_string;
U_CHAR *cur_buf_loc;
int line_directive_len = 80;
char *line_directive = xmalloc (line_directive_len);
int len;
/* In each run through the loop, either cur_buf_loc ==
next_string_loc, in which case we print a series of strings, or
it is less than next_string_loc, in which case we write some of
the buffer. */
cur_buf_loc = outbuf.buf;
next_string = stringlist;
while (cur_buf_loc < outbuf.bufp || next_string) {
if (next_string
&& cur_buf_loc - outbuf.buf == next_string->output_mark) {
if (next_string->writeflag) {
len = 4 * strlen ((char *) next_string->filename) + 32;
while (len > line_directive_len)
line_directive = xrealloc (line_directive,
line_directive_len *= 2);
sprintf (line_directive, "\n# %d ", next_string->lineno);
strcpy (quote_string (line_directive + strlen (line_directive),
(char *) next_string->filename,
strlen ((char *) next_string->filename)),
"\n");
safe_write (fileno (stdout), line_directive, strlen (line_directive));
safe_write (fileno (stdout),
(char *) next_string->contents, next_string->len);
}
next_string = next_string->chain;
}
else {
len = (next_string
? (next_string->output_mark
- (cur_buf_loc - outbuf.buf))
: outbuf.bufp - cur_buf_loc);
safe_write (fileno (stdout), (char *) cur_buf_loc, len);
cur_buf_loc += len;
}
}
free (line_directive);
}
/* Pass a directive through to the output file.
BUF points to the contents of the directive, as a contiguous string.
LIMIT points to the first character past the end of the directive.
KEYWORD is the keyword-table entry for the directive. */
static void
pass_thru_directive (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
struct directive *keyword;
{
register int keyword_length = keyword->length;
check_expand (op, 1 + keyword_length + (limit - buf));
*op->bufp++ = '#';
bcopy (keyword->name, (char *) op->bufp, keyword_length);
op->bufp += keyword_length;
if (limit != buf && buf[0] != ' ')
*op->bufp++ = ' ';
bcopy ((char *) buf, (char *) op->bufp, limit - buf);
op->bufp += (limit - buf);
#if 0
*op->bufp++ = '\n';
/* Count the line we have just made in the output,
to get in sync properly. */
op->lineno++;
#endif
}
/* The arglist structure is built by do_define to tell
collect_definition where the argument names begin. That
is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
would contain pointers to the strings x, y, and z.
Collect_definition would then build a DEFINITION node,
with reflist nodes pointing to the places x, y, and z had
appeared. So the arglist is just convenience data passed
between these two routines. It is not kept around after
the current #define has been processed and entered into the
hash table. */
struct arglist {
struct arglist *next;
U_CHAR *name;
int length;
int argno;
char rest_args;
};
/* Create a DEFINITION node from a #define directive. Arguments are
as for do_define. */
static MACRODEF
create_definition (buf, limit, op)
U_CHAR *buf, *limit;
FILE_BUF *op;
{
U_CHAR *bp; /* temp ptr into input buffer */
U_CHAR *symname; /* remember where symbol name starts */
int sym_length; /* and how long it is */
int line = instack[indepth].lineno;
char *file = instack[indepth].nominal_fname;
size_t file_len = instack[indepth].nominal_fname_len;
int rest_args = 0;
DEFINITION *defn;
int arglengths = 0; /* Accumulate lengths of arg names
plus number of args. */
MACRODEF mdef;
bp = buf;
while (is_hor_space[*bp])
bp++;
symname = bp; /* remember where it starts */
sym_length = check_macro_name (bp, 0);
bp += sym_length;
/* Lossage will occur if identifiers or control keywords are broken
across lines using backslash. This is not the right place to take
care of that. */
if (*bp == '(') {
struct arglist *arg_ptrs = NULL;
int argno = 0;
bp++; /* skip '(' */
SKIP_WHITE_SPACE (bp);
/* Loop over macro argument names. */
while (*bp != ')') {
struct arglist *temp;
temp = (struct arglist *) alloca (sizeof (struct arglist));
temp->name = bp;
temp->next = arg_ptrs;
temp->argno = argno++;
temp->rest_args = 0;
arg_ptrs = temp;
if (rest_args)
pedwarn ("another parameter follows `%s'",
rest_extension);
if (!is_idstart[*bp])
{
if (c9x && limit - bp > (long) REST_EXTENSION_LENGTH
&& bcmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0)
{
/* This is the ISO C 9x way to write macros with variable
number of arguments. */
rest_args = 1;
temp->rest_args = 1;
}
else
pedwarn ("invalid character in macro parameter name");
}
/* Find the end of the arg name. */
while (is_idchar[*bp]) {
bp++;
/* do we have a "special" rest-args extension here? */
if (limit - bp > (long) REST_EXTENSION_LENGTH
&& bcmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
if (pedantic && !instack[indepth].system_header_p)
pedwarn ("ANSI C does not allow macro with variable arguments");
rest_args = 1;
temp->rest_args = 1;
break;
}
}
if (bp == temp->name && rest_args == 1)
{
/* This is the ISO C 9x style. */
temp->name = (U_CHAR *) va_args_name;
temp->length = VA_ARGS_NAME_LENGTH;
}
else
temp->length = bp - temp->name;
if (rest_args == 1)
bp += REST_EXTENSION_LENGTH;
arglengths += temp->length + 2;
SKIP_WHITE_SPACE (bp);
if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
error ("badly punctuated parameter list in `#define'");
goto nope;
}
if (*bp == ',') {
bp++;
SKIP_WHITE_SPACE (bp);
/* A comma at this point can only be followed by an identifier. */
if (!is_idstart[*bp]
&& !(c9x && limit - bp > (long) REST_EXTENSION_LENGTH
&& bcmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0)) {
error ("badly punctuated parameter list in `#define'");
goto nope;
}
}
if (bp >= limit) {
error ("unterminated parameter list in `#define'");
goto nope;
}
{
struct arglist *otemp;
for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
if (temp->length == otemp->length
&& bcmp (temp->name, otemp->name, temp->length) == 0)
{
error ("duplicate argument name `%.*s' in `#define'",
temp->length, temp->name);
goto nope;
}
if (rest_args == 0 && temp->length == VA_ARGS_NAME_LENGTH
&& bcmp (temp->name, va_args_name, VA_ARGS_NAME_LENGTH) == 0)
{
error ("\
reserved name `%s' used as argument name in `#define'", va_args_name);
goto nope;
}
}
}
++bp; /* skip paren */
SKIP_WHITE_SPACE (bp);
/* now everything from bp before limit is the definition. */
defn = collect_expansion (bp, limit, argno, arg_ptrs);
defn->rest_args = rest_args;
/* Now set defn->args.argnames to the result of concatenating
the argument names in reverse order
with comma-space between them. */
defn->args.argnames = (U_CHAR *) xmalloc (arglengths + 1);
{
struct arglist *temp;
int i = 0;
for (temp = arg_ptrs; temp; temp = temp->next) {
bcopy (temp->name, &defn->args.argnames[i], temp->length);
i += temp->length;
if (temp->next != 0) {
defn->args.argnames[i++] = ',';
defn->args.argnames[i++] = ' ';
}
}
defn->args.argnames[i] = 0;
}
} else {
/* Simple expansion or empty definition. */
if (bp < limit)
{
if (is_hor_space[*bp]) {
bp++;
SKIP_WHITE_SPACE (bp);
} else if (sym_length) {
switch (*bp) {
case '!': case '"': case '#': case '%': case '&': case '\'':
case ')': case '*': case '+': case ',': case '-': case '.':
case '/': case ':': case ';': case '<': case '=': case '>':
case '?': case '[': case '\\': case ']': case '^': case '{':
case '|': case '}': case '~':
warning ("missing white space after `#define %.*s'",
sym_length, symname);
break;
default:
pedwarn ("missing white space after `#define %.*s'",
sym_length, symname);
break;
}
}
}
/* Now everything from bp before limit is the definition. */
defn = collect_expansion (bp, limit, -1, NULL_PTR);
defn->args.argnames = (U_CHAR *) "";
}
defn->line = line;
defn->file = file;
defn->file_len = file_len;
/* OP is null if this is a predefinition */
defn->predefined = !op;
mdef.defn = defn;
mdef.symnam = symname;
mdef.symlen = sym_length;
return mdef;
nope:
mdef.symnam = NULL; /* AMB - remove gcc-4.0 warning */
mdef.symlen = 0; /* AMB - remove gcc-4.0 warning */
mdef.defn = 0;
return mdef;
}
/* Process a #define directive.
BUF points to the contents of the #define directive, as a contiguous string.
LIMIT points to the first character past the end of the definition.
KEYWORD is the keyword-table entry for #define. */
static int
do_define (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
struct directive *keyword;
{
int hashcode;
MACRODEF mdef;
/* If this is a precompiler run (with -pcp) pass thru #define directives. */
if (pcp_outfile && op)
pass_thru_directive (buf, limit, op, keyword);
mdef = create_definition (buf, limit, op);
if (mdef.defn == 0)
goto nope;
hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE);
{
HASHNODE *hp;
if ((hp = lookup (mdef.symnam, mdef.symlen, hashcode)) != NULL) {
int ok = 0;
/* Redefining a precompiled key is ok. */
if (hp->type == T_PCSTRING)
ok = 1;
/* Redefining a macro is ok if the definitions are the same. */
else if (hp->type == T_MACRO)
ok = ! compare_defs (mdef.defn, hp->value.defn);
/* Redefining a constant is ok with -D. */
else if (hp->type == T_CONST)
ok = ! done_initializing;
/* Print the warning if it's not ok. */
if (!ok) {
/* If we are passing through #define and #undef directives, do
that for this re-definition now. */
if (debug_output && op)
pass_thru_directive (buf, limit, op, keyword);
pedwarn ("`%.*s' redefined", mdef.symlen, mdef.symnam);
if (hp->type == T_MACRO)
pedwarn_with_file_and_line (hp->value.defn->file,
hp->value.defn->file_len,
hp->value.defn->line,
"this is the location of the previous definition");
}
/* Replace the old definition. */
hp->type = T_MACRO;
hp->value.defn = mdef.defn;
} else {
/* If we are passing through #define and #undef directives, do
that for this new definition now. */
if (debug_output && op)
pass_thru_directive (buf, limit, op, keyword);
install (mdef.symnam, mdef.symlen, T_MACRO,
(char *) mdef.defn, hashcode);
}
}
return 0;
nope:
return 1;
}
/* Check a purported macro name SYMNAME, and yield its length.
ASSERTION is nonzero if this is really for an assertion name. */
static int
check_macro_name (symname, assertion)
U_CHAR *symname;
int assertion;
{
U_CHAR *p;
int sym_length;
for (p = symname; is_idchar[*p]; p++)
;
sym_length = p - symname;
if (sym_length == 0
|| (sym_length == 1 && *symname == 'L' && (*p == '\'' || *p == '"')))
error (assertion ? "invalid assertion name" : "invalid macro name");
else if (!is_idstart[*symname]
|| (sym_length == 7 && ! bcmp (symname, "defined", 7)))
error ((assertion
? "invalid assertion name `%.*s'"
: "invalid macro name `%.*s'"),
sym_length, symname);
return sym_length;
}
/* Return zero if two DEFINITIONs are isomorphic. */
static int
compare_defs (d1, d2)
DEFINITION *d1, *d2;
{
register struct reflist *a1, *a2;
register U_CHAR *p1 = d1->expansion;
register U_CHAR *p2 = d2->expansion;
int first = 1;
if (d1->nargs != d2->nargs)
return 1;
if (pedantic
&& strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames))
return 1;
for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2;
a1 = a1->next, a2 = a2->next) {
if (!((a1->nchars == a2->nchars && ! bcmp (p1, p2, a1->nchars))
|| ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0))
|| a1->argno != a2->argno
|| a1->stringify != a2->stringify
|| a1->raw_before != a2->raw_before
|| a1->raw_after != a2->raw_after)
return 1;
first = 0;
p1 += a1->nchars;
p2 += a2->nchars;
}
if (a1 != a2)
return 1;
if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
p2, d2->length - (p2 - d2->expansion), 1))
return 1;
return 0;
}
/* Return 1 if two parts of two macro definitions are effectively different.
One of the parts starts at BEG1 and has LEN1 chars;
the other has LEN2 chars at BEG2.
Any sequence of whitespace matches any other sequence of whitespace.
FIRST means these parts are the first of a macro definition;
so ignore leading whitespace entirely.
LAST means these parts are the last of a macro definition;
so ignore trailing whitespace entirely. */
static int
comp_def_part (first, beg1, len1, beg2, len2, last)
int first;
U_CHAR *beg1, *beg2;
int len1, len2;
int last;
{
register U_CHAR *end1 = beg1 + len1;
register U_CHAR *end2 = beg2 + len2;
if (first) {
while (beg1 != end1 && is_space[*beg1]) beg1++;
while (beg2 != end2 && is_space[*beg2]) beg2++;
}
if (last) {
while (beg1 != end1 && is_space[end1[-1]]) end1--;
while (beg2 != end2 && is_space[end2[-1]]) end2--;
}
while (beg1 != end1 && beg2 != end2) {
if (is_space[*beg1] && is_space[*beg2]) {
while (beg1 != end1 && is_space[*beg1]) beg1++;
while (beg2 != end2 && is_space[*beg2]) beg2++;
} else if (*beg1 == *beg2) {
beg1++; beg2++;
} else break;
}
return (beg1 != end1) || (beg2 != end2);
}
/* Read a replacement list for a macro with parameters.
Build the DEFINITION structure.
Reads characters of text starting at BUF until END.
ARGLIST specifies the formal parameters to look for
in the text of the definition; NARGS is the number of args
in that list, or -1 for a macro name that wants no argument list.
MACRONAME is the macro name itself (so we can avoid recursive expansion)
and NAMELEN is its length in characters.
Note that comments, backslash-newlines, and leading white space
have already been deleted from the argument. */
/* If there is no trailing whitespace, a Newline Space is added at the end
to prevent concatenation that would be contrary to the standard. */
static DEFINITION *
collect_expansion (buf, end, nargs, arglist)
U_CHAR *buf, *end;
int nargs;
struct arglist *arglist;
{
DEFINITION *defn;
register U_CHAR *p, *limit, *lastp, *exp_p;
struct reflist *endpat = NULL;
/* Pointer to first nonspace after last ## seen. */
U_CHAR *concat = 0;
/* Pointer to first nonspace after last single-# seen. */
U_CHAR *stringify = 0;
/* How those tokens were spelled. */
enum sharp_token_type concat_sharp_token_type = NO_SHARP_TOKEN;
enum sharp_token_type stringify_sharp_token_type = NO_SHARP_TOKEN;
int maxsize;
int expected_delimiter = '\0';
/* Scan thru the replacement list, ignoring comments and quoted
strings, picking up on the macro calls. It does a linear search
thru the arg list on every potential symbol. Profiling might say
that something smarter should happen. */
if (end < buf)
abort ();
/* Find the beginning of the trailing whitespace. */
limit = end;
p = buf;
while (p < limit && is_space[limit[-1]]) limit--;
/* Allocate space for the text in the macro definition.
Each input char may or may not need 1 byte,
so this is an upper bound.
The extra 3 are for invented trailing newline-marker and final null. */
maxsize = (sizeof (DEFINITION)
+ (limit - p) + 3);
defn = (DEFINITION *) xcalloc (1, maxsize);
defn->nargs = nargs;
exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION);
lastp = exp_p;
if (p[0] == '#'
? p[1] == '#'
: p[0] == '%' && p[1] == ':' && p[2] == '%' && p[3] == ':') {
error ("`##' at start of macro definition");
p += p[0] == '#' ? 2 : 4;
}
/* Process the main body of the definition. */
while (p < limit) {
int skipped_arg = 0;
register U_CHAR c = *p++;
*exp_p++ = c;
if (!traditional) {
switch (c) {
case '\'':
case '\"':
if (expected_delimiter != '\0') {
if (c == expected_delimiter)
expected_delimiter = '\0';
} else
expected_delimiter = c;
break;
case '\\':
if (p < limit && expected_delimiter) {
/* In a string, backslash goes through
and makes next char ordinary. */
*exp_p++ = *p++;
}
break;
case '%':
if (!expected_delimiter && *p == ':') {
/* %: is not a digraph if preceded by an odd number of '<'s. */
U_CHAR *p0 = p - 1;
while (buf < p0 && p0[-1] == '<')
p0--;
if ((p - p0) & 1) {
/* Treat %:%: as ## and %: as #. */
if (p[1] == '%' && p[2] == ':') {
p += 2;
goto sharp_sharp_token;
}
if (nargs >= 0) {
p++;
goto sharp_token;
}
}
}
break;
case '#':
/* # is ordinary inside a string. */
if (expected_delimiter)
break;
if (*p == '#') {
sharp_sharp_token:
/* ##: concatenate preceding and following tokens. */
/* Take out the first #, discard preceding whitespace. */
exp_p--;
while (exp_p > lastp && is_hor_space[exp_p[-1]])
--exp_p;
/* Skip the second #. */
p++;
concat_sharp_token_type = c;
if (is_hor_space[*p]) {
concat_sharp_token_type = c + 1;
p++;
SKIP_WHITE_SPACE (p);
}
concat = p;
if (p == limit)
error ("`##' at end of macro definition");
} else if (nargs >= 0) {
/* Single #: stringify following argument ref.
Don't leave the # in the expansion. */
sharp_token:
exp_p--;
stringify_sharp_token_type = c;
if (is_hor_space[*p]) {
stringify_sharp_token_type = c + 1;
p++;
SKIP_WHITE_SPACE (p);
}
if (! is_idstart[*p] || nargs == 0
|| (*p == 'L' && (p[1] == '\'' || p[1] == '"')))
error ("`#' operator is not followed by a macro argument name");
else
stringify = p;
}
break;
}
} else {
/* In -traditional mode, recognize arguments inside strings and
character constants, and ignore special properties of #.
Arguments inside strings are considered "stringified", but no
extra quote marks are supplied. */
switch (c) {
case '\'':
case '\"':
if (expected_delimiter != '\0') {
if (c == expected_delimiter)
expected_delimiter = '\0';
} else
expected_delimiter = c;
break;
case '\\':
/* Backslash quotes delimiters and itself, but not macro args. */
if (expected_delimiter != 0 && p < limit
&& (*p == expected_delimiter || *p == '\\')) {
*exp_p++ = *p++;
continue;
}
break;
case '/':
if (expected_delimiter != '\0') /* No comments inside strings. */
break;
if (*p == '*') {
/* If we find a comment that wasn't removed by handle_directive,
this must be -traditional. So replace the comment with
nothing at all. */
exp_p--;
while (++p < limit) {
if (p[0] == '*' && p[1] == '/') {
p += 2;
break;
}
}
#if 0
/* Mark this as a concatenation-point, as if it had been ##. */
concat = p;
#endif
}
break;
}
}
#ifdef MULTIBYTE_CHARS
/* Handle multibyte characters inside string and character literals. */
if (expected_delimiter != '\0')
{
int length;
--p;
length = local_mblen (p, limit - p);
if (length > 1)
{
--exp_p;
bcopy (p, exp_p, length);
p += length;
exp_p += length;
continue;
}
++p;
}
#endif
/* Handle the start of a symbol. */
if (is_idchar[c] && nargs > 0) {
U_CHAR *id_beg = p - 1;
int id_len;
--exp_p;
while (p != limit && is_idchar[*p]) p++;
id_len = p - id_beg;
if (is_idstart[c]
&& ! (id_len == 1 && c == 'L' && (*p == '\'' || *p == '"'))) {
register struct arglist *arg;
for (arg = arglist; arg != NULL; arg = arg->next) {
struct reflist *tpat;
if (arg->name[0] == c
&& arg->length == id_len
&& bcmp (arg->name, id_beg, id_len) == 0) {
enum sharp_token_type tpat_stringify;
if (expected_delimiter) {
if (warn_stringify) {
if (traditional) {
warning ("macro argument `%.*s' is stringified.",
id_len, arg->name);
} else {
warning ("macro arg `%.*s' would be stringified with -traditional.",
id_len, arg->name);
}
}
/* If ANSI, don't actually substitute inside a string. */
if (!traditional)
break;
tpat_stringify = SHARP_TOKEN;
} else {
tpat_stringify
= (stringify == id_beg
? stringify_sharp_token_type : NO_SHARP_TOKEN);
}
/* make a pat node for this arg and append it to the end of
the pat list */
tpat = (struct reflist *) xmalloc (sizeof (struct reflist));
tpat->next = NULL;
tpat->raw_before
= concat == id_beg ? concat_sharp_token_type : NO_SHARP_TOKEN;
tpat->raw_after = NO_SHARP_TOKEN;
tpat->rest_args = arg->rest_args;
tpat->stringify = tpat_stringify;
if (endpat == NULL)
defn->pattern = tpat;
else
endpat->next = tpat;
endpat = tpat;
tpat->argno = arg->argno;
tpat->nchars = exp_p - lastp;
{
register U_CHAR *p1 = p;
SKIP_WHITE_SPACE (p1);
if (p1[0]=='#'
? p1[1]=='#'
: p1[0]=='%' && p1[1]==':' && p1[2]=='%' && p1[3]==':')
tpat->raw_after = p1[0] + (p != p1);
}
lastp = exp_p; /* place to start copying from next time */
skipped_arg = 1;
break;
}
}
}
/* If this was not a macro arg, copy it into the expansion. */
if (! skipped_arg) {
register U_CHAR *lim1 = p;
p = id_beg;
while (p != lim1)
*exp_p++ = *p++;
if (stringify == id_beg)
error ("`#' operator should be followed by a macro argument name");
}
}
}
if (!traditional && expected_delimiter == 0) {
/* If ANSI, put in a newline-space marker to prevent token pasting.
But not if "inside a string" (which in ANSI mode happens only for
-D option). */
*exp_p++ = '\n';
*exp_p++ = ' ';
}
*exp_p = '\0';
defn->length = exp_p - defn->expansion;
/* Crash now if we overrun the allocated size. */
if (defn->length + 1 > maxsize)
abort ();
#if 0
/* This isn't worth the time it takes. */
/* give back excess storage */
defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1);
#endif
return defn;
}
static int
do_assert (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op ATTRIBUTE_UNUSED;
struct directive *keyword ATTRIBUTE_UNUSED;
{
U_CHAR *bp; /* temp ptr into input buffer */
U_CHAR *symname; /* remember where symbol name starts */
int sym_length; /* and how long it is */
struct arglist *tokens = NULL;
if (pedantic && done_initializing && !instack[indepth].system_header_p)
pedwarn ("ANSI C does not allow `#assert'");
bp = buf;
while (is_hor_space[*bp])
bp++;
symname = bp; /* remember where it starts */
sym_length = check_macro_name (bp, 1);
bp += sym_length;
/* #define doesn't do this, but we should. */
SKIP_WHITE_SPACE (bp);
/* Lossage will occur if identifiers or control tokens are broken
across lines using backslash. This is not the right place to take
care of that. */
if (*bp != '(') {
error ("missing token-sequence in `#assert'");
return 1;
}
{
int error_flag = 0;
bp++; /* skip '(' */
SKIP_WHITE_SPACE (bp);
tokens = read_token_list (&bp, limit, &error_flag);
if (error_flag)
return 1;
if (tokens == 0) {
error ("empty token-sequence in `#assert'");
return 1;
}
++bp; /* skip paren */
SKIP_WHITE_SPACE (bp);
}
/* If this name isn't already an assertion name, make it one.
Error if it was already in use in some other way. */
{
ASSERTION_HASHNODE *hp;
int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
struct tokenlist_list *value
= (struct tokenlist_list *) xmalloc (sizeof (struct tokenlist_list));
hp = assertion_lookup (symname, sym_length, hashcode);
if (hp == NULL) {
if (sym_length == 7 && ! bcmp (symname, "defined", 7))
error ("`defined' redefined as assertion");
hp = assertion_install (symname, sym_length, hashcode);
}
/* Add the spec'd token-sequence to the list of such. */
value->tokens = tokens;
value->next = hp->value;
hp->value = value;
}
return 0;
}
static int
do_unassert (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op ATTRIBUTE_UNUSED;
struct directive *keyword ATTRIBUTE_UNUSED;
{
U_CHAR *bp; /* temp ptr into input buffer */
U_CHAR *symname; /* remember where symbol name starts */
int sym_length; /* and how long it is */
struct arglist *tokens = NULL;
int tokens_specified = 0;
if (pedantic && done_initializing && !instack[indepth].system_header_p)
pedwarn ("ANSI C does not allow `#unassert'");
bp = buf;
while (is_hor_space[*bp])
bp++;
symname = bp; /* remember where it starts */
sym_length = check_macro_name (bp, 1);
bp += sym_length;
/* #define doesn't do this, but we should. */
SKIP_WHITE_SPACE (bp);
/* Lossage will occur if identifiers or control tokens are broken
across lines using backslash. This is not the right place to take
care of that. */
if (*bp == '(') {
int error_flag = 0;
bp++; /* skip '(' */
SKIP_WHITE_SPACE (bp);
tokens = read_token_list (&bp, limit, &error_flag);
if (error_flag)
return 1;
if (tokens == 0) {
error ("empty token list in `#unassert'");
return 1;
}
tokens_specified = 1;
++bp; /* skip paren */
SKIP_WHITE_SPACE (bp);
}
{
ASSERTION_HASHNODE *hp;
int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
struct tokenlist_list *tail, *prev;
hp = assertion_lookup (symname, sym_length, hashcode);
if (hp == NULL)
return 1;
/* If no token list was specified, then eliminate this assertion
entirely. */
if (! tokens_specified) {
struct tokenlist_list *next;
for (tail = hp->value; tail; tail = next) {
next = tail->next;
free_token_list (tail->tokens);
free (tail);
}
delete_assertion (hp);
} else {
/* If a list of tokens was given, then delete any matching list. */
tail = hp->value;
prev = 0;
while (tail) {
struct tokenlist_list *next = tail->next;
if (compare_token_lists (tail->tokens, tokens)) {
if (prev)
prev->next = next;
else
hp->value = tail->next;
free_token_list (tail->tokens);
free (tail);
} else {
prev = tail;
}
tail = next;
}
}
}
return 0;
}
/* Test whether there is an assertion named NAME
and optionally whether it has an asserted token list TOKENS.
NAME is not null terminated; its length is SYM_LENGTH.
If TOKENS_SPECIFIED is 0, then don't check for any token list. */
int
check_assertion (name, sym_length, tokens_specified, tokens)
U_CHAR *name;
int sym_length;
int tokens_specified;
struct arglist *tokens;
{
ASSERTION_HASHNODE *hp;
int hashcode = hashf (name, sym_length, ASSERTION_HASHSIZE);
if (pedantic && !instack[indepth].system_header_p)
pedwarn ("ANSI C does not allow testing assertions");
hp = assertion_lookup (name, sym_length, hashcode);
if (hp == NULL)
/* It is not an assertion; just return false. */
return 0;
/* If no token list was specified, then value is 1. */
if (! tokens_specified)
return 1;
{
struct tokenlist_list *tail;
tail = hp->value;
/* If a list of tokens was given,
then succeed if the assertion records a matching list. */
while (tail) {
if (compare_token_lists (tail->tokens, tokens))
return 1;
tail = tail->next;
}
/* Fail if the assertion has no matching list. */
return 0;
}
}
/* Compare two lists of tokens for equality including order of tokens. */
static int
compare_token_lists (l1, l2)
struct arglist *l1, *l2;
{
while (l1 && l2) {
if (l1->length != l2->length)
return 0;
if (bcmp (l1->name, l2->name, l1->length))
return 0;
l1 = l1->next;
l2 = l2->next;
}
/* Succeed if both lists end at the same time. */
return l1 == l2;
}
/* Read a space-separated list of tokens ending in a close parenthesis.
Return a list of strings, in the order they were written.
(In case of error, return 0 and store -1 in *ERROR_FLAG.)
Parse the text starting at *BPP, and update *BPP.
Don't parse beyond LIMIT. */
static struct arglist *
read_token_list (bpp, limit, error_flag)
U_CHAR **bpp;
U_CHAR *limit;
int *error_flag;
{
struct arglist *token_ptrs = 0;
U_CHAR *bp = *bpp;
int depth = 1;
*error_flag = 0;
/* Loop over the assertion value tokens. */
while (depth > 0) {
struct arglist *temp;
int eofp = 0;
U_CHAR *beg = bp;
/* Find the end of the token. */
if (*bp == '(') {
bp++;
depth++;
} else if (*bp == ')') {
depth--;
if (depth == 0)
break;
bp++;
} else if (*bp == '"' || *bp == '\'')
bp = skip_quoted_string (bp, limit, 0, NULL_PTR, NULL_PTR, &eofp);
else
while (! is_hor_space[*bp] && *bp != '(' && *bp != ')'
&& *bp != '"' && *bp != '\'' && bp != limit)
bp++;
temp = (struct arglist *) xmalloc (sizeof (struct arglist));
temp->name = (U_CHAR *) xmalloc (bp - beg + 1);
bcopy ((char *) beg, (char *) temp->name, bp - beg);
temp->name[bp - beg] = 0;
temp->next = token_ptrs;
token_ptrs = temp;
temp->length = bp - beg;
SKIP_WHITE_SPACE (bp);
if (bp >= limit) {
error ("unterminated token sequence in `#assert' or `#unassert'");
*error_flag = -1;
return 0;
}
}
*bpp = bp;
/* We accumulated the names in reverse order.
Now reverse them to get the proper order. */
{
register struct arglist *prev = 0, *this, *next;
for (this = token_ptrs; this; this = next) {
next = this->next;
this->next = prev;
prev = this;
}
return prev;
}
}
static void
free_token_list (tokens)
struct arglist *tokens;
{
while (tokens) {
struct arglist *next = tokens->next;
free (tokens->name);
free (tokens);
tokens = next;
}
}
/* Install a name in the assertion hash table.
If LEN is >= 0, it is the length of the name.
Otherwise, compute the length by scanning the entire name.
If HASH is >= 0, it is the precomputed hash code.
Otherwise, compute the hash code. */
static ASSERTION_HASHNODE *
assertion_install (name, len, hash)
U_CHAR *name;
int len;
int hash;
{
register ASSERTION_HASHNODE *hp;
register int i, bucket;
register U_CHAR *p, *q;
i = sizeof (ASSERTION_HASHNODE) + len + 1;
hp = (ASSERTION_HASHNODE *) xmalloc (i);
bucket = hash;
hp->bucket_hdr = &assertion_hashtab[bucket];
hp->next = assertion_hashtab[bucket];
assertion_hashtab[bucket] = hp;
hp->prev = NULL;
if (hp->next != NULL)
hp->next->prev = hp;
hp->length = len;
hp->value = 0;
hp->name = ((U_CHAR *) hp) + sizeof (ASSERTION_HASHNODE);
p = hp->name;
q = name;
for (i = 0; i < len; i++)
*p++ = *q++;
hp->name[len] = 0;
return hp;
}
/* Find the most recent hash node for name "name" (ending with first
non-identifier char) installed by install
If LEN is >= 0, it is the length of the name.
Otherwise, compute the length by scanning the entire name.
If HASH is >= 0, it is the precomputed hash code.
Otherwise, compute the hash code. */
static ASSERTION_HASHNODE *
assertion_lookup (name, len, hash)
U_CHAR *name;
int len;
int hash;
{
register ASSERTION_HASHNODE *bucket;
bucket = assertion_hashtab[hash];
while (bucket) {
if (bucket->length == len && bcmp (bucket->name, name, len) == 0)
return bucket;
bucket = bucket->next;
}
return NULL;
}
static void
delete_assertion (hp)
ASSERTION_HASHNODE *hp;
{
if (hp->prev != NULL)
hp->prev->next = hp->next;
if (hp->next != NULL)
hp->next->prev = hp->prev;
/* Make sure that the bucket chain header that the deleted guy was
on points to the right thing afterwards. */
if (hp == *hp->bucket_hdr)
*hp->bucket_hdr = hp->next;
free (hp);
}
/*
* interpret #line directive. Remembers previously seen fnames
* in its very own hash table.
*/
#define FNAME_HASHSIZE 37
static int
do_line (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
struct directive *keyword ATTRIBUTE_UNUSED;
{
register U_CHAR *bp;
FILE_BUF *ip = &instack[indepth];
FILE_BUF tem;
int new_lineno;
enum file_change_code file_change = same_file;
/* Expand any macros. */
tem = expand_to_temp_buffer (buf, limit, 0, 0);
/* Point to macroexpanded line, which is null-terminated now. */
bp = tem.buf;
SKIP_WHITE_SPACE (bp);
if (!ISDIGIT (*bp)) {
error ("invalid format `#line' directive");
return 0;
}
/* The Newline at the end of this line remains to be processed.
To put the next line at the specified line number,
we must store a line number now that is one less. */
new_lineno = atoi ((char *) bp) - 1;
/* NEW_LINENO is one less than the actual line number here. */
if (pedantic && new_lineno < 0)
pedwarn ("line number out of range in `#line' directive");
/* skip over the line number. */
while (ISDIGIT (*bp))
bp++;
#if 0 /* #line 10"foo.c" is supposed to be allowed. */
if (*bp && !is_space[*bp]) {
error ("invalid format `#line' directive");
return;
}
#endif
SKIP_WHITE_SPACE (bp);
if (*bp == '\"') {
static HASHNODE *fname_table[FNAME_HASHSIZE];
HASHNODE *hp, **hash_bucket;
U_CHAR *fname, *p;
int fname_length;
fname = ++bp;
/* Turn the file name, which is a character string literal,
into a null-terminated string. Do this in place. */
p = bp;
for (;;)
switch ((*p++ = *bp++)) {
case '\0':
error ("invalid format `#line' directive");
return 0;
case '\\':
if (! ignore_escape_flag)
{
char *bpc = (char *) bp;
HOST_WIDEST_INT c = parse_escape (&bpc, (HOST_WIDEST_INT) (U_CHAR) (-1));
bp = (U_CHAR *) bpc;
if (c < 0)
p--;
else
p[-1] = c;
}
break;
case '\"':
*--p = 0;
goto fname_done;
}
fname_done:
fname_length = p - fname;
SKIP_WHITE_SPACE (bp);
if (*bp) {
if (pedantic)
pedwarn ("garbage at end of `#line' directive");
if (*bp == '1')
file_change = enter_file;
else if (*bp == '2')
file_change = leave_file;
else if (*bp == '3')
ip->system_header_p = 1;
else if (*bp == '4')
ip->system_header_p = 2;
else {
error ("invalid format `#line' directive");
return 0;
}
bp++;
SKIP_WHITE_SPACE (bp);
if (*bp == '3') {
ip->system_header_p = 1;
bp++;
SKIP_WHITE_SPACE (bp);
}
if (*bp == '4') {
ip->system_header_p = 2;
bp++;
SKIP_WHITE_SPACE (bp);
}
if (*bp) {
error ("invalid format `#line' directive");
return 0;
}
}
hash_bucket = &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
for (hp = *hash_bucket; hp != NULL; hp = hp->next)
if (hp->length == fname_length &&
bcmp (hp->value.cpval, fname, fname_length) == 0) {
ip->nominal_fname = hp->value.cpval;
ip->nominal_fname_len = fname_length;
break;
}
if (hp == 0) {
/* Didn't find it; cons up a new one. */
hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1);
hp->next = *hash_bucket;
*hash_bucket = hp;
ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE);
ip->nominal_fname_len = hp->length = fname_length;
bcopy (fname, hp->value.cpval, fname_length + 1);
}
} else if (*bp) {
error ("invalid format `#line' directive");
return 0;
}
ip->lineno = new_lineno;
output_line_directive (ip, op, 0, file_change);
check_expand (op, ip->length - (ip->bufp - ip->buf));
return 0;
}
/* Remove the definition of a symbol from the symbol table.
according to un*x /lib/cpp, it is not an error to undef
something that has no definitions, so it isn't one here either. */
static int
do_undef (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
struct directive *keyword;
{
int sym_length;
HASHNODE *hp;
U_CHAR *orig_buf = buf;
/* If this is a precompiler run (with -pcp) pass thru #undef directives. */
if (pcp_outfile && op)
pass_thru_directive (buf, limit, op, keyword);
SKIP_WHITE_SPACE (buf);
sym_length = check_macro_name (buf, 0);
while ((hp = lookup (buf, sym_length, -1)) != NULL) {
/* If we are generating additional info for debugging (with -g) we
need to pass through all effective #undef directives. */
if (debug_output && op)
pass_thru_directive (orig_buf, limit, op, keyword);
if (hp->type != T_MACRO)
warning ("undefining `%s'", hp->name);
delete_macro (hp);
}
if (pedantic) {
buf += sym_length;
SKIP_WHITE_SPACE (buf);
if (buf != limit)
pedwarn ("garbage after `#undef' directive");
}
return 0;
}
/* Report an error detected by the program we are processing.
Use the text of the line in the error message.
(We use error because it prints the filename & line#.) */
static int
do_error (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op ATTRIBUTE_UNUSED;
struct directive *keyword ATTRIBUTE_UNUSED;
{
int length = limit - buf;
U_CHAR *copy = (U_CHAR *) alloca (length + 1);
bcopy ((char *) buf, (char *) copy, length);
copy[length] = 0;
SKIP_WHITE_SPACE (copy);
error ("#error %s", copy);
return 0;
}
/* Report a warning detected by the program we are processing.
Use the text of the line in the warning message, then continue.
(We use error because it prints the filename & line#.) */
static int
do_warning (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op ATTRIBUTE_UNUSED;
struct directive *keyword ATTRIBUTE_UNUSED;
{
int length = limit - buf;
U_CHAR *copy = (U_CHAR *) alloca (length + 1);
bcopy ((char *) buf, (char *) copy, length);
copy[length] = 0;
SKIP_WHITE_SPACE (copy);
if (pedantic && !instack[indepth].system_header_p)
pedwarn ("ANSI C does not allow `#warning'");
/* Use `pedwarn' not `warning', because #warning isn't in the C Standard;
if -pedantic-errors is given, #warning should cause an error. */
pedwarn ("#warning %s", copy);
return 0;
}
/* Remember the name of the current file being read from so that we can
avoid ever including it again. */
static void
do_once ()
{
int i;
for (i = indepth; i >= 0; i--)
if (instack[i].inc) {
record_control_macro (instack[i].inc, (U_CHAR *) "");
break;
}
}
/* Report program identification. */
static int
do_ident (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
struct directive *keyword ATTRIBUTE_UNUSED;
{
FILE_BUF trybuf;
int len;
/* Allow #ident in system headers, since that's not user's fault. */
if (pedantic && !instack[indepth].system_header_p)
pedwarn ("ANSI C does not allow `#ident'");
trybuf = expand_to_temp_buffer (buf, limit, 0, 0);
buf = trybuf.buf;
len = trybuf.bufp - buf;
/* Output expanded directive. */
check_expand (op, 7 + len);
bcopy ("#ident ", (char *) op->bufp, 7);
op->bufp += 7;
bcopy ((char *) buf, (char *) op->bufp, len);
op->bufp += len;
free (buf);
return 0;
}
/* #pragma and its argument line have already been copied to the output file.
Just check for some recognized pragmas that need validation here. */
static int
do_pragma (buf, limit, op, keyword)
U_CHAR *buf, *limit ATTRIBUTE_UNUSED;
FILE_BUF *op ATTRIBUTE_UNUSED;
struct directive *keyword ATTRIBUTE_UNUSED;
{
SKIP_WHITE_SPACE (buf);
if (!strncmp ((char *) buf, "once", 4)) {
/* Allow #pragma once in system headers, since that's not the user's
fault. */
if (!instack[indepth].system_header_p)
warning ("`#pragma once' is obsolete");
do_once ();
}
if (!strncmp ((char *) buf, "implementation", 14)) {
/* Be quiet about `#pragma implementation' for a file only if it hasn't
been included yet. */
int h;
U_CHAR *p = buf + 14, *fname;
SKIP_WHITE_SPACE (p);
if (*p != '\"')
return 0;
fname = p + 1;
if ((p = (U_CHAR *) index ((char *) fname, '\"')))
*p = '\0';
for (h = 0; h < INCLUDE_HASHSIZE; h++) {
struct include_file *inc;
for (inc = include_hashtab[h]; inc; inc = inc->next) {
if (!strcmp (base_name (inc->fname), (char *) fname)) {
warning ("`#pragma implementation' for \"%s\" appears after its #include",fname);
return 0;
}
}
}
}
return 0;
}
#if 0
/* This was a fun hack, but #pragma seems to start to be useful.
By failing to recognize it, we pass it through unchanged to cc1. */
/* The behavior of the #pragma directive is implementation defined.
this implementation defines it as follows. */
static int
do_pragma ()
{
close (0);
if (open ("/dev/tty", O_RDONLY, 0666) != 0)
goto nope;
close (1);
if (open ("/dev/tty", O_WRONLY, 0666) != 1)
goto nope;
execl ("/usr/games/hack", "#pragma", 0);
execl ("/usr/games/rogue", "#pragma", 0);
execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
nope:
fatal ("You are in a maze of twisty compiler features, all different");
}
#endif
#ifdef SCCS_DIRECTIVE
/* Just ignore #sccs, on systems where we define it at all. */
static int
do_sccs (buf, limit, op, keyword)
U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
FILE_BUF *op ATTRIBUTE_UNUSED;
struct directive *keyword ATTRIBUTE_UNUSED;
{
if (pedantic)
pedwarn ("ANSI C does not allow `#sccs'");
return 0;
}
#endif /* defined (SCCS_DIRECTIVE) */
/* Handle #if directive by
1) inserting special `defined' keyword into the hash table
that gets turned into 0 or 1 by special_symbol (thus,
if the luser has a symbol called `defined' already, it won't
work inside the #if directive)
2) rescan the input into a temporary output buffer
3) pass the output buffer to the yacc parser and collect a value
4) clean up the mess left from steps 1 and 2.
5) call conditional_skip to skip til the next #endif (etc.),
or not, depending on the value from step 3. */
static int
do_if (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
struct directive *keyword ATTRIBUTE_UNUSED;
{
HOST_WIDEST_INT value;
FILE_BUF *ip = &instack[indepth];
value = eval_if_expression (buf, limit - buf);
conditional_skip (ip, value == 0, T_IF, NULL_PTR, op);
return 0;
}
/* Handle a #elif directive by not changing if_stack either.
see the comment above do_else. */
static int
do_elif (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
struct directive *keyword ATTRIBUTE_UNUSED;
{
HOST_WIDEST_INT value;
FILE_BUF *ip = &instack[indepth];
if (if_stack == instack[indepth].if_stack) {
error ("`#elif' not within a conditional");
return 0;
} else {
if (if_stack->type != T_IF && if_stack->type != T_ELIF) {
error ("`#elif' after `#else'");
fprintf (stderr, " (matches line %d", if_stack->lineno);
if (! (if_stack->fname_len == ip->nominal_fname_len
&& !bcmp (if_stack->fname, ip->nominal_fname,
if_stack->fname_len))) {
fprintf (stderr, ", file ");
eprint_string (if_stack->fname, if_stack->fname_len);
}
fprintf (stderr, ")\n");
}
if_stack->type = T_ELIF;
}
if (if_stack->if_succeeded)
skip_if_group (ip, 0, op);
else {
value = eval_if_expression (buf, limit - buf);
if (value == 0)
skip_if_group (ip, 0, op);
else {
++if_stack->if_succeeded; /* continue processing input */
output_line_directive (ip, op, 1, same_file);
}
}
return 0;
}
/* Evaluate a #if expression in BUF, of length LENGTH, then parse the
result as a C expression and return the value as an int. */
static HOST_WIDEST_INT
eval_if_expression (buf, length)
U_CHAR *buf;
int length;
{
FILE_BUF temp_obuf;
HASHNODE *save_defined;
HOST_WIDEST_INT value;
save_defined = install ((U_CHAR *) "defined", -1, T_SPEC_DEFINED,
NULL_PTR, -1);
pcp_inside_if = 1;
temp_obuf = expand_to_temp_buffer (buf, buf + length, 0, 1);
pcp_inside_if = 0;
delete_macro (save_defined); /* clean up special symbol */
temp_obuf.buf[temp_obuf.length] = '\n';
value = parse_c_expression ((char *) temp_obuf.buf,
warn_undef && !instack[indepth].system_header_p);
free (temp_obuf.buf);
return value;
}
/* routine to handle ifdef/ifndef. Try to look up the symbol, then do
or don't skip to the #endif/#else/#elif depending on what directive
is actually being processed. */
static int
do_xifdef (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
struct directive *keyword;
{
int skip;
FILE_BUF *ip = &instack[indepth];
U_CHAR *end;
int start_of_file = 0;
U_CHAR *control_macro = 0;
/* Detect a #ifndef at start of file (not counting comments). */
if (ip->fname != 0 && keyword->type == T_IFNDEF) {
U_CHAR *p = ip->buf;
while (p != directive_start) {
U_CHAR c = *p++;
if (is_space[c])
;
/* Make no special provision for backslash-newline here; this is
slower if backslash-newlines are present, but it's correct,
and it's not worth it to tune for the rare backslash-newline. */
else if (c == '/'
&& (*p == '*' || (cplusplus_comments && *p == '/'))) {
/* Skip this comment. */
int junk = 0;
U_CHAR *save_bufp = ip->bufp;
ip->bufp = p + 1;
p = skip_to_end_of_comment (ip, &junk, 1);
ip->bufp = save_bufp;
} else {
goto fail;
}
}
/* If we get here, this conditional is the beginning of the file. */
start_of_file = 1;
fail: ;
}
/* Discard leading and trailing whitespace. */
SKIP_WHITE_SPACE (buf);
while (limit != buf && is_hor_space[limit[-1]]) limit--;
/* Find the end of the identifier at the beginning. */
for (end = buf; is_idchar[*end]; end++);
if (end == buf) {
skip = (keyword->type == T_IFDEF);
if (! traditional)
pedwarn (end == limit ? "`#%s' with no argument"
: "`#%s' argument starts with punctuation",
keyword->name);
} else {
HASHNODE *hp;
if (! traditional) {
if (ISDIGIT (buf[0]))
pedwarn ("`#%s' argument starts with a digit", keyword->name);
else if (end != limit)
pedwarn ("garbage at end of `#%s' argument", keyword->name);
}
hp = lookup (buf, end-buf, -1);
if (pcp_outfile) {
/* Output a precondition for this macro. */
if (hp
&& (hp->type == T_CONST
|| (hp->type == T_MACRO && hp->value.defn->predefined)))
fprintf (pcp_outfile, "#define %s\n", hp->name);
else {
U_CHAR *cp = buf;
fprintf (pcp_outfile, "#undef ");
while (is_idchar[*cp]) /* Ick! */
fputc (*cp++, pcp_outfile);
putc ('\n', pcp_outfile);
}
}
skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
if (start_of_file && !skip) {
control_macro = (U_CHAR *) xmalloc (end - buf + 1);
bcopy ((char *) buf, (char *) control_macro, end - buf);
control_macro[end - buf] = 0;
}
}
conditional_skip (ip, skip, T_IF, control_macro, op);
return 0;
}
/* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
If this is a #ifndef starting at the beginning of a file,
CONTROL_MACRO is the macro name tested by the #ifndef.
Otherwise, CONTROL_MACRO is 0. */
static void
conditional_skip (ip, skip, type, control_macro, op)
FILE_BUF *ip;
int skip;
enum node_type type;
U_CHAR *control_macro;
FILE_BUF *op;
{
IF_STACK_FRAME *temp;
temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
temp->fname = ip->nominal_fname;
temp->fname_len = ip->nominal_fname_len;
temp->lineno = ip->lineno;
temp->next = if_stack;
temp->control_macro = control_macro;
if_stack = temp;
if_stack->type = type;
if (skip != 0) {
skip_if_group (ip, 0, op);
return;
} else {
++if_stack->if_succeeded;
output_line_directive (ip, &outbuf, 1, same_file);
}
}
/* Skip to #endif, #else, or #elif. adjust line numbers, etc.
Leaves input ptr at the sharp sign found.
If ANY is nonzero, return at next directive of any sort. */
static void
skip_if_group (ip, any, op)
FILE_BUF *ip;
int any;
FILE_BUF *op;
{
register U_CHAR *bp = ip->bufp, *cp;
register U_CHAR *endb = ip->buf + ip->length;
struct directive *kt;
IF_STACK_FRAME *save_if_stack = if_stack; /* don't pop past here */
U_CHAR *beg_of_line = bp;
register int ident_length;
U_CHAR *ident, *after_ident;
/* Save info about where the group starts. */
U_CHAR *beg_of_group = bp;
int beg_lineno = ip->lineno;
int skipping_include_directive = 0;
if (output_conditionals && op != 0) {
char *ptr = "#failed\n";
int len = strlen (ptr);
if (op->bufp > op->buf && op->bufp[-1] != '\n')
{
*op->bufp++ = '\n';
op->lineno++;
}
check_expand (op, len);
bcopy (ptr, (char *) op->bufp, len);
op->bufp += len;
op->lineno++;
output_line_directive (ip, op, 1, 0);
}
while (bp < endb) {
switch (*bp++) {
case '/': /* possible comment */
if (*bp == '\\' && bp[1] == '\n')
newline_fix (bp);
if (*bp == '*'
|| (cplusplus_comments && *bp == '/')) {
ip->bufp = ++bp;
bp = skip_to_end_of_comment (ip, &ip->lineno, 0);
}
break;
case '<':
if (skipping_include_directive) {
while (bp < endb && *bp != '>' && *bp != '\n') {
if (*bp == '\\' && bp[1] == '\n') {
ip->lineno++;
bp++;
}
bp++;
}
}
break;
case '\"':
if (skipping_include_directive) {
while (bp < endb && *bp != '\n') {
if (*bp == '"') {
bp++;
break;
}
if (*bp == '\\' && bp[1] == '\n') {
ip->lineno++;
bp++;
}
bp++;
}
break;
}
/* Fall through. */
case '\'':
bp = skip_quoted_string (bp - 1, endb, ip->lineno, &ip->lineno,
NULL_PTR, NULL_PTR);
break;
case '\\':
/* Char after backslash loses its special meaning in some cases. */
if (*bp == '\n') {
++ip->lineno;
bp++;
} else if (traditional && bp < endb)
bp++;
break;
case '\n':
++ip->lineno;
beg_of_line = bp;
skipping_include_directive = 0;
break;
case '%':
if (beg_of_line == 0 || traditional)
break;
ip->bufp = bp - 1;
while (bp[0] == '\\' && bp[1] == '\n')
bp += 2;
if (*bp == ':')
goto sharp_token;
break;
case '#':
/* # keyword: a # must be first nonblank char on the line */
if (beg_of_line == 0)
break;
ip->bufp = bp - 1;
sharp_token:
/* Scan from start of line, skipping whitespace, comments
and backslash-newlines, and see if we reach this #.
If not, this # is not special. */
bp = beg_of_line;
/* If -traditional, require # to be at beginning of line. */
if (!traditional) {
while (1) {
if (is_hor_space[*bp])
bp++;
else if (*bp == '\\' && bp[1] == '\n')
bp += 2;
else if (*bp == '/' && bp[1] == '*') {
bp += 2;
while (1)
{
if (*bp == '*')
{
if (bp[1] == '/')
{
bp += 2;
break;
}
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (bp, endb - bp);
if (length > 1)
bp += (length - 1);
#endif
}
bp++;
}
}
/* There is no point in trying to deal with C++ // comments here,
because if there is one, then this # must be part of the
comment and we would never reach here. */
else break;
}
}
if (bp != ip->bufp) {
bp = ip->bufp + 1; /* Reset bp to after the #. */
break;
}
bp = ip->bufp + 1; /* Point after the '#' */
if (ip->bufp[0] == '%') {
/* Skip past the ':' again. */
while (*bp == '\\') {
ip->lineno++;
bp += 2;
}
bp++;
}
/* Skip whitespace and \-newline. */
while (1) {
if (is_hor_space[*bp])
bp++;
else if (*bp == '\\' && bp[1] == '\n')
bp += 2;
else if (*bp == '/') {
if (bp[1] == '\\' && bp[2] == '\n')
newline_fix (bp + 1);
if (bp[1] == '*') {
for (bp += 2; ; bp++) {
if (*bp == '\n')
ip->lineno++;
else if (*bp == '*') {
if (bp[-1] == '/' && warn_comments)
warning ("`/*' within comment");
if (bp[1] == '\\' && bp[2] == '\n')
newline_fix (bp + 1);
if (bp[1] == '/')
break;
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (bp, endb - bp);
if (length > 1)
bp += (length - 1);
#endif
}
}
bp += 2;
} else if (bp[1] == '/' && cplusplus_comments) {
for (bp += 2; ; bp++) {
if (*bp == '\n')
break;
if (*bp == '\\' && bp[1] == '\n')
{
if (warn_comments)
warning ("multiline `//' comment");
ip->lineno++;
bp++;
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (bp, endb - bp);
if (length > 1)
bp += (length - 1);
#endif
}
}
} else
break;
} else
break;
}
cp = bp;
/* Now find end of directive name.
If we encounter a backslash-newline, exchange it with any following
symbol-constituents so that we end up with a contiguous name. */
while (1) {
if (is_idchar[*bp])
bp++;
else {
if (*bp == '\\' && bp[1] == '\n')
name_newline_fix (bp);
if (is_idchar[*bp])
bp++;
else break;
}
}
ident_length = bp - cp;
ident = cp;
after_ident = bp;
/* A line of just `#' becomes blank. */
if (ident_length == 0 && *after_ident == '\n') {
continue;
}
if (ident_length == 0 || !is_idstart[*ident]) {
U_CHAR *p = ident;
while (is_idchar[*p]) {
if (*p < '0' || *p > '9')
break;
p++;
}
/* Handle # followed by a line number. */
if (p != ident && !is_idchar[*p]) {
if (pedantic)
pedwarn ("`#' followed by integer");
continue;
}
/* Avoid error for `###' and similar cases unless -pedantic. */
if (p == ident) {
while (*p == '#' || is_hor_space[*p]) p++;
if (*p == '\n') {
if (pedantic && !lang_asm)
pedwarn ("invalid preprocessing directive");
continue;
}
}
if (!lang_asm && pedantic)
pedwarn ("invalid preprocessing directive name");
continue;
}
for (kt = directive_table; kt->length >= 0; kt++) {
IF_STACK_FRAME *temp;
if (ident_length == kt->length
&& bcmp (cp, kt->name, kt->length) == 0) {
/* If we are asked to return on next directive, do so now. */
if (any)
goto done;
switch (kt->type) {
case T_IF:
case T_IFDEF:
case T_IFNDEF:
temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
temp->next = if_stack;
if_stack = temp;
temp->lineno = ip->lineno;
temp->fname = ip->nominal_fname;
temp->fname_len = ip->nominal_fname_len;
temp->type = kt->type;
break;
case T_ELSE:
case T_ENDIF:
if (pedantic && if_stack != save_if_stack)
validate_else (bp, endb);
case T_ELIF:
if (if_stack == instack[indepth].if_stack) {
error ("`#%s' not within a conditional", kt->name);
break;
}
else if (if_stack == save_if_stack)
goto done; /* found what we came for */
if (kt->type != T_ENDIF) {
if (if_stack->type == T_ELSE)
error ("`#else' or `#elif' after `#else'");
if_stack->type = kt->type;
break;
}
temp = if_stack;
if_stack = if_stack->next;
free (temp);
break;
case T_INCLUDE:
case T_INCLUDE_NEXT:
case T_IMPORT:
skipping_include_directive = 1;
break;
default:
break;
}
break;
}
}
/* Don't let erroneous code go by. */
if (kt->length < 0 && !lang_asm && pedantic)
pedwarn ("invalid preprocessing directive name");
}
}
ip->bufp = bp;
/* after this returns, rescan will exit because ip->bufp
now points to the end of the buffer.
rescan is responsible for the error message also. */
done:
if (output_conditionals && op != 0) {
char *ptr = "#endfailed\n";
int len = strlen (ptr);
if (op->bufp > op->buf && op->bufp[-1] != '\n')
{
*op->bufp++ = '\n';
op->lineno++;
}
check_expand (op, beg_of_line - beg_of_group);
bcopy ((char *) beg_of_group, (char *) op->bufp,
beg_of_line - beg_of_group);
op->bufp += beg_of_line - beg_of_group;
op->lineno += ip->lineno - beg_lineno;
check_expand (op, len);
bcopy (ptr, (char *) op->bufp, len);
op->bufp += len;
op->lineno++;
}
}
/* Handle a #else directive. Do this by just continuing processing
without changing if_stack ; this is so that the error message
for missing #endif's etc. will point to the original #if. It
is possible that something different would be better. */
static int
do_else (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
struct directive *keyword ATTRIBUTE_UNUSED;
{
FILE_BUF *ip = &instack[indepth];
if (pedantic) {
SKIP_WHITE_SPACE (buf);
if (buf != limit)
pedwarn ("text following `#else' violates ANSI standard");
}
if (if_stack == instack[indepth].if_stack) {
error ("`#else' not within a conditional");
return 0;
} else {
/* #ifndef can't have its special treatment for containing the whole file
if it has a #else clause. */
if_stack->control_macro = 0;
if (if_stack->type != T_IF && if_stack->type != T_ELIF) {
error ("`#else' after `#else'");
fprintf (stderr, " (matches line %d", if_stack->lineno);
if (! (if_stack->fname_len == ip->nominal_fname_len
&& !bcmp (if_stack->fname, ip->nominal_fname,
if_stack->fname_len))) {
fprintf (stderr, ", file ");
eprint_string (if_stack->fname, if_stack->fname_len);
}
fprintf (stderr, ")\n");
}
if_stack->type = T_ELSE;
}
if (if_stack->if_succeeded)
skip_if_group (ip, 0, op);
else {
++if_stack->if_succeeded; /* continue processing input */
output_line_directive (ip, op, 1, same_file);
}
return 0;
}
/* Unstack after #endif directive. */
static int
do_endif (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
struct directive *keyword ATTRIBUTE_UNUSED;
{
if (pedantic) {
SKIP_WHITE_SPACE (buf);
if (buf != limit)
pedwarn ("text following `#endif' violates ANSI standard");
}
if (if_stack == instack[indepth].if_stack)
error ("unbalanced `#endif'");
else {
IF_STACK_FRAME *temp = if_stack;
if_stack = if_stack->next;
if (temp->control_macro != 0) {
/* This #endif matched a #ifndef at the start of the file.
See if it is at the end of the file. */
FILE_BUF *ip = &instack[indepth];
U_CHAR *p = ip->bufp;
U_CHAR *ep = ip->buf + ip->length;
while (p != ep) {
U_CHAR c = *p++;
if (!is_space[c]) {
if (c == '/'
&& (*p == '*' || (cplusplus_comments && *p == '/'))) {
/* Skip this comment. */
int junk = 0;
U_CHAR *save_bufp = ip->bufp;
ip->bufp = p + 1;
p = skip_to_end_of_comment (ip, &junk, 1);
ip->bufp = save_bufp;
} else
goto fail;
}
}
/* If we get here, this #endif ends a #ifndef
that contains all of the file (aside from whitespace).
Arrange not to include the file again
if the macro that was tested is defined.
Do not do this for the top-level file in a -include or any
file in a -imacros. */
if (indepth != 0
&& ! (indepth == 1 && no_record_file)
&& ! (no_record_file && no_output))
record_control_macro (ip->inc, temp->control_macro);
fail: ;
}
free (temp);
output_line_directive (&instack[indepth], op, 1, same_file);
}
return 0;
}
/* When an #else or #endif is found while skipping failed conditional,
if -pedantic was specified, this is called to warn about text after
the directive name. P points to the first char after the directive
name. */
static void
validate_else (p, limit)
register U_CHAR *p;
register U_CHAR *limit;
{
/* Advance P over whitespace and comments. */
while (1) {
while (*p == '\\' && p[1] == '\n')
p += 2;
if (is_hor_space[*p])
p++;
else if (*p == '/') {
while (p[1] == '\\' && p[2] == '\n')
p += 2;
if (p[1] == '*') {
/* Don't bother warning about unterminated comments
since that will happen later. Just be sure to exit. */
for (p += 2; ; p++) {
if (p == limit)
return;
if (*p == '*') {
while (p[1] == '\\' && p[2] == '\n')
p += 2;
if (p[1] == '/') {
p += 2;
break;
}
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (p, limit - p);
if (length > 1)
p += (length - 1);
#endif
}
}
}
else if (cplusplus_comments && p[1] == '/')
return;
else break;
} else break;
}
if (*p != '\n')
pedwarn ("text following `#else' or `#endif' violates ANSI standard");
}
/* Skip a comment, assuming the input ptr immediately follows the
initial slash-star. Bump *LINE_COUNTER for each newline.
(The canonical line counter is &ip->lineno.)
Don't use this routine (or the next one) if bumping the line
counter is not sufficient to deal with newlines in the string.
If NOWARN is nonzero, don't warn about slash-star inside a comment.
This feature is useful when processing a comment that is going to
be processed or was processed at another point in the preprocessor,
to avoid a duplicate warning. Likewise for unterminated comment
errors. */
static U_CHAR *
skip_to_end_of_comment (ip, line_counter, nowarn)
register FILE_BUF *ip;
int *line_counter; /* place to remember newlines, or NULL */
int nowarn;
{
register U_CHAR *limit = ip->buf + ip->length;
register U_CHAR *bp = ip->bufp;
FILE_BUF *op = put_out_comments && !line_counter ? &outbuf : (FILE_BUF *) 0;
int start_line = line_counter ? *line_counter : 0;
/* JF this line_counter stuff is a crock to make sure the
comment is only put out once, no matter how many times
the comment is skipped. It almost works */
if (op) {
*op->bufp++ = '/';
*op->bufp++ = bp[-1];
}
if (cplusplus_comments && bp[-1] == '/') {
for (; bp < limit; bp++) {
if (*bp == '\n')
break;
if (*bp == '\\' && bp + 1 < limit && bp[1] == '\n')
{
if (!nowarn && warn_comments)
warning ("multiline `//' comment");
if (line_counter)
++*line_counter;
if (op)
{
++op->lineno;
*op->bufp++ = *bp;
}
++bp;
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (bp, limit - bp);
if (length > 1)
{
if (op)
{
bcopy (bp, op->bufp, length - 1);
op->bufp += (length - 1);
}
bp += (length - 1);
}
#endif
}
if (op)
*op->bufp++ = *bp;
}
ip->bufp = bp;
return bp;
}
while (bp < limit) {
if (op)
*op->bufp++ = *bp;
switch (*bp++) {
case '\n':
/* If this is the end of the file, we have an unterminated comment.
Don't swallow the newline. We are guaranteed that there will be a
trailing newline and various pieces assume it's there. */
if (bp == limit)
{
--bp;
--limit;
break;
}
if (line_counter != NULL)
++*line_counter;
if (op)
++op->lineno;
break;
case '*':
if (bp[-2] == '/' && !nowarn && warn_comments)
warning ("`/*' within comment");
if (*bp == '\\' && bp[1] == '\n')
newline_fix (bp);
if (*bp == '/') {
if (op)
*op->bufp++ = '/';
ip->bufp = ++bp;
return bp;
}
break;
#ifdef MULTIBYTE_CHARS
default:
{
int length;
bp--;
length = local_mblen (bp, limit - bp);
if (length <= 0)
length = 1;
if (op)
{
op->bufp--;
bcopy (bp, op->bufp, length);
op->bufp += length;
}
bp += length;
}
#endif
}
}
if (!nowarn)
error_with_line (line_for_error (start_line), "unterminated comment");
ip->bufp = bp;
return bp;
}
/* Skip over a quoted string. BP points to the opening quote.
Returns a pointer after the closing quote. Don't go past LIMIT.
START_LINE is the line number of the starting point (but it need
not be valid if the starting point is inside a macro expansion).
The input stack state is not changed.
If COUNT_NEWLINES is nonzero, it points to an int to increment
for each newline passed.
If BACKSLASH_NEWLINES_P is nonzero, store 1 thru it
if we pass a backslash-newline.
If EOFP is nonzero, set *EOFP to 1 if the string is unterminated. */
static U_CHAR *
skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p, eofp)
register U_CHAR *bp;
register U_CHAR *limit;
int start_line;
int *count_newlines;
int *backslash_newlines_p;
int *eofp;
{
register U_CHAR c, match;
match = *bp++;
while (1) {
if (bp >= limit) {
error_with_line (line_for_error (start_line),
"unterminated string or character constant");
error_with_line (multiline_string_line,
"possible real start of unterminated constant");
multiline_string_line = 0;
if (eofp)
*eofp = 1;
break;
}
c = *bp++;
if (c == '\\') {
while (*bp == '\\' && bp[1] == '\n') {
if (backslash_newlines_p)
*backslash_newlines_p = 1;
if (count_newlines)
++*count_newlines;
bp += 2;
}
if (*bp == '\n') {
if (backslash_newlines_p)
*backslash_newlines_p = 1;
if (count_newlines)
++*count_newlines;
}
bp++;
} else if (c == '\n') {
if (traditional) {
/* Unterminated strings and character constants are 'valid'. */
bp--; /* Don't consume the newline. */
if (eofp)
*eofp = 1;
break;
}
if (match == '\'') {
error_with_line (line_for_error (start_line),
"unterminated string or character constant");
bp--;
if (eofp)
*eofp = 1;
break;
}
/* If not traditional, then allow newlines inside strings. */
if (count_newlines)
++*count_newlines;
if (multiline_string_line == 0) {
if (pedantic)
pedwarn_with_line (line_for_error (start_line),
"string constant runs past end of line");
multiline_string_line = start_line;
}
} else if (c == match)
break;
#ifdef MULTIBYTE_CHARS
{
int length;
--bp;
length = local_mblen (bp, limit - bp);
if (length <= 0)
length = 1;
bp += length;
}
#endif
}
return bp;
}
/* Place into DST a quoted string representing the string SRC.
SRCLEN is the length of SRC; SRC may contain null bytes.
Return the address of DST's terminating null. */
static char *
quote_string (dst, src, srclen)
char *dst, *src;
size_t srclen;
{
U_CHAR c;
char *srclim = src + srclen;
*dst++ = '\"';
while (src != srclim)
switch ((c = *src++))
{
default:
if (ISPRINT (c))
*dst++ = c;
else
{
sprintf (dst, "\\%03o", c);
dst += 4;
}
break;
case '\"':
case '\\':
*dst++ = '\\';
*dst++ = c;
break;
}
*dst++ = '\"';
*dst = '\0';
return dst;
}
/* Skip across a group of balanced parens, starting from IP->bufp.
IP->bufp is updated. Use this with IP->bufp pointing at an open-paren.
This does not handle newlines, because it's used for the arg of #if,
where there aren't any newlines. Also, backslash-newline can't appear. */
static U_CHAR *
skip_paren_group (ip)
register FILE_BUF *ip;
{
U_CHAR *limit = ip->buf + ip->length;
U_CHAR *p = ip->bufp;
int depth = 0;
int lines_dummy = 0;
while (p != limit) {
int c = *p++;
switch (c) {
case '(':
depth++;
break;
case ')':
depth--;
if (depth == 0)
return ip->bufp = p;
break;
case '/':
if (*p == '*') {
ip->bufp = p;
p = skip_to_end_of_comment (ip, &lines_dummy, 0);
p = ip->bufp;
}
case '"':
case '\'':
{
int eofp = 0;
p = skip_quoted_string (p - 1, limit, 0, NULL_PTR, NULL_PTR, &eofp);
if (eofp)
return ip->bufp = p;
}
break;
}
}
ip->bufp = p;
return p;
}
/* Write out a #line directive, for instance, after an #include file.
If CONDITIONAL is nonzero, we can omit the #line if it would
appear to be a no-op, and we can output a few newlines instead
if we want to increase the line number by a small amount.
FILE_CHANGE says whether we are entering a file, leaving, or neither. */
static void
output_line_directive (ip, op, conditional, file_change)
FILE_BUF *ip, *op;
int conditional;
enum file_change_code file_change;
{
int len;
char *line_directive_buf, *line_end;
if (no_line_directives
|| ip->fname == NULL
|| no_output) {
op->lineno = ip->lineno;
return;
}
if (conditional) {
if (ip->lineno == op->lineno)
return;
/* If the inherited line number is a little too small,
output some newlines instead of a #line directive. */
if (ip->lineno > op->lineno && ip->lineno < op->lineno + 8) {
check_expand (op, 10);
while (ip->lineno > op->lineno) {
*op->bufp++ = '\n';
op->lineno++;
}
return;
}
}
/* Output a positive line number if possible. */
while (ip->lineno <= 0 && ip->bufp - ip->buf < ip->length
&& *ip->bufp == '\n') {
ip->lineno++;
ip->bufp++;
}
line_directive_buf = (char *) alloca (4 * ip->nominal_fname_len + 100);
sprintf (line_directive_buf, "# %d ", ip->lineno);
line_end = quote_string (line_directive_buf + strlen (line_directive_buf),
ip->nominal_fname, ip->nominal_fname_len);
if (file_change != same_file) {
*line_end++ = ' ';
*line_end++ = file_change == enter_file ? '1' : '2';
}
/* Tell cc1 if following text comes from a system header file. */
if (ip->system_header_p) {
*line_end++ = ' ';
*line_end++ = '3';
}
#ifndef NO_IMPLICIT_EXTERN_C
/* Tell cc1plus if following text should be treated as C. */
if (ip->system_header_p == 2 && cplusplus) {
*line_end++ = ' ';
*line_end++ = '4';
}
#endif
*line_end++ = '\n';
len = line_end - line_directive_buf;
check_expand (op, len + 1);
if (op->bufp > op->buf && op->bufp[-1] != '\n')
*op->bufp++ = '\n';
bcopy ((char *) line_directive_buf, (char *) op->bufp, len);
op->bufp += len;
op->lineno = ip->lineno;
}
/* This structure represents one parsed argument in a macro call.
`raw' points to the argument text as written (`raw_length' is its length).
`expanded' points to the argument's macro-expansion
(its length is `expand_length').
`stringified_length' is the length the argument would have
if stringified.
`use_count' is the number of times this macro arg is substituted
into the macro. If the actual use count exceeds 10,
the value stored is 10.
`free1' and `free2', if nonzero, point to blocks to be freed
when the macro argument data is no longer needed. */
struct argdata {
U_CHAR *raw, *expanded;
int raw_length, expand_length;
int stringified_length;
U_CHAR *free1, *free2;
char newlines;
char use_count;
};
/* Expand a macro call.
HP points to the symbol that is the macro being called.
Put the result of expansion onto the input stack
so that subsequent input by our caller will use it.
If macro wants arguments, caller has already verified that
an argument list follows; arguments come from the input stack. */
static void
macroexpand (hp, op)
HASHNODE *hp;
FILE_BUF *op;
{
int nargs;
DEFINITION *defn = hp->value.defn;
register U_CHAR *xbuf;
int xbuf_len;
int start_line = instack[indepth].lineno;
int rest_args, rest_zero;
CHECK_DEPTH (return;);
/* it might not actually be a macro. */
if (hp->type != T_MACRO) {
special_symbol (hp, op);
return;
}
/* This macro is being used inside a #if, which means it must be */
/* recorded as a precondition. */
if (pcp_inside_if && pcp_outfile && defn->predefined)
dump_single_macro (hp, pcp_outfile);
nargs = defn->nargs;
if (nargs >= 0) {
register int i;
struct argdata *args;
int parse_error = 0;
args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
for (i = 0; i < nargs; i++) {
args[i].raw = (U_CHAR *) "";
args[i].expanded = 0;
args[i].raw_length = args[i].expand_length
= args[i].stringified_length = 0;
args[i].free1 = args[i].free2 = 0;
args[i].use_count = 0;
}
/* Parse all the macro args that are supplied. I counts them.
The first NARGS args are stored in ARGS.
The rest are discarded.
If rest_args is set then we assume macarg absorbed the rest of the args.
*/
i = 0;
rest_args = 0;
do {
/* Discard the open-parenthesis or comma before the next arg. */
++instack[indepth].bufp;
if (rest_args)
continue;
if (i < nargs || (nargs == 0 && i == 0)) {
/* If we are working on last arg which absorbs rest of args... */
if (i == nargs - 1 && defn->rest_args)
rest_args = 1;
parse_error = macarg (&args[i], rest_args);
}
else
parse_error = macarg (NULL_PTR, 0);
if (parse_error) {
error_with_line (line_for_error (start_line),
"unterminated macro call");
break;
}
i++;
} while (*instack[indepth].bufp != ')');
/* If we got one arg but it was just whitespace, call that 0 args. */
if (i == 1) {
register U_CHAR *bp = args[0].raw;
register U_CHAR *lim = bp + args[0].raw_length;
/* cpp.texi says for foo ( ) we provide one argument.
However, if foo wants just 0 arguments, treat this as 0. */
if (nargs == 0)
while (bp != lim && is_space[*bp]) bp++;
if (bp == lim)
i = 0;
}
/* Don't output an error message if we have already output one for
a parse error above. */
rest_zero = 0;
if (nargs == 0 && i > 0) {
if (! parse_error)
error ("arguments given to macro `%s'", hp->name);
} else if (i < nargs) {
/* traditional C allows foo() if foo wants one argument. */
if (nargs == 1 && i == 0 && traditional)
;
/* the rest args token is allowed to absorb 0 tokens */
else if (i == nargs - 1 && defn->rest_args)
rest_zero = 1;
else if (parse_error)
;
else if (i == 0)
error ("macro `%s' used without args", hp->name);
else if (i == 1)
error ("macro `%s' used with just one arg", hp->name);
else
error ("macro `%s' used with only %d args", hp->name, i);
} else if (i > nargs) {
if (! parse_error)
error ("macro `%s' used with too many (%d) args", hp->name, i);
}
/* Swallow the closeparen. */
++instack[indepth].bufp;
/* If macro wants zero args, we parsed the arglist for checking only.
Read directly from the macro definition. */
if (nargs == 0) {
xbuf = defn->expansion;
xbuf_len = defn->length;
} else {
register U_CHAR *exp = defn->expansion;
register int offset; /* offset in expansion,
copied a piece at a time */
register int totlen; /* total amount of exp buffer filled so far */
register struct reflist *ap, *last_ap;
/* Macro really takes args. Compute the expansion of this call. */
/* Compute length in characters of the macro's expansion.
Also count number of times each arg is used. */
xbuf_len = defn->length;
for (ap = defn->pattern; ap != NULL; ap = ap->next) {
if (ap->stringify)
xbuf_len += args[ap->argno].stringified_length;
else if (ap->raw_before != 0 || ap->raw_after != 0 || traditional)
/* Add 4 for two newline-space markers to prevent
token concatenation. */
xbuf_len += args[ap->argno].raw_length + 4;
else {
/* We have an ordinary (expanded) occurrence of the arg.
So compute its expansion, if we have not already. */
if (args[ap->argno].expanded == 0) {
FILE_BUF obuf;
obuf = expand_to_temp_buffer (args[ap->argno].raw,
args[ap->argno].raw + args[ap->argno].raw_length,
1, 0);
args[ap->argno].expanded = obuf.buf;
args[ap->argno].expand_length = obuf.length;
args[ap->argno].free2 = obuf.buf;
}
/* Add 4 for two newline-space markers to prevent
token concatenation. */
xbuf_len += args[ap->argno].expand_length + 4;
}
if (args[ap->argno].use_count < 10)
args[ap->argno].use_count++;
}
xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
/* Generate in XBUF the complete expansion
with arguments substituted in.
TOTLEN is the total size generated so far.
OFFSET is the index in the definition
of where we are copying from. */
offset = totlen = 0;
for (last_ap = NULL, ap = defn->pattern; ap != NULL;
last_ap = ap, ap = ap->next) {
register struct argdata *arg = &args[ap->argno];
int count_before = totlen;
/* Add chars to XBUF. */
for (i = 0; i < ap->nchars; i++, offset++)
xbuf[totlen++] = exp[offset];
/* If followed by an empty rest arg with concatenation,
delete the last run of nonwhite chars. */
if (rest_zero && totlen > count_before
&& ((ap->rest_args && ap->raw_before != 0)
|| (last_ap != NULL && last_ap->rest_args
&& last_ap->raw_after != 0))) {
/* Delete final whitespace. */
while (totlen > count_before && is_space[xbuf[totlen - 1]]) {
totlen--;
}
/* Delete the nonwhites before them. */
while (totlen > count_before && ! is_space[xbuf[totlen - 1]]) {
totlen--;
}
}
if (ap->stringify != 0) {
int arglen = arg->raw_length;
int escaped = 0;
int in_string = 0;
int c;
i = 0;
while (i < arglen
&& (c = arg->raw[i], is_space[c]))
i++;
while (i < arglen
&& (c = arg->raw[arglen - 1], is_space[c]))
arglen--;
if (!traditional)
xbuf[totlen++] = '\"'; /* insert beginning quote */
for (; i < arglen; i++) {
c = arg->raw[i];
if (! in_string) {
/* Special markers Newline Space
generate nothing for a stringified argument. */
if (c == '\n' && arg->raw[i+1] != '\n') {
i++;
continue;
}
/* Internal sequences of whitespace are replaced by one space
except within an string or char token. */
if (c == '\n' ? arg->raw[i+1] == '\n' : is_space[c]) {
while (1) {
/* Note that Newline Space does occur within whitespace
sequences; consider it part of the sequence. */
if (c == '\n' && is_space[arg->raw[i+1]])
i += 2;
else if (c != '\n' && is_space[c])
i++;
else break;
c = arg->raw[i];
}
i--;
c = ' ';
}
}
if (escaped)
escaped = 0;
else {
if (c == '\\')
escaped = 1;
else if (in_string) {
if (c == in_string)
in_string = 0;
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (arg->raw + i, arglen - i);
if (length > 1)
{
bcopy (arg->raw + i, xbuf + totlen, length);
i += length - 1;
totlen += length;
continue;
}
#endif
}
} else if (c == '\"' || c == '\'')
in_string = c;
}
/* Escape these chars */
if (c == '\"' || (in_string && c == '\\'))
xbuf[totlen++] = '\\';
/* We used to output e.g. \008 for control characters here,
but this doesn't conform to the C Standard.
Just output the characters as-is. */
xbuf[totlen++] = c;
}
if (!traditional)
xbuf[totlen++] = '\"'; /* insert ending quote */
} else if (ap->raw_before != 0 || ap->raw_after != 0 || traditional) {
U_CHAR *p1 = arg->raw;
U_CHAR *l1 = p1 + arg->raw_length;
if (ap->raw_before != 0) {
while (p1 != l1 && is_space[*p1]) p1++;
while (p1 != l1 && is_idchar[*p1])
xbuf[totlen++] = *p1++;
/* Delete any no-reexpansion marker that follows
an identifier at the beginning of the argument
if the argument is concatenated with what precedes it. */
if (p1[0] == '\n' && p1[1] == '-')
p1 += 2;
} else if (!traditional) {
/* Ordinary expanded use of the argument.
Put in newline-space markers to prevent token pasting. */
xbuf[totlen++] = '\n';
xbuf[totlen++] = ' ';
}
if (ap->raw_after != 0) {
/* Arg is concatenated after: delete trailing whitespace,
whitespace markers, and no-reexpansion markers. */
while (p1 != l1) {
if (is_space[l1[-1]]) l1--;
else if (l1[-1] == '-') {
U_CHAR *p2 = l1 - 1;
/* If a `-' is preceded by an odd number of newlines then it
and the last newline are a no-reexpansion marker. */
while (p2 != p1 && p2[-1] == '\n') p2--;
if ((l1 - 1 - p2) & 1) {
l1 -= 2;
}
else break;
}
else break;
}
}
bcopy ((char *) p1, (char *) (xbuf + totlen), l1 - p1);
totlen += l1 - p1;
if (!traditional && ap->raw_after == 0) {
/* Ordinary expanded use of the argument.
Put in newline-space markers to prevent token pasting. */
xbuf[totlen++] = '\n';
xbuf[totlen++] = ' ';
}
} else {
/* Ordinary expanded use of the argument.
Put in newline-space markers to prevent token pasting. */
if (!traditional) {
xbuf[totlen++] = '\n';
xbuf[totlen++] = ' ';
}
bcopy ((char *) arg->expanded, (char *) (xbuf + totlen),
arg->expand_length);
totlen += arg->expand_length;
if (!traditional) {
xbuf[totlen++] = '\n';
xbuf[totlen++] = ' ';
}
/* If a macro argument with newlines is used multiple times,
then only expand the newlines once. This avoids creating output
lines which don't correspond to any input line, which confuses
gdb and gcov. */
if (arg->use_count > 1 && arg->newlines > 0) {
/* Don't bother doing change_newlines for subsequent
uses of arg. */
arg->use_count = 1;
arg->expand_length
= change_newlines (arg->expanded, arg->expand_length);
}
}
if (totlen > xbuf_len)
abort ();
}
/* If there is anything left of the definition after handling
the arg list, copy that in too. */
for (i = offset; i < defn->length; i++) {
/* if we've reached the end of the macro */
if (exp[i] == ')')
rest_zero = 0;
if (! (rest_zero && last_ap != NULL && last_ap->rest_args
&& last_ap->raw_after != 0))
xbuf[totlen++] = exp[i];
}
xbuf[totlen] = 0;
xbuf_len = totlen;
for (i = 0; i < nargs; i++) {
if (args[i].free1 != 0)
free (args[i].free1);
if (args[i].free2 != 0)
free (args[i].free2);
}
}
} else {
xbuf = defn->expansion;
xbuf_len = defn->length;
}
/* Now put the expansion on the input stack
so our caller will commence reading from it. */
{
register FILE_BUF *ip2;
ip2 = &instack[++indepth];
ip2->fname = 0;
ip2->nominal_fname = 0;
ip2->nominal_fname_len = 0;
ip2->inc = 0;
/* This may not be exactly correct, but will give much better error
messages for nested macro calls than using a line number of zero. */
ip2->lineno = start_line;
ip2->buf = xbuf;
ip2->length = xbuf_len;
ip2->bufp = xbuf;
ip2->free_ptr = (nargs > 0) ? xbuf : 0;
ip2->macro = hp;
ip2->if_stack = if_stack;
ip2->system_header_p = 0;
/* Recursive macro use sometimes works traditionally.
#define foo(x,y) bar (x (y,0), y)
foo (foo, baz) */
if (!traditional)
hp->type = T_DISABLED;
}
}
/* Parse a macro argument and store the info on it into *ARGPTR.
REST_ARGS is passed to macarg1 to make it absorb the rest of the args.
Return nonzero to indicate a syntax error. */
static int
macarg (argptr, rest_args)
register struct argdata *argptr;
int rest_args;
{
FILE_BUF *ip = &instack[indepth];
int paren = 0;
int newlines = 0;
int comments = 0;
int result = 0;
/* Try to parse as much of the argument as exists at this
input stack level. */
U_CHAR *bp = macarg1 (ip->bufp, ip->buf + ip->length, ip->macro,
&paren, &newlines, &comments, rest_args);
/* If we find the end of the argument at this level,
set up *ARGPTR to point at it in the input stack. */
if (!(ip->fname != 0 && (newlines != 0 || comments != 0))
&& bp != ip->buf + ip->length) {
if (argptr != 0) {
argptr->raw = ip->bufp;
argptr->raw_length = bp - ip->bufp;
argptr->newlines = newlines;
}
ip->bufp = bp;
} else {
/* This input stack level ends before the macro argument does.
We must pop levels and keep parsing.
Therefore, we must allocate a temporary buffer and copy
the macro argument into it. */
int bufsize = bp - ip->bufp;
int extra = newlines;
U_CHAR *buffer = (U_CHAR *) xmalloc (bufsize + extra + 1);
int final_start = 0;
bcopy ((char *) ip->bufp, (char *) buffer, bufsize);
ip->bufp = bp;
ip->lineno += newlines;
while (bp == ip->buf + ip->length) {
if (instack[indepth].macro == 0) {
result = 1;
break;
}
ip->macro->type = T_MACRO;
if (ip->free_ptr)
free (ip->free_ptr);
ip = &instack[--indepth];
newlines = 0;
comments = 0;
bp = macarg1 (ip->bufp, ip->buf + ip->length, ip->macro, &paren,
&newlines, &comments, rest_args);
final_start = bufsize;
bufsize += bp - ip->bufp;
extra += newlines;
buffer = (U_CHAR *) xrealloc (buffer, bufsize + extra + 1);
bcopy ((char *) ip->bufp, (char *) (buffer + bufsize - (bp - ip->bufp)),
bp - ip->bufp);
ip->bufp = bp;
ip->lineno += newlines;
}
/* Now, if arg is actually wanted, record its raw form,
discarding comments and duplicating newlines in whatever
part of it did not come from a macro expansion.
EXTRA space has been preallocated for duplicating the newlines.
FINAL_START is the index of the start of that part. */
if (argptr != 0) {
argptr->raw = buffer;
argptr->raw_length = bufsize;
argptr->free1 = buffer;
argptr->newlines = newlines;
if ((newlines || comments) && ip->fname != 0)
argptr->raw_length
= final_start +
discard_comments (argptr->raw + final_start,
argptr->raw_length - final_start,
newlines);
argptr->raw[argptr->raw_length] = 0;
if (argptr->raw_length > bufsize + extra)
abort ();
}
}
/* If we are not discarding this argument,
macroexpand it and compute its length as stringified.
All this info goes into *ARGPTR. */
if (argptr != 0) {
register U_CHAR *buf, *lim;
register int totlen;
buf = argptr->raw;
lim = buf + argptr->raw_length;
while (buf != lim && is_space[*buf])
buf++;
while (buf != lim && is_space[lim[-1]])
lim--;
totlen = traditional ? 0 : 2; /* Count opening and closing quote. */
while (buf != lim) {
register U_CHAR c = *buf++;
totlen++;
/* Internal sequences of whitespace are replaced by one space
in most cases, but not always. So count all the whitespace
in case we need to keep it all. */
#if 0
if (is_space[c])
SKIP_ALL_WHITE_SPACE (buf);
else
#endif
if (c == '\"' || c == '\\') /* escape these chars */
totlen++;
}
argptr->stringified_length = totlen;
}
return result;
}
/* Scan text from START (inclusive) up to LIMIT (exclusive),
taken from the expansion of MACRO,
counting parens in *DEPTHPTR,
and return if reach LIMIT
or before a `)' that would make *DEPTHPTR negative
or before a comma when *DEPTHPTR is zero.
Single and double quotes are matched and termination
is inhibited within them. Comments also inhibit it.
Value returned is pointer to stopping place.
Increment *NEWLINES each time a newline is passed.
REST_ARGS notifies macarg1 that it should absorb the rest of the args.
Set *COMMENTS to 1 if a comment is seen. */
static U_CHAR *
macarg1 (start, limit, macro, depthptr, newlines, comments, rest_args)
U_CHAR *start;
register U_CHAR *limit;
struct hashnode *macro;
int *depthptr, *newlines, *comments;
int rest_args;
{
register U_CHAR *bp = start;
while (bp < limit) {
switch (*bp) {
case '(':
(*depthptr)++;
break;
case ')':
if (--(*depthptr) < 0)
return bp;
break;
case '\\':
/* Traditionally, backslash makes following char not special. */
if (traditional && bp + 1 < limit && bp[1] != '\n')
bp++;
break;
case '\n':
++*newlines;
break;
case '/':
if (macro)
break;
if (bp[1] == '\\' && bp[2] == '\n')
newline_fix (bp + 1);
if (bp[1] == '*') {
*comments = 1;
for (bp += 2; bp < limit; bp++) {
if (*bp == '\n')
++*newlines;
else if (*bp == '*') {
if (bp[-1] == '/' && warn_comments)
warning ("`/*' within comment");
if (bp[1] == '\\' && bp[2] == '\n')
newline_fix (bp + 1);
if (bp[1] == '/') {
bp++;
break;
}
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (bp, limit - bp);
if (length > 1)
bp += (length - 1);
#endif
}
}
} else if (bp[1] == '/' && cplusplus_comments) {
*comments = 1;
for (bp += 2; bp < limit; bp++) {
if (*bp == '\n') {
++*newlines;
break;
}
if (*bp == '\\' && bp + 1 < limit && bp[1] == '\n')
{
++*newlines;
if (warn_comments)
warning ("multiline `//' comment");
++bp;
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (bp, limit - bp);
if (length > 1)
bp += (length - 1);
#endif
}
}
}
break;
case '\'':
case '\"':
{
int quotec;
for (quotec = *bp++; bp + 1 < limit && *bp != quotec; bp++) {
if (*bp == '\\') {
bp++;
if (*bp == '\n')
++*newlines;
if (!macro) {
while (*bp == '\\' && bp[1] == '\n') {
bp += 2;
++*newlines;
}
}
} else if (*bp == '\n') {
++*newlines;
if (quotec == '\'')
break;
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
length = local_mblen (bp, limit - bp);
if (length > 1)
bp += (length - 1);
#endif
}
}
}
break;
case ',':
/* if we've returned to lowest level and we aren't absorbing all args */
if ((*depthptr) == 0 && rest_args == 0)
return bp;
break;
}
bp++;
}
return bp;
}
/* Discard comments and duplicate newlines
in the string of length LENGTH at START,
except inside of string constants.
The string is copied into itself with its beginning staying fixed.
NEWLINES is the number of newlines that must be duplicated.
We assume that that much extra space is available past the end
of the string. */
static int
discard_comments (start, length, newlines)
U_CHAR *start;
int length;
int newlines;
{
register U_CHAR *ibp;
register U_CHAR *obp;
register U_CHAR *limit;
register int c;
/* If we have newlines to duplicate, copy everything
that many characters up. Then, in the second part,
we will have room to insert the newlines
while copying down.
NEWLINES may actually be too large, because it counts
newlines in string constants, and we don't duplicate those.
But that does no harm. */
if (newlines > 0) {
ibp = start + length;
obp = ibp + newlines;
limit = start;
while (limit != ibp)
*--obp = *--ibp;
}
ibp = start + newlines;
limit = start + length + newlines;
obp = start;
while (ibp < limit) {
*obp++ = c = *ibp++;
switch (c) {
case '\n':
/* Duplicate the newline. */
*obp++ = '\n';
break;
case '\\':
if (*ibp == '\n') {
obp--;
ibp++;
}
break;
case '/':
if (*ibp == '\\' && ibp[1] == '\n')
newline_fix (ibp);
/* Delete any comment. */
if (cplusplus_comments && ibp[0] == '/') {
/* Comments are equivalent to spaces. */
obp[-1] = ' ';
ibp++;
while (ibp < limit)
{
if (*ibp == '\n')
break;
if (*ibp == '\\' && ibp + 1 < limit && ibp[1] == '\n')
ibp++;
else
{
#ifdef MULTIBYTE_CHARS
int length = local_mblen (ibp, limit - ibp);
if (length > 1)
ibp += (length - 1);
#endif
}
ibp++;
}
break;
}
if (ibp[0] != '*' || ibp + 1 >= limit)
break;
/* Comments are equivalent to spaces.
For -traditional, a comment is equivalent to nothing. */
if (traditional)
obp--;
else
obp[-1] = ' ';
while (++ibp < limit) {
if (ibp[0] == '*') {
if (ibp[1] == '\\' && ibp[2] == '\n')
newline_fix (ibp + 1);
if (ibp[1] == '/') {
ibp += 2;
break;
}
}
else
{
#ifdef MULTIBYTE_CHARS
int length = local_mblen (ibp, limit - ibp);
if (length > 1)
ibp += (length - 1);
#endif
}
}
break;
case '\'':
case '\"':
/* Notice and skip strings, so that we don't
think that comments start inside them,
and so we don't duplicate newlines in them. */
{
int quotec = c;
while (ibp < limit) {
*obp++ = c = *ibp++;
if (c == quotec)
break;
if (c == '\n')
{
if (quotec == '\'')
break;
}
else if (c == '\\') {
if (ibp < limit && *ibp == '\n') {
ibp++;
obp--;
} else {
while (*ibp == '\\' && ibp[1] == '\n')
ibp += 2;
if (ibp < limit)
*obp++ = *ibp++;
}
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
ibp--;
length = local_mblen (ibp, limit - ibp);
if (length > 1)
{
obp--;
bcopy (ibp, obp, length);
ibp += length;
obp += length;
}
else
ibp++;
#endif
}
}
}
break;
}
}
return obp - start;
}
/* Turn newlines to spaces in the string of length LENGTH at START,
except inside of string constants.
The string is copied into itself with its beginning staying fixed. */
static int
change_newlines (start, length)
U_CHAR *start;
int length;
{
register U_CHAR *ibp;
register U_CHAR *obp;
register U_CHAR *limit;
register int c;
ibp = start;
limit = start + length;
obp = start;
while (ibp < limit) {
*obp++ = c = *ibp++;
switch (c) {
case '\n':
/* If this is a NEWLINE NEWLINE, then this is a real newline in the
string. Skip past the newline and its duplicate.
Put a space in the output. */
if (*ibp == '\n')
{
ibp++;
obp--;
*obp++ = ' ';
}
break;
case '\'':
case '\"':
/* Notice and skip strings, so that we don't delete newlines in them. */
{
int quotec = c;
while (ibp < limit) {
*obp++ = c = *ibp++;
if (c == quotec)
break;
else if (c == '\\' && ibp < limit && *ibp == '\n')
*obp++ = *ibp++;
else if (c == '\n')
{
if (quotec == '\'')
break;
}
else
{
#ifdef MULTIBYTE_CHARS
int length;
ibp--;
length = local_mblen (ibp, limit - ibp);
if (length > 1)
{
obp--;
bcopy (ibp, obp, length);
ibp += length;
obp += length;
}
else
ibp++;
#endif
}
}
}
break;
}
}
return obp - start;
}
/* my_strerror - return the descriptive text associated with an
`errno' code. */
static char *
my_strerror (errnum)
int errnum;
{
char *result;
#ifndef VMS
#ifndef HAVE_STRERROR
result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
#else
result = strerror (errnum);
#endif
#else /* VMS */
/* VAXCRTL's strerror() takes an optional second argument, which only
matters when the first argument is EVMSERR. However, it's simplest
just to pass it unconditionally. `vaxc$errno' is declared in
<errno.h>, and maintained by the library in parallel with `errno'.
We assume that caller's `errnum' either matches the last setting of
`errno' by the library or else does not have the value `EVMSERR'. */
result = strerror (errnum, vaxc$errno);
#endif
if (!result)
result = "errno = ?";
return result;
}
/* notice - output message to stderr */
static void
notice VPROTO ((const char * msgid, ...))
{
#ifndef ANSI_PROTOTYPES
const char * msgid;
#endif
va_list args;
VA_START (args, msgid);
#ifndef ANSI_PROTOTYPES
msgid = va_arg (args, const char *);
#endif
vnotice (msgid, args);
va_end (args);
}
static void
vnotice (msgid, args)
const char *msgid;
va_list args;
{
vfprintf (stderr, _(msgid), args);
}
/* error - print error message and increment count of errors. */
void
error VPROTO ((const char * msgid, ...))
{
#ifndef ANSI_PROTOTYPES
const char * msgid;
#endif
va_list args;
VA_START (args, msgid);
#ifndef ANSI_PROTOTYPES
msgid = va_arg (args, const char *);
#endif
verror (msgid, args);
va_end (args);
}
void
verror (msgid, args)
const char *msgid;
va_list args;
{
int i;
FILE_BUF *ip = NULL;
print_containing_files ();
for (i = indepth; i >= 0; i--)
if (instack[i].fname != NULL) {
ip = &instack[i];
break;
}
if (ip != NULL) {
eprint_string (ip->nominal_fname, ip->nominal_fname_len);
fprintf (stderr, ":%d: ", ip->lineno);
}
vnotice (msgid, args);
fprintf (stderr, "\n");
errors++;
}
/* Error including a message from `errno'. */
static void
error_from_errno (name)
char *name;
{
int e = errno;
int i;
FILE_BUF *ip = NULL;
print_containing_files ();
for (i = indepth; i >= 0; i--)
if (instack[i].fname != NULL) {
ip = &instack[i];
break;
}
if (ip != NULL) {
eprint_string (ip->nominal_fname, ip->nominal_fname_len);
fprintf (stderr, ":%d: ", ip->lineno);
}
fprintf (stderr, "%s: %s\n", name, my_strerror (e));
errors++;
}
/* Print error message but don't count it. */
void
warning VPROTO ((const char * msgid, ...))
{
#ifndef ANSI_PROTOTYPES
const char * msgid;
#endif
va_list args;
VA_START (args, msgid);
#ifndef ANSI_PROTOTYPES
msgid = va_arg (args, const char *);
#endif
vwarning (msgid, args);
va_end (args);
}
static void
vwarning (msgid, args)
const char *msgid;
va_list args;
{
int i;
FILE_BUF *ip = NULL;
if (inhibit_warnings)
return;
if (warnings_are_errors)
errors++;
print_containing_files ();
for (i = indepth; i >= 0; i--)
if (instack[i].fname != NULL) {
ip = &instack[i];
break;
}
if (ip != NULL) {
eprint_string (ip->nominal_fname, ip->nominal_fname_len);
fprintf (stderr, ":%d: ", ip->lineno);
}
notice ("warning: ");
vnotice (msgid, args);
fprintf (stderr, "\n");
}
static void
error_with_line VPROTO ((int line, const char * msgid, ...))
{
#ifndef ANSI_PROTOTYPES
int line;
const char * msgid;
#endif
va_list args;
VA_START (args, msgid);
#ifndef ANSI_PROTOTYPES
line = va_arg (args, int);
msgid = va_arg (args, const char *);
#endif
verror_with_line (line, msgid, args);
va_end (args);
}
static void
verror_with_line (line, msgid, args)
int line;
const char *msgid;
va_list args;
{
int i;
FILE_BUF *ip = NULL;
print_containing_files ();
for (i = indepth; i >= 0; i--)
if (instack[i].fname != NULL) {
ip = &instack[i];
break;
}
if (ip != NULL) {
eprint_string (ip->nominal_fname, ip->nominal_fname_len);
fprintf (stderr, ":%d: ", line);
}
vnotice (msgid, args);
fprintf (stderr, "\n");
errors++;
}
static void
warning_with_line VPROTO ((int line, const char * msgid, ...))
{
#ifndef ANSI_PROTOTYPES
int line;
const char * msgid;
#endif
va_list args;
VA_START (args, msgid);
#ifndef ANSI_PROTOTYPES
line = va_arg (args, int);
msgid = va_arg (args, const char *);
#endif
vwarning_with_line (line, msgid, args);
va_end (args);
}
static void
vwarning_with_line (line, msgid, args)
int line;
const char *msgid;
va_list args;
{
int i;
FILE_BUF *ip = NULL;
if (inhibit_warnings)
return;
if (warnings_are_errors)
errors++;
print_containing_files ();
for (i = indepth; i >= 0; i--)
if (instack[i].fname != NULL) {
ip = &instack[i];
break;
}
if (ip != NULL) {
eprint_string (ip->nominal_fname, ip->nominal_fname_len);
fprintf (stderr, line ? ":%d: " : ": ", line);
}
notice ("warning: ");
vnotice (msgid, args);
fprintf (stderr, "\n");
}
/* Print an error message and maybe count it. */
void
pedwarn VPROTO ((const char * msgid, ...))
{
#ifndef ANSI_PROTOTYPES
const char * msgid;
#endif
va_list args;
VA_START (args, msgid);
#ifndef ANSI_PROTOTYPES
msgid = va_arg (args, const char *);
#endif
if (pedantic_errors)
verror (msgid, args);
else
vwarning (msgid, args);
va_end (args);
}
void
pedwarn_with_line VPROTO ((int line, const char * msgid, ...))
{
#ifndef ANSI_PROTOTYPES
int line;
const char * msgid;
#endif
va_list args;
VA_START (args, msgid);
#ifndef ANSI_PROTOTYPES
line = va_arg (args, int);
msgid = va_arg (args, const char *);
#endif
if (pedantic_errors)
verror_with_line (line, msgid, args);
else
vwarning_with_line (line, msgid, args);
va_end (args);
}
/* Report a warning (or an error if pedantic_errors)
giving specified file name and line number, not current. */
static void
pedwarn_with_file_and_line VPROTO ((const char *file, size_t file_len, int line,
const char * msgid, ...))
{
#ifndef ANSI_PROTOTYPES
const char *file;
size_t file_len;
int line;
const char * msgid;
#endif
va_list args;
if (!pedantic_errors && inhibit_warnings)
return;
VA_START (args, msgid);
#ifndef ANSI_PROTOTYPES
file = va_arg (args, const char *);
file_len = va_arg (args, size_t);
line = va_arg (args, int);
msgid = va_arg (args, const char *);
#endif
if (file) {
eprint_string (file, file_len);
fprintf (stderr, ":%d: ", line);
}
if (pedantic_errors)
errors++;
if (!pedantic_errors)
notice ("warning: ");
vnotice (msgid, args);
va_end (args);
fprintf (stderr, "\n");
}
static void
pedwarn_strange_white_space (ch)
int ch;
{
switch (ch)
{
case '\f': pedwarn ("formfeed in preprocessing directive"); break;
case '\r': pedwarn ("carriage return in preprocessing directive"); break;
case '\v': pedwarn ("vertical tab in preprocessing directive"); break;
default: abort ();
}
}
/* Print the file names and line numbers of the #include
directives which led to the current file. */
static void
print_containing_files ()
{
FILE_BUF *ip = NULL;
int i;
int first = 1;
/* If stack of files hasn't changed since we last printed
this info, don't repeat it. */
if (last_error_tick == input_file_stack_tick)
return;
for (i = indepth; i >= 0; i--)
if (instack[i].fname != NULL) {
ip = &instack[i];
break;
}
/* Give up if we don't find a source file. */
if (ip == NULL)
return;
/* Find the other, outer source files. */
for (i--; i >= 0; i--)
if (instack[i].fname != NULL) {
ip = &instack[i];
if (first) {
first = 0;
notice ( "In file included from ");
} else {
notice (",\n from ");
}
eprint_string (ip->nominal_fname, ip->nominal_fname_len);
fprintf (stderr, ":%d", ip->lineno);
}
if (! first)
fprintf (stderr, ":\n");
/* Record we have printed the status as of this time. */
last_error_tick = input_file_stack_tick;
}
/* Return the line at which an error occurred.
The error is not necessarily associated with the current spot
in the input stack, so LINE says where. LINE will have been
copied from ip->lineno for the current input level.
If the current level is for a file, we return LINE.
But if the current level is not for a file, LINE is meaningless.
In that case, we return the lineno of the innermost file. */
static int
line_for_error (line)
int line;
{
int i;
int line1 = line;
for (i = indepth; i >= 0; ) {
if (instack[i].fname != 0)
return line1;
i--;
if (i < 0)
return 0;
line1 = instack[i].lineno;
}
abort ();
/*NOTREACHED*/
return 0;
}
/*
* If OBUF doesn't have NEEDED bytes after OPTR, make it bigger.
*
* As things stand, nothing is ever placed in the output buffer to be
* removed again except when it's KNOWN to be part of an identifier,
* so flushing and moving down everything left, instead of expanding,
* should work ok.
*/
/* You might think void was cleaner for the return type,
but that would get type mismatch in check_expand in strict ANSI. */
static int
grow_outbuf (obuf, needed)
register FILE_BUF *obuf;
register int needed;
{
register U_CHAR *p;
int minsize;
if (obuf->length - (obuf->bufp - obuf->buf) > needed)
return 0;
/* Make it at least twice as big as it is now. */
obuf->length *= 2;
/* Make it have at least 150% of the free space we will need. */
minsize = (3 * needed) / 2 + (obuf->bufp - obuf->buf);
if (minsize > obuf->length)
obuf->length = minsize;
if ((p = (U_CHAR *) xrealloc (obuf->buf, obuf->length)) == NULL)
memory_full ();
obuf->bufp = p + (obuf->bufp - obuf->buf);
obuf->buf = p;
return 0;
}
/* Symbol table for macro names and special symbols */
/*
* install a name in the main hash table, even if it is already there.
* name stops with first non alphanumeric, except leading '#'.
* caller must check against redefinition if that is desired.
* delete_macro () removes things installed by install () in fifo order.
* this is important because of the `defined' special symbol used
* in #if, and also if pushdef/popdef directives are ever implemented.
*
* If LEN is >= 0, it is the length of the name.
* Otherwise, compute the length by scanning the entire name.
*
* If HASH is >= 0, it is the precomputed hash code.
* Otherwise, compute the hash code.
*/
static HASHNODE *
install (name, len, type, value, hash)
U_CHAR *name;
int len;
enum node_type type;
char *value;
int hash;
{
register HASHNODE *hp;
register int i, bucket;
register U_CHAR *p, *q;
if (len < 0) {
p = name;
while (is_idchar[*p])
p++;
len = p - name;
}
if (hash < 0)
hash = hashf (name, len, HASHSIZE);
i = sizeof (HASHNODE) + len + 1;
hp = (HASHNODE *) xmalloc (i);
bucket = hash;
hp->bucket_hdr = &hashtab[bucket];
hp->next = hashtab[bucket];
hashtab[bucket] = hp;
hp->prev = NULL;
if (hp->next != NULL)
hp->next->prev = hp;
hp->type = type;
hp->length = len;
hp->value.cpval = value;
hp->name = ((U_CHAR *) hp) + sizeof (HASHNODE);
p = hp->name;
q = name;
for (i = 0; i < len; i++)
*p++ = *q++;
hp->name[len] = 0;
return hp;
}
/*
* find the most recent hash node for name "name" (ending with first
* non-identifier char) installed by install
*
* If LEN is >= 0, it is the length of the name.
* Otherwise, compute the length by scanning the entire name.
*
* If HASH is >= 0, it is the precomputed hash code.
* Otherwise, compute the hash code.
*/
HASHNODE *
lookup (name, len, hash)
U_CHAR *name;
int len;
int hash;
{
register U_CHAR *bp;
register HASHNODE *bucket;
if (len < 0) {
for (bp = name; is_idchar[*bp]; bp++) ;
len = bp - name;
}
if (hash < 0)
hash = hashf (name, len, HASHSIZE);
bucket = hashtab[hash];
while (bucket) {
if (bucket->length == len && bcmp (bucket->name, name, len) == 0)
return bucket;
bucket = bucket->next;
}
return NULL;
}
/*
* Delete a hash node. Some weirdness to free junk from macros.
* More such weirdness will have to be added if you define more hash
* types that need it.
*/
/* Note that the DEFINITION of a macro is removed from the hash table
but its storage is not freed. This would be a storage leak
except that it is not reasonable to keep undefining and redefining
large numbers of macros many times.
In any case, this is necessary, because a macro can be #undef'd
in the middle of reading the arguments to a call to it.
If #undef freed the DEFINITION, that would crash. */
static void
delete_macro (hp)
HASHNODE *hp;
{
if (hp->prev != NULL)
hp->prev->next = hp->next;
if (hp->next != NULL)
hp->next->prev = hp->prev;
/* Make sure that the bucket chain header that the deleted guy was
on points to the right thing afterwards. */
if (hp == *hp->bucket_hdr)
*hp->bucket_hdr = hp->next;
#if 0
if (hp->type == T_MACRO) {
DEFINITION *d = hp->value.defn;
struct reflist *ap, *nextap;
for (ap = d->pattern; ap != NULL; ap = nextap) {
nextap = ap->next;
free (ap);
}
free (d);
}
#endif
free (hp);
}
/*
* return hash function on name. must be compatible with the one
* computed a step at a time, elsewhere
*/
static int
hashf (name, len, hashsize)
register U_CHAR *name;
register int len;
int hashsize;
{
register int r = 0;
while (len--)
r = HASHSTEP (r, *name++);
return MAKE_POS (r) % hashsize;
}
/* Dump the definition of a single macro HP to OF. */
static void
dump_single_macro (hp, of)
register HASHNODE *hp;
FILE *of;
{
register DEFINITION *defn = hp->value.defn;
struct reflist *ap;
int offset;
int concat;
/* Print the definition of the macro HP. */
fprintf (of, "#define %s", hp->name);
if (defn->nargs >= 0) {
int i;
fprintf (of, "(");
for (i = 0; i < defn->nargs; i++) {
dump_arg_n (defn, i, of);
if (i + 1 < defn->nargs)
fprintf (of, ", ");
}
fprintf (of, ")");
}
fprintf (of, " ");
offset = 0;
concat = 0;
for (ap = defn->pattern; ap != NULL; ap = ap->next) {
dump_defn_1 (defn->expansion, offset, ap->nchars, of);
offset += ap->nchars;
if (!traditional) {
if (ap->nchars != 0)
concat = 0;
if (ap->stringify) {
switch (ap->stringify) {
case SHARP_TOKEN: fprintf (of, "#"); break;
case WHITE_SHARP_TOKEN: fprintf (of, "# "); break;
case PERCENT_COLON_TOKEN: fprintf (of, "%%:"); break;
case WHITE_PERCENT_COLON_TOKEN: fprintf (of, "%%: "); break;
default: abort ();
}
}
if (ap->raw_before != 0) {
if (concat) {
switch (ap->raw_before) {
case WHITE_SHARP_TOKEN:
case WHITE_PERCENT_COLON_TOKEN:
fprintf (of, " ");
break;
default:
break;
}
} else {
switch (ap->raw_before) {
case SHARP_TOKEN: fprintf (of, "##"); break;
case WHITE_SHARP_TOKEN: fprintf (of, "## "); break;
case PERCENT_COLON_TOKEN: fprintf (of, "%%:%%:"); break;
case WHITE_PERCENT_COLON_TOKEN: fprintf (of, "%%:%%: "); break;
default: abort ();
}
}
}
concat = 0;
}
dump_arg_n (defn, ap->argno, of);
if (!traditional && ap->raw_after != 0) {
switch (ap->raw_after) {
case SHARP_TOKEN: fprintf (of, "##"); break;
case WHITE_SHARP_TOKEN: fprintf (of, " ##"); break;
case PERCENT_COLON_TOKEN: fprintf (of, "%%:%%:"); break;
case WHITE_PERCENT_COLON_TOKEN: fprintf (of, " %%:%%:"); break;
default: abort ();
}
concat = 1;
}
}
dump_defn_1 (defn->expansion, offset, defn->length - offset, of);
fprintf (of, "\n");
}
/* Dump all macro definitions as #defines to stdout. */
static void
dump_all_macros ()
{
int bucket;
for (bucket = 0; bucket < HASHSIZE; bucket++) {
register HASHNODE *hp;
for (hp = hashtab[bucket]; hp; hp= hp->next) {
if (hp->type == T_MACRO)
dump_single_macro (hp, stdout);
}
}
}
/* Output to OF a substring of a macro definition.
BASE is the beginning of the definition.
Output characters START thru LENGTH.
Unless traditional, discard newlines outside of strings, thus
converting funny-space markers to ordinary spaces. */
static void
dump_defn_1 (base, start, length, of)
U_CHAR *base;
int start;
int length;
FILE *of;
{
U_CHAR *p = base + start;
U_CHAR *limit = base + start + length;
if (traditional)
fwrite (p, sizeof (*p), length, of);
else {
while (p < limit) {
if (*p == '\"' || *p =='\'') {
U_CHAR *p1 = skip_quoted_string (p, limit, 0, NULL_PTR,
NULL_PTR, NULL_PTR);
fwrite (p, sizeof (*p), p1 - p, of);
p = p1;
} else {
if (*p != '\n')
putc (*p, of);
p++;
}
}
}
}
/* Print the name of argument number ARGNUM of macro definition DEFN
to OF.
Recall that DEFN->args.argnames contains all the arg names
concatenated in reverse order with comma-space in between. */
static void
dump_arg_n (defn, argnum, of)
DEFINITION *defn;
int argnum;
FILE *of;
{
register U_CHAR *p = defn->args.argnames;
while (argnum + 1 < defn->nargs) {
p = (U_CHAR *) index ((char *) p, ' ') + 1;
argnum++;
}
while (*p && *p != ',') {
putc (*p, of);
p++;
}
}
/* Initialize syntactic classifications of characters. */
static void
initialize_char_syntax ()
{
register int i;
/*
* Set up is_idchar and is_idstart tables. These should be
* faster than saying (is_alpha (c) || c == '_'), etc.
* Set up these things before calling any routines tthat
* refer to them.
*/
for (i = 'a'; i <= 'z'; i++) {
is_idchar[i - 'a' + 'A'] = 1;
is_idchar[i] = 1;
is_idstart[i - 'a' + 'A'] = 1;
is_idstart[i] = 1;
}
for (i = '0'; i <= '9'; i++)
is_idchar[i] = 1;
is_idchar['_'] = 1;
is_idstart['_'] = 1;
is_idchar['$'] = 1;
is_idstart['$'] = 1;
/* horizontal space table */
is_hor_space[' '] = 1;
is_hor_space['\t'] = 1;
is_hor_space['\v'] = 1;
is_hor_space['\f'] = 1;
is_hor_space['\r'] = 1;
is_space[' '] = 1;
is_space['\t'] = 1;
is_space['\v'] = 1;
is_space['\f'] = 1;
is_space['\n'] = 1;
is_space['\r'] = 1;
}
/* Initialize the built-in macros. */
static void
initialize_builtins (inp, outp)
FILE_BUF *inp;
FILE_BUF *outp;
{
install ((U_CHAR *) "__LINE__", -1, T_SPECLINE, NULL_PTR, -1);
install ((U_CHAR *) "__DATE__", -1, T_DATE, NULL_PTR, -1);
install ((U_CHAR *) "__FILE__", -1, T_FILE, NULL_PTR, -1);
install ((U_CHAR *) "__BASE_FILE__", -1, T_BASE_FILE, NULL_PTR, -1);
install ((U_CHAR *) "__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, NULL_PTR, -1);
/* Don't setup the standard #defines - AMB
install ((U_CHAR *) "__VERSION__", -1, T_VERSION, NULL_PTR, -1);
#ifndef NO_BUILTIN_SIZE_TYPE
install ((U_CHAR *) "__SIZE_TYPE__", -1, T_SIZE_TYPE, NULL_PTR, -1);
#endif
#ifndef NO_BUILTIN_PTRDIFF_TYPE
install ((U_CHAR *) "__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE, NULL_PTR, -1);
#endif
install ((U_CHAR *) "__WCHAR_TYPE__", -1, T_WCHAR_TYPE, NULL_PTR, -1);
install ((U_CHAR *) "__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE,
NULL_PTR, -1);
install ((U_CHAR *) "__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE,
NULL_PTR, -1);
install ((U_CHAR *) "__IMMEDIATE_PREFIX__", -1, T_IMMEDIATE_PREFIX_TYPE,
NULL_PTR, -1);
*/
install ((U_CHAR *) "__TIME__", -1, T_TIME, NULL_PTR, -1);
if (!traditional) {
install ((U_CHAR *) "__STDC__", -1, T_CONST, "1", -1);
install ((U_CHAR *) "__STDC_VERSION__", -1, T_CONST, "199409L", -1);
}
/* This is supplied using a -D by the compiler driver
so that it is present only when truly compiling with GNU C. */
/* install ((U_CHAR *) "__GNUC__", -1, T_CONST, "2", -1); */
/* Don't setup the standard #defines - AMB
install ((U_CHAR *) "__HAVE_BUILTIN_SETJMP__", -1, T_CONST, "1", -1);
*/
if (debug_output)
{
char directive[2048];
U_CHAR *udirective = (U_CHAR *) directive;
register struct directive *dp = &directive_table[0];
struct tm *timebuf = timestamp ();
sprintf (directive, " __BASE_FILE__ \"%s\"\n",
instack[0].nominal_fname);
output_line_directive (inp, outp, 0, same_file);
pass_thru_directive (udirective, &udirective[strlen (directive)],
outp, dp);
/* Don't setup the standard #defines - AMB
sprintf (directive, " __VERSION__ \"%s\"\n", version_string);
output_line_directive (inp, outp, 0, same_file);
pass_thru_directive (udirective, &udirective[strlen (directive)],
outp, dp);
#ifndef NO_BUILTIN_SIZE_TYPE
sprintf (directive, " __SIZE_TYPE__ %s\n", SIZE_TYPE);
output_line_directive (inp, outp, 0, same_file);
pass_thru_directive (udirective, &udirective[strlen (directive)],
outp, dp);
#endif
#ifndef NO_BUILTIN_PTRDIFF_TYPE
sprintf (directive, " __PTRDIFF_TYPE__ %s\n", PTRDIFF_TYPE);
output_line_directive (inp, outp, 0, same_file);
pass_thru_directive (udirective, &udirective[strlen (directive)],
outp, dp);
#endif
sprintf (directive, " __WCHAR_TYPE__ %s\n", wchar_type);
output_line_directive (inp, outp, 0, same_file);
pass_thru_directive (udirective, &udirective[strlen (directive)],
outp, dp);
*/
sprintf (directive, " __DATE__ \"%s %2d %4d\"\n",
monthnames[timebuf->tm_mon],
timebuf->tm_mday, timebuf->tm_year + 1900);
output_line_directive (inp, outp, 0, same_file);
pass_thru_directive (udirective, &udirective[strlen (directive)],
outp, dp);
sprintf (directive, " __TIME__ \"%02d:%02d:%02d\"\n",
timebuf->tm_hour, timebuf->tm_min, timebuf->tm_sec);
output_line_directive (inp, outp, 0, same_file);
pass_thru_directive (udirective, &udirective[strlen (directive)],
outp, dp);
if (!traditional)
{
sprintf (directive, " __STDC__ 1");
output_line_directive (inp, outp, 0, same_file);
pass_thru_directive (udirective, &udirective[strlen (directive)],
outp, dp);
}
if (objc)
{
sprintf (directive, " __OBJC__ 1");
output_line_directive (inp, outp, 0, same_file);
pass_thru_directive (udirective, &udirective[strlen (directive)],
outp, dp);
}
}
}
/*
* process a given definition string, for initialization
* If STR is just an identifier, define it with value 1.
* If STR has anything after the identifier, then it should
* be identifier=definition.
*/
static void
make_definition (str)
char *str;
{
FILE_BUF *ip;
struct directive *kt;
U_CHAR *buf, *p;
p = buf = (U_CHAR *) str;
if (!is_idstart[*p]) {
error ("malformed option `-D %s'", str);
return;
}
while (is_idchar[*++p])
;
if (*p == '(') {
while (is_idchar[*++p] || *p == ',' || is_hor_space[*p])
;
if (*p++ != ')')
p = (U_CHAR *) str; /* Error */
}
if (*p == 0) {
buf = (U_CHAR *) alloca (p - buf + 4);
strcpy ((char *)buf, str);
strcat ((char *)buf, " 1");
} else if (*p != '=') {
error ("malformed option `-D %s'", str);
return;
} else {
U_CHAR *q;
/* Copy the entire option so we can modify it. */
buf = (U_CHAR *) alloca (2 * strlen (str) + 1);
strncpy ((char *) buf, str, p - (U_CHAR *) str);
/* Change the = to a space. */
buf[p - (U_CHAR *) str] = ' ';
/* Scan for any backslash-newline and remove it. */
p++;
q = &buf[p - (U_CHAR *) str];
while (*p) {
if (*p == '\"' || *p == '\'') {
int unterminated = 0;
U_CHAR *p1 = skip_quoted_string (p, p + strlen ((char *) p), 0,
NULL_PTR, NULL_PTR, &unterminated);
if (unterminated)
return;
while (p != p1)
*q++ = *p++;
} else if (*p == '\\' && p[1] == '\n')
p += 2;
/* Change newline chars into newline-markers. */
else if (*p == '\n')
{
*q++ = '\n';
*q++ = '\n';
p++;
}
else
*q++ = *p++;
}
*q = 0;
}
ip = &instack[++indepth];
ip->nominal_fname = ip->fname = "*Initialization*";
ip->nominal_fname_len = strlen (ip->nominal_fname);
ip->buf = ip->bufp = buf;
ip->length = strlen ((char *) buf);
ip->lineno = 1;
ip->macro = 0;
ip->free_ptr = 0;
ip->if_stack = if_stack;
ip->system_header_p = 0;
for (kt = directive_table; kt->type != T_DEFINE; kt++)
;
/* Pass NULL instead of OP, since this is a "predefined" macro. */
do_define (buf, buf + strlen ((char *) buf), NULL_PTR, kt);
--indepth;
}
/* JF, this does the work for the -U option */
static void
make_undef (str, op)
char *str;
FILE_BUF *op;
{
FILE_BUF *ip;
struct directive *kt;
ip = &instack[++indepth];
ip->nominal_fname = ip->fname = "*undef*";
ip->nominal_fname_len = strlen (ip->nominal_fname);
ip->buf = ip->bufp = (U_CHAR *) str;
ip->length = strlen (str);
ip->lineno = 1;
ip->macro = 0;
ip->free_ptr = 0;
ip->if_stack = if_stack;
ip->system_header_p = 0;
for (kt = directive_table; kt->type != T_UNDEF; kt++)
;
do_undef ((U_CHAR *) str, (U_CHAR *) str + strlen (str), op, kt);
--indepth;
}
/* Process the string STR as if it appeared as the body of a #assert.
OPTION is the option name for which STR was the argument. */
static void
make_assertion (option, str)
const char *option;
const char *str;
{
FILE_BUF *ip;
struct directive *kt;
U_CHAR *buf, *p, *q;
/* Copy the entire option so we can modify it. */
buf = (U_CHAR *) alloca (strlen (str) + 2); /* Change to handle gcc 3.x "-Afoo=bar" - AMB */
strcpy ((char *) buf, str);
/* Scan for any backslash-newline and remove it. */
p = q = buf;
while (*p) {
if (*p == '\\' && p[1] == '\n')
p += 2;
else
*q++ = *p++;
}
*q = 0;
p = buf;
if (!is_idstart[*p]) {
error ("malformed option `%s %s'", option, str);
return;
}
while (is_idchar[*++p])
;
SKIP_WHITE_SPACE (p);
if (! (*p == 0 || *p == '(' || *p == '=')) { /* Change to handle gcc 3.x "-Afoo=bar" - AMB */
error ("malformed option `%s %s'", option, str);
return;
}
/* Start change to handle gcc 3.x "-Afoo=bar" - AMB */
if(*p=='=')
{
*p='(';
strcat((char*)p,")");
}
/* End change to handle gcc 3.x "-Afoo=bar" - AMB */
ip = &instack[++indepth];
ip->nominal_fname = ip->fname = "*Initialization*";
ip->nominal_fname_len = strlen (ip->nominal_fname);
ip->buf = ip->bufp = buf;
ip->length = strlen ((char *) buf);
ip->lineno = 1;
ip->macro = 0;
ip->free_ptr = 0;
ip->if_stack = if_stack;
ip->system_header_p = 0;
for (kt = directive_table; kt->type != T_ASSERT; kt++)
;
/* Pass NULL as output ptr to do_define since we KNOW it never does
any output.... */
do_assert (buf, buf + strlen ((char *) buf) , NULL_PTR, kt);
--indepth;
}
/* The previous include prefix, if any, is PREV_FILE_NAME.
Translate any pathnames with COMPONENT.
Allocate a new include prefix whose name is the
simplified concatenation of PREFIX and NAME,
with a trailing / added if needed.
But return 0 if the include prefix should be ignored,
e.g. because it is a duplicate of PREV_FILE_NAME. */
static struct file_name_list *
new_include_prefix (prev_file_name, component, prefix, name)
struct file_name_list *prev_file_name;
const char *component;
const char *prefix;
const char *name;
{
if (name == 0)
fatal ("Directory name missing after command line option");
if (*name == 0)
/* Ignore the empty string. */
return 0;
prefix = update_path (prefix, component);
name = update_path (name, component);
{
struct file_name_list *dir
= ((struct file_name_list *)
xmalloc (sizeof (struct file_name_list)
+ strlen (prefix) + strlen (name) + 2));
size_t len;
strcpy (dir->fname, prefix);
strcat (dir->fname, name);
len = simplify_filename (dir->fname);
/* Convert directory name to a prefix. */
if (len && dir->fname[len - 1] != DIR_SEPARATOR) {
if (len == 1 && dir->fname[len - 1] == '.')
len = 0;
else
#ifdef VMS
/* must be '/', hack_vms_include_specification triggers on it. */
dir->fname[len++] = '/';
#else
dir->fname[len++] = DIR_SEPARATOR;
#endif
dir->fname[len] = 0;
}
/* Ignore a directory whose name matches the previous one. */
if (prev_file_name && !strcmp (prev_file_name->fname, dir->fname)) {
/* But treat `-Idir -I- -Idir' as `-I- -Idir'. */
if (!first_bracket_include)
first_bracket_include = prev_file_name;
free (dir);
return 0;
}
#ifndef VMS
/* VMS can't stat dir prefixes, so skip these optimizations in VMS. */
/* Add a trailing "." if there is a filename. This increases the number
of systems that can stat directories. We remove it below. */
if (len != 0)
{
dir->fname[len] = '.';
dir->fname[len + 1] = 0;
}
/* Ignore a nonexistent directory. */
if (stat (len ? dir->fname : ".", &dir->st) != 0) {
if (errno != ENOENT && errno != ENOTDIR)
error_from_errno (dir->fname);
free (dir);
return 0;
}
if (len != 0)
dir->fname[len] = 0;
/* Ignore a directory whose identity matches the previous one. */
if (prev_file_name
&& INO_T_EQ (prev_file_name->st.st_ino, dir->st.st_ino)
&& prev_file_name->st.st_dev == dir->st.st_dev) {
/* But treat `-Idir -I- -Idir' as `-I- -Idir'. */
if (!first_bracket_include)
first_bracket_include = prev_file_name;
free (dir);
return 0;
}
#endif /* ! VMS */
dir->next = 0;
dir->c_system_include_path = 0;
dir->got_name_map = 0;
return dir;
}
}
/* Append a chain of `struct file_name_list's
to the end of the main include chain.
FIRST is the beginning of the chain to append, and LAST is the end. */
static void
append_include_chain (first, last)
struct file_name_list *first, *last;
{
struct file_name_list *dir;
if (!first || !last)
return;
if (include == 0)
include = first;
else
last_include->next = first;
if (first_bracket_include == 0)
first_bracket_include = first;
for (dir = first; ; dir = dir->next) {
int len = strlen (dir->fname) + INCLUDE_LEN_FUDGE;
if (len > max_include_len)
max_include_len = len;
if (dir == last)
break;
}
last->next = NULL;
last_include = last;
}
/* Place into DST a representation of the file named SRC that is suitable
for `make'. Do not null-terminate DST. Return its length. */
static int
quote_string_for_make (dst, src)
char *dst;
const char *src;
{
const char *p = src;
int i = 0;
for (;;)
{
char c = *p++;
switch (c)
{
case '\0':
case ' ':
case '\t':
{
/* GNU make uses a weird quoting scheme for white space.
A space or tab preceded by 2N+1 backslashes represents
N backslashes followed by space; a space or tab
preceded by 2N backslashes represents N backslashes at
the end of a file name; and backslashes in other
contexts should not be doubled. */
const char *q;
for (q = p - 1; src < q && q[-1] == '\\'; q--)
{
if (dst)
dst[i] = '\\';
i++;
}
}
if (!c)
return i;
if (dst)
dst[i] = '\\';
i++;
goto ordinary_char;
case '$':
if (dst)
dst[i] = c;
i++;
/* Fall through. This can mishandle things like "$(" but
there's no easy fix. */
default:
ordinary_char:
/* This can mishandle characters in the string "\0\n%*?[\\~";
exactly which chars are mishandled depends on the `make' version.
We know of no portable solution for this;
even GNU make 3.76.1 doesn't solve the problem entirely.
(Also, '\0' is mishandled due to our calling conventions.) */
if (dst)
dst[i] = c;
i++;
break;
}
}
}
/* Add output to `deps_buffer' for the -M switch.
STRING points to the text to be output.
SPACER is ':' for targets, ' ' for dependencies. */
static void
deps_output (string, spacer)
const char *string;
int spacer;
{
int size = quote_string_for_make ((char *) 0, string);
if (size == 0)
return;
#ifndef MAX_OUTPUT_COLUMNS
#define MAX_OUTPUT_COLUMNS 72
#endif
if (MAX_OUTPUT_COLUMNS - 1 /*spacer*/ - 2 /*` \'*/ < deps_column + size
&& 1 < deps_column) {
bcopy (" \\\n ", &deps_buffer[deps_size], 4);
deps_size += 4;
deps_column = 1;
if (spacer == ' ')
spacer = 0;
}
if (deps_size + 2 * size + 8 > deps_allocated_size) {
deps_allocated_size = (deps_size + 2 * size + 50) * 2;
deps_buffer = xrealloc (deps_buffer, deps_allocated_size);
}
if (spacer == ' ') {
deps_buffer[deps_size++] = ' ';
deps_column++;
}
quote_string_for_make (&deps_buffer[deps_size], string);
deps_size += size;
deps_column += size;
if (spacer == ':') {
deps_buffer[deps_size++] = ':';
deps_column++;
}
deps_buffer[deps_size] = 0;
}
void
fatal VPROTO ((const char * msgid, ...))
{
#ifndef ANSI_PROTOTYPES
const char * msgid;
#endif
va_list args;
fprintf (stderr, "%s: ", progname);
VA_START (args, msgid);
#ifndef ANSI_PROTOTYPES
msgid = va_arg (args, const char *);
#endif
vnotice (msgid, args);
va_end (args);
fprintf (stderr, "\n");
exit (FATAL_EXIT_CODE);
}
/* More 'friendly' abort that prints the line and file.
config.h can #define abort fancy_abort if you like that sort of thing. */
void
fancy_abort ()
{
fatal ("Internal gcc abort.");
}
static void
perror_with_name (name)
char *name;
{
fprintf (stderr, "%s: %s: %s\n", progname, name, my_strerror (errno));
errors++;
}
static void
pfatal_with_name (name)
char *name;
{
perror_with_name (name);
#ifdef VMS
exit (vaxc$errno);
#else
exit (FATAL_EXIT_CODE);
#endif
}
/* Handler for SIGPIPE. */
static void
pipe_closed (signo)
/* If this is missing, some compilers complain. */
int signo ATTRIBUTE_UNUSED;
{
fatal ("output pipe has been closed");
}
static void
memory_full ()
{
fatal ("Memory exhausted.");
}
PTR
xmalloc (size)
size_t size;
{
register PTR ptr = (PTR) malloc (size);
if (!ptr)
memory_full ();
return ptr;
}
PTR
xrealloc (old, size)
PTR old;
size_t size;
{
register PTR ptr;
if (old)
ptr = (PTR) realloc (old, size);
else
ptr = (PTR) malloc (size);
if (!ptr)
memory_full ();
return ptr;
}
PTR
xcalloc (number, size)
size_t number, size;
{
register size_t total = number * size;
register PTR ptr = (PTR) malloc (total);
if (!ptr)
memory_full ();
bzero (ptr, total);
return ptr;
}
char *
xstrdup (input)
const char *input;
{
register size_t len = strlen (input) + 1;
register char *output = xmalloc (len);
memcpy (output, input, len);
return output;
}
#ifdef VMS
/* Under VMS we need to fix up the "include" specification filename.
Rules for possible conversions
fullname tried paths
name name
./dir/name [.dir]name
/dir/name dir:name
/name [000000]name, name
dir/name dir:[000000]name, dir:name, dir/name
dir1/dir2/name dir1:[dir2]name, dir1:[000000.dir2]name
path:/name path:[000000]name, path:name
path:/dir/name path:[000000.dir]name, path:[dir]name
path:dir/name path:[dir]name
[path]:[dir]name [path.dir]name
path/[dir]name [path.dir]name
The path:/name input is constructed when expanding <> includes.
return 1 if name was changed, 0 else. */
static int
hack_vms_include_specification (fullname, vaxc_include)
char *fullname;
int vaxc_include;
{
register char *basename, *unixname, *local_ptr, *first_slash;
int f, check_filename_before_returning, must_revert;
char Local[512];
check_filename_before_returning = 0;
must_revert = 0;
/* See if we can find a 1st slash. If not, there's no path information. */
first_slash = index (fullname, '/');
if (first_slash == 0)
return 0; /* Nothing to do!!! */
/* construct device spec if none given. */
if (index (fullname, ':') == 0)
{
/* If fullname has a slash, take it as device spec. */
if (first_slash == fullname)
{
first_slash = index (fullname+1, '/'); /* 2nd slash ? */
if (first_slash)
*first_slash = ':'; /* make device spec */
for (basename = fullname; *basename != 0; basename++)
*basename = *(basename+1); /* remove leading slash */
}
else if ((first_slash[-1] != '.') /* keep ':/', './' */
&& (first_slash[-1] != ':')
&& (first_slash[-1] != ']')) /* or a vms path */
{
*first_slash = ':';
}
else if ((first_slash[1] == '[') /* skip './' in './[dir' */
&& (first_slash[-1] == '.'))
fullname += 2;
}
/* Get part after first ':' (basename[-1] == ':')
or last '/' (basename[-1] == '/'). */
basename = base_name (fullname);
/*
* Check if we have a vax-c style '#include filename'
* and add the missing .h
*/
if (vaxc_include && !index (basename,'.'))
strcat (basename, ".h");
local_ptr = Local; /* initialize */
/* We are trying to do a number of things here. First of all, we are
trying to hammer the filenames into a standard format, such that later
processing can handle them.
If the file name contains something like [dir.], then it recognizes this
as a root, and strips the ".]". Later processing will add whatever is
needed to get things working properly.
If no device is specified, then the first directory name is taken to be
a device name (or a rooted logical). */
/* Point to the UNIX filename part (which needs to be fixed!)
but skip vms path information.
[basename != fullname since first_slash != 0]. */
if ((basename[-1] == ':') /* vms path spec. */
|| (basename[-1] == ']')
|| (basename[-1] == '>'))
unixname = basename;
else
unixname = fullname;
if (*unixname == '/')
unixname++;
/* If the directory spec is not rooted, we can just copy
the UNIX filename part and we are done. */
if (((basename - fullname) > 1)
&& ( (basename[-1] == ']')
|| (basename[-1] == '>')))
{
if (basename[-2] != '.')
{
/* The VMS part ends in a `]', and the preceding character is not a `.'.
-> PATH]:/name (basename = '/name', unixname = 'name')
We strip the `]', and then splice the two parts of the name in the
usual way. Given the default locations for include files in cccp.c,
we will only use this code if the user specifies alternate locations
with the /include (-I) switch on the command line. */
basename -= 1; /* Strip "]" */
unixname--; /* backspace */
}
else
{
/* The VMS part has a ".]" at the end, and this will not do. Later
processing will add a second directory spec, and this would be a syntax
error. Thus we strip the ".]", and thus merge the directory specs.
We also backspace unixname, so that it points to a '/'. This inhibits the
generation of the 000000 root directory spec (which does not belong here
in this case). */
basename -= 2; /* Strip ".]" */
unixname--; /* backspace */
}
}
else
{
/* We drop in here if there is no VMS style directory specification yet.
If there is no device specification either, we make the first dir a
device and try that. If we do not do this, then we will be essentially
searching the users default directory (as if they did a #include "asdf.h").
Then all we need to do is to push a '[' into the output string. Later
processing will fill this in, and close the bracket. */
if ((unixname != fullname) /* vms path spec found. */
&& (basename[-1] != ':'))
*local_ptr++ = ':'; /* dev not in spec. take first dir */
*local_ptr++ = '['; /* Open the directory specification */
}
if (unixname == fullname) /* no vms dir spec. */
{
must_revert = 1;
if ((first_slash != 0) /* unix dir spec. */
&& (*unixname != '/') /* not beginning with '/' */
&& (*unixname != '.')) /* or './' or '../' */
*local_ptr++ = '.'; /* dir is local ! */
}
/* at this point we assume that we have the device spec, and (at least
the opening "[" for a directory specification. We may have directories
specified already.
If there are no other slashes then the filename will be
in the "root" directory. Otherwise, we need to add
directory specifications. */
if (index (unixname, '/') == 0)
{
/* if no directories specified yet and none are following. */
if (local_ptr[-1] == '[')
{
/* Just add "000000]" as the directory string */
strcpy (local_ptr, "000000]");
local_ptr += strlen (local_ptr);
check_filename_before_returning = 1; /* we might need to fool with this later */
}
}
else
{
/* As long as there are still subdirectories to add, do them. */
while (index (unixname, '/') != 0)
{
/* If this token is "." we can ignore it
if it's not at the beginning of a path. */
if ((unixname[0] == '.') && (unixname[1] == '/'))
{
/* remove it at beginning of path. */
if ( ((unixname == fullname) /* no device spec */
&& (fullname+2 != basename)) /* starts with ./ */
/* or */
|| ((basename[-1] == ':') /* device spec */
&& (unixname-1 == basename))) /* and ./ afterwards */
*local_ptr++ = '.'; /* make '[.' start of path. */
unixname += 2;
continue;
}
/* Add a subdirectory spec. Do not duplicate "." */
if ( local_ptr[-1] != '.'
&& local_ptr[-1] != '['
&& local_ptr[-1] != '<')
*local_ptr++ = '.';
/* If this is ".." then the spec becomes "-" */
if ( (unixname[0] == '.')
&& (unixname[1] == '.')
&& (unixname[2] == '/'))
{
/* Add "-" and skip the ".." */
if ((local_ptr[-1] == '.')
&& (local_ptr[-2] == '['))
local_ptr--; /* prevent [.- */
*local_ptr++ = '-';
unixname += 3;
continue;
}
/* Copy the subdirectory */
while (*unixname != '/')
*local_ptr++= *unixname++;
unixname++; /* Skip the "/" */
}
/* Close the directory specification */
if (local_ptr[-1] == '.') /* no trailing periods */
local_ptr--;
if (local_ptr[-1] == '[') /* no dir needed */
local_ptr--;
else
*local_ptr++ = ']';
}
/* Now add the filename. */
while (*unixname)
*local_ptr++ = *unixname++;
*local_ptr = 0;
/* Now append it to the original VMS spec. */
strcpy ((must_revert==1)?fullname:basename, Local);
/* If we put a [000000] in the filename, try to open it first. If this fails,
remove the [000000], and return that name. This provides flexibility
to the user in that they can use both rooted and non-rooted logical names
to point to the location of the file. */
if (check_filename_before_returning)
{
f = open (fullname, O_RDONLY, 0666);
if (f >= 0)
{
/* The file name is OK as it is, so return it as is. */
close (f);
return 1;
}
/* The filename did not work. Try to remove the [000000] from the name,
and return it. */
basename = index (fullname, '[');
local_ptr = index (fullname, ']') + 1;
strcpy (basename, local_ptr); /* this gets rid of it */
}
return 1;
}
#endif /* VMS */
#ifdef VMS
/* The following wrapper functions supply additional arguments to the VMS
I/O routines to optimize performance with file handling. The arguments
are:
"mbc=16" - Set multi-block count to 16 (use a 8192 byte buffer).
"deq=64" - When extending the file, extend it in chunks of 32Kbytes.
"fop=tef"- Truncate unused portions of file when closing file.
"shr=nil"- Disallow file sharing while file is open. */
static FILE *
VMS_freopen (fname, type, oldfile)
char *fname;
char *type;
FILE *oldfile;
{
#undef freopen /* Get back the real freopen routine. */
if (strcmp (type, "w") == 0)
return freopen (fname, type, oldfile,
"mbc=16", "deq=64", "fop=tef", "shr=nil");
return freopen (fname, type, oldfile, "mbc=16");
}
static FILE *
VMS_fopen (fname, type)
char *fname;
char *type;
{
#undef fopen /* Get back the real fopen routine. */
/* The gcc-vms-1.42 distribution's header files prototype fopen with two
fixed arguments, which matches ANSI's specification but not VAXCRTL's
pre-ANSI implementation. This hack circumvents the mismatch problem. */
FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;
if (*type == 'w')
return (*vmslib_fopen) (fname, type, "mbc=32",
"deq=64", "fop=tef", "shr=nil");
else
return (*vmslib_fopen) (fname, type, "mbc=32");
}
static int
VMS_open (fname, flags, prot)
char *fname;
int flags;
int prot;
{
#undef open /* Get back the real open routine. */
return open (fname, flags, prot, "mbc=16", "deq=64", "fop=tef");
}
/* more VMS hackery */
#include <fab.h>
#include <nam.h>
extern unsigned long SYS$PARSE(), SYS$SEARCH();
/* Work around another library bug. If a file is located via a searchlist,
and if the device it's on is not the same device as the one specified
in the first element of that searchlist, then both stat() and fstat()
will fail to return info about it. `errno' will be set to EVMSERR, and
`vaxc$errno' will be set to SS$_NORMAL due yet another bug in stat()!
We can get around this by fully parsing the filename and then passing
that absolute name to stat().
Without this fix, we can end up failing to find header files, which is
bad enough, but then compounding the problem by reporting the reason for
failure as "normal successful completion." */
#undef fstat /* Get back to the library version. */
static int
VMS_fstat (fd, statbuf)
int fd;
struct stat *statbuf;
{
int result = fstat (fd, statbuf);
if (result < 0)
{
FILE *fp;
char nambuf[NAM$C_MAXRSS+1];
if ((fp = fdopen (fd, "r")) != 0 && fgetname (fp, nambuf) != 0)
result = VMS_stat (nambuf, statbuf);
/* No fclose(fp) here; that would close(fd) as well. */
}
return result;
}
static int
VMS_stat (name, statbuf)
const char *name;
struct stat *statbuf;
{
int result = stat (name, statbuf);
if (result < 0)
{
struct FAB fab;
struct NAM nam;
char exp_nam[NAM$C_MAXRSS+1], /* expanded name buffer for SYS$PARSE */
res_nam[NAM$C_MAXRSS+1]; /* resultant name buffer for SYS$SEARCH */
fab = cc$rms_fab;
fab.fab$l_fna = (char *) name;
fab.fab$b_fns = (unsigned char) strlen (name);
fab.fab$l_nam = (void *) &nam;
nam = cc$rms_nam;
nam.nam$l_esa = exp_nam, nam.nam$b_ess = sizeof exp_nam - 1;
nam.nam$l_rsa = res_nam, nam.nam$b_rss = sizeof res_nam - 1;
nam.nam$b_nop = NAM$M_PWD | NAM$M_NOCONCEAL;
if (SYS$PARSE (&fab) & 1)
{
if (SYS$SEARCH (&fab) & 1)
{
res_nam[nam.nam$b_rsl] = '\0';
result = stat (res_nam, statbuf);
}
/* Clean up searchlist context cached by the system. */
nam.nam$b_nop = NAM$M_SYNCHK;
fab.fab$l_fna = 0, fab.fab$b_fns = 0;
(void) SYS$PARSE (&fab);
}
}
return result;
}
#endif /* VMS */
|