aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKarl Heuer1998-01-18 04:49:11 +0000
committerKarl Heuer1998-01-18 04:49:11 +0000
commite7fc914b0244b9b7488a0e4160210b76f4dc918e (patch)
treec6598efc31a820947edb049a6ca51af557c8a353 /src
parentc52d78d521b1a203423011b064a00a004e85e479 (diff)
downloademacs-e7fc914b0244b9b7488a0e4160210b76f4dc918e.tar.gz
emacs-e7fc914b0244b9b7488a0e4160210b76f4dc918e.zip
(read1): Escape codes can force multibyte or single-byte.
Otherwise buffer_defaults->enable_multibyte_characters decides. Only set force_singlebyte when a \-sequence is in the relevant range. (read_escape): New arg STRINGP. `\ ' is ignored only when STRINGP (normally, when reading a string). Calls changed.
Diffstat (limited to 'src')
-rw-r--r--src/lread.c53
1 files changed, 37 insertions, 16 deletions
diff --git a/src/lread.c b/src/lread.c
index b882d7fc026..e69e3f86943 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1203,8 +1203,9 @@ read_multibyte (c, readcharfun)
1203/* Read a \-escape sequence, assuming we already read the `\'. */ 1203/* Read a \-escape sequence, assuming we already read the `\'. */
1204 1204
1205static int 1205static int
1206read_escape (readcharfun) 1206read_escape (readcharfun, stringp)
1207 Lisp_Object readcharfun; 1207 Lisp_Object readcharfun;
1208 int stringp;
1208{ 1209{
1209 register int c = READCHAR; 1210 register int c = READCHAR;
1210 switch (c) 1211 switch (c)
@@ -1233,7 +1234,9 @@ read_escape (readcharfun)
1233 case '\n': 1234 case '\n':
1234 return -1; 1235 return -1;
1235 case ' ': 1236 case ' ':
1236 return -1; 1237 if (stringp)
1238 return -1;
1239 return ' ';
1237 1240
1238 case 'M': 1241 case 'M':
1239 c = READCHAR; 1242 c = READCHAR;
@@ -1241,7 +1244,7 @@ read_escape (readcharfun)
1241 error ("Invalid escape character syntax"); 1244 error ("Invalid escape character syntax");
1242 c = READCHAR; 1245 c = READCHAR;
1243 if (c == '\\') 1246 if (c == '\\')
1244 c = read_escape (readcharfun); 1247 c = read_escape (readcharfun, 0);
1245 return c | meta_modifier; 1248 return c | meta_modifier;
1246 1249
1247 case 'S': 1250 case 'S':
@@ -1250,7 +1253,7 @@ read_escape (readcharfun)
1250 error ("Invalid escape character syntax"); 1253 error ("Invalid escape character syntax");
1251 c = READCHAR; 1254 c = READCHAR;
1252 if (c == '\\') 1255 if (c == '\\')
1253 c = read_escape (readcharfun); 1256 c = read_escape (readcharfun, 0);
1254 return c | shift_modifier; 1257 return c | shift_modifier;
1255 1258
1256 case 'H': 1259 case 'H':
@@ -1259,7 +1262,7 @@ read_escape (readcharfun)
1259 error ("Invalid escape character syntax"); 1262 error ("Invalid escape character syntax");
1260 c = READCHAR; 1263 c = READCHAR;
1261 if (c == '\\') 1264 if (c == '\\')
1262 c = read_escape (readcharfun); 1265 c = read_escape (readcharfun, 0);
1263 return c | hyper_modifier; 1266 return c | hyper_modifier;
1264 1267
1265 case 'A': 1268 case 'A':
@@ -1268,7 +1271,7 @@ read_escape (readcharfun)
1268 error ("Invalid escape character syntax"); 1271 error ("Invalid escape character syntax");
1269 c = READCHAR; 1272 c = READCHAR;
1270 if (c == '\\') 1273 if (c == '\\')
1271 c = read_escape (readcharfun); 1274 c = read_escape (readcharfun, 0);
1272 return c | alt_modifier; 1275 return c | alt_modifier;
1273 1276
1274 case 's': 1277 case 's':
@@ -1277,7 +1280,7 @@ read_escape (readcharfun)
1277 error ("Invalid escape character syntax"); 1280 error ("Invalid escape character syntax");
1278 c = READCHAR; 1281 c = READCHAR;
1279 if (c == '\\') 1282 if (c == '\\')
1280 c = read_escape (readcharfun); 1283 c = read_escape (readcharfun, 0);
1281 return c | super_modifier; 1284 return c | super_modifier;
1282 1285
1283 case 'C': 1286 case 'C':
@@ -1287,7 +1290,7 @@ read_escape (readcharfun)
1287 case '^': 1290 case '^':
1288 c = READCHAR; 1291 c = READCHAR;
1289 if (c == '\\') 1292 if (c == '\\')
1290 c = read_escape (readcharfun); 1293 c = read_escape (readcharfun, 0);
1291 if ((c & 0177) == '?') 1294 if ((c & 0177) == '?')
1292 return 0177 | c; 1295 return 0177 | c;
1293 /* ASCII control chars are made from letters (both cases), 1296 /* ASCII control chars are made from letters (both cases),
@@ -1662,7 +1665,7 @@ read1 (readcharfun, pch, first_in_list)
1662 if (c < 0) return Fsignal (Qend_of_file, Qnil); 1665 if (c < 0) return Fsignal (Qend_of_file, Qnil);
1663 1666
1664 if (c == '\\') 1667 if (c == '\\')
1665 c = read_escape (readcharfun); 1668 c = read_escape (readcharfun, 0);
1666 else if (BASE_LEADING_CODE_P (c)) 1669 else if (BASE_LEADING_CODE_P (c))
1667 c = read_multibyte (c, readcharfun); 1670 c = read_multibyte (c, readcharfun);
1668 1671
@@ -1674,7 +1677,14 @@ read1 (readcharfun, pch, first_in_list)
1674 register char *p = read_buffer; 1677 register char *p = read_buffer;
1675 register char *end = read_buffer + read_buffer_size; 1678 register char *end = read_buffer + read_buffer_size;
1676 register int c; 1679 register int c;
1680 /* Nonzero if we saw an escape sequence specifying
1681 a multibyte character. */
1682 int force_multibyte = 0;
1683 /* Nonzero if we saw an escape sequence specifying
1684 a single-byte character. */
1685 int force_singlebyte = 0;
1677 int cancel = 0; 1686 int cancel = 0;
1687 int nchars;
1678 1688
1679 while ((c = READCHAR) >= 0 1689 while ((c = READCHAR) >= 0
1680 && c != '\"') 1690 && c != '\"')
@@ -1688,7 +1698,7 @@ read1 (readcharfun, pch, first_in_list)
1688 } 1698 }
1689 if (c == '\\') 1699 if (c == '\\')
1690 { 1700 {
1691 c = read_escape (readcharfun); 1701 c = read_escape (readcharfun, 1);
1692 if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_META))) 1702 if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_META)))
1693 { 1703 {
1694 unsigned char workbuf[4]; 1704 unsigned char workbuf[4];
@@ -1696,6 +1706,8 @@ read1 (readcharfun, pch, first_in_list)
1696 int length; 1706 int length;
1697 1707
1698 length = non_ascii_char_to_string (c, workbuf, &str); 1708 length = non_ascii_char_to_string (c, workbuf, &str);
1709 if (length > 1)
1710 force_multibyte = 1;
1699 1711
1700 if (p + length > end) 1712 if (p + length > end)
1701 { 1713 {
@@ -1709,6 +1721,8 @@ read1 (readcharfun, pch, first_in_list)
1709 p += length; 1721 p += length;
1710 continue; 1722 continue;
1711 } 1723 }
1724 else if (! ASCII_BYTE_P (c))
1725 force_singlebyte = 1;
1712 } 1726 }
1713 1727
1714 /* c is -1 if \ newline has just been seen */ 1728 /* c is -1 if \ newline has just been seen */
@@ -1742,13 +1756,20 @@ read1 (readcharfun, pch, first_in_list)
1742 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel) 1756 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
1743 return make_number (0); 1757 return make_number (0);
1744 1758
1745 if (read_pure) 1759 if (force_singlebyte && force_multibyte)
1746 return make_pure_string (read_buffer, p - read_buffer, 1760 error ("Multibyte and single-byte escapes in one string constant");
1747 p - read_buffer); 1761
1748 else if (! NILP (current_buffer->enable_multibyte_characters)) 1762 if (force_singlebyte)
1749 return make_string (read_buffer, p - read_buffer); 1763 nchars = p - read_buffer;
1764 else if (! NILP (buffer_defaults.enable_multibyte_characters)
1765 || force_multibyte)
1766 nchars = chars_in_text (read_buffer, p - read_buffer);
1750 else 1767 else
1751 return make_unibyte_string (read_buffer, p - read_buffer); 1768 nchars = p - read_buffer;
1769
1770 if (read_pure)
1771 return make_pure_string (read_buffer, nchars, p - read_buffer);
1772 return make_multibyte_string (read_buffer, nchars, p - read_buffer);
1752 } 1773 }
1753 1774
1754 case '.': 1775 case '.':