home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / HEXDUMP.CMD < prev    next >
OS/2 REXX Batch file  |  1995-03-28  |  2KB  |  53 lines

  1. EXTPROC CEnvi2
  2. /**********************************************************************
  3.  *** HexDump.cmd - Hexidecimal dump of the contents of a file. This ***
  4.  *** ver.1         examples program uses the CEnvi2 file routines.   ***
  5.  **********************************************************************/
  6.  
  7. main(argc,argv)
  8. {
  9.    if ( 2 != argc ) {
  10.       Instructions()
  11.    } else if ( NULL == (fp = fopen(argv[1],"rb")) ) {
  12.       printf("Could not open file \"%s\" for hex output.\a\n",argv[1])
  13.    } else {
  14.       dump(fp)
  15.       fclose(fp)
  16.    }
  17. }
  18.  
  19. dump(file)
  20. {
  21.    Unprintables = "\a\b\t\r\n\032\033"
  22.    for ( offset = 0; 0 < (count = fread(data,16,file)); offset += 16 ) {
  23.       // display hex offset in file
  24.       printf("%06X  ",offset)
  25.       // display hex value for each number
  26.       for ( i = 0; i < count; i++ )
  27.          printf("%02X ",data[i])
  28.       // fill in any extra gaps if count < 16
  29.       while( i++ < 16 )
  30.          printf("   ")
  31.       // display ascii value for each printable character
  32.       // substitute a period for unprintable characters
  33.       data[count] = 0; // string must be null-terminated
  34.       while( (UnprintableIndex = strcspn(data,Unprintables)) < count )
  35.          data[UnprintableIndex] = '.';
  36.       printf("   %s\n",data)
  37.       if ( count < 16 )
  38.          break
  39.    }
  40. }
  41.  
  42. Instructions()
  43. {
  44.    printf("\n");
  45.    printf("HexDump.cmd - Hexidecimal binary display of file data\n");
  46.    printf("\n");
  47.    printf("USAGE: HexDump <filespec>\n");
  48.    printf("\n");
  49.    printf("Where: filespec - Complete file specification without wildcards\n");
  50.    printf("\n");
  51. }
  52.  
  53.