define load-ini pathname call-with-input-file pathname parse-ini defin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(define (load-ini pathname)
(call-with-input-file pathname parse-ini))
(define (parse-ini port)
(let ((char (read-char port)))
(if (not (eof-object? char))
(case char
((#\[)
(display (parse-section port))
(parse-ini port))
((#\space)
(parse-ini port))
((#\;)
(parse-comment port)
(parse-ini port))
(else
(parse-ini port))))))
(define (parse-comment port)
(let ((char (read-char port)))
(if (not (or (eof-object? char)
(char=? #\newline char)))
(parse-comment port))))
(define (parse-section port)
(let loop ((section-name '()))
(let ((char (read-char port)))
(if (or (eof-object? char)
(char=? #\] char))
(list->string (reverse! section-name))
(loop (cons char section-name))))))