Mirror of git://git.busybox.net/busybox with our patches on top
Source
static unsigned char *curp=NULL, *savp; /*DBU:[dave@cray.com]initialize curp */
/* vi: set sw=4 ts=4: */
/*
* Support code for the hexdump and od applets,
* based on code from util-linux v 2.11l
*
* Copyright (c) 1989
* The Regents of the University of California. All rights reserved.
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*
* Original copyright notice is retained at the end of this file.
*/
enum _vflag bb_dump_vflag = FIRST;
FS *bb_dump_fshead; /* head of format strings */
static FU *endfu;
static char **_argv;
static off_t savaddress; /* saved address/offset in stream */
static off_t eaddress; /* end address */
static off_t address; /* address/offset in stream */
off_t bb_dump_skip; /* bytes to skip */
static int exitval; /* final exit value */
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 size_conv_str[] =
"\x1\x4\x4\x4\x4\x4\x4\x8\x8\x8\x8\010cdiouxXeEfgG";
static const char lcc[] = "diouxX";
int bb_dump_size(FS * fs)
{
FU *fu;
int bcnt, cur_size;
char *fmt;
const char *p;
int prec;
/* figure out the data block bb_dump_size needed for each format unit */
for (cur_size = 0, fu = fs->nextfu; fu; fu = fu->nextfu) {
if (fu->bcnt) {
cur_size += fu->bcnt * fu->reps;
continue;
}
for (bcnt = prec = 0, fmt = fu->fmt; *fmt; ++fmt) {
if (*fmt != '%')
continue;
/*
* bb_dump_skip any special chars -- save precision in
* case it's a %s format.
*/
while (strchr(index_str + 1, *++fmt));
if (*fmt == '.' && isdigit(*++fmt)) {
prec = atoi(fmt);
while (isdigit(*++fmt));
}
if (!(p = strchr(size_conv_str + 12, *fmt))) {
if (*fmt == 's') {