2 # parseini --- parses 'ini' style configuration files.
5 # awk -f parseini S=<section> P=<param> <ini file>
7 # if section is an empty string, then we use the default section
13 # multiline = this is a multiline \
27 # > awk -f parseini S=ocean P=fish testfile.ini
38 # remove lines starting with #, but not #!
44 # we want to read the lines of the matched section
45 # and disable for other sections
52 if (S && match($0, "^\\[" S "\\][ \n]*")) {
53 # we found the section, so start reading.
57 # no section, so stop reading lines
58 if (readlines) readlines = 0
63 # when reading, store lines.
68 if ($0 ~ /\\[ \r\t]*$/)
74 # process the read lines lines, matching parameters
77 # if section is set but implied is still true
78 # then we never found the section, so use everything
83 # if have P then find P in read lines and get values
85 MATCH = "^[ \r\t]*" P "[ \r\t]*="
87 for (x = 0; x < nline; ++x) {
90 sub(/[ \r\t]+$/, "", v)
92 v = substr(v, 1, length(v)-1)
93 sub(/[ \r\t]+$/, "", v)
95 if (v) value[nvalue++] = v
99 sub(/^[ \r\t]+/, "", v)
100 sub(/[ \r\t]+$/, "", v)
103 v = substr(v, 1, length(v)-1)
104 sub(/[ \r\t]+$/, "", v)
106 if (v) value[nvalue++] = v
109 # copy parameter definition to output array
111 for (x = 0; x < nvalue; ++x)
115 # trim all leading & trailing whitespace;
116 # except for leading whitespace in continuation lines,
118 for (x = 0; x < nline; ++x) {
119 sub(/^[ \r\t]+/, "", line[x])
120 sub(/[ \r\t]+$/, "", line[x])
123 # output the final result
124 for (x = 0; x < nline; ++x)