mIRC Home    About    Download    Register    News    Help

Print Thread
#136457 28/11/05 10:39 AM
Joined: Dec 2002
Posts: 83
D
Babel fish
OP Offline
Babel fish
D
Joined: Dec 2002
Posts: 83
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

Last edited by dunkelzahn; 28/11/05 10:40 AM.
#136458 28/11/05 12:19 PM
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
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?

#136459 28/11/05 01:27 PM
Joined: Dec 2002
Posts: 83
D
Babel fish
OP Offline
Babel fish
D
Joined: Dec 2002
Posts: 83
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.

#136460 29/11/05 06:50 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
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.

#136461 01/12/05 08:47 AM
Joined: Mar 2003
Posts: 27
Q
Ameglian cow
Offline
Ameglian cow
Q
Joined: Mar 2003
Posts: 27
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.


* Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another
#136462 01/12/05 07:00 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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
  }
}




Gone.
#136463 06/12/05 11:12 AM
Joined: Dec 2002
Posts: 83
D
Babel fish
OP Offline
Babel fish
D
Joined: Dec 2002
Posts: 83
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

#136464 07/12/05 04:17 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
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?


Link Copied to Clipboard