1 | [[tags: egg]] |
---|
2 | |
---|
3 | == ini-file |
---|
4 | |
---|
5 | [[toc:]] |
---|
6 | |
---|
7 | === Description |
---|
8 | |
---|
9 | Read & write INI configuration files. |
---|
10 | |
---|
11 | === Documentation |
---|
12 | |
---|
13 | {{ini-file}} is a small library for reading & writing INI files, |
---|
14 | such as those used in early Windows configuration scripts. |
---|
15 | |
---|
16 | INI syntax as a whole is underspecified and its implementations vary. |
---|
17 | This egg supports only its most basic features (comments, sections, |
---|
18 | zero- and one-valued properties). |
---|
19 | |
---|
20 | ==== API |
---|
21 | |
---|
22 | <procedure>(read-property [port])</procedure> |
---|
23 | |
---|
24 | Reads a single INI property from {{port}}. If it is a section header, |
---|
25 | returns a symbol. If it is a property or property/value pair, a pair is |
---|
26 | returned. Invalid properties will signal an error. |
---|
27 | |
---|
28 | Numeric values and quoted strings are read as such; everything else is treated |
---|
29 | as a string literal. |
---|
30 | |
---|
31 | <procedure>(read-ini [file-or-port])</procedure> |
---|
32 | |
---|
33 | Reads configuration directives from {{file-or-port}} until {{#!eof}}, |
---|
34 | returning an alist of alists corresponding hierarchically to the |
---|
35 | source INI's SECTION -> PROPERTY -> VALUE structure. |
---|
36 | |
---|
37 | Properties appearing before any section heading are associated |
---|
38 | with the key given by the {{default-section}} parameter. |
---|
39 | |
---|
40 | If {{file-or-port}} is a port, it is not closed. |
---|
41 | |
---|
42 | <procedure>(write-ini alist [file-or-port])</procedure> |
---|
43 | |
---|
44 | Writes {{alist}} as INI directives to {{file-or-port}}. |
---|
45 | |
---|
46 | A symbol at the head of {{alist}} signifies a section of that name. |
---|
47 | The write order of {{alist}}'s properties is reverse that of {{alist}}. |
---|
48 | |
---|
49 | The {{property-separator}} parameter specifies the character or |
---|
50 | string with which to separate property names & values. |
---|
51 | |
---|
52 | If {{file-or-port}} is a port, it is not closed. |
---|
53 | |
---|
54 | ==== Parameters |
---|
55 | |
---|
56 | <parameter>(default-section [name])</parameter> |
---|
57 | |
---|
58 | Specifies the default alist key (usually a symbol) under which properties |
---|
59 | without a section label will be placed {{read-ini}}. Defaults to {{'default}}. |
---|
60 | |
---|
61 | <parameter>(property-separator [char-or-string])</parameter> |
---|
62 | |
---|
63 | Specifies the character or string to be used by {{write-ini}} to separate |
---|
64 | property names & values. Defaults to {{#\=}}. |
---|
65 | |
---|
66 | <parameter>(allow-empty-values? [boolean])</parameter> |
---|
67 | |
---|
68 | Specifies whether the empty string should be treated as a valid property value. |
---|
69 | If {{#f}}, an empty value will signal an error. Defaults to {{#f}}. |
---|
70 | |
---|
71 | <parameter>(allow-bare-properties? [boolean])</parameter> |
---|
72 | |
---|
73 | Specifies whether "bare" properties (those without a value) should be allowed. |
---|
74 | If {{#f}}, a line not following "key separator value" format will signal an |
---|
75 | error. Defaults to {{#t}}, making the default parsing behavior very forgiving. |
---|
76 | |
---|
77 | === Example |
---|
78 | |
---|
79 | Git uses INI syntax for its configuration files. From {{man git-config}}: |
---|
80 | |
---|
81 | # |
---|
82 | # This is the config file, and |
---|
83 | # a '#' or ';' character indicates |
---|
84 | # a comment |
---|
85 | # |
---|
86 | |
---|
87 | ; core variables |
---|
88 | [core] |
---|
89 | ; Don't trust file modes |
---|
90 | filemode = false |
---|
91 | |
---|
92 | ; Our diff algorithm |
---|
93 | [diff] |
---|
94 | external = /usr/local/bin/diff-wrapper |
---|
95 | renames = true |
---|
96 | |
---|
97 | ; Proxy settings |
---|
98 | [core] |
---|
99 | gitproxy="proxy-command" for kernel.org |
---|
100 | gitproxy=default-proxy ; for all the rest |
---|
101 | |
---|
102 | (use ini-file) |
---|
103 | (read-ini ".git/config") |
---|
104 | ; => ((core (gitproxy . "default-proxy") |
---|
105 | ; (gitproxy . "\"proxy-command\" for kernel.org")) |
---|
106 | ; (diff (renames . "true") |
---|
107 | ; (external . "/usr/local/bin/diff-wrapper")) |
---|
108 | ; (core (filemode . "false"))) |
---|
109 | |
---|
110 | Note that separate sections of the same name are not merged. |
---|
111 | |
---|
112 | === History |
---|
113 | |
---|
114 | * 0.2 Use regex unit |
---|
115 | * 0.1 Initial release |
---|
116 | |
---|
117 | === Author |
---|
118 | |
---|
119 | [[Evan Hanson]] |
---|
120 | |
---|
121 | === License |
---|
122 | |
---|
123 | Copyright (c) 2011 Evan Hanson, 3-Clause BSD. |
---|