/usr/include/libast.h is in libast2-dev 0.7-6ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
* Copyright (C) 1997-2004, Michael Jennings
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies of the Software, its documentation and marketing & publicity
* materials, and acknowledgment shall be given in the documentation, materials
* and software packages that this Software was used.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file libast.h
* Global LibAST header file.
*
* This file contains all general-purpose macros, function
* declarations, etc. for LibAST. It is also responsible for
* including all required system headers and LibAST Object headers.
*
* @author Michael Jennings <mej@eterm.org>
* @version $Revision: 1.61 $
* @date $Date: 2005/07/16 01:39:24 $
*/
#ifndef _LIBAST_H_
#define _LIBAST_H_
#include <libast/sysdefs.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <signal.h>
#include <limits.h>
#include <math.h>
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
#endif
#if WITH_DMALLOC
# include <dmalloc.h>
#elif HAVE_MALLOC_H
# include <malloc.h>
#endif
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#if LIBAST_X11_SUPPORT
# include <X11/Xatom.h>
# include <X11/X.h>
# include <X11/Intrinsic.h>
# if LIBAST_IMLIB2_SUPPORT
# include <Imlib2.h>
# endif
#endif
#ifdef __GNUC__
# if __GNUC__ >= 4
# undef STRICT_ISO_C99
# define STRICT_ISO_C99 1
# endif
#else
# define __attribute__(x)
# define __extension__(x)
# define __volatile__(x)
#endif
#if LIBAST_REGEXP_SUPPORT_PCRE
# if HAVE_PCRE_H
# include <pcre.h>
# elif HAVE_PCRE_PCRE_H
# include <pcre/pcre.h>
# endif
#elif LIBAST_REGEXP_SUPPORT_POSIX || LIBAST_REGEXP_SUPPORT_BSD
# if HAVE_REGEX_H
# include <regex.h>
# endif
# if LIBAST_REGEXP_SUPPORT_BSD
extern char *re_comp();
extern int re_exec();
# endif
#endif
#include <libast/types.h>
#include <libast/obj.h>
#include <libast/mbuff.h>
#include <libast/objpair.h>
#include <libast/regexp.h>
#include <libast/socket.h>
#include <libast/str.h>
#include <libast/tok.h>
#include <libast/url.h>
#include <libast/iterator_if.h>
#include <libast/list_if.h>
#include <libast/map_if.h>
#include <libast/vector_if.h>
#include <libast/array.h>
#include <libast/linked_list.h>
#include <libast/dlinked_list.h>
#include <libast/avl_tree.h>
/******************************* GENERIC GOOP *********************************/
/**
* Mark a variable as used.
*
* This macro is used to explicitly mark a variable as "used." It
* intentionally generates no real code, but suppresses gcc warnings
* about unused variables and/or parameters. That way, the programmer
* can explicitly acknowledge that certain variables/parameters are
* intentionally unused, making the warnings more effective by
* eliminating false positives.
*
* @param x Any variable or parameter name.
*/
#define USE_VAR(x) (void) x
/**
* @def MIN(a, b)
* Return the lesser of @a a or @a b.
*
* This macro compares its two parameters, @a a and @a b, and returns
* the lesser of the two (the minimum). When building under gcc, a
* GNU-specific extension is used which prevents expressions used as
* parameters from being evaluated multiple times.
*
* @param a Any expression that evaluates to a value.
* @param b Any expression that evaluates to a value.
* @return The lesser of the two values.
*/
/**
* @def MAX(a, b)
* Return the greater of @a a or @a b.
*
* This macro compares its two parameters, @a a and @a b, and returns
* the greater of the two (the maximum). When building under gcc, a
* GNU-specific extension is used which prevents expressions used as
* parameters from being evaluated multiple times.
*
* @param a Any expression that evaluates to a value.
* @param b Any expression that evaluates to a value.
* @return The greater of the two values.
*/
/**
* @def LOWER_BOUND(current, other)
* Force a lower bound on a variable.
*
* This macro checks the value of its first parameter, @a current, and
* makes sure it is greater than or equal to the value of @a other.
* If @a current is less than @a other, @a current is assigned the
* value of @a other. In essence, this establishes a "lower bound" on
* @a current equal to the value of @a other.
*
* @param current The variable to check.
* @param other The value by which @a current will be bound.
* @return The new value of @a current.
*/
/**
* @def UPPER_BOUND(current, other)
* Force an upper bound on a variable.
*
* This macro checks the value of its first parameter, @a current, and
* makes sure it is less than or equal to the value of @a other. If
* @a current is greater than @a other, @a current is assigned the
* value of @a other. In essence, this establishes an "upper bound"
* on @a current equal to the value of @a other.
*
* @param current The variable to check.
* @param other The value by which @a current will be bound.
* @return The new value of @a current.
*/
/**
* @def BOUND(val, min, max)
* Force a variable to be within a given range.
*
* This macro checks the value of its first parameter, @a val, and
* makes sure it is between @a min and @a max, inclusive. If @a val
* is above this range, it is assigned the value of @a max. Likewise,
* if @a val is below this range, it is assigned the value of @a min.
* In essence, this establishes both an "upper bound" and a "lower
* bound" on @a val.
*
* @param val The variable to check.
* @param min The lowest value @a val may have.
* @param max The highest value @a val may have.
* @return The new value of @a val.
*/
#ifdef MIN
# undef MIN
#endif
#ifdef MAX
# undef MAX
#endif
#ifdef __GNUC__
# define MIN(a,b) __extension__ ({__typeof__(a) aa = (a); __typeof__(b) bb = (b); (aa < bb) ? (aa) : (bb);})
# define MAX(a,b) __extension__ ({__typeof__(a) aa = (a); __typeof__(b) bb = (b); (aa > bb) ? (aa) : (bb);})
# define LOWER_BOUND(current, other) __extension__ ({__typeof__(other) o = (other); ((current) < o) ? ((current) = o) : (current);})
# define UPPER_BOUND(current, other) __extension__ ({__typeof__(other) o = (other); ((current) > o) ? ((current) = o) : (current);})
# define BOUND(val, min, max) __extension__ ({__typeof__(min) m1 = (min); __typeof__(max) m2 = (max); ((val) < m1) ? ((val) = m1) : (((val) > m2) ? ((val) = m2) : (val));})
#else
# define MIN(a,b) (((a) < (b)) ? (a) : (b))
# define MAX(a,b) (((a) > (b)) ? (a) : (b))
# define LOWER_BOUND(current, other) (((current) < (other)) ? ((current) = (other)) : (current))
# define UPPER_BOUND(current, other) (((current) > (other)) ? ((current) = (other)) : (current))
# define BOUND(val, min, max) (((val) < (min)) ? ((val) = (min)) : (((val) > (max)) ? ((val) = (max)) : (val)))
#endif
/** @def AT_LEAST(current, other) Alias for LOWER_BOUND(). This macro is an alias for LOWER_BOUND(). */
#define AT_LEAST(current, other) LOWER_BOUND(current, other)
/** @def MAX_IT(current, other) Alias for LOWER_BOUND(). This macro is an alias for LOWER_BOUND(). */
#define MAX_IT(current, other) LOWER_BOUND(current, other)
/** @def AT_MOST(current, other) Alias for UPPER_BOUND(). This macro is an alias for UPPER_BOUND(). */
#define AT_MOST(current, other) UPPER_BOUND(current, other)
/** @def MIN_IT(current, other) Alias for UPPER_BOUND(). This macro is an alias for UPPER_BOUND(). */
#define MIN_IT(current, other) UPPER_BOUND(current, other)
/** @def CONTAIN(val, min, max) Alias for BOUND(). This macro is an alias for BOUND(). */
#define CONTAIN(val, min, max) BOUND(val, min, max)
/**
* Swaps two values.
*
* This macro swaps the values of its first two parameters using the
* third as temporary storage.
*
* @param one The first variable.
* @param two The second variable.
* @param tmp A temporary holding spot used during swapping.
*/
#define SWAP_IT(one, two, tmp) do {(tmp) = (one); (one) = (two); (two) = (tmp);} while (0)
/**
* @def SWAP(a, b)
* Swaps two values.
*
* This macro performs the same task as the SWAP_IT() macro, except
* that no temporary variable is required. Instead, a temporary
* variable is created by the macro itself. Under gcc, the
* __typeof__() extension is used to create a temporary variable of
* the same type as @a a. Under other compilers, a void pointer is
* used.
*
* @param a The first variable.
* @param b The second variable.
*/
#ifdef __GNUC__
# define SWAP(a, b) (void) __extension__ ({__typeof__(a) __tmp = (a); (a) = (b); (b) = __tmp;})
#else
# define SWAP(a, b) do {void *__tmp = ((void *)(a)); (a) = (b); (b) = __tmp;} while (0)
#endif
/**
* Swaps two values.
*
* This macro swaps the values of @a a and @a b using the now-infamous
* chained XOR trick.
*
* @attention ONLY use this with like variables, and only those which
* can safely be cast to and from a long. If you're unsure of whether
* or not it would be safe, use SWAP() or SWAP_IT() instead!
*
* @param a The first variable.
* @param b The second variable.
*/
#if STRICT_ISO_C99
# define BINSWAP(a, b) SWAP(a, b)
#else
# define BINSWAP(a, b) (((long) (a)) ^= ((long) (b)) ^= ((long) (a)) ^= ((long) (b)))
#endif
/**
* Make sure a char pointer is non-NULL before printing it.
*
* This is a convenience macro primarily targetted at systems like
* Solaris where doing a printf() on a NULL char pointer using %s
* results in a segmentation fault rather than helpful message. This
* macro should be used in any place where a string is printed which
* could potentially be NULL.
*
* @param x A string (char *).
* @return @a x, or if @a x is NULL, the string "<@a x null>"
*/
#define NONULL(x) (((char *) (x)) ? ((char *) (x)) : ((char *) ("<" #x " null>")))
/**
* Not-A-Number
*
* This makes sure NAN is defined.
*/
#ifndef NAN
# ifdef MAX_FLOAT
# define NAN MAX_FLOAT
# elsif defined(MAXFLOAT)
# define NAN MAX_FLOAT
# elsif defined(HUGE)
# define NAN HUGE
# else
/* FIXME: This could be dangerous...anyone have a better idea? */
# define NAN 3.40282347e+38F
# endif
#endif
/****************************** DEBUGGING GOOP ********************************/
#ifndef LIBAST_DEBUG_FD
/**
* Where to send debugging output.
*
* This defines where debugging output should be sent. Should be
* either stdout or stderr.
*
* @ingroup DOXGRP_DEBUG
*/
# define LIBAST_DEBUG_FD (stderr)
#endif
#ifndef DEBUG
/**
* Maximum compile-time debugging level.
*
* LibAST supports debugging levels, allowing for progressively more
* verbosity of debugging output as the level gets higher. This
* defines the compile-time maximum; support for higher debugging
* levels than this will not even be compiled in, so use care when
* setting this.
*
* @ingroup DOXGRP_DEBUG
*/
# define DEBUG 0
#endif
/** UNDOCUMENTED. */
#define DEBUG_LEVEL (libast_debug_level)
/** UNDOCUMENTED. */
#define DEBUG_FLAGS (libast_debug_flags)
/** Does nothing. This macro is a nop (no operation). It does nothing. */
#define NOP ((void)0)
/**
* A fix-me NOP.
*
* This is the same as NOP(), but is used to mark something needing to
* be fixed.
*/
#define FIXME_NOP(x)
/**
* Mark a block of code needing fixing.
*
* This marks a block of code needing fixing and removes it.
*/
#define FIXME_BLOCK 0
/**
* Mark unused blocks of code.
*
* This marks a block of code as unused and removes it.
*/
#define UNUSED_BLOCK 0
/**
* @def __DEBUG()
* Format and print debugging output.
*
* This macro formats and prints debugging output by prepending a
* timestamp, the filename, the line number, and (if available) the
* function name.
*
* This is an internal macro and should not be used directly.
* @ingroup DOXGRP_DEBUG
*/
#if defined(__FILE__) && defined(__LINE__)
# ifdef __GNUC__
# define __DEBUG() fprintf(LIBAST_DEBUG_FD, "[%lu] %12s | %4d: %s(): ", (unsigned long) time(NULL), __FILE__, __LINE__, __FUNCTION__)
# else
# define __DEBUG() fprintf(LIBAST_DEBUG_FD, "[%lu] %12s | %4d: ", (unsigned long) time(NULL), __FILE__, __LINE__)
# endif
#else
# define __DEBUG() NOP
#endif
/**
* Assert reaching a line of code.
*
* This macro is simply a quick-and-dirty way of printing out a unique
* message which proves that a particular portion of code was reached
* and executed properly.
*
* @ingroup DOXGRP_DEBUG
*/
#define MOO() do {__DEBUG(); libast_dprintf("Moo.\n");} while (0)
/**
* @def ASSERT(x)
* Asserts that a condition is true.
*
* This macro evaluates an expression, @a x, and takes action if the
* expression evaluates to false (0). It works similarly to the libc
* function assert(), with the exception that it will not call abort()
* if the assertion fails. Instead, it will either issue a fatal
* error (generally resulting in a backtrace) if debugging is active,
* or print a warning if it is not. In either event, the warning/error
* message will contain the filename, line number, and (if available)
* function name where the error occured.
*
* If only a warning is generated, the function will return
* immediately.
*
* @param x Any valid boolean expression.
* @ingroup DOXGRP_DEBUG
*/
/**
* @def ASSERT_RVAL(x, val)
* Asserts that a condition is true, and provides a return value in
* case it isn't.
*
* This macro is identical to ASSERT(), except that it returns a
* value, @a val, instead of returning void.
*
* @param x Any valid boolean expression.
* @param val The return value to use if @a x evaluates to false.
* @ingroup DOXGRP_DEBUG
*/
/**
* @def ASSERT_NOTREACHED()
* Asserts that a particular piece of code is not reached.
*
* This macro is used in sections of code that should never be
* reached. Its actions are similar to those of ASSERT(), but instead
* of evaluating an expression, it always evaluates to false.
*
* @ingroup DOXGRP_DEBUG
*/
/**
* @def ASSERT_NOTREACHED_RVAL(val)
* Asserts that a particular piece of code is not reached, and
* provides a return value in case it is.
*
* This macro is identical to ASSERT_NOTREACHED(), except that it
* returns a value, @a val, instead of returning void.
*
* @ingroup DOXGRP_DEBUG
*/
/**
* @def ABORT()
* Throw a fatal exception.
*
* This macro is a replacement for the libc abort() function. This
* version provides file/line/function information in the fatal error
* message.
*
* @ingroup DOXGRP_DEBUG
*/
/**
* @def REQUIRE(x)
* Return if an expression is false.
*
* This macro is similar to ASSERT(), except that @a x evaluating to
* false is not necessarily an error. Normally, this macro simply
* causes the function to return. However, if debugging is active, a
* message is printed noting the expression @a x and the location of
* the failure. This macro is often used to test preconditions, such
* as making sure pointers are non-NULL before using them.
*
* @param x Any valid boolean expression.
* @ingroup DOXGRP_DEBUG
*/
/**
* @def REQUIRE_RVAL(x, v)
* Return @a v if an expression is false.
*
* This macro is identical to REQUIRE(), except that a return value
* for the function is supplied.
*
* @param x Any valid boolean expression
* @param v The function return value to use if @a x evaluates to
* false.
* @ingroup DOXGRP_DEBUG
*/
#if DEBUG >= 1
# if defined(__FILE__) && defined(__LINE__)
# ifdef __GNUC__
# define ASSERT(x) do {if (!(x)) {if (DEBUG_LEVEL>=1) {libast_fatal_error("ASSERT failed in %s() at %s:%d: %s\n", __FUNCTION__, __FILE__, __LINE__, #x);} \
else {libast_print_warning("ASSERT failed in %s() at %s:%d: %s\n", __FUNCTION__, __FILE__, __LINE__, #x); return;}}} while (0)
# define ASSERT_RVAL(x, val) do {if (!(x)) {if (DEBUG_LEVEL>=1) {libast_fatal_error("ASSERT failed in %s() at %s:%d: %s\n", __FUNCTION__, __FILE__, __LINE__, #x);} \
else {libast_print_warning("ASSERT failed in %s() at %s:%d: %s\n", __FUNCTION__, __FILE__, __LINE__, #x);} \
return (val);}} while (0)
# define ASSERT_NOTREACHED() do {if (DEBUG_LEVEL>=1) {libast_fatal_error("ASSERT failed in %s() at %s:%d: This code should not be reached.\n", __FUNCTION__, __FILE__, __LINE__);} \
else {libast_print_warning("ASSERT failed in %s() at %s:%d: This code should not be reached.\n", __FUNCTION__, __FILE__, __LINE__);} \
} while (0)
# define ASSERT_NOTREACHED_RVAL(val) do {if (DEBUG_LEVEL>=1) {libast_fatal_error("ASSERT failed in %s() at %s:%d: This code should not be reached.\n", __FUNCTION__, __FILE__, __LINE__);} \
else {libast_print_warning("ASSERT failed in %s() at %s:%d: This code should not be reached.\n", __FUNCTION__, __FILE__, __LINE__);} \
return (val);} while (0)
# define ABORT() libast_fatal_error("Aborting in %s() at %s:%d.\n", __FUNCTION__, __FILE__, __LINE__)
# else
# define ASSERT(x) do {if (!(x)) {if (DEBUG_LEVEL>=1) {libast_fatal_error("ASSERT failed at %s:%d: %s\n", __FILE__, __LINE__, #x);} \
else {libast_print_warning("ASSERT failed at %s:%d: %s\n", __FILE__, __LINE__, #x); return;}}} while (0)
# define ASSERT_RVAL(x, val) do {if (!(x)) {if (DEBUG_LEVEL>=1) {libast_fatal_error("ASSERT failed at %s:%d: %s\n", __FILE__, __LINE__, #x);} \
else {libast_print_warning("ASSERT failed at %s:%d: %s\n", __FILE__, __LINE__, #x);} \
return (val);}} while (0)
# define ASSERT_NOTREACHED() do {if (DEBUG_LEVEL>=1) {libast_fatal_error("ASSERT failed at %s:%d: This code should not be reached.\n", __FILE__, __LINE__);} \
else {libast_print_warning("ASSERT failed at %s:%d: This code should not be reached.\n", __FILE__, __LINE__);} \
} while (0)
# define ASSERT_NOTREACHED_RVAL(val) do {if (DEBUG_LEVEL>=1) {libast_fatal_error("ASSERT failed at %s:%d: This code should not be reached.\n", __FILE__, __LINE__);} \
else {libast_print_warning("ASSERT failed at %s:%d: This code should not be reached.\n", __FILE__, __LINE__);} \
return (val);} while (0)
# define ABORT() libast_fatal_error("Aborting at %s:%d.\n", __FILE__, __LINE__)
# endif
# else
# define ASSERT(x) do {if (!(x)) {if (DEBUG_LEVEL>=1) {libast_fatal_error("ASSERT failed: %s\n", #x);} \
else {libast_print_warning("ASSERT failed: %s\n", #x); return;}}} while (0)
# define ASSERT_RVAL(x, val) do {if (!(x)) {if (DEBUG_LEVEL>=1) {libast_fatal_error("ASSERT failed: %s\n", #x);} \
else {libast_print_warning("ASSERT failed: %s\n", #x);} return (val);}} while (0)
# define ASSERT_NOTREACHED() return
# define ASSERT_NOTREACHED_RVAL(x) return (x)
# define ABORT() libast_fatal_error("Aborting.\n")
# endif
# define REQUIRE(x) do {if (!(x)) {if (DEBUG_LEVEL>=1) {__DEBUG(); libast_dprintf("REQUIRE failed: %s\n", #x);} return;}} while (0)
# define REQUIRE_RVAL(x, v) do {if (!(x)) {if (DEBUG_LEVEL>=1) {__DEBUG(); libast_dprintf("REQUIRE failed: %s\n", #x);} return (v);}} while (0)
#else
# define ASSERT(x) NOP
# define ASSERT_RVAL(x, val) NOP
# define ASSERT_NOTREACHED() return
# define ASSERT_NOTREACHED_RVAL(val) return (val)
# define ABORT() libast_fatal_error("Aborting.\n")
# define REQUIRE(x) do {if (!(x)) return;} while (0)
# define REQUIRE_RVAL(x, v) do {if (!(x)) return (v);} while (0)
#endif
/**
* @def DPRINTF(x)
* Print debugging output.
*
* This macro can be used for unconditional debugging output. If any
* level of debugging support has been compiled in, this macro will
* print a debugging message.
*
* This macro will almost never be used directly; instead, use the
* D_*() macros.
*
* @attention Calls to this and other debugging output macros
* MUST be double-parenthesized, like so: DPRINTF((...));
*
* @param x A parenthesized argument list suitable for a printf-style
* function.
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
/**
* @def DPRINTF1(x)
* Print level 1 debugging output.
*
* This macro is identical to DPRINTF(), except that the message will
* only be printed if the debug level is 1 or higher.
*
* @param x A parenthesized argument list suitable for a printf-style
* function.
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
/**
* @def DPRINTF2(x)
* Print level 2 debugging output.
*
* This macro is identical to DPRINTF(), except that the message will
* only be printed if the debug level is 2 or higher.
*
* @param x A parenthesized argument list suitable for a printf-style
* function.
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
/**
* @def DPRINTF3(x)
* Print level 3 debugging output.
*
* This macro is identical to DPRINTF(), except that the message will
* only be printed if the debug level is 3 or higher.
*
* @param x A parenthesized argument list suitable for a printf-style
* function.
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
/**
* @def DPRINTF4(x)
* Print level 4 debugging output.
*
* This macro is identical to DPRINTF(), except that the message will
* only be printed if the debug level is 4 or higher.
*
* @param x A parenthesized argument list suitable for a printf-style
* function.
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
/**
* @def DPRINTF5(x)
* Print level 5 debugging output.
*
* This macro is identical to DPRINTF(), except that the message will
* only be printed if the debug level is 5 or higher.
*
* @param x A parenthesized argument list suitable for a printf-style
* function.
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
/**
* @def DPRINTF6(x)
* Print level 6 debugging output.
*
* This macro is identical to DPRINTF(), except that the message will
* only be printed if the debug level is 6 or higher.
*
* @param x A parenthesized argument list suitable for a printf-style
* function.
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
/**
* @def DPRINTF7(x)
* Print level 7 debugging output.
*
* This macro is identical to DPRINTF(), except that the message will
* only be printed if the debug level is 7 or higher.
*
* @param x A parenthesized argument list suitable for a printf-style
* function.
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
/**
* @def DPRINTF8(x)
* Print level 8 debugging output.
*
* This macro is identical to DPRINTF(), except that the message will
* only be printed if the debug level is 8 or higher.
*
* @param x A parenthesized argument list suitable for a printf-style
* function.
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
/**
* @def DPRINTF9(x)
* Print level 9 debugging output.
*
* This macro is identical to DPRINTF(), except that the message will
* only be printed if the debug level is 9 or higher.
*
* @param x A parenthesized argument list suitable for a printf-style
* function.
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
#if DEBUG >= 1
# ifndef DPRINTF
# define DPRINTF(x) do { __DEBUG(); libast_dprintf x; } while (0)
# endif
# define DPRINTF1(x) do { if (DEBUG_LEVEL >= 1) {__DEBUG(); libast_dprintf x;} } while (0)
# define DPRINTF2(x) do { if (DEBUG_LEVEL >= 2) {__DEBUG(); libast_dprintf x;} } while (0)
# define DPRINTF3(x) do { if (DEBUG_LEVEL >= 3) {__DEBUG(); libast_dprintf x;} } while (0)
# define DPRINTF4(x) do { if (DEBUG_LEVEL >= 4) {__DEBUG(); libast_dprintf x;} } while (0)
# define DPRINTF5(x) do { if (DEBUG_LEVEL >= 5) {__DEBUG(); libast_dprintf x;} } while (0)
# define DPRINTF6(x) do { if (DEBUG_LEVEL >= 6) {__DEBUG(); libast_dprintf x;} } while (0)
# define DPRINTF7(x) do { if (DEBUG_LEVEL >= 7) {__DEBUG(); libast_dprintf x;} } while (0)
# define DPRINTF8(x) do { if (DEBUG_LEVEL >= 8) {__DEBUG(); libast_dprintf x;} } while (0)
# define DPRINTF9(x) do { if (DEBUG_LEVEL >= 9) {__DEBUG(); libast_dprintf x;} } while (0)
#else
# ifndef DPRINTF
# define DPRINTF(x) NOP
# endif
# define DPRINTF1(x) NOP
# define DPRINTF2(x) NOP
# define DPRINTF3(x) NOP
# define DPRINTF4(x) NOP
# define DPRINTF5(x) NOP
# define DPRINTF6(x) NOP
# define DPRINTF7(x) NOP
# define DPRINTF8(x) NOP
# define DPRINTF9(x) NOP
#endif
/**
* Debugging output you (almost) never want.
*
* This macro is used for mapping debugging output you almost never
* want to see. Map D_*() macros to this for overly verbose or
* problematic debugging information, then manually redefine this as
* needed.
*
* @param x A parenthesized argument list suitable for a printf-style
* function.
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
#define D_NEVER(x) NOP
/** Set options debugging to level 1. @see @link DOXGRP_DEBUG Debugging Subsystem @endlink */
#define DEBUG_OPTIONS 1
/**
* Option debugging macro.
*
* This macro is used for debugging output related to the options
* subsystem. It maps to DPRINTF1() so that options-related debugging
* output will occur at debug level 1 and higher.
*
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
#if DEBUG >= DEBUG_OPTIONS
# define D_OPTIONS_IF if (DEBUG_LEVEL >= DEBUG_OPTIONS)
# define D_OPTIONS(x) do { D_OPTIONS_IF {DPRINTF(x);} } while (0)
#else
# define D_OPTIONS_IF if (0)
# define D_OPTIONS(x) NOP
#endif
/** Set object system debugging to level 2. @see @link DOXGRP_DEBUG Debugging Subsystem @endlink */
#define DEBUG_OBJ 2
/**
* Object debugging macro.
*
* This macro is used for debugging output related to the object
* subsystem. It maps to DPRINTF2() so that object-related debugging
* output will occur at debug level 2 and higher.
*
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
#if DEBUG >= DEBUG_OBJ
# define D_OBJ_IF if (DEBUG_LEVEL >= DEBUG_OBJ)
# define D_OBJ(x) do { D_OBJ_IF {DPRINTF(x);} } while (0)
#else
# define D_OBJ_IF if (0)
# define D_OBJ(x) NOP
#endif
/** Set config file parser debugging to level 3. @see @link DOXGRP_DEBUG Debugging Subsystem @endlink */
#define DEBUG_CONF 3
/**
* Config file parser debugging macro.
*
* This macro is used for debugging output related to the config file
* parser. It maps to DPRINTF3() so that config-related debugging
* output will occur at debug level 3 and higher.
*
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
#if DEBUG >= DEBUG_CONF
# define D_CONF_IF if (DEBUG_LEVEL >= DEBUG_CONF)
# define D_CONF(x) do { D_CONF_IF {DPRINTF(x);} } while (0)
#else
# define D_CONF_IF if (0)
# define D_CONF(x) NOP
#endif
/** Set memory allocation debugging to level 5. @see @link DOXGRP_DEBUG Debugging Subsystem @endlink */
#define DEBUG_MEM 5
/**
* Memory allocation debugging macro.
*
* This macro is used for debugging output related to the memory
* allocation subsystem. It maps to DPRINTF1() so that mem-related
* debugging output will occur at debug level 5 and higher.
*
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
#if DEBUG >= DEBUG_MEM
# define D_MEM_IF if (DEBUG_LEVEL >= DEBUG_MEM)
# define D_MEM(x) do { D_MEM_IF {DPRINTF(x);} } while (0)
#else
# define D_MEM_IF if (0)
# define D_MEM(x) NOP
#endif
/** Set strings module debugging to level 9999. @see @link DOXGRP_DEBUG Debugging Subsystem @endlink */
#define DEBUG_STRINGS 9999
/**
* String routine debugging macro.
*
* This macro is used for debugging output related to the string
* manipulation subsystem. It maps to D_NEVER() so that
* string-related debugging output can only be activated manually.
*
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
#if DEBUG >= DEBUG_STRINGS
# define D_STRINGS_IF if (DEBUG_LEVEL >= DEBUG_STRINGS)
# define D_STRINGS(x) do { D_STRINGS_IF {DPRINTF(x);} } while (0)
#else
# define D_STRINGS_IF if (0)
# define D_STRINGS(x) NOP
#endif
/** Set lexer/parser debugging to level 9999. @see @link DOXGRP_DEBUG Debugging Subsystem @endlink */
#define DEBUG_PARSE 9999
/**
* Lexer/parser debugging macro.
*
* This macro is used for debugging output related to the lexer/parser
* portion of the config parser. It maps to D_NEVER() so that
* parser-related debugging output can only be activated manually.
*
* @see @link DOXGRP_DEBUG Debugging Subsystem @endlink
* @ingroup DOXGRP_DEBUG
*/
#if DEBUG >= DEBUG_PARSE
# define D_PARSE_IF if (DEBUG_LEVEL >= DEBUG_PARSE)
# define D_PARSE(x) do { D_PARSE_IF {DPRINTF(x);} } while (0)
#else
# define D_PARSE_IF if (0)
# define D_PARSE(x) NOP
#endif
/********************************* MEM GOOP ***********************************/
/**
* @def MALLOC(sz)
* Allocate @a sz bytes of memory.
*
* This macro is a replacement for the libc function malloc(). It
* allocates the specified number of bytes of memory on the heap and
* returns a pointer to that memory location. This macro calls libc's
* malloc() if memory debugging is off, and spifmem_malloc() if it's
* on.
*
* @param sz The size in bytes of the block of memory to allocate.
* @return A pointer to the allocated memory.
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def CALLOC(type, n)
* Allocate enough memory for @a n objects of type @a type.
*
* This macro is a replacement for the libc function calloc(). It
* allocates a block of memory on the heap large enough to hold @a n
* objects of type @a type (e.g., a @a type array of size @a n). The
* memory area is zeroed out prior to the pointer to it being
* returned. This macro calls libc's calloc() if memory debugging is
* off and spifmem_calloc() if it's on.
*
* @param type The type of object to be allocated (e.g., int).
* @param n The number of objects to be allocated.
* @return A pointer to the allocated memory.
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def REALLOC(mem, sz)
* Resize the memory block pointed to by @a mem to @a sz bytes.
*
* This macro is a replacement for the libc function realloc(). It
* changes the size of a chunk of memory previously allocated by
* malloc() or calloc() (or, by extension, the MALLOC()/CALLOC()
* macros) and returns a pointer to the (possibly moved) memory area.
* This macro calls libc's realloc() if memory debugging is off and
* spifmem_realloc() if it's on.
*
* @param mem The old pointer whose size will be changed.
* @param sz The new size, in bytes, to be allocated.
* @return The new pointer value, which may or may not differ from the
* old value.
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def FREE(ptr)
* Free a previously-allocated memory block.
*
* This macro is a replacement for the libc function free(). It
* returns the previously-allocated memory block pointed to by @a ptr
* to the heap. This macro calls libc's free() if memory debugging is
* off and spifmem_free() if it's on. The @a ptr parameter is assigned
* the value of NULL after it has been freed.
*
* @param ptr The pointer to be freed.
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def STRDUP(s)
* Duplicate a string pointer and return a pointer to the new copy.
*
* This macro is a replacement for the libc function strdup(). It
* allocates a section of memory large enough to hold the string @a s
* (including the trailing NUL character), copies the contents of @a s
* into the new buffer, and returns a pointer to the new copy. This
* macro calls libc's strdup() of memory debugging is off and
* spifmem_strdup() if it's on.
*
* @param s The string to duplicate.
* @return A pointer to the newly-created copy.
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def MALLOC_DUMP()
* Dumps a listing of all allocated pointers along with their sizes
* and contents in both hex and ASCII.
*
* This macro is used to view the status of memory allocated via the
* LibAST memory management system. First the pointers used to track
* allocated memory are dumped (that's what pointer #0 is); then, each
* allocated pointer is dumped along with its size and contents, the
* latter being displayed both in hexadecimal form and ASCII form.
* Non-printable characters are replaced by dots ('.'). You can see
* a sample of the output in the
* @link mem_example.c memory management system example @endlink.
*
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def X_CREATE_PIXMAP(d, win, w, h, depth)
* Create an X pixmap.
*
* This macro is a replacement for the Xlib function XCreatePixmap().
* It creates a pixmap of the specified size and returns an X resource
* ID for it. This macro calls Xlib's XCreatePixmap() if memory
* debugging is off and spifmem_x_create_pixmap() if it's on.
*
* @param d The X display connection.
* @param win The X drawable on whose display the pixmap will be
* created.
* @param w The width in pixels of the pixmap.
* @param h The height in pixels of the pixmap.
* @param depth The color depth for the pixmap.
* @return The Pixmap ID for the new pixmap.
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def X_FREE_PIXMAP(d, p)
* Free the specified X pixmap.
*
* This macro is a replacement for the Xlib function XFreePixmap().
* It frees the specified pixmap. This macro calls Xlib's
* XFreePixmap() if memory debugging is off and spifmem_x_free_pixmap()
* if it's on.
*
* @param d The X display connection.
* @param p The Pixmap to be freed.
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def IMLIB_REGISTER_PIXMAP(p)
* Register a pixmap generated by Imlib2 so LibAST can track it.
*
* Unfortunately, there is no easy way to wrap all the different ways
* Imlib2 could conceivably create an image. So instead, simply use
* this macro to register the pixmaps Imlib2 creates. Then LibAST
* will be able to track them. This macro calls
* spifmem_imlib_register_pixmap() if memory debugging is on and if
* Imlib2 support has been enabled. Otherwise, it's a NOP().
*
* @param p The Pixmap Imlib2 created.
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def IMLIB_FREE_PIXMAP(p)
* Free a pixmap (and its mask) generated by Imlib2.
*
* Once an Imlib2-generated pixmap has been registered, you should
* use this macro to free it. It calls spifmem_imlib_free_pixmap() if
* Imlib2 support has been enabled. Otherwise, it's a NOP().
*
* @param p The Imlib2-generated Pixmap to be freed.
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def PIXMAP_DUMP()
* Dump a listing of allocated pixmaps.
*
* This macro is analogous to the MALLOC_DUMP() macro; rather than
* dumping a list of pointers, however, it dumps a list of allocated
* pixmaps. Like MALLOC_DUMP(), this macro is a NOP() if memory
* debugging support has not been compiled into LibAST.
*
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def X_CREATE_GC(d, win, f, gcv)
* Create an X graphics context.
*
* This macro is a replacement for the Xlib function XCreateGC(). It
* creates a graphics context (GC) object and returns its X resource
* ID. This macro calls Xlib's XCreateGC() if memory debugging is
* off and spifmem_x_create_gc() if it's on.
*
* @param d The X display connection.
* @param win The X drawable on whose screen the GC will be created.
* @param f The GC flags noting which members of @a gcv have set
* values.
* @param gcv The GCValues structure defining properties of the GC.
* @return The ID of the new GC.
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def X_FREE_GC(d, gc)
* Free an X graphics context.
*
* This macro is a replacement for the Xlib function XFreeGC(). It
* frees a previously allocated graphics context (GC) object. This
* macro calls Xlib's XFreeGC() if memory debugging is off and
* spifmem_x_free_gc() if it's on.
*
* @param d The X display connection.
* @param gc The graphics context object to free.
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def GC_DUMP()
* Dump a list of allocated graphics context objects.
*
* This macro is analogous to the MALLOC_DUMP() macro; rather than
* dumping a list of pointers, however, it dumps a list of allocated
* GC's. Like MALLOC_DUMP(), this macro is a NOP() if memory
* debugging support has not been compiled into LibAST.
*
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def MALLOC_MOD
* MALLOC() call count interval.
*
* LibAST has the ability to count calls to MALLOC(); this defines the
* interval for reporting the call count. The default is 25, meaning
* that LibAST will print the current count every 25 calls. Note that
* MALLOC_CALL_DEBUG must be defined when compiling LibAST, in
* addition to memory debugging, for this feature to work.
*
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def REALLOC_MOD
* REALLOC() call count interval.
*
* LibAST has the ability to count calls to REALLOC(); this defines
* the interval for reporting the call count. The default is 25,
* meaning that LibAST will print the current count every 25 calls.
* Note that MALLOC_CALL_DEBUG must be defined when compiling LibAST,
* in addition to memory debugging, for this feature to work.
*
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def CALLOC_MOD
* CALLOC() call count interval.
*
* LibAST has the ability to count calls to CALLOC(); this defines the
* interval for reporting the call count. The default is 25, meaning
* that LibAST will print the current count every 25 calls. Note that
* MALLOC_CALL_DEBUG must be defined when compiling LibAST, in
* addition to memory debugging, for this feature to work.
*
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
/**
* @def FREE_MOD
* FREE() call count interval.
*
* LibAST has the ability to count calls to FREE(); this defines the
* interval for reporting the call count. The default is 25, meaning
* that LibAST will print the current count every 25 calls. Note that
* MALLOC_CALL_DEBUG must be defined when compiling LibAST, in
* addition to memory debugging, for this feature to work.
*
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
#if (DEBUG >= DEBUG_MEM)
# define MALLOC(sz) spifmem_malloc(SPIF_CAST(charptr) __FILE__, __LINE__, (sz))
# define CALLOC(type,n) spifmem_calloc(SPIF_CAST(charptr) __FILE__, __LINE__, (n), (sizeof(type)))
# define REALLOC(mem,sz) spifmem_realloc(SPIF_CAST(charptr) #mem, SPIF_CAST(charptr) __FILE__, __LINE__, (mem), (sz))
# define FREE(ptr) do { spifmem_free(SPIF_CAST(charptr) #ptr, SPIF_CAST(charptr) __FILE__, __LINE__, (ptr)); (ptr) = NULL; } while (0)
# define STRDUP(s) spifmem_strdup(SPIF_CAST(charptr) #s, SPIF_CAST(charptr) __FILE__, __LINE__, SPIF_CAST(charptr) (s))
# define MALLOC_DUMP() spifmem_dump_mem_tables()
# define X_CREATE_PIXMAP(d, win, w, h, depth) spifmem_x_create_pixmap(SPIF_CAST(charptr) __FILE__, __LINE__, (d), (win), (w), (h), (depth))
# define X_FREE_PIXMAP(d, p) spifmem_x_free_pixmap(SPIF_CAST(charptr) #p, SPIF_CAST(charptr) __FILE__, __LINE__, (d), (p))
# if LIBAST_IMLIB2_SUPPORT
# define IMLIB_REGISTER_PIXMAP(p) spifmem_imlib_register_pixmap(SPIF_CAST(charptr) #p, SPIF_CAST(charptr) __FILE__, __LINE__, (p))
# define IMLIB_FREE_PIXMAP(p) spifmem_imlib_free_pixmap(SPIF_CAST(charptr) #p, SPIF_CAST(charptr) __FILE__, __LINE__, (p))
# else
# define IMLIB_REGISTER_PIXMAP(p) NOP
# define IMLIB_FREE_PIXMAP(p) NOP
# endif
# define PIXMAP_DUMP() spifmem_dump_pixmap_tables()
# define X_CREATE_GC(d, win, f, gcv) spifmem_x_create_gc(__FILE__, __LINE__, (d), (win), (f), (gcv))
# define X_FREE_GC(d, gc) spifmem_x_free_gc(#gc, __FILE__, __LINE__, (d), (gc))
# define GC_DUMP() spifmem_dump_gc_tables()
# define MALLOC_MOD 25
# define REALLOC_MOD 25
# define CALLOC_MOD 25
# define FREE_MOD 25
#else
# define MALLOC(sz) malloc(sz)
# define CALLOC(type,n) calloc((n),(sizeof(type)))
# define REALLOC(mem,sz) ((sz) ? ((mem) ? (realloc((mem), (sz))) : (malloc(sz))) : ((mem) ? (free(mem), NULL) : (NULL)))
# define FREE(ptr) do { free(ptr); (ptr) = NULL; } while (0)
# define STRDUP(s) strdup((char *) s)
# define MALLOC_DUMP() NOP
# define X_CREATE_PIXMAP(d, win, w, h, depth) XCreatePixmap((d), (win), (w), (h), (depth))
# define X_FREE_PIXMAP(d, p) XFreePixmap((d), (p))
# ifdef LIBAST_IMLIB2_SUPPORT
# define IMLIB_REGISTER_PIXMAP(p) NOP
# define IMLIB_FREE_PIXMAP(p) imlib_free_pixmap_and_mask(p)
# else
# define IMLIB_REGISTER_PIXMAP(p) NOP
# define IMLIB_FREE_PIXMAP(p) NOP
# endif
# define PIXMAP_DUMP() NOP
# define X_CREATE_GC(d, win, f, gcv) XCreateGC((d), (win), (f), (gcv))
# define X_FREE_GC(d, gc) XFreeGC((d), (gc))
# define GC_DUMP() NOP
#endif
/* Fast memset() macro contributed by vendu */
#if !defined(SIZEOF_LONG) || (SIZEOF_LONG == 8)
/** UNDOCUMENTED */
# define MEMSET_LONG() (l |= l<<32)
#else
/** UNDOCUMENTED */
# define MEMSET_LONG() NOP
#endif
/**
* @def MEMSET(s, c, count)
* Initialize a memory region to a particular value.
*
* This macro is a replacement for the libc function memset(). It
* initializes the memory region pointed to by @a s to the value
* specified by @a c. The size of the memory region is specified by
* @a count. Note that @a c must be a byte (char) value.
*
* This macro has been optimized to set as many bytes simultaneously as
* the architecture can handle, so it should offer superior
* performance to libc's memset() function.
*
* @param s A pointer to the memory region to initialize.
* @param c The value to which all bytes in the block will be
* set.
* @param count The size, in bytes, of the memory region.
* @see @link DOXGRP_MEM Memory Management Subsystem @endlink
* @ingroup DOXGRP_MEM
*/
#define MEMSET(s, c, count) do { \
char *end = (char *)(s) + (count); \
long l; \
long *l_dest = (long *)(s); \
char *c_dest; \
\
if (!(s)) { \
break; \
} \
/* areas of less than 4 * sizeof(long) are set in 1-byte chunks. */ \
if (((unsigned long) count) >= 4 * sizeof(long)) { \
/* fill l with c. */ \
l = (c) | (c)<<8; \
l |= l<<16; \
MEMSET_LONG(); \
\
/* fill in 1-byte chunks until boundary of long is reached. */ \
if ((unsigned long)l_dest & (unsigned long)(sizeof(long) -1)) { \
c_dest = (char *)l_dest; \
while ((unsigned long)c_dest & (unsigned long)(sizeof(long) -1)) { \
*(c_dest++) = (c); \
} \
l_dest = (long *)c_dest; \
} \
\
/* fill in long-size chunks as long as possible. */ \
while (((unsigned long) (end - (char *)l_dest)) >= sizeof(long)) { \
*(l_dest++) = l; \
} \
} \
\
/* fill the tail in 1-byte chunks. */ \
if ((char *)l_dest < end) { \
c_dest = (char *)l_dest; \
*(c_dest++) = (c); \
while (c_dest < end) { \
*(c_dest++) = (c); \
} \
} \
} while (0)
/******************************* STRINGS GOOP *********************************/
/**
* Returns the length of a literal string.
*
* This macro is like libc's strlen() function, except that it
* requires the string parameter be a literal rather than a variable.
* This makes calculating the string length for a literal easy without
* incurring the speed penalty of a call to strlen().
*
* @param x The literal string (i.e., a fixed string in quotes, like
* "this.").
* @return The length of the string.
* @see @link DOXGRP_STRINGS String Utility Routines @endlink
* @ingroup DOXGRP_STRINGS
*/
#define CONST_STRLEN(x) (sizeof(x) - 1)
/**
* Compares the beginning of a string with a literal.
*
* This macro, like the libc str*cmp() functions, returns an integer
* less than, equal to, or greater than zero depending on if the
* initial part of string @a s is found to be less than, to match, or
* to be greater than the literal string. Generally, this is used as
* a boolean value (as !BEG_STRCASECMP()) to determine whether or not
* @a s starts with @a constr or not. Note that case is ignored, as
* the name implies.
*
* @param s The string variable to compare to.
* @param constr A literal string representing what should be the
* beginning of @a s.
* @return See above.
* @see @link DOXGRP_STRINGS String Utility Routines @endlink
* @ingroup DOXGRP_STRINGS
*/
#define BEG_STRCASECMP(s, constr) (strncasecmp(SPIF_CAST_C(char *) (s), constr, CONST_STRLEN(constr)))
/******************************** CONF GOOP ***********************************/
/**
* @def PATH_MAX
* The maximum length of a path specifier.
*
* LibAST requires PATH_MAX to be properly defined. Unfortunately,
* some UNIX versions (namely HP-UX) define it incorrectly. Most UNIX
* versions support a PATH_MAX of 1024, but all must support at least
* 255. So if PATH_MAX is defined to be less than 255 (like HP-UX and
* its absolutely ludicrous value of 14), LibAST forceably redefines
* it to be 255.
* @see @link DOXGRP_CONF Configuration File Parser @endlink
* @ingroup DOXGRP_CONF
*/
#if defined(PATH_MAX) && (PATH_MAX < 255)
# undef PATH_MAX
#endif
#ifndef PATH_MAX
# define PATH_MAX 255
#endif
/**
* Maximum length of a line in a config file.
*
* At no time during parsing can any line in a config file exceed this
* length (20 kB by default).
* @see @link DOXGRP_CONF Configuration File Parser @endlink
* @ingroup DOXGRP_CONF
*/
#define CONFIG_BUFF 20480
/**
* Special flag character.
*
* This is the special character value passed to a config context
* parser when the @c begin statement for that context is
* encountered.
*
* @see @link DOXGRP_CONF Configuration File Parser @endlink
* @ingroup DOXGRP_CONF
*/
#define SPIFCONF_BEGIN_CHAR '\001'
/**
* Special flag character string.
*
* This is the string representation of SPIFCONF_BEGIN_CHAR.
*
* @see @link DOXGRP_CONF Configuration File Parser @endlink
* @ingroup DOXGRP_CONF
*/
#define SPIFCONF_BEGIN_STRING "\001"
/**
* Special flag character.
*
* This is the special character value passed to a config context
* parser when the @c end statement for that context is encountered.
*
* @see @link DOXGRP_CONF Configuration File Parser @endlink
* @ingroup DOXGRP_CONF
*/
#define SPIFCONF_END_CHAR '\002'
/**
* Special flag character string.
*
* This is the string representation of SPIFCONF_END_CHAR.
*
* @see @link DOXGRP_CONF Configuration File Parser @endlink
* @ingroup DOXGRP_CONF
*/
#define SPIFCONF_END_STRING "\002"
/**
* Compares boolean option value to allowed true values.
*
* This macro compares the value of a boolean option against the
* acceptable boolean "true" values ("1", "on", "yes", and "true").
*
* @param s String value of a boolean option.
* @return Non-zero if a match is found, zero if not.
* @see @link DOXGRP_CONF Configuration File Parser @endlink
* @ingroup DOXGRP_CONF
*/
#define BOOL_OPT_ISTRUE(s) (!strcasecmp(SPIF_CHARPTR_C(s), true_vals[0]) \
|| !strcasecmp(SPIF_CHARPTR_C(s), true_vals[1]) \
|| !strcasecmp(SPIF_CHARPTR_C(s), true_vals[2]) \
|| !strcasecmp(SPIF_CHARPTR_C(s), true_vals[3]))
/**
* Compares boolean option value to allowed false values.
*
* This macro compares the value of a boolean option against the
* acceptable boolean "false" values ("0", "off", "no", and "false").
*
* @param s String value of a boolean option.
* @return Non-zero if a match is found, zero if not.
* @see @link DOXGRP_CONF Configuration File Parser @endlink
* @ingroup DOXGRP_CONF
*/
#define BOOL_OPT_ISFALSE(s) (!strcasecmp(SPIF_CHARPTR_C(s), false_vals[0]) \
|| !strcasecmp(SPIF_CHARPTR_C(s), false_vals[1]) \
|| !strcasecmp(SPIF_CHARPTR_C(s), false_vals[2]) \
|| !strcasecmp(SPIF_CHARPTR_C(s), false_vals[3]))
/**
* Skip-to-end flag.
*
* This symbol represents the bit in the FSS flags which specifies
* that the parser should skip the rest of the file.
*
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define FILE_SKIP_TO_END (0x01)
/**
* Preprocessing flag.
*
* This symbol represents the bit in the FSS flags which specifies
* that this file should be preprocessed.
*
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define FILE_PREPROC (0x02)
/**
* Push info for a new file onto the state stack.
*
* This macro adds a new file state structure to the top of the stack
* and populates it with the information contained in the macro
* parameters. When a new file is opened for parsing, a call is made
* to this macro to "push" the new file onto the top of the stack.
*
* @param f The file pointer (FILE *) representing the newly-opened
* file.
* @param p The path to the newly-opened file.
* @param o The output file name (for preprocessing).
* @param l The current line number for the file.
* @param fl The flag set for the file.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_push(f, p, o, l, fl) spifconf_register_fstate(f, p, o, l, fl)
/**
* Pop a state structure off the stack.
*
* This macro pops a file state structure off the top of the stack. A
* call to this macro occurs once the parsing of the current file is
* completed.
*
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_pop() (fstate_idx--)
/**
* Return the top file state structure on the stack.
*
* This macro is used to access the file state structure currently on
* top of the stack.
*
* @return The file state structure atop the stack.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_peek() (fstate[fstate_idx])
/**
* Examine the file pointer on top of the stack.
*
* This macro returns the file pointer (FILE *) corresponding to the
* file currently being parsed.
*
* @return The current file pointer.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_peek_fp() (fstate[fstate_idx].fp)
/**
* Examine the path of the current file.
*
* This macro returns the path for the file currently being parsed.
*
* @return The path of the current file.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_peek_path() (fstate[fstate_idx].path)
/**
* Examine the path of the current pre-processing output file.
*
* This macro returns the path for the preprocessing output file
* currently being parsed.
*
* @return The path of the current preproc output file.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_peek_outfile() (fstate[fstate_idx].outfile)
/**
* Examine the line number of the current file.
*
* This macro returns the current line number within the current
* config file.
*
* @return The line number of the current file.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_peek_line() (fstate[fstate_idx].line)
/**
* Check whether or not we're skipping to the end of the current
* file.
*
* This macro returns zero if the current file is being parsed and
* non-zero if the parser is skipping to its end.
*
* @return The skip-to-end flag for the current file.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_peek_skip() (fstate[fstate_idx].flags & FILE_SKIP_TO_END)
/**
* Check whether or not the current file was preprocessed.
*
* This macro returns zero if the current file was not preprocessed
* and non-zero if it was.
*
* @return The preprocessing flag for the current file.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_peek_preproc() (fstate[fstate_idx].flags & FILE_PREPROC)
/**
* Set the file pointer for the current file.
*
* @internal
* @param f The file pointer (FILE *).
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_poke_fp(f) ((fstate[fstate_idx].fp) = (f))
/**
* Set the path for the current file.
*
* @internal
* @param p The path.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_poke_path(p) ((fstate[fstate_idx].path) = (p))
/**
* Set the outfile for the current file.
*
* @internal
* @param o The outfile.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_poke_outfile(o) ((fstate[fstate_idx].outfile) = (o))
/**
* Set the current line number for the current file.
*
* @internal
* @param l The line number.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_poke_line(l) ((fstate[fstate_idx].line) = (l))
/**
* Set the skip-to-end flag for the current file.
*
* @internal
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_skip_to_end() ((fstate[fstate_idx].flags) |= (FILE_SKIP_TO_END))
/**
* Set/clear the skip-to-end flag for the current file.
*
* @internal
* @param s 0 to clear, non-zero to set.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_poke_skip(s) do {if (s) {fstate[fstate_idx].flags |= FILE_SKIP_TO_END;} else {fstate[fstate_idx].flags &= ~(FILE_SKIP_TO_END);} } while (0)
/**
* Set/clear the preprocessing flag for the current file.
*
* @internal
* @param s 0 to clear, non-zero to set.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_poke_preproc(s) do {if (s) {fstate[fstate_idx].flags |= FILE_PREPROC;} else {fstate[fstate_idx].flags &= ~(FILE_PREPROC);} } while (0)
/**
* Set all state info for the current file.
*
* @internal
* @param f The file pointer (FILE *).
* @param p The file path.
* @param o The outfile.
* @param l The line number.
* @param fl The flags.
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_poke(f, p, o, l, fl) do {file_poke_fp(f); file_poke_path(p); file_poke_outfile(o); file_poke_line(l); fstate[fstate_idx].flags = (fl);} while (0)
/**
* Increment the line number for the current file.
*
* @internal
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
#define file_inc_line() (fstate[fstate_idx].line++)
/**
* File state stack structure.
*
* This structure comprises the individual stack elements on the file
* state stack. One of these structures is present on the stack for
* each file being parsed.
*
* @see @link DOXGRP_CONF_FSS File State Stack @endlink
* @ingroup DOXGRP_CONF_FSS
*/
typedef struct file_state_struct {
/**
* File pointer.
*
* Contains an open file pointer used to read data from the
* file.
*/
FILE *fp;
/**
* File path.
*
* Contains the path to the file.
*/
spif_charptr_t path;
/**
* Preprocessing output file.
*
* Contains the path to the file used for preprocessing
* output.
*/
spif_charptr_t outfile;
/**
* Line number.
*
* Contains the current line number for the file.
*/
spif_uint32_t line;
/**
* File state flags.
*
* Contains the skip-to-end (FILE_SKIP_TO_END) and preprocessing
* (FILE_PREPROC) flags for the file.
*/
spif_uint8_t flags;
} fstate_t;
/**
* Typedef for pointers to context handler functions.
*
* This function pointer type is used for variables, typecasts,
* etc. involving context handler functions. Context handlers must
* accept two parameters, a char * containing either the config file
* line or a begin/end magic string, and a void * containing state
* information; they must return a void * which will be passed to the
* next invocation of the handler as the aforementioned state
* information parameter.
*
* @see @link DOXGRP_CONF_CTX Context Handling @endlink
* @ingroup DOXGRP_CONF_CTX
*/
typedef spif_ptr_t (*ctx_handler_t)(spif_charptr_t, spif_ptr_t);
/**
* Typedef for pointers to built-in functions.
*
* This function pointer type is used for config file built-in
* function handlers. LibAST supplies several built-in functions
* which can be used in config files (%get(), %appname(), etc.);
* client programs can add their own as well. Built-in functions take
* a single char * parameter, the parameter list passed to the
* built-in function in the config file. They return a char *, the
* result string to substitute for the function call.
*
* @see @link DOXGRP_CONF Configuration File Parser @endlink
* @ingroup DOXGRP_CONF
*/
typedef spif_charptr_t (*spifconf_func_ptr_t) (spif_charptr_t);
extern fstate_t *fstate;
extern unsigned char fstate_idx;
extern const char *true_vals[], *false_vals[];
/******************************* OPTIONS GOOP **********************************/
/*@{*/
/**
* @name Option Flags
* Flags for individual options.
*
* Each option structure (spifopt_t_struct) has a 16-bit value called
* "flags" associated with it. The lowest 5 bits (0-4) are for option
* types which do not require a specific value (such as boolean). The
* next 5 bits (5-9) are for option types which always require a
* value. Bit 10 is for abstract options, which could by definition
* go either way. And the final 5 bits (11-15) are for
* non-type-related information, such as flagging preparsed or
* deprecated options.
*
* @ingroup DOXGRP_OPT
*/
/** No flags. No flags. */
#define SPIFOPT_FLAG_NONE (0)
/** Boolean option. This flag marks a boolean option. */
#define SPIFOPT_FLAG_BOOLEAN (1UL << 0)
/** Counter option. This flag marks a counter option. */
#define SPIFOPT_FLAG_COUNTER (1UL << 1)
/** No-value type mask. This is a bitmask to select the lower 5 bits
* (those which represent options where no value is required).
*/
#define SPIFOPT_FLAG_TYPEMASK_NOVALUE (0x001f)
/** Integer option. This flag marks an integer (numeric) option. */
#define SPIFOPT_FLAG_INTEGER (1UL << 5)
/** String option. This flag marks a string option. */
#define SPIFOPT_FLAG_STRING (1UL << 6)
/** Argument list option. This flag marks an argument list option
* (such as -e/--exec). There can be one of these at most.
*/
#define SPIFOPT_FLAG_ARGLIST (1UL << 7)
/** Value type mask. This is a bitmask to select bits 5-9
* (those which represent options where a value is required).
*/
#define SPIFOPT_FLAG_TYPEMASK_VALUE (0x03e0)
/** Abstract option. This flag marks an abstract (client-handled)
* option.
*/
#define SPIFOPT_FLAG_ABSTRACT (1UL << 10)
/** Type mask. This is a bitmask to select all type-identifying
* option flag bits (0-10, inclusive).
*/
#define SPIFOPT_FLAG_TYPEMASK (0x07ff)
/**
* Preparsed option. This flag marks an option which is preparsed
* (i.e., parsed only on the pre-parse pass, which is generally done
* before config files are read).
*/
#define SPIFOPT_FLAG_PREPARSE (1UL << 11)
/**
* Deprecated option. This flag marks an option which has been
* deprecated by the author(s) of the program. A warning message is
* printed whenever a deprecated option is encountered.
*/
#define SPIFOPT_FLAG_DEPRECATED (1UL << 12)
/**
* Array option. This flag marks an option which, rather than taking
* a single value of its type, takes multiple values of its type.
* LibAST will allocate and return a NULL-terminated C-style array of
* the given type. The absence of this flag, except for abstract
* options, means that multiple instances of a given flag will
* overwrite previous values, if any. Abstract options are entirely
* client-handled, so this flag has no meaning there.
*/
#define SPIFOPT_FLAG_ARRAY (1UL << 13)
/** Modifier mask. This is a bitmask to select all the non-type
* flags; i.e., those which modify option behavior.
*/
#define SPIFOPT_FLAG_MODMASK (0xf800)
/*@}*/
/*@{*/
/**
* @name Parser Settings
* Flags which alter the behavior of the parser itself.
*
* The option parser settings structure (spifopt_settings_t_struct)
* has an 8-bit flag field which contains toggles affecting the
* parser's internal behavior. As a general rule, these will not be
* flags that client programs will want to manipulate. In the event
* that you do wish to manipulate these flags, use the
* SPIFOPT_FLAGS_*() macros.
*
* @ingroup DOXGRP_OPT
*/
/**
* Preparse flag. This flag denotes whether or not the next call to
* the spifopt_parse() function will parse only those options which
* have the SPIFOPT_FLAG_PREPARSE flag set, after which it will clear
* this flag. Callers wishing to have certain options pre-parsed
* should set this flag prior to invoking spifopt_parse(). Use of
* this flag is not required.
*/
#define SPIFOPT_SETTING_PREPARSE (1UL << 0)
/*@}*/
/*@{*/
/**
* @name Option Declaration Convenience Macros
* Macros which simplify the building of the options list.
*
* Each client program which intends to use the LibAST option parser
* (i.e., calls spifopt_parse() one or more times) is responsible for
* building its own option structure (spifopt_t) array which is then
* registered with LibAST using the SPIFOPT_OPTLIST_SET() macro.
*
* To simplify the declaration of this structure, a set of convenience
* macros is provided that will make the structure more
* human-readable. Although their use is not required, it is
* recommended in order to enhance readability and reduce the
* probability of human error.
*
* @ingroup DOXGRP_OPT
*/
/**
* Primary option declaration macro.
*
* This is the primary macro used for declaring an option. All other
* option declaration convenience macros are merely simpler forms of
* this macro. If you prefer, you can use this macro for all option
* declarations; just be sure to get the parameters right.
*
* @param s The short form as a char, or 0 for none.
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param f Bitwise OR of zero or more flags.
* @param p The pointer to where the data should be stored. Except in
* the case of function pointers (for abstract options), this
* parameter will need the & operator. See the other
* convenience macros for type requirements.
* @param m The bitmask for a boolean option, or 0 for other types.
*/
#define SPIFOPT_OPTION(s, l, d, f, p, m) { s, SPIF_CHARPTR(l), SPIF_CHARPTR(d), f, p, m }
/**
* Declare a boolean option.
*
* This macro is used to declare a simple boolean option with both a
* short and a long form.
*
* @param s The short form as a char, or 0 for none.
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param v A variable of type "unsigned long" (or one that can be
* safely typecast to/from it) to be used as a bitfield.
* @param m The bitmask to be set/unset within the bitfield.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_BOOL(s, l, d, v, m) \
SPIFOPT_OPTION(s, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_BOOLEAN), &(v), m)
/**
* Declare a pre-parsed boolean option.
*
* This macro is used to declare a boolean option with both a short
* and a long form which will be pre-parsed.
*
* @param s The short form as a char, or 0 for none.
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param v A variable of type "unsigned long" (or one that can be
* safely typecast to/from it) to be used as a bitfield.
* @param m The bitmask to be set/unset within the bitfield.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_BOOL_PP(s, l, d, v, m) \
SPIFOPT_OPTION(s, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_BOOLEAN | SPIFOPT_FLAG_PREPARSE), &(v), m)
/**
* Declare a long-only boolean option.
*
* This macro is used to declare a boolean option with only a long
* form.
*
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param v A variable of type "unsigned long" (or one that can be
* safely typecast to/from it) to be used as a bitfield.
* @param m The bitmask to be set/unset within the bitfield.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_BOOL_LONG(l, d, v, m) \
SPIFOPT_OPTION(0, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_BOOLEAN), &(v), m)
/**
* Declare a long-only, pre-parsed boolean option.
*
* This macro is used to declare a boolean option with only a long
* form which will be pre-parsed.
*
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param v A variable of type "unsigned long" (or one that can be
* safely typecast to/from it) to be used as a bitfield.
* @param m The bitmask to be set/unset within the bitfield.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_BOOL_LONG_PP(l, d, v, m) \
SPIFOPT_OPTION(0, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_BOOLEAN | SPIFOPT_FLAG_PREPARSE), &(v), m)
/**
* Declare an integer option.
*
* This macro is used to declare a simple integer option with both a
* short and a long form.
*
* @param s The short form as a char, or 0 for none.
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param v A variable of type "int" (or one that can be
* safely typecast to/from it) to store the option value.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_INT(s, l, d, v) \
SPIFOPT_OPTION(s, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_INTEGER), &(v), 0)
/**
* Declare a pre-parsed integer option.
*
* This macro is used to declare an integer option with both a short
* and a long form which will be pre-parsed.
*
* @param s The short form as a char, or 0 for none.
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param v A variable of type "int" (or one that can be
* safely typecast to/from it) to store the option value.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_INT_PP(s, l, d, v) \
SPIFOPT_OPTION(s, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_INTEGER | SPIFOPT_FLAG_PREPARSE), &(v), 0)
/**
* Declare a long-only integer option.
*
* This macro is used to declare an integer option with only a long
* form.
*
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param v A variable of type "int" (or one that can be
* safely typecast to/from it) to store the option value.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_INT_LONG(l, d, v) \
SPIFOPT_OPTION(0, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_INTEGER), &(v), 0)
/**
* Declare a long-only, pre-parsed integer option.
*
* This macro is used to declare an integer option with only a long
* form which will be pre-parsed.
*
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param v A variable of type "int" (or one that can be
* safely typecast to/from it) to store the option value.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_INT_LONG_PP(l, d, v) \
SPIFOPT_OPTION(0, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_INTEGER | SPIFOPT_FLAG_PREPARSE), &(v), 0)
/**
* Declare a string option.
*
* This macro is used to declare a simple string option with both a
* short and a long form.
*
* @param s The short form as a char, or 0 for none.
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param v A variable of type "const char *" (or one that can be
* safely typecast to/from it) to store the option value.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_STR(s, l, d, v) \
SPIFOPT_OPTION(s, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_STRING), &(v), 0)
/**
* Declare a pre-parsed string option.
*
* This macro is used to declare a string option with both a short and
* a long form which will be pre-parsed.
*
* @param s The short form as a char, or 0 for none.
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param v A variable of type "const char *" (or one that can be
* safely typecast to/from it) to store the option value.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_STR_PP(s, l, d, v) \
SPIFOPT_OPTION(s, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_STRING | SPIFOPT_FLAG_PREPARSE), &(v), 0)
/**
* Declare a long-only string option.
*
* This macro is used to declare a string option with only a long
* form.
*
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param v A variable of type "const char *" (or one that can be
* safely typecast to/from it) to store the option value.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_STR_LONG(l, d, v) \
SPIFOPT_OPTION(0, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_STRING), &(v), 0)
/**
* Declare a long-only, pre-parsed string option.
*
* This macro is used to declare a string option with only a long form
* which will be pre-parsed.
*
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param v A variable of type "const char *" (or one that can be
* safely typecast to/from it) to store the option value.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_STR_LONG_PP(l, d, v) \
SPIFOPT_OPTION(0, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_STRING | SPIFOPT_FLAG_PREPARSE), &(v), 0)
/**
* Declare an argument list option.
*
* This macro is used to declare a simple argument list option with
* both a short and a long form.
*
* @note Due to the nature of this option type and the fact that it
* can consume values to the end of the command line, only one
* option of this type can be declared.
*
* @param s The short form as a char, or 0 for none.
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param p A pointer of type "char **" (or one that can be
* safely typecast to/from it) to store the NULL-terminated
* argument list.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_ARGS(s, l, d, p) \
SPIFOPT_OPTION(s, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_ARGLIST), &(p), 0)
/**
* Declare a pre-parsed argument list option.
*
* This macro is used to declare an argument list option with both a
* short and a long form which will be pre-parsed.
*
* @note Due to the nature of this option type and the fact that it
* can consume values to the end of the command line, only one
* option of this type can be declared.
*
* @param s The short form as a char, or 0 for none.
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param p A pointer of type "char **" (or one that can be
* safely typecast to/from it) to store the NULL-terminated
* argument list.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_ARGS_PP(s, l, d, p) \
SPIFOPT_OPTION(s, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_ARGLIST | SPIFOPT_FLAG_PREPARSE), &(p), 0)
/**
* Declare a long-only argument list option.
*
* This macro is used to declare an argument list option with only a
* long form.
*
* @note Due to the nature of this option type and the fact that it
* can consume values to the end of the command line, only one
* option of this type can be declared.
*
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param p A pointer of type "char **" (or one that can be
* safely typecast to/from it) to store the NULL-terminated
* argument list.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_ARGS_LONG(l, d, p) \
SPIFOPT_OPTION(0, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_ARGLIST), &(p), 0)
/**
* Declare a long-only, pre-parsed argument list option.
*
* This macro is used to declare an argument list option with only a
* long form which will be pre-parsed.
*
* @note Due to the nature of this option type and the fact that it
* can consume values to the end of the command line, only one
* option of this type can be declared.
*
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param p A pointer of type "char **" (or one that can be
* safely typecast to/from it) to store the NULL-terminated
* argument list.
* @see SPIFOPT_OPTION()
*/
#define SPIFOPT_ARGS_LONG_PP(l, d, p) \
SPIFOPT_OPTION(0, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_ARGLIST | SPIFOPT_FLAG_PREPARSE), &(p), 0)
/**
* Declare an abstract option.
*
* This macro is used to declare a simple abstract option with both a
* short and a long form.
*
* @param s The short form as a char, or 0 for none.
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param f A function pointer of type "spifopt_abstract_handler_t"
* (or one that can be safely typecast to/from it) to handle
* the parsing of the option.
* @see SPIFOPT_OPTION(), spifopt_abstract_handler_t
*/
#define SPIFOPT_ABST(s, l, d, f) \
SPIFOPT_OPTION(s, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_ABSTRACT), SPIF_CAST(ptr) f, 0)
/**
* Declare a pre-parsed abstract option.
*
* This macro is used to declare an abstract option with both a short
* and a long form which will be pre-parsed.
*
* @param s The short form as a char, or 0 for none.
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param f A function pointer of type "spifopt_abstract_handler_t"
* (or one that can be safely typecast to/from it) to handle
* the parsing of the option.
* @see SPIFOPT_OPTION(), spifopt_abstract_handler_t
*/
#define SPIFOPT_ABST_PP(s, l, d, f) \
SPIFOPT_OPTION(s, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_ABSTRACT | SPIFOPT_FLAG_PREPARSE), SPIF_CAST(ptr) f, 0)
/**
* Declare a long-only abstract option.
*
* This macro is used to declare an abstract option with only a long
* form.
*
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param f A function pointer of type "spifopt_abstract_handler_t"
* (or one that can be safely typecast to/from it) to handle
* the parsing of the option.
* @see SPIFOPT_OPTION(), spifopt_abstract_handler_t
*/
#define SPIFOPT_ABST_LONG(l, d, f) \
SPIFOPT_OPTION(0, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_ABSTRACT), SPIF_CAST(ptr) f, 0)
/**
* Declare a long-only, pre-parsed abstract option.
*
* This macro is used to declare an abstract option with only a long
* form which will be pre-parsed.
*
* @param l The long form as a char *. (required)
* @param d The description as a char *. (required)
* @param f A function pointer of type "spifopt_abstract_handler_t"
* (or one that can be safely typecast to/from it) to handle
* the parsing of the option.
* @see SPIFOPT_OPTION(), spifopt_abstract_handler_t
*/
#define SPIFOPT_ABST_LONG_PP(l, d, f) \
SPIFOPT_OPTION(0, SPIF_CHARPTR(l), SPIF_CHARPTR(d), (SPIFOPT_FLAG_ABSTRACT | SPIFOPT_FLAG_PREPARSE), SPIF_CAST(ptr) f, 0)
/*@}*/
/*@{*/
/**
* @name Option Flag Macros
* Macros which provide access to option flag information.
*
* These macros provide access to option type and flag information
* while abstracting the actual method of storage and retrieval. Each
* macro takes exactly one parameter, the offset within the options
* list.
*
* @ingroup DOXGRP_OPT
*/
/**
* Type macro.
*
* Retrieves the type flag. Use of this macro is discouraged; use one
* of the other macros instead.
*
* @param n The index of the desired option in the options list.
* @return The type flag (SPIFOPT_FLAG_*)
*/
#define SPIFOPT_OPT_TYPE(n) (SPIFOPT_OPT_FLAGS(n) & SPIFOPT_FLAG_TYPEMASK)
/**
* Boolean option test. Tests whether or not the given option is boolean.
*
* @param n The index of the desired option in the options list.
* @return 0 if option is not boolean, non-zero if it is.
*/
#define SPIFOPT_OPT_IS_BOOLEAN(n) (SPIFOPT_OPT_FLAGS(n) & SPIFOPT_FLAG_BOOLEAN)
/**
* Counter option test. Tests whether or not the given option is a counter.
*
* @param n The index of the desired option in the options list.
* @return 0 if option is not a counter, non-zero if it is.
*/
#define SPIFOPT_OPT_IS_COUNTER(n) (SPIFOPT_OPT_FLAGS(n) & SPIFOPT_FLAG_COUNTER)
/**
* Integer option test. Tests whether or not the given option is an integer.
*
* @param n The index of the desired option in the options list.
* @return 0 if option is not an integer, non-zero if it is.
*/
#define SPIFOPT_OPT_IS_INTEGER(n) (SPIFOPT_OPT_FLAGS(n) & SPIFOPT_FLAG_INTEGER)
/**
* String option test. Tests whether or not the given option is a string.
*
* @param n The index of the desired option in the options list.
* @return 0 if option is not a string, non-zero if it is.
*/
#define SPIFOPT_OPT_IS_STRING(n) (SPIFOPT_OPT_FLAGS(n) & SPIFOPT_FLAG_STRING)
/**
* Argument list option test. Tests whether or not the given option
* is an argument list.
*
* @param n The index of the desired option in the options list.
* @return 0 if option is not an argument list, non-zero if it is.
*/
#define SPIFOPT_OPT_IS_ARGLIST(n) (SPIFOPT_OPT_FLAGS(n) & SPIFOPT_FLAG_ARGLIST)
/**
* Abstract option test. Tests whether or not the given option is abstract.
*
* @param n The index of the desired option in the options list.
* @return 0 if option is not abstract, non-zero if it is.
*/
#define SPIFOPT_OPT_IS_ABSTRACT(n) (SPIFOPT_OPT_FLAGS(n) & SPIFOPT_FLAG_ABSTRACT)
/**
* Preparse option test. Tests whether or not the given option is to
* be preparsed.
*
* @param n The index of the desired option in the options list.
* @return 0 if option is not to be pre-parsed, non-zero if it is.
*/
#define SPIFOPT_OPT_IS_PREPARSE(n) (SPIFOPT_OPT_FLAGS(n) & SPIFOPT_FLAG_PREPARSE)
/**
* Deprecated option test. Tests whether or not the given option is deprecated.
*
* @param n The index of the desired option in the options list.
* @return 0 if option is not deprecated, non-zero if it is.
*/
#define SPIFOPT_OPT_IS_DEPRECATED(n) (SPIFOPT_OPT_FLAGS(n) & SPIFOPT_FLAG_DEPRECATED)
/**
* Array option test. Tests whether or not the given option is an array.
*
* @param n The index of the desired option in the options list.
* @return 0 if option is not an array, non-zero if it is.
*/
#define SPIFOPT_OPT_IS_ARRAY(n) (SPIFOPT_OPT_FLAGS(n) & SPIFOPT_FLAG_ARRAY)
/**
* Value required option test. Tests whether or not the given option
* requires a value.
*
* @param n The index of the desired option in the options list.
* @return 0 if option does not require a value, non-zero if it does.
*/
#define SPIFOPT_OPT_NEEDS_VALUE(n) (SPIFOPT_OPT_FLAGS(n) & SPIFOPT_FLAG_TYPEMASK_VALUE)
/*@}*/
/*@{*/
/**
* @name Option Structure Access Macros
* Macros which provide access to individual structure components.
*
* These macros provide an easy method for accessing the various
* members of a single option structure (spifopt_t_struct) within the
* options list without needing to know how the options list, or the
* options within it, are stored.
*
* @ingroup DOXGRP_OPT
*/
/**
* Short form. Returns the short form of the option.
*
* @param n The index of the desired option in the options list.
* @return The short (char) form of the option.
*/
#define SPIFOPT_OPT_SHORT(n) (SPIFOPT_OPTLIST_GET_OPT(n).short_opt)
/**
* Long form. Returns the long form of the option.
*
* @param n The index of the desired option in the options list.
* @return The long (const char *) form of the option.
*/
#define SPIFOPT_OPT_LONG(n) (SPIFOPT_OPTLIST_GET_OPT(n).long_opt)
/**
* Description. Returns the description of the option.
*
* @param n The index of the desired option in the options list.
* @return The description (const char *) of the option.
*/
#define SPIFOPT_OPT_DESC(n) (SPIFOPT_OPTLIST_GET_OPT(n).desc)
/**
* Flags. Returns the flags for the option.
*
* @param n The index of the desired option in the options list.
* @return The flags (spif_uint16_t) for the option.
*/
#define SPIFOPT_OPT_FLAGS(n) (SPIFOPT_OPTLIST_GET_OPT(n).flags)
/**
* Value pointer. Returns the value pointer for the option.
*
* @param n The index of the desired option in the options list.
* @return The value pointer (void *) for the option.
*/
#define SPIFOPT_OPT_VALUE(n) (SPIFOPT_OPTLIST_GET_OPT(n).value)
/**
* Bitmask. Returns the bitmask for the option.
*
* @param n The index of the desired option in the options list.
* @return The bitmask (spif_uint32_t) for the option.
*/
#define SPIFOPT_OPT_MASK(n) (SPIFOPT_OPTLIST_GET_OPT(n).mask)
/*@}*/
/*@{*/
/**
* @name Option Parser Settings Macros
* Macros which provide access to the option parser settings.
*
* These macros provide abstracted access to various settings used by
* the option parser.
*
* @ingroup DOXGRP_OPT
*/
/**
* Retrieves a single option structure.
*
* This macro returns a single option structure (spifopt_t_struct)
* from the options list. This is mostly for internal use.
*
* @param n The index of the desired option in the options list.
* @return The option structure (spifopt_t_struct).
*/
#define SPIFOPT_OPTLIST_GET_OPT(n) (spifopt_settings.opt_list[((n) < (spifopt_settings.num_opts) ? (n) : (0))])
/**
* Sets the option list.
*
* This macro should be called by client programs to set the option
* list. It must be a spifopt_t * of some type (probably a
* spifopt_t []). Once set, it must not be manipulated directly; only
* via the LibAST-supplied macros.
*
* @param l The options list variable (a spifopt_t pointer or array).
*/
#define SPIFOPT_OPTLIST_SET(l) (spifopt_settings.opt_list = ((spifopt_t *) (l)))
/**
* Obtains the number of options.
*
* This macro returns the total number of options in the options list.
*
* @return The number of options in the list.
*/
#define SPIFOPT_NUMOPTS_GET() (spifopt_settings.num_opts)
/**
* Sets the number of options.
*
* This macro sets the number of options in the options list. It
* should be called immediately after SPIFOPT_OPTLIST_SET() and
* @em before any functions or macros which use the options list. The
* most common way to handle this is to use a fixed array for the
* options list and call
*
* @code
* SPIFOPT_NUMOPTS_SET(sizeof(option_list) / sizeof(spifopt_t))
* @endcode
*
* to set the option count.
*
* @param n The number of elements in the options list.
*/
#define SPIFOPT_NUMOPTS_SET(n) (spifopt_settings.num_opts = (n))
/**
* Obtains the option parser flag settings.
*
* This macro returns the value of the parser settings flags. In most
* cases, you should use SPIFOPT_FLAGS_IS_SET() instead.
*
* @return The value of the parser settings flags.
*/
#define SPIFOPT_FLAGS_GET() (spifopt_settings.flags)
/**
* Sets an option parser settings flag.
*
* This macro sets one or more parser settings flags. There are
* currently no client-managed parser flags, so you should avoid this
* macro.
*
* @param m The flag (or set of bitwise-or'd flags) to turn on.
*/
#define SPIFOPT_FLAGS_SET(m) (spifopt_settings.flags |= (m))
/**
* Checks whether or not an option parser settings flag is set.
*
* This macro tests one or more parser settings flags. There are
* currently no client-managed parser flags, so you should avoid this
* macro.
*
* @param m The flag (or set of bitwise-or'd flags) to check.
* @return 0 if none of the selected flags are set, non-zero if at
* least one is.
*/
#define SPIFOPT_FLAGS_IS_SET(m) (spifopt_settings.flags & (m))
/**
* Clears an option parser settings flag.
*
* This macro clears one or more parser settings flags. There are
* currently no client-managed parser flags, so you should avoid this
* macro.
*
* @param m The flag (or set of bitwise-or'd flags) to turn off.
*/
#define SPIFOPT_FLAGS_CLEAR(m) (spifopt_settings.flags &= ~(m))
/**
* Gets the bad option count.
*
* This macro retrieves the count of bad options encountered during
* option parsing.
*
* @return The number of bad options encountered.
*/
#define SPIFOPT_BADOPTS_GET() (spifopt_settings.bad_opts)
/**
* Sets the bad option count.
*
* This macro sets the count of bad options encountered during option
* parsing. This macro should not be used by client programs.
*
* @param n The number of bad options encountered.
*/
#define SPIFOPT_BADOPTS_SET(n) (spifopt_settings.bad_opts = (n))
/**
* Gets the bad option setting.
*
* This macro retrieves the setting for the number of bad options
* allowed before parsing is aborted and the help screen is displayed.
*
* @return The number of bad options allowed.
*/
#define SPIFOPT_ALLOWBAD_GET() (spifopt_settings.allow_bad)
/**
* Sets the bad option setting.
*
* This macro sets the number of bad options allowed before parsing is
* aborted and the help screen is displayed. This macro should be
* called prior to option parsing.
*
* @param n The number of bad options allowed.
*/
#define SPIFOPT_ALLOWBAD_SET(n) (spifopt_settings.allow_bad = (n))
/**
* Gets the help handler function pointer.
*
* This macro retrieves the pointer to the function which will be
* called to display program help, due either to a help option or
* an excess number of option parsing errors. If this value is not
* set by the client (via the SPIFOPT_HELPHANDLER_SET() macro), the
* default handler is the built-in spifopt_usage() function.
*
* @return The function pointer for the help/usage screen function.
*/
#define SPIFOPT_HELPHANDLER ((spifopt_settings.help_handler) ? (spifopt_settings.help_handler) : (spifopt_usage))
/**
* Sets the help handler function pointer.
*
* This macro sets the pointer to the function which will be called to
* display program help, due either to a help option or an excess
* number of option parsing errors. If the client fails to call this
* macro prior to option parsing, the built-in spifopt_usage()
* function is used instead.
*
* @param f A function pointer of type spifopt_helphandler_t.
*/
#define SPIFOPT_HELPHANDLER_SET(f) (spifopt_settings.help_handler = (f))
/*@}*/
/**
* @name Type Definitions
*
*/
/*@{*/
/**
* Typedef for help handler function.
*
* This type is used for declaring/typecasting function pointers which
* will be used for help handlers. Functions used for this should be
* declared as returning void (and in reality does not return at all)
* and should take either no parameters, or a single char * parameter.
*
* @see @link DOXGRP_OPT Command Line Option Parser @endlink, SPIFOPT_HELPHANDLER_SET()
* @ingroup DOXGRP_OPT
*/
typedef void (*spifopt_helphandler_t)();
/**
* Typedef for abstract option handler function.
*
* This type is used for declaring/typecasting function pointers which
* will be used for abstract option handlers. Abstract options are
* those which require special handling; LibAST implements this by
* allowing for an arbitrary user-specified function be invoked when
* such an option is encountered. Functions used for this should be
* declared as returning void and should take a single char *
* parameter (the value of the option, or NULL if it had no value).
*
* @see @link DOXGRP_OPT Command Line Option Parser @endlink
* @ingroup DOXGRP_OPT
*/
typedef void (*spifopt_abstract_handler_t)(spif_charptr_t);
/**
* Option structure.
*
* This is the structure that holds the data for each of the command
* line options for which the parser will be looking. Client programs
* must create an array of these structures (a spifopt_t []) and use
* the SPIFOPT_OPTLIST_SET() macro to tell LibAST which variable it
* is.
*
* @note This structure and its members should NEVER be accessed
* directly; they are documented solely for informational purposes.
* The SPIFOPT_* convenience macros provide a streamlined, easy-to-use
* abstraction layer for declaring the option list, setting option
* parser parameters, and so forth. Even the internal code uses these
* macros! Consult the macro documentation and the example code for
* further assistance.
*
* @see @link DOXGRP_OPT Command Line Option Parser @endlink, @link opt_example.c example code @endlink
* @ingroup DOXGRP_OPT
*/
typedef struct spifopt_t_struct {
/**
* Short form.
*
* The short (one char) form of the option.
*/
spif_char_t short_opt;
/**
* Long form.
*
* The long (string) form of the option.
*/
spif_charptr_t long_opt;
/**
* Description.
*
* The (brief) description of the option for the help screen.
*/
spif_charptr_t desc;
/**
* Option type/attribute flags.
*
* The type and attribute flags for this option.
*/
spif_uint16_t flags;
/**
* Value pointer.
*
* A pointer to where the value for this option should be stored.
* Its exact type, and how it is interpreted, depends on the type
* of option being defined.
*/
void *value;
/**
* Boolean bitmask.
*
* For boolean options, this is the bitmask for the option. For
* other option types, it has no meaning.
*/
spif_uint32_t mask;
} spifopt_t;
/**
* Option parser settings structure.
*
* This is the structure that holds the settings and other internal
* variables which control how the options parser functions.
*
* @note This structure and its members should NEVER be accessed
* directly; they are documented solely for informational purposes.
* The SPIFOPT_* convenience macros provide a streamlined, easy-to-use
* abstraction layer for declaring the option list, setting option
* parser parameters, and so forth. Even the internal code uses these
* macros! Consult the macro documentation and the example code for
* further assistance.
*
* @see @link DOXGRP_OPT Command Line Option Parser @endlink, @link opt_example.c example code @endlink
* @ingroup DOXGRP_OPT
*/
typedef struct spifopt_settings_t_struct {
/**
* Options list.
*
* The array of option structures defining the options to look
* for.
*/
spifopt_t *opt_list;
/**
* Option count.
*
* The total number of options in the options list.
*/
spif_uint16_t num_opts;
/**
* Parser flags.
*
* Flags which control the behavior of the parser.
*/
spif_uint8_t flags;
/**
* Bad option count.
*
* Keeps track of the number of bad options (i.e., option syntax
* errors, such as missing values or unknown options)
* encountered.
*/
spif_uint8_t bad_opts;
/**
* Bad option limit.
*
* The maximum number of bad options allowed before giving up and
* displaying the help text.
*/
spif_uint8_t allow_bad;
spif_uint8_t indent; /**< Unused. */
/**
* Help handler.
*
* Pointer to the function which is responsible for displaying the
* help text. If undefined, spifopt_usage() is used.
*/
spifopt_helphandler_t help_handler;
} spifopt_settings_t;
/*@}*/
extern spifopt_settings_t spifopt_settings;
/******************************* HASHING GOOP *********************************/
/**
* @name Jenkins Hash
*
* Bob Jenkins' hash algorithm as published in December 1996. Public
* domain. See http://burtleburtle.net/bob/hash/
*/
/*@{*/
/**
* Calculate number of hash buckets needed for an n-bit hash key.
*
* This macro returns the number of hash buckets needed for a hash key
* of n distinct bits. Choose n based on your tolerable level of
* collisions, on average, for 2^n key values.
*
* @param n The number of bits.
* @return Number of hash buckets required.
*
*/
#define SPIFHASH_SIZE(n) (SPIF_CAST(uint32) (1UL << (n)))
/**
* Calculate mask to apply to hash key to get lowest n bits.
*
* This macro returns the bitmask needed for a hash key of n distinct
* bits. Choose n based on your tolerable level of collisions, on
* average, for 2^n key values.
*
* @param n The number of bits.
* @return Bitmask to zero out all but the n lowest bits.
*
*/
#define SPIFHASH_MASK(n) (SPIF_CAST(uint32) (SPIFHASH_SIZE(n) - 1))
/**
* Mix 3 32-bit integer values in a reproducible, reversible manner.
*
* This macro is used by the Jenkins hash algorithm to shuffle bits of
* three integers in such a way as to make sure that changes are
* propogated throughout the values.
*
* Instructions are arranged in such a way as to be parallizable;
* i.e., excluding the first two instructions, each subsequent pair of
* instructions may be evaluated simultaneously for pipelining
* purposes.
*
* @param a A 32-bit integer.
* @param b A 32-bit integer.
* @param c A 32-bit integer.
*/
#define SPIFHASH_JENKINS_MIX(a,b,c) \
{ \
a -= b; a -= c; a ^= (c>>13); \
b -= c; b -= a; b ^= (a<<8); \
c -= a; c -= b; c ^= (b>>13); \
a -= b; a -= c; a ^= (c>>12); \
b -= c; b -= a; b ^= (a<<16); \
c -= a; c -= b; c ^= (b>>5); \
a -= b; a -= c; a ^= (c>>3); \
b -= c; b -= a; b ^= (a<<10); \
c -= a; c -= b; c ^= (b>>15); \
}
/**
* A pointer to a hash function.
*
* This type is used to refer to any of the spifhash_* functions. A
* variable of this type can point to any of the built-in hash
* functions in LibAST interchangeably.
*
*/
typedef spif_uint32_t (*spifhash_func_t)(spif_uint8_t *, spif_uint32_t, spif_uint32_t);
/*@}*/
/******************************** PROTOTYPES **********************************/
/* msgs.c */
extern void libast_set_program_name(const char *);
extern void libast_set_program_version(const char *);
extern int libast_dprintf(const char *, ...);
extern void libast_print_error(const char *fmt, ...);
extern void libast_print_warning(const char *fmt, ...);
extern void libast_fatal_error(const char *fmt, ...);
/* debug.c */
extern unsigned int DEBUG_LEVEL;
/* mem.c */
extern void spifmem_init(void);
extern void *spifmem_malloc(const spif_charptr_t, unsigned long, size_t);
extern void *spifmem_realloc(const spif_charptr_t, const spif_charptr_t, unsigned long, void *, size_t);
extern void *spifmem_calloc(const spif_charptr_t, unsigned long, size_t, size_t);
extern void spifmem_free(const spif_charptr_t, const spif_charptr_t, unsigned long, void *);
extern spif_charptr_t spifmem_strdup(const spif_charptr_t, const spif_charptr_t,
unsigned long, const spif_charptr_t);
extern void spifmem_dump_mem_tables(void);
#if LIBAST_X11_SUPPORT
extern Pixmap spifmem_x_create_pixmap(const spif_charptr_t, unsigned long, Display *,
Drawable, unsigned int, unsigned int, unsigned int);
extern void spifmem_x_free_pixmap(const spif_charptr_t, const spif_charptr_t,
unsigned long, Display *, Pixmap);
# if LIBAST_IMLIB2_SUPPORT
extern void spifmem_imlib_register_pixmap(const spif_charptr_t var, const spif_charptr_t filename,
unsigned long line, Pixmap p);
extern void spifmem_imlib_free_pixmap(const spif_charptr_t var, const spif_charptr_t filename,
unsigned long line, Pixmap p);
# endif
extern void spifmem_dump_pixmap_tables(void);
extern GC spifmem_x_create_gc(const spif_charptr_t, unsigned long, Display *, Drawable,
unsigned long, XGCValues *);
extern void spifmem_x_free_gc(const spif_charptr_t, const spif_charptr_t, unsigned long, Display *, GC);
extern void spifmem_dump_gc_tables(void);
#endif
extern void spiftool_free_array(void *, size_t);
/* file.c */
extern int spiftool_temp_file(spif_charptr_t, size_t);
/* strings.c */
extern spif_bool_t spiftool_safe_strncpy(spif_charptr_t dest, const spif_charptr_t src, spif_int32_t size);
extern spif_bool_t spiftool_safe_strncat(spif_charptr_t dest, const spif_charptr_t src, spif_int32_t size);
extern spif_charptr_t spiftool_substr(const spif_charptr_t, spif_int32_t, spif_int32_t);
#if LIBAST_REGEXP_SUPPORT_POSIX && HAVE_REGEX_H
extern spif_bool_t spiftool_regexp_match(const spif_charptr_t, const spif_charptr_t);
extern spif_bool_t spiftool_regexp_match_r(const spif_charptr_t str, const spif_charptr_t pattern, regex_t **rexp);
#endif
extern spif_charptr_t *spiftool_split(const spif_charptr_t, const spif_charptr_t);
extern spif_charptr_t *spiftool_split_regexp(const spif_charptr_t, const spif_charptr_t);
extern spif_charptr_t spiftool_join(spif_charptr_t, spif_charptr_t *);
extern spif_charptr_t spiftool_get_word(unsigned long, const spif_charptr_t);
extern spif_charptr_t spiftool_get_pword(unsigned long, const spif_charptr_t);
extern unsigned long spiftool_num_words(const spif_charptr_t);
extern spif_charptr_t spiftool_chomp(spif_charptr_t);
extern spif_charptr_t spiftool_downcase_str(spif_charptr_t);
extern spif_charptr_t spiftool_upcase_str(spif_charptr_t);
extern spif_charptr_t spiftool_safe_str(spif_charptr_t, unsigned short);
extern spif_charptr_t spiftool_condense_whitespace(spif_charptr_t);
extern void spiftool_hex_dump(void *, size_t);
extern spif_cmp_t spiftool_version_compare(spif_charptr_t, spif_charptr_t);
#if !(HAVE_MEMMEM)
extern void *memmem(const void *, size_t, const void *, size_t);
#endif
#if !(HAVE_STRNLEN)
extern size_t strnlen(const char *, size_t);
#endif
#if !(HAVE_USLEEP)
extern void usleep(unsigned long);
#endif
#if !(HAVE_SNPRINTF)
extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
extern int snprintf(char *str, size_t count, const char *fmt, ...);
#endif
#if !(HAVE_STRCASESTR)
extern char *strcasestr(const char *, const char *);
#endif
#if !(HAVE_STRCASECHR)
extern char *strcasechr(const char *, const char);
#endif
#if !(HAVE_STRCASEPBRK)
extern char *strcasepbrk(const char *, const char *);
#endif
#if !(HAVE_STRREV)
extern char *strrev(char *);
#endif
#if !(HAVE_STRSEP)
extern char *strsep(char **, char *);
#endif
/* builtin_hashes.c */
extern spif_uint32_t spifhash_jenkins(register spif_uint8_t *key, register spif_uint32_t length, register spif_uint32_t seed);
extern spif_uint32_t spifhash_jenkins32(spif_uint8_t *key, register spif_uint32_t length, register spif_uint32_t seed);
#if WORDS_BIGENDIAN
# define spifhash_jenkinsLE(k, l, s) spifhash_jenkins((k), (l), (s))
#else
extern spif_uint32_t spifhash_jenkinsLE(register spif_uint8_t *key, register spif_uint32_t length, register spif_uint32_t seed);
#endif
extern spif_uint32_t spifhash_rotating(spif_uint8_t *key, spif_uint32_t len, spif_uint32_t seed);
extern spif_uint32_t spifhash_one_at_a_time(spif_uint8_t *key, spif_uint32_t len, spif_uint32_t seed);
extern spif_uint32_t spifhash_fnv(spif_uint8_t *key, spif_uint32_t len, spif_uint32_t seed);
/* conf.c */
extern void spifconf_init_subsystem(void);
extern unsigned char spifconf_register_context(spif_charptr_t name, ctx_handler_t handler);
extern unsigned char spifconf_register_fstate(FILE *fp, spif_charptr_t path, spif_charptr_t outfile, unsigned long line, unsigned char flags);
extern unsigned char spifconf_register_builtin(char *name, spifconf_func_ptr_t ptr);
extern unsigned char spifconf_register_context_state(unsigned char ctx_id);
extern void spifconf_free_subsystem(void);
extern spif_charptr_t spifconf_shell_expand(spif_charptr_t);
extern spif_charptr_t spifconf_find_file(const spif_charptr_t file, const spif_charptr_t dir, const spif_charptr_t pathlist);
extern FILE *spifconf_open_file(spif_charptr_t name);
extern void spifconf_parse_line(FILE *fp, spif_charptr_t buff);
extern spif_charptr_t spifconf_parse(spif_charptr_t conf_name, const spif_charptr_t dir, const spif_charptr_t path);
/* options.c */
extern void spifopt_parse(int, char **);
extern void spifopt_usage(void);
/* Do we, or do we not, pollute the namespace like we used to? */
#if LIBAST_COMPAT_05_API
/* The application must have defined this. */
/* conf.c */
# define CONF_BEGIN_CHAR SPIFCONF_BEGIN_CHAR
# define CONF_END_CHAR SPIFCONF_END_CHAR
# define CONF_BEGIN_STRING SPIFCONF_BEGIN_STRING
# define CONF_END_STRING SPIFCONF_END_STRING
typedef spifconf_func_ptr_t conf_func_ptr_t;
# define conf_init_subsystem() spifconf_init_subsystem()
# define conf_register_context(a, b) spifconf_register_context((a), (b))
# define conf_register_fstate(a, b, c, d, e) spifconf_register_fstate((a), (b), (c), (d), (e))
# define conf_register_builtin(a, b) spifconf_register_builtin((a), (b))
# define conf_register_context_state(a) spifconf_register_context_state(a)
# define conf_free_subsystem() spifconf_free_subsystem()
# define shell_expand(a) spifconf_shell_expand(a)
# define conf_find_file(a, b, c) spifconf_find_file((a), (b), (c))
# define open_config_file(a) spifconf_open_file(a)
# define conf_parse_line(a, b) spifconf_parse_line((a), (b))
# define conf_parse(a, b, c) spifconf_parse((a), (b), (c))
/* mem.c */
# define memrec_init() spifmem_init()
# define libast_malloc(a, b, c) spifmem_malloc((a), (b), (c))
# define libast_realloc(a, b, c, d, e) spifmem_realloc((a), (b), (c), (d), (e))
# define libast_calloc(a, b, c, d) spifmem_calloc((a), (b), (c), (d))
# define libast_free(a, b, c, d) spifmem_free((a), (b), (c), (d))
# define libast_strdup(a, b, c, d) spifmem_strdup((a), (b), (c), (d))
# define libast_dump_mem_tables() spifmem_dump_mem_tables()
# if LIBAST_X11_SUPPORT
# define libast_x_create_pixmap(a, b, c, d, e, f, g) spifmem_x_create_pixmap((a), (b), (c), (d), (e), (f), (g))
# define libast_x_free_pixmap(a, b, c, d, e) spifmem_x_free_pixmap((a), (b), (c), (d), (e))
# if LIBAST_IMLIB2_SUPPORT
# define libast_imlib_register_pixmap(a, b, c, d) spifmem_imlib_register_pixmap((a), (b), (c), (d))
# define libast_imlib_free_pixmap(a, b, c, d) spifmem_imlib_free_pixmap((a), (b), (c), (d))
# endif
# define libast_dump_pixmap_tables() spifmem_dump_pixmap_tables()
# define libast_x_create_gc(a, b, c, d, e, f) spifmem_x_create_gc((a), (b), (c), (d), (e), (f))
# define libast_x_free_gc(a, b, c, d, e) spifmem_x_free_gc((a), (b), (c), (d), (e))
# define libast_dump_gc_tables() spifmem_dump_gc_tables()
# endif
# define free_array(a, b) spiftool_free_array((a), (b))
/* file.c */
# define libast_temp_file(a, b) spiftool_temp_file((a), (b))
/* msgs.c */
static void (*print_error)(const char *, ...) = libast_print_error;
static void (*print_warning)(const char *, ...) = libast_print_warning;
static void (*fatal_error)(const char *, ...) = libast_fatal_error;
/* strings.c */
# define regexp_match(a, b) spiftool_regexp_match((a), (b))
# define regexp_match_r(a, b, c) spiftool_regexp_match_r((a), (b), (c))
# define split(a, b) spiftool_split((a), (b))
# define join(a, b) spiftool_join((a), (b))
# define get_word(a, b) spiftool_get_word((a), (b))
# define get_pword(a, b) spiftool_get_pword((a), (b))
# define num_words(a) spiftool_num_words(a)
# define chomp(a) spiftool_chomp(a)
# define strip_whitespace(a) spiftool_strip_whitespace(a)
# define downcase_str(a) spiftool_downcase_str(a)
# define upcase_str(a) spiftool_upcase_str(a)
# define safe_str(a, b) spiftool_safe_str((a), (b))
# define condense_whitespace(a) spiftool_condense_whitespace(a)
# define hex_dump(a, b) spiftool_hex_dump((a), (b))
# define version_compare(a, b) spiftool_version_compare((a), (b))
#endif /* LIBAST_COMPAT_05_API */
#endif /* _LIBAST_H_ */
|