Hi,
attached is an example of a possible bug in the way, [pool] saves symbols starting with a number. This seems to be a new bug, as it was working in previous versions of pool, but is not in current CVS pool.
The correct data is stored, but loading seems to go wrong.
Frank Barknecht _ ______footils.org__
_ __latest track: "scans" _ http://footils.org/cms/show/41
Hallo, Frank Barknecht hat gesagt: // Frank Barknecht wrote:
attached is an example of a possible bug in the way, [pool] saves symbols starting with a number. This seems to be a new bug, as it was working in previous versions of pool, but is not in current CVS pool.
The correct data is stored, but loading seems to go wrong.
Hm, I found, where it goes wrong:
In pool.cpp, method: "static char *ReadAtom(char *c,A *a)" there is a check if a key is a float, which also detects strings like "10x20" as floats:
// ...
// save character and set delimiter
float fres;
// first try float
if(sscanf(tmp,"%f",&fres) == 1) {
if(a) {
int ires = (int)fres; // try a cast
if(fres == ires)
flext::SetInt(*a,ires);
else
flext::SetFloat(*a,fres);
}
}
// no, it's a symbol
else {
if(a) flext::SetString(*a,tmp);
}
// ...
"sscanf(tmp,"%f",&fres)" returns "1" for all strings which *start* with a digit, even if they later include alphabetic characters.
Now, does anyone know, how to better check for real floats?
Frank Barknecht _ ______footils.org__
_ __latest track: "scans" _ http://footils.org/cms/show/41
Hi Frank, thanks for your report. It seems the only (cheap) way of storing arbitrary symbols is to escape them with " ". I've done so now - will be mirrored to the SF cvs shortly.
best greetings, Thomas
Frank Barknecht schrieb:
Hallo, Frank Barknecht hat gesagt: // Frank Barknecht wrote:
attached is an example of a possible bug in the way, [pool] saves symbols starting with a number. This seems to be a new bug, as it was working in previous versions of pool, but is not in current CVS pool.
The correct data is stored, but loading seems to go wrong.
Hm, I found, where it goes wrong:
In pool.cpp, method: "static char *ReadAtom(char *c,A *a)" there is a check if a key is a float, which also detects strings like "10x20" as floats:
// ... // save character and set delimiter
float fres; // first try float if(sscanf(tmp,"%f",&fres) == 1) { if(a) { int ires = (int)fres; // try a cast if(fres == ires) flext::SetInt(*a,ires); else flext::SetFloat(*a,fres); } } // no, it's a symbol else { if(a) flext::SetString(*a,tmp); } // ...
"sscanf(tmp,"%f",&fres)" returns "1" for all strings which *start* with a digit, even if they later include alphabetic characters.
Now, does anyone know, how to better check for real floats?
Ciao
Hallo, Thomas Grill hat gesagt: // Thomas Grill wrote:
thanks for your report. It seems the only (cheap) way of storing arbitrary symbols is to escape them with " ". I've done so now - will be mirrored to the SF cvs shortly.
Thanks for the fast reply.
Will this still allow my old preset files, which contain symbols like "10x20x40", to be loaded correctly?
I was researching the problem a bit in the meantime, and maybe "strtof" can help. This is what I have so far:
// save character and set delimiter
float fres;
char *endp;
// see if it's a float
fres = strtof(tmp,&endp);
if (endp or (endp == tmp)) {
// it's a symbol:
post("end: %s", endp);
post("tmp: %s", tmp);
if(a) flext::SetString(*a,tmp);
}
else {
if(a) {
int ires = (int)fres; // try a cast
if(fres == ires)
flext::SetInt(*a,ires);
else
flext::SetFloat(*a,fres);
}
}
This works correctly for symbols like "set a 10xxx", the only problem is, that now "set a 10" will result in "symbol 10" as result of "get a" after loading in the savefile again.
Frank Barknecht _ ______footils.org__
_ __latest track: "scans" _ http://footils.org/cms/show/41
Hi Frank,
Will this still allow my old preset files, which contain symbols like "10x20x40", to be loaded correctly?
you mean symbols containing " " characters? The symbols loaded into pool would lose these " " - that's a problem, of course. If the " " are not in the symbol, then there's no problem... the old recognition method is used then.
I was researching the problem a bit in the meantime, and maybe "strtof" can help. This is what I have so far:
It seems that strtof doesn't exist under Windows.
best greetings, Thomas
Hallo, Thomas Grill hat gesagt: // Thomas Grill wrote:
Will this still allow my old preset files, which contain symbols like "10x20x40", to be loaded correctly?
you mean symbols containing " " characters?
No, actually I mean symbols, which were saved as:
, a , 10x20x30
after a message [set a 10x20( was sent.
The symbols loaded into pool would lose these " " - that's a problem, of course. If the " " are not in the symbol, then there's no problem... the old recognition method is used then.
Ah, cool ...
I was researching the problem a bit in the meantime, and maybe "strtof" can help. This is what I have so far:
It seems that strtof doesn't exist under Windows.
Hhm, according to the man page "strtof" on Linux, it's part of the standard:
CONFORMING TO ANSI C describes strtod, C99 describes the other two functions.
Frank Barknecht _ ______footils.org__
_ __latest track: "scans" _ http://footils.org/cms/show/41
Hallo, Frank Barknecht hat gesagt: // Frank Barknecht wrote:
I was researching the problem a bit in the meantime, and maybe "strtof" can help. This is what I have so far:
And I almost got it!
// save character and set delimiter float fres; char *endp; // see if it's a float fres = strtof(tmp,&endp); if (endp or (endp == tmp)) {
Above line should be: if (*endp or (endp == tmp)) {
After this change, now in my short tests floats and symbols seem to be correctly indentified on load. Lists also still work.
Frank Barknecht _ ______footils.org__
_ __latest track: "scans" _ http://footils.org/cms/show/41
Hallo, Frank Barknecht hat gesagt: // Frank Barknecht wrote:
After this change, now in my short tests floats and symbols seem to be correctly indentified on load. Lists also still work.
However, as strtof and strtod also parse hex-numbers like 0x200 my change needs further changes, because "set a 0x200" will save "a" as "512". ;)
Frank Barknecht _ ______footils.org__
_ __latest track: "scans" _ http://footils.org/cms/show/41
After this change, now in my short tests floats and symbols seem to be correctly indentified on load. Lists also still work.
However, as strtof and strtod also parse hex-numbers like 0x200 my change needs further changes, because "set a 0x200" will save "a" as "512". ;)
Hmmm, my (small) change is already in the SF CVS and should be ok for all symbols saved by pool. I'll try to adopt your findings later, if still necessary.
many thanks, Thomas
Hallo, Thomas Grill hat gesagt: // Thomas Grill wrote:
Hmmm, my (small) change is already in the SF CVS and should be ok for all symbols saved by pool. I'll try to adopt your findings later, if still necessary.
I tested your version now, however it is as I feared:
When I try to load older .dat files, which contain symbols like 10x20x30 *without* quotes around them, then those are not loaded correctly.
I would need to convert my old files to use the quoting, which would be possible with a bit of scripting, but I'd rather avoid this. So for now, or rather for my LAC concert next weekend, I guess I will just use the "strtod" solution I posted, which is compatible with my old preset files.
Frank Barknecht _ ______footils.org__
_ __latest track: "scans" _ http://footils.org/cms/show/41
When I try to load older .dat files, which contain symbols like 10x20x30 *without* quotes around them, then those are not loaded correctly.
Yes, this is true
I would need to convert my old files to use the quoting, which would be possible with a bit of scripting, but I'd rather avoid this. So for now, or rather for my LAC concert next weekend, I guess I will just use the "strtod" solution I posted, which is compatible with my old preset files.
Well if it works also with the pseudo-hex numbers i'll gladly adopt it.
best greetings, Thomas