From 8318be1420455239e6aa3cc99496a459f1672e8b Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Mon, 4 Aug 2025 13:25:33 +0200 Subject: [PATCH 1/2] preference directory functionality added --- main.rkt | 14 +++++++++++--- scribblings/ini.scrbl | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/main.rkt b/main.rkt index 3c8a626..2dbfa37 100644 --- a/main.rkt +++ b/main.rkt @@ -10,8 +10,15 @@ make-ini ) + +(define (get-ini-file f) + (if (symbol? f) + (let* ((pref-dir (find-system-path 'pref-dir))) + (build-path pref-dir (string-append (symbol->string f) ".ini"))) + (build-path f))) + (define (ini->file ini file) - (let ((out (open-output-file file #:exists 'replace))) + (let ((out (open-output-file (get-ini-file file) #:exists 'replace))) (let ((last-is-newline #f)) (for-each (lambda (section) (let ((section-name (car section))) @@ -64,8 +71,9 @@ #f) s))))))) -(define (file->ini file) - (let* ((lines (file->lines file)) +(define (file->ini file*) + (let* ((file (get-ini-file file*)) + (lines (if (file-exists? file) (file->lines file) '())) (re-section #px"^\\[([a-zA-Z0-9_-]+)\\]$") (re-keyval #px"^([a-zA-Z0-9_-]+)[=](.*)$") (re-comment #px"^[;](.*)$")) diff --git a/scribblings/ini.scrbl b/scribblings/ini.scrbl index 34f87b4..53e3eda 100644 --- a/scribblings/ini.scrbl +++ b/scribblings/ini.scrbl @@ -23,6 +23,8 @@ @defproc[(file->ini [file path-string?]) mc-pair?]{ Reads an INI file from disk and parses it into an internal mutable cons pair (mc-pair) structure. + If the file does noet exist, an empty ini structure is made. + If file is a symbol?, the file will be constructed from the prefs-dir, the symbol and a suffix ".ini". The parser supports: @@ -42,7 +44,8 @@ } @defproc[(ini->file [ini mc-pair?] [file path-string?]) void?]{ - Writes an INI structure (as produced by @racket[file->ini] or @racket[make-ini]) to the specified file. + Writes an INI structure (as produced by @racket[file->ini] or @racket[make-ini]) to the specified file. + If file is a symbol?, the file will be constructed from the prefs-dir, the symbol and a suffix ".ini". The output preserves: @itemlist[ From 0316d84647d4385384bc21d12477b6577969af67 Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Mon, 4 Aug 2025 13:29:39 +0200 Subject: [PATCH 2/2] ini --- info.rkt | 2 +- main.rkt | 1 + roos.rkt | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/info.rkt b/info.rkt index da82c41..ce6d01d 100644 --- a/info.rkt +++ b/info.rkt @@ -1,7 +1,7 @@ #lang info (define pkg-authors '(hnmdijkema)) -(define version "0.20") +(define version "0.21") (define license 'Apache-2.0) ;(define collection "simple-ini") (define pkg-desc "A Simple .ini file reader/writer for racket") diff --git a/main.rkt b/main.rkt index 2dbfa37..45b5b3d 100644 --- a/main.rkt +++ b/main.rkt @@ -8,6 +8,7 @@ ini-get ini-set! make-ini + get-ini-file ) diff --git a/roos.rkt b/roos.rkt index 63dc927..008fe1f 100644 --- a/roos.rkt +++ b/roos.rkt @@ -12,7 +12,7 @@ (set! a b)))) (def-roos (ini . _file) this (supers) - (file* (if (null? _file) #f (car _file))) + (file* (if (null? _file) #f (get-ini-file (car _file)))) (content (if (not (eq? file* #f)) (if (file-exists? file*) (file->ini file*)