diff options
| author | Ron Yorston <rmy@pobox.com> | 2023-06-16 13:02:47 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2023-06-16 13:02:47 +0100 |
| commit | 4b3d7e62cff6015e1c4b856165efd90cf9182a5c (patch) | |
| tree | 0a59c6a94a47c3e8f1a47b0a3218f9591b842385 /coreutils | |
| parent | 0627e352656effac8d8e617378e7a68edfce41df (diff) | |
| parent | 2ca39ffd447ca874fcea933194829717d5573247 (diff) | |
| download | busybox-w32-4b3d7e62cff6015e1c4b856165efd90cf9182a5c.tar.gz busybox-w32-4b3d7e62cff6015e1c4b856165efd90cf9182a5c.tar.bz2 busybox-w32-4b3d7e62cff6015e1c4b856165efd90cf9182a5c.zip | |
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/od.c | 73 | ||||
| -rw-r--r-- | coreutils/od_bloaty.c | 56 |
2 files changed, 86 insertions, 43 deletions
diff --git a/coreutils/od.c b/coreutils/od.c index 6f22331e0..a7b1ba444 100644 --- a/coreutils/od.c +++ b/coreutils/od.c | |||
| @@ -22,7 +22,9 @@ | |||
| 22 | 22 | ||
| 23 | //usage:#if !ENABLE_DESKTOP | 23 | //usage:#if !ENABLE_DESKTOP |
| 24 | //usage:#define od_trivial_usage | 24 | //usage:#define od_trivial_usage |
| 25 | //usage: "[-aBbcDdeFfHhIiLlOovXx] [FILE]" | 25 | //usage: "[-abcdeFfhiloxsv] [FILE]" |
| 26 | // We also support -BDOHXIL, but they are not documented in coreutils 9.1 | ||
| 27 | // manpage/help, so don't show them either. | ||
| 26 | //usage:#define od_full_usage "\n\n" | 28 | //usage:#define od_full_usage "\n\n" |
| 27 | //usage: "Print FILE (or stdin) unambiguously, as octal bytes by default" | 29 | //usage: "Print FILE (or stdin) unambiguously, as octal bytes by default" |
| 28 | //usage:#endif | 30 | //usage:#endif |
| @@ -144,29 +146,50 @@ odoffset(dumper_t *dumper, int argc, char ***argvp) | |||
| 144 | } | 146 | } |
| 145 | } | 147 | } |
| 146 | 148 | ||
| 149 | // bb_dump_add(): | ||
| 150 | // A format string contains format units separated by [optional] whitespace. | ||
| 151 | // A format unit contains up to three items: an iteration count, a byte count, | ||
| 152 | // and a format. | ||
| 153 | // The iteration count is an optional integer (default 1). | ||
| 154 | // Each format is applied iteration count times. | ||
| 155 | // The byte count is an optional integer. It defines the number | ||
| 156 | // of bytes to be interpreted by each iteration of the format. | ||
| 157 | // If an iteration count and/or a byte count is specified, a slash must be | ||
| 158 | // placed after the iteration count and/or before the byte count | ||
| 159 | // to disambiguate them. | ||
| 160 | // The printf-style format is required and must be surrounded by " "s. | ||
| 161 | // (Below, each string contains two format units) | ||
| 147 | static const char *const add_strings[] ALIGN_PTR = { | 162 | static const char *const add_strings[] ALIGN_PTR = { |
| 148 | "16/1 \"%3_u \" \"\\n\"", /* a */ | 163 | "16/1 \" %3_u\"" "\"\n\"", /* 0: a */ |
| 149 | "8/2 \" %06o \" \"\\n\"", /* B, o */ | 164 | "8/2 \" %06o\"" "\"\n\"", /* 1: B (undocumented in od), o */ |
| 150 | "16/1 \"%03o \" \"\\n\"", /* b */ | 165 | "16/1 \" %03o\"" "\"\n\"", /* 2: b */ |
| 151 | "16/1 \"%3_c \" \"\\n\"", /* c */ | 166 | "16/1 \" %3_c\"" "\"\n\"", /* 3: c */ |
| 152 | "8/2 \" %05u \" \"\\n\"", /* d */ | 167 | "8/2 \" %5u\"" "\"\n\"", /* 4: d */ |
| 153 | "4/4 \" %010u \" \"\\n\"", /* D */ | 168 | "4/4 \" %10u\"" "\"\n\"", /* 5: D */ |
| 154 | "2/8 \" %21.14e \" \"\\n\"", /* e (undocumented in od), F */ | 169 | "2/8 \" %24.14e\"" "\"\n\"", /* 6: e (undocumented in od), F */ |
| 155 | "4/4 \" %14.7e \" \"\\n\"", /* f */ | 170 | "4/4 \" %15.7e\"" "\"\n\"", /* 7: f */ |
| 156 | "4/4 \" %08x \" \"\\n\"", /* H, X */ | 171 | "4/4 \" %08x\"" "\"\n\"", /* 8: H, X */ |
| 157 | "8/2 \" %04x \" \"\\n\"", /* h, x */ | 172 | "8/2 \" %04x\"" "\"\n\"", /* 9: h, x */ |
| 158 | "4/4 \" %11d \" \"\\n\"", /* I, L, l */ | 173 | "4/4 \" %11d\"" "\"\n\"", /* 10: i */ |
| 159 | "8/2 \" %6d \" \"\\n\"", /* i */ | 174 | "4/4 \" %011o\"" "\"\n\"", /* 11: O */ |
| 160 | "4/4 \" %011o \" \"\\n\"", /* O */ | 175 | "8/2 \" %6d\"" "\"\n\"", /* 12: s */ |
| 176 | /* -I,L,l: depend on word width of the arch (what is "long"?) */ | ||
| 177 | #if ULONG_MAX > 0xffffffff | ||
| 178 | "2/8 \" %20lld\"" "\"\n\"", /* 13: I, L, l */ | ||
| 179 | #define L_ 13 | ||
| 180 | #else | ||
| 181 | /* 32-bit arch: -I,L,l are the same as -i */ | ||
| 182 | #define L_ 10 | ||
| 183 | #endif | ||
| 161 | }; | 184 | }; |
| 162 | 185 | ||
| 163 | static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxv"; | 186 | static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv"; |
| 164 | 187 | ||
| 165 | static const char od_o2si[] ALIGN1 = { | 188 | static const char od_o2si[] ALIGN1 = { |
| 166 | 0, 1, 2, 3, 5, | 189 | 0, 1, 2, 3, 5, /* aBbcD */ |
| 167 | 4, 6, 6, 7, 8, | 190 | 4, 6, 6, 7, 8, /* deFfH */ |
| 168 | 9, 0xa, 0xb, 0xa, 0xa, | 191 | 9, L_, 10, L_, L_, /* hIiLl */ |
| 169 | 0xb, 1, 8, 9, | 192 | 11, 1, 8, 9, 12 /* OoXxs */ |
| 170 | }; | 193 | }; |
| 171 | 194 | ||
| 172 | int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 195 | int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| @@ -184,19 +207,21 @@ int od_main(int argc, char **argv) | |||
| 184 | if (first) { | 207 | if (first) { |
| 185 | first = 0; | 208 | first = 0; |
| 186 | bb_dump_add(dumper, "\"%07.7_Ao\n\""); | 209 | bb_dump_add(dumper, "\"%07.7_Ao\n\""); |
| 187 | bb_dump_add(dumper, "\"%07.7_ao \""); | 210 | bb_dump_add(dumper, "\"%07.7_ao\""); |
| 188 | } else { | 211 | } else { |
| 189 | bb_dump_add(dumper, "\" \""); | 212 | bb_dump_add(dumper, "\" \""); |
| 190 | } | 213 | } |
| 191 | bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]); | 214 | bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]); |
| 192 | } else { /* P, p, s, w, or other unhandled */ | 215 | } else { /* P, p, w, or other unhandled */ |
| 193 | bb_show_usage(); | 216 | bb_show_usage(); |
| 194 | } | 217 | } |
| 195 | } | 218 | } |
| 196 | if (!dumper->fshead) { | 219 | if (!dumper->fshead) { |
| 197 | bb_dump_add(dumper, "\"%07.7_Ao\n\""); | 220 | bb_dump_add(dumper, "\"%07.7_Ao\n\""); |
| 198 | bb_dump_add(dumper, "\"%07.7_ao \" 8/2 \"%06o \" \"\\n\""); | 221 | bb_dump_add(dumper, "\"%07.7_ao\""); |
| 222 | bb_dump_add(dumper, add_strings[1]); /* -o format is default */ | ||
| 199 | } | 223 | } |
| 224 | dumper->od_eofstring = "\n"; | ||
| 200 | 225 | ||
| 201 | argc -= optind; | 226 | argc -= optind; |
| 202 | argv += optind; | 227 | argv += optind; |
| @@ -205,7 +230,7 @@ int od_main(int argc, char **argv) | |||
| 205 | 230 | ||
| 206 | return bb_dump_dump(dumper, argv); | 231 | return bb_dump_dump(dumper, argv); |
| 207 | } | 232 | } |
| 208 | #endif /* ENABLE_DESKTOP */ | 233 | #endif /* !ENABLE_DESKTOP */ |
| 209 | 234 | ||
| 210 | /*- | 235 | /*- |
| 211 | * Copyright (c) 1990 The Regents of the University of California. | 236 | * Copyright (c) 1990 The Regents of the University of California. |
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 1830aca83..641d93503 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c | |||
| @@ -27,6 +27,8 @@ | |||
| 27 | //usage:#if ENABLE_DESKTOP | 27 | //usage:#if ENABLE_DESKTOP |
| 28 | //usage:#define od_trivial_usage | 28 | //usage:#define od_trivial_usage |
| 29 | //usage: "[-abcdfhilovxs] [-t TYPE] [-A RADIX] [-N SIZE] [-j SKIP] [-S MINSTR] [-w WIDTH] [FILE]..." | 29 | //usage: "[-abcdfhilovxs] [-t TYPE] [-A RADIX] [-N SIZE] [-j SKIP] [-S MINSTR] [-w WIDTH] [FILE]..." |
| 30 | // We also support -BDOHXIL, but they are not documented in coreutils 9.1 | ||
| 31 | // manpage/help, so don't show them either. | ||
| 30 | // We don't support: | 32 | // We don't support: |
| 31 | // ... [FILE] [[+]OFFSET[.][b]] | 33 | // ... [FILE] [[+]OFFSET[.][b]] |
| 32 | // Support is buggy for: | 34 | // Support is buggy for: |
| @@ -43,26 +45,33 @@ enum { | |||
| 43 | OPT_b = 1 << 3, | 45 | OPT_b = 1 << 3, |
| 44 | OPT_c = 1 << 4, | 46 | OPT_c = 1 << 4, |
| 45 | OPT_d = 1 << 5, | 47 | OPT_d = 1 << 5, |
| 46 | OPT_f = 1 << 6, | 48 | OPT_D = 1 << 6, /* undocumented in coreutils 9.1 */ |
| 47 | OPT_h = 1 << 7, | 49 | OPT_f = 1 << 7, |
| 48 | OPT_i = 1 << 8, | 50 | OPT_h = 1 << 8, |
| 49 | OPT_j = 1 << 9, | 51 | OPT_H = 1 << 9, /* undocumented in coreutils 9.1 */ |
| 50 | OPT_l = 1 << 10, | 52 | OPT_i = 1 << 10, |
| 51 | OPT_o = 1 << 11, | 53 | OPT_I = 1 << 11, /* undocumented in coreutils 9.1 */ |
| 52 | OPT_t = 1 << 12, | 54 | OPT_j = 1 << 12, |
| 55 | OPT_l = 1 << 13, | ||
| 56 | OPT_L = 1 << 14, /* undocumented in coreutils 9.1 */ | ||
| 57 | OPT_o = 1 << 15, | ||
| 58 | OPT_O = 1 << 16, /* undocumented in coreutils 9.1 */ | ||
| 59 | OPT_B = 1 << 17, /* undocumented synonym to -o */ | ||
| 60 | OPT_t = 1 << 18, | ||
| 53 | /* When zero and two or more consecutive blocks are equal, format | 61 | /* When zero and two or more consecutive blocks are equal, format |
| 54 | only the first block and output an asterisk alone on the following | 62 | only the first block and output an asterisk alone on the following |
| 55 | line to indicate that identical blocks have been elided: */ | 63 | line to indicate that identical blocks have been elided: */ |
| 56 | OPT_v = 1 << 13, | 64 | OPT_v = 1 << 19, |
| 57 | OPT_x = 1 << 14, | 65 | OPT_x = 1 << 20, |
| 58 | OPT_s = 1 << 15, | 66 | OPT_X = 1 << 21, /* undocumented in coreutils 9.1 */ |
| 59 | OPT_S = 1 << 16, | 67 | OPT_s = 1 << 22, |
| 60 | OPT_w = 1 << 17, | 68 | OPT_S = 1 << 23, |
| 61 | OPT_traditional = (1 << 18) * ENABLE_LONG_OPTS, | 69 | OPT_w = 1 << 24, |
| 70 | OPT_traditional = (1 << 25) * ENABLE_LONG_OPTS, | ||
| 62 | }; | 71 | }; |
| 63 | 72 | ||
| 64 | #define OD_GETOPT32() getopt32long(argv, \ | 73 | #define OD_GETOPT32() getopt32long(argv, \ |
| 65 | "A:N:abcdfhij:lot:*vxsS:w:+:", od_longopts, \ | 74 | "A:N:abcdDfhHiIj:lLoOBt:*vxXsS:w:+:", od_longopts, \ |
| 66 | /* -w with optional param */ \ | 75 | /* -w with optional param */ \ |
| 67 | /* -S was -s and also had optional parameter */ \ | 76 | /* -S was -s and also had optional parameter */ \ |
| 68 | /* but in coreutils 6.3 it was renamed and now has */ \ | 77 | /* but in coreutils 6.3 it was renamed and now has */ \ |
| @@ -1246,20 +1255,29 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
| 1246 | if (opt & OPT_N) { | 1255 | if (opt & OPT_N) { |
| 1247 | max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm_suffixes); | 1256 | max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm_suffixes); |
| 1248 | } | 1257 | } |
| 1258 | |||
| 1249 | if (opt & OPT_a) decode_format_string("a"); | 1259 | if (opt & OPT_a) decode_format_string("a"); |
| 1250 | if (opt & OPT_b) decode_format_string("oC"); | 1260 | if (opt & OPT_b) decode_format_string("oC"); |
| 1251 | if (opt & OPT_c) decode_format_string("c"); | 1261 | if (opt & OPT_c) decode_format_string("c"); |
| 1252 | if (opt & OPT_d) decode_format_string("u2"); | 1262 | if (opt & OPT_d) decode_format_string("u2"); |
| 1263 | if (opt & OPT_D) decode_format_string("uI"); | ||
| 1253 | if (opt & OPT_f) decode_format_string("fF"); | 1264 | if (opt & OPT_f) decode_format_string("fF"); |
| 1254 | if (opt & OPT_h) decode_format_string("x2"); | 1265 | if (opt & (OPT_h|OPT_x)) decode_format_string("x2"); |
| 1255 | if (opt & OPT_i) decode_format_string("d2"); | 1266 | if (opt & (OPT_H|OPT_X)) decode_format_string("xI"); |
| 1267 | /* -I,L,l: depend on word width of the arch (what is "long"?) */ | ||
| 1268 | #if ULONG_MAX > 0xffffffff | ||
| 1269 | if (opt & OPT_i) decode_format_string("dI"); | ||
| 1270 | if (opt & (OPT_I|OPT_l|OPT_L)) decode_format_string("dL"); | ||
| 1271 | #else | ||
| 1272 | /* 32-bit arch: -I,L,l are the same as -i */ | ||
| 1273 | if (opt & (OPT_i|OPT_I|OPT_l|OPT_L)) decode_format_string("dI"); | ||
| 1274 | #endif | ||
| 1256 | if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes); | 1275 | if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes); |
| 1257 | if (opt & OPT_l) decode_format_string("d4"); | 1276 | if (opt & (OPT_o|OPT_B)) decode_format_string("o2"); |
| 1258 | if (opt & OPT_o) decode_format_string("o2"); | 1277 | if (opt & OPT_O) decode_format_string("oI"); |
| 1259 | while (lst_t) { | 1278 | while (lst_t) { |
| 1260 | decode_format_string(llist_pop(&lst_t)); | 1279 | decode_format_string(llist_pop(&lst_t)); |
| 1261 | } | 1280 | } |
| 1262 | if (opt & OPT_x) decode_format_string("x2"); | ||
| 1263 | if (opt & OPT_s) decode_format_string("d2"); | 1281 | if (opt & OPT_s) decode_format_string("d2"); |
| 1264 | if (opt & OPT_S) { | 1282 | if (opt & OPT_S) { |
| 1265 | G.string_min = xstrtou_sfx(str_S, 0, bkm_suffixes); | 1283 | G.string_min = xstrtou_sfx(str_S, 0, bkm_suffixes); |
