aboutsummaryrefslogtreecommitdiffstats
path: root/src/lread.c
diff options
context:
space:
mode:
authorRichard M. Stallman1998-05-16 18:30:00 +0000
committerRichard M. Stallman1998-05-16 18:30:00 +0000
commit00a9a93524237a78dd6996614cc3c7140cae6f30 (patch)
tree1b8f8765a7ecbb04d3b25b8784dce33db6f00dd8 /src/lread.c
parent26174ef4fe149cc46484a7d985b5df7531fe3435 (diff)
downloademacs-00a9a93524237a78dd6996614cc3c7140cae6f30.tar.gz
emacs-00a9a93524237a78dd6996614cc3c7140cae6f30.zip
(readchar): Use readchar_backlog again
to read a character byte by byte, if its byte sequence does not really match the character code. (unreadchar): Handle readchar_backlog. (readevalloop, Fread): Initialize readchar_backlog to -1.
Diffstat (limited to 'src/lread.c')
-rw-r--r--src/lread.c100
1 files changed, 87 insertions, 13 deletions
diff --git a/src/lread.c b/src/lread.c
index 00d93192f30..3eb56a2c35a 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -183,14 +183,46 @@ readchar (readcharfun)
183 int pt_byte = BUF_PT_BYTE (inbuffer); 183 int pt_byte = BUF_PT_BYTE (inbuffer);
184 int orig_pt_byte = pt_byte; 184 int orig_pt_byte = pt_byte;
185 185
186 if (readchar_backlog > 0)
187 /* We get the address of the byte just passed,
188 which is the last byte of the character.
189 The other bytes in this character are consecutive with it,
190 because the gap can't be in the middle of a character. */
191 return *(BUF_BYTE_ADDRESS (inbuffer, BUF_PT_BYTE (inbuffer) - 1)
192 - --readchar_backlog);
193
186 if (pt_byte >= BUF_ZV_BYTE (inbuffer)) 194 if (pt_byte >= BUF_ZV_BYTE (inbuffer))
187 return -1; 195 return -1;
188 196
197 readchar_backlog = -1;
198
189 if (! NILP (inbuffer->enable_multibyte_characters)) 199 if (! NILP (inbuffer->enable_multibyte_characters))
190 { 200 {
201 unsigned char workbuf[4];
202 unsigned char *str = workbuf;
203 int length;
204
205 /* Fetch the character code from the buffer. */
191 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte); 206 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte);
192 BUF_INC_POS (inbuffer, pt_byte); 207 BUF_INC_POS (inbuffer, pt_byte);
193 c = STRING_CHAR (p, pt_byte - orig_pt_byte); 208 c = STRING_CHAR (p, pt_byte - orig_pt_byte);
209
210 /* Find the byte-sequence representation of that character. */
211 if (SINGLE_BYTE_CHAR_P (c))
212 length = 1, workbuf[0] = c;
213 else
214 length = non_ascii_char_to_string (c, workbuf, &str);
215
216 /* If the bytes for this character in the buffer
217 are not identical with what the character code implies,
218 read the bytes one by one from the buffer. */
219 if (length != pt_byte - orig_pt_byte
220 || (length == 1 ? *str != *p : bcmp (str, p, length)))
221 {
222 readchar_backlog = pt_byte - orig_pt_byte;
223 c = BUF_FETCH_BYTE (inbuffer, orig_pt_byte);
224 readchar_backlog--;
225 }
194 } 226 }
195 else 227 else
196 { 228 {
@@ -208,14 +240,46 @@ readchar (readcharfun)
208 int bytepos = marker_byte_position (readcharfun); 240 int bytepos = marker_byte_position (readcharfun);
209 int orig_bytepos = bytepos; 241 int orig_bytepos = bytepos;
210 242
243 if (readchar_backlog > 0)
244 /* We get the address of the byte just passed,
245 which is the last byte of the character.
246 The other bytes in this character are consecutive with it,
247 because the gap can't be in the middle of a character. */
248 return *(BUF_BYTE_ADDRESS (inbuffer, XMARKER (readcharfun)->bytepos - 1)
249 - --readchar_backlog);
250
211 if (bytepos >= BUF_ZV_BYTE (inbuffer)) 251 if (bytepos >= BUF_ZV_BYTE (inbuffer))
212 return -1; 252 return -1;
213 253
254 readchar_backlog = -1;
255
214 if (! NILP (inbuffer->enable_multibyte_characters)) 256 if (! NILP (inbuffer->enable_multibyte_characters))
215 { 257 {
258 unsigned char workbuf[4];
259 unsigned char *str = workbuf;
260 int length;
261
262 /* Fetch the character code from the buffer. */
216 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos); 263 unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos);
217 BUF_INC_POS (inbuffer, bytepos); 264 BUF_INC_POS (inbuffer, bytepos);
218 c = STRING_CHAR (p, bytepos - orig_bytepos); 265 c = STRING_CHAR (p, bytepos - orig_bytepos);
266
267 /* Find the byte-sequence representation of that character. */
268 if (SINGLE_BYTE_CHAR_P (c))
269 length = 1, workbuf[0] = c;
270 else
271 length = non_ascii_char_to_string (c, workbuf, &str);
272
273 /* If the bytes for this character in the buffer
274 are not identical with what the character code implies,
275 read the bytes one by one from the buffer. */
276 if (length != bytepos - orig_bytepos
277 || (length == 1 ? *str != *p : bcmp (str, p, length)))
278 {
279 readchar_backlog = bytepos - orig_bytepos;
280 c = BUF_FETCH_BYTE (inbuffer, orig_bytepos);
281 readchar_backlog--;
282 }
219 } 283 }
220 else 284 else
221 { 285 {
@@ -280,26 +344,36 @@ unreadchar (readcharfun, c)
280 struct buffer *b = XBUFFER (readcharfun); 344 struct buffer *b = XBUFFER (readcharfun);
281 int bytepos = BUF_PT_BYTE (b); 345 int bytepos = BUF_PT_BYTE (b);
282 346
283 BUF_PT (b)--; 347 if (readchar_backlog >= 0)
284 if (! NILP (b->enable_multibyte_characters)) 348 readchar_backlog++;
285 BUF_DEC_POS (b, bytepos);
286 else 349 else
287 bytepos--; 350 {
351 BUF_PT (b)--;
352 if (! NILP (b->enable_multibyte_characters))
353 BUF_DEC_POS (b, bytepos);
354 else
355 bytepos--;
288 356
289 BUF_PT_BYTE (b) = bytepos; 357 BUF_PT_BYTE (b) = bytepos;
358 }
290 } 359 }
291 else if (MARKERP (readcharfun)) 360 else if (MARKERP (readcharfun))
292 { 361 {
293 struct buffer *b = XMARKER (readcharfun)->buffer; 362 struct buffer *b = XMARKER (readcharfun)->buffer;
294 int bytepos = XMARKER (readcharfun)->bytepos; 363 int bytepos = XMARKER (readcharfun)->bytepos;
295 364
296 XMARKER (readcharfun)->charpos--; 365 if (readchar_backlog >= 0)
297 if (! NILP (b->enable_multibyte_characters)) 366 readchar_backlog++;
298 BUF_DEC_POS (b, bytepos);
299 else 367 else
300 bytepos--; 368 {
369 XMARKER (readcharfun)->charpos--;
370 if (! NILP (b->enable_multibyte_characters))
371 BUF_DEC_POS (b, bytepos);
372 else
373 bytepos--;
301 374
302 XMARKER (readcharfun)->bytepos = bytepos; 375 XMARKER (readcharfun)->bytepos = bytepos;
376 }
303 } 377 }
304 else if (STRINGP (readcharfun)) 378 else if (STRINGP (readcharfun))
305 { 379 {
@@ -959,7 +1033,7 @@ readevalloop (readcharfun, stream, sourcename, evalfun, printflag, unibyte)
959 record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil); 1033 record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil);
960 load_convert_to_unibyte = !NILP (unibyte); 1034 load_convert_to_unibyte = !NILP (unibyte);
961 1035
962 readchar_backlog = 0; 1036 readchar_backlog = -1;
963 1037
964 GCPRO1 (sourcename); 1038 GCPRO1 (sourcename);
965 1039
@@ -1147,7 +1221,7 @@ STREAM or the value of `standard-input' may be:\n\
1147 if (EQ (stream, Qt)) 1221 if (EQ (stream, Qt))
1148 stream = Qread_char; 1222 stream = Qread_char;
1149 1223
1150 readchar_backlog = 0; 1224 readchar_backlog = -1;
1151 new_backquote_flag = 0; 1225 new_backquote_flag = 0;
1152 read_objects = Qnil; 1226 read_objects = Qnil;
1153 1227
@@ -1726,7 +1800,7 @@ read1 (readcharfun, pch, first_in_list)
1726 return make_number (c); 1800 return make_number (c);
1727 } 1801 }
1728 1802
1729 case '\"': 1803 case '"':
1730 { 1804 {
1731 register char *p = read_buffer; 1805 register char *p = read_buffer;
1732 register char *end = read_buffer + read_buffer_size; 1806 register char *end = read_buffer + read_buffer_size;