If you want to make a lot of actions (like updating sections, creating new section and save the .cfg ) the classical Nimbus API is not enougth (It's just here to help people to read cfg files easily).
sub createSection {
my ($CFG,$sectionName) = @_;
cfgKeyWrite($CFG,$sectionName,"key","value");
cfgKeyDelete($CFG,$sectionName,"key");
}
my $CFG = cfgOpen("test.cfg", 0);
createSection($CFG,"/setup");
cfgKeyWrite($CFG,"/setup/","loglevel","5");
cfgSync($CFG);
cfgClose($CFG);
Open the cfg file. First argument is the cfg location and the second one allow to only allow to read the cfg file.
my $CFGHandler = cfgOpen('test.cfg',0);
Close the cfg. Take as argument the cfg handle.
cfgClose($CFGHandler);
Write the cfg to the disk (but leave the file open).
cfgSync($CFGHandler);
Warning : It's Sync and not Synch
Delete a key in a specific section.
cfgKeyDelete($CFGHandler,"/setup","logsize");
Retrieving an array of keys from a section.
my ($ARR) = cfgKeyList($CFGHandler,"/setup");
foreach my $keyName ($ARR) {
my $keyValue = cfgKeyRead($CFGHandler,"/setup",$keyName);
print "$keyName => $keyValue \n";
}
Read a key value from a section.
Write a new value for a section/key.
cfgKeyWrite($CFGHandler,"/setup","loglevel","5");
If the section does'nt exist it will be created.
Reads the section that is specified and returns the list of values as an array. This is a cfgValueList
method.
Take the following xml :
<setup>
loglevel = 5
logsize = 10000
</setup>
And now you want to retrieve all keys value from setup (so we need 5 and 10000).
my ($valArr) = cfgListRead($CFGHandler,"/setup");
Replace a section with the contents of the array list. Each entry in the array is treated as a value. The key names are generated based on the KeyBody prefix (for example, "key" generates "key0", "key1"…).
my @Equipments = ("T1","T2","T3");
cfgListWrite($CFGHandler,"/equipments","id_",@Equipments);
And now your cfg look like
<equipments>
id_0 = T1
id_1 = T2
id_2 = T3
</equipements>
Copy section from
to section to
with a new name.
cfgSectionCopy($CFGHandler,"/setup","/setup_copy");
Delete a section.
List all sections from a section
my ($ARR) = cfgSectionList($CFGHandler,"/");
foreach my $sectionName ($ARR) {
cfgSectionDelete($CFGHandler,"/$sectionName");
}
Rename a section
cfgSectionRename($CFGHandler,"/setup","/setup_new");
Perl SDK have no method to create a section. So we have to create a key on our needed section (and delete this key right after).
cfgKeyWrite($CFGHandler,"/needed_section","key","value");
cfgKeyDelete($CFGHandler,"/needed_section","key");
And now you have the section needed_section
without any key!