comparison src/lread.c @ 20609:4bf29951648f

(read_escape): `\ ' stands for nothing at all. (oblookup): Take args SIZE and SIZE_BYTE. Callers changed. (init_obarray, read1, make_symbol): Pass new arg to make_pure_string. (Fintern, oblookup, Fintern_soft, intern): Handle size_byte. (dir_warning): Pass new arg to message_dolog. (read1): PCH is now int *. Declare ch as int. (read0): Declare c as int. (read_list): Declare ch as int. (read0): Use Fmake_string not make_string. (read1): When reading a string, maybe use make_unibyte_string. (Fread_from_string): Convert string indices to/from bytes.
author Richard M. Stallman <rms@gnu.org>
date Fri, 09 Jan 1998 22:52:08 +0000
parents 0877f6e6fc15
children fa76057543dd
comparison
equal deleted inserted replaced
20608:a6cca06d5aaf 20609:4bf29951648f
524 /* Make the progress messages mention that source is newer. */ 524 /* Make the progress messages mention that source is newer. */
525 newer = 1; 525 newer = 1;
526 526
527 /* If we won't print another message, mention this anyway. */ 527 /* If we won't print another message, mention this anyway. */
528 if (! NILP (nomessage)) 528 if (! NILP (nomessage))
529 message ("Source file `%s' newer than byte-compiled file", 529 message_with_string ("Source file `%s' newer than byte-compiled file",
530 XSTRING (found)->data); 530 found, 1);
531 } 531 }
532 XSTRING (found)->data[XSTRING (found)->size - 1] = 'c'; 532 XSTRING (found)->data[XSTRING (found)->size - 1] = 'c';
533 } 533 }
534 else 534 else
535 { 535 {
559 Vpreloaded_file_list = Fcons (file, Vpreloaded_file_list); 559 Vpreloaded_file_list = Fcons (file, Vpreloaded_file_list);
560 560
561 if (NILP (nomessage)) 561 if (NILP (nomessage))
562 { 562 {
563 if (!compiled) 563 if (!compiled)
564 message ("Loading %s (source)...", XSTRING (file)->data); 564 message_with_string ("Loading %s (source)...", file, 1);
565 else if (newer) 565 else if (newer)
566 message ("Loading %s (compiled; note, source file is newer)...", 566 message_with_string ("Loading %s (compiled; note, source file is newer)...",
567 XSTRING (file)->data); 567 file, 1);
568 else /* The typical case; compiled file newer than source file. */ 568 else /* The typical case; compiled file newer than source file. */
569 message ("Loading %s...", XSTRING (file)->data); 569 message_with_string ("Loading %s...", file, 1);
570 } 570 }
571 571
572 GCPRO1 (file); 572 GCPRO1 (file);
573 lispstream = Fcons (Qnil, Qnil); 573 lispstream = Fcons (Qnil, Qnil);
574 XSETFASTINT (XCONS (lispstream)->car, (EMACS_UINT)stream >> 16); 574 XSETFASTINT (XCONS (lispstream)->car, (EMACS_UINT)stream >> 16);
595 saved_doc_string_size = 0; 595 saved_doc_string_size = 0;
596 596
597 if (!noninteractive && NILP (nomessage)) 597 if (!noninteractive && NILP (nomessage))
598 { 598 {
599 if (!compiled) 599 if (!compiled)
600 message ("Loading %s (source)...done", XSTRING (file)->data); 600 message_with_string ("Loading %s (source)...done", file, 1);
601 else if (newer) 601 else if (newer)
602 message ("Loading %s (compiled; note, source file is newer)...done", 602 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
603 XSTRING (file)->data); 603 file, 1);
604 else /* The typical case; compiled file newer than source file. */ 604 else /* The typical case; compiled file newer than source file. */
605 message ("Loading %s...done", XSTRING (file)->data); 605 message_with_string ("Loading %s...done", file, 1);
606 } 606 }
607 return Qt; 607 return Qt;
608 } 608 }
609 609
610 static Lisp_Object 610 static Lisp_Object
1123 Lisp_Object tem; 1123 Lisp_Object tem;
1124 1124
1125 CHECK_STRING (string,0); 1125 CHECK_STRING (string,0);
1126 1126
1127 if (NILP (end)) 1127 if (NILP (end))
1128 endval = XSTRING (string)->size; 1128 endval = XSTRING (string)->size_byte;
1129 else 1129 else
1130 { CHECK_NUMBER (end,2); 1130 {
1131 endval = XINT (end); 1131 CHECK_NUMBER (end, 2);
1132 if (endval < 0 || endval > XSTRING (string)->size) 1132 endval = string_char_to_byte (string, XINT (end));
1133 if (endval < 0 || endval > XSTRING (string)->size_byte)
1133 args_out_of_range (string, end); 1134 args_out_of_range (string, end);
1134 } 1135 }
1135 1136
1136 if (NILP (start)) 1137 if (NILP (start))
1137 startval = 0; 1138 startval = 0;
1138 else 1139 else
1139 { CHECK_NUMBER (start,1); 1140 {
1140 startval = XINT (start); 1141 CHECK_NUMBER (start, 1);
1142 startval = string_char_to_byte (string, XINT (start));
1141 if (startval < 0 || startval > endval) 1143 if (startval < 0 || startval > endval)
1142 args_out_of_range (string, start); 1144 args_out_of_range (string, start);
1143 } 1145 }
1144 1146
1145 read_from_string_index = startval; 1147 read_from_string_index = startval;
1147 1149
1148 new_backquote_flag = 0; 1150 new_backquote_flag = 0;
1149 read_objects = Qnil; 1151 read_objects = Qnil;
1150 1152
1151 tem = read0 (string); 1153 tem = read0 (string);
1152 return Fcons (tem, make_number (read_from_string_index)); 1154 endval = string_byte_to_char (string,
1155 read_from_string_index);
1156 return Fcons (tem, make_number (endval));
1153 } 1157 }
1154 1158
1155 /* Use this for recursive reads, in contexts where internal tokens 1159 /* Use this for recursive reads, in contexts where internal tokens
1156 are not allowed. */ 1160 are not allowed. */
1161
1157 static Lisp_Object 1162 static Lisp_Object
1158 read0 (readcharfun) 1163 read0 (readcharfun)
1159 Lisp_Object readcharfun; 1164 Lisp_Object readcharfun;
1160 { 1165 {
1161 register Lisp_Object val; 1166 register Lisp_Object val;
1162 char c; 1167 int c;
1163 1168
1164 val = read1 (readcharfun, &c, 0); 1169 val = read1 (readcharfun, &c, 0);
1165 if (c) 1170 if (c)
1166 Fsignal (Qinvalid_read_syntax, Fcons (make_string (&c, 1), Qnil)); 1171 Fsignal (Qinvalid_read_syntax, Fcons (Fmake_string (make_number (c),
1172 make_number (1)),
1173 Qnil));
1167 1174
1168 return val; 1175 return val;
1169 } 1176 }
1170 1177
1171 static int read_buffer_size; 1178 static int read_buffer_size;
1222 case 't': 1229 case 't':
1223 return '\t'; 1230 return '\t';
1224 case 'v': 1231 case 'v':
1225 return '\v'; 1232 return '\v';
1226 case '\n': 1233 case '\n':
1234 return -1;
1235 case ' ':
1227 return -1; 1236 return -1;
1228 1237
1229 case 'M': 1238 case 'M':
1230 c = READCHAR; 1239 c = READCHAR;
1231 if (c != '-') 1240 if (c != '-')
1362 FIRST_IN_LIST is nonzero if this is the first element of a list. */ 1371 FIRST_IN_LIST is nonzero if this is the first element of a list. */
1363 1372
1364 static Lisp_Object 1373 static Lisp_Object
1365 read1 (readcharfun, pch, first_in_list) 1374 read1 (readcharfun, pch, first_in_list)
1366 register Lisp_Object readcharfun; 1375 register Lisp_Object readcharfun;
1367 char *pch; 1376 int *pch;
1368 int first_in_list; 1377 int first_in_list;
1369 { 1378 {
1370 register int c; 1379 register int c;
1371 int uninterned_symbol = 0; 1380 int uninterned_symbol = 0;
1372 1381
1468 #ifdef USE_TEXT_PROPERTIES 1477 #ifdef USE_TEXT_PROPERTIES
1469 if (c == '(') 1478 if (c == '(')
1470 { 1479 {
1471 Lisp_Object tmp; 1480 Lisp_Object tmp;
1472 struct gcpro gcpro1; 1481 struct gcpro gcpro1;
1473 char ch; 1482 int ch;
1474 1483
1475 /* Read the string itself. */ 1484 /* Read the string itself. */
1476 tmp = read1 (readcharfun, &ch, 0); 1485 tmp = read1 (readcharfun, &ch, 0);
1477 if (ch != 0 || !STRINGP (tmp)) 1486 if (ch != 0 || !STRINGP (tmp))
1478 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil)); 1487 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil));
1732 that we are really going to find in etc/DOC.nn.nn */ 1741 that we are really going to find in etc/DOC.nn.nn */
1733 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel) 1742 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
1734 return make_number (0); 1743 return make_number (0);
1735 1744
1736 if (read_pure) 1745 if (read_pure)
1737 return make_pure_string (read_buffer, p - read_buffer); 1746 return make_pure_string (read_buffer, p - read_buffer,
1747 p - read_buffer);
1748 else if (! NILP (current_buffer->enable_multibyte_characters))
1749 return make_string (read_buffer, p - read_buffer);
1738 else 1750 else
1739 return make_string (read_buffer, p - read_buffer); 1751 return make_unibyte_string (read_buffer, p - read_buffer);
1740 } 1752 }
1741 1753
1742 case '.': 1754 case '.':
1743 { 1755 {
1744 #ifdef LISP_FLOAT_TYPE 1756 #ifdef LISP_FLOAT_TYPE
1967 val = Qnil; 1979 val = Qnil;
1968 tail = Qnil; 1980 tail = Qnil;
1969 1981
1970 while (1) 1982 while (1)
1971 { 1983 {
1972 char ch; 1984 int ch;
1973 GCPRO2 (val, tail); 1985 GCPRO2 (val, tail);
1974 elt = read1 (readcharfun, &ch, first_in_list); 1986 elt = read1 (readcharfun, &ch, first_in_list);
1975 UNGCPRO; 1987 UNGCPRO;
1976 1988
1977 first_in_list = 0; 1989 first_in_list = 0;
2125 Lisp_Object obarray; 2137 Lisp_Object obarray;
2126 2138
2127 obarray = Vobarray; 2139 obarray = Vobarray;
2128 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0) 2140 if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
2129 obarray = check_obarray (obarray); 2141 obarray = check_obarray (obarray);
2130 tem = oblookup (obarray, str, len); 2142 tem = oblookup (obarray, str, len, len);
2131 if (SYMBOLP (tem)) 2143 if (SYMBOLP (tem))
2132 return tem; 2144 return tem;
2133 return Fintern (make_string (str, len), obarray); 2145 return Fintern (make_string (str, len), obarray);
2134 } 2146 }
2135 2147
2140 char *str; 2152 char *str;
2141 { 2153 {
2142 int len = strlen (str); 2154 int len = strlen (str);
2143 2155
2144 return Fmake_symbol ((!NILP (Vpurify_flag) 2156 return Fmake_symbol ((!NILP (Vpurify_flag)
2145 ? make_pure_string (str, len) 2157 ? make_pure_string (str, len, len)
2146 : make_string (str, len))); 2158 : make_string (str, len)));
2147 } 2159 }
2148 2160
2149 DEFUN ("intern", Fintern, Sintern, 1, 2, 0, 2161 DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
2150 "Return the canonical symbol whose name is STRING.\n\ 2162 "Return the canonical symbol whose name is STRING.\n\
2159 if (NILP (obarray)) obarray = Vobarray; 2171 if (NILP (obarray)) obarray = Vobarray;
2160 obarray = check_obarray (obarray); 2172 obarray = check_obarray (obarray);
2161 2173
2162 CHECK_STRING (string, 0); 2174 CHECK_STRING (string, 0);
2163 2175
2164 tem = oblookup (obarray, XSTRING (string)->data, XSTRING (string)->size); 2176 tem = oblookup (obarray, XSTRING (string)->data,
2177 XSTRING (string)->size,
2178 XSTRING (string)->size_byte);
2165 if (!INTEGERP (tem)) 2179 if (!INTEGERP (tem))
2166 return tem; 2180 return tem;
2167 2181
2168 if (!NILP (Vpurify_flag)) 2182 if (!NILP (Vpurify_flag))
2169 string = Fpurecopy (string); 2183 string = Fpurecopy (string);
2194 if (NILP (obarray)) obarray = Vobarray; 2208 if (NILP (obarray)) obarray = Vobarray;
2195 obarray = check_obarray (obarray); 2209 obarray = check_obarray (obarray);
2196 2210
2197 CHECK_STRING (string, 0); 2211 CHECK_STRING (string, 0);
2198 2212
2199 tem = oblookup (obarray, XSTRING (string)->data, XSTRING (string)->size); 2213 tem = oblookup (obarray, XSTRING (string)->data,
2214 XSTRING (string)->size,
2215 XSTRING (string)->size_byte);
2200 if (!INTEGERP (tem)) 2216 if (!INTEGERP (tem))
2201 return tem; 2217 return tem;
2202 return Qnil; 2218 return Qnil;
2203 } 2219 }
2204 2220
2223 { 2239 {
2224 CHECK_STRING (name, 0); 2240 CHECK_STRING (name, 0);
2225 string = name; 2241 string = name;
2226 } 2242 }
2227 2243
2228 tem = oblookup (obarray, XSTRING (string)->data, XSTRING (string)->size); 2244 tem = oblookup (obarray, XSTRING (string)->data,
2245 XSTRING (string)->size,
2246 XSTRING (string)->size_byte);
2229 if (INTEGERP (tem)) 2247 if (INTEGERP (tem))
2230 return Qnil; 2248 return Qnil;
2231 /* If arg was a symbol, don't delete anything but that symbol itself. */ 2249 /* If arg was a symbol, don't delete anything but that symbol itself. */
2232 if (SYMBOLP (name) && !EQ (name, tem)) 2250 if (SYMBOLP (name) && !EQ (name, tem))
2233 return Qnil; 2251 return Qnil;
2260 2278
2261 return Qt; 2279 return Qt;
2262 } 2280 }
2263 2281
2264 /* Return the symbol in OBARRAY whose names matches the string 2282 /* Return the symbol in OBARRAY whose names matches the string
2265 of SIZE characters at PTR. If there is no such symbol in OBARRAY, 2283 of SIZE characters (SIZE_BYTE bytes) at PTR.
2266 return nil. 2284 If there is no such symbol in OBARRAY, return nil.
2267 2285
2268 Also store the bucket number in oblookup_last_bucket_number. */ 2286 Also store the bucket number in oblookup_last_bucket_number. */
2269 2287
2270 Lisp_Object 2288 Lisp_Object
2271 oblookup (obarray, ptr, size) 2289 oblookup (obarray, ptr, size, size_byte)
2272 Lisp_Object obarray; 2290 Lisp_Object obarray;
2273 register char *ptr; 2291 register char *ptr;
2274 register int size; 2292 int size, size_byte;
2275 { 2293 {
2276 int hash; 2294 int hash;
2277 int obsize; 2295 int obsize;
2278 register Lisp_Object tail; 2296 register Lisp_Object tail;
2279 Lisp_Object bucket, tem; 2297 Lisp_Object bucket, tem;
2285 obsize = XVECTOR (obarray)->size; 2303 obsize = XVECTOR (obarray)->size;
2286 } 2304 }
2287 /* This is sometimes needed in the middle of GC. */ 2305 /* This is sometimes needed in the middle of GC. */
2288 obsize &= ~ARRAY_MARK_FLAG; 2306 obsize &= ~ARRAY_MARK_FLAG;
2289 /* Combining next two lines breaks VMS C 2.3. */ 2307 /* Combining next two lines breaks VMS C 2.3. */
2290 hash = hash_string (ptr, size); 2308 hash = hash_string (ptr, size_byte);
2291 hash %= obsize; 2309 hash %= obsize;
2292 bucket = XVECTOR (obarray)->contents[hash]; 2310 bucket = XVECTOR (obarray)->contents[hash];
2293 oblookup_last_bucket_number = hash; 2311 oblookup_last_bucket_number = hash;
2294 if (XFASTINT (bucket) == 0) 2312 if (XFASTINT (bucket) == 0)
2295 ; 2313 ;
2296 else if (!SYMBOLP (bucket)) 2314 else if (!SYMBOLP (bucket))
2297 error ("Bad data in guts of obarray"); /* Like CADR error message */ 2315 error ("Bad data in guts of obarray"); /* Like CADR error message */
2298 else 2316 else
2299 for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next)) 2317 for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next))
2300 { 2318 {
2301 if (XSYMBOL (tail)->name->size == size 2319 if (XSYMBOL (tail)->name->size_byte == size_byte
2302 && !bcmp (XSYMBOL (tail)->name->data, ptr, size)) 2320 && XSYMBOL (tail)->name->size == size
2321 && !bcmp (XSYMBOL (tail)->name->data, ptr, size_byte))
2303 return tail; 2322 return tail;
2304 else if (XSYMBOL (tail)->next == 0) 2323 else if (XSYMBOL (tail)->next == 0)
2305 break; 2324 break;
2306 } 2325 }
2307 XSETINT (tem, hash); 2326 XSETINT (tem, hash);
2381 int hash; 2400 int hash;
2382 Lisp_Object *tem; 2401 Lisp_Object *tem;
2383 2402
2384 XSETFASTINT (oblength, OBARRAY_SIZE); 2403 XSETFASTINT (oblength, OBARRAY_SIZE);
2385 2404
2386 Qnil = Fmake_symbol (make_pure_string ("nil", 3)); 2405 Qnil = Fmake_symbol (make_pure_string ("nil", 3, 3));
2387 Vobarray = Fmake_vector (oblength, make_number (0)); 2406 Vobarray = Fmake_vector (oblength, make_number (0));
2388 initial_obarray = Vobarray; 2407 initial_obarray = Vobarray;
2389 staticpro (&initial_obarray); 2408 staticpro (&initial_obarray);
2390 /* Intern nil in the obarray */ 2409 /* Intern nil in the obarray */
2391 XSYMBOL (Qnil)->obarray = Vobarray; 2410 XSYMBOL (Qnil)->obarray = Vobarray;
2394 /* Separate statement here to avoid VAXC bug. */ 2413 /* Separate statement here to avoid VAXC bug. */
2395 hash %= OBARRAY_SIZE; 2414 hash %= OBARRAY_SIZE;
2396 tem = &XVECTOR (Vobarray)->contents[hash]; 2415 tem = &XVECTOR (Vobarray)->contents[hash];
2397 *tem = Qnil; 2416 *tem = Qnil;
2398 2417
2399 Qunbound = Fmake_symbol (make_pure_string ("unbound", 7)); 2418 Qunbound = Fmake_symbol (make_pure_string ("unbound", 7, 7));
2400 XSYMBOL (Qnil)->function = Qunbound; 2419 XSYMBOL (Qnil)->function = Qunbound;
2401 XSYMBOL (Qunbound)->value = Qunbound; 2420 XSYMBOL (Qunbound)->value = Qunbound;
2402 XSYMBOL (Qunbound)->function = Qunbound; 2421 XSYMBOL (Qunbound)->function = Qunbound;
2403 2422
2404 Qt = intern ("t"); 2423 Qt = intern ("t");
2731 char *buffer 2750 char *buffer
2732 = (char *) alloca (XSTRING (dirname)->size + strlen (format) + 5); 2751 = (char *) alloca (XSTRING (dirname)->size + strlen (format) + 5);
2733 2752
2734 fprintf (stderr, format, XSTRING (dirname)->data); 2753 fprintf (stderr, format, XSTRING (dirname)->data);
2735 sprintf (buffer, format, XSTRING (dirname)->data); 2754 sprintf (buffer, format, XSTRING (dirname)->data);
2736 message_dolog (buffer, strlen (buffer), 0); 2755 message_dolog (buffer, strlen (buffer), 0, STRING_MULTIBYTE (dirname));
2737 } 2756 }
2738 2757
2739 void 2758 void
2740 syms_of_lread () 2759 syms_of_lread ()
2741 { 2760 {