/* hdump.c
jms1 30 july 96
hex dump program
2007-11-08 jms1 - adding GPLv2/3 notice
#######################################################################
Copyright (C) 1996,2007 John Simpson.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 or version 3 of the
license, at your option.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
#######################################################################
*/
#include
void dumpline ( long addr , unsigned char *buf , int len )
{
int a ;
printf ( "%08lX - " , addr ) ;
for ( a=0 ; a<16 ; a++ )
{
if ( a < len )
printf ( "%02X " , (unsigned int)buf[a] ) ;
else
printf ( " " ) ;
if ( a == 7 )
printf ( "- " ) ;
}
printf ( ":" ) ;
for ( a=0 ; a<16 ; a++ )
{
if ( a < len )
{
if ( buf[a] < 32 )
printf ( "." ) ;
else if ( buf[a] < 127 )
printf ( "%c" , buf[a] ) ;
else if ( buf[a] == 127 )
printf ( "." ) ;
else
printf ( "." ) ;
}
else
printf ( " " ) ;
}
printf ( ":\n" ) ;
}
int main ( int argc , char *argv[] )
{
FILE *f ;
long addr ;
int rv ;
unsigned char buf[16] ;
if ( argc < 2 )
f = stdin ;
else if ( argc == 2 )
{
f = fopen ( argv[1] , "r" ) ;
if ( !f )
{
fprintf ( stderr , "can\'t open \"%s\" for input\n" ,
argv[1] ) ;
return 1 ;
}
}
else
{
fprintf ( stderr , "%s [filename]\n" , argv[0] ) ;
return 1 ;
}
addr = 0L ;
while ( !feof(f) )
{
rv = fread ( buf , 1 , 16 , f ) ;
if ( rv )
dumpline ( addr , buf , rv ) ;
addr += 16 ;
}
}