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
|
head 1.24;
access;
symbols;
locks; strict;
comment @# @;
1.24
date 99.12.13.16.18.30; author krisrose; state Exp;
branches;
next 1.23;
1.23
date 99.12.09.16.18.39; author krisrose; state Exp;
branches;
next 1.22;
1.22
date 99.12.09.08.22.01; author krisrose; state Exp;
branches;
next 1.21;
1.21
date 99.12.09.03.47.43; author krisrose; state Exp;
branches;
next 1.20;
1.20
date 99.12.06.21.08.09; author krisrose; state Exp;
branches;
next 1.19;
1.19
date 99.12.03.23.46.37; author krisrose; state Exp;
branches;
next 1.18;
1.18
date 99.12.03.23.24.40; author krisrose; state Exp;
branches;
next 1.17;
1.17
date 99.12.03.02.08.56; author krisrose; state Exp;
branches;
next 1.16;
1.16
date 99.12.02.00.32.24; author krisrose; state Exp;
branches;
next 1.15;
1.15
date 99.12.01.03.41.19; author krisrose; state Exp;
branches;
next 1.14;
1.14
date 99.11.30.18.28.23; author krisrose; state Exp;
branches;
next 1.13;
1.13
date 99.11.29.16.09.02; author krisrose; state Exp;
branches;
next 1.12;
1.12
date 99.11.25.18.42.03; author krisrose; state Exp;
branches;
next 1.11;
1.11
date 99.11.25.03.01.47; author krisrose; state Exp;
branches;
next 1.10;
1.10
date 99.11.24.16.46.57; author krisrose; state Exp;
branches;
next 1.9;
1.9
date 99.11.23.17.28.07; author krisrose; state Exp;
branches;
next 1.8;
1.8
date 99.11.23.10.27.04; author krisrose; state Exp;
branches;
next 1.7;
1.7
date 99.11.23.10.10.36; author krisrose; state Exp;
branches;
next 1.6;
1.6
date 99.11.23.09.32.31; author krisrose; state Exp;
branches;
next 1.5;
1.5
date 99.11.23.04.03.05; author krisrose; state Exp;
branches;
next 1.4;
1.4
date 99.11.23.02.37.11; author krisrose; state Exp;
branches;
next 1.3;
1.3
date 99.11.22.18.41.48; author krisrose; state Exp;
branches;
next 1.2;
1.2
date 99.11.08.03.21.12; author krisrose; state Exp;
branches;
next 1.1;
1.1
date 99.10.26.16.19.45; author krisrose; state Exp;
branches;
next ;
desc
@@
1.24
log
@pcdata -> {#PCDATA}
@
text
@#!/usr/bin/perl -w
# Flex(1) XML processor scanner generator.
# Copyright 1999 Kristoffer Rose. All rights reserved.
#
# This file is part of the FleXML XML processor generator system.
# Copyright 1999 Kristoffer Rose. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place, Suite 330, Boston, MA 02111-1307 USA.
my $Id = '$Id: flexml.pl,v 1.23 1999/12/09 16:18:39 krisrose Exp krisrose $ ';
$Id =~ s/\s*\$\s*//go;
# IMPORTS.
use Getopt::Std;
use LWP::UserAgent;
use strict;
# FILES (must be global).
use vars qw/ $SKELETON /; # the skeleton scanner
use vars qw/ $SCANNER /; # generated XML processor (+ application if requested)
use vars qw/ $HEADER /; # generated XML processor API header
use vars qw/ $ACTIONS /; # the actions file
use vars qw/ $APPLICATION /; # generated XML application
# OPTIONS (and other globals).
my $Use; # usage string
my %opt = (); # options
my $debug; # -d option flag
my $verbose; # -v option flag
my $lineno; # -L option flag
my $nofail; # -X option flag
my $uri; # -u option uri
my $pubid; # -p option string
my $dtd; # DTD file name (or URI)
my $dtdrevision; # DTD version pruned from file
my $cdtd; # C identifier derived from DTD name
my @@inputs = (); # input data stack (array of arrays of lines)
my @@inputnames = (); # names of files on input data stack
my @@inputlinenos = (); # line number in input files
# DTD regular expressions (extended to not mess up the counting).
my $NameChar = '[A-Za-z0-9.:_-]';
my $Name = "[A-Za-z_:]$NameChar*";
my $Names = "$Name(?:\s+$Name)*";
my $Nmtoken = "$NameChar+";
my $Nmtokens = "$Nmtoken(?:\s+$Nmtoken)*";
my $Eq = '\s*=\s*';
my $Literal = '(?:\'[^\']*\'|"[^"]*")';
# DTD DESCRIPTION STRUCTURES.
my %source = (); # DTD source lines associated to tag and tag/attribute.
my @@tags = (); # Tags of the DTD.
my %roottags = (); # Tags that may be the root tag.
my %ctag = (); # C variable name of each tag.
my %states = (); # $states{tag} is list of states used by tag element.
my %emptytrans = (); # $emptytrans{state} contains empty transitions in automaton.
my %instates = (); # $instates{tag} is list of states for element start/empty tag.
my %startstate = (); # $startstate{tag} is the state entered after the start tag.
my %endstates = (); # $endstates{tag} is list of states for element end tag.
my %exittrans = (); # $exittrans{tag} is state transitions after end tag.
my %empty = (); # $empty{tag} == true if the tag may be empty.
my %properempty = (); # $empty{tag} == true if the tag is declared EMPTY
my %any = (); # $any{tag} == true if the tag has ANY contents.
my %mixed = (); # $mixed{tag} == true if the tag has Mixed (or ANY) contents.
my %children = (); # $children{tag} == true if the tag has Element contents
my %inmixed = (); # $inmixed{tag} == true if the tag occurs *in* Mixed contents.
my @@attributes = (); # Attributes of the DTD.
my %catt = (); # C variable name for attribute.
my %atttype = (); # XML AttType (type) of tag/attribute
my %enumtype = (); # whether the tag/attribute is an enumeration type
my %literaltype = (); # whether the tag/attribute is a tokenized type
my %entitytype = (); # whether the tag/attribute is of entity type
my %typeof = (); # C type of tag/attribute
my %attdef = (); # XML AttDef (default value) of tag/attribute
my %required = (); # true if tag/attribute is required
my %fixed = (); # true if tag/attribute has fixed default
my %initof = (); # C initial attribute value of tag/attribute, if any
my %attlist = (); # $attlist{tag} is comma-separated list of attribute
# names allowed in tag elements.
my %withattr = (); # $withattr{attribute} is comma-separated list of
# elements within which the tag element may occur.
my %entity = (); # general entity table (C strings)
my %parameter = (); # parameter entity table (raw string)
my %external = (); # external entity table (uris)
my %startok = (); # start tag action already dumped
my %endok = (); # end tag action already dumped
# UTILITIES.
sub printsource { # Print source lines of argument.
my ($key) = @@_;
local $_ = $source{$key};
return if not $_;
s:[*][/]:* /:g; # avoid */ in output [sic]
s/\n/\n * /mg;
print "\n /* " . $_ . " */\n";
}
sub cquote { # Convert a string to C source format.
local ($_) = @@_;
s/\\/\\\\/g; # First replace \ to avoid interference...
s/\"/\\\"/g;
s/\n/\\n/g; s/\r/\\r/g; s/\t/\\t/g; s/\f/\\f/g;
s/[\0-\037\200-\377]/ sprintf("\\%.3o",ord($&)) /ge;
$_
}
sub variablify { # Change XML Name to legal C variable name.
local ($_) = @@_;
s|-|_d_|go;
s|:|_c_|go;
s|/|__|go;
$_
}
sub redistribute { # Print C comment with generated file "license".
my ($pre) = @@_;
print <<EOT;
$pre This program was generated with the FleXML XML processor generator,
$pre ($Id).
$pre Copyright 1999 Kristoffer Rose. All rights reserved.
$pre
$pre You can redistribute and/or modify this program provided the following
$pre two conditions hold:
$pre
$pre 1. The program is distributed WITHOUT ANY WARRANTY from the author of
$pre FleXML; without even the implied warranty of MERCHANTABILITY or
$pre FITNESS FOR A PARTICULAR PURPOSE.
$pre
$pre 2. The program distribution conditions do not in any way affect the
$pre distribution conditions of the FleXML system used to generate this
$pre file or any version of FleXML derived from that system.
$pre
$pre Notice that these are explicit rights granted to you for files
$pre generated by the FleXML system. For your rights in connection with
$pre the FleXML system itself please consult the GNU General Public License.
EOT
}
sub api_functions { # Print XML application interface functions.
my ($pre,$post) = @@_;
print "/* XML application entry points. */\n" if @@tags;
for (@@tags) {
print $pre . "void STag_$ctag{$_}(void)$post\n" unless $startok{$_};
print $pre . "void ETag_$ctag{$_}(void)$post\n" unless $endok{$_};
}
}
sub api_types { # Print XML application interface types.
print "/* XML application data. */\n" if %atttype;
for (keys %atttype) {
if (m.($Nmtoken)[/]($Nmtoken).xo) {
my ($tag,$attribute) = ($1,$2);
print "typedef $typeof{$_} AT_$ctag{$tag}_$catt{$attribute};\n";
print "#define AU_$ctag{$tag}_$catt{$attribute} NULL\n"
if not $enumtype{$_};
}
}
}
sub api_data { # Print XML application interface parameters.
my ($pre) = @@_;
print "/* FleXML-provided data. */\n";
print $pre . "char* pcdata;\n";
for (keys %atttype) {
if (m.($Nmtoken)[/]($Nmtoken).xo) {
print $pre . "AT_$ctag{$1}_$catt{$2} A_$ctag{$1}_$catt{$2};\n";
}
}
}
sub expandparametersat { # Expand parameter entities in $_ at $place.
my ($place) = @@_;
while ( m/$place\s*%($Name);/ ) {
if ($parameter{$1}) {
s/$place(\s*)%($Name);/ ' '. $1 . $parameter{$2} . ' ' /xe;
}
}
}
sub geturl { # Insert contents of URL into input stream at current point
my ($url) = @@_;
$url = "file:$url" if not $url =~ m/:/;
local $_ = $url;
s.([^/:]*[/:])*..g;
s/\.dtd$//;
print STDOUT "Fetching URL <$url>.\n" if $verbose;
my $ua = new LWP::UserAgent; # Create a user agent object
$ua->agent("FleXML/1 " . $ua->agent);
my $req = new HTTP::Request GET => $url; # Create a request
my $res = $ua->request($req); # Pass request to the user agent and get a response
if ($res->is_error) {
die place()."URL <$url> could not be fetched.\n";
}
# Make the data available...
push @@inputs, [ split /\r?\n/, $res->content ];
if (@@{$inputs[$#inputs]}) {
push @@inputnames, "$url";
push @@inputlinenos, 0;
}
else {
pop @@inputs; # oops, empty.
}
# print STDOUT "Testing:\n";
# my $i = 0;
# for my $ref (@@inputs) {
# print STDOUT " inputs[" . $i++ . "] =\n";
# for my $line (@@{$ref}) {
# print " | $line\n";
# }
# }
# $i = 0;
# for my $name (@@inputnames) {
# print STDOUT " inputnames[" . $i++ . "] = `$name'\n";
# }
# $i = 0;
# for my $no (@@inputlinenos) {
# print STDOUT " inputlinenos[" . $i++ . "] = `$no'\n";
# }
}
sub nextline { # return one input line
return undef unless @@inputs;
my $line = shift @@{$inputs[$#inputs]};
$inputlinenos[$#inputs]++;
while (@@inputs and not @@{$inputs[$#inputs]}) { # discard exhausted inputs
pop @@inputs;
pop @@inputnames;
pop @@inputlinenos;
}
return $line;
}
sub place {
if (@@inputs) {
local $_ = "\"$inputnames[$#inputs]\", line $inputlinenos[$#inputs]: ";
s/"file:/"/;
return $_;
}
else {
return "";
}
}
sub extractcp { # Split argument in one cp[48] and the rest.
local ($_) = @@_;
if ( m/^($Name[+?*]?)\s*/o ) {
return ($1,$');
}
elsif ( m/^\s*\(/o ) {
my $cp = '('; $_ = $';
my $level = 1;
while ($level > 0 and $_) {
if ( m/^\s*\(\s*/o ) {
$level++; $cp .= '('; $_ = $';
}
elsif ( m/^\s*(\)[+?*]?)\s*/o ) {
$level--; $cp .= $1; $_ = $';
}
elsif ( m/^\s+/o ) {
$_ = $';
}
else {
m/[^()\s]+/o; $cp .= $&; $_ = $';
}
}
return ($cp,$_);
}
}
my $statecounter;
sub analysechildren { # Analyse DTD children specification; return
# true if it may be empty. Uses global $statecounter.
my ($tag,$re,$in,$out) = @@_;
local $_ = $re;
if ( m/^\s*($Name)\s*$/o ) { # tag
my $thetag = $1;
my %ins = ();
if (exists $instates{$thetag}) {
for (split /,/,$instates{$thetag}) { $ins{$_} = 'true'; }
}
$ins{$in} = 'true';
$instates{$thetag} = join(',',keys %ins);
$exittrans{$thetag} .= ($exittrans{$thetag}?',':'') . "$in=>$out" if $in ne $out;
return undef;
}
elsif ( m/^((.|\n)+)\?\s*$/o ) { # re ?
$emptytrans{$in} .= ($emptytrans{$in}?',':'') . $out unless $in eq $out;
analysechildren($tag,$1,$in,$out);
return 'true';
}
elsif ( m/^((.|\n)+)\+\s*$/o ) { # re +
my $re = $1;
my $s1 = "S_$ctag{$tag}_" . (++$statecounter);
my $s2 = "S_$ctag{$tag}_" . (++$statecounter);
$states{$tag} .= ",$s1,$s2";
$emptytrans{$in} .= ($emptytrans{$in}?',':'') . $s1;
$emptytrans{$s2} = "$s1,$out";
return analysechildren($tag,$re,$s1,$s2);
}
elsif ( m/^((.|\n)+)\*\s*$/o ) { # re *
return analysechildren($tag,"$1+?",$in,$out);
}
elsif ( m/^\s*\(\s*((.|\n)+)\s*\)\s*$/xo ) { # choice or seq
local $_;
my $cp;
($cp,$_) = extractcp($1);
if ( m/^\s*$/ ) { # () with single member.
return analysechildren($tag,$cp,$in,$out);
}
elsif ( m/^\s*([|,])\s*/m ) {
my $type = "[$1]";
my $maybeempty = ($type eq '[,]');
my $state = $in;
while ( m/^\s*$type\s*/ ) {
$_ = $';
if ($type eq '[|]') { # $cp is choice
$maybeempty = 'true' if analysechildren($tag,$cp,$in,$out);
}
else { # $cp is seq component
my $oldstate = $state;
$state = "S_$ctag{$tag}_" . (++$statecounter);
$states{$tag} .= ",$state";
$maybeempty = undef unless analysechildren($tag,$cp,$oldstate,$state);
}
($cp,$_) = extractcp($_);
}
# Last cp needs special treatment in sequence.
if ($type eq '[|]') { # $cp is choice
$maybeempty = 'true' if analysechildren($tag,$cp,$in,$out);
}
else { # $cp is seq component
$maybeempty = undef unless analysechildren($tag,$cp,$state,$out);
}
$emptytrans{$in} .= ($emptytrans{$in}?',':'') . $out
if $maybeempty and $in ne $out;
return $maybeempty unless $_;
}
}
die place()."DTD element `$tag' has nonsense fragment `$_'.\n";
}
# OPTIONS PROCESSING (explained in manual).
# Parse options.
$Use = "Usage: flexml [-ASHDvdnLXV] [-s skel] [-p pubid] [-u uri]\n"
. " [-r roottags] [-a actions] name[.dtd]";
getopts('ASHDvdnLXVp:s:u:r:a:', \%opt);
# Version!
print "FleXML version $Id.\n" if $opt{V} or $opt{v};
exit 0 if $opt{V};
# Debugging?
$debug = $opt{d};
$verbose = $opt{v};
# Line numbers?
$lineno = $opt{L};
# Exit without fail message?
$nofail = $opt{X};
# Specific root tags?
if ($opt{r}) {
for (split ',',$opt{r}) { $roottags{$_} = 'true'; }
}
# Set skeleton scanner file name and check it is readable (if needed).
$SKELETON = ($opt{'s'} ? $opt{'s'} : './skel');
die "$0: No skeleton file $SKELETON.\n" if not -r $SKELETON and $opt{S};
# Set document type URI and PUBID.
$uri = $opt{u} if $opt{u};
$pubid = $opt{p} if $opt{p};
# Set DTD file name...and extract prefix for later
my $prefix = $ARGV[0];
if (defined $prefix and $#ARGV == 0) {
$prefix =~ s/\.dtd$//;
$dtd = "$prefix.dtd"; # Require .dtd extension on DTD
geturl($dtd); # Read the DTD
$prefix =~ s|^([^:/]*[:/])*||;
$cdtd = variablify($prefix);
}
else {
die "$Use\n";
}
# Selection options: If none of -SHDA specified then default to -SH.
# Furthermore -a implies -D.
$opt{S} = $opt{H} = 'true' unless ($opt{S} or $opt{H} or $opt{D} or $opt{A});
$opt{D} ||= $opt{a} unless $opt{A};
# Set default (DTD-based) output file names.
$SCANNER = "$prefix.l";
$HEADER = "$prefix.h";
$APPLICATION = "$prefix-dummy.c";
# Set actions=based output file names, if any.
if ($ACTIONS = $opt{a}) {
$opt{a} =~ s/\.[a-z]+$//;
$APPLICATION = "$opt{a}.c";
}
# Stand-alone applications...
if ($opt{A}) {
die "$0: -A conflicts with -SHD.\n" if ($opt{S} or $opt{H} or $opt{D});
$SCANNER = $APPLICATION;
$SCANNER =~ s/\.c$/.l/;
}
# Dry-run?
if ($opt{n}) {
$opt{A} = $opt{S} = $opt{H} = $opt{D} = undef;
}
# PARSE DTD.
print STDOUT "Processing DTD in $dtd.\n" if $verbose;
$_ = ''; # Current entry
while (@@inputs) { # While there are lines...
my $orig = "$_"; # current source line(s)
# Skip spaces and complete comments (but save as source).
do {
# Skip blank lines.
$_ = nextline() while @@inputs and m/^\s*$/;
# If we're looking at a parameter or external entity then expand it.
if ( m/^\s*%($Name);/ ) {
my $ent = $1;
if ($parameter{$ent}) {
expandparametersat('^');
}
elsif ($external{$ent}) {
$_ = $';
geturl($external{$ent});
}
else {
die "Unknown entity `%$ent;'\n";
}
}
# Skip (but save) comments.
while ( m/^\s*<!--/ ) {
until (m/-->/ or not @@inputs) { $_ .= "\n" . nextline(); }
# Extract first DTD version number...
if ( not $dtdrevision and /\$(Id|Header|Revision): [^\$]*\$/ ) {
$dtdrevision = "$&";
$dtdrevision =~ s/\s*\$\s*//go;
}
# Remove the comment to read on to next nonblank (but save as
# source).
$orig .= ($orig?"\n":"").$1 if s/^\s*(<!--([^-]|-[^-]|--[^>])*-->)\s*//;
}
s/^\s*//;
} until $_ or not @@inputs;
# If we're looking at a parameter or external entity then expand and retry.
if ( m/^\s*%($Name);/ ) {
my $ent = $1;
if ($parameter{$ent}) {
expandparametersat('^');
}
elsif ($external{$ent}) {
$_ = $';
geturl($external{$ent});
next;
}
else {
die "Unknown entity `%$ent;'\n";
}
}
die place()."Nonsense `$_'.\n" if /^[^<]/ or /^<[^!]/;
# Read on until a full DTD <!...> or <?...?> entry is available.
until (m/^\s*<![^>]*>/o or m/^\s*<[?]([^?]|[?][^>])*[?]>/o or not @@inputs) {
my $line = nextline();
$orig .= ($orig?"\n":"") . $line;
$_ .= "\n" . $line;
}
unless ( m/^\s*<![^>]*>/o or m/^\s*<[?]([^?]|[?][^>])*[?]>/o ) {
last if not @@inputs;
die place()."Could not find end of declaration.\n";
}
# Clean out in $orig.
$orig =~ s/\n+/\n/g;
$orig =~ s/^\n*//g;
$orig =~ s/\n*$//g;
print STDOUT " [$_]\n" if $debug;
# Processing instruction.
if ( m/^\s*<[?]([^?]|[?][^>])*[?]>\s*/o ) {
print STDERR place()."Warning: ignoring processing instruction $&.\n";
$_ = $';
}
# Parse element declarations.
elsif ( m/^<!ELEMENT\s+($Name)\s+([^>]*)>\s*/xo ) {
$_ = $'; $source{$1} = "$orig";
my $tag = $1;
die place()."Repeated element $tag.\n" if $ctag{$tag};
push @@tags, $tag;
# Create C-friendly tag names.
$ctag{$tag} = variablify($tag) unless $ctag{$tag};
my $c = $ctag{$tag};
local $_ = $2;
expandparametersat(''); s/^\s+//;
# All elements should be followed by nothing when at the root.
$exittrans{$tag} .= ($exittrans{$tag}?',':'') . "ROOT_$c=>EPILOG"
if not %roottags or $roottags{$tag};
# Handle element declaration.
if ( m/^EMPTY\s*$/o ) {
$empty{$tag} = 'true';
$properempty{$tag} = 'true';
$states{$tag} = "E_$c";
$startstate{$tag} = "E_$c";
$endstates{$tag} = "E_$c";
}
elsif ( m/^ANY\s*$/o ) {
$any{$tag} = 'true';
$mixed{$tag} = 'true';
$empty{$tag} = 'true';
$states{$tag} = "IN_$c";
$startstate{$tag} = "IN_$c";
$endstates{$tag} = "IN_$c";
}
elsif ( m/^\(\s*\#PCDATA\s*\)\s*$/o
or m/^\(\s*\#PCDATA\s*((\|\s*$Name\s*)*)\)\*\s*$/xo ) {
$mixed{$tag} = 'true';
$empty{$tag} = 'true';
if ($1) {
my $desc = $1;
$desc =~ s/^\s*\|\s*//o;
for (split /\s*\|\s*/,$desc) {
$instates{$_} .= ($instates{$_}?',':'') . "IN_$c";
$inmixed{$_} = 'true';
}
}
$states{$tag} = "IN_$c";
$startstate{$tag} = "IN_$c";
$endstates{$tag} = "IN_$c";
}
else {
$children{$tag} = 'true';
$statecounter = 0;
$states{$tag} = "S_$c";
$startstate{$tag} = "S_$c";
$empty{$tag} = 'true' if analysechildren($tag,$_,"S_$c","E_$c");
$states{$tag} .= ",E_$c";
$endstates{$tag} = "E_$c";
}
}
# Parse attribute declarations.
elsif ( m/^<!ATTLIST\s+($Name)\s+([^>]*)>\s*/o ) {
$_ = $';
{
my $tag = $1;
local $_ = $2;
expandparametersat(''); s/^\s+//;
# Repeat while there are attribute declarations.
while ( s/^($Name)\s+([A-Z]+|\(\s*$Nmtoken\s*(?:\|\s*$Nmtoken\s*)*\))
(?:\s+(\#IMPLIED|\#REQUIRED|(?:\#FIXED\s+)?$Literal))?\s*//xo ) {
my ($attribute,$type,$default) = ($1,$2,$3);
if ($atttype{"$tag/$attribute"}) {
print place()."Warning: Redeclaration of element $tag attribute $attribute ignored.\n";
}
else {
if ($orig) { # to only print the source once once
$source{"$tag/$attribute"} = "$orig";
$orig = '';
}
$ctag{$tag} = variablify($tag) unless $ctag{$tag};
$catt{$attribute} = variablify($attribute) unless $catt{$attribute};
# Add atribute to the appropriate lists.
$attlist{$tag} .= ($attlist{$tag}?',':'') . "$attribute";
if ($withattr{$attribute}) {
$withattr{$attribute} .= ",$tag";
}
else {
push @@attributes, $attribute;
$withattr{$attribute} = "$tag";
}
# Analyse default value.
if (defined $default) {
if ($default eq '#REQUIRED') {
$required{"$tag/$attribute"} = 'true';
$default = undef;
}
elsif ($default eq '#IMPLIED') {
$default = undef;
}
else {
$fixed{"$tag/$attribute"} = 'true' if $default =~ s/\#FIXED\s+//o;
$default =~ s/^'([^'']*)'$/$1/o unless $default =~ s/^"([^""]*)"$/$1/o;
}
}
# Store attribute default string and type.
$attdef{"$tag/$attribute"} = $default if $default;
$atttype{"$tag/$attribute"} = $type;
# Handle enumeration types...
if ( $type =~ m/^\(((.|\n)*)\)$/x ) {
local $_ = $1;
s/\s+//go;
s/\|/,/go;
$enumtype{"$tag/$attribute"} = "$_";
s/$Nmtoken/ "A_$ctag{$tag}_$catt{$attribute}_" . variablify($&) /xge;
my $undefined = "AU_$ctag{$tag}_$catt{$attribute}";
s/^/enum \{ $undefined, /o;
s/$/ \}/o;
$typeof{"$tag/$attribute"} = "$_";
if ($default) {
$initof{"$tag/$attribute"} = "A_$ctag{$tag}_$catt{$attribute}_"
. variablify($default);
}
else {
$initof{"$tag/$attribute"} = "$undefined";
}
}
# ...and string/token types.
else {
$typeof{"$tag/$attribute"} = 'char*';
if ($default) {
$initof{"$tag/$attribute"} = "\"$default\"";
}
else {
$initof{"$tag/$attribute"} = 'NULL';
}
# Special treatment of token types.
if ( $type eq 'ID' or $type eq 'IDREF' ) {
$literaltype{"$tag/$attribute"} = '{Name}';
print STDERR place()."Warning: attribute type `$type' not validated.\n";
}
elsif ( $type eq 'IDREFS' ) {
$literaltype{"$tag/$attribute"} = '{Names}';
print STDERR place()."Warning: attribute type `$type' not validated.\n";
}
elsif ( $type eq 'NMTOKEN' ) {
$literaltype{"$tag/$attribute"} = '{Nmtoken}';
}
elsif ( $type eq 'NMTOKENS' ) {
$literaltype{"$tag/$attribute"} = '{Nmtokens}';
}
elsif ( $type eq 'ENTITY' ) {
die place()."ENTITY attribute type unimplemented.\n";
}
elsif ( $type eq 'ENTITIES' ) {
die place()."ENTITIES attribute type unimplemented.\n";
}
elsif ( $type ne 'CDATA' ) {
die place()."Unknown AttType `$type'.\n";
}
}
}
expandparametersat('^'); s/^\s+//; # to expand next set of declarations...
}
die place()."Nonsense ($_) in attribute list.\n" if $_;
}
$orig = ''; # in case there were no attributes...
}
# Parse internal parameter entity declaration.
elsif ( m/^\s*<!ENTITY\s+%\s+($Name)\s+'([^'']*)'\s*>\s*/xo
or m/^\s*<!ENTITY\s+%\s+($Name)\s+"([^""]*)"\s*>\s*/xo ) {
$_ = $'; $source{"%$1;"} = "$orig"; $orig = ''; # cycle
my $name = $1;
local $_ = $2;
die "Entity `%$name;' doubly defined.\n" if $parameter{$name} or $external{$name};
expandparametersat(''); s/^\s+//; s/\s+$//;
s/\&\#([0-9]+|x[0-9a-fA-F]+);/
(substr($1,0,1) eq 'x' ? chr(hex(substr($1,1))) : chr($1)) /ge;
$parameter{$name} = $_;
}
# Parse external parameter entity declaration.
elsif ( m/^<!ENTITY\s+%\s+($Name)\s+SYSTEM\s+'([^'']*)'\s*>\s*/xo
or m/^<!ENTITY\s+%\s+($Name)\s+SYSTEM\s+"([^""]*)"\s*>\s*/xo
or m/^<!ENTITY\s+%\s+($Name)\s+PUBLIC\s+$Literal\s+'([^'']*)'\s*>\s*/xo
or m/^<!ENTITY\s+%\s+($Name)\s+PUBLIC\s+$Literal\s+"([^""]*)"\s*>\s*/xo ) {
$_ = $'; $source{"%$1;"} = "$orig"; $orig = ''; # cycle
my $name = $1;
die "Entity `%$name;' doubly defined.\n" if $parameter{$name} or $external{$name};
$external{$name} = $2;
}
# Parse internal general entity declarations.
elsif ( /^<!ENTITY\s+($Name)\s+['"]([^''""]*)["']\s*>\s*/xo ) {
$_ = $'; $source{"&$1;"} = "$orig"; $orig = ''; # cycle
my $name = $1;
local $_ = $2;
die "Entity `&$name;' doubly defined.\n" if $entity{$name};
s/\&\#([0-9]+|x[0-9a-fA-F]+);/
(substr($1,0,1) eq 'x' ? chr(hex(substr($1,1))) : chr($1)) /ge;
$entity{$name} = cquote($_);
}
# Unrecognised declaration.
else {
die place()."Unrecognized declaration.\n";
}
}
# Post-process DTD.
print STDOUT "Post-processing DTD.\n" if $verbose;
# Add transitive empty transitions until none can be found.
{ my $changed = 'true';
while ($changed) {
$changed = undef;
for my $from (keys %emptytrans) {
my %tos = (); for (split /,/,$emptytrans{$from}) { $tos{$_} = 'true'; }
for my $to (keys %tos) {
if (exists $emptytrans{$to}) {
for my $next (split /,/,$emptytrans{$to}) {
if (not $tos{$next}) {
$changed = $tos{$next} = 'true';
}
}
}
}
$emptytrans{$from} = join ',',keys %tos;
}
}
}
# Complete all states with their `empty' equivalents.
for my $tag (@@tags) {
# Complete and prune instates and endstates...
my %ins = ();
if (exists $instates{$tag}) {
for (split ',',$instates{$tag}) { $ins{$_} = 'true'; }
}
my %ens = ();
if (exists $endstates{$tag}) {
for (split ',',$endstates{$tag}) { $ens{$_} = 'true'; }
}
# ...and exit transitions...
my %exits = ();
if (exists $exittrans{$tag}) {
for (split ',',$exittrans{$tag}) { m/^($Name)=>($Name)$/o; $exits{$1} = $2; }
}
# Encode ANY as Mixed contents with all tags permitted.
for (keys %any) { $ins{"IN_$_"} = 'true'; }
# For each empty transition A->B add A where B occurs.
for my $from (keys %emptytrans) {
for my $to (split /,/,$emptytrans{$from}) {
$ins{$from} = 'true' if $ins{$to};
$ens{$from} = 'true' if $ens{$to};
$exits{$from} = $exits{$to} if $exits{$to};
}
}
# Completion done...now store'em right back.
$instates{$tag} = join ',', keys %ins if %ins;
$endstates{$tag} = join ',', keys %ens if %ens;
$exittrans{$tag} = join ',', map "$_=>$exits{$_}", keys %exits if %exits;
}
if (not %roottags) {
for (@@tags) { $roottags{$_} = 'true'; }
}
# Debugging: show DTD representation.
if ($debug) {
print STDOUT "DTD debug output:\n" if $verbose;
sub printhash {
my ($name) = @@_;
my @@keys = eval "keys \%$name";
my @@values = eval "values \%$name";
my $out = '';
while (@@keys) { $out .= "\n " . pop(@@keys) . " => " . pop(@@values); }
$out;
}
print '%opt = (' . printhash('opt') . ")\n";
print '%source = (' . printhash('source') . ")\n";
print "\n";
print '@@tags = (' . join(',',@@tags) . ")\n";
print '%ctag = (' . printhash('ctag') . ")\n";
print '%states = (' . printhash('states') . ")\n";
print '%instates = (' . printhash('instates') . ")\n";
print '%endstates = (' . printhash('endstates') . ")\n";
print '%emptytrans = (' . printhash('emptytrans') . ")\n";
print '%exittrans = (' . printhash('exittrans') . ")\n";
print '%empty = (' . printhash('empty') . ")\n";
print '%any = (' . printhash('any') . ")\n";
print '%mixed = (' . printhash('mixed') . ")\n";
print '%children = (' . printhash('children') . ")\n";
print '%inmixed = (' . printhash('inmixed') . ")\n";
print "\n";
print '@@attributes = (' . join(',',@@attributes) . ")\n";
print '%catt = (' . printhash('catt') . ")\n";
print '%atttype = (' . printhash('atttype') . ")\n";
print '%enumtype = (' . printhash('enumtype') . ")\n";
print '%literaltype = (' . printhash('literaltype') . ")\n";
print '%typeof = (' . printhash('typeof') . ")\n";
print '%attdef = (' . printhash('attdef') . ")\n";
print '%required = (' . printhash('required') . ")\n";
print '%fixed = (' . printhash('fixed') . ")\n";
print '%initof = (' . printhash('initof') . ")\n";
print '%attlist = (' . printhash('attlist') . ")\n";
print '%withattr = (' . printhash('withattr') . ")\n";
print "\n";
print '%entity = (' . printhash('entity') . ")\n";
print '%parameter = (' . printhash('parameter') . ")\n";
print '%external = (' . printhash('external') . ")\n";
}
# WRITE API HEADER (if requested).
if ($opt{H}) {
print STDOUT "Generating XML processor header in `$HEADER'.\n" if $verbose;
open HEADER, "+>$HEADER";
select HEADER;
# Identification and license.
print "/* XML processor/application API for $dtd"
. ($dtdrevision ? " ($dtdrevision)" : "") . ".\n";
print " * Generated " . `date +'%Y/%m/%d %T.'`;
print " *\n";
redistribute(" *");
print " */\n";
print "\n";
# Output the declarations safeguarded againts repeated loading.
print "#ifndef _FLEXML_${cdtd}_H\n";
print "\n";
api_functions('extern ',';');
print "\n";
api_types();
print "\n";
api_data('extern ');
print "\n";
print "/* XML application utilities. */\n";
print "extern int element_context(int);\n";
print "\n";
print "/* XML processor entry point. */\n";
print "extern int yylex(void);\n";
print "\n";
print "#endif\n";
close HEADER;
}
# WRITE XML PROCESSOR (if requested).
if ($opt{S} or $opt{A}) {
print STDOUT "Writing XML processor"
. ($opt{a} || $opt{A} ? " and application" : "")
. " onto `$SCANNER'.\n" if $verbose;
open SCANNER, "+>$SCANNER";
select SCANNER;
open SKELETON;
# Identification and license.
print "/* Validating XML processor for $dtd"
. ($dtdrevision ? " ($dtdrevision)" : "") . ".\n";
print " * Generated " . `date +'%Y/%m/%d %T.'`;
print " *\n";
redistribute(" *");
print " */\n";
print "\n";
# Skip initial comment.
while (<SKELETON>) { last if m/^\%\{/; }
print;
# Copy body of skeleton scanner with substitutions...
while (<SKELETON>) {
if ( /^FLEXML_VERSION$/ ) {
print "const char rcs_flexml[] =\n"
. " \"\$\" \"$Id \$\";\n";
print "const char rcs_${cdtd}_dtd[] =\n"
. " \"\$\" \"$dtdrevision \$\";\n" if $dtdrevision;
}
elsif ( /^FLEXML_DEFINITIONS$/ ) {
print "#define DEBUG\n" if $debug;
print "#define FLEXML_yylineno\n" if $lineno;
print "#define FLEXML_NOFAIL\n" if $nofail;
print "#define FLEXML_HasMixed\n" if %inmixed;
print "#define FLEXML_BUFFERSTACKSIZE 100000\n";
print "\n";
if ($opt{A}) {
api_functions('static ',';');
print "\n";
api_types();
print "\n";
api_data('static ');
}
else {
print "/* XML processor api. */\n";
print "#include \"$HEADER\"\n";
print "\n";
api_data('');
}
}
elsif ( /^FLEXML_FLEX_OPTIONS$/ ) {
print "%option yylineno\n" if $lineno;
print "%option debug\n" if $debug;
print "%option nounput\n" if not %entity;
}
elsif ( /^FLEXML_START_CONDITIONS$/ ) {
for (@@tags) {
my $c = $ctag{$_};
print "%x"
. ($roottags{$_} ? " ROOT_$c" : "")
. " AL_$c " . join(' ',split(',',$states{$_})) . "\n";
}
}
elsif ( /^FLEXML_EXTRA_DEFINITIONS$/ ) {
my ($state, $tag);
print "%{\n";
print "/* State names. */\n";
print "char* statenames[IMPOSSIBLE];\n";
print "\n";
print "void FleXML_init(void)\n";
print "{\n";
for ('PROLOG','DOCTYPE','EPILOG','INCOMMENT','INPI','VALUE1','VALUE2','CDATA') {
print " statenames[$_] = NULL;\n";
}
for my $tag (@@tags) {
my $c = $ctag{$tag};
print " statenames[ROOT_$c] = NULL;\n" if $roottags{$tag};
print " statenames[AL_$c] = NULL;\n";
for (split ',',$states{$tag}) {
print " statenames[$_] = \"$tag\";\n";
}
}
print "}\n";
print "%}\n";
}
elsif ( /^FLEXML_DOCTYPES$/ ) {
my $sysid = ( $uri ? "(\"'$uri'\"|\"\\\"$uri\\\"\")"
: "(\"'$dtd'\"|\"\\\"$dtd\\\"\")" );
for (keys %roottags) {
my $c = $ctag{$_};
print " \"<!DOCTYPE\"{S}\"$_\"{S}"
. "SYSTEM{S}" . $sysid . "{s}\">\" SET(ROOT_$c);\n";
if ($pubid) {
print " \"<!DOCTYPE\"{S}\"$_\"{S}"
. "PUBLIC{S}(\"'$pubid'\"|\"\\\"$pubid\\\"\"){S}"
. $sysid . "{s}\">\" SET(ROOT_$c);\n";
}
}
}
elsif ( /^FLEXML_RULES$/ ) {
# Dump all parameter entity declarations.
for (keys %parameter) { printsource($_); }
# Dump all start and empty tag recognition rules.
for my $tag (@@tags) {
my $myctag = $ctag{$tag};
my @@myattributes = (exists $attlist{$tag} ? split /,/,"$attlist{$tag}" : ());
my ($intag, $attribute);
# Tag's source element and attribute declarations.
printsource($tag);
for my $attribute (@@myattributes) {
printsource("$tag/$attribute");
}
# Build element exit transition command.
my $exitswitch = "";
if (exists $exittrans{$tag}) {
$exitswitch .= " switch (YY_START) {\n";
my %casesto = ();
for (split /,/,$exittrans{$tag}) {
if (m/^($Name)=>($Name)$/o) {
$casesto{$2} .= "case $1: ";
}
}
for (keys %casesto) {
$exitswitch .= " $casesto{$_}SET($_); break;\n"
}
$exitswitch .= " }\n";
}
# Start or empty tag: initialise attribute list.
print "\n";
if ($roottags{$tag}) {
print "<ROOT_$myctag" . ($instates{$tag} ? ",$instates{$tag}" : "");
}
else {
print "<$instates{$tag}";
}
print ">\"<$tag\"{s} {\n";
for my $attribute (@@myattributes) {
print " A_${myctag}_$catt{$attribute} = " . $initof{"$tag/$attribute"} . ";\n";
}
print " ENTER(AL_$myctag);\n";
print "}\n";
# Attribute list (of start or empty tag):
print "\n";
print "<AL_$myctag>{\n";
for my $attribute (@@myattributes) {
my $type; # set by conditions
if ($type = $enumtype{"$tag/$attribute"}) {
# - fixed enumeration attribute: generate one rule,
if ($fixed{"$tag/$attribute"}) {
print " \"$attribute\"{Eq}\"'" . $attdef{"$tag/$attribute"} . "'\""
. " |\n"
. " \"$attribute\"{Eq}\"\\\"" . $attdef{"$tag/$attribute"} . "\\\"\""
. " A_${myctag}_$catt{$attribute}"
. " = " . $initof{"$tag/$attribute"} . ";\n";
}
else {
# - (non-fixed) enumeration attribute: generate a rule per value,
for my $alternative (split /,/,$type) {
print " \"$attribute\"{Eq}\"'$alternative'\""
. " |\n"
. " \"$attribute\"{Eq}\"\\\"$alternative\\\"\""
. " A_${myctag}_$catt{$attribute}"
. " = A_${myctag}_$catt{$attribute}_" . variablify($alternative) . ";\n";
}
}
}
elsif ($fixed{"$tag/$attribute"}) {
# - fixed (non-enumeration) attribute: generate one rule per literal form,
print " \"$attribute\"{Eq}\"'" . $attdef{"$tag/$attribute"} . "'\""
. " |\n"
. " \"$attribute\"{Eq}\"\\\"" . $attdef{"$tag/$attribute"} . "\\\"\""
. " A_${myctag}_$catt{$attribute}"
. " = " . $initof{"$tag/$attribute"} . ";\n";
}
elsif ($type = $literaltype{"$tag/$attribute"}) {
# - (non-fixed) literal-type attribute: scan literal string directly, or
print " \"$attribute\"{Eq}\'$type\' BUFFERLITERAL('\\\'',A_${myctag}_$catt{$attribute});\n";
print " \"$attribute\"{Eq}\\\"$type\\\" BUFFERLITERAL('\"',A_${myctag}_$catt{$attribute});\n";
}
else {
# - (non-fixed non-literal) attribute: scan string with entity expansion.
print " \"$attribute\"{Eq}\\' ENTER(VALUE1); BUFFERSET(A_${myctag}_$catt{$attribute});\n";
print " \"$attribute\"{Eq}\\\" ENTER(VALUE2); BUFFERSET(A_${myctag}_$catt{$attribute});\n";
}
print "\n";
}
#
# - the end of a start tag means to enter the contents after
# checking that all required attributes were set.
print " \">\" {\n";
for my $attribute (@@myattributes) {
if ($required{"$tag/$attribute"}) {
print " if (!A_$ctag{$tag}_" . variablify($attribute) . ")"
. " FAIL(\"Required attribute `$attribute' not set for `$tag' element.\");\n";
}
}
print " LEAVE; STag_$myctag();"
. (%inmixed ? ' pushbuffer(pcdata);' : '')
. " pcdata = " .($mixed{$tag} ? 'BUFFERSET(pcdata)' : 'NULL'). ";"
. " ENTER($startstate{$tag});\n";
print " }\n";
#
# - accept and handle empty tags straight away,
if ($empty{$tag}) {
print " \"/>\" {\n";
for my $attribute (@@myattributes) {
if ($required{"$tag/$attribute"}) {
print " if (!A_$ctag{$tag}_" . variablify($attribute) . ")"
. " FAIL(\"Required attribute `$attribute' not set for `$tag' element.\");\n";
}
}
print " LEAVE; STag_$myctag();"
. (%inmixed ? ' pushbuffer(pcdata);' : '')
. ' pcdata = ' . ($mixed{$tag} ? '""' : 'NULL') . ';'
. " ETag_$myctag();"
. (%inmixed ? ' pcdata = popbuffer();' : '')
. "\n";
#
print $exitswitch;
print " }\n";
}
elsif (not $nofail) {
print " \"/>\" FAIL(\"`$tag' element cannot be empty.\");\n";
}
#
# - spaces are skipped, and
print " . FAIL(\"Unexpected character \`%c\' in attribute list of $tag element.\", yytext[0]);\n" unless $nofail;
#
# - other stuff is an error.
print " {Name} FAIL(\"Bad attribute `%s' in `$tag' element start tag.\",yytext);\n" unless $nofail;
print " <<EOF>> FAIL(\"EOF in attribute list of `$tag' element.\");\n" unless $nofail;
print "}\n";
# End tag.
print "\n";
print "<$endstates{$tag}>{\n";
print " \"</$tag\"{s}\">\" {\n";
print " LEAVE;\n";
print " BUFFERDONE;\n" if $mixed{$tag};
print " ETag_$myctag();\n";
print " pcdata = popbuffer();\n" if %inmixed;
print $exitswitch;
print " }\n";
# Errors when expecting end tag.
print " \"</\"{Name}{s}\">\" FAIL(\"Unexpected end-tag `%s': `</$tag>' expected.\",yytext);\n"
unless $nofail;
print " . FAIL(\"Unexpected character `%c': `</$tag>' expected.\",yytext[0]);\n"
unless $mixed{$tag} or $nofail;
print " <<EOF>> FAIL(\"Premature EOF: `</$tag>' expected.\");\n" unless $nofail;
print "}\n";
# Errors when expecting root tag.
if ($roottags{$tag} and $nofail) {
print "\n";
print "<ROOT_$myctag>{\n";
print " . FAIL(\"Unexpected character `%c': `$tag' element expected.\",yytext[0]);\n";
print " <<EOF>> FAIL(\"EOF in prolog.\");\n";
print "}\n";
}
}
}
elsif ( /FLEXML_MIXED([,>])/ ) {
if (%mixed) {
print "$`" . join(',', map("IN_$ctag{$_}", keys %mixed)) . "$1$'";
}
else {
print "$`IMPOSSIBLE$1$'";
}
}
elsif ( /FLEXML_NON_MIXED([,>])/ ) {
my $sep = $`;
for (@@tags) {
print $sep . ($roottags{$_} ? "ROOT_$ctag{$_}," : "")
. "AL_$ctag{$_}";
print ",$states{$_}" if $properempty{$_} or $children{$_};
$sep = ',';
}
print "$1$'";
}
elsif ( /FLEXML_COMMENTS([,>])/ ) {
print "$`"
. join(',', map(($roottags{$_} ? "ROOT_$ctag{$_}," : "")
. "AL_$ctag{$_},$states{$_}", @@tags))
. "$1$'";
}
elsif ( /^FLEXML_ENTITIES$/ ) {
# Process general entities.
for my $ent (keys %entity) {
printsource("%$ent;");
print " \"&$ent;\" ENTITYTEXT(\"" . $entity{$ent} . "\");\n";
}
print " /* Non-defined standard entities... */\n";
print "\"&\" BUFFERPUTC('&');\n" unless $entity{"amp"};
print "\"<\" BUFFERPUTC('<');\n" unless $entity{"lt"};
print "\">\" BUFFERPUTC('>');\n" unless $entity{"gt"};
print "\"'\" BUFFERPUTC('\\\'');\n" unless $entity{"apos"};
print "\""\" BUFFERPUTC('\"');\n" unless $entity{"quot"};
}
elsif ( /^FLEXML_FINAL$/ and not $nofail ) {
# Catch-all error cases.
for my $tag (@@tags) {
for (split ',',$states{$tag}) {
print "<$_>{\n";
print " . FAIL(\"Unrecognized `%c' in $_.\",yytext[0]);\n";
print " [\\n] FAIL(\"Unrecognized newline in $_.\");\n";
print "}\n";
}
}
for ('PROLOG','DOCTYPE','EPILOG','INCOMMENT','INPI','VALUE1','VALUE2','CDATA','INITIAL','IMPOSSIBLE') {
print "<$_>{\n";
print " . FAIL(\"Unrecognized `%c' in $_.\",yytext[0]);\n";
print " [\\n] FAIL(\"Unrecognized space in $_.\");\n";
print "}\n";
}
}
elsif ( $nofail and /FAIL\(/ ) {
#ignore
}
else {
s/"\$Id/"\$" "Id/;
print;
}
}
close SKELETON;
close SCANNER unless $opt{A};
}
# WRITE APPLICATION.
if ($opt{D}) {
print STDOUT "Writing XML"
. ($opt{a} ? "" : " dummy")
. " application onto `$APPLICATION'.\n" if $verbose;
open APPLICATION, "+>$APPLICATION";
select APPLICATION;
# Identification and license.
print "/* XML application for $dtd"
. ($dtdrevision ? " ($dtdrevision)" : "") . ".\n";
print " * Includes actions from $ACTIONS.\n" if $ACTIONS;
print " * Generated " . `date +'%Y/%m/%d %T.'`;
print " *\n";
redistribute(" *");
print " */\n";
print "\n";
# Declarations.
print "#include \"$HEADER\"\n";
print "\n";
}
if ($opt{D} or $opt{A}) {
# Get requested actions.
if ($ACTIONS) {
open ACTIONS, "./flexml-act $ACTIONS|";
my ($tag,$attribute);
my @@myattributes;
my $lineno = 0;
my $isstart = undef;
while (<ACTIONS>) {
++$lineno;
if ( m/^\#line ([0-9]+)/ ) {
$lineno = $1;
}
elsif ( m/^void\s+STag_($Name)\(void\)$/xo ) {
$tag = $1;
die "\"$ACTIONS\", line $lineno: Unknown element `$tag'.\n" unless $ctag{$tag};
$startok{$tag} = 'true';
@@myattributes = (exists $withattr{$tag} ? split /,/,"$withattr{$tag}" : ());
$isstart = 'true';
}
elsif ( m|^\}\s+\/\*\s+STag_($Name)\s+\*\/$|xo ) {
$tag = undef;
@@myattributes = ();
$isstart = 'true';
}
elsif ( m/^void\s+ETag_($Name)\(void\)$/xo ) {
$tag = $1;
$endok{$1} = 'true';
$isstart = undef;
}
# Make function names C-friendly (idempotently!)
s/(\s+[SE])Tag_($Name)\(/$1Tag_$ctag{$2}\(/xg;
# Replace special annotations with C equivalents.
if ($tag) {
while ( s/\{($Name)\}/A_$ctag{$tag}_$catt{$1}/x ) {
die "\"$ACTIONS\", line $lineno: Attributes only allowed in start tag.\n"
if not $isstart;
die "\"$ACTIONS\", line $lineno: Unknown attribute `$1' for <$tag>.\n"
if not $atttype{"$tag/$1"};
}
while ( s/\{[!]($Name)\}/AU_$ctag{$tag}_$catt{$1}/x ) {
die "\"$ACTIONS\", line $lineno: Attributes only allowed in start tag.\n"
if not $isstart;
die "\"$ACTIONS\", line $lineno: Unknown attribute `$1' for <$tag>.\n"
if not $atttype{"$tag/$1"};
}
while ( s|\{($Name)=($Name)\}|
"A_$ctag{$tag}_$catt{$1}_" . variablify($2); |xe ) {
die "\"$ACTIONS\", line $lineno: Attributes only allowed in start tag.\n"
if not $isstart;
my ($att,$elt) = ($1,$2);
die "\"$ACTIONS\", line $lineno: Unknown attribute $1 for <$tag>.\n"
if not $atttype{"$tag/$1"};
die "\"$ACTIONS\", line $lineno: Attribute $att does not have value $elt for <$tag>.\n"
if not $enumtype{"$tag/$att"} =~ m/\b$elt\b/ ;
}
while ( s|\{\#(PCDATA)\}|pcdata| ) {
die "\"$ACTIONS\", line $lineno: {#PCDATA} only allowed in end tag.\n"
if $isstart;
die "\"$ACTIONS\", line $lineno: {#PCDATA} only permitted in end tag with Mixed contents.\n"
if not $mixed{$tag};
}
die "\"$ACTIONS\", line $lineno: Malformed annotation `$&' in <$tag> action.\n"
if m|\{[^;\s]+\}|o;
}
print $_;
}
close ACTIONS;
print "\n";
}
# Fill up with dummy declarations for the remaining functions.
api_functions('',' {}');
}
if ($opt{D}) {
close APPLICATION;
}
elsif ($opt{A}) {
close SCANNER;
}
=pod
=head1 NAME
flexml - generate validating XML processor and applications from DTD
=head1 SYNOPSIS
B<flexml>
[B<-ASHDvdnLXV>]
[B<-s>I<skel>]
[B<-p>I<pubid>]
[B<-u>I<uri>]
[B<-r>I<rootags>]
[B<-a>I<actions>]
I<name>[F<.dtd>]
=head1 DESCRIPTION
I<Flexml> reads I<name>F<.dtd> which must be a DTD (Document Type
Definition) describing the format of XML (Extensible Markup Language)
documents, and produces a "validating" XML I<processor> with an
interface to support XML I<application>s. Proper applications can be
generated optionally from special "action files", either for linking
or textual combination with the processor.
The generated processor will only validate documents that conform
strictly to the DTD, I<without extending it>, more precisely we in
practice restrict XML rule [28] to
[28r] doctypedecl ::= '<!DOCTYPE' S Name S ExternalID S? '>'
where the C<ExternalId> denotes the used DTD. (One might say, in
fact, that I<flexml> implements "non-extensible" markup. :)
The generated processor is a I<flex>(1) scanner, by default named
I<name>F<.l> with a corresponding C header file I<name>F<.h> for
separate compilation of generated applications. Optionally I<flexml>
takes an I<actions> file with per-element actions and produces a C
file with element functions for an XML application with entry points
called from the XML processor (it can also fold the XML application
into the XML processor to make stand-alone XML applications but this
prevents sharing of the processor between applications).
In L</OPTIONS>Z<> we list the possible options, in L</ACTION FILE
FORMAT>Z<> we explain how to write applications, in L</COMPILATION> we
explain how to compile produced processors and applications into
executables, and in L</BUGS> we list the current limitations of the
system before giving standard references.
=head1 OPTIONS
I<Flexml> takes the following options.
=over 4
=item B<-A>
Generate a I<stand-alone> scanner application. If combined with
B<-a>I<actions> then the application will be named as I<actions> with
the extension replaced by F<.l>, otherwise it will be in I<name>F<.l>.
Conflicts with B<-S>, B<-H>, and B<-D>.
=item B<-a> I<actions>
Uses the I<actions> file to produce an XML application in the file
with the same name as I<actions> after replacing the extension with
F<.c>. If combined with B<-A> then instead the stand-alone
application will include the action functions.
=item B<-D>
Generate a dummy application I<name>F<-dummy.c> with just empty
functions to be called by the XML processor. If combined with
B<-a>I<actions> then the application will insert the specified
actions and be named as I<actions> with the extension replaced by
F<.c>. Conflicts with B<-A>; implied by B<-a> unless either of
B<-SHD> is specified.
=item B<-d>
Turns on debug mode in the flex scanner and also prints out the
details of the DTD analysis performed by I<flexml>.
=item B<-H>
Generate the header file I<name>F<.h>. Conflicts with B<-A>; on by
default if none of B<-SHD> specified.
=item B<-L>
Makes the XML processor (as produced by I<flex>(1)) count the lines in
the input and keep it available to XML application actions in the
integer C<yylineno>. (This is off by default as the performance
overhead is significant.)
=item B<-n>
"Dry-run": do not produce any of the output files.
=item B<-p> I<pubid>
Sets the document type to be C<PUBLIC> with the identifier I<pubid>
instead of C<SYSTEM>, the default.
=item B<-r> I<roottags>
Restricts the XML processor to validate only documents with one of the
root elements listed in the comma-separated I<roottags>.
=item B<-S>
Generate the scanner I<name>F<.l>. Conflicts with B<-A>; on by
default if none of B<-SHD> specified.
=item B<-s> I<skel>
Use the skeleton scanner I<skel> instead of the default.
=item B<-u> I<uri>
Sets the URI of the DTD, used in the C<DOCTYPE> header, to the
specified I<uri> (the default is the DTD name).
=item B<-v>
Be verbose: echo each DTD declaration (after parameter expansion).
=item B<-V>
Print the version of I<flexml> and exit.
=back
=head1 ACTION FILE FORMAT
Action files, passed to the B<-a> option, are XML documents conforming
to the DTD F<flexml-act.dtd> which is the following:
<!ELEMENT actions ((top|start|end)*,main?)>
<!ENTITY % C-code "(#PCDATA)">
<!ELEMENT top %C-code;>
<!ELEMENT start %C-code;> <!ATTLIST start tag NMTOKEN #REQUIRED>
<!ELEMENT end %C-code;> <!ATTLIST end tag NMTOKEN #REQUIRED>
<!ELEMENT main %C-code;>
The elements should be used as follows:
=over 4
=item C<top>
Use for top-level C code such as global declarations, utility
functions, etc.
=item C<start>
Attaches the code as an action to the element with the name of the
required "C<tag>" attribute. The "C<%C-code;>" component should be C
code suitable for inclusion in a C block (i.e., within C<{>...C<}> so
it may contain local variables); furthermore the following extensions
are available:
C<{>I<attribute>C<}>: Can be used to access the value of the
I<attribute> as set with I<attribute>C<=>I<value> in the start tag.
In C, C<{>I<attribute>C<}> will be interpreted depending on the
declaration of the attribute. If the attribute is declared as an
enumerated type like
<!ATTLIST attrib (alt1 | alt2 |...) ...>
then the C attribute value is of an enumerated type with the elements
written C<{>I<attribute>C<=>I<alt1>C<}>,
C<{>I<attribute>C<=>I<alt2>C<}>, etc.; furthermore an I<unset>
attribute has the "value" C<{!>I<attribute>C<}>. If the attribute is
not an enumeration then C<{>I<attribute>C<}> is a null-terminated C
string (of type C<char*>) and C<{!>I<attribute>C<}> is C<NULL>.
=item C<end>
Similarly attaches the code as an action to the end tag with the name
of the required "C<tag>" attribute; also here the "C<%C-code;>"
component should be C code suitable for inclusion in a C block. In
case the element has "Mixed" contents, i.e, was declared to permit
C<#PCDATA>, then the following variable is available:
C<{#PCDATA}>: Contains the text (C<#PCDATA>) of the element as a
null-terminated C string (of type C<char*>). In case the Mixed
contents element actually mixed text and child elements then C<pcdata>
contains the plain concatenation of the text fragments as one string.
=item C<main>
Finally, an optional "C<main>" element can contain the C C<main>
function of the XML application. Normally the C<main> function should
include (at least) one call of the XML processor:
C<yylex()>:
Invokes the XML processor produced by I<flex>(1) on the XML document
found on the standard input (actually the C<yyin> file handle: see the
manual for I<flex>(1) for information on how to change this as well as
the name C<yylex>).
If no C<main> action is provided then the following is used:
int main() { exit(yylex()); }
=back
It is advisable to use XML E<lt>C<![CDATA[> ... C<]]>E<gt> sections
for the C code to make sure that all characters are properly passed to
the output file.
Finally note that I<Flexml> handles empty elements
E<lt>I<tag>C</>E<gt> as equivalent to
E<lt>I<tag>E<gt>E<lt>C</>I<tag>E<gt>.
=head1 COMPILATION
The following I<make>(1) file fragment shows how one can compile
I<flexml>-generated programs:
# Programs.
FLEXML = flexml -v
# Generate linkable XML processor with header for application.
%.l %.h: %.dtd
$(FLEXML) $<
# Generate C source from flex scanner.
%.c: %.l
$(FLEX) -Bs -o"$@@" "$<"
# Generate XML application C source to link with processor.
# Note: The dependency must be of the form "appl.c: appl.act proc.dtd".
%.c: %.act
$(FLEXML) -D -a $^
# Direct generation of stand-alone XML processor+application.
# Note: The dependency must be of the form "appl.l: appl.act proc.dtd".
%.l: %.act
$(FLEXML) -A -a $^
=head1 BUGS
The present version of I<flexml> is to be considered in "early beta"
state thus bugs should be expected (and the author would like to hear
about them). Here are some known restrictions that we hope to
overcome in the future:
=over 4
=item *
The character set is merely ASCII (actually I<flex>(1) handles 8 bit
characters but only the ASCII character set is common with the XML
default UTF-8 encoding).
=item *
C<ID> type attributes are not validated for uniqueness; C<IDREF> and
C<IDREFS> attributes are not validated for existence.
=item *
The C<ENTITY> and C<ENTITIES> attribute types are not supported.
=item *
C<NOTATION> declarations are not supported.
=item *
The various C<xml:>-attributes are treated like any other attributes;
in particular C<xml:spaces> should be supported.
=item *
The XML processor currently uses a fixed-size buffer to read
C<pcdata>. It should not.
=item *
The DTD parser is presently a perl hack so it may parse some DTDs
badly; in particular the expansion of parameter entities may not
conform fully to the XML specification.
=item *
A child should be able to "return" a value for the parent (also called
a I<synthesised attribute>). Similarly an element in Mixed contents
should be able to inject text into the C<pcdata> of the parent.
=back
=head1 FILES
=over 4
=item F<./skel>
The skeleton scanner with the generic parts of XML scanning.
=item F</usr/share/doc/flexml/>
License, further documentation, and examples.
=back
=head1 SEE ALSO
I<flex>(1), Extensible Markup Language (XML) 1.0 (W3C Recommendation
REC-xml-1998-0210).
=head1 AUTHOR
I<Flexml> was written by Kristoffer Hgsbro Rose,
E<lt>C<krisrose@@debian.org>E<gt>.
=head1 COPYRIGHT
The program is Copyright (c) 1999 Kristoffer Rose (all rights
reserved) and distributed under the GNU General Public License (GPL,
also known as "copyleft", which clarifies that the author provides
absolutely no warranty for I<flexml> and ensures that I<flexml> is and
will remain available for all uses, even comercial).
=head1 ACKNOWLEDGEMENT
I am grateful to NTSys (France) for supporting the development of
I<flexml>. Finally extend my severe thanks to Jef Poskanzer, Vern
Paxson, and the rest of the I<flex> maintainers and GNU developers for
a great tool.
=cut
@
1.23
log
@Released for Debian.
@
text
@d23 1
a23 1
my $Id = '$Id: flexml.pl,v 1.22 1999/12/09 08:22:01 krisrose Exp krisrose $ ';
d1108 2
a1109 1
my $extid;
a1110 8
if ($pubid) {
$extid = "PUBLIC{S}(\"'$pubid'\"|\"\\\"$pubid\\\"\")";
}
else {
$extid = 'SYSTEM';
}
$extid .= '{S}' . ( $uri ? "(\"'$uri'\"|\"\\\"$uri\\\"\")"
: "(\"'$dtd'\"|\"\\\"$dtd\\\"\")" );
d1112 9
a1120 2
print " \"<!DOCTYPE\"{S}\"$_\"{S}" .$extid . "{s}\">\" SET(ROOT_$ctag{$_});\n";
}
d1292 4
a1295 2
print " \"</\"{Name}{s}\">\" FAIL(\"Unexpected end-tag `%s': `</$tag>' expected.\",yytext);\n" unless $nofail;
print " . FAIL(\"Unexpected character `%c': `</$tag>' expected.\",yytext[0]);\n" unless $mixed{$tag} or $nofail;
d1429 1
d1442 1
d1447 1
d1450 1
d1452 1
d1462 4
a1465 1
die "\"$ACTIONS\", line $lineno: Unknown attribute `$1' for <$tag>.\n" if not $atttype{"$tag/$1"};
d1469 4
a1472 1
die "\"$ACTIONS\", line $lineno: Unknown attribute `$1' for <$tag>.\n" if not $atttype{"$tag/$1"};
d1474 1
d1477 3
a1481 1
my ($att,$elt) = ($1,$2);
d1485 10
a1494 1
die "\"$ACTIONS\", line $lineno: Malformed annotation `$&' in <$tag> action.\n" if m|\{[^;\s]+\}|o;
d1562 5
a1566 4
In L</OPTIONS>Z<> we list the possible options, in
L</ACTION FILE FORMAT>Z<> we explain how to write applications, and in
L</BUGS> we list the current limitations of the system before giving
standard references.
d1681 5
a1685 8
C<{>I<attribute>C<}>
=over 4
Can be used to access the value of the I<attribute> as set with
I<attribute>C<=>I<value> in the start tag. In C, C<{>I<attribute>C<}>
will be interpreted depending on the declaration of the attribute. If
the attribute is declared as an enumerated type like
a1695 2
=back
d1704 4
a1707 10
C<pcdata>
=over 4
Contains the text (C<#PCDATA>) of the element as a null-terminated C
string (of type C<char*>). In case the Mixed contents element
actually mixed text and child elements then C<pcdata> contains the
plain concatenation of the text fragments as one string.
=back
d1715 1
a1715 4
C<yylex()>
=over 4
a1720 2
=back
d1735 27
d1764 1
a1764 1
The present version of I<flexml> is to be considered in "late alpha"
@
1.22
log
@Oops: tricky stopped working...holding...
@
text
@d23 1
a23 1
my $Id = '$Id: flexml.pl,v 1.21 1999/12/09 03:47:43 krisrose Exp krisrose $ ';
a218 1
print STDOUT "Expanding `$_'\n";
d234 1
a234 1
print STDOUT "Fetching URL <$url>..." if $verbose;
a239 1
print STDOUT "failed.\n";
a241 1
print STDOUT "done.\n" if $verbose;
d508 1
a508 1
print "Processing DTD in $dtd:\n" if $verbose;
d518 16
a533 3
while (@@inputs and m/^\s*$/) {
$_ = nextline();
expandparametersat('^');
d535 2
d539 1
a539 1
# Extract FIRST DTD version number...
d551 2
a552 2
# Insert parameter or external entity and retry.
if ( s/^%($Name);// ) {
a555 1
next;
d558 1
d586 1
a586 1
print STDOUT " [$_]\n" if $verbose;
d781 2
a782 2
elsif ( m/^<!ENTITY\s+%\s+($Name)\s+'([^'']*)'\s*>\s*/xo
or m/^<!ENTITY\s+%\s+($Name)\s+"([^""]*)"\s*>\s*/xo ) {
a817 2
print "ENTITY &$name;\n";
d1343 1
a1343 1
print " \"$ent\" ENTITYTEXT(\"" . $entity{$ent} . "\");\n";
@
1.21
log
@External entities added.
@
text
@d23 1
a23 1
my $Id = '$Id: flexml.pl,v 1.20 1999/12/06 21:08:09 krisrose Exp krisrose $ ';
d219 1
d521 4
a524 1
$_ = nextline() while @@inputs and m/^\s*$/;
d539 1
a539 1
# Insert external entity and retry.
d542 11
a552 3
die "Unknown entity `%$ent;'\n" unless $external{$ent};
geturl($external{$ent});
next;
d656 1
a656 1
while ( s/^($Name)\s+([A-Z]+|\(\s*$Nmtoken(?:\s*\|\s*$Nmtoken)*\))
d805 3
d1131 21
d1255 1
a1255 7
if (exists $exittrans{$tag}) {
print " switch (YY_START) {\n";
for (split /,/,$exittrans{$tag}) {
print " case $1: SET($2); break;\n" if m/^($Name)=>($Name)$/xo;
}
print " }\n";
}
d1278 1
a1278 7
if (exists $exittrans{$tag}) {
print " switch (YY_START) {\n";
for (split /,/,$exittrans{$tag}) {
print " case $1: SET($2); break;\n" if m/^($Name)=>($Name)$/xo;
}
print " }\n";
}
d1738 4
@
1.20
log
@Releasing.
@
text
@d1 1
a1 1
#!/usr/bin/perl
d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.19 1999/12/03 23:46:37 krisrose Exp krisrose $ ';
d26 1
d28 34
a61 2
# DTD DESCRIPTION STRUCTURES.
d63 7
d71 1
a71 1
%source = (); # DTD source lines associated to tag and tag/attribute.
d73 1
a73 38
@@tags = (); # Tags of the DTD.
%roottags = (); # Tags that may be the root tag.
%ctag = (); # C variable name of each tag.
%states = (); # $states{tag} is list of states used by tag element.
%emptytrans = ();# $emptytrans{state} contains empty transitions in automaton.
%instates = (); # $instates{tag} is list of states for element start/empty tag.
%startstate = ();# $startstate{tag} is the state entered after the start tag.
%endstates = ();# $endstates{tag} is list of states for element end tag.
%exittrans = ();# $exittrans{tag} is state transitions after end tag.
%empty = (); # $empty{tag} == true if the tag may be empty.
%properempty = ();# $empty{tag} == true if the tag is declared EMPTY
%any = (); # $any{tag} == true if the tag has ANY contents.
%mixed = (); # $mixed{tag} == true if the tag has Mixed (or ANY) contents.
%children = (); # $children{tag} == true if the tag has Element contents
%inmixed = (); # $inmixed{tag} == true if the tag occurs *in* Mixed contents.
@@attributes = ();# Attributes of the DTD.
%catt = (); # C variable name for attribute.
%atttype = (); # XML AttType (type) of tag/attribute
%enumtype = (); # whether the tag/attribute is an enumeration type
%literaltype = ();# whether the tag/attribute is a tokenized type
%entitytype = ();# whether the tag/attribute is of entity type
%typeof = (); # C type of tag/attribute
%attdef = (); # XML AttDef (default value) of tag/attribute
%required = (); # true if tag/attribute is required
%fixed = (); # true if tag/attribute has fixed default
%initof = (); # C initial attribute value of tag/attribute, if any
%attlist = (); # $attlist{tag} is comma-separated list of attribute
# names allowed in tag elements.
%withattr = (); # $withattr{attribute} is comma-separated list of
# elements within which the tag element may occur.
d75 42
a116 2
%entity = (); # general entity table (C strings)
%parameter = ();# parameter entity table (raw string)
d118 2
a119 2
%startok = (); # start tag action already dumped
%endok = (); # end tag action already dumped
d180 1
d182 1
a182 1
local ($pre,$post) = @@_;
d205 1
a205 1
local ($pre) = @@_;
d216 1
a216 1
sub expandparametersat {
d218 67
a284 2
while (s/$place(\s*)(%$Name;)/ ' '. $1 . $parameter{$2} . ' ' /xe) {
die "\"$DTD\", line $.: Unknown parameter entity $2.\n" unless $parameter{$2};
d286 2
d291 8
a298 8
sub getnonblank { # skip until a non-blank DTD line
# available in $_; expand it's
# parameters but return original (!)
my $line = $_;
until ($_ or eof DTD) {
$_ = <DTD>; chomp;
$line .= "\n" . $_;
expandparametersat('^'); s/^\s+//;
a299 1
$line;
d335 2
d347 5
a351 2
my %ins = (); for (split /,/,$instates{$thetag}) { $ins{$_} = true; }
$ins{$in} = true;
d361 1
a361 1
return true;
d400 1
a400 1
$maybeempty = true if analysechildren($tag,$cp,$in,$out);
d413 1
a413 1
$maybeempty = true if analysechildren($tag,$cp,$in,$out);
d424 1
a424 1
die "\"$DTD\", line $.: DTD element $tag has nonsense fragment `$_'.\n";
d435 2
a436 2
use Getopt::Std; getopts('ASHDvdnLXVp:s:u:r:a:');
if ($#ARGV != 0) { die $Use."\n"; }
d439 2
a440 4
if ($opt_V) {
print "FleXML version $Id.\n";
exit 0;
}
d443 2
a444 2
$debug = $opt_d;
$verbose = $opt_v;
d447 1
a447 1
$lineno = $opt_L;
d450 1
a450 1
$nofail = $opt_X;
d453 2
a454 2
if ($opt_r) {
for (split ',',$opt_r) { $roottags{$_} = true; }
d458 2
a459 2
$SKELETON = ($opt_s ? $opt_s : './skel');
die "$0: No skeleton file $SKELETON.\n" if not -r $SKELETON and $opt_S;
d461 3
a463 5
# Set DTD file name.
$prefix = $ARGV[0];
$prefix =~ s/\.dtd$//;
$DTD = "$prefix.dtd";
die "$0: No DTD file $DTD.\n" if not -r $DTD;
d465 12
a476 3
# Set document type URI and PUBID.
$uri = $opt_u if $opt_u;
$pubid = $opt_p if $opt_p;
d480 2
a481 2
$opt_S = $opt_H = true unless ($opt_S or $opt_H or $opt_D or $opt_A);
$opt_D ||= $opt_a unless $opt_A;
d489 3
a491 3
if ($ACTIONS = $opt_a) {
$opt_a =~ s/\.[a-z]+$//;
$APPLICATION = "$opt_a.c";
d495 2
a496 2
if ($opt_A) {
die "$0: -A conflicts with -SHD.\n" if ($opt_S or $opt_H or $opt_D);
d502 2
a503 2
if ($opt_n) {
$opt_A = $opt_S = $opt_H = $opt_D = undef;
a505 3
# Clean up for use as C variable name parts
$cprefix = variablify("$prefix");
a508 1
print "Processing DTD in $DTD:\n" if $verbose;
d510 24
d535 6
a540 35
# DTD regular expressions (extended to not mess up the counting).
$NameChar = '[A-Za-z0-9.:_-]';
$Name = "[A-Za-z_:]$NameChar*";
$Names = "$Name(?:\s+$Name)*";
$Nmtoken = "$NameChar+";
$Nmtokens = "$Nmtoken(?:\s+$Nmtoken)*";
$Eq = '\s*=\s*';
$Literal = '\'[^\']*\'|"[^"]*"';
$StartSep = '(^|,)';
$EndSep = '(,|$)';
open DTD;
$orig = ''; # current source line(s)
$_ = ''; # current entity, possibly with trailing stuff
until (eof DTD) { # One pass per item.
$orig = getnonblank();
# Skip any comments (but save as source).
while ( m/^\s*<!--/ ) {
until (m/-->/ or eof DTD) {
my $line = <DTD>; chomp $line;
$_ .= ($_?"\n":"") . $line;
$orig .= "\n" . $line;
}
# Extract any DTD version number...
if ( /\$(Id|Header|Revision): [^\$]*\$/ ) {
$DTDrevision = "$&";
$DTDrevision =~ s/\s*\$\s*//go;
}
# Remove the comment to read on to next nonblank (but save as source).
s/^\s*<!--([^-]|-[^-]|--[^>])*-->\s*//g;
$orig .= "\n" . getnonblank();
d543 2
d546 2
a547 2
until (m/^\s*<![^>]*>/o or m/^\s*<[?]([^?]|[?][^>])*[?]>/o or eof DTD) {
my $line = <DTD>; chomp $line;
d553 2
a554 2
last if eof DTD;
die "\"$DTD\", line $.: Could not find end of declaration.\n";
d562 1
a562 1
print "[$_]\n" if $verbose;
d566 2
a567 2
print "\"$DTD\", line $.: Warning: ignoring processing instruction $&.\n";
$_ = $'; $orig = ''; # cycle
d573 1
a573 1
$_ = $'; $source{$1} = "$orig"; $orig = ''; # cycle
d576 1
a576 1
die "\"$DTD\", line $.: Repeated element $tag.\n" if $ctag{$tag};
d592 2
a593 2
$empty{$tag} = true;
$properempty{$tag} = true;
d599 3
a601 3
$any{$tag} = true;
$mixed{$tag} = true;
$empty{$tag} = true;
d608 9
a616 7
$mixed{$tag} = true;
$empty{$tag} = true;
my $desc = $1;
$desc =~ s/^\s*\|\s*//o;
for (split /\s*\|\s*/,"$desc") {
$instates{$_} .= ($instates{$_}?',':'') . "IN_$c";
$inmixed{$_} = true;
d623 1
a623 1
$children{$tag} = true;
d627 1
a627 1
$empty{$tag} = true if analysechildren($tag,$_,"S_$c","E_$c");
a636 1
d644 1
a644 1
while ( s/^($Name)\s+([A-Z]+|\(\s*$Nmtoken(?:\s*\|\s*$Nmtoken)*\s*\))
d650 1
a650 1
print "\"$DTD\", line $.: Warning: Redeclaration of element $tag attribute $attribute ignored.\n";
d672 12
a683 10
if ("$default" eq '#REQUIRED') {
$required{"$tag/$attribute"} = true;
$default = undef;
}
elsif ($default eq '#IMPLIED') {
$default = undef;
}
else {
$fixed{"$tag/$attribute"} = true if $default =~ s/\#FIXED\s+//o;
$default =~ s/^'([^'']*)'$/$1/o unless $default =~ s/^"([^""]*)"$/$1/o;
d688 1
a688 1
$atttype{"$tag/$attribute"} = "$type";
d722 1
d726 1
d735 1
a735 1
die "\"$DTD\", line $.: ENTITY attribute type unimplemented.\n";
d738 1
a738 1
die "\"$DTD\", line $.: ENTITIES attribute type unimplemented.\n";
d741 1
a741 1
die "\"$DTD\", line $.: Unknown AttType `$type'.\n";
a744 3
# Store default value
$defaultdecl{"$tag/$attribute"} = $default;
d750 1
a750 1
die "\"$DTD\", line $.: Nonsense ($_) in attribute list.\n" if $_;
d756 1
a756 1
# parse internal parameter entity declarations.
d764 3
d770 14
a783 1
$parameter{"%$name;"} = $_;
d793 1
d796 1
a796 1
$entity{"&$name;"} = cquote($_);
d801 1
a801 1
die "\"$DTD\", line $.: Unrecognized declaration.\n";
d806 1
a806 1
close DTD;
d808 1
a808 1
# Post-process DTD.
d811 1
a811 1
{ my $changed = true;
d815 1
a815 1
my %tos = (); for (split /,/,$emptytrans{$from}) { $tos{$_} = true; }
d817 5
a821 4
for my $next (split /,/,$emptytrans{$to}) {
if (not $tos{$next}) {
$changed = true;
$tos{$next} = true;
d834 8
a841 2
my %ins = (); for (split ',',$instates{$tag}) { $ins{$_} = true; }
my %ens = (); for (split ',',$endstates{$tag}) { $ens{$_} = true; }
d845 3
a847 1
for (split ',',$exittrans{$tag}) { m/^($Name)=>($Name)$/o; $exits{$1} = $2; }
d850 1
a850 1
for (keys %any) { $ins{"IN_$_"} = true; }
d855 2
a856 2
$ins{$from} = true if $ins{$to};
$ens{$from} = true if $ens{$to};
d868 1
a868 1
for (@@tags) { $roottags{$_} = true; }
d876 2
d888 3
a890 1
print '%source = (' . printhash(source) . ")\n";
d894 1
a894 1
print '%ctag = (' . printhash(ctag) . ")\n";
d896 12
a907 12
print '%states = (' . printhash(states) . ")\n";
print '%instates = (' . printhash(instates) . ")\n";
print '%endstates = (' . printhash(endstates) . ")\n";
print '%emptytrans = (' . printhash(emptytrans) . ")\n";
print '%exittrans = (' . printhash(exittrans) . ")\n";
print '%empty = (' . printhash(empty) . ")\n";
print '%any = (' . printhash(any) . ")\n";
print '%mixed = (' . printhash(mixed) . ")\n";
print '%children = (' . printhash(children) . ")\n";
print '%inmixed = (' . printhash(inmixed) . ")\n";
d911 1
a911 1
print '%catt = (' . printhash(catt) . ")\n";
d913 9
a921 9
print '%atttype = (' . printhash(atttype) . ")\n";
print '%enumtype = (' . printhash(enumtype) . ")\n";
print '%literaltype = (' . printhash(literaltype) . ")\n";
print '%typeof = (' . printhash(typeof) . ")\n";
print '%attdef = (' . printhash(attdef) . ")\n";
print '%required = (' . printhash(required) . ")\n";
print '%fixed = (' . printhash(fixed) . ")\n";
print '%initof = (' . printhash(initof) . ")\n";
d923 2
a924 2
print '%attlist = (' . printhash(attlist) . ")\n";
print '%withattr = (' . printhash(withattr) . ")\n";
d927 3
a929 2
print '%entity = (' . printhash(entity) . ")\n";
print '%parameter = (' . printhash(parameter) . ")\n";
d936 1
a936 1
if ($opt_H) {
d938 1
a938 1
print "Generating XML processor header in $HEADER.\n" if $verbose;
d944 2
a945 2
print "/* XML processor/application API for $DTD"
. ($DTDrevision ? " ($DTDrevision)" : "") . ".\n";
d953 1
a953 1
print "#ifndef _FLEXML_${cprefix}_H\n";
d978 1
a978 1
if ($opt_S or $opt_A) {
d980 3
a982 3
print "Writing XML processor"
. ($opt_a || $opt_A ? " and application" : "")
. " onto $SCANNER.\n" if $verbose;
a988 3
# Skip initial comment.
while (<SKELETON>) { last if m/^\s*\*\//; }
d990 2
a991 2
print "/* Validating XML processor for $DTD"
. ($DTDrevision ? " ($DTDrevision)" : "") . ".\n";
d998 4
d1010 2
a1011 2
print "const char rcs_${cprefix}_dtd[] =\n"
. " \"\$\" \"$DTDrevision \$\";\n" if $DTDrevision;
d1023 1
a1023 1
if ($opt_A) {
d1083 2
a1084 4
# Build pattern...
my ($pub,$sys);
$sys = "SYSTEM{S}" . ( $uri ? "(\"'$uri'\"|\"\\\"$uri\\\"\")"
: "(\"'$DTD'\"|\"\\\"$DTD\\\"\")");
d1086 4
a1089 2
$pub = "PUBLIC{S}(\"'$pubid'\"|\"\\\"$pubid\\\"\")";
$sys = undef if $pub and not $uri;
d1091 2
d1094 1
a1094 2
print " \"<!DOCTYPE\"{S}\"$_\"{S}" .$sys . "{s}\">\" SET(ROOT_$ctag{$_});\n" if $sys;
print " \"<!DOCTYPE\"{S}\"$_\"{S}" .$pub . "{s}\">\" SET(ROOT_$ctag{$_});\n" if $pub;
d1107 1
a1107 1
my @@myattributes = split /,/,"$attlist{$tag}";
d1219 6
a1224 3
print " switch (YY_START) {\n";
for (split /,/,$exittrans{$tag}) {
print " case $1: SET($2); break;\n" if m/^($Name)=>($Name)$/xo;
a1225 1
print " }\n";
d1248 6
a1253 3
print " switch (YY_START) {\n";
for (split /,/,$exittrans{$tag}) {
print " case $1: SET($2); break;\n" if m/^($Name)=>($Name)$/xo;
a1254 1
print " }\n";
d1308 1
a1308 1
printsource($ent);
d1313 5
a1317 5
print "\"&\" BUFFERPUTC('&');\n" unless $entity{"&"};
print "\"<\" BUFFERPUTC('<');\n" unless $entity{"<"};
print "\">\" BUFFERPUTC('>');\n" unless $entity{">"};
print "\"'\" BUFFERPUTC('\\\'');\n" unless $entity{"'"};
print "\""\" BUFFERPUTC('\"');\n" unless $entity{"""};
d1350 1
a1350 1
close SCANNER unless $opt_A;
d1358 1
a1358 1
if ($opt_D) {
d1360 3
a1362 3
print "Writing XML"
. ($opt_a ? "" : " dummy")
. " application onto $APPLICATION.\n" if $verbose;
d1368 2
a1369 2
print "/* XML application for $DTD" . ($DTDrevision ? " ($DTDrevision)" : "") . ".\n";
d1383 1
a1383 1
if ($opt_D or $opt_A) {
d1392 1
d1395 1
d1397 4
a1400 1
if ( m/^void\s+STag_($Name)\(void\)$/xo ) {
d1402 3
a1404 3
die "Unknown element `$tag'.\n" unless $ctag{$tag};
$startok{$tag} = true;
@@myattributes = split /,/,"$withattr{$tag}";
d1411 1
a1411 1
$endok{$1} = true;
d1421 1
a1421 1
die "Unknown attribute $1 for <$tag>.\n" if not $atttype{"$tag/$1"};
d1425 1
a1425 1
die "Unknown attribute $1 for <$tag>.\n" if not $atttype{"$tag/$1"};
d1429 1
a1429 1
die "Unknown attribute $1 for <$tag>.\n"
d1432 1
a1432 1
die "Attribute $att does not have value $elt for <$tag>.\n"
d1435 1
a1435 1
die "Malformed annotation $& in <$tag> action.\n" if m|\{[^;\s]+\}|o;
d1449 1
a1449 1
if ($opt_D) {
d1452 1
a1452 1
elsif ($opt_A) {
d1483 1
a1483 1
or textual combination with the processor
d1491 2
a1492 1
where the C<ExternalId> denotes the used DTD.
d1496 11
a1506 12
separate compilation of generated applications.
Optionally I<flexml> takes an I<actions> file with per-element actions
and produces a C file with element functions for an XML application
with entry points called from the XML processor (it can also fold the
XML application into the XML processor to make stand-alone XML
applications but this prevents sharing of the processor between
applications).
In L</OPTIONS> we list the possible options, in L</ACTION FILE FORMAT>
we explain how to write applications, and in L</BUGS> we list the
current limitations of the system before giving standard references.
d1561 1
a1561 2
instead of C<SYSTEM>, the default. If both B<-p> and B<-u> are
specified then both will be permitted.
d1580 1
a1580 1
specified I<uri>. (The default is the file name of the DTD.)
d1604 2
d1621 2
a1624 2
=item C<{>I<attribute>C<}>
d1649 2
a1652 2
=item C<pcdata>
d1666 2
a1669 2
=item C<yylex()>
d1681 2
a1686 2
=back
d1719 5
@
1.19
log
@-n option added :)
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.18 1999/12/03 23:24:40 krisrose Exp krisrose $ ';
d37 2
a38 1
%states = (); # $states{tag} is list of states used for tag element.
d43 1
a43 4
%emptytrans = ();# $emptytrans{state} contains empty transitions in automaton.
%intrans = (); # $intrans{tag} is state translation table after start tag.
%outtrans = (); # $outtrans{tag} is state translation table after end tag.
d53 1
a53 1
@@attributes = (); # Attributes of the DTD.
d59 1
d73 1
a73 1
%parameter = (); # parameter entity table (raw string)
a85 1
s/^(\s*\n)*//;
d148 1
a148 1
print "/* FleXML-provided data types. */\n" if %atttype;
d180 3
a182 1
sub getnonblank { # skip until a non-blank line available
d186 1
a186 1
$line = $_;
d232 1
a232 1
if ( m/^\s*($Name)\s*$/o or m/^\s*\(\s*($Name)\s*\)\s*$/o ) { # tag
d234 6
a239 17
my $tag = $1;
my $ins = $instates{$tag};
$ins .= ($ins?',':'') . $in unless $ins =~ m/$StartSep$in$EndSep/;
$instates{$tag} = $ins;
if ($in ne $out) {
if ( $intrans{$tag} =~ m/$StartSep$in=>$out$EndSep/ ) {
die "\"$DTD\", line $.: Oops...state transform tag: $in=>$out already registered?!\n";
}
elsif ( $intrans{$tag} =~ m/$StartSep$in=>([^,]*)$EndSep/ ) {
die "\"$DTD\", line $.: DTD element $tag ambiguous ($in=>$out and $2).\n";
}
else {
$intrans{$tag} .= ($intrans{$tag}?',':'') . "$in=>$out"
}
}
return false;
d242 1
a242 1
elsif ( m/^((.|\n)+)\+\s*$/o ) { # re +
d244 3
a246 7
my $re = $1;
my $s = "S_$ctag{$tag}_" . (++$statecounter);
$states{$tag} .= ",$s";
my $maybeempty = analysechildren($tag,$re,$in,$s);
analysechildren($tag,$re,$s,$s);
$emptytrans{$s} = $out;
return $maybeempty;
d249 1
a249 1
elsif ( m/^((.|\n)+)\?\s*$/o ) { # re ?
d251 7
a257 3
$emptytrans{$in} = $out unless $in eq $out;
analysechildren($tag,$1,$in,$out);
return true;
d291 1
a291 1
$maybeempty = false unless analysechildren($tag,$cp,$oldstate,$state);
d296 1
a296 1
# Last cp needs special treatment (in sequence, at least).
d301 1
a301 1
$maybeempty = false unless analysechildren($tag,$cp,$state,$out);
d304 2
a305 1
$emptytrans{$in} = $out if $maybeempty and $in ne $out;
d318 1
a318 1
$Use = "Usage: flexml [-ASHDvdLX] [-s skel] [-p pubid] [-u uri]\n"
d320 1
a320 1
use Getopt::Std; getopts('ASHDvdnLXp:s:u:r:a:');
d323 6
d383 1
a383 1
$opt_A = $opt_S = $opt_H = $opt_D = false;
d392 2
d413 1
a413 1
getnonblank();
d420 1
d428 2
a429 4
$orig .= "\n";
$orig .= $& while s/^\s*<!--([^-]|-[^-]|--[^>])*-->\s*//m;
$orig .= "\n" unless $_;
$orig .= getnonblank();
a431 3
# If we just have a plain line then we did not yet store the source.
$orig .= $_ unless $orig;
d444 5
d474 1
a474 1
$intrans{$tag} .= ($intrans{$tag}?',':'') . "ROOT_$c=>EPILOG"
d678 20
d700 7
a706 3
# Complete instates and endstates...
my $ins = $instates{$tag};
my $ons = $endstates{$tag};
d709 1
a709 7
for (keys %any) {
$ins .= ($ins?',':'') . "IN_$_";
}
# Encode empty transitions A->B: add B where A occurs.
for (keys %emptytrans) {
my ($a,$b) = ($_,$emptytrans{$_});
d711 6
a716 7
if ($ins =~ m/$StartSep$b$EndSep/) {
$ins = "$`$1$a,$b$2$'" unless $ins =~ m/$StartSep$a$EndSep/;
$intrans{$tag} .= ($intrans{$tag}?',':'') . "$a=>$b";
}
if ($ons =~ m/$StartSep$b$EndSep/) {
$ons = "$`$1$a,$b$2$'" unless $ons =~ m/$StartSep$a$EndSep/;
$outtrans{$tag} .= ($outtrans{$tag}?',':'') . "$a=>$b";
d720 4
a723 23
$instates{$tag} = $ins if $ins;
$endstates{$tag} = $ons if $ons;
# Take transitive closure of intrans and outtrans.
my %intranstag = ();
for (split /,/,$intrans{$tag}) {
$intranstag{$1} = $2 if m/^($Name)=>($Name)$/xo;
}
for (keys %intranstag) {
my $a = $_;
while ($a = $intranstag{$a}) { $intranstag{$_} = $a; }
}
$intrans{$tag} = join ',',(map "$_=>$intranstag{$_}",keys %intranstag);
my %outtranstag = ();
for (split /,/,$outtrans{$tag}) {
$outtranstag{$1} = $2 if m/^($Name)=>($Name)$/xo;
}
for (keys %outtranstag) {
my $a = $_;
while ($a = $outtranstag{$a}) { $outtranstag{$_} = $a; }
}
$outtrans{$tag} = join ',',(map "$_=>$outtranstag{$_}",keys %outtranstag);
d739 1
d756 1
a756 3
print '%intrans = (' . printhash(intrans) . ")\n";
print '%outtrans = (' . printhash(outtrans) . ")\n";
print '%inmixed = (' . printhash(inmixed) . ")\n";
d762 1
d791 3
d798 3
a800 3
print "/* XML processor/application API for $DTD";
print ",\n * ($DTDrevision)" if $DTDrevision;
print ".\n * Generated " . `date +'%Y/%m/%d %T.'`;
d834 4
d847 3
a849 3
print "/* Validating XML processor for $DTD";
print ",\n * ($DTDrevision)" if $DTDrevision;
print ".\n * Generated " . `date +'%Y/%m/%d %T.'`;
d988 1
a988 1
my $type;
d992 1
d1001 1
d1010 11
a1020 2
print " \"$attribute\"{Eq}{Literal}" # avoid backup
. " FAIL(\"`%s' illegal in `$tag' element start tag.\",yytext);\n" unless $nofail;
d1024 1
a1028 2
print " \"$attribute\"{Eq}{Literal}" # avoid backup
. " FAIL(\"`%s' illegal in `$tag' element start tag ($attribute declared $atttype{$tag}).\",yytext);\n" unless $nofail;
d1030 1
a1030 4
elsif ($fixed{"$tag/$attribute"}) {
print " \"$attribute\"{Eq}\"'" . $attdef{"$tag/$attribute"} . "'\""
. " A_${myctag}_$catt{$attribute}"
. " = " . $initof{"$tag/$attribute"} . ";\n";
d1032 1
a1032 8
print " \"$attribute\"{Eq}\"\\\"" . $attdef{"$tag/$attribute"} . "\\\"\""
. " A_${myctag}_$catt{$attribute}"
. " = " . $initof{"$tag/$attribute"} . ";\n";
print " \"$attribute\"{Eq}{Literal}" # avoid backup
. " FAIL(\"`%s' illegal in `$tag' element start tag.\",yytext);\n" unless $nofail;
}
else {
d1035 1
d1040 10
a1049 5
# - generic backup-avoiding rule,
print " {Name}{Eq} FAIL(\"`%s' illegal in `$tag' element start tag.\",yytext);\n" unless $nofail;
#
# - the end of a start tag means to enter the contents,
print " \">\" LEAVE; STag_$myctag();"
a1051 1
d1053 1
a1053 1
d1057 8
a1064 2
print " \"/>\" {\n"
. " LEAVE; STag_$myctag();"
d1070 1
a1070 5
my %setstateafter = ();
for (split /,/,$intrans{$tag}) {
$setstateafter{$1} .= " SET($2);" if m/^($Name)=>($Name)$/xo;
}
d1072 2
a1073 2
for (keys %setstateafter) {
print " case $_:$setstateafter{$_} break;\n";
a1075 1
d1078 3
d1082 1
a1082 1
# - spaces are skipped, and other stuff is an error.
d1084 3
d1090 1
a1090 16
# Errors when expecting root tag.
if ($roottags{$tag}) {
print "\n";
print "<ROOT_$myctag>{\n";
print " . FAIL(\"Unexpected character `%c': `$tag' element expected.\",yytext[0]);\n" unless $nofail;
print " <<EOF>> FAIL(\"EOF in prolog.\");\n" unless $nofail;
print "}\n";
}
}
# Dump all end tag recognition rules together (since they have
# catch-alls).
print "\n";
print " /* End-tags. */\n";
for my $tag (@@tags) {
my $myctag = $ctag{$tag};
a1096 1
a1097 4
my %setstateafter = ();
for (split /,/,$intrans{$tag}) {
$setstateafter{$1} .= " SET($2);" if m/^($Name)=>($Name)$/xo;
}
d1099 2
a1100 2
for (keys %setstateafter) {
print " case $_:$setstateafter{$_} break;\n";
a1102 1
d1105 1
d1107 1
a1107 1
print " . FAIL(\"Unexpected character `%c': `</$tag>' expected.\",yytext[0]);\n" unless ($mixed{$tag} or $nofail);
d1110 9
d1208 4
d1216 2
a1217 2
print "/* XML application for $DTD generated " . `date +'%Y/%m/%d %T.'`;
print " * ($DTDrevision).\n" if $DTDrevision;
d1219 1
d1311 1
a1311 1
[B<-ASHDvdnLX>]
d1430 4
d1550 2
a1551 1
C<ID>/C<IDREF> (and C<IDREFS>) are not validated for consistency.
d1555 1
a1555 1
The C<ENTITY> attribute type is not supported.
d1559 2
a1560 2
The various C<xml:>-attributes are ignored; in particular
C<xml:spaces> would be useful.
d1570 3
a1572 4
A child should be able to "return" a value for use by it's parent
(also called a I<synthesised attribute>). Similarly an element in
Mixed contents should be able to inject text into the C<pcdata> of
the parent.
a1613 2
$Id: flexml.pl,v 1.18 1999/12/03 23:24:40 krisrose Exp krisrose $
@
1.18
log
@Can now generate validating processors for XHTML!
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.17 1999/12/03 02:08:56 krisrose Exp krisrose $ ';
d330 1
a330 1
use Getopt::Std; getopts('ASHDvdLXp:s:u:r:a:');
d385 5
a392 1
d1301 1
a1301 1
[B<-ASHDvdLX>]
d1387 4
d1601 1
a1601 1
$Id: flexml.pl,v 1.17 1999/12/03 02:08:56 krisrose Exp krisrose $
@
1.17
log
@Compiles xhtml.dtd!
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.16 1999/12/02 00:32:24 krisrose Exp krisrose $ ';
d34 1
d73 2
a74 2
%entity = (); # general entity table
%parameter = (); # parameter entity table
d87 1
d96 10
d111 1
a111 1
$_;
a174 1
d328 3
a330 2
$Use = 'Usage: flexml [-ASHDvdLX] [-s skel] [-p pubid] [-u uri] [-a actions] name[.dtd]';
use Getopt::Std; getopts('ASHDvdLXp:s:u:a:');
d343 5
d349 1
a349 1
$SKELETON = ($opt_s ? $opt_s : '/usr/share/flexml/skel');
d359 1
a359 6
if ($opt_u) {
$uri = $opt_u
}
else {
$uri = $DTD;
}
d471 2
a472 1
$intrans{$tag} .= ($intrans{$tag}?',':'') . "ROOT_$c=>EPILOG";
d524 1
a524 1
expandparametersat('^'); s/^\s+//;
d572 1
a572 1
if ( $type =~ m/^\((.*)\)$/x ) {
d628 2
d632 1
a632 1
expandparametersat('^'); s/^\s+//; # to expand next set of declarations...
d647 3
a649 3
s/\&\#([0-9]+);/ pack("c",$1) /ge;
s/\&\#x([0-9a-fA-F]+);/ pack("c",hex($1)) /ge;
$parameter{"%$name;"} = "$_";
d659 3
a661 3
s/\&\#([0-9]+);/ pack("c",$1) /geo;
s/\&\#x([0-9a-fA-F]+);/ pack("c",hex($1)) /geo;
$entity{"&$name;"} = "$_";
d725 4
d894 3
a896 1
print "%x ROOT_$c AL_$c " . join(' ',split(',',$states{$_})) . "\n";
d911 1
a911 1
for ('PROLOG','DOCTYPE','EPILOG','COMMENT','VALUE1','VALUE2','CDATA') {
d916 1
a916 1
print " statenames[ROOT_$c] = NULL;\n";
d929 3
a931 1
my $id;
d933 2
a934 4
$id = "PUBLIC{S}(\"'$opt_p'\"|\"\\\"$opt_p\"\\\")";
}
else {
$id = 'SYSTEM';
d936 3
a938 4
$id .= "{S}(\"'$uri'\"|\"\\\"$uri\"\\\")";
for (@@tags) {
print " \"<!DOCTYPE\"{S}\"$_\"{S}" .$id . "{s}\">\" SET(ROOT_$ctag{$_});\n";
d945 1
a945 3
for my $key (keys %source) {
printsource($key) if $key =~ m/^\%/;
}
d962 6
a967 1
print "<ROOT_$myctag" . ($instates{$tag} ? ",$instates{$tag}" : "");
d1071 7
a1077 5
print "\n";
print "<ROOT_$myctag>{\n";
print " . FAIL(\"Unexpected character `%c': `$tag' element expected.\",yytext[0]);\n" unless $nofail;
print " <<EOF>> FAIL(\"EOF in prolog.\");\n" unless $nofail;
print "}\n";
d1127 2
a1128 1
print $sep . "ROOT_$ctag{$_},AL_$ctag{$_}";
d1138 2
a1139 1
. join(',', map("ROOT_$ctag{$_},AL_$ctag{$_},$states{$_}", @@tags))
d1148 1
a1148 1
print " \"$ent\" ENTITYTEXT(\"$entity{$ent}\");\n";
d1170 1
a1170 1
for ('PROLOG','DOCTYPE','EPILOG','COMMENT','VALUE1','VALUE2','CDATA','INITIAL','IMPOSSIBLE') {
d1222 1
a1222 1
open ACTIONS, "/usr/lib/flexml-act $ACTIONS|";
d1257 1
a1257 1
"A_$ctag{$tag}_$catt{$1}_" . variablify($2); |xe ) {
a1263 3
s/\{pcdata\}/pcdata/gx;
s/\{processor\}/yylex()/gx;
d1301 1
d1334 2
a1335 2
we explahow to write applications, and in L</BUGS> we list the current
limitations of the system before giving standard references.
d1386 7
a1392 2
instead of C<SYSTEM>; in any case followed by the DTD file name or the
I<uri> passed with B<-u>I<uri>.
d1471 1
a1471 1
=item C<{pcdata}>
d1488 1
a1488 1
=item C<{processor}>
d1492 2
a1493 1
manual for I<flex>(1) for information on how to change this).
d1499 1
a1499 1
int main() { exit({process}); }
d1542 2
a1543 1
badly.
d1549 1
a1549 1
Mixed contents should be able to inject text into the C<{pcdata}> of
d1558 1
a1558 1
=item F</usr/share/flexml/skel>
d1593 1
a1593 1
$Id: flexml.pl,v 1.16 1999/12/02 00:32:24 krisrose Exp krisrose $
@
1.16
log
@Manual updated...
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.15 1999/12/01 03:41:19 krisrose Exp krisrose $ ';
d39 2
a40 1
%outstates = ();# $outstates{tag} is list of states for element end tag.
d88 1
d162 1
a162 2
sub expandparameters { # Expand paremeter entities.
local ($_) = @@_;
d164 3
a166 24
# Upper limit of number of expandings (to avoid looping on cycles :)
my $count = (keys %parameter) + 1;
my $test = true;
while ($test and $count > 0) {
my $line = '';
$test = false;
while ($_) {
if ( s/^\'[^']*\'|^\"[^"]*\"|^%\s+|^[^%"']//o ) {
$line .= $&;
}
elsif ( s/^%$Name;//xo ) {
$test = true;
my $replacement = $parameter{$&};
die "Line $.: Unknown parameter entity reference \`$&\'.\n" if not $replacement;
$line .= $replacement;
}
else {
die "Messy line at >>>: \`$line>>>$_\'.\n";
}
}
$_ = $line;
$count--;
d168 1
a169 1
die "Internal parameter entity expansion loop.\n" if $count<0;
d171 8
a178 1
return $_;
d186 1
a186 1
if ( m/^($Name[+?*]?)\s*/xo ) {
d221 1
a221 1
if ( m/^\s*($Name)\s*$/xo or m/^\s*\(\s*($Name)\s*\)\s*$/xo ) { # tag
d230 1
a230 1
die "Oops...state transform tag: $in=>$out already registered?!\n";
d233 1
a233 1
die "DTD element $tag ambiguous ($in=>$out and $2).\n";
d242 1
a242 1
elsif ( m/^(.+)\+\s*$/o ) { # re +
d253 1
a253 1
elsif ( m/^(.+)\?\s*$/o ) { # re ?
d260 1
a260 1
elsif ( m/^(.+)\*\s*$/o ) { # re *
d265 1
a265 1
elsif ( m/^\s*\(\s*(.+)\s*\)\s*$/xo ) { # choice or seq
d276 1
a276 1
elsif ( m/^\s*([|,])\s*/ ) {
d308 1
a308 1
die "DTD element $tag has nonsense fragment `$_'.\n";
d317 2
a318 2
$Use = 'Usage: flexml [-ASHDdLX] [-s skel] [-p pubid] [-u uri] [-a actions] name[.dtd]';
use Getopt::Std; getopts('ASHDdLXp:s:u:a:');
d323 1
d341 8
a348 5
# Set document type URI.
if ($opt_u) { $uri = $opt_u; }
else { $uri = $DTD; }
if ($opt_p) { $uri = 'PUBLIC "' . $opt_p . '" "' . $uri . '"'; }
else { $uri = 'SYSTEM "' . $uri . '"'; }
a351 1
d368 1
a368 1
die "-A conflicts with -SHD.\n" if ($opt_S or $opt_H or $opt_D);
d394 24
a417 1
until (eof DTD) { # we exit in reader below
d419 2
a420 2
# Remove any "old" DTD entry and non-entry prefix.
s/^<![^>]*>([^<]|<[^!])*//o;
d422 2
a423 4
# Read until a full DTD <!...> entry is available in $_; take care
# to store the unmodified line in $orig and bail out when there are
# no more entries.
while (not m/^<![^>]*>/o and not eof DTD) {
d425 1
a425 1
$line = expandparameters($line);
a426 1
s/^([^<]|<[^!])*//o;
d428 4
a431 3
if (m/^(<![^>]*>)/o) {
$orig = "$1";
s/\s+/ /og;
d433 7
a439 2
else {
last;
d443 4
a446 1
if ( m/^<!ELEMENT\s+($Name)\s+([^>]*)>/xo ) {
d448 1
a448 1
die "Repeated element $tag.\n" if $source{$tag};
a449 1
$source{$tag} = "$orig";
d453 1
d456 1
a456 1
my $c = $ctag{$tag};
d465 3
a467 3
$states{$tag} = "S_$c,E_$c";
$outstates{$tag} = "E_$c";
$emptytrans{"S_$c"} = "E_$c";
d474 2
a475 1
$outstates{$tag} = "IN_$c";
d478 1
a478 1
or m/^\(\s*\#PCDATA\s*((\s*\|\s*$Name)*)\)\*\s*$/xo ) {
d488 2
a489 1
$outstates{$tag} = "IN_$c";
d495 1
d498 1
a498 1
$outstates{$tag} = "E_$c";
d503 1
a503 1
elsif ( m/^<!ATTLIST\s+([a-zA-Z:_.-]+)\s+([^>]*)>/o ) {
d505 1
a505 2
my $tag = $1;
local $_ = $2;
d507 3
a509 3
# Repeat while there are attribute declarations.
while ( s/^($Name)\s+([A-Z]+|\(\s*$Nmtoken(?:\s*\|\s*$Nmtoken)*\s*\))
(?:\s+(\#IMPLIED|\#REQUIRED|(?:\#FIXED\s+)?$Literal))?\s*//xo ) {
d511 1
a511 1
my ($attribute,$type,$default) = ($1,$2,$3);
d513 3
a515 8
if ($atttype{"$tag/$attribute"}) {
print "Warning: Redeclaration of element $tag attribute $attribute ignored.\n";
}
else {
if ($orig) { # to only print the source once
$source{"$tag/$attribute"} = "$orig";
$orig = '';
}
d517 1
a517 2
$ctag{$tag} = variablify($tag) unless $ctag{$tag};
$catt{$attribute} = variablify($attribute) unless $catt{$attribute};
d519 2
a520 4
# Add atribute to the appropriate lists.
$attlist{$tag} .= ($attlist{$tag}?',':'') . "$attribute";
if ($withattr{$attribute}) {
$withattr{$attribute} .= ",$tag";
d523 4
a526 3
push @@attributes, $attribute;
$withattr{$attribute} = "$tag";
}
d528 2
a529 12
# Analyse default value.
if ("$default" eq '#REQUIRED') {
$required{"$tag/$attribute"} = true;
$default = undef;
}
elsif ($default eq '#IMPLIED') {
$default = undef;
}
else {
$fixed{"$tag/$attribute"} = true if $default =~ s/\#FIXED\s+//o;
$default =~ s/^'([^'']*)'$/$1/o unless $default =~ s/^"([^""]*)"$/$1/o;
}
d531 4
a534 17
# Store attribute default string and type.
$attdef{"$tag/$attribute"} = $default if $default;
$atttype{"$tag/$attribute"} = "$type";
# Handle enumeration types...
if ( $type =~ m/^\((.*)\)$/x ) {
local $_ = $1;
s/\s+//go;
s/\|/,/go;
$enumtype{"$tag/$attribute"} = "$_";
s/$Nmtoken/ "A_$ctag{$tag}_$catt{$attribute}_" . variablify($&) /xge;
my $undefined = "AU_$ctag{$tag}_$catt{$attribute}";
s/^/enum \{ $undefined, /o;
s/$/ \}/o;
$typeof{"$tag/$attribute"} = "$_";
if ($default) {
$initof{"$tag/$attribute"} = "A_$ctag{$tag}_$catt{$attribute}_" . variablify($default);
d537 8
a544 1
$initof{"$tag/$attribute"} = "$undefined";
d546 2
a547 6
}
# ...and string/token types.
else {
$typeof{"$tag/$attribute"} = 'char*';
if ($default) {
$initof{"$tag/$attribute"} = "\"$default\"";
d550 2
a551 1
$initof{"$tag/$attribute"} = 'NULL';
d554 22
a575 3
# Special treatment of token types.
if ( $type eq 'ID' or $type eq 'IDREF' ) {
$literaltype{"$tag/$attribute"} = '{Name}';
d577 33
a609 17
elsif ( $type eq 'IDREFS' ) {
$literaltype{"$tag/$attribute"} = '{Names}';
}
elsif ( $type eq 'NMTOKEN' ) {
$literaltype{"$tag/$attribute"} = '{Nmtoken}';
}
elsif ( $type eq 'NMTOKENS' ) {
$literaltype{"$tag/$attribute"} = '{Nmtokens}';
}
elsif ( $type eq 'ENTITY' ) {
die "ENTITY attribute type unimplemented.\n";
}
elsif ( $type eq 'ENTITIES' ) {
die "ENTITIES attribute type unimplemented.\n";
}
elsif ( $type ne 'CDATA' ) {
die "Unknown AttType `$type'.\n";
d612 2
d615 1
d617 1
a617 3
# Store default value
$defaultdecl{"$tag/$attribute"} = $default;
}
d620 1
d623 12
a634 4
# Parse internal parameter entity declarations.
elsif ( /^<!ENTITY\s+%\s+([a-zA-Z:_.-]+)\s+"([^>]*)"\s*>/ ) {
$parameter{"%$1;"} = "$2";
$source{"%$1;"} = "$orig";
d638 9
a646 3
elsif ( /^<!ENTITY\s+([a-zA-Z:_.-]+)\s+"([^>]*)"\s*>/ ) {
$entity{"&$1;"} = "$2";
$source{"&$1;"} = "$orig";
d649 3
a651 4
# Save DTD RCS version number...
elsif ( /\$(Id|Header|Revision): [^\$]*\$/ ) {
$DTDrevision = "$&";
$DTDrevision =~ s/\s*\$\s*//go;
d662 1
a662 1
# Complete instates and outstates...
d664 1
a664 1
my $ons = $outstates{$tag};
d686 1
a686 1
$outstates{$tag} = $ons if $ons;
d732 1
a732 1
print '%outstates = (' . printhash(outstates) . ")\n";
d907 10
a916 3
my $uri1 = $uri; $uri1 =~ s/"/\\'/og; #'"
my $uri2 = $uri; $uri2 =~ s/"/\\"/og;
d918 1
a918 3
print ' "<!DOCTYPE"{S}' . $_ . '{S}'
. '(' . $uri . '|' . $uri1 . ')'
. '{s}">"' . " SET(ROOT_$ctag{$_});\n";
d982 1
a982 1
print " \"$attribute\"{Eq}\"\'\"$type\"\'\" BUFFERLITERAL('\\\'',A_${myctag}_$catt{$attribute});\n";
d1016 1
a1016 1
. " ENTER(" . ($mixed{$tag} ? 'IN' : 'S') . "_$myctag);\n";
d1062 1
a1062 1
print "<$outstates{$tag}>{\n";
d1121 1
a1121 1
print " \"$ent\" ENTITYTEXT(\"$entity{$ent}\")\n";
d1124 7
d1132 1
a1132 1
elsif ( /^FLEXML_FINAL$/ ) {
d1134 1
a1134 1
# Process general entities.
d1151 1
a1151 1
elsif ( $nofail and /FAIL/ ) {
d1204 1
d1273 1
a1273 1
[B<-ASHDdLX>]
d1285 11
a1295 8
interface to support XML I<application>s. Proper XML applications can
be generated optionally from special "action files", either for
linking or textual combination with the processor
Not all XML DTDs are supported: the DTD file must contain a complete
C<extSubset> (XML rule [30]) with the further restriction that it
cannot contain any external entity declarations or "processing
instruction".
d1299 1
a1299 5
separate compilation of generated applications. The generated
processor will only validate documents that conform strictly to the
DTD without extending it, more precisely we restrict XML rule [28] to
[28s] doctypedecl ::= '<!DOCTYPE' S Name S ExternalID S? '>'
d1303 4
a1306 3
called from the XML processor (it can also fold the XML application
into the XML processor to make stand-alone XML applications but this
prevents sharing of the processor between applications).
a1311 39
=head1 STATIC DTD FORMAT
As metioned above, the XML processors generated by I<Flexml> are
restricted to validate documents that have their entire definition in
one "external DTD subset".
However, the DTD itself should also obey certain restrictions that ensure that it can be completelt
Only internal (general and parameter) entities are handled. I<Flexml>
currently rejects DTDs using or declaring external entities,
notations, etc. More precisely we treat DTD files that match the
C<extSubset> production of XML with the additional restriction that it cannot
[29] markupdecl ::= elementdecl | AttlistDecl
| EntityDecl | NotationDecl | PI
| Comment
[30] extSubset ::= TextDecl? extSubsetDecl
[31] extSubsetDecl ::= ( markupdecl | conditionalSect | PEReference | S )*
[45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'
[46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
[47] children ::= (choice | seq) ('?' | '*' | '+')?
[48] cp ::= (Name | choice | seq) ('?' | '*' | '+')?
[49] choice ::= '(' S? cp ( S? '|' S? cp )* S? ')'
[50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
d1378 4
d1396 6
a1401 2
The contents of "C<top>" elements should be used for top-level C code
such as global declarations, utility functions, etc.
d1403 7
a1409 5
A "C<start>" element attaches the code as an action to the element
with the name of the required "C<tag>" attribute. The "C<%C-code;>"
component should be C code suitable for inclusion in a C block (i.e.,
within C<{>...C<}> so it may contain local variables); furthermore the
following extensions are available:
d1431 7
a1437 6
An "C<end>" element similarly attaches the code as an action to the
end tag with the name of the required "C<tag>" attribute; also here
the "C<%C-code;>" component should be C code suitable for inclusion in
a C block. In case the element has "Mixed" contents, i.e, was
declared to permit C<#PCDATA>, then the following variable is
available:
d1450 2
d1474 5
a1478 2
Note: I<Flexml> handles empty elements E<lt>I<tag>C</>E<gt> as
equivalent to E<lt>I<tag>E<gt>E<lt>C</>I<tag>E<gt>.
d1482 3
a1484 1
The present version of I<flexml> has some restrictions that we hope to
a1496 7
A child should be able to "return" a value for use by it's parent
(also called a I<synthesised attribute>). Similarly an element in
Mixed contents should be able to inject text into the C<{pcdata}> of
the parent.
=item *
d1508 12
a1521 6
If you discover a bug, in particular if you have a DTD for which you
believe I<flexml> should run but it does not (or produces bad output),
then please don't hesitate to contact the author. It is the goal that
I<flexml> may reject some valid DTDs but never a valid XML document
conforming to the restrictions summarised at the beginning of this manual.
d1561 1
a1561 1
$Id: flexml.pl,v 1.15 1999/12/01 03:41:19 krisrose Exp krisrose $
@
1.15
log
@Works (still needs testing, though... :).
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.14 1999/11/30 18:28:23 krisrose Exp krisrose $ ';
d330 2
a331 2
$Use = 'Usage: flexml [-ASHDdLX] [-s skel] [-u uri] [-a actions] name[.dtd]';
use Getopt::Std; getopts('ASHDdLXs:u:a:');
a346 3
# Get URI if any.
$uri = $opt_u if $opt_u;
d353 7
a359 1
# Selection options: If none of -SHD specified then default to -SH.
d862 2
a863 1
my $id = ($uri ? $uri : $DTD);
d866 2
a867 2
print ' "<!DOCTYPE"{S}' . $_ . '{S}' . 'SYSTEM{S}'
. '(' . "\\'" . $id . "\\'" . '|' . '\"' . $id . '\"' . ')'
d1179 2
d1215 3
a1217 1
[B<-ASHDdL>]
a1218 1
[B<-s>I<skel>]
d1226 65
a1290 10
documents. It produces a validating XML processor for the DTD in the
form of a I<flex>(1) scanner I<name>F<.l> with a corresponding C
header file I<name>F<.h>. (Not all XML DTDs are supported: see
L</BUGS>Z<> for a description of what is not (yet) implemented.)
Optionally it takes an I<actions> file with per-element actions and
produces a C file with element functions for an XML application called
from the XML processor (it can also fold the XML application into the
XML processor to make stand-alone XML applications but this prevents
sharing of the processor between applications).
a1291 1
The generated processor and applications are designed for speed.
d1295 1
a1295 1
I<Flexml> takes the following options:
d1301 4
a1304 4
Generate a I<stand-alone> scanner application. If combined with B<-a>
the aplication will be names as I<actions> with the extension replaced
with F<.l>, otherwise it will be in I<name>F<.l>. B<-A> conflicts
with B<-S>, B<-H>, and B<-D>.
d1306 1
a1306 1
=item B<-a>I<actions>
d1315 6
a1320 4
Generate the dummy application I<name>F<-dummy.c>. If combined with
B<-a>I<actions> then the application will include the specified
actions and be named as I<actions> with the extension replaced with
F<.c>.
d1324 1
a1324 1
Turns on debug mode in the flex scanner and also prints out a the
d1329 2
a1330 1
Generate the header file I<name>F<.h>.
d1334 10
a1343 3
Makes the XML processor count the lines in the input and keep it
available to XML application actions as C<yylineno>. (This is not the
default as the performance overhead is significant.)
d1347 2
a1348 1
Generate the scanner I<name>F<.l>.
d1350 1
a1350 1
=item B<-s>I<skel>
d1354 1
a1354 1
=item B<-u>I<uri>
a1358 1
d1361 1
a1361 1
=head1 ACTION FILES
d1366 1
a1366 1
<!ELEMENT actions ((top|start|end)*,main)>
d1377 1
a1377 1
with the name of the requred "C<tag>" attribute. The "C<%C-code;>"
d1388 1
a1388 1
appears as a null-terminated C string (of type C<char*>) except if
d1391 1
a1391 1
<!ATTLIST attrib (alt1 | alt2 |...)*>
d1393 2
a1394 2
in which case an the attribute is of an enumerated type with the
elements written C<{>I<attribute>C<=>I<alt1>C<}>,
d1396 3
a1398 1
attribute has the "value" C<{!>I<attribute>C<}>.
d1403 5
a1407 4
end tag names as the required "C<tag>" attribute. The "C<%C-code;>"
component should be C code suitable for inclusion in a C block (i.e.,
within C<{>...C<}>). In case the element has "Mixed" contents then
the following variable is available:
d1411 1
a1411 1
=item C<pcdata>
d1420 1
a1420 1
Finally, a "C<main>" element should contain the entire C C<main>
d1426 1
a1426 1
=item C<yylex()>
d1434 1
a1434 1
If no C<main> action is provided then the following default is provided:
d1436 1
a1436 1
int main() { exit(yylex()); }
d1447 2
a1448 7
I<Flexml> is restricted (by design) to validate XML documents with a
document type declaration of the simple form
<!DOCTYPE root SYSTEM "uri">
because these can be efficiently parsed. However, the present version
has more serious restrictions that we hope to overcome in the future:
d1455 2
a1456 2
characters but this only has the ASCII character set in common with
the UTF-8 encoding required by XML).
d1460 4
a1463 10
Element-content is restricted to declarations of the form
<!ELEMENT tag (child1 | child2 | ... )*>
(essentially as Mixed contents without C<#PCDATA>). This is being fixed.
=item *
A child should be able to insert a "cookie" (also called a
I<synthesised attribute>) in the data stream of the parent.
d1467 1
a1467 1
C<ID>/C<IDREF> consistency is not validated.
a1474 6
Only internal (general and parameter) entities are handled. I<Flexml>
currently rejects DTDs using or declaring external entities,
notations, etc.
=item *
d1480 5
a1484 3
There are further restrictions on the form of DTDs because the present
DTD parser does not conform to the XML specification, however,
I<flexml> will complain rather than produce incorrect XML processors.
d1525 1
a1525 1
$Id: flexml.pl,v 1.14 1999/11/30 18:28:23 krisrose Exp krisrose $
@
1.14
log
@Full DTD parsing almost done...still some nitty-gritty, though.
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.13 1999/11/29 16:09:02 krisrose Exp krisrose $ ';
d36 5
a40 1
%states = (); # $states{tag} is list of states for tag element.
d42 2
a43 1
%restate = (); # $restate{tag} is state translation table after tag element.
d46 1
a50 2
%instates = (); # $instates{tag} is comma-separated list of element
# contexts within which the tag element may occur.
a126 1
a135 1
a149 1
a160 1
d237 3
a239 1
$instates{$tag} .= ($instates{$tag}?',':'') . $in;
d242 1
a242 1
if ( $restate{$tag} =~ m/(^|,)$in=>$out(,|$)/ ) {
d245 1
a245 1
elsif ( $restate{$tag} =~ m/(^|,)$in=>([^,]*)(,|$)/ ) {
d249 1
a249 1
$restate{$tag} .= ($restate{$tag}?',':'') . "$in=>$out"
d396 2
d437 1
a437 1
$restate{$tag} .= ($restate{$tag}?',':'') . "ROOT_$c=>EPILOG";
d442 1
d444 1
d452 1
d465 1
d473 1
d614 3
a616 2
# Complete instates...
my $ss = $instates{$tag};
d620 1
a620 1
$ss .= ($ss?',':'') . "IN_$_";
d626 8
a633 2
if ($ss =~ s/(^|,)$b(,|$)/$1$a,$b$2/) {
$restate{$tag} .= ($restate{$tag}?',':'') . "$a=>$b";
d637 2
a638 1
$instates{$tag} = $ss;
d640 4
a643 4
# Take transitive closure of restate.
my %restatetag = ();
for (split /,/,$restate{$tag}) {
$restatetag{$1} = $2 if m/^($Name)=>($Name)$/xo;
d645 1
a645 1
for (keys %restatetag) {
d647 1
a647 1
while ($a = $restatetag{$a}) { $restatetag{$_} = $a; }
d649 11
a659 1
$restate{$tag} = join ',',(map "$_=>$restatetag{$_}",keys %restatetag);
d683 3
d687 3
a689 1
print '%restate = (' . printhash(restate) . ")\n";
a694 3
print '%instates = (' . printhash(instates) . ")\n";
print '%inmixed = (' . printhash(inmixed) . ")\n";
d796 2
a797 1
print "#define FLEXML_Mixed\n" if %inmixed;
d976 1
a976 1
for (split /,/,$restate{$tag}) {
a988 1
print " {S} SKIP;\n";
a995 1
print " {S} SKIP;\n";
d1008 1
a1008 1
print "<" . ($mixed{$tag} ? 'IN' : 'E') . "_$myctag>{\n";
d1016 1
a1016 1
for (split /,/,$restate{$tag}) {
a1026 2
print " {S} SKIP;\n" unless $mixed{$tag};
d1044 11
d1071 19
d1466 3
a1468 1
$Id: flexml.pl,v 1.13 1999/11/29 16:09:02 krisrose Exp krisrose $
@
1.13
log
@Full DTD parsing in progress...currently not working.
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.12 1999/11/25 18:42:03 krisrose Exp krisrose $ ';
d34 1
a34 1
%ctag = (); # C variable name for tag.
d36 3
a38 2
%states = (); # states (,-separated) corresponding to tag.
%leavetags = ();# reverse state table to apply at end of each tag.
a40 1
a41 1
a42 2
%inmixed = (); # $inmixed{tag} == true if the tag occurs *in* Mixed contents.
d45 1
a45 1
%instates = (); # $instates{tag} is comma-separated list of element
d47 1
a47 3
%emptytransto = ();# $emptyransto{tag} == tag2 for empty: tag2->tag1.
%leavetags = ();# state transformations to do at end tag.
a61 3
%startok = (); # start tag action already dumped
%endok = (); # end tag action already dumped
a63 1
d68 1
d70 2
a71 1
%parameter = (); # parameter entity table
d114 4
d125 3
a127 3
foreach $tag (@@tags) {
print $pre . "void STag_$ctag{$tag}(void)$post\n" unless $startok{$tag};
print $pre . "void ETag_$ctag{$tag}(void)$post\n" unless $endok{$tag};
d135 2
a136 2
foreach $ta (keys %atttype) {
if ($ta =~ m.($Nmtoken)[/]($Nmtoken).o) {
d138 1
a138 1
print "typedef $typeof{$ta} AT_$ctag{$tag}_$catt{$attribute};\n";
d140 1
a140 1
if not $enumtype{$ta};
d151 4
a154 4
foreach $ta (keys %atttype) {
my ($tag,$attribute);
($tag,$attribute) = ($1,$2) if $ta =~ m.($Nmtoken)[/]($Nmtoken).o;
print $pre . "AT_$ctag{$tag}_$catt{$attribute} A_$ctag{$tag}_$catt{$attribute};\n";
d236 15
a250 1
print"Analyse: tag $1.\n";
d252 2
a253 1
$instates{$1} .= ($instates{$1} ? "," : "") . $in;
d255 7
a261 3
die "DTD element $tag ambiguous ($in).\n"
if $leavetags{"$1,$in"} and $leavetags{"$1,$in"} ne $out;
$leavetags{"$1,$in"} = $out unless $in eq $out;
a262 1
return false;
d266 1
a266 3
print"Analyse: $1 ?\n";
$emptytransto{$out} = $in unless $in eq $out;
d269 1
d273 1
a273 1
print"Analyse: $1 *\n";
a274 11
$emptytransto{$out} = $in unless $in eq $out;
analysechildren($tag,$1,$out,$out);
return true;
}
elsif ( m/^(.+)\+\s*$/o ) { # re +
print"Analyse: $1 +\n";
my $re = $1;
analysechildren($tag,$re,$out,$out) unless $in eq $out;
return analysechildren($tag,$re,$in,$out);
a277 2
print"Analyse: $1...\n";
a281 2
print" head: $cp\n";
d284 1
a284 1
print" recurse...\n";
a285 1
return analysechildren($tag,$cp,$in,$out);
d289 1
a289 1
my $result = ($type eq '[,]');
a291 2
print" type $type...\n";
a294 2
print" rest is $_...\n";
d296 1
a296 4
print" choice $cp...\n";
$result = true if analysechildren($tag,$cp,$in,$out);
a298 3
print" sequent $cp...\n";
a300 1
$result = false unless analysechildren($tag,$cp,$oldstate,$state);
d302 1
d309 1
a309 4
print" final choice $cp...\n";
$result = true if analysechildren($tag,$cp,$in,$out);
d312 2
d315 2
a316 6
print" final sequent $cp...\n";
$result = false unless analysechildren($tag,$cp,$state,$out);
}
return $result unless $_;
d328 1
a328 1
$Use = "Usage: flexml [-ASHDdLX] [-s skel] [-u uri] [-a actions] name[.dtd]";
d342 1
a342 1
$SKELETON = ($opt_s ? $opt_s : "/usr/share/flexml/skel");
d433 1
a433 1
$leavetags{"$tag,ROOT_$c"} = 'EPILOG';
d438 2
a439 1
$states{$tag} = "IN_$c";
d453 3
a455 3
foreach $tag2 (split /\s*\|\s*/,"$desc") {
$instates{$tag2} .= ($instates{$tag2} ? "," : "") . "IN_$c";
$inmixed{$tag2} = true;
d462 3
a464 10
$empty{$tag} = true if analysechildren($tag,$_,"S_$c","IN_$c");
# Try to optimise non-needed states away...
if ($empty{$tag}) {
$states{$tag} = "IN_$c" . $states{$tag};
delete $emptytransto{"IN_$c"};
}
else {
$states{$tag} = "IN_$c,S_$c" . $states{$tag};
}
d493 1
a493 1
$attlist{$tag} .= ($attlist{$tag} ? "," : "") . "$attribute";
d539 1
a539 1
$typeof{"$tag/$attribute"} = "char*";
d544 1
a544 1
$initof{"$tag/$attribute"} = "NULL";
d548 2
a549 2
if ( $type eq "ID" or $type eq "IDREF" ) {
$literaltype{"$tag/$attribute"} = "{Name}";
d551 2
a552 2
elsif ( $type eq "IDREFS" ) {
$literaltype{"$tag/$attribute"} = "{Names}";
d554 2
a555 2
elsif ( $type eq "NMTOKEN" ) {
$literaltype{"$tag/$attribute"} = "{Nmtoken}";
d557 2
a558 2
elsif ( $type eq "NMTOKENS" ) {
$literaltype{"$tag/$attribute"} = "{Nmtokens}";
d560 1
a560 1
elsif ( $type eq "ENTITY" ) {
d563 1
a563 1
elsif ( $type eq "ENTITIES" ) {
d566 1
a566 1
elsif ( $type ne "CDATA" ) {
d601 6
a606 1
# DTD Post-processing.
d608 3
a610 4
# Expand ANY element contents into the corresponding Mixed contents.
foreach $tag (keys %any) {
foreach $tag2 (@@tags) {
$instates{$tag2} .= ($instates{$tag2} ? "," : "") . "IN_$tag";
a611 1
}
d613 5
a617 7
# Remove empty element content tag states.
foreach $tag (@@tags) {
if ($empty{$tag}) {
my $c = $ctag{$tag};
foreach $tag2 (@@tags) {
delete $leavetags{"$tag2,S_$c"};
$instates{$tag2} =~ s/,S_$c$//;
d620 13
d635 1
d654 1
d656 3
a658 1
print '%leavetags = (' . printhash(leavetags) . ")\n";
a661 1
print '%inmixed = (' . printhash(inmixed) . ")\n";
d663 1
d665 1
a665 2
print '%emptytransto = (' . printhash(emptytransto) . ")\n";
print '%leavetags = (' . printhash(leavetags) . ")\n";
d667 1
d669 2
d674 2
d679 2
a682 3
print '%catt = (' . printhash(catt) . ")\n";
print '%typeof = (' . printhash(typeof) . ")\n";
print '%initof = (' . printhash(initof) . ")\n";
d684 1
d767 1
a767 1
print "#define FLEXML_inmixed\n" if %inmixed;
d795 3
a797 5
my $tag;
foreach $tag (@@tags) {
my $c = $ctag{$tag};
print "%x ROOT_$c AL_$c " . join(' ',split(',',$states{$tag})) . "\n";
d807 1
a807 1
print "char* statenames[DISABLE];\n";
d812 2
a813 2
foreach $state ('PROLOG','DOCTYPE','EPILOG','COMMENT','VALUE1','VALUE2','CDATA','DISABLE') {
print " statenames[$state] = \"$state\";\n";
d815 1
a815 1
foreach $tag (@@tags) {
d817 4
a820 5
print " statenames[ROOT_$c] = \"document ($tag)\";\n";
print " statenames[AL_$c] = \"$tag (attributes)\";\n";
foreach $state (split ',',$states{$tag}) {
print " statenames[$state] = \"$tag\";\n";
d831 2
a832 2
foreach $tag (@@tags) {
print ' "<!DOCTYPE"{S}' . $tag . '{S}' . 'SYSTEM{S}'
d834 1
a834 1
. '{s}">"' . " SET(ROOT_$ctag{$tag});\n";
d841 1
a841 1
foreach $key (keys %source) {
d846 1
a846 1
foreach $tag (@@tags) {
d854 1
a854 1
foreach $attribute (@@myattributes) {
d862 1
a862 1
foreach $attribute (@@myattributes) {
d872 1
a872 1
foreach $attribute (@@myattributes) {
d885 1
a885 1
foreach $alternative (split /,/,$type) {
d894 1
a894 1
. " FAIL(\"%s illegal in $tag element.\",yytext);\n" unless $nofail;
d903 1
a903 1
. " FAIL(\"%s illegal in $tag element ($attribute is #FIXED).\",yytext);\n" unless $nofail;
d915 1
a915 1
. " FAIL(\"%s illegal for $tag element.\",yytext);\n" unless $nofail;
d925 1
a925 1
print " {Name}{Eq} FAIL(\"%s illegal in $tag.\",yytext);\n" unless $nofail;
d929 1
a929 1
. ($inmixed{$tag} ? ' pushbuffer(pcdata);' : '')
d931 3
a933 1
. " ENTER(" . ($empty{$tag} ? 'IN' : 'S') . "_$myctag);\n";
d937 12
a948 7
print " \"/>\" {\n";
print " LEAVE; STag_$myctag();\n";
print " pushbuffer(pcdata);\n" if $inmixed{$tag};
print " pcdata = " . ($mixed{$tag} ? '""' : 'NULL') . ";\n";
print " ETag_$myctag();\n";
print " pcdata = popbuffer();\n" if $inmixed{$tag};
d950 2
a951 4
foreach $key (keys %leavetags) {
if ($key =~ m/$tag,($Name)/x) {
print " case $1: SET($leavetags{$key}); break;\n"
}
d960 2
a961 2
print " . FAIL(\"Unexpected character \`%c\' in attribute list of $tag element.\", *yytext);\n" unless $nofail;
print " <<EOF>> FAIL(\"EOF in attribute list of $tag element.\");\n" unless $nofail;
d968 1
a968 1
print " . FAIL(\"<$tag> root element expected.\");\n" unless $nofail;
d977 1
a977 1
foreach $tag (@@tags) {
d980 1
a980 1
print "<IN_$myctag>{\n";
d986 5
a990 1
print " pcdata = popbuffer();\n" if $inmixed{$tag};
d992 2
a993 4
foreach $key (keys %leavetags) {
if ($key =~ m/$tag,($Name)/x) {
print " case $1: SET($leavetags{$key})\n;"
}
d1001 3
a1003 3
print " \"</\"{Name}{s}\">\" FAIL(\"Bad end tag: %s where </$tag> expected.\",yytext);\n" unless $nofail;
print " . FAIL(\"Unexpected character \`%c\' where </$tag> expected.\",*yytext);\n" unless ($mixed{$tag} or $nofail);
print " <<EOF>> FAIL(\"Premature EOF: </$tag> expected.\");\n" unless $nofail;
d1014 1
a1014 1
print "$`DISABLE$1$'";
d1028 1
a1028 1
foreach $ent (keys %entity) {
d1410 1
a1410 1
$Id: flexml.pl,v 1.12 1999/11/25 18:42:03 krisrose Exp krisrose $
@
1.12
log
@Stand-alone mode added and documented; still technical section to write.
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.11 1999/11/25 03:01:47 krisrose Exp krisrose $ ';
d36 4
a39 1
%empty = (); # $empty{tag} == true if the tag is an empty tag.
d46 3
a48 1
%intags = (); # $intags{tag} is comma-separated list of element
d51 3
d162 1
a162 1
sub expandparameters {
d166 2
a167 2
# Expand parameter entities until none left (or we hit a cycle :)
my $count = keys %parameter;
d192 2
d198 142
d345 2
a346 2
$Use = "Usage: flexml [-ASHDdL] [-s skel] [-u uri] [-a actions] name[.dtd]";
use Getopt::Std; getopts('SHDdLs:u:a:A');
d355 3
d447 1
d449 4
d455 1
d458 1
d460 2
a461 1
$any{$tag} = true;
d463 9
a471 8
elsif ( m/^\(\s*(\#PCDATA\s*\|\s*)?($Name\s*(\|\s*$Name\s*)*)\)\*\s*$/xo
or m/^\(\s*(\#PCDATA)\s*\)\s*$/o ) {
if ($1) {
$mixed{$tag} = true;
}
foreach $tag2 (split /[| ]+/,"$2") {
$intags{$tag2} .= ($intags{$tag2} ? "," : "") . "$tag";
$inmixed{$tag2} = true if $1;
d473 1
d476 12
a487 1
die "$0: unsupported $orig";
d535 1
a535 1
$default =~ s/^'([^'']*)'$/\1/o unless $default =~ s/^"([^""]*)"$/\1/o;
d624 2
a626 1
d629 12
a640 1
$intags{$tag2} .= ($intags{$tag2} ? "," : "") . "$tag";
d662 2
d668 4
a671 1
print '%intags = (' . printhash(intags) . ")\n";
d796 2
d799 2
a800 2
$c = $ctag{$tag};
print "%x ROOT_$c AL_$c IN_$c\n";
d803 2
a804 2
if ($debug) {
print "%{\n";
d806 1
a806 1
my ($state, $tag);
d808 17
a824 7
foreach $state ('PROLOG','DOCTYPE','EPILOG','COMMENT','VALUE1','VALUE2','CDATA','DISABLE') {
print "#define X$state \"$state\"\n";
}
foreach $tag (@@tags) {
$c = $ctag{$tag};
print "#define XAL_$c \"AL_$c\"\n";
print "#define XIN_$c \"IN_$c\"\n";
a825 1
print "%}\n";
d827 2
d838 1
a838 1
. '{s}">"' . " BEGIN(ROOT_$ctag{$tag});\n";
d864 1
a864 2
print "<ROOT_$myctag";
foreach $intag (split /,/,"$intags{$tag}") { print ",IN_$ctag{$intag}"; }
d883 2
a884 3
. " A_${myctag}_$catt{$attribute}"
. " = " . $initof{"$tag/$attribute"} . ";\n";
print " \"$attribute\"{Eq}\"\\\"" . $attdef{"$tag/$attribute"} . "\\\"\""
d891 2
a892 4
. " A_${myctag}_$catt{$attribute}"
. " = A_${myctag}_$catt{$attribute}_" . variablify($alternative) . ";\n";
print " \"$attribute\"{Eq}\"\\\"$alternative\\\"\""
d898 1
a898 1
. " FAIL(\"%s illegal in $tag element.\",yytext);\n";
d907 1
a907 1
. " FAIL(\"%s illegal in $tag element ($attribute is #FIXED).\",yytext);\n";
d919 1
a919 1
. " FAIL(\"%s illegal for $tag element.\",yytext);\n";
d929 1
a929 1
print " {Name}{Eq} FAIL(\"%s illegal in $tag.\",yytext);\n";
d932 4
a935 4
print " \">\" LEAVE(AL_$myctag); STag_$myctag();";
print " pushbuffer(pcdata);" if $inmixed{$tag};
print " pcdata = " . ($mixed{$tag} ? 'BUFFERSET(pcdata)' : 'NULL') . ";";
print " ENTER(IN_$myctag);\n";
d937 19
a955 5
# - the end of an empty tag means handle it straight away,
print " \"/>\" LEAVE(AL_$myctag); STag_$myctag();";
print " pushbuffer(pcdata);" if $inmixed{$tag};
print " pcdata = " . ($mixed{$tag} ? '""' : 'NULL') . ";";
print " ETag_$myctag(); CHECKEPILOG($myctag);\n";
d959 2
a960 2
print " . FAIL(\"Unexpected character \`%c\' in attribute list of $tag element.\", *yytext);\n";
print " <<EOF>> FAIL(\"EOF in attribute list of $tag element.\");\n";
a965 1
print " \"<!--\" ENTER(COMMENT);\n";
d967 2
a968 2
print " . FAIL(\"<$tag> root element expected.\");\n";
print " <<EOF>> FAIL(\"EOF in prolog.\");\n";
d975 1
a975 1
print " /* End-tags and nesting errors. */\n";
d980 15
a994 5
print " \"</$tag\"{s}\">\" LEAVE(IN_$myctag);";
print " BUFFERDONE;" if $mixed{$tag};
print " ETag_$myctag();";
print " pcdata = popbuffer();" if $inmixed{$tag};
print " CHECKEPILOG($myctag);\n";
d998 3
a1000 3
print " \"</\"{Name}{s}\">\" FAIL(\"Bad end tag: %s where </$tag> expected.\",yytext);\n";
print " . FAIL(\"Unexpected character \`%c\' where </$tag> expected.\",*yytext);\n" unless $mixed{$tag};
print " <<EOF>> FAIL(\"Premature EOF: </$tag> expected.\");\n";
d1015 1
a1015 1
elsif ( /FLEXML_NORMAL([,>])/ ) {
d1018 2
a1019 2
. join(',', map("IN_$ctag{$_}", keys %mixed)) . ','
. join(',', map("AL_$ctag{$_}", @@tags)) . "$1$'";
d1031 3
d1096 1
a1096 1
s/(\s+[SE])Tag_($Name)\(/\1Tag_$ctag{$2}\(/xg;
d1407 1
a1407 1
$Id: flexml.pl,v 1.11 1999/11/25 03:01:47 krisrose Exp krisrose $
@
1.11
log
@Almost ready...
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.10 1999/11/24 16:46:57 krisrose Exp krisrose $ ';
a115 1
d119 1
a119 1
print "/* XML application entry points. */\n";
a123 1
print "\n";
d128 2
a129 1
print "/* FleXML-provided data types. */\n";
d193 2
a194 2
$Use = "Usage: flexml [-dSHDL] [-s skel] [-u uri] [-a actions] name[.dtd]";
use Getopt::Std; getopts('LdSHDs:u:a:');
d203 7
d219 2
a220 9
$opt_S = $opt_H = true unless ($opt_S or $opt_H or $opt_D);
$opt_D ||= $opt_a;
# Get URI if any.
$uri = $opt_u if $opt_u;
# Set skeleton scanner file name and check it is readable (if needed).
$SKELETON = ($opt_s ? $opt_s : "/usr/share/flexml/skel");
die "$0: No skeleton file $SKELETON.\n" if not -r $SKELETON and $opt_S;
d229 9
a237 3
local $_ = $opt_a;
s/\.(xml|act)$//;
$APPLICATION = "$_.c";
d518 1
d520 1
d523 4
d540 1
a540 1
if ($opt_S) {
d564 1
a564 1
print "const char* rcs_flexml =\n"
d567 1
a567 1
print "const char* rcs_${cprefix}_dtd =\n"
a569 2
print "#define DEBUG\n" if $debug;
d571 1
a571 1
elsif ( /^FLEXML_API$/ ) {
d573 4
a576 2
print "/* XML processor interface. */\n";
print "#include \"$HEADER\"\n";
d578 14
a591 1
api_data('');
d696 1
a696 1
. " FAIL(\"%s illegal in $tag element.\");\n";
d705 1
a705 1
. " FAIL(\"%s illegal in $tag element ($attribute is #FIXED).\");\n";
d717 1
a717 1
. " FAIL(\"%s illegal for $tag element.\");\n";
d727 1
a727 1
print " {Name}{Eq} FAIL(\"%s illegal in $tag.\");\n";
d752 1
a752 1
print " . FAIL(\"$tag root element.\");\n";
d774 1
a774 1
print " . FAIL(\"Unexpected character \`%c\' where </$tag> expected.\");\n" unless $mixed{$tag};
d783 1
a783 1
print "$`IN_" . join(',IN_', map($ctag{$_}, keys %mixed)) . "$1$'";
d790 7
d814 1
a814 1
close SCANNER;
d840 4
d895 1
d901 3
d906 3
d922 1
a922 1
[B<-dSHD>]
d924 1
a925 1
[B<-s>I<skel>]
d932 4
a935 5
documents. From this I<flexml> produces a validating XML processor
for the DTD in the form of a I<flex>(1) scanner I<name>F<.l> with a
corresponding C header file I<name>F<.h>. (Not all XML DTDs are
supported: see L</BUGS>Z<> for a description of what is not (yet)
implemented.)
d939 5
a943 1
from the XML processor.
d951 20
a970 1
=item B<-S -H -D>
d972 8
a979 3
These options make it explicit that only the scanner, header, and/or
(dummy) application files should be generated. If none of them are
given the default is B<-SH> (except B<-a> below implies B<-A>).
d987 5
a991 1
=item B<-a>I<actions>
d993 1
a993 3
Uses the I<actions> file to produce an XML application in the file
with the same name as I<actions> after replacing the extension with
F<.c>.
a999 8
=item B<-s>I<skel>
Use the skeleton scanner I<skel> instead of the default.
=item B<-d>
Turns on debug mode in the flex scanner and also prints out a the
details of the DTD analysis performed by I<flexml>.
d1013 1
d1121 4
d1129 5
d1178 2
@
1.10
log
@Program and manpage done.
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.9 1999/11/23 17:28:07 krisrose Exp krisrose $ ';
d132 6
a137 3
my ($tag,$attribute);
($tag,$attribute) = ($1,$2) if $ta =~ m.($Nmtoken)[/]($Nmtoken).o;
print "typedef $typeof{$ta} AT_$ctag{$tag}_$catt{$attribute};\n";
d194 2
a195 2
$Use = "Usage: flexml [-dSHD] [-s skel] [-u uri] [-a actions] name[.dtd]";
use Getopt::Std; getopts('dSHDs:u:a:');
d201 3
d254 1
a254 1
until (eof DTD) {
d259 3
a261 1
# Read until a full DTD <!...> entry is available in $_.
d276 1
a276 1
# Parse the understood element declarations.
d283 1
a283 1
# Create C-friendly variable names.
d316 1
a316 1
# Repeat while there are attribute declarations. Alert: large regexp...
a414 2
d443 1
a443 1
# Fix ANY tags.
a450 1
d572 1
d607 1
a607 1
. '(' . "\\'" . $uri . "\\'" . '|' . '\"' . $uri . '\"' . ')'
d671 2
d677 1
d680 14
d696 2
a697 12
if ($fixed{"$tag/$attribute"}) {
print " \"$attribute\"{Eq}\"'" . $attdef{"$tag/$attribute"} . "'\""
. " A_${myctag}_$catt{$attribute}"
. " = " . $initof{"$tag/$attribute"} . ";\n";
print " \"$attribute\"{Eq}\"\\\"" . $attdef{"$tag/$attribute"} . "\\\"\""
. " A_${myctag}_$catt{$attribute}"
. " = " . $initof{"$tag/$attribute"} . ";\n";
}
else {
print " \"$attribute\"{Eq}\\' ENTER(VALUE1); BUFFERSET(A_${myctag}_$catt{$attribute});\n";
print " \"$attribute\"{Eq}\\\" ENTER(VALUE2); BUFFERSET(A_${myctag}_$catt{$attribute});\n";
}
d702 3
d819 1
a819 1
if ( m/^void STag_($Name)\(void\)$/ ) {
d824 1
a824 1
elsif ( m|^\} \/\* STag_($Name) \*\/$| ) {
d828 1
a828 1
elsif ( m/^void ETag_($Name)\(void\)$/ ) {
d832 2
a833 3
s/\{($Name)\}/A_$ctag{$tag}_$catt{$1}/xg if $tag;
s/\{($Name)\/($Name)\}/ "A_$ctag{$tag}_$catt{$1}_" . variablify($2); /xge if $tag;
s/([SE])Tag_($Name)/\1Tag_$ctag{$2}/xg;
d835 21
d912 6
d921 2
a922 1
with the same name as I<actions> after stripping the extension.
d972 3
a974 2
elements written C<{>I<attribute>C</>I<alt1>C<}>,
C<{>I<attribute>C</>I<alt2>C<}>, etc.
@
1.9
log
@Works but manual/paper still in flux...
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.8 1999/11/23 10:27:04 krisrose Exp krisrose $ ';
d210 2
a211 2
# Get base URI.
$baseuri = $opt_u if $opt_u;
d230 1
a230 1
$prefix = variablify("$prefix");
d505 1
a505 1
print "#ifndef _FLEXML_${prefix}_H\n";
d551 1
a551 1
print "const char* rcs_${prefix}_dtd =\n"
d597 2
d600 3
a602 5
print ' "<!DOCTYPE"{S}' . $tag . '{S}'
. 'SYSTEM{S}('
. "\\'" . "$baseuri$DTD" . "\\'"
. '|\"' . "$baseuri$DTD" . '\"'
. '){s}">"' . " BEGIN(ROOT_$ctag{$tag});\n";
d834 1
a834 1
# DOCUMENTATION.
a836 1
d839 1
a839 1
flexml - Generate validating XML processor from XML DTD.
d845 3
a847 4
[B<-s> I<skel>]
[B<-u> I<uri>]
[B<-a> I<actions>]
[B<-p> I<prefix>]
d850 1
d852 11
a862 1
=head1 DESCRIPTION
d864 1
a864 2
Assume that we have an XML (Extensibe Markup Language) document
C<my-joke.xml> containing
d866 1
a866 16
<!DOCTYPE joke SYSTEM "my.dtd">
<joke><line>My appartment is so small</line> <suspense/>
<line type='punch-line'>the mice are round-shouldered</line></joke>
which we wish to create an XML "processor" to validate it with respest
to the DTD (Document Type Definition) in the file C<my.dtd> containing
<!-- Small DTD for jokes (just for fun). -->
<!ELEMENT joke (line|pause)*>
<!ELEMENT line (#PCDATA)>
<!ATTLIST line type (normal|question|punch-line) 'normal'>
<!ELEMENT suspense EMPTY>
and that we furthermore wish to write an XML "application" for
displaying it in an amusing way. I<Flexml> can do this in the
following easy steps (see L</OPTIONS> for variations):
d870 1
a870 1
=item 1
d872 3
a874 1
We start by generating the XML processor from C<my.dtd> with the command
d876 1
a876 1
flexml my.dtd
d878 2
a879 3
This creates two program files: a I<scanner>, C<my.l>, and an I<API
header>, C<my.h>. (There are some restrictions on the facilities that
can be used in the DTD, detailed in L</BUGS>.)
d881 1
a881 1
=item 2
d883 2
a884 63
The program files are already in C except for the scanner for which we
must generate the C code with a I<flex>(1) command like
flex -Bspp -omy.c my.l
to create C<my.c> (the flags sets up I<flex> to create a "batch"
scanner with no default "fall-back" rules and with maximal warnings
about problematic constructions in the scanner source). If you prefer
C++ then you can use I<flex++> instead of I<flex>.
=item 3
Now we have an XML processor but we cannot run it without an XML
application. Fortunately I<flexml> has a built-in "dummy" application
which we can get out with
flexml -D my.dtd
into a file C<my-dummy.c>. We can now compile our first XML application:
gcc -Wall -ansi -pedantic -omy-dummy my-dummy.c my.c -lfl
which is able to anwer whether a document is validating or not:
./my-dummy <my-joke.xml
will succeed (silently) whereas
These three files constitute a complete validating XML processor
(which does not yet interact with an application, however). You
compile this XML processor with something like
gcc -Wall -ansi -pedantic my.c my-dummy.o -omy
to create the "my" executable (again you can use any ANSI C compiler
instead of I<gcc>(1) as long as the libraries it supports are
sufficiently close to the ANSI and POSIX standards). Actually the
above will only command if you
=item 4
You can now test your new XML validator filter on some XML files:
./my < my-test.xml
The C<./my> command should be silent (and succeed) when the document
is valid and protest otherwise (failing). (Again the present version
will, in fact, reject some valid documents and accept some invalid
ones: see the L</BUGS> section for the details.) The program will,
for example succeed with the input
=item 5
Now we are ready to start writing XML applications. You do this by
writing so-called I<action files> that contain a mixture of C and XML
to explain what you wish your application to do. This has the
advantage that it is easy to interface your program to just about
everything, and that it will run fast. (The disadvantage, of course,
is that you will be forced to program at the rather low level offered
by C and C++.) We will discuss this phase in detail after the L</OPTIONS>.
d886 1
a886 1
gcc -Wall -ansi -pedantic my-application.c my.o -omy-application
d888 1
a888 21
=item 6
Finally you compile and run you application. If the user has written
the action file C<my-test.act>, for example, then this is achieved
with the command
flexml -a my-application.xml my.dtd
which produces the XML application program C<my-application.c> which
you can compile and link with the command
gcc my-application.c my.o my-dummy.o -omy-application
=back
=head1 OPTIONS
=over 4
a894 20
=item B<-SHD>
These options make it explicit that only the scanner, header, and/or
(dummy) application files should be generated. If none of them are
given the default is B<-SH>.
=item B<-s> I<skel>
Use the skeleton scanner I<skel> instead of the default
F</usr/share/flexml/skel>.
=item B<-u> I<uri>
Sets the URI of the DTD, used in the C<DOCTYPE> header, to the
specified I<uri>.
=item B<-a> I<actions>
Uses the I<actions> file to produce an XML application in the file with the same name as I<aktions> after stripping the extension.
d897 1
a897 1
=head1 Writing XML applications
d899 2
a900 2
The format of the action files is rather simple; in fact it obeys the
following DTD:
d902 1
a902 2
<!-- DTD for FleXML "action" files. -->
<!ELEMENT actions (top|start|end)*>
d905 2
a906 2
<!ELEMENT start %C-code;> <!ATTLIST start tag NMTOKEN>
<!ELEMENT end %C-code;> <!ATTLIST end tag NMTOKEN>
d908 2
a909 1
(The "C<%C-code;>" parameter entity is just for readability.)
d911 5
a915 4
The idea is simple: the XML processor is a "filter" that receives your
XML data in a stream. For each start tag (or empty tag) in your DTD
that wish to act on upon receival, say E<lt>C<joke>...E<gt>, you must
write an "action".
d917 1
a917 1
<start tag = 'joke'><![CDATA[ ... ]]></start>
d919 1
a919 4
where the "C<...>" is the C code you wish to execute for this start
tag. While executing a "start action" you have access to the values
of all I<attributes> stored by that tag, but for efficiency their C
type depends on their declaration.
d921 10
a930 2
Let us illustrate this with an example: Assume we are given the
following DTD for jokes.
d932 1
a932 1
d934 5
d940 1
d942 1
d944 4
d949 1
d951 3
a953 105
=head1 DESCRIPTION
I<Flexml> takes an input DTD (Document Type Definition) describing the
format of XML (eXtensible Markup Language) documents, together with an
I<actions> file with the desired actions for some of the elements.
It produces a collection of four files on the output: the actual I<XML
processor> is a I<flex>(1) scanner stored in I<name>F<.l> (by
default), the I<XML application interface> is defined by the header
I<name>F<.h> and a full set of empty interface functions is written
onto I<name>F<-dummy.c>, and finally the actions file, if given with
B<-a>, is used to instantiate the actual I<XML application> in the
file I<name>F<-actions.c>.
The simplest way to get I<flexml> to do its job is to use I<make>(1).
Here are some default rules that fit the operation of I<flexml>.
The first pattern rule explicits how scanners, headers, and dummy
files are created from the DTD.
%.l %.h %-dummy.c: %.dtd
$(FLEXML) $<
Generating an application file requires an action specification so we
do it seperately.
%-actions.c: %.act
$(FLEXML) -Aa $< $*
Generating the C source of the scanner involves I<flex>(1).
%.c: %.l
$(FLEX) -o$@@ $<
Finally a hairy rule for constructing a library archive with each of
the dummy functions as a separate entity: this ensures that we can
always link with this library to complete an incomplete set of
actions. The important part is the last line where all the individual
dummy files are assembled into a library archive.
%-dummy.a: %-dummy.c
$(RM) $*-dummy-*.c
(cat $< | while read line; do \
f=`expr "$$line" : '[a-z][a-z]* \([A-Za-z_]*\)(.*'`; \
if [ -n "$$f" ]; then \
echo $$line > $*-dummy-$$f.c &&\
$(CC) -c $*-dummy-$$f.c; \
fi; done)
ar r $*-dummy.a $*-dummy-*.o
With this setup the following dependencies ensure that the XML
application I<joke> can be built. First the four generated files:
joke.l joke.h joke-dummy.c: joke.dtd
joke-actions.c: joke.act joke.dtd
Then the further processing of the files (which is standard apart from
the creative library archive above).
joke.c: joke.l
joke.o: joke.c joke.h
joke-dummy.a: joke-dummy.c joke.h
joke-actions.o: joke-actions.c joke.h
joke: joke.o joke-actions.o joke-dummy.a
The compilers etc. were instantiated as follows
CC = gcc -Wall -ansi -pedantic
FLEX = flex -Bsp
FLEXML = flexml
=head1 THE ACTIONS FILE
The actions file must be a valid XML document conforming to the DTD in
F</usr/doc/flexml/flexml-act.dtd>. This is a very simple DTD that
just contains the following:
The individual text "actions" should contain C (or C++) source code:
the code in the C<top> element will be inserted directly in the source
file of the application, that of a C<start> becomes the action to
invoke for each start E<lt>I<tag>E<gt>, and similarly for the end
E<lt>C</>I<tag>E<gt>. (Empty tags are treated identically to tags
with empty contents). However, some special notations are available:
d957 1
a957 1
=item C<{>I<attribute>C<}>
d959 3
a961 2
Can be used in a C<start> element action to denotes the value of the
I<attribute> as set with I<attribute>C<=>I<value> in the E<lt>I<tag>.
d963 1
a963 1
If the attribute is declared as an enumerated type like
d965 1
a965 1
<!ATTLIST attrib (alt | alt |...)*>
d967 1
a967 3
then the possible values are written
C<{>I<attribute>C</>I<alt>C<}>,
C<{>I<attribute>C</>I<alt>C<}> I<etc.>
d969 3
a971 1
Otherwise it is a null-terminated C string.
d973 2
a974 9
=item C<pcdata>
Can be used in the C<end> element action to denote the text of the
element when it had "Mixed" contents (if the element had "element"
contents then C<pcdata> is C<NULL>). In case the Mixed contents
element actually mixed text and child elements then C<pcdata> contains
the plain concatenation of the text fragments.
=back
d978 1
a978 1
I<Flexml> is by design restricted to validate XML documents with a
d981 1
a981 1
<!DOCTYPE root SYSTEM "uri/name.dtd">
d990 6
d1013 3
a1015 1
Only internal entities are handled.
d1019 3
a1021 15
In addition to this there are several minor restrictions on the form
of DTDs. This is not so serious, however, as this will be known
before using the generated XML processor and applications.
Uptil now I have mostly experimented with generating C scanners but
I<flex> can also generate C++ scanners and this should not change much
in the working of I<flexml>..
But please consider I<flexml> as "late alpha" software.
=head1 SEE ALSO
Extensible Markup Language (XML) 1.0 (W3C Recommendation
REC-xml-1998-0210) C<http://www.w3.org/TR/REC-xml>, I<make>(1),
I<flex>(1).
d1027 1
a1027 1
=item /usr/share/flexml/skel
d1031 1
a1031 1
=item /usr/share/flexmlskeleton-dummy.c
d1033 1
a1033 1
The skeleton of the dummy handle file.
d1037 5
d1044 2
a1045 2
I<Flexml> Was Written By Kristoffer Hgsbro Rose. I am grateful to
NTSys.fr for support of this work.
d1049 12
a1060 3
The program is distributed under GNU GPL ("copyleft").
=cut
@
1.8
log
@Ready for release of Debian version 0.0.
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.7 1999/11/23 10:10:36 krisrose Exp krisrose $ ';
d59 3
d122 2
a123 2
print $pre . "void STag_$ctag{$tag}(void)$post\n";
print $pre . "void ETag_$ctag{$tag}(void)$post\n";
d191 2
a192 2
$Use = "Usage: flexml [-dSHDA] [-s skel] [-u uri] [-a actions] [-p prefix] name[.dtd]";
use Getopt::Std; getopts('dSHDAs:u:a:p:');
d204 5
a208 2
# Change prefix for output files (if requested).
$prefix = $opt_p if $opt_p;
d213 1
a213 1
# Set skeleton scanner file name and check it is readable.
d215 1
a215 1
die "$0: No skeleton file $SKELETON.\n" if not -r $SKELETON;
d217 4
a220 2
# Set actions file name.
$ACTIONS = $opt_a if $opt_a;
d222 5
a226 9
# if neither of -S, -H, or -D given then pick defaults.
if ($opt_S or $opt_H or $opt_D or $opt_A) {
$opt_A = true if $opt_a;
}
else {
$opt_S = true;
$opt_H = true;
$opt_D = true;
$opt_A = $opt_a;
a228 6
# Set output file names.
$SCANNER = "$prefix.l";
$HEADER = "$prefix.h";
$DUMMIES = "$prefix-dummies.c";
$CALLBACKS = "$prefix-actions.c";
d236 1
d488 1
a488 33
# CREATE PROCESSOR DUMMY ACTIONS (if requested).
if ($opt_D) {
open DUMMIES, "+>$DUMMIES";
select DUMMIES;
# Identification and license.
print "/* XML processor dummy actions for $DTD";
print ",\n * ($DTDrevision)" if $DTDrevision;
print ".\n * Generated " . `date +'%Y/%m/%d %T.'`;
print " *\n";
redistribute(" *");
print " */\n";
print "\n";
# Declarations.
print "#include \"$HEADER\"\n";
print "\n";
# Dummy declaration of each function.
api_functions('',' {}');
# Output a dummy main program [sic].
print "\n";
print "/* Default main program. */\n";
print "int main() { return yylex(); }\n";
close DUMMIES;
}
# CREATE PROCESSOR HEADER (if requested).
d496 1
a496 1
print "/* XML processor header for $DTD";
d521 2
a522 1
# WRITE XML PROCESSOR.
d535 1
a535 1
print "/* XML processor for $DTD";
d770 1
d772 1
a772 1
# ACTIONS
a773 1
if ($opt_A) {
d775 4
a778 2
open CALLBACKS, "+>$CALLBACKS";
select CALLBACKS;
d781 3
a783 4
print "/* XML processor actions from $ACTIONS.\n";
print " * Fits with $DTD";
print ", ($DTDrevision)" if $DTDrevision;
print ".\n * Generated " . `date +'%Y/%m/%d %T.'`;
d793 4
a796 2
# Get data from actions file.
open ACTIONS, "/usr/lib/flexml-act $ACTIONS|";
d798 2
a799 2
my ($tag,$attribute);
my @@myattributes;
d801 1
a801 1
while (<ACTIONS>) {
d803 12
a814 8
if ( m/^void STag_($Name)\(void\)$/ ) {
$tag = $1;
@@myattributes = split /,/,"$withattr{$tag}";
}
elsif ( m|^\} \/\* STag_($Name) \*\/$| ) {
$tag = undef;
@@myattributes = ();
}
d816 3
a818 3
s/\{($Name)\}/A_$ctag{$tag}_$catt{$1}/xg if $tag;
s/\{($Name)\/($Name)\}/ "A_$ctag{$tag}_$catt{$1}_" . variablify($2); /xge if $tag;
s/([SE])Tag_($Name)/\1Tag_$ctag{$2}/xg;
d820 1
a820 1
print $_;
d822 2
d826 4
a829 2
close ACTIONS;
close CALLBACKS;
d832 1
d835 1
a836 1
=pod
d845 1
a845 1
[B<-dSHDA>]
d852 1
d855 116
a970 3
I<Flexml> takes an input DTD (Document Type Definition) describing the
format of XML (eXtensible Markup Language) documents, together with an
I<actions> file with the desired actions for some of the elements.
a971 7
It produces a collection of four files on the output: the actual I<XML
processor> is a I<flex(1)> scanner stored in I<name>F<.l> (by
default), the I<XML application interface> is defined by the header
I<name>F<.h> and a full set of empty interface functions is written
onto I<name>F<-dummies.c>, and finally the actions file, if given with
B<-a>, is used to instantiate the actual I<XML application> in the
file I<name>F<-actions.c>.
d982 1
a982 1
=item B<-SHDA>
d984 3
a986 2
These options make it explicit that only the scanner, header, dummies,
and/or application files should be generated (the default is B<-SHD>).
d1000 64
a1063 2
Uses the I<actions> file to produce an XML application (implies the
B<-A> option). See the section I<The Actions File> below.
a1064 1
=item B<-p> I<prefix>
a1065 3
Use the I<prefix> instead of I<name> for all produced output files
(useful in conjunction with B<-a> because one can then reuse the
scanner, header, and dummies, because they only depend on the DTD).
a1066 1
=back
a1067 1
=head1 OPERATION
d1069 1
a1069 1
The simplest way to get I<flexml> to do its job is to use I<make(1)>.
d1075 1
a1075 1
%.l %.h %-dummies.c: %.dtd
d1084 1
a1084 1
Generating the C source of the scanner involves I<flex(1)>.
d1095 2
a1096 2
%-dummies.a: %-dummies.c
$(RM) -f $*-dummies-*.c
d1100 2
a1101 2
echo $$line > $*-dummies-$$f.c &&\
$(CC) -c $*-dummies-$$f.c; \
d1103 1
a1103 1
ar r $*-dummies.a $*-dummies-*.o
d1108 1
a1108 1
joke.l joke.h joke-dummies.c: joke.dtd
d1117 1
a1117 1
joke-dummies.a: joke-dummies.c joke.h
d1121 1
a1121 1
joke: joke.o joke-actions.o joke-dummies.a
a1134 1
<!ELEMENT actions (top|start|end)*>
a1135 1
<!ELEMENT top (#PCDATA)>
a1136 2
<!ELEMENT start (#PCDATA)>
<!ATTLIST start tag NMTOKEN>
a1137 2
<!ELEMENT end (#PCDATA)>
<!ATTLIST end tag NMTOKEN>
d1221 2
a1222 2
REC-xml-1998-0210) C<http://www.w3.org/TR/REC-xml>, I<make(1)>,
I<flex(1)>.
d1232 1
a1232 1
=item /usr/share/flexmlskeleton-dummies.c
d1234 1
a1234 1
The skeleton of the dummies handle file.
d1240 1
a1240 1
I<FlexML> was written by Kristoffer Hgsbro Rose. I am grateful to
@
1.7
log
@Spellling mistakes fixed...
@
text
@d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.6 1999/11/23 09:32:31 krisrose Exp krisrose $ ';
d208 1
a208 1
$SKELETON = ($opt_s ? $opt_s : "/usr/share/flexml.skel");
d903 1
a903 1
F</usr/share/flexml.skel>.
d1090 1
a1090 1
=item /usr/share/flexml.skel
@
1.6
log
@Documentation updated.
@
text
@d6 1
a6 1
# This file is part of the FleXML XML processer generator system.
d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.5 1999/11/23 04:03:05 krisrose Exp krisrose $ ';
d96 1
a96 1
$pre This program was generated with the FleXML XML processer generator,
a1032 4
=item C<cookie(>I<>C<)>
A child can be
d1057 5
d1073 6
@
1.5
log
@Works for simple examples
@
text
@a6 1
# See the companion README and INSTALL files for further information.
d23 1
a23 1
$Id = '$Id: flexml.pl,v 1.4 1999/11/23 02:37:11 krisrose Exp krisrose $ ';
d226 4
a229 4
$SCANNER = "$prefix.l" if $opt_S;
$HEADER = "$prefix.h" if $opt_H;
$DUMMIES = "$prefix-dummies.c" if $opt_D;
$CALLBACKS = "$prefix-actions.c" if $opt_A;
d492 1
a492 1
if ($DUMMIES) {
d524 1
a524 1
if ($HEADER) {
d556 1
a556 1
if ($SCANNER and $SKELETON) {
d805 1
a805 1
if ($CALLBACKS) {
d825 1
a825 1
open ACTIONS, "/usr/lib/flexml-act <$ACTIONS|";
d832 1
a832 1
if ( m/^void STag_($Name)\(void\)$/xo ) {
d834 1
a834 1
@@myattributes = split /,/,"$attlist{$tag}";
d836 1
a836 1
elsif ( m/^void STag_($Name)\(void\)$/xo ) {
d841 6
a846 3
s/\$([A-Za-z][A-Za-z0-9_]*)/A_$ctag{$tag}_$catt{$1}/xg;
s/\$\{([A-Za-z][A-Za-z0-9_]*)\}/A_$ctag{$tag}_$catt{$1}/xg;
print;
d856 2
d865 1
a865 1
[B<-dSHD>]
d870 1
a870 1
I<name>[C<.dtd>]
d875 12
a886 4
format of XML (eXtensible Markup Language) documents; this is assumed
to be in the file I<name>C<.dtd>. The output is the L<flex(1)> source
file I<name>C<.l> that implements an I<XML processor> which will call
the following functions (that must be provided by the user):
d890 19
a908 1
=item C<void STag_>I<tag>C<(void)>
d910 1
a910 2
Called when the start-tag E<lt>I<tag>...E<gt> has been recognised.
The attributes are available
d912 2
a913 1
=item C<void ETag_>I<tag>C<(void)>
d915 5
a919 3
Called when the E<lt>C</>I<tag>E<gt> end-tag has been read. If the
tag is of Mixed contents type then C<pcdata> string contains the
contents of all text in the element (otherwise C<pcdata> is C<NULL>).
d923 46
a968 2
You must generate the C-code od the XML processor with L<flex(1)> as
well as link with appropriate actions.
d970 2
d973 1
d975 32
a1006 1
=head1 OPTIONS
d1010 6
a1015 1
=item [B<-d>]
d1017 1
a1017 3
Generate a C source file I<name>C<-dummies.c> with dummy handlers for
all call-backs (that merely print the handled tag or attribute to
I<stdout>).
d1019 3
a1021 1
=item [B<-S> I<skel>C<.l>]
d1023 1
a1023 1
Use the skeleton scanner I<skel>C<.l> instead of the default.
d1025 1
a1025 1
=item [B<-o> I<name>C<.l>]
d1027 9
a1035 2
Write the generated scanner to I<name>C<.l> instead of to the name
obtained by replacing C<.dtd> with C<.l> in the DTD file name.
d1041 11
a1051 1
I<Flexml> only accepts DTDs with lines of the forms
d1053 1
a1053 4
<!ELEMENT tag EMPTY>
<!ELEMENT tag (#PCDATA)>
<!ELEMENT tag (tag1|tag2|...|tagn)*>
<!ATTLIST tag attribute CDATA>
d1055 1
a1055 2
plus internal entity declarations (and comments, of course) of the
forms
d1057 11
a1067 1
<!ENTITY % name "string">
d1069 9
a1077 3
In fact it I<ignores> any lines not in this form (a rather serious
limitation). A tag may be split over several lines but I<flexml> does
not handle several elements on a line.
d1083 1
a1083 1
=item /usr/lib/flexml/skeleton.l
d1087 1
a1087 1
=item /usr/lib/flexml/skeleton-dummies.c
d1095 2
a1096 1
Kristoffer Hgsbro Rose sponsored by NTSys.fr.
@
1.4
log
@Works except for seq element contents and the action generation.
@
text
@d24 1
a24 1
$Id = '$Id: flexml.pl,v 1.3 1999/11/22 18:41:48 krisrose Exp krisrose $ ';
d189 2
a190 2
$Use = "Usage: flexml [-dSHD] [-s skel] [-u uri] [-a actions] [-p prefix] name[.dtd]";
use Getopt::Std; getopts('dSHs:u:a:p:');
d216 2
a217 2
if ($opt_S or $opt_H or $opt_D) {
die "$0: -a conflicts with -H.\n" if $opt_a and $opt_H;
d221 1
a221 1
$opt_H = true unless $opt_a;
d223 1
d230 1
a230 1
$CALLBACKS = "$prefix-actions.c" if $opt_a;
d361 1
a361 1
s/$Nmtoken/ "AA_$ctag{$tag}_$catt{$attribute}_" . variablify($&) /xge;
d367 1
a367 1
$initof{"$tag/$attribute"} = "AA_$ctag{$tag}_$catt{$attribute}_" . variablify($default);
d585 3
a587 1
. " \"\$\" \"$DTDrevision\$\";\n" if $DTDrevision;
d611 16
d691 1
a691 1
. " = AA_${myctag}_$catt{$attribute}_" . variablify($alternative) . ";\n";
d695 1
a695 1
. " = AA_${myctag}_$catt{$attribute}_" . variablify($alternative) . ";\n";
d765 2
d826 1
a826 1
open ACTIONS, "$FLEXMLACT $ACTIONS|";
d828 18
a848 2
@
1.3
log
@Working like mad...
@
text
@d24 2
a25 2
$Id = '$Id: flexml.pl,v 1.2 1999/11/08 03:21:12 krisrose Exp krisrose $ ';
$Id =~ s/\$//go;
d32 1
a32 2
%source = (); # DTD source lines associated to tag and tag/attribute
# pairs.
d42 1
d51 2
a52 1
%enumtype = (); # whether the tag/attribute is an enumeration
a66 1
%entitysource = (); # - source
a68 1
%parametersource = (); # - source
d75 7
a81 4
sub indent { # Indent all lines of the argument by four spaces.
local ($_) = @@_;
s/^/ * /mg;
" /* " . $_ . " */\n";
d104 1
a104 1
$pre 1. The program is distributed WITHOUT ANY WARRANTY from the author(s) of
d116 1
a116 1
local ($pre) = @@_;
d120 2
a121 2
print $pre . "void STag_$ctag{$tag}(void);\n";
print $pre . "void ETag_$ctag{$tag}(void);\n";
a122 1
print $pre . "void partial_pcdata(void);\n";
d163 1
a163 1
if ( s/^\'[^']*\'|^\"[^"]\"|^%\s+|^[^%"']//o ) {
d173 1
a173 1
die "Messy line: \`$line$_\'.\n";
d180 1
a180 1
$_;
d189 1
a189 1
$Use = "Usage: flexml [-dSH] [-s skel] [-u uri] [-a actions] [-p prefix] name[.dtd]";
a213 1
die "$0: -a implies -S and conflicts with -H.\n" if $opt_a and $opt_H;
d215 15
a229 3
# Set output scanner and header file names.
$SCANNER = "$prefix.l" if not $opt_H or $opt_a;
$HEADER = "$prefix.h" if not $opt_S and not $opt_a;
d290 3
d295 1
a295 3
}
if ($1) {
$mixed{$tag} = true;
d315 1
a315 1
if ($source{"$tag/$attribute"}) {
d319 4
a322 1
$source{"$tag/$attribute"} = "$orig";
a337 1
$attdef{"$tag/$attribute"} = $default if $default;
d342 6
a347 2
elsif ($default =~ s/\#FIXED\s+//) {
$fixed{"$tag/$attribute"} = true;
a348 1
$default =~ s/^'([^'']*)'$/\1/o unless $default =~ s/^"([^""]*)"$//;
d350 2
a351 1
# Store attribute type.
d353 8
a360 3
if (substr("$type",0,1) eq "(") {
local $_ = $type;
$enumtype{"$tag/$attribute"} = true;
d362 3
a364 6
s/\s*\|\s*/, /go;
s/$Nmtoken/ "AA_$ctag{$tag}_$catt{$attribute}_" . variablify($&) /xge;
s/^\(\s*/enum \{ $undefined, /o;
s/\s*\)$/ \}/o;
$type = $_;
$typeof{"$tag/$attribute"} = "$type";
d372 1
d381 24
d419 1
a419 1
$parametersource{"%$1;"} = "$orig";
d425 1
a425 1
$entitysource{"&$1;"} = "$orig";
d468 1
d473 2
d485 18
a502 1
print '%entitysource = (' . printhash(entitysource) . ")\n";
d504 14
a517 2
print '%parameter = (' . printhash(parameter) . ")\n";
print '%parametersource = (' . printhash(parametersource) . ")\n";
d540 1
a540 1
api_functions("extern ");
d542 4
a545 1
api_data("extern ");
d554 1
a554 1
# WRITE XML PROCESSOR BASED ON SCANNER AND MAYBE ACTIONS.
a568 1
print ";\n * with application actions from $ACTIONS" if $ACTIONS;
d581 1
a581 1
. " \"\$\" \"$Id\$\";\n";
d589 10
a598 6
if ($HEADER) {
print "/* XML processor interface. */\n";
print "#include \"$HEADER\"\n";
print "\n";
}
api_data("");
d604 2
a605 1
print "%x ROOT_$tag AL_$tag IN_$tag\n";
d616 1
a616 1
. '){S}?">"' . " BEGIN(ROOT_$tag);\n";
d623 2
a624 5
if (keys %parametersource) {
print "\n";
foreach $ent (keys %parametersource) {
print indent($parametersource{$ent});
}
d630 1
d634 5
a638 3
# Tag's source element.
print "\n";
print indent($source{$tag});
d642 3
a644 4
print "<ROOT_$tag";
foreach $intag (split /,/,"$intags{$tag}") { print ",IN_$intag"; }
print ">\"<$tag\"{S}? {\n";
print " BUFFERINIT;\n";
d646 1
a646 3
if ($atttype{"$tag/$attribute"} eq "CDATA") {
print " A_$ctag{$tag}_$catt{attribute} = " . $initof{"$tag/$attribute"} . ";\n";
}
d648 1
a648 10
print " ENTER(AL_$tag);\n";
print "}\n";
# Errors when expecting root tag.
print "\n";
print "<ROOT_$tag>{\n";
print " \"<!--\" ENTER(COMMENT);\n";
print " {S} SKIP;\n";
print " . FAIL(\"$tag root element.\");\n";
print " <<EOF>> FAIL(\"EOF in prolog.\");\n";
d653 1
a653 1
print "<AL_$tag>{\n";
d656 29
a684 4
print "\n";
print indent($source{"$tag/$attribute"});
if ($enumtype{"$tag/$attribute"}) {
print " /* ENUM TYPEM TO BE DEFINED */\n";
d687 12
a698 2
print " \"$attribute\"{Eq}\\' ENTER(VALUE1); BUFFERSET(A_$ctag{$tag}_$catt{$attribute});\n";
print " \"$attribute\"{Eq}\\\" ENTER(VALUE2); BUFFERSET(A_$ctag{$tag}_$catt{$attribute});\n";
d704 4
a707 8
print " \">\" LEAVE(AL_$tag); STag_$tag(); BUFFERINIT;";
if ($mixed{$tag}) {
print " BUFFERSET(pcdata);";
}
else {
print " pcdata = NULL;"
}
print " ENTER(IN_$tag);\n";
d710 4
a713 8
print " \"/>\" LEAVE(AL_$tag); STag_$tag(); BUFFERINIT;";
if ($mixed{$tag}) {
print " pcdata = \"\";";
}
else {
print " pcdata = NULL;"
}
print " ETag_$tag(); CHECKEPILOG($tag);\n";
d721 8
d736 1
d738 7
a744 4
print "<IN_$tag>{\n";
print " \"</$tag\"{S}?\">\" LEAVE(IN_$tag);"
. ($mixed{$tag} ? " BUFFERDONE;" : "")
. " ETag_$tag(); CHECKEPILOG($tag);\n";
d755 1
a755 1
print "$`IN_" . join(',IN_', keys %mixed) . "$1$'";
d758 1
a758 1
print "$`DISABLE$comma$'";
d766 1
a766 2
print "\n";
print indent($entitysource{$ent});
d779 7
d787 12
a798 2
# Add actions if requested.
if ($ACTIONS) {
d800 10
a809 5
open ACTIONS;
while (<ACTIONS>) {
print if /<actions>/;
}
close ACTIONS;
a810 1
}
a811 1
close SCANNER;
a813 1
a816 1
d819 1
a819 1
flexml - Generate flex(1) scanner from XML DTD.
d824 4
a827 1
[B<-s> I<skeleton-scanner>]
a828 1
[B<-o> I<name>C<.l>]
d834 4
a837 4
format of XML (eXtensible Markup Language) documents; this is assumed to
be in the file I<name>C<.dtd>. The output is the L<flex(1)> source file
I<name>C<.l> where you have to provide the definitions of the
following call-back "handlers":
d841 1
a841 1
=item C<STag_>I<tag>C<(void)>
d843 2
a844 2
Called when the start-tag E<lt>I<tag>...E<gt> has been recognised but
before any attributes or contents have been read.
d846 1
a846 1
=item C<A_>I<tag>C<_>I<attribute>C<(char* value)>
d848 3
a850 2
Called for each I<attribute>C<=">I<value>C<"> attribute definition in
the I<tag>.
d852 4
a855 1
=item C<ETag_>I<tag>C<(char* pcdata)>
a856 4
Called when the E<lt>C</>I<tag>E<gt> end-tag has been read. If the
tag is of type C<(#PCDATA)> then the C<pcdata> parameter is bound to
the contents as a string (with entities decoded), otherwise the
parameter is C<NULL>.
a857 1
=back
@
1.2
log
@ZzZzZzZ.
@
text
@d3 2
a4 2
# FleXML: fast lexical XML scanning.
# Copyright 1999 Kristoffer H. Rose. All rights reserved.
d6 3
a8 4
# Description: Translate DTD to flex(1) scanner
# Author: Kristoffer Rose
# Created: September 1999
# License: GNU GPL ("copyleft")
d10 4
a13 4
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
d15 4
a18 4
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
d20 3
a22 12
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Header = '$Header: /plume/yquem/home/krisrose/cons/FleXML/RCS/flexml.pl,v 1.1 1999/10/26 16:19:45 krisrose Exp krisrose $'; #'sic
$Header =~ s/^\$//;
# Options processing.
$Usage = "Usage: flexml [-d] [-S skel.l] [-P prefix] name[.dtd]";
use Getopt::Std; getopts('dS:P:');
if ($#ARGV != 0) { die $Usage; }
d24 2
a25 4
$prefix = $ARGV[0];
$prefix =~ s/\.dtd$//;
$DTD = "$prefix.dtd";
die "$0: No DTD file $DTD.\n" if not -r $DTD;
a26 1
$prefix = $opt_P if $opt_P;
d28 2
a29 2
$SKELETON = ($opt_S ? $opt_S : "/usr/lib/flexml/skeleton.l");
die "$0: No skeleton file $SKELETON.\n" if not -r $SKELETON;
a30 7
$SKELETON_H = $SKELETON;
$SKELETON_H =~ s/\.l$/.h/;
die "$0: No skeleton file $SKELETON_H.\n" if not -r $SKELETON_H;
$SCANNER = "$prefix.l";
$HEADER = "$prefix.h";
$DUMMIES = ($opt_d ? "$prefix-dummies.c" : "");
d32 2
a33 1
# Initialise structures.
d36 28
a63 5
%source = (); # DTD source lines associated to tag and tag/attribute pairs.
%mixed = (); # $mixed{tag} == true if the tag is a mixed tag.
%attlist = (); # $attlist{tag} is comma-separated list of attribute names.
%parsed = (); # parsed entity table
%parsedsource = (); # parsed entity source lines
d65 2
a66 1
# Open DTD and extract information.
d68 22
a89 1
open DTD;
a90 1
while (<DTD>) {
d92 19
a110 1
chomp;
a111 3
# Erase up till <! and append up till >.
next unless s/^([^<]|<[^!])*<!/<!/;
local $orig = $_;
d113 7
a119 4
while (not eof DTD and not m/^<![^>]*>/) {
local $line = <DTD>; chomp $line;
$_ .= " " . $line;
$orig .= "\n" . $line;
d121 3
d125 7
a131 9
# Expand all parsed entities until none left (beware of cycles :)
local @@entities = keys %parsed;
local $count = $#entities + 1;
while ($count > 0) {
local $test = 0;
foreach $ent (@@entities) {
$test = $count if s/$ent/$parsed{$ent}/g;
}
$count = $test - 1;
d133 5
d139 6
a144 29
# Parse the understood element types.
if ( /<!ELEMENT\s+([a-zA-Z:_.-]+)\s+(EMPTY|\(\s*\#PCDATA\s*\))\s*>/ ) {
die "Repeated element $1.\n" if $source{$1};
push @@tags, $1;
$mixed{$1} = true;
$source{$1} = "/* $orig */\n";
}
elsif ( /<!ELEMENT\s+([a-zA-Z:_.-]+)\s+[a-zA-Z:_.-|(),* ]+\s*>/ ) {
die "Repeated element $1.\n" if $source{$1};
push @@tags, $1;
$source{$1} = "/* $orig */\n";
}
elsif ( /<!ELEMENT\s+[^>]*>/ ) {
die "$0: unsupported $orig";
}
elsif ( /<!ATTLIST\s+([a-zA-Z:_.-]+)\s+([a-zA-Z:_.-]+)\s+CDATA(\s+\#[A-Z]+)?\s*>/ ) {
$attlist{$1} .= ($attlist{$1} ? "," : "") . "$2";
$source{"$1/$2"} = "/* $orig */\n";
}
elsif ( /<!ATTLIST\s+[^>]*>/ ) {
die "$0: unsupported $orig";
}
elsif ( /<!ENTITY\s+%\s+([a-zA-Z:_.-]+)\s+"([^>]*)"\s*>/ ) {
$parsed{"%$1;"} = "$2";
$parsedsource{"%$1;"} = "/* $orig */\n";
}
elsif ( /<!ENTITY\s+([a-zA-Z:_.-]+)\s+"([^>]*)"\s*>/ ) {
$parsed{"&$1;"} = "$2";
$parsedsource{"&$1;"} = "/* $orig */\n";
a145 5
elsif ( /[\$]Header: [^\$]*\$/ ) {
$DTDrevision = "$&";
$DTDrevision =~ s/^\$//;
}
a147 1
close DTD;
d149 1
a149 1
# Indenting
a150 1
sub indent {
d152 27
a178 1
s/^/ /mg;
a181 1
# Copy skeleton scanner header to output scanner with substitutions.
d183 58
a240 1
if ($HEADER) {
d242 14
a255 3
open SKELETON_H;
open HEADER, "+>$HEADER";
select HEADER;
d257 6
a262 1
while (<SKELETON_H>) {
d264 2
a265 1
if ( /^FLEXML_IFDEF$/ ) {
d267 1
a267 1
print "#ifdef _FLEXML_${prefix}_H\n"
d269 18
d288 1
a288 1
elsif ( /^FLEXML_TOPMATTER$/ ) {
d290 2
a291 5
print " * This file instantiated for FleXML scanner for $DTD.\n"
. " * Generated " . localtime() . ".\n";
}
elsif ( /^FLEXML_VERSION$/ ) {
d293 2
a294 2
print "static char* rcs_flexml = \"\$\"\n"
. "\"$Header\";\n";
d296 3
a298 3
print "\n"
. "static char* rcs_${prefix}_dtd = \"\$\"\n"
. "\"$DTDrevision\";\n" if $DTDrevision;
d300 1
a300 2
}
elsif ( /^FLEXML_API$/ ) {
d302 2
a303 9
print "\n";
print "/* User-defined functions. */\n";
foreach $tag (@@tags) {
print "#ifndef STag_$tag\n";
print "extern void STag_$tag(void);\n";
print "#endif\n";
print "#ifndef ETag_$tag\n";
print "extern void ETag_$tag(void);\n";
print "#endif\n";
d305 2
d308 51
a358 6
print "\n";
print "/* FleXML-provided data. */\n";
print "extern char* pcdata;\n";
foreach $tag (@@tags) {
foreach $attribute (split ",","$attlist{$tag}") {
print "extern char* Attribute_${attribute};\n";
d360 5
d366 15
d382 11
a392 5
}
else {
s/^"\$Header/"\$" "Header/;
print;
}
d394 3
d398 69
a467 1
close SKELETON_H;
a470 1
# Copy skeleton scanner to output with substitutions.
d472 4
a475 1
if ($SCANNER) {
a476 1
open SKELETON;
d480 4
a483 1
while (<SKELETON>) {
d485 9
a493 1
if ( /^FLEXML_TOPMATTER$/ ) {
d495 2
a496 2
print " * This file instantiated as FleXML scanner for $DTD.\n"
. " * Generated " . localtime() . ".\n";
d498 1
a498 2
}
elsif ( /^FLEXML_VERSION$/ ) {
d500 2
a501 2
print "static char* rcs_flexml = \"\$\"\n"
. "\"$Header\";\n";
d503 2
a504 3
print "\n"
. "static char* rcs_${prefix}_dtd = \"\$\"\n"
. "\"$DTDrevision\";\n" if $DTDrevision;
d509 4
a512 10
print "/* User-defined functions. */\n";
print "#include \"$HEADER\"\n";
print "\n";
print "/* FleXML-provided data. */\n";
print "char* pcdata;\n";
foreach $tag (@@tags) {
foreach $attribute (split ",","$attlist{$tag}") {
print "char* Attribute_${attribute};\n";
}
d514 1
d520 1
a520 4
print "%x AL_$tag\n";
print "%s IN_$tag\n" if not $mixed{$tag} ;
d524 1
a524 1
elsif ( /^FLEXML_DOCTYPE$/ ) {
d526 7
a532 5
print ' "<!DOCTYPE"{S}{Name}{S}"SYSTEM"{S}\"'
. $DTD
. '\"{S}">" |' . "\n";
# Todo: {Name} must be root element.
d537 2
a538 2
# Dump all parsed entity declarations.
if (keys %parsedsource) {
d540 2
a541 2
foreach $ent (keys %parsedsource) {
print indent($parsedsource{$ent});
d545 1
d548 2
a549 1
local @@tagatts = split ",","$attlist{$tag}";
d555 1
a555 1
# Start tag begins with <tag.
d557 8
a564 3
print "\"<$tag\"{s} {\n";
foreach $attribute (@@tagatts) {
print " Attribute_${attribute} = NULL;\n";
a565 1
print " BUFFERINIT;\n";
d569 14
a582 2
# Save each encountered permitted attribute.
foreach $attribute (@@tagatts) {
d585 7
a592 8
print "<AL_$tag>\"$attribute\"{Eq}\\' {\n";
print " ENTER(VALUE1);\n";
print " BUFFERSET(Attribute_$attribute);\n";
print "}\n";
print "<AL_$tag>\"$attribute\"{Eq}\\\" {\n";
print " ENTER(VALUE2);\n";
print " BUFFERSET(Attribute_$attribute);\n";
print "}\n";
d594 3
a596 9
# Start tag is done so call start tag action and pass into
# PCDATA state for mixed contents or the appropriate element
# state for element contents.
print "\n";
print "<AL_$tag>\">\" {\n";
print " LEAVE(AL_$tag);\n";
print " STag_$tag();\n";
print " BUFFERINIT;\n";
d598 1
a598 2
print " BUFFERSET(pcdata);\n";
print " ENTER(PCDATA);\n";
d601 1
a601 2
print " pcdata = NULL;\n";
print " ENTER(IN_$tag);\n";
d603 4
a606 4
print "}\n";
# End tag encountered.
print "\n";
d608 1
a608 2
print "<PCDATA>\"</$tag\"{s}\">\" {\n";
print " LEAVE(PCDATA);\n";
d611 1
a611 2
print "<IN_$tag>\"</$tag\"{s}\">\" {\n";
print " LEAVE(IN_$tag);\n";
d613 6
a618 1
print " ETag_$tag();\n";
d621 7
a627 1
# Special case for EMPTY tags.
d629 7
a635 5
print "<AL_$tag>\"/>\" {\n";
print " LEAVE(AL_$tag);\n";
print " STag_$tag();\n";
print " pcdata = NULL;\n";
print " ETag_$tag();\n";
d637 14
d652 5
d661 1
a661 1
s/^"\$Header/"\$" "Header/;
a667 10
close SCANNER;
}
# Copy skeleton dummy handlers to dummy output if requested.
if ($DUMMIES) {
local $DUMMYSKELETON = $SKELETON;
$DUMMYSKELETON =~ s/\.l$/-dummies.c/;
d669 2
a670 10
open DUMMYSKELETON;
open DUMMIES, "+>$DUMMIES";
select DUMMIES;
while (<DUMMYSKELETON>) {
if ( /^FLEXML_TOPMATTER$/ ) {
print " * Note: this file instantiated with dummies for $DTD.\n"
. " * Generated " . localtime() . ".\n";
d672 3
d676 1
a676 1
elsif ( /^FLEXML_VERSION$/ ) {
d678 1
a678 2
print "static char* rcs_flexml = \"\$\"\n"
. "\"$Header\";\n";
d680 2
a681 3
print "\n"
. "static char* rcs_${prefix}_dtd = \"\$\"\n"
. "\"$DTDrevision\";\n" if $DTDrevision;
a682 22
}
elsif ( /^FLEXML_API$/ ) {
print "/* User-defined functions. */\n";
print "#include \"$HEADER\"\n";
}
elsif ( /^FLEXML_DUMMIES$/ ) {
if (keys %parsedsource) {
foreach $ent (keys %parsedsource) {
print $parsedsource{$ent};
}
print "\n";
}
foreach $tag (@@tags) {
print "\n";
print "$source{$tag}";
foreach $attribute (split ",","$attlist{$tag}") {
print $source{"$tag/$attribute"};
}
d684 2
a685 23
print "\n"
. "void STag_$tag(void)\n"
. "{\n"
. " FLEXML_DUMMY_STag(\"$tag\");\n";
foreach $attribute (split ",","$attlist{$tag}") {
print " FLEXML_DUMMY_Attribute(${attribute});\n";
}
print "}\n";
print "\n";
print "void ETag_$tag(void)\n"
. "{\n"
. " FLEXML_DUMMY_ETag(\"$tag\",pcdata);\n"
. "}\n";
}
}
else {
s/^\$Header/\$" "Header/;
print;
}
}
}
a687 2
# Finally the documentation.
d694 5
a698 1
B<flexml> [B<-d>] [B<-S> I<skel>C<.l>] [B<-o> I<name>C<.l>] I<name>[C<.dtd>]
d703 1
a703 1
format of XML (eXtended Markup Language) documents; this is assumed to
d715 1
a715 1
=item C<Attribute_>I<tag>C<_>I<attribute>C<(char* value)>
d759 8
a766 4
plus simple parsed entity declarations (and comments, of
course). In fact it I<ignores> any lines not in this form (a rather
serious limitation). A tag may be split over several lines but
I<flexml> does not handle several elements on a line.
@
1.1
log
@Initial revision
@
text
@d25 1
a25 1
$Header = '$Header: /var/cvsroot/ntsys/FleXML/flexml.pl,v 1.20 1999/09/14 20:47:09 krisrose Exp $'; #'sic
d30 2
a31 3
$Usage = "Usage: flexml [-d] [-S skel.l] [-o name.l] name[.dtd]";
use Getopt::Std; getopts('dS:o:');
a35 1
d39 2
d44 6
a49 1
$SCANNER = ($opt_o ? $opt_o : "$prefix.l");
d56 4
a59 4
%leaf = (); # $leaf{tag} == true if the tag is a leaf tag.
%attlist = (); # $attlist{tag} is list of attribute names.
%entity = (); # entity table
%entitysource = (); # entity source lines
d79 2
a80 2
# Expand all declared entities until none left (beware of cycles :)
local @@entities = keys %entity;
d85 1
a85 1
$test = $count if s/$ent/$entity{$ent}/g;
d94 1
a94 1
$leaf{$1} = true;
d106 1
a106 1
$attlist{$1} .= " $2";
d112 4
d117 2
a118 6
$entity{"&$1;"} = "$2";
$entitysource{"&$1;"} = "/* $orig */\n";
}
elsif ( /<!ENTITY\s+%\s+([a-zA-Z:_.-]+)\s+"([^>]*)"\s*>/ ) {
$entity{"%$1;"} = "$2";
$entitysource{"%$1;"} = "/* $orig */\n";
d137 66
a202 1
# Copy skeleton scanner to output scanner with substitutions.
d228 1
a228 1
elsif ( /^FLEXML_HANDLER_DECLARATIONS$/ ) {
d230 6
d237 2
a238 8
print "\n"
. "void STag_$tag(void);\n"
. "void ETag_$tag(char*);\n";
foreach $attribute (split " ","$attlist{$tag}") {
print "void Attribute_${tag}_${attribute}(char*);\n";
d247 2
a248 2
print SCANNER ("%x AL_$tag\n") if $attlist{$tag};
print SCANNER ("%s IN_$tag\n") if not $leaf{$tag} ;
d253 9
d264 2
a265 1
if (keys %entitysource) {
d267 2
a268 2
foreach $ent (keys %entitysource) {
print indent($entitysource{$ent});
d274 5
a278 2
print "\n"
. indent($source{$tag});
d280 24
a303 1
local $inner = ($leaf{$tag} ? "PCDATA" : "IN_$tag");
d305 17
a321 3
print "\"<$tag\"{s}\"/>\" STag($tag), ETag($tag);\n"
. "\"<$tag\"{s}\">\" STag($tag), ENTER($inner);\n"
. "<$inner>\"</$tag\"{s}\">\" ETag($tag), LEAVE($inner);\n";
d323 12
a334 1
if ($attlist{$tag}) {
d336 8
a343 3
print "\"<$tag\"{S} STag($tag), ENTER(AL_$tag);\n"
. "<AL_$tag>\"/>\" LEAVE(AL_$tag), ETag($tag);\n"
. "<AL_$tag>\">\" LEAVE(AL_$tag), ENTER(PCDATA);\n";
a344 5
foreach $attribute (split " ","$attlist{$tag}") {
print indent($source{"$tag/$attribute"});
print "<AL_$tag>\"$attribute\"{Eq}{Q} Attribute($tag,$attribute);\n";
}
}
d349 1
a349 1
s/^\$Header/\$" "Header/;
d389 6
d397 3
a399 3
if (keys %entitysource) {
foreach $ent (keys %entitysource) {
print $entitysource{$ent};
d405 5
a411 2
. $source{$tag}
. "\n"
d414 8
a421 4
. " flexml_dummy_STag(\"$tag\");\n"
. "}\n"
. "\n"
. "void ETag_$tag(char* text)\n"
d423 1
a423 1
. " flexml_dummy_ETag(\"$tag\",text);\n"
a424 12
foreach $attribute (split " ","$attlist{$tag}") {
print "\n"
. $source{"$tag/$attribute"}
. "\n"
. "void Attribute_${tag}_${attribute}(char* value)\n"
. "{\n"
. " flexml_dummy_Attribute(\"$tag\",\"$attribute\",value);\n"
. "}\n";
}
print "\n";
d505 4
a508 4
plus simple internal entity declarations (and comments, of course).
In fact it I<ignores> any lines not in this form (a rather serious
limitation). A tag may be split over several lines but I<flexml> does
not handle several elements on a line.
@
|