Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libbb/dump.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/libbb/dump.c
r821 r1770 1 /* vi: set sw=4 ts=4: */ 1 2 /* 2 3 * Support code for the hexdump and od applets, … … 12 13 13 14 #include "libbb.h" 14 #include <string.h>15 #include <unistd.h>16 #include <ctype.h> /* for isdigit() */17 15 #include "dump.h" 18 16 … … 29 27 int bb_dump_length = -1; /* max bytes to read */ 30 28 31 static const char index_str[] = ".#-+ 0123456789";32 33 static const char size_conv_str[] =29 static const char index_str[] ALIGN1 = ".#-+ 0123456789"; 30 31 static const char size_conv_str[] ALIGN1 = 34 32 "\x1\x4\x4\x4\x4\x4\x4\x8\x8\x8\x8\010cdiouxXeEfgG"; 35 33 36 static const char lcc[] = "diouxX";34 static const char lcc[] ALIGN1 = "diouxX"; 37 35 38 36 int bb_dump_size(FS * fs) 39 37 { 40 registerFU *fu;41 registerint bcnt, cur_size;42 registerchar *fmt;38 FU *fu; 39 int bcnt, cur_size; 40 char *fmt; 43 41 const char *p; 44 42 int prec; … … 77 75 cur_size += bcnt * fu->reps; 78 76 } 79 return (cur_size);77 return cur_size; 80 78 } 81 79 … … 156 154 /* Unlike the original, output the remainder of the format string. */ 157 155 if (!*byte_count_str) { 158 bb_error_msg_and_die("bad byte count for conversion character %s .", p1);156 bb_error_msg_and_die("bad byte count for conversion character %s", p1); 159 157 } 160 158 pr->bcnt = *byte_count_str; … … 189 187 pr->bcnt = prec; 190 188 } else { /* NOTOKAY */ 191 bb_error_msg_and_die("%%s requires a precision or a byte count .");189 bb_error_msg_and_die("%%s requires a precision or a byte count"); 192 190 } 193 191 } else if (*p1 == '_') { … … 223 221 } else { 224 222 DO_BAD_CONV_CHAR: 225 bb_error_msg_and_die("bad conversion character %%%s .\n", p1);223 bb_error_msg_and_die("bad conversion character %%%s", p1); 226 224 } 227 225 … … 232 230 savech = *p2; 233 231 p1[1] = '\0'; 234 pr->fmt = bb_xstrdup(fmtp);232 pr->fmt = xstrdup(fmtp); 235 233 *p2 = savech; 236 234 pr->cchar = pr->fmt + (p1 - fmtp); … … 256 254 /* only one conversion character if byte count */ 257 255 if (!(pr->flags & F_ADDRESS) && fu->bcnt && nconv++) { 258 bb_error_msg_and_die("byte count with multiple conversion characters .\n");256 bb_error_msg_and_die("byte count with multiple conversion characters"); 259 257 } 260 258 } … … 294 292 } 295 293 296 static void do_skip(c har *fname, int statok)294 static void do_skip(const char *fname, int statok) 297 295 { 298 296 struct stat sbuf; … … 320 318 static int next(char **argv) 321 319 { 322 static int done; 320 static smallint done; 321 323 322 int statok; 324 323 325 324 if (argv) { 326 325 _argv = argv; 327 return (1);326 return 1; 328 327 } 329 328 for (;;) { … … 335 334 continue; 336 335 } 337 statok = done= 1;336 done = statok = 1; 338 337 } else { 339 if (done++) 340 return (0); 338 if (done) 339 return 0; 340 done = 1; 341 341 statok = 0; 342 342 } … … 346 346 ++_argv; 347 347 if (!bb_dump_skip) 348 return (1);348 return 1; 349 349 } 350 350 /* NOTREACHED */ … … 353 353 static unsigned char *get(void) 354 354 { 355 static int ateof = 1; 356 static unsigned char *curp=NULL, *savp; /*DBU:[dave@cray.com]initialize curp */ 357 register int n; 355 static smallint ateof = 1; 356 static unsigned char *curp = NULL, *savp; /*DBU:[dave@cray.com]initialize curp */ 357 358 int n; 358 359 int need, nread; 359 360 unsigned char *tmpp; … … 361 362 if (!curp) { 362 363 address = (off_t)0; /*DBU:[dave@cray.com] initialize,initialize..*/ 363 curp = (unsigned char *)xmalloc(bb_dump_blocksize);364 savp = (unsigned char *)xmalloc(bb_dump_blocksize);364 curp = xmalloc(bb_dump_blocksize); 365 savp = xmalloc(bb_dump_blocksize); 365 366 } else { 366 367 tmpp = curp; … … 377 378 if (!bb_dump_length || (ateof && !next((char **) NULL))) { 378 379 if (need == bb_dump_blocksize) { 379 return ((unsigned char *) NULL);380 return NULL; 380 381 } 381 382 if (bb_dump_vflag != ALL && !memcmp(curp, savp, nread)) { 382 383 if (bb_dump_vflag != DUP) { 383 p rintf("*\n");384 } 385 return ((unsigned char *) NULL);384 puts("*"); 385 } 386 return NULL; 386 387 } 387 388 memset((char *) curp + nread, 0, need); 388 389 eaddress = address + nread; 389 return (curp);390 return curp; 390 391 } 391 392 n = fread((char *) curp + nread, sizeof(unsigned char), … … 402 403 bb_dump_length -= n; 403 404 } 404 if (!(need -= n)) { 405 need -= n; 406 if (!need) { 405 407 if (bb_dump_vflag == ALL || bb_dump_vflag == FIRST 406 408 || memcmp(curp, savp, bb_dump_blocksize)) { … … 408 410 bb_dump_vflag = WAIT; 409 411 } 410 return (curp);412 return curp; 411 413 } 412 414 if (bb_dump_vflag == WAIT) { 413 p rintf("*\n");415 puts("*"); 414 416 } 415 417 bb_dump_vflag = DUP; … … 439 441 } 440 442 441 static const char conv_str[] =443 static const char conv_str[] ALIGN1 = 442 444 "\0\\0\0" 443 445 "\007\\a\0" /* \a */ … … 448 450 "\t\\t\0" 449 451 "\v\\v\0" 450 "\0";452 ; 451 453 452 454 … … 478 480 static void conv_u(PR * pr, unsigned char * p) 479 481 { 480 static const char list[] =482 static const char list[] ALIGN1 = 481 483 "nul\0soh\0stx\0etx\0eot\0enq\0ack\0bel\0" 482 484 "bs\0_ht\0_lf\0_vt\0_ff\0_cr\0_so\0_si\0_" … … 503 505 { 504 506 /* extern FU *endfu; */ 505 registerFS *fs;506 registerFU *fu;507 registerPR *pr;508 registerint cnt;509 registerunsigned char *bp;507 FS *fs; 508 FU *fu; 509 PR *pr; 510 int cnt; 511 unsigned char *bp; 510 512 511 513 off_t saveaddress; … … 651 653 int bb_dump_dump(char **argv) 652 654 { 653 registerFS *tfs;655 FS *tfs; 654 656 655 657 /* figure out the data block bb_dump_size */ … … 668 670 display(); 669 671 670 return (exitval);672 return exitval; 671 673 } 672 674 … … 727 729 /* byte count */ 728 730 if (isdigit(*p)) { 729 for (savep = p; isdigit(*p); ++p); 731 // TODO: use bb_strtou 732 savep = p; 733 do p++; while (isdigit(*p)); 730 734 if (!isspace(*p)) { 731 735 bb_error_msg_and_die("bad format {%s}", fmt);
Note:
See TracChangeset
for help on using the changeset viewer.