File:  [MW Coherent from dump] / coherent / a / usr / src / misc / xdump.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

/*
 * Vertical hex dump subroutine
 * dumps 64 bytes per line
 */

static
clean(c)
register char c;
{
	return ((c >= ' ' && c <= '~' ) ? c : '.');
}

static unsigned int linepos = 0; /* how many non sep chars output so far */
/*
 * Put char and separators.
 */
static void
outc(c)
char c;
{
	if(!(linepos & 3))
		putchar(linepos ? ' ' : '\n');
	putchar(c);
	linepos++;
}

static
hex(c)
register char c;
{
	return(c + ((c <= 9) ? '0' : 'A' - 10));
}

xdump(p, length)
register unsigned char *p;
{
	register int tlength;
	register unsigned char *l;

	for(;(tlength = (length > 64) ? 64 : length) > 0; length -= 64) {
		for(linepos = 0, l = p; linepos < tlength; )
			outc(clean(*p++));

		for(linepos = 0, p = l; linepos < tlength; )
			outc(hex(((*p++) >> 4) & 15));

		for(linepos = 0, p = l; linepos < tlength; )
			outc(hex((*p++) & 15));
	}
	putchar('\n');
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.