* 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.1 (Berkeley) %G%";
static off_t address
; /* address/offset in stream */
static off_t eaddress
; /* end address */
static off_t savaddress
; /* saved address/offset in stream */
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
) {
if (cnt
== 1 && pr
->nospace
) {
if (cnt
== 1 && pr
->nospace
)
* if eaddress not set, file size was multiple of blocksize,
* and no partial block ever found.
eaddress
= address
+ blocksize
;
for (pr
= endfu
->nextpr
; pr
; pr
= pr
->nextpr
)
(void)printf(pr
->fmt
, eaddress
);
(void)printf(pr
->fmt
, address
);
(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
);
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
|| bcmp(curp
, savp
, blocksize
)) {
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: out of memory.\n");