#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>

#ifndef __cplusplus
typedef enum { false, true } bool;
#endif

typedef unsigned char byte;

void PrintLine(const byte *line, int linesize, long pos)
{
  int c;

  printf("%04lX : ", pos);
  for(c = 0; c < linesize; c++)
    printf("%02X ", line[c]);

  printf("- ");
  for(c = 0; c < linesize; c++)
    printf("%c", line[c] < 32 ? '.' : line[c]);
      
  printf("\n");
}

bool ReadFromFile(const char *filename)
{
  byte buffer[17];
  long size, total;
  FILE *file = fopen(filename, "rb");

  if(!file)
    return false;
  
  total = 0;
  while(!feof(file))  
  {
    size = fread(buffer, sizeof(byte), sizeof(buffer), file);
    PrintLine(buffer, size, total);
    total += size;
  }
  
  fclose(file);

  return true;
}


void main(int argc, char *argv[])
{
  if(argc < 2)
  {
    printf("Uso: readfile arquivo.ext.\n");
    return;
  }

  if(!ReadFromFile(argv[1]))
  {
    printf("Erro lendo arquivo %s.\n", argv[1]);
    return;
  }
}