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
|
/***********************************************************************/
/* TARGET.C - Functions related to targets. */
/***********************************************************************/
/*
* 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: target.c,v 1.1 1999/06/25 06:11:56 mark Exp mark $";
#include <the.h>
#include <proto.h>
#define STATE_START 0
#define STATE_DELIM 1
#define STATE_STRING 2
#define STATE_BOOLEAN 3
#define STATE_NEXT 4
#define STATE_POINT 5
#define STATE_ABSOLUTE 6
#define STATE_RELATIVE 7
#define STATE_POSITIVE 8
#define STATE_NEGATIVE 9
#define STATE_SPARE 10
#define STATE_QUIT 98
#define STATE_ERROR 99
#ifdef HAVE_PROTO
static bool is_blank(LINE *);
#else
static bool is_blank();
#endif
/***********************************************************************/
#ifdef HAVE_PROTO
short split_change_params(CHARTYPE *cmd_line,CHARTYPE **old_str,CHARTYPE **new_str,
TARGET *target,LINETYPE *num,LINETYPE *occ)
#else
short split_change_params(cmd_line,old_str,new_str,target,num,occ)
CHARTYPE *cmd_line,**old_str,**new_str;
TARGET *target;
LINETYPE *num,*occ;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
#define SCP_PARAMS 2
CHARTYPE *word[SCP_PARAMS+1];
CHARTYPE strip[SCP_PARAMS];
register short i=0,j=0;
CHARTYPE *target_start=NULL;
short rc=RC_OK;
CHARTYPE delim=' ';
short idx=0;
short target_type = TARGET_NORMAL|TARGET_BLOCK_CURRENT|TARGET_ALL|TARGET_SPARE;
unsigned short num_params=0;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: split_change_params");
#endif
/*---------------------------------------------------------------------*/
/* First, determine the delimiter; the first character in the argument */
/* string. */
/*---------------------------------------------------------------------*/
delim = *(cmd_line);
/*---------------------------------------------------------------------*/
/* Set up default values for the return values... */
/*---------------------------------------------------------------------*/
*old_str = cmd_line+1;
*new_str = (CHARTYPE *)"";
target_start = (CHARTYPE *)"";
*num = *occ = 1L;
target->num_lines = 1L;
target->true_line = get_true_line(TRUE);
/*---------------------------------------------------------------------*/
/* Set up default values for the return values... */
/*---------------------------------------------------------------------*/
idx = strlen((DEFCHAR *)cmd_line);
for (i=1,j=0;i<idx;i++)
{
if (*(cmd_line+i) == delim)
{
j++;
switch(j)
{
case 1:
*(cmd_line+i) = '\0';
*new_str = cmd_line+i+1;
break;
case 2:
*(cmd_line+i) = '\0';
target_start = cmd_line+i+1;
break;
default:
break;
}
}
if (j == 2)
break;
}
/*---------------------------------------------------------------------*/
/* Check to see if there is a target, if not return here. */
/*---------------------------------------------------------------------*/
if (blank_field(target_start))
{
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OK);
}
/*---------------------------------------------------------------------*/
/* Parse and validate the target... */
/*---------------------------------------------------------------------*/
if ((rc = validate_target(target_start,target,target_type,get_true_line(TRUE),TRUE,TRUE)) != RC_OK)
{
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
}
/*---------------------------------------------------------------------*/
/* Check to see if there are further arguments after the target... */
/*---------------------------------------------------------------------*/
if (target->spare == (-1))
{
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OK);
}
/*---------------------------------------------------------------------*/
/* Validate the arguments following the target... */
/*---------------------------------------------------------------------*/
strip[0]=STRIP_BOTH;
strip[1]=STRIP_BOTH;
num_params = param_split(strtrunc(target->rt[target->spare].string),word,SCP_PARAMS,WORD_DELIMS,TEMP_PARAM,strip,FALSE);
if (num_params == 1
|| num_params == 2)
{
if (strcmp((DEFCHAR *)word[0],"*") == 0)
*num = max_line_length;
/* *num = MAX_LONG;*/
else
if (!valid_positive_integer(word[0]))
{
display_error(4,word[0],FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
else
*num = min(atol((DEFCHAR *)word[0]),max_line_length);
}
if (num_params == 2)
{
if (!valid_positive_integer(word[1]))
{
display_error(4,word[1],FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
else
*occ = atol((DEFCHAR *)word[1]);
}
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short parse_target(CHARTYPE *target_spec,LINETYPE true_line,TARGET *target,
short target_types,bool display_parse_error,
bool allow_error_display,bool column_target)
#else
short parse_target(target_spec,true_line,target,target_types,
display_parse_error,allow_error_display,column_target)
CHARTYPE *target_spec;
LINETYPE true_line;
TARGET *target;
short target_types;
bool display_parse_error,allow_error_display,column_target;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
short num_targets=0;
CHARTYPE boolean=' ';
short state=STATE_NEXT;
short len=0,inc=0,target_length=strlen((DEFCHAR *)target_spec),off=0;
CHARTYPE delim=' ';
register short i=0;
register short j=0;
short str_start=0,str_end=0;
short rc=RC_OK;
short potential_spare_start=0;
bool negative=FALSE;
CHARTYPE *ptr=NULL;
LINETYPE lineno=0L;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: parse_target");
#endif
/*---------------------------------------------------------------------*/
/* Copy the incoming target specification... */
/*---------------------------------------------------------------------*/
if ((target->string = (CHARTYPE *)my_strdup(target_spec)) == NULL)
{
if (allow_error_display)
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
ptr = target->string;
/*---------------------------------------------------------------------*/
/* Parse the target... */
/*---------------------------------------------------------------------*/
switch(target_types)
{
case TARGET_FIND:
case TARGET_NFIND:
case TARGET_FINDUP:
case TARGET_NFINDUP:
for (i=0;i<target_length;i++)
{
if (*(ptr+i) == ' ')
*(ptr+i) = CURRENT_VIEW->arbchar_single;
else
if (*(ptr+i) == '_')
*(ptr+i) = ' ';
}
target->rt = (RTARGET *)(*the_malloc)(sizeof(RTARGET));
if (target->rt == NULL)
{
if (allow_error_display)
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
target->num_targets = 1;
target->rt[0].not = (target_types == TARGET_NFIND || target_types == TARGET_NFINDUP)?TRUE:FALSE;
target->rt[0].negative = (target_types == TARGET_FINDUP || target_types == TARGET_NFINDUP)?TRUE:FALSE;
target->rt[0].boolean = ' ';
target->rt[0].length = target_length;
target->rt[0].target_type = TARGET_STRING;
target->rt[0].numeric_target = 0L;
target->rt[0].string = (CHARTYPE *)(*the_malloc)((target_length*sizeof(CHARTYPE))+1);
if (target->rt[0].string == (CHARTYPE *)NULL)
{
if (allow_error_display)
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
strcpy((DEFCHAR *)target->rt[0].string,(DEFCHAR *)ptr);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OK);
break;
default:
break;
}
while(1)
{
inc = 1;
switch(state)
{
case STATE_NEXT:
if (target->rt == NULL)
target->rt = (RTARGET *)(*the_malloc)((num_targets+1)*sizeof(RTARGET));
else
target->rt = (RTARGET *)(*the_realloc)(target->rt,(num_targets+1)*sizeof(RTARGET));
if (target->rt == NULL)
{
if (allow_error_display)
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
target->rt[num_targets].not = FALSE;
target->rt[num_targets].boolean = boolean;
target->rt[num_targets].length = 0;
target->rt[num_targets].string = NULL;
target->rt[num_targets].negative = FALSE;
target->rt[num_targets].target_type = TARGET_ERR;
if (target->spare != (-1))
state = STATE_SPARE;
else
state = STATE_START;
inc = 0;
break;
case STATE_START:
switch(*(ptr+i))
{
case '~': case '^':
if (target->rt[num_targets].not)
{
state = STATE_ERROR;
inc = 0;
break;
}
target->rt[num_targets].not = TRUE;
break;
case ' ':
case '\t':
break;
case '-':
if (target->rt[num_targets].negative)
{
state = STATE_ERROR;
inc = 0;
break;
}
target->rt[num_targets].negative = TRUE;
state = STATE_NEGATIVE;
break;
case '+':
if (target->rt[num_targets].negative)
{
state = STATE_ERROR;
inc = 0;
break;
}
/* inc = 1; */
target->rt[num_targets].negative = FALSE;
state = STATE_POSITIVE;
break;
case '.':
if (target->rt[num_targets].negative)
{
state = STATE_ERROR;
inc = 0;
break;
}
state = STATE_POINT;
str_start = i;
break;
case '*':
state = STATE_BOOLEAN;
target->rt[num_targets].target_type = TARGET_RELATIVE;
target->rt[num_targets].string = (CHARTYPE *)(*the_malloc)(3);
if (target->rt[num_targets].string == NULL)
{
if (allow_error_display)
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
if (target->rt[num_targets].negative)
{
if (column_target)
target->rt[num_targets].numeric_target = (LINETYPE)CURRENT_VIEW->zone_start - true_line - 1L;
else
target->rt[num_targets].numeric_target = true_line*(-1L);
strcpy((DEFCHAR *)target->rt[num_targets].string,"-*");
}
else
{
if (column_target)
target->rt[num_targets].numeric_target = (LINETYPE)((LINETYPE)CURRENT_VIEW->zone_end - true_line) + 1L;
else
target->rt[num_targets].numeric_target = (CURRENT_FILE->number_lines - true_line) + 2L;
strcpy((DEFCHAR *)target->rt[num_targets].string,"*");
}
inc = 1;
potential_spare_start = i+1;
num_targets++;
break;
case ':': case ';':
state = STATE_ABSOLUTE;
delim = *(ptr+i);
str_start = i+1;
break;
case '/': case '\\': case '@': case '`': case '#': case '$':
case '%': case '(': case ')': case '{': case '}': case '[': case ']':
case '"': case '\'': case '<': case '>':
case ',':
state = STATE_STRING;
str_start = i+1;
delim = *(ptr+i);
break;
case 'a': case 'A':
if (target->rt[num_targets].not
|| target->rt[num_targets].negative)
{
state = STATE_ERROR;
inc = 0;
break;
}
if (target_length-i < 3)
{
target->rt[num_targets].target_type = TARGET_ERR;
state = STATE_ERROR;
inc = 0;
break;
}
if (memcmpi((CHARTYPE *)"all",ptr+i,3) == 0
&& (*(ptr+(i+3)) == ' '
|| *(ptr+(i+3)) == '\0'
|| *(ptr+(i+3)) == '\t'))
{
target->rt[num_targets].target_type = TARGET_ALL;
inc = 3;
state = STATE_BOOLEAN;
num_targets++;
potential_spare_start = i+3;
break;
}
state = STATE_ERROR;
inc = 0;
break;
case 'b': case 'B':
if (target_length-i < 5)
{
state = STATE_ERROR;
inc = 0;
break;
}
if (memcmpi((CHARTYPE *)"blank",ptr+i,5) == 0
&& (*(ptr+(i+5)) == ' '
|| *(ptr+(i+5)) == '\0'
|| *(ptr+(i+5)) == '\t'))
{
target->rt[num_targets].target_type = TARGET_BLANK;
inc = 5;
potential_spare_start = i+5;
state = STATE_BOOLEAN;
num_targets++;
break;
}
if (target->rt[num_targets].not
|| target->rt[num_targets].negative)
{
state = STATE_ERROR;
inc = 0;
break;
}
if (memcmpi((CHARTYPE *)"block",ptr+i,5) == 0
&& (*(ptr+(i+5)) == ' '
|| *(ptr+(i+5)) == '\0'
|| *(ptr+(i+5)) == '\t'))
{
target->rt[num_targets].target_type = TARGET_BLOCK;
inc = 5;
potential_spare_start = i+5;
state = STATE_BOOLEAN;
num_targets++;
break;
}
state = STATE_ERROR;
inc = 0;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if (UNTAAx)
state = STATE_ABSOLUTE;
else
state = STATE_RELATIVE;
str_start = i;
delim = '\0';
inc = 0;
break;
default:
state = STATE_ERROR;
inc = 0;
break;
}
break;
case STATE_STRING:
switch(*(ptr+i))
{
case '/': case '\\': case '@': case '`': case '#': case '$':
case '%': case '(': case ')': case '{': case '}': case '[': case ']':
case '"': case '\'': case '<': case '>':
case '\0':
if (*(ptr+i) == delim
|| *(ptr+i) == '\0')
{
state = STATE_BOOLEAN;
str_end = i;
len = str_end-str_start;
target->rt[num_targets].string = (CHARTYPE *)(*the_malloc)(len+1);
if (target->rt[num_targets].string == NULL)
{
if (allow_error_display)
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
memcpy(target->rt[num_targets].string,ptr+str_start,len);
target->rt[num_targets].string[len] = '\0';
target->rt[num_targets].length = len;
target->rt[num_targets].target_type = TARGET_STRING;
potential_spare_start = i+1;
num_targets++;
}
break;
default:
break;
}
break;
case STATE_BOOLEAN:
switch(*(ptr+i))
{
case '\0':
break;
case ' ':
case '\t':
break;
case '&':
case '|':
state = STATE_NEXT;
boolean = *(ptr+i);
break;
default:
if (target_types & TARGET_SPARE)
{
/* str_start = i;*/
str_start = potential_spare_start;
state = STATE_NEXT;
target->spare = 0; /* just to ensure state is set */
break;
}
state = STATE_ERROR;
inc = 0;
break;
}
break;
case STATE_SPARE:
switch(*(ptr+i))
{
case '\0':
str_end = i;
len = str_end-str_start;
target->rt[num_targets].string = (CHARTYPE *)(*the_malloc)(len+1);
if (target->rt[num_targets].string == NULL)
{
if (allow_error_display)
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
memcpy(target->rt[num_targets].string,ptr+str_start,len);
target->rt[num_targets].string[len] = '\0';
target->rt[num_targets].length = len;
target->rt[num_targets].target_type = TARGET_SPARE;
target->spare = num_targets;
num_targets++;
*(ptr+str_start) = '\0'; /* so target string does not include spare */
break;
default:
break;
}
break;
case STATE_ABSOLUTE:
case STATE_RELATIVE:
if (target->rt[num_targets].not)
{
state = STATE_ERROR;
inc = 0;
break;
}
switch(*(ptr+i))
{
case '\0':
case ' ':
case '\t':
str_end = i;
len = str_end-str_start;
target->rt[num_targets].string = (CHARTYPE *)(*the_malloc)(len+2);
if (target->rt[num_targets].string == NULL)
{
if (allow_error_display)
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
if (delim != '\0')
{
target->rt[num_targets].string[0] = delim;
off = 1;
}
else
off = 0;
memcpy(target->rt[num_targets].string+off,ptr+str_start,len);
target->rt[num_targets].string[len+off] = '\0';
target->rt[num_targets].length = len+off;
target->rt[num_targets].target_type = (state == STATE_ABSOLUTE) ? TARGET_ABSOLUTE : TARGET_RELATIVE;
target->rt[num_targets].numeric_target = atol((DEFCHAR *)target->rt[num_targets].string+off);
if (target->rt[num_targets].negative)
target->rt[num_targets].numeric_target *= (-1L);
if (state == STATE_ABSOLUTE)
{
if (column_target)
{
/* if (target->rt[num_targets].numeric_target < CURRENT_VIEW->current_column)*/
if (target->rt[num_targets].numeric_target < true_line)
{
target->rt[num_targets].negative = TRUE;
target->rt[num_targets].numeric_target = max(target->rt[num_targets].numeric_target,max(1,CURRENT_VIEW->zone_start-1));
}
else
target->rt[num_targets].numeric_target = min(target->rt[num_targets].numeric_target,min(max_line_length+1,CURRENT_VIEW->zone_end+1));
}
else
{
if (target->rt[num_targets].numeric_target < true_line)
target->rt[num_targets].negative = TRUE;
else
target->rt[num_targets].numeric_target = min(target->rt[num_targets].numeric_target,(CURRENT_FILE->number_lines+1L));
}
}
else
{
if (column_target)
{
if (target->rt[num_targets].negative)
target->rt[num_targets].numeric_target = max(target->rt[num_targets].numeric_target,((LINETYPE)CURRENT_VIEW->zone_start - true_line - 1L));
else
target->rt[num_targets].numeric_target = min(target->rt[num_targets].numeric_target,((LINETYPE)CURRENT_VIEW->zone_end - true_line + 1L));
}
else
{
if (target->rt[num_targets].negative)
target->rt[num_targets].numeric_target = max((target->rt[num_targets].numeric_target),(true_line == 0L) ? (0L) : (true_line*(-1L)));
else
target->rt[num_targets].numeric_target = min(target->rt[num_targets].numeric_target,(CURRENT_FILE->number_lines - true_line+1L));
}
}
potential_spare_start = i;
num_targets++;
state = STATE_BOOLEAN;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
break;
default:
state = STATE_ERROR;
inc = 0;
break;
}
break;
case STATE_NEGATIVE:
case STATE_POSITIVE:
switch(*(ptr+i))
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
state = STATE_RELATIVE;
delim = (state==STATE_NEGATIVE) ? '-' : '+';
str_start = i;
inc = 0;
break;
case '/': case '\\': case '@': case '`': case '#': case '$':
case '%': case '(': case ')': case '{': case '}': case '[': case ']':
case '"': case '\'': case '<': case '>':
state = STATE_START;
inc = 0;
break;
case '*':
state = STATE_START;
inc = 0;
break;
case 'b': case 'B':
state = STATE_START;
inc = 0;
break;
default:
state = STATE_ERROR;
inc = 0;
break;
}
break;
case STATE_POINT:
switch(*(ptr+i))
{
case ' ':
case '\t':
state = STATE_BOOLEAN;
/* fall through */
case '&':
case '|':
case '\0':
target->rt[num_targets].target_type = TARGET_POINT;
str_end = i;
len = str_end-str_start;
target->rt[num_targets].string = (CHARTYPE *)(*the_malloc)(len+1);
if (target->rt[num_targets].string == NULL)
{
if (allow_error_display)
display_error(30,(CHARTYPE *)"",FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OUT_OF_MEMORY);
}
memcpy(target->rt[num_targets].string,ptr+str_start,len);
target->rt[num_targets].string[len] = '\0';
target->rt[num_targets].length = len;
if (find_named_line(target->rt[num_targets].string,&lineno,TRUE) == NULL)
{
if (allow_error_display)
display_error(17,(CHARTYPE *)target->rt[num_targets].string,FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_TARGET_NOT_FOUND);
}
target->rt[num_targets].numeric_target = lineno;
if (target->rt[num_targets].numeric_target < true_line)
target->rt[num_targets].negative = TRUE;
else
target->rt[num_targets].numeric_target = min(target->rt[num_targets].numeric_target,(CURRENT_FILE->number_lines+1L));
num_targets++;
potential_spare_start = i;
if (*(ptr+i) == ' ' || *(ptr+i) == '\t')
break;
boolean = *(ptr+i);
state = STATE_NEXT;
break;
default:
break;
}
break;
case STATE_ERROR:
for (j=0;j<num_targets;j++)
target->rt[j].target_type = TARGET_ERR;
state = STATE_QUIT;
break;
}
if (state == STATE_QUIT)
break;
i += inc;
if (i > target_length) /* this allows for testing '\0' as delimiter */
break;
}
target->num_targets = num_targets;
if (num_targets == 0
|| target->rt[0].target_type == TARGET_ERR)
{
if (display_parse_error
&& allow_error_display)
display_error(1,ptr,FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
/*---------------------------------------------------------------------*/
/* Time to validate the targets we have parsed... */
/*---------------------------------------------------------------------*/
/* Valid combinations are: */
/* TARGET_ALL (1 target only) */
/* ALL only */
/* TARGET_BLOCK (1 target only) */
/* BLOCK only */
/* this section sets target_type to TARGET_BLOCK_ANY */
/* or TARGET_BLOCK_CURRENT */
/* TARGET_BLANK (BLANK can be upper or lower case) */
/* BLANK */
/* -BLANK */
/* ~BLANK */
/* ~-BLANK */
/* TARGET_STRING (valid delimiters are / \ or @ */
/* /string/ */
/* -/string/ */
/* ~/string/ */
/* ~-/string/ */
/* TARGET_POINT */
/* .xxxxxx */
/* ~.xxxxxx */
/* TARGET_ABSOLUTE */
/* :99 */
/* ;99 */
/* TARGET_RELATIVE */
/* 99 */
/* +99 */
/* -99 */
/* * */
/* +* */
/* -* */
/* */
/* Any of the above target types may be or'd together. */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* For each of the targets, check its validity... */
/*---------------------------------------------------------------------*/
negative = target->rt[0].negative;
for (i=0;i<num_targets-((target->spare == (-1)) ? 0 : 1);i++)
{
switch(target->rt[i].target_type)
{
case TARGET_BLOCK:
if (num_targets-((target->spare == (-1)) ? 0 : 1) != 1)
{
rc = RC_INVALID_OPERAND;
break;
}
if (target_types & TARGET_BLOCK_ANY)
target->rt[i].target_type = TARGET_BLOCK_ANY;
else
if (target_types & TARGET_BLOCK_CURRENT)
target->rt[i].target_type = TARGET_BLOCK_CURRENT;
else
rc = RC_INVALID_OPERAND;
break;
case TARGET_ALL:
if (num_targets-((target->spare == (-1)) ? 0 : 1) != 1)
{
rc = RC_INVALID_OPERAND;
break;
}
if (target_types & target->rt[i].target_type)
break;
rc = RC_INVALID_OPERAND;
break;
default:
if (target->rt[i].negative != negative)
{
rc = RC_INVALID_OPERAND;
break;
}
if (target_types & target->rt[i].target_type)
break;
rc = RC_INVALID_OPERAND;
break;
}
if (rc == RC_INVALID_OPERAND)
break;
}
/*---------------------------------------------------------------------*/
/* Display an error if anything found amiss and we are directed to */
/* display an error... */
/*---------------------------------------------------------------------*/
if (rc != RC_OK
&& display_parse_error
&& allow_error_display)
display_error(1,ptr,FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
void initialise_target(TARGET *target)
#else
void initialise_target(target)
TARGET *target;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: initialise_target");
#endif
target->rt=NULL;
target->string=NULL;
target->num_lines = target->true_line = target->last_line = 0L;
target->num_targets = 0;
target->spare = (-1);
target->ignore_scope = FALSE;
#ifdef THE_TRACE
trace_return();
#endif
return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
void free_target(TARGET *target)
#else
void free_target(target)
TARGET *target;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: free_target");
#endif
if (target->string == NULL
&& target->num_targets == 0
&& target->rt == NULL)
{
#ifdef THE_TRACE
trace_return();
#endif
return;
}
for (i=0;i<target->num_targets;i++)
{
if (target->rt[i].string != NULL)
(*the_free)(target->rt[i].string);
}
if (target->string != NULL)
(*the_free)(target->string);
if (target->rt != NULL)
(*the_free)(target->rt);
#ifdef THE_TRACE
trace_return();
#endif
return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
short find_target(TARGET *target,LINETYPE true_line,bool display_parse_error,bool allow_error_display)
#else
short find_target(target,true_line,display_parse_error,allow_error_display)
TARGET *target;
LINETYPE true_line;
bool display_parse_error,allow_error_display;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
short rc=RC_OK;
LINE *curr=NULL;
LINETYPE num_lines=0L;
LINETYPE line_number=0L;
short status=RC_OK;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: find_target");
#endif
/*---------------------------------------------------------------------*/
/* Check single targets first (ALL and BLOCK) */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Check if first, and only target, is BLOCK... */
/*---------------------------------------------------------------------*/
switch(target->rt[0].target_type)
{
case TARGET_ALL:
target->true_line = 1L;
target->last_line = CURRENT_FILE->number_lines;
target->num_lines = CURRENT_FILE->number_lines;
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OK);
break;
case TARGET_BLOCK_ANY:
if (MARK_VIEW == NULL)
{
if (allow_error_display)
display_error(44,(CHARTYPE *)"",FALSE);
rc = RC_TARGET_NOT_FOUND;
}
else
{
target->num_lines = MARK_VIEW->mark_end_line - MARK_VIEW->mark_start_line + 1L;
target->true_line = MARK_VIEW->mark_start_line;
target->last_line = MARK_VIEW->mark_end_line;
}
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
break;
case TARGET_BLOCK_CURRENT:
if (MARK_VIEW == NULL)
{
if (allow_error_display)
display_error(44,(CHARTYPE *)"",FALSE);
rc = RC_TARGET_NOT_FOUND;
}
else
{
if (MARK_VIEW != CURRENT_VIEW)
{
if (allow_error_display)
display_error(45,(CHARTYPE *)"",FALSE);
rc = RC_TARGET_NOT_FOUND;
}
else
{
target->num_lines = MARK_VIEW->mark_end_line - MARK_VIEW->mark_start_line + 1L;
target->true_line = MARK_VIEW->mark_start_line;
target->last_line = MARK_VIEW->mark_end_line;
}
}
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
break;
default:
break;
}
/*---------------------------------------------------------------------*/
/* All other targets are potentially repeating targets... */
/*---------------------------------------------------------------------*/
rc = RC_TARGET_NOT_FOUND;
line_number = true_line;
curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,true_line,CURRENT_FILE->number_lines);
num_lines = 0L;
while(1)
{
status = find_rtarget_target(curr,target,true_line,line_number,&num_lines);
if (status != RC_TARGET_NOT_FOUND)
break;
/*---------------------------------------------------------------------*/
/* We can determine the direction of execution based on the first */
/* target, as all targets must have the same direction to have reached */
/* here. */
/*---------------------------------------------------------------------*/
if (target->rt[0].negative)
{
curr = curr->prev;
line_number--;
}
else
{
curr = curr->next;
line_number++;
}
if (curr == NULL)
break;
}
if (status == RC_OK)
{
num_lines = ((target->rt[0].negative) ? -num_lines : num_lines);
target->num_lines = num_lines;
target->true_line = true_line;
if (target->rt[0].negative)
{
curr = curr->next;
target->last_line = find_next_in_scope(CURRENT_VIEW,curr,++line_number,DIRECTION_FORWARD);
}
else
{
curr = curr->prev;
target->last_line = find_next_in_scope(CURRENT_VIEW,curr,--line_number,DIRECTION_BACKWARD);
}
rc = RC_OK;
}
else if (status == RC_TARGET_NOT_FOUND)
{
if (allow_error_display)
display_error(17,target->string,FALSE);
rc = RC_TARGET_NOT_FOUND;
}
else
rc = status;
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short find_column_target(CHARTYPE *line,LENGTHTYPE len,TARGET *target,LENGTHTYPE true_column,bool display_parse_error,bool allow_error_display)
#else
short find_column_target(line,len,target,true_column,display_parse_error,allow_error_display)
CHARTYPE *line;
LENGTHTYPE len;
TARGET *target;
LENGTHTYPE true_column;
bool display_parse_error,allow_error_display;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
short rc=RC_OK;
LINETYPE column_number=0L;
LINETYPE num_columns=0L;
bool status=FALSE;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: find_column_target");
#endif
/*---------------------------------------------------------------------*/
/* All column targets are potentially repeating targets... */
/*---------------------------------------------------------------------*/
rc = RC_TARGET_NOT_FOUND;
status = FALSE;
column_number = true_column;
num_columns = 0;
while(1)
{
status = find_rtarget_column_target(line,len,target,true_column,column_number,&num_columns);
if (status)
break;
/*---------------------------------------------------------------------*/
/* We can determine the direction of execution based on the first */
/* target, as all targets must have the same direction to have reached */
/* here. */
/*---------------------------------------------------------------------*/
if (target->rt[0].negative)
{
if (column_number-- == (LINETYPE)CURRENT_VIEW->zone_start - 2L)
{
status = FALSE;
break;
}
}
else
{
if (column_number++ == (LINETYPE)CURRENT_VIEW->zone_end + 2L)
{
status = FALSE;
break;
}
}
}
if (status)
{
num_columns = ((target->rt[0].negative) ? -num_columns : num_columns);
target->num_lines = num_columns;
target->true_line = (LINETYPE)true_column;
target->last_line = (LINETYPE)column_number;
rc = RC_OK;
}
else
{
if (allow_error_display)
display_error(17,target->string,FALSE);
rc = RC_TARGET_NOT_FOUND;
}
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
static bool is_blank(LINE *curr)
#else
static bool is_blank(curr)
LINE *curr;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
bool rc=TRUE;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: is_blank");
#endif
if (CURRENT_VIEW->zone_start > curr->length)
{
#ifdef THE_TRACE
trace_return();
#endif
return(TRUE);
}
for (i=CURRENT_VIEW->zone_start-1;i<min(CURRENT_VIEW->zone_end,curr->length);i++)
{
if (*(curr->line+i) != ' ')
{
rc = FALSE;
break;
}
}
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
LINE *find_named_line(CHARTYPE *name,LINETYPE *retline,bool respect_scope)
#else
LINE *find_named_line(name,retline,respect_scope)
CHARTYPE *name;
LINETYPE *retline;
bool respect_scope;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
LINETYPE lineno=0;
LINE *curr=NULL;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: find_named_line");
#endif
/*---------------------------------------------------------------------*/
/* Find the line number in the current file of the named line specified*/
/*---------------------------------------------------------------------*/
curr = CURRENT_FILE->first_line;
while(curr != (LINE *)NULL)
{
/*---------------------------------------------------------------------*/
/* Check the line's name if we are not respecting scope or if we are */
/* respecting scope and the line is in scope. */
/*---------------------------------------------------------------------*/
if (!respect_scope
|| (respect_scope && (IN_SCOPE(CURRENT_VIEW,curr) || CURRENT_VIEW->scope_all)))
{
if (curr->name != (CHARTYPE *)NULL)
if (strcmp((DEFCHAR *)curr->name,(DEFCHAR *)name) == 0)
{
#ifdef THE_TRACE
trace_return();
#endif
*retline = lineno;
return(curr);
}
}
lineno++;
curr = curr->next;
}
#ifdef THE_TRACE
trace_return();
#endif
return((LINE *)NULL);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short find_string_target(LINE *curr,RTARGET *rt)
#else
short find_string_target(curr,rt)
LINE *curr;
RTARGET *rt;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
CHARTYPE *haystack=curr->line;
CHARTYPE temp_str[MAX_COMMAND_LENGTH];
CHARTYPE *needle=temp_str;
LENGTHTYPE needle_length=0,haystack_length=0,real_start=0,real_end=0;
bool use_trec=FALSE;
short rc=RC_OK;
short loc=(-1);
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: find_string_target");
#endif
/*---------------------------------------------------------------------*/
/* Copy the supplied string target rather than point to it, as we don't*/
/* want to change the value of the target if it is a HEX string. */
/*---------------------------------------------------------------------*/
strcpy((DEFCHAR*)temp_str,(DEFCHAR*)rt->string);
/*---------------------------------------------------------------------*/
/* If HEX is on, convert the target from a HEX format to CHARTYPE. */
/*---------------------------------------------------------------------*/
if (CURRENT_VIEW->hex == TRUE)
{
rc = convert_hex_strings(needle);
if (rc == (-1))
{
display_error(32,needle,FALSE);
#ifdef THE_TRACE
trace_return();
#endif
return(RC_INVALID_OPERAND);
}
else
needle_length = rc;
}
else
needle_length = strlen((DEFCHAR *)needle);
/*---------------------------------------------------------------------*/
/* Determine if we need to copy the contents of the line into trec. */
/* The reasons we need to do this are: */
/* - the length of the needle is 0 */
/* - the last character of needle is a space */
/*---------------------------------------------------------------------*/
if (needle_length == 0)
use_trec = TRUE;
else
if (*(needle+(needle_length-1)) == ' ')
use_trec = TRUE;
if (use_trec)
{
memset(trec,' ',max_line_length);
memcpy(trec,curr->line,curr->length);
haystack = trec;
/* haystack_length = max_line_length;*/
haystack_length = min(max_line_length,max(CURRENT_VIEW->zone_start,curr->length)+needle_length);
}
else
{
haystack = curr->line;
haystack_length = curr->length;
}
/*---------------------------------------------------------------------*/
/* Calculate the bounds to search in based on length of haystack and */
/* ZONE settings. If the haystack is empty, no need to search. */
/*---------------------------------------------------------------------*/
if (haystack_length != 0)
{
real_end = min(haystack_length-1,CURRENT_VIEW->zone_end-1);
real_start = max(0,CURRENT_VIEW->zone_start-1);
/*---------------------------------------------------------------------*/
/* Find the needle in the haystack. */
/*---------------------------------------------------------------------*/
loc = memfind(haystack+real_start,needle,(real_end-real_start+1),
needle_length,(CURRENT_VIEW->case_locate == CASE_IGNORE) ? TRUE : FALSE,
CURRENT_VIEW->arbchar_status,
CURRENT_VIEW->arbchar_single,
CURRENT_VIEW->arbchar_multiple);
}
if (loc == (-1))
rc = RC_TARGET_NOT_FOUND;
else
rc = RC_OK;
/*---------------------------------------------------------------------*/
/* Copy contents of linked list into rec if we have used rec as a work */
/* area. NOT NOW WE DON'T, we are using trec instead of rec. */
/*---------------------------------------------------------------------*/
#if 0
if (use_rec)
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
#endif
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short find_rtarget_target(LINE *curr,TARGET *target,LINETYPE true_line,LINETYPE line_number,LINETYPE *num_lines)
#else
short find_rtarget_target(curr,target,true_line,line_number,num_lines)
LINE *curr;
TARGET *target;
LINETYPE true_line,line_number;
LINETYPE *num_lines;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
bool target_found=FALSE,status=FALSE;
LINETYPE multiplier=0;
short rc=RC_OK;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: find_rtarget_target");
#endif
/*---------------------------------------------------------------------*/
/* If the line is not in scope and scope is respected, return FALSE. */
/*---------------------------------------------------------------------*/
if (!(IN_SCOPE(CURRENT_VIEW,curr))
&& !target->ignore_scope)
{
if (!CURRENT_VIEW->scope_all
&& !TOF(line_number)
&& !BOF(line_number))
{
#ifdef THE_TRACE
trace_return();
#endif
return(RC_TARGET_NOT_FOUND);
}
}
if (line_number != true_line)
*num_lines = *num_lines + 1L;
for (i=0;i<target->num_targets-((target->spare == (-1)) ? 0 : 1);i++)
{
target_found = FALSE;
multiplier = (target->rt[i].negative) ? -1L : 1L;
switch(target->rt[i].target_type)
{
case TARGET_BLANK:
if (true_line == line_number)
{
target_found = ((target->rt[i].not) ? TRUE : FALSE);
break;
}
if (target->rt[0].negative)
{
if (curr->prev == NULL)
break;
}
else
{
if (curr->next == NULL)
break;
}
target_found = is_blank(curr);
break;
case TARGET_POINT:
#if 0
if (true_line == line_number)
{
target_found = ((target->rt[i].not) ? TRUE : FALSE);
break;
}
#endif
if (curr->name == (CHARTYPE *)NULL)
break;
if (strcmp((DEFCHAR *)curr->name,(DEFCHAR *)target->rt[i].string) == 0)
target_found = TRUE;
break;
case TARGET_STRING:
if (true_line == line_number)
{
target_found = ((target->rt[i].not) ? TRUE : FALSE);
break;
}
if (target->rt[0].negative)
{
if (curr->prev == NULL)
break;
}
else
{
if (curr->next == NULL)
break;
}
rc = find_string_target(curr,&target->rt[i]);
switch(rc)
{
case RC_OK:
target_found = TRUE;
break;
case RC_TARGET_NOT_FOUND:
break;
default:
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
break;
}
break;
case TARGET_RELATIVE:
if ((*num_lines * multiplier) == target->rt[i].numeric_target)
target_found = TRUE;
if (target->rt[0].negative)
{
if (curr->prev == NULL)
{
target_found = TRUE;
break;
}
}
else
{
if (curr->next == NULL)
{
target_found = TRUE;
break;
}
}
break;
case TARGET_ABSOLUTE:
if (line_number == target->rt[i].numeric_target)
target_found = TRUE;
break;
default:
break;
}
if (target->rt[i].not)
target_found = (target_found) ? FALSE : TRUE;
switch(target->rt[i].boolean)
{
case ' ':
status = target_found;
break;
case '&':
status &= target_found;
break;
case '|':
status |= target_found;
break;
}
}
#ifdef THE_TRACE
trace_return();
#endif
return((status)?RC_OK:RC_TARGET_NOT_FOUND);
}
/***********************************************************************/
#ifdef HAVE_PROTO
bool find_rtarget_column_target(CHARTYPE *line,LENGTHTYPE len,TARGET *target,LENGTHTYPE true_column,LENGTHTYPE column_number,LINETYPE *num_columns)
#else
bool find_rtarget_column_target(line,len,target,true_column,column_number,num_columns)
CHARTYPE *line;
LENGTHTYPE len;
TARGET *target;
LENGTHTYPE true_column,column_number;
LINETYPE *num_columns;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
bool target_found=FALSE,status=FALSE;
LINETYPE multiplier=0;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: find_rtarget_column_target");
#endif
if (column_number != true_column)
*num_columns = *num_columns + 1L;
for (i=0;i<target->num_targets-((target->spare == (-1)) ? 0 : 1);i++)
{
target_found = FALSE;
multiplier = (target->rt[i].negative) ? -1L : 1L;
switch(target->rt[i].target_type)
{
case TARGET_BLANK:
if (true_column == column_number)
{
target_found = ((target->rt[i].not) ? TRUE : FALSE);
break;
}
if (column_number < CURRENT_VIEW->zone_start
|| column_number > CURRENT_VIEW->zone_end)
{
target_found = FALSE;
break;
}
if (column_number > len)
{
target_found = TRUE;
break;
}
if (*(line+column_number-1) == ' ') /* should be blank word */
target_found = TRUE;
else
target_found = FALSE;
break;
case TARGET_STRING:
#if NOTYET
if (true_line == line_number)
{
target_found = ((target->rt[i].not) ? TRUE : FALSE);
break;
}
if (target->rt[0].negative)
{
if (curr->prev == NULL)
break;
}
else
{
if (curr->next == NULL)
break;
}
if (find_string_target(curr,&target->rt[i]) == RC_OK)
target_found = TRUE;
#endif
break;
break;
case TARGET_ABSOLUTE:
if (column_number == target->rt[i].numeric_target)
target_found = TRUE;
break;
case TARGET_RELATIVE:
if ((*num_columns * multiplier) == target->rt[i].numeric_target)
target_found = TRUE;
break;
default:
break;
}
if (target->rt[i].not)
target_found = (target_found) ? FALSE : TRUE;
switch(target->rt[i].boolean)
{
case ' ':
status = target_found;
break;
case '&':
status &= target_found;
break;
case '|':
status |= target_found;
break;
}
}
#ifdef THE_TRACE
trace_return();
#endif
return(status);
}
/***********************************************************************/
#ifdef HAVE_PROTO
LINETYPE find_next_in_scope(VIEW_DETAILS *view,LINE *in_curr,LINETYPE line_number,short direction)
#else
LINETYPE find_next_in_scope(view,in_curr,line_number,direction)
VIEW_DETAILS *view;
LINE *in_curr;
LINETYPE line_number;
short direction;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
LINE *curr=in_curr;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: find_next_in_scope");
#endif
if (in_curr == NULL)
curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,line_number,CURRENT_FILE->number_lines);
for (;;line_number+=(LINETYPE)direction)
{
if (IN_SCOPE(view,curr))
break;
if (direction == DIRECTION_FORWARD)
curr = curr->next;
else
curr = curr->prev;
if (curr == NULL)
break;
}
#ifdef THE_TRACE
trace_return();
#endif
return(line_number);
}
/***********************************************************************/
#ifdef HAVE_PROTO
LINETYPE find_last_not_in_scope(VIEW_DETAILS *view,LINE *in_curr,LINETYPE line_number,short direction)
#else
LINETYPE find_last_not_in_scope(view,in_curr,line_number,direction)
VIEW_DETAILS *view;
LINE *in_curr;
LINETYPE line_number;
short direction;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
LINE *curr=in_curr;
LINETYPE offset=0L;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: find_last_not_in_scope");
#endif
if (in_curr == NULL)
curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,line_number,CURRENT_FILE->number_lines);
for (;;line_number+=(LINETYPE)direction)
{
if (IN_SCOPE(view,curr))
break;
if (direction == DIRECTION_FORWARD)
{
curr = curr->next;
offset = (-1L);
}
else
{
curr = curr->prev;
offset = 1L;
}
if (curr == NULL)
break;
}
#ifdef THE_TRACE
trace_return();
#endif
return(line_number+offset);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short validate_target(CHARTYPE *string,TARGET *target,short target_type,LINETYPE true_line,bool display_parse_error,bool allow_error_display)
#else
short validate_target(string,target,target_type,true_line,display_parse_error,allow_error_display)
CHARTYPE *string;
TARGET *target;
short target_type;
LINETYPE true_line;
bool display_parse_error,allow_error_display;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
short rc=RC_OK;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: validate_target");
#endif
rc = parse_target(string,true_line,target,target_type,display_parse_error,allow_error_display,FALSE);
if (rc != RC_OK)
{
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
}
rc = find_target(target,true_line,display_parse_error,allow_error_display);
if (rc != RC_OK)
{
#ifdef THE_TRACE
trace_return();
#endif
return(RC_TARGET_NOT_FOUND);
}
#ifdef THE_TRACE
trace_return();
#endif
return(RC_OK);
}
#ifdef NOT_USED_ANYMORE
/***********************************************************************/
#ifdef HAVE_PROTO
bool in_scope(VIEW_DETAILS *view,LINE *curr)
#else
bool in_scope(view,curr)
VIEW_DETAILS *view;
LINE *curr;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
bool rc=RC_OK;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: in_scope");
#endif
if (curr->select < view->display_low
|| curr->select > view->display_high)
rc = FALSE;
else
rc = TRUE;
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
}
#endif
/***********************************************************************/
#ifdef HAVE_PROTO
void calculate_scroll_values(short *number_focus_rows,LINETYPE *new_focus_line,
LINETYPE *new_current_line,bool *limit_of_screen,
bool *limit_of_file,bool *leave_cursor,
short direction)
#else
void calculate_scroll_values(number_focus_rows,new_focus_line,new_current_line,
limit_of_screen,limit_of_file,leave_cursor,direction)
short *number_focus_rows;
LINETYPE *new_focus_line,*new_current_line;
bool *limit_of_screen,*limit_of_file,*leave_cursor;
short direction;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
unsigned short y=0;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: calculate_scroll_values");
#endif
*limit_of_screen = *limit_of_file = FALSE;
*number_focus_rows = 0;
*new_focus_line = (-1L);
y = CURRENT_SCREEN.rows[WINDOW_FILEAREA];
switch(direction)
{
case DIRECTION_FORWARD:
/*---------------------------------------------------------------------*/
/* Determine the new focus line and the number of rows to adjust the */
/* cursor position. */
/*---------------------------------------------------------------------*/
for (i=0;i<CURRENT_SCREEN.rows[WINDOW_FILEAREA];i++)
{
if (CURRENT_SCREEN.sl[i].line_number == CURRENT_VIEW->focus_line)
{
y = i;
continue;
}
if (CURRENT_SCREEN.sl[i].line_number != (-1L)
&& y != CURRENT_SCREEN.rows[WINDOW_FILEAREA])
{
*number_focus_rows = i-y;
*new_focus_line = CURRENT_SCREEN.sl[i].line_number;
break;
}
}
/*---------------------------------------------------------------------*/
/* If we have NOT set a new focus line (because we are on the bottom */
/* of the screen) the new focus line is the next line in scope (if */
/* SHADOW is OFF). If SHADOW is ON, the new focus line is determined by*/
/* the status of the current focus line. */
/*---------------------------------------------------------------------*/
if (*new_focus_line == (-1L))
{
if (CURRENT_VIEW->shadow)
{
*new_focus_line = CURRENT_SCREEN.sl[y].line_number +
((CURRENT_SCREEN.sl[y].number_lines_excluded == 0) ?
1L :
(LINETYPE)CURRENT_SCREEN.sl[y].number_lines_excluded);
}
else
{
if (CURRENT_SCREEN.sl[y].current->next != NULL)
*new_focus_line = find_next_in_scope(CURRENT_VIEW,CURRENT_SCREEN.sl[y].current->next,
CURRENT_SCREEN.sl[y].line_number+1L,direction);
}
}
/*---------------------------------------------------------------------*/
/* Determine the new current line and the number of rows to adjust the */
/* cursor position. */
/*---------------------------------------------------------------------*/
*leave_cursor = TRUE;
*new_current_line = (-1L);
for (i=CURRENT_VIEW->current_row+1;i<CURRENT_SCREEN.rows[WINDOW_FILEAREA];i++)
{
if (CURRENT_SCREEN.sl[i].line_type == LINE_LINE
|| CURRENT_SCREEN.sl[i].line_type == LINE_TOF /* MH12 */
|| CURRENT_SCREEN.sl[i].line_type == LINE_EOF) /* MH12 */
{
*new_current_line = CURRENT_SCREEN.sl[i].line_number;
break;
}
if (CURRENT_SCREEN.sl[i].line_type == LINE_SHADOW)
*leave_cursor = FALSE;
}
/*---------------------------------------------------------------------*/
/* If we have NOT set a new current line (only way this can happen is */
/* if all lines after the current line are RESERVED, SCALE or TABLINE) */
/* and the cursor is on the current line) the new current line is the */
/* next line in scope. */
/*---------------------------------------------------------------------*/
if (*new_current_line == (-1L))
{
if (CURRENT_SCREEN.sl[y].current->next != NULL)
*new_current_line = find_next_in_scope(CURRENT_VIEW,CURRENT_SCREEN.sl[y].current->next,
CURRENT_SCREEN.sl[y].line_number+1L,direction);
}
/*---------------------------------------------------------------------*/
/* Set flags for bottom_of_screen and bottom_of_file as appropriate. */
/*---------------------------------------------------------------------*/
if (*number_focus_rows == 0)
*limit_of_screen = TRUE;
/* if (CURRENT_SCREEN.sl[y].line_type == LINE_TOF_EOF MH12 */
/* && CURRENT_SCREEN.sl[y].current->next == NULL) MH12 */
if (CURRENT_SCREEN.sl[y].line_type == LINE_EOF)
*limit_of_file = TRUE;
break;
case DIRECTION_BACKWARD:
/*---------------------------------------------------------------------*/
/* Determine the new focus line and the number of rows to adjust the */
/* cursor position. */
/*---------------------------------------------------------------------*/
for (i=CURRENT_SCREEN.rows[WINDOW_FILEAREA]-1;i>-1;i--)
{
if (CURRENT_SCREEN.sl[i].line_number == CURRENT_VIEW->focus_line)
{
y = i;
continue;
}
if (CURRENT_SCREEN.sl[i].line_number != (-1L)
&& y != CURRENT_SCREEN.rows[WINDOW_FILEAREA])
{
*number_focus_rows = y-i;
*new_focus_line = CURRENT_SCREEN.sl[i].line_number;
break;
}
}
/*---------------------------------------------------------------------*/
/* If we have NOT set a new focus line (because we are on the top */
/* of the screen) the new focus line is the prev line in scope (if */
/* SHADOW is OFF). If SHADOW is ON, the new focus line is determined by*/
/* the status of the current focus line. */
/*---------------------------------------------------------------------*/
if (*new_focus_line == (-1L))
{
if (CURRENT_VIEW->shadow)
{
if (CURRENT_SCREEN.sl[y].line_type == LINE_SHADOW)
*new_focus_line = CURRENT_SCREEN.sl[y].line_number - 1L;
else
{
if (CURRENT_SCREEN.sl[y].current->prev != NULL)
{
*new_focus_line = find_next_in_scope(CURRENT_VIEW,CURRENT_SCREEN.sl[y].current->prev,
CURRENT_SCREEN.sl[y].line_number-1L,direction);
if (*new_focus_line != CURRENT_SCREEN.sl[y].line_number-1L)
*new_focus_line = *new_focus_line + 1;
}
}
}
else
{
if (CURRENT_SCREEN.sl[y].current->prev != NULL)
*new_focus_line = find_next_in_scope(CURRENT_VIEW,CURRENT_SCREEN.sl[y].current->prev,
CURRENT_SCREEN.sl[y].line_number-1L,direction);
}
}
/*---------------------------------------------------------------------*/
/* Determine the new current line and the number of rows to adjust the */
/* cursor position. */
/*---------------------------------------------------------------------*/
*leave_cursor = TRUE;
*new_current_line = (-1L);
for (i=CURRENT_VIEW->current_row-1;i>-1;i--)
{
if (CURRENT_SCREEN.sl[i].line_type == LINE_LINE
|| CURRENT_SCREEN.sl[i].line_type == LINE_TOF /* MH12 */
|| CURRENT_SCREEN.sl[i].line_type == LINE_EOF) /* MH12 */
{
*new_current_line = CURRENT_SCREEN.sl[i].line_number;
break;
}
if (CURRENT_SCREEN.sl[i].line_type == LINE_SHADOW)
*leave_cursor = FALSE;
}
/*---------------------------------------------------------------------*/
/* If we have NOT set a new current line (only way this can happen is */
/* if all lines before the current line are RESERVED, SCALE or TABLINE)*/
/* and the cursor is on the current line) the new current line is the */
/* previous line in scope. */
/*---------------------------------------------------------------------*/
if (*new_current_line == (-1L))
{
if (CURRENT_SCREEN.sl[y].current->prev != NULL)
*new_current_line = find_next_in_scope(CURRENT_VIEW,CURRENT_SCREEN.sl[y].current->prev,
CURRENT_SCREEN.sl[y].line_number-1L,direction);
}
/*---------------------------------------------------------------------*/
/* Set flags for top_of_screen and top_of_file as appropriate. */
/*---------------------------------------------------------------------*/
if (*number_focus_rows == 0)
*limit_of_screen = TRUE;
/* if (CURRENT_SCREEN.sl[y].line_type == LINE_TOF_EOF MH12 */
/* && CURRENT_SCREEN.sl[y].current->prev == NULL) MH12 */
if (CURRENT_SCREEN.sl[y].line_type == LINE_TOF)
*limit_of_file = TRUE;
break;
}
#ifdef THE_TRACE
trace_return();
#endif
return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
short find_last_focus_line(unsigned short *newrow)
#else
short find_last_focus_line(newrow)
unsigned short *newrow;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
short row=(-1);
short rc=RC_OK;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: find_last_focus_line");
#endif
for (i=CURRENT_SCREEN.rows[WINDOW_FILEAREA]-1;i>-1;i--)
{
if (CURRENT_SCREEN.sl[i].line_number != (-1L))
{
*newrow = row = i;
break;
}
}
if (row == (-1))
rc = RC_INVALID_OPERAND;
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short find_first_focus_line(unsigned short *newrow)
#else
short find_first_focus_line(newrow)
unsigned short *newrow;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
short row=(-1);
short rc=RC_OK;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: find_first_focus_line");
#endif
for (i=0;i<CURRENT_SCREEN.rows[WINDOW_FILEAREA];i++)
{
if (CURRENT_SCREEN.sl[i].line_number != (-1L))
{
*newrow = row = i;
break;
}
}
if (row == (-1))
rc = RC_INVALID_OPERAND;
#ifdef THE_TRACE
trace_return();
#endif
return(rc);
}
/***********************************************************************/
#ifdef HAVE_PROTO
CHARTYPE find_unique_char(CHARTYPE *str)
#else
CHARTYPE find_unique_char(str)
CHARTYPE *str;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
register short i=0;
/*--------------------------- processing ------------------------------*/
#ifdef THE_TRACE
trace_function("target.c: find_unique_char");
#endif
for (i=254;i>0;i--)
{
if (strzeq(str,(CHARTYPE)i) == (-1))
{
#ifdef THE_TRACE
trace_return();
#endif
return((CHARTYPE)i);
}
}
#ifdef THE_TRACE
trace_return();
#endif
return(0);
}
|