Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

y_ini - name[] parameter contains an empty string for single character keys #192

Closed
spacemud opened this issue Aug 7, 2017 · 7 comments
Closed
Labels

Comments

@spacemud
Copy link
Contributor

spacemud commented Aug 7, 2017

I'm trying to loop through the keys of an INI file using the name[] parameter. For keys of a single character the parameter contains an empty string instead of the key. Interestingly, reading the key using INI_String works fine.

name:  value: test
name:  value: test
name:  value: test
name: ab value: test
name: bc value: test
name: cd value: test
a: test
ab: test

Code used:

#include <YSI\y_ini>

new
    gA[8],
    gAB[8];

main()
{
    INI_Load("test.ini");

    printf("a: %s", gA);
    printf("ab: %s", gAB);

    return 1;
}

INI:test[](name[], value[])
{
    printf("name: %s value: %s", name, value);

    INI_String("a", gA);
    INI_String("ab", gAB);

    return 1;
}

.ini file:

a=test
b=test
c=test
ab=test
bc=test
cd=test
@Y-Less
Copy link
Member

Y-Less commented Aug 7, 2017

I thought I already replied to this, apparently not...

INI_String uses strcmp internally, which returns 0 when one string is empty*, so I suspect if you use different values in your test file, not just "test" everywhere, you will see that it actually doesn't work correctly.

As for why name is empty, I don't know, but thanks.

* Some people call this a bug, I'm not certain as it is well documented behaviour, just not what they expect by just thinking that all the function does is check if two strings are the same, which is not all it does, but anyway...

@Misiur Misiur added the bug label Sep 22, 2017
@Misiur
Copy link
Collaborator

Misiur commented Sep 22, 2017

Looking into it

@Misiur
Copy link
Collaborator

Misiur commented Sep 22, 2017

#225

@Misiur Misiur closed this as completed Sep 22, 2017
@Misiur Misiur reopened this Oct 3, 2017
@Misiur
Copy link
Collaborator

Misiur commented Oct 3, 2017

I screwed up this one, this catches key names including padding before the =. I reverted the commit, and I'll look again how to make it work as intended

@Y-Less
Copy link
Member

Y-Less commented Oct 8, 2017

I fixed this. However, it is with a load of other commits, so I can't push just yet until the code all compiles correctly. For reference:

 YSI_Storage/y_ini/reading.inc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/YSI_Storage/y_ini/reading.inc b/YSI_Storage/y_ini/reading.inc
index b8260cd..6180a03 100644
--- a/YSI_Storage/y_ini/reading.inc
+++ b/YSI_Storage/y_ini/reading.inc
@@ -470,6 +470,8 @@ stock e_INI_LINE_TYPE:
 		case '=': return e_INI_LINE_TYPE_INVALID;
 		default: p0s = pos - 1;
 	}
+	// Default end point, for single-character lines.
+	end = pos;
 //state_in_entry: // Default (fall-through).
 	// Get the key.
 	for ( ; ; )

@Y-Less
Copy link
Member

Y-Less commented Oct 8, 2017

I don't know if single character tags were a problem, but maybe, and this should do them as well.

@Y-Less
Copy link
Member

Y-Less commented Oct 8, 2017

Actually, no it won't, but I think they worked anyway looking at the code.

@Y-Less Y-Less closed this as completed in bada721 Oct 9, 2017
Y-Less added a commit that referenced this issue Oct 29, 2017
Misiur added a commit that referenced this issue Dec 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants