home *** CD-ROM | disk | FTP | other *** search
- /*
- ** db - dumpbytes
- **
- ** display bytes of file in hex format
- **
- ** Tal 1991
- */
-
-
-
- #ifdef C_ANSI
- #include <stdlib.h>
- #include <string.h>
- #endif
-
- #include <stdio.h>
- #include <ctype.h>
-
- #define LINE_BYTES 16
-
- char HexString[] = {"0123456789ABCDEF"};
-
- void HexStr(szString,iVal)
- char * szString;
- int iVal;
- {
- szString[0] = HexString[(iVal >> 4)];
- szString[1] = HexString[(iVal % 16)];
- szString[2] = '\0';
- }
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- FILE * psFile;
- int iLines;
- unsigned char ucBuffer[LINE_BYTES];
- int iCnt;
- int iReadBytes;
-
- if(argc != 2)
- {
- printf("usage: dumpbytes filename\n");
- exit(1);
- }
-
- psFile = fopen(argv[1],"rb");
- if(psFile == NULL)
- {
- printf("Could not open %s\n",argv[1]);
- exit(1);
- }
-
- iLines = 1;
-
- printf("File: %s\n\n", argv[1]);
-
-
- while(!feof(psFile))
- {
- memset(ucBuffer,0,LINE_BYTES);
-
- iReadBytes = fread(ucBuffer,1,LINE_BYTES,psFile);
-
- /* HexStr(szWorkStr,(iLines-1) * LINE_BYTES); */
-
- printf("%6x: ",(iLines-1) * LINE_BYTES);
-
- for(iCnt = 0; iCnt < iReadBytes; iCnt++)
- {
- /* HexStr(szWorkStr,ucBuffer[iCnt]); */
- printf("%2x ",ucBuffer[iCnt]);
- }
-
- for(iCnt = iReadBytes; iCnt < LINE_BYTES; iCnt++)
- printf(" ");
-
- printf(" ");
-
- for(iCnt = 0; iCnt < iReadBytes; iCnt++)
- {
- if(isprint(ucBuffer[iCnt]))
- printf("%c",ucBuffer[iCnt]);
- else
- printf(".");
-
- }
-
- printf("\n");
-
- iLines++;
-
- }
-
-
- return(0);
-
- }
-
-
-