summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/shell/main_mwdump.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-10-01 20:02:34 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-10-01 20:02:34 +0000
commitcaf0e53e8f428e48f1c66e378d304f7412bd15f0 (patch)
tree538413dec54ce49ef4727a3f0db1615d1fcefa46 /cpukit/libmisc/shell/main_mwdump.c
parent2008-10-01 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-caf0e53e8f428e48f1c66e378d304f7412bd15f0.tar.bz2
2008-10-01 Gene Smith <gene.smith@siemens.com>
PR 1328/cpukit * libmisc/shell/main_mdump.c, libmisc/shell/main_mwdump.c: Fix printing of more than 256 bytes.
Diffstat (limited to 'cpukit/libmisc/shell/main_mwdump.c')
-rw-r--r--cpukit/libmisc/shell/main_mwdump.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/cpukit/libmisc/shell/main_mwdump.c b/cpukit/libmisc/shell/main_mwdump.c
index fda0a780c7..1105656814 100644
--- a/cpukit/libmisc/shell/main_mwdump.c
+++ b/cpukit/libmisc/shell/main_mwdump.c
@@ -30,30 +30,46 @@ int rtems_shell_main_mwdump(
char *argv[]
)
{
- unsigned char n, m, max=20;
- uintptr_t addr=0;
- unsigned short *pw;
- unsigned char *p;
+ unsigned char n, m;
+ int max;
+ int res;
+ uintptr_t addr = 0;
+ unsigned char *pb;
if (argc>1)
addr = rtems_shell_str2int(argv[1]);
if (argc>2) {
max = rtems_shell_str2int(argv[2]);
- max /= 16;
+ if (max <= 0) {
+ max = 1; /* print 1 item if 0 or neg. */
+ res = 0;
+ }
+ else {
+ max--;
+ res = max & 0xf;/* num bytes in last row */
+ max >>= 4; /* div by 16 */
+ max++; /* num of rows to print */
+ if (max > 20) { /* limit to 20 */
+ max = 20;
+ res = 0xf; /* 16 bytes print in last row */
+ }
+ }
+ }
+ else {
+ max = 20;
+ res = 0xf;
}
-
- if (!max)
- max = 1;
for (m=0;m<max;m++) {
printf("0x%08" PRIXPTR " ",addr);
- p = (unsigned char *) addr;
- pw = (unsigned short*) addr;
- for (n=0;n<8;n++)
- printf("%04X%c",pw[n],n==3?'-':' ');
- for (n=0;n<16;n++) {
- printf("%c",isprint(p[n])?p[n]:'.');
+ pb = (unsigned char *) addr;
+ for (n=0;n<=(m==(max-1)?res:0xf);n+=2)
+ printf("%04X%c",*((unsigned short*)(pb+n)),n==6?'-':' ');
+ for (;n<=0xf;n+=2)
+ printf(" %c", n==6?'-':' ');
+ for (n=0;n<=(m==(max-1)?res:0xf);n++) {
+ printf("%c", isprint(pb[n]) ? pb[n] : '.');
}
printf("\n");
addr += 16;