aboutsummaryrefslogtreecommitdiff
path: root/libbb/dump.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/dump.c')
-rw-r--r--libbb/dump.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/libbb/dump.c b/libbb/dump.c
index 1a54ebbd9..b12a8e223 100644
--- a/libbb/dump.c
+++ b/libbb/dump.c
@@ -10,11 +10,10 @@
10 * Original copyright notice is retained at the end of this file. 10 * Original copyright notice is retained at the end of this file.
11 */ 11 */
12 12
13#include <stdlib.h> 13#include "libbb.h"
14#include <string.h> 14#include <string.h>
15#include <unistd.h> 15#include <unistd.h>
16#include <ctype.h> /* for isdigit() */ 16#include <ctype.h> /* for isdigit() */
17#include "libbb.h"
18#include "dump.h" 17#include "dump.h"
19 18
20enum _vflag bb_dump_vflag = FIRST; 19enum _vflag bb_dump_vflag = FIRST;
@@ -83,9 +82,9 @@ int bb_dump_size(FS * fs)
83static void rewrite(FS * fs) 82static void rewrite(FS * fs)
84{ 83{
85 enum { NOTOKAY, USEBCNT, USEPREC } sokay; 84 enum { NOTOKAY, USEBCNT, USEPREC } sokay;
86 register PR *pr, **nextpr = NULL; 85 PR *pr, **nextpr = NULL;
87 register FU *fu; 86 FU *fu;
88 register char *p1, *p2, *p3; 87 char *p1, *p2, *p3;
89 char savech, *fmtp; 88 char savech, *fmtp;
90 const char *byte_count_str; 89 const char *byte_count_str;
91 int nconv, prec = 0; 90 int nconv, prec = 0;
@@ -98,7 +97,7 @@ static void rewrite(FS * fs)
98 for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) { 97 for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) {
99 /* NOSTRICT */ 98 /* NOSTRICT */
100 /* DBU:[dvae@cray.com] calloc so that forward ptrs start out NULL*/ 99 /* DBU:[dvae@cray.com] calloc so that forward ptrs start out NULL*/
101 pr = (PR *) xzalloc(sizeof(PR)); 100 pr = xzalloc(sizeof(PR));
102 if (!fu->nextpr) 101 if (!fu->nextpr)
103 fu->nextpr = pr; 102 fu->nextpr = pr;
104 /* ignore nextpr -- its unused inside the loop and is 103 /* ignore nextpr -- its unused inside the loop and is
@@ -246,8 +245,7 @@ static void rewrite(FS * fs)
246 { 245 {
247 savech = *p3; 246 savech = *p3;
248 *p3 = '\0'; 247 *p3 = '\0';
249 if (!(pr->fmt = realloc(pr->fmt, strlen(pr->fmt)+(p3-p2)+1))) 248 pr->fmt = xrealloc(pr->fmt, strlen(pr->fmt)+(p3-p2)+1);
250 bb_perror_msg_and_die("hexdump");
251 strcat(pr->fmt, p2); 249 strcat(pr->fmt, p2);
252 *p3 = savech; 250 *p3 = savech;
253 p2 = p3; 251 p2 = p3;
@@ -673,17 +671,16 @@ int bb_dump_dump(char **argv)
673 671
674void bb_dump_add(const char *fmt) 672void bb_dump_add(const char *fmt)
675{ 673{
676 register const char *p; 674 const char *p;
677 register char *p1; 675 char *p1;
678 register char *p2; 676 char *p2;
679 static FS **nextfs; 677 static FS **nextfs;
680 FS *tfs; 678 FS *tfs;
681 FU *tfu, **nextfu; 679 FU *tfu, **nextfu;
682 const char *savep; 680 const char *savep;
683 681
684 /* start new linked list of format units */ 682 /* start new linked list of format units */
685 /* NOSTRICT */ 683 tfs = xzalloc(sizeof(FS)); /*DBU:[dave@cray.com] start out NULL */
686 tfs = (FS *) xzalloc(sizeof(FS)); /*DBU:[dave@cray.com] start out NULL */
687 if (!bb_dump_fshead) { 684 if (!bb_dump_fshead) {
688 bb_dump_fshead = tfs; 685 bb_dump_fshead = tfs;
689 } else { 686 } else {
@@ -695,7 +692,7 @@ void bb_dump_add(const char *fmt)
695 /* take the format string and break it up into format units */ 692 /* take the format string and break it up into format units */
696 for (p = fmt;;) { 693 for (p = fmt;;) {
697 /* bb_dump_skip leading white space */ 694 /* bb_dump_skip leading white space */
698 p = bb_skip_whitespace(p); 695 p = skip_whitespace(p);
699 if (!*p) { 696 if (!*p) {
700 break; 697 break;
701 } 698 }
@@ -703,7 +700,7 @@ void bb_dump_add(const char *fmt)
703 /* allocate a new format unit and link it in */ 700 /* allocate a new format unit and link it in */
704 /* NOSTRICT */ 701 /* NOSTRICT */
705 /* DBU:[dave@cray.com] calloc so that forward pointers start out NULL */ 702 /* DBU:[dave@cray.com] calloc so that forward pointers start out NULL */
706 tfu = (FU *) xzalloc(sizeof(FU)); 703 tfu = xzalloc(sizeof(FU));
707 *nextfu = tfu; 704 *nextfu = tfu;
708 nextfu = &tfu->nextfu; 705 nextfu = &tfu->nextfu;
709 tfu->reps = 1; 706 tfu->reps = 1;
@@ -718,12 +715,12 @@ void bb_dump_add(const char *fmt)
718 tfu->reps = atoi(savep); 715 tfu->reps = atoi(savep);
719 tfu->flags = F_SETREP; 716 tfu->flags = F_SETREP;
720 /* bb_dump_skip trailing white space */ 717 /* bb_dump_skip trailing white space */
721 p = bb_skip_whitespace(++p); 718 p = skip_whitespace(++p);
722 } 719 }
723 720
724 /* bb_dump_skip slash and trailing white space */ 721 /* bb_dump_skip slash and trailing white space */
725 if (*p == '/') { 722 if (*p == '/') {
726 p = bb_skip_whitespace(++p); 723 p = skip_whitespace(++p);
727 } 724 }
728 725
729 /* byte count */ 726 /* byte count */
@@ -734,7 +731,7 @@ void bb_dump_add(const char *fmt)
734 } 731 }
735 tfu->bcnt = atoi(savep); 732 tfu->bcnt = atoi(savep);
736 /* bb_dump_skip trailing white space */ 733 /* bb_dump_skip trailing white space */
737 p = bb_skip_whitespace(++p); 734 p = skip_whitespace(++p);
738 } 735 }
739 736
740 /* format */ 737 /* format */