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
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "glk/jacl/jacl.h"
#include "glk/jacl/language.h"
#include "glk/jacl/types.h"
#include "glk/jacl/prototypes.h"
#include "glk/jacl/csv.h"
#include "common/str.h"
namespace Glk {
namespace JACL {
struct flock {
short l_type;
short l_whence;
long l_start;
long l_len;
long l_pid;
};
#define F_DUPFD 0
#define F_GETFD 1
#define F_SETFD 2
#define F_GETFL 3
#define F_SETFL 4
#define F_GETLK 5
#define F_SETLK 6
#define F_SETLKW 7
#define F_RDLCK 0
#define F_WRLCK 1
#define F_UNLCK 2
int fcntl(int __fd, int __cmd, ...) {
return 0;
}
#ifndef strcasestr
const char *strcasestr(const char *s, const char *find) {
char c, sc;
size_t len;
if ((c = *find++) != 0) {
c = (char)tolower((unsigned char)c);
len = strlen(find);
do {
do {
if ((sc = *s++) == 0)
return (nullptr);
} while ((char)tolower((unsigned char)sc) != c);
} while (scumm_strnicmp(s, find, len) != 0);
s--;
}
return s;
}
#endif
#define MAX_TRY 10
flock read_lck;
int read_fd;
flock write_lck;
int write_fd;
char *url_encode(char *str);
char to_hex(char code);
const char *location_attributes[] = {
"VISITED ", "DARK ", "ON_WATER ", "UNDER_WATER ", "WITHOUT_AIR ", "OUTDOORS ",
"MID_AIR ", "TIGHT_ROPE ", "POLLUTED ", "SOLVED ", "MID_WATER ", "DARKNESS ",
"MAPPED ", "KNOWN ",
nullptr
};
const char *object_attributes[] = {
"CLOSED ", "LOCKED ", "DEAD ", "IGNITABLE ", "WORN ", "CONCEALING ",
"LUMINOUS ", "WEARABLE ", "CLOSABLE ", "LOCKABLE ", "ANIMATE ", "LIQUID ",
"CONTAINER ", "SURFACE ", "PLURAL ", "FLAMMABLE ", "BURNING ", "LOCATION ",
"ON ", "DAMAGED ", "FEMALE ", "POSSESSIVE ", "OUT_OF_REACH ", "TOUCHED ",
"SCORED ", "SITTING ", "NPC ", "DONE ", "GAS ", "NO_TAB ",
"NOT_IMPORTANT ", nullptr
};
const char *object_elements[] = {
"parent", "capacity", "mass", "bearing", "velocity", "next", "previous",
"child", "index", "status", "state", "counter", "points", "class", "x", "y",
nullptr
};
const char *location_elements[] = {
"north", "south", "east", "west", "northeast", "northwest", "southeast",
"southwest", "up", "down", "in", "out", "points", "class", "x", "y",
nullptr
};
struct csv_parser parser_csv;
char in_name[1024];
char out_name[1024];
Common::SeekableReadStream *infile;
Common::WriteStream *outfile;
int stack = 0;
int proxy_stack = 0;
int field_no = 0;
struct stack_type backup[STACK_SIZE];
struct proxy_type proxy_backup[STACK_SIZE];
struct function_type *resolved_function = nullptr;
struct string_type *resolved_string = nullptr;
struct string_type *new_string = nullptr;
struct string_type *current_cstring = nullptr;
struct string_type *previous_cstring = nullptr;
struct cinteger_type *new_cinteger = nullptr;
struct cinteger_type *current_cinteger = nullptr;
struct cinteger_type *previous_cinteger = nullptr;
long bit_mask;
extern int encrypted;
extern int after_from;
extern int last_exact;
extern char temp_directory[];
extern char data_directory[];
char csv_buffer[1024];
int resolved_attribute;
/* THE ITERATION VARIABLE USED FOR LOOPS */
int *loop_integer = nullptr;
int *select_integer = nullptr;
int criterion_value = 0;
int criterion_type = 0;
int criterion_negate = FALSE;
int current_level;
int execution_level;
int *ask_integer;
int new_x;
int new_y;
int interrupted = FALSE;
char string_buffer[2048];
char argument_buffer[1024];
#ifdef GLK
extern schanid_t sound_channel[];
extern strid_t game_stream;
extern winid_t mainwin;
extern winid_t statuswin;
extern winid_t current_window;
extern strid_t mainstr;
extern strid_t statusstr;
extern strid_t quotestr;
extern strid_t inputstr;
int top_of_loop = 0;
int top_of_select = 0;
int top_of_while = 0;
int top_of_iterate = 0;
int top_of_update = 0;
int top_of_do_loop = 0;
#else
extern FILE *file;
char option_buffer[2024];
int style_stack[100];
int style_index = 0;
long top_of_loop = 0;
long top_of_select = 0;
long top_of_while = 0;
long top_of_iterate = 0;
long top_of_update = 0;
long top_of_do_loop = 0;
#endif
#ifdef __NDS__
extern int bold_mode;
extern int pre_mode;
extern int reverse_mode;
extern int input_mode;
extern int subheader_mode;
extern int note_mode;
#endif
extern char user_id[];
extern char prefix[];
extern char text_buffer[];
extern char chunk_buffer[];
extern const char *word[];
extern char bookmark[];
extern char file_prompt[];
/* CONTAINED IN PARSER.C */
extern int object_list[4][MAX_OBJECTS];
extern int list_size[];
extern int max_size[];
/* CONTAINED IN ENCAPSULATE.C */
extern int quoted[];
extern struct object_type *object[];
extern struct integer_type *integer_table;
extern struct integer_type *integer[];
extern struct cinteger_type *cinteger_table;
extern struct attribute_type *attribute_table;
extern struct string_type *string_table;
extern struct string_type *cstring_table;
extern struct function_type *function_table;
extern struct function_type *executing_function;
extern struct command_type *completion_list;
extern struct word_type *grammar_table;
extern struct synonym_type *synonym_table;
extern struct filter_type *filter_table;
extern char function_name[];
extern char temp_buffer[];
extern char error_buffer[];
extern char proxy_buffer[];
extern char default_function[];
extern char override_[];
extern int noun[];
extern int wp;
extern int start_of_this_command;
extern int start_of_last_command;
extern int buffer_index;
extern int objects;
extern int integers;
extern int player;
extern int oec;
extern int *object_element_address;
extern int *object_backup_address;
extern int walkthru_running;
// VALUES FROM LOADER
extern int value_resolved;
extern Common::WriteStream *transcript;
extern char margin_string[];
char integer_buffer[16];
char called_name[1024];
char scope_criterion[24];
const char *output;
void terminate(int code) {
// FREE ANY EXTRA RAM ALLOCATED BY THE CSV PARSER
csv_free(&parser_csv);
#ifdef GLK
int index;
event_t event;
// FLUSH THE GLK WINDOW SO THE ERROR GETS DISPLAYED IMMEDIATELY.
g_vm->glk_select_poll(&event);
/* CLOSE THE SOUND CHANNELS */
for (index = 0; index < 8; index++) {
if (sound_channel[index] != nullptr) {
g_vm->glk_schannel_destroy(sound_channel[index]);
}
}
/* CLOSE THE STREAM */
if (game_stream != nullptr) {
g_vm->glk_stream_close(game_stream, nullptr);
}
g_vm->glk_exit();
#else
if (file != NULL) /* CLOSE THE GAME FILE */
fclose(file);
exit(code);
#endif
}
void build_proxy() {
int index;
proxy_buffer[0] = 0;
/* LOOP THROUGH ALL THE PARAMETERS OF THE PROXY COMMAND
AND BUILD THE MOVE TO BE ISSUED ON THE PLAYER'S BEHALF */
for (index = 1; word[index] != nullptr; index++) {
Common::strcat_s(proxy_buffer, 1024, text_of_word(index));
}
for (index = 0; index < (int)strlen(proxy_buffer); index++) {
if (proxy_buffer[index] == '~') {
proxy_buffer[index] = '\"';
}
}
//printf("--- proxy buffer = \"%s\"\n", proxy_buffer);
}
void cb1(void *s, size_t i, void *not_used) {
struct string_type *resolved_cstring;
//sprintf (temp_buffer, "Trying to set field %d to equal %s^", field_no, (const char *) s);
//write_text(temp_buffer);
Common::sprintf_s(temp_buffer, 1024, "field[%d]", field_no);
if ((resolved_cstring = cstring_resolve(temp_buffer)) != nullptr) {
//write_text("Resolved ");
//write_text(temp_buffer);
//write_text("^");
Common::strcpy_s(resolved_cstring->value, (const char *)s);
//sprintf(temp_buffer, "Setting field %d to ~%s~^", field_no, (const char *) s);
//write_text(temp_buffer);
// INCREMENT THE FIELD NUMBER SO THE NEXT ONE GETS STORED IN THE RIGHT CONSTANT
field_no++;
} else {
write_text("Can't resolve ");
write_text(temp_buffer);
write_text("^");
}
}
void cb2(int c, void *not_used) {
// THE END OF THE RECORD HAS BEEN REACHED, EXPORT THE NUMBER OF FIELDS READ
struct cinteger_type *resolved_cinteger;
if ((resolved_cinteger = cinteger_resolve("field_count")) != nullptr) {
resolved_cinteger->value = field_no;
}
}
int execute(const char *funcname) {
int index;
int counter;
int *container;
int object_1,
object_2;
if (g_vm->shouldQuit())
return 0;
/* THESE VARIABLE KEEP TRACK OF if AND endif COMMANDS TO DECIDE WHETHER
*THE CURRENT LINE OF CODE SHOULD BE EXECUTED OR NOT */
int currentLevel = 0;
int executionLevel = 0;
/* THESE ARE USED AS FILE POINTER OFFSETS TO RETURN TO FIXED
* POINTS IN THE GAME FILE */
#ifdef GLK
int before_command = 0;
#else
long before_command = 0;
#endif
Common::strlcpy(called_name, funcname, 1024);
/* GET THE FUNCTION OBJECT BY THE FUNCTION NAME */
resolved_function = function_resolve(called_name);
if (resolved_function == nullptr) {
//printf("--- failed to find %s\n", called_name);
return (FALSE);
}
#ifdef GLK
push_stack(g_vm->glk_stream_get_position(game_stream));
if (g_vm->shouldQuit())
return FALSE;
#else
push_stack(ftell(file));
#endif
top_of_loop = 0;
top_of_select = 0;
top_of_while = 0;
top_of_iterate = 0;
top_of_update = 0;
top_of_do_loop = 0;
executing_function = resolved_function;
executing_function->call_count++;
// CREATE ALL THE PASSED ARGUMENTS AS JACL INTEGER CONSTANTS
set_arguments(called_name);
// SET function_name TO THE CORE NAME STORED IN THE FUNCTION OBJECT
// LEAVING called_name TO CONTAIN THE FULL ARGUMENT LIST
Common::strlcpy(function_name, executing_function->name, 81);
Common::strlcpy(cstring_resolve("function_name")->value, executing_function->name, sizeof(((string_type *)0)->value));
//sprintf(temp_buffer, "--- starting to execute %s^", function_name);
//write_text(temp_buffer);
// JUMP TO THE POINT IN THE PROCESSED GAME FILE WHERE THIS FUNCTION STARTS
#ifdef GLK
g_vm->glk_stream_set_position(game_stream, executing_function->position, seekmode_Start);
before_command = executing_function->position;
(void)glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
#else
fseek(file, executing_function->position, SEEK_SET);
before_command = executing_function->position;
fgets(text_buffer, 1024, file);
#endif
if (encrypted) jacl_decrypt(text_buffer);
while (text_buffer[0] != 125 && !interrupted) {
encapsulate();
if (word[0] == nullptr);
else if (!strcmp(word[0], "endwhile")) {
currentLevel--;
if (currentLevel < executionLevel) {
// THIS ENDWHILE COMMAND WAS BEING EXECUTED,
// NOT JUST COUNTED.
if (top_of_while == FALSE) {
Common::sprintf_s(error_buffer, 1024, NO_WHILE, executing_function->name);
log_error(error_buffer, PLUS_STDOUT);
} else {
#ifdef GLK
g_vm->glk_stream_set_position(game_stream, top_of_while, seekmode_Start);
#else
fseek(file, top_of_while, SEEK_SET);
#endif
executionLevel = currentLevel;
}
}
} else if (!strcmp(word[0], "enditerate")) {
currentLevel--;
if (currentLevel < executionLevel) {
// THIS ENDITERATE COMMAND WAS BEING EXECUTED,
// NOT JUST COUNTED.
if (top_of_iterate == FALSE) {
Common::sprintf_s(error_buffer, 1024, NO_ITERATE, executing_function->name);
log_error(error_buffer, PLUS_STDOUT);
} else {
#ifdef GLK
g_vm->glk_stream_set_position(game_stream, top_of_iterate, seekmode_Start);
#else
fseek(file, top_of_iterate, SEEK_SET);
#endif
executionLevel = currentLevel;
}
}
} else if (!strcmp(word[0], "endupdate")) {
currentLevel--;
if (currentLevel < executionLevel) {
// THIS ENDUPDATE COMMAND WAS BEING EXECUTED,
// NOT JUST COUNTED.
if (top_of_update == FALSE) {
Common::sprintf_s(error_buffer, 1024, NO_UPDATE, executing_function->name);
log_error(error_buffer, PLUS_STDOUT);
} else {
#ifdef GLK
g_vm->glk_stream_set_position(game_stream, top_of_update, seekmode_Start);
#else
fseek(file, top_of_update, SEEK_SET);
#endif
executionLevel = currentLevel;
}
}
} else if (!strcmp(word[0], "print") && currentLevel != executionLevel) {
// SKIP THIS BLOCK OF PLAIN TEXT UNTIL IT FINDS A
// LINE THAT STARTS WITH A '.' OR A '}'
#ifdef GLK
(void)glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
#else
fgets(text_buffer, 1024, file);
#endif
if (encrypted) jacl_decrypt(text_buffer);
while (text_buffer[0] != '.') {
if (text_buffer[0] == '}') {
// HIT THE END OF THE FUNCTION, JUST BAIL OUT
return (exit_function(TRUE));
}
// GET THE NEXT LINE
#ifdef GLK
(void)glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
#else
fgets(text_buffer, 1024, file);
#endif
if (encrypted) jacl_decrypt(text_buffer);
}
} else if (!strcmp(word[0], "endif")) {
currentLevel--;
if (currentLevel < executionLevel) {
/* THIS SHOULD NEVER HAPPEN */
executionLevel = currentLevel;
}
} else if (!strcmp(word[0], "endall")) {
currentLevel = 0;
executionLevel = 0;
} else if (!strcmp(word[0], "else")) {
if (currentLevel == executionLevel) {
executionLevel--;
} else if (currentLevel == executionLevel + 1) {
executionLevel++;
}
} else if (currentLevel == executionLevel) {
if (!strcmp(word[0], "look")) {
// THIS IS JUST HERE FOR BACKWARDS COMPATIBILITY
object[HERE]->attributes &= ~1L;
look_around();
} else if (!strcmp(word[0], "repeat")) {
#ifdef GLK
top_of_do_loop = g_vm->glk_stream_get_position(game_stream);
#else
top_of_do_loop = ftell(file);
#endif
} else if (!strcmp(word[0], "until")) {
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
if (top_of_do_loop == FALSE) {
Common::sprintf_s(error_buffer, 1024, NO_REPEAT, executing_function->name);
log_error(error_buffer, PLUS_STDOUT);
} else if (!condition()) {
#ifdef GLK
g_vm->glk_stream_set_position(game_stream, top_of_do_loop, seekmode_Start);
#else
fseek(file, top_of_do_loop, SEEK_SET);
#endif
}
}
} else if (!strcmp(word[0], "untilall")) {
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
if (top_of_do_loop == FALSE) {
Common::sprintf_s(error_buffer, 1024, NO_REPEAT, executing_function->name);
log_error(error_buffer, PLUS_STDOUT);
} else if (!and_condition()) {
#ifdef GLK
g_vm->glk_stream_set_position(game_stream, top_of_do_loop, seekmode_Start);
#else
fseek(file, top_of_do_loop, SEEK_SET);
#endif
}
}
} else if (!strcmp(word[0], "iterate")) {
int i;
// A NEW iterate LOOP MEANS STARTING BACK AT THE FIRST FIELD
field_no = 0;
currentLevel++;
/* THIS LOOP COMES BACK TO THE START OF THE LINE CURRENTLY
EXECUTING, NOT THE LINE AFTER */
top_of_iterate = before_command;
// infile REMAINS OPEN DURING THE ITERATION, ONLY NEEDS
// OPENING THE FIRST TIME
if (infile == nullptr) {
Common::strcpy_s(temp_buffer, 1024, data_directory);
Common::strcat_s(temp_buffer, 1024, prefix);
Common::strcat_s(temp_buffer, 1024, "-");
Common::strcat_s(temp_buffer, 1024, text_of_word(1));
Common::strcat_s(temp_buffer, 1024, ".csv");
infile = File::openForReading(temp_buffer);
if (word[2] != nullptr && !strcmp(word[2], "skip_header")) {
assert(infile);
infile->read(csv_buffer, 1024);
}
}
if (infile == nullptr) {
Common::sprintf_s(error_buffer, 1024, "Failed to open file %s\n", temp_buffer);
log_error(error_buffer, LOG_ONLY);
infile = nullptr;
} else {
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
// IF THERE IS ANOTHER RECORD TO READ FROM THE CSV FILE THEN
// SET THE field[] CONSTANTS AND INCREMENT THE executionLevel
infile->read(csv_buffer, 1024);
if (infile->pos() < infile->size()) {
i = strlen(csv_buffer);
//sprintf (temp_buffer, "Read ~%s~ with %d bytes.^", csv_buffer, i);
//write_text(temp_buffer);
if (csv_parse(&parser_csv, csv_buffer, i, cb1, cb2, (void *) nullptr) != (uint)i) {
Common::sprintf_s(error_buffer, 1024, "Error parsing file: %s\n", csv_strerror(csv_error(&parser_csv)));
log_error(error_buffer, PLUS_STDOUT);
delete infile;
infile = nullptr;
} else {
// A LINE HAS BEEN SUCCESSFULLY READ, EXECUTE THE CONTENTS OF THE LOOP
executionLevel++;
}
} else {
delete infile;
infile = nullptr;
}
}
}
} else if (!strcmp(word[0], "update")) {
int i;
// SET UP THE RECORD LOCKING STRUCTURE, THE ADDRESS OF WHICH
// IS PASSED TO THE fcntl() SYSTEM CALL
write_lck.l_type = F_WRLCK; // SETTING A WRITE LOCK
write_lck.l_whence = 0; // OFFSET l_start FROM BEGINNING OF FILE
write_lck.l_start = 0LL;
write_lck.l_len = 0LL; // UNTIL THE END OF THE FILE ADDRESS SPACE
read_lck.l_type = F_RDLCK; // SETTING A READ LOCK
read_lck.l_whence = 0; // OFFSET l_start FROM BEGINNING OF FILE
read_lck.l_start = 0LL;
read_lck.l_len = 0LL; // UNTIL THE END OF THE FILE ADDRESS SPACE
// A NEW iterate LOOP MEANS STARTING BACK AT THE FIRST FIELD
field_no = 0;
currentLevel++;
// THIS LOOP COMES BACK TO THE START OF THE LINE CURRENTLY
// EXECUTING, NOT THE LINE AFTER
top_of_update = before_command;
// infile REMAINS OPEN DURING THE ITERATION, ONLY NEEDS
// OPENING THE FIRST TIME
if (infile == nullptr) {
Common::strcpy_s(in_name, data_directory);
Common::strcat_s(in_name, prefix);
Common::strcat_s(in_name, "-");
Common::strcat_s(in_name, text_of_word(1));
Common::strcat_s(in_name, ".csv");
infile = File::openForReading(in_name);
}
if (outfile == nullptr) {
// OPEN A TEMPORARY OUTPUT FILE TO WRITE THE MODIFICATIONS TO
Common::strcpy_s(out_name, data_directory);
Common::strcat_s(out_name, prefix);
Common::strcat_s(out_name, "-");
Common::strcat_s(out_name, text_of_word(1));
Common::strcat_s(out_name, "-");
Common::strcat_s(out_name, user_id);
Common::strcat_s(out_name, ".csv");
outfile = File::openForWriting(out_name);
}
if (infile == nullptr) {
Common::sprintf_s(error_buffer, 1024, "Failed to open input CSV file ~%s\n", in_name);
log_error(error_buffer, LOG_ONLY);
if (outfile != nullptr) {
delete outfile;
outfile = nullptr;
}
return (exit_function(TRUE));
} else {
if (outfile == nullptr) {
Common::sprintf_s(error_buffer, 1024, "Failed to open output CSV file ~%s~\n", out_name);
log_error(error_buffer, LOG_ONLY);
if (infile != nullptr) {
delete infile;
infile = nullptr;
}
return (exit_function(TRUE));
} else {
#ifdef FILE_CTL
int tryCtr = 0;
write_fd = fileno(outfile);
// ATTEMPT LOCKING OUTPUT FILE MAX_TRY TIMES BEFORE GIVING UP.
while (fcntl(write_fd, F_SETLK, &write_lck) < 0) {
if (errno == EAGAIN || errno == EACCES) {
// THERE MIGHT BE OTHER ERROR CASES IN WHICH
// USERS MIGHT TRY AGAIN
if (++tryCtr < MAX_TRY) {
jacl_sleep(1000);
continue;
}
Common::sprintf_s(error_buffer, 1024, "File busy unable to get lock on output file.\n");
log_error(error_buffer, PLUS_STDOUT);
return (exit_function(TRUE));
}
}
tryCtr = 0;
read_fd = fileno(infile);
// ATTEMPT LOCKING OUTPUT FILE MAX_TRY TIMES BEFORE GIVING UP.
while (fcntl(read_fd, F_SETLK, &read_lck) < 0) {
if (errno == EAGAIN || errno == EACCES) {
// THERE MIGHT BE OTHER ERROR CASES IN WHICH
// USERS MIGHT TRY AGAIN
if (++tryCtr < MAX_TRY) {
jacl_sleep(1000);
continue;
}
Common::sprintf_s(error_buffer, 1024, "File busy unable to get lock on input file.\n");
log_error(error_buffer, PLUS_STDOUT);
return (exit_function(TRUE));
}
}
#endif
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
// IF THERE IS ANOTHER RECORD TO READ FROM THE CSV FILE THEN
// SET THE field[] CONSTANTS AND INCREMENT THE executionLevel
infile->read(csv_buffer, 1024);
if (infile->pos() < infile->size()) {
i = strlen(csv_buffer);
if (csv_parse(&parser_csv, csv_buffer, i, cb1, cb2, (int *) &field_no) != (uint)i) {
Common::sprintf_s(error_buffer, 1024, "Error parsing file: %s\n", csv_strerror(csv_error(&parser_csv)));
log_error(error_buffer, PLUS_STDOUT);
read_lck.l_type = F_UNLCK; // SETTING A READ LOCK
fcntl(read_fd, F_SETLK, &read_lck);
delete infile;
infile = nullptr;
} else {
// A LINE HAS BEEN SUCCESSFULLY READ, EXECUTE THE CONTENTS OF THE LOOP
executionLevel++;
}
} else {
write_lck.l_type = F_UNLCK; // REMOVE THE WRITE LOCK
fcntl(write_fd, F_SETLK, &write_lck);
delete outfile;
read_lck.l_type = F_UNLCK; // REMOVE THE READ LOCK
fcntl(read_fd, F_SETLK, &read_lck);
delete infile;
rename(out_name, in_name);
outfile = nullptr;
infile = nullptr;
}
}
}
}
} else if (!strcmp(word[0], "while")) {
currentLevel++;
/* THIS LOOP COMES BACK TO THE START OF THE LINE CURRENTLY
EXECUTING, NOT THE LINE AFTER */
top_of_while = before_command;
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else if (condition()) {
executionLevel++;
}
} else if (!strcmp(word[0], "whileall")) {
currentLevel++;
/* THIS LOOP COMES BACK TO THE START OF THE LINE CURRENTLY
EXECUTING, NOT THE LINE AFTER */
top_of_while = before_command;
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else if (and_condition()) {
executionLevel++;
}
} else if (!strcmp(word[0], "loop")) {
/* THE LOOP COMMAND LOOPS ONCE FOR EACH DEFINED
* OBJECT (FOREACH) */
#ifdef GLK
top_of_loop = g_vm->glk_stream_get_position(game_stream);
#else
top_of_loop = ftell(file);
#endif
if (word[1] == nullptr) {
// IF NONE IS SUPPLIED DEFAULT TO noun3
loop_integer = &noun[2];
} else {
// STORE THE CONTAINER TO PUT THE CURRENT OBJECT IN
loop_integer = container_resolve(word[1]);
// IF THE SUPPLIED CONTAINER CAN'T BE RESOLVED
// DEFAULT TO noun3
if (loop_integer == nullptr)
loop_integer = &noun[2];
}
// SET THE VALUE OF THE LOOP INDEX TO POINT TO THE FIRST OBJECT
*loop_integer = 1;
} else if (!strcmp(word[0], "endloop")) {
if (top_of_loop == FALSE) {
Common::sprintf_s(error_buffer, 1024, NO_LOOP, executing_function->name);
log_error(error_buffer, PLUS_STDOUT);
} else {
*loop_integer += 1;
if (*loop_integer > objects) {
top_of_loop = FALSE;
*loop_integer = 0;
} else {
#ifdef GLK
g_vm->glk_stream_set_position(game_stream, top_of_loop, seekmode_Start);
#else
fseek(file, top_of_loop, SEEK_SET);
#endif
}
}
} else if (!strcmp(word[0], "select")) {
/* THE SELECT COMMAND LOOPS ONCE FOR EACH DEFINED
* OBJECT THAT MATCHES THE SUPPLIED CRITERION */
#ifdef GLK
top_of_select = g_vm->glk_stream_get_position(game_stream);
#else
top_of_select = ftell(file);
#endif
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else if (word[2] == nullptr) {
// IF NONE IS SUPPLIED DEFAULT TO noun3
select_integer = &noun[2];
} else {
// STORE THE CONTAINER TO PUT THE CURRENT OBJECT IN
select_integer = container_resolve(word[2]);
// IF THE SUPPLIED CONTAINER CAN'T BE RESOLVED
// DEFAULT TO noun3
if (select_integer == nullptr) {
select_integer = &noun[2];
}
}
// SET THE VALUE OF THE SELECT INDEX TO ONE BEFORE THE
// FIRST OBJECT. THE NEXT FUNCTION AUTOMATICALLY INCREMENTS
// THE INDEX BY ONE AT THE START OF THE WHILE LOOP.
*select_integer = 0;
if (word[1][0] == '!') {
criterion_negate = TRUE;
Common::strcpy_s(argument_buffer, &word[1][1]);
} else {
criterion_negate = FALSE;
Common::strcpy_s(argument_buffer, word[1]);
}
// DETERMINE THE CRITERION FOR SELETION
if (!strcmp(argument_buffer, "*held")
|| !strcmp(argument_buffer, "*here")
|| !strcmp(argument_buffer, "*anywhere")
|| !strcmp(argument_buffer, "*present")) {
criterion_type = CRI_SCOPE;
Common::strlcpy(scope_criterion, argument_buffer, sizeof(scope_criterion));
} else if ((criterion_value = attribute_resolve(argument_buffer))) {
criterion_type = CRI_ATTRIBUTE;
} else if ((criterion_value = user_attribute_resolve(argument_buffer))) {
criterion_type = CRI_USER_ATTRIBUTE;
} else {
// USE VALUE OF AS A CATCH ALL IF IT IS NOT AN ATTRIBUTE OR SCOPE
criterion_value = value_of(argument_buffer);
if (value_resolved) {
criterion_type = CRI_PARENT;
} else {
// CAN'T RESOLVE CRITERION
criterion_type = CRI_NONE;
}
}
if (criterion_type != CRI_NONE) {
if (select_next() == FALSE) {
*select_integer = 0;
top_of_select = 0;
}
} else {
*select_integer = 0;
}
if (*select_integer == 0) {
// THERE ARE NO MATCHING OBJECTS SO JUMP TO THE endselect
#ifdef GLK
(void)glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
#else
fgets(text_buffer, 1024, file);
#endif
if (encrypted) jacl_decrypt(text_buffer);
while (text_buffer[0] != '}') {
encapsulate();
if (word[0] != nullptr && !strcmp(word[0], "endselect")) {
break;
}
#ifdef GLK
(void)glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
#else
fgets(text_buffer, 1024, file);
#endif
}
}
} else if (!strcmp(word[0], "endselect")) {
if (top_of_select == FALSE) {
Common::sprintf_s(error_buffer, 1024, NO_LOOP, executing_function->name);
log_error(error_buffer, PLUS_STDOUT);
} else {
if (select_next(/* select_integer, criterion_type, criterion_value, scope_criterion */)) {
#ifdef GLK
g_vm->glk_stream_set_position(game_stream, top_of_select, seekmode_Start);
#else
fseek(file, top_of_select, SEEK_SET);
#endif
} else {
*select_integer = 0;
top_of_select = 0;
}
}
} else if (!strcmp(word[0], "break")) {
currentLevel++;
executionLevel--;
#ifdef GLK
} else if (!strcmp(word[0], "cursor")) {
if (word[2] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else {
if (current_window == statuswin) {
g_vm->glk_window_move_cursor(statuswin, value_of(word[1], TRUE), value_of(word[2], TRUE));
} else {
log_error(BAD_CURSOR, PLUS_STDOUT);
}
}
} else if (!strcmp(word[0], "stop")) {
int channel;
if (SOUND_SUPPORTED->value) {
/* SET THE CHANNEL TO STOP, IF SUPPLIED */
if (word[1] == nullptr) {
channel = 0;
} else {
channel = value_of(word[1], TRUE);
/* SANITY CHECK THE CHANNEL SELECTED */
if (channel < 0 || channel > 7) {
channel = 0;
}
}
g_vm->glk_schannel_stop(sound_channel[channel]);
}
} else if (!strcmp(word[0], "volume")) {
int channel, volume;
if (SOUND_SUPPORTED->value) {
/* SET THE CHANNEL TO STOP, IF SUPPLIED */
if (word[2] == nullptr) {
channel = 0;
} else {
channel = value_of(word[2], TRUE);
/* SANITY CHECK THE CHANNEL SELECTED */
if (channel < 0 || channel > 7) {
channel = 0;
}
}
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
volume = value_of(word[1], TRUE);
/* SANITY CHECK THE CHANNEL SELECTED */
if (volume < 0) {
volume = 0;
}
if (volume > 100) {
volume = 100;
}
/* STORE A COPY OF THE CURRENT VOLUME FOR ACCESS
* FROM JACL CODE */
Common::sprintf_s(temp_buffer, 1024, "volume[%d]", channel);
cinteger_resolve(temp_buffer)->value = volume;
/* NOW SCALE THE 0-100 VOLUME TO THE 0-65536 EXPECTED
* BY Glk */
volume = volume * 655;
/* SET THE VOLUME */
g_vm->glk_schannel_set_volume(sound_channel[channel], (glui32) volume);
}
}
} else if (!strcmp(word[0], "timer")) {
if (TIMER_SUPPORTED->value && TIMER_ENABLED->value) {
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
index = value_of(word[1], TRUE);
/* DON'T ALLOW NEGATIVE VALUES, BUT NO UPPER LIMIT */
if (index < 0) index = 0;
/* SET THE GLK TIMER */
g_vm->glk_request_timer_events((glui32) index);
/* EXPOSE THE CURRENT VALUE THROUGH A JACL CONSTANT
SO THAT GAME CODE CAN READ THE IT */
cinteger_resolve("timer")->value = index;
}
}
} else if (!strcmp(word[0], "sound")) {
int channel;
glui32 repeats;
if (SOUND_SUPPORTED->value && SOUND_ENABLED->value) {
/* SET THE CHANNEL TO USE, IF SUPPLIED */
if (word[2] == nullptr) {
channel = 0;
} else {
channel = value_of(word[2], TRUE);
/* SANITY CHECK THE CHANNEL SELECTED */
if (channel < 0 || channel > 7) {
channel = 0;
}
}
/* SET THE NUMBER OF REPEATS, IF SUPPLIED */
if (word[3] == nullptr) {
repeats = 1;
} else {
repeats = value_of(word[3], TRUE);
}
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
if (g_vm->glk_schannel_play_ext(sound_channel[channel], (glui32) value_of(word[1], TRUE), repeats, channel + 1) == 0) {
/* THE CHANNEL NUMBER IS PASSED SO THAT THE SOUND
* NOTIFICATION EVENT CAN USE THE INFORMATION
* IT HAS 1 ADDED TO IT SO THAT IT IS A NON-ZERO
* NUMBER AND THE EVENT IS ACTIVATED */
Common::sprintf_s(error_buffer, 1024, "Unable to play sound: %ld", value_of(word[1], FALSE));
log_error(error_buffer, PLUS_STDERR);
}
}
}
} else if (!strcmp(word[0], "image")) {
if (GRAPHICS_SUPPORTED->value && GRAPHICS_ENABLED->value) {
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
if (!g_vm->loadingSavegame() && g_vm->glk_image_draw(mainwin, (glui32) value_of(word[1], TRUE), imagealign_InlineDown, 0) == 0) {
Common::sprintf_s(error_buffer, 1024, "Unable to draw image: %ld", value_of(word[1], FALSE));
log_error(error_buffer, PLUS_STDERR);
}
}
}
} else if (!strcmp(word[0], "askstring") || !strcmp(word[0], "getstring")) {
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else {
/* GET A POINTER TO THE STRING BEING MODIFIED */
if ((resolved_string = string_resolve(word[1])) == nullptr) {
unkstrrun(word[1]);
return (exit_function(TRUE));
}
// PROMPT THE USER TO INPUT A STRING AND STORE IT IN THE
// RESOLVED VARIABLE
get_string(resolved_string->value);
}
} else if (!strcmp(word[0], "asknumber") || !strcmp(word[0], "getnumber")) {
int low, high;
int insist = FALSE;
/* THE ONLY DIFFERENCE WITH THE getnumber COMMAND IS THAT
* IT INSISTS THE PLAYER GIVES A LEGAL RESPONSE */
if (!strcmp(word[0], "getnumber")) {
insist = TRUE;
}
if (word[3] != nullptr) {
ask_integer = container_resolve(word[1]);
if (ask_integer == nullptr) {
unkvarrun(word[1]);
return (exit_function(TRUE));
}
low = value_of(word[2], TRUE);
high = value_of(word[3], TRUE);
if (high == -1 || low == -1) {
return (exit_function(TRUE));
}
*ask_integer = get_number(insist, low, high);
} else {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
}
} else if (!strcmp(word[0], "getyesorno")) {
if (word[1] != nullptr) {
ask_integer = container_resolve(word[1]);
if (ask_integer == nullptr) {
unkvarrun(word[1]);
return (exit_function(TRUE));
}
*ask_integer = get_yes_or_no();
} else {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
}
} else if (!strcmp(word[0], "clear")) {
if (!walkthru_running) {
g_vm->glk_window_clear(current_window);
}
} else if (!strcmp(word[0], "terminate")) {
terminate(0);
return 0;
} else if (!strcmp(word[0], "more")) {
if (word[1] == nullptr) {
more("[MORE]");
} else {
more(word[1]);
}
} else if (!strcmp(word[0], "style")) {
/* THIS COMMAND IS USED TO OUTPUT ANSI CODES OR SET GLK
* STREAM STYLES */
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
if (!strcmp(word[1], "bold")
|| !strcmp(word[1], "emphasised")) {
g_vm->glk_set_style(style_Emphasized);
} else if (!strcmp(word[1], "note")) {
g_vm->glk_set_style(style_Note);
} else if (!strcmp(word[1], "input")) {
g_vm->glk_set_style(style_Input);
} else if (!strcmp(word[1], "header")) {
g_vm->glk_set_style(style_Header);
} else if (!strcmp(word[1], "subheader")) {
g_vm->glk_set_style(style_Subheader);
} else if (!strcmp(word[1], "reverse")
|| !strcmp(word[1], "inverse")) {
if (current_window == mainwin) {
g_vm->glk_set_style(style_User2);
} else {
g_vm->glk_set_style(style_User1);
}
} else if (!strcmp(word[1], "pre")
|| !strcmp(word[1], "preformatted")) {
g_vm->glk_set_style(style_Preformatted);
} else if (!strcmp(word[1], "normal")) {
g_vm->glk_set_style(style_Normal);
}
}
} else if (!strcmp(word[0], "flush")) {
} else if (!strcmp(word[0], "hyperlink")) {
/* OUTPUT LINK TEXT AS PLAIN TEXT UNDER Glk */
if (word[2] == nullptr) {
noproprun();
pop_stack();
return (TRUE);
} else {
write_text(text_of_word(1));
}
#else
#ifdef __NDS__
} else if (!strcmp(word[0], "flush")) {
jflush();
} else if (!strcmp(word[0], "cursor")) {
if (word[2] == NULL) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else {
printf("\x1b[%d;%dH", (int) value_of(word[1], TRUE), (int) value_of(word[2], TRUE));
}
} else if (!strcmp(word[0], "stop")) {
} else if (!strcmp(word[0], "volume")) {
} else if (!strcmp(word[0], "timer")) {
} else if (!strcmp(word[0], "sound")) {
} else if (!strcmp(word[0], "image")) {
} else if (!strcmp(word[0], "askstring") || !strcmp(word[0], "getstring")) {
if (word[1] == NULL) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else {
/* GET A POINTER TO THE STRING BEING MODIFIED */
if ((resolved_string = string_resolve(word[1])) == NULL) {
unkstrrun(word[1]);
return (exit_function(TRUE));
}
// PROMPT THE USER TO INPUT A STRING AND STORE IT IN THE
// RESOLVED VARIABLE
get_string(resolved_string->value);
}
} else if (!strcmp(word[0], "asknumber") || !strcmp(word[0], "getnumber")) {
int low, high;
int insist = FALSE;
/* THE ONLY DIFFERENCE WITH THE getnumber COMMAND IS THAT
* IT INSISTS THE PLAYER GIVES A LEGAL RESPONSE */
if (!strcmp(word[0], "getnumber")) {
insist = TRUE;
}
if (word[3] != NULL) {
ask_integer = container_resolve(word[1]);
if (ask_integer == NULL) {
unkvarrun(word[1]);
return (exit_function(TRUE));
}
low = value_of(word[2], TRUE);
high = value_of(word[3], TRUE);
if (high == -1 || low == -1) {
return (exit_function(TRUE));
}
*ask_integer = get_number(insist, low, high);
} else {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
}
} else if (!strcmp(word[0], "getyesorno")) {
if (word[1] != NULL) {
ask_integer = container_resolve(word[1]);
if (ask_integer == NULL) {
unkvarrun(word[1]);
return (exit_function(TRUE));
}
*ask_integer = get_yes_or_no();
} else {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
}
} else if (!strcmp(word[0], "clear")) {
clrscrn();
} else if (!strcmp(word[0], "terminate")) {
terminate(0);
return;
} else if (!strcmp(word[0], "more")) {
if (word[1] == NULL) {
more("[MORE]");
} else {
more(word[1]);
}
} else if (!strcmp(word[0], "style")) {
/* THIS COMMAND IS USED TO OUTPUT ANSI CODES OR SET GLK
* STREAM STYLES */
if (word[1] == NULL) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
if (!strcmp(word[1], "bold")
|| !strcmp(word[1], "emphasised")) {
printf("\x1b[37;1m"); // SET TO BRIGHT WHITE
bold_mode = TRUE;
} else if (!strcmp(word[1], "note")) {
printf("\x1b[34;1m"); // SET TO BRIGHT BLUE
note_mode = TRUE;
} else if (!strcmp(word[1], "input")) {
printf("\x1b[32;0m"); // SET TO DIM GREEN
input_mode = TRUE;
} else if (!strcmp(word[1], "header")) {
printf("\x1b[37;0m"); // SET TO DIM WHITE
} else if (!strcmp(word[1], "subheader")) {
printf("\x1b[33;1m"); // SET TO BRIGHT YELLOW
subheader_mode = TRUE;
} else if (!strcmp(word[1], "reverse")
|| !strcmp(word[1], "inverse")) {
printf("\x1b[7m"); // SET TO DIM WHITE
reverse_mode = TRUE;
} else if (!strcmp(word[1], "pre")
|| !strcmp(word[1], "preformatted")) {
printf("\x1b[37;0m"); // SET TO DIM WHITE
pre_mode = TRUE;
} else if (!strcmp(word[1], "normal")) {
printf("\x1b[37;0m"); // SET TO DIM WHITE
bold_mode = FALSE;
pre_mode = FALSE;
reverse_mode = FALSE;
input_mode = FALSE;
subheader_mode = FALSE;
note_mode = FALSE;
}
}
} else if (!strcmp(word[0], "hyperlink")) {
/* OUTPUT LINK TEXT AS PLAIN TEXT UNDER Glk */
if (word[2] == NULL) {
noproprun();
pop_stack();
return (TRUE);
} else {
write_text(text_of_word(1));
}
#else
/* HERE STARTS THE CGIJACL-ONLY FUNCTIONS */
} else if (!strcmp(word[0], "option")) {
/* USED TO ADD AN OPTION TO AN HTML LIST */
if (word[1] == NULL) {
noproprun();
pop_stack();
return (TRUE);
} else {
index = value_of(word[1]);
if (word[2] != NULL) {
Common::sprintf_s(option_buffer, "<option value=\"%d\">",
index);
} else {
object_names(index, temp_buffer);
Common::sprintf_s(option_buffer, "<option value=\"%s\">", temp_buffer);
}
write_text(option_buffer);
list_output(index, TRUE);
write_text(temp_buffer);
}
} else if (!strcmp(word[0], "getenv")) {
struct string_type *resolved_setstring = NULL;
if (word[2] == NULL) {
noproprun();
pop_stack();
return (TRUE);
} else {
// GET A POINTER TO THE STRING BEING MODIFIED
if ((resolved_setstring = string_resolve(word[1])) == NULL) {
unkstrrun(word[1]);
return (exit_function(TRUE));
}
// COPY THE VARIABLE OF THE CGI VARIABLE INTO THE SPECIFIED STRING VARIABLE
if (getenv(text_of_word(2)) != NULL) {
Common::strlcpy(resolved_setstring->value, getenv(text_of_word(2)), 256);
} else {
resolved_setstring->value[0] = '\0';
}
}
} else if (!strcmp(word[0], "button")) {
/* USED TO CREATE AN HTML BUTTON */
if (word[1] == NULL) {
noproprun();
pop_stack();
return (TRUE);
}
if (word[2] != NULL) {
Common::sprintf_s(option_buffer, "<input class=~button~ type=~image~ src=~%s~ name=~verb~ value=~", text_of_word(2));
strcat(option_buffer, text_of_word(1));
strcat(option_buffer, "~>");
write_text(option_buffer);
} else {
Common::sprintf_s(option_buffer, "<input class=~button~ type=~submit~ style=~width: 90px; margin: 5px;~ name=~verb~ value=~%s~>", text_of_word(1));
write_text(option_buffer);
}
} else if (!strcmp(word[0], "hidden")) {
Common::sprintf_s(temp_buffer, 1024, "<INPUT TYPE=\"hidden\" NAME=\"user_id\" VALUE=\"%s\">", user_id);
write_text(temp_buffer);
} else if (!strcmp(word[0], "control")) {
/* USED TO CREATE A HYPERLINK THAT IS AN IMAGE */
if (word[2] == NULL) {
noproprun();
pop_stack();
return (TRUE);
} else {
Common::sprintf_s(option_buffer, "<a href=\"?command=%s&user_id=%s\"><img border=0 SRC=\"", text_of_word(2), user_id);
strcat(option_buffer, text_of_word(1));
strcat(option_buffer, "\"></a>");
write_text(option_buffer);
}
} else if (!strcmp(word[0], "hyperlink") || !strcmp(word[0], "hyperlinkNE")) {
string_buffer[0] = 0;
/* USED TO CREATE A HYPERLINK WITH SESSION INFORMATION INCLUDED */
if (word[2] == NULL) {
noproprun();
pop_stack();
return (TRUE);
} else {
char *encoded;
if (!strcmp(word[0], "hyperlink")) {
encoded = url_encode(text_of_word(2));
} else {
encoded = text_of_word(2);
}
if (word[3] == NULL) {
Common::sprintf_s(string_buffer, "<a href=\"?command=%s&user_id=%s\">", encoded, user_id);
strcat(string_buffer, text_of_word(1));
strcat(string_buffer, "</a>");
} else {
Common::sprintf_s(string_buffer, "<a class=\"%s\" href=\"?command=", text_of_word(3));
strcat(string_buffer, encoded);
Common::sprintf_s(option_buffer, "&user_id=%s\">%s</a>", user_id, text_of_word(1));
strcat(string_buffer, option_buffer);
}
if (!strcmp(word[0], "hyperlink")) {
free(encoded);
}
write_text(string_buffer);
}
} else if (!strcmp(word[0], "prompt")) {
/* USED TO OUTPUT A HTML INPUT CONTROL THAT CONTAINS SESSION INFORMATION */
if (word[1] != NULL) {
Common::sprintf_s(temp_buffer, 1024, "<input id=\"JACLCommandPrompt\" type=text name=~command~ onKeyPress=~%s~>\n", word[1]);
write_text(temp_buffer);
} else {
Common::sprintf_s(temp_buffer, 1024, "<input id=\"JACLCommandPrompt\" type=text name=~command~>\n");
write_text(temp_buffer);
}
Common::sprintf_s(temp_buffer, 1024, "<input type=hidden name=\"user_id\" value=\"%s\">", user_id);
write_text(temp_buffer);
} else if (!strcmp(word[0], "style")) {
/* THIS COMMAND IS USED TO OUTPUT ANSI CODES OR SET GLK
* STREAM STYLES */
if (word[1] == NULL) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
if (!strcmp(word[1], "bold")
|| !strcmp(word[1], "emphasised")) {
write_text("<b>");
style_stack[style_index++] = BOLD;
} else if (!strcmp(word[1], "note")) {
write_text("<i>");
style_stack[style_index++] = NOTE;
} else if (!strcmp(word[1], "input")) {
write_text("<i>");
style_stack[style_index++] = INPUT;
} else if (!strcmp(word[1], "header")) {
write_text("<h1>");
style_stack[style_index++] = HEADER;
} else if (!strcmp(word[1], "subheader")) {
write_text("<h2>");
style_stack[style_index++] = SUBHEADER;
} else if (!strcmp(word[1], "reverse")
|| !strcmp(word[1], "inverse")) {
write_text("<b>");
style_stack[style_index++] = REVERSE;
} else if (!strcmp(word[1], "pre")
|| !strcmp(word[1], "preformatted")) {
write_text("<pre>");
style_stack[style_index++] = PRE;
} else if (!strcmp(word[1], "normal")) {
style_index--;
for (; style_index > -1; style_index--) {
switch (style_stack[style_index]) {
case BOLD:
write_text("</b>");
break;
case NOTE:
write_text("</i>");
break;
case INPUT:
write_text("</i>");
break;
case HEADER:
write_text("</h1>");
break;
case SUBHEADER:
write_text("</h2>");
break;
case REVERSE:
write_text("</b>");
break;
case PRE:
write_text("</pre>");
break;
}
}
style_index = 0;
}
}
/* THESE FINAL COMMANDS HAVE NO EFFECT UNDER CGIJACL
AND THERE IS NO HARM IN IGNORING THEM */
} else if (!strcmp(word[0], "flush")) {
} else if (!strcmp(word[0], "image")) {
if (word[1] == NULL) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else {
if (word[2] == NULL) {
Common::sprintf_s(option_buffer, "<img src=~%s~>", text_of_word(1));
} else {
Common::sprintf_s(option_buffer, "<img class=~%s~ src=~%s~>", text_of_word(2), text_of_word(1));
}
write_text(option_buffer);
}
} else if (!strcmp(word[0], "sound")) {
if (word[2] == NULL) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else {
write_text("<audio autoplay=~autoplay~>");
if (word[3] == NULL) {
Common::sprintf_s(option_buffer, "<source src=~%s~ type=~%s~>", text_of_word(1), text_of_word(2));
write_text(option_buffer);
}
write_text("</audio>");
}
} else if (!strcmp(word[0], "cursor")) {
} else if (!strcmp(word[0], "timer")) {
} else if (!strcmp(word[0], "volume")) {
} else if (!strcmp(word[0], "askstring") || !strcmp(word[0], "getstring")) {
} else if (!strcmp(word[0], "asknumber") || !strcmp(word[0], "getnumber")) {
} else if (!strcmp(word[0], "getyesorno")) {
} else if (!strcmp(word[0], "clear")) {
} else if (!strcmp(word[0], "more")) {
} else if (!strcmp(word[0], "terminate")) {
#endif
#endif
} else if (!strcmp(word[0], "proxy")) {
/* THE PROXY COMMAND ISSUES A MOVE ON THE PLAYER'S BEHALF
* ALL STATE MUST BE SAVED SO THE CURRENT MOVE CAN CONTINUE
* ONCE THE PROXIED MOVE IS COMPLETE */
#ifdef GLK
push_stack(g_vm->glk_stream_get_position(game_stream));
#else
push_stack(ftell(file));
#endif
push_proxy();
build_proxy();
// TEXT BUFFER IS THE NORMAL ARRAY FOR HOLDING THE PLAYERS
// MOVE FOR PROCESSING
Common::strlcpy(text_buffer, proxy_buffer, 1024);
command_encapsulate();
jacl_truncate();
preparse();
pop_proxy();
pop_stack();
} else if (!strcmp(word[0], "override")) {
/* TELLS THE INTERPRETER TO LOOK FOR AN _override FUNCTION
* TO EXECUTE IN PLACE OF ANY CODE THAT FOLLOWS THIS LINE.
* THIS COMMAND IS USED EXCLUSIVELY IN GLOBAL FUNCTIONS
* ASSOCIATED WITH GRAMMAR LINES */
if (execute(override_) == TRUE) {
return (exit_function(TRUE));
} else {
if (execute(default_function) == TRUE) {
return (exit_function(TRUE));
}
}
} else if (!strcmp(word[0], "execute") || !strcmp(word[0], "call")) {
/* CALLS ANOTHER JACL FUNCTION */
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
/* RESOLVE ALL THE TEXT AND STORE IT IN A TEMPORARY BUFFER*/
string_buffer[0] = 0;
for (counter = 1; word[counter] != nullptr && counter < MAX_WORDS; counter++) {
Common::strcat_s(string_buffer, arg_text_of_word(counter));
}
if (function_resolve(string_buffer) == nullptr && !strcmp(word[0], "execute")) {
char *argstart;
/* REMOVE ANY PARAMETERS FROM FUNCTION NAME
BEFORE DISPLAYING ERROR MESSAGE */
argstart = strchr(string_buffer, '<');
if (argstart != nullptr)
*argstart = 0;
Common::sprintf_s(error_buffer, 1024, UNDEFINED_FUNCTION, executing_function->name, string_buffer);
log_error(error_buffer, PLUS_STDOUT);
} else {
execute(string_buffer);
}
}
} else if (!strcmp(word[0], "points")) {
/* INCREASE THE PLAYER'S SCORE AND POTENTIALLY INFORM THEM OF THE INCREASE */
if (word[1] != nullptr) {
SCORE->value += value_of(word[1], TRUE);
if (NOTIFY->value) {
#ifdef GLK
g_vm->glk_set_style(style_Note);
#else
#ifdef __NDS__
printf("\x1b[34;1m"); // SET TO BRIGHT BLUE
note_mode = TRUE;
#else
write_text("<b><i>");
#endif
#endif
write_text(cstring_resolve("SCORE_UP")->value);
Common::sprintf_s(temp_buffer, 1024, "%ld", value_of(word[1], TRUE));
write_text(temp_buffer);
if (value_of(word[1], TRUE) == 1) {
write_text(cstring_resolve("POINT")->value);
} else {
write_text(cstring_resolve("POINTS")->value);
}
#ifdef GLK
g_vm->glk_set_style(style_Normal);
#else
#ifdef __NDS__
printf("\x1b[37;0m"); // SET TO DIM WHITE
note_mode = FALSE;
#else
write_text("</i></b>");
#endif
#endif
}
} else {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
}
} else if (!strcmp(word[0], "print")) {
int non_space = FALSE;
// DISPLAYS A BLOCK OF PLAIN TEXT UNTIL IT FINDS A
// LINE THAT STARTS WITH A '.' OR A '}'
#ifdef GLK
(void)glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
#else
fgets(text_buffer, 1024, file);
#endif
if (encrypted) jacl_decrypt(text_buffer);
while (text_buffer[0] != '.' && text_buffer[0] != '}') {
index = 0;
non_space = FALSE;
/* REMOVE ANY NEWLINE CHARACTERS */
while (text_buffer[index] != 0) {
if (text_buffer[index] == '|' && non_space == FALSE) {
/* THE BAR CHARACTER IS CHANGED TO A SPACE TO
* ALLOW INDENTING OF NEW PARAGRAPHS ETC */
text_buffer[index] = ' ';
} else if (text_buffer[index] == '\r') {
text_buffer[index] = 0;
break;
} else if (text_buffer[index] == '\n') {
text_buffer[index] = 0;
break;
} else if (text_buffer[index] != ' ' && text_buffer[index] != '\t') {
non_space = TRUE;
}
index++;
}
if (text_buffer[0] != 0) {
// CHECK IF THERE IS THE NEED TO ADD AN
// IMPLICIT SPACE
index = strlen(text_buffer);
if (text_buffer[index - 1] == '\\') {
// A BACKSLASH IS USED TO INDICATE AN IMPLICIT
// SPACE SHOULD NOT BE PRINTED
text_buffer[index - 1] = 0;
} else if (text_buffer[index - 1] != '^') {
// ADD AN IMPLICIT SPACE IF THE PREVIOUS LINE
// DIDN'T END WITH A CARRIAGE RETURN
Common::strcat_s(text_buffer, 1024, " ");
}
// OUTPUT THE LINE READ AS PLAIN TEXT
write_text(text_buffer);
}
// GET THE NEXT LINE
#ifdef GLK
(void)glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
#else
fgets(text_buffer, 1024, file);
#endif
if (encrypted) jacl_decrypt(text_buffer);
}
} else if (!strcmp(word[0], "mesg")) {
for (counter = 1; word[counter] != nullptr && counter < MAX_WORDS; counter++) {
warning("%s", text_of_word(counter));
}
} else if (!strcmp(word[0], "error")) {
write_text("ERROR: In function ~");
write_text(executing_function->name);
write_text("~, ");
for (counter = 1; word[counter] != nullptr && counter < MAX_WORDS; counter++) {
write_text(text_of_word(counter));
}
} else if (!strcmp(word[0], "debug") && DEBUG->value) {
write_text("DEBUG: ");
for (counter = 1; word[counter] != nullptr && counter < MAX_WORDS; counter++) {
write_text(text_of_word(counter));
}
} else if (!strcmp(word[0], "write")) {
for (counter = 1; word[counter] != nullptr && counter < MAX_WORDS; counter++) {
output = text_of_word(counter);
if (*output != 0) {
// IF THE OUTPUT ISN'T AN EMPTY STRING, DISPLAY IT
write_text(output);
}
}
} else if (!strcmp(word[0], "length")) {
if (word[2] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else {
if ((container = container_resolve(word[1])) == nullptr) {
unkvarrun(word[1]);
return (exit_function(TRUE));
}
*container = strlen(text_of(word[2]));
}
} else if (!strcmp(word[0], "savegame")) {
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
if ((container = container_resolve(word[1])) == nullptr) {
unkvarrun(word[1]);
return (exit_function(TRUE));
} else {
*container = save_interaction();
}
}
} else if (!strcmp(word[0], "restoregame")) {
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
if ((container = container_resolve(word[1])) == nullptr) {
unkvarrun(word[1]);
return (exit_function(TRUE));
} else {
*container = restore_interaction();
}
}
} else if (!strcmp(word[0], "restartgame")) {
restart_game();
execute("+intro");
eachturn();
#ifdef GLK
} else if (!strcmp(word[0], "undomove")) {
undoing();
} else if (!strcmp(word[0], "updatestatus")) {
status_line();
#else
} else if (!strcmp(word[0], "undomove")) {
} else if (!strcmp(word[0], "updatestatus")) {
#endif
} else if (!strcmp(word[0], "split")) {
// 0 1 2 3 4
// split counter source delimiter destination
int *split_container;
char split_buffer[256] = "";
char container_buffer[256] = "";
char delimiter[256] = "";
char *match = nullptr;
struct string_type *resolved_splitstring = nullptr;
Common::strcpy_s(split_buffer, text_of_word(2));
Common::strcpy_s(delimiter, text_of_word(3));
char *source = split_buffer;
if (word[4] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else {
split_container = container_resolve(var_text_of_word(1));
if (split_container == nullptr) {
unkvarrun(var_text_of_word(1));
return (exit_function(TRUE));
} else {
*split_container = 0;
match = source; // THERE IS ALWAYS ONE MATCH, EVEN IF
// NO DELIMETERS ARE FOUND
while ((match = strstr(source, delimiter))) {
*match = 0;
Common::strcpy_s(container_buffer, var_text_of_word(4));
Common::strcat_s(container_buffer, "[");
Common::sprintf_s(integer_buffer, "%d", *split_container);
Common::strcat_s(container_buffer, integer_buffer);
Common::strcat_s(container_buffer, "]");
if ((resolved_splitstring = string_resolve(container_buffer)) == nullptr) {
unkstrrun(var_text_of_word(4));
return (exit_function(TRUE));
} else {
Common::strcpy_s(resolved_splitstring->value, source);
source = match + strlen(delimiter);
(*split_container)++;
}
}
Common::strcpy_s(container_buffer, var_text_of_word(4));
Common::strcat_s(container_buffer, "[");
Common::sprintf_s(integer_buffer, "%d", *split_container);
Common::strcat_s(container_buffer, integer_buffer);
Common::strcat_s(container_buffer, "]");
if ((resolved_splitstring = string_resolve(container_buffer)) == nullptr) {
unkstrrun(word[1]);
return (exit_function(TRUE));
} else {
Common::strcpy_s(resolved_splitstring->value, source);
(*split_container)++;
}
}
}
} else if (!strcmp(word[0], "setstring") ||
!strcmp(word[0], "addstring")) {
char setstring_buffer[2048] = "";
struct string_type *resolved_setstring = nullptr;
if (word[2] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else {
/* GET A POINTER TO THE STRING BEING MODIFIED */
if ((resolved_setstring = string_resolve(var_text_of_word(1))) == nullptr) {
unkstrrun(word[1]);
return (exit_function(TRUE));
}
/* RESOLVE ALL THE TEXT AND STORE IT IN A TEMPORARY BUFFER*/
for (counter = 2; word[counter] != nullptr && counter < MAX_WORDS; counter++) {
Common::strcat_s(setstring_buffer, text_of_word(counter));
}
/* setstring_buffer IS NOW FILLED, COPY THE UP TO 256 BYTES OF
* IT INTO THE STRING */
if (!strcmp(word[0], "setstring")) {
Common::strlcpy(resolved_setstring->value, setstring_buffer, 256);
} else {
/* THIS IS A addstring COMMAND, SO USE STRNCAT INSTEAD */
Common::strlcat(resolved_setstring->value, setstring_buffer, 256);
}
}
} else if (!strcmp(word[0], "padstring")) {
char setstring_buffer[2048] = "";
struct string_type *resolved_setstring = nullptr;
string_buffer[0] = 0;
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else {
/* GET A POINTER TO THE STRING BEING MODIFIED */
if ((resolved_setstring = string_resolve(word[1])) == nullptr) {
unkstrrun(word[1]);
return (exit_function(TRUE));
}
index = value_of(word[3], TRUE);
for (counter = 0; counter < index; counter++) {
Common::strcat_s(setstring_buffer, text_of_word(2));
}
/* setstring_buffer IS NOW FILLED, COPY THE UP TO 256 BYTES OF
* IT INTO THE STRING */
Common::strlcpy(resolved_setstring->value, setstring_buffer, 256);
}
} else if (!strcmp(word[0], "return")) {
/* RETURN FROM THIS FUNCTION, POSSIBLY RETURNING AN INTEGER VALUE */
if (word[1] == nullptr) {
return (exit_function(TRUE));
} else {
index = value_of(word[1], TRUE);
return (exit_function(index));
}
} else if (!strcmp(word[0], "position")) {
/* MOVE AN OBJECT TO ITS NEW X,Y COORDINATES BASED ON ITS CURRENT VALUES
* FOR x, y, bearing, velocity */
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
object_1 = value_of(word[1], TRUE);
if (object_1 < 1 || object_1 > objects) {
badptrrun(word[1], object_1);
return (exit_function(TRUE));
} else {
new_position((double) object[object_1]->X,
(double) object[object_1]->Y,
(double) object[object_1]->BEARING,
(double) object[object_1]->VELOCITY);
object[object_1]->X = new_x;
object[object_1]->Y = new_y;
}
}
} else if (!strcmp(word[0], "bearing")) {
/* CALCULATE THE BEARING BETWEEN TWO OBJECTS */
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
if ((container = container_resolve(word[1])) == nullptr) {
unkvarrun(word[1]);
return (exit_function(TRUE));
}
object_1 = value_of(word[2], TRUE);
if (object_1 < 1 || object_1 > objects) {
badptrrun(word[2], object_1);
return (exit_function(TRUE));
} else {
object_2 = value_of(word[3], TRUE);
if (object_2 < 1 || object_2 > objects) {
badptrrun(word[3], object_2);
return (exit_function(TRUE));
} else {
if (container != nullptr
&& object_1 != FALSE
&& object_2 != FALSE) {
*container = bearing((double) object[object_1]->X,
(double) object[object_1]->Y,
(double) object[object_2]->X,
(double) object[object_2]->Y);
}
}
}
}
} else if (!strcmp(word[0], "distance")) {
/* CALCULATE THE DISTANCE BETWEEN TWO OBJECTS */
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
container = container_resolve(word[1]);
object_1 = value_of(word[2], TRUE);
if (object_1 < 1 || object_1 > objects) {
badptrrun(word[2], object_1);
return (exit_function(TRUE));
} else {
object_2 = value_of(word[3], TRUE);
if (object_2 < 1 || object_2 > objects) {
badptrrun(word[3], object_2);
return (exit_function(TRUE));
} else {
if (container != nullptr
&& object_1 != FALSE
&& object_2 != FALSE) {
*container = distance((double)
object[object_1]->X,
(double)
object[object_1]->Y,
(double)
object[object_2]->X,
(double)
object[object_2]->Y);
}
}
}
}
} else if (!strcmp(word[0], "dir_to") ||
!strcmp(word[0], "npc_to")) {
/* CALCULATE THE FIRST DIRECTION TO TRAVEL IN GET TO
* A SPECIFIED LOCATION */
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
container = container_resolve(word[1]);
object_1 = value_of(word[2], TRUE);
if (object_1 < 1 || object_1 > objects) {
badptrrun(word[2], object_1);
return (exit_function(TRUE));
} else {
object_2 = value_of(word[3], TRUE);
if (object_2 < 1 || object_2 > objects) {
badptrrun(word[3], object_2);
return (exit_function(TRUE));
} else {
if (container != nullptr
&& object_1 != FALSE
&& object_2 != FALSE) {
if (!strcmp(word[0], "dir_to")) {
*container = find_route(object_1, object_2, TRUE);
} else {
*container = find_route(object_1, object_2, FALSE);
}
}
}
}
}
} else if (!strcmp(word[0], "set")) {
/* SET THE VALUE OF AN ELEMENT TO A SUPPLIED INTEGER */
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
container = container_resolve(var_text_of_word(1));
if (container == nullptr) {
unkvarrun(word[1]);
return (exit_function(TRUE));
} else {
int mark = 2; // SET mark TO POINT TO THE FIRST OPERATOR
while (word[mark + 1] != nullptr) {
counter = value_of(word[mark + 1], TRUE);
if (word[mark][0] == '+')
*container += counter;
else if (word[mark][0] == '-')
*container -= counter;
else if (word[mark][0] == '*')
*container = *container * counter;
else if (word[mark][0] == '%')
*container = *container % counter;
else if (word[mark][0] == '/') {
if (counter == 0) {
Common::sprintf_s(error_buffer, 1024, DIVIDE_BY_ZERO,
executing_function->name);
log_error(error_buffer, PLUS_STDOUT);
} else
*container = *container / counter;
} else if (!strcmp(word[mark], "locationof")) {
*container = grand_of(counter, FALSE);
} else if (!strcmp(word[mark], "grandof")) {
*container = grand_of(counter, TRUE);
} else if (word[mark][0] == '=') {
*container = counter;
} else {
Common::sprintf_s(error_buffer, 1024, ILLEGAL_OPERATOR,
executing_function->name,
word[2]);
log_error(error_buffer, PLUS_STDOUT);
}
mark += 2;
}
}
}
} else if (!strcmp(word[0], "ensure")) {
/* USED TO GIVE OR TAKE AN ATTRIBUTE TO OR FROM AND OBJECT */
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
} else {
if ((bit_mask = attribute_resolve(arg_text_of(word[3])))) {
index = value_of(word[1], TRUE);
if (index < 1 || index > objects) {
badptrrun(word[1], index);
return (exit_function(TRUE));
} else {
if (!strcmp(word[2], "has")) {
object[index]->attributes =
object[index]->attributes | bit_mask;
} else if (!strcmp(word[2], "hasnt")) {
bit_mask = ~bit_mask;
object[index]->attributes =
object[index]->attributes & bit_mask;
}
}
} else if ((bit_mask = user_attribute_resolve(arg_text_of(word[3])))) {
index = value_of(word[1], TRUE);
if (index < 1 || index > objects) {
badptrrun(word[1], index);
return (exit_function(TRUE));
} else {
if (!strcmp(word[2], "has")) {
object[index]->user_attributes =
object[index]->user_attributes | bit_mask;
} else if (!strcmp(word[2], "hasnt")) {
bit_mask = ~bit_mask;
object[index]->user_attributes =
object[index]->user_attributes & bit_mask;
}
}
} else {
unkattrun(3);
return (exit_function(TRUE));
}
}
} else if (!strcmp(word[0], "append")) {
int first = TRUE;
if (word[2] == nullptr) {
// NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND
noproprun();
return (exit_function(TRUE));
} else {
Common::strcpy_s(temp_buffer, 1024, data_directory);
Common::strcat_s(temp_buffer, 1024, prefix);
Common::strcat_s(temp_buffer, 1024, "-");
Common::strcat_s(temp_buffer, 1024, text_of_word(1));
Common::strcat_s(temp_buffer, 1024, ".csv");
outfile = File::openForWriting(temp_buffer);
if (outfile == nullptr) {
Common::sprintf_s(error_buffer, 1024, "Failed to open file %s\n", temp_buffer);
log_error(error_buffer, PLUS_STDOUT);
} else {
for (counter = 2; word[counter] != nullptr && counter < MAX_WORDS; counter++) {
output = text_of_word(counter);
if (*output != 0) {
if (first == FALSE) {
outfile->writeByte(',');
}
csv_fwrite(outfile, output, (size_t) strlen(output));
first = FALSE;
}
}
// TERMINATE THE LINE
outfile->writeByte('\n');
// FLUSH AND CLOSE THE FILE
outfile->flush();
}
delete outfile;
outfile = nullptr;
}
} else if (!strcmp(word[0], "insert")) {
int first = TRUE;
if (word[1] == nullptr) {
// NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND
noproprun();
return (exit_function(TRUE));
} else {
if (outfile == nullptr) {
log_error("Insert statement not inside an 'update' loop.", PLUS_STDOUT);
} else {
for (counter = 1; word[counter] != nullptr && counter < MAX_WORDS; counter++) {
output = text_of_word(counter);
if (*output != 0) {
if (first == FALSE) {
outfile->writeByte(',');
}
csv_fwrite(outfile, output, (size_t) strlen(output));
first = FALSE;
}
}
// TERMINATE THE LINE
outfile->writeByte('\n');
}
}
} else if (!strcmp(word[0], "inspect")) {
if (word[1] == nullptr) {
// NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND
noproprun();
return (exit_function(TRUE));
} else {
inspect(value_of(word[1], TRUE));
}
} else if (!strcmp(word[0], "move")) {
/* THIS COMMAND IS USED TO MOVE AN OBJECT TO HAVE ANOTHER PARENT
* INCLUDING MODIFYING ALL QUANTITY VALUES BASED ON THE OBJECTS MASS */
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun();
return (exit_function(TRUE));
}
index = value_of(word[1], TRUE);
if (index < 1 || index > objects) {
badptrrun(word[1], index);
return (exit_function(TRUE));
} else {
object_2 = object[index]->PARENT;
if (object_2 && !(object[object_2]->attributes & LOCATION)) {
object[object_2]->QUANTITY += object[index]->MASS;
}
object_1 = value_of(word[3], TRUE);
if (object_1 < 1 || object_1 > objects) {
badptrrun(word[1], object_1);
return (exit_function(TRUE));
} else {
object[index]->PARENT = object_1;
if (!(object[object_1]->attributes & LOCATION))
object[object_1]->QUANTITY -= object[index]->MASS;
}
}
} else if (!strcmp(word[0], "ifstringall")) {
/* CHECK IF A STRING EQUALS OR CONTAINS ANOTHER STRING */
currentLevel++;
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else if (and_strcondition()) {
executionLevel++;
}
} else if (!strcmp(word[0], "ifstring")) {
/* CHECK IF A STRING EQUALS OR CONTAINS ANOTHER STRING */
currentLevel++;
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else if (strcondition()) {
executionLevel++;
}
} else if (!strcmp(word[0], "ifexecute")) {
currentLevel++;
if (word[1] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else {
/* RESOLVE ALL THE TEXT AND STORE IT IN A TEMPORARY BUFFER*/
string_buffer[0] = 0;
for (counter = 1; word[counter] != nullptr && counter < MAX_WORDS; counter++) {
Common::strcat_s(string_buffer, arg_text_of_word(counter));
}
if (execute(string_buffer)) {
executionLevel++;
}
}
} else if (!strcmp(word[0], "if")) {
currentLevel++;
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else if (condition()) {
executionLevel++;
}
} else if (!strcmp(word[0], "ifall")) {
currentLevel++;
if (word[3] == nullptr) {
/* NOT ENOUGH PARAMETERS SUPPLIED FOR THIS COMMAND */
noproprun(0);
return (exit_function(TRUE));
} else if (and_condition()) {
executionLevel++;
}
} else {
Common::sprintf_s(error_buffer, 1024, UNKNOWN_COMMAND,
executing_function->name, word[0]);
log_error(error_buffer, PLUS_STDOUT);
}
} else if (!strcmp(word[wp], "if")
|| !strcmp(word[wp], "ifall")
|| !strcmp(word[wp], "ifstring")
|| !strcmp(word[wp], "ifstringall")
|| !strcmp(word[wp], "ifexecute")
|| !strcmp(word[wp], "iterate")
|| !strcmp(word[wp], "update")
|| !strcmp(word[wp], "while")
|| !strcmp(word[wp], "whileall")) {
currentLevel++;
}
#ifdef GLK
if (g_vm->shouldQuit())
return 0;
before_command = g_vm->glk_stream_get_position(game_stream);
(void)glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
#else
before_command = ftell(file);
fgets(text_buffer, 1024, file);
#endif
if (encrypted) jacl_decrypt(text_buffer);
};
return (exit_function(TRUE));
}
int exit_function(int return_code) {
if (infile != nullptr) {
read_lck.l_type = F_UNLCK; // SETTING A READ LOCK
fcntl(read_fd, F_SETLK, &read_lck);
delete infile;
infile = nullptr;
}
if (outfile != nullptr) {
write_lck.l_type = F_UNLCK; // SETTING A WRITE LOCK
fcntl(write_fd, F_SETLK, &write_lck);
delete outfile;
outfile = nullptr;
}
/* POP THE STACK REGARDLESS OF THE RETURN CODE */
pop_stack();
return (return_code);
}
char *object_names(int object_index, char *names_buffer) {
/* THIS FUNCTION CREATES A LIST OF ALL AN OBJECT'S NAMES.
THE escape ARGUMENT INDICATES WHETHER A + SIGN SHOULD BE
USED IN PLACE OF A SPACE BETWEEN EACH OF THE NAMES */
struct name_type *current_name = object[object_index]->first_name;
names_buffer[0] = 0;
while (current_name != nullptr) {
Common::strcat_s(names_buffer, 1024, " ");
Common::strcat_s(names_buffer, 1024, current_name->name);
current_name = current_name->next_name;
}
return names_buffer;
}
int distance(double x1, double y1, double x2, double y2) {
/* THIS FUNCTION CALCULATES THE DISTANCE BETWEEN TWO POINTS IN A
TWO-DIMENSIONAL PLANE */
double delta_x,
delta_y;
double distance,
total;
/*
* Object two in which quadrant compared to object one? 0 x = opp, y =
* ajd + 0 degrees 1 x = adj, y = opp + 90 degrees 2 x = opp, y = ajd
* + 180 degrees 3 x = adj, y = opp + 270 degrees
*/
/*
* DETERMINE WHICH QUADRANT OBJECT TWO IS IN
*/
if (x2 > x1) {
/*
* OBJECT TWO IS IN 1 OR 2
*/
delta_x = x2 - x1;
if (y2 > y1) {
delta_y = y2 - y1;
} else {
delta_y = y1 - y2;
}
} else {
/*
* OBJECT TWO IS IN 3 OR 4
*/
delta_x = x1 - x2;
if (y2 > y1) {
delta_y = y2 - y1;
} else {
delta_y = y1 - y2;
}
}
delta_y = delta_y * delta_y;
delta_x = delta_x * delta_x;
total = delta_y + delta_x;
distance = sqrt(total);
return ((int) distance);
}
void new_position(double x1, double y1, double bearing, double velocity) {
double delta_x,
delta_y;
double radians;
/*
* Object two in which quadrant compared to object one? 0 x = opp, y =
* ajd + 0 degrees 1 x = adj, y = opp + 90 degrees 2 x = opp, y = ajd
* + 180 degrees 3 x = adj, y = opp + 270 degrees
*/
/*
* sin finds opp, cos finds adj
*/
if (bearing < 91) {
radians = bearing * 2.0 * M_PI / 360.;
delta_x = velocity * sin(radians);
delta_y = velocity * cos(radians);
new_x = x1 + delta_x;
new_y = y1 + delta_y;
} else if (bearing < 181) {
bearing -= 90;
radians = bearing * 2.0 * M_PI / 360.;
delta_y = velocity * sin(radians);
delta_x = velocity * cos(radians);
new_x = x1 + delta_x;
new_y = y1 - delta_y;
} else if (bearing < 271) {
bearing -= 180;
radians = bearing * 2.0 * M_PI / 360.;
delta_x = velocity * sin(radians);
delta_y = velocity * cos(radians);
new_x = x1 - delta_x;
new_y = y1 - delta_y;
} else {
bearing -= 270;
radians = bearing * 2.0 * M_PI / 360.;
delta_y = velocity * sin(radians);
delta_x = velocity * cos(radians);
new_x = x1 - delta_x;
new_y = y1 + delta_y;
}
}
int bearing(double x1, double y1, double x2, double y2) {
int quadrant;
double delta_x,
delta_y;
double oppoadj;
double bearing;
/*
* Object two in which quadrant compared to object one? 0 x = opp, y =
* ajd + 0 degrees 1 x = adj, y = opp + 90 degrees 2 x = opp, y = ajd
* + 180 degrees 3 x = adj, y = opp + 270 degrees
*/
if (x2 > x1) {
delta_x = x2 - x1;
if (y2 > y1) {
quadrant = 0;
delta_y = y2 - y1;
oppoadj = delta_x / delta_y;
} else {
quadrant = 1;
delta_y = y1 - y2;
oppoadj = delta_y / delta_x;
}
} else {
delta_x = x1 - x2;
if (y2 > y1) {
quadrant = 3;
delta_y = y2 - y1;
oppoadj = delta_y / delta_x;
} else {
quadrant = 2;
delta_y = y1 - y2;
oppoadj = delta_x / delta_y;
}
}
bearing = atan(oppoadj);
bearing = bearing / (2.0 * M_PI) * 360.;
bearing = bearing + (90 * quadrant);
return ((int) bearing);
}
void set_arguments(const char *function_call) {
/* THIS FUNCTION CREATES AN ARRAY OF JACL INTEGER CONSTANTS TO
REPRESENT THE ARGUMENTS PASSED TO A JACL FUNCTION */
int index,
counter,
length;
int position = 0; /* STORE THE INDEX OF THE WORD */
/* SETTING new_word TO FALSE SKIPS THE FIRST */
/* WORD WHICH IS THE FUNCTION NAME */
int new_word = FALSE;
char *arg_ptr[MAX_WORDS];
int arg_value[MAX_WORDS];
struct integer_type *resolved_integer;
struct cinteger_type *resolved_cinteger;
/* SPLIT UP THE FUNCTION CALL STRING AND EXTRACT THE ARGUMENTS */
length = strlen(function_call);
for (index = 0; index < length; index++) {
if (function_call[index] == '<') {
argument_buffer[index] = 0;
new_word = TRUE;
} else {
// COPY THE CHARACTER FROM THE CALLED NAME INTO THE CURRENT
// ARGUMENT BUFFER
argument_buffer[index] = function_call[index];
if (new_word) {
// THIS IS THE FIRST CHARACTER OF A NEW ARGUMENT SO STORE
// THE ADDRESS OF THIS CHARACTER IN THE ARGUMENT BUFFER
arg_ptr[position] = &argument_buffer[index];
new_word = FALSE;
if (position < MAX_WORDS)
position++;
}
}
}
argument_buffer[index] = 0;
/* CLEAR THE NEXT ARGUMENT POINTER */
arg_ptr[position] = nullptr;
/* STORE THE INTEGER VALUE OF EACH ARGUMENT PASSED*/
index = 0;
while (arg_ptr[index] != nullptr) {
//arg_value[index] = value_of(arg_ptr[index], TRUE);
if ((resolved_integer = integer_resolve(arg_ptr[index])) != nullptr) {
arg_value[index] = resolved_integer->value;
} else if ((resolved_cinteger = cinteger_resolve(arg_ptr[index])) != nullptr) {
arg_value[index] = resolved_cinteger->value;
} else if (object_element_resolve(arg_ptr[index])) {
arg_value[index] = oec;
} else if ((counter = object_resolve(arg_ptr[index])) != -1) {
if (counter < 1 || counter > objects) {
badptrrun(arg_ptr[index], counter);
pop_stack();
return;
} else {
arg_value[index] = counter;
}
} else if (validate(arg_ptr[index])) {
arg_value[index] = atoi(arg_ptr[index]);
} else {
arg_value[index] = -1;
}
index++;
}
/* THE CURRENT ARGUMENTS HAVE ALREADY BEEN PUSHED ONTO THE STACK
* AND STORED IF PASSED AS AN ARGUMENT TO THIS FUNCTION SO IT IS
* OKAY TO CLEAR THEM AND SET THE NEW VALUES */
clear_cinteger("arg");
clear_cstring("string_arg");
/* CREATE A CONSTANT FOR EACH ARGUMENT AFTER THE CORE FUNCTION NAME */
index = 0;
while (arg_ptr[index] != nullptr) {
if (index == 0) noun[3] = arg_value[index];
add_cinteger("arg", arg_value[index]);
//printf("--- %s = %s\n", arg_ptr[index], arg_text_of(arg_ptr[index]));
add_cstring("string_arg", arg_text_of(arg_ptr[index]));
index++;
}
}
void pop_stack() {
int index, counter;
stack--;
clear_cinteger("arg");
clear_cstring("string_arg");
/* RECREATE THE arg ARRAY FOR THIS STACK FRAME */
for (index = 0; index < backup[stack].argcount; index++) {
if (index == 0) noun[3] = backup[stack].arguments[0];
add_cinteger("arg", backup[stack].arguments[index]);
}
/* RECREATE THE string_arg ARRAY FOR THIS STACK FRAME */
for (index = 0; index < backup[stack].argcount; index++) {
add_cstring("string_arg", backup[stack].str_arguments[index]);
}
/* RESTORE THE CONTENTS OF text_buffer */
for (counter = 0; counter < 1024; counter++)
text_buffer[counter] = backup[stack].text_buffer[counter];
/* RESTORE THE CONTENTS OF called_name */
//for (counter = 0; counter < 256; counter++)
//called_name[counter] = backup[stack].called_name[counter];
Common::strlcpy(called_name, backup[stack].called_name, 1024);
/* RESTORE THE CONTENTS OF scope_criterion */
//for (counter = 0; counter < 21; counter++)
// scope_criterion[counter] = backup[stack].scope_criterion[counter];
Common::strlcpy(scope_criterion, backup[stack].scope_criterion, sizeof(scope_criterion));
/* RESTORE THE STORED FUNCTION NAMES THAT ARE USED WHEN AN
* 'override' COMMAND IS ENCOUNTERED IN THE CURRENT FUNCTION */
Common::strlcpy(override_, backup[stack]._override, 81);
Common::strlcpy(default_function, backup[stack].default_function, 84);
/* RESTORE ALL THE WORD POINTERS */
for (counter = 0; counter < MAX_WORDS; counter++) {
word[counter] = backup[stack].word[counter];
quoted[counter] = backup[stack].quoted[counter];
}
executing_function = backup[stack].function;
if (executing_function != nullptr) {
Common::strlcpy(function_name, executing_function->name, 81);
Common::strlcpy(cstring_resolve("function_name")->value, executing_function->name, 81);
}
wp = backup[stack].wp;
top_of_loop = backup[stack].top_of_loop;
outfile = backup[stack].outfile;
infile = backup[stack].infile;
top_of_select = backup[stack].top_of_select;
top_of_while = backup[stack].top_of_while;
top_of_iterate = backup[stack].top_of_iterate;
top_of_update = backup[stack].top_of_update;
top_of_do_loop = backup[stack].top_of_do_loop;
criterion_value = backup[stack].criterion_value;
criterion_type = backup[stack].criterion_type;
criterion_negate = backup[stack].criterion_negate;
current_level = backup[stack].current_level;
execution_level = backup[stack].execution_level;
loop_integer = backup[stack].loop_integer;
select_integer = backup[stack].select_integer;
#ifdef GLK
g_vm->glk_stream_set_position(game_stream, backup[stack].address, seekmode_Start);
#else
fseek(file, backup[stack].address, SEEK_SET);
#endif
}
void push_stack(int32 file_pointer) {
/* COPY ALL THE CURRENT SYSTEM DATA ONTO THE STACK */
int index;
int counter = 0;
if (stack == STACK_SIZE) {
log_error("Stack overflow.", PLUS_STDERR);
terminate(45);
return;
} else {
backup[stack].infile = infile;
infile = nullptr;
backup[stack].outfile = outfile;
outfile = nullptr;
backup[stack].function = executing_function;
backup[stack].address = file_pointer;
backup[stack].wp = wp;
backup[stack].top_of_loop = top_of_loop;
backup[stack].top_of_select = top_of_select;
backup[stack].top_of_while = top_of_while;
backup[stack].top_of_iterate = top_of_iterate;
backup[stack].top_of_update = top_of_update;
backup[stack].top_of_do_loop = top_of_do_loop;
backup[stack].criterion_value = criterion_value;
backup[stack].criterion_type = criterion_type;
backup[stack].criterion_negate = criterion_negate;
backup[stack].current_level = current_level;
backup[stack].execution_level = execution_level;
backup[stack].loop_integer = loop_integer;
backup[stack].select_integer = select_integer;
/* MAKE A COPY OF THE CURRENT CONTENTS OF text_buffer */
for (counter = 0; counter < 1024; counter++)
backup[stack].text_buffer[counter] = text_buffer[counter];
/* MAKE A COPY OF THE CURRENT CONTENTS OF called_name */
Common::strlcpy(backup[stack].called_name, called_name, 1024);
// MAKE A COPY OF THE CURRENT CONTENTS OF scope_criterion
Common::strlcpy(backup[stack].scope_criterion, scope_criterion, 21);
/* COPY THE STORED FUNCTION NAMES THAT ARE USED WHEN AN
* 'override' COMMAND IS ENCOUNTERED IN THE CURRENT FUNCTION */
Common::strlcpy(backup[stack]._override, override_, 81);
Common::strlcpy(backup[stack].default_function, default_function, 81);
/* PUSH ALL THE WORD POINTERS ONTO THE STACK */
for (counter = 0; counter < MAX_WORDS; counter++) {
backup[stack].word[counter] = word[counter];
backup[stack].quoted[counter] = quoted[counter];
}
// PUSH ALL THE ARGUMENTS AS INTEGERS ONTO THE STACK
index = 0;
current_cinteger = cinteger_table;
if (current_cinteger != nullptr) {
do {
if (!strcmp(current_cinteger->name, "arg")) {
backup[stack].arguments[index++] = current_cinteger->value;
}
current_cinteger = current_cinteger->next_cinteger;
} while (current_cinteger != nullptr);
}
// STORE THE NUMBER OF ARGUMENTS PASSED TO THIS FUNCTION
// THIS IS THE SAME NUMBER FOR STRINGS AND INTEGERS
backup[stack].argcount = index;
// PUSH ALL THE ARGUMENTS AS STRINGS STRING ONTO THE STACK
index = 0;
current_cstring = cstring_table;
if (current_cstring != nullptr) {
do {
if (!strcmp(current_cstring->name, "string_arg")) {
Common::strlcpy(backup[stack].str_arguments[index++], current_cstring->value, 256);
}
current_cstring = current_cstring->next_string;
} while (current_cstring != nullptr);
}
}
// PUSH ON TO THE NEXT STACK FRAME
stack++;
}
void pop_proxy() {
int index, counter;
proxy_stack--;
clear_cinteger("$integer");
clear_cstring("$string");
clear_cstring("$word");
/* RECREATE THE integer ARRAY FOR THIS STACK FRAME */
for (index = 0; index < proxy_backup[proxy_stack].integercount; index++) {
add_cinteger("$integer", proxy_backup[proxy_stack].integer[index]);
}
/* RECREATE THE text ARRAY FOR THIS STACK FRAME */
for (index = 0; index < proxy_backup[proxy_stack].textcount; index++) {
add_cstring("$string", proxy_backup[proxy_stack].text[index]);
}
/* RECREATE THE $word ARRAY FOR THIS STACK FRAME */
for (index = 0; index < proxy_backup[proxy_stack].commandcount; index++) {
add_cstring("$word", proxy_backup[proxy_stack].command[index]);
}
/* RESTORE ALL THE NOUN POINTERS */
for (counter = 0; counter < 4; counter++)
noun[counter] = proxy_backup[proxy_stack].object_pointers[counter];
/* PUSH ALL THE RESOLVED OBJECTS ONTO THE STACK */
for (index = 0; index < 4; index++) {
list_size[index] = proxy_backup[proxy_stack].list_size[index];
max_size[index] = proxy_backup[proxy_stack].max_size[index];
for (counter = 0; counter < max_size[index]; counter++) {
object_list[index][counter] = proxy_backup[proxy_stack].object_list[index][counter];
}
}
start_of_this_command = proxy_backup[proxy_stack].start_of_this_command;
start_of_last_command = proxy_backup[proxy_stack].start_of_last_command;
after_from = proxy_backup[proxy_stack].after_from;
last_exact = proxy_backup[proxy_stack].last_exact;
}
void push_proxy() {
/* COPY ALL THE CURRENT SYSTEM DATA ONTO THE STACK */
int index;
int counter = 0;
int command = 0;
int text = 0;
current_cinteger = cinteger_table;
current_cstring = cstring_table;
if (proxy_stack == STACK_SIZE) {
log_error("Stack overflow.", PLUS_STDERR);
terminate(45);
return;
} else {
proxy_backup[proxy_stack].start_of_this_command = start_of_this_command;
proxy_backup[proxy_stack].start_of_last_command = start_of_last_command;
/* PUSH ALL THE OBJECT POINTERS ONTO THE STACK */
for (counter = 0; counter < 4; counter++)
proxy_backup[proxy_stack].object_pointers[counter] = noun[counter];
/* PUSH ALL THE RESOLVED OBJECTS ONTO THE STACK */
for (index = 0; index < 4; index++) {
for (counter = 0; counter < max_size[index]; counter++) {
proxy_backup[proxy_stack].object_list[index][counter]
= object_list[index][counter];
}
proxy_backup[proxy_stack].list_size[index] = list_size[index];
proxy_backup[proxy_stack].max_size[index] = max_size[index];
}
/* PUSH ALL THE CURRENT COMMAND INTEGERS ONTO THE STACK */
counter = 0;
if (current_cinteger != nullptr) {
do {
if (!strcmp(current_cinteger->name, "$integer")) {
proxy_backup[proxy_stack].integer[counter++] = current_cinteger->value;
}
current_cinteger = current_cinteger->next_cinteger;
} while (current_cinteger != nullptr);
}
proxy_backup[proxy_stack].integercount = counter;
// PUSH ALL THE TEXT STRING SUPPLIED BY THE CURRENT COMMAND ONTO THE STACK
text = 0;
command = 0;
if (current_cstring != nullptr) {
do {
if (!strcmp(current_cstring->name, "$string")) {
Common::strlcpy(proxy_backup[proxy_stack].text[text++], current_cstring->value, 256);
counter++;
} else if (!strcmp(current_cstring->name, "$word")) {
Common::strlcpy(proxy_backup[proxy_stack].command[command++], current_cstring->value, 256);
}
current_cstring = current_cstring->next_string;
} while (current_cstring != nullptr);
}
proxy_backup[proxy_stack].textcount = counter;
proxy_backup[proxy_stack].commandcount = command;
proxy_backup[proxy_stack].after_from = after_from;
proxy_backup[proxy_stack].last_exact = last_exact;
}
// PUSH ON TO THE NEXT STACK FRAME
proxy_stack++;
}
int condition() {
/* COMPARE GROUPS OF TWO ELEMENTS. RETURN TRUE IF ANY ONE GROUP OF
* ELEMENTS COMPARE 'TRUE' */
int first;
first = 1;
while (word[first + 2] != nullptr && ((first + 2) < MAX_WORDS)) {
if (logic_test(first))
return (TRUE);
else
first = first + 3;
}
return (FALSE);
}
int and_condition() {
/* COMPARE GROUPS OF TWO ELEMENTS. RETURN FALSE IF ANY ONE GROUP OF
* ELEMENTS COMPARE 'FALSE' */
int first;
first = 1;
while (word[first + 2] != nullptr && ((first + 2) < MAX_WORDS)) {
if (logic_test(first) == FALSE)
return (FALSE);
else
first = first + 3;
}
return (TRUE);
}
int logic_test(int first) {
long index,
compare;
resolved_attribute = FALSE;
index = value_of(word[first], TRUE);
compare = value_of(word[first + 2], TRUE);
if (!strcmp(word[first + 1], "=") || !strcmp(word[first + 1], "==")) {
if (index == compare)
return (TRUE);
else
return (FALSE);
} else if (!strcmp(word[first + 1], ">")) {
if (index > compare)
return (TRUE);
else
return (FALSE);
} else if (!strcmp(word[first + 1], "<")) {
if (index < compare)
return (TRUE);
else
return (FALSE);
} else if (!strcmp(word[first + 1], "is")) {
if (index < 1 || index > objects) {
unkobjrun(first);
return (FALSE);
} else
return (scope(index, word[first + 2]));
} else if (!strcmp(word[first + 1], "isnt")) {
if (index < 1 || index > objects) {
unkobjrun(first);
return (FALSE);
} else
return (!scope(index, word[first + 2]));
} else if (!strcmp(word[first + 1], "has"))
if (index < 1 || index > objects) {
unkobjrun(first);
return (FALSE);
} else {
if (resolved_attribute == SYSTEM_ATTRIBUTE) {
return (object[index]->attributes & compare);
} else {
return (object[index]->user_attributes & compare);
}
}
else if (!strcmp(word[first + 1], "hasnt"))
if (index < 1 || index > objects) {
unkobjrun(first);
return (FALSE);
} else {
if (resolved_attribute == SYSTEM_ATTRIBUTE) {
return (!(object[index]->attributes & compare));
} else {
return (!(object[index]->user_attributes & compare));
}
}
else if (!strcmp(word[first + 1], "!=")
|| !strcmp(word[first + 1], "<>")) {
if (index != compare)
return (TRUE);
else
return (FALSE);
} else if (!strcmp(word[first + 1], ">=")
|| !strcmp(word[first + 1], "=>")) {
if (index >= compare)
return (TRUE);
else
return (FALSE);
} else if (!strcmp(word[first + 1], "<=")
|| !strcmp(word[first + 1], "=<")) {
if (index <= compare)
return (TRUE);
else
return (FALSE);
} else if (!strcmp(word[first + 1], "grandof")) {
/* GRANDOF SAYS THAT AN OBJECT IS THE EVENTUAL PARENT OF ANOTHER OBJECT, NOT
* NECESSARILY IMMEDIATE */
if (index < 1 || index > objects) {
unkobjrun(first);
return (FALSE);
} else {
if (compare < 1 || compare > objects) {
unkobjrun(first + 2);
return (FALSE);
} else {
if (parent_of(index, compare, UNRESTRICT))
return (TRUE);
else
return (FALSE);
}
}
} else if (!strcmp(word[first + 1], "!grandof")) {
if (index < 1 || index > objects) {
unkobjrun(first);
return (FALSE);
} else {
if (compare < 1 || compare > objects) {
unkobjrun(first + 2);
return (FALSE);
} else {
if (parent_of(index, compare, UNRESTRICT))
return (FALSE);
else
return (TRUE);
}
}
} else {
Common::sprintf_s(error_buffer, 1024,
"ERROR: In function \"%s\", illegal operator \"%s\".^",
executing_function->name, word[2]);
write_text(error_buffer);
return (FALSE);
}
}
int strcondition() {
int first;
first = 1;
while (word[first + 2] != nullptr && ((first + 2) < MAX_WORDS)) {
if (str_test(first))
return (TRUE);
else
first = first + 3;
}
return (FALSE);
}
int and_strcondition() {
int first;
first = 1;
while (word[first + 2] != nullptr && ((first + 2) < MAX_WORDS)) {
if (str_test(first) == FALSE)
return (FALSE);
else
first = first + 3;
}
return (TRUE);
}
int str_test(int first) {
const char *index;
const char *compare;
// GET THE TWO STRING VALUES TO COMPARE
index = arg_text_of_word(first);
compare = arg_text_of_word(first + 2);
if (!strcmp(word[first + 1], "==") || !strcmp(word[first + 1], "=")) {
if (!scumm_stricmp(index, compare)) {
return (TRUE);
} else {
return (FALSE);
}
} else if (!strcmp(word[first + 1], "!contains")) {
if (strcasestr(index, compare))
return (FALSE);
else
return (TRUE);
} else if (!strcmp(word[first + 1], "contains")) {
if (strcasestr(index, compare))
return (TRUE);
else
return (FALSE);
} else if (!strcmp(word[first + 1], "<>") || !strcmp(word[first + 1], "!=")) {
if (scumm_stricmp(index, compare))
return (TRUE);
else
return (FALSE);
} else if (!strcmp(word[first + 1], "==C") || !strcmp(word[first + 1], "=C")) {
if (!strcmp(index, compare)) {
return (TRUE);
} else {
return (FALSE);
}
} else if (!strcmp(word[first + 1], "!containsC")) {
if (strstr(index, compare))
return (FALSE);
else
return (TRUE);
} else if (!strcmp(word[first + 1], "containsC")) {
if (strstr(index, compare))
return (TRUE);
else
return (FALSE);
} else if (!strcmp(word[first + 1], "<>C") || !strcmp(word[first + 1], "!=C")) {
if (strcmp(index, compare))
return (TRUE);
else
return (FALSE);
} else {
Common::sprintf_s(error_buffer, 1024,
"ERROR: In function \"%s\", illegal operator \"%s\".^",
executing_function->name, word[2]);
write_text(error_buffer);
return (FALSE);
}
}
void add_cinteger(const char *name, int value) {
/* THIS FUNCTION ADDS A NEW JACL CONSTANT TO THE LIST */
if ((new_cinteger = (struct cinteger_type *)
malloc(sizeof(struct cinteger_type))) == nullptr)
outofmem();
else {
if (cinteger_table == nullptr) {
cinteger_table = new_cinteger;
} else {
/* FIND LAST CONSTANT IN LIST */
current_cinteger = cinteger_table;
while (current_cinteger->next_cinteger != nullptr) {
current_cinteger = current_cinteger->next_cinteger;
}
current_cinteger->next_cinteger = new_cinteger;
}
Common::strlcpy(new_cinteger->name, name, 41);
new_cinteger->value = value;
new_cinteger->next_cinteger = nullptr;
}
}
void clear_cinteger(const char *name) {
/* FREE CONSTANTS THAT HAVE SUPPLIED NAME*/
//printf("--- clear integer %s\n", name);
if (cinteger_table != nullptr) {
current_cinteger = cinteger_table;
previous_cinteger = cinteger_table;
while (current_cinteger != nullptr) {
//sprintf(temp_buffer, "--- checking integer %s^", current_cinteger->name);
//write_text(temp_buffer);
if (!strcmp(current_cinteger->name, name)) {
//sprintf(temp_buffer, "--- found integer %s^", name);
//write_text(temp_buffer);
/* FREE THIS CONSTANT */
if (previous_cinteger == current_cinteger) {
// THE INTEGER BEING CLEARED IS THE FIRST INTEGER IN THE LIST
cinteger_table = current_cinteger->next_cinteger;
previous_cinteger = current_cinteger->next_cinteger;
free(current_cinteger);
current_cinteger = previous_cinteger;
} else {
previous_cinteger->next_cinteger = current_cinteger->next_cinteger;
free(current_cinteger);
current_cinteger = previous_cinteger->next_cinteger;
}
} else {
previous_cinteger = current_cinteger;
current_cinteger = current_cinteger->next_cinteger;
}
}
}
//printf("--- leaving clear integer\n");
}
void add_cstring(const char *name, const char *value) {
/* ADD A STRING CONSTANT WITH THE SUPPLIED NAME AND VALUE */
if ((new_string = (struct string_type *)
malloc(sizeof(struct string_type))) == nullptr)
outofmem();
else {
if (cstring_table == nullptr) {
cstring_table = new_string;
} else {
/* FIND LAST STRING IN LIST */
current_cstring = cstring_table;
while (current_cstring->next_string != nullptr) {
current_cstring = current_cstring->next_string;
}
current_cstring->next_string = new_string;
}
Common::strlcpy(new_string->name, name, 41);
Common::strlcpy(new_string->value, value, 256);
new_string->next_string = nullptr;
}
}
void clear_cstring(const char *name) {
/* FREE CONSTANTS THAT HAVE SUPPLIED NAME*/
if (cstring_table != nullptr) {
current_cstring = cstring_table;
previous_cstring = cstring_table;
while (current_cstring != nullptr) {
if (!strcmp(current_cstring->name, name)) {
/* FREE THIS STRING */
if (previous_cstring == current_cstring) {
cstring_table = current_cstring->next_string;
previous_cstring = current_cstring->next_string;
free(current_cstring);
current_cstring = previous_cstring;
} else {
previous_cstring->next_string = current_cstring->next_string;
free(current_cstring);
current_cstring = previous_cstring->next_string;
}
} else {
previous_cstring = current_cstring;
current_cstring = current_cstring->next_string;
}
}
}
}
void inspect(int object_num) {
// THIS FUNCTION DISPLAYS THE STATE OF A JACL OBJECT FOR DEBUGGING
int index, attribute_value;
struct attribute_type *pointer = attribute_table;
if (object_num < 1 || object_num > objects) {
badptrrun(word[1], object_num);
return;
}
write_text("label: ");
write_text(object[object_num]->label);
if (object[object_num]->attributes & LOCATION) {
// OUTPUT ALL THE ATTRIBUTES WITH LOCATION ATTRIBUTE TEXT
write_text("^has location attributes: ");
index = 0;
attribute_value = 1;
while (location_attributes[index] != nullptr) {
if (object[object_num]->attributes & attribute_value) {
write_text(location_attributes[index]);
}
index++;
attribute_value *= 2;
}
} else {
// OUTPUT ALL THE ATTRIBUTES WITH OBJECT ATTRIBUTE TEXT
write_text("^has object attributes: ");
index = 0;
attribute_value = 1;
while (object_attributes[index] != nullptr) {
if (object[object_num]->attributes & attribute_value) {
write_text(object_attributes[index]);
}
index++;
attribute_value *= 2;
}
write_text("^has user attributes: ");
attribute_value = 1;
}
if (pointer != nullptr) {
// THERE ARE USER ATTRIBUTES, SO CHECK IF THIS OBJECT OR LOCATION
// HAS ANY OF THEM
do {
if (object[object_num]->user_attributes & pointer->value) {
write_text(pointer->name);
write_text(" ");
}
pointer = pointer->next_attribute;
} while (pointer != nullptr);
}
write_text("^");
index = 0;
if (object[object_num]->attributes & LOCATION) {
while (location_elements[index] != nullptr) {
if (index < 12) {
if (object[object_num]->integer[index] < 1 || object[object_num]->integer[index] > objects) {
Common::sprintf_s(temp_buffer, 1024, "%s: nowhere (%d)^", location_elements[index], object[object_num]->integer[index]);
} else {
Common::sprintf_s(temp_buffer, 1024, "%s: %s (%d)^", location_elements[index], object[object[object_num]->integer[index]]->label, object[object_num]->integer[index]);
}
} else {
Common::sprintf_s(temp_buffer, 1024, "%s: %d^", location_elements[index], object[object_num]->integer[index]);
}
write_text(temp_buffer);
index++;
}
} else {
while (object_elements[index] != nullptr) {
if (index == 0) {
Common::sprintf_s(temp_buffer, 1024, "%s: %s (%d)^", object_elements[index], object[object[object_num]->integer[index]]->label, object[object_num]->integer[index]);
} else {
Common::sprintf_s(temp_buffer, 1024, "%s: %d^", object_elements[index], object[object_num]->integer[index]);
}
write_text(temp_buffer);
index++;
}
}
}
int grand_of(int child, int objs_only) {
/* THIS FUNCTION WILL CLIMB THE OBJECT TREE STARTING AT 'CHILD' UNTIL
* A 'PARENT' IS REACHED */
/* objs_only ARGUMENT TELLS FUNCTION TO IGNORE OBJECT IF IT IS IN A
* LOCATION */
int parent;
if (object[child]->PARENT != NOWHERE) {
/* STORE THE CHILDS PARENT OBJECT */
parent = object[child]->PARENT;
if (object[parent]->attributes & LOCATION) {
if (objs_only) {
/* THE CHILDS PARENT IS LOCATION AND SEARCH IS RESTRICTED TO
* OBJECTS */
return (child);
} else {
return (parent);
}
} else {
/* KEEP LOOKING UP THE TREE UNTIL THE CHILD HAS NO
* PARENT */
return (grand_of(parent, objs_only));
}
} else {
/* THE SPECIFIED OBJECT HAS NO PARENT */
return (child);
}
}
int select_next() {
while (++*select_integer <= objects) {
switch (criterion_type) {
case CRI_ATTRIBUTE:
if (object[*select_integer]->attributes & criterion_value) {
if (!criterion_negate) {
return TRUE;
}
} else {
if (criterion_negate) {
return TRUE;
}
}
break;
case CRI_USER_ATTRIBUTE:
if (object[*select_integer]->user_attributes & criterion_value) {
if (!criterion_negate) {
return TRUE;
}
} else {
if (criterion_negate) {
return TRUE;
}
}
break;
case CRI_PARENT:
if (object[*select_integer]->PARENT == criterion_value) {
if (!criterion_negate) {
return TRUE;
}
} else {
if (criterion_negate) {
return TRUE;
}
}
break;
case CRI_SCOPE:
if (scope(*select_integer, scope_criterion)) {
if (!criterion_negate) {
return TRUE;
}
} else {
if (criterion_negate) {
return TRUE;
}
}
break;
default:
break;
}
}
return (FALSE);
}
/* Converts an integer value to its hex character*/
char to_hex(char code) {
static char hex[] = "0123456789abcdef";
return hex[code & 15];
}
/* Returns a url-encoded version of str */
/* IMPORTANT: be sure to free() the returned string after use */
char *url_encode(char *str) {
char *pstr = str, *buf = (char *)malloc(strlen(str) * 3 + 1), *pbuf = buf;
while (*pstr) {
if (Common::isAlnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~')
*pbuf++ = *pstr;
else if (*pstr == ' ')
*pbuf++ = '+';
else
*pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15);
pstr++;
}
*pbuf = '\0';
return buf;
}
} // End of namespace JACL
} // End of namespace Glk
|