* Copyright (c) 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)display.c 5.8 (Berkeley) %G%";
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
);
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
));