* Copyright (c) 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)display.c 5.11 (Berkeley) 3/9/91";
enum _vflag vflag
= FIRST
;
static off_t address
; /* address/offset in stream */
static off_t eaddress
; /* end address */
static off_t savaddress
; /* saved address/offset in stream */
(void)printf(pr->fmt, address); \
(void)printf(pr->fmt, ""); \
(void)printf(pr->fmt, *bp); \
bcopy((char *)bp, (char *)&fval, sizeof(fval)); \
(void)printf(pr->fmt, fval); \
bcopy((char *)bp, (char *)&dval, sizeof(dval)); \
(void)printf(pr->fmt, dval); \
(void)printf(pr->fmt, (int)*bp); \
bcopy((char *)bp, (char *)&sval, sizeof(sval)); \
(void)printf(pr->fmt, (int)sval); \
bcopy((char *)bp, (char *)&ival, sizeof(ival)); \
(void)printf(pr->fmt, ival); \
(void)printf(pr->fmt, isprint(*bp) ? *bp : '.'); \
(void)printf(pr->fmt, (char *)bp); \
(void)printf(pr->fmt, (u_int)*bp); \
bcopy((char *)bp, (char *)&sval, sizeof(sval)); \
(void)printf(pr->fmt, (u_int)sval); \
bcopy((char *)bp, (char *)&ival, sizeof(ival)); \
(void)printf(pr->fmt, ival); \
u_char savech
, *savebp
, *get();
for (fs
= fshead
, savebp
= bp
, saveaddress
= address
; fs
;
fs
= fs
->nextfs
, bp
= savebp
, address
= saveaddress
)
for (fu
= fs
->nextfu
; fu
; fu
= fu
->nextfu
) {
for (cnt
= fu
->reps
; cnt
; --cnt
)
for (pr
= fu
->nextpr
; pr
; address
+= pr
->bcnt
,
bp
+= pr
->bcnt
, pr
= pr
->nextpr
) {
if (eaddress
&& address
>= eaddress
&&
!(pr
->flags
&(F_TEXT
|F_BPAD
)))
if (cnt
== 1 && pr
->nospace
) {
if (cnt
== 1 && pr
->nospace
)
* if eaddress not set, error or file size was multiple of
* blocksize, and no partial block ever found.
for (pr
= endfu
->nextpr
; pr
; pr
= pr
->nextpr
)
(void)printf(pr
->fmt
, eaddress
);
static char *spec
= " -0+#";
* remove all conversion flags; '-' is the only one valid
* with %s, and it's not useful here.
for (p1
= pr
->fmt
; *p1
!= '%'; ++p1
);
for (p2
= ++p1
; *p1
&& index(spec
, *p1
); ++p1
);
extern enum _vflag vflag
;
static u_char
*curp
, *savp
;
curp
= (u_char
*)emalloc(blocksize
);
savp
= (u_char
*)emalloc(blocksize
);
address
= savaddress
+= blocksize
;
for (need
= blocksize
, nread
= 0;;) {
* if read the right number of bytes, or at EOF for one file,
* and no other files are available, zero-pad the rest of the
* block and set the end flag.
if (!length
|| ateof
&& !next((char **)NULL
)) {
if (vflag
!= ALL
&& !bcmp(curp
, savp
, nread
)) {
bzero((char *)curp
+ nread
, need
);
eaddress
= address
+ nread
;
n
= fread((char *)curp
+ nread
, sizeof(u_char
),
length
== -1 ? need
: MIN(length
, need
), stdin
);
(void)fprintf(stderr
, "hexdump: %s: %s\n",
_argv
[-1], strerror(errno
));
if (vflag
== ALL
|| vflag
== FIRST
||
bcmp(curp
, savp
, blocksize
)) {
if (vflag
== DUP
|| vflag
== FIRST
)
address
= savaddress
+= blocksize
;
extern off_t skip
; /* bytes to skip */
extern int errno
, exitval
;
if (!(freopen(*_argv
, "r", stdin
))) {
(void)fprintf(stderr
, "hexdump: %s: %s\n",
*_argv
, strerror(errno
));
doskip(statok
? *_argv
: "stdin", statok
);
if (fstat(fileno(stdin
), &sbuf
)) {
(void)fprintf(stderr
, "hexdump: %s: %s.\n",
if (skip
>= sbuf
.st_size
) {
if (fseek(stdin
, skip
, SEEK_SET
)) {
(void)fprintf(stderr
, "hexdump: %s: %s.\n",
savaddress
= address
+= skip
;
if (!(p
= malloc((u_int
)size
)))
(void)fprintf(stderr
, "hexdump: %s.\n", strerror(errno
));