source: rtems/cpukit/libmisc/shell/main_mdump.c @ 9a77af8

4.104.115
Last change on this file since 9a77af8 was 0893220, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/29/09 at 12:12:39

Whitespace removal.

  • Property mode set to 100644
File size: 2.2 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 char  n;
35  unsigned char  m;
36  int            max;
37  int            res;
38  void          *addr = NULL;
39  unsigned char *pb;
40
41  if (argc > 1) {
42    if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) {
43      printf( "Address argument (%s) is not a number\n", argv[1] );
44      return -1;
45    }
46
47  }
48
49  if (argc > 2) {
50    if ( rtems_string_to_int(argv[1], &max, NULL, 0) ) {
51      printf( "Length argument (%s) is not a number\n", argv[1] );
52      return -1;
53    }
54    if (max <= 0) {
55      max = 1;      /* print 1 item if 0 or neg. */
56      res = 0;
57    } else {
58      max--;
59      res = max & 0xf;/* num bytes in last row */
60      max >>= 4;      /* div by 16 */
61      max++;          /* num of rows to print */
62      if (max > 20) { /* limit to 20 */
63        max = 20;
64        res = 0xf;    /* 16 bytes print in last row */
65      }
66    }
67  } else {
68    max = 20;
69    res = 0xf;
70  }
71
72  pb = addr;
73  for (m=0; m<max; m++) {
74    printf("%10p ", pb);
75    for (n=0;n<=(m==(max-1)?res:0xf);n++)
76      printf("%02X%c",pb[n],n==7?'-':' ');
77    for (;n<=0xf;n++)
78      printf("  %c",n==7?'-':' ');
79    for (n=0;n<=(m==(max-1)?res:0xf);n++) {
80      printf("%c", isprint(pb[n]) ? pb[n] : '.');
81    }
82    printf("\n");
83    pb += 16;
84  }
85  return 0;
86}
87
88rtems_shell_cmd_t rtems_shell_MDUMP_Command = {
89  "mdump",                                      /* name */
90  "mdump [address [length]]",                   /* usage */
91  "mem",                                        /* topic */
92  rtems_shell_main_mdump,                       /* command */
93  NULL,                                         /* alias */
94  NULL                                          /* next */
95};
96
Note: See TracBrowser for help on using the repository browser.