aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-07-14 00:59:32 -0500
committerRob Landley <rob@landley.net>2012-07-14 00:59:32 -0500
commitf96fe64b1ed0ffa7bd7c954de3e1b14104d5bac6 (patch)
treea02dff236045d9e0584d9f81b27ea922099c73aa
parent4625d5e9d261d1231ad08cd6d2b7e7e4ba5b87f4 (diff)
downloadtoybox-f96fe64b1ed0ffa7bd7c954de3e1b14104d5bac6.tar.gz
Fill out od -c and -f.
-rw-r--r--toys/od.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/toys/od.c b/toys/od.c
index 7ac468e3..dfde4440 100644
--- a/toys/od.c
+++ b/toys/od.c
@@ -96,6 +96,7 @@ static void od_outline(void)
t = types+i;
while (j<len) {
unsigned k;
+ int throw = 0;
// Handle ascii
if (t->type < 2) {
@@ -108,19 +109,35 @@ static void od_outline(void)
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];