home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdatabs / vbdstats.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-30  |  13.1 KB  |  351 lines

  1. // ------------------------------- //
  2. // -------- Start of File -------- //
  3. // ------------------------------- //
  4. // ----------------------------------------------------------- //
  5. // C++ Source Code File Name: vbdref.cpp
  6. // Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
  7. // Produced By: Doug Gaer   
  8. // File Creation Date: 02/03/1997  
  9. // Date Last Modified: 03/30/1999
  10. // Copyright (c) 1997 Douglas M. Gaer
  11. // ----------------------------------------------------------- // 
  12. // ------------- Program Description and Details ------------- // 
  13. // ----------------------------------------------------------- // 
  14. /*
  15. The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
  16. All those who put this code or its derivatives in a commercial
  17. product MUST mention this copyright in their documentation for
  18. users of the products in which this code or its derivative
  19. classes are used. Otherwise, you have the freedom to redistribute
  20. verbatim copies of this source code, adapt it to your specific
  21. needs, or improve the code and release your improvements to the
  22. public provided that the modified files carry prominent notices
  23. stating that you changed the files and the date of any change.
  24.  
  25. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
  26. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
  27. IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
  28. YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
  29. CORRECTION.
  30.  
  31. The VBD file statistics functions are used to display detailed
  32. file information about the open file This information is used
  33. to analyze and troubleshoot VBD files. 
  34. */
  35. // ----------------------------------------------------------- // 
  36. #include "vbdstats.h"
  37.  
  38. #ifdef __CONSOLE__
  39. #include <iostream.h>
  40. #include <iomanip.h>
  41.  
  42. void VBDStats(const VBDFilePtr &f)
  43. // Passing VBDFilePtr by reference to avoid calling the Refcount
  44. // copy constructor. This will avoid any unnecessary aliasing.
  45. {
  46.   cout << endl;
  47.   const char *FName = f->VBDFileName();
  48.   char rev_letter = f->GetRevLetter();
  49.   __SBYTE__ FileStatus = f->GetFileStatus(); // Get the current file status
  50.   cout << "----- VBD file statistics -----" << endl;
  51.   cout << endl;
  52.   cout << "----- Static information -----" << endl;
  53.   cout << "File Name:         " << FName << endl;
  54.   cout << "File Signature:    " << f->GetSignature() << endl; 
  55.   if(rev_letter == ' ' || rev_letter == 0)
  56.     cout << "Revision Letter:   " << "None" << endl;
  57.   else
  58.     cout << "Revision Letter:   " << rev_letter << endl;
  59.   cout << "Version Number:    " << f->GetVersion() << endl;
  60.   cout << "File Header Size:  " << f->FileHeaderSize() << endl;
  61.   cout << "Block Header Size: " << f->VBHeaderSize() << endl;
  62.   cout << "Static area size:  " << f->StaticArea() << endl;
  63.   cout << "Static file size:  " << f->FileSize(FName) << endl;
  64.   cout << endl;
  65.   cout << "----- Dynamic Information -----" << endl;
  66.   cout << "File Status:     ";
  67.   if(FileStatus & 0x01) cout << "Good "; else cout << "Bad ";
  68.   if(FileStatus & 0x02) cout << "Open "; else cout << "Closed ";
  69.   if(FileStatus & 0x04) cout << "Read/Write "; else cout << "Read/Only ";
  70.   cout << endl;
  71.   cout << "Free Space:      " << f->GetFreeSpace() << endl;
  72.   cout << "End of File:     " << f->GetEOF() << endl;
  73.   cout << "Heap Start:      " << f->GetHeapStart() << endl;
  74.   cout << "Highest Block:   " << f->GetHighestVB() << endl;
  75.   cout << "Total Blocks:    " << f->VBTotal() << endl;
  76.   unsigned tl, dl, rm;
  77.   tl = f->VBDeleted(&dl, &rm);
  78.   cout << "Deleted/Removed: " << dl << "/" << rm << " (" << tl << ")"
  79.        << endl;
  80.   cout << endl;
  81. }
  82.  
  83. void VBStats(const VBDFilePtr &f, FAU oa)
  84. // Passing VBDFilePtr by reference to avoid calling the Refcount
  85. // copy constructor. This will avoid any unnecessary aliasing.
  86. {
  87.   VBHeader vb;
  88.   FAU VBAddress = oa - sizeof(VBHeader);
  89.   f->Read(&vb, sizeof(VBHeader), VBAddress);
  90.   char rev_letter = f->GetRevLetter();
  91.   __ULWORD__ object_crc, calc_crc;
  92.   
  93.   cout << endl;
  94.   cout << "----- Block statistics -----" << endl;
  95.   
  96.   cout << "Check Word   = ";
  97.   cout.setf(ios::uppercase);
  98.   cout << "0x" << setfill('0') << setw(8) << hex << vb.CkWord << endl;
  99.   cout.unsetf(ios::uppercase);
  100.   cout << "Length       = " << dec << vb.Length << endl;
  101.   cout << "Status       = " << (__SBYTE__)vb.Status << endl;
  102.   cout << "Next Deleted = " << vb.NextDeletedVB << endl;
  103.   cout << endl;
  104.   cout << "----- Object statistics -----" << endl;
  105.   cout << "Object Length  = " << f->ObjectLength(oa) << endl;
  106.  
  107.   switch(rev_letter) {
  108.     case 'A':
  109.       f->ReadObjectChecksum(oa, &object_crc, &calc_crc);
  110.       cout.setf(ios::uppercase);
  111.       cout << "Stored CRC     = 0x" << setfill('0') << setw(8) << hex
  112.        << object_crc << endl;
  113.       cout << "Calculated CRC = 0x" << setfill('0') << setw(8) << hex
  114.        << calc_crc << dec << endl;
  115.       break;
  116.     
  117.     default: // Default to versions prior to 1027
  118.       break;
  119.   }
  120.   
  121.   cout << endl;
  122. }
  123. #endif // __CONSOLE__
  124.  
  125. #ifdef __CURSES__
  126. #include "terminal.h"
  127.  
  128. void VBDStats(Terminal *t, const VBDFilePtr &f)
  129. // Passing VBDFilePtr by reference to avoid calling the Refcount
  130. // copy constructor. This will avoid any unnecessary aliasing.
  131. {
  132.   t->ClearScreen();
  133.   int tab = 5; int ypos = 2;
  134.   const int BUFF_LEN = 255;
  135.   char sbuffer[BUFF_LEN];
  136.   const char *FileName = f->VBDFileName();
  137.   char rev_letter = f->GetRevLetter();
  138.   __SBYTE__ FileStatus = f->GetFileStatus(); // Get the current file status
  139.   char *s1 = "----- Variable Block Database file statistics -----";
  140.   t->Write(s1, t->Center(s1), 0);
  141.   t->Write("----- Static information -----", 0, ypos);
  142.   t->Write("File Name:         ", tab, ++ypos);
  143.   t->Write(FileName);
  144.   t->Write("Signature:         ", tab, ++ypos);
  145.   t->Write(f->GetSignature());
  146.   if(rev_letter == ' ' || rev_letter == 0) {
  147.     t->Write("Revision Letter:   ", tab, ++ypos);
  148.     t->Write("None");
  149.   }
  150.   else {
  151.     t->Write("Revision Letter:   ", tab, ++ypos);
  152.     t->Write(rev_letter);
  153.   }
  154.   t->Write("Version Number:    ", tab, ++ypos);
  155.   t->Write(f->GetVersion());
  156.   t->Write("File Header Size:  ", tab, ++ypos);
  157.   t->Write((int)f->FileHeaderSize());
  158.   t->Write("Block Header Size: ", tab, ++ypos);
  159.   t->Write((int)f->VBHeaderSize());
  160.   t->Write("Static area size:  ", tab, ++ypos);
  161.   t->Write(f->StaticArea());
  162.   ypos++;
  163.   t->Write("----- Dynamic Information -----", 0, ++ypos);
  164.   t->Write("File Status:     ", tab, ++ypos);
  165.   if(FileStatus & 0x01)
  166.     t->Write("Good ");
  167.   else
  168.     t->Write("Bad ");
  169.   if(FileStatus & 0x02)
  170.     t->Write("Open ");
  171.   else
  172.     t->Write("Closed ");
  173.   if(FileStatus & 0x04)
  174.     t->Write("Read/Write ");
  175.   else
  176.     t->Write("Read/Only ");
  177.   t->Write("Free Space:      ", tab, ++ypos);
  178.   t->Write(f->GetFreeSpace());
  179.   t->Write("End of File:     ", tab, ++ypos);
  180.   t->Write(f->GetEOF());
  181.   t->Write("Heap Start:      ", tab, ++ypos);
  182.   t->Write(f->GetHeapStart());
  183.   t->Write("Highest Block:   ", tab, ++ypos);
  184.   t->Write(f->GetHighestVB());
  185.   t->Write("Total Blocks:    ", tab, ++ypos);
  186.   t->Write((int)f->VBTotal());
  187.   unsigned tl, dl, rm; 
  188.   tl = f->VBDeleted(&dl, &rm);
  189.   t->Write("Deleted/Removed: ", tab, ++ypos);
  190.   sprintf(sbuffer, "%u/%u (%u)", dl, rm, tl);
  191.   t->Write(sbuffer);
  192.   ypos += 2;
  193.   t->AnyKey(0, ypos);
  194.   t->ClearScreen();
  195. }
  196. #endif // __CURSES__
  197.  
  198. #ifdef __wxWIN168B__
  199.  
  200. #ifdef __GNUG__
  201. #pragma implementation
  202. #pragma interface
  203. #endif
  204.  
  205. // For compilers that support precompilation, includes "wx.h".
  206. #include "wx_prec.h"
  207.  
  208. #ifdef __BORLANDC__
  209. #pragma hdrstop
  210. #endif
  211.  
  212. #ifndef WX_PRECOMP
  213. #include "wx.h"
  214. #endif
  215.  
  216. void VBDStats(wxTextWindow *textWin, const VBDFilePtr &f)
  217. {
  218.   const char *filename = f->VBDFileName();
  219.   const int BUFF_LEN = 255;
  220.   char sbuffer[BUFF_LEN];
  221.   char rev_letter = f->GetRevLetter();
  222.   __SBYTE__ FileStatus = f->GetFileStatus(); // Get the current file status
  223.   *(textWin) << "\n";
  224.   *(textWin) << "----- Static information -----" << "\n";
  225.   *(textWin) << "File Name: " << (char *)filename << "\n";
  226.   *(textWin) << "Signature: " << (char *)f->GetSignature() << "\n"; 
  227.   if(rev_letter == ' ' || rev_letter == 0)
  228.     *(textWin) << "Revision Letter: " << "None" << "\n";     
  229.   else
  230.     *(textWin) << "Revision Letter: " << rev_letter << "\n";     
  231.   *(textWin) << "Version Number: " << (int)f->GetVersion() << "\n";
  232.   *(textWin) << "File Header Size: " << (int)f->FileHeaderSize() << "\n";
  233.   *(textWin) << "Block Header Size: " << (int)f->VBHeaderSize() << "\n";
  234.   *(textWin) << "Static Area Size: " << f->StaticArea() << "\n";
  235.   *(textWin) << "\n";
  236.   *(textWin) << "----- Dynamic Information -----" << "\n";
  237.   *(textWin) << "File Status: ";
  238.   if(FileStatus & 0x01) *(textWin) << "Good "; else *(textWin) << "Bad ";
  239.   if(FileStatus & 0x02) *(textWin) << "Open "; else *(textWin) << "Closed ";
  240.   if(FileStatus & 0x04)
  241.     *(textWin) << "Read/Write ";
  242.   else
  243.     *(textWin) << "Read/Only ";
  244.   *(textWin) << "\n";
  245.   *(textWin) << "Free Space: " << f->GetVBDFreeSpace() << "\n";
  246.   *(textWin) << "End of File: " << f->GetEOF() << "\n";
  247.   *(textWin) << "Heap Start: " << f->GetHeapStart() << "\n";
  248.   *(textWin) << "Highest Block: " << f->GetHighestVB() << "\n";
  249.   *(textWin) << "Total Blocks: " << (int)f->VBTotal() << "\n";
  250.   unsigned tl, dl, rm;
  251.   tl = f->VBDeleted(&dl, &rm);
  252.   sprintf(sbuffer, "%u/%u (%u)", dl, rm, tl);
  253.   *(textWin) << "Deleted/Removed: " << sbuffer << "\n";
  254.   int tobjects = f->VBTotal() - f->VBDeleted();
  255.   if(tobjects <= 0) tobjects = 0;
  256.   *(textWin) << "Number of objects: " << tobjects << "\n"; 
  257.   *(textWin) << "\n";
  258. }
  259.  
  260. void VBStats(wxTextWindow *textWin, const VBDFilePtr &f, FAU oa)
  261. {
  262.   VBHeader vb;
  263.   const int BUFF_LEN = 255;
  264.   char sbuffer[BUFF_LEN];
  265.   FAU VBAddress = oa - sizeof(VBHeader);
  266.   f->Read(&vb, sizeof(VBHeader), VBAddress);
  267.   *(textWin) << "----- Block statistics -----" << "\n";
  268.   sprintf(sbuffer, "0x%08X", vb.CkWord);
  269.   *(textWin) << "Check Word: " << sbuffer << "\n";
  270.   *(textWin) << "Length: " << (long)vb.Length << "\n";
  271.   *(textWin) << "Next Deleted: " << vb.NextDeletedVB << "\n";
  272.   *(textWin) << "\n";
  273.   *(textWin) << "----- Object statistics -----" << "\n";
  274.   sprintf(sbuffer, "%d", (vb.Length - sizeof(VBHeader)));
  275.   *(textWin) << "Object Length: " << (long)f->ObjectLength(oa) << "\n";
  276.   *(textWin) << "\n";
  277. }
  278. #endif // __wxWIN168B__
  279.  
  280. #ifdef __wxWIN201__
  281. #include "wx2incs.h"
  282.  
  283. void VBDStats(wxTextCtrl *textWin, const VBDFilePtr &f)
  284. {
  285.   const char *filename = f->VBDFileName();
  286.   const int BUFF_LEN = 255;
  287.   char sbuffer[BUFF_LEN];
  288.   char rev_letter = f->GetRevLetter();
  289.   __SBYTE__ FileStatus = f->GetFileStatus(); // Get the current file status
  290.   *(textWin) << "\n";
  291.   *(textWin) << "----- Static information -----" << "\n";
  292.   *(textWin) << "File Name: " << (char *)filename << "\n";
  293.   *(textWin) << "Signature: " << (char *)f->GetSignature() << "\n"; 
  294.   if(rev_letter == ' ' || rev_letter == 0)
  295.     *(textWin) << "Revision Letter: " << "None" << "\n";     
  296.   else
  297.     *(textWin) << "Revision Letter: " << rev_letter << "\n";     
  298.   *(textWin) << "Version Number: " << (int)f->GetVersion() << "\n";
  299.   *(textWin) << "File Header Size: " << (int)f->FileHeaderSize() << "\n";
  300.   *(textWin) << "Block Header Size: " << (int)f->VBHeaderSize() << "\n";
  301.   *(textWin) << "Static Area Size: " << f->StaticArea() << "\n";
  302.   *(textWin) << "\n";
  303.   *(textWin) << "----- Dynamic Information -----" << "\n";
  304.   *(textWin) << "File Status: ";
  305.   if(FileStatus & 0x01) *(textWin) << "Good "; else *(textWin) << "Bad ";
  306.   if(FileStatus & 0x02) *(textWin) << "Open "; else *(textWin) << "Closed ";
  307.   if(FileStatus & 0x04)
  308.     *(textWin) << "Read/Write ";
  309.   else
  310.     *(textWin) << "Read/Only ";
  311.   *(textWin) << "\n";
  312.   *(textWin) << "Free Space: " << f->GetVBDFreeSpace() << "\n";
  313.   *(textWin) << "End of File: " << f->GetEOF() << "\n";
  314.   *(textWin) << "Heap Start: " << f->GetHeapStart() << "\n";
  315.   *(textWin) << "Highest Block: " << f->GetHighestVB() << "\n";
  316.   *(textWin) << "Total Blocks: " << (int)f->VBTotal() << "\n";
  317.   unsigned tl, dl, rm;
  318.   tl = f->VBDeleted(&dl, &rm);
  319.   sprintf(sbuffer, "%u/%u (%u)", dl, rm, tl);
  320.   *(textWin) << "Deleted/Removed: " << sbuffer << "\n";
  321.   int tobjects = f->VBTotal() - f->VBDeleted();
  322.   if(tobjects <= 0) tobjects = 0;
  323.   *(textWin) << "Number of objects: " << tobjects << "\n"; 
  324.   *(textWin) << "\n";
  325. }
  326.  
  327. void VBStats(wxTextCtrl *textWin, const VBDFilePtr &f, FAU oa)
  328. {
  329.   VBHeader vb;
  330.   const int BUFF_LEN = 255;
  331.   char sbuffer[BUFF_LEN];
  332.   FAU VBAddress = oa - sizeof(VBHeader);
  333.   f->Read(&vb, sizeof(VBHeader), VBAddress);
  334.   *(textWin) << "----- Block statistics -----" << "\n";
  335.   sprintf(sbuffer, "0x%08X", vb.CkWord);
  336.   *(textWin) << "Check Word: " << sbuffer << "\n";
  337.   *(textWin) << "Length: " << (long)vb.Length << "\n";
  338.   *(textWin) << "Next Deleted: " << vb.NextDeletedVB << "\n";
  339.   *(textWin) << "\n";
  340.   *(textWin) << "----- Object statistics -----" << "\n";
  341.   sprintf(sbuffer, "%d", (vb.Length - sizeof(VBHeader)));
  342.   *(textWin) << "Object Length: " << (long)f->ObjectLength(oa) << "\n";
  343.   *(textWin) << "\n";
  344. }
  345. #endif // __wxWIN201__
  346.  
  347. // ----------------------------------------------------------- //
  348. // ------------------------------- //
  349. // --------- End of File --------- //
  350. // ------------------------------- //
  351.