- // DBCDIFF par Franck (francksouris@yahoo.fr) pour la WaadTeam
- #include <fstream>
- #include <iostream>
- #include <string>
- #include<cstdio>
- #include <vector>
- #ifdef WIN32
- #include <conio.h>
- #endif
- #ifndef _VISUAL_CPP_
- #include <mem.h>
- #endif
- using namespace std;
- #define DBCP_version "beta0.1"
- struct Entete // entete DBC
- {
- char Signature[5];
- int Records,Fields,Record_Size,String_Block_Size;
- };
- int LectureEntete (FILE * DBC, Entete * E)
- {
- memset(E->Signature,0x00,5);
- fread (E->Signature,sizeof(char),4,DBC);
- fread (&E->Records,sizeof(int),1,DBC);
- fread (&E->Fields,sizeof(int),1,DBC);
- fread (&E->Record_Size,sizeof(int),1,DBC);
- fread (&E->String_Block_Size,sizeof(int),1,DBC);
- cout << "Signature:" << E->Signature << " Records:" << E->Records <<
- " Fields:" << E->Fields << " Record_Size:" << E->Record_Size <<
- " String_Block_Size:" << E->String_Block_Size << endl;
- return 0;
- }
- int CompareEntete ( Entete dbc1, Entete dbc2 )
- {
- // int Records,Fields,Record_Size,String_Block_Size;
- cout << "Comparaison des entetes des DBC" << endl;
- if ( dbc1.Records != dbc2.Records )
- cout << "Nombre d'enregistrement : modif de " << dbc1.Records << " a " << dbc2.Records << endl;
- if ( dbc1.Fields != dbc2.Fields )
- cout << "Nombre de champ : modif de " << dbc1.Fields << " a " << dbc2.Fields << endl;
- if ( dbc1.Record_Size != dbc2.Record_Size )
- cout << "Taille d'enregistrement : modif de " << dbc1.Record_Size << " a " << dbc2.Record_Size << endl;
- if ( dbc1.String_Block_Size != dbc2.String_Block_Size )
- cout << "Taille du String Block : modif de " << dbc1.String_Block_Size << " a " << dbc2.String_Block_Size << endl;
- return 0;
- }
- int LectureData ( vector< vector <unsigned long> > * Data , FILE * f , Entete E)
- {
- // On redimensionne le tableau pour qu'il ait 'Records' lignes et de 'Fields' colonnes
- Data->resize(E.Records,vector<unsigned long>(E.Fields));
- for( int l=0; l < E.Records ;l++)
- {
- for( int c=0; c < E.Fields ;c++)
- {
- unsigned long data;
- fread(&data,sizeof(unsigned long),1,f);
- (*Data)[l][c] = data;
- }
- }
- return 0;
- }
- int StringBlock ( vector<int> * SP , FILE * f , Entete E)
- {
- cout << "Taille du Block " << E.String_Block_Size << endl;
- char c;
- for (int i=0 ; i < E.String_Block_Size ; i++)
- {
- fread(&c,sizeof(char),1,f);
- if ( c == 0x00 ) SP->push_back(i);
- }
- /*
- vector<int>::iterator itr;
- cout << "Valeur des fins de string :" ;
- for (itr = SP->begin() ; itr != SP->end() ; itr++)
- {
- cout << " " << *itr;
- }
- cout << endl;
- */
- return 0;
- }
- int FieldString ( vector< vector <unsigned long> > Data , vector<int> Parse , Entete E)
- {
- for ( int c=0 ; c < E.Fields ; c++ )
- {
- //cout << "DEBUG field en cours " << c << endl;
- bool IsString = true;
- for ( int l=0 ; l < E.Records ; l++ )
- {
- bool IsInParse = false;
- vector<int>::iterator itr;
- for (itr = Parse.begin() ; itr != Parse.end() ; itr++)
- {
- if ( Data[l][c] == *itr+1 ) IsInParse = true; //+1 car on cherche le debut du string
- }
- if ( IsInParse == false )
- {
- IsString = false;
- break;
- }
- }
- if ( IsString ) cout << "Fields(" << c << ") est de type string ?" << endl;
- }
- return 0;
- }
- int main(int argc, char ** argv)
- {
- printf ( "DBC Comp %s\n",DBCP_version );
- FILE * FichierDBC1;
- FILE * FichierDBC2;
- if ( argv[1] != NULL ) FichierDBC1=fopen(argv[1],"rb");
- else
- {
- cout << "1ier DBC non valide." << endl;
- #ifdef WIN32
- getch();
- #endif
- return 0;
- }
- if ( argv[2] != NULL ) FichierDBC2=fopen(argv[2],"rb");
- else
- {
- cout << "2ieme DBC non valide." << endl;
- #ifdef WIN32
- getch();
- #endif
- return 0;
- }
- if ( (FichierDBC1 == NULL) || (FichierDBC2 == NULL) )
- {
- cout << "Impossible d'ouvrir l'un des DBCs !" << endl;
- #ifdef WIN32
- getch();
- #endif
- return 0;
- }
- cout << endl;
- Entete Edbc1,Edbc2;
- LectureEntete ( FichierDBC1 , &Edbc1 );
- LectureEntete ( FichierDBC2 , &Edbc2 );
- cout << endl;
- CompareEntete ( Edbc1 , Edbc2 );
- cout << endl;
- vector< vector <unsigned long> > DataDBC1;
- LectureData ( &DataDBC1 , FichierDBC1 , Edbc1 );
- // on compare les données ?
- if ( Edbc1.String_Block_Size > 1 )
- {
- //on a du texte :)
- // ((Records * RecordSize) + 20) 20 = taille entette (4char + 4int)
- vector<int> ParseString;
- StringBlock ( &ParseString , FichierDBC1 , Edbc1 );
- FieldString ( DataDBC1 , ParseString , Edbc1 );
- cout << endl;
- }
- fclose (FichierDBC1);
- fclose (FichierDBC2);
- cout << "Fin Programme !" << endl;
- #ifdef WIN32
- getch();
- #endif
- }