*/
#include "libbb.h"
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h> /* for isdigit() */
#include "dump.h"
enum _vflag bb_dump_vflag = FIRST;
int bb_dump_blocksize; /* data block size */
int bb_dump_length = -1; /* max bytes to read */
-static const char index_str[] = ".#-+ 0123456789";
+static const char index_str[] ALIGN1 = ".#-+ 0123456789";
-static const char size_conv_str[] =
+static const char size_conv_str[] ALIGN1 =
"\x1\x4\x4\x4\x4\x4\x4\x8\x8\x8\x8\010cdiouxXeEfgG";
-static const char lcc[] = "diouxX";
+static const char lcc[] ALIGN1 = "diouxX";
int bb_dump_size(FS * fs)
{
prec = atoi(fmt);
while (isdigit(*++fmt));
}
- if (!(p = strchr(size_conv_str + 12, *fmt))) {
+ p = strchr(size_conv_str + 12, *fmt);
+ if (!p) {
if (*fmt == 's') {
bcnt += prec;
} else if (*fmt == '_') {
}
cur_size += bcnt * fu->reps;
}
- return (cur_size);
+ return cur_size;
}
static void rewrite(FS * fs)
if (!fu->nextpr)
fu->nextpr = pr;
/* ignore nextpr -- its unused inside the loop and is
- * uninitialized 1st time thru.
+ * uninitialized 1st time through.
*/
/* bb_dump_skip preceding text and up to the next % sign */
}
/* Unlike the original, output the remainder of the format string. */
if (!*byte_count_str) {
- bb_error_msg_and_die("bad byte count for conversion character %s.", p1);
+ bb_error_msg_and_die("bad byte count for conversion character %s", p1);
}
pr->bcnt = *byte_count_str;
} else if (*p1 == 'l') {
DO_INT_CONV:
{
const char *e;
- if (!(e = strchr(lcc, *p1))) {
+ e = strchr(lcc, *p1);
+ if (!e) {
goto DO_BAD_CONV_CHAR;
}
pr->flags = F_INT;
} else if (sokay == USEPREC) {
pr->bcnt = prec;
} else { /* NOTOKAY */
- bb_error_msg_and_die("%%s requires a precision or a byte count.");
+ bb_error_msg_and_die("%%s requires a precision or a byte count");
}
} else if (*p1 == '_') {
++p2;
}
} else {
DO_BAD_CONV_CHAR:
- bb_error_msg_and_die("bad conversion character %%%s.\n", p1);
+ bb_error_msg_and_die("bad conversion character %%%s", p1);
}
/*
*/
savech = *p2;
p1[1] = '\0';
- pr->fmt = bb_xstrdup(fmtp);
+ pr->fmt = xstrdup(fmtp);
*p2 = savech;
pr->cchar = pr->fmt + (p1 - fmtp);
/* only one conversion character if byte count */
if (!(pr->flags & F_ADDRESS) && fu->bcnt && nconv++) {
- bb_error_msg_and_die("byte count with multiple conversion characters.\n");
+ bb_error_msg_and_die("byte count with multiple conversion characters");
}
}
/*
}
}
-static void do_skip(char *fname, int statok)
+static void do_skip(const char *fname, int statok)
{
struct stat sbuf;
if (statok) {
if (fstat(STDIN_FILENO, &sbuf)) {
- bb_perror_msg_and_die("%s", fname);
+ bb_simple_perror_msg_and_die(fname);
}
if ((!(S_ISCHR(sbuf.st_mode) ||
S_ISBLK(sbuf.st_mode) ||
}
}
if (fseek(stdin, bb_dump_skip, SEEK_SET)) {
- bb_perror_msg_and_die("%s", fname);
+ bb_simple_perror_msg_and_die(fname);
}
savaddress = address += bb_dump_skip;
bb_dump_skip = 0;
static int next(char **argv)
{
- static int done;
+ static smallint done;
+
int statok;
if (argv) {
_argv = argv;
- return (1);
+ return 1;
}
for (;;) {
if (*_argv) {
if (!(freopen(*_argv, "r", stdin))) {
- bb_perror_msg("%s", *_argv);
+ bb_simple_perror_msg(*_argv);
exitval = 1;
++_argv;
continue;
}
- statok = done = 1;
+ done = statok = 1;
} else {
- if (done++)
- return (0);
+ if (done)
+ return 0;
+ done = 1;
statok = 0;
}
if (bb_dump_skip)
if (*_argv)
++_argv;
if (!bb_dump_skip)
- return (1);
+ return 1;
}
/* NOTREACHED */
}
static unsigned char *get(void)
{
- static int ateof = 1;
- static unsigned char *curp=NULL, *savp; /*DBU:[dave@cray.com]initialize curp */
+ static smallint ateof = 1;
+ static unsigned char *curp = NULL, *savp; /*DBU:[dave@cray.com]initialize curp */
+
int n;
int need, nread;
unsigned char *tmpp;
if (!curp) {
address = (off_t)0; /*DBU:[dave@cray.com] initialize,initialize..*/
- curp = (unsigned char *) xmalloc(bb_dump_blocksize);
- savp = (unsigned char *) xmalloc(bb_dump_blocksize);
+ curp = xmalloc(bb_dump_blocksize);
+ savp = xmalloc(bb_dump_blocksize);
} else {
tmpp = curp;
curp = savp;
*/
if (!bb_dump_length || (ateof && !next((char **) NULL))) {
if (need == bb_dump_blocksize) {
- return ((unsigned char *) NULL);
+ return NULL;
}
if (bb_dump_vflag != ALL && !memcmp(curp, savp, nread)) {
if (bb_dump_vflag != DUP) {
- printf("*\n");
+ puts("*");
}
- return ((unsigned char *) NULL);
+ return NULL;
}
memset((char *) curp + nread, 0, need);
eaddress = address + nread;
- return (curp);
+ return curp;
}
n = fread((char *) curp + nread, sizeof(unsigned char),
bb_dump_length == -1 ? need : MIN(bb_dump_length, need), stdin);
if (!n) {
if (ferror(stdin)) {
- bb_perror_msg("%s", _argv[-1]);
+ bb_simple_perror_msg(_argv[-1]);
}
ateof = 1;
continue;
if (bb_dump_length != -1) {
bb_dump_length -= n;
}
- if (!(need -= n)) {
+ need -= n;
+ if (!need) {
if (bb_dump_vflag == ALL || bb_dump_vflag == FIRST
|| memcmp(curp, savp, bb_dump_blocksize)) {
if (bb_dump_vflag == DUP || bb_dump_vflag == FIRST) {
bb_dump_vflag = WAIT;
}
- return (curp);
+ return curp;
}
if (bb_dump_vflag == WAIT) {
- printf("*\n");
+ puts("*");
}
bb_dump_vflag = DUP;
address = savaddress += bb_dump_blocksize;
while ((*p2++ = *p1++) != 0);
}
-static const char conv_str[] =
+static const char conv_str[] ALIGN1 =
"\0\\0\0"
"\007\\a\0" /* \a */
"\b\\b\0"
"\r\\r\0"
"\t\\t\0"
"\v\\v\0"
- "\0";
+ ;
static void conv_c(PR * pr, unsigned char * p)
static void conv_u(PR * pr, unsigned char * p)
{
- static const char list[] =
+ static const char list[] ALIGN1 =
"nul\0soh\0stx\0etx\0eot\0enq\0ack\0bel\0"
"bs\0_ht\0_lf\0_vt\0_ff\0_cr\0_so\0_si\0_"
"dle\0dcl\0dc2\0dc3\0dc4\0nak\0syn\0etb\0"
next(argv);
display();
- return (exitval);
+ return exitval;
}
void bb_dump_add(const char *fmt)
/* byte count */
if (isdigit(*p)) {
- for (savep = p; isdigit(*p); ++p);
+// TODO: use bb_strtou
+ savep = p;
+ do p++; while (isdigit(*p));
if (!isspace(*p)) {
bb_error_msg_and_die("bad format {%s}", fmt);
}