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
|
/***********************************************************************/
/* UTIL.C - Utility routines */
/***********************************************************************/
/*
* THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
* Copyright (C) 1991-1999 Mark Hessling
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
*
* The Free Software Foundation, Inc.
* 675 Mass Ave,
* Cambridge, MA 02139 USA.
*
*
* If you make modifications to this software that you feel increases
* it usefulness for the rest of the community, please email the
* changes, enhancements, bug fixes as well as any and all ideas to me.
* This software is going to be maintained and enhanced as deemed
* necessary by the community.
*
* Mark Hessling, M.Hessling@qut.edu.au http://www.lightlink.com/hessling/
* PO Box 203, Bellara, QLD 4507, AUSTRALIA
* Author of THE, a Free XEDIT/KEDIT editor and, Rexx/SQL
* Maintainer of PDCurses: Public Domain Curses and, Regina Rexx interpreter
* Use Rexx ? join the Rexx Language Association: http://www.rexxla.org
*/
static char RCSid[] = "$Id: util.c,v 1.3 2001/04/16 09:40:57 mark Exp $";
#include <the.h>
#include <proto.h>
#ifdef my_stricmp
# undef my_stricmp
#endif
/*--------------------------- common data -----------------------------*/
static CHARTYPE *rcvry[MAX_RECV];
static LENGTHTYPE rcvry_len[MAX_RECV];
static short add_rcvry=(-1);
static short retr_rcvry=(-1);
static short num_rcvry=0;
static int CompareLen=0;
static bool CompareExact;
#ifdef USE_EXTCURSES
chtype color_pair[COLOR_PAIRS];
static chtype fore_color[8];
static chtype back_color[8];
#endif
/*
* ASCII to EBCDIC
*/
static unsigned char asc2ebc_table[256] = {
0x00 ,0x01 ,0x02 ,0x03 ,0x37 ,0x2D ,0x2E ,0x2F, /* 00 - 07 */
0x16 ,0x05 ,0x25 ,0x0B ,0x0C ,0x0D ,0x0E ,0x0F, /* 08 - 0f */
0x10 ,0x11 ,0x12 ,0x13 ,0x3C ,0x3D ,0x32 ,0x26, /* 10 - 17 */
0x18 ,0x19 ,0x3F ,0x27 ,0x22 ,0x1D ,0x35 ,0x1F, /* 18 - 1f */
0x40 ,0x5A ,0x7F ,0x7B ,0x5B ,0x6C ,0x50 ,0x7D, /* 20 - 27 */
0x4D ,0x5D ,0x5C ,0x4E ,0x6B ,0x60 ,0x4B ,0x61, /* 28 - 2f */
0xF0 ,0xF1 ,0xF2 ,0xF3 ,0xF4 ,0xF5 ,0xF6 ,0xF7, /* 30 - 37 */
0xF8 ,0xF9 ,0x7A ,0x5E ,0x4C ,0x7E ,0x6E ,0x6F, /* 38 - 3f */
0x7C ,0xC1 ,0xC2 ,0xC3 ,0xC4 ,0xC5 ,0xC6 ,0xC7, /* 40 - 47 */
0xC8 ,0xC9 ,0xD1 ,0xD2 ,0xD3 ,0xD4 ,0xD5 ,0xD6, /* 48 - 4f */
0xD7 ,0xD8 ,0xD9 ,0xE2 ,0xE3 ,0xE4 ,0xE5 ,0xE6, /* 50 - 57 */
0xE7 ,0xE8 ,0xE9 ,0xAD ,0xE0 ,0xBD ,0x5F ,0x6D, /* 58 - 5f */
0x79 ,0x81 ,0x82 ,0x83 ,0x84 ,0x85 ,0x86 ,0x87, /* 60 - 67 */
0x88 ,0x89 ,0x91 ,0x92 ,0x93 ,0x94 ,0x95 ,0x96, /* 68 - 6f */
0x97 ,0x98 ,0x99 ,0xA2 ,0xA3 ,0xA4 ,0xA5 ,0xA6, /* 70 - 77 */
0xA7 ,0xA8 ,0xA9 ,0xC0 ,0x4F ,0xD0 ,0xA1 ,0x07, /* 78 - 7f */
0x43 ,0x20 ,0x21 ,0x1C ,0x23 ,0xEB ,0x24 ,0x9B, /* 80 - 87 */
0x71 ,0x28 ,0x38 ,0x49 ,0x90 ,0xBA ,0xEC ,0xDF, /* 88 - 8f */
0x45 ,0x29 ,0x2A ,0x9D ,0x72 ,0x2B ,0x8A ,0x9A, /* 90 - 97 */
0x67 ,0x56 ,0x64 ,0x4A ,0x53 ,0x68 ,0x59 ,0x46, /* 98 - 9f */
0xEA ,0xDA ,0x2C ,0xDE ,0x8B ,0x55 ,0x41 ,0xFE, /* a0 - a7 */
0x58 ,0x51 ,0x52 ,0x48 ,0x69 ,0xDB ,0x8E ,0x8D, /* a8 - af */
0x73 ,0x74 ,0x75 ,0xFA ,0x15 ,0xB0 ,0xB1 ,0xB3, /* b0 - b7 */
0xB4 ,0xB5 ,0x6A ,0xB7 ,0xB8 ,0xB9 ,0xCC ,0xBC, /* b8 - bf */
0xAB ,0x3E ,0x3B ,0x0A ,0xBF ,0x8F ,0x3A ,0x14, /* c0 - c7 */
0xA0 ,0x17 ,0xCB ,0xCA ,0x1A ,0x1B ,0x9C ,0x04, /* c8 - cf */
0x34 ,0xEF ,0x1E ,0x06 ,0x08 ,0x09 ,0x77 ,0x70, /* d0 - d7 */
0xBE ,0xBB ,0xAC ,0x54 ,0x63 ,0x65 ,0x66 ,0x62, /* d8 - df */
0x30 ,0x42 ,0x47 ,0x57 ,0xEE ,0x33 ,0xB6 ,0xE1, /* e0 - e7 */
0xCD ,0xED ,0x36 ,0x44 ,0xCE ,0xCF ,0x31 ,0xAA, /* e8 - ef */
0xFC ,0x9E ,0xAE ,0x8C ,0xDD ,0xDC ,0x39 ,0xFB, /* f0 - f7 */
0x80 ,0xAF ,0xFD ,0x78 ,0x76 ,0xB2 ,0x9F ,0xFF /* f8 - ff */
};
/*
* EBCDIC to ASCII
*/
static unsigned char ebc2asc_table[256] = {
0x00 ,0x01 ,0x02 ,0x03 ,0xCF ,0x09 ,0xD3 ,0x7F, /* 00 - 07 */
0xD4 ,0xD5 ,0xC3 ,0x0B ,0x0C ,0x0D ,0x0E ,0x0F, /* 08 - 0f */
0x10 ,0x11 ,0x12 ,0x13 ,0xC7 ,0xB4 ,0x08 ,0xC9, /* 10 - 17 */
0x18 ,0x19 ,0xCC ,0xCD ,0x83 ,0x1D ,0xD2 ,0x1F, /* 18 - 1f */
0x81 ,0x82 ,0x1C ,0x84 ,0x86 ,0x0A ,0x17 ,0x1B, /* 20 - 27 */
0x89 ,0x91 ,0x92 ,0x95 ,0xA2 ,0x05 ,0x06 ,0x07, /* 28 - 2f */
0xE0 ,0xEE ,0x16 ,0xE5 ,0xD0 ,0x1E ,0xEA ,0x04, /* 30 - 37 */
0x8A ,0xF6 ,0xC6 ,0xC2 ,0x14 ,0x15 ,0xC1 ,0x1A, /* 38 - 3f */
0x20 ,0xA6 ,0xE1 ,0x80 ,0xEB ,0x90 ,0x9F ,0xE2, /* 40 - 47 */
0xAB ,0x8B ,0x9B ,0x2E ,0x3C ,0x28 ,0x2B ,0x7C, /* 48 - 4f */
0x26 ,0xA9 ,0xAA ,0x9C ,0xDB ,0xA5 ,0x99 ,0xE3, /* 50 - 57 */
0xA8 ,0x9E ,0x21 ,0x24 ,0x2A ,0x29 ,0x3B ,0x5E, /* 58 - 5f */
0x2D ,0x2F ,0xDF ,0xDC ,0x9A ,0xDD ,0xDE ,0x98, /* 60 - 67 */
0x9D ,0xAC ,0xBA ,0x2C ,0x25 ,0x5F ,0x3E ,0x3F, /* 68 - 6f */
0xD7 ,0x88 ,0x94 ,0xB0 ,0xB1 ,0xB2 ,0xFC ,0xD6, /* 70 - 77 */
0xFB ,0x60 ,0x3A ,0x23 ,0x40 ,0x27 ,0x3D ,0x22, /* 78 - 7f */
0xF8 ,0x61 ,0x62 ,0x63 ,0x64 ,0x65 ,0x66 ,0x67, /* 80 - 87 */
0x68 ,0x69 ,0x96 ,0xA4 ,0xF3 ,0xAF ,0xAE ,0xC5, /* 88 - 8f */
0x8C ,0x6A ,0x6B ,0x6C ,0x6D ,0x6E ,0x6F ,0x70, /* 90 - 97 */
0x71 ,0x72 ,0x97 ,0x87 ,0xCE ,0x93 ,0xF1 ,0xFE, /* 98 - 9f */
0xC8 ,0x7E ,0x73 ,0x74 ,0x75 ,0x76 ,0x77 ,0x78, /* a0 - a7 */
0x79 ,0x7A ,0xEF ,0xC0 ,0xDA ,0x5B ,0xF2 ,0xF9, /* a8 - af */
0xB5 ,0xB6 ,0xFD ,0xB7 ,0xB8 ,0xB9 ,0xE6 ,0xBB, /* b0 - b7 */
0xBC ,0xBD ,0x8D ,0xD9 ,0xBF ,0x5D ,0xD8 ,0xC4, /* b8 - bf */
0x7B ,0x41 ,0x42 ,0x43 ,0x44 ,0x45 ,0x46 ,0x47, /* c0 - c7 */
0x48 ,0x49 ,0xCB ,0xCA ,0xBE ,0xE8 ,0xEC ,0xED, /* c8 - cf */
0x7D ,0x4A ,0x4B ,0x4C ,0x4D ,0x4E ,0x4F ,0x50, /* d0 - d7 */
0x51 ,0x52 ,0xA1 ,0xAD ,0xF5 ,0xF4 ,0xA3 ,0x8F, /* d8 - df */
0x5C ,0xE7 ,0x53 ,0x54 ,0x55 ,0x56 ,0x57 ,0x58, /* e0 - e7 */
0x59 ,0x5A ,0xA0 ,0x85 ,0x8E ,0xE9 ,0xE4 ,0xD1, /* e8 - ef */
0x30 ,0x31 ,0x32 ,0x33 ,0x34 ,0x35 ,0x36 ,0x37, /* f0 - f7 */
0x38 ,0x39 ,0xB3 ,0xF7 ,0xF0 ,0xFA ,0xA7 ,0xFF
};
/***********************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *asc2ebc(CHARTYPE *str,int len,int start,int end)
#else
CHARTYPE *asc2ebc(str,len,start,end)
CHARTYPE *str;
int len;
int start;
int end;
#endif
/***********************************************************************/
/* Function : Converts an ASCII string to an EBCDIC string. */
/* Parameters: str - ASCII string */
/* len - length of string to convert */
/* Return : *str - the same string converted */
/***********************************************************************/
{
register int i = 0;
for (i=0; i<len; i++)
str[i] = asc2ebc_table[str[i]];
return(str);
}
/***********************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *ebc2asc(CHARTYPE *str,int len,int start,int end)
#else
CHARTYPE *ebc2asc(str,len,start,end)
CHARTYPE *str;
int len;
int start;
int end;
#endif
/***********************************************************************/
/* Function : Converts an EBCDIC string to an ASCII string. */
/* Parameters: str - EBCDIC string */
/* len - length of string to convert */
/* Return : *str - the same string converted */
/***********************************************************************/
{
register int i = 0;
for (i=start; i<min(len,end+1); i++)
str[i] = ebc2asc_table[str[i]];
return(str);
}
/*man***************************************************************************
NAME
memreveq - search buffer reversed for character
SYNOPSIS
short memreveq(buffer,chr,max_length)
CHARTYPE *buffer;
CHARTYPE ch;
short max_length;
DESCRIPTION
The memreveq function searches the buffer from the right for the
first character equal to the supplied character.
RETURN VALUE
If successful, returns the position of first matching character
or (-1) if unsuccessful.
SEE ALSO
strzreveq, memrevne
*******************************************************************************/
#ifdef HAVE_PROTO
short memreveq(CHARTYPE *buffer,CHARTYPE ch,short max_len)
#else
short memreveq(buffer,ch,max_len)
CHARTYPE *buffer,ch;
short max_len;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short len=max_len;
/*--------------------------- processing ------------------------------*/
for (--len; len>=0 && buffer[len]!=ch; len--);
return(len);
}
/*man***************************************************************************
NAME
memrevne - search buffer reversed for NOT character
SYNOPSIS
short memrevne(buffer,known_char,max_len)
CHARTYPE *buffer;
CHARTYPE known_char;
short max_len;
DESCRIPTION
The memrevne function searches the buffer from the right for first
character NOT equal to the supplied character.
RETURN VALUE
If successful, returns the position of first NON-matching character
or (-1) if unsuccessful.
SEE ALSO
strzrevne, strzne
*******************************************************************************/
#ifdef HAVE_PROTO
short memrevne(CHARTYPE *buffer,CHARTYPE known_char,short max_len)
#else
short memrevne(buffer,known_char,max_len)
CHARTYPE *buffer;
CHARTYPE known_char;
short max_len;
#endif
{
/*--------------------------- local data ------------------------------*/
register short len=max_len;
/*--------------------------- processing ------------------------------*/
for (--len; len>=0 && buffer[len]==known_char; len--);
return(len);
}
/*man***************************************************************************
NAME
meminschr - insert character into buffer
SYNOPSIS
CHARTYPE *meminschr(buffer,chr,location,max_length,curr_length)
CHARTYPE *buffer;
CHARTYPE chr;
short location,max_length,curr_length;
DESCRIPTION
The meminschr inserts the supplied 'chr' into the buffer 'buffer'
before the 'location' specified. 'location' is an offset (0 based)
from the start of 'buffer'.
The 'buffer' will not be allowed to have more than 'max_length'
characters, so if the insertion of the character causes the
'max_length' to be exceeded, the last character of 'buffer' will
be lost.
RETURN VALUE
A pointer to the same 'buffer' as was supplied.
SEE ALSO
meminsstr, memdeln
*******************************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *meminschr(CHARTYPE *buffer,CHARTYPE chr,short location,
short max_length,short curr_length)
#else
CHARTYPE *meminschr(buffer,chr,location,max_length,curr_length)
CHARTYPE *buffer;
CHARTYPE chr;
short location,max_length,curr_length;
#endif
{
/*--------------------------- local data ------------------------------*/
register short i=0;
/*--------------------------- processing ------------------------------*/
for (i=curr_length;i > location;i--)
if (i < max_length)
buffer[i] = buffer[i-1];
if (location < max_length)
buffer[location] = chr;
return(buffer);
}
/*man***************************************************************************
NAME
meminsmem - insert memory into buffer
SYNOPSIS
#include "the.h"
CHARTYPE *meminsmem(buffer,str,len,location,max_length,curr_length)
CHARTYPE *buffer;
CHARTYPE *str;
short len,location,max_length,curr_length;
DESCRIPTION
The meminsmem function inserts the supplied 'str' into the buffer 'buffer'
before the 'location' specified. 'location' is an offset (0 based)
from the start of 'buffer'.
The 'buffer' will not be allowed to have more than 'max_length'
characters, so if the insertion of the string causes the
'max_length' to be exceeded, the last character(s) of 'buffer' will
be lost.
RETURN VALUE
A pointer to the same 'buffer' as was supplied.
SEE ALSO
meminschr
*******************************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *meminsmem(CHARTYPE *buffer,CHARTYPE *str,short len,short location,
short max_length,short curr_length)
#else
CHARTYPE *meminsmem(buffer,str,len,location,max_length,curr_length)
CHARTYPE *buffer,*str;
short len,location,max_length,curr_length;
#endif
{
/*--------------------------- local data ------------------------------*/
register short i=0;
/*--------------------------- processing ------------------------------*/
for (i=curr_length;i > location;i--)
if (i+len-1 < max_length)
buffer[i+len-1] = buffer[i-1];
for (i=0;i<len;i++)
if (location+i < max_length)
buffer[location+i] = str[i];
return(buffer);
}
/*man***************************************************************************
NAME
memdeln - delete a number of character(s) from buffer
SYNOPSIS
CHARTYPE *memdeln(buffer,location,curr_length,num_chars)
CHARTYPE *buffer;
short location,curr_length,num_chars;
DESCRIPTION
The memdeln deletes the supplied number of characters from the
buffer starting at the 'location' specified. 'location' is an offset (0 based)
from the start of 'buffer'.
For each character deleted, what was the last character in buffer;
based on 'curr_length' will be replaced with a space.
RETURN VALUE
A pointer to the same 'buffer' as was supplied.
SEE ALSO
meminschr, strdelchr
*******************************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *memdeln(CHARTYPE *buffer,short location,short curr_length,short num_chars)
#else
CHARTYPE *memdeln(buffer,location,curr_length,num_chars)
CHARTYPE *buffer;
short location,curr_length,num_chars;
#endif
{
/*--------------------------- local data ------------------------------*/
register short i=0;
/*--------------------------- processing ------------------------------*/
for (i=location;i <curr_length;i++)
if (i+num_chars >= curr_length)
buffer[i] = ' ';
else
buffer[i] = buffer[i+num_chars];
return(buffer);
}
/*man***************************************************************************
NAME
strdelchr - delete all supplied character from buffer
SYNOPSIS
CHARTYPE *memdeln(buffer,chr)
CHARTYPE *buffer;
CHARTYPE chr;
DESCRIPTION
The memdeln deletes all occurrences of chr from the ASCIIZ buffer.
RETURN VALUE
A pointer to the same 'buffer' as was supplied.
SEE ALSO
meminschr, memdeln
*******************************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *strdelchr(CHARTYPE *buffer,CHARTYPE chr)
#else
CHARTYPE *strdelchr(buffer,chr)
CHARTYPE *buffer;
CHARTYPE chr;
#endif
{
/*--------------------------- local data ------------------------------*/
register int i=0,j=0;
int len=strlen((DEFCHAR *)buffer);
/*--------------------------- processing ------------------------------*/
for(i=0;i<len;i++)
{
if (buffer[i] != chr)
buffer[j++] = buffer[i];
}
buffer[j] = (CHARTYPE)'\0';
return(buffer);
}
/*man***************************************************************************
NAME
memrmdup - remove duplicate, contiguous characters
SYNOPSIS
CHARTYPE *memrmdup(buf,len,chr)
CHARTYPE *buf;
short *len;
CHARTYPE ch;
DESCRIPTION
The memrmdup function removes all duplicate, contiguous characters
from the supplied buffer.
eg. memrmdup("abc$$$def$$ghi$",15,'$')
will return pointer to buf equal to "abc$def$ghi$" and new length
in len.
RETURN VALUE
Returns the new buf.
*******************************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *memrmdup(CHARTYPE *buf,short *len,CHARTYPE ch)
#else
CHARTYPE *memrmdup(buf,len,ch)
CHARTYPE *buf;
short *len;
CHARTYPE ch;
#endif
{
/*--------------------------- local data ------------------------------*/
register short i=0,num_dups=0,newlen=*len;
CHARTYPE *src=buf,*dst=buf;
bool dup=FALSE;
/*--------------------------- processing ------------------------------*/
for (; i<newlen; i++,src++)
{
if (*src == ch)
{
if (dup)
{
num_dups++;
continue;
}
else
{
dup = TRUE;
}
}
else
dup = FALSE;
*dst++ = *src;
}
*len = newlen-num_dups;
return(buf);
}
/*man***************************************************************************
NAME
strrmdup - remove duplicate, contiguous characters
SYNOPSIS
CHARTYPE *strrmdup(buf,chr)
CHARTYPE *buf;
CHARTYPE ch;
bool exclude_leading;
DESCRIPTION
The strrmdup function removes all duplicate, contiguous characters
from the supplied string. if exclude_leading is TRUE, no removal
is done of leading characters.
eg. strrmdup("abc$$$def$$ghi$",'$')
will return pointer to buf equal to "abc$def$ghi$".
RETURN VALUE
Returns the new buf.
*******************************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *strrmdup(CHARTYPE *buf,CHARTYPE ch,bool exclude_leading)
#else
CHARTYPE *strrmdup(buf,ch,exclude_leading)
CHARTYPE *buf;
CHARTYPE ch;
bool exclude_leading;
#endif
{
/*--------------------------- local data ------------------------------*/
CHARTYPE *src=buf,*dst=buf;
bool dup=FALSE;
/*--------------------------- processing ------------------------------*/
if (exclude_leading)
{
while(*src == ch)
*dst++ = *src++;
}
while(*src)
{
if (*src == ch)
{
if (dup)
{
src++;
continue;
}
else
dup = TRUE;
}
else
dup = FALSE;
*dst++ = *src++;
}
*dst = '\0';
return(buf);
}
/*man***************************************************************************
NAME
strzne - search string for NOT character
SYNOPSIS
short strzne(str,chr)
CHARTYPE *str;
CHARTYPE ch;
DESCRIPTION
The strzne function searches the string from the left for the first
character NOT equal to the supplied character.
RETURN VALUE
If successful, returns the position of first NON-matching character
or (-1) if unsuccessful.
SEE ALSO
strzrevne, memrevne
*******************************************************************************/
#ifdef HAVE_PROTO
short strzne(CHARTYPE *str,CHARTYPE ch)
#else
short strzne(str,ch)
CHARTYPE *str;
CHARTYPE ch;
#endif
{
/*--------------------------- local data ------------------------------*/
register short len=0;
register short i = 0;
/*--------------------------- processing ------------------------------*/
len = strlen((DEFCHAR *)str);
for (; i<len && str[i]==ch; i++);
if (i>=len)
i = (-1);
return(i);
}
/*man***************************************************************************
NAME
my_strdup - equivalent to strdup
SYNOPSIS
CHARTYPE *my_strdup(str)
CHARTYPE *str;
DESCRIPTION
The my_strdup function duplicates the supplied string.
RETURN VALUE
If successful, returns a pointer to the copy of the supplied string
or NULL if unsuccessful.
*******************************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *my_strdup(CHARTYPE *str)
#else
CHARTYPE *my_strdup(str)
CHARTYPE *str;
#endif
{
/*--------------------------- local data ------------------------------*/
register short len=0;
CHARTYPE *tmp=NULL;
/*--------------------------- processing ------------------------------*/
len = strlen((DEFCHAR *)str);
if ((tmp = (CHARTYPE *)(*the_malloc)((len+1)*sizeof(CHARTYPE))) == (CHARTYPE *)NULL)
return((CHARTYPE *)NULL);
strcpy((DEFCHAR *)tmp,(DEFCHAR *)str);
return(tmp);
}
/*man***************************************************************************
NAME
memne - search buffer for NOT character
SYNOPSIS
#include "the.h"
short memne(buffer,chr,length)
CHARTYPE *buffer;
CHARTYPE chr;
short length;
DESCRIPTION
The memne function searches the buffer from the left for the first
character NOT equal to the supplied character.
RETURN VALUE
If successful, returns the position of first NON-matching character
or (-1) if unsuccessful.
SEE ALSO
strzrevne, memrevne, strzne
*******************************************************************************/
#ifdef HAVE_PROTO
short memne(CHARTYPE *buffer,CHARTYPE chr,short length)
#else
short memne(buffer,chr,length)
CHARTYPE *buffer;
CHARTYPE chr;
short length;
#endif
{
/*--------------------------- local data ------------------------------*/
register short i = 0;
/*--------------------------- processing ------------------------------*/
for (; i<length && buffer[i]==chr; i++);
if (i>=length)
i = (-1);
return(i);
}
/*man***************************************************************************
NAME
strzrevne - search string reversed for NOT character
SYNOPSIS
#include "the.h"
short strzrevne(str,chr)
CHARTYPE *str;
CHARTYPE ch;
DESCRIPTION
The strzrevne function searches the string from the right for the
first character NOT equal to the supplied character.
RETURN VALUE
If successful, returns the position of first NON-matching character
or (-1) if unsuccessful.
SEE ALSO
strzne, memrevne
*******************************************************************************/
#ifdef HAVE_PROTO
short strzrevne(CHARTYPE *str,CHARTYPE ch)
#else
short strzrevne(str,ch)
CHARTYPE *str;
CHARTYPE ch;
#endif
{
/*--------------------------- local data ------------------------------*/
register short len=0;
/*--------------------------- processing ------------------------------*/
len = strlen((DEFCHAR *)str);
for (--len; len>=0 && str[len]==ch; len--);
return(len);
}
/*man***************************************************************************
NAME
strzreveq - search string reversed for character
SYNOPSIS
short strzreveq(str,chr)
CHARTYPE *str;
CHARTYPE ch;
DESCRIPTION
The strzreveq function searches the string from the right for the
first character equal to the supplied character.
RETURN VALUE
If successful, returns the position of first matching character
or (-1) if unsuccessful.
SEE ALSO
strzrevne
*******************************************************************************/
#ifdef HAVE_PROTO
short strzreveq(CHARTYPE *str,CHARTYPE ch)
#else
short strzreveq(str,ch)
CHARTYPE *str,ch;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short len=0;
/*--------------------------- processing ------------------------------*/
len = strlen((DEFCHAR *)str);
for (--len; len>=0 && str[len]!=ch; len--);
return(len);
}
/*man***************************************************************************
NAME
strtrunc - truncate leading and trailing spaces from string
SYNOPSIS
#include "the.h"
CHARTYPE *strtrunc(string)
CHARTYPE *string;
DESCRIPTION
The strtrunc function truncates all leading and trailing spaces
from the supplied string.
RETURN VALUE
A pointer to the original string, now truncated.
SEE ALSO
*******************************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *strtrunc(CHARTYPE *string)
#else
CHARTYPE *strtrunc(string)
CHARTYPE *string;
#endif
{
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
return(MyStrip(string,STRIP_BOTH,' '));
}
/*man***************************************************************************
NAME
MyStrip - truncate leading and/or trailing spaces from string
SYNOPSIS
#include "the.h"
CHARTYPE *MyStrip(string,option,ch)
CHARTYPE *string;
char option;
char ch;
DESCRIPTION
The MyStrip function truncates all leading and/or trailing ch
from the supplied string.
The value of the "option" argument can be one of:
STRIP_LEADING
STRIP_TRAILING
STRIP_BOTH
STRIP_ALL
STRIP_NONE
These are defined elsewhere with the values:
STRIP_LEADING 1
STRIP_TRAILING 2
STRIP_BOTH STRIP_LEADING|STRIP_TRAILING
STRIP_ALL STRIP_LEADING|STRIP_TRAILING|4
STRIP_NONE 0
RETURN VALUE
A pointer to the original string, now truncated.
SEE ALSO
*******************************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *MyStrip(CHARTYPE *string,char option,char ch)
#else
CHARTYPE *MyStrip(string,option,ch)
CHARTYPE *string;
char option,ch;
#endif
{
/*--------------------------- local data ------------------------------*/
register short i=0;
short pos=0;
/*--------------------------- processing ------------------------------*/
if (strlen((DEFCHAR *)string) == 0)
return(string);
if (option & STRIP_TRAILING)
{
pos = strzrevne(string,ch);
if (pos == (-1))
*(string) = '\0';
else
*(string+pos+1) = '\0';
}
if (option & STRIP_LEADING)
{
pos = strzne(string,ch);
if (pos == (-1))
*(string) = '\0';
else
{
/* for (i=0;*(string+i)!='\0';i++) */
for (i=0;*(string+i+pos)!='\0';i++) /* fixed by FGC */
*(string+i) = *(string+i+pos);
*(string+i) = '\0';
}
}
if (option == STRIP_ALL)
string = strdelchr(string,' ');
return(string);
}
/*man***************************************************************************
NAME
memfind - finds a needle in a haystack respecting case and arbitrary
characters if set.
SYNOPSIS
short memfind(haystack,needle,hay_len,nee_len,case_ignore,arbsts,arb)
CHARTYPE *haystack; string to be searched
CHARTYPE *needle; string to search for - may contain arbchars
short hay_len; length of haystack
short nee_len; length of needle
bool case_ignore; TRUE if search to ignore case
bool arbsts; TRUE if need to check for arbitrary characters
CHARTYPE single the single arbitrary character
CHARTYPE multiple the multiple arbitrary character
short *target_len return the length of the matched string
DESCRIPTION
The memfind function locates a needle in a haystack. Both the needle
and haystack may contain null characters. If case_ignore is TRUE,
then upper and lower case characters are treated equal. If arbsts
is ON, any arbitrary character, specified by arb, in needle, will
match ANY character in the haystack.
RETURN VALUE
The first occurrence (0 based) of needle in haystack, or (-1) if
the needle does not appear in the haystack. The length of the matched
string is returned in target_len
*******************************************************************************/
#ifdef HAVE_PROTO
short memfind(CHARTYPE *haystack,CHARTYPE *needle,short hay_len,short nee_len,
bool case_ignore,bool arbsts,CHARTYPE arb_single,CHARTYPE arb_multiple,
short *target_len)
#else
short memfind(haystack,needle,hay_len,nee_len,case_ignore,arbsts,arb_single,arb_multiple)
CHARTYPE *haystack;
CHARTYPE *needle;
short hay_len;
short nee_len;
bool case_ignore;
bool arbsts;
CHARTYPE arb_single;
CHARTYPE arb_multiple;
#endif
/*--------------------------- local data ------------------------------*/
{
register CHARTYPE c1=0,c2=0;
register CHARTYPE *buf1=NULL,*buf2=NULL;
register short i=0,j=0;
short matches=0;
CHARTYPE *new_needle=needle;
bool need_free=FALSE;
/*--------------------------- processing ------------------------------*/
/*
* Strip any duplicate, contiguous occurrences of arb_multiple if
* we are handling arbchars.
*/
if (arbsts
&& strzeq(needle,arb_multiple) != (-1))
{
if ((new_needle = (CHARTYPE *)my_strdup(needle)) == NULL)
{
display_error(30,(CHARTYPE *)"",FALSE);
return(-1);
}
need_free = TRUE;
memrmdup(new_needle,&nee_len,arb_multiple);
}
for (i=0;i<(hay_len-nee_len+1);i++)
{
buf1 = haystack+i;
buf2 = new_needle;
matches=0;
for (j=0;j<nee_len;j++)
{
if (case_ignore)
{
if (isupper(*buf1))
c1 = tolower(*buf1);
else
c1 = *buf1;
if (isupper(*buf2))
c2 = tolower(*buf2);
else
c2 = *buf2;
}
else
{
c1 = *buf1;
c2 = *buf2;
}
if (arbsts)
{
/* Next lines added by R.BOSSUT */
if (c2 == arb_multiple)
{
short new_hay_len = hay_len-(buf1-haystack);
short new_nee_len = nee_len-(buf2+1-new_needle);
short new_tar;
if (memfind(buf1,buf2+1,new_hay_len,new_nee_len,
case_ignore,arbsts,arb_single,arb_multiple,&new_tar) == (-1))
break;
else
{
if (need_free)
(*the_free)(new_needle);
*target_len = *target_len + new_tar;
return(i);
}
}
else
{
/* Up to here... */
if (c1 != c2 && c2 != arb_single)
break;
else
matches++;
}
/* Next lines added by R.BOSSUT */
}
/* Up to here... */
else
{
if (c1 != c2)
break;
else
matches++;
}
++buf1;
++buf2;
}
if (matches == nee_len)
{
if (need_free)
(*the_free)(new_needle);
*target_len = matches;
return(i);
}
}
if (need_free)
(*the_free)(new_needle);
return(-1);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short memcmpi(CHARTYPE *buf1,CHARTYPE *buf2,short len)
#else
short memcmpi(buf1,buf2,len)
CHARTYPE *buf1,*buf2;
short len;
#endif
/***********************************************************************/
/* Function : Compares two memory buffers for equality; */
/* case insensitive. Same as memicmp() Microsoft C. */
/* Parameters: buf1 - first buffer */
/* buf2 - second buffer */
/* len - number of characters to compare. */
/* Return : <0 if buf1 < buf2, */
/* =0 if buf1 = buf2, */
/* >0 if buf1 > buf2, */
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
CHARTYPE c1,c2;
/*--------------------------- processing ------------------------------*/
for(i=0;i<len;i++)
{
if (isupper(*buf1))
c1 = tolower(*buf1);
else
c1 = *buf1;
if (isupper(*buf2))
c2 = tolower(*buf2);
else
c2 = *buf2;
if (c1 != c2)
return(c1-c2);
++buf1;
++buf2;
}
return(0);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short my_stricmp(char *str1,char *str2)
#else
short my_stricmp(str1,str2)
char *str1,*str2;
#endif
/***********************************************************************/
/* Function : Compares two string buffers for equality; */
/* case insensitive. Same as stricmp(), strcasecmp() etc. */
/* Parameters: str1 - first string */
/* str2 - second string */
/* Return : <0 if str1 < str2, */
/* =0 if str1 = str2, */
/* >0 if str1 > str2, */
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i,len,len1=strlen(str1),len2=strlen(str2);
CHARTYPE c1,c2;
/*--------------------------- processing ------------------------------*/
len = min(len1,len2);
for(i=0;i<len;i++)
{
if (isupper(*str1))
c1 = tolower(*str1);
else
c1 = *str1;
if (isupper(*str2))
c2 = tolower(*str2);
else
c2 = *str2;
if (c1 != c2)
return(c1-c2);
++str1;
++str2;
}
if (len1 > len2)
return(1);
if (len1 < len2)
return(-1);
return(0);
}
/***********************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *make_upper(CHARTYPE *str)
#else
CHARTYPE *make_upper(str)
CHARTYPE *str;
#endif
/***********************************************************************/
/* Function : Makes the supplied string uppercase. */
/* Equivalent to strupr() on some platforms. */
/* Parameters: str - string to uppercase */
/* Return : str uppercased */
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
CHARTYPE *save_str=str;
/*--------------------------- processing ------------------------------*/
while(*str)
{
if (islower(*str))
*str = toupper(*str);
++str;
}
return(save_str);
}
/*man***************************************************************************
NAME
equal - determine if strings are equal up to specified length
SYNOPSIS
unsigned short equal(con,str,min_len)
CHARTYPE *con,*str;
short min_len;
DESCRIPTION
The equal function determines if a two strings are equal, irrespective
of case, up to the length of the second string. The length of the
second string must be greater than or equal to the specified minimum
length for the strings to be considered equal.
RETURN VALUE
If 'equal' TRUE else FALSE.
*******************************************************************************/
#ifdef HAVE_PROTO
unsigned short equal(CHARTYPE *con,CHARTYPE *str,short min_len)
#else
unsigned short equal(con,str,min_len)
CHARTYPE *con,*str;
short min_len;
#endif
{
/*--------------------------- local data ------------------------------*/
register int i=0,lenstr=0;
CHARTYPE c1,c2;
/*--------------------------- processing ------------------------------*/
if (min_len == 0)
{
return(FALSE);
}
#if 0
if (memfind(con,str,(short)min(strlen((DEFCHAR *)str),strlen((DEFCHAR *)con)),
(short)min(strlen((DEFCHAR *)str),strlen((DEFCHAR *)con)),TRUE,FALSE,'\0','\0') == 0
&& strlen((DEFCHAR *)str) >= min_len
&& strlen((DEFCHAR *)con) >= strlen((DEFCHAR *)str))
{
TRACE_RETURN();
return(TRUE);
}
TRACE_RETURN();
return(FALSE);
#else
if (strlen((DEFCHAR *)str) < min_len
|| strlen((DEFCHAR *)con) < strlen((DEFCHAR *)str))
{
return(FALSE);
}
lenstr = strlen((DEFCHAR*)str);
for (i=0;i<lenstr;i++)
{
if (isupper(*con))
c1 = tolower(*con);
else
c1 = *con;
if (isupper(*str))
c2 = tolower(*str);
else
c2 = *str;
if (c1 != c2)
{
return(FALSE);
}
++con;
++str;
}
return(TRUE);
#endif
}
/***********************************************************************/
#ifdef HAVE_PROTO
short valid_integer(CHARTYPE *str)
#else
short valid_integer(str)
CHARTYPE *str;
#endif
/***********************************************************************/
/* Function : Checks that string contains only 0-9,- or +. */
/* Parameters: *str - string to be checked */
/* Return : TRUE or FALSE */
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
short num_signs=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: valid_integer");
for (i=0; i<strlen((DEFCHAR *)str); i++)
{
if (*(str+i) == '-' || *(str+i) == '+')
num_signs++;
else
if (!isdigit(*(str+i)))
{
TRACE_RETURN();
return(FALSE);
}
}
if (num_signs > 1)
{
TRACE_RETURN();
return(FALSE);
}
TRACE_RETURN();
return(TRUE);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short valid_positive_integer(CHARTYPE *str)
#else
short valid_positive_integer(str)
CHARTYPE *str;
#endif
/***********************************************************************/
/* Function : Checks that string contains only 0-9, or +. */
/* Parameters: *str - string to be checked */
/* Return : TRUE or FALSE */
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
short num_signs=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: valid_positive_integer");
for (i=0; i<strlen((DEFCHAR *)str); i++)
{
if (*(str+i) == '+')
num_signs++;
else
if (!isdigit(*(str+i)))
{
TRACE_RETURN();
return(FALSE);
}
}
if (num_signs > 1)
{
TRACE_RETURN();
return(FALSE);
}
TRACE_RETURN();
return(TRUE);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short strzeq(CHARTYPE *str,CHARTYPE ch)
#else
short strzeq(str,ch)
CHARTYPE *str;
CHARTYPE ch;
#endif
/***********************************************************************/
/* Function : Locate in ASCIIZ string, character */
/* Parameters: *str - string to be searched */
/* ch - character to be searched for */
/* Return : position in string of character - (-1) if not found */
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short len=0;
register short i = 0;
/*--------------------------- processing ------------------------------*/
len = strlen((DEFCHAR *)str);
for (; i<len && str[i]!=ch; i++);
if (i>=len)
i = (-1);
return(i);
}
/***********************************************************************/
#ifdef HAVE_PROTO
CHARTYPE *strtrans(CHARTYPE *str,CHARTYPE oldch,CHARTYPE newch)
#else
CHARTYPE *strtrans(str,oldch,newch)
CHARTYPE *str;
CHARTYPE oldch,newch;
#endif
/***********************************************************************/
/* Function : Translate all occurrences of oldch to newch in str */
/* Parameters: *str - string to be amendedd */
/* oldch - character to be replaced */
/* newch - character to replace oldch */
/* Return : same string but with characters translated */
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
/*--------------------------- processing ------------------------------*/
for (i=0;i<strlen((DEFCHAR *)str); i++)
{
if (*(str+i) == oldch)
*(str+i) = newch;
}
return(str);
}
/***********************************************************************/
#ifdef HAVE_PROTO
LINE *add_LINE(LINE *first,LINE *curr,CHARTYPE *line,
LENGTHTYPE len,SELECTTYPE select,bool new_flag)
#else
LINE *add_LINE(first,curr,line,len,select,new_flag)
LINE *first;
LINE *curr;
CHARTYPE *line;
LENGTHTYPE len;
SELECTTYPE select;
bool new_flag;
#endif
/***********************************************************************/
/* Adds a member of the linked list for the specified file containing */
/* the line contents and length. */
/* PARAMETERS: */
/* first - pointer to first line for the file */
/* curr - pointer to current line for the file */
/* line - contents of line to be added */
/* len - length of line to be added */
/* select - select level of new line */
/* RETURN: - pointer to current item in linked list or NULL if error*/
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: add_LINE");
next_line = lll_add(first,curr,sizeof(LINE));
if (next_line == NULL)
{
TRACE_RETURN();
return(NULL);
}
curr_line = next_line;
curr_line->line = (CHARTYPE *)(*the_malloc)((len+1)*sizeof(CHARTYPE));
if (curr_line->line == NULL)
{
TRACE_RETURN();
return(NULL);
}
memcpy(curr_line->line,line,len);
*(curr_line->line+len) = '\0'; /* for functions that expect ASCIIZ string */
curr_line->length = len;
curr_line->select = select;
curr_line->save_select = select;
curr_line->pre = NULL;
curr_line->name = NULL;
curr_line->flags.new_flag = new_flag;
curr_line->flags.changed_flag = FALSE;
curr_line->flags.tag_flag = FALSE;
curr_line->flags.save_tag_flag = FALSE;
/*
* If this is the first line of the file, and the current parser for the
* file is NULL, see if we can use one of the magic string parsers...
*/
if (curr_line->prev
&& curr_line->prev->prev == NULL
&& CURRENT_VIEW
&& CURRENT_FILE
&& CURRENT_FILE->parser == NULL)
{
find_auto_parser(CURRENT_FILE);
}
TRACE_RETURN();
return(curr_line);
}
/***********************************************************************/
#ifdef HAVE_PROTO
LINE *append_LINE(LINE *curr,CHARTYPE *line,LENGTHTYPE len)
#else
LINE *append_LINE(curr,line,len)
LINE *curr;
CHARTYPE *line;
LENGTHTYPE len;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: append_LINE");
curr->line = (CHARTYPE *)(*the_realloc)(curr->line,(curr->length+len+1)*sizeof(CHARTYPE));
if (curr->line == NULL)
{
TRACE_RETURN();
return(NULL);
}
memcpy(curr->line+curr->length,line,len);
curr->length += len;
*(curr->line+curr->length) = '\0'; /* for functions that expect ASCIIZ string */
TRACE_RETURN();
return(curr);
}
/***********************************************************************/
#ifdef HAVE_PROTO
LINE *delete_LINE(LINE *first,LINE *last,LINE *curr,short direction)
#else
LINE *delete_LINE(first,last,curr,direction)
LINE *first,*last,*curr;
short direction;
#endif
/***********************************************************************/
/* Deletes a member of the linked list for the specified file. */
/* PARAMETERS: */
/* first - pointer to first line for the file */
/* first - pointer to last line for the file */
/* curr - pointer to current line for the file */
/* direction - direction in which to delete. */
/* RETURN: - pointer to current item in linked list or NULL if error*/
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: delete_LINE");
if (curr->name != (CHARTYPE *)NULL)
(*the_free)(curr->name);
(*the_free)(curr->line);
curr = lll_del(&first,&last,curr,direction);
TRACE_RETURN();
return(curr);
}
/***********************************************************************/
#ifdef HAVE_PROTO
void put_string(WINDOW *win,short row,short col,CHARTYPE *string,short len)
#else
void put_string(win,row,col,string,len)
WINDOW *win;
short row,col;
CHARTYPE *string;
short len;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: put_string");
wmove(win,row,col);
for (i=0;i<len;i++)
{
waddch(win,etmode_table[*(string+i)]);
}
TRACE_RETURN();
return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
void put_char(WINDOW *win,chtype ch,CHARTYPE add_ins)
#else
void put_char(win,ch,add_ins)
WINDOW *win;
chtype ch;
CHARTYPE add_ins;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
chtype chr=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: put_char");
chr = ch & A_CHARTEXT;
if (etmode_flag[chr]) /* etmode character has attributes, use them */
ch = etmode_table[chr];
else
ch = etmode_table[chr] | (ch & A_ATTRIBUTES);
if (add_ins == ADDCHAR)
waddch(win,ch);
else
winsch(win,ch);
TRACE_RETURN();
return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
short set_up_windows(short scrn)
#else
short set_up_windows(scrn)
short scrn;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
short y=0,x=0;
FILE_DETAILS fp;
short my_prefix_width=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: set_up_windows");
/*---------------------------------------------------------------------*/
/* If curses has not started exit gracefully... */
/*---------------------------------------------------------------------*/
if (!curses_started)
{
TRACE_RETURN();
return(RC_OK);
}
/*---------------------------------------------------------------------*/
/* Allocate space for a file descriptor colour attributes... */
/*---------------------------------------------------------------------*/
if ((fp.attr = (COLOUR_ATTR *)(*the_malloc)(ATTR_MAX*sizeof(COLOUR_ATTR))) == NULL)
{
display_error(30,(CHARTYPE *)"",FALSE);
TRACE_RETURN();
return(RC_OUT_OF_MEMORY);
}
if (screen[scrn].screen_view)
{
memcpy(fp.attr,screen[scrn].screen_view->file_for_view->attr,ATTR_MAX*sizeof(COLOUR_ATTR));
memcpy(fp.attr+ATTR_DIVIDER,CURRENT_FILE->attr+ATTR_DIVIDER,sizeof(COLOUR_ATTR));
my_prefix_width = screen[scrn].screen_view->prefix_width;
}
else
{
set_up_default_colours(&fp,(COLOUR_ATTR *)NULL,ATTR_MAX);
my_prefix_width = prefix_width;
}
/*---------------------------------------------------------------------*/
/* Save the position of the cursor in each window, and then delete the */
/* window. Recreate each window, that has a valid size and move the */
/* cursor back to the position it had in each window. */
/*---------------------------------------------------------------------*/
for (i=0;i<VIEW_WINDOWS;i++)
{
y = x = 0;
if (screen[scrn].win[i] != (WINDOW *)NULL)
{
getyx(screen[scrn].win[i],y,x);
delwin(screen[scrn].win[i]);
screen[scrn].win[i] = (WINDOW *)NULL;
}
if (screen[scrn].rows[i] != 0
&& screen[scrn].cols[i] != 0)
{
screen[scrn].win[i] = newwin(screen[scrn].rows[i],screen[scrn].cols[i],
screen[scrn].start_row[i],screen[scrn].start_col[i]);
if (screen[scrn].win[i] == (WINDOW *)NULL)
{
display_error(30,(CHARTYPE *)"creating window",FALSE);
TRACE_RETURN();
return(RC_OUT_OF_MEMORY);
}
#if !defined(PDCURSES)
touchwin(screen[scrn].win[i]);
#endif
wmove(screen[scrn].win[i],y,x);
}
}
wattrset(screen[scrn].win[WINDOW_FILEAREA],set_colour(fp.attr+ATTR_FILEAREA));
create_statusline_window();
if (screen[scrn].win[WINDOW_ARROW] != (WINDOW *)NULL)
{
wattrset(screen[scrn].win[WINDOW_ARROW],set_colour(fp.attr+ATTR_ARROW));
for (i=0;i<my_prefix_width-2;i++)
mvwaddch(screen[scrn].win[WINDOW_ARROW],0,i,'=');
mvwaddstr(screen[scrn].win[WINDOW_ARROW],0,my_prefix_width-2,"> ");
wnoutrefresh(screen[scrn].win[WINDOW_ARROW]);
}
if (screen[scrn].win[WINDOW_IDLINE] != (WINDOW *)NULL)
{
wattrset(screen[scrn].win[WINDOW_IDLINE],set_colour(fp.attr+ATTR_IDLINE));
wmove(screen[scrn].win[WINDOW_IDLINE],0,0);
my_wclrtoeol(screen[scrn].win[WINDOW_IDLINE]);
}
if (screen[scrn].win[WINDOW_PREFIX] != (WINDOW *)NULL)
wattrset(screen[scrn].win[WINDOW_PREFIX],set_colour(fp.attr+ATTR_PENDING));
if (screen[scrn].win[WINDOW_GAP] != (WINDOW *)NULL)
wattrset(screen[scrn].win[WINDOW_GAP],set_colour(fp.attr+ATTR_GAP));
if (screen[scrn].win[WINDOW_COMMAND] != (WINDOW *)NULL)
{
wattrset(screen[scrn].win[WINDOW_COMMAND],set_colour(fp.attr+ATTR_CMDLINE));
wmove(screen[scrn].win[WINDOW_COMMAND],0,0);
my_wclrtoeol(screen[scrn].win[WINDOW_COMMAND]);
wnoutrefresh(screen[scrn].win[WINDOW_COMMAND]);
wmove(screen[scrn].win[WINDOW_COMMAND],0,0);
}
/*---------------------------------------------------------------------*/
/* Set up divider window... */
/*---------------------------------------------------------------------*/
if (display_screens > 1
&& !horizontal)
{
if (divider != (WINDOW *)NULL)
delwin(divider);
divider = newwin(screen[1].screen_rows,2,screen[1].screen_start_row,
screen[1].screen_start_col-2);
if (divider == (WINDOW *)NULL)
{
display_error(30,(CHARTYPE *)"creating window",FALSE);
TRACE_RETURN();
return(RC_OUT_OF_MEMORY);
}
#if 0
# if defined(A_ALTCHARSET) && !defined(USE_NCURSES)
wattrset(divider,A_ALTCHARSET|set_colour(fp.attr+ATTR_DIVIDER));
# else
wattrset(divider,set_colour(fp.attr+ATTR_DIVIDER));
# endif
#else
wattrset(divider,set_colour(fp.attr+ATTR_DIVIDER));
#endif
draw_divider();
}
if (SLKx)
{
#if defined(HAVE_SLK_ATTRSET)
slk_attrset( set_colour( fp.attr+ATTR_SLK ) );
#endif
slk_noutrefresh();
}
/*---------------------------------------------------------------------*/
/* Free up space for a file descriptor colour attributes... */
/*---------------------------------------------------------------------*/
(*the_free)(fp.attr);
TRACE_RETURN();
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short draw_divider(void)
#else
short draw_divider()
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
#ifndef HAVE_WVLINE
register int i=0;
#endif
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: draw_divider");
#ifdef HAVE_WVLINE
wmove(divider,0,0);
wvline(divider,0,screen[1].screen_rows);
wmove(divider,0,1);
wvline(divider,0,screen[1].screen_rows);
#else
for (i=0;i<screen[1].screen_rows;i++)
{
wmove(divider,i,0);
waddch(divider,'|');
waddch(divider,'|');
}
#endif
TRACE_RETURN();
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short create_statusline_window(void)
#else
short create_statusline_window()
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
COLOUR_ATTR attr;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: create_statusline_window");
if (!curses_started)
{
TRACE_RETURN();
return(RC_OK);
}
if (CURRENT_VIEW == NULL
|| CURRENT_FILE == NULL)
set_up_default_colours((FILE_DETAILS *)NULL,&attr,ATTR_STATAREA);
else
memcpy(&attr,CURRENT_FILE->attr+ATTR_STATAREA,sizeof(COLOUR_ATTR));
if (statarea != (WINDOW *)NULL)
{
delwin(statarea);
statarea = (WINDOW *)NULL;
}
switch(STATUSLINEx)
{
case 'B':
statarea = newwin(1,COLS,terminal_lines-1,0);
wattrset(statarea,set_colour(&attr));
clear_statarea();
break;
case 'T':
statarea = newwin(1,COLS,0,0);
wattrset(statarea,set_colour(&attr));
clear_statarea();
break;
default:
break;
}
TRACE_RETURN();
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
void pre_process_line(VIEW_DETAILS *the_view,LINETYPE line_number,LINE *known_curr)
#else
void pre_process_line(the_view,line_number,known_curr)
VIEW_DETAILS *the_view;
LINETYPE line_number;
LINE *known_curr;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
LINE *curr=known_curr;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: pre_process_line");
/*---------------------------------------------------------------------*/
/* If we haven't been passed a valid LINE*, go and get one for the */
/* supplied line_number. */
/*---------------------------------------------------------------------*/
if (curr == (LINE *)NULL)
curr = lll_find(the_view->file_for_view->first_line,the_view->file_for_view->last_line,
line_number,the_view->file_for_view->number_lines);
memset(rec,' ',max_line_length);
memcpy(rec,curr->line,curr->length);
rec_len = curr->length;
/*---------------------------------------------------------------------*/
/* Now set up the prefix command from the linked list... */
/*---------------------------------------------------------------------*/
if (curr->pre == NULL)
{
memset(pre_rec,' ',MAX_PREFIX_WIDTH);
pre_rec_len = 0;
}
else
{
memset(pre_rec,' ',MAX_PREFIX_WIDTH);
strcpy((DEFCHAR *)pre_rec,(DEFCHAR *)curr->pre->ppc_command);
pre_rec_len = strlen((DEFCHAR *)pre_rec);
pre_rec[pre_rec_len] = ' ';
pre_rec[MAX_PREFIX_WIDTH] = '\0';
}
TRACE_RETURN();
return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
short post_process_line(VIEW_DETAILS *the_view,LINETYPE line_number,LINE *known_curr,bool set_alt)
#else
short post_process_line(the_view,line_number,known_curr,set_alt)
VIEW_DETAILS *the_view;
LINETYPE line_number;
LINE *known_curr;
bool set_alt;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
LINE *curr=known_curr;
short rc=RC_OK;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: post_process_line");
/*
* If there are no lines in the file associated with the view, exit...
*/
if (the_view->file_for_view->first_line == NULL)
{
TRACE_RETURN();
return(RC_OK);
}
/*
* If we haven't been passed a valid LINE*, go and get one for the
* supplied line_number.
*/
if (curr == (LINE *)NULL)
curr = lll_find(the_view->file_for_view->first_line,the_view->file_for_view->last_line,
line_number,the_view->file_for_view->number_lines);
/*
* First copy the pending prefix command to the linked list.
* Only do it if the prefix command has a value or there is already a
* pending prefix command for that line.
*/
if (prefix_changed)
add_prefix_command(curr,line_number,FALSE);
/*
* If the line hasn't changed, return.
*/
if (rec_len == curr->length && (memcmp(rec,curr->line,curr->length) == 0))
{
TRACE_RETURN();
return(RC_NO_LINES_CHANGED);
}
/*
* If it has set the changed_flag.
*/
curr->flags.changed_flag = TRUE;
/*
* Increment the alteration counters, if requested to do so...
*/
if (set_alt)
increment_alt(the_view->file_for_view);
/*
* Add the old line contents to the line recovery list.
*/
if (the_view->file_for_view->undoing)
add_to_recovery_list(curr->line,curr->length);
/*
* Realloc the dynamic memory for the line if the line is now longer.
*/
if (rec_len > curr->length)
{
curr->line = (CHARTYPE *)(*the_realloc)((void *)curr->line,(rec_len+1)*sizeof(CHARTYPE));
if (curr->line == NULL)
{
display_error(30,(CHARTYPE *)"",FALSE);
TRACE_RETURN();
return(RC_OUT_OF_MEMORY);
}
}
/*
* Copy the contents of rec into the line.
*/
memcpy(curr->line,rec,rec_len);
curr->length = rec_len;
*(curr->line+rec_len) = '\0';
/*
* If this is the first line of the file, and the current parser for the
* file is NULL, see if we can use one of the magic string parsers...
*/
if (line_number == 1
&& CURRENT_FILE->parser == NULL)
{
find_auto_parser(CURRENT_FILE);
}
TRACE_RETURN();
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
bool blank_field(CHARTYPE *field)
#else
bool blank_field(field)
CHARTYPE *field;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: blank_field");
if (strzne(field,' ') == (-1))
{
TRACE_RETURN();
return(TRUE); /* field is NULL or just contains spaces */
}
TRACE_RETURN();
return(FALSE);
}
/***********************************************************************/
#ifdef HAVE_PROTO
void adjust_marked_lines(bool binsert_line,LINETYPE base_line,LINETYPE num_lines)
#else
void adjust_marked_lines(binsert_line,base_line,num_lines)
bool binsert_line;
LINETYPE base_line;
LINETYPE num_lines;
#endif
/***********************************************************************/
{
/*
* When lines are deleted, the base line is the first line in the file
* irrespective of the direction that the delete is done.
*/
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: adjust_marked_lines");
/*
* If there are no marked lines in the current view, return.
*/
if (MARK_VIEW != CURRENT_VIEW)
{
TRACE_RETURN();
return;
}
switch(binsert_line)
{
case TRUE:/* INSERT */
if (base_line < CURRENT_VIEW->mark_start_line)
{
CURRENT_VIEW->mark_start_line += num_lines;
CURRENT_VIEW->mark_end_line += num_lines;
break;
}
if (base_line >= CURRENT_VIEW->mark_start_line
&& base_line < CURRENT_VIEW->mark_end_line)
{
CURRENT_VIEW->mark_end_line += num_lines;
break;
}
break;
case FALSE: /* DELETE */
if (base_line <= CURRENT_VIEW->mark_start_line
&& base_line+num_lines-1L >= CURRENT_VIEW->mark_end_line)
{
CURRENT_VIEW->marked_line = FALSE;
MARK_VIEW = (VIEW_DETAILS *)NULL;
break;
}
if (base_line+num_lines-1L < CURRENT_VIEW->mark_start_line)
{
CURRENT_VIEW->mark_start_line -= num_lines;
CURRENT_VIEW->mark_end_line -= num_lines;
break;
}
if (base_line > CURRENT_VIEW->mark_end_line)
{
break;
}
if (base_line+num_lines-1L > CURRENT_VIEW->mark_end_line)
{
CURRENT_VIEW->mark_end_line = base_line - 1L;
break;
}
if (base_line < CURRENT_VIEW->mark_start_line)
{
CURRENT_VIEW->mark_start_line = base_line;
CURRENT_VIEW->mark_end_line = base_line +
(CURRENT_VIEW->mark_end_line -
(base_line + num_lines));
break;
}
CURRENT_VIEW->mark_end_line -= num_lines;
break;
}
TRACE_RETURN();
return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
void adjust_pending_prefix(VIEW_DETAILS *view,bool binsert_line,LINETYPE base_line,LINETYPE num_lines)
#else
void adjust_pending_prefix(view,binsert_line,base_line,num_lines)
VIEW_DETAILS *view;
bool binsert_line;
LINETYPE base_line;
LINETYPE num_lines;
#endif
/***********************************************************************/
{
/*---------------------------------------------------------------------*/
/* When lines are deleted, the base line is the first line in the file */
/* irrespective of the direction that the delete is done. */
/*---------------------------------------------------------------------*/
/*--------------------------- local data ------------------------------*/
THE_PPC *curr_ppc=NULL;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: adjust_pending_prefix");
/*---------------------------------------------------------------------*/
/* If there are no pending prefix commands in the view, return. */
/*---------------------------------------------------------------------*/
if (view->file_for_view->first_ppc == NULL)
{
TRACE_RETURN();
return;
}
curr_ppc = view->file_for_view->first_ppc;
while (curr_ppc != NULL)
{
switch(binsert_line)
{
case TRUE:/* INSERT */
if (base_line < curr_ppc->ppc_line_number)
{
curr_ppc->ppc_line_number += num_lines;
break;
}
break;
case FALSE: /* DELETE */
if (base_line+num_lines-1L < curr_ppc->ppc_line_number)
{
curr_ppc->ppc_line_number -= num_lines;
break;
}
if (base_line > curr_ppc->ppc_line_number)
break;
#if OLD_CLEAR
(void)delete_pending_prefix_command(curr_ppc,view->file_for_view,(LINE *)NULL);
#else
clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
#endif
break;
}
curr_ppc = curr_ppc->next;
}
TRACE_RETURN();
return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
CHARTYPE case_translate(CHARTYPE key)
#else
CHARTYPE case_translate(key)
CHARTYPE key;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: case_translate");
if (CURRENT_VIEW->case_enter == CASE_UPPER
&& islower(key))
{
TRACE_RETURN();
return(toupper(key));
}
if (CURRENT_VIEW->case_enter == CASE_LOWER
&& isupper(key))
{
TRACE_RETURN();
return(tolower(key));
}
TRACE_RETURN();
return(key);
}
/***********************************************************************/
#ifdef HAVE_PROTO
void add_to_recovery_list(CHARTYPE *line,LENGTHTYPE len)
#else
void add_to_recovery_list(line,len)
CHARTYPE *line;
LENGTHTYPE len;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: add_to_recovery_list");
/*---------------------------------------------------------------------*/
/* Ignore if running in batch. */
/*---------------------------------------------------------------------*/
if (batch_only)
{
TRACE_RETURN();
return;
}
/*---------------------------------------------------------------------*/
/* First time through, set line array to NULL, to indicated unused. */
/* This setup MUST occur before the freeing up code. */
/*---------------------------------------------------------------------*/
if (add_rcvry == (-1))
{
for (i=0;i<MAX_RECV;i++)
rcvry[i] = NULL;
add_rcvry = 0; /* set to point to next available slot */
}
/*---------------------------------------------------------------------*/
/* Now we are here, lets add to the array. */
/*---------------------------------------------------------------------*/
if (rcvry[add_rcvry] == NULL) /* haven't malloced yet */
{
if ((rcvry[add_rcvry] = (CHARTYPE *)(*the_malloc)((len+1)*sizeof(CHARTYPE))) == NULL)
{
display_error(30,(CHARTYPE *)"",FALSE);
TRACE_RETURN();
return;
}
}
else
{
if ((rcvry[add_rcvry] = (CHARTYPE *)(*the_realloc)(rcvry[add_rcvry],(len+1)*sizeof(CHARTYPE))) == NULL)
{
display_error(30,(CHARTYPE *)"",FALSE);
TRACE_RETURN();
return;
}
}
memcpy(rcvry[add_rcvry],line,len);
rcvry_len[add_rcvry] = len;
retr_rcvry = add_rcvry;
add_rcvry = (++add_rcvry >= MAX_RECV) ? 0 : add_rcvry;
num_rcvry = (++num_rcvry > MAX_RECV) ? MAX_RECV : num_rcvry;
TRACE_RETURN();
return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
void get_from_recovery_list(short num)
#else
void get_from_recovery_list(num)
short num;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
short num_retr = min(num,num_rcvry);
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: get_from_recovery_list");
/*---------------------------------------------------------------------*/
/* Return error if nothing to recover. */
/*---------------------------------------------------------------------*/
if (retr_rcvry == (-1))
{
display_error(0,(CHARTYPE *)"0 line(s) recovered",TRUE);
TRACE_RETURN();
return;
}
/*---------------------------------------------------------------------*/
/* Retrieve each allocated recovery line and put back into the body. */
/*---------------------------------------------------------------------*/
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
for (i=0;i<num_retr;i++)
{
if (rcvry[retr_rcvry] != NULL)
{
insert_new_line(rcvry[retr_rcvry],rcvry_len[retr_rcvry],1L,get_true_line(TRUE),TRUE,FALSE,FALSE,CURRENT_VIEW->display_low,TRUE,FALSE);
retr_rcvry = (--retr_rcvry < 0) ? num_rcvry-1 : retr_rcvry;
}
}
/*---------------------------------------------------------------------*/
/* If one or more lines were retrieved, increment the alteration counts*/
/*---------------------------------------------------------------------*/
if (num_retr)
increment_alt(CURRENT_FILE);
sprintf((DEFCHAR *)temp_cmd,"%d line(s) recovered",num_retr);
display_error(0,temp_cmd,TRUE);
TRACE_RETURN();
return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
void free_recovery_list(void)
#else
void free_recovery_list()
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: free_recovery_list");
for (i=0;i<MAX_RECV;i++)
{
if (rcvry[i] != NULL)
{
(*the_free)(rcvry[i]);
rcvry[i] = NULL;
}
}
add_rcvry = (-1);
retr_rcvry = (-1);
num_rcvry = 0;
TRACE_RETURN();
return;
}
#if THIS_APPEARS_TO_NOT_BE_USED
/***********************************************************************/
#ifdef HAVE_PROTO
WINDOW *adjust_window(WINDOW *win,short tr,short tc,short lines,short cols)
#else
WINDOW *adjust_window(win,tr,tc,lines,cols)
WINDOW *win;
short tr;
short tc;
short lines;
short cols;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
WINDOW *neww=NULL;
short begy=0,begx=0,maxy=0,maxx=0,y=0,x=0;
short rc=RC_OK;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: adjust_window");
/*---------------------------------------------------------------------*/
/* Get existing details about the current window. */
/*---------------------------------------------------------------------*/
getbegyx(win,begy,begx);
getmaxyx(win,maxy,maxx);
if (maxy == lines && maxx == cols) /* same size */
{
if (begy == tr && begx == tc) /* same position */
{
TRACE_RETURN();
return(win); /* nothing to do, return same window */
}
else /* need to move window */
{
rc = mvwin(win,tr,tc);
TRACE_RETURN();
return(win);
}
}
/*---------------------------------------------------------------------*/
/* To get here the window needs to be resized. */
/*---------------------------------------------------------------------*/
getyx(win,y,x);
delwin(win);
neww = newwin(lines,cols,tr,tc);
if (neww != (WINDOW *)NULL)
wmove(neww,y,x);
TRACE_RETURN();
return(neww);
}
#endif
/***********************************************************************/
#ifdef HAVE_PROTO
void draw_cursor(bool visible)
#else
void draw_cursor(visible)
bool visible;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: draw_cursor");
#ifdef HAVE_CURS_SET
if (visible)
{
if (INSERTMODEx)
{
curs_set(1); /* First set to displayed... */
curs_set(2); /* ...then try to make it more visible */
}
else
curs_set(1); /* underline cursor */
}
else
curs_set(0); /* cursor off */
#endif
TRACE_RETURN();
return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
short my_wclrtoeol(WINDOW *win)
#else
short my_wclrtoeol(win)
WINDOW *win;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
short x=0,y=0,maxx=0,maxy=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: my_wclrtoeol");
#if defined(USE_NCURSES_IGNORED)
/*
* This extra code here to get around an ncurses bug that
* does not overwrite existing characters displayed when a
* clrtoeol() is called.
* Try COMPAT X#PREFIX OFF#PREFIX ON
*/
if (win != (WINDOW *)NULL)
{
getyx(win,y,x);
getmaxyx(win,maxy,maxx);
for (i=x;i<maxx;i++)
waddch(win,'@');
wmove(win,y,x);
}
#endif
if (win != (WINDOW *)NULL)
{
getyx(win,y,x);
getmaxyx(win,maxy,maxx);
for (i=x;i<maxx;i++)
waddch(win,' ');
wmove(win,y,x);
}
TRACE_RETURN();
return(0);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short my_wdelch(WINDOW *win)
#else
short my_wdelch(win)
WINDOW *win;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
short x=0,y=0,maxx=0,maxy=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: my_wdelch");
getyx(win,y,x);
getmaxyx(win,maxy,maxx);
wdelch(win);
mvwaddch(win,y,maxx-1,' ');
wmove(win,y,x);
TRACE_RETURN();
return(0);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short get_word(CHARTYPE *string,LENGTHTYPE length,LENGTHTYPE curr_pos,
LENGTHTYPE *first_col,LENGTHTYPE *last_col)
#else
short get_word(string,length,curr_pos,first_col,last_col)
CHARTYPE *string;
LENGTHTYPE length,curr_pos;
LENGTHTYPE *first_col,*last_col;
#endif
/***********************************************************************/
{
#define FIRST_BLANK 0
#define SECOND_BLANK 1
#define FIRST_WORD 2
#define SECOND_WORD 3
#define THE_ALPHANUM 4
#define THE_NOT_ALPHANUM 5
/*--------------------------- local data ------------------------------*/
short state=0;
register short i=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: get_word");
/*---------------------------------------------------------------------*/
/* If we are after the last column of the line, then just ignore the */
/* command and leave the cursor where it is. */
/*---------------------------------------------------------------------*/
if (curr_pos >= length)
{
TRACE_RETURN();
return(0);
}
/*---------------------------------------------------------------------*/
/* Determine the end of the next word, or go to the end of the line */
/* if already at or past beginning of last word. */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* If the current character is a space, mark all spaces as the word. */
/* The beahiour is the same for this situation regardless of WORD */
/* setting. */
/*---------------------------------------------------------------------*/
if (*(string+curr_pos) == ' ')
{
for (i=curr_pos;i<length;i++)
{
if (*(string+i) != ' ')
{
*last_col = i-1;
break;
}
}
if (i == length)
*last_col = length - 1;
for (i=curr_pos;i>(-1);i--)
{
if (*(string+i) != ' ')
{
*first_col = i+1;
break;
}
}
if (i < 0)
*first_col = 0;
TRACE_RETURN();
return(1);
}
/*---------------------------------------------------------------------*/
/* To get here the current character is non-blank. */
/*---------------------------------------------------------------------*/
state = my_isalphanum(*(string+curr_pos));
if (CURRENT_VIEW->word == 'N')
{
/*
* Get first column
*/
for (i=curr_pos;i>(-1);i--)
{
if (*(string+i) == ' ')
{
*first_col = i+1;
break;
}
}
if (i < 0)
*first_col = 0;
/*
* Get last column
*/
for (i=curr_pos;i<length;i++)
{
if (*(string+i) == ' ')
{
*last_col = i-1;
break;
}
}
if (i < length)
{
for (;i<length;i++)
{
if (*(string+i) != ' ')
{
*last_col = i-1;
break;
}
}
}
if (i == length)
*last_col = length - 1;
}
else
{
/*
* Get first column
*/
for (i=curr_pos;i>(-1);i--)
{
if (my_isalphanum(*(string+i)) != state)
{
*first_col = i+1;
break;
}
}
if (i < 0)
*first_col = 0;
/*
* Get last column
*/
for (i=curr_pos;i<length;i++)
{
if (my_isalphanum(*(string+i)) != state)
{
*last_col = i-1;
break;
}
}
if (i < length
&& *(string+i) == ' ')
{
for (;i<length;i++)
{
if (*(string+i) != ' ')
{
*last_col = i-1;
break;
}
}
}
if (i == length)
*last_col = length - 1;
}
TRACE_RETURN();
return(1);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short my_isalphanum(CHARTYPE chr)
#else
short my_isalphanum(chr)
CHARTYPE chr;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
short char_type=CHAR_OTHER;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: my_isalphanum");
if (chr == ' ')
char_type = CHAR_SPACE;
else
{
if (isalpha(chr)
|| isdigit(chr)
|| chr == '_'
|| chr > 128)
char_type = CHAR_ALPHANUM;
}
TRACE_RETURN();
return(char_type);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short my_wmove(WINDOW *win,short scridx,short winidx,short y,short x)
#else
short my_wmove(win,scridx,winidx,y,x)
WINDOW *win;
short scridx,winidx,y,x;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
short rc=RC_OK;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: my_wmove");
/*---------------------------------------------------------------------*/
/* If the scridx or winidx are -1, do not try to save the x/y position.*/
/*---------------------------------------------------------------------*/
if (scridx != (-1)
&& winidx != (-1))
{
screen[scridx].screen_view->x[winidx] = x;
screen[scridx].screen_view->y[winidx] = y;
}
if (curses_started)
wmove(win,y,x);
TRACE_RETURN();
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short get_row_for_tof_eof(short row,CHARTYPE scridx)
#else
short get_row_for_tof_eof(row,scridx)
short row;
CHARTYPE scridx;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: get_row_for_tof_eof");
if (screen[scridx].sl[row].line_type == LINE_OUT_OF_BOUNDS_ABOVE)
{
for(;screen[scridx].sl[row].line_type != LINE_TOF;row++)
/* for(;screen[scridx].sl[row].line_type != LINE_TOF_EOF;row++) MH12 */
;
}
if (screen[scridx].sl[row].line_type == LINE_OUT_OF_BOUNDS_BELOW)
{
/* for(;screen[scridx].sl[row].line_type != LINE_TOF_EOF;row--) MH12 */
for(;screen[scridx].sl[row].line_type != LINE_EOF;row--)
;
}
TRACE_RETURN();
return(row);
}
/***********************************************************************/
#ifdef HAVE_PROTO
void set_compare_exact( bool exact )
#else
void set_compare_exact( exact )
bool exact;
#endif
/***********************************************************************/
{
CompareExact = exact;
}
/***********************************************************************/
#ifdef HAVE_PROTO
static int query_item_compare(const void *inkey, const void *intpl)
#else
static int query_item_compare(inkey, intpl)
const void *inkey;
const void *intpl;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
const char *key = (char *)inkey;
const QUERY_ITEM *tpl = (QUERY_ITEM *)intpl;
int rc=0,m=CompareLen;
/*--------------------------- processing ------------------------------*/
if (m > tpl->name_length)
m = tpl->name_length;
rc = memcmp(key, (DEFCHAR*)tpl->name, m);
if (rc != 0)
return(rc);
if ( CompareExact )
{
if (CompareLen > tpl->name_length)
return(1);
if (CompareLen < tpl->name_length)
return(-1);
}
else
{
if (equal(tpl->name,key,tpl->min_len))
return 0;
if (CompareLen > tpl->name_length)
return(1);
if (CompareLen < tpl->name_length)
return(-1);
}
return(0);
}
/***********************************************************************/
#ifdef HAVE_PROTO
int search_query_item_array(void *base, size_t num, size_t width, const char *needle, int len)
#else
int search_query_item_array(base, num, width, needle, len)
void *base;
size_t num;
size_t width;
const char *needle;
int len;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
char *buf=NULL, *result=NULL;
int i=0;
#ifdef __CHECKER__
/* checker has a buggy bsearch stub */
size_t alloclen = width;
#endif
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: search_query_item_array");
#ifdef __CHECKER__
if (len > alloclen)
alloclen = len;
if ((buf = (char*)(*the_malloc)(alloclen+1)) == NULL)
#else
if ((buf = (char*)(*the_malloc)(len+1)) == NULL)
#endif
{
TRACE_RETURN();
return(-1);
}
for (i=0; i<len; i++)
{
buf[i] = (char)tolower(needle[i]);
}
buf[i] = '\0';
CompareLen = len;
result = bsearch(buf, base, num, width, query_item_compare);
(*the_free)(buf);
if (result == NULL)
{
TRACE_RETURN();
return(-1);
}
TRACE_RETURN();
return((int) (((long) result - (long) base) / width ));
}
/***********************************************************************/
#ifdef HAVE_PROTO
int split_function_name(CHARTYPE *funcname, int *funcname_length)
#else
int split_function_name(funcname, funcname_length)
CHARTYPE *funcname;
int *funcname_length;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
int functionname_length = strlen((DEFCHAR*)funcname);
int itemno=0,pos=0;
/*--------------------------- processing ------------------------------*/
pos = memreveq((CHARTYPE *)funcname,(CHARTYPE)'.',functionname_length);
if (pos == (-1)
|| functionname_length == pos-1)
{
/*
* Not a valid implied extract function; could be a boolean
*/
itemno = -1;
}
else
{
if (!valid_positive_integer((CHARTYPE *)funcname+pos+1))
{
/*
* Not a valid implied extract function; could be a boolean
*/
itemno = -1;
}
else
{
itemno = atoi((DEFCHAR *)funcname+pos+1);
/*
* If the tail is > maximum number of variables that we can
* handle, exit with error.
*/
functionname_length = pos;
}
}
*funcname_length = functionname_length;
return itemno;
}
/***********************************************************************/
#ifdef HAVE_PROTO
char *thetmpnam(char *prefix)
#else
char *thetmpnam(prefix)
char *prefix;
#endif
/***********************************************************************/
{
/*
* This function is not thread safe.
*/
#define PATH_DELIMS ":\\/"
/*--------------------------- local data ------------------------------*/
#if !defined HAVE_BROKEN_TMPNAM
return tmpnam( NULL );
#else
char *path=NULL,*filename=NULL;
static char *buffer = NULL;
static size_t buffersize = 0;
size_t needed;
unsigned long i;
FILE *fp=NULL;
char tmpbuf[4]="C:?";
if ((path = getenv("TMP")) == NULL)
if ((path = getenv("TEMP")) == NULL)
if ((path = getenv("TMPDIR")) == NULL)
{
tmpbuf[2] = ISLASH;
path = tmpbuf; /* works in most cases */
}
needed = strlen(path) + 1 /* ISTR_SLASH */ + sizeof("TMP12345.TMP");
if (needed > buffersize)
{
if ((buffer = realloc(buffer,needed)) == NULL)
return(NULL);
buffersize = needed;
}
strcpy(buffer,path);
if (strchr(PATH_DELIMS,buffer[strlen(buffer)-1]) == NULL)
strcat(buffer,ISTR_SLASH);
filename = buffer + strlen(buffer);
for (i = 0;i <= 99999;i++)
{
sprintf(filename,"%s%05lu.TMP",prefix,i);
if (access(filename,0) != 0)
{
/*
* Open the file to ensure it is created
*/
if ( ( fp = fopen( buffer, "w" ) ) == NULL )
return( NULL );
fclose( fp );
return(buffer);
}
}
return(NULL);
#endif
}
#ifndef HAVE_DOUPDATE
/***********************************************************************/
#ifdef HAVE_PROTO
int doupdate(void)
#else
int doupdate()
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
unsigned short y=0,x=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("util.c: doupdate");
getyx(CURRENT_WINDOW,y,x);
refresh();
wmove(CURRENT_WINDOW,y,x);
wrefresh(CURRENT_WINDOW);
TRACE_RETURN();
return(0);
}
#endif
#ifdef USE_EXTCURSES
/***********************************************************************/
#ifdef HAVE_PROTO
int has_colors(void)
#else
int has_colors()
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
return(TRUE);
}
/***********************************************************************/
#ifdef HAVE_PROTO
int start_color(void)
#else
int start_color()
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register int i=0;
/*--------------------------- processing ------------------------------*/
for (i=0;i<COLOR_PAIRS;i++)
color_pair[i] = NORMAL;
fore_color[COLOR_BLACK ] = F_BLACK ;
fore_color[COLOR_BLUE ] = F_BLUE ;
fore_color[COLOR_GREEN ] = F_GREEN ;
fore_color[COLOR_CYAN ] = F_CYAN ;
fore_color[COLOR_RED ] = F_RED ;
fore_color[COLOR_MAGENTA] = F_MAGENTA;
fore_color[COLOR_YELLOW ] = F_BROWN ;
fore_color[COLOR_WHITE ] = F_WHITE ;
back_color[COLOR_BLACK ] = B_BLACK ;
back_color[COLOR_BLUE ] = B_BLUE ;
back_color[COLOR_GREEN ] = B_GREEN ;
back_color[COLOR_CYAN ] = B_CYAN ;
back_color[COLOR_RED ] = B_RED ;
back_color[COLOR_MAGENTA] = B_MAGENTA;
back_color[COLOR_YELLOW ] = B_BROWN ;
back_color[COLOR_WHITE ] = B_WHITE ;
return(0);
}
/***********************************************************************/
#ifdef HAVE_PROTO
int init_pair(int pairnum,chtype fore,chtype back)
#else
int init_pair(pairnum,fore,back)
int pairnum;
chtype fore,back;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register int i=0;
/*--------------------------- processing ------------------------------*/
color_pair[pairnum] = fore_color[fore] | back_color[back];
return(0);
}
#endif
|