INI File Parser and Writer
(define myeval (make-base-eval ’(require simple-ini roos)))
(require simple-ini) | package: simple-ini |
1 Creating and Parsing INI Files
procedure
file : path-string?
The parser supports:
Sections (e.g., [section-name])
Key-value pairs (e.g., key=value)
Comments (lines starting with ;)
Empty lines
Numbers, if the value matches a number pattern
Booleans, if the value is #t, true, #f, or false (case-insensitive)
Otherwise, as strings
procedure
(ini->file ini file) → void?
ini : mc-pair? file : path-string?
Section headers
Key-value pairs
Comments (prefixed with ;)
Empty lines
2 Accessing and Modifying Values
3 The ini% Racket Class
(require simple-ini/class) | package: simple-ini |
Require this module for the OO implementation of this Simple INI implementation
Creates the ini from the given file. * If (eq? file #f), an empty ini will be made. * if (symbol? file), an ini will be made or read in the users preferences folder with the given (format "~a.ini" file) as name. * Otherwise, the file will be made or read at the given location.The fail flag determines if methods of the class will fail when some value in the ini file is written while there is no file to write to or if some non existing key is read.
Gets the current ini file. See constructor for more information.Sets the ini file to be used. See constructor for more information.Gets the value of the ’fail’ flag. See constructor for more information.Sets the value of the ’fail’ flag. See constructor for more information.Gets the contents of the ini structure as stored in memory.See get-contents.Reloads the ini file in memory, or empties the ini structure (eq? file #f).Sets the value of the key in the given section. After the set! operation, the ini structure will be written to file. Note. Although ini files can be read from standard .ini formats, the simple-ini format will be enhanced. It wil store values in racket format, so that ’read’ can be used to read in the racket value.
method
(send an-ini get section key default-value) → any/c?
section : (or/c symbol? string?) key : (or/c symbol? string?) default-value : any/c? (send an-ini get section key) → any/c section : (or/c symbol? string?) key : (or/c symbol? string) Returns the value for the given section and key combination. If this combination does not exist in the ini structure, it will return the default-value. However, if default-value is not given, it will return #f.
4 The ini Roos Class
(require simple-ini/roos) | package: simple-ini |
procedure
ini : roos-class* or/c : path-string?
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!).
procedure
(file) → (or/c path-string? #f)
procedure
(file! f) → void?
f : path-string?
procedure
(fail) → boolean?
procedure
(reload) → void?
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.
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
file* — the filename (or #f)
content — the mutable INI structure