* Use scm_mem2symbol or scm_str2symbol to create symbol objects.
[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_FALSEP (SCM_FILENAME (port)))
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 return scm_mem2symbol (SCM_STRING_CHARS (*tok_buf), j);
385
386 case '\\':
387 c = scm_getc (port);
388 j = scm_read_token (c, tok_buf, port, 0);
389 if (j == 1)
390 return SCM_MAKE_CHAR (c);
391 if (c >= '0' && c < '8')
392 {
393 p = scm_istr2int (SCM_STRING_CHARS (*tok_buf), (long) j, 8);
394 if (SCM_NFALSEP (p))
395 return SCM_MAKE_CHAR (SCM_INUM (p));
396 }
397 for (c = 0; c < scm_n_charnames; c++)
398 if (scm_charnames[c]
399 && (scm_casei_streq (scm_charnames[c], SCM_STRING_CHARS (*tok_buf))))
400 return SCM_MAKE_CHAR (scm_charnums[c]);
401 scm_wta (SCM_UNDEFINED, "unknown # object: #\\", SCM_STRING_CHARS (*tok_buf));
402
403 /* #:SYMBOL is a syntax for keywords supported in all contexts. */
404 case ':':
405 j = scm_read_token ('-', tok_buf, port, 0);
406 p = scm_mem2symbol (SCM_STRING_CHARS (*tok_buf), j);
407 return scm_make_keyword_from_dash_symbol (p);
408
409 default:
410 callshrp:
411 {
412 SCM sharp = scm_get_hash_procedure (c);
413
414 if (SCM_NIMP (sharp))
415 {
416 int line = SCM_LINUM (port);
417 int column = SCM_COL (port) - 2;
418 SCM got;
419
420 got = scm_apply (sharp,
421 SCM_MAKE_CHAR (c),
422 scm_acons (port, SCM_EOL, SCM_EOL));
423 if (SCM_EQ_P (got, SCM_UNSPECIFIED))
424 goto unkshrp;
425 if (SCM_RECORD_POSITIONS_P)
426 return *copy = recsexpr (got, line, column,
427 SCM_FILENAME (port));
428 else
429 return got;
430 }
431 }
432 unkshrp:
433 scm_misc_error (s_scm_read, "Unknown # object: ~S",
434 scm_listify (SCM_MAKE_CHAR (c), SCM_UNDEFINED));
435 }
436
437 case '"':
438 j = 0;
439 while ('"' != (c = scm_getc (port)))
440 {
441 SCM_ASSERT (EOF != c, SCM_UNDEFINED, "end of file in ", "string");
442
443 while (j + 2 >= SCM_STRING_LENGTH (*tok_buf))
444 scm_grow_tok_buf (tok_buf);
445
446 if (c == '\\')
447 switch (c = scm_getc (port))
448 {
449 case '\n':
450 continue;
451 case '0':
452 c = '\0';
453 break;
454 case 'f':
455 c = '\f';
456 break;
457 case 'n':
458 c = '\n';
459 break;
460 case 'r':
461 c = '\r';
462 break;
463 case 't':
464 c = '\t';
465 break;
466 case 'a':
467 c = '\007';
468 break;
469 case 'v':
470 c = '\v';
471 break;
472 }
473 SCM_STRING_CHARS (*tok_buf)[j] = c;
474 ++j;
475 }
476 if (j == 0)
477 return scm_nullstr;
478 SCM_STRING_CHARS (*tok_buf)[j] = 0;
479 {
480 SCM str;
481 str = scm_makfromstr (SCM_STRING_CHARS (*tok_buf), j, 0);
482 return str;
483 }
484
485 case'0':case '1':case '2':case '3':case '4':
486 case '5':case '6':case '7':case '8':case '9':
487 case '.':
488 case '-':
489 case '+':
490 num:
491 j = scm_read_token (c, tok_buf, port, 0);
492 p = scm_istring2number (SCM_STRING_CHARS (*tok_buf), (long) j, 10L);
493 if (SCM_NFALSEP (p))
494 return p;
495 if (c == '#')
496 {
497 if ((j == 2) && (scm_getc (port) == '('))
498 {
499 scm_ungetc ('(', port);
500 c = SCM_STRING_CHARS (*tok_buf)[1];
501 goto callshrp;
502 }
503 scm_wta (SCM_UNDEFINED, "unknown # object", SCM_STRING_CHARS (*tok_buf));
504 }
505 goto tok;
506
507 case ':':
508 if (SCM_EQ_P (SCM_PACK (SCM_KEYWORD_STYLE), scm_keyword_prefix))
509 {
510 j = scm_read_token ('-', tok_buf, port, 0);
511 p = scm_mem2symbol (SCM_STRING_CHARS (*tok_buf), j);
512 return scm_make_keyword_from_dash_symbol (p);
513 }
514 /* fallthrough */
515 default:
516 j = scm_read_token (c, tok_buf, port, 0);
517 /* fallthrough */
518
519 tok:
520 return scm_mem2symbol (SCM_STRING_CHARS (*tok_buf), j);
521 }
522 }
523
524 #ifdef _UNICOS
525 _Pragma ("noopt"); /* # pragma _CRI noopt */
526 #endif
527
528 scm_sizet
529 scm_read_token (int ic, SCM *tok_buf, SCM port, int weird)
530 {
531 register scm_sizet j;
532 register int c;
533 register char *p;
534
535 c = (SCM_CASE_INSENSITIVE_P ? scm_downcase(ic) : ic);
536 p = SCM_STRING_CHARS (*tok_buf);
537
538 if (weird)
539 j = 0;
540 else
541 {
542 j = 0;
543 while (j + 2 >= SCM_STRING_LENGTH (*tok_buf))
544 p = scm_grow_tok_buf (tok_buf);
545 p[j] = c;
546 ++j;
547 }
548
549 while (1)
550 {
551 while (j + 2 >= SCM_STRING_LENGTH (*tok_buf))
552 p = scm_grow_tok_buf (tok_buf);
553 c = scm_getc (port);
554 switch (c)
555 {
556 case '(':
557 case ')':
558 case '"':
559 case ';':
560 case SCM_WHITE_SPACES:
561 case SCM_LINE_INCREMENTORS:
562 if (weird)
563 goto default_case;
564
565 scm_ungetc (c, port);
566 case EOF:
567 eof_case:
568 p[j] = 0;
569 return j;
570 case '\\':
571 if (!weird)
572 goto default_case;
573 else
574 {
575 c = scm_getc (port);
576 if (c == EOF)
577 goto eof_case;
578 else
579 goto default_case;
580 }
581 case '}':
582 if (!weird)
583 goto default_case;
584
585 c = scm_getc (port);
586 if (c == '#')
587 {
588 p[j] = 0;
589 return j;
590 }
591 else
592 {
593 scm_ungetc (c, port);
594 c = '}';
595 goto default_case;
596 }
597
598 default:
599 default_case:
600 {
601 c = (SCM_CASE_INSENSITIVE_P ? scm_downcase(c) : c);
602 p[j] = c;
603 ++j;
604 }
605
606 }
607 }
608 }
609
610 #ifdef _UNICOS
611 _Pragma ("opt"); /* # pragma _CRI opt */
612 #endif
613
614 SCM
615 scm_lreadparen (SCM *tok_buf, SCM port, char *name, SCM *copy)
616 {
617 SCM tmp;
618 SCM tl;
619 SCM ans;
620 int c;
621
622 c = scm_flush_ws (port, name);
623 if (')' == c)
624 return SCM_EOL;
625 scm_ungetc (c, port);
626 if (SCM_EQ_P (scm_sym_dot, (tmp = scm_lreadr (tok_buf, port, copy))))
627 {
628 ans = scm_lreadr (tok_buf, port, copy);
629 closeit:
630 if (')' != (c = scm_flush_ws (port, name)))
631 scm_wta (SCM_UNDEFINED, "missing close paren", "");
632 return ans;
633 }
634 ans = tl = scm_cons (tmp, SCM_EOL);
635 while (')' != (c = scm_flush_ws (port, name)))
636 {
637 scm_ungetc (c, port);
638 if (SCM_EQ_P (scm_sym_dot, (tmp = scm_lreadr (tok_buf, port, copy))))
639 {
640 SCM_SETCDR (tl, scm_lreadr (tok_buf, port, copy));
641 goto closeit;
642 }
643 SCM_SETCDR (tl, scm_cons (tmp, SCM_EOL));
644 tl = SCM_CDR (tl);
645 }
646 return ans;
647 }
648
649
650 SCM
651 scm_lreadrecparen (SCM *tok_buf, SCM port, char *name, SCM *copy)
652 {
653 register int c;
654 register SCM tmp;
655 register SCM tl, tl2 = SCM_EOL;
656 SCM ans, ans2 = SCM_EOL;
657 /* Need to capture line and column numbers here. */
658 int line = SCM_LINUM (port);
659 int column = SCM_COL (port) - 1;
660
661 c = scm_flush_ws (port, name);
662 if (')' == c)
663 return SCM_EOL;
664 scm_ungetc (c, port);
665 if (SCM_EQ_P (scm_sym_dot, (tmp = scm_lreadr (tok_buf, port, copy))))
666 {
667 ans = scm_lreadr (tok_buf, port, copy);
668 if (')' != (c = scm_flush_ws (port, name)))
669 scm_wta (SCM_UNDEFINED, "missing close paren", "");
670 return ans;
671 }
672 /* Build the head of the list structure. */
673 ans = tl = scm_cons (tmp, SCM_EOL);
674 if (SCM_COPY_SOURCE_P)
675 ans2 = tl2 = scm_cons (SCM_CONSP (tmp)
676 ? *copy
677 : tmp,
678 SCM_EOL);
679 while (')' != (c = scm_flush_ws (port, name)))
680 {
681 SCM new_tail;
682
683 scm_ungetc (c, port);
684 if (SCM_EQ_P (scm_sym_dot, (tmp = scm_lreadr (tok_buf, port, copy))))
685 {
686 SCM_SETCDR (tl, tmp = scm_lreadr (tok_buf, port, copy));
687 if (SCM_COPY_SOURCE_P)
688 SCM_SETCDR (tl2, scm_cons (SCM_CONSP (tmp)
689 ? *copy
690 : tmp,
691 SCM_EOL));
692 if (')' != (c = scm_flush_ws (port, name)))
693 scm_wta (SCM_UNDEFINED, "missing close paren", "");
694 goto exit;
695 }
696
697 new_tail = scm_cons (tmp, SCM_EOL);
698 SCM_SETCDR (tl, new_tail);
699 tl = new_tail;
700
701 if (SCM_COPY_SOURCE_P)
702 {
703 SCM new_tail2 = scm_cons (SCM_CONSP (tmp) ? *copy : tmp, SCM_EOL);
704 SCM_SETCDR (tl2, new_tail2);
705 tl2 = new_tail2;
706 }
707 }
708 exit:
709 scm_whash_insert (scm_source_whash,
710 ans,
711 scm_make_srcprops (line,
712 column,
713 SCM_FILENAME (port),
714 SCM_COPY_SOURCE_P
715 ? *copy = ans2
716 : SCM_UNDEFINED,
717 SCM_EOL));
718 return ans;
719 }
720
721
722 \f
723
724 /* Manipulate the read-hash-procedures alist. This could be written in
725 Scheme, but maybe it will also be used by C code during initialisation. */
726 SCM_DEFINE (scm_read_hash_extend, "read-hash-extend", 2, 0, 0,
727 (SCM chr, SCM proc),
728 "")
729 #define FUNC_NAME s_scm_read_hash_extend
730 {
731 SCM this;
732 SCM prev;
733
734 SCM_VALIDATE_CHAR (1,chr);
735 SCM_ASSERT (SCM_FALSEP (proc) || SCM_NIMP(proc), proc, SCM_ARG2,
736 FUNC_NAME);
737
738 /* Check if chr is already in the alist. */
739 this = *scm_read_hash_procedures;
740 prev = SCM_BOOL_F;
741 while (1)
742 {
743 if (SCM_NULLP (this))
744 {
745 /* not found, so add it to the beginning. */
746 if (SCM_NFALSEP (proc))
747 {
748 *scm_read_hash_procedures =
749 scm_cons (scm_cons (chr, proc), *scm_read_hash_procedures);
750 }
751 break;
752 }
753 if (SCM_EQ_P (chr, SCM_CAAR (this)))
754 {
755 /* already in the alist. */
756 if (SCM_FALSEP (proc))
757 {
758 /* remove it. */
759 if (SCM_FALSEP (prev))
760 {
761 *scm_read_hash_procedures =
762 SCM_CDR (*scm_read_hash_procedures);
763 }
764 else
765 scm_set_cdr_x (prev, SCM_CDR (this));
766 }
767 else
768 {
769 /* replace it. */
770 scm_set_cdr_x (SCM_CAR (this), proc);
771 }
772 break;
773 }
774 prev = this;
775 this = SCM_CDR (this);
776 }
777
778 return SCM_UNSPECIFIED;
779 }
780 #undef FUNC_NAME
781
782 /* Recover the read-hash procedure corresponding to char c. */
783 static SCM
784 scm_get_hash_procedure (int c)
785 {
786 SCM rest = *scm_read_hash_procedures;
787
788 while (1)
789 {
790 if (SCM_NULLP (rest))
791 return SCM_BOOL_F;
792
793 if (SCM_CHAR (SCM_CAAR (rest)) == c)
794 return SCM_CDAR (rest);
795
796 rest = SCM_CDR (rest);
797 }
798 }
799
800 void
801 scm_init_read ()
802 {
803 scm_read_hash_procedures =
804 SCM_CDRLOC (scm_sysintern ("read-hash-procedures", SCM_EOL));
805
806 scm_init_opts (scm_read_options, scm_read_opts, SCM_N_READ_OPTIONS);
807 #ifndef SCM_MAGIC_SNARFER
808 #include "libguile/read.x"
809 #endif
810 }
811
812 /*
813 Local Variables:
814 c-file-style: "gnu"
815 End:
816 */