home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:13463 comp.lang.c++:13477
- Newsgroups: comp.lang.c,comp.lang.c++
- Path: sparky!uunet!mnemosyne.cs.du.edu!arrakis!thor
- From: thor@arrakis.denver.co.us (Robert B. Hood)
- Subject: cBASE - Part 3 of 4
- Message-ID: <1992Sep10.134452.8617@arrakis.denver.co.us>
- Summary: A dBASE III+ Class in C++
- Reply-To: thor@arrakis.denver.co.us
- Organization: Bob's Programming Paradise, Lakewood, CO, USA
- Date: Thu, 10 Sep 1992 13:44:52 GMT
- Lines: 146
-
- --------------------------- CBTEST.CPP ----------------------------
- // CBTEST - A program to test the dBASE III+ C++ class
- // Copyright (C) 1992 Bob Hood
- //
- // Author : Bob Hood (thor@arrakis.denver.co.us)
- // Last Update : 08.01.92
- // Header Files: cBASE.HPP
- // Comments : Class is still under construction, so use at your own risk.
- //
- // You are free to copy and distribute this code as long as
- // you do not charge a fee for it, and the Copyright notice
- // above remains intact.
-
- #include <stdio.h>
- #include <iostream.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <io.h>
- #include <alloc.h>
- #include <string.h>
- #include <mem.h>
-
- #include "cbase.hpp"
-
- void main(int argc,char *argv[])
- {
- int x,y,z;
- char command[80];
- dBASE *db; // dBASE object
-
- if(argc < 2)
- {
- cout << "Missing database name.\n";
- exit(1);
- }
-
- db = new dBASE; // create an arbritrary dBASE object
-
- if((x = db->activate(argv[1],NULL)) != NO_PROBLEM)
- {
- switch(x)
- {
- case DOS_OPEN_ERROR: cout << "Error opening \"" << argv[1] << "\"\n";
- break;
-
- case DOS_READ_ERROR: cout << "Error reading \"" << argv[1] << "\"\n";
- break;
- }
-
- delete db;
- exit(1);
- }
-
- if(db->goTop() < 0)
- {
- cout << "\n(** !! goTop() failed **)\n";
- delete db;
- exit(1);
- }
-
- while(TRUE)
- {
- *command = 0;
-
- cout << ".";
- cin >> command;
-
- if(!*command) break;
-
- if(*command == '\r') continue;
-
- if(strncmp(command,"top",3) == 0)
- {
- if(db->goTop() < 0)
- {
- cout << "\n(** !! goTop() failed with " << y << " **)\n";
- delete db;
- exit(1);
- }
- cout << "1\n";
- continue;
- }
-
- if(strncmp(command,"bot",3) == 0)
- {
- if(db->goBottom() < 0)
- {
- cout << "\n(** !! goBottom() failed **)\n";
- delete db;
- exit(1);
- }
- cout << db->lastRecord() << "\n";
- continue;
- }
-
- if(strncmp(command,"lis",3) == 0)
- {
- db->printDBFields();
- continue;
- }
-
- if(strncmp(command,"ski",3) == 0)
- {
- db->skip();
- if(db->eof())
- cout << "EOF\n";
- else
- cout << db->currRecord() << "\n";
- continue;
- }
-
- if(strncmp(command,"str",3) == 0)
- {
- db->listInfo();
- continue;
- }
-
- if(strncmp(command,"loc",3) == 0)
- {
- if(!db->rLock())
- cout << "Unable to lock record (network error #" << db->getNetErr() << ")\n";
- continue;
- }
-
- if(strncmp(command,"unl",3) == 0)
- {
- if(!db->rUnLock())
- cout << "Unable to unlock record (network error #" << db->getNetErr() << ")\n";
-
- continue;
- }
-
- if(strcmp(command,"quit") == 0 || strcmp(command,"exit") == 0) break;
- }
-
- delete db; // initiate the destructor to shut it down.
- }
-
-
- ---------------------------- end CBTEST.CPP ------------------------------
-
- --
- Bob Hood thor@arrakis.denver.co.us H: 303-980-8392 W: 303-632-2180
- ---------------------------------------------------------------------------
- When people are free to do as they please, they usually imitate each other.
-