home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / text_cla / db.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-12  |  1.7 KB  |  103 lines

  1. /*
  2. **   db - dumpbytes
  3. **
  4. **   display bytes of file in hex format
  5. **
  6. **   Tal   1991
  7. */
  8.  
  9.  
  10.  
  11. #ifdef C_ANSI
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #endif
  15.  
  16. #include <stdio.h>
  17. #include <ctype.h>
  18.  
  19. #define  LINE_BYTES 16
  20.  
  21. char  HexString[] = {"0123456789ABCDEF"};
  22.  
  23. void HexStr(szString,iVal)
  24. char * szString;
  25. int    iVal;
  26. {
  27.     szString[0] = HexString[(iVal >> 4)];
  28.     szString[1] = HexString[(iVal % 16)];
  29.     szString[2] = '\0';
  30. }
  31.  
  32. main(argc,argv)
  33. int argc;
  34. char *argv[];
  35. {
  36.     FILE * psFile;
  37.     int    iLines;
  38.     unsigned char  ucBuffer[LINE_BYTES];
  39.     int    iCnt;
  40.     int    iReadBytes;
  41.  
  42.     if(argc != 2)
  43.     {
  44.        printf("usage: dumpbytes filename\n");
  45.        exit(1);
  46.     } 
  47.  
  48.     psFile = fopen(argv[1],"rb");
  49.     if(psFile == NULL)
  50.     {
  51.        printf("Could not open %s\n",argv[1]);
  52.        exit(1);
  53.     }
  54.  
  55.     iLines = 1;
  56.  
  57.     printf("File: %s\n\n", argv[1]);
  58.  
  59.  
  60.     while(!feof(psFile))
  61.     {
  62.        memset(ucBuffer,0,LINE_BYTES);
  63.  
  64.        iReadBytes = fread(ucBuffer,1,LINE_BYTES,psFile);
  65.        
  66.        /* HexStr(szWorkStr,(iLines-1) * LINE_BYTES); */
  67.       
  68.        printf("%6x: ",(iLines-1) * LINE_BYTES);
  69.  
  70.        for(iCnt = 0; iCnt < iReadBytes; iCnt++)
  71.        {
  72.           /* HexStr(szWorkStr,ucBuffer[iCnt]); */
  73.           printf("%2x ",ucBuffer[iCnt]);
  74.        }
  75.  
  76.        for(iCnt = iReadBytes; iCnt < LINE_BYTES; iCnt++)
  77.           printf("   ");
  78.  
  79.        printf("  ");
  80.  
  81.        for(iCnt = 0; iCnt < iReadBytes; iCnt++)    
  82.        {
  83.           if(isprint(ucBuffer[iCnt]))
  84.              printf("%c",ucBuffer[iCnt]);
  85.           else
  86.              printf(".");
  87.  
  88.        }
  89.  
  90.        printf("\n");
  91.  
  92.        iLines++;
  93.  
  94.     }
  95.  
  96.  
  97.     return(0);
  98.  
  99. }
  100.  
  101.  
  102.  
  103.