Mercurial > hg > toybox
changeset 613:4601e408223b
Longer usage line and combine ascii[] into a single string.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 26 Jun 2012 20:45:56 -0500 |
parents | 1121e0f42132 |
children | 2b40588a3d25 |
files | toys/od.c |
diffstat | 1 files changed, 6 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/toys/od.c Tue Jun 26 20:45:14 2012 -0500 +++ b/toys/od.c Tue Jun 26 20:45:56 2012 -0500 @@ -12,7 +12,7 @@ bool "od" default y help - usage: od + usage: od [-bdosxv] [-j #] [-N #] [-A arg] [-t arg] */ #include "toys.h" @@ -39,11 +39,8 @@ #define TT this.od -static const char *ascii[] = { - "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel", "bs", "ht", - "nl", "vt", "ff", "cr", "so", "si", "dle", "dc1", "dc2", "dc3", "dc4", - "nak", "syn", "etb", "can", "em", "sub", "esc", "fs", "gs", "rs", - "us", "sp"}; +static const char *ascii = "nulsohstxetceotenqackbel bs ht nl vt ff cr so si" + "deldc1dc2dc3dc4naksynetbcan emsubesc fs gs rs us sp"; static void display_line_1(char base, off_t offset, uint8_t *line, int len) { @@ -51,12 +48,9 @@ switch (base) { case 'a': { int ch = *line & 0x7f; - if (ch < sizeof(ascii)/sizeof(ascii[0])) - printf(" %3s", ascii[ch]); - else if (ch == 127) - printf(" del"); - else - printf(" %c", ch); + if (ch <= 32) printf(" %.3s", ascii+(3*ch)); + else if (ch == 127) printf(" del"); + else printf("%4c", ch); break; } case 'o': printf(" %3.3o", *line); break;