Code Base 4



April 01, 1990
URL:http://www.drdobbs.com/code-base-4/184402140

April 1990/Code Base 4


The author is a consulting dBase and Clipper programmer. He holds a bachelor's degree in computer science from Central New England College of Technology in Worcester, Mass. He can be contacted at 253 Main St., Cherry Valley, MA 01611 (508) 892-3351.

Code Base 4 from Sequiter Software, Inc., is a set of C routines which allow you to access dBase III+ and IV files and perform screen I/O similar to dBaseIII+. Code Base 4 includes support for dBase .NDX index files, Clipper .NTX files, memo fields, and networked applications. The new dBaseIV .MDX (multiple index) files are not yet supported. Code Base 4 also adds some new levels of functionality with special routines for windows, menus, and memory handling.

Code Base 4 supports dBase/Clipper functionality with 12 categories of routines:

The conversion routines convert data from one format to another. For example, c4dt_dbf() converts Julian dates from the internal double representation to a string formatted CCYYMMDD (century, year, month and day).

The database routines are the main meat of the Code Base 4 package. They allow C programmers to access and store information in the well-established dBase .DBF file format and include C function equivalents of many dBase commands. Due to the more stringent nature of compiled C programming as opposed to the dBase interpretive environment, some differences exist. Table 1 compares dBase commands to their Code Base 4 function counterparts.

Expression And Indexes

With the dBase LINK_DEST 125 command, one may use any valid dBase expression to interactively build an index. For example, to create an index for an accounts receivable file based on invoices sorted by invoice date, you could use the following command:

INDEX ON STR(YEAR(invc_date))+;  STR(MONTH(invc_date))+STR(DAY(invc_date)); TO INVOICE
The STR(YEAR(invc_date.... portion is an "index expression". dBase evaluates this expression from left to right at runtime, and builds an .NDX file based on the expression. Code Base 4 uses an internal expression parser similar to dBase's. Several of the expression functions are available to advanced programmers who might wish to build an SQL-like front end to their application.

The field routines access individual fields and information pertaining to the fields (e.g., their name, length, and data type).

The get routines form the basis for data entry. The get routines arrange field data entry blocks and control field-to-field navigation within that block. As with dBase, you can control the get field in various ways, through pictures and validation clauses. Unlike dBase, Code Base 4 also allows you to access the individual attributes of each get field, allowing each Code Base 4 field to have its own color, brightness, or other attribute setting.

Programmers with strong memory management background can use the Code Base 4 memory handling routines to optimize their applications memory usage. Routines are included to allocate, reallocate, and free memory from the internal Code Base 4 structures.

Index files are used to access data in sorted order. With Code Base 4, either dBase .NDX files or Clipper .NTX files can be used. Like dBase and Clipper, Code Base 4 automatically updates all open index files when a record is written. However, with Code Base 4 you can use lower-level routines to access and update the index files directly.

The memo routines access dBase variable length memo fields (pointers to a separate text file containing free format text).

Unfortunately, Code Base 4 doesn't provide an editor for memo fields. A small Wordstar-compatible editor window function should have been included in the package, with definable screen coordinates. Nantucket's Clipper provides a MEMOEDIT() function which takes screen coordinates as its parameters, and allows you to edit memo fields in a word-wrapping window.

The menuing routines include pulldown, popup, vertical, horizontal, and Lotus 1-2-3 style menus.

The utility routines provide some low-level functions for parsing and validating file names, sorting arrays, and locking and unlocking regions of a shared file.

The windowing routines display and manipulate regions of the I/O screen. The windowing routines form the basis for the menuing routines.

The extended routines support some of dBaseIII and dBaseIV's extended functions, including record filtering (a subset view of a file based on some selection criteria), dBase relations (conditions which synchronize the movement of record pointers in separate files), an edit function (interactively change records), a record listing function, and an insertion function (adds blank records at any point).

Code Base 4 comes with complete source code and conditional compilation switches for Clipper .NTX compatibility, no screen management, OS/2 support, Turbo C compatibility and Microsoft Windows support. A batch file is supplied for performing customized compilations of the library.

dBase programs ported to Code Base 4 should be faster than the interpreted dBase original and smaller than a version compiled by Clipper. The Clipper (t) compiler from Nantucket Software speeds up program execution greatly, but due to library overhead, Clipper applications have a minimum size of 150K. Complete applications are typically about 300-350K. This makes it difficult to run a Clipper program with many TSRs loaded or in a multitasking environment such as DoubleDos. With Code Base 4, the linker only links in exactly what it needs from the library, so the application is much smaller.

Code Base 4 assumes the user has a lot of C and dBase experience and a good command of C pointers, memory allocation, and structures. Beginning C programmers may quickly find themselves lost. The package makes heavy use of linked lists to model database, field, window, and menu structures. Code Base 4 is primarily a tool for the programmer who has mastered C and dBase and wants to transcend the limits of dBase and Compiled dBase (Clipper, Quicksilver).

The wire-bound, 200-page Code Base 4 manual, while comprehensive, has no tutorial or examples section. Each chapter is broken down into a functional area of the Code Base 4 library, and each library function is documented for that section. Some function descriptions have small source code examples; others do not. Several sample programs are supplied on diskette. The samples are well written, and illustrate examples of how to build menus, windows, and database applications. I liked the manual's organization but often found the function descriptions a little thin. A front-end tutorial section with plenty of examples would help this manual greatly.

Technical support is available by phone.

Overall, Code Base 4 does the job for which it is intended: it brings a dBase-like programming environment to C, and allows you to share data between dBase and C programs. It does have some limitations. Using an external editor to access dBase memo fields is a little awkward.

I have worked with several other dBase C libraries. APEX ADL from Apex Software offers similar support for dBase file and index creation and access, but doesn't include any menuing, windowing, or get functions.

I would recommend Codeview4 to any programming shop that needs to transcend the limits of dBaseIII+ and Clipper. Code Base 4 can address speed, memory requirements, or specialized dBase compatible applications (such as a memory resident TSR). For straightforward applications development, dBase and Clipper are still pretty powerful programming environments.

The MS-DOS version is listed at $295 and the UNIX version at $495. For more information contact Sequiter Software Inc., P.O. Box 5659, Station L, Edmonton, Alberta T6C 4G1 (403) 439 8171; FAX (403) 433-7460.

Listing 1

April 1990/Code Base 4/Listing 1

Listing 1 test.c

#include <d4base.h>

#define SAFETY_ON 1  /* d4create will return -1 if database already exists.. */
#define SAFETY_OFF 0 /* d4create will overwrite database if it exists... */


/* Declare Field Structure for database */

static FIELD FIELDS[] =
{
   /* Field Name,    Type,  Width,  Dec,    Offset */
     {"FIRST_NAME",   'C',     25,      0,      0   }, /* Char 25 */
     {"LAST_NAME",    'C',     25,      0,      0   }, /* Char 25 */
     {"COMPANY",      'C',     30,      0,      0   }, /* Char 30 */
     {"TELEPHONE",    'C',     12,      0,      0   }, /* Char 12 */
     {"LAST_SALE",    'N',     12,      2,      0   }, /* Numeric */
     {"LAST_DATE",    'D',      8,      0,      0   }, /* Date    */
     {"GOOD_CUST",    'L',      1,      0,      0   }  /* Logical */
} ;

int create_name( void );  /* Prototype for CUSTOMERS.DBF creation function */

main()
{
   int rc;             /* Return Code */
   rc = create_name();
   printf("\n rc return code was %d",rc);
   return;
}

int create_name( void )
{
   int rc;           /* Return Code */

   rc = d4create("CUSTOMER.DBF",7,FIELDS,SAFETY_OFF);
   return rc;
}

April 1990/Code Base 4/Table 1

Table 1 Dbase Commands & Their Codebase4 Equivalents

Dbase             Codebase4
Command/Function  Function       Description
--------------------------------------------------------------
go bottom         d4bottom()     Go to last record
go top            d4top()        Go to first record
use               d4close()      Close individual .DBF file
close all         d4close_all()  Close all open database files
create            d4create()     Create a new .DBF File
delete            d4delete()     Mark a record for deletion
deleted()         d4deleted()    Return TRUE if record deleted
go <record#>      d4go()         Go to a specific record #
rlock()/flock()   d4lock()       Lock a portion or all of file
pack              d4pack()       Remove deleted records
recall            d4recall()     Undelete marked records
reccount()        d4reccount()   # of records in file
recno()           d4recno()      Current record number
seek "key-val"    d4seek()       Look up record in index key
select            d4select()     Make database area current
skip <#records>   d4skip()       Move record pointer #records
unlock            d4unlock()     Unlock File/Record
use <Filename>    d4use()        Open a database file
replace           d4write()      Update database record
append blank      d4write(0)     Append a blank record
zap               d4zap()        Delete all records & pack

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.