mIRC Homepage
Posted By: Stealth $ini and entries with [ or ] - 08/01/07 08:16 AM
Code:
/write test.ini Test [Brackets] 123
//echo -a $readini(test.ini, test, [Brackets]) == 123
//echo -a $ini(test.ini, test, 1) == ~Brackets~


Is this a bug?
A windows thing?
Or just what?

Is there any (sane) workaround?
Posted By: billythekid Re: $ini and entries with [ or ] - 08/01/07 12:50 PM
/writeini should have been your first line, however i see what you mean, the item [brackets] is changed to ~brackets~ in the inifile, with a value of 123. I would take a guess this is a windows thing.

is a workaround really needed as the $readini using [brackets] does return the correct value?

I suppose for the $ini identifier you could do something like:
Code:
alias correctbrackets {
  if ( $left($ini($1,$2,$3),1) == ~ ) { 
    var %i = $replace($ini($1,$2,$3),~,$chr(91))
    if ( $right(%i,1) == $chr(91) ) {
      var %o = $left(%i,-1) $+ $chr(93)
      return %o
    }
  }
}

/writeini test.ini Test [Brackets] 123
//echo -a $readini(test.ini, test, [Brackets]) == 123
//echo -a $ini(test.ini, test, 1) == ~Brackets~
//echo -a $correctbrackets(test.ini,test,1) == [Brackets]

I know its a bit hackish and I'm sure there's a one line regex that does the same, but it works i guess...

btk


Posted By: Jigsy Re: $ini and entries with [ or ] - 08/01/07 02:59 PM
I think it's a Windows thing.

The only work around I can think of would be converting all the non alphanum characters into hex values and then vica versa when reading them.

e.g. Hello! -> Hello%21
Posted By: Stealth Re: $ini and entries with [ or ] - 08/01/07 03:29 PM
Originally Posted By: Jigsy
I think it's a Windows thing.

The only work around I can think of would be converting all the non alphanum characters into hex values and then vica versa when reading them.

e.g. Hello! -> Hello%21
Yes, I was thinking about doing exactly that, except just changing the brackets to (). This way they can be converted back without any confusion if they get reversed (eg, [Brackets] would be read the same as ]Brackets[)
Posted By: billythekid Re: $ini and entries with [ or ] - 08/01/07 06:48 PM
as

//echo -a $readini(test.ini, test, ]Brackets[) == 123

shows.

I'd say this is a bug then, perhaps with mirc perhaps with windows, but a bug nonetheless(unless there's some protocol with []s and .ini files that we don't know of)

could it be that a topic inside an ini has brackets so maybe items under a topic cannot, or they would be parsed as new topics

btk
Posted By: Riamus2 Re: $ini and entries with [ or ] - 08/01/07 09:49 PM
Originally Posted By: billythekid
could it be that a topic inside an ini has brackets so maybe items under a topic cannot, or they would be parsed as new topics


Exactly. You can't have [itemname] as the item in an INI file in Windows. Otherwise, windows has no way to know what is a topic and what is an item.

Without testing, I'm guessing that you also cannot have an = in the item name and you cannot have a ] in the topic name because those are used to indicate specific things in the INI file. Whether or not Windows/mIRC changes those as well as the []'s, I don't know.
© mIRC Discussion Forums