INI parser/writer?
Does anyone has an ini parser/writer in ObjectScript they can share?
Product version: IRIS 2022.1
Discussion (3)0
Comments
I have an (some ten years old) one which I use in the %ZSTART routine. Sometimes (for maintenance or whatever other reasons) you have to (re)start Cache and nowdays IRIS, but you want to start just some of the automatic processes listed in %ZSTART. If you forgot to disable those other before shutdown a init-file comes handy to disable things before start. A sample section looks like this:
[Start]
# 0 = do not start
# 1 = start
LoginServer = 1
UserLogin = 0
SystemTasks = 1
UserTasks = 0I added some more comments to the class, you can download the InitFile.xml (class export) from my FTP server (which will be open for the next few days).
Addr: ftp.kavay.at
User: dcmember
Pass: member-of-DCThank you, @Julius.Kavaygot it.
Ended up with this implementation:
Parameter NOSECTION = "DEFAULT";/// do ##class().INIToLocal(,.ini)ClassMethod INIToLocal(file, Output ini) As%Status
{
#dim sc As%Status = $$$OKkill ini
set stream = ##class(%Stream.FileCharacter).%New()
do stream.LinkToFile(file)
set section = ..#NOSECTION
while 'stream.AtEnd {
set line = stream.ReadLine()
set line=$zstrip(line, "<>w")
continue:($e(line)="#")||($l(line)<3)
if$e(line)="[" {
set section = $e(line, 2, *-1)
} else {
set key = $zstrip($p(line, "="), "<>w")
set value = $zstrip($p(line, "=", 2, *), "<>w")
set ini(section, key) = value
}
}
kill stream
quit sc
}
/// do ##class().LocalToINI(.ini)ClassMethod LocalToINI(ByRef ini, file) As%Status
{
merge iniTemp = ini
#dim sc As%Status = $$$OKset stream = ##class(%Stream.FileCharacter).%New()
do stream.LinkToFile(file)
set section = ..#NOSECTION
set key=$o(iniTemp(section, ""),1,value)
while (key'="") {
do stream.WriteLine(key _ "=" _ value)
set key = $o(iniTemp(section, key),1,value)
}
do stream.WriteLine()
kill iniTemp(section)
set section=$o(iniTemp(""))
while (section'="") {
do stream.WriteLine("[" _ section _ "]")
set key=$o(iniTemp(section, ""),1,value)
while (key'="") {
do stream.WriteLine(key _ "=" _ value)
set key = $o(iniTemp(section, key),1,value)
}
set section = $o(iniTemp(section))
do stream.WriteLine()
}
set sc = stream.%Save()
kill stream, iniTemp
quit sc
}