Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/dump.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/libbb/dump.c
r1765 r2725 5 5 * 6 6 * Copyright (c) 1989 7 * 7 * The Regents of the University of California. All rights reserved. 8 8 * 9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.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. … … 15 15 #include "dump.h" 16 16 17 enum _vflag bb_dump_vflag = FIRST;18 FS *bb_dump_fshead; /* head of format strings */19 static FU *endfu;20 static char **_argv;21 static off_t savaddress; /* saved address/offset in stream */22 static off_t eaddress; /* end address */23 static off_t address; /* address/offset in stream */24 off_t bb_dump_skip; /* bytes to skip */25 static int exitval; /* final exit value */26 int bb_dump_blocksize; /* data block size */27 int bb_dump_length = -1; /* max bytes to read */28 29 17 static const char index_str[] ALIGN1 = ".#-+ 0123456789"; 30 18 … … 34 22 static const char lcc[] ALIGN1 = "diouxX"; 35 23 36 int 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) 37 54 { 38 55 FU *fu; … … 52 69 continue; 53 70 /* 54 * bb_dump_skip any special chars -- save precision in71 * skip any special chars -- save precision in 55 72 * case it's a %s format. 56 73 */ … … 58 75 if (*fmt == '.' && isdigit(*++fmt)) { 59 76 prec = atoi(fmt); 60 while (isdigit(*++fmt)); 61 } 62 if (!(p = strchr(size_conv_str + 12, *fmt))) { 77 while (isdigit(*++fmt)) 78 continue; 79 } 80 p = strchr(size_conv_str + 12, *fmt); 81 if (!p) { 63 82 if (*fmt == 's') { 64 83 bcnt += prec; … … 78 97 } 79 98 80 static void rewrite(FS *fs)99 static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) 81 100 { 82 101 enum { NOTOKAY, USEBCNT, USEPREC } sokay; … … 95 114 for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) { 96 115 /* NOSTRICT */ 97 /* DBU:[dvae@cray.com] calloc so that forward ptrs start out NULL*/116 /* DBU:[dvae@cray.com] zalloc so that forward ptrs start out NULL*/ 98 117 pr = xzalloc(sizeof(PR)); 99 118 if (!fu->nextpr) 100 119 fu->nextpr = pr; 101 120 /* ignore nextpr -- its unused inside the loop and is 102 * uninitialized 1st time thr u.121 * uninitialized 1st time through. 103 122 */ 104 123 105 /* bb_dump_skip preceding text and up to the next % sign */ 106 for (p1 = fmtp; *p1 && *p1 != '%'; ++p1); 124 /* skip preceding text and up to the next % sign */ 125 for (p1 = fmtp; *p1 && *p1 != '%'; ++p1) 126 continue; 107 127 108 128 /* only text in the string */ … … 119 139 if (fu->bcnt) { 120 140 sokay = USEBCNT; 121 /* bb_dump_skip to conversion character */ 122 for (++p1; strchr(index_str, *p1); ++p1); 141 /* skip to conversion character */ 142 for (++p1; strchr(index_str, *p1); ++p1) 143 continue; 123 144 } else { 124 /* bb_dump_skip any special chars, field width */ 125 while (strchr(index_str + 1, *++p1)); 145 /* skip any special chars, field width */ 146 while (strchr(index_str + 1, *++p1)) 147 continue; 126 148 if (*p1 == '.' && isdigit(*++p1)) { 127 149 sokay = USEPREC; 128 150 prec = atoi(p1); 129 while (isdigit(*++p1)); 151 while (isdigit(*++p1)) 152 continue; 130 153 } else 131 154 sokay = NOTOKAY; 132 155 } 133 156 134 p2 = p1 + 1; 157 p2 = p1 + 1; /* set end pointer */ 135 158 136 159 /* … … 139 162 * pbb_dump_adding for end of data. 140 163 */ 141 142 164 if (*p1 == 'c') { 143 165 pr->flags = F_CHAR; 144 166 DO_BYTE_COUNT_1: 145 167 byte_count_str = "\001"; 146 168 DO_BYTE_COUNT: 147 169 if (fu->bcnt) { 148 170 do { … … 160 182 ++p2; 161 183 ++p1; 162 184 DO_INT_CONV: 163 185 { 164 186 const char *e; 165 if (!(e = strchr(lcc, *p1))) { 187 e = strchr(lcc, *p1); 188 if (!e) { 166 189 goto DO_BAD_CONV_CHAR; 167 190 } … … 186 209 } else if (sokay == USEPREC) { 187 210 pr->bcnt = prec; 188 } else { 211 } else { /* NOTOKAY */ 189 212 bb_error_msg_and_die("%%s requires a precision or a byte count"); 190 213 } … … 193 216 switch (p1[1]) { 194 217 case 'A': 195 endfu = fu;218 dumper->endfu = fu; 196 219 fu->flags |= F_IGNORE; 197 220 /* FALLTHROUGH */ … … 220 243 } 221 244 } else { 222 245 DO_BAD_CONV_CHAR: 223 246 bb_error_msg_and_die("bad conversion character %%%s", p1); 224 247 } … … 232 255 pr->fmt = xstrdup(fmtp); 233 256 *p2 = savech; 234 pr->cchar = pr->fmt + (p1 - fmtp); 257 //Too early! xrealloc can move pr->fmt! 258 //pr->cchar = pr->fmt + (p1 - fmtp); 235 259 236 260 /* DBU:[dave@cray.com] w/o this, trailing fmt text, space is lost. … … 239 263 * we lose the " is a HEX number" part of fmt. 240 264 */ 241 for (p3 = p2; *p3 && *p3 != '%'; p3++) ;242 if (p3 > p2)243 {265 for (p3 = p2; *p3 && *p3 != '%'; p3++) 266 continue; 267 if (p3 > p2) { 244 268 savech = *p3; 245 269 *p3 = '\0'; 246 pr->fmt = xrealloc(pr->fmt, strlen(pr->fmt) +(p3-p2)+1);270 pr->fmt = xrealloc(pr->fmt, strlen(pr->fmt) + (p3-p2) + 1); 247 271 strcat(pr->fmt, p2); 248 272 *p3 = savech; … … 250 274 } 251 275 276 pr->cchar = pr->fmt + (p1 - fmtp); 252 277 fmtp = p2; 253 278 … … 267 292 /* 268 293 * if the format string interprets any data at all, and it's 269 * not the same as the b b_dump_blocksize, and its last format unit294 * not the same as the blocksize, and its last format unit 270 295 * interprets any data at all, and has no iteration count, 271 296 * repeat it as necessary. … … 274 299 * gets output from the last iteration of the format unit. 275 300 */ 276 for (fu = fs->nextfu;; fu = fu->nextfu) { 277 if (!fu->nextfu && fs->bcnt < bb_dump_blocksize && 278 !(fu->flags & F_SETREP) && fu->bcnt) 279 fu->reps += (bb_dump_blocksize - fs->bcnt) / fu->bcnt; 301 for (fu = fs->nextfu; fu; fu = fu->nextfu) { 302 if (!fu->nextfu && fs->bcnt < dumper->blocksize 303 && !(fu->flags & F_SETREP) && fu->bcnt 304 ) { 305 fu->reps += (dumper->blocksize - fs->bcnt) / fu->bcnt; 306 } 280 307 if (fu->reps > 1) { 281 308 for (pr = fu->nextpr;; pr = pr->nextpr) … … 292 319 } 293 320 294 static void do_skip( const char *fname, int statok)321 static void do_skip(priv_dumper_t *dumper, const char *fname, int statok) 295 322 { 296 323 struct stat sbuf; 297 324 298 325 if (statok) { 299 if (fstat(STDIN_FILENO, &sbuf)) { 300 bb_perror_msg_and_die("%s", fname); 301 } 302 if ((!(S_ISCHR(sbuf.st_mode) || 303 S_ISBLK(sbuf.st_mode) || 304 S_ISFIFO(sbuf.st_mode))) && bb_dump_skip >= sbuf.st_size) { 305 /* If bb_dump_size valid and bb_dump_skip >= size */ 306 bb_dump_skip -= sbuf.st_size; 307 address += sbuf.st_size; 326 xfstat(STDIN_FILENO, &sbuf, fname); 327 if (!(S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode) || S_ISFIFO(sbuf.st_mode)) 328 && dumper->pub.dump_skip >= sbuf.st_size 329 ) { 330 /* If bb_dump_size valid and pub.dump_skip >= size */ 331 dumper->pub.dump_skip -= sbuf.st_size; 332 dumper->address += sbuf.st_size; 308 333 return; 309 334 } 310 335 } 311 if (fseek(stdin, bb_dump_skip, SEEK_SET)) { 312 bb_perror_msg_and_die("%s", fname); 313 } 314 savaddress = address += bb_dump_skip; 315 bb_dump_skip = 0; 316 } 317 318 static int next(char **argv) 319 { 320 static smallint done; 321 336 if (fseek(stdin, dumper->pub.dump_skip, SEEK_SET)) { 337 bb_simple_perror_msg_and_die(fname); 338 } 339 dumper->address += dumper->pub.dump_skip; 340 dumper->savaddress = dumper->address; 341 dumper->pub.dump_skip = 0; 342 } 343 344 static NOINLINE int next(priv_dumper_t *dumper) 345 { 322 346 int statok; 323 347 324 if (argv) {325 _argv = argv;326 return 1;327 }328 348 for (;;) { 329 if (*_argv) { 330 if (!(freopen(*_argv, "r", stdin))) { 331 bb_perror_msg("%s", *_argv); 332 exitval = 1; 333 ++_argv; 349 if (*dumper->argv) { 350 dumper->next__done = statok = 1; 351 if (!(freopen(*dumper->argv, "r", stdin))) { 352 bb_simple_perror_msg(*dumper->argv); 353 dumper->exitval = 1; 354 ++dumper->argv; 334 355 continue; 335 356 } 336 done = statok = 1;337 357 } else { 338 if (d one)339 return 0; 340 d one = 1;358 if (dumper->next__done) 359 return 0; /* no next file */ 360 dumper->next__done = 1; 341 361 statok = 0; 342 362 } 343 if ( bb_dump_skip)344 do_skip( statok ? *_argv : "stdin", statok);345 if (* _argv)346 ++ _argv;347 if (! bb_dump_skip)363 if (dumper->pub.dump_skip) 364 do_skip(dumper, statok ? *dumper->argv : "stdin", statok); 365 if (*dumper->argv) 366 ++dumper->argv; 367 if (!dumper->pub.dump_skip) 348 368 return 1; 349 369 } … … 351 371 } 352 372 353 static unsigned char *get(void) 354 { 355 static smallint ateof = 1; 356 static unsigned char *curp = NULL, *savp; /*DBU:[dave@cray.com]initialize curp */ 357 373 static unsigned char *get(priv_dumper_t *dumper) 374 { 358 375 int n; 359 376 int need, nread; 360 unsigned char *tmpp;361 362 if (! curp) {363 address = (off_t)0; /*DBU:[dave@cray.com] initialize,initialize..*/364 curp = xmalloc(bb_dump_blocksize);365 savp = xmalloc(bb_dump_blocksize);377 int blocksize = dumper->blocksize; 378 379 if (!dumper->get__curp) { 380 dumper->address = (off_t)0; /*DBU:[dave@cray.com] initialize,initialize..*/ 381 dumper->get__curp = xmalloc(blocksize); 382 dumper->get__savp = xzalloc(blocksize); /* need to be initialized */ 366 383 } else { 367 tmpp = curp; 368 curp = savp; 369 savp = tmpp; 370 address = savaddress += bb_dump_blocksize; 371 } 372 for (need = bb_dump_blocksize, nread = 0;;) { 384 unsigned char *tmp = dumper->get__curp; 385 dumper->get__curp = dumper->get__savp; 386 dumper->get__savp = tmp; 387 dumper->savaddress += blocksize; 388 dumper->address = dumper->savaddress; 389 } 390 need = blocksize; 391 nread = 0; 392 while (1) { 373 393 /* 374 394 * if read the right number of bytes, or at EOF for one file, … … 376 396 * block and set the end flag. 377 397 */ 378 if (! bb_dump_length || (ateof && !next((char **) NULL))) {379 if (need == b b_dump_blocksize) {398 if (!dumper->pub.dump_length || (dumper->get__ateof && !next(dumper))) { 399 if (need == blocksize) { 380 400 return NULL; 381 401 } 382 if ( bb_dump_vflag != ALL && !memcmp(curp,savp, nread)) {383 if ( bb_dump_vflag != DUP) {402 if (dumper->pub.dump_vflag != ALL && !memcmp(dumper->get__curp, dumper->get__savp, nread)) { 403 if (dumper->pub.dump_vflag != DUP) { 384 404 puts("*"); 385 405 } 386 406 return NULL; 387 407 } 388 memset( (char *)curp + nread, 0, need);389 eaddress =address + nread;390 return curp;391 } 392 n = fread( (char *)curp + nread, sizeof(unsigned char),393 bb_dump_length == -1 ? need : MIN(bb_dump_length, need), stdin);408 memset(dumper->get__curp + nread, 0, need); 409 dumper->eaddress = dumper->address + nread; 410 return dumper->get__curp; 411 } 412 n = fread(dumper->get__curp + nread, sizeof(unsigned char), 413 dumper->pub.dump_length == -1 ? need : MIN(dumper->pub.dump_length, need), stdin); 394 414 if (!n) { 395 415 if (ferror(stdin)) { 396 bb_ perror_msg("%s", _argv[-1]);397 } 398 ateof = 1;416 bb_simple_perror_msg(dumper->argv[-1]); 417 } 418 dumper->get__ateof = 1; 399 419 continue; 400 420 } 401 ateof = 0;402 if ( bb_dump_length != -1) {403 bb_dump_length -= n;421 dumper->get__ateof = 0; 422 if (dumper->pub.dump_length != -1) { 423 dumper->pub.dump_length -= n; 404 424 } 405 425 need -= n; 406 426 if (!need) { 407 if (bb_dump_vflag == ALL || bb_dump_vflag == FIRST 408 || memcmp(curp, savp, bb_dump_blocksize)) { 409 if (bb_dump_vflag == DUP || bb_dump_vflag == FIRST) { 410 bb_dump_vflag = WAIT; 411 } 412 return curp; 413 } 414 if (bb_dump_vflag == WAIT) { 427 if (dumper->pub.dump_vflag == ALL || dumper->pub.dump_vflag == FIRST 428 || memcmp(dumper->get__curp, dumper->get__savp, blocksize) 429 ) { 430 if (dumper->pub.dump_vflag == DUP || dumper->pub.dump_vflag == FIRST) { 431 dumper->pub.dump_vflag = WAIT; 432 } 433 return dumper->get__curp; 434 } 435 if (dumper->pub.dump_vflag == WAIT) { 415 436 puts("*"); 416 437 } 417 bb_dump_vflag = DUP; 418 address = savaddress += bb_dump_blocksize; 419 need = bb_dump_blocksize; 438 dumper->pub.dump_vflag = DUP; 439 dumper->savaddress += blocksize; 440 dumper->address = dumper->savaddress; 441 need = blocksize; 420 442 nread = 0; 421 443 } else { … … 425 447 } 426 448 427 static void bpad(PR * 449 static void bpad(PR *pr) 428 450 { 429 451 char *p1, *p2; … … 435 457 pr->flags = F_BPAD; 436 458 *pr->cchar = 's'; 437 for (p1 = pr->fmt; *p1 != '%'; ++p1); 459 for (p1 = pr->fmt; *p1 != '%'; ++p1) 460 continue; 438 461 for (p2 = ++p1; *p1 && strchr(" -0+#", *p1); ++p1) 439 if (pr->nospace) pr->nospace--; 440 while ((*p2++ = *p1++) != 0); 462 if (pr->nospace) 463 pr->nospace--; 464 while ((*p2++ = *p1++) != 0) 465 continue; 441 466 } 442 467 443 468 static const char conv_str[] ALIGN1 = 444 469 "\0\\0\0" 445 "\007\\a\0" 470 "\007\\a\0" /* \a */ 446 471 "\b\\b\0" 447 472 "\f\\b\0" … … 453 478 454 479 455 static void conv_c(PR * pr, unsigned char *p)480 static void conv_c(PR *pr, unsigned char *p) 456 481 { 457 482 const char *str = conv_str; … … 466 491 } while (*str); 467 492 468 if (isprint (*p)) {493 if (isprint_asciionly(*p)) { 469 494 *pr->cchar = 'c'; 470 (void)printf(pr->fmt, *p);495 printf(pr->fmt, *p); 471 496 } else { 472 497 sprintf(buf, "%03o", (int) *p); 473 498 str = buf; 474 499 strpr: 475 500 *pr->cchar = 's'; 476 501 printf(pr->fmt, str); … … 478 503 } 479 504 480 static void conv_u(PR * pr, unsigned char *p)505 static void conv_u(PR *pr, unsigned char *p) 481 506 { 482 507 static const char list[] ALIGN1 = … … 493 518 *pr->cchar = 's'; 494 519 printf(pr->fmt, "del"); 495 } else if ( isprint(*p)) {520 } else if (*p < 0x7f) { /* isprint() */ 496 521 *pr->cchar = 'c'; 497 522 printf(pr->fmt, *p); … … 502 527 } 503 528 504 static void display(void) 505 { 506 /* extern FU *endfu; */ 529 static void display(priv_dumper_t* dumper) 530 { 507 531 FS *fs; 508 532 FU *fu; 509 533 PR *pr; 510 534 int cnt; 511 unsigned char *bp; 512 535 unsigned char *bp, *savebp; 513 536 off_t saveaddress; 514 unsigned char savech = 0, *savebp; 515 516 while ((bp = get()) != NULL) { 517 for (fs = bb_dump_fshead, savebp = bp, saveaddress = address; fs; 518 fs = fs->nextfs, bp = savebp, address = saveaddress) { 537 unsigned char savech = '\0'; 538 539 while ((bp = get(dumper)) != NULL) { 540 fs = dumper->pub.fshead; 541 savebp = bp; 542 saveaddress = dumper->address; 543 for (; fs; fs = fs->nextfs, bp = savebp, dumper->address = saveaddress) { 519 544 for (fu = fs->nextfu; fu; fu = fu->nextfu) { 520 545 if (fu->flags & F_IGNORE) { … … 522 547 } 523 548 for (cnt = fu->reps; cnt; --cnt) { 524 for (pr = fu->nextpr; pr; address += pr->bcnt, 525 bp += pr->bcnt, pr = pr->nextpr) { 526 if (eaddress && address >= eaddress && 527 !(pr->flags & (F_TEXT | F_BPAD))) { 549 for (pr = fu->nextpr; pr; dumper->address += pr->bcnt, 550 bp += pr->bcnt, pr = pr->nextpr) { 551 if (dumper->eaddress && dumper->address >= dumper->eaddress 552 && !(pr->flags & (F_TEXT | F_BPAD)) 553 ) { 528 554 bpad(pr); 529 555 } … … 535 561 switch (pr->flags) { 536 562 case F_ADDRESS: 537 printf(pr->fmt, (unsigned int)address);563 printf(pr->fmt, (unsigned) dumper->address); 538 564 break; 539 565 case F_BPAD: … … 546 572 printf(pr->fmt, *bp); 547 573 break; 548 case F_DBL: {574 case F_DBL: { 549 575 double dval; 550 576 float fval; … … 552 578 switch (pr->bcnt) { 553 579 case 4: 554 memmove((char *) &fval, (char *) bp, 555 sizeof(fval)); 580 memcpy(&fval, bp, sizeof(fval)); 556 581 printf(pr->fmt, fval); 557 582 break; 558 583 case 8: 559 memmove((char *) &dval, (char *) bp, 560 sizeof(dval)); 584 memcpy(&dval, bp, sizeof(dval)); 561 585 printf(pr->fmt, dval); 562 586 break; … … 564 588 break; 565 589 } 566 case F_INT: {590 case F_INT: { 567 591 int ival; 568 592 short sval; … … 573 597 break; 574 598 case 2: 575 memmove((char *) &sval, (char *) bp, 576 sizeof(sval)); 599 memcpy(&sval, bp, sizeof(sval)); 577 600 printf(pr->fmt, (int) sval); 578 601 break; 579 602 case 4: 580 memmove((char *) &ival, (char *) bp, 581 sizeof(ival)); 603 memcpy(&ival, bp, sizeof(ival)); 582 604 printf(pr->fmt, ival); 583 605 break; … … 586 608 } 587 609 case F_P: 588 printf(pr->fmt, isprint (*bp) ? *bp : '.');610 printf(pr->fmt, isprint_asciionly(*bp) ? *bp : '.'); 589 611 break; 590 612 case F_STR: … … 597 619 conv_u(pr, bp); 598 620 break; 599 case F_UINT: {600 unsigned i nt ival;621 case F_UINT: { 622 unsigned ival; 601 623 unsigned short sval; 602 624 603 625 switch (pr->bcnt) { 604 626 case 1: 605 printf(pr->fmt, (unsigned int) *bp);627 printf(pr->fmt, (unsigned) *bp); 606 628 break; 607 629 case 2: 608 memmove((char *) &sval, (char *) bp, 609 sizeof(sval)); 610 printf(pr->fmt, (unsigned int) sval); 630 memcpy(&sval, bp, sizeof(sval)); 631 printf(pr->fmt, (unsigned) sval); 611 632 break; 612 633 case 4: 613 memmove((char *) &ival, (char *) bp, 614 sizeof(ival)); 634 memcpy(&ival, bp, sizeof(ival)); 615 635 printf(pr->fmt, ival); 616 636 break; … … 627 647 } 628 648 } 629 if ( endfu) {649 if (dumper->endfu) { 630 650 /* 631 * if eaddress not set, error or file bb_dump_size was multiple of632 * bb_dump_blocksize, and no partial block ever found.651 * if eaddress not set, error or file size was multiple 652 * of blocksize, and no partial block ever found. 633 653 */ 634 if (! eaddress) {635 if (! address) {654 if (!dumper->eaddress) { 655 if (!dumper->address) { 636 656 return; 637 657 } 638 eaddress =address;639 } 640 for (pr = endfu->nextpr; pr; pr = pr->nextpr) {658 dumper->eaddress = dumper->address; 659 } 660 for (pr = dumper->endfu->nextpr; pr; pr = pr->nextpr) { 641 661 switch (pr->flags) { 642 662 case F_ADDRESS: 643 (void) printf(pr->fmt, (unsigned int)eaddress);663 printf(pr->fmt, (unsigned) dumper->eaddress); 644 664 break; 645 665 case F_TEXT: 646 (void)printf(pr->fmt);666 printf(pr->fmt); 647 667 break; 648 668 } … … 651 671 } 652 672 653 int bb_dump_dump(char **argv) 673 #define dumper ((priv_dumper_t*)pub_dumper) 674 int FAST_FUNC bb_dump_dump(dumper_t *pub_dumper, char **argv) 654 675 { 655 676 FS *tfs; 677 int blocksize; 656 678 657 679 /* figure out the data block bb_dump_size */ 658 for (bb_dump_blocksize = 0, tfs = bb_dump_fshead; tfs; tfs = tfs->nextfs) { 680 blocksize = 0; 681 tfs = dumper->pub.fshead; 682 while (tfs) { 659 683 tfs->bcnt = bb_dump_size(tfs); 660 if (bb_dump_blocksize < tfs->bcnt) { 661 bb_dump_blocksize = tfs->bcnt; 662 } 663 } 684 if (blocksize < tfs->bcnt) { 685 blocksize = tfs->bcnt; 686 } 687 tfs = tfs->nextfs; 688 } 689 dumper->blocksize = blocksize; 690 664 691 /* rewrite the rules, do syntax checking */ 665 for (tfs = bb_dump_fshead; tfs; tfs = tfs->nextfs) {666 rewrite( tfs);667 } 668 669 next(argv);670 display( );671 672 return exitval;673 } 674 675 void bb_dump_add(const char *fmt)692 for (tfs = dumper->pub.fshead; tfs; tfs = tfs->nextfs) { 693 rewrite(dumper, tfs); 694 } 695 696 dumper->argv = argv; 697 display(dumper); 698 699 return dumper->exitval; 700 } 701 702 void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt) 676 703 { 677 704 const char *p; 678 705 char *p1; 679 706 char *p2; 680 static FS **nextfs;681 707 FS *tfs; 682 FU *tfu, **nextfu ;708 FU *tfu, **nextfupp; 683 709 const char *savep; 684 710 685 711 /* start new linked list of format units */ 686 712 tfs = xzalloc(sizeof(FS)); /*DBU:[dave@cray.com] start out NULL */ 687 if (! bb_dump_fshead) {688 bb_dump_fshead = tfs;713 if (!dumper->pub.fshead) { 714 dumper->pub.fshead = tfs; 689 715 } else { 690 *nextfs = tfs; 691 } 692 nextfs = &tfs->nextfs; 693 nextfu = &tfs->nextfu; 716 FS *fslast = dumper->pub.fshead; 717 while (fslast->nextfs) 718 fslast = fslast->nextfs; 719 fslast->nextfs = tfs; 720 } 721 nextfupp = &tfs->nextfu; 694 722 695 723 /* take the format string and break it up into format units */ 696 for (p = fmt;;) {697 /* bb_dump_skip leading white space */724 p = fmt; 725 for (;;) { 698 726 p = skip_whitespace(p); 699 727 if (!*p) { … … 703 731 /* allocate a new format unit and link it in */ 704 732 /* NOSTRICT */ 705 /* DBU:[dave@cray.com] calloc so that forward pointers start out NULL */733 /* DBU:[dave@cray.com] zalloc so that forward pointers start out NULL */ 706 734 tfu = xzalloc(sizeof(FU)); 707 *nextfu = tfu;708 nextfu = &tfu->nextfu;735 *nextfupp = tfu; 736 nextfupp = &tfu->nextfu; 709 737 tfu->reps = 1; 710 738 711 739 /* if leading digit, repetition count */ 712 740 if (isdigit(*p)) { 713 for (savep = p; isdigit(*p); ++p); 741 for (savep = p; isdigit(*p); ++p) 742 continue; 714 743 if (!isspace(*p) && *p != '/') { 715 744 bb_error_msg_and_die("bad format {%s}", fmt); … … 718 747 tfu->reps = atoi(savep); 719 748 tfu->flags = F_SETREP; 720 /* bb_dump_skip trailing white space */749 /* skip trailing white space */ 721 750 p = skip_whitespace(++p); 722 751 } 723 752 724 /* bb_dump_skip slash and trailing white space */753 /* skip slash and trailing white space */ 725 754 if (*p == '/') { 726 755 p = skip_whitespace(++p); … … 731 760 // TODO: use bb_strtou 732 761 savep = p; 733 do p++; while (isdigit(*p)); 762 while (isdigit(*++p)) 763 continue; 734 764 if (!isspace(*p)) { 735 765 bb_error_msg_and_die("bad format {%s}", fmt); 736 766 } 737 767 tfu->bcnt = atoi(savep); 738 /* bb_dump_skip trailing white space */768 /* skip trailing white space */ 739 769 p = skip_whitespace(++p); 740 770 } … … 749 779 } 750 780 } 751 tfu->fmt = xmalloc(p - savep + 1); 752 strncpy(tfu->fmt, savep, p - savep); 753 tfu->fmt[p - savep] = '\0'; 781 tfu->fmt = xstrndup(savep, p - savep); 754 782 /* escape(tfu->fmt); */ 755 783
Note:
See TracChangeset
for help on using the changeset viewer.