source: rtems/cpukit/libmisc/shell/hexsyntax.c @ 7eada71

4.115
Last change on this file since 7eada71 was 5b1f1979, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/02/11 at 04:21:26

2011-02-02 Ralf Corsépius <ralf.corsepius@…>

  • libmisc/shell/hexdump-display.c: Eliminate bcopy, bzero, bcmp, index (Obsolete).
  • libmisc/shell/hexdump-parse.c: Eliminate index (Obsolete).
  • libmisc/shell/hexsyntax.c: Eliminate rindex (Obsolete).
  • libmisc/shell/main_hexdump.c: Eliminate rindex (Obsolete).
  • libmisc/shell/main_rm.c: Eliminate rindex (Obsolete).
  • Property mode set to 100644
File size: 4.7 KB
Line 
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#ifdef HAVE_CONFIG_H
35#include "config.h"
36#endif
37
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#define rindex(s,c)     strrchr(s,c)
55
56#include "hexdump.h"
57
58#define __need_getopt_newlib
59#include <getopt.h>
60
61#if RTEMS_REMOVED
62off_t skip;                             /* bytes to skip */
63#endif
64
65void
66newsyntax(rtems_shell_hexdump_globals* globals, int argc, char ***argvp)
67{
68        int ch;
69        char *p, **argv;
70
71  struct getopt_data getopt_reent;
72  memset(&getopt_reent, 0, sizeof(getopt_data));
73
74        argv = *argvp;
75        if ((p = rindex(argv[0], 'h')) != NULL &&
76            strcmp(p, "hd") == 0) {
77                /* "Canonical" format, implies -C. */
78                add(globals, "\"%08.8_Ax\n\"");
79                add(globals, "\"%08.8_ax  \" 8/1 \"%02x \" \"  \" 8/1 \"%02x \" ");
80                add(globals, "\"  |\" 16/1 \"%_p\" \"|\\n\"");
81        }
82        while ((ch = getopt_r(argc, argv, "bcCde:f:n:os:vx", &getopt_reent)) != -1)
83                switch (ch) {
84                case 'b':
85                        add(globals, "\"%07.7_Ax\n\"");
86                        add(globals, "\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
87                        break;
88                case 'c':
89                        add(globals, "\"%07.7_Ax\n\"");
90                        add(globals, "\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
91                        break;
92                case 'C':
93                        add(globals, "\"%08.8_Ax\n\"");
94                        add(globals, "\"%08.8_ax  \" 8/1 \"%02x \" \"  \" 8/1 \"%02x \" ");
95                        add(globals, "\"  |\" 16/1 \"%_p\" \"|\\n\"");
96                        break;
97                case 'd':
98                        add(globals, "\"%07.7_Ax\n\"");
99                        add(globals, "\"%07.7_ax \" 8/2 \"  %05u \" \"\\n\"");
100                        break;
101                case 'e':
102                        add(globals, getopt_reent.optarg);
103                        break;
104                case 'f':
105                        addfile(globals, getopt_reent.optarg);
106                        break;
107                case 'n':
108                        if ((length = atoi(getopt_reent.optarg)) < 0)
109                                errx(exit_jump, 1, "%s: bad length value", getopt_reent.optarg);
110                        break;
111                case 'o':
112                        add(globals, "\"%07.7_Ax\n\"");
113                        add(globals, "\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
114                        break;
115                case 's':
116                        if ((skip = strtoll(getopt_reent.optarg, &p, 0)) < 0)
117                                errx(exit_jump, 1, "%s: bad skip value", getopt_reent.optarg);
118                        switch(*p) {
119                        case 'b':
120                                skip *= 512;
121                                break;
122                        case 'k':
123                                skip *= 1024;
124                                break;
125                        case 'm':
126                                skip *= 1048576;
127                                break;
128                        }
129                        break;
130                case 'v':
131                        vflag = ALL;
132                        break;
133                case 'x':
134                        add(globals, "\"%07.7_Ax\n\"");
135                        add(globals, "\"%07.7_ax \" 8/2 \"   %04x \" \"\\n\"");
136                        break;
137                case '?':
138                        usage(globals);
139                }
140
141        if (!fshead) {
142                add(globals, "\"%07.7_Ax\n\"");
143                add(globals, "\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
144        }
145
146        *argvp += getopt_reent.optind;
147}
148
149void
150usage(rtems_shell_hexdump_globals* globals)
151{
152        (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
153"usage: hexdump [-bcCdovx] [-e fmt] [-f fmt_file] [-n length]",
154"               [-s skip] [file ...]",
155"       hd      [-bcdovx]  [-e fmt] [-f fmt_file] [-n length]",
156"               [-s skip] [file ...]");
157        exit(1);
158}
Note: See TracBrowser for help on using the repository browser.