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

4.104.115
Last change on this file since 9a77af8 was 9a77af8, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/26/10 at 17:18:43

Add HAVE_CONFIG_H support to let files receive configure defines.

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[e4a3d93]1/*-
2 * Copyright (c) 1990, 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
[9a77af8]34#ifdef HAVE_CONFIG_H
35#include "config.h"
36#endif
37
[e4a3d93]38#ifndef lint
39#if 0
40static char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 5/4/95";
41#include <sys/cdefs.h>
42__FBSDID("$FreeBSD: src/usr.bin/hexdump/hexsyntax.c,v 1.12 2002/09/04 23:29:01 dwmalone Exp $");
43#endif
44#endif /* not lint */
45
46#include <sys/types.h>
47
48#include <err.h>
49#include <stdio.h>
50#include <stdlib.h>
51#include <string.h>
52#include <unistd.h>
53
54#include "hexdump.h"
55
56#define __need_getopt_newlib
57#include <getopt.h>
58
59#if RTEMS_REMOVED
60off_t skip;                             /* bytes to skip */
61#endif
62
63void
64newsyntax(rtems_shell_hexdump_globals* globals, int argc, char ***argvp)
65{
66        int ch;
67        char *p, **argv;
68
69  struct getopt_data getopt_reent;
[0893220]70  memset(&getopt_reent, 0, sizeof(getopt_data));
[e4a3d93]71
72        argv = *argvp;
73        if ((p = rindex(argv[0], 'h')) != NULL &&
74            strcmp(p, "hd") == 0) {
75                /* "Canonical" format, implies -C. */
76                add(globals, "\"%08.8_Ax\n\"");
77                add(globals, "\"%08.8_ax  \" 8/1 \"%02x \" \"  \" 8/1 \"%02x \" ");
78                add(globals, "\"  |\" 16/1 \"%_p\" \"|\\n\"");
79        }
80        while ((ch = getopt_r(argc, argv, "bcCde:f:n:os:vx", &getopt_reent)) != -1)
81                switch (ch) {
82                case 'b':
83                        add(globals, "\"%07.7_Ax\n\"");
84                        add(globals, "\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
85                        break;
86                case 'c':
87                        add(globals, "\"%07.7_Ax\n\"");
88                        add(globals, "\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
89                        break;
90                case 'C':
91                        add(globals, "\"%08.8_Ax\n\"");
92                        add(globals, "\"%08.8_ax  \" 8/1 \"%02x \" \"  \" 8/1 \"%02x \" ");
93                        add(globals, "\"  |\" 16/1 \"%_p\" \"|\\n\"");
94                        break;
95                case 'd':
96                        add(globals, "\"%07.7_Ax\n\"");
97                        add(globals, "\"%07.7_ax \" 8/2 \"  %05u \" \"\\n\"");
98                        break;
99                case 'e':
100                        add(globals, getopt_reent.optarg);
101                        break;
102                case 'f':
103                        addfile(globals, getopt_reent.optarg);
104                        break;
105                case 'n':
106                        if ((length = atoi(getopt_reent.optarg)) < 0)
107                                errx(exit_jump, 1, "%s: bad length value", getopt_reent.optarg);
108                        break;
109                case 'o':
110                        add(globals, "\"%07.7_Ax\n\"");
111                        add(globals, "\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
112                        break;
113                case 's':
114                        if ((skip = strtoll(getopt_reent.optarg, &p, 0)) < 0)
115                                errx(exit_jump, 1, "%s: bad skip value", getopt_reent.optarg);
116                        switch(*p) {
117                        case 'b':
118                                skip *= 512;
119                                break;
120                        case 'k':
121                                skip *= 1024;
122                                break;
123                        case 'm':
124                                skip *= 1048576;
125                                break;
126                        }
127                        break;
128                case 'v':
129                        vflag = ALL;
130                        break;
131                case 'x':
132                        add(globals, "\"%07.7_Ax\n\"");
133                        add(globals, "\"%07.7_ax \" 8/2 \"   %04x \" \"\\n\"");
134                        break;
135                case '?':
136                        usage(globals);
137                }
138
139        if (!fshead) {
140                add(globals, "\"%07.7_Ax\n\"");
141                add(globals, "\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
142        }
143
144        *argvp += getopt_reent.optind;
145}
146
147void
148usage(rtems_shell_hexdump_globals* globals)
149{
150        (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
151"usage: hexdump [-bcCdovx] [-e fmt] [-f fmt_file] [-n length]",
152"               [-s skip] [file ...]",
153"       hd      [-bcdovx]  [-e fmt] [-f fmt_file] [-n length]",
154"               [-s skip] [file ...]");
155        exit(1);
156}
Note: See TracBrowser for help on using the repository browser.