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

4.104.11
Last change on this file since c648ca5 was c648ca5, checked in by Ralf Corsepius <ralf.corsepius@…>, on Mar 26, 2010 at 5:42:24 PM

Add HAVE_STRINGS_H for better POSIX compliance.

  • 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#ifdef HAVE_STRINGS_H
62#include <strings.h>
63#endif
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
82int
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.