Page 1 of 1

Confused, can't read INI value correctly

Posted: 16 Jun 2014 07:36
by bdeshi
INI:

Code: Select all

[vars]
path=<xyscripts>\xyskins
script:

Code: Select all

...
 $path=getkey(path,vars, "path\to\file.ini");
 new("$path\res\some.file", file);
Doesn't work. (neither with any other SC in fact) Why?

If I use the actual value within the script as : $path="<xyscripts>\xyskins" then it works. But again doesn't work if the ini value is quoted (path='<xyscripts>\xyskins' path="<xyscripts>\xyskins")
Please help.

Re: Confused, can't read INI value correctly

Posted: 16 Jun 2014 08:02
by binocular222
You forgot the quote

Code: Select all

$path=getkey("path","vars", "path\to\file.ini");

Re: Confused, can't read INI value correctly

Posted: 16 Jun 2014 08:19
by bdeshi
Nope, it's the same with quotes in getkey... :(

Re: Confused, can't read INI value correctly

Posted: 16 Jun 2014 09:02
by highend
Doesn't work means: The <xyscripts> variable isn't resolved?

I've had similiar issues with windows environment variables yesterday and I've had to use eval() to do that...
In fact my paths weren't resolved if they contained more than just the environment variable, I even had to
do this...

Code: Select all

            $envVarList = regexmatches($item, "%[^%]+%", "|");
            foreach($envVar, $envVarList, "|") {
                $item = replace($item, $envVar, eval($envVar));
Can't remember that I had the same issues in the past so maybe a regression?

Re: Confused, can't read INI value correctly

Posted: 16 Jun 2014 09:04
by Filehero
SammaySarkar wrote:Nope, it's the same with quotes in getkey... :(
Single or double quotes? Have you tested bino's line exactly as it was quoted?

I am asking because
SammaySarkar wrote:...But again doesn't work if the ini value is quoted (path='<xyscripts>\xyskins')
doesn't work as you obviously expect since single quotes are defined to prevent XY vars to be evaluated.

Try this

Code: Select all

$path_1="<xyscripts>\xyskins";
 $path_2='<xyscripts>\xyskins';
 msg($path_1<br>$path_2);
/e: slightly too late - but it's a different flavor.

Cheers,
Filehero

Re: Confused, can't read INI value correctly

Posted: 16 Jun 2014 09:10
by bdeshi
@Filehero, that was a posting typo, I used "s in script.
@highend, yes, <xyscripts> isn't resolved. I also tried eval() but it gave an "overflow 0/0" error.

Re: Confused, can't read INI value correctly

Posted: 16 Jun 2014 09:19
by highend

Code: Select all

I also tried eval() but it gave an "overflow 0/0" error.
Because you've had more than the variable itself in the .ini file for "path" (the "\xyskins" part)

I guess it's a bug.

Until Don fixes it you could use:

Code: Select all

    $path = getkey("path","vars", "<xyscripts>\file.ini");
    $envVarList = regexmatches($path, "<[^>]+>", "|");
    foreach($envVar, $envVarList, "|") {
        $path = replace($path, $envVar, eval($envVar));
    }
    text $path;

Re: Confused, can't read INI value correctly

Posted: 16 Jun 2014 09:30
by bdeshi
Sure looks like a bug.
Thanks for the alt fix. But I only have a few fixed variables, so replacelist should be faster than foreach+regex, right?

Code: Select all

$path = replacelist($path, '<xyscripts>|<xydata>…', "<xyscripts>|<xydata>…");

Re: Confused, can't read INI value correctly

Posted: 16 Jun 2014 09:53
by highend
But I only have a few fixed variables, so replacelist should be faster than foreach+regex, right?
Absolutely. In my case I didn't want to populate a list with > 20 environment variables manually :)

Don't forget to add the separator "|" to your replacelist() command^^

Re: Confused, can't read INI value correctly

Posted: 16 Jun 2014 09:55
by bdeshi
Right, thanks again!

Re: Confused, can't read INI value correctly

Posted: 16 Jun 2014 13:30
by TheQwerty
This is where the reprocess parameter of set comes in handy (and it also works with environment variables):

Code: Select all

set $path, getkey('path','vars', 'path\to\file.ini'), 'r';
 new("$path\res\some.file", file);

Re: Confused, can't read INI value correctly

Posted: 16 Jun 2014 13:39
by bdeshi
Yes, I'd tried this too while trying to solve:

Code: Select all

 $path = getkey("path", "vars", "path\to\file,ini");
 new("$path\res\some.file", file);
But in this case, the $path variable's value turns into the full path of <xyscripts>\Xyskins. I needed to keep it in the short form (for portability).
with "r": $path="C:\path\to\xyplorer\xydata\scripts\xyskins"
need to keep: $path="<xyscripts>\xyskins" and expand <xyscripts> ONLY where $path is used.
I'm going to either use highend's solution or just hardcode the path.

Re: Confused, can't read INI value correctly

Posted: 16 Jun 2014 13:45
by TheQwerty
Then only use a reprocessing set right before using $path or combine it with a reversed ResolvePath to keep it relative to <xyscripts>.