INI Files
Description:
We’ll use an .ini file to store information in an organized order.
It’s useful to use as a permanent storage for hash tables.
Advantages:
Ability to store items by 2 parameters : section and item name.
Unlimited storage space (well, you won’t fill your HDD with this).
Easy access to data through the topic and item names.
Ability to load to hash tables, and save hash tables to them.
Disadvantages:
Takes a lot of cpu power to access the file and use it regularly.
No trivial sort command.
Difficult to search the data.
Storage:
The data is stored in a file on the HDD, using the .ini file format:
File.ini {
[section]
Item1=data
Item2=data
[section2]
Item1= data
Item2 = data
}
Adding data:
/writeini –n file.ini section item data
This will add the data to the specified item under the specified section. The –n switch will allow access to “large” .ini files.
Deleting data:
/remini file.ini section
This will remove an entire section from the file.
/remini file.ini section item
This will remove an item from the specified section.
/remove file.ini
Will permanently remove the file.
Retrieving data:
Set %data $readini(file.ini,section.item)
Searching data:
Set %section $ini(file.ini,N)
This will return the Nth section in the file.
Set %item $ini(file.ini,section,N)
This will return the Nth item in the section.
Converting to Hash:
/hsave –I Hash_Name file.ini section
This will save the Hash table to the specified section.
/hload –I Hash_Name file.ini section
This will load the specified section into the Hash table.
Loading to @windows:
/loadbuf –tSection @window file.ini
This will load all the items in the section to the custom @window .
Retrieving size:
Set %num_sec $ini(file.ini,0)
This will return the number of sections in the .ini file.
Set %num_items $ini(file.ini,section,0)
This will return the number of items in the section.
Example:
Load the example to the remotes, and right click on a channel.
menu channel {
INI Store data: {
writeini -n mychanneldata.ini $chan topic $chan($chan).topic
writeini -n mychanneldata.ini $chan mode $chan($chan).mode
if ($chan($chan).key) writeini -n mychanneldata.ini $chan key $v1
}
INI Show data: {
if ($ini(mychanneldata.ini,$chan)) {
echo -a The chan's stored topic is: $readini(mychanneldata.ini,$chan,topic)
if ($ini(mychanneldata.ini,$chan,0) = 3) echo -a I've stored 3 items, so there must be a key: $readini(mychanneldata.ini,$chan,key)
echo -a Last stored modes were: $readini(mychanneldata.ini,$chan,mode)
}
else echo -a The channel has no stored data
}
INI Remove data :{
if ($ini(mychanneldata.ini,$chan)) remini mychanneldata.ini $chan
if ($ini(mychanneldata.ini,0) == 0) && ($isfile(mychanneldata.ini)) remove mychanneldata.ini
}
}