Author: jmb
Date: Fri Jan 23 14:44:32 2009
New Revision: 6193
URL: http://source.netsurf-browser.org?rev=6193&view=rev
Log:
Use our own fixed point value printing routine rather than relying on sprintf's
%f modifier to do the right thing
Modified:
trunk/libcss/test/dump.h
Modified: trunk/libcss/test/dump.h
URL:
http://source.netsurf-browser.org/trunk/libcss/test/dump.h?rev=6193&r1=6192&r2=6193&view=diff
==============================================================================
--- trunk/libcss/test/dump.h (original)
+++ trunk/libcss/test/dump.h Fri Jan 23 14:44:32 2009
@@ -319,12 +319,67 @@
*/
static const char *sides[] = { "top", "right", "bottom", "left" };
+static void dump_fixed(fixed f, char **ptr)
+{
+#define ABS(x) ((x) < 0 ? -(x) : (x))
+ uint32_t uintpart = FIXTOINT(ABS(f));
+ uint32_t fracpart = ((ABS(f) & 0x3ff) * 1000) / (1 << 10);
+#undef ABS
+ size_t flen = 0;
+ char tmp[20];
+ size_t tlen = 0;
+ char *buf = *ptr;
+
+ if (f < 0) {
+ buf[0] = '-';
+ buf++;
+ }
+
+ do {
+ tmp[tlen] = "0123456789"[uintpart % 10];
+ tlen++;
+
+ uintpart /= 10;
+ } while (tlen < 20 && uintpart != 0);
+
+ while (tlen > 0) {
+ buf[0] = tmp[--tlen];
+ buf++;
+ }
+
+ buf[0] = '.';
+ buf++;
+
+ do {
+ tmp[tlen] = "0123456789"[fracpart % 10];
+ tlen++;
+
+ fracpart /= 10;
+ } while (tlen < 20 && fracpart != 0);
+
+ while (tlen > 0) {
+ buf[0] = tmp[--tlen];
+ buf++;
+ flen++;
+ }
+
+ while (flen < 3) {
+ buf[0] = '0';
+ buf++;
+ flen++;
+ }
+
+ buf[0] = '\0';
+
+ *ptr = buf;
+}
+
static void dump_number(fixed val, char **ptr)
{
if (INTTOFIX(FIXTOINT(val)) == val)
*ptr += sprintf(*ptr, "%d", FIXTOINT(val));
else
- *ptr += sprintf(*ptr, "%f", FIXTOFLT(val));
+ dump_fixed(val, ptr);
}
static void dump_unit(fixed val, uint32_t unit, char **ptr)
_______________________________________________
netsurf-commits mailing list
[email protected]
http://vlists.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org