8.17
INI File Parser and Writer🔗ℹ
(define myeval
(make-base-eval ’(require simple-ini roos)))
This module provides simple facilities for reading and writing INI-style configuration files, allowing interpretation of numeric and boolean values, and modification of the parsed structure.
1 Creating and Parsing INI Files🔗ℹ
Creates a new empty INI structure as a mutable cons pair. This is the base structure for manipulating INI contents.
Reads an INI file from disk and parses it into an internal mutable cons pair (mc-pair) structure.
The parser supports:
Sections (e.g., [section-name])
Key-value pairs (e.g., key=value)
Comments (lines starting with ;)
Empty lines
The keys are stored as symbols, and values are automatically interpreted as:
Numbers, if the value matches a number pattern
Booleans, if the value is #t, true, #f, or false (case-insensitive)
Otherwise, as strings
Writes an INI structure (as produced by file->ini or make-ini) to the specified file.
The output preserves:
2 Accessing and Modifying Values🔗ℹ
(ini-get ini section key def-val) → any/c
|
ini : mc-pair? |
section : symbol? |
key : symbol? |
def-val : any/c |
Retrieves the value associated with the given key in the specified section of the INI structure. If the key is not found, returns def-val.
(ini-set! ini section key val) → mc-pair?
|
ini : mc-pair? |
section : symbol? |
key : symbol? |
val : any/c |
Sets the value of key in the specified section of the INI structure. If the section or key does not exist, it is created. Returns the modified INI structure.
3 The ini Roos Class🔗ℹ
Require this module for the OO implementation of this Simple INI implementation
Provides a
Roos class that gives object-oriented access to INI files using the underlying
file->ini parser system. The class offers methods to load, query, and update INI files using familiar object-style interactions.
(-! ini or/c) → roos-object*
|
ini : roos-class* |
or/c : path-string? |
Creates an
ini object. If a
file path is provided and the file exists, it is loaded immediately. Otherwise, an empty INI structure is created.
If no file is provided, the object operates in-memory only. Subsequent set! operations will raise an error unless a file is later specified with (file!).
Returns the current filename associated with this INI object.
Sets the file to use as backing storage for the INI structure. Triggers a reload from disk.
Returns if an error will be thrown when a set! is done and no file has been set to write the contents to
Sets fail to the given value.
Reloads the INI content from disk, using the current file path.
If the file does not exist, the content is reset to an empty INI structure.
Sets the value in the INI structure for the given section and key to val.
If a file is associated with the object, the structure is saved to disk immediately.
If no file is set and fail is enabled, an error is raised.
Returns the INI object itself.
(get section key def-val ...) → any/c
|
section : symbol? |
key : symbol? |
def-val : any/c |
Retrieves the value associated with the given section and key.
If not found:
Returns #f if no default is given and fail is disabled
Returns def-val if one is provided
Raises an error if fail is enabled and no default is given
Internal state: