[PATCH] Flesh out the UDDF xml parsing a bit more
Linus Torvalds
torvalds at linux-foundation.org
Fri Feb 22 16:18:39 PST 2013
Commit 28aba5a2062c ("Flesh out the UDDF xml parsing a bit more")
improved on parsing UDDF files by teaching "percent()" to also handle
pure fractions like UDDF uses. So in a UDDF file, an o2 value of "1.0"
means "100%".
But it turns out that I have a few dives with "1% He", and the "Turn
fractions into percent" logic also turns that into 100%.
So this makes the 'percent()' function a bit smarter. If it actually
finds a percentage-sign after the number, it knows it is already
percent, not a fraction. That disambiguates the two cases: "1.0" is
100%, but "1.0%" (note the explicit percentage sign) is 1%.
So now our native format cannot get confused, because it generally
tries to avoid naked numbers. Good choice.
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---
On Fri, Feb 22, 2013 at 9:04 AM, Linus Torvalds
<torvalds at linux-foundation.org> wrote:
>
> @@ -342,6 +351,10 @@ static void percent(char *buffer, void *_fraction)
>
> switch (integer_or_float(buffer, &val)) {
> case FLOAT:
> + /* Turn fractions into percent.. */
> + if (val.fp <= 1.0)
> + val.fp *= 100;
> + /* Then turn percent into our integer permille format */
> if (val.fp <= 100.0)
> fraction->permille = val.fp * 10 + 0.5;
> break;
Ugh. This part was the one that broke native format.
The attached patch is a bit bigger, but that's largely because it adds
that new helper function to parse floats and makes our old
integer_or_float() (that doesn't return the required finishing part)
use the new helper function. And the new helper function doesn't have
that odd historical union thing).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: application/octet-stream
Size: 2038 bytes
Desc: not available
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20130222/c6b51f13/attachment.obj>
More information about the subsurface
mailing list