diff options
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/Makefile | 1 | ||||
| -rw-r--r-- | util-linux/config.in | 1 | ||||
| -rw-r--r-- | util-linux/hexdump.c | 169 |
3 files changed, 171 insertions, 0 deletions
diff --git a/util-linux/Makefile b/util-linux/Makefile index ddecf50d3..0971acadc 100644 --- a/util-linux/Makefile +++ b/util-linux/Makefile | |||
| @@ -30,6 +30,7 @@ obj-$(CONFIG_FDFLUSH) += fdflush.o | |||
| 30 | obj-$(CONFIG_FREERAMDISK) += freeramdisk.o | 30 | obj-$(CONFIG_FREERAMDISK) += freeramdisk.o |
| 31 | obj-$(CONFIG_FSCK_MINIX) += fsck_minix.o | 31 | obj-$(CONFIG_FSCK_MINIX) += fsck_minix.o |
| 32 | obj-$(CONFIG_GETOPT) += getopt.o | 32 | obj-$(CONFIG_GETOPT) += getopt.o |
| 33 | obj-$(CONFIG_HEXDUMP) += hexdump.o | ||
| 33 | obj-$(CONFIG_MKFS_MINIX) += mkfs_minix.o | 34 | obj-$(CONFIG_MKFS_MINIX) += mkfs_minix.o |
| 34 | obj-$(CONFIG_MKSWAP) += mkswap.o | 35 | obj-$(CONFIG_MKSWAP) += mkswap.o |
| 35 | obj-$(CONFIG_MORE) += more.o | 36 | obj-$(CONFIG_MORE) += more.o |
diff --git a/util-linux/config.in b/util-linux/config.in index 3eb8ee0b5..50a874d6c 100644 --- a/util-linux/config.in +++ b/util-linux/config.in | |||
| @@ -13,6 +13,7 @@ bool 'fdflush' CONFIG_FDFLUSH | |||
| 13 | bool 'freeramdisk' CONFIG_FREERAMDISK | 13 | bool 'freeramdisk' CONFIG_FREERAMDISK |
| 14 | bool 'fsck_minix' CONFIG_FSCK_MINIX | 14 | bool 'fsck_minix' CONFIG_FSCK_MINIX |
| 15 | bool 'getopt' CONFIG_GETOPT | 15 | bool 'getopt' CONFIG_GETOPT |
| 16 | bool 'hexdump' CONFIG_HEXDUMP | ||
| 16 | bool 'mkfs_minix' CONFIG_MKFS_MINIX | 17 | bool 'mkfs_minix' CONFIG_MKFS_MINIX |
| 17 | bool 'mkswap' CONFIG_MKSWAP | 18 | bool 'mkswap' CONFIG_MKSWAP |
| 18 | bool 'more' CONFIG_MORE | 19 | bool 'more' CONFIG_MORE |
diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c new file mode 100644 index 000000000..4510a5e66 --- /dev/null +++ b/util-linux/hexdump.c | |||
| @@ -0,0 +1,169 @@ | |||
| 1 | /* | ||
| 2 | * hexdump implementation for busybox | ||
| 3 | * Based on code from util-linux v 2.11l | ||
| 4 | * | ||
| 5 | * Copyright (c) 1989 | ||
| 6 | * The Regents of the University of California. All rights reserved. | ||
| 7 | * | ||
| 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. | ||
| 12 | * | ||
| 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. | ||
| 17 | * | ||
| 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 | ||
| 21 | * | ||
| 22 | * Original copyright notice is retained at the end of this file. | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include <getopt.h> | ||
| 26 | #include <stdlib.h> | ||
| 27 | #include <string.h> | ||
| 28 | #include "dump.h" | ||
| 29 | #include "busybox.h" | ||
| 30 | |||
| 31 | extern off_t skip; /* bytes to skip */ | ||
| 32 | |||
| 33 | extern FS *fshead; /* head of format strings */ | ||
| 34 | extern int blocksize; /* data block size */ | ||
| 35 | extern int length; /* max bytes to read */ | ||
| 36 | |||
| 37 | void addfile(char *name) | ||
| 38 | { | ||
| 39 | register char *p; | ||
| 40 | FILE *fp; | ||
| 41 | int ch; | ||
| 42 | char buf[2048 + 1]; | ||
| 43 | |||
| 44 | if (!(fp = fopen(name, "r"))) { | ||
| 45 | error_msg_and_die("hexdump: can't read %s.\n", name); | ||
| 46 | } | ||
| 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); | ||
| 51 | continue; | ||
| 52 | } | ||
| 53 | *p = '\0'; | ||
| 54 | for (p = buf; *p && isspace(*p); ++p); | ||
| 55 | if (!*p || *p == '#') { | ||
| 56 | continue; | ||
| 57 | } | ||
| 58 | add(p); | ||
| 59 | } | ||
| 60 | (void)fclose(fp); | ||
| 61 | } | ||
| 62 | |||
| 63 | int hexdump_main(int argc, char **argv) | ||
| 64 | { | ||
| 65 | // register FS *tfs; | ||
| 66 | char *p; | ||
| 67 | int ch; | ||
| 68 | extern enum _vflag vflag; | ||
| 69 | vflag = FIRST; | ||
| 70 | length = -1; | ||
| 71 | |||
| 72 | while ((ch = getopt(argc, argv, "bcde:f:n:os:vx")) != EOF) { | ||
| 73 | switch (ch) { | ||
| 74 | case 'b': | ||
| 75 | add("\"%07.7_Ax\n\""); | ||
| 76 | add("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\""); | ||
| 77 | break; | ||
| 78 | case 'c': | ||
| 79 | add("\"%07.7_Ax\n\""); | ||
| 80 | add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\""); | ||
| 81 | break; | ||
| 82 | case 'd': | ||
| 83 | add("\"%07.7_Ax\n\""); | ||
| 84 | add("\"%07.7_ax \" 8/2 \" %05u \" \"\\n\""); | ||
| 85 | break; | ||
| 86 | case 'e': | ||
| 87 | add(optarg); | ||
| 88 | break; | ||
| 89 | case 'f': | ||
| 90 | addfile(optarg); | ||
| 91 | break; | ||
| 92 | case 'n': | ||
| 93 | if ((length = atoi(optarg)) < 0) { | ||
| 94 | error_msg_and_die("hexdump: bad length value.\n"); | ||
| 95 | } | ||
| 96 | break; | ||
| 97 | case 'o': | ||
| 98 | add("\"%07.7_Ax\n\""); | ||
| 99 | add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\""); | ||
| 100 | break; | ||
| 101 | case 's': | ||
| 102 | if ((skip = strtol(optarg, &p, 0)) < 0) { | ||
| 103 | error_msg_and_die("hexdump: bad skip value.\n"); | ||
| 104 | } | ||
| 105 | switch(*p) { | ||
| 106 | case 'b': | ||
| 107 | skip *= 512; | ||
| 108 | break; | ||
| 109 | case 'k': | ||
| 110 | skip *= 1024; | ||
| 111 | break; | ||
| 112 | case 'm': | ||
| 113 | skip *= 1048576; | ||
| 114 | break; | ||
| 115 | } | ||
| 116 | break; | ||
| 117 | case 'v': | ||
| 118 | vflag = ALL; | ||
| 119 | break; | ||
| 120 | case 'x': | ||
| 121 | add("\"%07.7_Ax\n\""); | ||
| 122 | add("\"%07.7_ax \" 8/2 \" %04x \" \"\\n\""); | ||
| 123 | break; | ||
| 124 | case '?': | ||
| 125 | show_usage(); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | if (!fshead) { | ||
| 130 | add("\"%07.7_Ax\n\""); | ||
| 131 | add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\""); | ||
| 132 | } | ||
| 133 | |||
| 134 | argv += optind; | ||
| 135 | |||
| 136 | return(dump(argv)); | ||
| 137 | } | ||
| 138 | /* | ||
| 139 | * Copyright (c) 1989 The Regents of the University of California. | ||
| 140 | * All rights reserved. | ||
| 141 | * | ||
| 142 | * Redistribution and use in source and binary forms, with or without | ||
| 143 | * modification, are permitted provided that the following conditions | ||
| 144 | * are met: | ||
| 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. All advertising materials mentioning features or use of this software | ||
| 151 | * must display the following acknowledgement: | ||
| 152 | * This product includes software developed by the University of | ||
| 153 | * California, Berkeley and its contributors. | ||
| 154 | * 4. Neither the name of the University nor the names of its contributors | ||
| 155 | * may be used to endorse or promote products derived from this software | ||
| 156 | * without specific prior written permission. | ||
| 157 | * | ||
| 158 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 159 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 160 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 161 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 162 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 163 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 164 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 165 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 166 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 167 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 168 | * SUCH DAMAGE. | ||
| 169 | */ | ||
