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
|
//
// "$Id: ppdc-source.cxx 358 2007-09-28 22:55:07Z mike $"
//
// Source class for the CUPS PPD Compiler.
//
// Copyright 2007 by Apple Inc.
// Copyright 2002-2007 by Easy Software Products.
//
// These coded instructions, statements, and computer programs are the
// property of Apple Inc. and are protected by Federal copyright
// law. Distribution and use rights are outlined in the file "LICENSE.txt"
// which should have been included with this file. If this file is
// file is missing or damaged, see the license at "http://www.cups.org/".
//
// Contents:
//
// ppdcSource::ppdcSource() - Load a driver source file.
// ppdcSource::~ppdcSource() - Free a driver source file.
// ppdcSource::add_include() - Add an include directory.
// ppdcSource::find_driver() - Find a driver.
// ppdcSource::find_include() - Find an include file.
// ppdcSource::find_size() - Find a media size.
// ppdcSource::find_variable() - Find a variable.
// ppdcSource::get_attr() - Get an attribute.
// ppdcSource::get_boolean() - Get a boolean value.
// ppdcSource::get_choice() - Get a choice.
// ppdcSource::get_color_model() - Get an old-style color model option.
// ppdcSource::get_color_order() - Get an old-style color order value.
// ppdcSource::get_color_profile() - Get a color profile definition.
// ppdcSource::get_color_space() - Get an old-style colorspace value.
// ppdcSource::get_constraint() - Get a constraint.
// ppdcSource::get_custom_size() - Get a custom media size definition
// from a file.
// ppdcSource::get_filter() - Get a filter.
// ppdcSource::get_float() - Get a single floating-point number.
// ppdcSource::get_font() - Get a font definition.
// ppdcSource::get_generic() - Get a generic old-style option.
// ppdcSource::get_group() - Get an option group.
// ppdcSource::get_installable() - Get an installable option.
// ppdcSource::get_integer() - Get an integer value from a string.
// ppdcSource::get_integer() - Get an integer value from a file.
// ppdcSource::get_measurement() - Get a measurement value.
// ppdcSource::get_option() - Get an option definition.
// ppdcSource::get_resolution() - Get an old-style resolution option.
// ppdcSource::get_simple_profile() - Get a simple color profile definition.
// ppdcSource::get_size() - Get a media size definition from a file.
// ppdcSource::get_token() - Get a token from a file.
// ppdcSource::get_variable() - Get a variable definition.
// ppdcSource::quotef() - Write a formatted, quoted string...
// ppdcSource::read_file() - Read a driver source file.
// ppdcSource::scan_file() - Scan a driver source file.
// ppdcSource::set_variable() - Set a variable.
// ppdcSource::write_file() - Write the current source data to a file.
//
//
// Include necessary headers...
//
#include "ppdc.h"
#include <limits.h>
#include <math.h>
#include <unistd.h>
#include <cups/raster.h>
#include "data/epson.h"
#include "data/escp.h"
#include "data/hp.h"
#include "data/label.h"
#include "data/pcl.h"
//
// Class globals...
//
ppdcArray *ppdcSource::includes = 0;
const char *ppdcSource::driver_types[] =
{
"custom",
"ps",
"escp",
"pcl",
"label",
"epson",
"hp"
};
//
// 'ppdcSource::ppdcSource()' - Load a driver source file.
//
ppdcSource::ppdcSource(const char *f) // I - File to read
{
filename = new ppdcString(f);
base_fonts = new ppdcArray();
drivers = new ppdcArray();
po_files = new ppdcArray();
sizes = new ppdcArray();
vars = new ppdcArray();
if (f)
read_file(f);
}
//
// 'ppdcSource::~ppdcSource()' - Free a driver source file.
//
ppdcSource::~ppdcSource()
{
delete filename;
delete base_fonts;
delete drivers;
delete po_files;
delete sizes;
delete vars;
}
//
// 'ppdcSource::add_include()' - Add an include directory.
//
void
ppdcSource::add_include(const char *d) // I - Include directory
{
if (!d)
return;
if (!includes)
includes = new ppdcArray();
includes->add(new ppdcString(d));
}
//
// 'ppdcSource::find_driver()' - Find a driver.
//
ppdcDriver * // O - Driver
ppdcSource::find_driver(const char *f) // I - Driver file name
{
ppdcDriver *d; // Current driver
for (d = (ppdcDriver *)drivers->first(); d; d = (ppdcDriver *)drivers->next())
if (!strcasecmp(f, d->pc_file_name->value))
return (d);
return (NULL);
}
//
// 'ppdcSource::find_include()' - Find an include file.
//
char * // O - Found path or NULL
ppdcSource::find_include(
const char *f, // I - Include filename
const char *base, // I - Current directory
char *n, // I - Path buffer
int nlen) // I - Path buffer length
{
ppdcString *dir; // Include directory
char temp[1024], // Temporary path
*ptr; // Pointer to end of path
// Range check input...
if (!f || !*f || !n || nlen < 2)
return (0);
// Check the first character to see if we have <name> or "name"...
if (*f == '<')
{
// Remove the surrounding <> from the name...
strlcpy(temp, f + 1, sizeof(temp));
ptr = temp + strlen(temp) - 1;
if (*ptr != '>')
{
fprintf(stderr, "ppdc: Invalid #include/#po filename \"%s\"!\n", n);
return (0);
}
*ptr = '\0';
f = temp;
}
else
{
// Check for the local file relative to the current directory...
if (base && *base && f[0] != '/')
snprintf(n, nlen, "%s/%s", base, f);
else
strlcpy(n, f, nlen);
if (!access(n, 0))
return (n);
else if (*f == '/')
{
// Absolute path that doesn't exist...
return (0);
}
}
// Search the include directories, if any...
if (includes)
{
for (dir = (ppdcString *)includes->first(); dir; dir = (ppdcString *)includes->next())
{
snprintf(n, nlen, "%s/%s", dir->value, f);
if (!access(n, 0))
return (n);
}
}
// Search the standard include directories...
const char *env; // Directory environment variable
if ((env = getenv("PPDC_INCLUDE_DIR")) == NULL)
env = PPDC_INCLUDE_DIR;
snprintf(n, nlen, "%s/%s", env, f);
if (!access(n, 0))
return (n);
if ((env = getenv("PPDC_PO_DIR")) == NULL)
env = PPDC_PO_DIR;
snprintf(n, nlen, "%s/%s", env, f);
if (!access(n, 0))
return (n);
else
return (0);
}
//
// 'ppdcSource::find_po()' - Find a message catalog for the given locale...
//
ppdcCatalog * // O - Message catalog or NULL
ppdcSource::find_po(const char *l) // I - Locale name
{
ppdcCatalog *cat; // Current message catalog
for (cat = (ppdcCatalog *)po_files->first();
cat;
cat = (ppdcCatalog *)po_files->next())
if (!strcasecmp(l, cat->locale->value))
return (cat);
return (NULL);
}
//
// 'ppdcSource::find_size()' - Find a media size.
//
ppdcMediaSize * // O - Size
ppdcSource::find_size(const char *s) // I - Size name
{
ppdcMediaSize *m; // Current media size
for (m = (ppdcMediaSize *)sizes->first(); m; m = (ppdcMediaSize *)sizes->next())
if (!strcasecmp(s, m->name->value))
return (m);
return (NULL);
}
//
// 'ppdcSource::find_variable()' - Find a variable.
//
ppdcVariable * // O - Variable
ppdcSource::find_variable(const char *n)// I - Variable name
{
ppdcVariable *v; // Current variable
for (v = (ppdcVariable *)vars->first(); v; v = (ppdcVariable *)vars->next())
if (!strcasecmp(n, v->name->value))
return (v);
return (NULL);
}
//
// 'ppdcSource::get_attr()' - Get an attribute.
//
ppdcAttr * // O - Attribute
ppdcSource::get_attr(ppdcFile *fp) // I - File to read
{
char name[1024], // Name string
selector[1024], // Selector string
*text, // Text string
value[1024]; // Value string
// Get the attribute parameters:
//
// Attribute name selector value
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr, "ppdc: Expected name after Attribute on line %d of %s!\n",
fp->line, fp->filename);
return (0);
}
if (!get_token(fp, selector, sizeof(selector)))
{
fprintf(stderr, "ppdc: Expected selector after Attribute on line %d of %s!\n",
fp->line, fp->filename);
return (0);
}
if ((text = strchr(selector, '/')) != NULL)
*text++ = '\0';
if (!get_token(fp, value, sizeof(value)))
{
fprintf(stderr, "ppdc: Expected value after Attribute on line %d of %s!\n",
fp->line, fp->filename);
return (0);
}
// printf("name=\"%s\", selector=\"%s\", value=\"%s\"\n", name, selector, value);
return (new ppdcAttr(name, selector, text, value));
}
//
// 'ppdcSource::get_boolean()' - Get a boolean value.
//
int // O - Boolean value
ppdcSource::get_boolean(ppdcFile *fp) // I - File to read
{
char buffer[256]; // String buffer
if (!get_token(fp, buffer, sizeof(buffer)))
{
fprintf(stderr, "ppdc: Expected boolean value on line %d of %s.\n",
fp->line, fp->filename);
return (-1);
}
if (!strcasecmp(buffer, "on") ||
!strcasecmp(buffer, "yes") ||
!strcasecmp(buffer, "true"))
return (1);
else if (!strcasecmp(buffer, "off") ||
!strcasecmp(buffer, "no") ||
!strcasecmp(buffer, "false"))
return (0);
else
{
fprintf(stderr, "ppdc: Bad boolean value (%s) on line %d of %s.\n",
buffer, fp->line, fp->filename);
return (-1);
}
}
//
// 'ppdcSource::get_choice()' - Get a choice.
//
ppdcChoice * // O - Choice data
ppdcSource::get_choice(ppdcFile *fp) // I - File to read
{
char name[1024], // Name
*text, // Text
code[10240]; // Code
// Read a choice from the file:
//
// Choice name/text code
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr, "ppdc: Expected choice name/text on line %d of %s.\n",
fp->line, fp->filename);
return (NULL);
}
if ((text = strchr(name, '/')) != NULL)
*text++ = '\0';
else
text = name;
if (!get_token(fp, code, sizeof(code)))
{
fprintf(stderr, "ppdc: Expected choice code on line %d of %s.\n",
fp->line, fp->filename);
return (NULL);
}
// Return the new choice
return (new ppdcChoice(name, text, code));
}
//
// 'ppdcSource::get_color_model()' - Get an old-style color model option.
//
ppdcChoice * // O - Choice data
ppdcSource::get_color_model(ppdcFile *fp)
// I - File to read
{
char name[1024], // Option name
*text, // Text option
temp[256]; // Temporary string
int color_space, // Colorspace
color_order, // Color order
compression; // Compression mode
// Get the ColorModel parameters:
//
// ColorModel name/text colorspace colororder compression
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr,
"ppdc: Expected name/text combination for ColorModel on line "
"%d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if ((text = strchr(name, '/')) != NULL)
*text++ = '\0';
else
text = name;
if (!get_token(fp, temp, sizeof(temp)))
{
fprintf(stderr,
"ppdc: Expected colorspace for ColorModel on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if ((color_space = get_color_space(temp)) < 0)
color_space = get_integer(temp);
if (!get_token(fp, temp, sizeof(temp)))
{
fprintf(stderr,
"ppdc: Expected color order for ColorModel on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if ((color_order = get_color_order(temp)) < 0)
color_order = get_integer(temp);
if (!get_token(fp, temp, sizeof(temp)))
{
fprintf(stderr,
"ppdc: Expected compression for ColorModel on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
compression = get_integer(temp);
snprintf(temp, sizeof(temp),
"<</cupsColorSpace %d/cupsColorOrder %d/cupsCompression %d>>"
"setpagedevice",
color_space, color_order, compression);
return (new ppdcChoice(name, text, temp));
}
//
// 'ppdcSource::get_color_order()' - Get an old-style color order value.
//
int // O - Color order value
ppdcSource::get_color_order(
const char *co) // I - Color order string
{
if (!strcasecmp(co, "chunked") ||
!strcasecmp(co, "chunky"))
return (CUPS_ORDER_CHUNKED);
else if (!strcasecmp(co, "banded"))
return (CUPS_ORDER_BANDED);
else if (!strcasecmp(co, "planar"))
return (CUPS_ORDER_PLANAR);
else
return (-1);
}
//
// 'ppdcSource::get_color_profile()' - Get a color profile definition.
//
ppdcProfile * // O - Color profile
ppdcSource::get_color_profile(
ppdcFile *fp) // I - File to read
{
char resolution[1024], // Resolution/media type
*media_type; // Media type
int i; // Looping var
float g, // Gamma value
d, // Density value
m[9]; // Transform matrix
// Get the ColorProfile parameters:
//
// ColorProfile resolution/mediatype gamma density m00 m01 m02 ... m22
if (!get_token(fp, resolution, sizeof(resolution)))
{
fprintf(stderr, "ppdc: Expected resolution/mediatype following ColorProfile on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if ((media_type = strchr(resolution, '/')) != NULL)
*media_type++ = '\0';
else
media_type = resolution;
g = get_float(fp);
d = get_float(fp);
for (i = 0; i < 9; i ++)
m[i] = get_float(fp);
return (new ppdcProfile(resolution, media_type, g, d, m));
}
//
// 'ppdcSource::get_color_space()' - Get an old-style colorspace value.
//
int // O - Colorspace value
ppdcSource::get_color_space(
const char *cs) // I - Colorspace string
{
if (!strcasecmp(cs, "w"))
return (CUPS_CSPACE_W);
else if (!strcasecmp(cs, "rgb"))
return (CUPS_CSPACE_RGB);
else if (!strcasecmp(cs, "rgba"))
return (CUPS_CSPACE_RGBA);
else if (!strcasecmp(cs, "k"))
return (CUPS_CSPACE_K);
else if (!strcasecmp(cs, "cmy"))
return (CUPS_CSPACE_CMY);
else if (!strcasecmp(cs, "ymc"))
return (CUPS_CSPACE_YMC);
else if (!strcasecmp(cs, "cmyk"))
return (CUPS_CSPACE_CMYK);
else if (!strcasecmp(cs, "ymck"))
return (CUPS_CSPACE_YMCK);
else if (!strcasecmp(cs, "kcmy"))
return (CUPS_CSPACE_KCMY);
else if (!strcasecmp(cs, "kcmycm"))
return (CUPS_CSPACE_KCMYcm);
else if (!strcasecmp(cs, "gmck"))
return (CUPS_CSPACE_GMCK);
else if (!strcasecmp(cs, "gmcs"))
return (CUPS_CSPACE_GMCS);
else if (!strcasecmp(cs, "white"))
return (CUPS_CSPACE_WHITE);
else if (!strcasecmp(cs, "gold"))
return (CUPS_CSPACE_GOLD);
else if (!strcasecmp(cs, "silver"))
return (CUPS_CSPACE_SILVER);
else if (!strcasecmp(cs, "CIEXYZ"))
return (CUPS_CSPACE_CIEXYZ);
else if (!strcasecmp(cs, "CIELab"))
return (CUPS_CSPACE_CIELab);
else if (!strcasecmp(cs, "RGBW"))
return (CUPS_CSPACE_RGBW);
else if (!strcasecmp(cs, "ICC1"))
return (CUPS_CSPACE_ICC1);
else if (!strcasecmp(cs, "ICC2"))
return (CUPS_CSPACE_ICC2);
else if (!strcasecmp(cs, "ICC3"))
return (CUPS_CSPACE_ICC3);
else if (!strcasecmp(cs, "ICC4"))
return (CUPS_CSPACE_ICC4);
else if (!strcasecmp(cs, "ICC5"))
return (CUPS_CSPACE_ICC5);
else if (!strcasecmp(cs, "ICC6"))
return (CUPS_CSPACE_ICC6);
else if (!strcasecmp(cs, "ICC7"))
return (CUPS_CSPACE_ICC7);
else if (!strcasecmp(cs, "ICC8"))
return (CUPS_CSPACE_ICC8);
else if (!strcasecmp(cs, "ICC9"))
return (CUPS_CSPACE_ICC9);
else if (!strcasecmp(cs, "ICCA"))
return (CUPS_CSPACE_ICCA);
else if (!strcasecmp(cs, "ICCB"))
return (CUPS_CSPACE_ICCB);
else if (!strcasecmp(cs, "ICCC"))
return (CUPS_CSPACE_ICCC);
else if (!strcasecmp(cs, "ICCD"))
return (CUPS_CSPACE_ICCD);
else if (!strcasecmp(cs, "ICCE"))
return (CUPS_CSPACE_ICCE);
else if (!strcasecmp(cs, "ICCF"))
return (CUPS_CSPACE_ICCF);
else
return (-1);
}
//
// 'ppdcSource::get_constraint()' - Get a constraint.
//
ppdcConstraint * // O - Constraint
ppdcSource::get_constraint(ppdcFile *fp)// I - File to read
{
char temp[1024], // One string to rule them all
*ptr, // Pointer into string
*option1, // Constraint option 1
*choice1, // Constraint choice 1
*option2, // Constraint option 2
*choice2; // Constraint choice 2
// Read the UIConstaints parameter in one of the following forms:
//
// UIConstraints "*Option1 *Option2"
// UIConstraints "*Option1 Choice1 *Option2"
// UIConstraints "*Option1 *Option2 Choice2"
// UIConstraints "*Option1 Choice1 *Option2 Choice2"
if (!get_token(fp, temp, sizeof(temp)))
{
fprintf(stderr, "ppdc: Expected constraints string for UIConstraints on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
for (ptr = temp; isspace(*ptr); ptr ++);
if (*ptr != '*')
{
fprintf(stderr, "ppdc: Option constraint must *name on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
option1 = ptr;
for (; *ptr && !isspace(*ptr); ptr ++);
for (; isspace(*ptr); *ptr++ = '\0');
if (*ptr != '*')
{
choice1 = ptr;
for (; *ptr && !isspace(*ptr); ptr ++);
for (; isspace(*ptr); *ptr++ = '\0');
}
else
choice1 = NULL;
if (*ptr != '*')
{
fprintf(stderr, "ppdc: Expected two option names on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
option2 = ptr;
for (; *ptr && !isspace(*ptr); ptr ++);
for (; isspace(*ptr); *ptr++ = '\0');
if (*ptr)
choice2 = ptr;
else
choice2 = NULL;
return (new ppdcConstraint(option1, choice1, option2, choice2));
}
//
// 'ppdcSource::get_custom_size()' - Get a custom media size definition from a file.
//
ppdcMediaSize * // O - Media size
ppdcSource::get_custom_size(ppdcFile *fp)
// I - File to read
{
char name[1024], // Name
*text, // Text
size_code[10240], // PageSize code
region_code[10240]; // PageRegion
float width, // Width
length, // Length
left, // Left margin
bottom, // Bottom margin
right, // Right margin
top; // Top margin
// Get the name, text, width, length, margins, and code:
//
// CustomMedia name/text width length left bottom right top size-code region-code
if (!get_token(fp, name, sizeof(name)))
return (NULL);
if ((text = strchr(name, '/')) != NULL)
*text++ = '\0';
else
text = name;
if ((width = get_measurement(fp)) < 0.0f)
return (NULL);
if ((length = get_measurement(fp)) < 0.0f)
return (NULL);
if ((left = get_measurement(fp)) < 0.0f)
return (NULL);
if ((bottom = get_measurement(fp)) < 0.0f)
return (NULL);
if ((right = get_measurement(fp)) < 0.0f)
return (NULL);
if ((top = get_measurement(fp)) < 0.0f)
return (NULL);
if (!get_token(fp, size_code, sizeof(size_code)))
return (NULL);
if (!get_token(fp, region_code, sizeof(region_code)))
return (NULL);
// Return the new media size...
return (new ppdcMediaSize(name, text, width, length, left, bottom,
right, top, size_code, region_code));
}
//
// 'ppdcSource::get_duplex()' - Get a duplex option.
//
void
ppdcSource::get_duplex(ppdcFile *fp, // I - File to read from
ppdcDriver *d) // I - Current driver
{
char temp[256]; // Duplex keyword
ppdcAttr *attr; // cupsFlipDuplex attribute
ppdcGroup *g; // Current group
ppdcOption *o; // Duplex option
// Duplex {boolean|none|normal|flip}
if (!get_token(fp, temp, sizeof(temp)))
{
fprintf(stderr, "ppdc: Expected duplex type after Duplex on line %d of %s!\n",
fp->line, fp->filename);
return;
}
if (!strcasecmp(temp, "none") || !strcasecmp(temp, "false") ||
!strcasecmp(temp, "no") || !strcasecmp(temp, "off"))
{
g = d->find_group("General");
if ((o = g->find_option("Duplex")) != NULL)
g->options->remove(o);
for (attr = (ppdcAttr *)d->attrs->first();
attr;
attr = (ppdcAttr *)d->attrs->next())
if (!strcmp(attr->name->value, "cupsFlipDuplex"))
{
d->attrs->remove(attr);
break;
}
}
else if (!strcasecmp(temp, "normal") || !strcasecmp(temp, "true") ||
!strcasecmp(temp, "yes") || !strcasecmp(temp, "on") ||
!strcasecmp(temp, "flip"))
{
g = d->find_group("General");
o = g->find_option("Duplex");
if (!o)
{
o = new ppdcOption(PPDC_PICKONE, "Duplex", "2-Sided Printing",
!strcasecmp(temp, "flip") ? PPDC_SECTION_PAGE :
PPDC_SECTION_ANY, 10.0f);
o->add_choice(new ppdcChoice("None", "Off (1-Sided)",
"<</Duplex false>>setpagedevice"));
o->add_choice(new ppdcChoice("DuplexNoTumble", "Long-Edge (Portrait)",
"<</Duplex true/Tumble false>>setpagedevice"));
o->add_choice(new ppdcChoice("DuplexTumble", "Short-Edge (Landscape)",
"<</Duplex true/Tumble true>>setpagedevice"));
g->add_option(o);
}
for (attr = (ppdcAttr *)d->attrs->first();
attr;
attr = (ppdcAttr *)d->attrs->next())
if (!strcmp(attr->name->value, "cupsFlipDuplex"))
{
if (strcasecmp(temp, "flip"))
d->attrs->remove(attr);
break;
}
if (!strcasecmp(temp, "flip") && !attr)
d->add_attr(new ppdcAttr("cupsFlipDuplex", NULL, NULL, "true"));
}
else
fprintf(stderr, "ppdc: Unknown duplex type \"%s\" on line %d of %s!\n",
temp, fp->line, fp->filename);
}
//
// 'ppdcSource::get_filter()' - Get a filter.
//
ppdcFilter * // O - Filter
ppdcSource::get_filter(ppdcFile *fp) // I - File to read
{
char type[1024], // MIME type
program[1024], // Filter program
*ptr; // Pointer into MIME type
int cost; // Relative cost
// Read filter parameters in one of the following formats:
//
// Filter "type cost program"
// Filter type cost program
if (!get_token(fp, type, sizeof(type)))
{
fprintf(stderr, "ppdc: Expected a filter definition on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if ((ptr = strchr(type, ' ')) != NULL)
{
// Old-style filter definition in one string...
*ptr++ = '\0';
cost = strtol(ptr, &ptr, 10);
while (isspace(*ptr))
ptr ++;
strcpy(program, ptr);
}
else
{
cost = get_integer(fp);
if (!get_token(fp, program, sizeof(program)))
{
fprintf(stderr, "ppdc: Expected a program name on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
}
if (!type[0])
{
fprintf(stderr, "ppdc: Invalid empty MIME type for filter on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if (cost < 0 || cost > 200)
{
fprintf(stderr, "ppdc: Invalid cost for filter on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if (!program[0])
{
fprintf(stderr, "ppdc: Invalid empty program name for filter on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
return (new ppdcFilter(type, program, cost));
}
//
// 'ppdcSource::get_float()' - Get a single floating-point number.
//
float // O - Number
ppdcSource::get_float(ppdcFile *fp) // I - File to read
{
char temp[256], // String buffer
*ptr; // Pointer into buffer
float val; // Floating point value
// Get the number from the file and range-check...
if (!get_token(fp, temp, sizeof(temp)))
{
fprintf(stderr, "ppdc: Expected real number on line %d of %s!\n",
fp->line, fp->filename);
return (-1.0f);
}
val = (float)strtod(temp, &ptr);
if (*ptr)
{
fprintf(stderr, "ppdc: Unknown trailing characters in real number \"%s\" on line %d of %s!\n",
temp, fp->line, fp->filename);
return (-1.0f);
}
else
return (val);
}
//
// 'ppdcSource::get_font()' - Get a font definition.
//
ppdcFont * // O - Font data
ppdcSource::get_font(ppdcFile *fp) // I - File to read
{
char name[256], // Font name
encoding[256], // Font encoding
version[256], // Font version
charset[256], // Font charset
temp[256]; // Font status string
ppdcFontStatus status; // Font status enumeration
// Read font parameters as follows:
//
// Font *
// Font name encoding version charset status
// %font name encoding version charset status
//
// "Name" is the PostScript font name.
//
// "Encoding" is the default encoding of the font: Standard, ISOLatin1,
// Special, Expert, ExpertSubset, etc.
//
// "Version" is the version number string.
//
// "Charset" specifies the characters that are included in the font:
// Standard, Special, Expert, Adobe-Identity, etc.
//
// "Status" is the keyword ROM or Disk.
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr, "ppdc: Expected name after Font on line %d of %s!\n",
fp->line, fp->filename);
return (0);
}
if (!strcmp(name, "*"))
{
// Include all base fonts...
encoding[0] = '\0';
version[0] = '\0';
charset[0] = '\0';
status = PPDC_FONT_ROM;
}
else
{
// Load a full font definition...
if (!get_token(fp, encoding, sizeof(encoding)))
{
fprintf(stderr, "ppdc: Expected encoding after Font on line %d of %s!\n",
fp->line, fp->filename);
return (0);
}
if (!get_token(fp, version, sizeof(version)))
{
fprintf(stderr, "ppdc: Expected version after Font on line %d of %s!\n",
fp->line, fp->filename);
return (0);
}
if (!get_token(fp, charset, sizeof(charset)))
{
fprintf(stderr, "ppdc: Expected charset after Font on line %d of %s!\n",
fp->line, fp->filename);
return (0);
}
if (!get_token(fp, temp, sizeof(temp)))
{
fprintf(stderr, "ppdc: Expected status after Font on line %d of %s!\n",
fp->line, fp->filename);
return (0);
}
if (!strcasecmp(temp, "ROM"))
status = PPDC_FONT_ROM;
else if (!strcasecmp(temp, "Disk"))
status = PPDC_FONT_DISK;
else
{
fprintf(stderr, "ppdc: Bad status keyword %s on line %d of %s!\n",
temp, fp->line, fp->filename);
return (0);
}
}
// printf("Font %s %s %s %s %s\n", name, encoding, version, charset, temp);
return (new ppdcFont(name, encoding, version, charset, status));
}
//
// 'ppdcSource::get_generic()' - Get a generic old-style option.
//
ppdcChoice * // O - Choice data
ppdcSource::get_generic(ppdcFile *fp, // I - File to read
const char *keyword,
// I - Keyword name
const char *tattr,
// I - Text attribute
const char *nattr)
// I - Numeric attribute
{
char name[1024], // Name
*text, // Text
command[256]; // Command string
int val; // Numeric value
// Read one of the following parameters:
//
// Foo name/text
// Foo integer name/text
if (nattr)
val = get_integer(fp);
else
val = 0;
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr, "ppdc: Expected name/text after %s on line %d of %s!\n",
keyword, fp->line, fp->filename);
return (NULL);
}
if ((text = strchr(name, '/')) != NULL)
*text++ = '\0';
else
text = name;
if (nattr)
{
if (tattr)
snprintf(command, sizeof(command),
"<</%s(%s)/%s %d>>setpagedevice",
tattr, name, nattr, val);
else
snprintf(command, sizeof(command),
"<</%s %d>>setpagedevice",
nattr, val);
}
else
snprintf(command, sizeof(command),
"<</%s(%s)>>setpagedevice",
tattr, name);
return (new ppdcChoice(name, text, command));
}
//
// 'ppdcSource::get_group()' - Get an option group.
//
ppdcGroup * // O - Group
ppdcSource::get_group(ppdcFile *fp, // I - File to read
ppdcDriver *d) // I - Printer driver
{
char name[1024], // UI name
*text; // UI text
ppdcGroup *g; // Group
// Read the Group parameters:
//
// Group name/text
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr, "ppdc: Expected group name/text on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if ((text = strchr(name, '/')) != NULL)
*text++ = '\0';
else
text = name;
// See if the group already exists...
if ((g = d->find_group(name)) == NULL)
{
// Nope, add a new one...
g = new ppdcGroup(name, text);
d->add_group(g);
}
return (g);
}
//
// 'ppdcSource::get_installable()' - Get an installable option.
//
ppdcOption * // O - Option
ppdcSource::get_installable(ppdcFile *fp)
// I - File to read
{
char name[1024], // Name for installable option
*text; // Text for installable option
ppdcOption *o; // Option
// Read the parameter for an installable option:
//
// Installable name/text
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr, "ppdc: Expected name/text after Installable on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if ((text = strchr(name, '/')) != NULL)
*text++ = '\0';
else
text = name;
// Create the option...
o = new ppdcOption(PPDC_BOOLEAN, name, text, PPDC_SECTION_ANY, 10.0f);
// Add the false and true choices...
o->add_choice(new ppdcChoice("False", "Not Installed", ""));
o->add_choice(new ppdcChoice("True", "Installed", ""));
return (o);
}
//
// 'ppdcSource::get_integer()' - Get an integer value from a string.
//
int // O - Integer value
ppdcSource::get_integer(const char *v) // I - Value string
{
int val; // Value
int temp; // Temporary value
char *newv; // New value string pointer
// Parse the value string...
if (!v)
return (-1);
if (isdigit(*v) || *v == '-' || *v == '+')
{
// Return a simple integer value
val = strtol(v, (char **)&v, 0);
if (*v || val == LONG_MIN)
return (-1);
else
return (val);
}
else if (*v == '(')
{
// Return the bitwise OR of each integer in parenthesis...
v ++;
val = 0;
while (*v && *v != ')')
{
temp = strtol(v, &newv, 0);
if (!*newv || newv == v || !(isspace(*newv) || *newv == ')') ||
temp == LONG_MIN)
return (-1);
val |= temp;
v = newv;
}
if (*v == ')')
return (val);
else
return (-1);
}
else
return (-1);
}
//
// 'ppdcSource::get_integer()' - Get an integer value from a file.
//
int // O - Integer value
ppdcSource::get_integer(ppdcFile *fp) // I - File to read
{
char temp[1024]; // String buffer
if (!get_token(fp, temp, sizeof(temp)))
{
fprintf(stderr, "ppdc: Expected integer on line %d of %s!\n",
fp->line, fp->filename);
return (-1);
}
else
return (get_integer(temp));
}
//
// 'ppdcSource::get_measurement()' - Get a measurement value.
//
float // O - Measurement value in points
ppdcSource::get_measurement(ppdcFile *fp)
// I - File to read
{
char buffer[256], // Number buffer
*ptr; // Pointer into buffer
float val; // Measurement value
// Grab a token from the file...
if (!get_token(fp, buffer, sizeof(buffer)))
return (-1.0f);
// Get the floating point value of "s" and skip all digits and decimal points.
val = (float)strtod(buffer, &ptr);
// Check for a trailing unit specifier...
if (!strcasecmp(ptr, "mm"))
val *= 72.0f / 25.4f;
else if (!strcasecmp(ptr, "cm"))
val *= 72.0f / 2.54f;
else if (!strcasecmp(ptr, "m"))
val *= 72.0f / 0.0254f;
else if (!strcasecmp(ptr, "in"))
val *= 72.0f;
else if (!strcasecmp(ptr, "ft"))
val *= 72.0f * 12.0f;
else if (strcasecmp(ptr, "pt") && *ptr)
return (-1.0f);
return (val);
}
//
// 'ppdcSource::get_option()' - Get an option definition.
//
ppdcOption * // O - Option
ppdcSource::get_option(ppdcFile *fp, // I - File to read
ppdcDriver *d, // I - Printer driver
ppdcGroup *g) // I - Current group
{
char name[1024], // UI name
*text, // UI text
type[256]; // UI type string
ppdcOptType ot; // Option type value
ppdcOptSection section; // Option section
float order; // Option order
ppdcOption *o; // Option
// Read the Option parameters:
//
// Option name/text type section order
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr, "ppdc: Expected option name/text on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if ((text = strchr(name, '/')) != NULL)
*text++ = '\0';
else
text = name;
if (!get_token(fp, type, sizeof(type)))
{
fprintf(stderr, "ppdc: Expected option type on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if (!strcasecmp(type, "boolean"))
ot = PPDC_BOOLEAN;
else if (!strcasecmp(type, "pickone"))
ot = PPDC_PICKONE;
else if (!strcasecmp(type, "pickmany"))
ot = PPDC_PICKMANY;
else
{
fprintf(stderr, "ppdc: Invalid option type \"%s\" on line %d of %s!\n",
type, fp->line, fp->filename);
return (NULL);
}
if (!get_token(fp, type, sizeof(type)))
{
fprintf(stderr, "ppdc: Expected option section on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if (!strcasecmp(type, "AnySetup"))
section = PPDC_SECTION_ANY;
else if (!strcasecmp(type, "DocumentSetup"))
section = PPDC_SECTION_DOCUMENT;
else if (!strcasecmp(type, "ExitServer"))
section = PPDC_SECTION_EXIT;
else if (!strcasecmp(type, "JCLSetup"))
section = PPDC_SECTION_JCL;
else if (!strcasecmp(type, "PageSetup"))
section = PPDC_SECTION_PAGE;
else if (!strcasecmp(type, "Prolog"))
section = PPDC_SECTION_PROLOG;
else
{
fprintf(stderr, "ppdc: Invalid option section \"%s\" on line %d of %s!\n",
type, fp->line, fp->filename);
return (NULL);
}
order = get_float(fp);
// See if the option already exists...
if ((o = d->find_option(name)) == NULL)
{
// Nope, add a new one...
o = new ppdcOption(ot, name, text, section, order);
g->add_option(o);
}
else if (o->type != ot)
{
// printf("o=%p, o->type=%d, o->name=%s, ot=%d, name=%s\n",
// o, o->type, o->name->value, ot, name);
fprintf(stderr, "ppdc: Option already defined with a different type on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
return (o);
}
//
// 'ppdcSource::get_po()' - Get a message catalog.
//
ppdcCatalog * // O - Message catalog
ppdcSource::get_po(ppdcFile *fp) // I - File to read
{
char locale[32], // Locale name
poname[1024], // Message catalog filename
basedir[1024], // Base directory
*baseptr, // Pointer into directory
pofilename[1024]; // Full filename of message catalog
ppdcCatalog *cat; // Message catalog
// Read the #po parameters:
//
// #po locale "filename.po"
if (!get_token(fp, locale, sizeof(locale)))
{
fprintf(stderr, "ppdc: Expected locale after #po on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if (!get_token(fp, poname, sizeof(poname)))
{
fprintf(stderr, "ppdc: Expected filename after #po %s on line %d of %s!\n",
locale, fp->line, fp->filename);
return (NULL);
}
// See if the locale is already loaded...
if (find_po(locale))
{
fprintf(stderr, "ppdc: Duplicate #po for locale %s on line %d of %s!\n",
locale, fp->line, fp->filename);
return (NULL);
}
// Figure out the current directory...
strlcpy(basedir, fp->filename, sizeof(basedir));
if ((baseptr = strrchr(basedir, '/')) != NULL)
*baseptr = '\0';
else
strcpy(basedir, ".");
// Find the po file...
if (find_include(poname, basedir, pofilename, sizeof(pofilename)))
{
// Found it, so load it...
cat = new ppdcCatalog(locale, pofilename);
// Reset the filename to the name supplied by the user...
delete cat->filename;
cat->filename = new ppdcString(poname);
// Return the catalog...
return (cat);
}
else
{
fprintf(stderr, "ppdc: Unable to find #po file %s on line %d of %s!\n",
poname, fp->line, fp->filename);
return (NULL);
}
}
//
// 'ppdcSource::get_resolution()' - Get an old-style resolution option.
//
ppdcChoice * // O - Choice data
ppdcSource::get_resolution(ppdcFile *fp)// I - File to read
{
char name[1024], // Name
*text, // Text
temp[256], // Temporary string
command[256], // Command string
*commptr; // Pointer into command
int xdpi, ydpi, // X + Y resolution
color_order, // Color order
color_space, // Colorspace
compression, // Compression mode
depth, // Bits per color
row_count, // Row count
row_feed, // Row feed
row_step; // Row step/interval
// Read the resolution parameters:
//
// Resolution colorspace bits row-count row-feed row-step name/text
if (!get_token(fp, temp, sizeof(temp)))
{
fprintf(stderr, "ppdc: Expected override field after Resolution on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
color_order = get_color_order(temp);
color_space = get_color_space(temp);
compression = get_integer(temp);
depth = get_integer(fp);
row_count = get_integer(fp);
row_feed = get_integer(fp);
row_step = get_integer(fp);
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr, "ppdc: Expected name/text after Resolution on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if ((text = strchr(name, '/')) != NULL)
*text++ = '\0';
else
text = name;
switch (sscanf(name, "%dx%d", &xdpi, &ydpi))
{
case 0 :
fprintf(stderr, "ppdc: Bad resolution name \"%s\" on line %d of %s!\n",
name, fp->line, fp->filename);
break;
case 1 :
ydpi = xdpi;
break;
}
// Create the necessary PS commands...
snprintf(command, sizeof(command),
"<</HWResolution[%d %d]/cupsBitsPerColor %d/cupsRowCount %d"
"/cupsRowFeed %d/cupsRowStep %d",
xdpi, ydpi, depth, row_count, row_feed, row_step);
commptr = command + strlen(command);
if (color_order >= 0)
{
snprintf(commptr, sizeof(command) - (commptr - command),
"/cupsColorOrder %d", color_order);
commptr += strlen(commptr);
}
if (color_space >= 0)
{
snprintf(commptr, sizeof(command) - (commptr - command),
"/cupsColorSpace %d", color_space);
commptr += strlen(commptr);
}
if (compression >= 0)
{
snprintf(commptr, sizeof(command) - (commptr - command),
"/cupsCompression %d", compression);
commptr += strlen(commptr);
}
snprintf(commptr, sizeof(command) - (commptr - command), ">>setpagedevice");
// Return the new choice...
return (new ppdcChoice(name, text, command));
}
//
// 'ppdcSource::get_simple_profile()' - Get a simple color profile definition.
//
ppdcProfile * // O - Color profile
ppdcSource::get_simple_profile(ppdcFile *fp)
// I - File to read
{
char resolution[1024], // Resolution/media type
*media_type; // Media type
float m[9]; // Transform matrix
float kd, rd, g; // Densities and gamma
float red, green, blue; // RGB adjustments
float yellow; // Yellow density
float color; // Color density values
// Get the SimpleColorProfile parameters:
//
// SimpleColorProfile resolution/mediatype black-density yellow-density
// red-density gamma red-adjust green-adjust blue-adjust
if (!get_token(fp, resolution, sizeof(resolution)))
{
fprintf(stderr, "ppdc: Expected resolution/mediatype following SimpleColorProfile on line %d of %s!\n",
fp->line, fp->filename);
return (NULL);
}
if ((media_type = strchr(resolution, '/')) != NULL)
*media_type++ = '\0';
else
media_type = resolution;
// Collect the profile parameters...
kd = get_float(fp);
yellow = get_float(fp);
rd = get_float(fp);
g = get_float(fp);
red = get_float(fp);
green = get_float(fp);
blue = get_float(fp);
// Build the color profile...
color = 0.5f * rd / kd - kd;
m[0] = 1.0f; // C
m[1] = color + blue; // C + M (blue)
m[2] = color - green; // C + Y (green)
m[3] = color - blue; // M + C (blue)
m[4] = 1.0f; // M
m[5] = color + red; // M + Y (red)
m[6] = yellow * (color + green); // Y + C (green)
m[7] = yellow * (color - red); // Y + M (red)
m[8] = yellow; // Y
if (m[1] > 0.0f)
{
m[3] -= m[1];
m[1] = 0.0f;
}
else if (m[3] > 0.0f)
{
m[1] -= m[3];
m[3] = 0.0f;
}
if (m[2] > 0.0f)
{
m[6] -= m[2];
m[2] = 0.0f;
}
else if (m[6] > 0.0f)
{
m[2] -= m[6];
m[6] = 0.0f;
}
if (m[5] > 0.0f)
{
m[7] -= m[5];
m[5] = 0.0f;
}
else if (m[7] > 0.0f)
{
m[5] -= m[7];
m[7] = 0.0f;
}
// Return the new profile...
return (new ppdcProfile(resolution, media_type, g, kd, m));
}
//
// 'ppdcSource::get_size()' - Get a media size definition from a file.
//
ppdcMediaSize * // O - Media size
ppdcSource::get_size(ppdcFile *fp) // I - File to read
{
char name[1024], // Name
*text; // Text
float width, // Width
length; // Length
// Get the name, text, width, and length:
//
// #media name/text width length
if (!get_token(fp, name, sizeof(name)))
return (NULL);
if ((text = strchr(name, '/')) != NULL)
*text++ = '\0';
else
text = name;
if ((width = get_measurement(fp)) < 0.0f)
return (NULL);
if ((length = get_measurement(fp)) < 0.0f)
return (NULL);
// Return the new media size...
return (new ppdcMediaSize(name, text, width, length, 0.0f, 0.0f, 0.0f, 0.0f));
}
//
// 'ppdcSource::get_token()' - Get a token from a file.
//
char * // O - Token string or NULL
ppdcSource::get_token(ppdcFile *fp, // I - File to read
char *buffer, // I - Buffer
int buflen) // I - Length of buffer
{
char *bufptr, // Pointer into string buffer
*bufend; // End of string buffer
int ch, // Character from file
nextch, // Next char in file
quote, // Quote character used...
empty, // Empty input?
startline; // Start line for quote
char name[256], // Name string
*nameptr; // Name pointer
ppdcVariable *var; // Variable pointer
// Mark the beginning and end of the buffer...
bufptr = buffer;
bufend = buffer + buflen - 1;
// Loop intil we've read a token...
quote = 0;
startline = 0;
empty = 1;
while ((ch = fp->get()) != EOF)
{
if (isspace(ch) && !quote)
{
if (empty)
continue;
else
break;
}
else if (ch == '$')
{
// Variable substitution
empty = 0;
for (nameptr = name; (ch = fp->peek()) != EOF;)
{
if (!isalnum(ch) && ch != '_')
break;
else if (nameptr < (name + sizeof(name) - 1))
*nameptr++ = fp->get();
}
if (nameptr == name)
{
// Just substitute this character...
if (ch == '$')
{
// $$ = $
if (bufptr < bufend)
*bufptr++ = fp->get();
}
else
{
// $ch = $ch
fprintf(stderr, "ppdc: Bad variable substitution ($%c) on line %d of %s.\n",
ch, fp->line, fp->filename);
if (bufptr < bufend)
*bufptr++ = '$';
}
}
else
{
// Substitute the variable value...
*nameptr = '\0';
var = find_variable(name);
if (var)
{
strncpy(bufptr, var->value->value, bufend - bufptr);
bufptr += strlen(var->value->value);
}
else
{
fprintf(stderr, "ppdc: Undefined variable (%s) on line %d of %s.\n",
name, fp->line, fp->filename);
snprintf(bufptr, bufend - bufptr + 1, "$%s", name);
bufptr += strlen(name) + 1;
}
}
}
else if (ch == '/' && !quote)
{
// Possibly a comment...
nextch = fp->peek();
if (nextch == '*')
{
// C comment...
fp->get();
ch = fp->get();
while ((nextch = fp->get()) != EOF)
{
if (ch == '*' && nextch == '/')
break;
ch = nextch;
}
if (nextch == EOF)
break;
}
else if (nextch == '/')
{
// C++ comment...
while ((nextch = fp->get()) != EOF)
if (nextch == '\n')
break;
if (nextch == EOF)
break;
}
else
{
// Not a comment...
empty = 0;
if (bufptr < bufend)
*bufptr++ = ch;
}
}
else if (ch == '\'' || ch == '\"')
{
empty = 0;
if (quote == ch)
{
// Ending the current quoted string...
quote = 0;
}
else if (quote)
{
// Insert the opposing quote char...
if (bufptr < bufend)
*bufptr++ = ch;
}
else
{
// Start a new quoted string...
startline = fp->line;
quote = ch;
}
}
else if ((ch == '(' || ch == '<') && !quote)
{
empty = 0;
quote = ch;
startline = fp->line;
if (bufptr < bufend)
*bufptr++ = ch;
}
else if ((ch == ')' && quote == '(') || (ch == '>' && quote == '<'))
{
quote = 0;
if (bufptr < bufend)
*bufptr++ = ch;
}
else if (ch == '\\')
{
empty = 0;
if ((ch = fp->get()) == EOF)
break;
if (bufptr < bufend)
*bufptr++ = ch;
}
else if (bufptr < bufend)
{
empty = 0;
*bufptr++ = ch;
if ((ch == '{' || ch == '}') && !quote)
break;
}
}
if (quote)
{
fprintf(stderr, "ppdc: Unterminated string starting with %c on line %d of %s!\n",
quote, startline, fp->filename);
return (NULL);
}
if (empty)
return (NULL);
else
{
*bufptr = '\0';
// puts(buffer);
return (buffer);
}
}
//
// 'ppdcSource::get_variable()' - Get a variable definition.
//
ppdcVariable * // O - Variable
ppdcSource::get_variable(ppdcFile *fp) // I - File to read
{
char name[1024], // Name
value[1024]; // Value
// Get the name and value:
//
// #define name value
if (!get_token(fp, name, sizeof(name)))
return (NULL);
if (!get_token(fp, value, sizeof(value)))
return (NULL);
// Set the variable...
return (set_variable(name, value));
}
//
// 'ppdcSource::quotef()' - Write a formatted, quoted string...
//
int // O - Number bytes on success, -1 on failure
ppdcSource::quotef(cups_file_t *fp, // I - File to write to
const char *format, // I - Printf-style format string
...) // I - Additional args as needed
{
va_list ap; // Pointer to additional arguments
int bytes; // Bytes written
char sign, // Sign of format width
size, // Size character (h, l, L)
type; // Format type character
const char *bufformat; // Start of format
int width, // Width of field
prec; // Number of characters of precision
char tformat[100]; // Temporary format string for fprintf()
char *s; // Pointer to string
int slen; // Length of string
int i; // Looping var
// Range check input...
if (!fp || !format)
return (-1);
// Loop through the format string, formatting as needed...
va_start(ap, format);
bytes = 0;
while (*format)
{
if (*format == '%')
{
bufformat = format;
format ++;
if (*format == '%')
{
cupsFilePutChar(fp, *format++);
bytes ++;
continue;
}
else if (strchr(" -+#\'", *format))
sign = *format++;
else
sign = 0;
width = 0;
while (isdigit(*format))
width = width * 10 + *format++ - '0';
if (*format == '.')
{
format ++;
prec = 0;
while (isdigit(*format))
prec = prec * 10 + *format++ - '0';
}
else
prec = -1;
if (*format == 'l' && format[1] == 'l')
{
size = 'L';
format += 2;
}
else if (*format == 'h' || *format == 'l' || *format == 'L')
size = *format++;
if (!*format)
break;
type = *format++;
switch (type)
{
case 'E' : // Floating point formats
case 'G' :
case 'e' :
case 'f' :
case 'g' :
if ((format - bufformat + 1) > (int)sizeof(tformat))
break;
strncpy(tformat, bufformat, format - bufformat);
tformat[format - bufformat] = '\0';
bytes += cupsFilePrintf(fp, tformat, va_arg(ap, double));
break;
case 'B' : // Integer formats
case 'X' :
case 'b' :
case 'd' :
case 'i' :
case 'o' :
case 'u' :
case 'x' :
if ((format - bufformat + 1) > (int)sizeof(tformat))
break;
strncpy(tformat, bufformat, format - bufformat);
tformat[format - bufformat] = '\0';
bytes += cupsFilePrintf(fp, tformat, va_arg(ap, int));
break;
case 'p' : // Pointer value
if ((format - bufformat + 1) > (int)sizeof(tformat))
break;
strncpy(tformat, bufformat, format - bufformat);
tformat[format - bufformat] = '\0';
bytes += cupsFilePrintf(fp, tformat, va_arg(ap, void *));
break;
case 'c' : // Character or character array
if (width <= 1)
{
bytes ++;
cupsFilePutChar(fp, va_arg(ap, int));
}
else
{
cupsFileWrite(fp, va_arg(ap, char *), width);
bytes += width;
}
break;
case 's' : // String
if ((s = va_arg(ap, char *)) == NULL)
s = (char *)"(nil)";
slen = strlen(s);
if (slen > width && prec != width)
width = slen;
if (slen > width)
slen = width;
if (sign != '-')
{
for (i = width - slen; i > 0; i --, bytes ++)
cupsFilePutChar(fp, ' ');
}
for (i = slen; i > 0; i --, s ++, bytes ++)
{
if (*s == '\\' || *s == '\"')
{
cupsFilePutChar(fp, '\\');
bytes ++;
}
cupsFilePutChar(fp, *s);
}
if (sign == '-')
{
for (i = width - slen; i > 0; i --, bytes ++)
cupsFilePutChar(fp, ' ');
}
break;
}
}
else
{
cupsFilePutChar(fp, *format++);
bytes ++;
}
}
va_end(ap);
// Return the number of characters written.
return (bytes);
}
//
// 'ppdcSource::read_file()' - Read a driver source file.
//
void
ppdcSource::read_file(const char *f) // I - File to read
{
ppdcFile *fp = new ppdcFile(f);
scan_file(fp);
delete fp;
}
//
// 'ppdcSource::scan_file()' - Scan a driver source file.
//
void
ppdcSource::scan_file(ppdcFile *fp, // I - File to read
ppdcDriver *td, // I - Driver template
bool inc) // I - Including?
{
ppdcDriver *d; // Current driver
ppdcGroup *g, // Current group
*general, // General options group
*install; // Installable options group
ppdcOption *o; // Current option
ppdcChoice *c; // Current choice
char temp[256], // Token from file...
*ptr; // Pointer into token
int isdefault; // Default option?
// Initialize things as needed...
if (inc && td)
d = td;
else
d = new ppdcDriver(td);
if ((general = d->find_group("General")) == NULL)
{
general = new ppdcGroup("General", NULL);
d->add_group(general);
}
if ((install = d->find_group("InstallableOptions")) == NULL)
{
install = new ppdcGroup("InstallableOptions", "Installable Options");
d->add_group(install);
}
// Loop until EOF or }
o = 0;
g = general;
while (get_token(fp, temp, sizeof(temp)))
{
if (temp[0] == '*')
{
// Mark the next choice as the default
isdefault = 1;
for (ptr = temp; ptr[1]; ptr ++)
*ptr = ptr[1];
*ptr = '\0';
}
else
{
// Don't mark the next choice as the default
isdefault = 0;
}
if (!strcasecmp(temp, "}"))
{
// Close this one out...
break;
}
else if (!strcasecmp(temp, "{"))
{
// Open a new child...
scan_file(fp, d);
}
else if (!strcasecmp(temp, "#define"))
{
// Get the variable...
get_variable(fp);
}
else if (!strcasecmp(temp, "#include"))
{
// #include filename
char basedir[1024], // Base directory
*baseptr, // Pointer into directory
inctemp[1024], // Initial filename
incname[1024]; // Include filename
ppdcFile *incfile; // Include file
// Get the include name...
if (!get_token(fp, inctemp, sizeof(inctemp)))
{
fprintf(stderr, "ppdc: Expected include filename on line %d of %s!\n",
fp->line, fp->filename);
break;
}
// Figure out the current directory...
strlcpy(basedir, fp->filename, sizeof(basedir));
if ((baseptr = strrchr(basedir, '/')) != NULL)
*baseptr = '\0';
else
strcpy(basedir, ".");
// Find the include file...
if (find_include(inctemp, basedir, incname, sizeof(incname)))
{
// Open the include file, scan it, and then close it...
incfile = new ppdcFile(incname);
scan_file(incfile, d, true);
delete incfile;
}
else
{
// Can't find it!
fprintf(stderr,
"ppdc: Unable to find include file \"%s\" on line %d of %s!\n",
inctemp, fp->line, fp->filename);
break;
}
}
else if (!strcasecmp(temp, "#media"))
{
ppdcMediaSize *m; // Media size
// Get a media size...
m = get_size(fp);
if (m)
sizes->add(m);
}
else if (!strcasecmp(temp, "#po"))
{
ppdcCatalog *cat; // Message catalog
// Get a message catalog...
cat = get_po(fp);
if (cat)
po_files->add(cat);
}
else if (!strcasecmp(temp, "Attribute"))
{
ppdcAttr *a; // Attribute
// Get an attribute...
a = get_attr(fp);
if (a)
d->add_attr(a);
}
else if (!strcasecmp(temp, "Choice"))
{
// Get a choice...
if (!o)
{
fprintf(stderr, "ppdc: Choice found on line %d of %s with no Option!\n",
fp->line, fp->filename);
break;
}
c = get_choice(fp);
if (!c)
break;
// Add it to the current option...
o->add_choice(c);
if (isdefault)
o->set_defchoice(c);
}
else if (!strcasecmp(temp, "ColorDevice"))
{
// ColorDevice boolean
d->color_device = get_boolean(fp);
}
else if (!strcasecmp(temp, "ColorModel"))
{
// Get the color model
c = get_color_model(fp);
if (!c)
continue;
// Add the choice to the ColorModel option...
if ((o = d->find_option("ColorModel")) == NULL)
{
// Create the ColorModel option...
o = new ppdcOption(PPDC_PICKONE, "ColorModel", "Color Mode", PPDC_SECTION_ANY, 10.0f);
g = general;
g->add_option(o);
}
o->add_choice(c);
if (isdefault)
o->set_defchoice(c);
o = NULL;
}
else if (!strcasecmp(temp, "ColorProfile"))
{
ppdcProfile *p; // Color profile
// Get the color profile...
p = get_color_profile(fp);
if (p)
d->profiles->add(p);
}
else if (!strcasecmp(temp, "Copyright"))
{
// Copyright string
char copytemp[8192], // Copyright string
*copyptr, // Pointer into string
*copyend; // Pointer to end of string
// Get the copyright string...
if (!get_token(fp, copytemp, sizeof(temp)))
{
fprintf(stderr,
"ppdc: Expected string after Copyright on line %d of %s!\n",
fp->line, fp->filename);
break;
}
// Break it up into individual lines...
for (copyptr = copytemp; copyptr; copyptr = copyend)
{
if ((copyend = strchr(copyptr, '\n')) != NULL)
*copyend++ = '\0';
d->copyright->add(new ppdcString(copyptr));
}
}
else if (!strcasecmp(temp, "CustomMedia"))
{
ppdcMediaSize *m; // Media size
// Get a custom media size...
m = get_custom_size(fp);
if (m)
d->sizes->add(m);
if (isdefault)
d->set_default_size(m);
}
else if (!strcasecmp(temp, "Cutter"))
{
// Cutter boolean
int have_cutter; // Have a paper cutter?
have_cutter = get_boolean(fp);
if (have_cutter <= 0)
continue;
if ((o = d->find_option("CutMedia")) == NULL)
{
o = new ppdcOption(PPDC_BOOLEAN, "CutMedia", "Cut Media", PPDC_SECTION_ANY, 10.0f);
g = general;
g->add_option(o);
c = new ppdcChoice("False", NULL, "<</CutMedia 0>>setpagedevice");
o->add_choice(c);
o->set_defchoice(c);
c = new ppdcChoice("True", NULL, "<</CutMedia 4>>setpagedevice");
o->add_choice(c);
}
o = NULL;
}
else if (!strcasecmp(temp, "Darkness"))
{
// Get the darkness choice...
c = get_generic(fp, "Darkness", NULL, "cupsCompression");
if (!c)
continue;
// Add the choice to the cupsDarkness option...
if ((o = d->find_option("cupsDarkness")) == NULL)
{
// Create the cupsDarkness option...
o = new ppdcOption(PPDC_PICKONE, "cupsDarkness", "Darkness", PPDC_SECTION_ANY, 10.0f);
g = general;
g->add_option(o);
}
o->add_choice(c);
if (isdefault)
o->set_defchoice(c);
o = NULL;
}
else if (!strcasecmp(temp, "DriverType"))
{
int i; // Looping var
// DriverType keyword
if (!get_token(fp, temp, sizeof(temp)))
{
fprintf(stderr, "ppdc: Expected driver type keyword following DriverType on line %d of %s!\n",
fp->line, fp->filename);
continue;
}
for (i = 0; i < (int)(sizeof(driver_types) / sizeof(driver_types[0])); i ++)
if (!strcasecmp(temp, driver_types[i]))
break;
if (i < (int)(sizeof(driver_types) / sizeof(driver_types[0])))
d->type = (ppdcDrvType)i;
else if (!strcasecmp(temp, "dymo"))
d->type = PPDC_DRIVER_LABEL;
else
fprintf(stderr, "ppdc: Unknown driver type %s on line %d of %s!\n",
temp, fp->line, fp->filename);
}
else if (!strcasecmp(temp, "Duplex"))
get_duplex(fp, d);
else if (!strcasecmp(temp, "Filter"))
{
ppdcFilter *f; // Filter
// Get the filter value...
f = get_filter(fp);
if (f)
d->filters->add(f);
}
else if (!strcasecmp(temp, "Finishing"))
{
// Get the finishing choice...
c = get_generic(fp, "Finishing", "OutputType", NULL);
if (!c)
continue;
// Add the choice to the cupsFinishing option...
if ((o = d->find_option("cupsFinishing")) == NULL)
{
// Create the cupsFinishing option...
o = new ppdcOption(PPDC_PICKONE, "cupsFinishing", "Finishing", PPDC_SECTION_ANY, 10.0f);
g = general;
g->add_option(o);
}
o->add_choice(c);
if (isdefault)
o->set_defchoice(c);
o = NULL;
}
else if (!strcasecmp(temp, "Font") ||
!strcasecmp(temp, "#font"))
{
ppdcFont *f; // Font
// Get a font...
f = get_font(fp);
if (f)
{
if (!strcasecmp(temp, "#font"))
base_fonts->add(f);
else
d->add_font(f);
if (isdefault)
d->set_default_font(f);
}
}
else if (!strcasecmp(temp, "Group"))
{
// Get a group...
g = get_group(fp, d);
if (!g)
break;
}
else if (!strcasecmp(temp, "HWMargins"))
{
// HWMargins left bottom right top
d->left_margin = get_measurement(fp);
d->bottom_margin = get_measurement(fp);
d->right_margin = get_measurement(fp);
d->top_margin = get_measurement(fp);
}
else if (!strcasecmp(temp, "InputSlot"))
{
// Get the input slot choice...
c = get_generic(fp, "InputSlot", NULL, "MediaPosition");
if (!c)
continue;
// Add the choice to the InputSlot option...
if ((o = d->find_option("InputSlot")) == NULL)
{
// Create the InputSlot option...
o = new ppdcOption(PPDC_PICKONE, "InputSlot", "Media Source",
PPDC_SECTION_ANY, 10.0f);
g = general;
g->add_option(o);
}
o->add_choice(c);
if (isdefault)
o->set_defchoice(c);
o = NULL;
}
else if (!strcasecmp(temp, "Installable"))
{
// Get the installable option...
o = get_installable(fp);
// Add it as needed...
if (o)
{
install->add_option(o);
o = NULL;
}
}
else if (!strcasecmp(temp, "ManualCopies"))
{
// ManualCopies boolean
d->manual_copies = get_boolean(fp);
}
else if (!strcasecmp(temp, "Manufacturer"))
{
// Manufacturer name
char name[256]; // Model name string
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr, "ppdc: Expected name after Manufacturer on line %d of %s!\n",
fp->line, fp->filename);
break;
}
d->set_manufacturer(name);
}
else if (!strcasecmp(temp, "MaxSize"))
{
// MaxSize width length
d->max_width = get_measurement(fp);
d->max_length = get_measurement(fp);
}
else if (!strcasecmp(temp, "MediaSize"))
{
// MediaSize keyword
char name[41]; // Media size name
ppdcMediaSize *m, // Matching media size...
*dm; // Driver media size...
if (get_token(fp, name, sizeof(name)) == NULL)
{
fprintf(stderr, "ppdc: Expected name after MediaSize on line %d of %s!\n",
fp->line, fp->filename);
break;
}
m = find_size(name);
if (!m)
{
fprintf(stderr, "ppdc: Unknown media size \"%s\" on line %d of %s!\n",
name, fp->line, fp->filename);
break;
}
// Add this size to the driver...
dm = new ppdcMediaSize(m->name->value, m->text->value,
m->width, m->length, d->left_margin,
d->bottom_margin, d->right_margin,
d->top_margin);
d->sizes->add(dm);
if (isdefault)
d->set_default_size(dm);
}
else if (!strcasecmp(temp, "MediaType"))
{
// Get the media type choice...
c = get_generic(fp, "MediaType", "MediaType", "cupsMediaType");
if (!c)
continue;
// Add the choice to the MediaType option...
if ((o = d->find_option("MediaType")) == NULL)
{
// Create the MediaType option...
o = new ppdcOption(PPDC_PICKONE, "MediaType", "Media Type",
PPDC_SECTION_ANY, 10.0f);
g = general;
g->add_option(o);
}
o->add_choice(c);
if (isdefault)
o->set_defchoice(c);
o = NULL;
}
else if (!strcasecmp(temp, "MinSize"))
{
// MinSize width length
d->min_width = get_measurement(fp);
d->min_length = get_measurement(fp);
}
else if (!strcasecmp(temp, "ModelName"))
{
// ModelName name
char name[256]; // Model name string
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr, "ppdc: Expected name after ModelName on line %d of %s!\n",
fp->line, fp->filename);
break;
}
d->set_model_name(name);
}
else if (!strcasecmp(temp, "ModelNumber"))
{
// ModelNumber number
d->model_number = get_integer(fp);
}
else if (!strcasecmp(temp, "Option"))
{
// Get an option...
o = get_option(fp, d, g);
if (!o)
break;
}
else if (!strcasecmp(temp, "PCFileName"))
{
// PCFileName name
char name[256]; // Model name string
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr, "ppdc: Expected name after PCFileName on line %d of %s!\n",
fp->line, fp->filename);
break;
}
d->set_pc_file_name(name);
}
else if (!strcasecmp(temp, "Resolution"))
{
// Get the resolution choice...
c = get_resolution(fp);
if (!c)
continue;
// Add the choice to the Resolution option...
if ((o = d->find_option("Resolution")) == NULL)
{
// Create the Resolution option...
o = new ppdcOption(PPDC_PICKONE, "Resolution", NULL, PPDC_SECTION_ANY, 10.0f);
g = general;
g->add_option(o);
}
o->add_choice(c);
if (isdefault)
o->set_defchoice(c);
o = NULL;
}
else if (!strcasecmp(temp, "SimpleColorProfile"))
{
ppdcProfile *p; // Color profile
// Get the color profile...
p = get_simple_profile(fp);
if (p)
d->profiles->add(p);
}
else if (!strcasecmp(temp, "Throughput"))
{
// Throughput number
d->throughput = get_integer(fp);
}
else if (!strcasecmp(temp, "UIConstraints"))
{
ppdcConstraint *con; // Constraint
con = get_constraint(fp);
if (con)
d->constraints->add(con);
}
else if (!strcasecmp(temp, "VariablePaperSize"))
{
// VariablePaperSize boolean
d->variable_paper_size = get_boolean(fp);
}
else if (!strcasecmp(temp, "Version"))
{
// Version string
char name[256]; // Model name string
if (!get_token(fp, name, sizeof(name)))
{
fprintf(stderr, "ppdc: Expected string after Version on line %d of %s!\n",
fp->line, fp->filename);
break;
}
d->set_version(name);
}
else
{
fprintf(stderr, "ppdc: Unknown token \"%s\" seen on line %d of %s!\n",
temp, fp->line, fp->filename);
break;
}
}
// Done processing this block, is there anything to save?
if (!inc)
{
if (!d->pc_file_name || !d->model_name || !d->manufacturer || !d->version ||
!d->sizes->count)
{
// Nothing to save...
d->release();
}
else
{
// Got a driver, save it...
drivers->add(d);
}
}
}
//
// 'ppdcSource::set_variable()' - Set a variable.
//
ppdcVariable * // O - Variable
ppdcSource::set_variable(
const char *name, // I - Name
const char *value) // I - Value
{
ppdcVariable *v; // Variable
// See if the variable exists already...
v = find_variable(name);
if (v)
{
// Change the variable value...
v->set_value(value);
}
else
{
// Create a new variable and add it...
v = new ppdcVariable(name, value);
vars->add(v);
}
return (v);
}
//
// 'ppdcSource::write_file()' - Write the current source data to a file.
//
int // O - 0 on success, -1 on error
ppdcSource::write_file(const char *f) // I - File to write
{
cups_file_t *fp; // Output file
char bckname[1024]; // Backup file
ppdcDriver *d; // Current driver
ppdcString *st; // Current string
ppdcAttr *a; // Current attribute
ppdcConstraint *co; // Current constraint
ppdcFilter *fi; // Current filter
ppdcFont *fo; // Current font
ppdcGroup *g; // Current group
ppdcOption *o; // Current option
ppdcChoice *ch; // Current choice
ppdcProfile *p; // Current color profile
ppdcMediaSize *si; // Current media size
float left, // Current left margin
bottom, // Current bottom margin
right, // Current right margin
top; // Current top margin
int dtused[PPDC_DRIVER_MAX];// Driver type usage...
// Rename the current file, if any, to .bck...
snprintf(bckname, sizeof(bckname), "%s.bck", f);
rename(f, bckname);
// Open the output file...
fp = cupsFileOpen(f, "w");
if (!fp)
{
// Can't create file; restore backup and return...
rename(bckname, f);
return (-1);
}
cupsFilePuts(fp, "// CUPS PPD Compiler " DDK_VERSION "\n\n");
// Include standard files...
cupsFilePuts(fp, "// Include necessary files...\n");
cupsFilePuts(fp, "#include <font.defs>\n");
cupsFilePuts(fp, "#include <media.defs>\n");
memset(dtused, 0, sizeof(dtused));
for (d = (ppdcDriver *)drivers->first(); d; d = (ppdcDriver *)drivers->next())
if (d->type > PPDC_DRIVER_PS && !dtused[d->type])
{
cupsFilePrintf(fp, "#include <%s.h>\n", driver_types[d->type]);
dtused[d->type] = 1;
}
// Output each driver...
for (d = (ppdcDriver *)drivers->first(); d; d = (ppdcDriver *)drivers->next())
{
// Start the driver...
cupsFilePrintf(fp, "\n// %s %s\n", d->manufacturer->value, d->model_name->value);
cupsFilePuts(fp, "{\n");
// Write the copyright stings...
for (st = (ppdcString *)d->copyright->first();
st;
st = (ppdcString *)d->copyright->next())
quotef(fp, " Copyright \"%s\"\n", st->value);
// Write other strings and values...
if (d->manufacturer->value)
quotef(fp, " Manufacturer \"%s\"\n", d->manufacturer->value);
if (d->model_name->value)
quotef(fp, " ModelName \"%s\"\n", d->model_name->value);
if (d->pc_file_name->value)
quotef(fp, " PCFileName \"%s\"\n", d->pc_file_name->value);
if (d->version->value)
quotef(fp, " Version \"%s\"\n", d->version->value);
cupsFilePrintf(fp, " DriverType %s\n", driver_types[d->type]);
if (d->model_number)
{
switch (d->type)
{
case PPDC_DRIVER_ESCP :
cupsFilePuts(fp, " ModelNumber (");
if (d->model_number & ESCP_DOTMATRIX)
cupsFilePuts(fp, " $ESCP_DOTMATRIX");
if (d->model_number & ESCP_MICROWEAVE)
cupsFilePuts(fp, " $ESCP_MICROWEAVE");
if (d->model_number & ESCP_STAGGER)
cupsFilePuts(fp, " $ESCP_STAGGER");
if (d->model_number & ESCP_ESCK)
cupsFilePuts(fp, " $ESCP_ESCK");
if (d->model_number & ESCP_EXT_UNITS)
cupsFilePuts(fp, " $ESCP_EXT_UNITS");
if (d->model_number & ESCP_EXT_MARGINS)
cupsFilePuts(fp, " $ESCP_EXT_MARGINS");
if (d->model_number & ESCP_USB)
cupsFilePuts(fp, " $ESCP_USB");
if (d->model_number & ESCP_PAGE_SIZE)
cupsFilePuts(fp, " $ESCP_PAGE_SIZE");
if (d->model_number & ESCP_RASTER_ESCI)
cupsFilePuts(fp, " $ESCP_RASTER_ESCI");
if (d->model_number & ESCP_REMOTE)
cupsFilePuts(fp, " $ESCP_REMOTE");
cupsFilePuts(fp, ")\n");
break;
case PPDC_DRIVER_PCL :
cupsFilePuts(fp, " ModelNumber (");
if (d->model_number & PCL_PAPER_SIZE)
cupsFilePuts(fp, " $PCL_PAPER_SIZE");
if (d->model_number & PCL_INKJET)
cupsFilePuts(fp, " $PCL_INKJET");
if (d->model_number & PCL_RASTER_END_COLOR)
cupsFilePuts(fp, " $PCL_RASTER_END_COLOR");
if (d->model_number & PCL_RASTER_CID)
cupsFilePuts(fp, " $PCL_RASTER_CID");
if (d->model_number & PCL_RASTER_CRD)
cupsFilePuts(fp, " $PCL_RASTER_CRD");
if (d->model_number & PCL_RASTER_SIMPLE)
cupsFilePuts(fp, " $PCL_RASTER_SIMPLE");
if (d->model_number & PCL_RASTER_RGB24)
cupsFilePuts(fp, " $PCL_RASTER_RGB24");
if (d->model_number & PCL_PJL)
cupsFilePuts(fp, " $PCL_PJL");
if (d->model_number & PCL_PJL_PAPERWIDTH)
cupsFilePuts(fp, " $PCL_PJL_PAPERWIDTH");
if (d->model_number & PCL_PJL_HPGL2)
cupsFilePuts(fp, " $PCL_PJL_HPGL2");
if (d->model_number & PCL_PJL_PCL3GUI)
cupsFilePuts(fp, " $PCL_PJL_PCL3GUI");
if (d->model_number & PCL_PJL_RESOLUTION)
cupsFilePuts(fp, " $PCL_PJL_RESOLUTION");
cupsFilePuts(fp, ")\n");
break;
case PPDC_DRIVER_LABEL :
cupsFilePuts(fp, " ModelNumber ");
switch (d->model_number)
{
case DYMO_3x0 :
cupsFilePuts(fp, "$DYMO_3x0\n");
break;
case ZEBRA_EPL_LINE :
cupsFilePuts(fp, "$ZEBRA_EPL_LINE\n");
break;
case ZEBRA_EPL_PAGE :
cupsFilePuts(fp, "$ZEBRA_EPL_PAGE\n");
break;
case ZEBRA_ZPL :
cupsFilePuts(fp, "$ZEBRA_ZPL\n");
break;
case ZEBRA_CPCL :
cupsFilePuts(fp, "$ZEBRA_CPCL\n");
break;
case INTELLITECH_PCL :
cupsFilePuts(fp, "$INTELLITECH_PCL\n");
break;
default :
cupsFilePrintf(fp, "%d\n", d->model_number);
break;
}
break;
case PPDC_DRIVER_EPSON :
cupsFilePuts(fp, " ModelNumber ");
switch (d->model_number)
{
case EPSON_9PIN :
cupsFilePuts(fp, "$EPSON_9PIN\n");
break;
case EPSON_24PIN :
cupsFilePuts(fp, "$EPSON_24PIN\n");
break;
case EPSON_COLOR :
cupsFilePuts(fp, "$EPSON_COLOR\n");
break;
case EPSON_PHOTO :
cupsFilePuts(fp, "$EPSON_PHOTO\n");
break;
case EPSON_ICOLOR :
cupsFilePuts(fp, "$EPSON_ICOLOR\n");
break;
case EPSON_IPHOTO :
cupsFilePuts(fp, "$EPSON_IPHOTO\n");
break;
default :
cupsFilePrintf(fp, "%d\n", d->model_number);
break;
}
break;
case PPDC_DRIVER_HP :
cupsFilePuts(fp, " ModelNumber ");
switch (d->model_number)
{
case HP_LASERJET :
cupsFilePuts(fp, "$HP_LASERJET\n");
break;
case HP_DESKJET :
cupsFilePuts(fp, "$HP_DESKJET\n");
break;
case HP_DESKJET2 :
cupsFilePuts(fp, "$HP_DESKJET2\n");
break;
default :
cupsFilePrintf(fp, "%d\n", d->model_number);
break;
}
cupsFilePuts(fp, ")\n");
break;
default :
cupsFilePrintf(fp, " ModelNumber %d\n", d->model_number);
break;
}
}
if (d->manual_copies)
cupsFilePuts(fp, " ManualCopies Yes\n");
if (d->color_device)
cupsFilePuts(fp, " ColorDevice Yes\n");
if (d->throughput)
cupsFilePrintf(fp, " Throughput %d\n", d->throughput);
// Output all of the attributes...
for (a = (ppdcAttr *)d->attrs->first();
a;
a = (ppdcAttr *)d->attrs->next())
if (a->text->value && a->text->value[0])
quotef(fp, " Attribute \"%s\" \"%s/%s\" \"%s\"\n",
a->name->value, a->selector->value ? a->selector->value : "",
a->text->value, a->value->value ? a->value->value : "");
else
quotef(fp, " Attribute \"%s\" \"%s\" \"%s\"\n",
a->name->value, a->selector->value ? a->selector->value : "",
a->value->value ? a->value->value : "");
// Output all of the constraints...
for (co = (ppdcConstraint *)d->constraints->first();
co;
co = (ppdcConstraint *)d->constraints->next())
{
if (co->option1->value[0] == '*')
cupsFilePrintf(fp, " UIConstraints \"%s %s", co->option1->value,
co->choice1->value ? co->choice1->value : "");
else
cupsFilePrintf(fp, " UIConstraints \"*%s %s", co->option1->value,
co->choice1->value ? co->choice1->value : "");
if (co->option2->value[0] == '*')
cupsFilePrintf(fp, " %s %s\"\n", co->option2->value,
co->choice2->value ? co->choice2->value : "");
else
cupsFilePrintf(fp, " *%s %s\"\n", co->option2->value,
co->choice2->value ? co->choice2->value : "");
}
// Output all of the filters...
for (fi = (ppdcFilter *)d->filters->first();
fi;
fi = (ppdcFilter *)d->filters->next())
cupsFilePrintf(fp, " Filter \"%s %d %s\"\n",
fi->mime_type->value, fi->cost, fi->program->value);
// Output all of the fonts...
for (fo = (ppdcFont *)d->fonts->first();
fo;
fo = (ppdcFont *)d->fonts->next())
if (!strcmp(fo->name->value, "*"))
cupsFilePuts(fp, " Font *\n");
else
cupsFilePrintf(fp, " Font \"%s\" \"%s\" \"%s\" \"%s\" %s\n",
fo->name->value, fo->encoding->value,
fo->version->value, fo->charset->value,
fo->status == PPDC_FONT_ROM ? "ROM" : "Disk");
// Output all options...
for (g = (ppdcGroup *)d->groups->first();
g;
g = (ppdcGroup *)d->groups->next())
{
if (g->options->count == 0)
continue;
if (g->text->value && g->text->value[0])
quotef(fp, " Group \"%s/%s\"\n", g->name->value, g->text->value);
else
cupsFilePrintf(fp, " Group \"%s\"\n", g->name->value);
for (o = (ppdcOption *)g->options->first();
o;
o = (ppdcOption *)g->options->next())
{
if (o->choices->count == 0)
continue;
if (o->text->value && o->text->value[0])
quotef(fp, " Option \"%s/%s\"", o->name->value, o->text->value);
else
cupsFilePrintf(fp, " Option \"%s\"", o->name->value);
cupsFilePrintf(fp, " %s %s %.1f\n",
o->type == PPDC_BOOLEAN ? "Boolean" :
o->type == PPDC_PICKONE ? "PickOne" : "PickMany",
o->section == PPDC_SECTION_ANY ? "AnySetup" :
o->section == PPDC_SECTION_DOCUMENT ? "DocumentSetup" :
o->section == PPDC_SECTION_EXIT ? "ExitServer" :
o->section == PPDC_SECTION_JCL ? "JCLSetup" :
o->section == PPDC_SECTION_PAGE ? "PageSetup" :
"Prolog",
o->order);
for (ch = (ppdcChoice *)o->choices->first();
ch;
ch = (ppdcChoice *)o->choices->next())
{
if (ch->text->value && ch->text->value[0])
quotef(fp, " %sChoice \"%s/%s\" \"%s\"\n",
o->defchoice == ch->name ? "*" : "",
ch->name->value, ch->text->value,
ch->code->value ? ch->code->value : "");
else
quotef(fp, " %sChoice \"%s\" \"%s\"\n",
o->defchoice == ch->name ? "*" : "",
ch->name->value,
ch->code->value ? ch->code->value : "");
}
}
}
// Output all of the color profiles...
for (p = (ppdcProfile *)d->profiles->first();
p;
p = (ppdcProfile *)d->profiles->next())
cupsFilePrintf(fp, " ColorProfile \"%s/%s\" %.3f %.3f "
"%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",
p->resolution->value, p->media_type->value,
p->density, p->gamma,
p->profile[0], p->profile[1], p->profile[2],
p->profile[3], p->profile[4], p->profile[5],
p->profile[6], p->profile[7], p->profile[8]);
// Output all of the media sizes...
left = 0.0;
bottom = 0.0;
right = 0.0;
top = 0.0;
for (si = (ppdcMediaSize *)d->sizes->first();
si;
si = (ppdcMediaSize *)d->sizes->next())
if (si->size_code->value && si->region_code->value)
{
// Output a custom media size...
quotef(fp, " %sCustomMedia \"%s/%s\" %.2f %.2f %.2f %.2f %.2f %.2f \"%s\" \"%s\"\n",
si->name == d->default_size ? "*" : "", si->name->value,
si->text->value, si->width, si->length, si->left, si->bottom,
si->right, si->top, si->size_code->value,
si->region_code->value);
}
else
{
// Output a standard media size...
if (fabs(left - si->left) > 0.1 ||
fabs(bottom - si->bottom) > 0.1 ||
fabs(right - si->right) > 0.1 ||
fabs(top - si->top) > 0.1)
{
cupsFilePrintf(fp, " HWMargins %.2f %.2f %.2f %.2f\n",
si->left, si->bottom, si->right, si->top);
left = si->left;
bottom = si->bottom;
right = si->right;
top = si->top;
}
cupsFilePrintf(fp, " %sMediaSize %s\n",
si->name == d->default_size ? "*" : "",
si->name->value);
}
if (d->variable_paper_size)
{
cupsFilePuts(fp, " VariablePaperSize Yes\n");
if (fabs(left - d->left_margin) > 0.1 ||
fabs(bottom - d->bottom_margin) > 0.1 ||
fabs(right - d->right_margin) > 0.1 ||
fabs(top - d->top_margin) > 0.1)
{
cupsFilePrintf(fp, " HWMargins %.2f %.2f %.2f %.2f\n",
d->left_margin, d->bottom_margin, d->right_margin,
d->top_margin);
}
cupsFilePrintf(fp, " MinSize %.2f %.2f\n", d->min_width, d->min_length);
cupsFilePrintf(fp, " MaxSize %.2f %.2f\n", d->max_width, d->max_length);
}
// End the driver...
cupsFilePuts(fp, "}\n");
}
// Close the file and return...
cupsFileClose(fp);
return (0);
}
//
// End of "$Id: ppdc-source.cxx 358 2007-09-28 22:55:07Z mike $".
//
|