mIRC Homepage
Posted By: dunkelzahn $ini little problem - 28/11/05 10:39 AM
I saw a problem with $ini.

A have a ini file with a following syntaxe :

[3000]
truc=thing
[3001]
....

I made an automatic system which look at the name of the section and the name of the item.

For the section, I use $ini(file.ini,x)
For the item, I use $ini(file.ini,$ini(file.ini,x),y)
x and y are numbers with 0 for the total, obviously.

But, if the section is only a number, I have in return $null while with a name section avec letters, I have the number of items.

I know how to correct now, but is it possible to use numerical sections with $ini ?

I forget to say I use mIRC 6.16 on XP home
Posted By: Kelder Re: $ini little problem - 28/11/05 12:19 PM
Usually ini files are read using $readini because topic name and item name are known, and $readini has no problems at all with numeric topic or item names.

Since you have both x and y, $ini(file.ini,x,y) gives you the correct answer and it's shorter too.
Maybe add a switch ti $ini to tell mIRC it's the name and not the sequence number. It's also a good idea to think about your data, is an ini file where you know nothing about it's structure really the best way to store the data for your script?
Posted By: dunkelzahn Re: $ini little problem - 28/11/05 01:27 PM
I wanted to make an automatic loop because I don't know the name section.
But it is not the purpose of my message.

The purpose is when I give a number to a section (in exemple, 3000), I type :
$ini(file.ini,3000,0)
To know how much item I have inside section 3000.

But, mIRC reply me by a $null. If I make a section named ls3000, with :
$ini(file.ini,ls3000,0) it send me the number of items inside.

I know that $readini act correctly. The title was for $ini. Not for $readini.
Posted By: DaveC Re: $ini little problem - 29/11/05 06:50 AM
Did you even read the help file?

/help $ini
$ini(file,topic/N,item/N)
Returns the name/Nth position of the specified topic/item in an ini/text file.

$ini(mirc.ini,0) returns total number of topics in mirc.ini
$ini(mirc.ini,1) returns name of 1st topic in mirc.ini
$ini(mirc.ini,help) returns Nth position of topic help if it exists, or returns 0 if it doesn't exist

The item/N parameter is optional. If you specify specify N = 0, it returns the total number of topics/items.

-

$ini(file.ini,3000,0)
3000 is well not refrence a topic name but rather it refrences the 3000th topic, which i assume there isnt one. This is the reason for the $null return, correct as per the help file.
Posted By: Quietust Re: $ini little problem - 01/12/05 08:47 AM
Quote:
$ini(file.ini,3000,0)
3000 is well not refrence a topic name but rather it refrences the 3000th topic, which i assume there isnt one. This is the reason for the $null return, correct as per the help file.


The problem is that it is impossible to count the number of entries in a topic which has a numeric name, and I consider that to be a significant bug since there does not appear to be any workaround.
Posted By: FiberOPtics Re: $ini little problem - 01/12/05 07:00 PM
You can find the position of a topic, whether its name is numerical or not by doing a simple loop through $ini. You can then use this position to use $ini(file,position,0) for total items etc.

It returns 0 if the topic was not found, else it returns a positive integer.

/*

Usage:

$inipos(file,topic)

Returns 0 if the topic doesn't exist

Example:

//if ($inipos(test.ini,500)) echo -a $ini(test.ini,$ifmatch,0) items found


*/

Code:
alias inipos {
  if (!$isfile($1)) || ($0 < 2) return
  if ($2 !isnum) return $ini($1,$2)
  var %a = $ini($1,0)
  while ($ini($1,%a) != $2) && (%a) dec %a 
  return %a
}

Here's a little snippet you can try it with:

; Usage: /echoitems <file> <topic>

Code:
alias echoitems {
  var %pos = $$inipos($1,$2)
  if (%pos == 0) return
  var %i = 1, %ii = $ini($1,%pos,0), %item
  while (%i &lt;= %ii) {
    %item = $ini($1,%pos,%i)
    echo -a $+(%item,=,$readini($1,n,$2,%item))
    inc %i
  }
}


Posted By: dunkelzahn Re: $ini little problem - 06/12/05 11:12 AM
Quote:
Did you even read the help file?

/help $ini
$ini(file,topic/N,item/N)
Returns the name/Nth position of the specified topic/item in an ini/text file.

$ini(mirc.ini,0) returns total number of topics in mirc.ini
$ini(mirc.ini,1) returns name of 1st topic in mirc.ini
$ini(mirc.ini,help) returns Nth position of topic help if it exists, or returns 0 if it doesn't exist

The item/N parameter is optional. If you specify specify N = 0, it returns the total number of topics/items.

-

$ini(file.ini,3000,0)
3000 is well not refrence a topic name but rather it refrences the 3000th topic, which i assume there isnt one. This is the reason for the $null return, correct as per the help file.


Yeah, I read the help file. Now, is it specified in the help file that topic and item mustn't be a numerical because mirc use it for the position ? No. It is may be not a bug but a I tjink it is a source of problem when using ini files which comport numerical topics. May be a note in the help file can help it.

The other reason is was I used the last token with a number and not the two last tokens with a number (I don't know if you understand, sorry). I don't know this method before. Now, I know it. thanks

Thanks for your code Fiberoptics and others
Posted By: DaveC Re: $ini little problem - 07/12/05 04:17 AM
The same problem exists in more than just INI files, if u use a number when you should use a name what more can you expect, I mean its not hard to make the section name a a name instead of a number just use ^ $+ <number>. What if there was a section named "0" what would you expect $ini(file,0) to resolve to?
© mIRC Discussion Forums