2 * hexdump implementation for busybox
3 * Based on code from util-linux v 2.11l
6 * The Regents of the University of California. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Original copyright notice is retained at the end of this file.
31 extern off_t skip; /* bytes to skip */
33 extern FS *fshead; /* head of format strings */
34 extern int blocksize; /* data block size */
35 extern int length; /* max bytes to read */
37 void addfile(char *name)
44 if (!(fp = fopen(name, "r"))) {
45 error_msg_and_die("hexdump: can't read %s.\n", name);
47 while (fgets(buf, sizeof(buf), fp)) {
48 if (!(p = index(buf, '\n'))) {
49 error_msg("hexdump: line too long.\n");
50 while ((ch = getchar()) != '\n' && ch != EOF);
54 for (p = buf; *p && isspace(*p); ++p);
55 if (!*p || *p == '#') {
63 int hexdump_main(int argc, char **argv)
68 extern enum _vflag vflag;
72 while ((ch = getopt(argc, argv, "bcde:f:n:os:vx")) != EOF) {
75 add("\"%07.7_Ax\n\"");
76 add("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
79 add("\"%07.7_Ax\n\"");
80 add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
83 add("\"%07.7_Ax\n\"");
84 add("\"%07.7_ax \" 8/2 \" %05u \" \"\\n\"");
93 if ((length = atoi(optarg)) < 0) {
94 error_msg_and_die("hexdump: bad length value.\n");
98 add("\"%07.7_Ax\n\"");
99 add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
102 if ((skip = strtol(optarg, &p, 0)) < 0) {
103 error_msg_and_die("hexdump: bad skip value.\n");
121 add("\"%07.7_Ax\n\"");
122 add("\"%07.7_ax \" 8/2 \" %04x \" \"\\n\"");
130 add("\"%07.7_Ax\n\"");
131 add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
139 * Copyright (c) 1989 The Regents of the University of California.
140 * All rights reserved.
142 * Redistribution and use in source and binary forms, with or without
143 * modification, are permitted provided that the following conditions
145 * 1. Redistributions of source code must retain the above copyright
146 * notice, this list of conditions and the following disclaimer.
147 * 2. Redistributions in binary form must reproduce the above copyright
148 * notice, this list of conditions and the following disclaimer in the
149 * documentation and/or other materials provided with the distribution.
150 * 3. Neither the name of the University nor the names of its contributors
151 * may be used to endorse or promote products derived from this software
152 * without specific prior written permission.
154 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
155 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
156 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
157 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
158 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
159 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
160 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
161 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
162 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
163 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF