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

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

Add HAVE_CONFIG_H support to let files receive configure defines.

  • 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#include "hexdump.h"
62
63#if RTEMS_REMOVED
64FS *fshead;                             /* head of format strings */
65int blocksize;                          /* data block size */
66int exitval;                            /* final exit value */
67int length = -1;                        /* max bytes to read */
68#endif
69
70void
71rtems_shell_hexdump_exit (rtems_shell_hexdump_globals* globals, int code)
72{
73  globals->exit_code = code;
74  longjmp (globals->exit_jmp, 1);
75}
76
77static int main_hexdump(rtems_shell_hexdump_globals* globals, int argc, char *argv[]);
78
79int
80rtems_shell_main_hexdump(int argc, char *argv[])
81{
82  rtems_shell_hexdump_globals  hexdump_globals;
83  rtems_shell_hexdump_globals* globals = &hexdump_globals;
84  memset (globals, 0, sizeof (hexdump_globals));
85  vflag = FIRST;
86  ateof = 1;
87  hexdump_globals.exit_code = 1;
88  if (setjmp (hexdump_globals.exit_jmp) == 0)
89    hexdump_globals.exit_code = main_hexdump (globals, argc, argv);
90  if (curp)
91    free (curp);
92  if (savp)
93    free (savp);
94  while (fshead)
95  {
96    FS* nextfs = fshead->nextfs;
97    while (fshead->nextfu)
98    {
99      FU* nextfu = fshead->nextfu->nextfu;
100      if (fshead->nextfu->fmt)
101        free(fshead->nextfu->fmt);
102      while (fshead->nextfu->nextpr)
103      {
104        PR* nextpr = fshead->nextfu->nextpr->nextpr;
105        if (((fshead->nextfu->nextpr->flags & F_TEXT) == 0) &&
106            fshead->nextfu->nextpr->fmt)
107          free(fshead->nextfu->nextpr->fmt);
108        free(fshead->nextfu->nextpr);
109        fshead->nextfu->nextpr = nextpr;
110      }
111      free(fshead->nextfu);
112      fshead->nextfu = nextfu;
113    }
114    free(fshead);
115    fshead = nextfs;
116  }
117  if (hdstdin)
118  {
119    fclose (hdstdin);
120    free (hdstdin);
121  }
122  return hexdump_globals.exit_code;
123}
124
125int
126main_hexdump(rtems_shell_hexdump_globals* globals, int argc, char *argv[])
127{
128        FS *tfs;
129        char *p;
130
131#if RTEMS_REMOVED
132        (void)setlocale(LC_ALL, "");
133#endif
134
135        if (!(p = rindex(argv[0], 'o')) || strcmp(p, "od"))
136                newsyntax(globals, argc, &argv);
137        else
138                oldsyntax(globals, argc, &argv);
139
140        /* figure out the data block size */
141        for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) {
142                tfs->bcnt = size(globals, tfs);
143                if (blocksize < tfs->bcnt)
144                        blocksize = tfs->bcnt;
145        }
146        /* rewrite the rules, do syntax checking */
147        for (tfs = fshead; tfs; tfs = tfs->nextfs)
148                rewrite(globals, tfs);
149
150        (void)next(globals, argv);
151        display(globals);
152  exit(exitval);
153  return exitval;
154}
155
156rtems_shell_cmd_t rtems_shell_HEXDUMP_Command = {
157  "hexdump",                                                /* name */
158  "hexdump [-bcCdovx] [-e fmt] [-f fmt_file] [-n length]\n" /* usage */
159  "        [-s skip] [file ...]",
160  "files",                                                  /* topic */
161  rtems_shell_main_hexdump,                                 /* command */
162  NULL,                                                     /* alias */
163  NULL                                                      /* next */
164};
165
Note: See TracBrowser for help on using the repository browser.