home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / db02_src.zip / dispr.cc < prev    next >
C/C++ Source or Header  |  1993-11-05  |  6KB  |  269 lines

  1. /**************************************************************************
  2.  * Source Id :
  3.  *
  4.  * $Id: dispr.cc,v 1.4 1993/05/26 01:01:39 kevinl Exp $
  5.  *-------------------------------------------------------------------------
  6.  * Project Notes :
  7.  *
  8.  *  Diamond Base
  9.  *  ============
  10.  *      A solid database implementation, spurred on by the continuing
  11.  *  Metal (Lead) Base saga.
  12.  *
  13.  *  Project Team :
  14.  *        A. Davison
  15.  *        K. Lentin
  16.  *        D. Platt
  17.  *
  18.  *    Project Commenced : 05-02-1993
  19.  *
  20.  *-------------------------------------------------------------------------
  21.  *  Module Notes :
  22.  *
  23.  *        Relation Browser
  24.  *
  25.  *            Dumps out the format of a relation and it's associated 
  26.  *    index information from the database file.
  27.  *
  28.  *  Original Author : Andy
  29.  *
  30.  *-------------------------------------------------------------------------
  31.  * Revision History:
  32.  *
  33.  * $Log: dispr.cc,v $
  34. // Revision 1.4  1993/05/26  01:01:39  kevinl
  35. // MALLOC_H_MISSING
  36. //
  37. // Revision 1.3  1993/03/29  08:20:09  darrenp
  38. // Added new malloc library support
  39. //
  40. // Revision 1.2  1993/03/15  19:26:55  davison
  41. // Implemented a few nice things, like more than 2 index fields, line number
  42. // reporting on syntax errors, and usage reporting.
  43. //
  44. // Just for you, Daz :-)
  45. //
  46. // Revision 1.1  1993/03/15  19:25:53  davison
  47. // Initial revision
  48. //
  49.  **************************************************************************/
  50. #include <iostream.h>
  51. #include <fstream.h>
  52. #include "idxinfo.h"
  53. #include "d_types.h"
  54. #ifndef MALLOC_H_MISSING
  55. #include <malloc.h>
  56. #endif
  57.  
  58. //-----------------------
  59. //  Relation List program
  60. //
  61.  
  62. void dispInfo(fieldList& list,indexList& idxList);
  63.  
  64. // Usage information.
  65.  
  66. void usage(void)
  67. {
  68.     cerr << "Usage : dispr <relation filename>" << endl;
  69.     exit(1);
  70. }
  71.  
  72.  
  73. main(int argc, char* argv[])
  74. {
  75.     if (argc != 2)
  76.         usage();
  77.  
  78.     char name[200];
  79.     strcpy(name,argv[1]);
  80.  
  81.     // Strip the extension and replace it with ".db".
  82.  
  83.     char* dot = strchr(name,'.');
  84.     if(dot)
  85.         *dot=(char)0;
  86.     strcat(name,".db");
  87.     
  88.     // Just define a few things...
  89.  
  90.     ifstream input(name);
  91.     checkStream(input);
  92.     int headerLength;
  93.     fieldList fldList;
  94.     indexList idxList;
  95.  
  96.     // Now read the database.
  97.  
  98.     // First the length of the header info.
  99.  
  100.     input.read((char*)&headerLength,sizeof(int));
  101.     // Then get the field information
  102.     input >> fldList;
  103.     // Then get the index information.
  104.     input >> idxList;
  105.  
  106.     // And finally diaplay it.
  107.  
  108.     dispInfo(fldList,idxList);
  109.  
  110.     return 0;
  111. }
  112.  
  113. //--------------------------------------------------
  114. // Display the information once it's been retrieved.
  115. //
  116. // Buggered if I'm going to comment this. Let's see how it goes...
  117.  
  118.  
  119.  
  120. void dispInfo(fieldList& list,indexList& idxList)
  121. {
  122.     fieldInfo* curFld = list.fields;
  123.  
  124.     cout << "\tField Name \tField Type\t\tField Size (in bytes)" << endl;
  125.     cout << "===============================================================================" << endl;
  126.     while (curFld)
  127.     {
  128.         cout << "\t" << curFld->fldName << "\t\t";
  129.         switch (curFld->fldType)
  130.         {
  131.             case 3:
  132.                 cout << "short";
  133.                 if(curFld->fldSize != sizeof(short))
  134.                     cout << "[" << curFld->fldSize/sizeof(short) << "]";
  135.                 else
  136.                     cout << "\t";
  137.                 break;
  138.             case 4:
  139.                 cout << "unsigned short";
  140.                 if(curFld->fldSize != sizeof(unsigned short))
  141.                     cout << "[" << curFld->fldSize/sizeof(unsigned short) << "]";
  142.                 else
  143.                     cout << "\t";
  144.                 break;
  145.             case 1:
  146.                 cout << "long";
  147.                 if(curFld->fldSize != sizeof(long))
  148.                     cout << "[" << curFld->fldSize/sizeof(long) << "]";
  149.                 else
  150.                     cout << "\t";
  151.                 break;
  152.             case 2:
  153.                 cout << "unsigned long";
  154.                 if(curFld->fldSize != sizeof(unsigned long))
  155.                     cout << "[" << curFld->fldSize/sizeof(unsigned long) << "]";
  156.                 else
  157.                     cout << "\t";
  158.                 break;
  159.             case 5:
  160.                 cout << "double";
  161.                 if(curFld->fldSize != sizeof(double))
  162.                     cout << "[" << curFld->fldSize/sizeof(double) << "]";
  163.                 else
  164.                     cout << "\t";
  165.                 break;
  166.             case 6:
  167.                 cout << "float";
  168.                 if(curFld->fldSize != sizeof(float))
  169.                     cout << "[" << curFld->fldSize/sizeof(float) << "]";
  170.                 else
  171.                     cout << "\t";
  172.                 break;
  173.             case 7:
  174.                 cout << "money";
  175.                 if(curFld->fldSize != sizeof(moneyType))
  176.                     cout << "[" << curFld->fldSize/sizeof(moneyType) << "]";
  177.                 else
  178.                     cout << "\t";
  179.                 break;
  180.             case 8:
  181.                 cout << "date";
  182.                 if(curFld->fldSize != sizeof(dateType))
  183.                     cout << "[" << curFld->fldSize/sizeof(dateType) << "]";
  184.                 else
  185.                     cout << "\t";
  186.                 break;
  187.             case 9:
  188.                 cout << "char";
  189.                 if(curFld->fldSize != sizeof(char))
  190.                     cout << "[" << curFld->fldSize/sizeof(char) << "]";
  191.                 else
  192.                     cout << "\t";
  193.                 break;
  194.             case 10:
  195.                 cout << "unique";
  196.                 if(curFld->fldSize != sizeof(uniqueType))
  197.                     cout << "[" << curFld->fldSize/sizeof(uniqueType) << "]";
  198.                 else
  199.                     cout << "\t";
  200.                 break;
  201.             default:
  202.                 cerr << "Invalid data type in relation file. Aborting." << endl;
  203.                 exit(1);
  204.         }
  205.         
  206.         cout << "\t\t" << curFld->fldSize << endl;
  207.         curFld = curFld->nextFld;
  208.     }
  209.  
  210.     //----------------------------------------------
  211.     // Now display index information.
  212.  
  213.     cout << endl << endl 
  214.          << "\tIndexed Field(s)\t\t\tAllow Duplicates ?" << endl
  215.          << "==============================================================================" << endl;
  216.  
  217.     indexInfo* curIdx = idxList.indicies;
  218.     while (curIdx)
  219.     {
  220.         curFld = list.fields;
  221.         for(int i=0;i<curIdx->idxFields[0];i++)
  222.             curFld=curFld->nextFld;
  223.         cout << "\t" << curFld->fldName;
  224.  
  225.         // Now the second index (if necessary).
  226.  
  227.         if(curIdx->idxFields[1] != -1)
  228.         {
  229.             cout << ", ";
  230.             curFld = list.fields;
  231.             for(int i=0;i<curIdx->idxFields[1];i++)
  232.                 curFld=curFld->nextFld;
  233.             cout << curFld->fldName;
  234.         }
  235.         else
  236.             cout << "\t";
  237.         if(curIdx->idxFields[2] != -1)
  238.         {
  239.             cout << ", ";
  240.             curFld = list.fields;
  241.             for(int i=0;i<curIdx->idxFields[2];i++)
  242.                 curFld=curFld->nextFld;
  243.             cout << curFld->fldName;
  244.         }
  245.         else
  246.             cout << "\t";
  247.  
  248.         if(curIdx->idxFields[3] != -1)
  249.         {
  250.             for(int q=3;q<MAX_FIELDS_IN_INDEX && curIdx->idxFields[q] != -1;q++)
  251.             {
  252.                 cout << ", ";
  253.                 curFld = list.fields;
  254.                 for(int i=0;i<curIdx->idxFields[q];i++)
  255.                     curFld=curFld->nextFld;
  256.                 cout << curFld->fldName;
  257.             }
  258.             cout << endl << "\t\t\t";
  259.         }
  260.         cout << "\t\t\t";
  261.         if((curIdx->idxType) & IDX_DUPLICATES)
  262.             cout << "yes" << endl;
  263.         else
  264.             cout << "no" << endl;
  265.         curIdx=curIdx->nextIdx;
  266.     }
  267. }
  268.  
  269.