Update the system to support display of 64 bits ans a single file... and some other things

This commit is contained in:
Edouard Dupin 2012-02-10 14:02:51 +01:00
parent 0bd46f72ba
commit f8a3ab2db8
5 changed files with 828 additions and 1211 deletions

1269
display.c

File diff suppressed because it is too large Load Diff

View File

@ -32,16 +32,16 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
typedef unsigned char U8; typedef unsigned char uint8_t;
typedef signed char I8; typedef signed char int8_t;
typedef unsigned short int U16; typedef unsigned short int uint16_t;
typedef signed short int I16; typedef signed short int int16_t;
typedef unsigned long int U32; typedef unsigned long int uint32_t;
typedef signed long int I32; //typedef signed long int int32_t;
typedef unsigned long long int U64; typedef unsigned long long int uint64_t;
typedef signed long long int I64; typedef signed long long int int64_t;
//typedef unsigned long long long int U128; //typedef unsigned long long long int uint128_t;
//typedef signed long long long int I128; //typedef signed long long long int int128_t;
//regular colors //regular colors
#define COLOR_BLACK "\e[0;30m" #define COLOR_BLACK "\e[0;30m"

567
main.c
View File

@ -31,43 +31,43 @@
FILE *filePointer[2] = {NULL, NULL}; FILE *filePointer[2] = {NULL, NULL};
U32 filesize[2] = {0, 0}; uint32_t filesize[2] = {0, 0};
char fileName[2][2096] = {"",""}; char fileName[2][2096] = {"",""};
void usage(void) void usage(void)
{ {
printf("usage : hexViwer [file_1] [file_2]\n"); printf("usage : hexViwer [file_1] [file_2]\n");
printf("\t[file_1] : Show the first file only\n"); printf("\t[file_1] : Show the first file only\n");
printf("\t[file_2] : if it was precise : Show the comparaison with the first file\n"); printf("\t[file_2] : if it was precise : Show the comparaison with the first file\n");
printf("\t\n"); printf("\t\n");
printf("\tInside Usage : \n"); printf("\tInside Usage : \n");
printf("\t\t[a] Go to the start of the files\n"); printf("\t\t[a] Go to the start of the files\n");
printf("\t\t[z] Go to the end of the files (the first push is the File 1, the second push is the file 2) \n"); printf("\t\t[z] Go to the end of the files (the first push is the File 1, the second push is the file 2) \n");
printf("\t\t[q] Quit the curent program\n"); printf("\t\t[q] Quit the curent program\n");
printf("\t\t[s] Change the view of the propram of the size of interpretation (8 bits, 16 bits, 32 bits)\n"); printf("\t\t[s] Change the view of the propram of the size of interpretation (8 bits, 16 bits, 32 bits)\n");
printf("\t\t[t] Change the interpretation of Data (hexedecimal, Signed Decimal, Unigned Decimal)\n"); printf("\t\t[t] Change the interpretation of Data (hexedecimal, Signed Decimal, Unigned Decimal)\n");
printf("\t\t[f] Find the first Error when comparing the two files\n"); printf("\t\t[f] Find the first Error when comparing the two files\n");
printf("\t\t[UP] Go up 5 line in the view\n"); printf("\t\t[UP] Go up 5 line in the view\n");
printf("\t\t[DOWN] Go down 5 line in the view\n"); printf("\t\t[DOWN] Go down 5 line in the view\n");
printf("\t\t[LEFT] Go up 50 line in the view (one screen)\n"); printf("\t\t[LEFT] Go up 50 line in the view (one screen)\n");
printf("\t\t[RIGHT] Go down 50 line in the view (one screen)\n"); printf("\t\t[RIGHT] Go down 50 line in the view (one screen)\n");
printf("\t\n"); printf("\t\n");
printf("\tTODO : \n"); printf("\tTODO : \n");
printf("\t\t- The print of 128 bytes\n"); printf("\t\t- The print of 128 bytes\n");
printf("\t\t- The print in Octal\n"); printf("\t\t- The print in Octal\n");
printf("\t\t- The print in Binary\n"); printf("\t\t- The print in Binary\n");
printf("\t\t- The Modification of the file\n"); printf("\t\t- The Modification of the file\n");
printf("\t\t- The Saving of the file\n"); printf("\t\t- The Saving of the file\n");
printf("\t\t- The information that one of the files has been update\n"); printf("\t\t- The information that one of the files has been update\n");
printf("\t\t- To reload the two files ==> [U]\n"); printf("\t\t- To reload the two files ==> [U]\n");
printf("\t\t- The windows scroling with the mouse\n"); printf("\t\t- The windows scroling with the mouse\n");
printf("\t\t- The selection with the mouse\n"); printf("\t\t- The selection with the mouse\n");
printf("\t\t- The display on char view\n"); printf("\t\t- The display on char view\n");
printf("\t\t- The scroling Bar on the right\n"); printf("\t\t- The scroling Bar on the right\n");
printf("\t\t- Add to the croling bar the differences in the two files\n"); printf("\t\t- Add to the croling bar the differences in the two files\n");
printf("\t\t- The research of a sequency in the two files ==> [R]\n"); printf("\t\t- The research of a sequency in the two files ==> [R]\n");
printf("\t\t- The jump to an offset directly ==> [J] \n"); printf("\t\t- The jump to an offset directly ==> [J] \n");
/*printf("\t\t- \n");*/ /*printf("\t\t- \n");*/
} }
@ -79,198 +79,180 @@ void usage(void)
I32 findFirstDiff(void) int32_t findFirstDiff(void)
{ {
U8 data1, data2; uint8_t data1, data2;
I32 offset = 0; int32_t offset = 0;
if( NULL == filePointer[0]
while ( fread(&data1, sizeof(U8), 1, filePointer[0]) == 1 || NULL == filePointer[1] ) {
&& fread(&data2, sizeof(U8), 1, filePointer[1]) == 1) return 0;
{ }
offset ++; while ( fread(&data1, sizeof(uint8_t), 1, filePointer[0]) == 1
if (data1 != data2) && fread(&data2, sizeof(uint8_t), 1, filePointer[1]) == 1)
{ {
return offset; offset ++;
} if (data1 != data2)
} {
return -1; return offset;
}
}
return offset;
} }
int main (int argc, char**argv) int main (int argc, char**argv)
{ {
I32 first_Error = 0; int32_t first_Error = 0;
if (2 == argc) filePointer[0] = NULL;
{ filePointer[1] = NULL;
filePointer[0] = fopen(argv[1], "rb"); filesize[0] = 0;
strcpy(fileName[0], argv[1]); filesize[1] = 0;
if ( NULL == filePointer[0]) strcpy(fileName[0], "No-File");
{ strcpy(fileName[1], "No-File");
printf("Can not Open [File_1] = %s\n", argv[1]);
usage();
return -1;
}
}
else if (3 == argc)
{
filePointer[0] = fopen(argv[1], "rb");
strcpy(fileName[0], argv[1]);
filePointer[1] = fopen(argv[2], "rb");
strcpy(fileName[1], argv[2]);
fseek ( filePointer[0] , 0 , SEEK_END );
fseek ( filePointer[1] , 0 , SEEK_END );
filesize[0] = ftell (filePointer[0]);
filesize[1] = ftell (filePointer[1]);
fseek ( filePointer[0] , 0 , SEEK_SET );
fseek ( filePointer[1] , 0 , SEEK_SET );
first_Error = findFirstDiff();
}
else
{
usage();
return -1;
}
// rendre la lecture des données non canonique if (3 < argc || argc < 2) {
system("stty -icanon"); printf("You set more than 3 argument at the commande line\n");
// supression de l'écho des caractères usage();
system("stty -echo"); return -1;
}
system("clear"); if (2 <= argc) {
// Open file 1
filePointer[0] = fopen(argv[1], "rb");
strcpy(fileName[0], argv[1]);
if ( NULL == filePointer[0]) {
printf("Can not Open [File_1] = %s\n", fileName[0]);
}
// get size file 1
if ( NULL != filePointer[0]) {
fseek ( filePointer[0] , 0 , SEEK_END );
filesize[0] = ftell (filePointer[0]);
fseek ( filePointer[0] , 0 , SEEK_SET );
} else {
filesize[0] = 0;
}
}
if (3 <= argc) {
// open File 2
filePointer[1] = fopen(argv[2], "rb");
strcpy(fileName[1], argv[2]);
if ( NULL == filePointer[1]) {
printf("Can not Open [File_2] = %s\n", fileName[1]);
}
// get size file 2
if ( NULL != filePointer[1]) {
fseek ( filePointer[1] , 0 , SEEK_END );
filesize[1] = ftell (filePointer[1]);
fseek ( filePointer[1] , 0 , SEEK_SET );
} else {
filesize[1] = 0;
}
}
// try to find the first error...
first_Error = findFirstDiff();
// rendre la lecture des données non canonique
system("stty -icanon");
// supression de l'écho des caractères
system("stty -echo");
system("clear");
/* int ret = 0;
pthread_t HangleThreadDisplay;
printf(GO_TOP); ret = pthread_create ( & HangleThreadDisplay, NULL, threadDisplay, NULL );
if (! ret)
if ( NULL != filePointer[0] {
&& NULL == filePointer[1] ) while (1)
{ {
showFile(filePointer[0] ,CurentFilePosition); uint32_t inputValue;
} inputValue = getc (stdin);
else if ( NULL != filePointer[0] //printf("\n get data : 0x%08x ..... : \n", (unsigned int)inputValue);
&& NULL != filePointer[1] ) switch(inputValue)
{ {
compareFile(filePointer[0],filePointer[1] ,CurentFilePosition); case 'q':
} case 'Q':
*/ goto exit_programme;
break;
//case 0x1B:
case '\e':
inputValue = getc (stdin);
//printf("\n get data : 0x%08x ..... : \n", (unsigned int)inputValue);
int ret = 0; if (inputValue == 0x5B)
pthread_t HangleThreadDisplay; {
inputValue = getc (stdin);
//printf("\n get data : 0x%08x ..... : \n", (unsigned int)inputValue);
// Creation du thread du magasin. if ( inputValue == 0x41
//printf ("Creation du thread du magasin !\n"); || inputValue == 0x42
ret = pthread_create ( & HangleThreadDisplay, NULL, threadDisplay, NULL ); || inputValue == 0x43
if (! ret) || inputValue == 0x44)
{ {
while (1) if (inputValue == 0x41) {
{ upDownOfsetFile(-5);
U32 inputValue; } else if ( inputValue == 0x42) {
inputValue = getc (stdin); upDownOfsetFile(5);
//printf("\n get data : 0x%08x ..... : \n", (unsigned int)inputValue); } else if ( inputValue == 0x43) {
switch(inputValue) upDownOfsetFile(NB_MAX_LINE);
{ } else if ( inputValue == 0x44) {
case 'q': upDownOfsetFile(-NB_MAX_LINE);
case 'Q': }
goto exit_programme; }
break; }
//case 0x1B: break;
case '\e': // change the type of interpretation the file
inputValue = getc (stdin); case 't':
//printf("\n get data : 0x%08x ..... : \n", (unsigned int)inputValue); case 'T':
if (inputValue == 0x5B) nextType();
{ break;
inputValue = getc (stdin); // change the size of showing the file
//printf("\n get data : 0x%08x ..... : \n", (unsigned int)inputValue); case 's':
if ( inputValue == 0x41 case 'S':
|| inputValue == 0x42 nextTypeSize();
|| inputValue == 0x43 break;
|| inputValue == 0x44) // find the first ERROR
{ case 'f':
if (inputValue == 0x41) case 'F':
{ setOfsetFile((first_Error/16)*16 - 256);
upDownOfsetFile(-5); break;
} // find the first ERROR
else if ( inputValue == 0x42) case 'a':
{ case 'A':
upDownOfsetFile(5); setOfsetFile(0);
} break;
else if ( inputValue == 0x43) // go to the end of the file (File 1 and next File 2)
{ case 'z':
upDownOfsetFile(NB_MAX_LINE); case 'Z':
} {
else if ( inputValue == 0x44) static bool whichElement = false;
{ if (whichElement == false) {
upDownOfsetFile(-NB_MAX_LINE); whichElement = true;
} setOfsetFile((filesize[0]/16)*16 - 256);
} } else {
} whichElement = false;
break; setOfsetFile((filesize[1]/16)*16 - 256);
// change the type of interpretation the file }
case 't': }
case 'T': break;
nextType(); }
break; }
// change the size of showing the file } else {
case 's': fprintf (stderr, "%s", strerror (ret));
case 'S': }
nextTypeSize();
break;
// find the first ERROR
case 'f':
case 'F':
setOfsetFile((first_Error/16)*16 - 256);
break;
// find the first ERROR
case 'a':
case 'A':
setOfsetFile(0);
break;
// go to the end of the file (File 1 and next File 2)
case 'z':
case 'Z':
{
static bool whichElement = false;
if (whichElement == false)
{
whichElement = true;
setOfsetFile((filesize[0]/16)*16 - 256);
}
else
{
whichElement = false;
setOfsetFile((filesize[1]/16)*16 - 256);
}
}
break;
}
}
}
else
{
fprintf (stderr, "%s", strerror (ret));
}
exit_programme : exit_programme :
if (NULL != filePointer[0]) if (NULL != filePointer[0]) {
{ fclose(filePointer[0]);
fclose(filePointer[0]); } if (NULL != filePointer[1]) {
} fclose(filePointer[1]);
if (NULL != filePointer[1]) }
{
fclose(filePointer[1]);
}
// remettre la lecture des données canonique // remettre la lecture des données canonique
system("stty icanon"); system("stty icanon");
// repositionnement de l'écho des caractères // repositionnement de l'écho des caractères
system("stty echo"); system("stty echo");
return 0; return 0;
} }
@ -279,128 +261,81 @@ exit_programme :
void displayCouleurBash(void) void displayCouleurBash(void)
{ {
/* Initialise the main variables /* Initialise the main variables
* colour: for the 256 colours (0-255) * colour: for the 256 colours (0-255)
* space: to insert space or newline * space: to insert space or newline
*/ */
int colour = 0; int colour = 0;
int espace = 0; int espace = 0;
/* Print the 16 first colours, known as colours system */ /* Print the 16 first colours, known as colours system */
printf("System colours:\n"); printf("System colours:\n");
for( ; colour < 16; colour++) for( ; colour < 16; colour++) {
{ printf("\e[48;5;%dm ", colour);
printf("\e[48;5;%dm ", colour); }
} printf("\e[0m\n\n");
printf("\e[0m\n\n");
/* The 216 colours */ /* The 216 colours */
printf("Color cube: 6x6x6\n"); printf("Color cube: 6x6x6\n");
for ( ; colour < 232; colour++, espace++) for ( ; colour < 232; colour++, espace++) {
{ if ((espace%6) == 0) {
if ((espace%6) == 0) printf("\e[0m ");
{ }
printf("\e[0m "); if ((espace%36 == 0)) {
} printf("\e[0m\n");
if ((espace%36 == 0)) }
{ printf("\e[48;5;%dm ", colour);
printf("\e[0m\n"); }
} printf("\e[0m\n\n");
printf("\e[48;5;%dm ", colour);
}
printf("\e[0m\n\n");
/* And the grey colours */ /* And the grey colours */
printf("Greyscale ramp\n"); printf("Greyscale ramp\n");
for ( ; colour < 256; colour++) for ( ; colour < 256; colour++) {
{ printf("\e[48;5;%dm ", colour);
printf("\e[48;5;%dm ", colour); }
} printf("\e[0m\n\n");
printf("\e[0m\n\n");
/* Initialise the main variables /* Initialise the main variables
* colour: for the 256 colours (0-255) * colour: for the 256 colours (0-255)
* space: to insert space or newline * space: to insert space or newline
*/ */
/* Print the 16 first colours, known as colours system */ /* Print the 16 first colours, known as colours system */
printf("System colours:\n"); printf("System colours:\n");
for( ; colour < 16; colour++) for( ; colour < 16; colour++) {
{ printf("\e[48;5;%dm ", colour);
printf("\e[48;5;%dm ", colour); }
} printf("\e[0m\n\n");
printf("\e[0m\n\n");
/* The 216 colours */ /* The 216 colours */
printf("Color cube: 6x6x6\n"); printf("Color cube: 6x6x6\n");
for ( ; colour < 232; colour++, espace++) for ( ; colour < 232; colour++, espace++) {
{ if ((espace%6) == 0) {
if ((espace%6) == 0) printf("\e[0m ");
{ }
printf("\e[0m "); if ((espace%36 == 0)) {
} printf("\e[0m\n");
if ((espace%36 == 0)) }
{ printf("\e[48;5;%dm ", colour);
printf("\e[0m\n"); }
} printf("\e[0m\n\n");
printf("\e[48;5;%dm ", colour);
}
printf("\e[0m\n\n");
/* And the grey colours */ /* And the grey colours */
printf("Greyscale ramp\n"); printf("Greyscale ramp\n");
for ( ; colour < 256; colour++) for ( ; colour < 256; colour++) {
{ printf("\e[48;5;%dm ", colour);
printf("\e[48;5;%dm ", colour); }
} printf("\e[0m\n\n");
printf("\e[0m\n\n");
} }

View File

@ -26,7 +26,7 @@
#include "parameter.h" #include "parameter.h"
// Parameter Local Value : // Parameter Local Value :
static U32 fileOfset = 0; static uint32_t fileOfset = 0;
static bool parmamModifier = true; static bool parmamModifier = true;
@ -34,115 +34,106 @@ static showType_te curentType = SHOW_TYPE_HEX;
static showTypeSize_te curentTypeSize = SHOW_TYPE_SIZE_8; static showTypeSize_te curentTypeSize = SHOW_TYPE_SIZE_8;
extern U32 filesize[2]; extern uint32_t filesize[2];
void setOfsetFile(I32 offset) void setOfsetFile(int32_t offset)
{ {
if (0 > offset) if (0 > offset) {
{ offset = 0;
offset = 0; }
} if( offset > (int32_t)filesize[0]
if ( offset > (I32)filesize[0] && offset > (int32_t)filesize[1]) {
&& offset > (I32)filesize[1]) // nothing to do
{ return;
// nothing to do }
return; if (offset != (int32_t)fileOfset) {
} fileOfset = (uint32_t)offset;
if (offset != (I32)fileOfset) parmamModifier = true;
{ }
fileOfset = (U32)offset;
parmamModifier = true;
}
} }
void upDownOfsetFile(I32 offset) void upDownOfsetFile(int32_t offset)
{ {
I32 tmp; int32_t tmp;
tmp = fileOfset + (16 * offset); tmp = fileOfset + (16 * offset);
if (0 > tmp) if (0 > tmp) {
{ setOfsetFile(0);
setOfsetFile(0); } else {
} setOfsetFile(tmp);
else }
{
setOfsetFile(tmp);
}
} }
U32 getOfsetFile(void) uint32_t getOfsetFile(void)
{ {
return fileOfset; return fileOfset;
} }
bool getParamModification() bool getParamModification()
{ {
if (parmamModifier == true) if (parmamModifier == true) {
{ parmamModifier = false;
parmamModifier = false; return true;
return true; } else {
} return false;
else }
{
return false;
}
} }
void nextType(void) void nextType(void)
{ {
switch(curentType) switch(curentType)
{ {
case SHOW_TYPE_HEX: case SHOW_TYPE_HEX:
curentType = SHOW_TYPE_DECIMAL_SIGNED; curentType = SHOW_TYPE_DECIMAL_SIGNED;
break; break;
case SHOW_TYPE_DECIMAL_SIGNED: case SHOW_TYPE_DECIMAL_SIGNED:
curentType = SHOW_TYPE_DECIMAL_UNSIGNED; curentType = SHOW_TYPE_DECIMAL_UNSIGNED;
break; break;
case SHOW_TYPE_DECIMAL_UNSIGNED: case SHOW_TYPE_DECIMAL_UNSIGNED:
curentType = SHOW_TYPE_HEX; curentType = SHOW_TYPE_HEX;
break; break;
default : default :
curentType = SHOW_TYPE_HEX; curentType = SHOW_TYPE_HEX;
break; break;
} }
system("clear"); system("clear");
parmamModifier = true; parmamModifier = true;
} }
showType_te getType(void) showType_te getType(void)
{ {
return curentType; return curentType;
} }
void nextTypeSize(void) void nextTypeSize(void)
{ {
switch(curentTypeSize) switch(curentTypeSize)
{ {
case SHOW_TYPE_SIZE_8: case SHOW_TYPE_SIZE_8:
curentTypeSize = SHOW_TYPE_SIZE_16; curentTypeSize = SHOW_TYPE_SIZE_16;
break; break;
case SHOW_TYPE_SIZE_16: case SHOW_TYPE_SIZE_16:
curentTypeSize = SHOW_TYPE_SIZE_32; curentTypeSize = SHOW_TYPE_SIZE_32;
break; break;
case SHOW_TYPE_SIZE_32: case SHOW_TYPE_SIZE_32:
curentTypeSize = SHOW_TYPE_SIZE_8; curentTypeSize = SHOW_TYPE_SIZE_64;
break; break;
case SHOW_TYPE_SIZE_64: case SHOW_TYPE_SIZE_64:
curentTypeSize = SHOW_TYPE_SIZE_8; curentTypeSize = SHOW_TYPE_SIZE_8;
break; break;
case SHOW_TYPE_SIZE_128: case SHOW_TYPE_SIZE_128:
curentTypeSize = SHOW_TYPE_SIZE_8; curentTypeSize = SHOW_TYPE_SIZE_8;
break; break;
default : default :
curentTypeSize = SHOW_TYPE_SIZE_8; curentTypeSize = SHOW_TYPE_SIZE_8;
break; break;
} }
system("clear"); system("clear");
parmamModifier = true; parmamModifier = true;
} }
showTypeSize_te getTypeSize(void) showTypeSize_te getTypeSize(void)
{ {
return curentTypeSize; return curentTypeSize;
} }

View File

@ -30,9 +30,9 @@
#include "generalDefine.h" #include "generalDefine.h"
void setOfsetFile(I32 offset); void setOfsetFile(int32_t offset);
void upDownOfsetFile(I32 offset); void upDownOfsetFile(int32_t offset);
U32 getOfsetFile(void); uint32_t getOfsetFile(void);
bool getParamModification(); bool getParamModification();