aboutsummaryrefslogtreecommitdiffstats
path: root/src/syntax.c
diff options
context:
space:
mode:
authorKenichi Handa2000-09-28 01:42:31 +0000
committerKenichi Handa2000-09-28 01:42:31 +0000
commit9690d0263a5d95ddfff437dcef032db829e0a88f (patch)
tree5972da53ab8a37b354b17488dd293078a37fc265 /src/syntax.c
parent8610d90393d4756e649e080738af4cf33d7f1ec1 (diff)
downloademacs-9690d0263a5d95ddfff437dcef032db829e0a88f.tar.gz
emacs-9690d0263a5d95ddfff437dcef032db829e0a88f.zip
(skip_chars): Handle negation correctly.
Diffstat (limited to 'src/syntax.c')
-rw-r--r--src/syntax.c79
1 files changed, 30 insertions, 49 deletions
diff --git a/src/syntax.c b/src/syntax.c
index 189e50d0963..1b3f9fc9dc3 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -1346,12 +1346,8 @@ skip_chars (forwardp, syntaxp, string, lim)
1346 register int ch; 1346 register int ch;
1347 unsigned char fastmap[0400]; 1347 unsigned char fastmap[0400];
1348 /* If SYNTAXP is 0, STRING may contain multi-byte form of characters 1348 /* If SYNTAXP is 0, STRING may contain multi-byte form of characters
1349 of which codes don't fit in FASTMAP. In that case, we set the 1349 of which codes don't fit in FASTMAP. In that case, set the
1350 first byte of multibyte form (i.e. base leading-code) in FASTMAP 1350 ranges of characters in CHAR_RANGES. */
1351 and set the actual ranges of characters in CHAR_RANGES. In the
1352 form "X-Y" of STRING, both X and Y must belong to the same
1353 character set because a range striding across character sets is
1354 meaningless. */
1355 int *char_ranges; 1351 int *char_ranges;
1356 int n_char_ranges = 0; 1352 int n_char_ranges = 0;
1357 int negate = 0; 1353 int negate = 0;
@@ -1414,8 +1410,6 @@ skip_chars (forwardp, syntaxp, string, lim)
1414 1410
1415 while (i_byte < size_byte) 1411 while (i_byte < size_byte)
1416 { 1412 {
1417 int c_leading_code = str[i_byte];
1418
1419 c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte - i_byte, len); 1413 c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte - i_byte, len);
1420 i_byte += len; 1414 i_byte += len;
1421 1415
@@ -1428,14 +1422,13 @@ skip_chars (forwardp, syntaxp, string, lim)
1428 if (i_byte == size_byte) 1422 if (i_byte == size_byte)
1429 break; 1423 break;
1430 1424
1431 c_leading_code = str[i_byte];
1432 c = STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len); 1425 c = STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len);
1433 i_byte += len; 1426 i_byte += len;
1434 } 1427 }
1435 if (i_byte < size_byte 1428 if (i_byte < size_byte
1436 && str[i_byte] == '-') 1429 && str[i_byte] == '-')
1437 { 1430 {
1438 unsigned int c2, c2_leading_code; 1431 unsigned int c2;
1439 1432
1440 /* Skip over the dash. */ 1433 /* Skip over the dash. */
1441 i_byte++; 1434 i_byte++;
@@ -1444,7 +1437,6 @@ skip_chars (forwardp, syntaxp, string, lim)
1444 break; 1437 break;
1445 1438
1446 /* Get the end of the range. */ 1439 /* Get the end of the range. */
1447 c2_leading_code = str[i_byte];
1448 c2 =STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len); 1440 c2 =STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len);
1449 i_byte += len; 1441 i_byte += len;
1450 1442
@@ -1460,7 +1452,6 @@ skip_chars (forwardp, syntaxp, string, lim)
1460 int charset = CHAR_CHARSET (c2); 1452 int charset = CHAR_CHARSET (c2);
1461 int c1 = MAKE_CHAR (charset, 0, 0); 1453 int c1 = MAKE_CHAR (charset, 0, 0);
1462 1454
1463 fastmap[c2_leading_code] = 1;
1464 char_ranges[n_char_ranges++] = c1; 1455 char_ranges[n_char_ranges++] = c1;
1465 char_ranges[n_char_ranges++] = c2; 1456 char_ranges[n_char_ranges++] = c2;
1466 c2 = 0237; 1457 c2 = 0237;
@@ -1471,17 +1462,10 @@ skip_chars (forwardp, syntaxp, string, lim)
1471 c++; 1462 c++;
1472 } 1463 }
1473 } 1464 }
1474 else if (! SINGLE_BYTE_CHAR_P (c2)) 1465 else if (c <= c2) /* Both C and C2 are multibyte char. */
1475 { 1466 {
1476 if (c_leading_code != c2_leading_code) 1467 char_ranges[n_char_ranges++] = c;
1477 error ("Invalid character range: %s", 1468 char_ranges[n_char_ranges++] = c2;
1478 XSTRING (string)->data);
1479 if (c <= c2)
1480 {
1481 fastmap[c_leading_code] = 1;
1482 char_ranges[n_char_ranges++] = c;
1483 char_ranges[n_char_ranges++] = c2;
1484 }
1485 } 1469 }
1486 } 1470 }
1487 else 1471 else
@@ -1490,7 +1474,6 @@ skip_chars (forwardp, syntaxp, string, lim)
1490 fastmap[c] = 1; 1474 fastmap[c] = 1;
1491 else 1475 else
1492 { 1476 {
1493 fastmap[c_leading_code] = 1;
1494 char_ranges[n_char_ranges++] = c; 1477 char_ranges[n_char_ranges++] = c;
1495 char_ranges[n_char_ranges++] = c; 1478 char_ranges[n_char_ranges++] = c;
1496 } 1479 }
@@ -1498,19 +1481,10 @@ skip_chars (forwardp, syntaxp, string, lim)
1498 } 1481 }
1499 } 1482 }
1500 1483
1501 /* If ^ was the first character, complement the fastmap. In 1484 /* If ^ was the first character, complement the fastmap. */
1502 addition, as all multibyte characters have possibility of
1503 matching, set all entries for base leading codes, which is
1504 harmless even if SYNTAXP is 1. */
1505
1506 if (negate) 1485 if (negate)
1507 for (i = 0; i < sizeof fastmap; i++) 1486 for (i = 0; i < sizeof fastmap; i++)
1508 { 1487 fastmap[i] ^= 1;
1509 if (!multibyte || !BASE_LEADING_CODE_P (i))
1510 fastmap[i] ^= 1;
1511 else
1512 fastmap[i] = 1;
1513 }
1514 1488
1515 { 1489 {
1516 int start_point = PT; 1490 int start_point = PT;
@@ -1585,16 +1559,22 @@ skip_chars (forwardp, syntaxp, string, lim)
1585 if (forwardp) 1559 if (forwardp)
1586 { 1560 {
1587 if (multibyte) 1561 if (multibyte)
1588 while (pos < XINT (lim) && fastmap[(c = FETCH_BYTE (pos_byte))]) 1562 while (pos < XINT (lim))
1589 { 1563 {
1590 /* If we are looking at a multibyte character, we 1564 c = FETCH_MULTIBYTE_CHAR (pos_byte);
1591 must look up the character in the table 1565 if (SINGLE_BYTE_CHAR_P (c))
1592 CHAR_RANGES. If there's no data in the table, 1566 {
1593 that character is not what we want to skip. */ 1567 if (!fastmap[c])
1594 if (BASE_LEADING_CODE_P (c) 1568 break;
1595 && (c = FETCH_MULTIBYTE_CHAR (pos_byte), 1569 }
1596 ! SINGLE_BYTE_CHAR_P (c))) 1570 else
1597 { 1571 {
1572 /* If we are looking at a multibyte character,
1573 we must look up the character in the table
1574 CHAR_RANGES. If there's no data in the
1575 table, that character is not what we want to
1576 skip. */
1577
1598 /* The following code do the right thing even if 1578 /* The following code do the right thing even if
1599 n_char_ranges is zero (i.e. no data in 1579 n_char_ranges is zero (i.e. no data in
1600 CHAR_RANGES). */ 1580 CHAR_RANGES). */
@@ -1618,14 +1598,15 @@ skip_chars (forwardp, syntaxp, string, lim)
1618 int prev_pos_byte = pos_byte; 1598 int prev_pos_byte = pos_byte;
1619 1599
1620 DEC_POS (prev_pos_byte); 1600 DEC_POS (prev_pos_byte);
1621 if (!fastmap[(c = FETCH_BYTE (prev_pos_byte))]) 1601 c = FETCH_MULTIBYTE_CHAR (prev_pos_byte);
1622 break; 1602 if (SINGLE_BYTE_CHAR_P (c))
1623 1603 {
1624 /* See the comment in the previous similar code. */ 1604 if (!fastmap[c])
1625 if (BASE_LEADING_CODE_P (c) 1605 break;
1626 && (c = FETCH_MULTIBYTE_CHAR (prev_pos_byte), 1606 }
1627 ! SINGLE_BYTE_CHAR_P (c))) 1607 else
1628 { 1608 {
1609 /* See the comment in the previous similar code. */
1629 for (i = 0; i < n_char_ranges; i += 2) 1610 for (i = 0; i < n_char_ranges; i += 2)
1630 if (c >= char_ranges[i] && c <= char_ranges[i + 1]) 1611 if (c >= char_ranges[i] && c <= char_ranges[i + 1])
1631 break; 1612 break;