home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cslio205.zip / EXAMPLES / 2 / LIST.CPP < prev    next >
Text File  |  1996-10-08  |  3KB  |  113 lines

  1. #include "iostream.h"
  2. #include "csmalloc.h"
  3. #include "demodb.h"
  4.  
  5.  
  6. ////////////////////////////////////////////////////////////////////////
  7. ///////////////  Display Intro screen //////////////////////////////////
  8. ////////////////////////////////////////////////////////////////////////
  9.  
  10. void help(void)
  11. {
  12.       cout<<endl<<endl;
  13.       cout<<"list version 1.0 for "<<_CP_PLATFORM<<endl;
  14.       cout<<"  Lists the database alphabetically. "<<endl;
  15.       cout<<"Copyright (c) ComBits, 1996"<<endl;
  16.       cout<<"Compiled: "<<__DATE__<<",  "<<__TIME__<<endl<<endl;
  17.       cout<<"SYNTAX:  list <name|data|natural>     "<<endl;
  18.       cout<<"  name:    List the NAME fields in alphabetical order. "<<endl;
  19.       cout<<"  data:    List the DATA fields in alphabetical order. "<<endl;
  20.       cout<<"  natural: List the database unsorted. "<<endl<<endl;
  21.       cout<<"EXAMPLE: list name  "<<endl;
  22. }
  23.  
  24. ////////////////////////////////////////////////////////////////////////
  25. ///////////////  Main program //////////////////////////////////////////
  26. ////////////////////////////////////////////////////////////////////////
  27.  
  28.  
  29.  
  30. int main(int argc,char *argv[])
  31. {
  32.  
  33. //alloc_logging(TRUE);     // Uncomment if you like allocation logging.
  34.  
  35.  
  36.   DEMO     demo;    // An instance of the generated DEMO class.
  37.  
  38.   int     order;
  39.  
  40.   if(argc!=2)
  41.   {
  42.     help();
  43.     return 1;
  44.   }
  45.  
  46.  
  47.   if(!stricmp(argv[1],"name"))
  48.   {
  49.     order=DEMO_NAME_INDEX;
  50.   }else
  51.   if(!stricmp(argv[1],"data"))
  52.   {
  53.     order=DEMO_DATA_INDEX;
  54.   }else
  55.   if(!stricmp(argv[1],"natural"))
  56.   {
  57.     order=UNSORTED;
  58.   }else
  59.   {
  60.     help();
  61.     return 1;
  62.   }
  63.  
  64.  
  65.  
  66. ////// Open the now existing Database and Indexes.
  67.  
  68.   if(!demo.open(100))  // Open with 100Kb buffers.
  69.   {
  70.      cout<<"Error, can't open databases. "<<endl;
  71.      return 8;
  72.   }
  73.  
  74.  
  75.  
  76.   cout<<endl<<endl;
  77.  
  78.   demo.order(order);            // Select an index.
  79.  
  80.   if(demo.top())              // Read the first key.
  81.   {                      // Fails only if the btree is empty.
  82.  
  83.     do
  84.     {
  85.       cout.width(55);
  86.       cout.fill('.');
  87.       cout.setf(ios::left, ios::adjustfield);
  88.       cout<<demo.name()<<demo.data()<<endl;
  89.     }
  90.     while(demo.next());           // Next key.
  91.   }
  92.  
  93.  
  94.  
  95. ////// Close Database and Indexes.
  96.  
  97.   if(!demo.close())
  98.   {
  99.      cout<<"Error, while closeing databases. "<<endl;
  100.      return 8;
  101.   }
  102.  
  103. ////// Display errors IF ANY! Otherwise nothing is displayed.
  104.  
  105.   demo.display_error();
  106.  
  107.  
  108. ////// Return error level 0 to the command line.
  109.  
  110.   return 0;
  111.  
  112. }
  113.