############################################################################################################# # # script : ini.irc # version : 1.0 # author : blue-elf # date : 9 May 2005 / 3:07AM <-- this is what jIRCii does to me #------------------------------------------------------------------------------------------------------------ # NOTES: # # PLEASE USE LATEST JIRCII VERSION. Bugs/comments, email me at belf@null.net # # ini.irc is an alternative way of storing data. This should give mIRC scripters a boost in SLEEP scripting. # This is actually a fake ini function. You have to saveini() on exit to actually save the entries into files. # And if you want to use an ini file for read/writeini(), you have to loadini(file) first. Every modification # is done using multidimensional hashtables, that's why. # # This allows spaces in section/item names. # #------------------------------------------------------------------------------------------------------------ # LIMITATION: # # It will screw up if your section/item name has an equal sign '=' character in it. So it's up to you # to work around that. Having [] brackets in the section names shouldn't be a problem. # #------------------------------------------------------------------------------------------------------------ # FUNCTIONS: # # These are self-explanatory: # writeini(file, section, item, value) # readini(file, section, item) # remini(file, section [, item ] ) <- If you omit the item, the whole section is removed. # # loadini(file) # - Loads an ini file into a %hash table cache. # # saveini() # - Saves all ini entries (Writes them to the ini files). Use this on exit # ############################################################################################################# # werd to my unca 'tane # writeini(file, section, item, value) sub writeini { %GLOBAL["INI_ENTRIES"][$1][$2][$3] = $4; } # readini(file, section, item) sub readini { return %GLOBAL["INI_ENTRIES"][$1][$2][$3]; } # remini(file, section [, item ] ) sub remini { if ($3 ne '') { %GLOBAL["INI_ENTRIES"][$1][$2][$3] = ''; } else { %GLOBAL["INI_ENTRIES"][$1][$2] = ''; } } sub saveini { local('%phew $filekey $sectkey $itemkey $ini'); %phew = %GLOBAL["INI_ENTRIES"]; foreach $filekey (keys(%phew)) # File level { $ini = openf("> $filekey"); foreach $sectkey (keys(%phew[$filekey])) # Section level { println($ini, "[ $+ $sectkey $+ ]"); foreach $itemkey (keys(%phew[$filekey][$sectkey] )) # Item level { println($ini, "$itemkey $+ =" . %phew[$filekey][$sectkey][$itemkey]); } println($ini, chr(13)); # Add a space between the sections. Windows style. } closef($ini); } } sub loadini { local('$file @file $line $section $item $value $tmp'); $file = openf($1); @file = readAll($file); closef($file); foreach $line (@file) { if ($line ne '') # a continue() function would be nice to lessen the indentations { if ('[*]' iswm $line) { $section = substr($line, 1, strlen($line) - 1 ); } else if ($section ne '') # See how paranoid I am.. { $tmp = tokenize($line, '='); # I'm using getToken because values can have '=' in them. $item = getToken($tmp, 0); # If I use split('=', $line), I can't grab all the values, right? $value = getTokenFrom($tmp, 1); %phew[$1][$section][$item] = $value; } } } %GLOBAL["INI_ENTRIES"] = %phew; } # EOF