info {
created=1203230967
version=3.0rc2
}
programstatus {
modified_host_attributes=0
modified_service_attributes=0
(...)
}
namespace eval nagios {}
proc nagios::readFile {filename} {
set fh [open $filename r]
set rc [readFileChannel $fh]
close $fh
return $rc
}
proc nagios::readFileChannel {fh} {
set rc [list]
fconfigure $fh -encoding iso8859-1 -translation auto
seek $fh 0
set isobject 0
while {![eof $fh]} {
gets $fh line
if {[regexp "^\\s*#" $line]} {
# comment - skip it
} elseif {[regexp "^\\s*(.*?)\\s*\{\\s*\$" $line - objecttype]} {
# beginning of an object
set isobject 1
lappend rc $objecttype [list]
} elseif {$isobject && [regexp "^\\s*(.*?)=(.*)\$" $line - name value]} {
# name=value line
set value [string map [list \\n \n \\t \t \\\\ \\] $value]
set vl [lindex $rc end]
lappend vl $name $value
lset rc end $vl
}
}
return $rc
}