1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908
|
/*
* libfyaml.h - Main header file of the public interface
*
* Copyright (c) 2019-2021 Pantelis Antoniou <pantelis.antoniou@konsulko.com>
*
* 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 or substantial portions of the Software.
*
* 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 OR COPYRIGHT HOLDERS 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.
*
* SPDX-License-Identifier: MIT
*/
#ifndef LIBFYAML_H
#define LIBFYAML_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
#include <unistd.h>
#endif
#include <sys/uio.h>
/* opaque types for the user */
struct fy_token;
struct fy_document_state;
struct fy_parser;
struct fy_emitter;
struct fy_document;
struct fy_node;
struct fy_node_pair;
struct fy_anchor;
struct fy_node_mapping_sort_ctx;
struct fy_token_iter;
struct fy_diag;
struct fy_path_parser;
struct fy_path_expr;
struct fy_path_exec;
struct fy_path_component;
struct fy_path;
struct fy_composer;
struct fy_document_iterator;
struct fy_document_builder;
#ifndef FY_BIT
#define FY_BIT(x) (1U << (x))
#endif
/* NULL terminated string length specifier */
#define FY_NT ((size_t)-1)
#if defined(__GNUC__) && __GNUC__ >= 4
#define FY_EXPORT __attribute__ ((visibility ("default")))
#define FY_DEPRECATED __attribute__ ((deprecated))
#define FY_FORMAT(_t, _x, _y) __attribute__ ((format(_t, _x, _y)))
#else
#define FY_EXPORT /* nothing */
#define FY_DEPRECATED /* nothing */
#define FY_FORMAT(_t, x, y) /* nothing */
#endif
/* make a copy of an allocated string and return it on stack
* note that this is a convenience, and should not be called
* in a loop. The string is always '\0' terminated.
* If the _str pointer is NULL, then NULL will be returned
*/
#ifndef FY_ALLOCA_COPY_FREE
#define FY_ALLOCA_COPY_FREE(_str, _len) \
({ \
char *__str = (_str), *__stra = NULL; \
size_t __len = (size_t)(_len); \
\
if (__str) { \
if (__len == FY_NT) \
__len = strlen(__str); \
__stra = alloca(__len + 1); \
memcpy(__stra, __str, __len); \
__stra[__len] = '\0'; \
free(__str); \
} \
(const char *)__stra; \
})
#endif
/* same as above but when _str == NULL return "" */
#ifndef FY_ALLOCA_COPY_FREE_NO_NULL
#define FY_ALLOCA_COPY_FREE_NO_NULL(_str, _len) \
({ \
const char *__strb; \
\
__strb = FY_ALLOCA_COPY_FREE(_str, _len); \
if (!__strb) \
__strb = ""; \
__strb; \
})
#endif
/**
* DOC: libfyaml public API
*
*/
/**
* struct fy_version - The YAML version
*
* @major: Major version number
* @minor: Major version number
*
* The parser fills it according to the \%YAML directive
* found in the document.
*/
struct fy_version {
int major;
int minor;
};
/* Build a fy_version * from the given major and minor */
#define fy_version_make(_maj, _min) (&(struct fy_version){ (_maj), (_min) })
/**
* fy_version_compare() - Compare two yaml versions
*
* Compare the versions
*
* @va: The first version, if NULL use default version
* @vb: The second version, if NULL use default version
*
* Returns:
* 0 if versions are equal, > 0 if version va is higher than vb
* < 0 if version va is lower than vb
*/
int
fy_version_compare(const struct fy_version *va, const struct fy_version *vb)
FY_EXPORT;
/**
* fy_version_default() - Get the default version of the library
*
* Return the default version of the library, i.e. the highest
* stable version that is supported.
*
* Returns:
* The default YAML version of this library
*/
const struct fy_version *
fy_version_default(void)
FY_EXPORT;
/**
* fy_version_is_supported() - Check if supported version
*
* Check if the given YAML version is supported.
*
* @vers: The version to check, NULL means default version.
*
* Returns:
* true if version supported, false otherwise.
*/
bool
fy_version_is_supported(const struct fy_version *vers)
FY_EXPORT;
/**
* fy_version_supported_iterate() - Iterate over the supported YAML versions
*
* This method iterates over the supported YAML versions of this ibrary.
* The start of the iteration is signalled by a NULL in \*prevp.
*
* @prevp: The previous version iterator
*
* Returns:
* The next node in sequence or NULL at the end of the sequence.
*/
const struct fy_version *
fy_version_supported_iterate(void **prevp)
FY_EXPORT;
/**
* fy_shutdown() - Final cleanup before exit
*
* Some libraries *cough*libclang** need explicit cleanup calls
* at the end of program execution, even if you've never called
* any of their functions.
*
* This method will make sure it calls their cleanup functions
* so that no memory leaks are reported in valgrind etc.
*/
void
fy_shutdown(void)
FY_EXPORT;
/**
* struct fy_tag - The YAML tag structure.
*
* @handle: Handle of the tag (i.e. `"!!"`)
* @prefix: The prefix of the tag (i.e. `"tag:yaml.org,2002:"`)
* The parser fills it according to the \%TAG directives
* encountered during parsing.
*/
struct fy_tag {
const char *handle;
const char *prefix;
};
/**
* struct fy_mark - marker holding information about a location
* in a &struct fy_input
*
* @input_pos: Position of the mark (from the start of the current input)
* @line: Line position (0 index based)
* @column: Column position (0 index based)
*/
struct fy_mark {
size_t input_pos;
int line;
int column;
};
/**
* enum fy_error_type - The supported diagnostic/error types
*
* @FYET_DEBUG: Debug level (disabled if library is not compiled in debug mode)
* @FYET_INFO: Informational level
* @FYET_NOTICE: Notice level
* @FYET_WARNING: Warning level
* @FYET_ERROR: Error level - error reporting is using this level
* @FYET_MAX: Non inclusive maximum fy_error_type value
*
*/
enum fy_error_type {
FYET_DEBUG,
FYET_INFO,
FYET_NOTICE,
FYET_WARNING,
FYET_ERROR,
FYET_MAX,
};
/**
* enum fy_error_module - Module which generated the diagnostic/error
*
* @FYEM_UNKNOWN: Unknown, default if not specific
* @FYEM_ATOM: Atom module, used by atom chunking
* @FYEM_SCAN: Scanner module
* @FYEM_PARSE: Parser module
* @FYEM_DOC: Document module
* @FYEM_BUILD: Build document module (after tree is constructed)
* @FYEM_INTERNAL: Internal error/diagnostic module
* @FYEM_SYSTEM: System error/diagnostic module
* @FYEM_EMIT: Emitter module
* @FYEM_TYPESET: Prepare types module (C reflection)
* @FYEM_DECODE: Decode, serialization -> internal form module
* @FYEM_ENCODE: Encode, internal form -> serialized form module
* @FYEM_MAX: Non inclusive maximum fy_error_module value
*/
enum fy_error_module {
FYEM_UNKNOWN,
FYEM_ATOM,
FYEM_SCAN,
FYEM_PARSE,
FYEM_DOC,
FYEM_BUILD,
FYEM_INTERNAL,
FYEM_SYSTEM,
FYEM_EMIT,
FYEM_TYPESET,
FYEM_DECODE,
FYEM_ENCODE,
FYEM_MAX,
};
/* Shift amount of the default version */
#define FYPCF_DEFAULT_VERSION_SHIFT 9
/* Mask of the default version */
#define FYPCF_DEFAULT_VERSION_MASK ((1U << 5) - 1)
/* Build a default version */
#define FYPCF_DEFAULT_VERSION(x) (((unsigned int)(x) & FYPCF_DEFAULT_VERSION_MASK) << FYPCF_DEFAULT_VERSION_SHIFT)
/* Shift amount of the JSON input mode */
#define FYPCF_JSON_SHIFT 16
/* Mask of the JSON input mode */
#define FYPCF_JSON_MASK ((1U << 2) - 1)
/* Build a JSON input mode option */
#define FYPCF_JSON(x) (((unsigned int)(x) & FYPCF_JSON_MASK) << FYPCF_JSON_SHIFT)
/* guaranteed minimum depth limit for generated document */
/* the actual limit is larger depending on the platform */
#define FYPCF_GUARANTEED_MINIMUM_DEPTH_LIMIT 64
/**
* enum fy_parse_cfg_flags - Parse configuration flags
*
* These flags control the operation of the parse and the debugging
* output/error reporting via filling in the &fy_parse_cfg->flags member.
*
* @FYPCF_QUIET: Quiet, do not output any information messages
* @FYPCF_COLLECT_DIAG: Collect diagnostic/error messages
* @FYPCF_RESOLVE_DOCUMENT: When producing documents, automatically resolve them
* @FYPCF_DISABLE_MMAP_OPT: Disable mmap optimization
* @FYPCF_DISABLE_RECYCLING: Disable recycling optimization
* @FYPCF_PARSE_COMMENTS: Enable parsing of comments (experimental)
* @FYPCF_DISABLE_DEPTH_LIMIT: Disable depth limit check, use with enlarged stack
* @FYPCF_DISABLE_ACCELERATORS: Disable use of access accelerators (saves memory)
* @FYPCF_DISABLE_BUFFERING: Disable use of buffering where possible
* @FYPCF_DEFAULT_VERSION_AUTO: Automatically use the most recent version the library supports
* @FYPCF_DEFAULT_VERSION_1_1: Default version is YAML 1.1
* @FYPCF_DEFAULT_VERSION_1_2: Default version is YAML 1.2
* @FYPCF_DEFAULT_VERSION_1_3: Default version is YAML 1.3 (experimental)
* @FYPCF_SLOPPY_FLOW_INDENTATION: Allow sloppy indentation in flow mode
* @FYPCF_PREFER_RECURSIVE: Prefer recursive algorighms instead of iterative whenever possible
* @FYPCF_JSON_AUTO: Automatically enable JSON mode (when extension is .json)
* @FYPCF_JSON_NONE: Never enable JSON input mode
* @FYPCF_JSON_FORCE: Force JSON mode always
* @FYPCF_YPATH_ALIASES: Enable YPATH aliases mode
* @FYPCF_ALLOW_DUPLICATE_KEYS: Allow duplicate keys on mappings
*/
enum fy_parse_cfg_flags {
FYPCF_QUIET = FY_BIT(0),
FYPCF_COLLECT_DIAG = FY_BIT(1),
FYPCF_RESOLVE_DOCUMENT = FY_BIT(2),
FYPCF_DISABLE_MMAP_OPT = FY_BIT(3),
FYPCF_DISABLE_RECYCLING = FY_BIT(4),
FYPCF_PARSE_COMMENTS = FY_BIT(5),
FYPCF_DISABLE_DEPTH_LIMIT = FY_BIT(6),
FYPCF_DISABLE_ACCELERATORS = FY_BIT(7),
FYPCF_DISABLE_BUFFERING = FY_BIT(8),
FYPCF_DEFAULT_VERSION_AUTO = FYPCF_DEFAULT_VERSION(0),
FYPCF_DEFAULT_VERSION_1_1 = FYPCF_DEFAULT_VERSION(1),
FYPCF_DEFAULT_VERSION_1_2 = FYPCF_DEFAULT_VERSION(2),
FYPCF_DEFAULT_VERSION_1_3 = FYPCF_DEFAULT_VERSION(3),
FYPCF_SLOPPY_FLOW_INDENTATION = FY_BIT(14),
FYPCF_PREFER_RECURSIVE = FY_BIT(15),
FYPCF_JSON_AUTO = FYPCF_JSON(0),
FYPCF_JSON_NONE = FYPCF_JSON(1),
FYPCF_JSON_FORCE = FYPCF_JSON(2),
FYPCF_YPATH_ALIASES = FY_BIT(18),
FYPCF_ALLOW_DUPLICATE_KEYS = FY_BIT(19),
};
#define FYPCF_DEFAULT_PARSE (0)
#define FYPCF_DEFAULT_DOC (FYPCF_QUIET | FYPCF_DEFAULT_PARSE)
/*
* The FYPCF_DEBUG and FYPCF_COLOR flags have been removed, however
* to help with backwards compatibility we will define them as 0
* so that code can continue to compile.
*
* You will need to eventualy modify the code if you actually depended
* on the old behaviour.
*/
#define FYPCF_MODULE_SHIFT 0
#define FYPCF_MODULE_MASK 0
#define FYPCF_DEBUG_LEVEL_SHIFT 0
#define FYPCF_DEBUG_LEVEL_MASK 0
#define FYPCF_DEBUG_LEVEL(x) 0
#define FYPCF_DEBUG_DIAG_SHIFT 0
#define FYPCF_DEBUG_DIAG_MASK 0
#define FYPCF_DEBUG_DIAG_ALL 0
#define FYPCF_DEBUG_DIAG_DEFAULT 0
#define FYPCF_DEBUG_UNKNOWN 0
#define FYPCF_DEBUG_ATOM 0
#define FYPCF_DEBUG_SCAN 0
#define FYPCF_DEBUG_PARSE 0
#define FYPCF_DEBUG_DOC 0
#define FYPCF_DEBUG_BUILD 0
#define FYPCF_DEBUG_INTERNAL 0
#define FYPCF_DEBUG_SYSTEM 0
#define FYPCF_DEBUG_LEVEL_DEBUG 0
#define FYPCF_DEBUG_LEVEL_INFO 0
#define FYPCF_DEBUG_LEVEL_NOTICE 0
#define FYPCF_DEBUG_LEVEL_WARNING 0
#define FYPCF_DEBUG_LEVEL_ERROR 0
#define FYPCF_DEBUG_DIAG_SOURCE 0
#define FYPCF_DEBUG_DIAG_POSITION 0
#define FYPCF_DEBUG_DIAG_TYPE 0
#define FYPCF_DEBUG_DIAG_MODULE 0
#define FYPCF_DEBUG_ALL 0
#define FYPCF_DEBUG_DEFAULT 0
#define FYPCF_COLOR_SHIFT 0
#define FYPCF_COLOR_MASK 0
#define FYPCF_COLOR(x) 0
#define FYPCF_COLOR_AUTO 0
#define FYPCF_COLOR_NONE 0
#define FYPCF_COLOR_FORCE 0
/**
* struct fy_parse_cfg - parser configuration structure.
*
* Argument to the fy_parser_create() method which
* perform parsing of YAML files.
*
* @search_path: Search path when accessing files, seperate with ':'
* @flags: Configuration flags
* @userdata: Opaque user data pointer
* @diag: Optional diagnostic interface to use
*/
struct fy_parse_cfg {
const char *search_path;
enum fy_parse_cfg_flags flags;
void *userdata;
struct fy_diag *diag;
};
/**
* enum fy_event_type - Event types
*
* @FYET_NONE: No event
* @FYET_STREAM_START: Stream start event
* @FYET_STREAM_END: Stream end event
* @FYET_DOCUMENT_START: Document start event
* @FYET_DOCUMENT_END: Document end event
* @FYET_MAPPING_START: YAML mapping start event
* @FYET_MAPPING_END: YAML mapping end event
* @FYET_SEQUENCE_START: YAML sequence start event
* @FYET_SEQUENCE_END: YAML sequence end event
* @FYET_SCALAR: YAML scalar event
* @FYET_ALIAS: YAML alias event
*/
enum fy_event_type {
FYET_NONE,
FYET_STREAM_START,
FYET_STREAM_END,
FYET_DOCUMENT_START,
FYET_DOCUMENT_END,
FYET_MAPPING_START,
FYET_MAPPING_END,
FYET_SEQUENCE_START,
FYET_SEQUENCE_END,
FYET_SCALAR,
FYET_ALIAS,
};
/**
* fy_event_type_get_text() - Return text of an event type
*
* @type: The event type to get text from
*
* Returns:
* A pointer to a text, i.e for FYET_SCALAR "=VAL".
*/
const char *
fy_event_type_get_text(enum fy_event_type type)
FY_EXPORT;
/**
* enum fy_scalar_style - Scalar styles supported by the parser/emitter
*
* @FYSS_ANY: Any scalar style, not generated by the parser.
* Lets the emitter to choose
* @FYSS_PLAIN: Plain scalar style
* @FYSS_SINGLE_QUOTED: Single quoted style
* @FYSS_DOUBLE_QUOTED: Double quoted style
* @FYSS_LITERAL: YAML literal block style
* @FYSS_FOLDED: YAML folded block style
* @FYSS_MAX: marks end of scalar styles
*/
enum fy_scalar_style {
FYSS_ANY = -1,
FYSS_PLAIN,
FYSS_SINGLE_QUOTED,
FYSS_DOUBLE_QUOTED,
FYSS_LITERAL,
FYSS_FOLDED,
FYSS_MAX,
};
/**
* struct fy_event_stream_start_data - stream start event data
*
* @stream_start: The token that started the stream
*/
struct fy_event_stream_start_data {
struct fy_token *stream_start;
};
/**
* struct fy_event_stream_end_data - stream end event data
*
* @stream_end: The token that ended the stream
*/
struct fy_event_stream_end_data {
struct fy_token *stream_end;
};
/**
* struct fy_event_document_start_data - doument start event data
*
* @document_start: The token that started the document, or NULL if
* the document was implicitly started.
* @document_state: The state of the document (i.e. information about
* the YAML version and configured tags)
* @implicit: True if the document started implicitly
*/
struct fy_event_document_start_data {
struct fy_token *document_start;
struct fy_document_state *document_state;
bool implicit;
};
/**
* struct fy_event_document_end_data - doument end event data
*
* @document_end: The token that ended the document, or NULL if the
* document was implicitly ended
* @implicit: True if the document ended implicitly
*/
struct fy_event_document_end_data {
struct fy_token *document_end;
bool implicit;
};
/**
* struct fy_event_alias_data - alias event data
*
* @anchor: The anchor token definining this alias.
*/
struct fy_event_alias_data {
struct fy_token *anchor;
};
/**
* struct fy_event_scalar_data - scalar event data
*
* @anchor: anchor token or NULL
* @tag: tag token or NULL
* @value: scalar value token (cannot be NULL)
* @tag_implicit: true if the tag was implicit or explicit
*/
struct fy_event_scalar_data {
struct fy_token *anchor;
struct fy_token *tag;
struct fy_token *value;
bool tag_implicit;
};
/**
* struct fy_event_sequence_start_data - sequence start event data
*
* @anchor: anchor token or NULL
* @tag: tag token or NULL
* @sequence_start: sequence start value token or NULL if the sequence
* was started implicitly
*/
struct fy_event_sequence_start_data {
struct fy_token *anchor;
struct fy_token *tag;
struct fy_token *sequence_start;
};
/**
* struct fy_event_sequence_end_data - sequence end event data
*
* @sequence_end: The token that ended the sequence, or NULL if
* the sequence was implicitly ended
*/
struct fy_event_sequence_end_data {
struct fy_token *sequence_end;
};
/**
* struct fy_event_mapping_start_data - mapping start event data
*
* @anchor: anchor token or NULL
* @tag: tag token or NULL
* @mapping_start: mapping start value token or NULL if the mapping
* was started implicitly
*/
struct fy_event_mapping_start_data {
struct fy_token *anchor;
struct fy_token *tag;
struct fy_token *mapping_start;
};
/**
* struct fy_event_mapping_end_data - mapping end event data
*
* @mapping_end: The token that ended the mapping, or NULL if
* the mapping was implicitly ended
*/
struct fy_event_mapping_end_data {
struct fy_token *mapping_end;
};
/**
* struct fy_event - Event generated by the parser
*
* This structure is generated by the parser by each call
* to fy_parser_parse() and release by fy_parser_event_free()
*
* @type: Type of the event, see &enum fy_event_type
*
* @stream_start: Stream start information, it is valid when
* &fy_event->type is &enum FYET_STREAM_START
* @stream_end: Stream end information, it is valid when
* &fy_event->type is &enum FYET_STREAM_END
* @document_start: Document start information, it is valid when
* &fy_event->type is &enum FYET_DOCUMENT_START
* @document_end: Document end information, it is valid when
* &fy_event->type is &enum FYET_DOCUMENT_END
* @alias: Alias information, it is valid when
* &fy_event->type is &enum FYET_ALIAS
* @scalar: Scalar information, it is valid when
* &fy_event->type is &enum FYET_SCALAR
* @sequence_start: Sequence start information, it is valid when
* &fy_event->type is &enum FYET_SEQUENCE_START
* @sequence_end: Sequence end information, it is valid when
* &fy_event->type is &enum FYET_SEQUENCE_END
* @mapping_start: Mapping start information, it is valid when
* &fy_event->type is &enum FYET_MAPPING_START
* @mapping_end: Mapping end information, it is valid when
* &fy_event->type is &enum FYET_MAPPING_END
*/
struct fy_event {
enum fy_event_type type;
/* anonymous union */
union {
struct fy_event_stream_start_data stream_start;
struct fy_event_stream_end_data stream_end;
struct fy_event_document_start_data document_start;
struct fy_event_document_end_data document_end;
struct fy_event_alias_data alias;
struct fy_event_scalar_data scalar;
struct fy_event_sequence_start_data sequence_start;
struct fy_event_sequence_end_data sequence_end;
struct fy_event_mapping_start_data mapping_start;
struct fy_event_mapping_end_data mapping_end;
};
};
/**
* enum fy_event_part - Select part of the event
*
* @FYEP_VALUE: The value of the event (the main token)
* @FYEP_TAG: The tag of the event
* @FYEP_ANCHOR: The anchor of the event
*/
enum fy_event_part {
FYEP_VALUE,
FYEP_TAG,
FYEP_ANCHOR,
};
/**
* fy_event_get_type() - Get the event's type
*
* Return the type of the event
*
* @fye: The event
*
* Returns:
* The event type, or FYET_NONE when the event is invalid
*/
static inline enum fy_event_type
fy_event_get_type(const struct fy_event *fye)
{
return fye ? fye->type : FYET_NONE;
}
/**
* fy_event_data() - Get a pointer to the event data
*
* Some languages *cough*golang*cough* really don't like
* unions, and anonymous unions in particular.
*
* You should not have to use this in other language bindings.
*
* @fye: The event
*
* Returns:
* A pointer to the event data structure, or NULL if the
* event is invalid
*/
static inline void *
fy_event_data(struct fy_event *fye)
{
if (!fye)
return NULL;
/* note that the unions should all be laid out
* at the same address, but play it straight and
* hope the optimizer will figure this is all
* the same...
*/
switch (fye->type) {
case FYET_STREAM_START:
return &fye->stream_start;
case FYET_STREAM_END:
return &fye->stream_end;
case FYET_DOCUMENT_START:
return &fye->document_start;
case FYET_DOCUMENT_END:
return &fye->document_end;
case FYET_ALIAS:
return &fye->alias;
case FYET_SCALAR:
return &fye->scalar;
case FYET_SEQUENCE_START:
return &fye->sequence_start;
case FYET_SEQUENCE_END:
return &fye->sequence_end;
case FYET_MAPPING_START:
return &fye->mapping_start;
case FYET_MAPPING_END:
return &fye->mapping_end;
default:
break;
}
return NULL;
}
/**
* fy_library_version() - Return the library version string
*
* Returns:
* A pointer to a version string of the form
* <MAJOR>.<MINOR>[[.<PATCH>][-EXTRA-VERSION-INFO]]
*/
const char *
fy_library_version(void)
FY_EXPORT;
/**
* fy_string_to_error_type() - Return the error type from a string
*
* @str: The string to convert to an error type
*
* Returns:
* The error type if greater or equal to zero, FYET_MAX otherwise
*/
enum fy_error_type fy_string_to_error_type(const char *str)
FY_EXPORT;
/**
* fy_error_type_to_string() - Convert an error type to string
*
* @type: The error type to convert
*
* Returns:
* The string value of the error type or the empty string "" on error
*/
const char *fy_error_type_to_string(enum fy_error_type type)
FY_EXPORT;
/**
* fy_string_to_error_module() - Return the error module from a string
*
* @str: The string to convert to an error module
*
* Returns:
* The error type if greater or equal to zero, FYEM_MAX otherwise
*/
enum fy_error_module fy_string_to_error_module(const char *str)
FY_EXPORT;
/**
* fy_error_module_to_string() - Convert an error module to string
*
* @module: The error module to convert
*
* Returns:
* The string value of the error module or the empty string "" on error
*/
const char *fy_error_module_to_string(enum fy_error_module module)
FY_EXPORT;
/**
* fy_event_is_implicit() - Check whether the given event is an implicit one
*
* @fye: A pointer to a &struct fy_event to check.
*
* Returns:
* true if the event is an implicit one.
*/
bool
fy_event_is_implicit(struct fy_event *fye)
FY_EXPORT;
/**
* fy_document_event_is_implicit() - Check whether the given document event is an implicit one
*
* @fye: A pointer to a &struct fy_event to check.
* It must be either a document start or document end event.
*
* Returns:
* true if the event is an implicit one.
*/
bool
fy_document_event_is_implicit(const struct fy_event *fye)
FY_EXPORT;
/**
* fy_parser_create() - Create a parser.
*
* Creates a parser with its configuration @cfg
* The parser may be destroyed by a corresponding call to
* fy_parser_destroy().
*
* @cfg: The configuration for the parser
*
* Returns:
* A pointer to the parser or NULL in case of an error.
*/
struct fy_parser *
fy_parser_create(const struct fy_parse_cfg *cfg)
FY_EXPORT;
/**
* fy_parser_destroy() - Destroy the given parser
*
* Destroy a parser created earlier via fy_parser_create().
*
* @fyp: The parser to destroy
*/
void
fy_parser_destroy(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_parser_get_cfg() - Get the configuration of a parser
*
* @fyp: The parser
*
* Returns:
* The configuration of the parser
*/
const struct fy_parse_cfg *
fy_parser_get_cfg(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_parser_get_diag() - Get the diagnostic object of a parser
*
* Return a pointer to the diagnostic object of a parser object.
* Note that the returned diag object has a reference taken so
* you should fy_diag_unref() it when you're done with it.
*
* @fyp: The parser to get the diagnostic object
*
* Returns:
* A pointer to a ref'ed diagnostic object or NULL in case of an
* error.
*/
struct fy_diag *
fy_parser_get_diag(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_parser_set_diag() - Set the diagnostic object of a parser
*
* Replace the parser's current diagnostic object with the one
* given as an argument. The previous diagnostic object will be
* unref'ed (and freed if its reference gets to 0).
* Also note that the diag argument shall take a reference too.
*
* @fyp: The parser to replace the diagnostic object
* @diag: The parser's new diagnostic object, NULL for default
*
* Returns:
* 0 if everything OK, -1 otherwise
*/
int
fy_parser_set_diag(struct fy_parser *fyp, struct fy_diag *diag)
FY_EXPORT;
/**
* fy_parser_reset() - Reset a parser completely
*
* Completely reset a parser, including after an error
* that caused a parser error to be emitted.
*
* @fyp: The parser to reset
*
* Returns:
* 0 if the reset was successful, -1 otherwise
*/
int
fy_parser_reset(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_parser_set_input_file() - Set the parser to process the given file
*
* Point the parser to the given @file for processing. The file
* is located by honoring the search path of the configuration set
* by the earlier call to fy_parser_create().
* While the parser is in use the file will must be available.
*
* @fyp: The parser
* @file: The file to parse.
*
* Returns:
* zero on success, -1 on error
*/
int
fy_parser_set_input_file(struct fy_parser *fyp, const char *file)
FY_EXPORT;
/**
* fy_parser_set_string() - Set the parser to process the given string.
*
* Point the parser to the given (NULL terminated) string. Note that
* while the parser is active the string must not go out of scope.
*
* @fyp: The parser
* @str: The YAML string to parse.
* @len: The length of the string (or -1 if '\0' terminated)
*
* Returns:
* zero on success, -1 on error
*/
int
fy_parser_set_string(struct fy_parser *fyp, const char *str, size_t len)
FY_EXPORT;
/**
* fy_parser_set_malloc_string() - Set the parser to process the given malloced string.
*
* Point the parser to the given (possible NULL terminated) string. Note that
* the string is expected to be allocated via malloc(3) and ownership is transferred
* to the created input. When the input is free'ed the memory will be automatically
* freed.
*
* In case of an error the string is not freed.
*
* @fyp: The parser
* @str: The YAML string to parse (allocated).
* @len: The length of the string (or -1 if '\0' terminated)
*
* Returns:
* zero on success, -1 on error
*/
int
fy_parser_set_malloc_string(struct fy_parser *fyp, char *str, size_t len)
FY_EXPORT;
/**
* fy_parser_set_input_fp() - Set the parser to process the given file
*
* Point the parser to use @fp for processing.
*
* @fyp: The parser
* @name: The label of the stream
* @fp: The FILE pointer, it must be open in read mode.
*
* Returns:
* zero on success, -1 on error
*/
int
fy_parser_set_input_fp(struct fy_parser *fyp, const char *name, FILE *fp)
FY_EXPORT;
/**
* fy_parser_set_input_callback() - Set the parser to process via a callback
*
* Point the parser to use a callback for input.
*
* @fyp: The parser
* @user: The user data pointer
* @callback: The callback method to request data with
*
* Returns:
* zero on success, -1 on error
*/
int fy_parser_set_input_callback(struct fy_parser *fyp, void *user,
ssize_t (*callback)(void *user, void *buf, size_t count))
FY_EXPORT;
/**
* fy_parser_set_input_fd() - Set the parser to process the given file descriptor
*
* Point the parser to use @fd for processing.
*
* @fyp: The parser
* @fd: The file descriptor to use
*
* Returns:
* zero on success, -1 on error
*/
int
fy_parser_set_input_fd(struct fy_parser *fyp, int fd)
FY_EXPORT;
/**
* fy_parser_parse() - Parse and return the next event.
*
* Each call to fy_parser_parse() returns the next event from
* the configured input of the parser, or NULL at the end of
* the stream. The returned event must be released via
* a matching call to fy_parser_event_free().
*
* @fyp: The parser
*
* Returns:
* The next event in the stream or NULL.
*/
struct fy_event *
fy_parser_parse(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_parser_parse_peek() - Parse and peek at the next event.
*
* It will return the next event that a call to fy_parser_parse
* would generate, but as read-only.
*
* You must not free this event.
*
* @fyp: The parser
*
* Returns:
* A peek at the next event in the stream or NULL.
*/
const struct fy_event *
fy_parser_parse_peek(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_parser_skip() - Skip the current scalar/collection
*
* Skips the current scalar or collection.
*
* @fyp: The parser
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_parser_skip(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_parser_count_sequence_items() - Count the sequence items
*
* Counts the number of sequence items. Parser must already
* be in a sequence state.
* Note that this uses backtracking so it might not be very
* efficient.
*
* @fyp: The parser
*
* Returns:
* The number of sequence items on success, -1 on error
* Note if the number of items exceeds INT_MAX, INT_MAX will
* be returned.
*/
int
fy_parser_count_sequence_items(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_parser_count_mapping_items() - Count the mapping items
*
* Counts the number of mapping items. Parser must already
* be in a mapping state.
* Note that this uses backtracking so it might not be very
* efficient.
*
* @fyp: The parser
*
* Returns:
* The number of mapping items on success, -1 on error
* Note if the number of items exceeds INT_MAX, INT_MAX will
* be returned.
*/
int
fy_parser_count_mapping_items(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_parser_event_free() - Free an event
*
* Free a previously returned event from fy_parser_parse().
*
* @fyp: The parser
* @fye: The event to free (may be NULL)
*/
void
fy_parser_event_free(struct fy_parser *fyp, struct fy_event *fye)
FY_EXPORT;
/**
* fy_parser_get_stream_error() - Check the parser for stream errors
*
* @fyp: The parser
*
* Returns:
* true in case of a stream error, false otherwise.
*/
bool
fy_parser_get_stream_error(struct fy_parser *fyp)
FY_EXPORT;
enum fy_parser_mode {
fypm_invalid = -1,
fypm_none, /* scanning for mode, not committed yet */
fypm_yaml_1_1,
fypm_yaml_1_2,
fypm_yaml_1_3, /* experimental */
fypm_json,
};
static inline bool
fy_parser_mode_is_yaml(enum fy_parser_mode mode)
{
return mode >= fypm_yaml_1_1 && mode <= fypm_yaml_1_3;
}
/**
* fy_parser_get_mode() - Get the parser mode
*
* Retrieve the current mode of the parser, which indicates the YAML version
* or format being parsed (YAML 1.1, 1.2, 1.3, or JSON).
*
* @fyp: The parser
*
* Returns:
* The parser mode
*/
enum fy_parser_mode
fy_parser_get_mode(struct fy_parser *fyp)
FY_EXPORT;
static inline bool
fy_parser_is_in_yaml_mode(struct fy_parser *fyp)
{
return fy_parser_mode_is_yaml(fy_parser_get_mode(fyp));
}
static inline bool
fy_parser_is_in_json_mode(struct fy_parser *fyp)
{
return fy_parser_get_mode(fyp) == fypm_json;
}
/**
* fy_parser_vlog() - Log using the parsers diagnostics printf style (va_arg)
*
* Output a log on the parser diagnostic output
*
* @fyp: The parser
* @type: The error type
* @fmt: The printf format string
* @ap: The argument list
*/
void
fy_parser_vlog(struct fy_parser *fyp, enum fy_error_type type, const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_parser_log() - Log using the parsers diagnostics printf style
*
* Output a report on the parser's diagnostics
*
* @fyp: The parser
* @type: The error type
* @fmt: The printf format string
* @...: The extra arguments
*/
void
fy_parser_log(struct fy_parser *fyp, enum fy_error_type type, const char *fmt, ...)
FY_FORMAT(printf, 3, 4)
FY_EXPORT;
#ifndef NDEBUG
#define fy_parser_debug(_fyp, _fmt, ...) \
fy_parser_log((_fyp), FYET_DEBUG, (_fmt) , ## __VA_ARGS__)
#else
#define fy_parser_debug(_fyp, _fmt, ...) \
do { } while(0)
#endif
#define fy_parser_info(_fyp, _fmt, ...) \
fy_parser_log((_fyp), FYET_INFO, (_fmt) , ## __VA_ARGS__)
#define fy_parser_notice(_fyp, _fmt, ...) \
fy_parser_log((_fyp), FYET_NOTICE, (_fmt) , ## __VA_ARGS__)
#define fy_parser_warning(_fyp, _fmt, ...) \
fy_parser_log((_fyp), FYET_WARNING, (_fmt) , ## __VA_ARGS__)
#define fy_parser_error(_fyp, _fmt, ...) \
fy_parser_log((_fyp), FYET_ERROR, (_fmt) , ## __VA_ARGS__)
/**
* fy_parser_vreport() - Report using the parsers diagnostics printf style and mark token (va_arg)
*
* Output a report on the parser and indicate the token's position
*
* @fyp: The parser
* @type: The error type
* @fyt: The token
* @fmt: The printf format string
* @ap: The argument list
*/
void
fy_parser_vreport(struct fy_parser *fyp, enum fy_error_type type, struct fy_token *fyt,
const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_parser_report() - Report using the parsers diagnostics printf style and mark token
*
* Output a report on the parser and indicate the token's position
*
* @fyp: The parser
* @type: The error type
* @fyt: The token
* @fmt: The printf format string
* @...: The extra arguments
*/
void
fy_parser_report(struct fy_parser *fyp, enum fy_error_type type, struct fy_token *fyt,
const char *fmt, ...)
FY_FORMAT(printf, 4, 5)
FY_EXPORT;
#ifndef NDEBUG
#define fy_parser_report_debug(_fyp, _fyt, _fmt, ...) \
fy_parser_report((_fyp), FYET_DEBUG, (_fyt), (_fmt) , ## __VA_ARGS__)
#else
#define fy_parser_report_debug(_fyp, _fyt, _fmt, ...) \
do { } while(0)
#endif
#define fy_parser_report_info(_fyp, _fyt, _fmt, ...) \
fy_parser_report((_fyp), FYET_INFO, (_fyt), (_fmt) , ## __VA_ARGS__)
#define fy_parser_report_notice(_fyp, _fyt, _fmt, ...) \
fy_parser_report((_fyp), FYET_NOTICE, (_fyt), (_fmt) , ## __VA_ARGS__)
#define fy_parser_report_warning(_fyp, _fyt, _fmt, ...) \
fy_parser_report((_fyp), FYET_WARNING, (_fyt), (_fmt) , ## __VA_ARGS__)
#define fy_parser_report_error(_fyp, _fyt, _fmt, ...) \
fy_parser_report((_fyp), FYET_ERROR, (_fyt), (_fmt) , ## __VA_ARGS__)
/**
* fy_token_scalar_style() - Get the style of a scalar token
*
* @fyt: The scalar token to get it's style. Note that a NULL
* token is a &enum FYSS_PLAIN.
*
* Returns:
* The scalar style of the token, or FYSS_PLAIN on each other case
*/
enum fy_scalar_style
fy_token_scalar_style(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_token_scalar_is_null() - Test whether the scalar is null (content)
*
* @fyt: The scalar token to check for NULLity.
*
* Note that this is different than null of the YAML type system.
* It is null as in null content. It is also different than an
* empty scalar.
*
* Returns:
* true if is a null scalar, false otherwise
*/
bool
fy_token_scalar_is_null(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_token_get_text() - Get text (and length of it) of a token
*
* This method will return a pointer to the text of a token
* along with the length of it. Note that this text is *not*
* NULL terminated. If you need a NULL terminated pointer
* use fy_token_get_text0().
*
* In case that the token is 'simple' enough (i.e. a plain scalar)
* or something similar the returned pointer is a direct pointer
* to the space of the input that contains the token.
*
* That means that the pointer is *not* guaranteed to be valid
* after the parser is destroyed.
*
* If the token is 'complex' enough, then space shall be allocated,
* filled and returned.
*
* Note that the concept of 'simple' and 'complex' is vague, and
* that's on purpose.
*
* @fyt: The token out of which the text pointer will be returned.
* @lenp: Pointer to a variable that will hold the returned length
*
* Returns:
* A pointer to the text representation of the token, while
* @lenp will be assigned the character length of said representation.
* NULL in case of an error.
*/
const char *
fy_token_get_text(struct fy_token *fyt, size_t *lenp)
FY_EXPORT;
/**
* fy_token_get_text0() - Get zero terminated text of a token
*
* This method will return a pointer to the text of a token
* which is zero terminated. It will allocate memory to hold
* it in the token structure so try to use fy_token_get_text()
* instead if possible.
*
* @fyt: The token out of which the text pointer will be returned.
*
* Returns:
* A pointer to a zero terminated text representation of the token.
* NULL in case of an error.
*/
const char *
fy_token_get_text0(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_token_get_text_length() - Get length of the text of a token
*
* This method will return the length of the text representation
* of a token.
*
* @fyt: The token
*
* Returns:
* The size of the text representation of a token, -1 in case of an error.
* Note that the NULL token will return a length of zero.
*/
size_t
fy_token_get_text_length(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_token_get_utf8_length() - Get length of the text of a token
*
* This method will return the length of the text representation
* of a token as a utf8 string.
*
* @fyt: The token
*
* Returns:
* The size of the utf8 text representation of a token, -1 in case of an error.
* Note that the NULL token will return a length of zero.
*/
size_t
fy_token_get_utf8_length(struct fy_token *fyt)
FY_EXPORT;
/**
* enum fy_comment_placement - Comment placement relative to token
*
* @fycp_top: Comment on top of token
* @fycp_right: Comment to the right of the token
* @fycp_bottom: Comment to the bottom of the token
*/
enum fy_comment_placement {
fycp_top,
fycp_right,
fycp_bottom
};
#define fycp_max (fycp_bottom + 1)
/**
* fy_token_get_comment() - Get zero terminated comment of a token
*
* @fyt: The token out of which the comment text will be returned.
* @buf: The buffer to be filled with the contents of the token
* @maxsz: The maximum size of the comment buffer
* @which: The comment placement
*
* Returns:
* A pointer to a zero terminated text representation of the token comment.
* NULL in case of an error or if the token has no comment.
*/
const char *
fy_token_get_comment(struct fy_token *fyt, char *buf, size_t maxsz,
enum fy_comment_placement which)
FY_EXPORT;
/**
* struct fy_iter_chunk - An iteration chunk
*
* @str: Pointer to the start of the chunk
* @len: The size of the chunk
*
* The iterator produces a stream of chunks which
* cover the whole object.
*/
struct fy_iter_chunk {
const char *str;
size_t len;
};
/**
* fy_token_iter_create() - Create a token iterator
*
* Create an iterator for operating on the given token, or
* a generic iterator for use with fy_token_iter_start().
* The iterator must be destroyed with a matching call to
* fy_token_iter_destroy().
*
* @fyt: The token to iterate, or NULL.
*
* Returns:
* A pointer to the newly created iterator, or NULL in case of
* an error.
*/
struct fy_token_iter *
fy_token_iter_create(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_token_iter_destroy() - Destroy the iterator
*
* Destroy the iterator created by fy_token_iter_create().
*
* @iter: The iterator to destroy.
*/
void
fy_token_iter_destroy(struct fy_token_iter *iter)
FY_EXPORT;
/**
* fy_token_iter_start() - Start iterating over the contents of a token
*
* Prepare an iterator for operating on the given token.
* The iterator must be created via a previous call to fy_token_iter_create()
* for user level API access.
*
* @fyt: The token to iterate over
* @iter: The iterator to prepare.
*/
void
fy_token_iter_start(struct fy_token *fyt, struct fy_token_iter *iter)
FY_EXPORT;
/**
* fy_token_iter_finish() - Stop iterating over the contents of a token
*
* Stop the iteration operation.
*
* @iter: The iterator.
*/
void
fy_token_iter_finish(struct fy_token_iter *iter)
FY_EXPORT;
/**
* fy_token_iter_peek_chunk() - Peek at the next iterator chunk
*
* Peek at the next iterator chunk
*
* @iter: The iterator.
*
* Returns:
* A pointer to the next iterator chunk, or NULL in case there's
* no other.
*/
const struct fy_iter_chunk *
fy_token_iter_peek_chunk(struct fy_token_iter *iter)
FY_EXPORT;
/**
* fy_token_iter_chunk_next() - Get next iterator chunk
*
* Get the next iterator chunk in sequence,
*
* @iter: The iterator.
* @curr: The current chunk, or NULL for the first one.
* @errp: Pointer to an error return value or NULL
*
* Returns:
* A pointer to the next iterator chunk, or NULL in case there's
* no other. When the return value is NULL, the errp variable
* will be filled with 0 for normal end, or -1 in case of an error.
*/
const struct fy_iter_chunk *
fy_token_iter_chunk_next(struct fy_token_iter *iter,
const struct fy_iter_chunk *curr, int *errp)
FY_EXPORT;
/**
* fy_token_iter_advance() - Advance the iterator position
*
* Advance the read pointer of the iterator.
* Note that mixing calls of this with any call of fy_token_iter_ungetc() /
* fy_token_iter_utf8_unget() in a single iterator sequence leads
* to undefined behavior.
*
* @iter: The iterator.
* @len: Number of bytes to advance the iterator position
*/
void
fy_token_iter_advance(struct fy_token_iter *iter, size_t len)
FY_EXPORT;
/**
* fy_token_iter_read() - Read a block from an iterator
*
* Read a block from an iterator. Note than mixing calls of this
* and any of the ungetc methods leads to undefined behavior.
*
* @iter: The iterator.
* @buf: Pointer to a block of memory to receive the data. Must be at
* least count bytes long.
* @count: Amount of bytes to read.
*
* Returns:
* The amount of data read, or -1 in case of an error.
*/
ssize_t
fy_token_iter_read(struct fy_token_iter *iter, void *buf, size_t count)
FY_EXPORT;
/**
* fy_token_iter_getc() - Get a single character from an iterator
*
* Reads a single character from an iterator. If the iterator is
* finished, it will return -1. If any calls to ungetc have pushed
* a character in the iterator it shall return that.
*
* @iter: The iterator.
*
* Returns:
* The next character in the iterator, or -1 in case of an error, or
* end of stream.
*/
int
fy_token_iter_getc(struct fy_token_iter *iter)
FY_EXPORT;
/**
* fy_token_iter_ungetc() - Ungets a single character from an iterator
*
* Pushes back a single character to an iterator stream. It will be
* returned in subsequent calls of fy_token_iter_getc(). Currently
* only a single character is allowed to be pushed back, and any
* further calls to ungetc will return an error.
*
* @iter: The iterator.
* @c: The character to push back, or -1 to reset the pushback buffer.
*
* Returns:
* The pushed back character given as argument, or -1 in case of an error.
* If the pushed back character was -1, then 0 will be returned.
*/
int
fy_token_iter_ungetc(struct fy_token_iter *iter, int c)
FY_EXPORT;
/**
* fy_token_iter_peekc() - Peeks at single character from an iterator
*
* Peeks at the next character to get from an iterator. If the iterator is
* finished, it will return -1. If any calls to ungetc have pushed
* a character in the iterator it shall return that. The character is not
* removed from the iterator stream.
*
* @iter: The iterator.
*
* Returns:
* The next character in the iterator, or -1 in case of an error, or end
* of stream.
*/
int
fy_token_iter_peekc(struct fy_token_iter *iter)
FY_EXPORT;
/**
* fy_token_iter_utf8_get() - Get a single utf8 character from an iterator
*
* Reads a single utf8 character from an iterator. If the iterator is
* finished, it will return -1. If any calls to ungetc have pushed
* a character in the iterator it shall return that.
*
* @iter: The iterator.
*
* Returns:
* The next utf8 character in the iterator, or -1 in case of an error, or end
* of stream.
*/
int
fy_token_iter_utf8_get(struct fy_token_iter *iter)
FY_EXPORT;
/**
* fy_token_iter_utf8_unget() - Ungets a single utf8 character from an iterator
*
* Pushes back a single utf8 character to an iterator stream. It will be
* returned in subsequent calls of fy_token_iter_utf8_getc(). Currently
* only a single character is allowed to be pushed back, and any
* further calls to ungetc will return an error.
*
* @iter: The iterator.
* @c: The character to push back, or -1 to reset the pushback buffer.
*
* Returns:
* The pushed back utf8 character given as argument, or -1 in case of an error.
* If the pushed back utf8 character was -1, then 0 will be returned.
*/
int
fy_token_iter_utf8_unget(struct fy_token_iter *iter, int c)
FY_EXPORT;
/**
* fy_token_iter_utf8_peek() - Peeks at single utf8 character from an iterator
*
* Peeks at the next utf8 character to get from an iterator. If the iterator is
* finished, it will return -1. If any calls to ungetc have pushed
* a character in the iterator it shall return that. The character is not
* removed from the iterator stream.
*
* @iter: The iterator.
*
* Returns:
* The next utf8 character in the iterator, or -1 in case of an error, or end
* of stream.
*/
int
fy_token_iter_utf8_peek(struct fy_token_iter *iter)
FY_EXPORT;
/**
* fy_parse_load_document() - Parse the next document from the parser stream
*
* This method performs parsing on a parser stream and returns the next
* document. This means that for a compound document with multiple
* documents, each call will return the next document.
*
* @fyp: The parser
*
* Returns:
* The next document from the parser stream.
*/
struct fy_document *
fy_parse_load_document(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_parse_document_destroy() - Destroy a document created by fy_parse_load_document()
*
* @fyp: The parser
* @fyd: The document to destroy
*/
void
fy_parse_document_destroy(struct fy_parser *fyp, struct fy_document *fyd)
FY_EXPORT;
/**
* fy_document_resolve() - Resolve anchors and merge keys
*
* This method performs resolution of the given document,
* by replacing references to anchors with their contents
* and handling merge keys (<<)
*
* @fyd: The document to resolve
*
* Returns:
* zero on success, -1 on error
*/
int
fy_document_resolve(struct fy_document *fyd)
FY_EXPORT;
/**
* fy_document_has_directives() - Document directive check
*
* Checks whether the given document has any directives, i.e.
* %TAG or %VERSION.
*
* @fyd: The document to check for directives existence
*
* Returns:
* true if directives exist, false if not
*/
bool
fy_document_has_directives(const struct fy_document *fyd)
FY_EXPORT;
/**
* fy_document_has_explicit_document_start() - Explicit document start check
*
* Checks whether the given document has an explicit document start marker,
* i.e. ---
*
* @fyd: The document to check for explicit start marker
*
* Returns:
* true if document has an explicit document start marker, false if not
*/
bool
fy_document_has_explicit_document_start(const struct fy_document *fyd)
FY_EXPORT;
/**
* fy_document_has_explicit_document_end() - Explicit document end check
*
* Checks whether the given document has an explicit document end marker,
* i.e. ...
*
* @fyd: The document to check for explicit end marker
*
* Returns:
* true if document has an explicit document end marker, false if not
*/
bool
fy_document_has_explicit_document_end(const struct fy_document *fyd)
FY_EXPORT;
/**
* fy_node_document() - Retreive the document the node belong to
*
* Returns the document of the node; note that while the node may not
* be reachable via a path expression, it may still be member of a
* document.
*
* @fyn: The node to retreive it's document
*
* Returns:
* The document of the node, or NULL in case of an error, or
* when the node has no document attached.
*/
struct fy_document *
fy_node_document(struct fy_node *fyn)
FY_EXPORT;
/**
* enum fy_emitter_write_type - Type of the emitted output
*
* Describes the kind of emitted output, which makes it
* possible to colorize the output, or do some other content related
* filtering.
*
* @fyewt_document_indicator: Output chunk is a document indicator
* @fyewt_tag_directive: Output chunk is a tag directive
* @fyewt_version_directive: Output chunk is a version directive
* @fyewt_indent: Output chunk is a document indicator
* @fyewt_indicator: Output chunk is an indicator
* @fyewt_whitespace: Output chunk is white space
* @fyewt_plain_scalar: Output chunk is a plain scalar
* @fyewt_single_quoted_scalar: Output chunk is a single quoted scalar
* @fyewt_double_quoted_scalar: Output chunk is a double quoted scalar
* @fyewt_literal_scalar: Output chunk is a literal block scalar
* @fyewt_folded_scalar: Output chunk is a folded block scalar
* @fyewt_anchor: Output chunk is an anchor
* @fyewt_tag: Output chunk is a tag
* @fyewt_linebreak: Output chunk is a linebreak
* @fyewt_alias: Output chunk is an alias
* @fyewt_terminating_zero: Output chunk is a terminating zero
* @fyewt_plain_scalar_key: Output chunk is an plain scalar key
* @fyewt_single_quoted_scalar_key: Output chunk is an single quoted scalar key
* @fyewt_double_quoted_scalar_key: Output chunk is an double quoted scalar key
* @fyewt_comment: Output chunk is a comment
* @fyewt_indicator_question_mark: ? indicator
* @fyewt_indicator_colon: : indicator
* @fyewt_indicator_dash: - indicator
* @fyewt_indicator_left_bracket: [ indicator
* @fyewt_indicator_right_bracket: ] indicator
* @fyewt_indicator_left_brace: { indicator
* @fyewt_indicator_right_brace: } indicator
* @fyewt_indicator_comma: , indicator
* @fyewt_indicator_bar: | indicator
* @fyewt_indicator_greater: > indicator
* @fyewt_indicator_single_quote_start: ' indicator
* @fyewt_indicator_single_quote_end: ' indicator
* @fyewt_indicator_double_quote_start: " indicator
* @fyewt_indicator_double_quote_end: " indicator
* @fyewt_indicator_ambersand: & indicator
* @fyewt_indicator_star: * indicator
* @fyewt_indicator_chomp: chomp indicator (- or +)
* @fyewt_indicator_explicit_indent: explicit indent indicator (0-9)
*/
enum fy_emitter_write_type {
fyewt_document_indicator,
fyewt_tag_directive,
fyewt_version_directive,
fyewt_indent,
fyewt_indicator,
fyewt_whitespace,
fyewt_plain_scalar,
fyewt_single_quoted_scalar,
fyewt_double_quoted_scalar,
fyewt_literal_scalar,
fyewt_folded_scalar,
fyewt_anchor,
fyewt_tag,
fyewt_linebreak,
fyewt_alias,
fyewt_terminating_zero,
fyewt_plain_scalar_key,
fyewt_single_quoted_scalar_key,
fyewt_double_quoted_scalar_key,
fyewt_comment,
/* extended indicators */
fyewt_indicator_question_mark,
fyewt_indicator_colon,
fyewt_indicator_dash,
fyewt_indicator_left_bracket,
fyewt_indicator_right_bracket,
fyewt_indicator_left_brace,
fyewt_indicator_right_brace,
fyewt_indicator_comma,
fyewt_indicator_bar,
fyewt_indicator_greater,
fyewt_indicator_single_quote_start,
fyewt_indicator_single_quote_end,
fyewt_indicator_double_quote_start,
fyewt_indicator_double_quote_end,
fyewt_indicator_ambersand,
fyewt_indicator_star,
fyewt_indicator_chomp,
fyewt_indicator_explicit_indent,
};
#define FYEWT_EXTENDED_INDICATORS_FIRST fyewt_indicator_question_mark
#define FYEWT_EXTENDED_INDICATORS_LAST fyewt_indicator_explicit_indent
#define FYEWT_EXTENDED_START fyewt_indicator_question_mark
#define FYEWT_COUNT (fyewt_indicator_explicit_indent + 1)
#define FYECF_INDENT_SHIFT 8
#define FYECF_INDENT_MASK 0xf
#define FYECF_INDENT(x) (((x) & FYECF_INDENT_MASK) << FYECF_INDENT_SHIFT)
#define FYECF_WIDTH_SHIFT 12
#define FYECF_WIDTH_MASK 0xff
#define FYECF_WIDTH(x) (((x) & FYECF_WIDTH_MASK) << FYECF_WIDTH_SHIFT)
#define FYECF_MODE_SHIFT 20
#define FYECF_MODE_MASK 0xf
#define FYECF_MODE(x) (((x) & FYECF_MODE_MASK) << FYECF_MODE_SHIFT)
#define FYECF_DOC_START_MARK_SHIFT 24
#define FYECF_DOC_START_MARK_MASK 0x3
#define FYECF_DOC_START_MARK(x) (((x) & FYECF_DOC_START_MARK_MASK) << FYECF_DOC_START_MARK_SHIFT)
#define FYECF_DOC_END_MARK_SHIFT 26
#define FYECF_DOC_END_MARK_MASK 0x3
#define FYECF_DOC_END_MARK(x) (((x) & FYECF_DOC_END_MARK_MASK) << FYECF_DOC_END_MARK_SHIFT)
#define FYECF_VERSION_DIR_SHIFT 28
#define FYECF_VERSION_DIR_MASK 0x3
#define FYECF_VERSION_DIR(x) (((x) & FYECF_VERSION_DIR_MASK) << FYECF_VERSION_DIR_SHIFT)
#define FYECF_TAG_DIR_SHIFT 30
#define FYECF_TAG_DIR_MASK 0x3
#define FYECF_TAG_DIR(x) (((unsigned int)(x) & FYECF_TAG_DIR_MASK) << FYECF_TAG_DIR_SHIFT)
/**
* enum fy_emitter_cfg_flags - Emitter configuration flags
*
* These flags control the operation of the emitter
*
* @FYECF_SORT_KEYS: Sort key when emitting
* @FYECF_OUTPUT_COMMENTS: Output comments (experimental)
* @FYECF_STRIP_LABELS: Strip labels when emitting
* @FYECF_STRIP_TAGS: Strip tags when emitting
* @FYECF_STRIP_DOC: Strip document tags and markers when emitting
* @FYECF_NO_ENDING_NEWLINE: Do not output ending new line (useful for single line mode)
* @FYECF_STRIP_EMPTY_KV: Remove all keys with empty values from the output (not available in streaming mode)
* @FYECF_EXTENDED_CFG: Extend configuration, this config structure is embedded in a fy_emitter_xcfg.
* @FYECF_INDENT_DEFAULT: Default emit output indent
* @FYECF_INDENT_1: Output indent is 1
* @FYECF_INDENT_2: Output indent is 2
* @FYECF_INDENT_3: Output indent is 3
* @FYECF_INDENT_4: Output indent is 4
* @FYECF_INDENT_5: Output indent is 5
* @FYECF_INDENT_6: Output indent is 6
* @FYECF_INDENT_7: Output indent is 7
* @FYECF_INDENT_8: Output indent is 8
* @FYECF_INDENT_9: Output indent is 9
* @FYECF_WIDTH_DEFAULT: Default emit output width
* @FYECF_WIDTH_80: Output width is 80
* @FYECF_WIDTH_132: Output width is 132
* @FYECF_WIDTH_INF: Output width is infinite
* @FYECF_MODE_ORIGINAL: Emit using the same flow mode as the original
* @FYECF_MODE_BLOCK: Emit using only the block mode
* @FYECF_MODE_FLOW: Emit using only the flow mode
* @FYECF_MODE_FLOW_ONELINE: Emit using only the flow mode (in one line)
* @FYECF_MODE_JSON: Emit using JSON mode (non type preserving)
* @FYECF_MODE_JSON_TP: Emit using JSON mode (type preserving)
* @FYECF_MODE_JSON_ONELINE: Emit using JSON mode (non type preserving, one line)
* @FYECF_MODE_DEJSON: Emit YAML trying to pretify JSON
* @FYECF_MODE_PRETTY: Emit YAML that tries to look good
* @FYECF_MODE_MANUAL: Emit YAML respecting all manual style hints (reformats if needed)
* @FYECF_MODE_FLOW_COMPACT: Emit using only the flow mode in as much as possible compact form
* @FYECF_MODE_JSON_COMPACT: Emit using JSON compact form
* @FYECF_DOC_START_MARK_AUTO: Automatically generate document start markers if required
* @FYECF_DOC_START_MARK_OFF: Do not generate document start markers
* @FYECF_DOC_START_MARK_ON: Always generate document start markers
* @FYECF_DOC_END_MARK_AUTO: Automatically generate document end markers if required
* @FYECF_DOC_END_MARK_OFF: Do not generate document end markers
* @FYECF_DOC_END_MARK_ON: Always generate document end markers
* @FYECF_VERSION_DIR_AUTO: Automatically generate version directive
* @FYECF_VERSION_DIR_OFF: Never generate version directive
* @FYECF_VERSION_DIR_ON: Always generate version directive
* @FYECF_TAG_DIR_AUTO: Automatically generate tag directives
* @FYECF_TAG_DIR_OFF: Never generate tag directives
* @FYECF_TAG_DIR_ON: Always generate tag directives
* @FYECF_DEFAULT: The default emitter configuration
*/
enum fy_emitter_cfg_flags {
FYECF_SORT_KEYS = FY_BIT(0),
FYECF_OUTPUT_COMMENTS = FY_BIT(1),
FYECF_STRIP_LABELS = FY_BIT(2),
FYECF_STRIP_TAGS = FY_BIT(3),
FYECF_STRIP_DOC = FY_BIT(4),
FYECF_NO_ENDING_NEWLINE = FY_BIT(5),
FYECF_STRIP_EMPTY_KV = FY_BIT(6),
FYECF_EXTENDED_CFG = FY_BIT(7),
FYECF_INDENT_DEFAULT = FYECF_INDENT(0),
FYECF_INDENT_1 = FYECF_INDENT(1),
FYECF_INDENT_2 = FYECF_INDENT(2),
FYECF_INDENT_3 = FYECF_INDENT(3),
FYECF_INDENT_4 = FYECF_INDENT(4),
FYECF_INDENT_5 = FYECF_INDENT(5),
FYECF_INDENT_6 = FYECF_INDENT(6),
FYECF_INDENT_7 = FYECF_INDENT(7),
FYECF_INDENT_8 = FYECF_INDENT(8),
FYECF_INDENT_9 = FYECF_INDENT(9),
FYECF_WIDTH_DEFAULT = FYECF_WIDTH(80),
FYECF_WIDTH_80 = FYECF_WIDTH(80),
FYECF_WIDTH_132 = FYECF_WIDTH(132),
FYECF_WIDTH_INF = FYECF_WIDTH(255),
FYECF_MODE_ORIGINAL = FYECF_MODE(0),
FYECF_MODE_BLOCK = FYECF_MODE(1),
FYECF_MODE_FLOW = FYECF_MODE(2),
FYECF_MODE_FLOW_ONELINE = FYECF_MODE(3),
FYECF_MODE_JSON = FYECF_MODE(4),
FYECF_MODE_JSON_TP = FYECF_MODE(5),
FYECF_MODE_JSON_ONELINE = FYECF_MODE(6),
FYECF_MODE_DEJSON = FYECF_MODE(7),
FYECF_MODE_PRETTY = FYECF_MODE(8),
FYECF_MODE_MANUAL = FYECF_MODE(9),
FYECF_MODE_FLOW_COMPACT = FYECF_MODE(10),
FYECF_MODE_JSON_COMPACT = FYECF_MODE(11),
FYECF_DOC_START_MARK_AUTO = FYECF_DOC_START_MARK(0),
FYECF_DOC_START_MARK_OFF = FYECF_DOC_START_MARK(1),
FYECF_DOC_START_MARK_ON = FYECF_DOC_START_MARK(2),
FYECF_DOC_END_MARK_AUTO = FYECF_DOC_END_MARK(0),
FYECF_DOC_END_MARK_OFF = FYECF_DOC_END_MARK(1),
FYECF_DOC_END_MARK_ON = FYECF_DOC_END_MARK(2),
FYECF_VERSION_DIR_AUTO = FYECF_VERSION_DIR(0),
FYECF_VERSION_DIR_OFF = FYECF_VERSION_DIR(1),
FYECF_VERSION_DIR_ON = FYECF_VERSION_DIR(2),
FYECF_TAG_DIR_AUTO = FYECF_TAG_DIR(0),
FYECF_TAG_DIR_OFF = FYECF_TAG_DIR(1),
FYECF_TAG_DIR_ON = FYECF_TAG_DIR(2),
FYECF_DEFAULT = FYECF_WIDTH_INF |
FYECF_MODE_ORIGINAL |
FYECF_INDENT_DEFAULT,
};
/**
* struct fy_emitter_cfg - emitter configuration structure.
*
* Argument to the fy_emitter_create() method which
* is the way to convert a runtime document structure back to YAML.
*
* @flags: Configuration flags
* @output: Pointer to the method that will perform output.
* @userdata: Opaque user data pointer
* @diag: Diagnostic interface
*/
struct fy_emitter_cfg {
enum fy_emitter_cfg_flags flags;
int (*output)(struct fy_emitter *emit, enum fy_emitter_write_type type,
const char *str, int len, void *userdata);
void *userdata;
struct fy_diag *diag;
};
/* Shift amount of the color settings */
#define FYEXCF_COLOR_SHIFT 0
/* Mask of the color */
#define FYEXCF_COLOR_MASK ((1U << 2) - 1)
/* Build a color version */
#define FYEXCF_COLOR(x) (((unsigned int)(x) & FYEXCF_COLOR_MASK) << FYEXCF_COLOR_SHIFT)
/* Shift amount of the output settings */
#define FYEXCF_OUTPUT_SHIFT 2
/* Mask of the output */
#define FYEXCF_OUTPUT_MASK ((1U << 3) - 1)
/* Build an output */
#define FYEXCF_OUTPUT(x) (((unsigned int)(x) & FYEXCF_OUTPUT_MASK) << FYEXCF_OUTPUT_SHIFT)
/**
* enum fy_emitter_xcfg_flags - Emitter extended configuration flags
*
* These flags control the operation of the emitter.
* If no extended configuration mode is enabled all the flags are assumed 0.
*
* @FYEXCF_COLOR_AUTO: Automatically colorize if on a terminal
* @FYEXCF_COLOR_NONE: Do not colorize output
* @FYEXCF_COLOR_FORCE: Force color generation
* @FYEXCF_VISIBLE_WS: Make white space visible
* @FYEXCF_EXTENDED_INDICATORS: Extend the indicators generated
* @FYEXCF_OUTPUT_STDOUT: Output to stdout (default)
* @FYEXCF_OUTPUT_STDERR: Output to stderr, instead of stdout
* @FYEXCF_OUTPUT_FILE: Output to the fp FILE pointer
* @FYEXCF_OUTPUT_FD: Output to the fd file descriptor
* @FYEXCF_NULL_OUTPUT: No output
*/
enum fy_emitter_xcfg_flags {
FYEXCF_COLOR_AUTO = FYEXCF_COLOR(0),
FYEXCF_COLOR_NONE = FYEXCF_COLOR(1),
FYEXCF_COLOR_FORCE = FYEXCF_COLOR(2),
FYEXCF_OUTPUT_STDOUT = FYEXCF_OUTPUT(0),
FYEXCF_OUTPUT_STDERR = FYEXCF_OUTPUT(1),
FYEXCF_OUTPUT_FILE = FYEXCF_OUTPUT(2),
FYEXCF_OUTPUT_FD = FYEXCF_OUTPUT(2),
FYEXCF_NULL_OUTPUT = FYEXCF_OUTPUT(3),
FYEXCF_VISIBLE_WS = FY_BIT(5),
FYEXCF_EXTENDED_INDICATORS = FY_BIT(6),
};
/**
* struct fy_emitter_xcfg - emitter extended configuration structure.
*
* Argument to the fy_emitter create when FYECF_EXTENDED_CFG bit is
* set.
*
* @cfg: The standard emitter configuration
* @xflags: Extra configuration flags
* @colors: ANSI color overrides for the default output method
* @output_fp: The output FILE \*, FYEXCF\_FILE\_OUTPUT must be set
* @output_fd: The output file descriptor, FYEXCF\_FD\_OUTPUT must be set
*/
struct fy_emitter_xcfg {
struct fy_emitter_cfg cfg;
enum fy_emitter_xcfg_flags xflags;
const char *colors[FYEWT_COUNT];
union {
FILE *output_fp;
int output_fd;
};
};
/**
* fy_emitter_create() - Create an emitter
*
* Creates an emitter using the supplied configuration
*
* @cfg: The emitter configuration
*
* Returns:
* The newly created emitter or NULL on error.
*/
struct fy_emitter *
fy_emitter_create(const struct fy_emitter_cfg *cfg)
FY_EXPORT;
/**
* fy_emitter_destroy() - Destroy an emitter
*
* Destroy an emitter previously created by fy_emitter_create()
*
* @emit: The emitter to destroy
*/
void
fy_emitter_destroy(struct fy_emitter *emit)
FY_EXPORT;
/**
* fy_emitter_get_cfg() - Get the configuration of an emitter
*
* @emit: The emitter
*
* Returns:
* The configuration of the emitter
*/
const struct fy_emitter_cfg *
fy_emitter_get_cfg(struct fy_emitter *emit)
FY_EXPORT;
/**
* fy_emitter_get_diag() - Get the diagnostic object of an emitter
*
* Return a pointer to the diagnostic object of an emitter object.
* Note that the returned diag object has a reference taken so
* you should fy_diag_unref() it when you're done with it.
*
* @emit: The emitter to get the diagnostic object
*
* Returns:
* A pointer to a ref'ed diagnostic object or NULL in case of an
* error.
*/
struct fy_diag *
fy_emitter_get_diag(struct fy_emitter *emit)
FY_EXPORT;
/**
* fy_emitter_set_diag() - Set the diagnostic object of an emitter
*
* Replace the emitters's current diagnostic object with the one
* given as an argument. The previous diagnostic object will be
* unref'ed (and freed if its reference gets to 0).
* Also note that the diag argument shall take a reference too.
*
* @emit: The emitter to replace the diagnostic object
* @diag: The emitter's new diagnostic object, NULL for default
*
* Returns:
* 0 if everything OK, -1 otherwise
*/
int
fy_emitter_set_diag(struct fy_emitter *emit, struct fy_diag *diag)
FY_EXPORT;
/**
* fy_emitter_set_finalizer() - Set emitter finalizer
*
* Set a method callback to be called when the emitter
* is disposed of. If finalizer is NULL, then the method
* is removed.
*
* @emit: The emitter to replace the diagnostic object
* @finalizer: The finalizer callback
*/
void
fy_emitter_set_finalizer(struct fy_emitter *emit,
void (*finalizer)(struct fy_emitter *emit))
FY_EXPORT;
/**
* struct fy_emitter_default_output_data - emitter default output configuration
*
* This is the argument to the default output method of the emitter.
*
* @fp: File where the output is directed to
* @colorize: Use ANSI color sequences to colorize the output
* @visible: Make whitespace visible (requires a UTF8 capable terminal)
*/
struct fy_emitter_default_output_data {
FILE *fp;
bool colorize;
bool visible;
};
/**
* fy_emitter_default_output() - The default colorizing output method
*
* This is the default colorizing output method.
* Will be used when the output field of the emitter configuration is NULL.
*
* @fye: The emitter
* @type: Type of the emitted output
* @str: Pointer to the string to output
* @len: Length of the string
* @userdata: Must point to a fy_emitter_default_output_data structure
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emitter_default_output(struct fy_emitter *fye, enum fy_emitter_write_type type,
const char *str, int len, void *userdata)
FY_EXPORT;
/**
* fy_document_default_emit_to_fp() - Emit a document to a file, using defaults
*
* Simple one shot emitter to a file, using the default emitter output.
* The output will be colorized if the the file points to a tty.
*
* @fyd: The document to emit
* @fp: The file where the output is sent
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_document_default_emit_to_fp(struct fy_document *fyd, FILE *fp)
FY_EXPORT;
/**
* fy_emit_event() - Queue (and possibly emit) an event
*
* Queue and output using the emitter. This is the streaming
* output method which does not require creating a document.
*
* @emit: The emitter to use
* @fye: The event to queue for emission
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_event(struct fy_emitter *emit, struct fy_event *fye)
FY_EXPORT;
/**
* fy_emit_vevent() - Queue (and possibly emit) an event using varargs
*
* Queue and output using the emitter. The format is identical to
* the one used in fy_emit_event_vcreate().
*
* @emit: The emitter to use
* @type: The event type to create
* @ap: The variable argument list pointer.
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_vevent(struct fy_emitter *emit, enum fy_event_type type, va_list ap)
FY_EXPORT;
/**
* fy_emit_eventf() - Queue (and possibly emit) an event using variable args
*
* Queue and output using the emitter. The format is identical to
* the one used in fy_emit_event_create().
*
* @emit: The emitter to use
* @type: The event type to create
* @...: The optional extra arguments
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_eventf(struct fy_emitter *emit, enum fy_event_type type, ...)
FY_EXPORT;
/**
* fy_emit_scalar_write() - Emit a scalar with write semantics
*
* Queue and output using the emitter a scalar using a standard
* write interface.
*
* @fye: The emitter to use
* @style: The scalar style to use
* @anchor: The anchor or NULL
* @tag: The tag or NULL
* @buf: Pointer to the buffer
* @count: The number of bytes to write
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_scalar_write(struct fy_emitter *fye, enum fy_scalar_style style,
const char *anchor, const char *tag,
const char *buf, size_t count)
FY_EXPORT;
/**
* fy_emit_scalar_vprintf() - Emit a scalar with vprintf semantics
*
* Queue and output using the emitter a scalar using a standard
* vprintf interface.
*
* @fye: The emitter to use
* @style: The scalar style to use
* @anchor: The anchor or NULL
* @tag: The tag or NULL
* @fmt: The printf like format string
* @ap: The argument list
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_scalar_vprintf(struct fy_emitter *fye, enum fy_scalar_style style,
const char *anchor, const char *tag,
const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_emit_scalar_printf() - Emit a scalar with printf semantics
*
* Queue and output using the emitter a scalar using a standard
* printf interface.
*
* @fye: The emitter to use
* @style: The scalar style to use
* @anchor: The anchor or NULL
* @tag: The tag or NULL
* @fmt: The printf like format string
* @...: The extra arguments
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_scalar_printf(struct fy_emitter *fye, enum fy_scalar_style style,
const char *anchor, const char *tag,
const char *fmt, ...)
FY_FORMAT(printf, 5, 6)
FY_EXPORT;
/**
* fy_emit_event_from_parser() - Queue (and possibly emit) an event
* generated by the parser.
*
* Queue and output using the emitter. This is the streaming
* output method which does not require creating a document.
* Similar to fy_emit_event() but it is more efficient.
*
* @emit: The emitter to use
* @fyp: The parser that generated the event
* @fye: The event to queue for emission
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_event_from_parser(struct fy_emitter *emit, struct fy_parser *fyp, struct fy_event *fye)
FY_EXPORT;
/**
* fy_emit_document() - Emit the document using the emitter
*
* Emits a document in YAML format using the emitter.
*
* @emit: The emitter
* @fyd: The document to emit
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_document(struct fy_emitter *emit, struct fy_document *fyd)
FY_EXPORT;
/**
* fy_emit_document_start() - Emit document start using the emitter
*
* Emits a document start using the emitter. This is used in case
* you need finer control over the emitting output.
*
* @emit: The emitter
* @fyd: The document to use for emitting it's start
* @fyn: The root (or NULL for using the document's root)
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_document_start(struct fy_emitter *emit, struct fy_document *fyd,
struct fy_node *fyn)
FY_EXPORT;
/**
* fy_emit_document_end() - Emit document end using the emitter
*
* Emits a document end using the emitter. This is used in case
* you need finer control over the emitting output.
*
* @emit: The emitter
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_document_end(struct fy_emitter *emit)
FY_EXPORT;
/**
* fy_emit_node() - Emit a single node using the emitter
*
* Emits a single node using the emitter. This is used in case
* you need finer control over the emitting output.
*
* @emit: The emitter
* @fyn: The node to emit
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_node(struct fy_emitter *emit, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_emit_root_node() - Emit a single root node using the emitter
*
* Emits a single root node using the emitter. This is used in case
* you need finer control over the emitting output.
*
* @emit: The emitter
* @fyn: The root node to emit
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_root_node(struct fy_emitter *emit, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_emit_body_node() - Emit a single body node using the emitter
*
* Emits a single body node using the emitter. This is used in case
* you need finer control over the emitting output.
* No stream and document events will be generated at all.
*
* @emit: The emitter
* @fyn: The body node to emit
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_body_node(struct fy_emitter *emit, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_emit_explicit_document_end() - Emit an explicit document end
*
* Emits an explicit document end, i.e. ... . Use this if you
* you need finer control over the emitting output.
*
* @emit: The emitter
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_explicit_document_end(struct fy_emitter *emit)
FY_EXPORT;
/**
* fy_emit_document_to_fp() - Emit a document to an file pointer
*
* Emits a document from the root to the given file pointer.
*
* @fyd: The document to emit
* @flags: The emitter flags to use
* @fp: The file pointer to output to
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_document_to_fp(struct fy_document *fyd,
enum fy_emitter_cfg_flags flags, FILE *fp)
FY_EXPORT;
/**
* fy_emit_document_to_file() - Emit a document to file
*
* Emits a document from the root to the given file.
* The file will be fopen'ed using a "wa" mode.
*
* @fyd: The document to emit
* @flags: The emitter flags to use
* @filename: The filename to output to, or NULL for stdout
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_document_to_file(struct fy_document *fyd,
enum fy_emitter_cfg_flags flags,
const char *filename)
FY_EXPORT;
/**
* fy_emit_document_to_fd() - Emit a document to a file descriptor
*
* Emits a document from the root to the given file descriptor
*
* @fyd: The document to emit
* @flags: The emitter flags to use
* @fd: The file descriptor to output to
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_emit_document_to_fd(struct fy_document *fyd,
enum fy_emitter_cfg_flags flags, int fd)
FY_EXPORT;
/**
* fy_emit_document_to_buffer() - Emit a document to a buffer
*
* Emits an document from the root to the given buffer.
* If the document does not fit, an error will be returned.
*
* @fyd: The document to emit
* @flags: The emitter flags to use
* @buf: Pointer to the buffer area to fill
* @size: Size of the buffer
*
* Returns:
* A positive number, which is the size of the emitted document
* on the buffer on success, -1 on error
*/
int
fy_emit_document_to_buffer(struct fy_document *fyd,
enum fy_emitter_cfg_flags flags,
char *buf, size_t size)
FY_EXPORT;
/**
* fy_emit_document_to_string() - Emit a document to an allocated string
*
* Emits an document from the root to a string which will be dynamically
* allocated.
*
* @fyd: The document to emit
* @flags: The emitter flags to use
*
* Returns:
* A pointer to the allocated string, or NULL in case of an error
*/
char *
fy_emit_document_to_string(struct fy_document *fyd,
enum fy_emitter_cfg_flags flags)
FY_EXPORT;
#define fy_emit_document_to_string_alloca(_fyd, _flags) \
FY_ALLOCA_COPY_FREE(fy_emit_document_to_string((_fyd), (_flags)), FY_NT)
/**
* fy_emit_node_to_buffer() - Emit a node (recursively) to a buffer
*
* Emits a node recursively to the given buffer.
* If the document does not fit, an error will be returned.
*
* @fyn: The node to emit
* @flags: The emitter flags to use
* @buf: Pointer to the buffer area to fill
* @size: Size of the buffer
*
* Returns:
* A positive number, which is the size of the emitted node
* on the buffer on success, -1 on error
*/
int
fy_emit_node_to_buffer(struct fy_node *fyn, enum fy_emitter_cfg_flags flags,
char *buf, size_t size)
FY_EXPORT;
/**
* fy_emit_node_to_string() - Emit a node to an allocated string
*
* Emits a node recursively to a string which will be dynamically
* allocated.
*
* @fyn: The node to emit
* @flags: The emitter flags to use
*
* Returns:
* A pointer to the allocated string, or NULL in case of an error
*/
char *
fy_emit_node_to_string(struct fy_node *fyn, enum fy_emitter_cfg_flags flags)
FY_EXPORT;
#define fy_emit_node_to_string_alloca(_fyn, _flags) \
FY_ALLOCA_COPY_FREE(fy_emit_node_to_string((_fyn), (_flags)), FY_NT)
/**
* fy_emit_to_buffer() - Create an emitter for buffer output.
*
* Creates a special purpose emitter for buffer output.
* Calls to fy_emit_event() populate the buffer.
* The contents are retreived by a call to fy_emit_to_buffer_collect()
*
* @flags: The emitter flags to use
* @buf: Pointer to the buffer area to fill
* @size: Size of the buffer
*
* Returns:
* The newly created emitter or NULL on error.
*/
struct fy_emitter *
fy_emit_to_buffer(enum fy_emitter_cfg_flags flags, char *buf, size_t size)
FY_EXPORT;
/**
* fy_emit_to_buffer_collect() - Collect the buffer emitter output
*
* Collects the output of the emitter which was created by
* fy_emit_to_buffer() and populated using fy_emit_event() calls.
* The NULL terminated returned buffer is the same as the one used in the
* fy_emit_to_buffer() call and the sizep argument will be filled with
* the size of the buffer.
*
* @emit: The emitter
* @sizep: Pointer to the size to be filled
*
* Returns:
* The buffer or NULL in case of an error.
*/
char *
fy_emit_to_buffer_collect(struct fy_emitter *emit, size_t *sizep)
FY_EXPORT;
/**
* fy_emit_to_string() - Create an emitter to create a dynamically
* allocated string.
*
* Creates a special purpose emitter for output to a dynamically
* allocated string.
* Calls to fy_emit_event() populate the buffer.
* The contents are retreived by a call to fy_emit_to_string_collect()
*
* @flags: The emitter flags to use
*
* Returns:
* The newly created emitter or NULL on error.
*/
struct fy_emitter *
fy_emit_to_string(enum fy_emitter_cfg_flags flags)
FY_EXPORT;
/**
* fy_emit_to_string_collect() - Collect the string emitter output
*
* Collects the output of the emitter which was created by
* fy_emit_to_string() and populated using fy_emit_event() calls.
* The NULL terminated returned buffer is dynamically allocated
* and must be freed via a call to free().
* The sizep argument will be filled with the size of the buffer.
*
* @emit: The emitter
* @sizep: Pointer to the size to be filled
*
* Returns:
* The dynamically allocated string or NULL in case of an error.
*/
char *
fy_emit_to_string_collect(struct fy_emitter *emit, size_t *sizep)
FY_EXPORT;
/**
* fy_emitter_vlog() - Log using the emitters diagnostics printf style (va_arg)
*
* Output a log on the emitter diagnostic output
*
* @emit: The emitter
* @type: The error type
* @fmt: The printf format string
* @ap: The argument list
*/
void
fy_emitter_vlog(struct fy_emitter *emit, enum fy_error_type type, const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_emitter_log() - Log using the emitters diagnostics printf style
*
* Output a report on the emitter's diagnostics
*
* @emit: The emitter
* @type: The error type
* @fmt: The printf format string
* @...: The extra arguments
*/
void
fy_emitter_log(struct fy_emitter *emit, enum fy_error_type type, const char *fmt, ...)
FY_FORMAT(printf, 3, 4)
FY_EXPORT;
#ifndef NDEBUG
#define fy_emitter_debug(_emit, _fmt, ...) \
fy_emitter_log((_emit), FYET_DEBUG, (_fmt) , ## __VA_ARGS__)
#else
#define fy_emitter_debug(_emit, _fmt, ...) \
do { } while(0)
#endif
#define fy_emitter_info(_emit, _fmt, ...) \
fy_emitter_log((_emit), FYET_INFO, (_fmt) , ## __VA_ARGS__)
#define fy_emitter_notice(_emit, _fmt, ...) \
fy_emitter_log((_emit), FYET_NOTICE, (_fmt) , ## __VA_ARGS__)
#define fy_emitter_warning(_emit, _fmt, ...) \
fy_emitter_log((_emit), FYET_WARNING, (_fmt) , ## __VA_ARGS__)
#define fy_emitter_error(_emit, _fmt, ...) \
fy_emitter_log((_emit), FYET_ERROR, (_fmt) , ## __VA_ARGS__)
/**
* fy_node_copy() - Copy a node, associating the new node with the given document
*
* Make a deep copy of a node, associating the copy with the given document.
* Note that no content copying takes place as the contents of the nodes
* are reference counted. This means that the operation is relatively inexpensive.
*
* Note that the copy includes all anchors contained in the subtree of the
* source, so this call will register them with the document.
*
* @fyd: The document which the resulting node will be associated with
* @fyn_from: The source node to recursively copy
*
* Returns:
* The copied node on success, NULL on error
*/
struct fy_node *
fy_node_copy(struct fy_document *fyd, struct fy_node *fyn_from)
FY_EXPORT;
/**
* fy_document_clone() - Clones a document
*
* Clone a document, by making a deep copy of the source.
* Note that no content copying takes place as the contents of the nodes
* are reference counted. This means that the operation is relatively inexpensive.
*
* @fydsrc: The source document to clone
*
* Returns:
* The newly created clone document, or NULL in case of an error
*/
struct fy_document *
fy_document_clone(struct fy_document *fydsrc)
FY_EXPORT;
/**
* fy_node_insert() - Insert a node to the given node
*
* Insert a node to another node. If @fyn_from is NULL then this
* operation will delete the @fyn_to node.
*
* The operation varies according to the types of the arguments:
*
* from: scalar
*
* to: another-scalar -> scalar
* to: { key: value } -> scalar
* to: [ seq0, seq1 ] -> scalar
*
* from: [ seq2 ]
* to: scalar -> [ seq2 ]
* to: { key: value } -> [ seq2 ]
* to: [ seq0, seq1 ] -> [ seq0, seq1, sec2 ]
*
* from: { another-key: another-value }
* to: scalar -> { another-key: another-value }
* to: { key: value } -> { key: value, another-key: another-value }
* to: [ seq0, seq1 ] -> { another-key: another-value }
*
* from: { key: another-value }
* to: scalar -> { key: another-value }
* to: { key: value } -> { key: another-value }
* to: [ seq0, seq1 ] -> { key: another-value }
*
* The rules are:
* - If target node changes type, source ovewrites target.
* - If source or target node are scalars, source it overwrites target.
* - If target and source are sequences the items of the source sequence
* are appended to the target sequence.
* - If target and source are maps the key, value pairs of the source
* are appended to the target map. If the target map contains a
* key-value pair that is present in the source map, it is overwriten
* by it.
*
* @fyn_to: The target node
* @fyn_from: The source node
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_insert(struct fy_node *fyn_to, struct fy_node *fyn_from)
FY_EXPORT;
/**
* fy_node_delete() - Delete a node from a document
*
* Delete the given node.
* If it's part of a sequence it will be removed from it.
* If it's the value of a node key value pair, it will
* be removed from the mapping.
*
* This is an alias for fy_document_insert_at(fyn, NULL)
*
* Note that it is expected this node is attached to a document.
* Do not call this to free a node, because if it's part of
* a collection it will not be properly removed.
*
* @fyn: The node to delete.
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_delete(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_document_insert_at() - Insert a node to the given path in the document
*
* Insert a node to a given point in the document. If @fyn is NULL then this
* operation will delete the target node.
*
* Please see fy_node_insert for details of operation.
*
* Note that in any case the fyn node will be unref'ed.
* So if the operation fails, and the reference is 0
* the node will be freed. If you want it to stick around
* take a reference before.
*
* @fyd: The document
* @path: The path where the insert operation will target
* @pathlen: The length of the path (or -1 if '\0' terminated)
* @fyn: The source node
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_document_insert_at(struct fy_document *fyd,
const char *path, size_t pathlen,
struct fy_node *fyn)
FY_EXPORT;
/**
* enum fy_node_type - Node type
*
* Each node may be one of the following types
*
* @FYNT_SCALAR: Node is a scalar
* @FYNT_SEQUENCE: Node is a sequence
* @FYNT_MAPPING: Node is a mapping
*/
enum fy_node_type {
FYNT_SCALAR,
FYNT_SEQUENCE,
FYNT_MAPPING,
};
/**
* enum fy_node_style - Node style
*
* A node may contain a hint of how it should be
* rendered, encoded as a style.
*
* @FYNS_ANY: No hint, let the emitter decide
* @FYNS_FLOW: Prefer flow style (for sequence/mappings)
* @FYNS_BLOCK: Prefer block style (for sequence/mappings)
* @FYNS_PLAIN: Plain style preferred
* @FYNS_SINGLE_QUOTED: Single quoted style preferred
* @FYNS_DOUBLE_QUOTED: Double quoted style preferred
* @FYNS_LITERAL: Literal style preferred (valid in block context)
* @FYNS_FOLDED: Folded style preferred (valid in block context)
* @FYNS_ALIAS: It's an alias
*/
enum fy_node_style {
FYNS_ANY = -1,
FYNS_FLOW,
FYNS_BLOCK,
FYNS_PLAIN,
FYNS_SINGLE_QUOTED,
FYNS_DOUBLE_QUOTED,
FYNS_LITERAL,
FYNS_FOLDED,
FYNS_ALIAS,
};
/* maximum depth is 256 */
#define FYNWF_MAXDEPTH_SHIFT 4
#define FYNWF_MAXDEPTH_MASK 0xff
#define FYNWF_MAXDEPTH(x) (((x) & FYNWF_MAXDEPTH_MASK) << FYNWF_MAXDEPTH_SHIFT)
#define FYNWF_MARKER_SHIFT 12
#define FYNWF_MARKER_MASK 0x1f
#define FYNWF_MARKER(x) (((x) & FYNWF_MARKER_MASK) << FYNWF_MARKER_SHIFT)
#define FYNWF_PTR_SHIFT 16
#define FYNWF_PTR_MASK 0x03
#define FYNWF_PTR(x) (((x) & FYNWF_PTR_MASK) << FYNWF_PTR_SHIFT)
/**
* enum fy_node_walk_flags - Node walk flags
*
* @FYNWF_DONT_FOLLOW: Don't follow aliases during pathwalk
* @FYNWF_FOLLOW: Follow aliases during pathwalk
* @FYNWF_PTR_YAML: YAML pointer path walks
* @FYNWF_PTR_JSON: JSON pointer path walks
* @FYNWF_PTR_RELJSON: Relative JSON pointer path walks
* @FYNWF_PTR_YPATH: YPATH pointer path walks
* @FYNWF_URI_ENCODED: The path is URI encoded
* @FYNWF_MAXDEPTH_DEFAULT: Max follow depth is automatically determined
* @FYNWF_MARKER_DEFAULT: Default marker to use when scanning
* @FYNWF_PTR_DEFAULT: Default path type
*/
enum fy_node_walk_flags {
FYNWF_DONT_FOLLOW = 0,
FYNWF_FOLLOW = FY_BIT(0),
FYNWF_PTR_YAML = FYNWF_PTR(0),
FYNWF_PTR_JSON = FYNWF_PTR(1),
FYNWF_PTR_RELJSON = FYNWF_PTR(2),
FYNWF_PTR_YPATH = FYNWF_PTR(3),
FYNWF_URI_ENCODED = FY_BIT(18),
FYNWF_MAXDEPTH_DEFAULT = FYNWF_MAXDEPTH(0),
FYNWF_MARKER_DEFAULT = FYNWF_MARKER(0),
FYNWF_PTR_DEFAULT = FYNWF_PTR(0),
};
/* the maximum user marker */
#define FYNWF_MAX_USER_MARKER 24
/**
* fy_node_style_from_scalar_style() - Convert from scalar to node style
*
* Convert a scalar style to a node style.
*
* @sstyle: The input scalar style
*
* Returns:
* The matching node style
*/
static inline enum fy_node_style
fy_node_style_from_scalar_style(enum fy_scalar_style sstyle)
{
if (sstyle == FYSS_ANY)
return FYNS_ANY;
return (enum fy_node_style)(FYNS_PLAIN + (sstyle - FYSS_PLAIN));
}
/**
* typedef fy_node_mapping_sort_fn - Mapping sorting method function
*
* @fynp_a: The first node_pair used in the comparison
* @fynp_b: The second node_pair used in the comparison
* @arg: The opaque user provided pointer to the sort operation
*
* Returns:
* <0 if @fynp_a is less than @fynp_b
* 0 if @fynp_a is equal to fynp_b
* >0 if @fynp_a is greater than @fynp_b
*/
typedef int (*fy_node_mapping_sort_fn)(const struct fy_node_pair *fynp_a,
const struct fy_node_pair *fynp_b,
void *arg);
/**
* typedef fy_node_scalar_compare_fn - Node compare method function for scalars
*
* @fyn_a: The first scalar node used in the comparison
* @fyn_b: The second scalar node used in the comparison
* @arg: The opaque user provided pointer to the compare operation
*
* Returns:
* <0 if @fyn_a is less than @fyn_b
* 0 if @fyn_a is equal to fyn_b
* >0 if @fyn_a is greater than @fyn_b
*/
typedef int (*fy_node_scalar_compare_fn)(struct fy_node *fyn_a,
struct fy_node *fyn_b,
void *arg);
/**
* fy_node_compare() - Compare two nodes for equality
*
* Compare two nodes for equality.
* The comparison is 'deep', i.e. it recurses in subnodes,
* and orders the keys of maps using default libc strcmp
* ordering. For scalar the comparison is performed after
* any escaping so it's a true content comparison.
*
* @fyn1: The first node to use in the comparison
* @fyn2: The second node to use in the comparison
*
* Returns:
* true if the nodes contain the same content, false otherwise
*/
bool
fy_node_compare(struct fy_node *fyn1, struct fy_node *fyn2)
FY_EXPORT;
/**
* fy_node_compare_user() - Compare two nodes for equality using
* user supplied sort and scalar compare methods
*
* Compare two nodes for equality using user supplied sot and scalar
* compare methods.
* The comparison is 'deep', i.e. it recurses in subnodes,
* and orders the keys of maps using the supplied mapping sort method for
* ordering. For scalars the comparison is performed using the supplied
* scalar node compare methods.
*
* @fyn1: The first node to use in the comparison
* @fyn2: The second node to use in the comparison
* @sort_fn: The method to use for sorting maps, or NULL for the default
* @sort_fn_arg: The extra user supplied argument to the @sort_fn
* @cmp_fn: The method to use for comparing scalars, or NULL for the default
* @cmp_fn_arg: The extra user supplied argument to the @cmp_fn
*
* Returns:
* true if the nodes contain the same content, false otherwise
*/
bool
fy_node_compare_user(struct fy_node *fyn1, struct fy_node *fyn2,
fy_node_mapping_sort_fn sort_fn, void *sort_fn_arg,
fy_node_scalar_compare_fn cmp_fn, void *cmp_fn_arg)
FY_EXPORT;
/**
* fy_node_compare_string() - Compare a node for equality with a YAML string
*
* Compare a node for equality with a YAML string.
* The comparison is performed using fy_node_compare() with the
* first node supplied as an argument and the second being generated
* by calling fy_document_build_from_string with the YAML string.
*
* @fyn: The node to use in the comparison
* @str: The YAML string to compare against
* @len: The length of the string (or -1 if '\0' terminated)
*
* Returns:
* true if the node and the string are equal.
*/
bool
fy_node_compare_string(struct fy_node *fyn, const char *str, size_t len)
FY_EXPORT;
/**
* fy_node_compare_token() - Compare a node for equality against a token
*
* Compare a node for equality with a token.
* Both the node and the tokens must be a scalars.
*
* @fyn: The node to use in the comparison
* @fyt: The scalar token
*
* Returns:
* true if the node and the token are equal.
*/
bool
fy_node_compare_token(struct fy_node *fyn, struct fy_token *fyt)
FY_EXPORT;
/**
* fy_node_compare_text() - Compare a node for equality with a raw C text
*
* Compare a node for equality with a raw C string.
* The node must be a scalar.
*
* @fyn: The node to use in the comparison
* @text: The raw C text to compare against
* @len: The length of the text (or -1 if '\0' terminated)
*
* Returns:
* true if the node and the text are equal.
*/
bool
fy_node_compare_text(struct fy_node *fyn, const char *text, size_t len)
FY_EXPORT;
/**
* fy_document_create() - Create an empty document
*
* Create an empty document using the provided parser configuration.
* If NULL use the default parse configuration.
*
* @cfg: The parse configuration to use or NULL for the default.
*
* Returns:
* The created empty document, or NULL on error.
*/
struct fy_document *
fy_document_create(const struct fy_parse_cfg *cfg)
FY_EXPORT;
/**
* fy_document_destroy() - Destroy a document previously created via
* fy_document_create()
*
* Destroy a document (along with all children documents)
*
* @fyd: The document to destroy
*
*/
void
fy_document_destroy(struct fy_document *fyd)
FY_EXPORT;
/**
* fy_document_get_cfg() - Get the configuration of a document
*
* @fyd: The document
*
* Returns:
* The configuration of the document
*/
const struct fy_parse_cfg *
fy_document_get_cfg(struct fy_document *fyd)
FY_EXPORT;
/**
* fy_document_get_diag() - Get the diagnostic object of a document
*
* Return a pointer to the diagnostic object of a document object.
* Note that the returned diag object has a reference taken so
* you should fy_diag_unref() it when you're done with it.
*
* @fyd: The document to get the diagnostic object
*
* Returns:
* A pointer to a ref'ed diagnostic object or NULL in case of an
* error.
*/
struct fy_diag *
fy_document_get_diag(struct fy_document *fyd)
FY_EXPORT;
/**
* fy_document_set_diag() - Set the diagnostic object of a document
*
* Replace the documents's current diagnostic object with the one
* given as an argument. The previous diagnostic object will be
* unref'ed (and freed if its reference gets to 0).
* Also note that the diag argument shall take a reference too.
*
* @fyd: The document to replace the diagnostic object
* @diag: The document's new diagnostic object, NULL for default
*
* Returns:
* 0 if everything OK, -1 otherwise
*/
int
fy_document_set_diag(struct fy_document *fyd, struct fy_diag *diag)
FY_EXPORT;
/**
* fy_document_set_parent() - Make a document a child of another
*
* Set the parent of @fyd_child document to be @fyd
*
* @fyd: The parent document
* @fyd_child: The child document
*
* Returns:
* 0 if all OK, -1 on error.
*/
int
fy_document_set_parent(struct fy_document *fyd, struct fy_document *fyd_child)
FY_EXPORT;
/**
* fy_document_build_from_string() - Create a document using the provided YAML source.
*
* Create a document parsing the provided string as a YAML source.
*
* @cfg: The parse configuration to use or NULL for the default.
* @str: The YAML source to use.
* @len: The length of the string (or -1 if '\0' terminated)
*
* Returns:
* The created document, or NULL on error.
*/
struct fy_document *
fy_document_build_from_string(const struct fy_parse_cfg *cfg,
const char *str, size_t len)
FY_EXPORT;
/**
* fy_document_build_from_malloc_string() - Create a document using the provided YAML source which was malloced.
*
* Create a document parsing the provided string as a YAML source. The string is expected to have been
* allocated by malloc(3) and when the document is destroyed it will be automatically freed.
*
* @cfg: The parse configuration to use or NULL for the default.
* @str: The YAML source to use.
* @len: The length of the string (or -1 if '\0' terminated)
*
* Returns:
* The created document, or NULL on error.
*/
struct fy_document *
fy_document_build_from_malloc_string(const struct fy_parse_cfg *cfg,
char *str, size_t len)
FY_EXPORT;
/**
* fy_document_build_from_file() - Create a document parsing the given file
*
* Create a document parsing the provided file as a YAML source.
*
* @cfg: The parse configuration to use or NULL for the default.
* @file: The name of the file to parse
*
* Returns:
* The created document, or NULL on error.
*/
struct fy_document *
fy_document_build_from_file(const struct fy_parse_cfg *cfg, const char *file)
FY_EXPORT;
/**
* fy_document_build_from_fp() - Create a document parsing the given file pointer
*
* Create a document parsing the provided file pointer as a YAML source.
*
* @cfg: The parse configuration to use or NULL for the default.
* @fp: The file pointer
*
* Returns:
* The created document, or NULL on error.
*/
struct fy_document *
fy_document_build_from_fp(const struct fy_parse_cfg *cfg, FILE *fp)
FY_EXPORT;
/**
* fy_document_vbuildf() - Create a document using the provided YAML via vprintf formatting
*
* Create a document parsing the provided string as a YAML source. The string
* is created by applying vprintf formatting.
*
* @cfg: The parse configuration to use or NULL for the default.
* @fmt: The format string creating the YAML source to use.
* @ap: The va_list argument pointer
*
* Returns:
* The created document, or NULL on error.
*/
struct fy_document *
fy_document_vbuildf(const struct fy_parse_cfg *cfg,
const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_document_buildf() - Create a document using the provided YAML source via printf formatting
*
* Create a document parsing the provided string as a YAML source. The string
* is created by applying printf formatting.
*
* @cfg: The parse configuration to use or NULL for the default.
* @fmt: The format string creating the YAML source to use.
* @...: The printf arguments
*
* Returns:
* The created document, or NULL on error.
*/
struct fy_document *
fy_document_buildf(const struct fy_parse_cfg *cfg, const char *fmt, ...)
FY_FORMAT(printf, 2, 3)
FY_EXPORT;
/**
* fy_flow_document_build_from_string() - Create a document using the provided YAML source.
*
* Create a document parsing the provided string as a YAML source.
*
* The document is a flow document, i.e. does not contain any block content
* and is usually laid out in a single line.
*
* Example of flow documents:
*
* plain-scalar
* "double-quoted-scalar"
* 'single-quoted-scalar'
* { foo: bar }
* [ 0, 1, 2 ]
*
* A flow document is important because parsing stops at the end
* of it, and so can be placed in other non-yaml content.
*
* @cfg: The parse configuration to use or NULL for the default.
* @str: The YAML source to use.
* @len: The length of the string (or -1 if '\0' terminated)
* @consumed: A pointer to the consumed amount
*
* Returns:
* The created document, or NULL on error.
*/
struct fy_document *
fy_flow_document_build_from_string(const struct fy_parse_cfg *cfg,
const char *str, size_t len, size_t *consumed)
FY_EXPORT;
/**
* fy_block_document_build_from_string() - Create a document using the provided YAML source.
*
* Create a document parsing the provided string as a YAML source.
*
* The document is a block document, and it terminates when indentation
* appears to do so.
*
* Example of block documents::
*
* this-is-yaml
* foo: bar <- starts here
* baz: [1, 2]
* this-is-yaml-no-more
*
* @cfg: The parse configuration to use or NULL for the default.
* @str: The YAML source to use.
* @len: The length of the string (or -1 if '\0' terminated)
* @consumed: A pointer to the consumed amount
*
* Returns:
* The created document, or NULL on error.
*/
struct fy_document *
fy_block_document_build_from_string(const struct fy_parse_cfg *cfg,
const char *str, size_t len, size_t *consumed)
FY_EXPORT;
/**
* fy_document_root() - Return the root node of the document
*
* Returns the root of the document. If the document is empty
* NULL will be returned instead.
*
* @fyd: The document
*
* Returns:
* The root of the document, or NULL if the document is empty.
*/
struct fy_node *
fy_document_root(struct fy_document *fyd)
FY_EXPORT;
/**
* fy_document_set_root() - Set the root of the document
*
* Set the root of a document. If the document was not empty
* the old root will be freed. If @fyn is NULL then the
* document is set to empty.
*
* @fyd: The document
* @fyn: The new root of the document.
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_document_set_root(struct fy_document *fyd, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_type() - Get the node type
*
* Retrieve the node type. It is one of FYNT_SCALAR, FYNT_SEQUENCE
* or FYNT_MAPPING. A NULL node argument is a FYNT_SCALAR.
*
* @fyn: The node
*
* Returns:
* The node type
*/
enum fy_node_type
fy_node_get_type(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_style() - Get the node style
*
* Retrieve the node rendering style.
* If the node is NULL then the style is FYNS_PLAIN.
*
* @fyn: The node
*
* Returns:
* The node style
*/
enum fy_node_style
fy_node_get_style(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_start_token() - Get the node start token
*
* Retrieve the node start token.
*
* For scalars, this is the same as the end token.
*
* @fyn: The node
*
* Returns:
* The node start token
*/
struct fy_token * fy_node_get_start_token(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_end_token() - Get the node end token
*
* Retrieve the node end token.
*
* For scalars, this is the same as the start token.
*
* @fyn: The node
*
* Returns:
* The node end token
*/
struct fy_token * fy_node_get_end_token(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_is_scalar() - Check whether the node is a scalar
*
* Convenience method for checking whether a node is a scalar.
*
* @fyn: The node
*
* Returns:
* true if the node is a scalar, false otherwise
*/
static inline bool
fy_node_is_scalar(struct fy_node *fyn)
{
return fy_node_get_type(fyn) == FYNT_SCALAR;
}
/**
* fy_node_is_sequence() - Check whether the node is a sequence
*
* Convenience method for checking whether a node is a sequence.
*
* @fyn: The node
*
* Returns:
* true if the node is a sequence, false otherwise
*/
static inline bool
fy_node_is_sequence(struct fy_node *fyn)
{
return fy_node_get_type(fyn) == FYNT_SEQUENCE;
}
/**
* fy_node_is_mapping() - Check whether the node is a mapping
*
* Convenience method for checking whether a node is a mapping.
*
* @fyn: The node
*
* Returns:
* true if the node is a mapping, false otherwise
*/
static inline bool
fy_node_is_mapping(struct fy_node *fyn)
{
return fy_node_get_type(fyn) == FYNT_MAPPING;
}
/**
* fy_node_is_alias() - Check whether the node is an alias
*
* Convenience method for checking whether a node is an alias.
*
* @fyn: The node
*
* Returns:
* true if the node is an alias, false otherwise
*/
static inline bool
fy_node_is_alias(struct fy_node *fyn)
{
return fy_node_get_type(fyn) == FYNT_SCALAR &&
fy_node_get_style(fyn) == FYNS_ALIAS;
}
/**
* fy_node_is_null() - Check whether the node is a NULL
*
* Convenience method for checking whether a node is a NULL scalar..
* Note that a NULL node argument returns true...
*
* @fyn: The node
*
* Returns:
* true if the node is a NULL scalar, false otherwise
*/
bool
fy_node_is_null(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_is_attached() - Check whether the node is attached
*
* Checks whether a node is attached in a document structure.
* An attached node may not be freed, before being detached.
* Note that there is no method that explicitly detaches
* a node, since this is handled internaly by the sequence
* and mapping removal methods.
*
* @fyn: The node
*
* Returns:
* true if the node is attached, false otherwise
*/
bool
fy_node_is_attached(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_tag_token() - Gets the tag token of a node (if it exists)
*
* Gets the tag token of a node, if it exists
*
* @fyn: The node which has the tag token to be returned
*
* Returns:
* The tag token of the given node, or NULL if the tag does not
* exist.
*/
struct fy_token *
fy_node_get_tag_token(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_scalar_token() - Gets the scalar token of a node (if it exists)
*
* Gets the scalar token of a node, if it exists and the node is a valid scalar
* node. Note that aliases are scalars, so if this call is issued on an alias
* node the return shall be of an alias token.
*
* @fyn: The node which has the scalar token to be returned
*
* Returns:
* The scalar token of the given node, or NULL if the node is not a scalar.
*/
struct fy_token *
fy_node_get_scalar_token(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_resolve_alias() - Resolve an alias node
*
* Resolve an alias node, following any subsequent aliases until
* a non alias node has been found. This call performs cycle detection
* and excessive redirections checks so it's safe to call in any
* context.
*
* @fyn: The alias node to be resolved
*
* Returns:
* The resolved alias node, or NULL if either fyn is not an alias, or
* resolution fails due to a graph cycle.
*/
struct fy_node *
fy_node_resolve_alias(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_dereference() - Dereference a single alias node
*
* Dereference an alias node. This is different than resolution
* in that will only perform a single alias follow call and
* it will fail if the input is not an alias.
* This call performs cycle detection
* and excessive redirections checks so it's safe to call in any
* context.
*
* @fyn: The alias node to be dereferenced
*
* Returns:
* The dereferenced alias node, or NULL if either fyn is not an alias, or
* resolution fails due to a graph cycle.
*/
struct fy_node *
fy_node_dereference(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_free() - Free a node
*
* Recursively frees the given node releasing the memory it uses, removing
* any anchors on the document it contains, and releasing references
* on the tokens it contains.
*
* This method will return an error if the node is attached, or
* if not NULL it is not a member of a document.
*
* @fyn: The node to free
*
* Returns:
* 0 on success, -1 on error.
*/
int
fy_node_free(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_build_from_string() - Create a node using the provided YAML source.
*
* Create a node parsing the provided string as a YAML source. The
* node created will be associated with the provided document.
*
* @fyd: The document
* @str: The YAML source to use.
* @len: The length of the string (or -1 if '\0' terminated)
*
* Returns:
* The created node, or NULL on error.
*/
struct fy_node *
fy_node_build_from_string(struct fy_document *fyd,
const char *str, size_t len)
FY_EXPORT;
/**
* fy_node_build_from_malloc_string() - Create a node using the provided YAML source which was malloced.
*
* Create a node parsing the provided string as a YAML source. The
* node created will be associated with the provided document. The string is expected to have been
* allocated by malloc(3) and when the document is destroyed it will be automatically freed.
*
* @fyd: The document
* @str: The YAML source to use.
* @len: The length of the string (or -1 if '\0' terminated)
*
* Returns:
* The created node, or NULL on error.
*/
struct fy_node *
fy_node_build_from_malloc_string(struct fy_document *fyd,
char *str, size_t len)
FY_EXPORT;
/**
* fy_node_build_from_file() - Create a node using the provided YAML file.
*
* Create a node parsing the provided file as a YAML source. The
* node created will be associated with the provided document.
*
* @fyd: The document
* @file: The name of the file to parse
*
* Returns:
* The created node, or NULL on error.
*/
struct fy_node *
fy_node_build_from_file(struct fy_document *fyd, const char *file)
FY_EXPORT;
/**
* fy_node_build_from_fp() - Create a node using the provided file pointer.
*
* Create a node parsing the provided file pointer as a YAML source. The
* node created will be associated with the provided document.
*
* @fyd: The document
* @fp: The file pointer
*
* Returns:
* The created node, or NULL on error.
*/
struct fy_node *
fy_node_build_from_fp(struct fy_document *fyd, FILE *fp)
FY_EXPORT;
/**
* fy_node_vbuildf() - Create a node using the provided YAML source via vprintf formatting
*
* Create a node parsing the resulting string as a YAML source. The string
* is created by applying vprintf formatting.
*
* @fyd: The document
* @fmt: The format string creating the YAML source to use.
* @ap: The va_list argument pointer
*
* Returns:
* The created node, or NULL on error.
*/
struct fy_node *
fy_node_vbuildf(struct fy_document *fyd, const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_node_buildf() - Create a node using the provided YAML source via printf formatting
*
* Create a node parsing the resulting string as a YAML source. The string
* is created by applying printf formatting.
*
* @fyd: The document
* @fmt: The format string creating the YAML source to use.
* @...: The printf arguments
*
* Returns:
* The created node, or NULL on error.
*/
struct fy_node *
fy_node_buildf(struct fy_document *fyd, const char *fmt, ...)
FY_FORMAT(printf, 2, 3)
FY_EXPORT;
/**
* fy_node_by_path() - Retrieve a node using the provided path spec.
*
* This method will retrieve a node relative to the given node using
* the provided path spec.
*
* Path specs are comprised of keys seperated by slashes '/'.
* Keys are either regular YAML expressions in flow format for traversing
* mappings, or indexes in brackets for traversing sequences.
* Path specs may start with '/' which is silently ignored.
*
* A few examples will make this clear::
*
* fyn = { foo: bar } - fy_node_by_path(fyn, "/foo") -> bar
* fyn = [ foo, bar ] - fy_node_by_path(fyn, "1") -> bar
* fyn = { { foo: bar }: baz } - fy_node_by_path(fyn, "{foo: bar}") -> baz
* fyn = [ foo, { bar: baz } } - fy_node_by_path(fyn, "1/bar") -> baz
*
* Note that the special characters /{}[] are not escaped in plain style,
* so you will not be able to use them as path traversal keys.
* In that case you can easily use either the single, or double quoted forms::
*
* fyn = { foo/bar: baz } - fy_node_by_path(fyn, "'foo/bar'") -> baz
*
* @fyn: The node to use as start of the traversal operation
* @path: The path spec to use in the traversal operation
* @len: The length of the path (or -1 if '\0' terminated)
* @flags: The extra path walk flags
*
* Returns:
* The retrieved node, or NULL if not possible to be found.
*/
struct fy_node *
fy_node_by_path(struct fy_node *fyn, const char *path, size_t len,
enum fy_node_walk_flags flags)
FY_EXPORT;
/**
* fy_node_get_path() - Get the path of this node
*
* Retrieve the given node's path address relative to the document root.
* The address is dynamically allocated and should be freed when
* you're done with it.
*
* @fyn: The node
*
* Returns:
* The node's address, or NULL if fyn is the root.
*/
char *
fy_node_get_path(struct fy_node *fyn)
FY_EXPORT;
#define fy_node_get_path_alloca(_fyn) \
FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_path((_fyn)), FY_NT)
/**
* fy_node_get_parent() - Get the parent node of a node
*
* Get the parent node of a node. The parent of a document's root
* is NULL, and so is the parent of the root of a key node's of a mapping.
* This is because the nodes of a key may not be addressed using a
* path expression.
*
* @fyn: The node
*
* Returns:
* The node's parent, or NULL if fyn is the root, or the root of a key mapping.
*/
struct fy_node *
fy_node_get_parent(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_document_parent() - Get the document parent node of a node
*
* Get the document parent node of a node. The document parent differs
* than the regular parent in that a key's root node of a mapping is not
* NULL, rather it points to the actual node parent.
*
* @fyn: The node
*
* Returns:
* The node's document parent, or NULL if fyn is the root
*/
struct fy_node *
fy_node_get_document_parent(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_parent_address() - Get the path address of this node's parent
*
* Retrieve the given node's parent path address
* The address is dynamically allocated and should be freed when
* you're done with it.
*
* @fyn: The node
*
* Returns:
* The parent's address, or NULL if fyn is the root.
*/
char *
fy_node_get_parent_address(struct fy_node *fyn)
FY_EXPORT;
#define fy_node_get_parent_address_alloca(_fyn) \
FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_parent_address((_fyn)), FY_NT)
/**
* fy_node_get_path_relative_to() - Get a path address of a node relative
* to one of it's parents
*
* Retrieve the given node's path address relative to an arbitrary
* parent in the tree.
* The address is dynamically allocated and should be freed when
* you're done with it.
*
* @fyn_parent: The node parent/grandparent...
* @fyn: The node
*
* Returns:
* The relative address from the parent to the node
*/
char *
fy_node_get_path_relative_to(struct fy_node *fyn_parent, struct fy_node *fyn)
FY_EXPORT;
#define fy_node_get_path_relative_to_alloca(_fynp, _fyn) \
FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_path_relative_to((_fynp), (_fyn)), FY_NT)
/**
* fy_node_get_short_path() - Get a path address of a node in the shortest path possible
*
* Retrieve the given nodes short path address relative to the
* closest anchor (either on this node, or its parent).
* If no such parent is found then returns the absolute path
* from the start of the document.
*
* Example::
*
* --- &foo
* foo: &bar
* bar
* baz
*
* - The short path of /foo is \*foo
* - The short path of /foo/bar is \*bar
* - The short path of /baz is \*foo/baz
*
* The address is dynamically allocated and should be freed when
* you're done with it.
*
* @fyn: The node
*
* Returns:
* The shortest path describing the node
*/
char *
fy_node_get_short_path(struct fy_node *fyn)
FY_EXPORT;
#define fy_node_get_short_path_alloca(_fyn) \
FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_short_path((_fyn)), FY_NT)
/**
* fy_node_get_reference() - Get a textual reference to a node
*
* Retrieve the given node's textual reference. If the node
* contains an anchor the expression that references the anchor
* will be returned, otherwise an absolute path reference relative
* to the root of the document will be returned.
*
* The address is dynamically allocated and should be freed when
* you're done with it.
*
* @fyn: The node
*
* Returns:
* The node's text reference.
*/
char *
fy_node_get_reference(struct fy_node *fyn)
FY_EXPORT;
#define fy_node_get_reference_alloca(_fyn) \
FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_reference((_fyn)), FY_NT)
/**
* fy_node_create_reference() - Create an alias reference node
*
* Create an alias node reference. If the node
* contains an anchor the expression that references the alias will
* use the anchor, otherwise an absolute path reference relative
* to the root of the document will be created.
*
* @fyn: The node
*
* Returns:
* An alias node referencing the argument node
*/
struct fy_node *
fy_node_create_reference(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_relative_reference() - Get a textual reference to a node
* relative to a base node.
*
* Retrieve the given node's textual reference as generated using
* another parent (or grand parent) as a base.
* If the node contains an anchor the expression that references the anchor
* will be returned.
* If the base node contains an anchor the reference will be relative to it
* otherwise an absolute path reference will be returned.
*
* The address is dynamically allocated and should be freed when
* you're done with it.
*
* @fyn_base: The base node
* @fyn: The node
*
* Returns:
* The node's text reference.
*/
char *
fy_node_get_relative_reference(struct fy_node *fyn_base, struct fy_node *fyn)
FY_EXPORT;
#define fy_node_get_relative_reference_alloca(_fynb, _fyn) \
FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_relative_reference((_fynb), (_fyn)), FY_NT)
/**
* fy_node_create_relative_reference() - Create an alias reference node
*
* Create a relative alias node reference using
* another parent (or grand parent) as a base.
* If the node contains an anchor the alias will reference the anchor.
* If the base node contains an anchor the alias will be relative to it
* otherwise an absolute path reference will be created.
*
* @fyn_base: The base node
* @fyn: The node
*
* Returns:
* An alias node referencing the argument node relative to the base
*/
struct fy_node *
fy_node_create_relative_reference(struct fy_node *fyn_base, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_create_scalar() - Create a scalar node.
*
* Create a scalar node using the provided memory area as input.
* The input is expected to be regular utf8 encoded. It may contain
* escaped characters in which case the style of the scalar will be
* set to double quoted.
*
* Note that the data are not copied, merely a reference is taken, so
* it must be available while the node is in use.
*
* @fyd: The document which the resulting node will be associated with
* @data: Pointer to the data area
* @size: Size of the data area, or (size_t)-1 for '\0' terminated data.
*
* Returns:
* The created node, or NULL on error.
*/
struct fy_node *
fy_node_create_scalar(struct fy_document *fyd,
const char *data, size_t size)
FY_EXPORT;
/**
* fy_node_create_scalar_copy() - Create a scalar node copying the data.
*
* Create a scalar node using the provided memory area as input.
* The input is expected to be regular utf8 encoded. It may contain
* escaped characters in which case the style of the scalar will be
* set to double quoted.
*
* A copy of the data will be made, so it is safe to free the data
* after the call.
*
* @fyd: The document which the resulting node will be associated with
* @data: Pointer to the data area
* @size: Size of the data area, or (size_t)-1 for '\0' terminated data.
*
* Returns:
* The created node, or NULL on error.
*/
struct fy_node *
fy_node_create_scalar_copy(struct fy_document *fyd,
const char *data, size_t size)
FY_EXPORT;
/**
* fy_node_create_vscalarf() - vprintf interface for creating scalars
*
* Create a scalar node using a vprintf interface.
* The input is expected to be regular utf8 encoded. It may contain
* escaped characters in which case the style of the scalar will be
* set to double quoted.
*
* @fyd: The document which the resulting node will be associated with
* @fmt: The printf based format string
* @ap: The va_list containing the arguments
*
* Returns:
* The created node, or NULL on error.
*/
struct fy_node *
fy_node_create_vscalarf(struct fy_document *fyd, const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_node_create_scalarf() - printf interface for creating scalars
*
* Create a scalar node using a printf interface.
* The input is expected to be regular utf8 encoded. It may contain
* escaped characters in which case the style of the scalar will be
* set to double quoted.
*
* @fyd: The document which the resulting node will be associated with
* @fmt: The printf based format string
* @...: The arguments
*
* Returns:
* The created node, or NULL on error.
*/
struct fy_node *
fy_node_create_scalarf(struct fy_document *fyd, const char *fmt, ...)
FY_FORMAT(printf, 2, 3)
FY_EXPORT;
/**
* fy_node_create_sequence() - Create an empty sequence node.
*
* Create an empty sequence node associated with the given document.
*
* @fyd: The document which the resulting node will be associated with
*
* Returns:
* The created node, or NULL on error.
*/
struct fy_node *
fy_node_create_sequence(struct fy_document *fyd)
FY_EXPORT;
/**
* fy_node_create_mapping() - Create an empty mapping node.
*
* Create an empty mapping node associated with the given document.
*
* @fyd: The document which the resulting node will be associated with
*
* Returns:
* The created node, or NULL on error.
*/
struct fy_node *
fy_node_create_mapping(struct fy_document *fyd)
FY_EXPORT;
/**
* fy_node_set_tag() - Set the tag of node
*
* Manually set the tag of a node. The tag must be a valid one for
* the document the node belongs to.
*
* Note that the data are not copied, merely a reference is taken, so
* it must be available while the node is in use.
*
* If the node already contains a tag it will be overwriten.
*
* @fyn: The node to set it's tag.
* @data: Pointer to the tag data.
* @len: Size of the tag data, or (size_t)-1 for '\0' terminated.
*
* Returns:
* 0 on success, -1 on error.
*/
int
fy_node_set_tag(struct fy_node *fyn, const char *data, size_t len)
FY_EXPORT;
/**
* fy_node_remove_tag() - Remove the tag of node
*
* Remove the tag of a node.
*
* @fyn: The node to remove it's tag.
*
* Returns:
* 0 on success, -1 on error.
*/
int
fy_node_remove_tag(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_tag() - Get the tag of the node
*
* This method will return a pointer to the text of a tag
* along with the length of it. Note that this text is *not*
* NULL terminated.
*
* @fyn: The node
* @lenp: Pointer to a variable that will hold the returned length
*
* Returns:
* A pointer to the tag of the node, while @lenp will be assigned the
* length of said tag.
* A NULL will be returned in case of an error.
*/
const char *
fy_node_get_tag(struct fy_node *fyn, size_t *lenp)
FY_EXPORT;
/**
* fy_node_get_tag0() - Get the tag of the node
*
* This method will return a pointer to the text of a tag,
* which will be NULL terminated.
*
* @fyn: The node
*
* Returns:
* A pointer to the null terminated tag of the node.
* A NULL will be returned in case of an error.
*/
const char *
fy_node_get_tag0(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_tag_length() - Get the length of the tag of the node
*
* This method will return the size of the tag of the node.
* If the node is not tagged it will return 0.
*
* @fyn: The tagged node
*
* Returns:
* The size of the tag, or 0 if node is not tagged.
*/
size_t
fy_node_get_tag_length(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_scalar() - Get the scalar content of the node
*
* This method will return a pointer to the text of the scalar
* content of a node along with the length of it.
* Note that this pointer is *not* NULL terminated.
*
* @fyn: The scalar node
* @lenp: Pointer to a variable that will hold the returned length
*
* Returns:
* A pointer to the scalar content of the node, while @lenp will be assigned the
* length of said content.
* A NULL will be returned in case of an error, i.e. the node is not
* a scalar.
*/
const char *
fy_node_get_scalar(struct fy_node *fyn, size_t *lenp)
FY_EXPORT;
/**
* fy_node_get_scalar0() - Get the scalar content of the node
*
* This method will return a pointer to the text of the scalar
* content of a node as a null terminated string.
* Note that this call will allocate memory to hold the null terminated
* string so if possible use fy_node_get_scalar()
*
* @fyn: The scalar node
*
* Returns:
* A pointer to the scalar content of the node or NULL in returned in case of an error.
*/
const char *
fy_node_get_scalar0(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_scalar_length() - Get the length of the scalar content
*
* This method will return the size of the scalar content of the node.
* If the node is not a scalar it will return 0.
*
* @fyn: The scalar node
*
* Returns:
* The size of the scalar content, or 0 if node is not scalar.
*/
size_t
fy_node_get_scalar_length(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_scalar_utf8_length() - Get the length of the scalar content
* in utf8 characters
*
* This method will return the size of the scalar content of the node in
* utf8 characters.
* If the node is not a scalar it will return 0.
*
* @fyn: The scalar node
*
* Returns:
* The size of the scalar content in utf8 characters, or 0 if node is not scalar.
*/
size_t
fy_node_get_scalar_utf8_length(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_sequence_iterate() - Iterate over a sequence node
*
* This method iterates over all the item nodes in the sequence node.
* The start of the iteration is signalled by a NULL in \*prevp.
*
* @fyn: The sequence node
* @prevp: The previous sequence iterator
*
* Returns:
* The next node in sequence or NULL at the end of the sequence.
*/
struct fy_node *
fy_node_sequence_iterate(struct fy_node *fyn, void **prevp)
FY_EXPORT;
/**
* fy_node_sequence_reverse_iterate() - Iterate over a sequence node in reverse
*
* This method iterates in reverse over all the item nodes in the sequence node.
* The start of the iteration is signalled by a NULL in \*prevp.
*
* @fyn: The sequence node
* @prevp: The previous sequence iterator
*
* Returns:
* The next node in reverse sequence or NULL at the end of the sequence.
*/
struct fy_node *
fy_node_sequence_reverse_iterate(struct fy_node *fyn, void **prevp)
FY_EXPORT;
/**
* fy_node_sequence_item_count() - Return the item count of the sequence
*
* Get the item count of the sequence.
*
* @fyn: The sequence node
*
* Returns:
* The count of items in the sequence or -1 in case of an error.
*/
int
fy_node_sequence_item_count(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_sequence_is_empty() - Check whether the sequence is empty
*
* Check whether the sequence contains items.
*
* @fyn: The sequence node
*
* Returns:
* true if the node is a sequence containing items, false otherwise
*/
bool
fy_node_sequence_is_empty(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_sequence_get_by_index() - Return a sequence item by index
*
* Retrieve a node in the sequence using it's index. If index
* is positive or zero the count is from the start of the sequence,
* while if negative from the end. I.e. -1 returns the last item
* in the sequence.
*
* @fyn: The sequence node
* @index: The index of the node to retrieve.
* - >= 0 counting from the start
* - < 0 counting from the end
*
* Returns:
* The node at the specified index or NULL if no such item exist.
*/
struct fy_node *
fy_node_sequence_get_by_index(struct fy_node *fyn, int index)
FY_EXPORT;
/**
* fy_node_sequence_append() - Append a node item to a sequence
*
* Append a node item to a sequence.
*
* @fyn_seq: The sequence node
* @fyn: The node item to append
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_sequence_append(struct fy_node *fyn_seq, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_sequence_prepend() - Append a node item to a sequence
*
* Prepend a node item to a sequence.
*
* @fyn_seq: The sequence node
* @fyn: The node item to prepend
*
* Returns:
* 0 on success, -1 on error
*/
int fy_node_sequence_prepend(struct fy_node *fyn_seq, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_sequence_insert_before() - Insert a node item before another
*
* Insert a node item before another in the sequence.
*
* @fyn_seq: The sequence node
* @fyn_mark: The node item which the node will be inserted before.
* @fyn: The node item to insert in the sequence.
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_sequence_insert_before(struct fy_node *fyn_seq,
struct fy_node *fyn_mark, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_sequence_insert_after() - Insert a node item after another
*
* Insert a node item after another in the sequence.
*
* @fyn_seq: The sequence node
* @fyn_mark: The node item which the node will be inserted after.
* @fyn: The node item to insert in the sequence.
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_sequence_insert_after(struct fy_node *fyn_seq,
struct fy_node *fyn_mark, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_sequence_remove() - Remove an item from a sequence
*
* Remove a node item from a sequence and return it.
*
* @fyn_seq: The sequence node
* @fyn: The node item to remove from the sequence.
*
* Returns:
* The removed node item fyn, or NULL in case of an error.
*/
struct fy_node *
fy_node_sequence_remove(struct fy_node *fyn_seq, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_mapping_iterate() - Iterate over a mapping node
*
* This method iterates over all the node pairs in the mapping node.
* The start of the iteration is signalled by a NULL in \*prevp.
*
* Note that while a mapping is an unordered collection of key/values
* the order of which they are created is important for presentation
* purposes.
*
* @fyn: The mapping node
* @prevp: The previous sequence iterator
*
* Returns:
* The next node pair in the mapping or NULL at the end of the mapping.
*/
struct fy_node_pair *
fy_node_mapping_iterate(struct fy_node *fyn, void **prevp)
FY_EXPORT;
/**
* fy_node_mapping_reverse_iterate() - Iterate over a mapping node in reverse
*
* This method iterates in reverse over all the node pairs in the mapping node.
* The start of the iteration is signalled by a NULL in \*prevp.
*
* Note that while a mapping is an unordered collection of key/values
* the order of which they are created is important for presentation
* purposes.
*
* @fyn: The mapping node
* @prevp: The previous sequence iterator
*
* Returns:
* The next node pair in reverse sequence in the mapping or NULL at the end of the mapping.
*/
struct fy_node_pair *
fy_node_mapping_reverse_iterate(struct fy_node *fyn, void **prevp)
FY_EXPORT;
/**
* fy_node_mapping_item_count() - Return the node pair count of the mapping
*
* Get the count of the node pairs in the mapping.
*
* @fyn: The mapping node
*
* Returns:
* The count of node pairs in the mapping or -1 in case of an error.
*/
int
fy_node_mapping_item_count(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_mapping_is_empty() - Check whether the mapping is empty
*
* Check whether the mapping contains any node pairs.
*
* @fyn: The mapping node
*
* Returns:
* true if the node is a mapping containing node pairs, false otherwise
*/
bool
fy_node_mapping_is_empty(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_mapping_get_by_index() - Return a node pair by index
*
* Retrieve a node pair in the mapping using its index. If index
* is positive or zero the count is from the start of the sequence,
* while if negative from the end. I.e. -1 returns the last node pair
* in the mapping.
*
* @fyn: The mapping node
* @index: The index of the node pair to retrieve.
* - >= 0 counting from the start
* - < 0 counting from the end
*
* Returns:
* The node pair at the specified index or NULL if no such item exist.
*/
struct fy_node_pair *
fy_node_mapping_get_by_index(struct fy_node *fyn, int index)
FY_EXPORT;
/**
* fy_node_mapping_lookup_pair_by_string() - Lookup a node pair in mapping by string
*
* This method will return the node pair that contains the same key
* from the YAML node created from the @key argument. The comparison of the
* node is using fy_node_compare()
*
* @fyn: The mapping node
* @key: The YAML source to use as key
* @len: The length of the key (or -1 if '\0' terminated)
*
* Returns:
* The value matching the given key, or NULL if not found.
*/
struct fy_node_pair *
fy_node_mapping_lookup_pair_by_string(struct fy_node *fyn,
const char *key, size_t len)
FY_EXPORT;
/**
* fy_node_mapping_lookup_by_string() - Lookup a node value in mapping by string
*
* This method will return the value of node pair that contains the same key
* from the YAML node created from the @key argument. The comparison of the
* node is using fy_node_compare()
*
* @fyn: The mapping node
* @key: The YAML source to use as key
* @len: The length of the key (or -1 if '\0' terminated)
*
* Returns:
* The value matching the given key, or NULL if not found.
*/
struct fy_node *
fy_node_mapping_lookup_by_string(struct fy_node *fyn,
const char *key, size_t len)
FY_EXPORT;
/**
* fy_node_mapping_lookup_value_by_string() - Lookup a node value in mapping by string
*
* This method will return the value of node pair that contains the same key
* from the YAML node created from the @key argument. The comparison of the
* node is using fy_node_compare()
*
* It is synonymous with fy_node_mapping_lookup_by_string().
*
* @fyn: The mapping node
* @key: The YAML source to use as key
* @len: The length of the key (or -1 if '\0' terminated)
*
* Returns:
* The value matching the given key, or NULL if not found.
*/
struct fy_node *
fy_node_mapping_lookup_value_by_string(struct fy_node *fyn,
const char *key, size_t len)
FY_EXPORT;
/**
* fy_node_mapping_lookup_key_by_string() - Lookup a node key in mapping by string
*
* This method will return the key of node pair that contains the same key
* from the YAML node created from the @key argument. The comparison of the
* node is using fy_node_compare()
*
* @fyn: The mapping node
* @key: The YAML source to use as key
* @len: The length of the key (or -1 if '\0' terminated)
*
* Returns:
* The key matching the given key, or NULL if not found.
*/
struct fy_node *
fy_node_mapping_lookup_key_by_string(struct fy_node *fyn,
const char *key, size_t len)
FY_EXPORT;
/**
* fy_node_mapping_lookup_pair_by_simple_key() - Lookup a node pair in mapping by simple string
*
* This method will return the node pair that contains the same key
* from the YAML node created from the @key argument. The comparison of the
* node is using by comparing the strings for identity.
*
* @fyn: The mapping node
* @key: The string to use as key
* @len: The length of the key (or -1 if '\0' terminated)
*
* Returns:
* The node pair matching the given key, or NULL if not found.
*/
struct fy_node_pair *
fy_node_mapping_lookup_pair_by_simple_key(struct fy_node *fyn,
const char *key, size_t len)
FY_EXPORT;
/**
* fy_node_mapping_lookup_value_by_simple_key() - Lookup a node value in mapping by simple string
*
* This method will return the value of node pair that contains the same key
* from the YAML node created from the @key argument. The comparison of the
* node is using by comparing the strings for identity.
*
* @fyn: The mapping node
* @key: The string to use as key
* @len: The length of the key (or -1 if '\0' terminated)
*
* Returns:
* The value matching the given key, or NULL if not found.
*/
struct fy_node *
fy_node_mapping_lookup_value_by_simple_key(struct fy_node *fyn,
const char *key, size_t len)
FY_EXPORT;
/**
* fy_node_mapping_lookup_pair_by_null_key() - Lookup a node pair in mapping that has a NULL key
*
* This method will return the node pair that has a NULL key.
* Note this method is not using the mapping accelerator
* and arguably NULL keys should not exist. Alas...
*
* @fyn: The mapping node
*
* Returns:
* The node pair with a NULL key, NULL otherwise
*/
struct fy_node_pair *
fy_node_mapping_lookup_pair_by_null_key(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_mapping_lookup_value_by_null_key() - Lookup a node value with a NULL key.
*
* Return the value of a node pair that has a NULL key.
*
* @fyn: The mapping node
*
* Returns:
* The value matching the null key, NULL otherwise.
* Note that the value may be NULL too, but for that pathological case
* use the node pair method instead.
*/
struct fy_node *
fy_node_mapping_lookup_value_by_null_key(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_mapping_lookup_scalar_by_simple_key() - Lookup a scalar in mapping by simple string
*
* This method will return the scalar contents that contains the same key
* from the YAML node created from the @key argument. The comparison of the
* node is using by comparing the strings for identity.
*
* @fyn: The mapping node
* @lenp: Pointer to a variable that will hold the returned length
* @key: The string to use as key
* @keylen: The length of the key (or -1 if '\0' terminated)
*
* Returns:
* The scalar contents matching the given key, or NULL if not found.
*/
const char *
fy_node_mapping_lookup_scalar_by_simple_key(struct fy_node *fyn, size_t *lenp,
const char *key, size_t keylen)
FY_EXPORT;
/**
* fy_node_mapping_lookup_scalar0_by_simple_key() - Lookup a scalar in mapping by simple string
* returning a '\0' terminated scalar
*
* This method will return the NUL terminated scalar contents that contains the same key
* from the YAML node created from the @key argument. The comparison of the
* node is using by comparing the strings for identity.
*
* @fyn: The mapping node
* @key: The string to use as key
* @keylen: The length of the key (or -1 if '\0' terminated)
*
* Returns:
* The NUL terminated scalar contents matching the given key, or NULL if not found.
*/
const char *
fy_node_mapping_lookup_scalar0_by_simple_key(struct fy_node *fyn,
const char *key, size_t keylen)
FY_EXPORT;
/**
* fy_node_mapping_lookup_pair() - Lookup a node pair matching the provided key
*
* This method will return the node pair that matches the provided @fyn_key
*
* @fyn: The mapping node
* @fyn_key: The node to use as key
*
* Returns:
* The node pair matching the given key, or NULL if not found.
*/
struct fy_node_pair *
fy_node_mapping_lookup_pair(struct fy_node *fyn, struct fy_node *fyn_key)
FY_EXPORT;
/**
* fy_node_mapping_lookup_value_by_key() - Lookup a node pair's value matching the provided key
*
* This method will return the node pair that matches the provided @fyn_key
* The key may be collection and a content match check is performed recursively
* in order to find the right key.
*
* @fyn: The mapping node
* @fyn_key: The node to use as key
*
* Returns:
* The node value matching the given key, or NULL if not found.
*/
struct fy_node *
fy_node_mapping_lookup_value_by_key(struct fy_node *fyn, struct fy_node *fyn_key);
/**
* fy_node_mapping_lookup_key_by_key() - Lookup a node pair's key matching the provided key
*
* This method will return the node pair that matches the provided @fyn_key
* The key may be collection and a content match check is performed recursively
* in order to find the right key.
*
* @fyn: The mapping node
* @fyn_key: The node to use as key
*
* Returns:
* The node key matching the given key, or NULL if not found.
*/
struct fy_node *
fy_node_mapping_lookup_key_by_key(struct fy_node *fyn, struct fy_node *fyn_key);
/**
* fy_node_mapping_get_pair_index() - Return the node pair index in the mapping
*
* This method will return the node pair index in the mapping of the given
* node pair argument.
*
* @fyn: The mapping node
* @fynp: The node pair
*
* Returns:
* The index of the node pair in the mapping or -1 in case of an error.
*/
int
fy_node_mapping_get_pair_index(struct fy_node *fyn,
const struct fy_node_pair *fynp)
FY_EXPORT;
/**
* fy_node_pair_key() - Return the key of a node pair
*
* This method will return the node pair's key.
* Note that this may be NULL, which is returned also in case
* the node pair argument is NULL, so you should protect against
* such a case.
*
* @fynp: The node pair
*
* Returns:
* The node pair key
*/
struct fy_node *
fy_node_pair_key(struct fy_node_pair *fynp)
FY_EXPORT;
/**
* fy_node_pair_value() - Return the value of a node pair
*
* This method will return the node pair's value.
* Note that this may be NULL, which is returned also in case
* the node pair argument is NULL, so you should protect against
* such a case.
*
* @fynp: The node pair
*
* Returns:
* The node pair value
*/
struct fy_node *
fy_node_pair_value(struct fy_node_pair *fynp)
FY_EXPORT;
/**
* fy_node_pair_set_key() - Sets the key of a node pair
*
* This method will set the key part of the node pair.
* It will ovewrite any previous key.
*
* Note that no checks for duplicate keys are going to be
* performed.
*
* @fynp: The node pair
* @fyn: The key node
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_pair_set_key(struct fy_node_pair *fynp, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_pair_set_value() - Sets the value of a node pair
*
* This method will set the value part of the node pair.
* It will ovewrite any previous value.
*
* @fynp: The node pair
* @fyn: The value node
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_pair_set_value(struct fy_node_pair *fynp, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_mapping_append() - Append a node item to a mapping
*
* Append a node pair to a mapping.
*
* @fyn_map: The mapping node
* @fyn_key: The node pair's key
* @fyn_value: The node pair's value
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_mapping_append(struct fy_node *fyn_map,
struct fy_node *fyn_key, struct fy_node *fyn_value)
FY_EXPORT;
/**
* fy_node_mapping_prepend() - Prepend a node item to a mapping
*
* Prepend a node pair to a mapping.
*
* @fyn_map: The mapping node
* @fyn_key: The node pair's key
* @fyn_value: The node pair's value
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_mapping_prepend(struct fy_node *fyn_map,
struct fy_node *fyn_key, struct fy_node *fyn_value)
FY_EXPORT;
/**
* fy_node_mapping_remove() - Remove a node pair from a mapping
*
* Remove node pair from a mapping.
*
* @fyn_map: The mapping node
* @fynp: The node pair to remove
*
* Returns:
* 0 on success, -1 on failure.
*/
int
fy_node_mapping_remove(struct fy_node *fyn_map, struct fy_node_pair *fynp)
FY_EXPORT;
/**
* fy_node_mapping_remove_by_key() - Remove a node pair from a mapping returning the value
*
* Remove node pair from a mapping using the supplied key.
*
* @fyn_map: The mapping node
* @fyn_key: The node pair's key
*
* Returns:
* The value part of removed node pair, or NULL in case of an error.
*/
struct fy_node *
fy_node_mapping_remove_by_key(struct fy_node *fyn_map, struct fy_node *fyn_key)
FY_EXPORT;
/**
* fy_node_sort() - Recursively sort node
*
* Recursively sort all mappings of the given node, using the given
* comparison method (if NULL use the default one).
*
* @fyn: The node to sort
* @key_cmp: The comparison method
* @arg: An opaque user pointer for the comparison method
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_sort(struct fy_node *fyn, fy_node_mapping_sort_fn key_cmp, void *arg)
FY_EXPORT;
/**
* fy_node_vscanf() - Retrieve data via vscanf
*
* This method easily retrieves data using a familiar vscanf interface.
* The format string is a regular scanf format string with the following format.
*
* "pathspec %opt pathspec %opt..."
*
* Each pathspec is separated with space from the scanf option
*
* For example:
* fyn = { foo: 3 } -> fy_node_scanf(fyn, "/foo %d", &var) -> var = 3
*
*
* @fyn: The node to use as a pathspec root
* @fmt: The scanf based format string
* @ap: The va_list containing the arguments
*
* Returns:
* The number of scanned arguments, or -1 on error.
*/
int fy_node_vscanf(struct fy_node *fyn, const char *fmt, va_list ap);
/**
* fy_node_scanf() - Retrieve data via scanf
*
* This method easily retrieves data using a familiar vscanf interface.
* The format string is a regular scanf format string with the following format.
*
* "pathspec %opt pathspec %opt..."
*
* Each pathspec is separated with space from the scanf option
*
* For example:
* fyn = { foo: 3 } -> fy_node_scanf(fyn, "/foo %d", &var) -> var = 3
*
*
* @fyn: The node to use as a pathspec root
* @fmt: The scanf based format string
* @...: The arguments
*
* Returns:
* The number of scanned arguments, or -1 on error.
*/
int
fy_node_scanf(struct fy_node *fyn, const char *fmt, ...)
FY_FORMAT(scanf, 2, 3)
FY_EXPORT;
/**
* fy_document_vscanf() - Retrieve data via vscanf relative to document root
*
* This method easily retrieves data using a familiar vscanf interface.
* The format string is a regular scanf format string with the following format.
*
* "pathspec %opt pathspec %opt..."
*
* Each pathspec is separated with space from the scanf option
*
* For example:
* fyd = { foo: 3 } -> fy_document_scanf(fyd, "/foo %d", &var) -> var = 3
*
*
* @fyd: The document
* @fmt: The scanf based format string
* @ap: The va_list containing the arguments
*
* Returns:
* The number of scanned arguments, or -1 on error.
*/
int
fy_document_vscanf(struct fy_document *fyd, const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_document_scanf() - Retrieve data via scanf relative to document root
*
* This method easily retrieves data using a familiar vscanf interface.
* The format string is a regular scanf format string with the following format.
*
* "pathspec %opt pathspec %opt..."
*
* Each pathspec is separated with space from the scanf option
*
* For example:
* fyn = { foo: 3 } -> fy_node_scanf(fyd, "/foo %d", &var) -> var = 3
*
*
* @fyd: The document
* @fmt: The scanf based format string
* @...: The arguments
*
* Returns:
* The number of scanned arguments, or -1 on error.
*/
int
fy_document_scanf(struct fy_document *fyd, const char *fmt, ...)
FY_FORMAT(scanf, 2, 3)
FY_EXPORT;
/**
* fy_document_tag_directive_iterate() - Iterate over a document's tag directives
*
* This method iterates over all the documents tag directives.
* The start of the iteration is signalled by a NULL in \*prevp.
*
* @fyd: The document
* @prevp: The previous state of the iterator
*
* Returns:
* The next tag directive token in the document or NULL at the end of them.
*/
struct fy_token *
fy_document_tag_directive_iterate(struct fy_document *fyd, void **prevp)
FY_EXPORT;
/**
* fy_document_tag_directive_lookup() - Retreive a document's tag directive
*
* Retreives the matching tag directive token of the document matching the handle.
*
* @fyd: The document
* @handle: The handle to look for
*
* Returns:
* The tag directive token with the given handle or NULL if not found
*/
struct fy_token *
fy_document_tag_directive_lookup(struct fy_document *fyd, const char *handle)
FY_EXPORT;
/**
* fy_tag_directive_token_handle() - Get a tag directive handle
*
* Retreives the tag directives token handle value. Only valid on
* tag directive tokens.
*
* @fyt: The tag directive token
* @lenp: Pointer to a variable that will hold the returned length
*
* Returns:
* A pointer to the tag directive's handle, while @lenp will be assigned the
* length of said handle.
* A NULL will be returned in case of an error.
*/
const char *
fy_tag_directive_token_handle(struct fy_token *fyt, size_t *lenp)
FY_EXPORT;
/**
* fy_tag_directive_token_prefix() - Get a tag directive prefix
*
* Retreives the tag directives token prefix value. Only valid on
* tag directive tokens.
*
* @fyt: The tag directive token
* @lenp: Pointer to a variable that will hold the returned length
*
* Returns:
* A pointer to the tag directive's prefix, while @lenp will be assigned the
* length of said prefix.
* A NULL will be returned in case of an error.
*/
const char *
fy_tag_directive_token_prefix(struct fy_token *fyt, size_t *lenp)
FY_EXPORT;
/**
* fy_document_tag_directive_add() - Add a tag directive to a document
*
* Add tag directive to the document.
*
* @fyd: The document
* @handle: The handle of the tag directive
* @prefix: The prefix of the tag directive
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_document_tag_directive_add(struct fy_document *fyd,
const char *handle, const char *prefix)
FY_EXPORT;
/**
* fy_document_tag_directive_remove() - Remove a tag directive
*
* Remove a tag directive from a document.
* Note that removal is prohibited if any node is still using this tag directive.
*
* @fyd: The document
* @handle: The handle of the tag directive to remove.
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_document_tag_directive_remove(struct fy_document *fyd, const char *handle)
FY_EXPORT;
/**
* fy_document_lookup_anchor() - Lookup an anchor
*
* Lookup for an anchor having the name provided
*
* @fyd: The document
* @anchor: The anchor to look for
* @len: The length of the anchor (or -1 if '\0' terminated)
*
* Returns:
* The anchor if found, NULL otherwise
*/
struct fy_anchor *
fy_document_lookup_anchor(struct fy_document *fyd,
const char *anchor, size_t len)
FY_EXPORT;
/**
* fy_document_lookup_anchor_by_token() - Lookup an anchor by token text
*
* Lookup for an anchor having the name provided from the text of the token
*
* @fyd: The document
* @anchor: The token contains the anchor text to look for
*
* Returns:
* The anchor if found, NULL otherwise
*/
struct fy_anchor *
fy_document_lookup_anchor_by_token(struct fy_document *fyd,
struct fy_token *anchor)
FY_EXPORT;
/**
* fy_document_lookup_anchor_by_node() - Lookup an anchor by node
*
* Lookup for an anchor located in the given node
*
* @fyd: The document
* @fyn: The node
*
* Returns:
* The anchor if found, NULL otherwise
*/
struct fy_anchor *
fy_document_lookup_anchor_by_node(struct fy_document *fyd,
struct fy_node *fyn)
FY_EXPORT;
/**
* fy_anchor_get_text() - Get the text of an anchor
*
* This method will return a pointer to the text of an anchor
* along with the length of it. Note that this text is *not*
* NULL terminated.
*
* @fya: The anchor
* @lenp: Pointer to a variable that will hold the returned length
*
* Returns:
* A pointer to the text of the anchor, while @lenp will be assigned the
* length of said anchor.
* A NULL will be returned in case of an error.
*/
const char *
fy_anchor_get_text(struct fy_anchor *fya, size_t *lenp)
FY_EXPORT;
/**
* fy_anchor_node() - Get the node of an anchor
*
* This method returns the node associated with the anchor.
*
* @fya: The anchor
*
* Returns:
* The node of the anchor, or NULL in case of an error.
*/
struct fy_node *
fy_anchor_node(struct fy_anchor *fya)
FY_EXPORT;
/**
* fy_document_anchor_iterate() - Iterate over a document's anchors
*
* This method iterates over all the documents anchors.
* The start of the iteration is signalled by a NULL in \*prevp.
*
* @fyd: The document
* @prevp: The previous state of the iterator
*
* Returns:
* The next anchor in the document or NULL at the end of them.
*/
struct fy_anchor *
fy_document_anchor_iterate(struct fy_document *fyd, void **prevp)
FY_EXPORT;
/**
* fy_document_set_anchor() - Place an anchor
*
* Places an anchor to the node with the give text name.
*
* Note that the data are not copied, merely a reference is taken, so
* it must be available while the node is in use.
*
* Also not that this method is deprecated; use fy_node_set_anchor()
* instead.
*
* @fyd: The document
* @fyn: The node to set the anchor to
* @text: Pointer to the anchor text
* @len: Size of the anchor text, or (size_t)-1 for '\0' terminated.
*
* Returns:
* 0 on success, -1 on error.
*/
int
fy_document_set_anchor(struct fy_document *fyd, struct fy_node *fyn,
const char *text, size_t len)
FY_EXPORT FY_DEPRECATED;
/**
* fy_node_set_anchor() - Place an anchor to the node
*
* Places an anchor to the node with the give text name.
*
* Note that the data are not copied, merely a reference is taken, so
* it must be available while the node is in use.
*
* This is similar to fy_document_set_anchor() with the document set
* to the document of the @fyn node.
*
* @fyn: The node to set the anchor to
* @text: Pointer to the anchor text
* @len: Size of the anchor text, or (size_t)-1 for '\0' terminated.
*
* Returns:
* 0 on success, -1 on error.
*/
int
fy_node_set_anchor(struct fy_node *fyn, const char *text, size_t len)
FY_EXPORT;
/**
* fy_node_set_anchor_copy() - Place an anchor to the node copying the text
*
* Places an anchor to the node with the give text name, which
* will be copied, so it's safe to dispose the text after the call.
*
* @fyn: The node to set the anchor to
* @text: Pointer to the anchor text
* @len: Size of the anchor text, or (size_t)-1 for '\0' terminated.
*
* Returns:
* 0 on success, -1 on error.
*/
int
fy_node_set_anchor_copy(struct fy_node *fyn, const char *text, size_t len)
FY_EXPORT;
/**
* fy_node_set_vanchorf() - Place an anchor to the node using a vprintf interface.
*
* Places an anchor to the node with the give text name as created
* via vprintf'ing the arguments.
*
* @fyn: The node to set the anchor to
* @fmt: Pointer to the anchor format string
* @ap: The argument list.
*
* Returns:
* 0 on success, -1 on error.
*/
int
fy_node_set_vanchorf(struct fy_node *fyn, const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_node_set_anchorf() - Place an anchor to the node using a printf interface.
*
* Places an anchor to the node with the give text name as created
* via printf'ing the arguments.
*
* @fyn: The node to set the anchor to
* @fmt: Pointer to the anchor format string
* @...: The extra arguments.
*
* Returns:
* 0 on success, -1 on error.
*/
int
fy_node_set_anchorf(struct fy_node *fyn, const char *fmt, ...)
FY_FORMAT(printf, 2, 3)
FY_EXPORT;
/**
* fy_node_remove_anchor() - Remove an anchor
*
* Remove an anchor for the given node (if it exists)
*
* @fyn: The node to remove anchors from
*
* Returns:
* 0 on success, -1 on error.
*/
int
fy_node_remove_anchor(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_anchor() - Get the anchor of a node
*
* Retrieve the anchor of the given node (if it exists)
*
* @fyn: The node
*
* Returns:
* The anchor if there's one at the node, or NULL otherwise
*/
struct fy_anchor *
fy_node_get_anchor(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_nearest_anchor() - Get the nearest anchor of the node
*
* Retrieve the anchor of the nearest parent of the given node or
* the given node if it has one.
*
* @fyn: The node
*
* Returns:
* The nearest anchor if there's one, or NULL otherwise
*/
struct fy_anchor *
fy_node_get_nearest_anchor(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_get_nearest_child_of() - Get the nearest node which is a
* child of the base
*
* Retrieve the nearest node which is a child of fyn_base starting
* at fyn and working upwards.
*
* @fyn_base: The base node
* @fyn: The node to start from
*
* Returns:
* The nearest child of the base if there's one, or NULL otherwise
*/
struct fy_node *
fy_node_get_nearest_child_of(struct fy_node *fyn_base, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_create_alias() - Create an alias node
*
* Create an alias on the given document
*
* Note that the data are not copied, merely a reference is taken, so
* it must be available while the node is in use.
*
* @fyd: The document
* @alias: The alias text
* @len: The length of the alias (or -1 if '\0' terminated)
*
* Returns:
* The created alias node, or NULL in case of an error
*/
struct fy_node *
fy_node_create_alias(struct fy_document *fyd,
const char *alias, size_t len)
FY_EXPORT;
/**
* fy_node_create_alias_copy() - Create an alias node copying the data
*
* Create an alias on the given document
*
* A copy of the data will be made, so it is safe to free the data
* after the call.
*
* @fyd: The document
* @alias: The alias text
* @len: The length of the alias (or -1 if '\0' terminated)
*
* Returns:
* The created alias node, or NULL in case of an error
*/
struct fy_node *
fy_node_create_alias_copy(struct fy_document *fyd,
const char *alias, size_t len)
FY_EXPORT;
/**
* fy_node_get_meta() - Get the meta pointer of a node
*
* Return the meta pointer of a node.
*
* @fyn: The node to get meta data from
*
* Returns:
* The stored meta data pointer
*/
void *
fy_node_get_meta(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_set_meta() - Set the meta pointer of a node
*
* Set the meta pointer of a node. If @meta is NULL
* then clear the meta data.
*
* @fyn: The node to set meta data
* @meta: The meta data pointer
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_set_meta(struct fy_node *fyn, void *meta)
FY_EXPORT;
/**
* fy_node_clear_meta() - Clear the meta data of a node
*
* Clears the meta data of a node.
*
* @fyn: The node to clear meta data
*/
void
fy_node_clear_meta(struct fy_node *fyn)
FY_EXPORT;
/**
* typedef fy_node_meta_clear_fn - Meta data clear method
*
* This is the callback called when meta data are cleared.
*
* @fyn: The node which the meta data is being cleared
* @meta: The meta data of the node assigned via fy_node_set_meta()
* @user: The user pointer of fy_document_register_meta()
*
*/
typedef void (*fy_node_meta_clear_fn)(struct fy_node *fyn, void *meta, void *user);
/**
* fy_document_register_meta() - Register a meta cleanup hook
*
* Register a meta data cleanup hook, to be called when
* the node is freed via a final call to fy_node_free().
* The hook is active for all nodes belonging to the document.
*
* @fyd: The document which the hook is registered to
* @clear_fn: The clear hook method
* @user: Opaque user provided pointer to the clear method
*
* Returns:
* 0 on success, -1 if another hook is already registered.
*/
int
fy_document_register_meta(struct fy_document *fyd,
fy_node_meta_clear_fn clear_fn, void *user)
FY_EXPORT;
/**
* fy_document_unregister_meta() - Unregister a meta cleanup hook
*
* Unregister the currently active meta cleanup hook.
* The previous cleanup hook will be called for every node in
* the document.
*
* @fyd: The document to unregister it's meta cleanup hook.
*/
void
fy_document_unregister_meta(struct fy_document *fyd)
FY_EXPORT;
/**
* fy_node_set_marker() - Set a marker of a node
*
* Sets the marker of the given node, while returning
* the previous state of the marker. Note that the
* markers use the same space as the node follow markers.
*
* @fyn: The node
* @marker: The marker to set
*
* Returns:
* The previous value of the marker
*/
bool
fy_node_set_marker(struct fy_node *fyn, unsigned int marker)
FY_EXPORT;
/**
* fy_node_clear_marker() - Clear a marker of a node
*
* Clears the marker of the given node, while returning
* the previous state of the marker. Note that the
* markers use the same space as the node follow markers.
*
* @fyn: The node
* @marker: The marker to clear
*
* Returns:
* The previous value of the marker
*/
bool
fy_node_clear_marker(struct fy_node *fyn, unsigned int marker)
FY_EXPORT;
/**
* fy_node_is_marker_set() - Checks whether a marker is set
*
* Check the state of the given marker.
*
* @fyn: The node
* @marker: The marker index (must be less that FYNWF_MAX_USER_MARKER)
*
* Returns:
* The value of the marker (invalid markers return false)
*/
bool
fy_node_is_marker_set(struct fy_node *fyn, unsigned int marker)
FY_EXPORT;
/**
* fy_node_vreport() - Report about a node vprintf style
*
* Output a report about the given node via the specific
* error type, and using the reporting configuration of the node's
* document.
*
* @fyn: The node
* @type: The error type
* @fmt: The printf format string
* @ap: The argument list
*/
void
fy_node_vreport(struct fy_node *fyn, enum fy_error_type type,
const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_node_report() - Report about a node printf style
*
* Output a report about the given node via the specific
* error type, and using the reporting configuration of the node's
* document.
*
* @fyn: The node
* @type: The error type
* @fmt: The printf format string
* @...: The extra arguments.
*/
void
fy_node_report(struct fy_node *fyn, enum fy_error_type type,
const char *fmt, ...)
FY_FORMAT(printf, 3, 4)
FY_EXPORT;
/**
* fy_node_override_vreport() - Report about a node vprintf style,
* overriding file, line and column info
*
* Output a report about the given node via the specific
* error type, and using the reporting configuration of the node's
* document. This method will use the overrides provided in order
* to massage the reporting information.
* If @file is NULL, no file location will be reported.
* If either @line or @column is negative no location will be reported.
*
* @fyn: The node
* @type: The error type
* @file: The file override
* @line: The line override
* @column: The column override
* @fmt: The printf format string
* @ap: The argument list
*/
void
fy_node_override_vreport(struct fy_node *fyn, enum fy_error_type type,
const char *file, int line, int column,
const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_node_override_report() - Report about a node printf style,
* overriding file, line and column info
*
* Output a report about the given node via the specific
* error type, and using the reporting configuration of the node's
* document. This method will use the overrides provided in order
* to massage the reporting information.
* If @file is NULL, no file location will be reported.
* If either @line or @column is negative no location will be reported.
*
* @fyn: The node
* @type: The error type
* @file: The file override
* @line: The line override
* @column: The column override
* @fmt: The printf format string
* @...: The extra arguments.
*/
void
fy_node_override_report(struct fy_node *fyn, enum fy_error_type type,
const char *file, int line, int column,
const char *fmt, ...)
FY_FORMAT(printf, 6, 7)
FY_EXPORT;
/**
* fy_event_vreport() - Report about an event vprintf style
*
* Output a report about the given event via the specific
* error type, focusing at the given event part.
*
* @fyp: The parser of which the event was generated from
* @fye: The event
* @fyep: The event part which the report is about
* @type: The error type
* @fmt: The printf format string
* @ap: The argument list
*/
void
fy_event_vreport(struct fy_parser *fyp, struct fy_event *fye,
enum fy_event_part fyep, enum fy_error_type type,
const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_event_report() - Report about an event printf style
*
* Output a report about the given event via the specific
* error type, focusing at the given event part.
*
* @fyp: The parser of which the event was generated from
* @fye: The event
* @fyep: The event part which the report is about
* @type: The error type
* @fmt: The printf format string
* @...: The extra arguments.
*/
void
fy_event_report(struct fy_parser *fyp, struct fy_event *fye,
enum fy_event_part fyep, enum fy_error_type type,
const char *fmt, ...)
FY_FORMAT(printf, 5, 6)
FY_EXPORT;
typedef void (*fy_diag_output_fn)(struct fy_diag *diag, void *user,
const char *buf, size_t len);
/**
* struct fy_diag_cfg - The diagnostics configuration
*
* @fp: File descriptor of the error output
* @output_fn: Callback to use when fp is NULL
* @user: User pointer to pass to the output_fn
* @level: The minimum debugging level
* @module_mask: A bitmask of the enabled modules
* @colorize: true if output should be colorized using ANSI sequences
* @show_source: true if source location should be displayed
* @show_position: true if position should be displayed
* @show_type: true if the type should be displayed
* @show_module: true if the module should be displayed
* @source_width: Width of the source field
* @position_width: Width of the position field
* @type_width: Width of the type field
* @module_width: Width of the module field
*
* This structure contains the configuration of the
* diagnostic object.
*/
struct fy_diag_cfg {
FILE *fp;
fy_diag_output_fn output_fn;
void *user;
enum fy_error_type level;
unsigned int module_mask;
bool colorize : 1;
bool show_source : 1;
bool show_position : 1;
bool show_type : 1;
bool show_module : 1;
int source_width;
int position_width;
int type_width;
int module_width;
};
/**
* struct fy_diag_error - A collected diagnostic error
*
* @type: Error type
* @module: The module
* @fyt: The token (may be NULL)
* @msg: The message to be output alongside
* @file: The file which contained the input
* @line: The line at the error
* @column: The column at the error
*
* This structure contains information about an error
* being collected by the diagnostic object.
*/
struct fy_diag_error {
enum fy_error_type type;
enum fy_error_module module;
struct fy_token *fyt;
const char *msg;
const char *file;
int line;
int column;
};
/**
* fy_diag_create() - Create a diagnostic object
*
* Creates a diagnostic object using the provided configuration.
*
* @cfg: The configuration for the diagnostic object (NULL is default)
*
* Returns:
* A pointer to the diagnostic object or NULL in case of an error.
*/
struct fy_diag *
fy_diag_create(const struct fy_diag_cfg *cfg)
FY_EXPORT;
/**
* fy_diag_destroy() - Destroy a diagnostic object
*
* Destroy a diagnostic object; note that the actual
* destruction only occurs when no more references to the
* object are present. However no output will be generated
* after this call.
*
* @diag: The diagnostic object to destroy
*/
void
fy_diag_destroy(struct fy_diag *diag)
FY_EXPORT;
/**
* fy_diag_get_cfg() - Get a diagnostic object's configuration
*
* Return the current configuration of a diagnostic object
*
* @diag: The diagnostic object
*
* Returns:
* A const pointer to the diagnostic object configuration, or NULL
* in case where diag is NULL
*/
const struct fy_diag_cfg *
fy_diag_get_cfg(struct fy_diag *diag)
FY_EXPORT;
/**
* fy_diag_set_cfg() - Set a diagnostic object's configuration
*
* Replace the current diagnostic configuration with the given
* configuration passed as an argument.
*
* @diag: The diagnostic object
* @cfg: The diagnostic configuration
*/
void
fy_diag_set_cfg(struct fy_diag *diag, const struct fy_diag_cfg *cfg)
FY_EXPORT;
/**
* fy_diag_set_level() - Set a diagnostic object's debug error level
*
* @diag: The diagnostic object
* @level: The debugging level to set
*/
void
fy_diag_set_level(struct fy_diag *diag, enum fy_error_type level);
/**
* fy_diag_set_colorize() - Set a diagnostic object's colorize option
*
* @diag: The diagnostic object
* @colorize: The colorize option
*/
void
fy_diag_set_colorize(struct fy_diag *diag, bool colorize);
/**
* fy_diag_ref() - Increment that reference counter of a diagnostic object
*
* Increment the reference.
*
* @diag: The diagnostic object to reference
*
* Returns:
* Always returns the @diag argument
*/
struct fy_diag *
fy_diag_ref(struct fy_diag *diag)
FY_EXPORT;
/**
* fy_diag_unref() - Take away a ref from a diagnostic object
*
* Take away a reference, if it gets to 0, the diagnostic object
* is freed.
*
* @diag: The diagnostic object to unref
*/
void
fy_diag_unref(struct fy_diag *diag)
FY_EXPORT;
/**
* fy_diag_got_error() - Test whether an error level diagnostic
* has been produced
*
* Tests whether an error diagnostic has been produced.
*
* @diag: The diagnostic object
*
* Returns:
* true if an error has been produced, false otherwise
*/
bool
fy_diag_got_error(struct fy_diag *diag)
FY_EXPORT;
/**
* fy_diag_set_error() - Sets the error produced state
*
* Sets the error produced state
*
* @diag: The diagnostic object
* @on_error: The set error state
*/
void
fy_diag_set_error(struct fy_diag *diag, bool on_error)
FY_EXPORT;
/**
* fy_diag_reset_error() - Reset the error flag of
* the diagnostic object
*
* Clears the error flag which was set by an output
* of an error level diagnostic
*
* @diag: The diagnostic object
*/
void
fy_diag_reset_error(struct fy_diag *diag)
FY_EXPORT;
/**
* fy_diag_set_collect_errors() - Collect errors instead of outputting
*
* Set the collect errors mode. When true instead of outputting to
* the diagnostic interface, errors are collected for later
* retrieval.
*
* @diag: The diagnostic object
* @collect_errors: The collect errors mode
*/
void
fy_diag_set_collect_errors(struct fy_diag *diag, bool collect_errors)
FY_EXPORT;
/**
* fy_diag_cfg_default() - Fill in the configuration structure
* with defaults
*
* Fills the configuration structure with defaults. The default
* always associates the file descriptor to stderr.
*
* @cfg: The diagnostic configuration structure
*/
void
fy_diag_cfg_default(struct fy_diag_cfg *cfg)
FY_EXPORT;
/**
* fy_diag_cfg_from_parser_flags() - Fill partial diagnostic config
* structure from parser config flags
*
* Fills in part of the configuration structure using parser flags.
* Since the parser flags do not contain debugging flags anymore this
* method is deprecated.
*
* @cfg: The diagnostic configuration structure
* @pflags: The parser flags
*/
void
fy_diag_cfg_from_parser_flags(struct fy_diag_cfg *cfg,
enum fy_parse_cfg_flags pflags)
FY_EXPORT FY_DEPRECATED;
/**
* fy_diag_vprintf() - vprintf raw interface to diagnostics
*
* Raw output to the diagnostic object using a standard
* vprintf interface. Note that this is the lowest level
* interface, and as such is not recommended for use, since
* no formatting or coloring will take place.
*
* @diag: The diagnostic object to use
* @fmt: The vprintf format string
* @ap: The arguments
*
* Returns:
* The number of characters output, or -1 in case of an error
* Note that 0 shall be returned if the diagnostic object has
* been destroyed but not yet freed.
*/
int
fy_diag_vprintf(struct fy_diag *diag, const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_diag_printf() - printf raw interface to diagnostics
*
* Raw output to the diagnostic object using a standard
* printf interface. Note that this is the lowest level
* interface, and as such is not recommended for use, since
* no formatting or coloring will take place.
*
* @diag: The diagnostic object to use
* @fmt: The printf format string
* @...: The arguments
*
* Returns:
* The number of characters output, or -1 in case of an error
* Note that 0 shall be returned if the diagnostic object has
* been destroyed but not yet freed.
*/
int
fy_diag_printf(struct fy_diag *diag, const char *fmt, ...)
FY_FORMAT(printf, 2, 3)
FY_EXPORT;
/**
* struct fy_diag_ctx - The diagnostics context
*
* @level: The level of the diagnostic
* @module: The module of the diagnostic
* @source_func: The source function
* @source_file: The source file
* @source_line: The source line
* @file: The file that caused the error
* @line: The line where the diagnostic occured
* @column: The column where the diagnostic occured
*
* This structure contains the diagnostic context
*/
struct fy_diag_ctx {
enum fy_error_type level;
enum fy_error_module module;
const char *source_func;
const char *source_file;
int source_line;
const char *file;
int line;
int column;
};
/**
* fy_vdiag() - context aware diagnostic output like vprintf
*
* Context aware output to the diagnostic object using a standard
* vprintf interface.
*
* @diag: The diagnostic object to use
* @fydc: The diagnostic context
* @fmt: The vprintf format string
* @ap: The arguments
*
* Returns:
* The number of characters output, or -1 in case of an error
* Note that 0 shall be returned if the diagnostic object has
* been destroyed but not yet freed.
*/
int
fy_vdiag(struct fy_diag *diag, const struct fy_diag_ctx *fydc,
const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_diagf() - context aware diagnostic output like printf
*
* Context aware output to the diagnostic object using a standard
* printf interface.
*
* @diag: The diagnostic object to use
* @fydc: The diagnostic context
* @fmt: The vprintf format string
*
* Returns:
* The number of characters output, or -1 in case of an error
* Note that 0 shall be returned if the diagnostic object has
* been destroyed but not yet freed.
*/
int
fy_diagf(struct fy_diag *diag, const struct fy_diag_ctx *fydc,
const char *fmt, ...)
FY_FORMAT(printf, 3, 4)
FY_EXPORT;
#define fy_diag_diag(_diag, _level, _fmt, ...) \
({ \
struct fy_diag_ctx _ctx = { \
.level = (_level), \
.module = FYEM_UNKNOWN, \
.source_func = __func__, \
.source_file = __FILE__, \
.source_line = __LINE__, \
.file = NULL, \
.line = 0, \
.column = 0, \
}; \
fy_diagf((_diag), &_ctx, (_fmt) , ## __VA_ARGS__); \
})
#ifndef NDEBUG
#define fy_debug(_diag, _fmt, ...) \
fy_diag_diag((_diag), FYET_DEBUG, (_fmt) , ## __VA_ARGS__)
#else
#define fy_debug(_diag, _fmt, ...) \
do { } while(0)
#endif
#define fy_info(_diag, _fmt, ...) \
fy_diag_diag((_diag), FYET_INFO, (_fmt) , ## __VA_ARGS__)
#define fy_notice(_diag, _fmt, ...) \
fy_diag_diag((_diag), FYET_NOTICE, (_fmt) , ## __VA_ARGS__)
#define fy_warning(_diag, _fmt, ...) \
fy_diag_diag((_diag), FYET_WARNING, (_fmt) , ## __VA_ARGS__)
#define fy_error(_diag, _fmt, ...) \
fy_diag_diag((_diag), FYET_ERROR, (_fmt) , ## __VA_ARGS__)
/**
* fy_diag_token_vreport() - Report about a token vprintf style using
* the given diagnostic object
*
* Output a report about the given token via the specific
* error type, and using the reporting configuration of the token's
* document.
*
* @diag: The diag object
* @fyt: The token
* @type: The error type
* @fmt: The printf format string
* @ap: The argument list
*/
void
fy_diag_token_vreport(struct fy_diag *diag, struct fy_token *fyt,
enum fy_error_type type, const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_diag_token_report() - Report about a token printf style using
* the given diagnostic object
*
* Output a report about the given token via the specific
* error type, and using the reporting configuration of the token's
* document.
*
* @diag: The diag object
* @fye: The token
* @type: The error type
* @fmt: The printf format string
* @...: The extra arguments.
*/
void
fy_diag_token_report(struct fy_diag *diag, struct fy_token *fye,
enum fy_error_type type, const char *fmt, ...)
FY_FORMAT(printf, 4, 5)
FY_EXPORT;
/**
* fy_diag_token_override_vreport() - Report about a token vprintf style,
* overriding file, line and column info using
* the given diagnostic object
*
* Output a report about the given token via the specific
* error type, and using the reporting configuration of the token's
* document. This method will use the overrides provided in order
* to massage the reporting information.
* If @file is NULL, no file location will be reported.
* If either @line or @column is negative no location will be reported.
*
* @diag: The diag object
* @fyt: The token
* @type: The error type
* @file: The file override
* @line: The line override
* @column: The column override
* @fmt: The printf format string
* @ap: The argument list
*/
void
fy_diag_token_override_vreport(struct fy_diag *diag, struct fy_token *fyt,
enum fy_error_type type, const char *file,
int line, int column, const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_diag_token_override_report() - Report about a token printf style,
* overriding file, line and column info using
* the given diagnostic object
*
* Output a report about the given token via the specific
* error type, and using the reporting configuration of the token's
* document. This method will use the overrides provided in order
* to massage the reporting information.
* If @file is NULL, no file location will be reported.
* If either @line or @column is negative no location will be reported.
*
* @diag: The diag object
* @fyt: The token
* @type: The error type
* @file: The file override
* @line: The line override
* @column: The column override
* @fmt: The printf format string
* @...: The extra arguments.
*/
void
fy_diag_token_override_report(struct fy_diag *diag, struct fy_token *fyt,
enum fy_error_type type, const char *file,
int line, int column, const char *fmt, ...)
FY_FORMAT(printf, 7, 8)
FY_EXPORT;
/**
* fy_diag_node_vreport() - Report about a node vprintf style using
* the given diagnostic object
*
* Output a report about the given node via the specific
* error type, and using the reporting configuration of the node's
* document.
*
* @diag: The diag object
* @fyn: The node
* @type: The error type
* @fmt: The printf format string
* @ap: The argument list
*/
void
fy_diag_node_vreport(struct fy_diag *diag, struct fy_node *fyn,
enum fy_error_type type, const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_diag_node_report() - Report about a node printf style using
* the given diagnostic object
*
* Output a report about the given node via the specific
* error type, and using the reporting configuration of the node's
* document.
*
* @diag: The diag object
* @fyn: The node
* @type: The error type
* @fmt: The printf format string
* @...: The extra arguments.
*/
void
fy_diag_node_report(struct fy_diag *diag, struct fy_node *fyn,
enum fy_error_type type, const char *fmt, ...)
FY_FORMAT(printf, 4, 5)
FY_EXPORT;
/**
* fy_diag_node_override_vreport() - Report about a node vprintf style,
* overriding file, line and column info using
* the given diagnostic object
*
* Output a report about the given node via the specific
* error type, and using the reporting configuration of the node's
* document. This method will use the overrides provided in order
* to massage the reporting information.
* If @file is NULL, no file location will be reported.
* If either @line or @column is negative no location will be reported.
*
* @diag: The diag object
* @fyn: The node
* @type: The error type
* @file: The file override
* @line: The line override
* @column: The column override
* @fmt: The printf format string
* @ap: The argument list
*/
void
fy_diag_node_override_vreport(struct fy_diag *diag, struct fy_node *fyn,
enum fy_error_type type, const char *file,
int line, int column, const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_diag_node_override_report() - Report about a node printf style,
* overriding file, line and column info using
* the given diagnostic object
*
* Output a report about the given node via the specific
* error type, and using the reporting configuration of the node's
* document. This method will use the overrides provided in order
* to massage the reporting information.
* If @file is NULL, no file location will be reported.
* If either @line or @column is negative no location will be reported.
*
* @diag: The diag object
* @fyn: The node
* @type: The error type
* @file: The file override
* @line: The line override
* @column: The column override
* @fmt: The printf format string
* @...: The extra arguments.
*/
void
fy_diag_node_override_report(struct fy_diag *diag, struct fy_node *fyn,
enum fy_error_type type, const char *file,
int line, int column, const char *fmt, ...)
FY_FORMAT(printf, 7, 8)
FY_EXPORT;
/**
* fy_diag_event_vreport() - Report about an event vprintf style using
* the given diagnostic object
*
* Output a report about the given event part via the specific
* error type.
*
* @diag: The diag object
* @fye: The event
* @fyep: The event part
* @type: The error type
* @fmt: The printf format string
* @ap: The argument list
*/
void
fy_diag_event_vreport(struct fy_diag *diag, struct fy_event *fye,
enum fy_event_part fyep, enum fy_error_type type,
const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_diag_event_report() - Report about a event printf style using
* the given diagnostic object
*
* Output a report about the given event part via the specific
* error type.
*
* @diag: The diag object
* @fye: The event
* @fyep: The event part
* @type: The error type
* @fmt: The printf format string
* @...: The extra arguments.
*/
void
fy_diag_event_report(struct fy_diag *diag, struct fy_event *fye,
enum fy_event_part fyep, enum fy_error_type type,
const char *fmt, ...)
FY_FORMAT(printf, 5, 6)
FY_EXPORT;
/**
* fy_diag_event_override_vreport() - Report about a token vprintf style,
* overriding file, line and column info using
* the given diagnostic object
*
* Output a report about the given event part via the specific
* error type. This method will use the overrides provided in order
* to massage the reporting information.
* If @file is NULL, no file location will be reported.
* If either @line or @column is negative no location will be reported.
*
* @diag: The diag object
* @fye: The event
* @fyep: The event part
* @type: The error type
* @file: The file override
* @line: The line override
* @column: The column override
* @fmt: The printf format string
* @ap: The argument list
*/
void
fy_diag_event_override_vreport(struct fy_diag *diag, struct fy_event *fye,
enum fy_event_part fyep, enum fy_error_type type,
const char *file, int line, int column,
const char *fmt, va_list ap)
FY_EXPORT;
/**
* fy_diag_event_override_report() - Report about a token printf style,
* overriding file, line and column info using
* the given diagnostic object
*
* Output a report about the given event part via the specific
* error type. This method will use the overrides provided in order
* to massage the reporting information.
* If @file is NULL, no file location will be reported.
* If either @line or @column is negative no location will be reported.
*
* @diag: The diag object
* @fyt: The event
* @fyep: The event part
* @type: The error type
* @file: The file override
* @line: The line override
* @column: The column override
* @fmt: The printf format string
* @...: The extra arguments.
*/
void
fy_diag_event_override_report(struct fy_diag *diag, struct fy_token *fyt,
enum fy_event_part fyep, enum fy_error_type type,
const char *file, int line, int column,
const char *fmt, ...)
FY_FORMAT(printf, 8, 9)
FY_EXPORT;
/**
* fy_diag_errors_iterate() - Iterate over the errors of a diagnostic object
*
* This method iterates over all the errors collected on the diagnostic object.
* The start of the iteration is signalled by a NULL in \*prevp.
*
* @diag: The diagnostic object
* @prevp: The previous result iterator
*
* Returns:
* The next errors or NULL when there are not any more.
*/
struct fy_diag_error *
fy_diag_errors_iterate(struct fy_diag *diag, void **prevp)
FY_EXPORT;
/**
* enum fy_path_parse_cfg_flags - Path parse configuration flags
*
* These flags control the operation of the path parse
*
* @FYPPCF_QUIET: Quiet, do not output any information messages
* @FYPPCF_DISABLE_RECYCLING: Disable recycling optimization
* @FYPPCF_DISABLE_ACCELERATORS: Disable use of access accelerators (saves memory)
*/
enum fy_path_parse_cfg_flags {
FYPPCF_QUIET = FY_BIT(0),
FYPPCF_DISABLE_RECYCLING = FY_BIT(1),
FYPPCF_DISABLE_ACCELERATORS = FY_BIT(2),
};
/**
* struct fy_path_parse_cfg - path parser configuration structure.
*
* Argument to the fy_path_parser_create() method which
* performs parsing of a ypath expression
*
* @flags: Configuration flags
* @userdata: Opaque user data pointer
* @diag: Optional diagnostic interface to use
*/
struct fy_path_parse_cfg {
enum fy_path_parse_cfg_flags flags;
void *userdata;
struct fy_diag *diag;
};
/**
* fy_path_parser_create() - Create a ypath parser.
*
* Creates a path parser with its configuration @cfg
* The path parser may be destroyed by a corresponding call to
* fy_path_parser_destroy().
* If @cfg is NULL a default yaml parser is created.
*
* @cfg: The configuration for the path parser
*
* Returns:
* A pointer to the path parser or NULL in case of an error.
*/
struct fy_path_parser *
fy_path_parser_create(const struct fy_path_parse_cfg *cfg)
FY_EXPORT;
/**
* fy_path_parser_destroy() - Destroy the given path parser
*
* Destroy a path parser created earlier via fy_path_parser_create().
*
* @fypp: The path parser to destroy
*/
void
fy_path_parser_destroy(struct fy_path_parser *fypp)
FY_EXPORT;
/**
* fy_path_parser_reset() - Reset a path parser completely
*
* Completely reset a path parser, including after an error
* that caused a parser error to be emitted.
*
* @fypp: The path parser to reset
*
* Returns:
* 0 if the reset was successful, -1 otherwise
*/
int
fy_path_parser_reset(struct fy_path_parser *fypp)
FY_EXPORT;
/**
* fy_path_parse_expr_from_string() - Parse an expression from a given string
*
* Create a path expression from a string using the provided path parser.
*
* @fypp: The path parser to use
* @str: The ypath source to use.
* @len: The length of the string (or -1 if '\0' terminated)
*
* Returns:
* The created path expression or NULL on error.
*/
struct fy_path_expr *
fy_path_parse_expr_from_string(struct fy_path_parser *fypp,
const char *str, size_t len)
FY_EXPORT;
/**
* fy_path_expr_build_from_string() - Parse an expression from a given string
*
* Create a path expression from a string using the provided path parser
* configuration.
*
* @pcfg: The path parser configuration to use, or NULL for default
* @str: The ypath source to use.
* @len: The length of the string (or -1 if '\0' terminated)
*
* Returns:
* The created path expression or NULL on error.
*/
struct fy_path_expr *
fy_path_expr_build_from_string(const struct fy_path_parse_cfg *pcfg,
const char *str, size_t len)
FY_EXPORT;
/**
* fy_path_expr_free() - Free a path expression
*
* Free a previously returned expression from any of the path parser
* methods like fy_path_expr_build_from_string()
*
* @expr: The expression to free (may be NULL)
*/
void
fy_path_expr_free(struct fy_path_expr *expr)
FY_EXPORT;
/**
* fy_path_expr_dump() - Dump the contents of a path expression to
* the diagnostic object
*
* Dumps the expression using the provided error level.
*
* @expr: The expression to dump
* @diag: The diagnostic object to use
* @errlevel: The error level which the diagnostic will use
* @level: The nest level; should be set to 0
* @banner: The banner to display on level 0
*/
void
fy_path_expr_dump(struct fy_path_expr *expr, struct fy_diag *diag,
enum fy_error_type errlevel, int level, const char *banner)
FY_EXPORT;
/**
* fy_path_expr_to_document() - Converts the path expression to a YAML document
*
* Converts the expression to a YAML document which is useful for
* understanding what the expression evaluates to.
*
* @expr: The expression to convert to a document
*
* Returns:
* The document of the expression or NULL on error.
*/
struct fy_document *
fy_path_expr_to_document(struct fy_path_expr *expr)
FY_EXPORT;
/**
* enum fy_path_exec_cfg_flags - Path executor configuration flags
*
* These flags control the operation of the path expression executor
*
* @FYPXCF_QUIET: Quiet, do not output any information messages
* @FYPXCF_DISABLE_RECYCLING: Disable recycling optimization
* @FYPXCF_DISABLE_ACCELERATORS: Disable use of access accelerators (saves memory)
*/
enum fy_path_exec_cfg_flags {
FYPXCF_QUIET = FY_BIT(0),
FYPXCF_DISABLE_RECYCLING = FY_BIT(1),
FYPXCF_DISABLE_ACCELERATORS = FY_BIT(2),
};
/**
* struct fy_path_exec_cfg - path expression executor configuration structure.
*
* Argument to the fy_path_exec_create() method which
* performs execution of a ypath expression
*
* @flags: Configuration flags
* @userdata: Opaque user data pointer
* @diag: Optional diagnostic interface to use
*/
struct fy_path_exec_cfg {
enum fy_path_exec_cfg_flags flags;
void *userdata;
struct fy_diag *diag;
};
/**
* fy_path_exec_create() - Create a ypath expression executor.
*
* Creates a ypath expression parser with its configuration @cfg
* The executor may be destroyed by a corresponding call to
* fy_path_exec_destroy().
*
* @xcfg: The configuration for the executor
*
* Returns:
* A pointer to the executor or NULL in case of an error.
*/
struct fy_path_exec *
fy_path_exec_create(const struct fy_path_exec_cfg *xcfg)
FY_EXPORT;
/**
* fy_path_exec_destroy() - Destroy the given path expression executor
*
* Destroy ane executor created earlier via fy_path_exec_create().
*
* @fypx: The path parser to destroy
*/
void
fy_path_exec_destroy(struct fy_path_exec *fypx)
FY_EXPORT;
/**
* fy_path_exec_reset() - Reset an executor
*
* Completely reset an executor without releasing it.
*
* @fypx: The executor to reset
*
* Returns:
* 0 if the reset was successful, -1 otherwise
*/
int
fy_path_exec_reset(struct fy_path_exec *fypx)
FY_EXPORT;
/**
* fy_path_exec_execute() - Execute a path expression starting at
* the given start node
*
* Execute the expression starting at fyn_start. If execution
* is successful the results are available via fy_path_exec_results_iterate()
*
* Note that it is illegal to modify the state of the document that the
* results reside between this call and the results collection.
*
* @fypx: The executor to use
* @expr: The expression to use
* @fyn_start: The node on which the expression will begin.
*
* Returns:
* 0 if the execution was successful, -1 otherwise
*
* Note that the execution may be successful but no results were
* produced, in which case the iterator will return NULL.
*/
int
fy_path_exec_execute(struct fy_path_exec *fypx, struct fy_path_expr *expr,
struct fy_node *fyn_start)
FY_EXPORT;
/**
* fy_path_exec_results_iterate() - Iterate over the results of execution
*
* This method iterates over all the results in the executor.
* The start of the iteration is signalled by a NULL in \*prevp.
*
* @fypx: The executor
* @prevp: The previous result iterator
*
* Returns:
* The next node in the result set or NULL at the end of the results.
*/
struct fy_node *
fy_path_exec_results_iterate(struct fy_path_exec *fypx, void **prevp)
FY_EXPORT;
/*
* Helper methods for binding implementers
* Note that users of the library do not need to know these details.
* However bindings that were developed against libyaml expect these
* to be exported, so provide a shim here
*/
/**
* enum fy_token_type - Token types
*
* @FYTT_NONE: No token
* @FYTT_STREAM_START: Stream start token
* @FYTT_STREAM_END: Stream end token
* @FYTT_VERSION_DIRECTIVE: Version directive token
* @FYTT_TAG_DIRECTIVE: Tag directive token
* @FYTT_DOCUMENT_START: Document start token
* @FYTT_DOCUMENT_END: Document end token
* @FYTT_BLOCK_SEQUENCE_START: Block sequence start token
* @FYTT_BLOCK_MAPPING_START: Block mapping start token
* @FYTT_BLOCK_END: Block end token
* @FYTT_FLOW_SEQUENCE_START: Flow sequence start token
* @FYTT_FLOW_SEQUENCE_END: Flow sequence end token
* @FYTT_FLOW_MAPPING_START: Flow mapping start token
* @FYTT_FLOW_MAPPING_END: Flow mapping end token
* @FYTT_BLOCK_ENTRY: Block entry token
* @FYTT_FLOW_ENTRY: Flow entry token
* @FYTT_KEY: Key token
* @FYTT_VALUE: Value token
* @FYTT_ALIAS: Alias token
* @FYTT_ANCHOR: Anchor token
* @FYTT_TAG: Tag token
* @FYTT_SCALAR: Scalar token
* @FYTT_INPUT_MARKER: Input marker token
* @FYTT_PE_SLASH: Path expression slash token
* @FYTT_PE_ROOT: Path expression root token
* @FYTT_PE_THIS: Path expression this token
* @FYTT_PE_PARENT: Path expression parent token
* @FYTT_PE_MAP_KEY: Path expression map key token
* @FYTT_PE_SEQ_INDEX: Path expression sequence index token
* @FYTT_PE_SEQ_SLICE: Path expression sequence slice token
* @FYTT_PE_SCALAR_FILTER: Path expression scalar filter token
* @FYTT_PE_COLLECTION_FILTER: Path expression collection filter token
* @FYTT_PE_SEQ_FILTER: Path expression sequence filter token
* @FYTT_PE_MAP_FILTER: Path expression map filter token
* @FYTT_PE_UNIQUE_FILTER: Path expression unique filter token
* @FYTT_PE_EVERY_CHILD: Path expression every child token
* @FYTT_PE_EVERY_CHILD_R: Path expression every child recursive token
* @FYTT_PE_ALIAS: Path expression alias token
* @FYTT_PE_SIBLING: Path expression sibling token
* @FYTT_PE_COMMA: Path expression comma token
* @FYTT_PE_BARBAR: Path expression || token
* @FYTT_PE_AMPAMP: Path expression && token
* @FYTT_PE_LPAREN: Path expression ( token
* @FYTT_PE_RPAREN: Path expression ) token
* @FYTT_PE_EQEQ: Path expression == token
* @FYTT_PE_NOTEQ: Path expression != token
* @FYTT_PE_LT: Path expression < token
* @FYTT_PE_GT: Path expression > token
* @FYTT_PE_LTE: Path expression <= token
* @FYTT_PE_GTE: Path expression >= token
* @FYTT_SE_PLUS: Scalar expression + token
* @FYTT_SE_MINUS: Scalar expression - token
* @FYTT_SE_MULT: Scalar expression \* token
* @FYTT_SE_DIV: Scalar expression / token
* @FYTT_PE_METHOD: Path expression method token
* @FYTT_SE_METHOD: Scalar expression method token
* @FYTT_PE_BANG: Path expression ! token
* @FYTT_PE_AT: Path expression \@ token
*/
enum fy_token_type {
/* non-content token types */
FYTT_NONE,
FYTT_STREAM_START,
FYTT_STREAM_END,
FYTT_VERSION_DIRECTIVE,
FYTT_TAG_DIRECTIVE,
FYTT_DOCUMENT_START,
FYTT_DOCUMENT_END,
/* content token types */
FYTT_BLOCK_SEQUENCE_START,
FYTT_BLOCK_MAPPING_START,
FYTT_BLOCK_END,
FYTT_FLOW_SEQUENCE_START,
FYTT_FLOW_SEQUENCE_END,
FYTT_FLOW_MAPPING_START,
FYTT_FLOW_MAPPING_END,
FYTT_BLOCK_ENTRY,
FYTT_FLOW_ENTRY,
FYTT_KEY,
FYTT_VALUE,
FYTT_ALIAS,
FYTT_ANCHOR,
FYTT_TAG,
FYTT_SCALAR,
/* special error reporting */
FYTT_INPUT_MARKER,
/* path expression tokens */
FYTT_PE_SLASH,
FYTT_PE_ROOT,
FYTT_PE_THIS,
FYTT_PE_PARENT,
FYTT_PE_MAP_KEY,
FYTT_PE_SEQ_INDEX,
FYTT_PE_SEQ_SLICE,
FYTT_PE_SCALAR_FILTER,
FYTT_PE_COLLECTION_FILTER,
FYTT_PE_SEQ_FILTER,
FYTT_PE_MAP_FILTER,
FYTT_PE_UNIQUE_FILTER,
FYTT_PE_EVERY_CHILD,
FYTT_PE_EVERY_CHILD_R,
FYTT_PE_ALIAS,
FYTT_PE_SIBLING,
FYTT_PE_COMMA,
FYTT_PE_BARBAR,
FYTT_PE_AMPAMP,
FYTT_PE_LPAREN,
FYTT_PE_RPAREN,
/* comparison operators */
FYTT_PE_EQEQ,
FYTT_PE_NOTEQ,
FYTT_PE_LT,
FYTT_PE_GT,
FYTT_PE_LTE,
FYTT_PE_GTE,
/* scalar expression tokens */
FYTT_SE_PLUS,
FYTT_SE_MINUS,
FYTT_SE_MULT,
FYTT_SE_DIV,
FYTT_PE_METHOD,
FYTT_SE_METHOD,
FYTT_PE_BANG,
FYTT_PE_AT,
};
/* The number of token types available */
#define FYTT_COUNT (FYTT_PE_AT+1)
/**
* fy_token_type_is_valid() - Check token type validity
*
* Check if argument token type is a valid one.
*
* @type: The token type
*
* Returns:
* true if the token type is valid, false otherwise
*/
static inline bool
fy_token_type_is_valid(enum fy_token_type type)
{
return type >= FYTT_NONE && type < FYTT_COUNT;
}
/**
* fy_token_type_is_yaml() - Check if token type is valid for YAML
*
* Check if argument token type is a valid YAML one.
*
* @type: The token type
*
* Returns:
* true if the token type is a valid YAML one, false otherwise
*/
static inline bool
fy_token_type_is_yaml(enum fy_token_type type)
{
return type >= FYTT_STREAM_START && type <= FYTT_SCALAR;
}
/**
* fy_token_type_is_content() - Check if token type is
* valid for YAML content
*
* Check if argument token type is a valid YAML content one.
*
* @type: The token type
*
* Returns:
* true if the token type is a valid YAML content one, false otherwise
*/
static inline bool
fy_token_type_is_content(enum fy_token_type type)
{
return type >= FYTT_BLOCK_SEQUENCE_START && type <= FYTT_SCALAR;
}
/**
* fy_token_type_is_path_expr() - Check if token type is
* valid for a YPATH expression
*
* Check if argument token type is a valid YPATH parse expression token
*
* @type: The token type
*
* Returns:
* true if the token type is a valid YPATH one, false otherwise
*/
static inline bool
fy_token_type_is_path_expr(enum fy_token_type type)
{
return type >= FYTT_PE_SLASH && type <= FYTT_PE_GTE;
}
/**
* fy_token_type_is_scalar_expr() - Check if token type is
* valid for a YPATH scalar expression
*
* Check if argument token type is a valid YPATH parse scalar expression token
*
* @type: The token type
*
* Returns:
* true if the token type is a valid YPATH scalar one, false otherwise
*/
static inline bool
fy_token_type_is_scalar_expr(enum fy_token_type type)
{
return type >= FYTT_SE_PLUS && type <= FYTT_SE_DIV;
}
/**
* fy_token_get_type() - Return the token's type
*
* Return the token's type; if NULL then FYTT_NONE is returned
*
* @fyt: The token
*
* Returns:
* The token's type; FYTT_NONE if not a valid token (or NULL)
*/
enum fy_token_type
fy_token_get_type(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_token_start_mark() - Get token's start marker
*
* Return the token's start marker if it exists. Note
* it is permissable for some token types to have no
* start marker because they are without content.
*
* @fyt: The token to get its start marker
*
* Returns:
* The token's start marker, NULL if not available.
*/
const struct fy_mark *
fy_token_start_mark(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_token_end_mark() - Get token's end marker
*
* Return the token's end marker if it exists. Note
* it is permissable for some token types to have no
* end marker because they are without content.
*
* @fyt: The token to get its end marker
*
* Returns:
* The token's end marker, NULL if not available.
*/
const struct fy_mark *
fy_token_end_mark(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_scan() - Low level access to the scanner
*
* Return the next scanner token. Note this is a very
* low level interface, intended for users that want/need
* to implement their own YAML parser. The returned
* token is expected to be disposed using fy_scan_token_free()
*
* @fyp: The parser to get the next token from.
*
* Returns:
* The next token, or NULL if no more tokens are available.
*/
struct fy_token *
fy_scan(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_scan_token_free() - Free the token returned by fy_scan()
*
* Free the token returned by fy_scan().
*
* @fyp: The parser of which the token was returned by fy_scan()
* @fyt: The token to free
*/
void
fy_scan_token_free(struct fy_parser *fyp, struct fy_token *fyt)
FY_EXPORT;
/**
* fy_tag_directive_token_prefix0() - Get the prefix contained in the
* tag directive token as zero terminated
* string
*
* Retrieve the tag directive's prefix contents as a zero terminated string.
* It is similar to fy_tag_directive_token_prefix(), with the difference
* that the returned string is zero terminated and memory may be allocated
* to hold it associated with the token.
*
* @fyt: The tag directive token out of which the prefix pointer
* will be returned.
*
* Returns:
* A pointer to the zero terminated text representation of the prefix token.
* NULL in case of an error.
*/
const char *
fy_tag_directive_token_prefix0(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_tag_directive_token_handle0() - Get the handle contained in the
* tag directive token as zero terminated
* string
*
* Retrieve the tag directive's handle contents as a zero terminated string.
* It is similar to fy_tag_directive_token_handle(), with the difference
* that the returned string is zero terminated and memory may be allocated
* to hold it associated with the token.
*
* @fyt: The tag directive token out of which the handle pointer
* will be returned.
*
* Returns:
* A pointer to the zero terminated text representation of the handle token.
* NULL in case of an error.
*/
const char *
fy_tag_directive_token_handle0(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_tag_token_handle() - Get the handle contained in the
* tag token
*
* Retrieve the tag handle contents. Will fail if
* token is not a tag token, or if a memory error happens.
*
* @fyt: The tag token out of which the handle pointer
* will be returned.
* @lenp: Pointer to a variable that will hold the returned length
*
* Returns:
* A pointer to the text representation of the handle token, while
* @lenp will be assigned the character length of said representation.
* NULL in case of an error.
*/
const char *
fy_tag_token_handle(struct fy_token *fyt, size_t *lenp)
FY_EXPORT;
/**
* fy_tag_token_suffix() - Get the suffix contained in the
* tag token
*
* Retrieve the tag suffix contents. Will fail if
* token is not a tag token, or if a memory error happens.
*
* @fyt: The tag token out of which the suffix pointer
* will be returned.
* @lenp: Pointer to a variable that will hold the returned length
*
* Returns:
* A pointer to the text representation of the suffix token, while
* @lenp will be assigned the character length of said representation.
* NULL in case of an error.
*/
const char *
fy_tag_token_suffix(struct fy_token *fyt, size_t *lenp)
FY_EXPORT;
/**
* fy_tag_token_short() - Get the short tag of the tag token
*
* Retrieve the short tag contents. The short tag is the same
* one that will need to be emitted.
* Will fail if token is not a tag token, or if a memory error happens.
*
* @fyt: The tag token out of which the short pointer
* will be returned.
* @lenp: Pointer to a variable that will hold the returned length
*
* Returns:
* A pointer to the text representation of the short tag, while
* @lenp will be assigned the character length of said representation.
* NULL in case of an error.
*/
const char *
fy_tag_token_short(struct fy_token *fyt, size_t *lenp)
FY_EXPORT;
/**
* fy_tag_token_handle0() - Get the handle contained in the
* tag token as zero terminated string
*
* Retrieve the tag handle contents as a zero terminated string.
* It is similar to fy_tag_token_handle(), with the difference
* that the returned string is zero terminated and memory may be allocated
* to hold it associated with the token.
*
* @fyt: The tag token out of which the handle pointer will be returned.
*
* Returns:
* A pointer to the zero terminated text representation of the handle token.
* NULL in case of an error.
*/
const char *
fy_tag_token_handle0(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_tag_token_short0() - Get the short tag of the tag token as zero
* terminated string.
*
* Retrieve the short tag contents. The short tag is the same
* one that will need to be emitted.
* Will fail if token is not a tag token, or if a memory error happens.
*
* @fyt: The tag token out of which the short pointer will be returned.
*
* Returns:
* A pointer to the null terminated text representation of the short tag.
* NULL in case of an error.
*/
const char *
fy_tag_token_short0(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_tag_token_suffix0() - Get the suffix contained in the
* tag token as zero terminated string
*
* Retrieve the tag suffix contents as a zero terminated string.
* It is similar to fy_tag_token_suffix(), with the difference
* that the returned string is zero terminated and memory may be allocated
* to hold it associated with the token.
*
* @fyt: The tag token out of which the suffix pointer will be returned.
*
* Returns:
* A pointer to the zero terminated text representation of the suffix token.
* NULL in case of an error.
*/
const char *
fy_tag_token_suffix0(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_version_directive_token_version() - Return the version of a version
* directive token
*
* Retrieve the version stored in a version directive token.
*
* @fyt: The version directive token
*
* Returns:
* A pointer to the version stored in the version directive token, or
* NULL in case of an error, or the token not being a version directive token.
*/
const struct fy_version *
fy_version_directive_token_version(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_scalar_token_get_style() - Return the style of a scalar token
*
* Retrieve the style of a scalar token.
*
* @fyt: The scalar token
*
* Returns:
* The scalar style of the token, or FYSS_ANY for an error
*/
enum fy_scalar_style
fy_scalar_token_get_style(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_tag_token_tag() - Get tag of a tag token
*
* Retrieve the tag of a tag token.
*
* @fyt: The tag token
*
* Returns:
* A pointer to the tag or NULL in case of an error
*/
const struct fy_tag *
fy_tag_token_tag(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_tag_directive_token_tag() - Get tag of a tag directive token
*
* Retrieve the tag of a tag directive token.
*
* @fyt: The tag directive token
*
* Returns:
* A pointer to the tag or NULL in case of an error
*/
const struct fy_tag *
fy_tag_directive_token_tag(struct fy_token *fyt)
FY_EXPORT;
/**
* fy_event_get_token() - Return the main token of an event
*
* Retrieve the main token (i.e. not the tag or the anchor) of
* an event. It may be NULL in case of an implicit event.
*
* @fye: The event to get its main token
*
* Returns:
* The main token if it exists, NULL otherwise or in case of an error
*/
struct fy_token *
fy_event_get_token(struct fy_event *fye)
FY_EXPORT;
/**
* fy_event_get_anchor_token() - Return the anchor token of an event
*
* Retrieve the anchor token if it exists. Only valid for
* mapping/sequence start and scalar events.
*
* @fye: The event to get its anchor token
*
* Returns:
* The anchor token if it exists, NULL otherwise or in case of an error
*/
struct fy_token *
fy_event_get_anchor_token(struct fy_event *fye)
FY_EXPORT;
/**
* fy_event_get_tag_token() - Return the tag token of an event
*
* Retrieve the tag token if it exists. Only valid for
* mapping/sequence start and scalar events.
*
* @fye: The event to get its tag token
*
* Returns:
* The tag token if it exists, NULL otherwise or in case of an error
*/
struct fy_token *
fy_event_get_tag_token(struct fy_event *fye)
FY_EXPORT;
/**
* fy_event_start_mark() - Get event's start marker
*
* Return the event's start marker if it exists. The
* start marker is the one of the event's main token.
*
* @fye: The event to get its start marker
*
* Returns:
* The event's start marker, NULL if not available.
*/
const struct fy_mark *
fy_event_start_mark(struct fy_event *fye)
FY_EXPORT;
/**
* fy_event_end_mark() - Get event's end marker
*
* Return the event's end marker if it exists. The
* end marker is the one of the event's main token.
*
* @fye: The event to get its end marker
*
* Returns:
* The event's end marker, NULL if not available.
*/
const struct fy_mark *
fy_event_end_mark(struct fy_event *fye)
FY_EXPORT;
/**
* fy_event_get_node_style() - Get the node style of an event
*
* Return the node style (FYNS_*) of an event. May return
* FYNS_ANY if the event is implicit.
* For collection start events the only possible values is
* FYNS_ANY, FYNS_FLOW, FYNS_BLOCK.
* A scalar event may return any.
*
* @fye: The event to get it's node style
*
* Returns:
* The event's end marker, NULL if not available.
*/
enum fy_node_style
fy_event_get_node_style(struct fy_event *fye)
FY_EXPORT;
/**
* fy_document_start_event_version() - Return the version of a document
* start event
*
* Retrieve the version stored in a document start event
*
* @fye: The document start event
*
* Returns:
* A pointer to the version, or NULL in case of an error, or the event
* not being a document start event.
*/
const struct fy_version *
fy_document_start_event_version(struct fy_event *fye)
FY_EXPORT;
/**
* fy_document_state_version() - Return the version of a document state
* object
*
* Retrieve the version stored in a document state object
*
* @fyds: The document state object
*
* Returns:
* A pointer to the version, or NULL in case of an error
*/
const struct fy_version *
fy_document_state_version(struct fy_document_state *fyds)
FY_EXPORT;
/**
* fy_document_state_start_mark() - Get document state's start mark
*
* Return the document state's start mark (if it exists).
* Note that purely synthetic documents do not contain one
*
* @fyds: The document state object
*
* Returns:
* The document's start marker, NULL if not available.
*/
const struct fy_mark *
fy_document_state_start_mark(struct fy_document_state *fyds)
FY_EXPORT;
/**
* fy_document_state_end_mark() - Get document state's end mark
*
* Return the document state's end mark (if it exists).
* Note that purely synthetic documents do not contain one
*
* @fyds: The document state object
*
* Returns:
* The document's end marker, NULL if not available.
*/
const struct fy_mark *
fy_document_state_end_mark(struct fy_document_state *fyds)
FY_EXPORT;
/**
* fy_document_state_version_explicit() - Version explicit?
*
* Find out if a document state object's version was explicitly
* set in the document.
* Note that for synthetic documents this method returns false.
*
* @fyds: The document state object
*
* Returns:
* true if version was set explicitly, false otherwise
*/
bool
fy_document_state_version_explicit(struct fy_document_state *fyds)
FY_EXPORT;
/**
* fy_document_state_tags_explicit() - Tags explicit?
*
* Find out if a document state object's tags were explicitly
* set in the document.
* Note that for synthetic documents this method returns false.
*
* @fyds: The document state object
*
* Returns:
* true if document had tags set explicitly, false otherwise
*/
bool
fy_document_state_tags_explicit(struct fy_document_state *fyds)
FY_EXPORT;
/**
* fy_document_state_start_implicit() - Started implicitly?
*
* Find out if a document state object's document was
* started implicitly.
* Note that for synthetic documents this method returns false.
*
* @fyds: The document state object
*
* Returns:
* true if document was started implicitly, false otherwise
*/
bool
fy_document_state_start_implicit(struct fy_document_state *fyds)
FY_EXPORT;
/**
* fy_document_state_end_implicit() - Started implicitly?
*
* Find out if a document state object's document was
* ended implicitly.
* Note that for synthetic documents this method returns false.
*
* @fyds: The document state object
*
* Returns:
* true if document was ended implicitly, false otherwise
*/
bool
fy_document_state_end_implicit(struct fy_document_state *fyds)
FY_EXPORT;
/**
* fy_document_state_json_mode() - Input was JSON?
*
* Find out if a document state object's document was
* created by a JSON input.
* Note that for synthetic documents this method returns false.
*
* @fyds: The document state object
*
* Returns:
* true if document was created in JSON mode, false otherwise
*/
bool
fy_document_state_json_mode(struct fy_document_state *fyds)
FY_EXPORT;
/**
* fy_document_state_tag_directive_iterate() - Iterate over the tag
* directives of a document state
* object
*
* This method iterates over all the tag directives nodes in the document state
* object.
* The start of the iteration is signalled by a NULL in \*prevp.
*
* @fyds: The document state
* @prevp: The previous iterator
*
* Returns:
* The next tag or NULL at the end of the iteration sequence.
*/
const struct fy_tag *
fy_document_state_tag_directive_iterate(struct fy_document_state *fyds, void **prevp)
FY_EXPORT;
/**
* fy_document_state_tag_directives() - Get all the tag directives in a
* malloc'ed array
*
* Return all the tag directives in a dynamically allocated area.
* Must be free()'d when not in use.
*
* @fyds: The document state
*
* Returns:
* An array of fy_tag pointer structures, terminated with a NULL pointer
* NULL on error
*/
struct fy_tag **
fy_document_state_tag_directives(struct fy_document_state *fyds)
FY_EXPORT;
/**
* fy_document_state_tag_is_default() - Test whether the given tag is a default one
*
* Test whether a tag is a default (i.e. impliciticly set)
*
* @fyds: The document state
* @tag: The tag to check
*
* Returns:
* true in case that the tag is a default one, false otherwise
*/
bool
fy_document_state_tag_is_default(struct fy_document_state *fyds, const struct fy_tag *tag)
FY_EXPORT;
/**
* fy_parser_get_document_state() - Get the document state of a parser object
*
* Retrieve the document state object of a parser. Note that this is only
* valid during parsing.
*
* @fyp: The parser
*
* Returns:
* The active document state object of the parser, NULL otherwise
*/
struct fy_document_state *
fy_parser_get_document_state(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_document_get_document_state() - Get the document state of a document
*
* Retrieve the document state object of a document.
*
* @fyd: The document
*
* Returns:
* The document state object of the document, NULL otherwise
*/
struct fy_document_state *
fy_document_get_document_state(struct fy_document *fyd)
FY_EXPORT;
/**
* fy_document_set_document_state() - Set the document state of a document
*
* Set the document state of a document
*
* @fyd: The document
* @fyds: The document state to use, or NULL for default
*
* Returns:
* 0 if set operation was successful, -1 otherwise
*/
int
fy_document_set_document_state(struct fy_document *fyd, struct fy_document_state *fyds)
FY_EXPORT;
/**
* fy_document_create_from_event() - Create an empty document using the event
*
* Create an empty document using the FYET_DOCUMENT_START event generated
* by the parser.
*
* @fyp: The parser
* @fye: The event
*
* Returns:
* The created empty document, or NULL on error.
*/
struct fy_document *
fy_document_create_from_event(struct fy_parser *fyp, struct fy_event *fye)
FY_EXPORT;
/**
* fy_document_update_from_event() - Update the document with the event
*
* Update the document using the FYET_DOCUMENT_END event generated
* by the parser.
*
* @fyd: The document
* @fyp: The parser
* @fye: The event
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_document_update_from_event(struct fy_document *fyd, struct fy_parser *fyp, struct fy_event *fye)
FY_EXPORT;
/**
* fy_node_create_from_event() - Create a node using the event
*
* Create a new node using the supplied event.
* Allowed events are FYET_SCALAR, FYET_ALIAS, FYET_MAPPING_START & FYET_SEQUENCE_START
*
* @fyd: The document
* @fyp: The parser
* @fye: The event
*
* Returns:
* The newly created node, or NULL on error
*/
struct fy_node *
fy_node_create_from_event(struct fy_document *fyd, struct fy_parser *fyp, struct fy_event *fye)
FY_EXPORT;
/**
* fy_node_update_from_event() - Update a node using the event
*
* Update information of node created using fy_node_create_from_event()
* Allowed events are FYET_MAPPING_END & FYET_SEQUENCE_END
*
* @fyn: The node
* @fyp: The parser
* @fye: The event
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_update_from_event(struct fy_node *fyn, struct fy_parser *fyp, struct fy_event *fye)
FY_EXPORT;
/**
* fy_node_pair_create_with_key() - Create a new node pair and set it's key
*
* Create a new node pair using the supplied fyn_parent mapping and fyn node as
* a key. Note that the nodes _must_ have been created by fy_node_create_from_event
* and they are not interchangeable with other node pair methods.
*
* The node pair will be added to the fyn_parent mapping with a subsequent call
* to fy_node_pair_update_with_value().
*
* @fyd: The document
* @fyn_parent: The mapping
* @fyn: The node pair key
*
* Returns:
* The newly created node pair, or NULL on error
*/
struct fy_node_pair *
fy_node_pair_create_with_key(struct fy_document *fyd, struct fy_node *fyn_parent, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_pair_update_with_value() - Update a node pair with a value and add it to the parent mapping
*
* Update the node pair with the given value and add it to the parent mapping.
* Note that the fyn node _must_ have been created by fy_node_create_from_event
* and the node pair created by fy_node_pair_create_with_key().
* Do not intermix other node pair manipulation methods.
*
* @fynp: The node pair
* @fyn: The node pair value
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_pair_update_with_value(struct fy_node_pair *fynp, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_node_sequence_add_item() - Add an item node to a sequence node
*
* Add an item to the end of the sequence node fyn_parent.
* Note that the fyn_parent and fyn nodes _must_ have been created by
* fy_node_create_from_event.
* Do not intermix other sequence node manipulation methods.
*
* @fyn_parent: The parent sequence node
* @fyn: The node pair item
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_node_sequence_add_item(struct fy_node *fyn_parent, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_emitter_get_document_state() - Get the document state of an emitter object
*
* Retrieve the document state object of an emitter. Note that this is only
* valid during emitting.
*
* @emit: The emitter
*
* Returns:
* The active document state object of the emitter, NULL otherwise
*/
struct fy_document_state *
fy_emitter_get_document_state(struct fy_emitter *emit)
FY_EXPORT;
/**
* fy_emit_event_create() - Create an emit event.
*
* Create an emit event to pass to fy_emit_event()
* The extra arguments differ according to the event to be created
*
* FYET_STREAM_START:
* - None
*
* FYET_STREAM_END:
* - None
*
* FYET_DOCUMENT_START:
* - int implicit
* true if document start should be marked implicit
* false if document start should not be marked implicit
* - const struct fy_version \*vers
* Pointer to version to use for the document, or NULL for default
* - const struct fy_tag \* const \*tags
* Pointer to a NULL terminated array of tag pointers (like argv)
* NULL if no extra tags are to be used
*
* FYET_DOCUMENT_END:
* - int implicit
* true if document end should be marked implicit
* false if document end should not be marked implicit
*
* FYET_MAPPING_START:
* - enum fy_node_style style
* Style of the mapping (one of FYNS_ANY, FYNS_BLOCK or FYNS_FLOW)
* - const char \*anchor
* Anchor to place at the mapping, or NULL for none
* - const char \*tag
* Tag to place at the mapping, or NULL for none
*
* FYET_MAPPING_END:
* - None
*
* FYET_SEQUENCE_START:
* - enum fy_node_style style
* Style of the sequence (one of FYNS_ANY, FYNS_BLOCK or FYNS_FLOW)
* - const char \*anchor
* Anchor to place at the sequence, or NULL for none
* - const char \*tag
* Tag to place at the sequence, or NULL for none
*
* FYET_SEQUENCE_END:
* - None
*
* FYET_SCALAR:
* - enum fy_scalar_style style
* Style of the scalar, any valid FYSS_* value
* Note that certain styles may not be used according to the
* contents of the data
* - const char \*value
* Pointer to the scalar contents.
* - size_t len
* Length of the scalar contents, of FY_NT (-1) for strlen(value)
* - const char \*anchor
* Anchor to place at the scalar, or NULL for none
* - const char \*tag
* Tag to place at the scalar, or NULL for none
*
* FYET_ALIAS:
* - const char \*value
* Pointer to the alias.
*
* @emit: The emitter
* @type: The event type to create
* @...: The optional extra arguments
*
* Returns:
* The created event or NULL in case of an error
*/
struct fy_event *
fy_emit_event_create(struct fy_emitter *emit, enum fy_event_type type, ...)
FY_EXPORT;
/**
* fy_emit_event_vcreate() - Create an emit event using varargs.
*
* Create an emit event to pass to fy_emit_event()
* The varargs analogous to fy_emit_event_create().
*
* @emit: The emitter
* @type: The event type to create
* @ap: The variable argument list pointer.
*
* Returns:
* The created event or NULL in case of an error
*/
struct fy_event *
fy_emit_event_vcreate(struct fy_emitter *emit, enum fy_event_type type, va_list ap)
FY_EXPORT;
/**
* fy_emit_event_free() - Free an event created via fy_emit_event_create()
*
* Free an event previously created via fy_emit_event_create(). Note
* that usually you don't have to call this method since if you pass
* the event to fy_emit_event() it shall be disposed properly.
* Only use is error recovery and cleanup.
*
* @emit: The emitter
* @fye: The event to free
*/
void
fy_emit_event_free(struct fy_emitter *emit, struct fy_event *fye)
FY_EXPORT;
/**
* fy_parse_event_create() - Create an emit event.
*
* See fy_emit_event_create()...
*
* @fyp: The parser
* @type: The event type to create
*
* Returns:
* The created event or NULL in case of an error
*/
struct fy_event *
fy_parse_event_create(struct fy_parser *fyp, enum fy_event_type type, ...)
FY_EXPORT;
/**
* fy_parse_event_vcreate() - Create an emit event using varargs.
*
* Create an emit event to pass to fy_emit_event()
* The varargs analogous to fy_parse_event_create().
*
* @fyp: The parser
* @type: The event type to create
* @ap: The variable argument list pointer.
*
* Returns:
* The created event or NULL in case of an error
*/
struct fy_event *
fy_parse_event_vcreate(struct fy_parser *fyp, enum fy_event_type type, va_list ap)
FY_EXPORT;
/**
* enum fy_composer_return - The returns of the composer callback
*
* @FYCR_OK_CONTINUE: continue processing, event processed
* @FYCR_OK_STOP: stop processing, event processed
* @FYCR_OK_START_SKIP: start skip object(s), event processed
* @FYCR_OK_STOP_SKIP: stop skipping of objects, event processed
* @FYCR_ERROR: error, stop processing
*/
enum fy_composer_return {
FYCR_OK_CONTINUE = 0,
FYCR_OK_STOP = 1,
FYCR_OK_START_SKIP = 2,
FYCR_OK_STOP_SKIP = 3,
FYCR_ERROR = -1,
};
/**
* fy_composer_return_is_ok() - Check if the return code is OK
*
* Convenience method for checking if it's OK to continue
*
* @ret: the composer return to check
*
* Returns:
* true if non error or skip condition
*/
static inline bool
fy_composer_return_is_ok(enum fy_composer_return ret)
{
return ret == FYCR_OK_CONTINUE || ret == FYCR_OK_STOP;
}
/**
* typedef fy_parse_composer_cb - composer callback method
*
* This method is called by the fy_parse_compose() method
* when an event must be processed.
*
* @fyp: The parser
* @fye: The event
* @path: The path that the parser is processing
* @userdata: The user data of the fy_parse_compose() method
*
* Returns:
* fy_composer_return code telling the parser what to do
*/
typedef enum fy_composer_return
(*fy_parse_composer_cb)(struct fy_parser *fyp, struct fy_event *fye,
struct fy_path *path, void *userdata);
/**
* fy_parse_compose() - Parse using a compose callback
*
* Alternative parsing method using a composer callback.
*
* The parser will construct a path argument that is used
* by the callback to make intelligent decisions about
* creating a document and/or DOM.
*
* @fyp: The parser
* @cb: The callback that will be called
* @userdata: user pointer to pass to the callback
*
* Returns:
* 0 if no error occured
* -1 on error
*/
int
fy_parse_compose(struct fy_parser *fyp, fy_parse_composer_cb cb,
void *userdata)
FY_EXPORT;
/**
* fy_path_component_is_mapping() - Check if the component is a mapping
*
* @fypc: The path component to check
*
* Returns:
* true if the path component is a mapping, false otherwise
*/
bool
fy_path_component_is_mapping(struct fy_path_component *fypc)
FY_EXPORT;
/**
* fy_path_component_is_sequence() - Check if the component is a sequence
*
* @fypc: The path component to check
*
* Returns:
* true if the path component is a sequence, false otherwise
*/
bool
fy_path_component_is_sequence(struct fy_path_component *fypc)
FY_EXPORT;
/**
* fy_path_component_sequence_get_index() - Get the index of sequence path component
*
* @fypc: The sequence path component to return it's index value
*
* Returns:
* >= 0 the sequence index
* -1 if the component is either not in the proper mode, or not a sequence
*/
int
fy_path_component_sequence_get_index(struct fy_path_component *fypc)
FY_EXPORT;
/**
* fy_path_component_mapping_get_scalar_key() - Get the scalar key of a mapping
*
* @fypc: The mapping path component to return it's scalar key
*
* Returns:
* a non NULL scalar or alias token if the mapping contains a scalar key
* NULL in case of an error, or if the component has a complex key
*/
struct fy_token *
fy_path_component_mapping_get_scalar_key(struct fy_path_component *fypc)
FY_EXPORT;
/**
* fy_path_component_mapping_get_scalar_key_tag() - Get the scalar key's tag of a mapping
*
* @fypc: The mapping path component to return it's scalar key's tag
*
* Returns:
* a non NULL tag token if the mapping contains a scalar key with a tag or
* NULL in case of an error, or if the component has a complex key
*/
struct fy_token *
fy_path_component_mapping_get_scalar_key_tag(struct fy_path_component *fypc)
FY_EXPORT;
/**
* fy_path_component_mapping_get_complex_key() - Get the complex key of a mapping
*
* @fypc: The mapping path component to return it's complex key
*
* Returns:
* a non NULL document if the mapping contains a complex key
* NULL in case of an error, or if the component has a simple key
*/
struct fy_document *
fy_path_component_mapping_get_complex_key(struct fy_path_component *fypc)
FY_EXPORT;
/**
* fy_path_component_get_text() - Get the textual representation of a path component
*
* Given a path component, return a malloc'ed string which contains
* the textual representation of it.
*
* Note that this method will only return fully completed components and not
* ones that are in the building process.
*
* @fypc: The path component to get it's textual representation
*
* Returns:
* The textual representation of the path component, NULL on error, or
* if the component has not been completely built during the composition
* of a complex key.
* The string must be free'ed using free.
*/
char *
fy_path_component_get_text(struct fy_path_component *fypc)
FY_EXPORT;
#define fy_path_component_get_text_alloca(_fypc) \
FY_ALLOCA_COPY_FREE(fy_path_component_get_text((_fypc)), FY_NT)
/**
* fy_path_depth() - Get the depth of a path
*
* @fypp: The path to query
*
* Returns:
* The depth of the path, or -1 on error
*/
int
fy_path_depth(struct fy_path *fypp)
FY_EXPORT;
/**
* fy_path_parent() - Get the parent of a path
*
* Paths may contain parents when traversing complex keys.
* This method returns the immediate parent.
*
* @fypp: The path to return it's parent
*
* Returns:
* The path parent or NULL on error, if it doesn't exist
*/
struct fy_path *
fy_path_parent(struct fy_path *fypp)
FY_EXPORT;
/**
* fy_path_get_text() - Get the textual representation of a path
*
* Given a path, return a malloc'ed string which contains
* the textual representation of it.
*
* Note that during processing, complex key paths are simply
* indicative and not to be used for addressing.
*
* @fypp: The path to get it's textual representation
*
* Returns:
* The textual representation of the path, NULL on error.
* The string must be free'ed using free.
*/
char *
fy_path_get_text(struct fy_path *fypp)
FY_EXPORT;
#define fy_path_get_text_alloca(_fypp) \
FY_ALLOCA_COPY_FREE(fy_path_get_text((_fypp)), FY_NT)
/**
* fy_path_in_root() - Check if the path is in the root of the document
*
* @fypp: The path
*
* Returns:
* true if the path is located within the root of the document
*/
bool
fy_path_in_root(struct fy_path *fypp)
FY_EXPORT;
/**
* fy_path_in_mapping() - Check if the path is in a mapping
*
* @fypp: The path
*
* Returns:
* true if the path is located within a mapping
*/
bool
fy_path_in_mapping(struct fy_path *fypp)
FY_EXPORT;
/**
* fy_path_in_sequence() - Check if the path is in a sequence
*
* @fypp: The path
*
* Returns:
* true if the path is located within a sequence
*/
bool
fy_path_in_sequence(struct fy_path *fypp)
FY_EXPORT;
/**
* fy_path_in_mapping_key() - Check if the path is in a mapping key state
*
* @fypp: The path
*
* Returns:
* true if the path is located within a mapping key state
*/
bool
fy_path_in_mapping_key(struct fy_path *fypp)
FY_EXPORT;
/**
* fy_path_in_mapping_value() - Check if the path is in a mapping value state
*
* @fypp: The path
*
* Returns:
* true if the path is located within a mapping value state
*/
bool
fy_path_in_mapping_value(struct fy_path *fypp)
FY_EXPORT;
/**
* fy_path_in_collection_root() - Check if the path is in a collection root
*
* A collection root state is when the path points to a sequence or mapping
* but the state does not allow setting keys, values or adding items.
*
* This occurs on MAPPING/SEQUENCE START/END events.
*
* @fypp: The path
*
* Returns:
* true if the path is located within a collectin root state
*/
bool
fy_path_in_collection_root(struct fy_path *fypp)
FY_EXPORT;
/**
* fy_path_get_root_user_data() - Return the userdata associated with the path root
*
* @fypp: The path
*
* Returns:
* The user data associated with the root of the path, or NULL if no path
*/
void *
fy_path_get_root_user_data(struct fy_path *fypp)
FY_EXPORT;
/**
* fy_path_set_root_user_data() - Set the user data associated with the root
*
* Note, no error condition if not a path
*
* @fypp: The path
* @data: The data to set as root data
*/
void
fy_path_set_root_user_data(struct fy_path *fypp, void *data)
FY_EXPORT;
/**
* fy_path_component_get_mapping_user_data() - Return the userdata associated with the mapping
*
* @fypc: The path component
*
* Returns:
* The user data associated with the mapping, or NULL if not a mapping or the user data are NULL
*/
void *
fy_path_component_get_mapping_user_data(struct fy_path_component *fypc)
FY_EXPORT;
/**
* fy_path_component_get_mapping_key_user_data() - Return the userdata associated with the mapping key
*
* @fypc: The path component
*
* Returns:
* The user data associated with the mapping key, or NULL if not a mapping or the user data are NULL
*/
void *
fy_path_component_get_mapping_key_user_data(struct fy_path_component *fypc)
FY_EXPORT;
/**
* fy_path_component_get_sequence_user_data() - Return the userdata associated with the sequence
*
* @fypc: The path component
*
* Returns:
* The user data associated with the sequence, or NULL if not a sequence or the user data are NULL
*/
void *
fy_path_component_get_sequence_user_data(struct fy_path_component *fypc)
FY_EXPORT;
/**
* fy_path_component_set_mapping_user_data() - Set the user data associated with a mapping
*
* Note, no error condition if not a mapping
*
* @fypc: The path component
* @data: The data to set as mapping data
*/
void
fy_path_component_set_mapping_user_data(struct fy_path_component *fypc, void *data)
FY_EXPORT;
/**
* fy_path_component_set_mapping_key_user_data() - Set the user data associated with a mapping key
*
* Note, no error condition if not in a mapping key state
*
* @fypc: The path component
* @data: The data to set as mapping key data
*/
void
fy_path_component_set_mapping_key_user_data(struct fy_path_component *fypc, void *data)
FY_EXPORT;
/**
* fy_path_component_set_sequence_user_data() - Set the user data associated with a sequence
*
* Note, no error condition if not a sequence
*
* @fypc: The path component
* @data: The data to set as sequence data
*/
void
fy_path_component_set_sequence_user_data(struct fy_path_component *fypc, void *data)
FY_EXPORT;
/**
* fy_path_get_parent_user_data() - Return the userdata of the parent collection
*
* @path: The path
*
* Returns:
* The user data associated with the parent collection of the path, or NULL if no path
*/
void *
fy_path_get_parent_user_data(struct fy_path *path)
FY_EXPORT;
/**
* fy_path_set_parent_user_data() - Set the user data associated with the parent collection
*
* Note, no error condition if not a path
*
* @path: The path
* @data: The data to set as parent collection data
*/
void
fy_path_set_parent_user_data(struct fy_path *path, void *data)
FY_EXPORT;
/**
* fy_path_get_last_user_data() - Return the userdata of the last collection
*
* @path: The path
*
* Returns:
* The user data associated with the last collection of the path, or NULL if no path
*/
void *
fy_path_get_last_user_data(struct fy_path *path)
FY_EXPORT;
/**
* fy_path_set_last_user_data() - Set the user data associated with the last collection
*
* Note, no error condition if not a path
*
* @path: The path
* @data: The data to set as last collection data
*/
void
fy_path_set_last_user_data(struct fy_path *path, void *data)
FY_EXPORT;
/**
* fy_path_last_component() - Get the very last component of a path
*
* Returns the last component of a path.
*
* @fypp: The path
*
* Returns:
* The last path component (which may be a collection root component), or NULL
* if it does not exist
*/
struct fy_path_component *
fy_path_last_component(struct fy_path *fypp)
FY_EXPORT;
/**
* fy_path_last_not_collection_root_component() - Get the last non collection root component of a path
*
* Returns the last non collection root component of a path. This may not be the
* last component that is returned by fy_path_last_component().
*
* The difference is present on MAPPING/SEQUENCE START/END events where the
* last component is present but not usuable as a object parent.
*
* @fypp: The path
*
* Returns:
* The last non collection root component, or NULL if it does not exist
*/
struct fy_path_component *
fy_path_last_not_collection_root_component(struct fy_path *fypp)
FY_EXPORT;
/**
* struct fy_composer_ops - Composer operation callbacks
*
* Callbacks used by the composer to process events and create document builders.
*
* @process_event: Callback for processing a single YAML event with path context
* @create_document_builder: Callback for creating a document builder instance
*/
struct fy_composer_ops {
/* single process event callback */
enum fy_composer_return (*process_event)(struct fy_composer *fyc, struct fy_path *path, struct fy_event *fye);
struct fy_document_builder *(*create_document_builder)(struct fy_composer *fyc);
};
/**
* struct fy_composer_cfg - Composer configuration structure
*
* Configuration structure for creating a composer instance.
*
* @ops: Pointer to composer operation callbacks
* @userdata: Opaque user data pointer passed to callbacks
* @diag: Optional diagnostic interface to use, NULL for default
*/
struct fy_composer_cfg {
const struct fy_composer_ops *ops;
void *userdata;
struct fy_diag *diag;
};
/**
* fy_composer_create() - Create a composer
*
* Creates a composer with the given configuration. The composer processes
* YAML events using callback methods and maintains path information for
* intelligent document composition. The composer may be destroyed by a
* corresponding call to fy_composer_destroy().
*
* @cfg: The configuration for the composer
*
* Returns:
* A pointer to the composer or NULL in case of an error.
*/
struct fy_composer *
fy_composer_create(struct fy_composer_cfg *cfg)
FY_EXPORT;
/**
* fy_composer_destroy() - Destroy the given composer
*
* Destroy a composer created earlier via fy_composer_create().
*
* @fyc: The composer to destroy
*/
void fy_composer_destroy(struct fy_composer *fyc)
FY_EXPORT;
/**
* fy_composer_process_event() - Process a YAML event through the composer
*
* Process a YAML event by calling the configured process_event callback
* with path context. The composer maintains the current path and provides
* it to the callback for intelligent processing decisions.
*
* @fyc: The composer
* @fye: The event to process
*
* Returns:
* A fy_composer_return code indicating how to proceed (continue, stop, skip, or error)
*/
enum fy_composer_return
fy_composer_process_event(struct fy_composer *fyc, struct fy_event *fye)
FY_EXPORT;
/**
* fy_composer_get_cfg() - Get the configuration of a composer
*
* @fyc: The composer
*
* Returns:
* The configuration of the composer
*/
struct fy_composer_cfg *
fy_composer_get_cfg(struct fy_composer *fyc)
FY_EXPORT;
/**
* fy_composer_get_cfg_userdata() - Get the userdata from composer configuration
*
* Retrieve the opaque userdata pointer from the composer's configuration.
*
* @fyc: The composer
*
* Returns:
* The userdata pointer from the configuration
*/
void *
fy_composer_get_cfg_userdata(struct fy_composer *fyc)
FY_EXPORT;
/**
* fy_composer_get_diag() - Get the diagnostic object of a composer
*
* Return a pointer to the diagnostic object of a composer object.
* Note that the returned diag object has a reference taken so
* you should fy_diag_unref() it when you're done with it.
*
* @fyc: The composer to get the diagnostic object
*
* Returns:
* A pointer to a ref'ed diagnostic object or NULL in case of an error.
*/
struct fy_diag *
fy_composer_get_diag(struct fy_composer *fyc)
FY_EXPORT;
/**
* fy_composer_get_path() - Get the current path of the composer
*
* Retrieve the current path being processed by the composer.
* The path represents the location in the YAML document structure
* where the composer is currently positioned.
*
* @fyc: The composer
*
* Returns:
* The current path, or NULL if no path is active
*/
struct fy_path *
fy_composer_get_path(struct fy_composer *fyc)
FY_EXPORT;
/**
* fy_composer_get_root_path() - Get the root path of the composer
*
* Retrieve the root path of the composer's path hierarchy.
*
* @fyc: The composer
*
* Returns:
* The root path, or NULL if no root exists
*/
struct fy_path *
fy_composer_get_root_path(struct fy_composer *fyc)
FY_EXPORT;
/**
* fy_composer_get_next_path() - Get the next path in the composer's path list
*
* Iterate through the composer's path list. Pass NULL to get the first path,
* or pass the previous path to get the next one.
*
* @fyc: The composer
* @fypp: The previous path, or NULL to get the first path
*
* Returns:
* The next path in the list, or NULL if no more paths exist
*/
struct fy_path *
fy_composer_get_next_path(struct fy_composer *fyc, struct fy_path *fypp)
FY_EXPORT;
/* Shift amount of the want mode */
#define FYDICF_WANT_SHIFT 0
/* Mask of the WANT mode */
#define FYDICF_WANT_MASK ((1U << 2) - 1)
/* Build a WANT mode option */
#define FYDICF_WANT(x) (((unsigned int)(x) & FYDICF_WANT_MASK) << FYDICF_WANT_SHIFT)
/**
* enum fy_document_iterator_cfg_flags - Document iterator configuration flags
*
* These flags control the operation of the document iterator
*
* @FYDICF_WANT_BODY_EVENTS: Generate body events
* @FYDICF_WANT_DOCUMENT_BODY_EVENTS: Generate document and body events
* @FYDICF_WANT_STREAM_DOCUMENT_BODY_EVENTS: Generate stream, document and body events
*/
enum fy_document_iterator_cfg_flags {
FYDICF_WANT_BODY_EVENTS = FYDICF_WANT(0),
FYDICF_WANT_DOCUMENT_BODY_EVENTS = FYDICF_WANT(1),
FYDICF_WANT_STREAM_DOCUMENT_BODY_EVENTS = FYDICF_WANT(2),
};
/**
* struct fy_document_iterator_cfg - document iterator configuration structure.
*
* Argument to the fy_document_iterator_create_cfg() method.
*
* @flags: The document iterator flags
* @fyd: The document to iterate on (or NULL if iterate_root is set)
* @iterate_root: The root of iteration (NULL when fyd is not NULL)
*/
struct fy_document_iterator_cfg {
enum fy_document_iterator_cfg_flags flags;
struct fy_document *fyd;
struct fy_node *iterate_root;
};
/**
* fy_document_iterator_create() - Create a document iterator
*
* Creates a document iterator, that can trawl through a document
* without using recursion.
*
* Returns:
* The newly created document iterator or NULL on error
*/
struct fy_document_iterator *
fy_document_iterator_create(void)
FY_EXPORT;
/**
* fy_document_iterator_create_cfg() - Create a document iterator using config
*
* Creates a document iterator, that can trawl through a document
* without using recursion. The iterator will generate all the events
* that created the given document starting at iterator root.
*
* @cfg: The document iterator to destroy
*
* Returns:
* The newly created document iterator or NULL on error
*/
struct fy_document_iterator *
fy_document_iterator_create_cfg(const struct fy_document_iterator_cfg *cfg)
FY_EXPORT;
/**
* fy_document_iterator_create_on_document() - Create a document iterator on document
*
* Creates a document iterator, starting at the root of the given document.
*
* @fyd: The document to iterate on
*
* Returns:
* The newly created document iterator or NULL on error
*/
struct fy_document_iterator *
fy_document_iterator_create_on_document(struct fy_document *fyd)
FY_EXPORT;
/**
* fy_document_iterator_create_on_node() - Create a document iterator on node
*
* Creates a document iterator, starting at the given node
*
* @fyn: The node to iterate on
*
* Returns:
* The newly created document iterator or NULL on error
*/
struct fy_document_iterator *
fy_document_iterator_create_on_node(struct fy_node *fyn)
FY_EXPORT;
/**
* fy_document_iterator_destroy() - Destroy the given document iterator
*
* Destroy a document iterator created earlier via fy_document_iterator_create().
*
* @fydi: The document iterator to destroy
*/
void
fy_document_iterator_destroy(struct fy_document_iterator *fydi)
FY_EXPORT;
/**
* fy_document_iterator_event_free() - Free an event that was created by a document iterator
*
* Free (possibly recycling) an event that was created by a document iterator.
*
* @fydi: The document iterator that created the event
* @fye: The event
*/
void
fy_document_iterator_event_free(struct fy_document_iterator *fydi, struct fy_event *fye)
FY_EXPORT;
/**
* fy_document_iterator_stream_start() - Create a stream start event using the iterator
*
* Creates a stream start event on the document iterator and advances the internal state
* of it accordingly.
*
* @fydi: The document iterator to create the event
*
* Returns:
* The newly created stream start event, or NULL on error.
*/
struct fy_event *
fy_document_iterator_stream_start(struct fy_document_iterator *fydi)
FY_EXPORT;
/**
* fy_document_iterator_stream_end() - Create a stream end event using the iterator
*
* Creates a stream end event on the document iterator and advances the internal state
* of it accordingly.
*
* @fydi: The document iterator to create the event
*
* Returns:
* The newly created stream end event, or NULL on error.
*/
struct fy_event *
fy_document_iterator_stream_end(struct fy_document_iterator *fydi)
FY_EXPORT;
/**
* fy_document_iterator_document_start() - Create a document start event using the iterator
*
* Creates a document start event on the document iterator and advances the internal state
* of it accordingly. The document must not be released until an error, cleanup or a call
* to fy_document_iterator_document_end().
*
* @fydi: The document iterator to create the event
* @fyd: The document containing the document state that is used in the event
*
* Returns:
* The newly created document start event, or NULL on error.
*/
struct fy_event *
fy_document_iterator_document_start(struct fy_document_iterator *fydi, struct fy_document *fyd)
FY_EXPORT;
/**
* fy_document_iterator_document_end() - Create a document end event using the iterator
*
* Creates a document end event on the document iterator and advances the internal state
* of it accordingly. The document that was used earlier in the call of
* fy_document_iterator_document_start() can now be released.
*
* @fydi: The document iterator to create the event
*
* Returns:
* The newly created document end event, or NULL on error.
*/
struct fy_event *
fy_document_iterator_document_end(struct fy_document_iterator *fydi)
FY_EXPORT;
/**
* fy_document_iterator_body_next() - Create document body events until the end
*
* Creates the next document body, depth first until the end of the document.
* The events are created depth first and are in same exact sequence that the
* original events that created the document.
*
* That means that the finite event stream that generated the document is losslesly
* preserved in such a way that the document tree representation is functionally
* equivalent.
*
* Repeated calls to this function will generate a stream of SCALAR, ALIAS, SEQUENCE
* START, SEQUENCE END, MAPPING START and MAPPING END events, returning NULL at the
* end of the body event stream.
*
* @fydi: The document iterator to create the event
*
* Returns:
* The newly created document body event or NULL at an error, or an end of the
* event stream. Use fy_document_iterator_get_error() to check if an error occured.
*/
struct fy_event *
fy_document_iterator_body_next(struct fy_document_iterator *fydi)
FY_EXPORT;
/**
* fy_document_iterator_node_start() - Start a document node iteration run using a starting point
*
* Starts an iteration run starting at the given node.
*
* @fydi: The document iterator to run with
* @fyn: The iterator root for the iteration
*/
void
fy_document_iterator_node_start(struct fy_document_iterator *fydi, struct fy_node *fyn)
FY_EXPORT;
/**
* fy_document_iterator_node_next() - Return the next node in the iteration sequence
*
* Returns a pointer to the next node iterating using as a start the node given
* at fy_document_iterator_node_start(). The first node returned will be that,
* followed by all the remaing nodes in the subtree.
*
* @fydi: The document iterator to use for the iteration
*
* Returns:
* The next node in the iteration sequence or NULL at the end, or if an error occured.
*/
struct fy_node *
fy_document_iterator_node_next(struct fy_document_iterator *fydi)
FY_EXPORT;
/**
* fy_document_iterator_generate_next() - Create events from document iterator
*
* This is a method that will handle the complex state of generating
* stream, document and body events on the given iterator.
*
* When generation is complete a NULL event will be generated.
*
* @fydi: The document iterator to create the event
*
* Returns:
* The newly created event or NULL at an error, or an end of the
* event stream. Use fy_document_iterator_get_error() to check if an error occured.
*/
struct fy_event *
fy_document_iterator_generate_next(struct fy_document_iterator *fydi)
FY_EXPORT;
/**
* fy_document_iterator_get_error() - Get the error state of the document iterator
*
* Returns the error state of the iterator. If it's in error state, return true
* and reset the iterator to the state just after creation.
*
* @fydi: The document iterator to use for checking it's error state.
*
* Returns:
* true if it was in an error state, false otherwise.
*/
bool
fy_document_iterator_get_error(struct fy_document_iterator *fydi)
FY_EXPORT;
/**
* struct fy_document_builder_cfg - document builder configuration structure.
*
* Argument to the fy_document_builder_create() method
*
* @parse_cfg: Parser configuration
* @userdata: Opaque user data pointer
* @diag: Optional diagnostic interface to use
*/
struct fy_document_builder_cfg {
struct fy_parse_cfg parse_cfg;
void *userdata;
struct fy_diag *diag;
};
/**
* fy_document_builder_create() - Create a document builder
*
* Creates a document builder with its configuration @cfg
* The document builder may be destroyed by a corresponding call to
* fy_document_builder_destroy().
*
* @cfg: The configuration for the document builder
*
* Returns:
* A pointer to the document builder or NULL in case of an error.
*/
struct fy_document_builder *
fy_document_builder_create(const struct fy_document_builder_cfg *cfg)
FY_EXPORT;
/**
* fy_document_builder_create_on_parser() - Create a document builder
* pulling state from the parser
*
* Creates a document builder pulling state from the given parser
*
* @fyp: The parser to associate with
*
* Returns:
* A pointer to the document builder or NULL in case of an error.
*/
struct fy_document_builder *
fy_document_builder_create_on_parser(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_document_builder_reset() - Reset a document builder
*
* Resets a document builder without destroying it
*
* @fydb: The document builder
*/
void
fy_document_builder_reset(struct fy_document_builder *fydb)
FY_EXPORT;
/**
* fy_document_builder_destroy() - Destroy a document builder
*
* Destroy a document builder
*
* @fydb: The document builder
*/
void
fy_document_builder_destroy(struct fy_document_builder *fydb)
FY_EXPORT;
/**
* fy_document_builder_get_document() - Get the document of a builder
*
* Retrieve the document of a document builder. This document
* may be incomplete. If you need to take ownership use
* fy_document_builder_take_document().
*
* @fydb: The document builder
*
* Returns:
* The document that the builder built, or NULL in case of an error
*/
struct fy_document *
fy_document_builder_get_document(struct fy_document_builder *fydb)
FY_EXPORT;
/**
* fy_document_builder_is_in_stream() - Test document builder in stream
*
* Find out if the document builder is in 'stream' state,
* i.e. after stream start but before stream end events are generated.
*
* @fydb: The document builder
*
* Returns:
* true if in stream, false otherwise
*/
bool
fy_document_builder_is_in_stream(struct fy_document_builder *fydb)
FY_EXPORT;
/**
* fy_document_builder_is_in_document() - Test document builder in document
*
* Find out if the document builder is in 'document' state,
* i.e. after document start but before document end events are generated.
*
* @fydb: The document builder
*
* Returns:
* true if in document, false otherwise
*/
bool
fy_document_builder_is_in_document(struct fy_document_builder *fydb)
FY_EXPORT;
/**
* fy_document_builder_is_document_complete() - Test document builder complete
*
* Find out if the document of the builder is complete.
* If it is complete then a call to fy_document_builder_take_document() will
* transfer ownership of the document to the caller.
*
* @fydb: The document builder
*
* Returns:
* true if document complete, false otherwise
*/
bool
fy_document_builder_is_document_complete(struct fy_document_builder *fydb)
FY_EXPORT;
/**
* fy_document_builder_take_document() - Take ownership the document of a builder
*
* Take ownership of the document of a document builder.
* The document builder's document must be complete.
*
* @fydb: The document builder
*
* Returns:
* The document that the builder built, or NULL in case of an error
*/
struct fy_document *
fy_document_builder_take_document(struct fy_document_builder *fydb)
FY_EXPORT;
/**
* fy_document_builder_peek_document() - Peek at the document of a builder
*
* Peek at the document of a document builder.
* Ownership still remains with the builder.
*
* @fydb: The document builder
*
* Returns:
* A peek to the document that the builder built, or NULL in case of an error
*/
struct fy_document *
fy_document_builder_peek_document(struct fy_document_builder *fydb)
FY_EXPORT;
/**
* fy_document_builder_set_in_stream() - Set the builders state in 'stream'
*
* Set the document builders state to in 'stream'
*
* @fydb: The document builder
*/
void
fy_document_builder_set_in_stream(struct fy_document_builder *fydb)
FY_EXPORT;
/**
* fy_document_builder_set_in_document() - Set the builders state in 'document'
*
* Set the document builders state to in 'document'
*
* @fydb: The document builder
* @fyds: The document state
* @single: Single document mode
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_document_builder_set_in_document(struct fy_document_builder *fydb, struct fy_document_state *fyds, bool single)
FY_EXPORT;
/**
* fy_document_builder_load_document() - Create a document from parser events
*
* Load a document by pumping the parser for events and then processing them
* with the builder.
*
* @fydb: The document builder
* @fyp: The parser
*
* Returns:
* The document that results from the parser, or NULL in case of an error (or EOF)
*/
struct fy_document *
fy_document_builder_load_document(struct fy_document_builder *fydb, struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_parse_load_document_with_builder() - Parse a document via built-in builder
*
* Load a document by pumping the parser for events and then processing them
* with the in-parser builder.
*
* @fyp: The parser
*
* Returns:
* The document that results from the parser, or NULL in case of an error (or EOF)
*/
struct fy_document *
fy_parse_load_document_with_builder(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_document_builder_process_event() - Process an event with a builder
*
* Pump an event to a document builder for processing.
*
* @fydb: The document builder
* @fye: The event
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_document_builder_process_event(struct fy_document_builder *fydb, struct fy_event *fye)
FY_EXPORT;
/**
* enum fy_parser_event_generator_flags - The parser event generator flags
*
* @FYPEGF_GENERATE_DOCUMENT_EVENTS: generate document events
* @FYPEGF_GENERATE_STREAM_EVENTS: generate stream events
* @FYPEGF_GENERATE_ALL_EVENTS: generate all events
*/
enum fy_parser_event_generator_flags {
FYPEGF_GENERATE_DOCUMENT_EVENTS = FY_BIT(0),
FYPEGF_GENERATE_STREAM_EVENTS = FY_BIT(1),
FYPEGF_GENERATE_ALL_EVENTS = FYPEGF_GENERATE_STREAM_EVENTS | FYPEGF_GENERATE_DOCUMENT_EVENTS,
};
/**
* fy_parser_set_document_iterator() - Associate a parser with a document iterator
*
* Associate a parser with a document iterator, that is instead of parsing the events
* will be generated by the document iterator.
*
* @fyp: The parser
* @flags: The event generation flags
* @fydi: The document iterator to associate
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_parser_set_document_iterator(struct fy_parser *fyp, enum fy_parser_event_generator_flags flags,
struct fy_document_iterator *fydi)
FY_EXPORT;
/*
* The libfyaml's push-pull thread implementation
*
*/
/* opaque types for the user */
struct fy_thread_pool;
struct fy_thread;
struct fy_work_pool;
/**
* typedef fy_work_exec_fn - Work exec function
*
* The callback executed on work submission
*
* @arg: The argument to the method
*
*/
typedef void (*fy_work_exec_fn)(void *arg);
/**
* typedef fy_work_check_fn - Work check function
*
* Work checker function to decide if it's worth to
* offload to a thread.
*
* @arg: The argument to the method
*
* Returns:
* true if it should offload to thread, false otherwise
*
*/
typedef bool (*fy_work_check_fn)(const void *arg);
/**
* struct fy_thread_work - Work submitted to a thread for execution
*
* @fn: The execution function for this work
* @arg: The argument to the fn
* @wp: Used internally, must be set to NULL on entry
*
* This is the structure describing the work submitted
* to a thread for execution.
*/
struct fy_thread_work {
fy_work_exec_fn fn;
void *arg;
struct fy_work_pool *wp;
};
/**
* enum fy_thread_pool_cfg_flags - Thread pool configuration flags
*
* These flags control the operation of the thread pool.
* For now only the steal mode flag is defined.
*
* @FYTPCF_STEAL_MODE: Enable steal mode for the thread pool
*/
enum fy_thread_pool_cfg_flags {
FYTPCF_STEAL_MODE = FY_BIT(0),
};
/**
* struct fy_thread_pool_cfg - thread pool configuration structure.
*
* Argument to the fy_thread_pool_create() method.
*
* @flags: Thread pool configuration flags
* @num_threads: Number of threads, if 0 == online CPUs
* @userdata: A userdata pointer
*/
struct fy_thread_pool_cfg {
enum fy_thread_pool_cfg_flags flags;
unsigned int num_threads;
void *userdata;
};
/**
* fy_thread_pool_create() - Create a thread pool
*
* Creates a thread pool with its configuration @cfg
* The thread pool may be destroyed by a corresponding call to
* fy_thread_pool_destroy().
*
* @cfg: The configuration for the thread pool
*
* Returns:
* A pointer to the thread pool or NULL in case of an error.
*/
struct fy_thread_pool *
fy_thread_pool_create(const struct fy_thread_pool_cfg *cfg)
FY_EXPORT;
/**
* fy_thread_pool_destroy() - Destroy the given thread pool
*
* Destroy a thread pool created earlier via fy_thread_pool_create().
* Note that this function will block until all threads
* of the pool are destroyed.
*
* @tp: The thread pool to destroy
*/
void
fy_thread_pool_destroy(struct fy_thread_pool *tp)
FY_EXPORT;
/**
* fy_thread_pool_get_num_threads() - Get the number of threads
*
* Returns the actual number of created threads.
*
* @tp: The thread pool
*
* Returns:
* > 0 for the number of actual threads created,
* -1 on error
*/
int
fy_thread_pool_get_num_threads(struct fy_thread_pool *tp)
FY_EXPORT;
/**
* fy_thread_pool_get_cfg() - Get the configuration of a thread pool
*
* @tp: The thread pool
*
* Returns:
* The configuration of the thread pool
*/
const struct fy_thread_pool_cfg *
fy_thread_pool_get_cfg(struct fy_thread_pool *tp)
FY_EXPORT;
/**
* fy_thread_reserve() - Reserve a thread from the pool.
*
* Reserve a thread from the pool and return it.
* Note this is only valid for a non-work stealing thread pool.
* You release the thread again via a call to fy_thread_unreserve.
*
* @tp: The thread pool
*
* Returns:
* A reserved thread if not NULL, NULL if no threads are available.
*/
struct fy_thread *
fy_thread_reserve(struct fy_thread_pool *tp)
FY_EXPORT;
/**
* fy_thread_unreserve() - Unreserve a previously reserved thread
*
* Unreserve a thread previously reserved via a call to fy_thread_reserve()
* Note this is only valid for a non-work stealing thread pool.
*
* @t: The thread
*/
void
fy_thread_unreserve(struct fy_thread *t)
FY_EXPORT;
/**
* fy_thread_submit_work() - Submit work for execution
*
* Submit work for execution. If successful the thread
* will start executing the work in parallel with the
* calling thread. You can wait for the thread to
* terminate via a call to fy_thread_wait_work().
* The thread must have been reserved earlier via fy_thread_reserve()
*
* Note this is only valid for a non-work stealing thread pool.
*
* @t: The thread
* @work: The work
*
* Returns:
* 0 if work has been submitted, -1 otherwise.
*/
int
fy_thread_submit_work(struct fy_thread *t, struct fy_thread_work *work)
FY_EXPORT;
/**
* fy_thread_wait_work() - Wait for completion of submitted work
*
* Wait until submitted work to the thread has finished.
* Note this is only valid for a non-work stealing thread pool.
*
* @t: The thread
*
* Returns:
* 0 if work finished, -1 on error.
*/
int
fy_thread_wait_work(struct fy_thread *t)
FY_EXPORT;
/**
* fy_thread_work_join() - Submit works for execution and wait
*
* Submit works for possible parallel execution. If no offloading
* is possible at the time execute in the current context.
* It is possible to use in both stealing and non-stealing mode
* with the difference being that stealing mode is about 30% faster.
*
* @tp: The thread pool
* @works: Pointer to an array of works sized @work_count
* @work_count: The size of the @works array
* @check_fn: Pointer to a check function, or NULL for no checks
*/
void
fy_thread_work_join(struct fy_thread_pool *tp,
struct fy_thread_work *works, size_t work_count,
fy_work_check_fn check_fn)
FY_EXPORT;
/**
* fy_thread_args_join() - Execute function in parallel using arguments as pointers
*
* Execute @fn possibly in parallel using the threads in the thread pool.
* The arguments of the function are provided by the args array.
*
* @tp: The thread pool
* @fn: The function to execute in parallel
* @check_fn: Pointer to a check function, or NULL for no checks
* @args: An args array sized @count of argument pointers
* @count: The count of the args array items
*/
void
fy_thread_args_join(struct fy_thread_pool *tp,
fy_work_exec_fn fn, fy_work_check_fn check_fn,
void **args, size_t count)
FY_EXPORT;
/**
* fy_thread_arg_array_join() - Execute function in parallel using argument array
*
* Execute @fn possibly in parallel using the threads in the thread pool.
* The arguments of the function are provided by the args array.
*
* @tp: The thread pool
* @fn: The function to execute in parallel
* @check_fn: Pointer to a check function, or NULL for no checks
* @args: An args array of @argsize items
* @argsize: The size of each argument array item
* @count: The count of the args array items
*/
void
fy_thread_arg_array_join(struct fy_thread_pool *tp,
fy_work_exec_fn fn, fy_work_check_fn check_fn,
void *args, size_t argsize, size_t count)
FY_EXPORT;
/**
* fy_thread_arg_join() - Execute function in parallel with the same argument
*
* Execute @fn possibly in parallel using the threads in the thread pool.
* The argument of the functions is the same.
*
* @tp: The thread pool
* @fn: The function to execute in parallel
* @check_fn: Pointer to a check function, or NULL for no checks
* @arg: The common argument
* @count: The count of executions
*/
void
fy_thread_arg_join(struct fy_thread_pool *tp,
fy_work_exec_fn fn, fy_work_check_fn check_fn,
void *arg, size_t count)
FY_EXPORT;
/*
* Minimal exposing of internal BLAKE3 implementation
*
*/
/* BLAKE3 key length */
#define FY_BLAKE3_KEY_LEN 32
/* BLAKE3 output length */
#define FY_BLAKE3_OUT_LEN 32
/* opaque BLAKE3 hasher type for the user*/
struct fy_blake3_hasher;
/**
* fy_blake3_backend_iterate() - Iterate over the supported BLAKE3 backends
*
* This method iterates over the supported BLAKE3 backends.
* The start of the iteration is signalled by a NULL in \*prevp.
*
* The default backend is always the last in sequence, so for
* example if the order is [ "portable", "sse2", NULL ] the
* default is "sse2".
*
* @prevp: The previous backend pointer, or NULL at start
*
* Returns:
* The next backend or NULL at the end.
*/
const char *
fy_blake3_backend_iterate(const char **prevp)
FY_EXPORT;
/**
* struct fy_blake3_hasher_cfg - BLAKE3 hasher configuration
*
* Argument to the fy_blake3_hasher_create() method which
* is the fyaml's user facing BLAKE3 API.
* It is very minimal, on purpose, since it's meant to be
* exposing a full blown BLAKE3 API.
*
* @backend: NULL for default, or a specific backend name
* @file_buffer: Use this amount of buffer for buffering, zero for default
* @mmap_min_chunk: Minimum chunk size for mmap case
* @mmap_max_chunk: Maximum chunk size for mmap case
* @no_mmap: Disable mmap for file access
* @key: pointer to a FY_BLAKE3_KEY_LEN area when in keyed mode.
* NULL otherwise.
* @context: pointer to a context when in key derivation mode.
* NULL otherwise.
* @context_len: The size of the context when in key derivation mode.
* 0 otherwise.
* @tp: The thread pool to use, if NULL, create a private one
* @num_threads: Number of threads to use
* - 0 means default: NUM_CPUS * 3 / 2
* - > 0 specific number of threads
* - -1 disable threading entirely
*/
struct fy_blake3_hasher_cfg {
const char *backend;
size_t file_buffer;
size_t mmap_min_chunk;
size_t mmap_max_chunk;
bool no_mmap;
const uint8_t *key;
const void *context;
size_t context_len;
struct fy_thread_pool *tp;
int num_threads;
};
/**
* fy_blake3_hasher_create() - Create a BLAKE3 hasher object.
*
* Creates a BLAKE3 hasher with its configuration @cfg
* The hasher may be destroyed by a corresponding call to
* fy_blake3_hasher_destroy().
*
* @cfg: The configuration for the BLAKE3 hasher
*
* Returns:
* A pointer to the BLAKE3 hasher or NULL in case of an error.
*/
struct fy_blake3_hasher *
fy_blake3_hasher_create(const struct fy_blake3_hasher_cfg *cfg)
FY_EXPORT;
/**
* fy_blake3_hasher_destroy() - Destroy the given BLAKE3 hasher
*
* Destroy a BLAKE3 hasher created earlier via fy_blake3_hasher_create().
*
* @fyh: The BLAKE3 hasher to destroy
*/
void
fy_blake3_hasher_destroy(struct fy_blake3_hasher *fyh)
FY_EXPORT;
/**
* fy_blake3_hasher_update() - Update the BLAKE3 hasher state with the given input
*
* Updates the BLAKE3 hasher state by hashing the given input.
*
* @fyh: The BLAKE3 hasher
* @input: Pointer to the input
* @input_len: Size of the input in bytes
*/
void
fy_blake3_hasher_update(struct fy_blake3_hasher *fyh, const void *input, size_t input_len)
FY_EXPORT;
/**
* fy_blake3_hasher_finalize() - Finalize the hash and get output
*
* Finalizes the BLAKE3 hasher and returns the output
*
* @fyh: The BLAKE3 hasher
*
* Returns:
* A pointer to the BLAKE3 output (sized FY_BLAKE3_OUT_LEN), or NULL
* in case of an error.
*/
const uint8_t *
fy_blake3_hasher_finalize(struct fy_blake3_hasher *fyh)
FY_EXPORT;
/**
* fy_blake3_hasher_reset() - Resets the hasher
*
* Resets the hasher for re-use
*
* @fyh: The BLAKE3 hasher
*/
void
fy_blake3_hasher_reset(struct fy_blake3_hasher *fyh)
FY_EXPORT;
/**
* fy_blake3_hash() - BLAKE3 hash a memory area
*
* Hash a memory area and return the BLAKE3 output.
*
* @fyh: The BLAKE3 hasher
* @mem: Pointer to the memory to use
* @size: The size of the memory in bytes
*
* Returns:
* A pointer to the BLAKE3 output (sized FY_BLAKE3_OUT_LEN), or NULL
* in case of an error.
*/
const uint8_t *
fy_blake3_hash(struct fy_blake3_hasher *fyh, const void *mem, size_t size)
FY_EXPORT;
/**
* fy_blake3_hash_file() - BLAKE3 hash a file.
*
* Hash the given file (possibly using mmap)
*
* @fyh: The BLAKE3 hasher
* @filename: The filename
*
* Returns:
* A pointer to the BLAKE3 output (sized FY_BLAKE3_OUT_LEN), or NULL
* in case of an error.
*/
const uint8_t *
fy_blake3_hash_file(struct fy_blake3_hasher *fyh, const char *filename)
FY_EXPORT;
/* forward decl of allocator interfaces */
struct fy_allocator;
/* A tag that represents the default tag */
#define FY_ALLOC_TAG_DEFAULT 0
/* A tag that denotes error */
#define FY_ALLOC_TAG_ERROR -1
/* A tag that represents 'none' */
#define FY_ALLOC_TAG_NONE -2
/**
* fy_allocator_iterate() - Iterate over available allocator names
*
* This method iterates over all the available allocator names.
* The start of the iteration is signalled by a NULL in \*prevp.
*
* @prevp: The previous allocator iterator pointer
*
* Returns:
* The next allocator name in sequence or NULL at the end.
*/
const char *
fy_allocator_iterate(const char **prevp)
FY_EXPORT;
/**
* fy_allocator_is_available() - Check if an allocator is available
*
* Check if the named allocator is available.
*
* @name: The name of the allocator to check
*
* Returns:
* true if the allocator is available, false otherwise
*/
bool
fy_allocator_is_available(const char *name)
FY_EXPORT;
/**
* fy_allocator_create() - Create an allocator.
*
* Creates an allocator of the given type, using the configuration
* argument provided.
* The allocator may be destroyed by a corresponding call to
* fy_allocator_destroy().
*
* You can retrieve the names of available allocators
* with the fy_allocator_get_names() method.
*
* @name: The name of the allocator
* @cfg: The type specific configuration for the allocator, or NULL
* for the default.
*
* Returns:
* A pointer to the allocator or NULL in case of an error.
*/
struct fy_allocator *
fy_allocator_create(const char *name, const void *cfg)
FY_EXPORT;
/**
* fy_allocator_destroy() - Destroy the given allocator
*
* Destroy an allocator created earlier via fy_allocator_create().
* Tracking allocators will release all memory allocated using them.
*
* @a: The allocator to destroy
*/
void
fy_allocator_destroy(struct fy_allocator *a)
FY_EXPORT;
/** The minimum amount of memory for an inplace linear allocator */
#define FY_LINEAR_ALLOCATOR_IN_PLACE_MIN_SIZE 256
/**
* fy_linear_allocator_create_in_place() - Create a linear allocator in place
*
* Creates a linear allocator in place, using the buffer provided.
* No memory allocations will be performed, so it's safe to embed.
* There is no need to call fy_allocator_destroy for this allocator.
*
* @buffer: The memory buffer to use for both storage and the allocator
* @size: The size of the memory buffer
*
* Returns:
* A pointer to the allocator, or NULL if there is no space
*/
struct fy_allocator *
fy_linear_allocator_create_in_place(void *buffer, size_t size)
FY_EXPORT;
/** The minimum amount of memory for an inplace dedup allocator */
#define FY_DEDUP_ALLOCATOR_IN_PLACE_MIN_SIZE 4096
/**
* fy_dedup_allocator_create_in_place() - Create a dedp allocator in place
*
* Creates a dedup allocator in place, using the buffer provided.
* No memory allocations will be performed, so it's safe to embed.
* There is no need to call fy_allocator_destroy for this allocator.
* The parent allocator of this will be a linear allocator.
*
* @buffer: The memory buffer to use for both storage and the allocator
* @size: The size of the memory buffer
*
* Returns:
* A pointer to the allocator, or NULL if there is no space
*/
struct fy_allocator *
fy_dedup_allocator_create_in_place(void *buffer, size_t size)
FY_EXPORT;
/**
* fy_allocator_get_tag() - Get a tag from an allocator
*
* The allocator interface requires all allocation to belong
* to a tag. This call creates a tag and returns its value,
* or an error if not available.
*
* If an allocator only provides a single tag (like the linear
* allocator for instance), the same tag number, usually 0, is
* returned.
*
* @a: The allocator
*
* Returns:
* The created tag or -1 in case of an error.
*/
int
fy_allocator_get_tag(struct fy_allocator *a)
FY_EXPORT;
/**
* fy_allocator_release_tag() - Release a tag from an allocator
*
* Releases a tag from an allocator and frees all memory it
* allocated (if such an operation is provided by the allocator).
*
* @a: The allocator
* @tag: The tag to release
*/
void
fy_allocator_release_tag(struct fy_allocator *a, int tag)
FY_EXPORT;
/**
* fy_allocator_get_tag_count() - Get the maximum number of tags a
* allocator supports
*
* Get the maximum amount of tags an allocator supports.
*
* If an allocator only provides a single tag (like the linear
* allocator for instance), 1 will be returned.
*
* @a: The allocator
*
* Returns:
* The number of tags, or -1 on error
*/
int
fy_allocator_get_tag_count(struct fy_allocator *a)
FY_EXPORT;
/**
* fy_allocator_set_tag_count() - Set the maximum number of tags a
* allocator supports
*
* Sets the maximum amount of tags an allocator supports.
* If the set allocator tag count is less than the current
* the additional tags will be released.
*
* @a: The allocator
* @count: The amount of tags the allocator should support
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_allocator_set_tag_count(struct fy_allocator *a, unsigned int count)
FY_EXPORT;
/**
* fy_allocator_trim_tag() - Trim a tag
*
* Trim a tag, that is free any excess memory it allocator, fitting
* it to the size of the content it carries.
* Allocators that cannot perform this operation treat it as a NOP.
*
* @a: The allocator
* @tag: The tag to trim
*/
void
fy_allocator_trim_tag(struct fy_allocator *a, int tag)
FY_EXPORT;
/**
* fy_allocator_reset_tag() - Reset a tag
*
* Reset a tag, that is free any content it carries, but do not
* release the tag.
*
* @a: The allocator
* @tag: The tag to reset
*/
void
fy_allocator_reset_tag(struct fy_allocator *a, int tag)
FY_EXPORT;
/**
* fy_allocator_alloc() - Allocate memory from an allocator
*
* Allocate memory from the given allocator tag, satisfying the
* size and align restrictions.
*
* @a: The allocator
* @tag: The tag to allocate from
* @size: The size of the memory to allocate
* @align: The alignment of the object
*
* Returns:
* A pointer to the allocated memory or NULL
*/
void *
fy_allocator_alloc(struct fy_allocator *a, int tag, size_t size, size_t align)
FY_EXPORT;
/**
* fy_allocator_free() - Free memory allocated from an allocator
*
* Attempt to free the memory allocated previously by fy_allocator_alloc()
* Note that non per object tracking allocators treat this as a NOP
*
* @a: The allocator
* @tag: The tag used to allocate the memory
* @ptr: The pointer to the memory to free
*/
void
fy_allocator_free(struct fy_allocator *a, int tag, void *ptr)
FY_EXPORT;
/**
* fy_allocator_store() - Store an object to an allocator
*
* Store an object to an allocator and return a pointer to the location
* it was stored. When using a deduplicating allocator no new allocation
* will take place and a pointer to the object already stored will be
* returned.
*
* The return pointer must not be modified, the objects stored are idempotent.
*
* @a: The allocator
* @tag: The tag used to allocate the memory
* @data: The pointer to object to store
* @size: The size of the object
* @align: The alignment restriction of the object
*
* Returns:
* A constant pointer to the object stored, or NULL in case of an error
*/
const void *
fy_allocator_store(struct fy_allocator *a, int tag, const void *data, size_t size, size_t align)
FY_EXPORT;
/**
* fy_allocator_storev() - Store an object to an allocator (scatter gather)
*
* Store an object to an allocator and return a pointer to the location
* it was stored. When using a deduplicating allocator no new allocation
* will take place and a pointer to the object already stored will be
* returned.
*
* The object is created linearly from the scatter gather io vector provided.
*
* The return pointer must not be modified, the objects stored are immutable.
*
* @a: The allocator
* @tag: The tag used to allocate the memory from
* @iov: The I/O scatter gather vector
* @iovcnt: The number of vectors
* @align: The alignment restriction of the object
*
* Returns:
* A constant pointer to the object stored, or NULL in case of an error
*/
const void *
fy_allocator_storev(struct fy_allocator *a, int tag, const struct iovec *iov, int iovcnt, size_t align)
FY_EXPORT;
/**
* fy_allocator_lookup() - Lookup for object in an allocator.
*
* Lookup for the exact contents of an object stored in an allocator
* and return a pointer to the location it was stored.
* The allocator must have the FYACF_CAN_LOOKUP capability.
*
* @a: The allocator
* @tag: The tag used to locate the memory
* @data: The pointer to object to store
* @size: The size of the object
* @align: The alignment restriction of the object
*
* Returns:
* A constant pointer to the object stored, or NULL if the object does not exist
*/
const void *
fy_allocator_lookup(struct fy_allocator *a, int tag, const void *data, size_t size, size_t align)
FY_EXPORT;
/**
* fy_allocator_lookupv() - Lookup for object in an allocator (scatter gather)
*
* Lookup for the exact contents of an object stored in an allocator
* and return a pointer to the location it was stored.
* The allocator must have the FYACF_CAN_LOOKUP capability.
*
* The scatter gather vector is used to recreate the object.
*
* @a: The allocator
* @tag: The tag used to search into
* @iov: The I/O scatter gather vector
* @iovcnt: The number of vectors
* @align: The alignment restriction of the object
*
* Returns:
* A constant pointer to the object stored, or NULL in case the object does not exist
*/
const void *
fy_allocator_lookupv(struct fy_allocator *a, int tag, const struct iovec *iov, int iovcnt, size_t align)
FY_EXPORT;
/**
* fy_allocator_dump() - Dump internal allocator state
*
* @a: The allocator
*/
void
fy_allocator_dump(struct fy_allocator *a)
FY_EXPORT;
/**
* enum fy_allocator_cap_flags - Allocator capability flags
*
* @FYACF_CAN_FREE_INDIVIDUAL: Allocator supports freeing individual allocations
* @FYACF_CAN_FREE_TAG: Allocator supports releasing entire tags
* @FYACF_CAN_DEDUP: Allocator supports deduplication
* @FYACF_HAS_CONTAINS: Allocator can report if it contains a pointer (even if inefficiently)
* @FYACF_HAS_EFFICIENT_CONTAINS: Allocator can report if it contains a pointer (efficiently)
* @FYACF_HAS_TAGS: Allocator has individual tags or not
* @FYACF_CAN_LOOKUP: Allocator supports lookup for content
*
* These flags describe what operations an allocator supports.
*/
enum fy_allocator_cap_flags {
FYACF_CAN_FREE_INDIVIDUAL = FY_BIT(0),
FYACF_CAN_FREE_TAG = FY_BIT(1),
FYACF_CAN_DEDUP = FY_BIT(2),
FYACF_HAS_CONTAINS = FY_BIT(3),
FYACF_HAS_EFFICIENT_CONTAINS = FY_BIT(4),
FYACF_HAS_TAGS = FY_BIT(5),
FYACF_CAN_LOOKUP = FY_BIT(6),
};
/**
* fy_allocator_get_caps() - Get allocator capabilities
*
* Retrieve the capabilities of an allocator.
*
* @a: The allocator
*
* Returns:
* The capabilities of the allocator
*/
enum fy_allocator_cap_flags
fy_allocator_get_caps(struct fy_allocator *a)
FY_EXPORT;
/**
* fy_allocator_contains() - Check if a allocator contains a pointer
*
* Report if an allocator contains the pointer
*
* @a: The allocator
* @tag: Tag to search in, -1 for all
* @ptr: The object pointer
*
* Returns:
* true if the pointer ptr is contained in the allocator, false otherwise
*/
bool
fy_allocator_contains(struct fy_allocator *a, int tag, const void *ptr)
FY_EXPORT;
/**
* fy_allocator_get_tag_linear_size() - Get the linear size of an allocator tag
*
* Retrieve the linear size of the content of a tag.
* That is the size of a buffer if one was to copy the content of the tag in
* that buffer in a linear manner.
*
* @a: The allocator
* @tag: The tag
*
* Returns:
* The linear size of the content stored in the tag or -1 in case of an error.
*/
ssize_t
fy_allocator_get_tag_linear_size(struct fy_allocator *a, int tag)
FY_EXPORT;
/**
* fy_allocator_get_tag_single_linear() - Get the linear extend of a tag
*
* If a tag stores it's content in a single linear buffer, retrieve it
* directly. This is possible only under careful arrangement of allocator
* configuration, but it is an important optimization case.
*
* @a: The allocator
* @tag: The tag
* @sizep: Pointer to a variable that will be filled with the size.
*
* Returns:
* A pointer to the linear content of the tag, or NULL if othersize.
*/
const void *
fy_allocator_get_tag_single_linear(struct fy_allocator *a, int tag, size_t *sizep)
FY_EXPORT;
/**
* struct fy_linear_allocator_cfg - linear allocator configuration
*
* @buf: A pointer to a buffer that will be used, or NULL in order to allocate
* @size: Size of the buffer in bytes
*/
struct fy_linear_allocator_cfg {
void *buf;
size_t size;
};
/**
* enum fy_mremap_arena_type - The mremap allocator arena types
*
* @FYMRAT_DEFAULT: Use what's optimal for this platform
* @FYMRAT_MALLOC: Use malloc/realloc arena type (not recommended)
* @FYMRAT_MMAP: Use mmap/mremap arena type
*
*/
enum fy_mremap_arena_type {
FYMRAT_DEFAULT,
FYMRAT_MALLOC,
FYMRAT_MMAP,
};
/**
* struct fy_mremap_allocator_cfg - mremap allocator configuration
*
* If any of the fields is zero, then the system will provide (somewhat)
* reasonable defaults.
*
* @big_alloc_threshold: Threshold for immediately creating a new arena.
* @empty_threshold: The threshold under which an arena is moved to the full list.
* @minimum_arena_size: The minimum (and starting size) of an arena.
* @grow_ratio: The ratio which an arena will try to grow if full (>1.0)
* @balloon_ratio: The multiplier for the vm area first allocation
* @arena_type: The arena type
*/
struct fy_mremap_allocator_cfg {
size_t big_alloc_threshold;
size_t empty_threshold;
size_t minimum_arena_size;
float grow_ratio;
float balloon_ratio;
enum fy_mremap_arena_type arena_type;
};
/* malloc allocator has no configuration data, pass NULL */
/**
* struct fy_dedup_allocator_cfg - dedup allocator configuration
*
* @parent_allocator: The parent allocator (required)
* @bloom_filter_bits: Number of bits of the bloom filter (or 0 for default)
* @bucket_count_bits: Number of bits for the bucket count (or 0 for default)
* @dedup_threshold: Number of bytes over which dedup takes place (default 0=always)
* @chain_length_grow_trigger: Chain length of a bucket over which a grow takes place (or 0 for auto)
* @estimated_content_size: Estimated content size (or 0 for don't know)
* @minimum_bucket_occupancy: The minimum amount that a tag bucket must be full before
* growth is allowed (default 50%, or 0.0)
*/
struct fy_dedup_allocator_cfg {
struct fy_allocator *parent_allocator;
unsigned int bloom_filter_bits;
unsigned int bucket_count_bits;
size_t dedup_threshold;
unsigned int chain_length_grow_trigger;
size_t estimated_content_size;
float minimum_bucket_occupancy;
};
/**
* enum fy_auto_allocator_scenario_type - auto allocator scenario type
*
* @FYAST_PER_TAG_FREE: only per tag freeing, no individual obj free
* @FYAST_PER_TAG_FREE_DEDUP: per tag freeing, dedup obj store
* @FYAST_PER_OBJ_FREE: object freeing allowed, tag freeing still works
* @FYAST_PER_OBJ_FREE_DEDUP: per obj freeing, dedup obj store
* @FYAST_SINGLE_LINEAR_RANGE: just a single linear range, no frees at all
* @FYAST_SINGLE_LINEAR_RANGE_DEDUP: single linear range, with dedup
*/
enum fy_auto_allocator_scenario_type {
FYAST_PER_TAG_FREE,
FYAST_PER_TAG_FREE_DEDUP,
FYAST_PER_OBJ_FREE,
FYAST_PER_OBJ_FREE_DEDUP,
FYAST_SINGLE_LINEAR_RANGE,
FYAST_SINGLE_LINEAR_RANGE_DEDUP,
};
/**
* struct fy_auto_allocator_cfg - auto allocator configuration
*
* @scenario: Auto allocator scenario
* @estimated_max_size: Estimated max content size (or 0 for don't know)
*/
struct fy_auto_allocator_cfg {
enum fy_auto_allocator_scenario_type scenario;
size_t estimated_max_size;
};
struct fy_parser_checkpoint;
/**
* fy_parser_checkpoint_create() - Create a parser checkpoint
*
* Create a checkpoint of the parser's current state. This allows you
* to save the parser state and potentially roll back to it later using
* fy_parser_rollback(). The checkpoint must be destroyed via
* fy_parser_checkpoint_destroy() when no longer needed.
*
* @fyp: The parser
*
* Returns:
* A pointer to the checkpoint, or NULL in case of an error
*/
struct fy_parser_checkpoint *
fy_parser_checkpoint_create(struct fy_parser *fyp)
FY_EXPORT;
/**
* fy_parser_checkpoint_destroy() - Destroy a parser checkpoint
*
* Destroy a checkpoint created earlier via fy_parser_checkpoint_create().
*
* @fypchk: The checkpoint to destroy
*/
void
fy_parser_checkpoint_destroy(struct fy_parser_checkpoint *fypchk)
FY_EXPORT;
/**
* fy_parser_rollback() - Roll back the parser to a checkpoint
*
* Roll back the parser state to a previously created checkpoint. This allows
* you to revert the parser to an earlier state and re-parse from that point.
* The checkpoint remains valid after rollback and can be used again or
* destroyed via fy_parser_checkpoint_destroy().
*
* @fyp: The parser
* @fypc: The checkpoint to roll back to
*
* Returns:
* 0 on success, -1 on error
*/
int
fy_parser_rollback(struct fy_parser *fyp, struct fy_parser_checkpoint *fypc)
FY_EXPORT;
#ifdef __cplusplus
}
#endif
#endif
|