source: rtems/cpukit/libmisc/shell/main_mdump.c @ 35d09ba

4.104.115
Last change on this file since 35d09ba was 35d09ba, checked in by Joel Sherrill <joel.sherrill@…>, on 07/22/09 at 15:17:37

2009-07-22 Joel Sherrill <joel.sherrill@…>

  • libmisc/Makefile.am, libmisc/shell/main_chmod.c, libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c, libmisc/shell/main_mfill.c, libmisc/shell/main_mmove.c, libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c, libmisc/shell/main_sleep.c, libmisc/shell/main_umask.c, libmisc/shell/shell.h, libmisc/shell/shell_script.c, libmisc/stringto/stringto_template.h: Convert all shell code to use stringto.h mehods with better error checking.
  • libmisc/shell/str2int.c: Removed.
  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  MDUMP Shell Command Implmentation
3 *
4 *  Author: Fernando RUIZ CASAS
5 *  Work: fernando.ruiz@ctv.es
6 *  Home: correo@fernando-ruiz.com
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <ctype.h>
20#include <stdio.h>
21#include <inttypes.h>
22#include <string.h>
23
24#include <rtems.h>
25#include <rtems/shell.h>
26#include <rtems/stringto.h>
27#include "internal.h"
28
29int rtems_shell_main_mdump(
30  int   argc,
31  char *argv[]
32)
33{
34  unsigned long  tmp;
35  unsigned char  n;
36  unsigned char  m;
37  int            max;
38  int            res;
39  uintptr_t      addr = 0;
40  unsigned char *pb;
41
42  if (argc > 1) {
43    if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
44      printf( "Address argument (%s) is not a number\n", argv[1] );
45      return -1;
46    }
47    addr = (uintptr_t) tmp;
48
49  }
50
51  if (argc>2) {
52    if ( !rtems_string_to_int(argv[1], &max, NULL, 0) ) {
53      printf( "Length argument (%s) is not a number\n", argv[1] );
54      return -1;
55    }
56    addr = (uintptr_t) tmp;
57    if (max <= 0) {
58      max = 1;      /* print 1 item if 0 or neg. */
59      res = 0;
60    }
61    else {
62      max--;
63      res = max & 0xf;/* num bytes in last row */
64      max >>= 4;      /* div by 16 */
65      max++;          /* num of rows to print */
66      if (max > 20) { /* limit to 20 */
67        max = 20;
68        res = 0xf;    /* 16 bytes print in last row */
69      }
70    }
71  }
72  else {
73    max = 20;
74    res = 0xf;
75  }
76
77  for (m=0; m<max; m++) {
78    pb = (unsigned char*) addr;
79    printf("%p ", pb);
80    for (n=0;n<=(m==(max-1)?res:0xf);n++)
81      printf("%02X%c",pb[n],n==7?'-':' ');
82    for (;n<=0xf;n++)
83      printf("  %c",n==7?'-':' ');
84    for (n=0;n<=(m==(max-1)?res:0xf);n++) {
85      printf("%c", isprint(pb[n]) ? pb[n] : '.');
86    }
87    printf("\n");
88    addr += 16;
89  }
90  return 0;
91}
92
93rtems_shell_cmd_t rtems_shell_MDUMP_Command = {
94  "mdump",                                      /* name */
95  "mdump [address [length]]",                   /* usage */
96  "mem",                                        /* topic */
97  rtems_shell_main_mdump,                       /* command */
98  NULL,                                         /* alias */
99  NULL                                          /* next */
100};
101
Note: See TracBrowser for help on using the repository browser.