diff --git a/tdump.c b/tdump.c new file mode 100644 index 0000000..9af4634 --- /dev/null +++ b/tdump.c @@ -0,0 +1,112 @@ +/* DUMP.C - Dumps stdin To stdout In Hexadecimal Format + Copyright (C) 1986, T.A. Daneliuk + $Id: tdump.c,v 1.101 2007/01/02 22:51:31 tundra Exp $ +*/ + +#include +#include +#include +#include +#define WIDTH 16 + +static char lineno[]="000000"; +static unsigned long line=0; + +main() + +{ + +int c,count; +char array[4],equiv[WIDTH+1]; +array[2]=' '; +array[3]='\0'; +equiv[WIDTH]='\0'; +count=WIDTH+1; +dl(); + + setmode(fileno(stdin),O_BINARY); + while ((c=getc(stdin)) != EOF) + { + if (! (--count)) + { + count=prnascii(equiv); + dl(); + } + tohex2(c,array); + if (isprint(c)) + equiv[WIDTH-count]=c; + else + equiv[WIDTH-count]='.'; + fputs(array,stdout); + } + while (--count) + { + fputs(" ",stdout); + equiv[WIDTH-count]=' '; + } + prnascii(equiv); +} + +/************************ Display Current Line No. **************************/ + +dl() + +{ + +tohex2((int) (line & 0xffL),&lineno[4]); +tohex2((int) ((line >> 8) & 0xffL),&lineno[2]); +tohex2((int) ((line >> 16) & 0xffl),&lineno[0]); +fputs(lineno,stdout); +fputs(" => ",stdout); + +} + +/*********************** Display ASCII Equivalents **************************/ + +int prnascii(equiv) + +char *equiv; + +{ +fputs(" | ",stdout); +fputs(equiv,stdout); +fputs(" |\n",stdout); +line=line + 0x10; +return(WIDTH); +} + + + + +/********************* Convert Binary Value To Hex **************************/ + +/* TOHEX2.C - This function is passed an integer value and an array + location which can hold at least a 2 element string. + The low 8 bits of the integer are converted to an + equivalent hexadecimal string which is stored in the + array at subscripts 0 and 1. + + Last modified: 01/01/85 - Copyright (c) 1985 By T.A. Daneliuk */ + + +tohex2(i,array) + +int i; +char array[]; + +{ + +int temp; +static char conv[]={"0123456789ABCDEF"}; + +temp=i; +temp=temp & 0x000f; /* Mask all but low nybble */ +array[1]=conv[temp]; /* Use to index into conversion table */ +temp=i; /* Now do high nybble */ +temp=temp >> 4; +temp=temp & 0x000f; +array[0]=conv[temp]; + +} + +