source: rtems/cpukit/libmisc/shell/main_hexdump.c @ c499856

4.115
Last change on this file since c499856 was 3421e520, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/04/11 at 10:22:51
  • libmisc/shell/main_help.c: Make rtems_shell_help_cmd, rtems_shell_help static.
  • libmisc/shell/main_hexdump.c: Make main_hexdump static.
  • libmisc/shell/main_id.c: Make rtems_shell_main_id static.
  • libmisc/shell/main_ifconfig.c: Make rtems_shell_main_ifconfig static.
  • libmisc/shell/main_ln.c: Make rtems_shell_main_ln static.
  • libmisc/shell/main_logoff.c: Make rtems_shell_main_logoff static.
  • libmisc/shell/main_ls.c: Make rtems_shell_main_ls static.
  • libmisc/shell/main_mallocinfo.c: Include <rtems/libcsupport.h>. Remove private decls of malloc_info, rtems_shell_print_unified_work_area_message. Make rtems_shell_main_malloc_info static.
  • libmisc/shell/main_medit.c: Remove private decl of rtems_shell_main_mdump. Make rtems_shell_main_medit static.
  • libmisc/shell/main_mfill.c: Make rtems_shell_main_mfill static.
  • libmisc/shell/main_mkdir.c: Make rtems_shell_main_mkdir static.
  • libmisc/shell/main_mknod.c: Make rtems_shell_main_mknod static.
  • libmisc/shell/main_mmove.c: Remove private decl of rtems_shell_main_mdump. Make rtems_shell_main_mmove static.
  • libmisc/shell/main_mount.c: Make rtems_shell_main_mount static.
  • libmisc/shell/main_msdosfmt.c: Make rtems_shell_main_msdos_format static.
  • libmisc/shell/main_mv.c: Include "internal.h". Make rtems_shell_mv_exit, rtems_shell_main_mv static. Remove private decls of strmode rtems_shell_main_cp, rtems_shell_main_rm.
  • libmisc/shell/main_mwdump.c: Make rtems_shell_main_mwdump static.
  • libmisc/shell/main_netstats.c: Make rtems_shell_main_netstats static.
  • libmisc/shell/main_perioduse.c: Make rtems_shell_main_perioduse static.
  • libmisc/shell/main_pwd.c: Make rtems_shell_main_pwd static.
  • libmisc/shell/main_rm.c: Include "internal.h". Make rtems_shell_rm_exit static. Remove private decl of strmode.
  • libmisc/shell/main_rmdir.c: Make rtems_shell_main_rmdir static. libmisc/shell/main_route.c: Make rtems_shell_main_route static.
  • libmisc/shell/main_setenv.c: Make rtems_shell_main_setenv static.
  • libmisc/shell/main_sleep.c: Make rtems_shell_main_sleep static.
  • libmisc/shell/main_stackuse.c: Make rtems_shell_main_stackuse static.
  • libmisc/shell/main_time.c: Make rtems_shell_main_time static.
  • libmisc/shell/main_tty.c: Make rtems_shell_main_tty static.
  • libmisc/shell/main_umask.c: Make rtems_shell_main_umask static.
  • libmisc/shell/main_unmount.c: Make rtems_shell_main_unmount static.
  • libmisc/shell/main_unsetenv.c: Make rtems_shell_main_unsetenv static.
  • libmisc/shell/main_whoami.c: Make rtems_shell_main_whoami static.
  • libmisc/shell/main_wkspaceinfo.c: Make rtems_shell_main_wkspace_info static.
  • Property mode set to 100644
File size: 5.2 KB
Line 
1/*
2 * Copyright (c) 1989, 1993
3 *      The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by the University of
16 *      California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if HAVE_CONFIG_H
35#include "config.h"
36#endif
37
38#ifndef lint
39static const char copyright[] =
40"@(#) Copyright (c) 1989, 1993\n\
41        The Regents of the University of California.  All rights reserved.\n";
42#endif /* not lint */
43
44#ifndef lint
45#if 0
46static char sccsid[] = "@(#)hexdump.c   8.1 (Berkeley) 6/6/93";
47#include <sys/cdefs.h>
48__FBSDID("$FreeBSD: src/usr.bin/hexdump/hexdump.c,v 1.7 2002/09/04 23:29:01 dwmalone Exp $");
49#endif
50#endif /* not lint */
51
52#include <rtems.h>
53#include <rtems/shell.h>
54#include <rtems/shellconfig.h>
55
56#include <sys/types.h>
57#include <locale.h>
58#include <stdlib.h>
59#include <stdio.h>
60#include <string.h>
61
62#define rindex(s,c)     strrchr(s,c)
63
64#include "hexdump.h"
65
66#if RTEMS_REMOVED
67FS *fshead;                             /* head of format strings */
68int blocksize;                          /* data block size */
69int exitval;                            /* final exit value */
70int length = -1;                        /* max bytes to read */
71#endif
72
73void
74rtems_shell_hexdump_exit (rtems_shell_hexdump_globals* globals, int code)
75{
76  globals->exit_code = code;
77  longjmp (globals->exit_jmp, 1);
78}
79
80static int main_hexdump(rtems_shell_hexdump_globals* globals, int argc, char *argv[]);
81
82static int
83rtems_shell_main_hexdump(int argc, char *argv[])
84{
85  rtems_shell_hexdump_globals  hexdump_globals;
86  rtems_shell_hexdump_globals* globals = &hexdump_globals;
87  memset (globals, 0, sizeof (hexdump_globals));
88  vflag = FIRST;
89  ateof = 1;
90  hexdump_globals.exit_code = 1;
91  if (setjmp (hexdump_globals.exit_jmp) == 0)
92    hexdump_globals.exit_code = main_hexdump (globals, argc, argv);
93  if (curp)
94    free (curp);
95  if (savp)
96    free (savp);
97  while (fshead)
98  {
99    FS* nextfs = fshead->nextfs;
100    while (fshead->nextfu)
101    {
102      FU* nextfu = fshead->nextfu->nextfu;
103      if (fshead->nextfu->fmt)
104        free(fshead->nextfu->fmt);
105      while (fshead->nextfu->nextpr)
106      {
107        PR* nextpr = fshead->nextfu->nextpr->nextpr;
108        if (((fshead->nextfu->nextpr->flags & F_TEXT) == 0) &&
109            fshead->nextfu->nextpr->fmt)
110          free(fshead->nextfu->nextpr->fmt);
111        free(fshead->nextfu->nextpr);
112        fshead->nextfu->nextpr = nextpr;
113      }
114      free(fshead->nextfu);
115      fshead->nextfu = nextfu;
116    }
117    free(fshead);
118    fshead = nextfs;
119  }
120  if (hdstdin)
121  {
122    fclose (hdstdin);
123    free (hdstdin);
124  }
125  return hexdump_globals.exit_code;
126}
127
128int
129main_hexdump(rtems_shell_hexdump_globals* globals, int argc, char *argv[])
130{
131        FS *tfs;
132        char *p;
133
134#if RTEMS_REMOVED
135        (void)setlocale(LC_ALL, "");
136#endif
137
138        if (!(p = rindex(argv[0], 'o')) || strcmp(p, "od"))
139                newsyntax(globals, argc, &argv);
140        else
141                oldsyntax(globals, argc, &argv);
142
143        /* figure out the data block size */
144        for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) {
145                tfs->bcnt = size(globals, tfs);
146                if (blocksize < tfs->bcnt)
147                        blocksize = tfs->bcnt;
148        }
149        /* rewrite the rules, do syntax checking */
150        for (tfs = fshead; tfs; tfs = tfs->nextfs)
151                rewrite(globals, tfs);
152
153        (void)next(globals, argv);
154        display(globals);
155  exit(exitval);
156  return exitval;
157}
158
159rtems_shell_cmd_t rtems_shell_HEXDUMP_Command = {
160  "hexdump",                                                /* name */
161  "hexdump [-bcCdovx] [-e fmt] [-f fmt_file] [-n length]\n" /* usage */
162  "        [-s skip] [file ...]",
163  "files",                                                  /* topic */
164  rtems_shell_main_hexdump,                                 /* command */
165  NULL,                                                     /* alias */
166  NULL                                                      /* next */
167};
168
Note: See TracBrowser for help on using the repository browser.