Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/od.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/coreutils/od.c
r1765 r2725 5 5 * 6 6 * Copyright (c) 1990 7 * 8 * 9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.7 * The Regents of the University of California. All rights reserved. 8 * 9 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 10 10 * 11 11 * Original copyright notice is retained at the end of this file. … … 18 18 #include "od_bloaty.c" 19 19 #else 20 #include <getopt.h>21 20 22 21 #include "dump.h" 23 22 24 #define isdecdigit(c) isdigit(c)25 #define ishexdigit(c) (isxdigit)(c)26 27 23 static void 28 odoffset( int argc, char ***argvp)24 odoffset(dumper_t *dumper, int argc, char ***argvp) 29 25 { 30 26 char *num, *p; … … 53 49 if ((*p != '+') 54 50 && (argc < 2 55 || (!isd ecdigit(p[0])56 && ((p[0] != 'x') || !is hexdigit(p[1])))))51 || (!isdigit(p[0]) 52 && ((p[0] != 'x') || !isxdigit(p[1]))))) 57 53 return; 58 54 59 55 base = 0; 60 56 /* 61 * bb_dump_skip over leading '+', 'x[0-9a-fA-f]' or '0x', and57 * skip over leading '+', 'x[0-9a-fA-f]' or '0x', and 62 58 * set base. 63 59 */ 64 60 if (p[0] == '+') 65 61 ++p; 66 if (p[0] == 'x' && is hexdigit(p[1])) {62 if (p[0] == 'x' && isxdigit(p[1])) { 67 63 ++p; 68 64 base = 16; … … 72 68 } 73 69 74 /* bb_dump_skip over the number */70 /* skip over the number */ 75 71 if (base == 16) 76 for (num = p; ishexdigit(*p); ++p); 72 for (num = p; isxdigit(*p); ++p) 73 continue; 77 74 else 78 for (num = p; isdecdigit(*p); ++p); 75 for (num = p; isdigit(*p); ++p) 76 continue; 79 77 80 78 /* check for no number */ … … 89 87 } 90 88 91 bb_dump_skip = strtol(num, &end, base ? base : 8);89 dumper->dump_skip = strtol(num, &end, base ? base : 8); 92 90 93 91 /* if end isn't the same as p, we got a non-octal digit */ 94 92 if (end != p) 95 bb_dump_skip = 0;93 dumper->dump_skip = 0; 96 94 else { 97 95 if (*p) { 98 96 if (*p == 'b') { 99 bb_dump_skip *= 512;97 dumper->dump_skip *= 512; 100 98 ++p; 101 99 } else if (*p == 'B') { 102 bb_dump_skip *= 1024;100 dumper->dump_skip *= 1024; 103 101 ++p; 104 102 } 105 103 } 106 104 if (*p) 107 bb_dump_skip = 0;105 dumper->dump_skip = 0; 108 106 else { 109 107 ++*argvp; … … 113 111 * but it's easy. 114 112 */ 115 #define TYPE_OFFSET7113 #define TYPE_OFFSET 7 116 114 { 117 115 char x_or_d; … … 122 120 if (base == 10) { 123 121 x_or_d = 'd'; 124 125 bb_dump_fshead->nextfu->fmt[TYPE_OFFSET]126 = bb_dump_fshead->nextfs->nextfu->fmt[TYPE_OFFSET]122 DO_X_OR_D: 123 dumper->fshead->nextfu->fmt[TYPE_OFFSET] 124 = dumper->fshead->nextfs->nextfu->fmt[TYPE_OFFSET] 127 125 = x_or_d; 128 126 } … … 133 131 134 132 static const char *const add_strings[] = { 135 "16/1 \"%3_u \" \"\\n\"", 136 "8/2 \" %06o \" \"\\n\"", 137 "16/1 \"%03o \" \"\\n\"", 138 "16/1 \"%3_c \" \"\\n\"", 139 "8/2 \" %05u \" \"\\n\"", 140 "4/4 \" %010u \" \"\\n\"", 141 "2/8 \" %21.14e \" \"\\n\"", 142 "4/4 \" %14.7e \" \"\\n\"", 143 "4/4 \" %08x \" \"\\n\"", 144 "8/2 \" %04x \" \"\\n\"", 145 "4/4 \" %11d \" \"\\n\"", 146 "8/2 \" %6d \" \"\\n\"", 147 "4/4 \" %011o \" \"\\n\"", 133 "16/1 \"%3_u \" \"\\n\"", /* a */ 134 "8/2 \" %06o \" \"\\n\"", /* B, o */ 135 "16/1 \"%03o \" \"\\n\"", /* b */ 136 "16/1 \"%3_c \" \"\\n\"", /* c */ 137 "8/2 \" %05u \" \"\\n\"", /* d */ 138 "4/4 \" %010u \" \"\\n\"", /* D */ 139 "2/8 \" %21.14e \" \"\\n\"", /* e (undocumented in od), F */ 140 "4/4 \" %14.7e \" \"\\n\"", /* f */ 141 "4/4 \" %08x \" \"\\n\"", /* H, X */ 142 "8/2 \" %04x \" \"\\n\"", /* h, x */ 143 "4/4 \" %11d \" \"\\n\"", /* I, L, l */ 144 "8/2 \" %6d \" \"\\n\"", /* i */ 145 "4/4 \" %011o \" \"\\n\"", /* O */ 148 146 }; 149 147 … … 157 155 }; 158 156 159 int od_main(int argc, char **argv) ;157 int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 160 158 int od_main(int argc, char **argv) 161 159 { … … 163 161 int first = 1; 164 162 char *p; 165 bb_dump_vflag = FIRST; 166 bb_dump_length = -1; 163 dumper_t *dumper = alloc_dumper(); 167 164 168 165 while ((ch = getopt(argc, argv, od_opts)) > 0) { 169 166 if (ch == 'v') { 170 bb_dump_vflag = ALL;167 dumper->dump_vflag = ALL; 171 168 } else if (((p = strchr(od_opts, ch)) != NULL) && (*p != '\0')) { 172 169 if (first) { 173 170 first = 0; 174 bb_dump_add( "\"%07.7_Ao\n\"");175 bb_dump_add( "\"%07.7_ao \"");171 bb_dump_add(dumper, "\"%07.7_Ao\n\""); 172 bb_dump_add(dumper, "\"%07.7_ao \""); 176 173 } else { 177 bb_dump_add( "\" \"");174 bb_dump_add(dumper, "\" \""); 178 175 } 179 bb_dump_add( add_strings[(int)od_o2si[(p-od_opts)]]);180 } else { 176 bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]); 177 } else { /* P, p, s, w, or other unhandled */ 181 178 bb_show_usage(); 182 179 } 183 180 } 184 if (! bb_dump_fshead) {185 bb_dump_add( "\"%07.7_Ao\n\"");186 bb_dump_add( "\"%07.7_ao \" 8/2 \"%06o \" \"\\n\"");181 if (!dumper->fshead) { 182 bb_dump_add(dumper, "\"%07.7_Ao\n\""); 183 bb_dump_add(dumper, "\"%07.7_ao \" 8/2 \"%06o \" \"\\n\""); 187 184 } 188 185 … … 190 187 argv += optind; 191 188 192 odoffset( argc, &argv);193 194 return bb_dump_dump( argv);189 odoffset(dumper, argc, &argv); 190 191 return bb_dump_dump(dumper, argv); 195 192 } 196 193 #endif /* ENABLE_DESKTOP */
Note:
See TracChangeset
for help on using the changeset viewer.