* Don't call scm_vector_set_length_x for non-vector arguments.
[bpt/guile.git] / libguile / read.c
1 /* Copyright (C) 1995,1996,1997, 1999, 2000 Free Software Foundation, Inc.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
17 *
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
20 *
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
37 *
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
40 * If you do not wish that, delete this exception notice. */
41
42 /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
43 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
44
45 \f
46
47 #include <stdio.h>
48 #include "libguile/_scm.h"
49 #include "libguile/chars.h"
50 #include "libguile/eval.h"
51 #include "libguile/unif.h"
52 #include "libguile/keywords.h"
53 #include "libguile/alist.h"
54 #include "libguile/srcprop.h"
55 #include "libguile/hashtab.h"
56 #include "libguile/hash.h"
57 #include "libguile/ports.h"
58 #include "libguile/root.h"
59 #include "libguile/strings.h"
60 #include "libguile/vectors.h"
61
62 #include "libguile/validate.h"
63 #include "libguile/read.h"
64
65 \f
66
67 SCM_SYMBOL (scm_keyword_prefix, "prefix");
68
69 scm_option scm_read_opts[] = {
70 { SCM_OPTION_BOOLEAN, "copy", 0,
71 "Copy source code expressions." },
72 { SCM_OPTION_BOOLEAN, "positions", 0,
73 "Record positions of source code expressions." },
74 { SCM_OPTION_BOOLEAN, "case-insensitive", 0,
75 "Convert symbols to lower case."},
76 { SCM_OPTION_SCM, "keywords", SCM_UNPACK (SCM_BOOL_F),
77 "Style of keyword recognition: #f or 'prefix"}
78 };
79
80 SCM_DEFINE (scm_read_options, "read-options-interface", 0, 1, 0,
81 (SCM setting),
82 "")
83 #define FUNC_NAME s_scm_read_options
84 {
85 SCM ans = scm_options (setting,
86 scm_read_opts,
87 SCM_N_READ_OPTIONS,
88 FUNC_NAME);
89 if (SCM_COPY_SOURCE_P)
90 SCM_RECORD_POSITIONS_P = 1;
91 return ans;
92 }
93 #undef FUNC_NAME
94
95 /* An association list mapping extra hash characters to procedures. */
96 static SCM *scm_read_hash_procedures;
97
98 SCM_DEFINE (scm_read, "read", 0, 1, 0,
99 (SCM port),
100 "")
101 #define FUNC_NAME s_scm_read
102 {
103 int c;
104 SCM tok_buf, copy;
105
106 if (SCM_UNBNDP (port))
107 port = scm_cur_inp;
108 SCM_VALIDATE_OPINPORT (1,port);
109
110 c = scm_flush_ws (port, (char *) NULL);
111 if (EOF == c)
112 return SCM_EOF_VAL;
113 scm_ungetc (c, port);
114
115 tok_buf = scm_makstr (30L, 0);
116 return scm_lreadr (&tok_buf, port, &copy);
117 }
118 #undef FUNC_NAME
119
120
121
122 char *
123 scm_grow_tok_buf (SCM *tok_buf)
124 {
125 unsigned long int oldlen = SCM_STRING_LENGTH (*tok_buf);
126 SCM newstr = scm_makstr (2 * oldlen, 0);
127 unsigned long int i;
128
129 for (i = 0; i != oldlen; ++i)
130 SCM_STRING_CHARS (newstr) [i] = SCM_STRING_CHARS (*tok_buf) [i];
131
132 *tok_buf = newstr;
133 return SCM_STRING_CHARS (newstr);
134 }
135
136
137
138 int
139 scm_flush_ws (SCM port, const char *eoferr)
140 {
141 register int c;
142 while (1)
143 switch (c = scm_getc (port))
144 {
145 case EOF:
146 goteof:
147 if (eoferr)
148 {
149 if (SCM_FILENAME (port) != SCM_BOOL_F)
150 scm_misc_error (eoferr,
151 "end of file in ~A",
152 SCM_LIST1 (SCM_FILENAME (port)));
153 else
154 scm_misc_error (eoferr, "end of file", SCM_EOL);
155 }
156 return c;
157 case ';':
158 lp:
159 switch (c = scm_getc (port))
160 {
161 case EOF:
162 goto goteof;
163 default:
164 goto lp;
165 case SCM_LINE_INCREMENTORS:
166 break;
167 }
168 break;
169 case SCM_LINE_INCREMENTORS:
170 case SCM_SINGLE_SPACES:
171 case '\t':
172 break;
173 default:
174 return c;
175 }
176 }
177
178
179
180 int
181 scm_casei_streq (char *s1, char *s2)
182 {
183 while (*s1 && *s2)
184 if (scm_downcase((int)*s1) != scm_downcase((int)*s2))
185 return 0;
186 else
187 {
188 ++s1;
189 ++s2;
190 }
191 return !(*s1 || *s2);
192 }
193
194
195 /* recsexpr is used when recording expressions
196 * constructed by read:sharp.
197 */
198 #ifndef DEBUG_EXTENSIONS
199 #define recsexpr(obj, line, column, filename) (obj)
200 #else
201 static SCM
202 recsexpr (SCM obj,int line,int column,SCM filename)
203 {
204 if (!SCM_CONSP(obj)) {
205 return obj;
206 } else {
207 SCM tmp = obj, copy;
208 /* If this sexpr is visible in the read:sharp source, we want to
209 keep that information, so only record non-constant cons cells
210 which haven't previously been read by the reader. */
211 if (SCM_FALSEP (scm_whash_lookup (scm_source_whash, obj)))
212 {
213 if (SCM_COPY_SOURCE_P)
214 {
215 copy = scm_cons (recsexpr (SCM_CAR (obj), line, column, filename),
216 SCM_UNDEFINED);
217 while ((tmp = SCM_CDR (tmp)) && SCM_CONSP (tmp))
218 {
219 SCM_SETCDR (copy, scm_cons (recsexpr (SCM_CAR (tmp),
220 line,
221 column,
222 filename),
223 SCM_UNDEFINED));
224 copy = SCM_CDR (copy);
225 }
226 SCM_SETCDR (copy, tmp);
227 }
228 else
229 {
230 recsexpr (SCM_CAR (obj), line, column, filename);
231 while ((tmp = SCM_CDR (tmp)) && SCM_CONSP (tmp))
232 recsexpr (SCM_CAR (tmp), line, column, filename);
233 copy = SCM_UNDEFINED;
234 }
235 scm_whash_insert (scm_source_whash,
236 obj,
237 scm_make_srcprops (line,
238 column,
239 filename,
240 copy,
241 SCM_EOL));
242 }
243 return obj;
244 }
245 }
246 #endif
247
248 /* Consume an SCSH-style block comment. Assume that we've already
249 read the initial `#!', and eat characters until we get a
250 newline/exclamation-point/sharp-sign/newline sequence. */
251
252 static void
253 skip_scsh_block_comment (SCM port)
254 {
255 /* Is this portable? Dear God, spare me from the non-eight-bit
256 characters. But is it tasteful? */
257 long history = 0;
258
259 for (;;)
260 {
261 int c = scm_getc (port);
262
263 if (c == EOF)
264 scm_wta (SCM_UNDEFINED,
265 "unterminated `#! ... !#' comment", "read");
266 history = ((history << 8) | (c & 0xff)) & 0xffffffff;
267
268 /* Were the last four characters read "\n!#\n"? */
269 if (history == (('\n' << 24) | ('!' << 16) | ('#' << 8) | '\n'))
270 return;
271 }
272 }
273
274 static SCM scm_get_hash_procedure(int c);
275
276 static char s_list[]="list";
277
278 SCM
279 scm_lreadr (SCM *tok_buf,SCM port,SCM *copy)
280 {
281 int c;
282 scm_sizet j;
283 SCM p;
284
285 tryagain:
286 c = scm_flush_ws (port, s_scm_read);
287 tryagain_no_flush_ws:
288 switch (c)
289 {
290 case EOF:
291 return SCM_EOF_VAL;
292
293 case '(':
294 return SCM_RECORD_POSITIONS_P
295 ? scm_lreadrecparen (tok_buf, port, s_list, copy)
296 : scm_lreadparen (tok_buf, port, s_list, copy);
297 case ')':
298 scm_wta (SCM_UNDEFINED, "unexpected \")\"", "read");
299 goto tryagain;
300
301 case '\'':
302 p = scm_sym_quote;
303 goto recquote;
304 case '`':
305 p = scm_sym_quasiquote;
306 goto recquote;
307 case ',':
308 c = scm_getc (port);
309 if ('@' == c)
310 p = scm_sym_uq_splicing;
311 else
312 {
313 scm_ungetc (c, port);
314 p = scm_sym_unquote;
315 }
316 recquote:
317 p = scm_cons2 (p,
318 scm_lreadr (tok_buf, port, copy),
319 SCM_EOL);
320 if (SCM_RECORD_POSITIONS_P)
321 scm_whash_insert (scm_source_whash,
322 p,
323 scm_make_srcprops (SCM_LINUM (port),
324 SCM_COL (port) - 1,
325 SCM_FILENAME (port),
326 SCM_COPY_SOURCE_P
327 ? (*copy = scm_cons2 (SCM_CAR (p),
328 SCM_CAR (SCM_CDR (p)),
329 SCM_EOL))
330 : SCM_UNDEFINED,
331 SCM_EOL));
332 return p;
333 case '#':
334 c = scm_getc (port);
335 switch (c)
336 {
337 case '(':
338 p = scm_lreadparen (tok_buf, port, "vector", copy);
339 return SCM_NULLP (p) ? scm_nullvect : scm_vector (p);
340
341 case 't':
342 case 'T':
343 return SCM_BOOL_T;
344 case 'f':
345 case 'F':
346 return SCM_BOOL_F;
347
348 case 'b':
349 case 'B':
350 case 'o':
351 case 'O':
352 case 'd':
353 case 'D':
354 case 'x':
355 case 'X':
356 case 'i':
357 case 'I':
358 case 'e':
359 case 'E':
360 scm_ungetc (c, port);
361 c = '#';
362 goto num;
363
364 case '!':
365 /* start of a shell script. Parse as a block comment,
366 terminated by !#, just like SCSH. */
367 skip_scsh_block_comment (port);
368 /* EOF is not an error here */
369 c = scm_flush_ws (port, (char *)NULL);
370 goto tryagain_no_flush_ws;
371
372 #ifdef HAVE_ARRAYS
373 case '*':
374 j = scm_read_token (c, tok_buf, port, 0);
375 p = scm_istr2bve (SCM_STRING_CHARS (*tok_buf) + 1, (long) (j - 1));
376 if (SCM_NFALSEP (p))
377 return p;
378 else
379 goto unkshrp;
380 #endif
381
382 case '{':
383 j = scm_read_token (c, tok_buf, port, 1);
384 p = scm_intern (SCM_STRING_CHARS (*tok_buf), j);
385 return SCM_CAR (p);
386
387 case '\\':
388 c = scm_getc (port);
389 j = scm_read_token (c, tok_buf, port, 0);
390 if (j == 1)
391 return SCM_MAKE_CHAR (c);
392 if (c >= '0' && c < '8')
393 {
394 p = scm_istr2int (SCM_STRING_CHARS (*tok_buf), (long) j, 8);
395 if (SCM_NFALSEP (p))
396 return SCM_MAKE_CHAR (SCM_INUM (p));
397 }
398 for (c = 0; c < scm_n_charnames; c++)
399 if (scm_charnames[c]
400 && (scm_casei_streq (scm_charnames[c], SCM_STRING_CHARS (*tok_buf))))
401 return SCM_MAKE_CHAR (scm_charnums[c]);
402 scm_wta (SCM_UNDEFINED, "unknown # object: #\\", SCM_STRING_CHARS (*tok_buf));
403
404 /* #:SYMBOL is a syntax for keywords supported in all contexts. */
405 case ':':
406 j = scm_read_token ('-', tok_buf, port, 0);
407 p = scm_intern (SCM_STRING_CHARS (*tok_buf), j);
408 return scm_make_keyword_from_dash_symbol (SCM_CAR (p));
409
410 default:
411 callshrp:
412 {
413 SCM sharp = scm_get_hash_procedure (c);
414
415 if (SCM_NIMP (sharp))
416 {
417 int line = SCM_LINUM (port);
418 int column = SCM_COL (port) - 2;
419 SCM got;
420
421 got = scm_apply (sharp,
422 SCM_MAKE_CHAR (c),
423 scm_acons (port, SCM_EOL, SCM_EOL));
424 if (SCM_EQ_P (got, SCM_UNSPECIFIED))
425 goto unkshrp;
426 if (SCM_RECORD_POSITIONS_P)
427 return *copy = recsexpr (got, line, column,
428 SCM_FILENAME (port));
429 else
430 return got;
431 }
432 }
433 unkshrp:
434 scm_misc_error (s_scm_read, "Unknown # object: ~S",
435 scm_listify (SCM_MAKE_CHAR (c), SCM_UNDEFINED));
436 }
437
438 case '"':
439 j = 0;
440 while ('"' != (c = scm_getc (port)))
441 {
442 SCM_ASSERT (EOF != c, SCM_UNDEFINED, "end of file in ", "string");
443
444 while (j + 2 >= SCM_STRING_LENGTH (*tok_buf))
445 scm_grow_tok_buf (tok_buf);
446
447 if (c == '\\')
448 switch (c = scm_getc (port))
449 {
450 case '\n':
451 continue;
452 case '0':
453 c = '\0';
454 break;
455 case 'f':
456 c = '\f';
457 break;
458 case 'n':
459 c = '\n';
460 break;
461 case 'r':
462 c = '\r';
463 break;
464 case 't':
465 c = '\t';
466 break;
467 case 'a':
468 c = '\007';
469 break;
470 case 'v':
471 c = '\v';
472 break;
473 }
474 SCM_STRING_CHARS (*tok_buf)[j] = c;
475 ++j;
476 }
477 if (j == 0)
478 return scm_nullstr;
479 SCM_STRING_CHARS (*tok_buf)[j] = 0;
480 {
481 SCM str;
482 str = scm_makfromstr (SCM_STRING_CHARS (*tok_buf), j, 0);
483 return str;
484 }
485
486 case'0':case '1':case '2':case '3':case '4':
487 case '5':case '6':case '7':case '8':case '9':
488 case '.':
489 case '-':
490 case '+':
491 num:
492 j = scm_read_token (c, tok_buf, port, 0);
493 p = scm_istring2number (SCM_STRING_CHARS (*tok_buf), (long) j, 10L);
494 if (SCM_NFALSEP (p))
495 return p;
496 if (c == '#')
497 {
498 if ((j == 2) && (scm_getc (port) == '('))
499 {
500 scm_ungetc ('(', port);
501 c = SCM_STRING_CHARS (*tok_buf)[1];
502 goto callshrp;
503 }
504 scm_wta (SCM_UNDEFINED, "unknown # object", SCM_STRING_CHARS (*tok_buf));
505 }
506 goto tok;
507
508 case ':':
509 if (SCM_EQ_P (SCM_PACK (SCM_KEYWORD_STYLE), scm_keyword_prefix))
510 {
511 j = scm_read_token ('-', tok_buf, port, 0);
512 p = scm_intern (SCM_STRING_CHARS (*tok_buf), j);
513 return scm_make_keyword_from_dash_symbol (SCM_CAR (p));
514 }
515 /* fallthrough */
516 default:
517 j = scm_read_token (c, tok_buf, port, 0);
518 /* fallthrough */
519
520 tok:
521 p = scm_intern (SCM_STRING_CHARS (*tok_buf), j);
522 return SCM_CAR (p);
523 }
524 }
525
526 #ifdef _UNICOS
527 _Pragma ("noopt"); /* # pragma _CRI noopt */
528 #endif
529
530 scm_sizet
531 scm_read_token (int ic, SCM *tok_buf, SCM port, int weird)
532 {
533 register scm_sizet j;
534 register int c;
535 register char *p;
536
537 c = (SCM_CASE_INSENSITIVE_P ? scm_downcase(ic) : ic);
538 p = SCM_STRING_CHARS (*tok_buf);
539
540 if (weird)
541 j = 0;
542 else
543 {
544 j = 0;
545 while (j + 2 >= SCM_STRING_LENGTH (*tok_buf))
546 p = scm_grow_tok_buf (tok_buf);
547 p[j] = c;
548 ++j;
549 }
550
551 while (1)
552 {
553 while (j + 2 >= SCM_STRING_LENGTH (*tok_buf))
554 p = scm_grow_tok_buf (tok_buf);
555 c = scm_getc (port);
556 switch (c)
557 {
558 case '(':
559 case ')':
560 case '"':
561 case ';':
562 case SCM_WHITE_SPACES:
563 case SCM_LINE_INCREMENTORS:
564 if (weird)
565 goto default_case;
566
567 scm_ungetc (c, port);
568 case EOF:
569 eof_case:
570 p[j] = 0;
571 return j;
572 case '\\':
573 if (!weird)
574 goto default_case;
575 else
576 {
577 c = scm_getc (port);
578 if (c == EOF)
579 goto eof_case;
580 else
581 goto default_case;
582 }
583 case '}':
584 if (!weird)
585 goto default_case;
586
587 c = scm_getc (port);
588 if (c == '#')
589 {
590 p[j] = 0;
591 return j;
592 }
593 else
594 {
595 scm_ungetc (c, port);
596 c = '}';
597 goto default_case;
598 }
599
600 default:
601 default_case:
602 {
603 c = (SCM_CASE_INSENSITIVE_P ? scm_downcase(c) : c);
604 p[j] = c;
605 ++j;
606 }
607
608 }
609 }
610 }
611
612 #ifdef _UNICOS
613 _Pragma ("opt"); /* # pragma _CRI opt */
614 #endif
615
616 SCM
617 scm_lreadparen (SCM *tok_buf, SCM port, char *name, SCM *copy)
618 {
619 SCM tmp;
620 SCM tl;
621 SCM ans;
622 int c;
623
624 c = scm_flush_ws (port, name);
625 if (')' == c)
626 return SCM_EOL;
627 scm_ungetc (c, port);
628 if (SCM_EQ_P (scm_sym_dot, (tmp = scm_lreadr (tok_buf, port, copy))))
629 {
630 ans = scm_lreadr (tok_buf, port, copy);
631 closeit:
632 if (')' != (c = scm_flush_ws (port, name)))
633 scm_wta (SCM_UNDEFINED, "missing close paren", "");
634 return ans;
635 }
636 ans = tl = scm_cons (tmp, SCM_EOL);
637 while (')' != (c = scm_flush_ws (port, name)))
638 {
639 scm_ungetc (c, port);
640 if (SCM_EQ_P (scm_sym_dot, (tmp = scm_lreadr (tok_buf, port, copy))))
641 {
642 SCM_SETCDR (tl, scm_lreadr (tok_buf, port, copy));
643 goto closeit;
644 }
645 SCM_SETCDR (tl, scm_cons (tmp, SCM_EOL));
646 tl = SCM_CDR (tl);
647 }
648 return ans;
649 }
650
651
652 SCM
653 scm_lreadrecparen (SCM *tok_buf, SCM port, char *name, SCM *copy)
654 {
655 register int c;
656 register SCM tmp;
657 register SCM tl, tl2 = SCM_EOL;
658 SCM ans, ans2 = SCM_EOL;
659 /* Need to capture line and column numbers here. */
660 int line = SCM_LINUM (port);
661 int column = SCM_COL (port) - 1;
662
663 c = scm_flush_ws (port, name);
664 if (')' == c)
665 return SCM_EOL;
666 scm_ungetc (c, port);
667 if (SCM_EQ_P (scm_sym_dot, (tmp = scm_lreadr (tok_buf, port, copy))))
668 {
669 ans = scm_lreadr (tok_buf, port, copy);
670 if (')' != (c = scm_flush_ws (port, name)))
671 scm_wta (SCM_UNDEFINED, "missing close paren", "");
672 return ans;
673 }
674 /* Build the head of the list structure. */
675 ans = tl = scm_cons (tmp, SCM_EOL);
676 if (SCM_COPY_SOURCE_P)
677 ans2 = tl2 = scm_cons (SCM_CONSP (tmp)
678 ? *copy
679 : tmp,
680 SCM_EOL);
681 while (')' != (c = scm_flush_ws (port, name)))
682 {
683 SCM new_tail;
684
685 scm_ungetc (c, port);
686 if (SCM_EQ_P (scm_sym_dot, (tmp = scm_lreadr (tok_buf, port, copy))))
687 {
688 SCM_SETCDR (tl, tmp = scm_lreadr (tok_buf, port, copy));
689 if (SCM_COPY_SOURCE_P)
690 SCM_SETCDR (tl2, scm_cons (SCM_CONSP (tmp)
691 ? *copy
692 : tmp,
693 SCM_EOL));
694 if (')' != (c = scm_flush_ws (port, name)))
695 scm_wta (SCM_UNDEFINED, "missing close paren", "");
696 goto exit;
697 }
698
699 new_tail = scm_cons (tmp, SCM_EOL);
700 SCM_SETCDR (tl, new_tail);
701 tl = new_tail;
702
703 if (SCM_COPY_SOURCE_P)
704 {
705 SCM new_tail2 = scm_cons (SCM_CONSP (tmp) ? *copy : tmp, SCM_EOL);
706 SCM_SETCDR (tl2, new_tail2);
707 tl2 = new_tail2;
708 }
709 }
710 exit:
711 scm_whash_insert (scm_source_whash,
712 ans,
713 scm_make_srcprops (line,
714 column,
715 SCM_FILENAME (port),
716 SCM_COPY_SOURCE_P
717 ? *copy = ans2
718 : SCM_UNDEFINED,
719 SCM_EOL));
720 return ans;
721 }
722
723
724 \f
725
726 /* Manipulate the read-hash-procedures alist. This could be written in
727 Scheme, but maybe it will also be used by C code during initialisation. */
728 SCM_DEFINE (scm_read_hash_extend, "read-hash-extend", 2, 0, 0,
729 (SCM chr, SCM proc),
730 "")
731 #define FUNC_NAME s_scm_read_hash_extend
732 {
733 SCM this;
734 SCM prev;
735
736 SCM_VALIDATE_CHAR (1,chr);
737 SCM_ASSERT (SCM_FALSEP (proc) || SCM_NIMP(proc), proc, SCM_ARG2,
738 FUNC_NAME);
739
740 /* Check if chr is already in the alist. */
741 this = *scm_read_hash_procedures;
742 prev = SCM_BOOL_F;
743 while (1)
744 {
745 if (SCM_NULLP (this))
746 {
747 /* not found, so add it to the beginning. */
748 if (SCM_NFALSEP (proc))
749 {
750 *scm_read_hash_procedures =
751 scm_cons (scm_cons (chr, proc), *scm_read_hash_procedures);
752 }
753 break;
754 }
755 if (SCM_EQ_P (chr, SCM_CAAR (this)))
756 {
757 /* already in the alist. */
758 if (SCM_FALSEP (proc))
759 {
760 /* remove it. */
761 if (SCM_FALSEP (prev))
762 {
763 *scm_read_hash_procedures =
764 SCM_CDR (*scm_read_hash_procedures);
765 }
766 else
767 scm_set_cdr_x (prev, SCM_CDR (this));
768 }
769 else
770 {
771 /* replace it. */
772 scm_set_cdr_x (SCM_CAR (this), proc);
773 }
774 break;
775 }
776 prev = this;
777 this = SCM_CDR (this);
778 }
779
780 return SCM_UNSPECIFIED;
781 }
782 #undef FUNC_NAME
783
784 /* Recover the read-hash procedure corresponding to char c. */
785 static SCM
786 scm_get_hash_procedure (int c)
787 {
788 SCM rest = *scm_read_hash_procedures;
789
790 while (1)
791 {
792 if (SCM_NULLP (rest))
793 return SCM_BOOL_F;
794
795 if (SCM_CHAR (SCM_CAAR (rest)) == c)
796 return SCM_CDAR (rest);
797
798 rest = SCM_CDR (rest);
799 }
800 }
801
802 void
803 scm_init_read ()
804 {
805 scm_read_hash_procedures =
806 SCM_CDRLOC (scm_sysintern ("read-hash-procedures", SCM_EOL));
807
808 scm_init_opts (scm_read_options, scm_read_opts, SCM_N_READ_OPTIONS);
809 #include "libguile/read.x"
810 }
811
812 /*
813 Local Variables:
814 c-file-style: "gnu"
815 End:
816 */