home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / c / 13463 < prev    next >
Encoding:
Text File  |  1992-09-10  |  4.1 KB  |  159 lines

  1. Xref: sparky comp.lang.c:13463 comp.lang.c++:13477
  2. Newsgroups: comp.lang.c,comp.lang.c++
  3. Path: sparky!uunet!mnemosyne.cs.du.edu!arrakis!thor
  4. From: thor@arrakis.denver.co.us (Robert B. Hood)
  5. Subject: cBASE - Part 3 of 4
  6. Message-ID: <1992Sep10.134452.8617@arrakis.denver.co.us>
  7. Summary: A dBASE III+ Class in C++
  8. Reply-To: thor@arrakis.denver.co.us
  9. Organization: Bob's Programming Paradise, Lakewood, CO, USA
  10. Date: Thu, 10 Sep 1992 13:44:52 GMT
  11. Lines: 146
  12.  
  13. --------------------------- CBTEST.CPP ----------------------------
  14. // CBTEST - A program to test the dBASE III+ C++ class
  15. //                Copyright (C) 1992 Bob Hood
  16. //
  17. // Author      : Bob Hood (thor@arrakis.denver.co.us)
  18. // Last Update : 08.01.92
  19. // Header Files: cBASE.HPP
  20. // Comments    : Class is still under construction, so use at your own risk.
  21. //
  22. //               You are free to copy and distribute this code as long as
  23. //               you do not charge a fee for it, and the Copyright notice
  24. //               above remains intact.
  25.  
  26. #include    <stdio.h>
  27. #include    <iostream.h>
  28. #include    <conio.h>
  29. #include    <stdlib.h>
  30. #include    <fcntl.h>
  31. #include    <io.h>
  32. #include    <alloc.h>
  33. #include    <string.h>
  34. #include    <mem.h>
  35.  
  36. #include    "cbase.hpp"
  37.  
  38. void main(int argc,char *argv[])
  39. {
  40.     int         x,y,z;
  41.     char        command[80];
  42.     dBASE       *db;                // dBASE object
  43.  
  44.     if(argc < 2)
  45.     {
  46.         cout << "Missing database name.\n";
  47.         exit(1);
  48.     }
  49.  
  50.     db = new dBASE;                 // create an arbritrary dBASE object
  51.  
  52.     if((x = db->activate(argv[1],NULL)) != NO_PROBLEM)
  53.     {
  54.         switch(x)
  55.         {
  56.             case DOS_OPEN_ERROR:    cout << "Error opening \"" << argv[1] << "\"\n";
  57.                                     break;
  58.  
  59.             case DOS_READ_ERROR:    cout << "Error reading \"" << argv[1] << "\"\n";
  60.                                     break;
  61.         }
  62.  
  63.         delete db;
  64.         exit(1);
  65.     }
  66.  
  67.     if(db->goTop() < 0)
  68.     {
  69.         cout << "\n(** !! goTop() failed **)\n";
  70.         delete db;
  71.         exit(1);
  72.     }
  73.  
  74.     while(TRUE)
  75.     {
  76.         *command = 0;
  77.  
  78.         cout << ".";
  79.         cin >> command;
  80.  
  81.         if(!*command) break;
  82.  
  83.         if(*command == '\r') continue;
  84.  
  85.         if(strncmp(command,"top",3) == 0)
  86.         {
  87.             if(db->goTop() < 0)
  88.             {
  89.                 cout << "\n(** !! goTop() failed with " << y << " **)\n";
  90.                 delete db;
  91.                 exit(1);
  92.             }
  93.             cout << "1\n";
  94.             continue;
  95.         }
  96.  
  97.         if(strncmp(command,"bot",3) == 0)
  98.         {
  99.             if(db->goBottom() < 0)
  100.             {
  101.                 cout << "\n(** !! goBottom() failed **)\n";
  102.                 delete db;
  103.                 exit(1);
  104.             }
  105.             cout << db->lastRecord() << "\n";
  106.             continue;
  107.         }
  108.  
  109.         if(strncmp(command,"lis",3) == 0)
  110.         {
  111.             db->printDBFields();
  112.             continue;
  113.         }
  114.  
  115.         if(strncmp(command,"ski",3) == 0)
  116.         {
  117.             db->skip();
  118.             if(db->eof())
  119.                 cout << "EOF\n";
  120.             else
  121.                 cout << db->currRecord() << "\n";
  122.             continue;
  123.         }
  124.  
  125.         if(strncmp(command,"str",3) == 0)
  126.         {
  127.             db->listInfo();
  128.             continue;
  129.         }
  130.  
  131.         if(strncmp(command,"loc",3) == 0)
  132.         {
  133.             if(!db->rLock())
  134.                 cout << "Unable to lock record (network error #" << db->getNetErr() << ")\n";
  135.             continue;
  136.         }
  137.  
  138.         if(strncmp(command,"unl",3) == 0)
  139.         {
  140.             if(!db->rUnLock())
  141.                 cout << "Unable to unlock record (network error #" << db->getNetErr() << ")\n";
  142.  
  143.             continue;
  144.         }
  145.  
  146.         if(strcmp(command,"quit") == 0 || strcmp(command,"exit") == 0) break;
  147.     }
  148.  
  149.     delete db;          // initiate the destructor to shut it down.
  150. }
  151.  
  152.  
  153. ---------------------------- end CBTEST.CPP ------------------------------
  154.  
  155. -- 
  156. Bob Hood    thor@arrakis.denver.co.us     H: 303-980-8392  W: 303-632-2180
  157. ---------------------------------------------------------------------------
  158. When people are free to do as they please, they usually imitate each other.
  159.