From e2df0883bd0e97277ce4f3c7131377158ea4c769 Mon Sep 17 00:00:00 2001 From: brad Date: Sat, 23 Oct 2010 23:31:49 +0000 Subject: [PATCH] --- utils/ushow/Makefile | 3 ++ utils/ushow/ushow.c | 120 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 109 insertions(+), 14 deletions(-) diff --git a/utils/ushow/Makefile b/utils/ushow/Makefile index 573b2e3..4c708a9 100644 --- a/utils/ushow/Makefile +++ b/utils/ushow/Makefile @@ -1,3 +1,6 @@ +# + +all: ushow ushow: ushow.c cc -o ushow ushow.c diff --git a/utils/ushow/ushow.c b/utils/ushow/ushow.c index 1143766..15610c7 100644 --- a/utils/ushow/ushow.c +++ b/utils/ushow/ushow.c @@ -8,28 +8,120 @@ */ #include +#include int c; -char b[1024]; +char b[1024*16]; -void add(int v) +int show_cummulative = 0; +int show_rx = 0; +int show_int = 0; + +void show(void) { - b[c++] = v & 0x7f; - b[c] = 0; - printf("output: %s\n", b); + printf("\n-------\noutput: %s\n", b); + printf("\n"); fflush(stdout); } -main() +void show_part(void) { - char line[1024]; + printf("%s", b); + fflush(stdout); + c = 0; +} - while (fgets(line, sizeof(line), stdin)) { - if (memcmp(&line[4], "tx_data ", 8) == 0) { - char s1[256], s2[256]; - int v; - sscanf(line, "%s %s %o", s1, s2, &v); - add(v); - } +void add_int(void) +{ + b[c++] = '*'; + b[c] = 0; + if (show_cummulative) { + show_part(); } } + +void add_rx(int v) +{ + v &= 0x7f; + b[c++] = '['; + if (v >= ' ') + b[c++] = v; + else { + c += sprintf(&b[c], "\\%03o", v); + } + b[c++] = ']'; + b[c] = 0; + if (show_cummulative) { + show_part(); + } +} + +void add(int v) +{ + v &= 0x7f; + if (v == 0) v = '@'; + b[c++] = v; + b[c] = 0; + if (show_cummulative) { + show_part(); + } +} + +main(int argc, char *argv[]) +{ + char line[1024]; + int i; + + for (i = 1; i < argc; i++) { + if (argv[i][0] == '-') + switch (argv[i][1]) { + case 's': show_cummulative = 1; break; + case 'r': show_rx = 1; break; + case 'i': show_int = 1; break; + } + } + + while (fgets(line, sizeof(line), stdin)) { + int v; + + if (memcmp(&line[4], "tx_data ", 8) == 0) { + sscanf(line, "xxx tx_data %o", &v); + add(v); + } + +#if 0 + if (memcmp(&line[4], "rx_data ", 8) == 0) { + sscanf(line, "xxx rx_data %o", &v); + if (show_rx) + add_rx(v); + } +#else + if (memcmp(&line[4], "dispense ", 9) == 0) { + sscanf(line, "xxx dispense %o", &v); + if (show_rx) + add_rx(v); + } +#endif + if (memcmp(&line[4], "interrupt", 9) == 0) { + if (show_int) + add_int(); + } + + + if (memcmp(&line[4], "rx input ", 9) == 0) { + sscanf(line, "xxx rx input %o", &v); + if (show_rx) + add_rx(v); + } + if (memcmp(&line[4], "int_req ", 8) == 0) { + if (show_int) + add_int(); + } + if (memcmp(line, "reset on", 8) == 0) { + c = 0; + printf("\n"); + } + } + + show(); +}