Got an iPhone or iPad? We have a brand new Pastebin App for both devices, and it's totally free! Click here to download the new Pastebin App for iOS.
Guest

Branruz

By: a guest on Feb 9th, 2010  |  syntax: None  |  size: 4.64 KB  |  hits: 57  |  expires: Never
download  |  raw  |  embed  |  report abuse
This paste has a previous version, view the difference. Copied
  1. // DBCDIFF par Franck (francksouris@yahoo.fr) pour la WaadTeam
  2.  
  3. #include <fstream>
  4. #include <iostream>
  5. #include <string>
  6. #include<cstdio>
  7. #include <vector>
  8. #ifdef WIN32
  9. #include <conio.h>
  10. #endif
  11. #ifndef _VISUAL_CPP_
  12. #include <mem.h>
  13. #endif
  14.  
  15. using namespace std;
  16.  
  17. #define DBCP_version "beta0.1"
  18.  
  19. struct Entete // entete DBC
  20. {
  21.         char Signature[5];
  22.         int Records,Fields,Record_Size,String_Block_Size;
  23. };
  24.  
  25. int LectureEntete (FILE * DBC, Entete * E)
  26. {
  27.         memset(E->Signature,0x00,5);
  28.         fread (E->Signature,sizeof(char),4,DBC);
  29.         fread (&E->Records,sizeof(int),1,DBC);
  30.         fread (&E->Fields,sizeof(int),1,DBC);
  31.         fread (&E->Record_Size,sizeof(int),1,DBC);
  32.         fread (&E->String_Block_Size,sizeof(int),1,DBC);
  33.        
  34.  
  35.         cout << "Signature:" << E->Signature << " Records:" << E->Records <<
  36.         " Fields:" << E->Fields << " Record_Size:" << E->Record_Size <<
  37.         " String_Block_Size:" << E->String_Block_Size << endl;
  38.  
  39.         return 0;
  40. }
  41.  
  42. int CompareEntete ( Entete dbc1, Entete dbc2 )
  43. {
  44. // int Records,Fields,Record_Size,String_Block_Size;
  45.        
  46.         cout << "Comparaison des entetes des DBC" << endl;
  47.        
  48.         if ( dbc1.Records != dbc2.Records )
  49.                 cout << "Nombre d'enregistrement : modif de " << dbc1.Records << " a " << dbc2.Records << endl;
  50.  
  51.         if ( dbc1.Fields != dbc2.Fields )
  52.                 cout << "Nombre de champ : modif de " << dbc1.Fields << " a " << dbc2.Fields << endl;
  53.  
  54.         if ( dbc1.Record_Size != dbc2.Record_Size )
  55.                 cout << "Taille d'enregistrement : modif de " << dbc1.Record_Size << " a " << dbc2.Record_Size << endl;
  56.  
  57.         if ( dbc1.String_Block_Size != dbc2.String_Block_Size )
  58.                 cout << "Taille du String Block : modif de " << dbc1.String_Block_Size << " a " << dbc2.String_Block_Size << endl;
  59.  
  60.         return 0;
  61. }
  62.  
  63. int LectureData ( vector< vector <unsigned long> > * Data , FILE * f , Entete E)
  64. {
  65.         // On redimensionne le tableau pour qu'il ait 'Records' lignes et de 'Fields' colonnes
  66.         Data->resize(E.Records,vector<unsigned long>(E.Fields));
  67.        
  68.         for( int l=0; l < E.Records ;l++)
  69.         {
  70.                 for( int c=0; c < E.Fields ;c++)
  71.                 {
  72.                         unsigned long data;
  73.                         fread(&data,sizeof(unsigned long),1,f);
  74.                         (*Data)[l][c] = data;
  75.                 }
  76.         }
  77.         return 0;
  78. }
  79.  
  80. int StringBlock ( vector<int> * SP , FILE * f , Entete E)
  81. {
  82.         cout << "Taille du Block " << E.String_Block_Size << endl;
  83.  
  84.         char c;
  85.        
  86.         for (int i=0 ; i < E.String_Block_Size ; i++)
  87.         {
  88.                 fread(&c,sizeof(char),1,f);
  89.                 if ( c == 0x00 ) SP->push_back(i);
  90.         }
  91.  
  92. /*     
  93.         vector<int>::iterator itr;
  94.  
  95.         cout << "Valeur des fins de string :" ;
  96.         for (itr = SP->begin() ; itr != SP->end() ; itr++)
  97.         {
  98.                 cout << " " << *itr;
  99.         }
  100.         cout << endl;
  101. */     
  102.         return 0;
  103. }
  104.  
  105. int FieldString ( vector< vector <unsigned long> > Data , vector<int> Parse , Entete E)
  106. {
  107.         for ( int c=0 ; c < E.Fields ; c++ )
  108.         {
  109.                 //cout << "DEBUG field en cours " << c << endl;
  110.                 bool IsString = true;
  111.                
  112.                 for ( int l=0 ; l < E.Records ; l++ )
  113.                 {
  114.  
  115.                         bool IsInParse = false;
  116.                         vector<int>::iterator itr;
  117.                        
  118.                         for (itr = Parse.begin() ; itr != Parse.end() ; itr++)
  119.                         {
  120.                                 if ( Data[l][c] == *itr+1 ) IsInParse = true; //+1 car on cherche le debut du string
  121.                         }
  122.                
  123.                         if ( IsInParse == false )
  124.                         {
  125.                                 IsString = false;
  126.                                 break;
  127.                         }
  128.                
  129.                 }
  130.                
  131.                 if ( IsString ) cout << "Fields(" << c << ") est de type string ?" << endl;
  132.                
  133.         }
  134.         return 0;
  135. }
  136.  
  137. int main(int argc, char ** argv)
  138. {
  139.  
  140.         printf ( "DBC Comp %s\n",DBCP_version );
  141.        
  142.         FILE * FichierDBC1;
  143.         FILE * FichierDBC2;
  144.        
  145.         if ( argv[1] != NULL ) FichierDBC1=fopen(argv[1],"rb");
  146.         else
  147.         {
  148.                 cout << "1ier DBC non valide." << endl;
  149. #ifdef WIN32
  150.             getch();
  151. #endif
  152.                 return 0;              
  153.         }
  154.         if ( argv[2] != NULL ) FichierDBC2=fopen(argv[2],"rb");
  155.         else
  156.         {
  157.                 cout << "2ieme DBC non valide." << endl;
  158. #ifdef WIN32
  159.             getch();
  160. #endif
  161.                 return 0;
  162.         }
  163.        
  164.         if ( (FichierDBC1 == NULL) || (FichierDBC2 == NULL) )
  165.         {
  166.                 cout << "Impossible d'ouvrir l'un des DBCs !" << endl;
  167. #ifdef WIN32
  168.             getch();
  169. #endif
  170.                 return 0;
  171.         }
  172.         cout << endl;
  173.        
  174.         Entete Edbc1,Edbc2;
  175.  
  176.         LectureEntete ( FichierDBC1 , &Edbc1 );
  177.         LectureEntete ( FichierDBC2 , &Edbc2 );
  178.         cout << endl;
  179.        
  180.         CompareEntete ( Edbc1 , Edbc2 );
  181.         cout << endl;
  182.        
  183.         vector< vector <unsigned long> > DataDBC1;
  184.         LectureData ( &DataDBC1 , FichierDBC1 , Edbc1 );
  185.  
  186.         // on compare les données ?
  187.        
  188.         if ( Edbc1.String_Block_Size > 1 )
  189.         {
  190.                 //on a du texte :)
  191.                 // ((Records * RecordSize) + 20)        20 = taille entette (4char + 4int)
  192.                 vector<int> ParseString;
  193.                 StringBlock ( &ParseString , FichierDBC1 , Edbc1 );
  194.  
  195.                 FieldString ( DataDBC1 , ParseString , Edbc1 );
  196.  
  197.                 cout << endl;
  198.         }
  199.                
  200.         fclose (FichierDBC1);
  201.         fclose (FichierDBC2);
  202.        
  203.         cout << "Fin Programme !" << endl;
  204. #ifdef WIN32
  205.         getch();
  206. #endif
  207. }