aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2001-12-30 03:24:17 +0000
committerRichard M. Stallman2001-12-30 03:24:17 +0000
commitf6f79b37f89c323e9b1d7ae1cda26aa46e2058f2 (patch)
tree51a86457dc158384bfcc9d183b59ed9e2d7d57e2
parentdb300f594401cebc32b18e2e9a04d0ed93747340 (diff)
downloademacs-f6f79b37f89c323e9b1d7ae1cda26aa46e2058f2.tar.gz
emacs-f6f79b37f89c323e9b1d7ae1cda26aa46e2058f2.zip
(read_escape): New arg BYTEREP for reporting whether
escape forces unibyte or multibyte. (read1): When reading a string, take note of that info.
-rw-r--r--src/lread.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/lread.c b/src/lread.c
index 824e34ae47b..758105d16f8 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1503,14 +1503,21 @@ read_multibyte (c, readcharfun)
1503 return str[0]; 1503 return str[0];
1504} 1504}
1505 1505
1506/* Read a \-escape sequence, assuming we already read the `\'. */ 1506/* Read a \-escape sequence, assuming we already read the `\'.
1507 If the escape sequence forces unibyte, store 1 into *BYTEREP.
1508 If the escape sequence forces multibyte, store 2 into *BYTEREP.
1509 Otherwise store 0 into *BYTEREP. */
1507 1510
1508static int 1511static int
1509read_escape (readcharfun, stringp) 1512read_escape (readcharfun, stringp, byterep)
1510 Lisp_Object readcharfun; 1513 Lisp_Object readcharfun;
1511 int stringp; 1514 int stringp;
1515 int *byterep;
1512{ 1516{
1513 register int c = READCHAR; 1517 register int c = READCHAR;
1518
1519 *byterep = 0;
1520
1514 switch (c) 1521 switch (c)
1515 { 1522 {
1516 case -1: 1523 case -1:
@@ -1547,7 +1554,7 @@ read_escape (readcharfun, stringp)
1547 error ("Invalid escape character syntax"); 1554 error ("Invalid escape character syntax");
1548 c = READCHAR; 1555 c = READCHAR;
1549 if (c == '\\') 1556 if (c == '\\')
1550 c = read_escape (readcharfun, 0); 1557 c = read_escape (readcharfun, 0, byterep);
1551 return c | meta_modifier; 1558 return c | meta_modifier;
1552 1559
1553 case 'S': 1560 case 'S':
@@ -1556,7 +1563,7 @@ read_escape (readcharfun, stringp)
1556 error ("Invalid escape character syntax"); 1563 error ("Invalid escape character syntax");
1557 c = READCHAR; 1564 c = READCHAR;
1558 if (c == '\\') 1565 if (c == '\\')
1559 c = read_escape (readcharfun, 0); 1566 c = read_escape (readcharfun, 0, byterep);
1560 return c | shift_modifier; 1567 return c | shift_modifier;
1561 1568
1562 case 'H': 1569 case 'H':
@@ -1565,7 +1572,7 @@ read_escape (readcharfun, stringp)
1565 error ("Invalid escape character syntax"); 1572 error ("Invalid escape character syntax");
1566 c = READCHAR; 1573 c = READCHAR;
1567 if (c == '\\') 1574 if (c == '\\')
1568 c = read_escape (readcharfun, 0); 1575 c = read_escape (readcharfun, 0, byterep);
1569 return c | hyper_modifier; 1576 return c | hyper_modifier;
1570 1577
1571 case 'A': 1578 case 'A':
@@ -1574,7 +1581,7 @@ read_escape (readcharfun, stringp)
1574 error ("Invalid escape character syntax"); 1581 error ("Invalid escape character syntax");
1575 c = READCHAR; 1582 c = READCHAR;
1576 if (c == '\\') 1583 if (c == '\\')
1577 c = read_escape (readcharfun, 0); 1584 c = read_escape (readcharfun, 0, byterep);
1578 return c | alt_modifier; 1585 return c | alt_modifier;
1579 1586
1580 case 's': 1587 case 's':
@@ -1583,7 +1590,7 @@ read_escape (readcharfun, stringp)
1583 error ("Invalid escape character syntax"); 1590 error ("Invalid escape character syntax");
1584 c = READCHAR; 1591 c = READCHAR;
1585 if (c == '\\') 1592 if (c == '\\')
1586 c = read_escape (readcharfun, 0); 1593 c = read_escape (readcharfun, 0, byterep);
1587 return c | super_modifier; 1594 return c | super_modifier;
1588 1595
1589 case 'C': 1596 case 'C':
@@ -1593,7 +1600,7 @@ read_escape (readcharfun, stringp)
1593 case '^': 1600 case '^':
1594 c = READCHAR; 1601 c = READCHAR;
1595 if (c == '\\') 1602 if (c == '\\')
1596 c = read_escape (readcharfun, 0); 1603 c = read_escape (readcharfun, 0, byterep);
1597 if ((c & ~CHAR_MODIFIER_MASK) == '?') 1604 if ((c & ~CHAR_MODIFIER_MASK) == '?')
1598 return 0177 | (c & CHAR_MODIFIER_MASK); 1605 return 0177 | (c & CHAR_MODIFIER_MASK);
1599 else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))) 1606 else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
@@ -1632,6 +1639,8 @@ read_escape (readcharfun, stringp)
1632 break; 1639 break;
1633 } 1640 }
1634 } 1641 }
1642
1643 *byterep = 1;
1635 return i; 1644 return i;
1636 } 1645 }
1637 1646
@@ -1662,6 +1671,8 @@ read_escape (readcharfun, stringp)
1662 break; 1671 break;
1663 } 1672 }
1664 } 1673 }
1674
1675 *byterep = 2;
1665 return i; 1676 return i;
1666 } 1677 }
1667 1678
@@ -2115,12 +2126,14 @@ read1 (readcharfun, pch, first_in_list)
2115 2126
2116 case '?': 2127 case '?':
2117 { 2128 {
2129 int discard;
2130
2118 c = READCHAR; 2131 c = READCHAR;
2119 if (c < 0) 2132 if (c < 0)
2120 end_of_file_error (); 2133 end_of_file_error ();
2121 2134
2122 if (c == '\\') 2135 if (c == '\\')
2123 c = read_escape (readcharfun, 0); 2136 c = read_escape (readcharfun, 0, &discard);
2124 else if (BASE_LEADING_CODE_P (c)) 2137 else if (BASE_LEADING_CODE_P (c))
2125 c = read_multibyte (c, readcharfun); 2138 c = read_multibyte (c, readcharfun);
2126 2139
@@ -2155,7 +2168,9 @@ read1 (readcharfun, pch, first_in_list)
2155 2168
2156 if (c == '\\') 2169 if (c == '\\')
2157 { 2170 {
2158 c = read_escape (readcharfun, 1); 2171 int byterep;
2172
2173 c = read_escape (readcharfun, 1, &byterep);
2159 2174
2160 /* C is -1 if \ newline has just been seen */ 2175 /* C is -1 if \ newline has just been seen */
2161 if (c == -1) 2176 if (c == -1)
@@ -2165,11 +2180,10 @@ read1 (readcharfun, pch, first_in_list)
2165 continue; 2180 continue;
2166 } 2181 }
2167 2182
2168 /* If an escape specifies a non-ASCII single-byte character, 2183 if (byterep == 1)
2169 this must be a unibyte string. */
2170 if (SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))
2171 && ! ASCII_BYTE_P ((c & ~CHAR_MODIFIER_MASK)))
2172 force_singlebyte = 1; 2184 force_singlebyte = 1;
2185 else if (byterep == 2)
2186 force_multibyte = 1;
2173 } 2187 }
2174 2188
2175 if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))) 2189 if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))