source: rtems/cpukit/libmisc/shell/hexsyntax.c @ 0893220

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