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 863 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 1863 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
|
/***********************************************************************/
/* Open Visualization Data Explorer */
/* (C) Copyright IBM Corp. 1989,1999 */
/* ALL RIGHTS RESERVED */
/* This code licensed under the */
/* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */
/***********************************************************************/
#include <dxconfig.h>
#include "defines.h"
#include <stdio.h>
#include <string.h>
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#if defined(HAVE_MALLOC_H)
#include <malloc.h>
#endif
#include "ErrorDialogManager.h"
#include "WarningDialogManager.h"
#include "MBGenerate.h"
#include "MBApplication.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
static int process_input(char *, Module *, Parameter **, Parameter **);
static int do_mdf(char *, Module *, Parameter **, Parameter **);
static int do_makefile(char *, Module *);
static int do_builder(char *, Module *, Parameter **, Parameter **);
static int cleanup(Module *m, Parameter **in, Parameter **out);
static int GetDXDataType(enum datatype, char **);
static int GetCDataType(enum datatype, char **);
static int GetDXDataShape(enum datashape, char **, char **);
static int GetElementTypeString(enum elementtype, char **);
static int copy_comments(char *, FILE *, char *, char *, char *);
#define MAX_IN 128
#define MAX_OUT 128
#define DO_MDF 0x1
#define DO_C 0x2
#define DO_MAKE 0x4
// Added COMMA_AND_NEWLINE to replace the use of a comma-separated list
// of statements in a cond?expr1:expr2 clause. (The expr1 was the list
// and its contents were passed to a sprintf function, the outcome of
// which was unpredictable.) MST
#if defined(intelnt) || defined (WIN32)
#define NEWLINE "\r\n"
#define COMMA_AND_NEWLINE ",\r\n"
#else
#define NEWLINE "\n"
#define COMMA_AND_NEWLINE ",\n"
#endif
int Generate(int which, char *filename)
{
Module module;
Parameter *inputs[MAX_IN], *outputs[MAX_OUT];
int i;
char *c, *fnamecopy = (char *)malloc(strlen(filename) 1);
inputs[0] = outputs[0] = NULL;
memset(&module, 0, sizeof(module));
strcpy(fnamecopy, filename);
for (i = 0; i < strlen(fnamecopy); i )
if (fnamecopy[i] == '.')
{
fnamecopy[i] = '\0';
break;
}
if (! process_input(fnamecopy, &module, inputs, outputs))
return 0;
if (which & DO_MDF)
if (! do_mdf(fnamecopy, &module, inputs, outputs))
return 0;
if (which & DO_C)
if (! do_builder(fnamecopy, &module, inputs, outputs))
return 0;
if (which & DO_MAKE)
if (! do_makefile(fnamecopy, &module))
return 0;
if (! cleanup(&module, inputs, outputs))
return 0;
free(fnamecopy);
return 1;
}
static int
cleanup(Module *m, Parameter **in, Parameter **out)
{
Parameter **p;
if (m->name) free(m->name);
if (m->category) free(m->category);
if (m->description) free(m->description);
if (m->outboard_host) free(m->description);
if (m->outboard_executable) free(m->outboard_executable);
if (m->loadable_executable) free(m->loadable_executable);
if (m->include_file) free(m->include_file);
for (p = in; *p != NULL; p )
{
if ((*p)->name) free((*p)->name);
if ((*p)->description) free((*p)->description);
if ((*p)->default_value) free((*p)->default_value);
if ((*p)->types) free((*p)->types);
free((char *)*p);
}
for (p = out; *p != NULL; p )
{
if ((*p)->name) free((*p)->name);
if ((*p)->description) free((*p)->description);
if ((*p)->default_value) free((*p)->default_value);
if ((*p)->types) free((*p)->types);
free((char *)*p);
}
return 1;
}
static int
do_makefile(char *basename, Module *mod)
{
FILE *fd = NULL;
char *buf = (char *)malloc(strlen(basename) 7);
char *makefilename;
char *c;
const char *uiroot = NULL;
#define OBJ_EXT "$(OBJEXT)"
if (! buf)
{
WarningMessage("allocation error");
goto error;
}
sprintf(buf, "%s.make", basename);
fd = fopen(buf, "w");
if (! fd)
{
ErrorMessage("error opening output file");
goto error;
}
if (! copy_comments(basename, fd, NULL, "# ", NULL))
goto error;
for (c = basename; *c; c )
if (*c == '/')
basename = c 1;
uiroot = theMBApplication->getUIRoot();
// This should not be necessary, but we'll be very
// careful just before the 3.1 release
if (!uiroot)
uiroot = "/usr/share/dx";
fprintf(fd, "SHELL = /bin/sh%s", NEWLINE);
fprintf(fd, "BASE = %s%s%s",uiroot, NEWLINE, NEWLINE);
fprintf(fd, "# need arch set, e.g. by%s", NEWLINE);
fprintf(fd, "# setenv DXARCH `dx -whicharch`%s", NEWLINE);
fprintf(fd, "include $(BASE)/lib_$(DXARCH)/arch.mak%s%s", NEWLINE, NEWLINE);
if(mod->outboard_executable != NULL)
fprintf(fd, "FILES_%s = %s.%s%s%s", basename, basename, OBJ_EXT, NEWLINE, NEWLINE);
else if(mod->loadable_executable != NULL)
fprintf(fd, "FILES_%s = user%s.%s %s.%s%s%s",
basename, basename, OBJ_EXT, basename, OBJ_EXT, NEWLINE, NEWLINE);
else
fprintf(fd, "FILES_%s = user%s.%s %s.%s%s%s",
basename, basename, OBJ_EXT, basename, OBJ_EXT, NEWLINE, NEWLINE);
fprintf(fd, "BIN = $(BASE)/bin%s%s", NEWLINE, NEWLINE);
fprintf(fd, "#windows BIN = $(BASE)\\bin%s%s", NEWLINE, NEWLINE);
fprintf(fd, "CFLAGS = -I./ -I$(BASE)/include $(DX_CFLAGS)%s%s", NEWLINE, NEWLINE);
fprintf(fd, "LDFLAGS = -L$(BASE)/lib_$(DXARCH)%s%s", NEWLINE, NEWLINE);
fprintf(fd, "LIBS = -lDX $(DX_GL_LINK_LIBS) $(DXEXECLINKLIBS)%s%s", NEWLINE, NEWLINE);
fprintf(fd, "OLIBS = -lDXlite -lm%s%s", NEWLINE, NEWLINE);
fprintf(fd, "BIN = $(BASE)/bin%s%s", NEWLINE, NEWLINE);
fprintf(fd, "# create the necessary executable%s", NEWLINE);
if(mod->outboard_executable != NULL)
{
fprintf(fd, "%s: $(FILES_%s) outboard.$(OBJEXT)%s",
mod->outboard_executable,
basename, NEWLINE);
fprintf(fd,
"\t$(CC) $(DXABI) $(LDFLAGS) $(FILES_%s) outboard.$(OBJEXT) $(OLIBS) -o %s$(DOT_EXE_EXT)%s%s",
basename,
mod->outboard_executable, NEWLINE, NEWLINE);
fprintf(fd, "# how to make the outboard main routine%s", NEWLINE);
fprintf(fd, "outboard.$(OBJEXT): $(BASE)/lib/outboard.c%s", NEWLINE);
fprintf(fd, "\t%s%s%s%s",
"$(CC) $(DXABI) $(CFLAGS) -DUSERMODULE=m_",
mod->name,
" -c $(BASE)/lib/outboard.c", NEWLINE);
fprintf(fd, "%s%s", NEWLINE, NEWLINE);
}
else if(mod->loadable_executable != NULL)
{
fprintf(fd, "%s: $(FILES_%s) %s",
mod->loadable_executable, basename, NEWLINE);
fprintf(fd, "\t$(SHARED_LINK) $(DXABI) $(DX_RTL_CFLAGS) $(LDFLAGS) -o %s user%s.$(OBJEXT) %s.$(OBJEXT) $(DX_RTL_LDFLAGS) $(SYSLIBS) $(DX_RTL_IMPORTS) $(DX_RTL_DXENTRY)%s%s",
mod->loadable_executable, basename, basename, NEWLINE, NEWLINE);
#if 0
#ifdef alphax
fprintf(fd, "\tld $(LDFLAGS) -o %s user%s.$(OBJEXT) %s.$(OBJEXT) $(SYSLIBS)%s%s",
mod->loadable_executable, basename, basename, NEWLINE, NEWLINE);
#endif
#ifdef hp700
fprintf(fd, "\tld $(LDFLAGS) -o %s user%s.$(OBJEXT) %s.$(OBJEXT) $(SYSLIBS)%s%s",
mod->loadable_executable, basename, basename, NEWLINE, NEWLINE);
#endif
#ifdef ibm6000
fprintf(fd, "\tcc -o %s user%s.$(OBJEXT) %s.$(OBJEXT) -qmkshrobj -G -bI:$(IMP)%s%s",
mod->loadable_executable, basename, basename, NEWLINE, NEWLINE);
#endif
#ifdef DXD_WIN
fprintf(fd, "\t$(CC) $(CFLAGS) -o %s user%s.$(OBJEXT) %s.$(OBJEXT) $(SYSLIBS) $(OLIBS) %s%s",
mod->loadable_executable, basename, basename, NEWLINE, NEWLINE);
#endif
#ifdef sgi
fprintf(fd, "\tcc $(LDFLAGS) -o %s user%s.$(OBJEXT) %s.$(OBJEXT) $(SYSLIBS)%s%s",
mod->loadable_executable, basename, basename, NEWLINE, NEWLINE);
#endif
#ifdef solaris
fprintf(fd, "\tcc $(LDFLAGS) -o %s user%s.$(OBJEXT) %s.$(OBJEXT)%s%s",
mod->loadable_executable, basename, basename, NEWLINE, NEWLINE);
#endif
#endif /* zero */
}
else
{
fprintf(fd, "dxexec: $(FILES_%s) %s",
basename, NEWLINE);
fprintf(fd, "\t$(CC) $(LDFLAGS) $(FILES_%s) $(LIBS) -o dxexec%s%s",
basename, NEWLINE, NEWLINE);
#if 0
#if defined(DXD_WIN) || defined(OS2)
fprintf(fd, "dxexec.exe: $(FILES_%s) %s",
basename, NEWLINE);
#else
fprintf(fd, "dxexec: $(FILES_%s) %s",
basename, NEWLINE);
#endif
#endif /* zero */
#if 0
#if defined(DXD_WIN)
fprintf(fd, "\t$(CC) (DXABI) $(LDFLAGS) $(FILES_%s) $(LIBS) -o dxexec.exe%s%s",
basename, NEWLINE, NEWLINE);
#else
fprintf(fd, "\t$(CC) $(DXABI) $(LDFLAGS) $(FILES_%s) $(LIBS) -o dxexec%s%s",
basename, NEWLINE, NEWLINE);
#endif
#endif /* zero */
}
fprintf(fd, ".c.o: ; cc -c $(DXABI) $(DX_RTL_CFLAGS) $(CFLAGS) $*.c %s%s", NEWLINE, NEWLINE);
fprintf(fd, ".C.o: ; cc -c $(DXABI) $(DX_RTL_CFLAGS) $(CFLAGS) $*.C %s%s", NEWLINE, NEWLINE);
/* a target to run dx using the user module */
fprintf(fd, "# a command to run the user module%s", NEWLINE);
/* outboard module */
if(mod->outboard_executable != NULL) {
fprintf(fd, "run: %s %s", mod->outboard_executable, NEWLINE);
fprintf(fd, "\tdx -edit -mdf %s.mdf &%s", basename, NEWLINE);
fprintf(fd, "%s", NEWLINE);
}
else if(mod->loadable_executable != NULL) {
/* runtime loadable module */
fprintf(fd, "run: %s %s", mod->loadable_executable, NEWLINE);
fprintf(fd, "\tdx -edit -mdf %s.mdf &%s", basename, NEWLINE);
fprintf(fd, "%s", NEWLINE);
}
else {
/* inboard module */
fprintf(fd, "run: dxexec %s", NEWLINE);
fprintf(fd, "\tdx -edit -exec ./dxexec -mdf %s.mdf &%s", basename, NEWLINE);
fprintf(fd, "%s", NEWLINE);
}
fprintf(fd, "# make the user files%s", NEWLINE);
fprintf(fd, "user%s.c: %s.mdf%s", basename, basename, NEWLINE);
#ifdef DXD_WIN /* just to change forward and back slashes */
if(mod->loadable_executable != NULL)
fprintf(fd, "\t$(BIN)\\mdf2c -m %s.mdf > user%s.c%s", basename, basename, NEWLINE);
else
fprintf(fd, "\t$(BIN)\\mdf2c %s.mdf > user%s.c%s", basename, basename, NEWLINE);
#else
if(mod->loadable_executable != NULL)
fprintf(fd, "\t$(BIN)/mdf2c -m %s.mdf > user%s.c%s", basename, basename, NEWLINE);
else
fprintf(fd, "\t$(BIN)/mdf2c %s.mdf > user%s.c%s", basename, basename, NEWLINE);
#endif
fprintf(fd, "# kluge for when DXARCH isn't set%s", NEWLINE);
fprintf(fd, "$(BASE)/lib_/arch.mak:%s", NEWLINE);
makefilename=strrchr(buf,'/');
if(!makefilename) makefilename = buf;
else makefilename ;
fprintf(fd, "\t(export DXARCH=`dx -whicharch` ; $(MAKE) -f %s )%s",makefilename, NEWLINE);
fprintf(fd, "\techo YOU NEED TO SET DXARCH via dx -whicharch%s", NEWLINE);
fclose(fd);
free(buf);
return 1;
error:
if (fd)
{
fclose(fd);
unlink(buf);
}
free(buf);
return 0;
}
static int
do_mdf(char *basename, Module *mod, Parameter **in, Parameter **out)
{
FILE *fd = NULL;
char *buf = (char *)malloc(strlen(basename) 5);
if (! buf)
{
ErrorMessage("allocation error");
goto error;
}
sprintf(buf, "%s.mdf", basename);
fd = fopen(buf, "w");
if (! fd)
{
ErrorMessage("error opening output file");
goto error;
}
if (! copy_comments(basename, fd, NULL, "# ", NULL))
goto error;
fprintf(fd, "MODULE %s%s", mod->name, NEWLINE);
fprintf(fd, "CATEGORY %s%s", mod->category, NEWLINE);
fprintf(fd, "DESCRIPTION %s%s", mod->description, NEWLINE);
if (mod->outboard_persistent == TRUE ||
mod->asynchronous == TRUE ||
mod->pinned == TRUE ||
mod->side_effect == TRUE)
{
int first = 1;
fprintf(fd, "FLAGS");
if (mod->outboard_persistent == TRUE)
fprintf(fd, "%sPERSISTENT", first ? " " : ", ");
if (mod->asynchronous == TRUE)
fprintf(fd, "%sASYNC", first ? " " : ", ");
if (mod->pinned == TRUE)
fprintf(fd, "%sPIN", first ? " " : ", ");
if (mod->side_effect == TRUE)
fprintf(fd, "%sSIDE_EFFECT", first ? " " : ", ");
fprintf(fd, "%s", NEWLINE);
}
if (mod->outboard_executable)
{
fprintf(fd, "OUTBOARD %s;", mod->outboard_executable);
if (mod->outboard_host)
fprintf(fd, "%s", mod->outboard_host);
fprintf(fd, "%s", NEWLINE);
}
if (mod->loadable_executable)
{
fprintf(fd, "LOADABLE %s;", mod->loadable_executable);
fprintf(fd, "%s", NEWLINE);
}
while (*in)
{
char *c;
fprintf(fd, "INPUT %s; ", (*in)->name);
if ((*in)->types)
{
char *buf, *b, *c;
int i, nc;
for (c = (*in)->types, nc = 0; *c; c )
if (*c == ',') nc ;
/* integer vector and integer vector list are not understood by
the ui */
if (!strcmp((*in)->types,"integer vector")) {
buf = b = (char *)malloc(strlen("vector") 4*nc 1);
for (c = "vector", nc = 0; *c; c )
*b = *c;
}
else if (!strcmp((*in)->types,"integer vector list")) {
buf = b = (char *)malloc(strlen("vector list") 4*nc 1);
for (c = "vector list", nc = 0; *c; c )
*b = *c;
}
else {
buf = b = (char *)malloc(strlen((*in)->types) 4*nc 1);
for (c = (*in)->types, nc = 0; *c; c )
*b = *c;
}
*b = '\0';
fprintf(fd, "%s; ", buf);
free(buf);
}
else if ((*in)->structure == VALUE)
fprintf(fd, "value; ");
else if ((*in)->structure == GROUP_FIELD)
fprintf(fd, "group; ");
else
{
ErrorMessage("input %s has no STRUCTURE parameter\n", (*in)->name);
goto error;
}
if ((*in)->required == TRUE)
fprintf(fd, " (none);");
else if ((*in)->descriptive == TRUE)
fprintf(fd, " (%s);", (*in)->default_value);
else
fprintf(fd, " %s;", (*in)->default_value);
fprintf(fd, " %s%s", (*in)->description, NEWLINE);
in ;
}
while (*out)
{
char *c;
fprintf(fd, "OUTPUT %s; ", (*out)->name);
if ((*out)->types)
{
char *buf, *b, *c;
int i, nc;
for (c = (*out)->types, nc = 0; *c; c )
if (*c == ',') nc ;
buf = b = (char *)malloc(strlen((*out)->types) 4*nc 1);
for (c = (*out)->types, nc = 0; *c; c )
if (*c == ',')
{
*b = ' ';
*b = 'o';
*b = 'r';
*b = ' ';
}
else
*b = *c;
*b = '\0';
fprintf(fd, "%s; ", buf);
free(buf);
}
else if ((*out)->structure == VALUE)
fprintf(fd, "value; ");
else if ((*out)->structure == GROUP_FIELD)
fprintf(fd, "group; ");
else
{
ErrorMessage("output %s has no STRUCTURE parameter\n", (*out)->name);
goto error;
}
fprintf(fd, " %s%s", (*out)->description, NEWLINE);
out ;
}
fclose(fd);
free(buf);
return 1;
error:
if (fd)
{
fclose(fd);
unlink(buf);
}
free(buf);
return 0;
}
static int
do_builder(char *basename, Module *mod, Parameter **in, Parameter **out)
{
FILE *fd = NULL;
int i, nin, nout, n_GF_in, n_GF_out, open;
char *buf = (char *)malloc(strlen(basename) 4);
if (! buf)
{
ErrorMessage("allocation error");
goto error;
}
sprintf(buf, "%s.c", basename);
fd = fopen(buf, "w");
if (! fd)
{
ErrorMessage("error opening output file");
goto error;
}
if (! copy_comments(basename, fd, "/*\n", " * ", " */\n"))
goto error;
for (nin = 0; in[nin] != NULL; nin );
for (nout = 0; out[nout] != NULL; nout );
fprintf(fd, "/*%s", NEWLINE);
fprintf(fd, " * Automatically generated on \"%s.mb\" by DX Module Builder%s",
basename, NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
fprintf(fd, "/* define your pre-dx.h include file for inclusion here*/ %s", NEWLINE);
fprintf(fd, "#ifdef PRE_DX_H%s", NEWLINE);
fprintf(fd, "#include \"%s_predx.h\"%s",mod->name, NEWLINE);
fprintf(fd, "#endif%s", NEWLINE);
fprintf(fd, "#include \"dx/dx.h\"%s", NEWLINE);
fprintf(fd, "/* define your post-dx.h include file for inclusion here*/ %s", NEWLINE);
fprintf(fd, "#ifdef POST_DX_H%s", NEWLINE);
fprintf(fd, "#include \"%s_postdx.h\"%s",mod->name, NEWLINE);
fprintf(fd, "#endif%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, "static Error traverse(Object *, Object *);%s", NEWLINE);
fprintf(fd, "static Error doLeaf(Object *, Object *);%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, "/*%s", NEWLINE);
fprintf(fd, " * Declare the interface routine.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, "int%s%s_worker(%s", NEWLINE, mod->name, NEWLINE);
open = 0;
if (in[0]->positions == GRID_REGULAR)
{
open = 1;
fprintf(fd, " int, int, int *, float *, float *");
}
else if (in[0]->positions == GRID_IRREGULAR)
{
open = 1;
fprintf(fd, " int, int, float *");
}
if (in[0]->connections == GRID_REGULAR)
{
fprintf(fd, "%s int, int, int *", (open)?COMMA_AND_NEWLINE:"");
open = 1;
}
else if (in[0]->connections == GRID_IRREGULAR)
{
fprintf(fd, "%s int, int, int *", (open)?COMMA_AND_NEWLINE:"");
open = 1;
}
for (i = 0; i < nin; i )
{
char *type;
GetCDataType(in[i]->datatype, &type);
fprintf(fd, "%s int, %s *", (open)?COMMA_AND_NEWLINE:"", type);
open = 1;
}
for (i = 0; i < nout; i )
{
char *type;
GetCDataType(out[i]->datatype, &type);
fprintf(fd, "%s int, %s *", (open)?COMMA_AND_NEWLINE:"", type);
open = 1;
}
fprintf(fd, ");%s%s", NEWLINE, NEWLINE);
fprintf(fd, "#if defined (__cplusplus) || defined (c_plusplus)%s", NEWLINE);
fprintf(fd, "extern \"C\"%s", NEWLINE);
fprintf(fd, "#endif%s", NEWLINE);
fprintf(fd, "Error%sm_%s(Object *in, Object *out)%s", NEWLINE, mod->name, NEWLINE);
fprintf(fd, "{%s", NEWLINE);
fprintf(fd, " int i;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Initialize all outputs to NULL%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
if (nout == 1)
fprintf(fd, " out[0] = NULL;%s", NEWLINE);
else if (nout > 1)
{
fprintf(fd, " for (i = 0; i < %d; i )%s", nout, NEWLINE);
fprintf(fd, " out[i] = NULL;%s", NEWLINE);
}
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Error checks: required inputs are verified.%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
n_GF_in = 0;
for (i = 0; i < nin; i )
{
if (in[i]->structure == GROUP_FIELD)
n_GF_in ;
if (in[i]->required == TRUE || i == 0)
{
fprintf(fd, " /* Parameter \"%s\" is required. */%s", in[i]->name, NEWLINE);
fprintf(fd, " if (in[%d] == NULL)%s", i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_MISSING_DATA, ");
fprintf(fd, "\"\\\"%s\\\" must be specified\");%s", in[i]->name, NEWLINE);
fprintf(fd, " return ERROR;%s", NEWLINE);
fprintf(fd, " }%s%s", NEWLINE, NEWLINE);
}
}
n_GF_out = 0;
for (i = 0; i < nout; i )
{
fprintf(fd, "%s", NEWLINE);
if (out[i]->structure == GROUP_FIELD)
{
n_GF_out ;
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Since output \"%s\" is structure Field/Group, it initially%s", out[i]->name, NEWLINE);
fprintf(fd, " * is a copy of input \"%s\".%s", in[0]->name, NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " out[%d] = DXCopy(in[0], COPY_STRUCTURE);%s", i, NEWLINE);
fprintf(fd, " if (! out[%d])%s", i, NEWLINE);
fprintf(fd, " goto error;%s%s", NEWLINE, NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * If in[0] was an array, then no copy is actually made - Copy %s", NEWLINE);
fprintf(fd, " * returns a pointer to the input object. Since this can't be written to%s", NEWLINE);
fprintf(fd, " * we postpone explicitly copying it until the leaf level, when we'll need%s", NEWLINE);
fprintf(fd, " * to be creating writable arrays anyway.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (out[%d] == in[0])%s", i, NEWLINE);
fprintf(fd, " out[%d] = NULL;%s", i, NEWLINE);
}
else if (out[i]->structure == VALUE)
{
char *t;
char *r, *s;
char *l;
if (! GetDXDataType(out[i]->datatype, &t))
{
ErrorMessage("cannot create array without DATATYPE");
goto error;
}
if (! GetDXDataShape(out[i]->datashape, &r, &s))
{
ErrorMessage("cannot create array without DATASHAPE");
goto error;
}
#if 0
switch(out[i]->counts)
{
case COUNTS_1: l = "1"; break;
default:
ErrorMessage("cannot create array without COUNTS");
goto error;
}
#endif
l = "1";
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Output \"%s\" is a value; set up an appropriate array%s", out[i]->name, NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " out[%d] = (Object)DXNewArray(%s, CATEGORY_REAL, %s, %s);%s", i, t, r, s, NEWLINE);
fprintf(fd, " if (! out[%d])%s", i, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " if (! DXAddArrayData((Array)out[%d], 0, %s, NULL))%s", i, l, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " memset(DXGetArrayData((Array)out[%d]), 0, %s*DXGetItemSize((Array)out[%d]));%s", i, l, i, NEWLINE);
fprintf(fd, "%s", NEWLINE);
}
}
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Call the hierarchical object traversal routine%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (!traverse(in, out))%s", NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " return OK;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, "error:%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * On error, any successfully-created outputs are deleted.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " for (i = 0; i < %d; i )%s", nout, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " if (in[i] != out[i])%s", NEWLINE);
fprintf(fd, " DXDelete(out[i]);%s", NEWLINE);
fprintf(fd, " out[i] = NULL;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, " return ERROR;%s", NEWLINE);
fprintf(fd, "}%s", NEWLINE);
fprintf(fd, "%s%s", NEWLINE, NEWLINE);
fprintf(fd, "static Error%s", NEWLINE);
fprintf(fd, "traverse(Object *in, Object *out)%s", NEWLINE);
fprintf(fd, "{%s", NEWLINE);
fprintf(fd, " switch(DXGetObjectClass(in[0]))%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " case CLASS_FIELD:%s", NEWLINE);
fprintf(fd, " case CLASS_ARRAY:%s", NEWLINE);
fprintf(fd, " case CLASS_STRING:%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * If we have made it to the leaf level, call the leaf handler.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (! doLeaf(in, out))%s", NEWLINE);
fprintf(fd, " return ERROR;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " return OK;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " case CLASS_GROUP:%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " int i, j;%s", NEWLINE);
fprintf(fd, " int memknt;%s", NEWLINE);
fprintf(fd, " Class groupClass = DXGetGroupClass((Group)in[0]);%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " DXGetMemberCount((Group)in[0], &memknt);%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (n_GF_in > 1)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * All inputs that are not NULL and are type Field/Group must%s", NEWLINE);
fprintf(fd, " * match the structure of input[0]. Verify that this is so.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
for (i = 1; i < nin; i )
if (in[i]->structure == GROUP_FIELD)
{
fprintf(fd, " if (in[%d] &&%s", i, NEWLINE);
fprintf(fd, " (DXGetObjectClass(in[%d]) != CLASS_GROUP ||%s", i, NEWLINE);
fprintf(fd, " DXGetGroupClass((Group)in[%d]) != groupClass ||%s", i, NEWLINE);
fprintf(fd, " !DXGetMemberCount((Group)in[%d], &i) || i != memknt))%s", i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID,%s", NEWLINE);
fprintf(fd, " \"structure of \\\"%s\\\" doesn't match that of \\\"%s\\\"\");%s",
in[i]->name, in[0]->name, NEWLINE);
fprintf(fd, " return ERROR;%s", NEWLINE);
fprintf(fd, " }%s%s", NEWLINE, NEWLINE);
}
}
else
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Create new in and out lists for each child%s", NEWLINE);
fprintf(fd, " * of the first input. %s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " for (i = 0; i < memknt; i )%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " Object new_in[%d], new_out[%d];%s", nin, nout, NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * For all inputs that are Values, pass them to %s", NEWLINE);
fprintf(fd, " * child object list. For all that are Field/Group, get %s", NEWLINE);
fprintf(fd, " * the appropriate descendent and place it into the%s", NEWLINE);
fprintf(fd, " * child input object list.%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 0; i < nin; i )
if (in[i]->structure == VALUE)
{
fprintf(fd, " /* input \"%s\" is Value */%s", in[i]->name, NEWLINE);
fprintf(fd, " new_in[%d] = in[%d];%s%s", i, i, NEWLINE, NEWLINE);
}
else if (in[i]->structure == GROUP_FIELD)
{
fprintf(fd, " /* input \"%s\" is Field/Group */%s", in[i]->name, NEWLINE);
fprintf(fd, " if (in[%d])%s", i, NEWLINE);
fprintf(fd, " new_in[%d] = DXGetEnumeratedMember((Group)in[%d], i, NULL);%s", i, i, NEWLINE);
fprintf(fd, " else%s", NEWLINE);
fprintf(fd, " new_in[%d] = NULL;%s", i, NEWLINE);
fprintf(fd, "%s", NEWLINE);
}
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * For all outputs that are Values, pass them to %s", NEWLINE);
fprintf(fd, " * child object list. For all that are Field/Group, get%s", NEWLINE);
fprintf(fd, " * the appropriate descendent and place it into the%s", NEWLINE);
fprintf(fd, " * child output object list. Note that none should%s", NEWLINE);
fprintf(fd, " * be NULL (unlike inputs, which can default).%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 0; i < nout; i )
if (out[i]->structure == VALUE)
{
fprintf(fd, " /* output \"%s\" is Value */%s", out[i]->name, NEWLINE);
fprintf(fd, " new_out[%d] = out[%d];%s%s", i, i, NEWLINE, NEWLINE);
}
else
{
fprintf(fd, " /* output \"%s\" is Field/Group */%s", out[i]->name, NEWLINE);
fprintf(fd, " new_out[%d] = DXGetEnumeratedMember((Group)out[%d], i, NULL);%s%s", i, i, NEWLINE, NEWLINE);
}
fprintf(fd, " if (! traverse(new_in, new_out))%s", NEWLINE);
fprintf(fd, " return ERROR;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (n_GF_out)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Now for each output that is not a Value, replace%s", NEWLINE);
fprintf(fd, " * the updated child into the object in the parent.%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 0; i < nout; i )
if (out[i]->structure == GROUP_FIELD)
{
fprintf(fd, " /* output \"%s\" is Field/Group */%s", out[i]->name, NEWLINE);
fprintf(fd, " DXSetEnumeratedMember((Group)out[%d], i, new_out[%d]);%s%s", i, i, NEWLINE, NEWLINE);
}
}
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, " return OK;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " case CLASS_XFORM:%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " int i, j;%s", NEWLINE);
fprintf(fd, " Object new_in[%d], new_out[%d];%s", nin, nout, NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (n_GF_in > 1)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * All inputs that are not NULL and are type Field/Group must%s", NEWLINE);
fprintf(fd, " * match the structure of input[0]. Verify that this is so.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
for (i = 1; i < nin; i )
if (in[i]->structure == GROUP_FIELD)
{
fprintf(fd, " if (in[%d] && DXGetObjectClass(in[%d]) != CLASS_XFORM)%s", i, i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID,%s", NEWLINE);
fprintf(fd, " \"structure of \\\"%s\\\" doesn't match that of \\\"%s\\\"\");%s",
in[i]->name, in[0]->name, NEWLINE);
fprintf(fd, " return ERROR;%s", NEWLINE);
fprintf(fd, " }%s%s", NEWLINE, NEWLINE);
}
}
else
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Create new in and out lists for the descendent of the%s", NEWLINE);
fprintf(fd, " * first input. For inputs and outputs that are Values%s", NEWLINE);
fprintf(fd, " * copy them into the new in and out lists. Otherwise%s", NEWLINE);
fprintf(fd, " * get the corresponding descendents.%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 0; i < nin; i )
if (in[i]->structure == VALUE)
{
fprintf(fd, " /* input \"%s\" is Value */%s", in[i]->name, NEWLINE);
fprintf(fd, " new_in[%d] = in[%d];%s%s", i, i, NEWLINE, NEWLINE);
}
else
{
fprintf(fd, " /* input \"%s\" is Field/Group */%s", in[i]->name, NEWLINE);
fprintf(fd, " if (in[%d])%s", i, NEWLINE);
fprintf(fd, " DXGetXformInfo((Xform)in[%d], &new_in[%d], NULL);%s", i, i, NEWLINE);
fprintf(fd, " else%s", NEWLINE);
fprintf(fd, " new_in[%d] = NULL;%s", i, NEWLINE);
fprintf(fd, "%s", NEWLINE);
}
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * For all outputs that are Values, copy them to %s", NEWLINE);
fprintf(fd, " * child object list. For all that are Field/Group, get%s", NEWLINE);
fprintf(fd, " * the appropriate descendent and place it into the%s", NEWLINE);
fprintf(fd, " * child output object list. Note that none should%s", NEWLINE);
fprintf(fd, " * be NULL (unlike inputs, which can default).%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 0; i < nout; i )
if (out[i]->structure == VALUE)
{
fprintf(fd, " /* output \"%s\" is Value */%s", out[i]->name, NEWLINE);
fprintf(fd, " new_out[%d] = out[%d];%s%s", i, i, NEWLINE, NEWLINE);
}
else
{
fprintf(fd, " /* output \"%s\" is Field/Group */%s", out[i]->name, NEWLINE);
fprintf(fd, " DXGetXformInfo((Xform)out[%d], &new_out[%d], NULL);%s%s", i,i, NEWLINE, NEWLINE);
}
fprintf(fd, " if (! traverse(new_in, new_out))%s", NEWLINE);
fprintf(fd, " return ERROR;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (n_GF_out)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Now for each output that is not a Value replace%s", NEWLINE);
fprintf(fd, " * the updated child into the object in the parent.%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 0; i < nout; i )
if (out[i]->structure == GROUP_FIELD)
{
fprintf(fd, " /* output \"%s\" is Field/Group */%s", out[i]->name, NEWLINE);
fprintf(fd, " DXSetXformObject((Xform)out[%d], new_out[%d]);%s%s", i, i, NEWLINE, NEWLINE);
}
}
fprintf(fd, " return OK;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " case CLASS_SCREEN:%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " int i, j;%s", NEWLINE);
fprintf(fd, " Object new_in[%d], new_out[%d];%s", nin, nout, NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (n_GF_in > 1)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * All inputs that are not NULL and are type Field/Group must%s", NEWLINE);
fprintf(fd, " * match the structure of input[0]. Verify that this is so.%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 1; i < nin; i )
if (in[i]->structure == GROUP_FIELD)
{
fprintf(fd, " if (in[%d] && DXGetObjectClass(in[%d]) != CLASS_SCREEN)%s", i, i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID,%s", NEWLINE);
fprintf(fd, " \"structure of \\\"%s\\\" doesn't match that of \\\"%s\\\"\");%s",
in[i]->name, in[0]->name, NEWLINE);
fprintf(fd, " return ERROR;%s", NEWLINE);
fprintf(fd, " }%s%s", NEWLINE, NEWLINE);
}
}
else
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Create new in and out lists for the descendent of the%s", NEWLINE);
fprintf(fd, " * first input. For inputs and outputs that are Values%s", NEWLINE);
fprintf(fd, " * copy them into the new in and out lists. Otherwise%s", NEWLINE);
fprintf(fd, " * get the corresponding descendents.%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 0; i < nin; i )
if (in[i]->structure == VALUE)
{
fprintf(fd, " /* input \"%s\" is Value */%s", in[i]->name, NEWLINE);
fprintf(fd, " new_in[%d] = in[%d];%s%s", i, i, NEWLINE, NEWLINE);
}
else
{
fprintf(fd, " /* input \"%s\" is Field/Group */%s", in[i]->name, NEWLINE);
fprintf(fd, " if (in[%d])%s", i, NEWLINE);
fprintf(fd, " DXGetScreenInfo((Screen)in[%d], &new_in[%d], NULL, NULL);%s",i,i, NEWLINE);
fprintf(fd, " else%s", NEWLINE);
fprintf(fd, " new_in[%d] = NULL;%s%s", i, NEWLINE,NEWLINE);
}
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * For all outputs that are Values, copy them to %s", NEWLINE);
fprintf(fd, " * child object list. For all that are Field/Group, get%s", NEWLINE);
fprintf(fd, " * the appropriate descendent and place it into the%s", NEWLINE);
fprintf(fd, " * child output object list. Note that none should%s", NEWLINE);
fprintf(fd, " * be NULL (unlike inputs, which can default).%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 0; i < nout; i )
if (out[i]->structure == VALUE)
{
fprintf(fd, " /* output \"%s\" is Value */%s", out[i]->name, NEWLINE);
fprintf(fd, " new_out[%d] = out[%d];%s%s", i, i, NEWLINE, NEWLINE);
}
else
{
fprintf(fd, " /* output \"%s\" is Field/Group */%s", out[i]->name, NEWLINE);
fprintf(fd, " DXGetScreenInfo((Screen)out[%d], &new_out[%d], NULL, NULL);%s%s", i,i, NEWLINE, NEWLINE);
}
fprintf(fd, " if (! traverse(new_in, new_out))%s", NEWLINE);
fprintf(fd, " return ERROR;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (n_GF_out)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Now for each output that is not a Value, replace%s", NEWLINE);
fprintf(fd, " * the updated child into the object in the parent.%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 0; i < nout; i )
if (out[i]->structure == GROUP_FIELD)
{
fprintf(fd, " /* output \"%s\" is Field/Group */%s", out[i]->name, NEWLINE);
fprintf(fd, " DXSetScreenObject((Screen)out[%d], new_out[%d]);%s%s", i,i, NEWLINE, NEWLINE);
}
}
fprintf(fd, " return OK;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " case CLASS_CLIPPED:%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " int i, j;%s", NEWLINE);
fprintf(fd, " Object new_in[%d], new_out[%d];%s", nin, nout, NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (n_GF_in > 1)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * All inputs that are not NULL and are type Field/Group must%s", NEWLINE);
fprintf(fd, " * match the structure of input[0]. Verify that this is so.%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 1; i < nin; i )
if (in[i]->structure == GROUP_FIELD)
{
fprintf(fd, " if (in[%d] && DXGetObjectClass(in[%d]) != CLASS_CLIPPED)%s", i, i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID,%s", NEWLINE);
fprintf(fd, " \"mismatching Field/Group objects\");%s", NEWLINE);
fprintf(fd, " return ERROR;%s", NEWLINE);
fprintf(fd, " }%s%s", NEWLINE, NEWLINE);
}
}
else
fprintf(fd, "%s", NEWLINE);
for (i = 0; i < nin; i )
if (in[i]->structure == VALUE)
{
fprintf(fd, " /* input \"%s\" is Value */%s", in[i]->name, NEWLINE);
fprintf(fd, " new_in[%d] = in[%d];%s%s", i, i, NEWLINE, NEWLINE);
}
else
{
fprintf(fd, " /* input \"%s\" is Field/Group */%s", in[i]->name, NEWLINE);
fprintf(fd, " if (in[%d])%s", i, NEWLINE);
fprintf(fd, " DXGetClippedInfo((Clipped)in[%d], &new_in[%d], NULL);%s",i,i, NEWLINE);
fprintf(fd, " else%s", NEWLINE);
fprintf(fd, " new_in[%d] = NULL;%s%s", i, NEWLINE, NEWLINE);
}
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * For all outputs that are Values, copy them to %s", NEWLINE);
fprintf(fd, " * child object list. For all that are Field/Group, get%s", NEWLINE);
fprintf(fd, " * the appropriate descendent and place it into the%s", NEWLINE);
fprintf(fd, " * child output object list. Note that none should%s", NEWLINE);
fprintf(fd, " * be NULL (unlike inputs, which can default).%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 0; i < nout; i )
if (out[i]->structure == VALUE)
{
fprintf(fd, " /* output \"%s\" is Value */%s", out[i]->name, NEWLINE);
fprintf(fd, " new_out[%d] = out[%d];%s%s", i, i, NEWLINE, NEWLINE);
}
else
{
fprintf(fd, " /* output \"%s\" is Field/Group */%s", out[i]->name, NEWLINE);
fprintf(fd, " DXGetClippedInfo((Clipped)out[%d], &new_out[%d], NULL);%s%s", i,i, NEWLINE, NEWLINE);
}
fprintf(fd, " if (! traverse(new_in, new_out))%s", NEWLINE);
fprintf(fd, " return ERROR;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (n_GF_out)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Now for each output that is not a Value, replace%s", NEWLINE);
fprintf(fd, " * the updated child into the object in the parent.%s", NEWLINE);
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
for (i = 0; i < nout; i )
if (out[i]->structure == GROUP_FIELD)
{
fprintf(fd, " /* output \"%s\" is Field/Group */%s", out[i]->name, NEWLINE);
fprintf(fd, " DXSetClippedObjects((Clipped)out[%d], new_out[%d], NULL);%s%s", i, i, NEWLINE, NEWLINE);
}
}
fprintf(fd, " return OK;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " default:%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_BAD_CLASS, ");
fprintf(fd, "\"encountered in object traversal\");%s", NEWLINE);
fprintf(fd, " return ERROR;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "}%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, "static int%s", NEWLINE);
fprintf(fd, "doLeaf(Object *in, Object *out)%s", NEWLINE);
fprintf(fd, "{%s", NEWLINE);
fprintf(fd, " int i, result=0;%s", NEWLINE);
fprintf(fd, " Array array;%s", NEWLINE);
fprintf(fd, " Field field;%s", NEWLINE);
fprintf(fd, " Pointer *in_data[%d], *out_data[%d];%s", nin, nout, NEWLINE);
fprintf(fd, " int in_knt[%d], out_knt[%d];%s", nin, nout, NEWLINE);
fprintf(fd, " Type type;%s", NEWLINE);
fprintf(fd, " Category category;%s", NEWLINE);
fprintf(fd, " int rank, shape;%s", NEWLINE);
fprintf(fd, " Object attr, src_dependency_attr = NULL;%s", NEWLINE);
fprintf(fd, " char *src_dependency = NULL;%s", NEWLINE);
if (in[0]->elementtype != ELT_NOT_REQUIRED)
{
fprintf(fd, " Object element_type_attr;%s", NEWLINE);
fprintf(fd, " char *element_type;%s", NEWLINE);
}
if (in[0]->positions == GRID_REGULAR)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Regular positions info%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " int p_knt = -1, p_dim, *p_counts = NULL;%s", NEWLINE);
fprintf(fd, " float *p_origin = NULL, *p_deltas = NULL;%s", NEWLINE);
}
else if (in[0]->positions == GRID_IRREGULAR)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Irregular positions info%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " int p_knt, p_dim;%s", NEWLINE);
fprintf(fd, " float *p_positions;%s", NEWLINE);
}
else
fprintf(fd, " int p_knt = -1;%s", NEWLINE);
if (in[0]->connections == GRID_REGULAR)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Regular connections info%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " int c_knt, c_nv, c_dim, *c_counts = NULL;%s", NEWLINE);
}
else if (in[0]->connections == GRID_IRREGULAR)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Irregular connections info%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " int c_knt, c_dim, c_nv;%s", NEWLINE);
fprintf(fd, " float *c_connections;%s", NEWLINE);
}
else
fprintf(fd, " int c_knt = -1;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (in[0]->connections != GRID_NOT_REQUIRED ||
in[0]->positions != GRID_NOT_REQUIRED)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * positions and/or connections are required, so the first must%s", NEWLINE);
fprintf(fd, " * be a field.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (DXGetObjectClass(in[0]) != CLASS_FIELD)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID,%s", NEWLINE);
fprintf(fd, " \"positions and/or connections unavailable in array object\");%s", NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, " else%s", NEWLINE);
}
else
fprintf(fd, " if (DXGetObjectClass(in[0]) == CLASS_FIELD)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " field = (Field)in[0];%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " if (DXEmptyField(field))%s", NEWLINE);
fprintf(fd, " return OK;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /* %s", NEWLINE);
fprintf(fd, " * Determine the dependency of the source object's data%s", NEWLINE);
fprintf(fd, " * component.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " src_dependency_attr = DXGetComponentAttribute(field, \"data\", \"dep\");%s", NEWLINE);
fprintf(fd, " if (! src_dependency_attr)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_MISSING_DATA, \"\\\"%s\\\" data component is missing a dependency attribute\");%s", in[0]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " if (DXGetObjectClass(src_dependency_attr) != CLASS_STRING)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_BAD_CLASS, \"\\\"%s\\\" dependency attribute\");%s", in[0]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " src_dependency = DXGetString((String)src_dependency_attr);%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " array = (Array)DXGetComponentValue(field, \"positions\");%s", NEWLINE);
fprintf(fd, " if (! array)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_BAD_CLASS, \"\\\"%s\\\" contains no positions component\");%s", in[0]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (in[0]->positions == GRID_REGULAR)
{
fprintf(fd, " /* %s", NEWLINE);
fprintf(fd, " * Input[0] should have regular positions. First check%s", NEWLINE);
fprintf(fd, " * that they are, and while you're at it, get the%s", NEWLINE);
fprintf(fd, " * dimensionality so we can size arrays later.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (! DXQueryGridPositions(array, &p_dim, NULL, NULL, NULL))%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_BAD_CLASS, \"\\\"%s\\\" positions component is not regular\");%s", in[0]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /* %s", NEWLINE);
fprintf(fd, " * Allocate arrays for position counts, origin and deltas.%s", NEWLINE);
fprintf(fd, " * Check that the allocations worked, then get the info.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " p_counts = (int *)DXAllocate(p_dim*sizeof(int));%s", NEWLINE);
fprintf(fd, " p_origin = (float *)DXAllocate(p_dim*sizeof(float));%s", NEWLINE);
fprintf(fd, " p_deltas = (float *)DXAllocate(p_dim*p_dim*sizeof(float));%s", NEWLINE);
fprintf(fd, " if (! p_counts || ! p_origin || ! p_deltas)%s", NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " DXQueryGridPositions(array, NULL, p_counts, p_origin, p_deltas);%s", NEWLINE);
fprintf(fd, " DXGetArrayInfo(array, &p_knt, NULL, NULL, NULL, NULL);%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
}
else if (in[0]->positions == GRID_IRREGULAR)
{
fprintf(fd, " /* %s", NEWLINE);
fprintf(fd, " * The user requested irregular positions. So we%s", NEWLINE);
fprintf(fd, " * get the count, the dimensionality and a pointer to the%s", NEWLINE);
fprintf(fd, " * explicitly enumerated positions. If the positions%s", NEWLINE);
fprintf(fd, " * are in fact regular, this will expand them.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " DXGetArrayInfo(array, &p_knt, NULL, NULL, NULL, &p_dim);%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " p_positions = (float *)DXGetArrayData(array);%s", NEWLINE);
fprintf(fd, " if (! p_positions)%s", NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
}
else
fprintf(fd, " DXGetArrayInfo(array, &p_knt, NULL, NULL, NULL, NULL);%s", NEWLINE);
if (in[0]->connections == GRID_REGULAR ||
in[0]->connections == GRID_IRREGULAR ||
in[0]->elementtype != ELT_NOT_REQUIRED)
{
fprintf(fd, " array = (Array)DXGetComponentValue(field, \"connections\");%s", NEWLINE);
fprintf(fd, " if (! array)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_BAD_CLASS, \"\\\"%s\\\" contains no connections component\");%s", in[0]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (in[0]->elementtype != ELT_NOT_REQUIRED)
{
char *str;
if (! GetElementTypeString(in[0]->elementtype, &str))
goto error;
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Check that the field's element type matches that requested%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " element_type_attr = DXGetAttribute((Object)array, \"element type\");%s", NEWLINE);
fprintf(fd, " if (! element_type_attr)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID,%s", NEWLINE);
fprintf(fd, " \"input \\\"%s\\\" has no element type attribute\");%s", in[0]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s%s", NEWLINE, NEWLINE);
fprintf(fd, " if (DXGetObjectClass(element_type_attr) != CLASS_STRING)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID,%s", NEWLINE);
fprintf(fd, " \"input \\\"%s\\\" element type attribute is not a string\");%s", in[0]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s%s", NEWLINE, NEWLINE);
fprintf(fd, " if (strcmp(DXGetString((String)element_type_attr), \"%s\"))%s", str, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID,%s", NEWLINE);
fprintf(fd, " \"input \\\"%s\\\" invalid element type\");%s", in[0]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s%s", NEWLINE, NEWLINE);
}
if (in[0]->connections == GRID_REGULAR)
{
fprintf(fd, " /* %s", NEWLINE);
fprintf(fd, " * Input[0] should have regular connections. First check%s", NEWLINE);
fprintf(fd, " * that they are, and while you're at it, get the%s", NEWLINE);
fprintf(fd, " * dimensionality so we can size an array later.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (! DXQueryGridConnections(array, &c_dim, NULL))%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_BAD_CLASS, \"\\\"%s\\\" connections component is not regular\");%s", in[0]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /* %s", NEWLINE);
fprintf(fd, " * Allocate arrays for connections counts.%s", NEWLINE);
fprintf(fd, " * Check that the allocation worked, then get the info.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " c_counts = (int *)DXAllocate(c_dim*sizeof(int));%s", NEWLINE);
fprintf(fd, " if (! c_counts)%s", NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " DXQueryGridConnections(array, NULL, c_counts);%s", NEWLINE);
fprintf(fd, " DXGetArrayInfo(array, &c_knt, NULL, NULL, NULL, &c_nv);%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
}
else if (in[0]->connections == GRID_IRREGULAR)
{
fprintf(fd, " /* %s", NEWLINE);
fprintf(fd, " * The user requested irregular connections. So we%s", NEWLINE);
fprintf(fd, " * get the count, the dimensionality and a pointer to the%s", NEWLINE);
fprintf(fd, " * explicitly enumerated elements. If the positions%s", NEWLINE);
fprintf(fd, " * are in fact regular, this will expand them.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " DXGetArrayInfo(array, &c_knt, NULL, NULL, NULL, &c_nv);%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " c_connections = (float *)DXGetArrayData(array);%s", NEWLINE);
fprintf(fd, " if (! c_connections)%s", NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
}
else
fprintf(fd, " DXGetArrayInfo(array, &c_knt, NULL, NULL, NULL, NULL);%s", NEWLINE);
}
else
{
fprintf(fd, " /* %s", NEWLINE);
fprintf(fd, " * If there are connections, get their count so that%s", NEWLINE);
fprintf(fd, " * connections-dependent result arrays can be sized.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " array = (Array)DXGetComponentValue(field, \"connections\");%s", NEWLINE);
fprintf(fd, " if (array)%s", NEWLINE);
fprintf(fd, " DXGetArrayInfo(array, &c_knt, NULL, NULL, NULL, NULL);%s", NEWLINE);
}
fprintf(fd, " }%s", NEWLINE);
for (i = 0; i < nin; i )
{
char *type, *rank, *shape;
if (! GetDXDataType(in[i]->datatype, &type) ||
! GetDXDataShape(in[i]->datashape, &rank, &shape))
goto error;
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * If the input argument is not NULL then we get the %s", NEWLINE);
fprintf(fd, " * data array: either the object itself, if its an %s", NEWLINE);
fprintf(fd, " * array, or the data component if the argument is a field%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (! in[%d])%s", i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " array = NULL;%s", NEWLINE);
fprintf(fd, " in_data[%d] = NULL;%s", i, NEWLINE);
fprintf(fd, " in_knt[%d] = NULL;%s", i, NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, " else%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " if (DXGetObjectClass(in[%d]) == CLASS_ARRAY)%s", i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " array = (Array)in[%d];%s", i, NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, " else if (DXGetObjectClass(in[%d]) == CLASS_STRING)%s", i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " in_data[%d] = (Pointer *)DXGetString((String)in[%d]);%s",i,i, NEWLINE);
fprintf(fd, " in_knt[%d] = 1;%s",i, NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, " else%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " if (DXGetObjectClass(in[%d]) != CLASS_FIELD)%s", i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_BAD_CLASS, \"\\\"%s\\\" should be a field\");%s", in[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " array = (Array)DXGetComponentValue((Field)in[%d], \"data\");%s", i, NEWLINE);
fprintf(fd, " if (! array)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_MISSING_DATA, \"\\\"%s\\\" has no data component\");%s", in[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " if (DXGetObjectClass((Object)array) != CLASS_ARRAY)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_BAD_CLASS, \"data component of \\\"%s\\\" should be an array\");%s", in[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (in[i]->dependency != NO_DEPENDENCY)
{
fprintf(fd, " /* %s", NEWLINE);
fprintf(fd, " * get the dependency of the data component%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " attr = DXGetAttribute((Object)array, \"dep\");%s", NEWLINE);
fprintf(fd, " if (! attr)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_MISSING_DATA, \"data component of \\\"%s\\\" has no dependency\");%s", in[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " if (DXGetObjectClass(attr) != CLASS_STRING)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_BAD_CLASS, \"dependency attribute of data component of \\\"%s\\\"\");%s", in[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (in[i]->dependency == DEP_INPUT && i != 0)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * The dependency of this arg should match input[0].%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (strcmp(src_dependency, DXGetString((String)attr)))%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID, \"data dependency of \\\"%s\\\" must match \\\"%s\\\"\");%s",
in[i]->name, in[0]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
}
else if (in[i]->dependency == DEP_POSITIONS)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * The dependency of this arg should be positions%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (strcmp(\"positions\", DXGetString((String)attr)))%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID, \"data dependency of \\\"%s\\\" must be positions\");%s",
in[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
}
else if (in[i]->dependency == DEP_CONNECTIONS)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * The dependency of this arg should be connections%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (strcmp(\"connections\", DXGetString((String)attr)))%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID, \"data dependency of \\\"%s\\\" must be connections\");%s",
in[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
}
}
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " if (DXGetObjectClass(in[%d]) != CLASS_STRING)", i);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXGetArrayInfo(array, &in_knt[%d], &type, &category, &rank, &shape);%s", i, NEWLINE);
fprintf(fd, " if (type != %s || category != CATEGORY_REAL ||%s", type, NEWLINE);
if (! strcmp(rank, "0"))
fprintf(fd, " !((rank == 0) || ((rank == 1)&&(shape == 1))))%s", NEWLINE);
else
fprintf(fd, " rank != %s || shape != %s)%s", rank, shape, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID, \"input \\\"%s\\\"\");%s", in[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " in_data[%d] = DXGetArrayData(array);%s", i, NEWLINE);
fprintf(fd, " if (! in_data[%d])%s", i, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
}
for (i = 0; i < nout; i )
{
char *type, *rank, *shape;
if (! GetDXDataType(out[i]->datatype, &type) ||
! GetDXDataShape(out[i]->datashape, &rank, &shape))
goto error;
if (out[i]->structure == VALUE)
{
fprintf(fd, " if (! out[%d])%s", i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_INTERNAL, \"Value output %d (\\\"%s\\\") is NULL\");%s", i, out[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, " if (DXGetObjectClass(out[%d]) != CLASS_ARRAY)%s", i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_INTERNAL, \"Value output %d (\\\"%s\\\") is not an array\");%s", i, out[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " array = (Array)out[%d];%s", i, NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " DXGetArrayInfo(array, &out_knt[%d], &type, &category, &rank, &shape);%s", i, NEWLINE);
fprintf(fd, " if (type != %s || category != CATEGORY_REAL ||%s", type, NEWLINE);
if (out[i]->datashape == SCALAR)
fprintf(fd, " !((rank == 0) || ((rank == 1)&&(shape == 1))))%s", NEWLINE);
else
fprintf(fd, " rank != %s || shape != %s)%s", rank, shape, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID, \"Value output \\\"%s\\\" has bad type\");%s", out[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
}
else
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Create an output data array typed according to the%s", NEWLINE);
fprintf(fd, " * specification given%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " array = DXNewArray(%s, CATEGORY_REAL, %s, %s);%s", type, rank, shape, NEWLINE);
fprintf(fd, " if (! array)%s", NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
if (out[i]->dependency == DEP_INPUT)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Set the dependency of the array to the same as the first input%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (src_dependency_attr != NULL)%s", NEWLINE);
fprintf(fd, " if (! DXSetAttribute((Object)array, \"dep\", src_dependency_attr))%s", NEWLINE);
fprintf(fd, " goto error;%s%s", NEWLINE, NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * The size and dependency of this output data array will %s", NEWLINE);
fprintf(fd, " * match that of input[0]%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " out_knt[%d] = in_knt[0];%s", i, NEWLINE);
}
else if (out[i]->dependency == DEP_POSITIONS)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * This output data array will be dep positions - and sized%s", NEWLINE);
fprintf(fd, " * appropriately - if the appropriate size is known%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (p_knt == -1)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID,%s", NEWLINE);
fprintf(fd, " \"cannot make output \\\"%s\\\" dep on positions because no positions were found in input[0]\");%s", out[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s%s", NEWLINE, NEWLINE);
fprintf(fd, " out_knt[%d] = p_knt;%s", i, NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " if (! DXSetAttribute((Object)array, \"dep\", (Object)DXNewString(\"positions\")))%s", NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
}
else if (out[i]->dependency == DEP_CONNECTIONS)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * This output data array will be dep connections - and sized%s", NEWLINE);
fprintf(fd, " * appropriately - if the appropriate size is known%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (c_knt == -1)%s", NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_DATA_INVALID,%s", NEWLINE);
fprintf(fd, " \"cannot make output \\\"%s\\\" dep on connections because no connections were found in input \\\"%s\\\"\");%s", out[i]->name, in[i]->name, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s%s", NEWLINE, NEWLINE);
fprintf(fd, " out_knt[%d] = c_knt;%s", i, NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " if (! DXSetAttribute((Object)array, \"dep\", (Object)DXNewString(\"connections\")))%s", NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
}
else
{
ErrorMessage("field parameter must have a dependency set%s", NEWLINE);
goto error;
}
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Actually allocate the array data space%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (! DXAddArrayData(array, 0, out_knt[%d], NULL))%s", i, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * If the output vector slot is not NULL, then it better be a field, and%s", NEWLINE);
fprintf(fd, " * we'll add the new array to it as its data component (delete any prior%s", NEWLINE);
fprintf(fd, " * data component so that its attributes won't overwrite the new component's)%s", NEWLINE);
fprintf(fd, " * Otherwise, place the new array into the out vector.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " if (out[%d])%s", i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " if (DXGetObjectClass(out[%d]) != CLASS_FIELD)%s", i, NEWLINE);
fprintf(fd, " {%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_INTERNAL, \"non-field object found in output vector\");%s", NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, " }%s%s", NEWLINE, NEWLINE);
fprintf(fd, " if (DXGetComponentValue((Field)out[%d], \"data\"))%s", i, NEWLINE);
fprintf(fd, " DXDeleteComponent((Field)out[%d], \"data\");%s%s", i, NEWLINE, NEWLINE);
fprintf(fd, " if (! DXSetComponentValue((Field)out[%d], \"data\", (Object)array))%s", i, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " }%s", NEWLINE);
fprintf(fd, " else%s", NEWLINE);
fprintf(fd, " out[%d] = (Object)array;%s", i, NEWLINE);
}
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Now get the pointer to the contents of the array%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " out_data[%d] = DXGetArrayData(array);%s", i, NEWLINE);
fprintf(fd, " if (! out_data[%d])%s", i, NEWLINE);
fprintf(fd, " goto error;%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
}
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Call the user's routine. Check the return code.%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " result = %s_worker(%s", mod->name, NEWLINE);
open = 0;
if (in[0]->positions == GRID_REGULAR)
{
fprintf(fd, " p_knt, p_dim, p_counts, p_origin, p_deltas");
open = 1;
}
else if (in[0]->positions == GRID_IRREGULAR)
{
fprintf(fd, " p_knt, p_dim, (float *)p_positions");
open = 1;
}
if (in[0]->connections == GRID_REGULAR)
{
fprintf(fd, "%s c_knt, c_nv, c_counts", (open)?COMMA_AND_NEWLINE:"");
open = 1;
}
else if (in[0]->connections == GRID_IRREGULAR)
{
fprintf(fd, "%s c_knt, c_nv, (int *)c_connections", (open)?COMMA_AND_NEWLINE:"");
open = 1;
}
for (i = 0; i < nin; i )
{
char *type;
GetCDataType(in[i]->datatype, &type);
fprintf(fd, "%s in_knt[%d], (%s *)in_data[%d]", (open)?COMMA_AND_NEWLINE:"", i, type, i);
open = 1;
}
for (i = 0; i < nout; i )
{
char *type;
GetCDataType(out[i]->datatype, &type);
fprintf(fd, "%s out_knt[%d], (%s *)out_data[%d]", (open)?COMMA_AND_NEWLINE:"", i, type, i);
open = 1;
}
fprintf(fd, ");%s%s", NEWLINE, NEWLINE);
fprintf(fd, " if (! result)%s", NEWLINE);
fprintf(fd, " if (DXGetError()==ERROR_NONE)%s", NEWLINE);
fprintf(fd, " DXSetError(ERROR_INTERNAL, \"error return from user routine\");%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * In either event, clean up allocated memory%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, "%s", NEWLINE);
fprintf(fd, "error:%s", NEWLINE);
if (in[0]->positions == GRID_REGULAR)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Free the arrays allocated for the regular positions%s", NEWLINE);
fprintf(fd, " * counts, origin and deltas%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " DXFree((Pointer)p_counts);%s", NEWLINE);
fprintf(fd, " DXFree((Pointer)p_origin);%s", NEWLINE);
fprintf(fd, " DXFree((Pointer)p_deltas);%s", NEWLINE);
}
if (in[0]->connections == GRID_REGULAR)
{
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * Free the arrays allocated for the regular connections%s", NEWLINE);
fprintf(fd, " * counts%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " DXFree((Pointer)c_counts);%s", NEWLINE);
}
fprintf(fd, " return result;%s", NEWLINE);
fprintf(fd, "}%s%s", NEWLINE, NEWLINE);
fprintf(fd, "int%s%s_worker(\n", NEWLINE, mod->name);
open = 0;
if (in[0]->positions == GRID_REGULAR)
{
fprintf(fd, " int p_knt, int p_dim, int *p_counts, float *p_origin, float *p_deltas");
open = 1;
}
else if (in[0]->positions == GRID_IRREGULAR)
{
fprintf(fd, " int p_knt, int p_dim, float *p_positions");
open = 1;
}
if (in[0]->connections == GRID_REGULAR)
{
fprintf(fd, "%s int c_knt, int c_nv, int *c_counts", (open)?COMMA_AND_NEWLINE:"");
open = 1;
}
else if (in[0]->connections == GRID_IRREGULAR)
{
fprintf(fd, "%s int c_knt, int c_nv, int *c_connections", (open)?COMMA_AND_NEWLINE:"");
open = 1;
}
for (i = 0; i < nin; i )
{
char *type;
GetCDataType(in[i]->datatype, &type);
fprintf(fd, "%s int %s_knt, %s *%s_data", (open)?COMMA_AND_NEWLINE:"", in[i]->name, type, in[i]->name);
open = 1;
}
for (i = 0; i < nout; i )
{
char *type;
GetCDataType(out[i]->datatype, &type);
fprintf(fd, "%s int %s_knt, %s *%s_data", (open)?COMMA_AND_NEWLINE:"", out[i]->name, type, out[i]->name);
open = 1;
}
fprintf(fd, ")%s{%s", NEWLINE, NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * The arguments to this routine are:%s", NEWLINE);
fprintf(fd, " *%s", NEWLINE);
if (in[0]->positions == GRID_REGULAR)
{
fprintf(fd, " * p_knt: total count of input positions%s", NEWLINE);
fprintf(fd, " * p_dim: dimensionality of input positions%s", NEWLINE);
fprintf(fd, " * p_counts: count along each axis of regular positions grid%s", NEWLINE);
fprintf(fd, " * p_origin: origin of regular positions grid%s", NEWLINE);
fprintf(fd, " * p_deltas: regular positions delta vectors%s", NEWLINE);
}
else if (in[0]->positions == GRID_IRREGULAR)
{
fprintf(fd, " * p_knt: total count of input positions%s", NEWLINE);
fprintf(fd, " * p_dim: dimensionality of input positions%s", NEWLINE);
fprintf(fd, " * p_positions: pointer to positions list%s", NEWLINE);
}
if (in[0]->connections == GRID_REGULAR)
{
fprintf(fd, " * c_knt: total count of input connections elements%s", NEWLINE);
fprintf(fd, " * c_nv: number of vertices per element%s", NEWLINE);
fprintf(fd, " * c_counts: vertex count along each axis of regular positions grid%s", NEWLINE);
}
else if (in[0]->connections == GRID_IRREGULAR)
{
fprintf(fd, " * c_knt: total count of input connections elements%s", NEWLINE);
fprintf(fd, " * c_nv: number of vertices per element%s", NEWLINE);
fprintf(fd, " * c_connections: pointer to connections list%s", NEWLINE);
}
fprintf(fd, " *%s", NEWLINE);
fprintf(fd, " * The following are inputs and therefore are read-only. The default%s", NEWLINE);
fprintf(fd, " * values are given and should be used if the knt is 0.%s", NEWLINE);
fprintf(fd, " *%s", NEWLINE);
for (i = 0; i < nin; i )
{
fprintf(fd, " * %s_knt, %s_data: count and pointer for input \"%s\"%s", in[i]->name, in[i]->name, in[i]->name, NEWLINE);
if (in[i]->default_value)
if (in[i]->descriptive == TRUE)
fprintf(fd, " * descriptive default value is \"%s\"%s", in[i]->default_value, NEWLINE);
else
fprintf(fd, " * non-descriptive default value is \"%s\"%s", in[i]->default_value, NEWLINE);
else
fprintf(fd, " * no default value given.%s", NEWLINE);
}
fprintf(fd, " *%s", NEWLINE);
fprintf(fd, " * The output data buffer(s) are writable.%s", NEWLINE);
fprintf(fd, " * The output buffer(s) are preallocated based on%s", NEWLINE);
fprintf(fd, " * the dependency (positions or connections),%s", NEWLINE);
fprintf(fd, " * the size of the corresponding positions or%s", NEWLINE);
fprintf(fd, " * connections component in the first input, and%s", NEWLINE);
fprintf(fd, " * the data type.%s", NEWLINE);
fprintf(fd, " *%s", NEWLINE);
for (i = 0; i < nout; i )
{
fprintf(fd, " * %s_knt, %s_data: count and pointer for output \"%s\"%s",
out[i]->name, out[i]->name, out[i]->name, NEWLINE);
}
fprintf(fd, " */%s%s", NEWLINE, NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * User's code goes here%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " %s", NEWLINE);
fprintf(fd, " %s", NEWLINE);
/* was an include file specified? */
if(mod->include_file != NULL)
fprintf(fd, "#include \"%s\" %s%s", mod->include_file, NEWLINE, NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * successful completion%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, " return 1;%s", NEWLINE);
fprintf(fd, " %s", NEWLINE);
fprintf(fd, " /*%s", NEWLINE);
fprintf(fd, " * unsuccessful completion%s", NEWLINE);
fprintf(fd, " */%s", NEWLINE);
fprintf(fd, "error:%s", NEWLINE);
fprintf(fd, " return 0;%s", NEWLINE);
fprintf(fd, " %s}%s", NEWLINE, NEWLINE);
fclose(fd);
free(buf);
return 1;
error:
if (fd)
{
fclose(fd);
unlink(buf);
}
free(buf);
return 0;
}
#define COPYSTRING(dst, src) \
{ \
(dst) = (char *)malloc(strlen((src)) 1); \
if ((dst) == NULL) { \
ErrorMessage("allocation error"); \
goto error; \
} \
\
strcpy((dst), (src)); \
}
#define TRUEFALSE(dst, src) \
{ \
if (! strcmp((src), "TRUE")) \
(dst) = TRUE; \
else if (! strcmp((src), "FALSE")) \
(dst) = FALSE; \
else { \
ErrorMessage("invalid true/false: %s\n", src); \
goto error; \
} \
}
static int
copy_comments(char *basename, FILE *out, char *hdr, char *ldr, char *trlr)
{
FILE *in = NULL;
int first_comment = 1, comment_found = 0;
int first_char = 1, is_comment;
int i, c;
char *buf = (char *)malloc(strlen(basename) 4);
if (! buf)
{
ErrorMessage("allocation error");
goto error;
}
sprintf(buf, "%s.mb", basename);
in = fopen(buf, "r");
free(buf);
buf = 0;
if (! in)
{
ErrorMessage("error opening mb file");
return 0;
}
while (! feof(in))
{
c = getc(in);
if (first_char)
is_comment = (c == '#');
if (is_comment)
{
comment_found = 1;
if (first_comment && hdr)
{
for(i = 0; hdr[i] != '\0'; i )
if (! putc(hdr[i], out))
return 0;
first_comment = 0;
}
if (first_char && ldr)
{
for(i = 0; ldr[i] != '\0'; i )
if (! putc(ldr[i], out))
return 0;
}
else
if (! putc(c, out))
return 0;
}
if (c == '\n')
first_char = 1;
else
first_char = 0;
}
if (comment_found && trlr)
{
for(i = 0; trlr[i] != '\0'; i )
if (! putc(trlr[i], out))
return 0;
first_comment = 0;
}
fclose(in);
return 1;
error:
if (in)
fclose(in);
return 0;
}
#define MAXLINE 16384
char linebuf[MAXLINE];
#define WHITESPACE(l) ((l) == ' ' || (l) == '\t')
char *
_dxf_getline(FILE *fd)
{
int i;
int c;
if (feof(fd))
return NULL;
do
{
c = getc(fd);
} while (c != EOF && WHITESPACE(c));
if (c == EOF)
return NULL;
for (i = 0; i < MAXLINE; i , c = getc(fd))
{
linebuf[i] = c;
if (c == EOF || c == '\n')
{
while (i > 0 && WHITESPACE(linebuf[i-1]))
i--;
linebuf[i] = '\0';
break;
}
}
if (i == MAXLINE)
{
ErrorMessage("line exceeds max length");
return NULL;
}
return linebuf;
}
static void
parseline(char *line, char **name, char **value)
{
*name = line;
while (!WHITESPACE(*line) && *line != '=')
line ;
*line = '\0';
line ;
while (WHITESPACE(*line) || *line == '=')
line ;
*value = line;
}
#define ISTOKEN(a,b) (!strcmp(a, b))
static int
process_input(char *basename, Module *mod, Parameter **in, Parameter **out)
{
FILE *fd = NULL;
int nin = 0, nout = 0;
int linenum;
char *line, *name, *value;
Parameter *parameter = NULL;
char *buf = (char *)malloc(strlen(basename) 4);
if (! buf)
{
ErrorMessage("allocation error");
goto error;
}
sprintf(buf, "%s.mb", basename);
mod->name = NULL;
mod->category = NULL;
mod->description = NULL;
mod->outboard_executable = NULL;
mod->include_file = NULL;
mod->outboard_persistent = UNKNOWN;
mod->asynchronous = UNKNOWN;
mod->pinned = UNKNOWN;
mod->side_effect = UNKNOWN;
in[0] = NULL; out[0] = NULL;
fd = fopen(buf, "r");
free(buf);
buf = 0;
if (! fd)
{
ErrorMessage("error opening file: %s\n", basename);
goto error;
}
linenum = -1;
while (NULL != (line = _dxf_getline(fd)))
{
linenum ;
if (line[0] == '\0')
continue;
if (line[0] == '#')
continue;
/* FIXME */
/*if (line[-1] == -1)
goto error;*/
parseline(line, &name, &value);
if (ISTOKEN(name, "MODULE_NAME")) {
COPYSTRING(mod->name, value);
}
else if (ISTOKEN(name, "CATEGORY")) {
COPYSTRING(mod->category, value);
}
else if (ISTOKEN(name, "MODULE_DESCRIPTION")) {
COPYSTRING(mod->description, value);
}
else if (ISTOKEN(name, "OUTBOARD_HOST")) {
COPYSTRING(mod->outboard_host, value);
}
else if (ISTOKEN(name, "OUTBOARD_EXECUTABLE")) {
COPYSTRING(mod->outboard_executable, value);
}
else if (ISTOKEN(name, "LOADABLE_EXECUTABLE")) {
COPYSTRING(mod->loadable_executable, value);
}
else if (ISTOKEN(name, "INCLUDE_FILE")) {
COPYSTRING(mod->include_file, value);
}
else if (ISTOKEN(name, "OUTBOARD_PERSISTENT")) {
TRUEFALSE(mod->outboard_persistent, value);
}
else if (ISTOKEN(name, "ASYNCHRONOUS")) {
TRUEFALSE(mod->asynchronous, value);
}
else if (ISTOKEN(name, "PINNED")) {
TRUEFALSE(mod->pinned, value);
}
else if (ISTOKEN(name, "SIDE_EFFECT")) {
TRUEFALSE(mod->side_effect, value);
}
else if (ISTOKEN(name, "LANGUAGE")) {
if (ISTOKEN(value, "C"))
mod->language = C;
else if (ISTOKEN(value, "Fortran"))
mod->language = FORTRAN;
else
{
ErrorMessage("unrecognized LANGUAGE: %s\n", value);
return 0;
}
}
else if (ISTOKEN(name, "INPUT"))
{
in[nin] = (Parameter *)malloc(sizeof(Parameter));
if (in[nin] == NULL)
{
ErrorMessage("allocation error");
goto error;
}
parameter = in[nin];
nin ;
COPYSTRING(parameter->name, value);
parameter->description = NULL;
parameter->required = UNKNOWN;
parameter->default_value = NULL;
parameter->types = NULL;
parameter->structure = NO_STRUCTURE;
parameter->datatype = NO_DATATYPE;
parameter->datashape = NO_DATASHAPE;
parameter->counts = NO_COUNTS;
parameter->positions = GRID_NOT_REQUIRED;
parameter->connections = GRID_NOT_REQUIRED;
parameter->elementtype = ELT_NOT_REQUIRED;
parameter->dependency = NO_DEPENDENCY;
}
else if (ISTOKEN(name, "OUTPUT"))
{
out[nout] = (Parameter *)malloc(sizeof(Parameter));
if (out[nout] == NULL)
{
ErrorMessage("allocation error");
goto error;
}
parameter = out[nout];
nout ;
COPYSTRING(parameter->name, value);
parameter->description = NULL;
parameter->required = UNKNOWN;
parameter->default_value = NULL;
parameter->types = NULL;
parameter->structure = NO_STRUCTURE;
parameter->datatype = NO_DATATYPE;
parameter->datashape = NO_DATASHAPE;
parameter->counts = NO_COUNTS;
parameter->positions = GRID_NOT_REQUIRED;
parameter->connections = GRID_NOT_REQUIRED;
parameter->elementtype = ELT_NOT_REQUIRED;
parameter->dependency = NO_DEPENDENCY;
}
else if (ISTOKEN(name, "DESCRIPTION"))
{
if (! parameter)
{
ErrorMessage("syntax error line %d\n DESCRIPTION encountered outside of parameter definition", linenum);
goto error;
}
COPYSTRING(parameter->description, value);
}
else if (ISTOKEN(name, "DESCRIPTIVE"))
{
if (! parameter)
{
ErrorMessage("syntax error line %d\n DESCRIPTIVE encountered outsideof parameter definition", linenum);
goto error;
}
TRUEFALSE(parameter->descriptive, value);
}
else if (ISTOKEN(name, "REQUIRED"))
{
if (! parameter)
{
ErrorMessage("syntax error line %d\n REQUIRED encountered outsideof parameter definition", linenum);
goto error;
}
TRUEFALSE(parameter->required, value);
}
else if (ISTOKEN(name, "DEFAULT_VALUE"))
{
if (! parameter)
{
ErrorMessage("syntax error line %d\nDEFAULT_VALUE encountered outside of parameter definition", linenum);
goto error;
}
COPYSTRING(parameter->default_value, value);
}
else if (ISTOKEN(name, "TYPES"))
{
if (! parameter)
{
ErrorMessage("syntax error line %d\nTYPES encountered outsideof parameter definition", linenum);
goto error;
}
COPYSTRING(parameter->types, value);
}
else if (ISTOKEN(name, "STRUCTURE"))
{
if (! parameter)
{
ErrorMessage("syntax error line %d\nSTRUCTURE encountered outside of parameter definition", linenum);
goto error;
}
if (ISTOKEN(value, "Value"))
parameter->structure = VALUE;
else if (ISTOKEN(value, "Field/Group"))
parameter->structure = GROUP_FIELD;
else
{
ErrorMessage("unknown STRUCTURE: %s\n", value);
goto error;
}
}
else if (ISTOKEN(name, "DATA_TYPE"))
{
if (! parameter)
{
ErrorMessage("syntax error line %d\nDATA_TYPE encountered outside of parameter definition", linenum);
goto error;
}
if (ISTOKEN(value, "float"))
parameter->datatype = FLOAT;
else if (ISTOKEN(value, "double"))
parameter->datatype = DOUBLE;
else if (ISTOKEN(value, "int"))
parameter->datatype = INT;
else if (ISTOKEN(value, "uint"))
parameter->datatype = UINT;
else if (ISTOKEN(value, "short"))
parameter->datatype = SHORT;
else if (ISTOKEN(value, "ushort"))
parameter->datatype = USHORT;
else if (ISTOKEN(value, "byte"))
parameter->datatype = BYTE;
else if (ISTOKEN(value, "ubyte"))
parameter->datatype = UBYTE;
else if (ISTOKEN(value, "string"))
parameter->datatype = STRING;
else
{
ErrorMessage("unknown DATATYPE: %s\n", value);
goto error;
}
}
else if (ISTOKEN(name, "DATA_SHAPE"))
{
if (! parameter)
{
ErrorMessage("syntax error line �ATA_SHAPE encountered outside of parameter definition\n", linenum);
goto error;
}
if (ISTOKEN(value, "Scalar"))
parameter->datashape = SCALAR;
else if (ISTOKEN(value, "1-vector"))
parameter->datashape = VECTOR_1;
else if (ISTOKEN(value, "2-vector"))
parameter->datashape = VECTOR_2;
else if (ISTOKEN(value, "3-vector"))
parameter->datashape = VECTOR_3;
else if (ISTOKEN(value, "4-vector"))
parameter->datashape = VECTOR_4;
else if (ISTOKEN(value, "5-vector"))
parameter->datashape = VECTOR_5;
else if (ISTOKEN(value, "6-vector"))
parameter->datashape = VECTOR_6;
else if (ISTOKEN(value, "7-vector"))
parameter->datashape = VECTOR_7;
else if (ISTOKEN(value, "8-vector"))
parameter->datashape = VECTOR_8;
else if (ISTOKEN(value, "9-vector"))
parameter->datashape = VECTOR_9;
else
{
ErrorMessage("unknown DATASHAPE: %s\n", value);
goto error;
}
}
else if (ISTOKEN(name, "ELEMENT_TYPE"))
{
if (! parameter)
{
ErrorMessage("syntax error line %d\nELEMENT_TYPE encountered outside of parameter definition", linenum);
goto error;
}
if (ISTOKEN(value, "Lines"))
parameter->elementtype = ELT_LINES;
else if (ISTOKEN(value, "Triangles"))
parameter->elementtype = ELT_TRIANGLES;
else if (ISTOKEN(value, "Quads"))
parameter->elementtype = ELT_QUADS;
else if (ISTOKEN(value, "Tetrahedra"))
parameter->elementtype = ELT_TETRAHEDRA;
else if (ISTOKEN(value, "Cubes"))
parameter->elementtype = ELT_CUBES;
else if (ISTOKEN(value, "Not required"))
parameter->elementtype = ELT_NOT_REQUIRED;
else
{
ErrorMessage("unknown ELEMENT_TYPE: %s\n", value);
goto error;
}
}
else if (ISTOKEN(name, "COUNTS"))
{
if (! parameter)
{
ErrorMessage("syntax error line %d\nCOUNTS encountered outside of parameter definition", linenum);
goto error;
}
if (ISTOKEN(value, "1"))
parameter->counts = COUNTS_1;
else if (ISTOKEN(value, "same as input"))
parameter->counts = COUNTS_SAME_AS_INPUT;
else
{
ErrorMessage("unknown COUNTS: %s\n", value);
goto error;
}
}
else if (ISTOKEN(name, "POSITIONS"))
{
if (! parameter)
{
ErrorMessage("syntax error line %d\nPOSITIONS encountered outside of parameter definition", linenum);
goto error;
}
if (ISTOKEN(value, "Regular"))
parameter->positions = GRID_REGULAR;
else if (ISTOKEN(value, "Irregular"))
parameter->positions = GRID_IRREGULAR;
else if (ISTOKEN(value, "Not required"))
parameter->positions = GRID_NOT_REQUIRED;
else
{
ErrorMessage("unknown POSITIONS: %s\n", value);
goto error;
}
}
else if (ISTOKEN(name, "CONNECTIONS"))
{
if (! parameter)
{
ErrorMessage("syntax error line %d\nCONNECTIONS encountered outside of parameter definition", linenum);
goto error;
}
if (ISTOKEN(value, "Regular"))
parameter->connections = GRID_REGULAR;
else if (ISTOKEN(value, "Irregular"))
parameter->connections = GRID_IRREGULAR;
else if (ISTOKEN(value, "Not required"))
parameter->connections = GRID_NOT_REQUIRED;
else
{
ErrorMessage("unknown CONNECTIONS: %s\n", value);
goto error;
}
}
else if (ISTOKEN(name, "DEPENDENCY"))
{
if (! parameter)
{
ErrorMessage("syntax error line %d\nDEPENDENCY encountered outside of parameter definition", linenum);
goto error;
}
if (ISTOKEN(value, "No dependency"))
parameter->dependency = NO_DEPENDENCY;
else if (ISTOKEN(value, "Positions only"))
parameter->dependency = DEP_POSITIONS;
else if (ISTOKEN(value, "Connections only"))
parameter->dependency = DEP_CONNECTIONS;
else if (ISTOKEN(value, "Positions or connections"))
parameter->dependency = DEP_INPUT;
else
{
ErrorMessage("unknown DEPENDENCY: %s\n", value);
goto error;
}
}
else
{
ErrorMessage("unrecognized keyword on line %d: %s\n",
linenum, name);
goto error;
}
}
in[nin] = NULL;
out[nout] = NULL;
fclose(fd);
return 1;
error:
if (fd)
fclose(fd);
return 0;
}
static int
GetDXDataType(enum datatype t, char **type)
{
switch(t)
{
case DOUBLE: *type = "TYPE_DOUBLE"; break;
case FLOAT: *type = "TYPE_FLOAT"; break;
case INT: *type = "TYPE_INT"; break;
case UINT: *type = "TYPE_UINT"; break;
case SHORT: *type = "TYPE_SHORT"; break;
case USHORT: *type = "TYPE_USHORT"; break;
case BYTE: *type = "TYPE_BYTE"; break;
case UBYTE: *type = "TYPE_UBYTE"; break;
case STRING: *type = "TYPE_STRING"; break;
default:
ErrorMessage("cannot create array without DATATYPE");
return 0;
}
return 1;
}
static int
GetCDataType(enum datatype t, char **type)
{
switch(t)
{
case DOUBLE: *type = "double"; break;
case FLOAT: *type = "float"; break;
case INT: *type = "int"; break;
case UINT: *type = "unsigned int"; break;
case SHORT: *type = "short"; break;
case USHORT: *type = "unsigned short"; break;
case BYTE: *type = "byte"; break;
case UBYTE: *type = "ubyte"; break;
case STRING: *type = "char"; break;
default:
ErrorMessage("cannot create array without DATATYPE");
return 0;
}
return 1;
}
static int
GetDXDataShape(enum datashape t, char **r, char **s)
{
switch(t)
{
case SCALAR: *r = "0"; *s = "0"; break;
case VECTOR_1: *r = "1"; *s = "1"; break;
case VECTOR_2: *r = "1"; *s = "2"; break;
case VECTOR_3: *r = "1"; *s = "3"; break;
case VECTOR_4: *r = "1"; *s = "4"; break;
case VECTOR_5: *r = "1"; *s = "5"; break;
case VECTOR_6: *r = "1"; *s = "6"; break;
case VECTOR_7: *r = "1"; *s = "7"; break;
case VECTOR_8: *r = "1"; *s = "8"; break;
case VECTOR_9: *r = "1"; *s = "9"; break;
default:
ErrorMessage("cannot create array without DATASHAPE");
return 0;
}
return 1;
}
static int
GetElementTypeString(enum elementtype t, char **r)
{
switch(t)
{
case ELT_LINES: *r = "lines"; break;
case ELT_TRIANGLES: *r = "triangles"; break;
case ELT_QUADS: *r = "quads"; break;
case ELT_TETRAHEDRA: *r = "tetrahedra"; break;
case ELT_CUBES: *r = "cubes"; break;
default:
ErrorMessage("no element type string available");
return 0;
}
return 1;
}
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
|