# HG changeset patch # User Rob Landley # Date 1342245572 18000 # Node ID 93ef2516f15a939d845606c9687b8f04b5ea2aca # Parent 488032f4394a4dba3d0de67ef21dabb54f910c1f Fill out od -c and -f. diff -r 488032f4394a -r 93ef2516f15a toys/od.c --- a/toys/od.c Wed Jul 11 20:59:17 2012 -0500 +++ b/toys/od.c Sat Jul 14 00:59:32 2012 -0500 @@ -96,6 +96,7 @@ t = types+i; while (jtype < 2) { @@ -108,19 +109,35 @@ else if (c==127) strcpy(buf, "del"); else sprintf(buf, "%c", c); } else { - char *bfnrt = "\b\f\n\r\t", *s = strchr(bfnrt, c); - if (s) sprintf(buf, "\\%c", "bfnrt0"[s-bfnrt]); + char *bfnrtav = "\b\f\n\r\t\a\v", *s = strchr(bfnrtav, c); + if (s) sprintf(buf, "\\%c", "bfnrtav0"[s-bfnrtav]); + else if (c < 32 || c >= 127) sprintf(buf, "%03o", c); else { // TODO: this should be UTF8 aware. sprintf(buf, "%c", c); } } } else if (CFG_TOYBOX_FLOAT && t->type == 6) { - // TODO: floating point stuff + long double ld; + union {float f; double d; long double ld;} fdl; + + memcpy(&fdl, TT.buf+j, t->size); + j += t->size; + if (sizeof(float) == t->size) { + ld = fdl.f; + pad += (throw = 8)+7; + } else if (sizeof(double) == t->size) { + ld = fdl.d; + pad += (throw = 17)+8; + } else if (sizeof(long double) == t->size) { + ld = fdl.ld; + pad += (throw = 21)+9; + } else error_exit("bad -tf '%d'", t->size); + + sprintf(buf, "%.*Le", throw, ld); // Integer types } else { unsigned long long ll = 0, or; - int throw = 0; char *c[] = {"%*lld", "%*llu", "%0*llo", "%0*llx"}, *class = c[t->type-2];