section/keys can now be symbols and strings

This commit is contained in:
2026-08-27 15:54:04 +02:00
parent 9f2dd563f0
commit fa6b1e3f3e
+11 -5
View File
@@ -41,6 +41,12 @@
)
)
(define (section=? sect inp-sect)
(string-ci=? (format "~a" sect) (format "~a" inp-sect)))
(define (key=? key inp-key)
(section=? key inp-key))
(define (ini->file ini file #:private? [private? #f])
(let* ((file (get-ini-file file))
(_ (make-parent-directory* file))
@@ -54,7 +60,7 @@
(let ((last-is-newline #f))
(for-each (lambda (section)
(let ((section-name (car section)))
(if (eq? section-name 'nil)
(if (section=? section-name 'nil)
#t
(begin
(unless last-is-newline (newline out))
@@ -155,13 +161,13 @@
(letrec ((g (lambda (ini)
(if (null? ini)
def-val
(if (eq? section (caar ini))
(if (section=? section (caar ini))
(letrec ((f (lambda (l)
(if (null? l)
def-val
(let ((entry (car l)))
(if (eq? (car entry) 'keyval)
(if (eq? (cadr entry) key)
(if (key=? (cadr entry) key)
(caddr entry)
(f (cdr l)))
(f (cdr l))))))))
@@ -180,7 +186,7 @@
(list (list 'keyval key val))))
(let ((entry (car sect)))
(if (eq? (car entry) 'keyval)
(if (eq? (cadr entry) key)
(if (key=? (cadr entry) key)
(begin
(set! found #t)
(cons (list 'keyval key val) (for-sect (cdr sect))))
@@ -193,7 +199,7 @@
(list (list section (list 'keyval key val))))
(let* ((ini-section (car ini))
(section-key (car ini-section)))
(if (eq? section-key section)
(if (section=? section-key section)
(cons (cons section (for-sect (cdr ini-section))) (for-ini (cdr ini)))
(cons ini-section (for-ini (cdr ini)))))))))
(let ((new-ini (for-ini (mcdr ini))))