diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-16 11:00:16 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-16 11:00:16 +0000 |
| commit | 55f7912ddaea7c21068a48841a6eb933e5f286ee (patch) | |
| tree | 8e048772811061a8db2429c3ef99e8205e1de1f6 /libbb | |
| parent | 8ddb6410edb0c4e87b4c6b9d0887868977c8eff5 (diff) | |
| download | busybox-w32-55f7912ddaea7c21068a48841a6eb933e5f286ee.tar.gz busybox-w32-55f7912ddaea7c21068a48841a6eb933e5f286ee.tar.bz2 busybox-w32-55f7912ddaea7c21068a48841a6eb933e5f286ee.zip | |
libbb: get rid of statics in dump.c; code shrinks a lot too
function old new delta
alloc_dumper - 26 +26
hexdump_main 600 601 +1
static.done 1 - -1
static.ateof 1 - -1
bb_dump_vflag 1 - -1
static.savp 4 - -4
static.nextfs 4 - -4
static.curp 4 - -4
exitval 4 - -4
endfu 4 - -4
bb_dump_length 4 - -4
bb_dump_fshead 4 - -4
bb_dump_blocksize 4 - -4
_argv 4 - -4
bb_dump_add 365 358 -7
savaddress 8 - -8
eaddress 8 - -8
bb_dump_skip 8 - -8
address 8 - -8
bb_dump_dump 2748 2672 -76
next 538 445 -93
------------------------------------------------------------------------------
(add/remove: 1/16 grow/shrink: 1/3 up/down: 27/-247) Total: -220 bytes
text data bss dec hex filename
789458 607 6764 796829 c289d busybox_old
789309 601 6696 796606 c27be busybox_unstripped
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/dump.c | 298 |
1 files changed, 160 insertions, 138 deletions
diff --git a/libbb/dump.c b/libbb/dump.c index 29c2c85ee..0d553d4d0 100644 --- a/libbb/dump.c +++ b/libbb/dump.c | |||
| @@ -14,19 +14,6 @@ | |||
| 14 | #include "libbb.h" | 14 | #include "libbb.h" |
| 15 | #include "dump.h" | 15 | #include "dump.h" |
| 16 | 16 | ||
| 17 | FS *bb_dump_fshead; /* head of format strings */ | ||
| 18 | off_t bb_dump_skip; /* bytes to skip */ | ||
| 19 | int bb_dump_blocksize; /* data block size */ | ||
| 20 | int bb_dump_length = -1; /* max bytes to read */ | ||
| 21 | smallint /*enum _vflag*/ bb_dump_vflag = FIRST; | ||
| 22 | |||
| 23 | static FU *endfu; | ||
| 24 | static char **_argv; | ||
| 25 | static off_t savaddress; /* saved address/offset in stream */ | ||
| 26 | static off_t eaddress; /* end address */ | ||
| 27 | static off_t address; /* address/offset in stream */ | ||
| 28 | static int exitval; /* final exit value */ | ||
| 29 | |||
| 30 | static const char index_str[] ALIGN1 = ".#-+ 0123456789"; | 17 | static const char index_str[] ALIGN1 = ".#-+ 0123456789"; |
| 31 | 18 | ||
| 32 | static const char size_conv_str[] ALIGN1 = | 19 | static const char size_conv_str[] ALIGN1 = |
| @@ -34,7 +21,36 @@ static const char size_conv_str[] ALIGN1 = | |||
| 34 | 21 | ||
| 35 | static const char lcc[] ALIGN1 = "diouxX"; | 22 | static const char lcc[] ALIGN1 = "diouxX"; |
| 36 | 23 | ||
| 37 | int FAST_FUNC bb_dump_size(FS *fs) | 24 | |
| 25 | typedef struct priv_dumper_t { | ||
| 26 | dumper_t pub; | ||
| 27 | |||
| 28 | char **argv; | ||
| 29 | FU *endfu; | ||
| 30 | off_t savaddress; /* saved address/offset in stream */ | ||
| 31 | off_t eaddress; /* end address */ | ||
| 32 | off_t address; /* address/offset in stream */ | ||
| 33 | int blocksize; | ||
| 34 | smallint exitval; /* final exit value */ | ||
| 35 | |||
| 36 | /* former statics */ | ||
| 37 | smallint next__done; | ||
| 38 | smallint get__ateof; // = 1; | ||
| 39 | unsigned char *get__curp; | ||
| 40 | unsigned char *get__savp; | ||
| 41 | } priv_dumper_t; | ||
| 42 | |||
| 43 | dumper_t* FAST_FUNC alloc_dumper(void) | ||
| 44 | { | ||
| 45 | priv_dumper_t *dumper = xzalloc(sizeof(*dumper)); | ||
| 46 | dumper->pub.dump_length = -1; | ||
| 47 | dumper->pub.dump_vflag = FIRST; | ||
| 48 | dumper->get__ateof = 1; | ||
| 49 | return &dumper->pub; | ||
| 50 | } | ||
| 51 | |||
| 52 | |||
| 53 | static NOINLINE int bb_dump_size(FS *fs) | ||
| 38 | { | 54 | { |
| 39 | FU *fu; | 55 | FU *fu; |
| 40 | int bcnt, cur_size; | 56 | int bcnt, cur_size; |
| @@ -52,13 +68,14 @@ int FAST_FUNC bb_dump_size(FS *fs) | |||
| 52 | if (*fmt != '%') | 68 | if (*fmt != '%') |
| 53 | continue; | 69 | continue; |
| 54 | /* | 70 | /* |
| 55 | * bb_dump_skip any special chars -- save precision in | 71 | * skip any special chars -- save precision in |
| 56 | * case it's a %s format. | 72 | * case it's a %s format. |
| 57 | */ | 73 | */ |
| 58 | while (strchr(index_str + 1, *++fmt)); | 74 | while (strchr(index_str + 1, *++fmt)); |
| 59 | if (*fmt == '.' && isdigit(*++fmt)) { | 75 | if (*fmt == '.' && isdigit(*++fmt)) { |
| 60 | prec = atoi(fmt); | 76 | prec = atoi(fmt); |
| 61 | while (isdigit(*++fmt)); | 77 | while (isdigit(*++fmt)) |
| 78 | continue; | ||
| 62 | } | 79 | } |
| 63 | p = strchr(size_conv_str + 12, *fmt); | 80 | p = strchr(size_conv_str + 12, *fmt); |
| 64 | if (!p) { | 81 | if (!p) { |
| @@ -79,7 +96,7 @@ int FAST_FUNC bb_dump_size(FS *fs) | |||
| 79 | return cur_size; | 96 | return cur_size; |
| 80 | } | 97 | } |
| 81 | 98 | ||
| 82 | static void rewrite(FS *fs) | 99 | static void rewrite(priv_dumper_t *dumper, FS *fs) |
| 83 | { | 100 | { |
| 84 | enum { NOTOKAY, USEBCNT, USEPREC } sokay; | 101 | enum { NOTOKAY, USEBCNT, USEPREC } sokay; |
| 85 | PR *pr, **nextpr = NULL; | 102 | PR *pr, **nextpr = NULL; |
| @@ -104,7 +121,7 @@ static void rewrite(FS *fs) | |||
| 104 | * uninitialized 1st time through. | 121 | * uninitialized 1st time through. |
| 105 | */ | 122 | */ |
| 106 | 123 | ||
| 107 | /* bb_dump_skip preceding text and up to the next % sign */ | 124 | /* skip preceding text and up to the next % sign */ |
| 108 | for (p1 = fmtp; *p1 && *p1 != '%'; ++p1) | 125 | for (p1 = fmtp; *p1 && *p1 != '%'; ++p1) |
| 109 | continue; | 126 | continue; |
| 110 | 127 | ||
| @@ -121,11 +138,11 @@ static void rewrite(FS *fs) | |||
| 121 | */ | 138 | */ |
| 122 | if (fu->bcnt) { | 139 | if (fu->bcnt) { |
| 123 | sokay = USEBCNT; | 140 | sokay = USEBCNT; |
| 124 | /* bb_dump_skip to conversion character */ | 141 | /* skip to conversion character */ |
| 125 | for (++p1; strchr(index_str, *p1); ++p1) | 142 | for (++p1; strchr(index_str, *p1); ++p1) |
| 126 | continue; | 143 | continue; |
| 127 | } else { | 144 | } else { |
| 128 | /* bb_dump_skip any special chars, field width */ | 145 | /* skip any special chars, field width */ |
| 129 | while (strchr(index_str + 1, *++p1)) | 146 | while (strchr(index_str + 1, *++p1)) |
| 130 | continue; | 147 | continue; |
| 131 | if (*p1 == '.' && isdigit(*++p1)) { | 148 | if (*p1 == '.' && isdigit(*++p1)) { |
| @@ -137,7 +154,7 @@ static void rewrite(FS *fs) | |||
| 137 | sokay = NOTOKAY; | 154 | sokay = NOTOKAY; |
| 138 | } | 155 | } |
| 139 | 156 | ||
| 140 | p2 = p1 + 1; /* set end pointer */ | 157 | p2 = p1 + 1; /* set end pointer */ |
| 141 | 158 | ||
| 142 | /* | 159 | /* |
| 143 | * figure out the byte count for each conversion; | 160 | * figure out the byte count for each conversion; |
| @@ -198,7 +215,7 @@ static void rewrite(FS *fs) | |||
| 198 | ++p2; | 215 | ++p2; |
| 199 | switch (p1[1]) { | 216 | switch (p1[1]) { |
| 200 | case 'A': | 217 | case 'A': |
| 201 | endfu = fu; | 218 | dumper->endfu = fu; |
| 202 | fu->flags |= F_IGNORE; | 219 | fu->flags |= F_IGNORE; |
| 203 | /* FALLTHROUGH */ | 220 | /* FALLTHROUGH */ |
| 204 | case 'a': | 221 | case 'a': |
| @@ -274,7 +291,7 @@ static void rewrite(FS *fs) | |||
| 274 | } | 291 | } |
| 275 | /* | 292 | /* |
| 276 | * if the format string interprets any data at all, and it's | 293 | * if the format string interprets any data at all, and it's |
| 277 | * not the same as the bb_dump_blocksize, and its last format unit | 294 | * not the same as the blocksize, and its last format unit |
| 278 | * interprets any data at all, and has no iteration count, | 295 | * interprets any data at all, and has no iteration count, |
| 279 | * repeat it as necessary. | 296 | * repeat it as necessary. |
| 280 | * | 297 | * |
| @@ -282,10 +299,10 @@ static void rewrite(FS *fs) | |||
| 282 | * gets output from the last iteration of the format unit. | 299 | * gets output from the last iteration of the format unit. |
| 283 | */ | 300 | */ |
| 284 | for (fu = fs->nextfu;; fu = fu->nextfu) { | 301 | for (fu = fs->nextfu;; fu = fu->nextfu) { |
| 285 | if (!fu->nextfu && fs->bcnt < bb_dump_blocksize | 302 | if (!fu->nextfu && fs->bcnt < dumper->blocksize |
| 286 | && !(fu->flags & F_SETREP) && fu->bcnt | 303 | && !(fu->flags & F_SETREP) && fu->bcnt |
| 287 | ) { | 304 | ) { |
| 288 | fu->reps += (bb_dump_blocksize - fs->bcnt) / fu->bcnt; | 305 | fu->reps += (dumper->blocksize - fs->bcnt) / fu->bcnt; |
| 289 | } | 306 | } |
| 290 | if (fu->reps > 1) { | 307 | if (fu->reps > 1) { |
| 291 | for (pr = fu->nextpr;; pr = pr->nextpr) | 308 | for (pr = fu->nextpr;; pr = pr->nextpr) |
| @@ -301,7 +318,7 @@ static void rewrite(FS *fs) | |||
| 301 | } | 318 | } |
| 302 | } | 319 | } |
| 303 | 320 | ||
| 304 | static void do_skip(const char *fname, int statok) | 321 | static void do_skip(priv_dumper_t *dumper, const char *fname, int statok) |
| 305 | { | 322 | { |
| 306 | struct stat sbuf; | 323 | struct stat sbuf; |
| 307 | 324 | ||
| @@ -309,125 +326,122 @@ static void do_skip(const char *fname, int statok) | |||
| 309 | if (fstat(STDIN_FILENO, &sbuf)) { | 326 | if (fstat(STDIN_FILENO, &sbuf)) { |
| 310 | bb_simple_perror_msg_and_die(fname); | 327 | bb_simple_perror_msg_and_die(fname); |
| 311 | } | 328 | } |
| 312 | if ((!(S_ISCHR(sbuf.st_mode) || | 329 | if (!(S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode) || S_ISFIFO(sbuf.st_mode)) |
| 313 | S_ISBLK(sbuf.st_mode) || | 330 | && dumper->pub.dump_skip >= sbuf.st_size |
| 314 | S_ISFIFO(sbuf.st_mode))) && bb_dump_skip >= sbuf.st_size) { | 331 | ) { |
| 315 | /* If bb_dump_size valid and bb_dump_skip >= size */ | 332 | /* If bb_dump_size valid and pub.dump_skip >= size */ |
| 316 | bb_dump_skip -= sbuf.st_size; | 333 | dumper->pub.dump_skip -= sbuf.st_size; |
| 317 | address += sbuf.st_size; | 334 | dumper->address += sbuf.st_size; |
| 318 | return; | 335 | return; |
| 319 | } | 336 | } |
| 320 | } | 337 | } |
| 321 | if (fseek(stdin, bb_dump_skip, SEEK_SET)) { | 338 | if (fseek(stdin, dumper->pub.dump_skip, SEEK_SET)) { |
| 322 | bb_simple_perror_msg_and_die(fname); | 339 | bb_simple_perror_msg_and_die(fname); |
| 323 | } | 340 | } |
| 324 | savaddress = address += bb_dump_skip; | 341 | dumper->address += dumper->pub.dump_skip; |
| 325 | bb_dump_skip = 0; | 342 | dumper->savaddress = dumper->address; |
| 343 | dumper->pub.dump_skip = 0; | ||
| 326 | } | 344 | } |
| 327 | 345 | ||
| 328 | static int next(char **argv) | 346 | static NOINLINE int next(priv_dumper_t *dumper) |
| 329 | { | 347 | { |
| 330 | static smallint done; | ||
| 331 | |||
| 332 | int statok; | 348 | int statok; |
| 333 | 349 | ||
| 334 | if (argv) { | ||
| 335 | _argv = argv; | ||
| 336 | return 1; | ||
| 337 | } | ||
| 338 | for (;;) { | 350 | for (;;) { |
| 339 | if (*_argv) { | 351 | if (*dumper->argv) { |
| 340 | if (!(freopen(*_argv, "r", stdin))) { | 352 | if (!(freopen(*dumper->argv, "r", stdin))) { |
| 341 | bb_simple_perror_msg(*_argv); | 353 | bb_simple_perror_msg(*dumper->argv); |
| 342 | exitval = 1; | 354 | dumper->exitval = 1; |
| 343 | ++_argv; | 355 | ++dumper->argv; |
| 344 | continue; | 356 | continue; |
| 345 | } | 357 | } |
| 346 | done = statok = 1; | 358 | dumper->next__done = statok = 1; |
| 347 | } else { | 359 | } else { |
| 348 | if (done) | 360 | if (dumper->next__done) |
| 349 | return 0; | 361 | return 0; |
| 350 | done = 1; | 362 | dumper->next__done = 1; |
| 351 | statok = 0; | 363 | statok = 0; |
| 352 | } | 364 | } |
| 353 | if (bb_dump_skip) | 365 | if (dumper->pub.dump_skip) |
| 354 | do_skip(statok ? *_argv : "stdin", statok); | 366 | do_skip(dumper, statok ? *dumper->argv : "stdin", statok); |
| 355 | if (*_argv) | 367 | if (*dumper->argv) |
| 356 | ++_argv; | 368 | ++dumper->argv; |
| 357 | if (!bb_dump_skip) | 369 | if (!dumper->pub.dump_skip) |
| 358 | return 1; | 370 | return 1; |
| 359 | } | 371 | } |
| 360 | /* NOTREACHED */ | 372 | /* NOTREACHED */ |
| 361 | } | 373 | } |
| 362 | 374 | ||
| 363 | static unsigned char *get(void) | 375 | static unsigned char *get(priv_dumper_t *dumper) |
| 364 | { | 376 | { |
| 365 | static smallint ateof = 1; | ||
| 366 | static unsigned char *curp = NULL, *savp; /*DBU:[dave@cray.com]initialize curp */ | ||
| 367 | |||
| 368 | int n; | 377 | int n; |
| 369 | int need, nread; | 378 | int need, nread; |
| 370 | unsigned char *tmpp; | 379 | unsigned char *tmpp; |
| 380 | int blocksize = dumper->blocksize; | ||
| 371 | 381 | ||
| 372 | if (!curp) { | 382 | if (!dumper->get__curp) { |
| 373 | address = (off_t)0; /*DBU:[dave@cray.com] initialize,initialize..*/ | 383 | dumper->address = (off_t)0; /*DBU:[dave@cray.com] initialize,initialize..*/ |
| 374 | curp = xmalloc(bb_dump_blocksize); | 384 | dumper->get__curp = xmalloc(blocksize); |
| 375 | savp = xmalloc(bb_dump_blocksize); | 385 | dumper->get__savp = xmalloc(blocksize); |
| 376 | } else { | 386 | } else { |
| 377 | tmpp = curp; | 387 | tmpp = dumper->get__curp; |
| 378 | curp = savp; | 388 | dumper->get__curp = dumper->get__savp; |
| 379 | savp = tmpp; | 389 | dumper->get__savp = tmpp; |
| 380 | address = savaddress += bb_dump_blocksize; | 390 | dumper->savaddress += blocksize; |
| 391 | dumper->address = dumper->savaddress; | ||
| 381 | } | 392 | } |
| 382 | for (need = bb_dump_blocksize, nread = 0;;) { | 393 | need = blocksize; |
| 394 | nread = 0; | ||
| 395 | while (1) { | ||
| 383 | /* | 396 | /* |
| 384 | * if read the right number of bytes, or at EOF for one file, | 397 | * if read the right number of bytes, or at EOF for one file, |
| 385 | * and no other files are available, zero-pad the rest of the | 398 | * and no other files are available, zero-pad the rest of the |
| 386 | * block and set the end flag. | 399 | * block and set the end flag. |
| 387 | */ | 400 | */ |
| 388 | if (!bb_dump_length || (ateof && !next(NULL))) { | 401 | if (!dumper->pub.dump_length || (dumper->get__ateof && !next(dumper))) { |
| 389 | if (need == bb_dump_blocksize) { | 402 | if (need == blocksize) { |
| 390 | return NULL; | 403 | return NULL; |
| 391 | } | 404 | } |
| 392 | if (bb_dump_vflag != ALL && !memcmp(curp, savp, nread)) { | 405 | if (dumper->pub.dump_vflag != ALL && !memcmp(dumper->get__curp, dumper->get__savp, nread)) { |
| 393 | if (bb_dump_vflag != DUP) { | 406 | if (dumper->pub.dump_vflag != DUP) { |
| 394 | puts("*"); | 407 | puts("*"); |
| 395 | } | 408 | } |
| 396 | return NULL; | 409 | return NULL; |
| 397 | } | 410 | } |
| 398 | memset(curp + nread, 0, need); | 411 | memset(dumper->get__curp + nread, 0, need); |
| 399 | eaddress = address + nread; | 412 | dumper->eaddress = dumper->address + nread; |
| 400 | return curp; | 413 | return dumper->get__curp; |
| 401 | } | 414 | } |
| 402 | n = fread(curp + nread, sizeof(unsigned char), | 415 | n = fread(dumper->get__curp + nread, sizeof(unsigned char), |
| 403 | bb_dump_length == -1 ? need : MIN(bb_dump_length, need), stdin); | 416 | dumper->pub.dump_length == -1 ? need : MIN(dumper->pub.dump_length, need), stdin); |
| 404 | if (!n) { | 417 | if (!n) { |
| 405 | if (ferror(stdin)) { | 418 | if (ferror(stdin)) { |
| 406 | bb_simple_perror_msg(_argv[-1]); | 419 | bb_simple_perror_msg(dumper->argv[-1]); |
| 407 | } | 420 | } |
| 408 | ateof = 1; | 421 | dumper->get__ateof = 1; |
| 409 | continue; | 422 | continue; |
| 410 | } | 423 | } |
| 411 | ateof = 0; | 424 | dumper->get__ateof = 0; |
| 412 | if (bb_dump_length != -1) { | 425 | if (dumper->pub.dump_length != -1) { |
| 413 | bb_dump_length -= n; | 426 | dumper->pub.dump_length -= n; |
| 414 | } | 427 | } |
| 415 | need -= n; | 428 | need -= n; |
| 416 | if (!need) { | 429 | if (!need) { |
| 417 | if (bb_dump_vflag == ALL || bb_dump_vflag == FIRST | 430 | if (dumper->pub.dump_vflag == ALL || dumper->pub.dump_vflag == FIRST |
| 418 | || memcmp(curp, savp, bb_dump_blocksize) | 431 | || memcmp(dumper->get__curp, dumper->get__savp, blocksize) |
| 419 | ) { | 432 | ) { |
| 420 | if (bb_dump_vflag == DUP || bb_dump_vflag == FIRST) { | 433 | if (dumper->pub.dump_vflag == DUP || dumper->pub.dump_vflag == FIRST) { |
| 421 | bb_dump_vflag = WAIT; | 434 | dumper->pub.dump_vflag = WAIT; |
| 422 | } | 435 | } |
| 423 | return curp; | 436 | return dumper->get__curp; |
| 424 | } | 437 | } |
| 425 | if (bb_dump_vflag == WAIT) { | 438 | if (dumper->pub.dump_vflag == WAIT) { |
| 426 | puts("*"); | 439 | puts("*"); |
| 427 | } | 440 | } |
| 428 | bb_dump_vflag = DUP; | 441 | dumper->pub.dump_vflag = DUP; |
| 429 | address = savaddress += bb_dump_blocksize; | 442 | dumper->savaddress += blocksize; |
| 430 | need = bb_dump_blocksize; | 443 | dumper->address = dumper->savaddress; |
| 444 | need = blocksize; | ||
| 431 | nread = 0; | 445 | nread = 0; |
| 432 | } else { | 446 | } else { |
| 433 | nread += n; | 447 | nread += n; |
| @@ -515,29 +529,31 @@ static void conv_u(PR *pr, unsigned char *p) | |||
| 515 | } | 529 | } |
| 516 | } | 530 | } |
| 517 | 531 | ||
| 518 | static void display(void) | 532 | static void display(priv_dumper_t* dumper) |
| 519 | { | 533 | { |
| 520 | /* extern FU *endfu; */ | ||
| 521 | FS *fs; | 534 | FS *fs; |
| 522 | FU *fu; | 535 | FU *fu; |
| 523 | PR *pr; | 536 | PR *pr; |
| 524 | int cnt; | 537 | int cnt; |
| 525 | unsigned char *bp; | 538 | unsigned char *bp, *savebp; |
| 526 | off_t saveaddress; | 539 | off_t saveaddress; |
| 527 | unsigned char savech = 0, *savebp; | 540 | unsigned char savech = '\0'; |
| 528 | 541 | ||
| 529 | while ((bp = get()) != NULL) { | 542 | while ((bp = get(dumper)) != NULL) { |
| 530 | for (fs = bb_dump_fshead, savebp = bp, saveaddress = address; fs; | 543 | fs = dumper->pub.fshead; |
| 531 | fs = fs->nextfs, bp = savebp, address = saveaddress) { | 544 | savebp = bp; |
| 545 | saveaddress = dumper->address; | ||
| 546 | for (; fs; fs = fs->nextfs, bp = savebp, dumper->address = saveaddress) { | ||
| 532 | for (fu = fs->nextfu; fu; fu = fu->nextfu) { | 547 | for (fu = fs->nextfu; fu; fu = fu->nextfu) { |
| 533 | if (fu->flags & F_IGNORE) { | 548 | if (fu->flags & F_IGNORE) { |
| 534 | break; | 549 | break; |
| 535 | } | 550 | } |
| 536 | for (cnt = fu->reps; cnt; --cnt) { | 551 | for (cnt = fu->reps; cnt; --cnt) { |
| 537 | for (pr = fu->nextpr; pr; address += pr->bcnt, | 552 | for (pr = fu->nextpr; pr; dumper->address += pr->bcnt, |
| 538 | bp += pr->bcnt, pr = pr->nextpr) { | 553 | bp += pr->bcnt, pr = pr->nextpr) { |
| 539 | if (eaddress && address >= eaddress && | 554 | if (dumper->eaddress && dumper->address >= dumper->eaddress |
| 540 | !(pr->flags & (F_TEXT | F_BPAD))) { | 555 | && !(pr->flags & (F_TEXT | F_BPAD)) |
| 556 | ) { | ||
| 541 | bpad(pr); | 557 | bpad(pr); |
| 542 | } | 558 | } |
| 543 | if (cnt == 1 && pr->nospace) { | 559 | if (cnt == 1 && pr->nospace) { |
| @@ -547,7 +563,7 @@ static void display(void) | |||
| 547 | /* PRINT; */ | 563 | /* PRINT; */ |
| 548 | switch (pr->flags) { | 564 | switch (pr->flags) { |
| 549 | case F_ADDRESS: | 565 | case F_ADDRESS: |
| 550 | printf(pr->fmt, (unsigned) address); | 566 | printf(pr->fmt, (unsigned) dumper->address); |
| 551 | break; | 567 | break; |
| 552 | case F_BPAD: | 568 | case F_BPAD: |
| 553 | printf(pr->fmt, ""); | 569 | printf(pr->fmt, ""); |
| @@ -558,7 +574,7 @@ static void display(void) | |||
| 558 | case F_CHAR: | 574 | case F_CHAR: |
| 559 | printf(pr->fmt, *bp); | 575 | printf(pr->fmt, *bp); |
| 560 | break; | 576 | break; |
| 561 | case F_DBL:{ | 577 | case F_DBL: { |
| 562 | double dval; | 578 | double dval; |
| 563 | float fval; | 579 | float fval; |
| 564 | 580 | ||
| @@ -574,7 +590,7 @@ static void display(void) | |||
| 574 | } | 590 | } |
| 575 | break; | 591 | break; |
| 576 | } | 592 | } |
| 577 | case F_INT:{ | 593 | case F_INT: { |
| 578 | int ival; | 594 | int ival; |
| 579 | short sval; | 595 | short sval; |
| 580 | 596 | ||
| @@ -605,7 +621,7 @@ static void display(void) | |||
| 605 | case F_U: | 621 | case F_U: |
| 606 | conv_u(pr, bp); | 622 | conv_u(pr, bp); |
| 607 | break; | 623 | break; |
| 608 | case F_UINT:{ | 624 | case F_UINT: { |
| 609 | unsigned ival; | 625 | unsigned ival; |
| 610 | unsigned short sval; | 626 | unsigned short sval; |
| 611 | 627 | ||
| @@ -633,21 +649,21 @@ static void display(void) | |||
| 633 | } | 649 | } |
| 634 | } | 650 | } |
| 635 | } | 651 | } |
| 636 | if (endfu) { | 652 | if (dumper->endfu) { |
| 637 | /* | 653 | /* |
| 638 | * if eaddress not set, error or file bb_dump_size was multiple of | 654 | * if eaddress not set, error or file size was multiple |
| 639 | * bb_dump_blocksize, and no partial block ever found. | 655 | * of blocksize, and no partial block ever found. |
| 640 | */ | 656 | */ |
| 641 | if (!eaddress) { | 657 | if (!dumper->eaddress) { |
| 642 | if (!address) { | 658 | if (!dumper->address) { |
| 643 | return; | 659 | return; |
| 644 | } | 660 | } |
| 645 | eaddress = address; | 661 | dumper->eaddress = dumper->address; |
| 646 | } | 662 | } |
| 647 | for (pr = endfu->nextpr; pr; pr = pr->nextpr) { | 663 | for (pr = dumper->endfu->nextpr; pr; pr = pr->nextpr) { |
| 648 | switch (pr->flags) { | 664 | switch (pr->flags) { |
| 649 | case F_ADDRESS: | 665 | case F_ADDRESS: |
| 650 | printf(pr->fmt, (unsigned) eaddress); | 666 | printf(pr->fmt, (unsigned) dumper->eaddress); |
| 651 | break; | 667 | break; |
| 652 | case F_TEXT: | 668 | case F_TEXT: |
| 653 | printf(pr->fmt); | 669 | printf(pr->fmt); |
| @@ -657,52 +673,58 @@ static void display(void) | |||
| 657 | } | 673 | } |
| 658 | } | 674 | } |
| 659 | 675 | ||
| 660 | int FAST_FUNC bb_dump_dump(char **argv) | 676 | #define dumper ((priv_dumper_t*)pub_dumper) |
| 677 | int FAST_FUNC bb_dump_dump(dumper_t *pub_dumper, char **argv) | ||
| 661 | { | 678 | { |
| 662 | FS *tfs; | 679 | FS *tfs; |
| 680 | int blocksize; | ||
| 663 | 681 | ||
| 664 | /* figure out the data block bb_dump_size */ | 682 | /* figure out the data block bb_dump_size */ |
| 665 | for (bb_dump_blocksize = 0, tfs = bb_dump_fshead; tfs; tfs = tfs->nextfs) { | 683 | blocksize = 0; |
| 684 | tfs = dumper->pub.fshead; | ||
| 685 | while (tfs) { | ||
| 666 | tfs->bcnt = bb_dump_size(tfs); | 686 | tfs->bcnt = bb_dump_size(tfs); |
| 667 | if (bb_dump_blocksize < tfs->bcnt) { | 687 | if (blocksize < tfs->bcnt) { |
| 668 | bb_dump_blocksize = tfs->bcnt; | 688 | blocksize = tfs->bcnt; |
| 669 | } | 689 | } |
| 690 | tfs = tfs->nextfs; | ||
| 670 | } | 691 | } |
| 692 | dumper->blocksize = blocksize; | ||
| 693 | |||
| 671 | /* rewrite the rules, do syntax checking */ | 694 | /* rewrite the rules, do syntax checking */ |
| 672 | for (tfs = bb_dump_fshead; tfs; tfs = tfs->nextfs) { | 695 | for (tfs = dumper->pub.fshead; tfs; tfs = tfs->nextfs) { |
| 673 | rewrite(tfs); | 696 | rewrite(dumper, tfs); |
| 674 | } | 697 | } |
| 675 | 698 | ||
| 676 | next(argv); | 699 | dumper->argv = argv; |
| 677 | display(); | 700 | display(dumper); |
| 678 | 701 | ||
| 679 | return exitval; | 702 | return dumper->exitval; |
| 680 | } | 703 | } |
| 681 | 704 | ||
| 682 | void FAST_FUNC bb_dump_add(const char *fmt) | 705 | void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt) |
| 683 | { | 706 | { |
| 684 | static FS **nextfs; | ||
| 685 | |||
| 686 | const char *p; | 707 | const char *p; |
| 687 | char *p1; | 708 | char *p1; |
| 688 | char *p2; | 709 | char *p2; |
| 689 | FS *tfs; | 710 | FS *tfs; |
| 690 | FU *tfu, **nextfu; | 711 | FU *tfu, **nextfupp; |
| 691 | const char *savep; | 712 | const char *savep; |
| 692 | 713 | ||
| 693 | /* start new linked list of format units */ | 714 | /* start new linked list of format units */ |
| 694 | tfs = xzalloc(sizeof(FS)); /*DBU:[dave@cray.com] start out NULL */ | 715 | tfs = xzalloc(sizeof(FS)); /*DBU:[dave@cray.com] start out NULL */ |
| 695 | if (!bb_dump_fshead) { | 716 | if (!dumper->pub.fshead) { |
| 696 | bb_dump_fshead = tfs; | 717 | dumper->pub.fshead = tfs; |
| 697 | } else { | 718 | } else { |
| 698 | *nextfs = tfs; | 719 | FS *fslast = dumper->pub.fshead; |
| 720 | while (fslast->nextfs) | ||
| 721 | fslast = fslast->nextfs; | ||
| 722 | fslast->nextfs = tfs; | ||
| 699 | } | 723 | } |
| 700 | nextfs = &tfs->nextfs; | 724 | nextfupp = &tfs->nextfu; |
| 701 | nextfu = &tfs->nextfu; | ||
| 702 | 725 | ||
| 703 | /* take the format string and break it up into format units */ | 726 | /* take the format string and break it up into format units */ |
| 704 | for (p = fmt;;) { | 727 | for (p = fmt;;) { |
| 705 | /* bb_dump_skip leading white space */ | ||
| 706 | p = skip_whitespace(p); | 728 | p = skip_whitespace(p); |
| 707 | if (!*p) { | 729 | if (!*p) { |
| 708 | break; | 730 | break; |
| @@ -712,8 +734,8 @@ void FAST_FUNC bb_dump_add(const char *fmt) | |||
| 712 | /* NOSTRICT */ | 734 | /* NOSTRICT */ |
| 713 | /* DBU:[dave@cray.com] zalloc so that forward pointers start out NULL */ | 735 | /* DBU:[dave@cray.com] zalloc so that forward pointers start out NULL */ |
| 714 | tfu = xzalloc(sizeof(FU)); | 736 | tfu = xzalloc(sizeof(FU)); |
| 715 | *nextfu = tfu; | 737 | *nextfupp = tfu; |
| 716 | nextfu = &tfu->nextfu; | 738 | nextfupp = &tfu->nextfu; |
| 717 | tfu->reps = 1; | 739 | tfu->reps = 1; |
| 718 | 740 | ||
| 719 | /* if leading digit, repetition count */ | 741 | /* if leading digit, repetition count */ |
| @@ -726,11 +748,11 @@ void FAST_FUNC bb_dump_add(const char *fmt) | |||
| 726 | /* may overwrite either white space or slash */ | 748 | /* may overwrite either white space or slash */ |
| 727 | tfu->reps = atoi(savep); | 749 | tfu->reps = atoi(savep); |
| 728 | tfu->flags = F_SETREP; | 750 | tfu->flags = F_SETREP; |
| 729 | /* bb_dump_skip trailing white space */ | 751 | /* skip trailing white space */ |
| 730 | p = skip_whitespace(++p); | 752 | p = skip_whitespace(++p); |
| 731 | } | 753 | } |
| 732 | 754 | ||
| 733 | /* bb_dump_skip slash and trailing white space */ | 755 | /* skip slash and trailing white space */ |
| 734 | if (*p == '/') { | 756 | if (*p == '/') { |
| 735 | p = skip_whitespace(++p); | 757 | p = skip_whitespace(++p); |
| 736 | } | 758 | } |
| @@ -745,7 +767,7 @@ void FAST_FUNC bb_dump_add(const char *fmt) | |||
| 745 | bb_error_msg_and_die("bad format {%s}", fmt); | 767 | bb_error_msg_and_die("bad format {%s}", fmt); |
| 746 | } | 768 | } |
| 747 | tfu->bcnt = atoi(savep); | 769 | tfu->bcnt = atoi(savep); |
| 748 | /* bb_dump_skip trailing white space */ | 770 | /* skip trailing white space */ |
| 749 | p = skip_whitespace(++p); | 771 | p = skip_whitespace(++p); |
| 750 | } | 772 | } |
| 751 | 773 | ||
