Difference between revisions of "Library dblsamp"

From Recital Documentation Wiki
Jump to: navigation, search
 
(31 intermediate revisions by one user not shown)
Line 1: Line 1:
// {{ todo: tidy up}}
 
 
 
The following program is written in 'C' as an example program using the RECITAL/Library functions. This file is stored in the SDK dbl sub-directory and is called "dblsamp.c".
 
The following program is written in 'C' as an example program using the RECITAL/Library functions. This file is stored in the SDK dbl sub-directory and is called "dblsamp.c".
  
 
<code lang="c">
 
<code lang="c">
/*#=============================================================
+
/*#============================================================================
 
  *# Copyright (C) 1988-2009 Recital Corporation Inc.
 
  *# Copyright (C) 1988-2009 Recital Corporation Inc.
  *# As an unpublished licensed proprietary work.
+
  *# As an unpublished licenced proprietary work.
 
  *# All rights reserved worldwide.
 
  *# All rights reserved worldwide.
 
  *#
 
  *#
Line 13: Line 11:
 
  *# copyright notice is included.
 
  *# copyright notice is included.
 
  *#
 
  *#
  #==============================================================
+
  *#============================================================================
 +
*
 +
*      MODULE          : dblsamp.c
 
  *
 
  *
  *MODULE                : dblsamp.c
+
  *     PURPOSE        : Recital DataBase Library sample program.
 
  *
 
  *
  *PURPOSE              : Recital Database Library sample program.
+
  *     AUTHOR          : RECITAL CORPORATION
 
  *
 
  *
  *AUTHOR                : RECITAL CORPORATION
+
  *     DATE            : 26 Jan 91
 +
*      REVISION        : 29 Oct 91
 +
*      REVISION        : 09 May 95
 
  *
 
  *
  *=============================================================*/
+
  *==========================================================================*/
  
 
#include <stdio.h>
 
#include <stdio.h>
#include "dbl.h"               /* Recital/Library include file         */
+
#include <stdlib.h>
#include "dblproto.h"           /* Recital/Library prototype file       */
+
#include <string.h>
 +
#include <sys/types.h>
 +
#include <unistd.h>
 +
#include "dbl.h"                       /* Recital/Library include file */
 +
#include "dblproto.h"                   /* Recital/Library prototype file */
  
extern int g_disable_txcount;
 
  
/*-------------------------------------------------------------------------------------------------*/
+
extern int g_disable_iostats;
/* Table structure for db to be constructed.                                            */
+
/* Structure dBFIELD defined in dbl.h                                          */
+
/*-------------------------------------------------------------------------------------------------*/
+
static dBFIELD fields[7]
+
=
+
  {
+
    "VESSEL", 'C', 18, 0, 0,
+
    "LAT", 'N', 4 1, 0,
+
    "LONG", 'N', 4, 1, 0,
+
    "AMOUNT", 'N', 10, 0, 0,
+
    "DATE", 'D', 8, 0, 0,
+
    "FLAG", 'C', 9, 0, 0,
+
    "MEMO", 'M', 4, 0, 0
+
  };
+
  
/*-------------------------------------------------------------------------------------------------*/
+
/*----------------------------------------------*/
/* Static Error Handling procedure.                                                     */
+
/* Table structure for db to be constructed. */
/*-------------------------------------------------------------------------------------------------*/
+
/* Structure dBFIELD defined in dbl.h.          */
static int
+
/*----------------------------------------------*/
errorproc();
+
static dBFIELD fields[7] = {
 +
        "VESSEL",      'C',    18,    0, 0,
 +
        "LAT",          'N',    4,      1, 0,
 +
        "LONG",        'N',    4,      1, 0,
 +
        "AMOUNT",      'N',    10,    0, 0,
 +
        "DATE",        'D',    8,      0, 0,
 +
        "FLAG",        'C',    9,      0, 0,
 +
        "MEMO",        'M',    sizeof(MEMO),      0, 0
 +
};
  
/*-------------------------------------------------------------------------------------------------*/
+
#define DB_RECORD_SIZE 100
/* Table records to add.                                                                */
+
/*-------------------------------------------------------------------------------------------------*/
+
static char
+
    *text_table[] =
+
      {
+
          "Santa Margarita        80.027.5        7000000 95/01/01        Spanish ",
+
          "Santa Rosa            81.824.8        30000000        32/01/01        Spanish  ",
+
          "Unknown galleon        83.123.0        0              15/01/01        Spanish",
+
          "Jessie                97.127.4        100000  75/01/01        U.S.    ",
+
          "Lea                    96.227.8        1000000 80/01/01        U.S.    ",
+
          "S.J. Lee              96.926.9        200000  75/01/01        U.S.    ",
+
          "Genovase              78.418.4        1850000 30/01/01        Spanish  ",
+
          "Unknown Vessel 77.517.9        0              75/01/01        U.S.    " };
+
  
/*-------------------------------------------------------------------------------------------------*/
+
/*----------------------------------------------*/
/* Main program entry point.                                                           */
+
/* Static Error Handling procedure.            */
/*-------------------------------------------------------------------------------------------------*/
+
/*----------------------------------------------*/
 +
static void errorproc(
 +
char    *func,
 +
char    *str,
 +
int    rc);
 +
 
 +
/*----------------------------------------------*/
 +
/* Table records to add.                     */
 +
/*----------------------------------------------*/
 +
static char *text_table[] =  {
 +
    "Santa Margarita  80.027.5  700000095/01/01Spanish  ",
 +
    "Santa Rosa        81.824.8  3000000032/01/01Spanish  ",
 +
    "Unknown galleon  83.123.0        015/01/01Spanish  ",
 +
    "Jessie            97.127.4    10000075/01/01U.S.    ",
 +
    "Lea              96.227.8  100000080/01/01U.S.    ",
 +
    "S.J. Lee          96.926.9    20000075/01/01U.S.    ",
 +
    "Genovase          78.418.4  185000030/01/01Spanish  ",
 +
    "Unknown Vessel    77.517.9        075/01/01U.S.    "
 +
};
 +
 
 +
 
 +
/*---------------------------*/
 +
/* Main program entry point. */
 +
/*---------------------------*/
 
main()
 
main()
 
{
 
{
  int rc; /* Return Code for error handling       */
+
        int     rc;                     /* Return Code for error handling */
  char *dbf; /* File descriptor for table           */
+
        char   *dbf;                   /* File descriptor for table   */
  char *dbx; /* File descriptor for tagged index     */
+
        char   *dbx;                   /* File descriptor for tagged index   */
  char *ndx; /* File descriptor for index           */
+
        char   *ndx;                   /* File descriptor for index       */
  char *dbt; /* File descriptor for memo file       */
+
        char   *dbt;                   /* File descriptor for memo file   */
  char record[58]; /* Array of char for records           */
+
        char   record[DB_RECORD_SIZE]; /* Array of char for records       */
  char keytype; /* Variable for varying keytype */
+
        char   keytype;               /* Variable for varying keytype   */
  char key[21]; /* Storage location for keys           */
+
        char   key[21];               /* Storage location for keys       */
  char tagname[21]; /* Storage location for tag name       */
+
        char   tagname[21];           /* Storage location for tag name */
  char keyexpr[512]; /* Storage location for key expr       */
+
        char   keyexpr[512];           /* Storage location for key expr   */
  char forexpr[512]; /* Storage location for for expr       */
+
        char   forexpr[512];           /* Storage location for for expr   */
  int kexprlen; /* The key expression length           */
+
        int     kexprlen;               /* The key expression length       */
  int keylen; /* The key length                       */
+
        int     keylen;                 /* The key length                 */
  dBFIELD dbfields[128]; /* Storage location for field names     */
+
        dBFIELD dbfields[MAX_RECORD_FIELDS];         /* Storage location for fld names */
  FLDNUM fieldcount; /* Number of fields to create           */
+
        FLDNUM fieldcount;             /* Number of fields to create     */
  int fldpos[128]; /* Fields position buffer               */
+
        int     fldpos[MAX_RECORD_FIELDS];           /* Fields position buffer         */
  char flddes[128][26]; /* Fields description buffer           */
+
        char   flddes[MAX_RECORD_FIELDS][26];       /* Fields description buffer       */
  char tmpbuf[81]; /* Temporary storage buffer             */
+
        char   tmpbuf[81];             /* Temporary storage buffer       */
  char fldbuf[128][256]; /* Field buffer (recin()/out())         */
+
        char   fldbuf[MAX_RECORD_FIELDS][256];       /* Field buffer (recin()/out())   */
  char nextkey[10][20]; /* Key buffers (dbnkey())               */
+
        char   nextkey[10][20];       /* Key buffers (dbnkey())         */
  char status; /* Deleted record flag                 */
+
        char   status;                 /* Deleted record flag             */
  long recno; /* Table record variable               */
+
        long   recno;                 /* Table record variable       */
  long rec_no[10]; /* Record number array (dbnkey())       */
+
        long   rec_no[10];             /* Record number array (dbnkey()) */
  long db_size; /* Size of table variable               */
+
        long   db_size;               /* Size of table variable       */
  int reclen; /* Table record length variable */
+
        int     reclen;                 /* Table record length variable */
  char month; /* Month variable                       */
+
        char   month;                 /* Month variable                 */
  char day; /* Day variable                 */
+
        char   day;                   /* Day variable                   */
  char year; /* Year variable                       */
+
        char   year;                   /* Year variable                   */
  FLDNUM nofields; /* Number of table fields variable      */
+
        FLDNUM nofields;               /* Number of table fields var  */
  int i; /* Loop control variable               */
+
        int     i;             /* Loop control variable           */
  double n; /* Double numeric variable             */
+
        double n;                     /* Double numeric variable         */
  int keyunique; /* Boolean for unique tag key           */
+
int keyunique; /* Boolean for unqiue tag key */
  int keydescend; /* Boolean for descending tag key       */
+
int keydescend; /* Boolean for descending tag key */
  int notags; /* number of tags in a dbx file */
+
int notags; /* number of tags in a dbx file */
  
  /*----------------------------------------------------------------------------------------*/
 
  /* Perform operational Library environment functions.                  */
 
  /*----------------------------------------------------------------------------------------*/
 
  
  /*----------------------------------------------------------------------------------------*/
+
        /*----------------------------------------------------*/
  /* DBDCACHE() - this example allocates a 100 record caching area        */
+
        /* Perform operational Library environment functions. */
  /*----------------------------------------------------------------------------------------*/
+
        /*----------------------------------------------------*/
  rc = dbdcache(100);
+
  errorproc("dbdcache()", "table cache specified.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------------------------------*/
  /* DBICACHE() - this example allocates 51200 bytes for index caching   */
+
        /* DBDCACHE() - this example allocates a 100 record caching area */
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------------------------------*/
  rc = dbicache(100);
+
        rc = dbdcache(100);
  errorproc("dbicache()", "index cache specified.", rc);
+
        errorproc("dbdcache()","table cache specified.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------------*/
  /* DBFILEMODE() - shared, read write access                            */
+
        /* DBICACHE() - this example allocates 51200 bytes for index caching */
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------------*/
  rc = dbfilemode(1, 0);
+
        rc = dbicache(100);
  errorproc("dbfilemode()", "file mode specified.", rc);
+
        errorproc("dbicache()", "index cache specified.",rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------*/
  /* DBSET() - Set exact index match to true                                      */
+
        /* DBFILEMODE() - shared, read write access */
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------*/
  rc = dbset("EXACT", 1);
+
        rc = dbfilemode(1,0);
  errorproc("dbset()", "filemode specified.", rc);
+
        errorproc("dbfilemode()", "filemode specified.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------*/
  /* Perform basic table functions.                                              */
+
        /* DBSET() - Set exact index match to true  */
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------*/
  fieldcount = 7; /* Number of Fields    */
+
        rc = dbset("EXACT", 1);
 +
        errorproc("dbset()", "filemode specified.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
        /*--------------------------------*/
  /* DBCREAT() - this example creates a table according to the 'dBFIELD'  */
+
        /* Perform basic table functions. */
  /* array fields.                                                                       */
+
        /*--------------------------------*/
  /*----------------------------------------------------------------------------------------*/
+
        fieldcount = 7;                         /* Number of Fields          */
  rc = dbcreat("shipwreck.dbf", fieldcount, fields);
+
  errorproc("dbcreat()", "database created.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------------------------------------*/
  /* DBCREATX() - Enables the addition of table field descriptions.               */
+
        /* DBCREAT() - this example creates a table according to the */
  /*----------------------------------------------------------------------------------------*/
+
        /*            'dBFIELD' array fields.                       */
  strcpy(flddes[0], "The vessel's name.");
+
/*-----------------------------------------------------------*/
  strcpy(flddes[1], "The latitude.");
+
        rc = dbcreat("shipwreck.dbf",fieldcount, fields);
  strcpy(flddes[2], "The longitude.");
+
        errorproc("dbcreat()","datebase created.", rc);
  strcpy(flddes[3], "The value.");
+
  strcpy(flddes[4], "The date.");
+
  strcpy(flddes[5], "The vessel's flag.");
+
  strcpy(flddes[6], "Notes.");
+
  
  rc = dbcreatx("shipwreck.dbf", fieldcount, fields, flddes);
+
/*----------------------------------------------------------------*/
 +
        /* DBCREATX() - Enables the addition of table field descriptions. */
 +
/*----------------------------------------------------------------*/
 +
        strcpy(flddes[0], "The vessel's name.");
 +
        strcpy(flddes[1], "The latitude.");
 +
        strcpy(flddes[2], "The longitude.");
 +
        strcpy(flddes[3], "The value.");
 +
        strcpy(flddes[4], "The date.");
 +
        strcpy(flddes[5], "The vessel's flag.");
 +
        strcpy(flddes[6], "Notes.");
  
  /*----------------------------------------------------------------------------------------*/
+
        rc = dbcreatx("shipwreck.dbf", fieldcount, fields, flddes);
  /* DBOPEN() - example opens table 'shipwreck.dbf' returning the table  */
+
  /* file descriptor (dbf) used in upcoming functions                            */
+
  /*----------------------------------------------------------------------------------------*/
+
  rc = dbopen("shipwreck.dbf", &dbf);
+
  errorproc("dbopen()", "table opened.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------------------*/
  /* DBGETF() - obtain table information on the table referenced by the   */
+
        /* DBOPEN() - example opens table 'shipwreck.dbf' returning the     */
  /* 'dbf' file descriptor.                                                              */
+
        /*           table file descriptor (dbf) used in upcoming funcs  */
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------------------*/
  rc = dbgetf(dbf, &reclen, &month, &day, &year, &nofields, dbfields);
+
        rc = dbopen("shipwreck.dbf", &dbf);
  errorproc("dbgetf()", "information retrieved.", rc);
+
        errorproc("dbopen()","table opened.", rc);
  printf("\t\tRecord length in bytes: %d\n", reclen);
+
  printf("\t\tCreation date: \t\t%d/%d/%d\n", month, day, year);
+
  printf("\t\tNumber of fields: \t%d\n", nofields);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------*/
  /* DBGETFX() - obtain extended table information including the numeric  */
+
        /* DBGETF() - obtain table information on the table referenced */
  /* field location array (fldpos) and the field descriptions (flddes).           */
+
        /*           by the 'dbf' file descriptor.                   */
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------*/
  rc = dbgetfx(dbf, &reclen, &month, &day, &year, &nofields, dbfields, fldpos,
+
        rc = dbgetf(dbf, &reclen, &month, &day,
      flddes);
+
                        &year, &nofields, dbfields);
  errorproc("dbgetfx()", "extra information retrieved.", rc);
+
        errorproc("dbgetf()","information retrieved.", rc);
  printf("\t\tLocation of fields in buffer: \t%d,%d,%d,%d,%d,%d\n", fldpos[1],
+
        printf("\t\tRecord length in bytes: %d\n", reclen);
      fldpos[2], fldpos[3], fldpos[4], fldpos[5], fldpos[6]);
+
        printf("\t\tCreation date: \t\t%d/%d/%d\n",month,day,year);
 +
        printf("\t\tNumber of fields: \t%d\n", nofields);
  
  /*----------------------------------------------------------------------------------------*/
 
  /* DBLOCKF() - locks the table for the additions that follow.          */
 
  /* Synonymous with DBTLOCKF(), which tests the lock                    */
 
  /*----------------------------------------------------------------------------------------*/
 
  rc = dblockf(dbf);
 
  if (rc == SUCCESS)
 
    {
 
      printf("Function: \tdblockf() \tfile locked successfully.\n");
 
    }
 
  else
 
    {
 
      printf("Lock Failed. tError: %d\n", rc);
 
    }
 
  
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------------------------------------------*/
  /* DBCLOSE() - close the active table                                  */
+
        /* DBGETFX() - obtain extended table information including the     */
  /*----------------------------------------------------------------------------------------*/
+
        /*            numeric field location array (fldpos) and the field */
  rc = dbclose(dbf);
+
        /*            descriptions (flddes).                              */
  errorproc("dbclose()", "table closed.", rc);
+
/*-----------------------------------------------------------------*/
 +
        rc = dbgetfx(dbf, &reclen, &month, &day, &year,
 +
                    &nofields, dbfields, fldpos, flddes);
 +
        errorproc("dbgetfx()", "extra information retrieved.", rc);
 +
        printf("\t\tLocation of fields in buffer: \t%d,%d,%d,%d,%d,%d\n",
 +
            fldpos[1],fldpos[2],fldpos[3],fldpos[4],fldpos[5],fldpos[6]);
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------*/
  /* Exclusive read write access of the table is required to create or delete    */
+
        /* DBLOCKF() - locks the table for following additions.        */
  /* tags.                                                                                */
+
        /*             Synonomous with DBTLOCKF() which tests the lock */
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------*/
  rc = dbfilemode(0, 0);
+
        rc = dblockf(dbf);
  rc = dbopen("shipwreck.dbf", &dbf);
+
        if ( rc == SUCCESS ) {
  errorproc("dbopen()", "table opened in exclusive mode.", rc);
+
            printf("Function: \tdblockf() \tfile locked successfully.\n");
 +
        } else {
 +
            printf("Lock Failed. \tError: %d\n",rc);
 +
}
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------*/
  /* Perform basic tagged index functions.                                        */
+
        /* DBCLOSE() - close the active table */
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------*/
 +
rc = dbclose(dbf);
 +
        errorproc("dbclose()", "table closed.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------*/
  /* DBXCREATE() - in this example creates an tag on field VESSEL */
+
        /* Exclusive, read write access of the table is */
  /*----------------------------------------------------------------------------------------*/
+
/* required to create or delete tags.         */
  rc = dbxcreate(dbf, fields[0].fieldnm, /* "VESSEL",   */
+
/*----------------------------------------------*/
  &dbx, fields[0].fieldnm, /* "VESSEL",    */
+
        rc = dbfilemode(0,0);
  NULL, 0, 0);
+
        rc = dbopen("shipwreck.dbf", &dbf);
  errorproc("dbxcreate()", "tag created", rc);
+
        errorproc("dbopen()","table opened in exclusive mode.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
        /*---------------------------------------*/
  /* DBXCREATE() - in this example creates an tag on field FLAG          */
+
        /* Perform basic tagged index functions. */
  /*----------------------------------------------------------------------------------------*/
+
        /*---------------------------------------*/
  rc = dbxcreate(dbf, fields[5].fieldnm, /* "FLAG",      */
+
  &dbx, fields[5].fieldnm, /* "FLAG",      */
+
  NULL, 0, 0);
+
  errorproc("dbxcreate()", "tag created", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
 
  /* DBXNOTAGS() - obtains the number of tagged indexes                  */
 
  /*----------------------------------------------------------------------------------------*/
 
  rc = dbxnotags(dbx, &notags);
 
  errorproc("dbxnotags()", "tagged index count obtained.", rc);
 
  printf("\t        Key count: \t%d\n", notags);
 
  
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------------------*/
  /* DBXKEXPR() - obtains tagged index information                        */
+
        /* DBXCREATE() - in this example creates an tag on field VESSEL */
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------------------*/
  for (i = 1; i <= notags; i++)
+
        rc = dbxcreate( dbf,
    {
+
fields[0].fieldnm, /* "VESSEL", */
      rc = dbxkexpr(dbx, &i, tagname, &keytype, keyexpr, forexpr, &kexprlen,
+
&dbx,
          &keylen, &keyunique, &keydescend);
+
fields[0].fieldnm, /* "VESSEL", */
      errorproc("dbxkexpr()", "key information retrieved.", rc);
+
NULL,
      printf("\t        Key number: \t%d\n", i);
+
0,
      printf("\t        Key name: \t%s\n", tagname);
+
0);
      printf("\t        Key type: \t%c\n", keytype);
+
         errorproc("dbxcreate()","tag created", rc);
      printf("\t         Key expression: %s\n", keyexpr);
+
      printf("\t        Key length: %d  Expression length: %d\n", kexprlen,
+
          keylen);
+
      printf("\t        For expression: %s\n", forexpr);
+
      printf("\t        Key unique: \t%s\n", keyunique ? "Yes" : "No");
+
      printf("\t        Key descending: \t%s\n", keydescend ? "Yes" : "No");
+
    }
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------------------------*/
  /* DBXDROPTAGS() - Drop the specified tag                               */
+
        /* DBXCREATE() - in this example creates an tag on field FLAG */
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------------------------*/
  rc = dbxdroptag(dbx, fields[5].fieldnm);
+
        rc = dbxcreate( dbf,
  errorproc("dbxdroptag()", "tagged index 'FLAG' dropped.", rc);
+
fields[5].fieldnm, /* "FLAG",  */
 +
&dbx,
 +
fields[5].fieldnm, /* "FLAG",  */
 +
NULL,
 +
0,
 +
0);
 +
        errorproc("dbxcreate()","tag created", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------*/
  /* DBXCLOSE() - close the active tagged index                          */
+
        /* DBXNOTAGS() - obtains the number of tagged indexes */
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------*/
  rc = dbxclose(dbx);
+
        rc = dbxnotags(dbx, &notags);
  errorproc("dbxclose()", "tagged index closed.", rc);
+
        errorproc("dbxnotags()","tagged index count obtained.", rc);
 +
        printf("\t        Key count: \t%d\n", notags );
  
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------------------------*/
  /* DBCLOSE() - close the active table                                  */
+
        /* DBXKEXPR() - obtains tagged index information */
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------------------------*/
  rc = dbclose(dbf);
+
for (i = 1; i <= notags; i++) {
  errorproc("dbclose()", "table closed.", rc);
+
            rc = dbxkexpr(dbx,
 +
  &i,
 +
  tagname,
 +
  &keytype,
 +
  keyexpr,
 +
  forexpr,
 +
  &kexprlen,
 +
  &keylen,
 +
  &keyunique,
 +
  &keydescend);
 +
            errorproc("dbxkexpr()", "key information retrieved.", rc);
 +
            printf("\t        Key number: \t%d\n", i );
 +
            printf("\t        Key name: \t%s\n", tagname );
 +
            printf("\t        Key type: \t%c\n", keytype );
 +
            printf("\t        Key expression: %s\n", keyexpr);
 +
            printf("\t        Key length: %d  Expression length: %d\n",
 +
                              kexprlen, keylen);
 +
            printf("\t        For expression: %s\n", forexpr);
 +
            printf("\t        Key unique: \t%s\n", keyunique ? "Yes" : "No" );
 +
            printf("\t        Key descending: \t%s\n", keydescend?"Yes":"No" );
 +
}
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------*/
  /* Reopen the table in shared, read-write access mode                  */
+
        /* DBXDROPTAGS() - Drop the specified tag */
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------*/
  rc = dbfilemode(1, 0);
+
        rc = dbxdroptag(dbx, fields[5].fieldnm);
  rc = dbopen("shipwreck.dbf", &dbf);
+
        errorproc("dbxdroptag()","tagged index 'FLAG' dropped.", rc);
  errorproc("dbopen()", "table opened in shared mode.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------*/
  /* DBXOPEN() - example opens index file 'shipwreck.dbx' returning the   */
+
        /* DBXCLOSE() - close the active tagged index */
  /* tagged index file descriptor (dbx) used in upcoming functions                */
+
/*--------------------------------------------*/
  /*----------------------------------------------------------------------------------------*/
+
        rc = dbxclose(dbx);
  rc = dbxopen(dbf, "shipwreck.dbx", &dbx);
+
        errorproc("dbxclose()", "tagged index closed.", rc);
  errorproc("dbxopen()", "tagged index opened.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------*/
  /* Perform basic index functions.                                              */
+
        /* DBCLOSE() - close the active table */
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------*/
 +
        rc = dbclose(dbf);
 +
        errorproc("dbclose()", "table closed.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------*/
  /* DBICREAT() - in this example creates an index on field VESSEL        */
+
        /* Reopen the table in shared, read-write access mode */
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------*/
  rc = dbicreat("shipwreck.ndx", fields[0].fieldnm, 18, 'C');
+
        rc = dbfilemode(1,0);
  errorproc("dbicreat()", "index created", rc);
+
        rc = dbopen("shipwreck.dbf", &dbf);
 +
        errorproc("dbopen()","table opened in shared mode.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------------------------*/
  /* DBIOPEN() - opens index to active status                                    */
+
        /* DBXOPEN() - example opens tag index 'shipwreck.dbx' returning the  */
  /*----------------------------------------------------------------------------------------*/
+
        /*          taged index file descriptor (dbx) used in upcoming funcs */
  rc = dbiopen("shipwreck.ndx", &ndx);
+
/*--------------------------------------------------------------------*/
  errorproc("dbiopen()", "index opened.", rc);
+
        rc = dbxopen(dbf, "shipwreck.dbx", &dbx);
 +
        errorproc("dbxopen()","tagged index opened.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
        /*--------------------------------*/
  /* DBKEXPR() - obtains index information                                        */
+
        /* Perform basic index functions. */
  /*----------------------------------------------------------------------------------------*/
+
        /*--------------------------------*/
  rc = dbkexpr(ndx, &keytype, keyexpr, &kexprlen, &keylen);
+
  errorproc("dbkexpr()", "key information retrieved.", rc);
+
  printf("\t        Key type: \t%c\n", keytype);
+
  printf("\t        Key expression: %s\n", keyexpr);
+
  printf("\t        Key length: %d  Expression length: %d\n", kexprlen,
+
      keylen);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------------------------------*/
  /* Lock data file                                                              */
+
        /* DBICREAT() - in this example creates an index on field VESSEL */
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------------------------------*/
  rc = dblockf(dbf);
+
        rc = dbicreat( "shipwreck.ndx", fields[0].fieldnm, 18, 'C');
  if (rc == SUCCESS)
+
        errorproc("dbicreat()","index created", rc);
    {
+
      printf("Function: \tdblockf() \tfile locked successfully.\n");
+
    }
+
  else
+
    {
+
      printf("Lock Failed. \tError: %d\n", rc);
+
    }
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------*/
  /* DBLOCKI() - locks the index for following additions                  */
+
        /* DBIOPEN() - opens index to active status */
  /* Synonymous with DBTLOCKI() which tests the lock                      */
+
/*------------------------------------------*/
  /*----------------------------------------------------------------------------------------*/
+
        rc = dbiopen( "shipwreck.ndx", &ndx);
  rc = dblocki(ndx);
+
        errorproc("dbiopen()", "index opened.", rc);
  if (rc == SUCCESS)
+
    {
+
      printf("Function: \tdblocki() \tindex locked successfully.\n");
+
    }
+
  else
+
    {
+
      printf("Lock Failed. tError: %dn", rc);
+
    }
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------*/
  /* Perform basic memo file functions.                                  */
+
        /* DBKEXPR() - obtains index information */
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------*/
 +
        rc = dbkexpr(ndx, &keytype, keyexpr, &kexprlen, &keylen);
 +
        errorproc("dbkexpr()", "key information retrieved.", rc);
 +
        printf("\t        Key type: \t%c\n", keytype );
 +
        printf("\t        Key expression: %s\n", keyexpr);
 +
        printf("\t        Key length: %d  Expression length: %d\n",
 +
                          kexprlen, keylen);
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------*/
  /* DBMCREAT() - creates a table memo file (if one needs creating)      */
+
/* Lock data file */
  /*----------------------------------------------------------------------------------------*/
+
/*----------------*/
  rc = dbmcreat("shipwreck.dbt");
+
rc = dblockf(dbf);
  errorproc("dbmcreat()", "memo file create", rc);
+
        if ( rc == SUCCESS ) {
 +
            printf("Function: \tdblockf() \tfile locked successfully.\n");
 +
        } else {
 +
            printf("Lock Failed. \tError: %d\n",rc);
 +
}
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------*/
  /* DBMOPEN() - opens an associated memo file                            */
+
        /* DBLOCKI() - locks the index for following additions        */
  /*----------------------------------------------------------------------------------------*/
+
        /*            Synonomous with DBTLOCKI() which tests the lock */
  rc = dbmopen("shipwreck.dbt", &dbt);
+
/*-------------------------------------------------------------*/
  errorproc("dbmopen()", "memo file open.", rc);
+
        rc = dblocki(ndx);
 +
        if ( rc == SUCCESS ) {
 +
            printf("Function: \tdblocki() \tindex locked successfully.\n");
 +
        } else {
 +
            printf("Lock Failed. \tError: %d\n",rc);
 +
}
  
  /*----------------------------------------------------------------------------------------*/
+
        /*------------------------------------*/
  /* Perform table input functions.                                               */
+
        /* Perform basic memo file functions. */
  /*----------------------------------------------------------------------------------------*/
+
        /*------------------------------------*/
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------------------*/
  /* DBAPPEND() - appends a record to the end of the active table         */
+
        /* DBMCREAT() - creates a table memo file (if one needs creating) */
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------------------*/
  rc = dbappend(dbf, text_table[0], &recno);
+
        rc = dbmcreat("shipwreck.dbt");
  errorproc("dbappend()", "record appended.", rc);
+
        errorproc("dbmcreat()", "memo file create", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------*/
  /* DBAKEY() - adds a key to the active index after dbappend()          */
+
        /* DBMOPEN() - opens an associated memo file */
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------*/
  rc = dbakey(ndx, "Santa Margarita  ", recno);
+
        rc = dbmopen("shipwreck.dbt", &dbt);
  errorproc("dbakey()", "key added.", rc);
+
        errorproc("dbmopen()", "memo file open.", rc);
  
  /*----------------------------------------------------------------------------------------*/
 
  /* DBXAKEY() - adds a key to the tagged index after dbappend()          */
 
  /* The tagged index file must be lock first                                    */
 
  /*----------------------------------------------------------------------------------------*/
 
  rc = dbxlocki(dbx);
 
  errorproc("dbxlocki()", "tagged index file locked.", rc);
 
  rc = dbxakey(dbx, recno);
 
  errorproc("dbxakey()", "key added.", rc);
 
  rc = dbxunlocki(dbx);
 
  errorproc("dbxunlocki()", "tagged index file unlocked.", rc);
 
  
  /*----------------------------------------------------------------------------------------*/
+
        /*--------------------------------*/
  /* DBFLUSH() - flushes the record cache to disk                        */
+
        /* Perform table input functions. */
  /*----------------------------------------------------------------------------------------*/
+
        /*--------------------------------*/
  rc = dbflush(dbf);
+
  errorproc("dbflush()", "table cache flushed.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------------------*/
  /* DBIFLSH() - flushes the index cache to disk                          */
+
        /* DBAPPEND() - appends a record to the end of the active table */
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------------------*/
  rc = dbiflsh(ndx);
+
        rc = dbappend(dbf, text_table[0], &recno);
  errorproc("dbiflsh()", "index cache flushed.", rc);
+
        errorproc("dbappend()", "record appended.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------------------------*/
  /* DBXFLSH() - flushes the tagged index cache to disk                  */
+
        /* DBAKEY() - adds a key to the active index after dbappend() */
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------------------------*/
  rc = dbxflsh(dbx);
+
        rc = dbakey(ndx,"Santa Margarita  " , recno);
  errorproc("dbxflsh()", "Tagged index cache flushed.", rc);
+
        errorproc("dbakey()", "key added.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------*/
  /* DBGETR() - retrieves a record                                                */
+
        /* DBXAKEY() - adds a key to the tagged index after dbappend() */
  /*----------------------------------------------------------------------------------------*/
+
/*       The tagged index file must be lock first       */
  rc = dbgetr(dbf, (long) 1, record, &status);
+
/*-------------------------------------------------------------*/
  errorproc("dbgetr()", "record retrieved.", rc);
+
        rc = dbxlocki(dbx);
  printf("\t\t%s\n", record);
+
        errorproc("dbxlocki()", "tagged index file locked.", rc);
 +
        rc = dbxakey(dbx,recno);
 +
        errorproc("dbxakey()", "key added.", rc);
 +
        rc = dbxunlocki(dbx);
 +
        errorproc("dbxunlocki()", "tagged index file unlocked.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------*/
  /* DBPUTM() - put the memo information                                  */
+
        /* DBFLUSH() - flushes the record cache to disk */
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------*/
  rc = dbputm(dbt, "128' 30% coral cover.", &record[53]);
+
        rc = dbflush(dbf);
  errorproc("dbputm", "memo placed in buffer", rc);
+
        errorproc("dbflush()", "table cache flushed.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------------*/
  /* DBUPDR() - updates the record in buffer 'record'                            */
+
        /* DBIFLSH() - flushes the index cache to disk */
  /* As of v8.0 this function automatically updates any attached indexes. */
+
/*---------------------------------------------*/
  /*----------------------------------------------------------------------------------------*/
+
        rc = dbiflsh(ndx);
  rc = dbupdr(dbf, (long) 1, record);
+
        errorproc("dbiflsh()", "index cache flushed.", rc);
  errorproc("dbupdr()", "record updated.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------*/
  /* DBGETM() - this example extracts the memo from the record buffer    */
+
        /* DBXFLSH() - flushes the tagged index cache to disk */
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------*/
  rc = dbgetm(dbt, &record[53], tmpbuf, 0);
+
        rc = dbxflsh(dbx);
  errorproc("dbgetm()", "retrieved memo.", rc);
+
        errorproc("dbxflsh()", "Tagged index cache flushed.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------*/
  /* DBUPDM() - Updates the memo field for this record                   */
+
        /* DBGETR() - retrieves a record */
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------*/
  strcat(tmpbuf, " Appending this string to the end of memo...");
+
        rc = dbgetr(dbf, (long)1, record, &status);
  rc = dbupdm(dbt, tmpbuf, &record[53], &record[53]);
+
        errorproc("dbgetr()", "record retreived.", rc);
  errorproc("dbupdm()", "updated memo.", rc);
+
        printf("\t\t%s\n", record);
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------*/
  /* DBPUTRK() - the following example adds a record and index            */
+
        /* DBPUTM() - put the memo information */
  /* to the respective files.                                                    */
+
/*-------------------------------------*/
  /* DBRECOUT() - scatter the record stored in buffer 'record' to a two  */
+
        rc = dbputm(dbt, "128' 30% coral cover.", &record[53]);
  /* dimensional character array 'fldbuf'                                */
+
        errorproc("dbputm", "memo placed in buffer",rc);
  /*----------------------------------------------------------------------------------------*/
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------------------------------------*/
  /* Read in 6 more records                                                      */
+
        /* DBUPDR() - updates the record in buffer 'record'          */
  /*----------------------------------------------------------------------------------------*/
+
/*            As of v8.0 this function automatically updates */
 +
/*            any attached indexes.                          */
 +
/*-----------------------------------------------------------*/
 +
        rc = dbupdr(dbf, (long)1, record);
 +
        errorproc("dbupdr()", "record updated.", rc);
  
  for (i = 1; i <= 6; i++)
+
/*------------------------------------------------------------------*/
    {
+
        /* DBGETM() - this example extracts the memo from the record buffer */
      dbrecout(dbf, dbfields, fldpos, text_table[i], fldbuf);
+
/*------------------------------------------------------------------*/
      rc = dbputrk(dbf, ndx, fldbuf[0], text_table[i]);
+
        rc = dbgetm(dbt, &record[53], tmpbuf, 0);
      errorproc("dbputrk()", "record placed by key.", rc);
+
        errorproc("dbgetm()", "retreived memo.", rc);
    }
+
  errorproc("dbputrk()", "6 records placed by key.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------*/
  /* DBFLUSH() - flushes the record cache to disk                        */
+
        /* DBUPDM() - Updates the memofield for this record */
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------*/
  rc = dbflush(dbf);
+
        strcat(tmpbuf, " Appending this string to the end of memo...");
  errorproc("dbflush()", "table cache flushed.", rc);
+
        rc = dbupdm(dbt, tmpbuf, &record[53], &record[53]);
 +
        errorproc("dbupdm()", "updated memo.", rc);
  
  /*----------------------------------------------------------------------------------------*/
 
  /* DBIFLSH() - flushes the index cache to disk                          */
 
  /*----------------------------------------------------------------------------------------*/
 
  rc = dbiflsh(ndx);
 
  errorproc("dbiflsh()", "index cache flushed.", rc);
 
  
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------------------*/
  /* DBXFLSH() - flushes the tagged index cache to disk                  */
+
        /* DBPUTRK() - the following example adds a record and index   */
  /*----------------------------------------------------------------------------------------*/
+
        /*            to the respective files.                        */
  rc = dbxflsh(dbx);
+
        /* DBRECOUT() - scatter the record stored in buffer 'record' to */
  errorproc("dbxflsh()", "Tagged index cache flushed.", rc);
+
        /*              two dimensional character array 'fldbuf'        */
 +
/*--------------------------------------------------------------*/
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------*/
  /* DBFIELD() - this example extracts the field 'VESSEL' from the                */
+
        /* Read in 6 more records */
  /* record (#5) stored in buffer 'record'                                        */
+
/*------------------------*/
  /*----------------------------------------------------------------------------------------*/
+
  rc = dbgetr(dbf, (long) 5, record, &status);
+
  /* rc = dbfield( dbf, record, "FLAG", tmpbuf); */
+
  rc = dbfield(dbf, record, fields[5].fieldnm, tmpbuf);
+
  errorproc("dbfield()", "field extracted.", rc);
+
  printf("\t\tFlag: \t%s\n", tmpbuf);
+
  
  /*----------------------------------------------------------------------------------------*/
+
        for( i = 1; i <= 6; i++)  {
  /* Modify a single field in record number 5                                    */
+
            dbrecout( dbf, dbfields, fldpos, text_table[i], fldbuf);
  /*----------------------------------------------------------------------------------------*/
+
            rc = dbputrk(dbf, ndx, fldbuf[0], text_table[i]);
 +
            errorproc("dbputrk()", "record placed by key.", rc);
 +
        }
 +
        errorproc("dbputrk()", "6 records placed by key.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------*/
  /* DBSCATTER() - scatter the record into specified field buffers                */
+
        /* DBFLUSH() - flushes the record cache to disk */
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------*/
  rc = dbscatter(dbf, record, fldbuf);
+
        rc = dbflush(dbf);
  errorproc("dbscatter()", "record scattered.", rc);
+
        errorproc("dbflush()", "table cache flushed.", rc);
  
  for (i = 0; i < nofields; i++)
+
/*---------------------------------------------*/
    {
+
        /* DBIFLSH() - flushes the index cache to disk */
      fprintf(stdout, "\t\tfldbuf[%d]='%s'\n", i, fldbuf[i]);
+
/*---------------------------------------------*/
    }
+
        rc = dbiflsh(ndx);
  strcpy(fldbuf[5], "Spanish"); /* Modify Field */
+
        errorproc("dbiflsh()", "index cache flushed.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------*/
  /* DBGATHER() - gather the field buffers and place the contents        */
+
        /* DBXFLSH() - flushes the tagged index cache to disk */
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------*/
  rc = dbgather(dbf, record, fldbuf);
+
        rc = dbxflsh(dbx);
  errorproc("dbgather()", "record gathered.", rc);
+
        errorproc("dbxflsh()", "Tagged index cache flushed.", rc);
  printf("\t\t%s\n", record);
+
  
  rc = dbupdr(dbf, (long) 5, record); /* Finish Example    */
+
/*---------------------------------------------------------------*/
  errorproc("dbupdr()", "record updated.", rc);
+
        /* DBFIELD() - this example extracts the field 'VESSEL' from the */
 +
        /*            record (#5) stored in buffer 'record'            */
 +
/*---------------------------------------------------------------*/
 +
        rc = dbgetr(dbf, (long)5, record, &status);
 +
        /* rc = dbfield( dbf, record, "FLAG", tmpbuf); */
 +
        rc = dbfield( dbf, record, fields[5].fieldnm, tmpbuf);
 +
        errorproc("dbfield()", "field extracted.", rc);
 +
        printf("\t\tFlag: \t%s\n", tmpbuf);
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------*/
  /* Perform index / index conversion functions.                          */
+
        /* Modify a single field in record number 5 */
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------*/
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------------------*/
  /* DBREWIND() - position the record pointer to the top of the index file        */
+
        /* DBSCATTER() - scatters the record into specified field buffers.*/
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------------------*/
  rc = dbrewind(ndx);
+
        rc = dbscatter(dbf, record, fldbuf);
  errorproc("dbrewind()", "index rewound.", rc);
+
        errorproc("dbscatter()", "record scattered.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
        strcpy(fldbuf[6], "Spanish");                /* Modify Field */
  /* DBGETNR() - after 'rewinding' to the top of the table, the first record      */
+
  /* can be retrieved with dbgetnr() using the active key                */
+
  /*----------------------------------------------------------------------------------------*/
+
  for (i = 1; i <= 6; i++)
+
    {
+
      rc = dbgetnr(dbf, ndx, record, &status);
+
      printf("\t\t%d: %s\n", i, record);
+
    }
+
  errorproc("dbgetnr()", "6 records retrieved by key.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------------------*/
  /* DBNKEY() - get next key                                                      */
+
        /* DBGATHER() - Gathers the field buffers and places the contents */
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------------------*/
  rc = dbnkey(ndx, nextkey[0], rec_no);
+
        rc = dbgather(dbf, record, fldbuf);
  errorproc("dbnkey()", "next key retrieved.", rc);
+
        errorproc("dbgather()", "record gathered.", rc);
  printf("\t\tnext key: \t%s\n", nextkey[0]);
+
        printf("\t\t%s\n", record);
  
  /*----------------------------------------------------------------------------------------*/
+
        rc = dbupdr(dbf, (long)5, record);              /* Finish Example    */
  /* DBFWD() - position the pointer to the end of the table                      */
+
        errorproc("dbupdr()", "record updated.", rc);
  /*----------------------------------------------------------------------------------------*/
+
  rc = dbfwd(ndx);
+
  errorproc("dbfwd()", "index pointer placed at bottom.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
        /*---------------------------------------------*/
  /* DBPKEY() - get previous key                                          */
+
        /* Perform index / index conversion functions. */
  /*----------------------------------------------------------------------------------------*/
+
        /*---------------------------------------------*/
  rc = dbpkey(ndx, nextkey[0], rec_no);
+
  errorproc("dbpkey()", "previous key found.", rc);
+
  printf("\t\tprev key: \t%s\n", nextkey[0]);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------*/
  /* DBGETPR() - obtain the previous record by key                                */
+
        /* DBREWIND() - positions the record pointer to the top of the */
  /*----------------------------------------------------------------------------------------*/
+
        /*              index file                                    */
  rc = dbgetpr(dbf, ndx, record, &status);
+
/*-------------------------------------------------------------*/
  errorproc("dbgetpr()", "previous record (by key) retrieved.", rc);
+
        rc = dbrewind(ndx);
  printf("Previous: \t%s\n", record);
+
        errorproc("dbrewind()", "index rewound.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------------*/
  /* Rewind the index                                                            */
+
        /* DBGETNR() - after 'rewind()ing' to the top of the table  */
  /*----------------------------------------------------------------------------------------*/
+
        /*             the first record using the active key can be */
  dbrewind(ndx);
+
        /*            retrieved with dbgetnr()                    */
 +
/*----------------------------------------------------------*/
 +
        for( i = 1; i <= 6; i++)  {
 +
            rc = dbgetnr(dbf, ndx, record, &status);
 +
            printf("\t\t%d: %s\n", i,record);
 +
        }
 +
        errorproc("dbgetnr()", "6 records retrieved by key.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------*/
  /* Perform table retrieval functions using indexes.                            */
+
        /* DBNKEY() - get next key */
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------*/
 +
        rc = dbnkey(ndx, nextkey[0], rec_no);
 +
        errorproc("dbnkey()", "next key retrieved.", rc);
 +
        printf("\t\tnext key: \t%s\n", nextkey[0]);
  
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------------*/
  /* DBTKEY() - translates supplied key to record number                  */
+
        /* DBFWD() - position the pointer to the end of the table */
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------------*/
  rc = dbtkey(ndx, "Santa Rosa      ", &recno);
+
        rc = dbfwd(ndx);
  errorproc("dbtkey()", "record number found by key.", rc);
+
        errorproc("dbfwd()", "index pointer placed at bottom.", rc);
  printf("\t\trecord number: \t%d\n", recno);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------*/
  /* DBGETRK() - obtains the record from the specified key                       */
+
        /* DBPKEY() - get previous key */
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------*/
  rc = dbgetrk(dbf, ndx, "Santa Rosa        ", record, &status);
+
        rc = dbpkey(ndx, nextkey[0], rec_no);
  errorproc("dbgetrk()", "record retrieved by key.", rc);
+
        errorproc("dbpkey()", "previous key found.", rc);
  printf("\t\t%s\n", record);
+
        printf("\t\tprev key: \t%s\n", nextkey[0]);
  
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------------------------*/
  /* DBCKEY() - read the current key                                             */
+
        /* DBGETPR() - obtain the previous record by key */
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------------------------*/
  rc = dbckey(ndx, key, &recno);
+
        rc = dbgetpr(dbf, ndx, record, &status);
  errorproc("dbckey()", "current key read.", rc);
+
        errorproc("dbgetpr()", "previous record (by key) retrieved.", rc);
  printf("\t\tcurrent key: \t%s\n", key);
+
        printf("Previous: \t%s\n", record);
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------*/
  /* Perform tagged index functions.                                              */
+
        /* Rewind the index */
  /*----------------------------------------------------------------------------------------*/
+
/*------------------*/
 +
        dbrewind(ndx);
  
  /*----------------------------------------------------------------------------------------*/
+
        /*--------------------------------------------------*/
  /* DBXREWIND() - position the pointer to the top of the index file      */
+
        /* Perform table retrieval functions using indexes. */
  /*----------------------------------------------------------------------------------------*/
+
        /*--------------------------------------------------*/
  rc = dbxrewind(dbx);
+
  errorproc("dbxrewind()", "Tagged index rewound.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------------------------------*/
  /* DBXGETNR() - after 'rewinding' to the top of the table, the first record     */
+
        /* DBTKEY() - translates supplied key to record number */
  /* can be retrieved with dbgetnr() using the active key                */
+
/*-----------------------------------------------------*/
  /*----------------------------------------------------------------------------------------*/
+
        rc = dbtkey(ndx, "Santa Rosa        ", &recno);
  for (i = 1; i <= 6; i++)
+
        errorproc("dbtkey()", "record number found by key.", rc);
    {
+
        printf("\t\trecord number: \t%d\n", recno);
      rc = dbxgetnr(dbf, dbx, record, &status);
+
      printf("\t\t%d: %s\n", i, record);
+
    }
+
  errorproc("dbxgetnr()", "6 records retrieved by tag key.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------*/
  /* DBXNKEY() - get next key                                             */
+
        /* DBGETRK() - obtains the record from the specified key */
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------*/
  rc = dbxnkey(dbx, nextkey[0], rec_no);
+
        rc = dbgetrk(dbf, ndx, "Santa Rosa        ", record, &status);
  errorproc("dbxnkey()", "next key retrieved in tagged index.", rc);
+
        errorproc("dbgetrk()", "record retrieved by key.", rc);
  printf("\t\tnext key: \t%s\n", nextkey[0]);
+
        printf("\t\t%s\n", record);
  
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------*/
  /* DBXFWD() - position the pointer to the end of the table                      */
+
        /* DBCKEY() - read the current key */
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------*/
  rc = dbxfwd(dbx);
+
        rc = dbckey(ndx, key, &recno);
  errorproc("dbxfwd()", "index pointer placed at bottom.", rc);
+
        errorproc("dbckey()", "current key read.", rc);
 +
        printf("\t\tcurrent key: \t%s\n", key);
  
  /*----------------------------------------------------------------------------------------*/
+
        /*---------------------------------*/
  /* DBXPKEY() - get previous key                                        */
+
        /* Perform tagged index functions. */
  /*----------------------------------------------------------------------------------------*/
+
        /*---------------------------------*/
  rc = dbxpkey(dbx, nextkey[0], rec_no);
+
  errorproc("dbxpkey()", "previous key found in tagged index.", rc);
+
  printf("\t\tprev key: \t%s\n", nextkey[0]);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------------------*/
  /* DBXGETPR() - obtain the previous record by key                      */
+
        /* DBXREWIND() - positions the record pointer to the top of the */
  /*----------------------------------------------------------------------------------------*/
+
        /*              index file                                      */
  rc = dbxgetpr(dbf, dbx, record, &status);
+
/*--------------------------------------------------------------*/
  errorproc("dbxgetpr()", "previous record (by key) retrieved.", rc);
+
        rc = dbxrewind(dbx);
  printf("Previous: \t%s\n", record);
+
        errorproc("dbxrewind()", "Tagged index rewound.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------------------------------------*/
  /* Rewind the index                                                            */
+
        /* DBXGETNR() - after 'rewind()ing' to the top of the table  */
  /*----------------------------------------------------------------------------------------*/
+
        /*             the first record using the active key can be  */
  dbxrewind(dbx);
+
        /*            retrieved with dbgetnr()                      */
 +
/*-----------------------------------------------------------*/
 +
        for( i = 1; i <= 6; i++)  {
 +
            rc = dbxgetnr(dbf, dbx, record, &status);
 +
            printf("\t\t%d: %s\n", i,record);
 +
        }
 +
        errorproc("dbxgetnr()", "6 records retrieved by tag key.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------*/
  /* Perform table retrieval functions using tagged indexes.                      */
+
        /* DBXNKEY() - get next key */
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------*/
 +
        rc = dbxnkey(dbx, nextkey[0], rec_no);
 +
        errorproc("dbxnkey()", "next key retrieved in tagged index.", rc);
 +
        printf("\t\tnext key: \t%s\n", nextkey[0]);
  
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------------------------*/
  /* DBTKEY() - translates supplied key to record number                  */
+
        /* DBXFWD() - position the pointer to the end of the table */
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------------------------*/
  rc = dbtkey(ndx, "Santa Rosa      ", &recno);
+
        rc = dbxfwd(dbx);
  errorproc("dbtkey()", "record number found by key.", rc);
+
        errorproc("dbxfwd()", "index pointer placed at bottom.", rc);
  printf("\t\trecord number: \t%d\n", recno);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------*/
  /* DBXGETRK() - obtains the record from the specified key               */
+
        /* DBXPKEY() - get previous key */
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------*/
  rc = dbxgetrk(dbf, dbx, "Santa Rosa      ", record, &status);
+
        rc = dbxpkey(dbx, nextkey[0], rec_no);
  errorproc("dbxgetrk()", "record retrieved by key.", rc);
+
        errorproc("dbxpkey()", "previous key found in tagged index.", rc);
  printf("\t\t%s\n", record);
+
        printf("\t\tprev key: \t%s\n", nextkey[0]);
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------------*/
  /* DBXCKEY() - read the current key                                     */
+
        /* DBXGETPR() - obtain the previous record by key */
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------------*/
  rc = dbxckey(dbx, key, &recno);
+
        rc = dbxgetpr(dbf, dbx, record, &status);
  errorproc("dbxckey()", "current key read.", rc);
+
        errorproc("dbxgetpr()", "previous record (by key) retrieved.", rc);
  printf("\t\tcurrent key: \t%s\n", key);
+
        printf("Previous: \t%s\n", record);
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------*/
  /* Perform field level functions including index/ASCII functions.              */
+
        /* Rewind the index */
  /*----------------------------------------------------------------------------------------*/
+
/*------------------*/
 +
        dbxrewind(dbx);
  
  /*----------------------------------------------------------------------------------------*/
+
        /*---------------------------------------------------------*/
  /* DBATOFLD() - converts ASCII string to Recital field                  */
+
        /* Perform table retrieval functions using tagged indexes. */
  /*----------------------------------------------------------------------------------------*/
+
        /*---------------------------------------------------------*/
  rc = dbatofld("23.3", 4, 1, tmpbuf);
+
  errorproc("dbatofld()", "string converted.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------------------------------*/
  /* DBATOKEY() - converts a ASCII string to Recital date key            */
+
        /* DBTKEY() - translates supplied key to record number */
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------------------------------*/
  key[0] = 'D';
+
        rc = dbtkey(ndx, "Santa Rosa        ", &recno);
  rc = dbatokey("16430411", key);
+
        errorproc("dbtkey()", "record number found by key.", rc);
  errorproc("dbatokey()", "string converted to key.", rc);
+
        printf("\t\trecord number: \t%d\n", recno);
  
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------------*/
  /* DBFLDTOA() - converts extracted field to ASCII                      */
+
        /* DBXGETRK() - obtains the record from the specified key */
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------------------------*/
  rc = dbfldtoa(record + 18, 4, tmpbuf);
+
        rc = dbxgetrk(dbf, dbx, "Santa Rosa        ", record, &status);
  errorproc("dbfldtoa()", "field converted.", rc);
+
        errorproc("dbxgetrk()", "record retrieved by key.", rc);
 +
        printf("\t\t%s\n", record);
  
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------*/
  /* DBSTRCPY() - formats character strings to Recital types              */
+
        /* DBXCKEY() - read the current key */
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------*/
  dbstrcpy(key, 'L', 10, " 320000");
+
        rc = dbxckey(dbx, key, &recno);
  printf("Function: \tdbstrcpy() \toutput: %s\n", key);
+
        errorproc("dbxckey()", "current key read.", rc);
 +
        printf("\t\tcurrent key: \t%s\n", key);
  
  /*----------------------------------------------------------------------------------------*/
+
        /*---------------------------------------------------------------*/
  /* DBSTRING() - formats non-'C' strings to C strings (null term)                */
+
        /* Perform field level functions including index/ASCII functions.*/
  /*----------------------------------------------------------------------------------------*/
+
        /*---------------------------------------------------------------*/
  dbstring("Santa Pedro", 13, tmpbuf);
+
  printf("Function: \tdbstring() \toutput: %s\n", tmpbuf);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------*/
  /* DBKEYTOA() - converts an extracted key to ASCII                      */
+
        /* DBATOFLD() - converts ASCII string to Recital compat. field */
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------*/
  tmpbuf[0] = 0; /* Number of decimal places            */
+
        rc = dbatofld("23.3", 4, 1, tmpbuf);
  tmpbuf[1] = 'N'; /* Key Type                            */
+
        errorproc("dbatofld()", "string converted.", rc);
  rc = dbkeytoa(key, tmpbuf);
+
  errorproc("dbkeytoa()", "key converted.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------------*/
  /* Perform record/index deletion and file access                                */
+
        /* DBATOKEY() - converts a ASCII string to Recital date key */
  /*----------------------------------------------------------------------------------------*/
+
/*-----------------------------------------------------------*/
 +
        key[0] = 'D';
 +
        rc = dbatokey("16430411", key);
 +
        errorproc("dbatokey()", "string converted to key.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------------*/
  /* DBSIZE() - retrieve the size of the table                                    */
+
        /* DBFLDTOA() - converts extracted field to ASCII */
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------------*/
  rc = dbsize(dbf, &db_size);
+
        rc = dbfldtoa(record + 18, 4, tmpbuf);
  errorproc("dbsize()", "size retrieved.", rc);
+
        errorproc("dbfldtoa()", "field converted.", rc);
  printf("\t        No. of Records: \t%d\n", db_size);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------------------------*/
  /* DBPUTR() - adds a record to the end of the table                            */
+
        /* DBSTRCPY() - formats character strings to Rectial types */
  /* You can also 'insert' a record using this function                          */
+
/*---------------------------------------------------------*/
  /*----------------------------------------------------------------------------------------*/
+
        dbstrcpy(key, 'L', 10, " 320000");
  rc = dbputr(dbf, db_size + 1L, text_table[7]);
+
        printf("Function: \tdbstrcpy() \toutput: %s\n", key);
  errorproc("dbputr()", "record placed.", rc);
+
  rc = dbakey(ndx, "Unknown Vessel    ", db_size + 1L);
+
  errorproc("dbakey()", "key added.", rc);
+
  /*----------------------------------------------------------------------------------------*/
+
  /* Add record to the Production Index as well */
+
  /*----------------------------------------------------------------------------------------*/
+
  rc = dbxakey(dbx, db_size + 1L);
+
  errorproc("dbxakey()", "key added.", rc);
+
  
  dbflush(dbf);
+
/*---------------------------------------------------------------*/
  dbiflsh(ndx);
+
        /* DBSTRING() - formats non-'C' strings to C strings (null term) */
  dbxflsh(dbx);
+
/*---------------------------------------------------------------*/
 +
        dbstring("Santa Pedro", 13, tmpbuf);
 +
        printf("Function: \tdbstring() \toutput: %s\n", tmpbuf);
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------*/
  /* DBDELETE() - mark a record (number 8) for deletion                  */
+
        /* DBKEYTOA() - converts an extracted key to ASCII */
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------*/
  rc = dbdelete(dbf, 8L);
+
        tmpbuf[0] = 0; /* Number of dec. places */
  errorproc("dbdelete()", "record 8 marked for deletion.", rc);
+
        tmpbuf[1] = 'N'; /* Key Type              */
 +
        rc = dbkeytoa(key, tmpbuf);
 +
        errorproc("dbkeytoa()", "key converted.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
        /*-----------------------------------------------*/
  /* DBRECALL() - recall a record marked for deletion (number 8)          */
+
        /* Perform record/index deletion and file access */
  /*----------------------------------------------------------------------------------------*/
+
        /*-----------------------------------------------*/
  rc = dbrecall(dbf, 8L);
+
  errorproc("dbrecall()", "record 8 recalled.", rc);
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------*/
  /* DBRMVKEY() - physically remove a key.  As of v8.0, this function    */
+
        /* DBSIZE() - retrieve the size of the table */
  /* is not permitted on tables opened shareable.                        */
+
/*-------------------------------------------*/
  /*----------------------------------------------------------------------------------------*/
+
        rc = dbsize(dbf, &db_size);
  /* rc = dbrmvkey(ndx, "Unknown Vessel    ", db_size+1L);               */
+
        errorproc("dbsize()", "size retrieved.", rc);
  /* errorproc("dbrmvkey()", "key physically removed.", rc);         */
+
        printf("\t        No. of Records: \t%d\n", db_size);
  
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------------------------------*/
  /* DBRMVR() - physically remove a data record. As of v8.0 this          */
+
        /* DBPUTR() - adds a record to the end of the table              */
  /* function is not permitted on tables opened shareable.                        */
+
        /*           You can also 'insert' a record using this function */
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------------------------------*/
  /* rc = dbrmvr(dbf, db_size+1L);                                               */
+
        rc = dbputr(dbf, db_size + 1L, text_table[7]);
  /* errorproc("dbrmvr()", "record 7 physically removed.", rc);           */
+
        errorproc("dbputr()", "record placed.", rc);
 +
        rc = dbakey(ndx,"Unknown Vessel    " , db_size + 1L);
 +
        errorproc("dbakey()",  "key added.", rc);
 +
        rc = dbxakey(dbx, db_size + 1L);
 +
        errorproc("dbxakey()",  "key added.", rc);
  
  /*----------------------------------------------------------------------------------------*/
+
        dbflush(dbf);                  /* Good Habit on shared files */
  /* DBUNLOCKF() - unlocks a table file                                  */
+
        dbiflsh(ndx);
  /*----------------------------------------------------------------------------------------*/
+
dbxflsh(dbx);
  rc = dbunlockf(dbf);
+
  if (rc == SUCCESS)
+
    {
+
      printf("Function: \tdbunlockf() tFile unlocked successfully\n");
+
    }
+
  else
+
    {
+
      printf("Unlock Failed. \tError: %d\n", rc);
+
    }
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------*/
  /* DBUNLOCKI() - unlocks an index file                                  */
+
        /* DBDELETE() - mark a record (number 8) for deletion */
  /*----------------------------------------------------------------------------------------*/
+
/*----------------------------------------------------*/
  rc = dbunlocki(ndx);
+
        rc = dbdelete(dbf, 8L);
  if (rc == SUCCESS)
+
        errorproc("dbdelete()", "record 8 marked for deletion.", rc);
    {
+
      printf("Function: \tdbunlocki() \tFile unlocked successfully\n");
+
    }
+
  else
+
    {
+
      printf("Unlock Failed. \tError: %d\n", rc);
+
    }
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------*/
  /* DBLOCKR() - tests available record locking in a multi user          */
+
        /* DBRECALL() - recall a record marked for deletion (number 8) */
  /* environment.  Same as DBTLOCKR() in multi access                    */
+
/*-------------------------------------------------------------*/
  /*----------------------------------------------------------------------------------------*/
+
        rc = dbrecall(dbf, 8L);
  rc = dblockr(dbf, (long) 7);
+
        errorproc("dbrecall()", "record 8 recalled.", rc);
  if (rc == SUCCESS)
+
    {
+
      printf("Function: \tdblockr() \trecord locked successfully.\n");
+
    }
+
  else
+
    {
+
      printf("Lock Failed. tError: %dn", rc);
+
    }
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------------------------------*/
  /* DBUNLOCKR() - unlocks a table Record                                */
+
        /* DBRMVKEY() - physically remove a key.  As of v8.0, this function */
  /*----------------------------------------------------------------------------------------*/
+
/*              is not permitted on tables opened shareable.        */
  rc = dbunlockr(dbf, (long) 7);
+
/*------------------------------------------------------------------*/
  if (rc == SUCCESS)
+
        /* rc = dbrmvkey(ndx, "Unknown Vessel    ", db_size+1L);           */
    {
+
        /* errorproc("dbrmvkey()", "key physically removed.", rc);         */
      printf("Function \tdbunlockr(): \trecord unlocked successfully\n");
+
    }
+
  else
+
    {
+
      printf("Unlock Failed. tError: %d\n", rc);
+
    }
+
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------------------------------------*/
  /* Perform record/index close functions                                */
+
        /* DBRMVR() - physically remove a data record. As of v8.0 this      */
  /*----------------------------------------------------------------------------------------*/
+
/*            function is not permitted on tables opened shareable. */
 +
/*------------------------------------------------------------------*/
 +
        /* rc = dbrmvr(dbf, db_size+1L);                                    */
 +
        /* errorproc("dbrmvr()", "record 7 physically removed.", rc);      */
  
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------*/
  /* DBICLOSE() - close the active index                                  */
+
        /* DBUNLOCKF() - unlocks a table file */
  /*----------------------------------------------------------------------------------------*/
+
/*------------------------------------*/
  rc = dbiclose(ndx);
+
        rc = dbunlockf(dbf);
  errorproc("dbiclose()", "index closed.", rc);
+
        if ( rc == SUCCESS ) {
 +
            printf("Function: \tdbunlockf() \tFile unlocked successfully\n");
 +
        } else {
 +
            printf("Unlock Failed. \tError: %d\n", rc);
 +
}
  
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------*/
  /* DBXCLOSE() - close the active tagged index                           */
+
        /* DBUNLOCKI() - unlocks an index file */
  /*----------------------------------------------------------------------------------------*/
+
/*-------------------------------------*/
  rc = dbxclose(dbx);
+
        rc = dbunlocki(ndx);
  errorproc("dbxclose()", "tagged index closed.", rc);
+
        if ( rc == SUCCESS ) {
 +
            printf("Function: \tdbunlocki() \tFile unlocked successfully\n");
 +
        } else {
 +
            printf("Unlock Failed. \tError: %d\n", rc);
 +
}
  
  /*----------------------------------------------------------------------------------------*/
+
/*---------------------------------------------------------------*/
  /* DBCLOSE() - close the active table                                  */
+
        /* DBLOCKR() - tests available record locking in a multiuser    */
  /*----------------------------------------------------------------------------------------*/
+
        /*              environment.  Same as DBTLOCKR() in multi access */
  rc = dbclose(dbf);
+
/*---------------------------------------------------------------*/
  errorproc("dbclose()", "table closed.", rc);
+
        rc = dblockr(dbf, (long)7);
 +
        if ( rc == SUCCESS ) {
 +
            printf("Function: \tdblockr() \trecord locked successfully.\n");
 +
        } else {
 +
            printf("Lock Failed. \tError: %d\n", rc);
 +
}
  
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------*/
  /* DBMCLOSE() - close the active memo table                             */
+
        /* DBUNLOCKR() - unlocks a table Record */
  /*----------------------------------------------------------------------------------------*/
+
/*--------------------------------------*/
  rc = dbmclose(dbt);
+
        rc = dbunlockr(dbf, (long)7);
  errorproc("dbmclose()", "memo table closed.", rc);
+
        if ( rc == SUCCESS ) {
 +
            printf("Function \tdbunlockr(): \trecord unlocked successfully\n");
 +
        } else {
 +
            printf("Unlock Failed. \tError: %d\n", rc);
 +
}
  
  /*----------------------------------------------------------------------------------------*/
 
  /* Perform miscellaneous Recital/Library functions                              */
 
  /*----------------------------------------------------------------------------------------*/
 
  
  /*----------------------------------------------------------------------------------------*/
+
        /*--------------------------------------*/
  /* DBONERROR() - enables/disables (1/0) recovery from errors            */
+
        /* Perform record/index close functions */
  /*----------------------------------------------------------------------------------------*/
+
        /*--------------------------------------*/
  dbonerror(0); /* Recovery disabled */
+
  printf("Function: \tdbonerror()  \terror checking disabled\n");
+
  
  printf("\nEnd of Recital C Library test program....\n");
+
/*-------------------------------------*/
 +
        /* DBICLOSE() - close the active index */
 +
/*-------------------------------------*/
 +
        rc = dbiclose(ndx);
 +
        errorproc("dbiclose()", "index closed.", rc);
  
  exit(0);
+
/*--------------------------------------------*/
 +
        /* DBXCLOSE() - close the active tagged index */
 +
/*--------------------------------------------*/
 +
        rc = dbxclose(dbx);
 +
        errorproc("dbxclose()", "tagged index closed.", rc);
 +
 
 +
/*------------------------------------*/
 +
        /* DBCLOSE() - close the active table */
 +
/*------------------------------------*/
 +
        rc = dbclose(dbf);
 +
        errorproc("dbclose()", "table closed.", rc);
 +
 
 +
/*------------------------------------------*/
 +
        /* DBMCLOSE() - close the active memo table */
 +
/*------------------------------------------*/
 +
        rc = dbmclose(dbt);
 +
        errorproc("dbmclose()", "memo table closed.", rc);
 +
 
 +
 
 +
        /*-------------------------------------------------*/
 +
        /* Perform miscellaneous Recital/Library functions */
 +
        /*-------------------------------------------------*/
 +
 
 +
/*-----------------------------------------------------------*/
 +
        /* DBONERROR() - enables/disables (1/0) recovery from errors */
 +
/*-----------------------------------------------------------*/
 +
        dbonerror(0);                          /* Recovery disabled */
 +
        printf("Function: \tdbonerror()  \terror checking disabled\n");
 +
 
 +
        printf("\nEnd of Recital C Library test program....\n");
 +
 
 +
        exit(0);
  
 
}
 
}
  
/*-------------------------------------------------------------------------------------------------*/
 
/* This procedure handles the return codes from called RECITAL/library          */
 
/* functions.  Intended to eliminate cryptic  'if...else...' statements                */
 
/* following library calls.                                                            */
 
/*-------------------------------------------------------------------------------------------------*/
 
  
static int errorproc(func, str, rc)
+
 
  char *func;char *str;int rc;
+
/*----------------------------------------------------------------------*/
 +
/* This procedure handles the return codes from called RECITAL/library  */
 +
/* functions.  Intended to eliminate cryptic  'if...else...' statements */
 +
/* following library calls.                                            */
 +
/*----------------------------------------------------------------------*/
 +
 
 +
static void errorproc(func, str, rc)
 +
char   *func;
 +
char   *str;
 +
int     rc;
 
{
 
{
  if (rc != SUCCESS)
+
        if ( rc != SUCCESS ) {
    {
+
            printf("\n  Error performing function %s -> %d\n", func, rc);
      printf("\n  Error performing function %s -> %d\n", func, rc);
+
            exit(1);
      exit(1);
+
        }
    }
+
        printf("Function: \t%s, \t%s - Ok\n", func,str);
  printf("Function: \t%s, \t%s - Ok\n", func, str);
+
        return;
  return;
+
 
}
 
}
 
 
</code>
 
</code>
 
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Library]]
 
[[Category:Library]]
 
[[Category:Reference]]
 
[[Category:Reference]]

Latest revision as of 13:54, 6 May 2009

The following program is written in 'C' as an example program using the RECITAL/Library functions. This file is stored in the SDK dbl sub-directory and is called "dblsamp.c".

/*#============================================================================
 *# Copyright (C) 1988-2009 Recital Corporation Inc.
 *# As an unpublished licenced proprietary work.
 *# All rights reserved worldwide.
 *#
 *# This program may be freely copied and used as a template for user
 *# programs which make use of the Recital/Library in so long as the above
 *# copyright notice is included.
 *#
 *#============================================================================
 *
 *      MODULE          : dblsamp.c
 *
 *      PURPOSE         : Recital DataBase Library sample program.
 *
 *      AUTHOR          : RECITAL CORPORATION
 *
 *      DATE            : 26 Jan 91
 *      REVISION        : 29 Oct 91
 *      REVISION        : 09 May 95
 *
 *==========================================================================*/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "dbl.h"                        /* Recital/Library include file */
#include "dblproto.h"                   /* Recital/Library prototype file */
 
 
extern	int	g_disable_iostats;
 
/*----------------------------------------------*/
/* Table structure for db to be constructed. */
/* Structure dBFIELD defined in dbl.h.          */
/*----------------------------------------------*/
static  dBFIELD fields[7] = {
        "VESSEL",       'C',    18,     0,	0,
        "LAT",          'N',    4,      1,	0,
        "LONG",         'N',    4,      1,	0,
        "AMOUNT",       'N',    10,     0,	0,
        "DATE",         'D',    8,      0,	0,
        "FLAG",         'C',    9,      0,	0,
        "MEMO",         'M',    sizeof(MEMO),      0,	0 
};
 
#define DB_RECORD_SIZE  100
 
/*----------------------------------------------*/
/* Static Error Handling procedure.             */
/*----------------------------------------------*/
static void errorproc(
	char    *func,
	char    *str,
	int     rc);
 
/*----------------------------------------------*/
/* Table records to add.                     */
/*----------------------------------------------*/
static char *text_table[] =  {
    "Santa Margarita   80.027.5   700000095/01/01Spanish  ",
    "Santa Rosa        81.824.8  3000000032/01/01Spanish  ",
    "Unknown galleon   83.123.0         015/01/01Spanish  ",
    "Jessie            97.127.4    10000075/01/01U.S.     ",
    "Lea               96.227.8   100000080/01/01U.S.     ",
    "S.J. Lee          96.926.9    20000075/01/01U.S.     ",
    "Genovase          78.418.4   185000030/01/01Spanish  ",
    "Unknown Vessel    77.517.9         075/01/01U.S.     "
};
 
 
/*---------------------------*/
/* Main program entry point. */
/*---------------------------*/
main()
{
        int     rc;                     /* Return Code for error handling  */
        char    *dbf;                   /* File descriptor for table    */
        char    *dbx;                   /* File descriptor for tagged index   */
        char    *ndx;                   /* File descriptor for index       */
        char    *dbt;                   /* File descriptor for memo file   */
        char    record[DB_RECORD_SIZE]; /* Array of char for records       */
        char    keytype;                /* Variable for varying keytype    */
        char    key[21];                /* Storage location for keys       */
        char    tagname[21];            /* Storage location for tag name */
        char    keyexpr[512];           /* Storage location for key expr   */
        char    forexpr[512];           /* Storage location for for expr   */
        int     kexprlen;               /* The key expression length       */
        int     keylen;                 /* The key length                  */
        dBFIELD dbfields[MAX_RECORD_FIELDS];          /* Storage location for fld names  */
        FLDNUM  fieldcount;             /* Number of fields to create      */
        int     fldpos[MAX_RECORD_FIELDS];            /* Fields position buffer          */
        char    flddes[MAX_RECORD_FIELDS][26];        /* Fields description buffer       */
        char    tmpbuf[81];             /* Temporary storage buffer        */
        char    fldbuf[MAX_RECORD_FIELDS][256];       /* Field buffer (recin()/out())    */
        char    nextkey[10][20];        /* Key buffers (dbnkey())          */
        char    status;                 /* Deleted record flag             */
        long    recno;                  /* Table record variable        */
        long    rec_no[10];             /* Record number array (dbnkey())  */
        long    db_size;                /* Size of table variable       */
        int     reclen;                 /* Table record length variable */
        char    month;                  /* Month variable                  */
        char    day;                    /* Day variable                    */
        char    year;                   /* Year variable                   */
        FLDNUM  nofields;               /* Number of table fields var   */
        int     i;             	 	/* Loop control variable           */
        double  n;                      /* Double numeric variable         */
	int	keyunique;		/* Boolean for unqiue tag key	*/
	int	keydescend;		/* Boolean for descending tag key */
	int	notags;			/* number of tags in a dbx file */
 
 
        /*----------------------------------------------------*/
        /* Perform operational Library environment functions. */
        /*----------------------------------------------------*/
 
	/*---------------------------------------------------------------*/
        /* DBDCACHE() - this example allocates a 100 record caching area */
	/*---------------------------------------------------------------*/
        rc = dbdcache(100);
        errorproc("dbdcache()","table cache specified.", rc);
 
	/*-------------------------------------------------------------------*/
        /* DBICACHE() - this example allocates 51200 bytes for index caching */
	/*-------------------------------------------------------------------*/
        rc = dbicache(100);
        errorproc("dbicache()", "index cache specified.",rc);
 
	/*------------------------------------------*/
        /* DBFILEMODE() - shared, read write access */
	/*------------------------------------------*/
        rc = dbfilemode(1,0);
        errorproc("dbfilemode()", "filemode specified.", rc);
 
	/*------------------------------------------*/
        /* DBSET() - Set exact index match to true  */
	/*------------------------------------------*/
        rc = dbset("EXACT", 1);
        errorproc("dbset()", "filemode specified.", rc);
 
        /*--------------------------------*/
        /* Perform basic table functions. */
        /*--------------------------------*/
        fieldcount = 7;                         /* Number of Fields          */
 
	/*-----------------------------------------------------------*/
        /* DBCREAT() - this example creates a table according to the */
        /*             'dBFIELD' array fields.                       */
	/*-----------------------------------------------------------*/
        rc = dbcreat("shipwreck.dbf",fieldcount, fields);
        errorproc("dbcreat()","datebase created.", rc);
 
	/*----------------------------------------------------------------*/
        /* DBCREATX() - Enables the addition of table field descriptions. */
	/*----------------------------------------------------------------*/
        strcpy(flddes[0], "The vessel's name.");
        strcpy(flddes[1], "The latitude.");
        strcpy(flddes[2], "The longitude.");
        strcpy(flddes[3], "The value.");
        strcpy(flddes[4], "The date.");
        strcpy(flddes[5], "The vessel's flag.");
        strcpy(flddes[6], "Notes.");
 
        rc = dbcreatx("shipwreck.dbf", fieldcount, fields, flddes);
 
	/*----------------------------------------------------------------*/
        /* DBOPEN() - example opens table 'shipwreck.dbf' returning the     */
        /*            table file descriptor (dbf) used in upcoming funcs  */
	/*----------------------------------------------------------------*/
        rc = dbopen("shipwreck.dbf", &dbf);
        errorproc("dbopen()","table opened.", rc);
 
	/*-------------------------------------------------------------*/
        /* DBGETF() - obtain table information on the table referenced */
        /*            by the 'dbf' file descriptor.                    */
	/*-------------------------------------------------------------*/
        rc = dbgetf(dbf, &reclen, &month, &day,
                        &year, &nofields, dbfields);
        errorproc("dbgetf()","information retrieved.", rc);
        printf("\t\tRecord length in bytes: %d\n", reclen);
        printf("\t\tCreation date: \t\t%d/%d/%d\n",month,day,year);
        printf("\t\tNumber of fields: \t%d\n", nofields);
 
 
	/*-----------------------------------------------------------------*/
        /* DBGETFX() - obtain extended table information including the     */
        /*             numeric field location array (fldpos) and the field */
        /*             descriptions (flddes).                              */
	/*-----------------------------------------------------------------*/
        rc = dbgetfx(dbf, &reclen, &month, &day, &year,
                     &nofields, dbfields, fldpos, flddes);
        errorproc("dbgetfx()", "extra information retrieved.", rc);
        printf("\t\tLocation of fields in buffer: \t%d,%d,%d,%d,%d,%d\n",
            fldpos[1],fldpos[2],fldpos[3],fldpos[4],fldpos[5],fldpos[6]);
 
	/*-------------------------------------------------------------*/
        /* DBLOCKF() - locks the table for following additions.        */
        /*             Synonomous with DBTLOCKF() which tests the lock */
	/*-------------------------------------------------------------*/
        rc = dblockf(dbf);
        if ( rc == SUCCESS ) {
            printf("Function: \tdblockf() \tfile locked successfully.\n");
        } else {
            printf("Lock Failed. \tError: %d\n",rc);
	}
 
	/*------------------------------------*/
        /* DBCLOSE() - close the active table */
	/*------------------------------------*/
	rc = dbclose(dbf);
        errorproc("dbclose()", "table closed.", rc);
 
	/*----------------------------------------------*/
        /* Exclusive, read write access of the table is */
	/* required to create or delete tags.	        */
	/*----------------------------------------------*/
        rc = dbfilemode(0,0);
        rc = dbopen("shipwreck.dbf", &dbf);
        errorproc("dbopen()","table opened in exclusive mode.", rc);
 
        /*---------------------------------------*/
        /* Perform basic tagged index functions. */
        /*---------------------------------------*/
 
 
	/*--------------------------------------------------------------*/
        /* DBXCREATE() - in this example creates an tag on field VESSEL */
	/*--------------------------------------------------------------*/
        rc = dbxcreate( dbf,
			fields[0].fieldnm,		/* "VESSEL",  */
			&dbx,
			fields[0].fieldnm,		/* "VESSEL",  */
			NULL,
			0,
			0);
        errorproc("dbxcreate()","tag created", rc);
 
	/*------------------------------------------------------------*/
        /* DBXCREATE() - in this example creates an tag on field FLAG */
	/*------------------------------------------------------------*/
        rc = dbxcreate( dbf,
			fields[5].fieldnm,		/* "FLAG",  */
			&dbx,
			fields[5].fieldnm,		/* "FLAG",  */
			NULL,
			0,
			0);
        errorproc("dbxcreate()","tag created", rc);
 
	/*----------------------------------------------------*/
        /* DBXNOTAGS() - obtains the number of tagged indexes */
	/*----------------------------------------------------*/
        rc = dbxnotags(dbx, &notags);
        errorproc("dbxnotags()","tagged index count obtained.", rc);
        printf("\t        Key count: \t%d\n", notags );
 
	/*-----------------------------------------------*/
        /* DBXKEXPR() - obtains tagged index information */
	/*-----------------------------------------------*/
	for (i = 1; i <= notags; i++) {
            rc = dbxkexpr(dbx, 
			  &i,
			  tagname,
			  &keytype, 
			  keyexpr, 
			  forexpr,
			  &kexprlen, 
			  &keylen,
			  &keyunique,
			  &keydescend);
            errorproc("dbxkexpr()", "key information retrieved.", rc);
            printf("\t        Key number: \t%d\n", i );
            printf("\t        Key name: \t%s\n", tagname );
            printf("\t        Key type: \t%c\n", keytype );
            printf("\t        Key expression: %s\n", keyexpr);
            printf("\t        Key length: %d   Expression length: %d\n",
                              kexprlen, keylen);
            printf("\t        For expression: %s\n", forexpr);
            printf("\t        Key unique: \t%s\n", keyunique ? "Yes" : "No" );
            printf("\t        Key descending: \t%s\n", keydescend?"Yes":"No" );
	}
 
	/*----------------------------------------*/
        /* DBXDROPTAGS() - Drop the specified tag */
	/*----------------------------------------*/
        rc = dbxdroptag(dbx, fields[5].fieldnm);
        errorproc("dbxdroptag()","tagged index 'FLAG' dropped.", rc);
 
	/*--------------------------------------------*/
        /* DBXCLOSE() - close the active tagged index */
	/*--------------------------------------------*/
        rc = dbxclose(dbx);
        errorproc("dbxclose()", "tagged index closed.", rc);
 
	/*------------------------------------*/
        /* DBCLOSE() - close the active table */
	/*------------------------------------*/
        rc = dbclose(dbf);
        errorproc("dbclose()", "table closed.", rc);
 
	/*----------------------------------------------------*/
        /* Reopen the table in shared, read-write access mode */
	/*----------------------------------------------------*/
        rc = dbfilemode(1,0);
        rc = dbopen("shipwreck.dbf", &dbf);
        errorproc("dbopen()","table opened in shared mode.", rc);
 
	/*--------------------------------------------------------------------*/
        /* DBXOPEN() - example opens tag index 'shipwreck.dbx' returning the  */
        /*           taged index file descriptor (dbx) used in upcoming funcs */
	/*--------------------------------------------------------------------*/
        rc = dbxopen(dbf, "shipwreck.dbx", &dbx);
        errorproc("dbxopen()","tagged index opened.", rc);
 
        /*--------------------------------*/
        /* Perform basic index functions. */
        /*--------------------------------*/
 
	/*---------------------------------------------------------------*/
        /* DBICREAT() - in this example creates an index on field VESSEL */
	/*---------------------------------------------------------------*/
        rc = dbicreat( "shipwreck.ndx", fields[0].fieldnm, 18, 'C');
        errorproc("dbicreat()","index created", rc);
 
	/*------------------------------------------*/
        /* DBIOPEN() - opens index to active status */
	/*------------------------------------------*/
        rc = dbiopen( "shipwreck.ndx", &ndx);
        errorproc("dbiopen()", "index opened.", rc);
 
	/*---------------------------------------*/
        /* DBKEXPR() - obtains index information */
	/*---------------------------------------*/
        rc = dbkexpr(ndx, &keytype, keyexpr, &kexprlen, &keylen);
        errorproc("dbkexpr()", "key information retrieved.", rc);
        printf("\t        Key type: \t%c\n", keytype );
        printf("\t        Key expression: %s\n", keyexpr);
        printf("\t        Key length: %d   Expression length: %d\n",
                          kexprlen, keylen);
 
	/*----------------*/
	/* Lock data file */
	/*----------------*/
	rc = dblockf(dbf);
        if ( rc == SUCCESS ) {
            printf("Function: \tdblockf() \tfile locked successfully.\n");
        } else {
            printf("Lock Failed. \tError: %d\n",rc);
	}
 
	/*-------------------------------------------------------------*/
        /* DBLOCKI() - locks the index for following additions         */
        /*             Synonomous with DBTLOCKI() which tests the lock */
	/*-------------------------------------------------------------*/
        rc = dblocki(ndx);
        if ( rc == SUCCESS ) {
            printf("Function: \tdblocki() \tindex locked successfully.\n");
        } else {
            printf("Lock Failed. \tError: %d\n",rc);
	}
 
        /*------------------------------------*/
        /* Perform basic memo file functions. */
        /*------------------------------------*/
 
	/*----------------------------------------------------------------*/
        /* DBMCREAT() - creates a table memo file (if one needs creating) */
	/*----------------------------------------------------------------*/
        rc = dbmcreat("shipwreck.dbt");
        errorproc("dbmcreat()", "memo file create", rc);
 
	/*-------------------------------------------*/
        /* DBMOPEN() - opens an associated memo file */
	/*-------------------------------------------*/
        rc = dbmopen("shipwreck.dbt", &dbt);
        errorproc("dbmopen()", "memo file open.", rc);
 
 
        /*--------------------------------*/
        /* Perform table input functions. */
        /*--------------------------------*/
 
	/*--------------------------------------------------------------*/
        /* DBAPPEND() - appends a record to the end of the active table */
	/*--------------------------------------------------------------*/
        rc = dbappend(dbf, text_table[0], &recno);
        errorproc("dbappend()", "record appended.", rc);
 
	/*------------------------------------------------------------*/
        /* DBAKEY() - adds a key to the active index after dbappend() */
	/*------------------------------------------------------------*/
        rc = dbakey(ndx,"Santa Margarita   " , recno);
        errorproc("dbakey()",  "key added.", rc);
 
	/*-------------------------------------------------------------*/
        /* DBXAKEY() - adds a key to the tagged index after dbappend() */
	/* 	       The tagged index file must be lock first	       */
	/*-------------------------------------------------------------*/
        rc = dbxlocki(dbx);
        errorproc("dbxlocki()",  "tagged index file locked.", rc);
        rc = dbxakey(dbx,recno);
        errorproc("dbxakey()",  "key added.", rc);
        rc = dbxunlocki(dbx);
        errorproc("dbxunlocki()",  "tagged index file unlocked.", rc);
 
	/*----------------------------------------------*/
        /* DBFLUSH() - flushes the record cache to disk */
	/*----------------------------------------------*/
        rc = dbflush(dbf);
        errorproc("dbflush()", "table cache flushed.", rc);
 
	/*---------------------------------------------*/
        /* DBIFLSH() - flushes the index cache to disk */
	/*---------------------------------------------*/
        rc = dbiflsh(ndx);
        errorproc("dbiflsh()", "index cache flushed.", rc);
 
	/*----------------------------------------------------*/
        /* DBXFLSH() - flushes the tagged index cache to disk */
	/*----------------------------------------------------*/
        rc = dbxflsh(dbx);
        errorproc("dbxflsh()", "Tagged index cache flushed.", rc);
 
	/*-------------------------------*/
        /* DBGETR() - retrieves a record */
	/*-------------------------------*/
        rc = dbgetr(dbf, (long)1, record, &status);
        errorproc("dbgetr()", "record retreived.", rc);
        printf("\t\t%s\n", record);
 
	/*-------------------------------------*/
        /* DBPUTM() - put the memo information */
	/*-------------------------------------*/
        rc = dbputm(dbt, "128' 30% coral cover.", &record[53]);
        errorproc("dbputm", "memo placed in buffer",rc);
 
	/*-----------------------------------------------------------*/
        /* DBUPDR() - updates the record in buffer 'record'          */
	/*            As of v8.0 this function automatically updates */
	/*            any attached indexes.                          */
	/*-----------------------------------------------------------*/
        rc = dbupdr(dbf, (long)1, record);
        errorproc("dbupdr()", "record updated.", rc);
 
	/*------------------------------------------------------------------*/
        /* DBGETM() - this example extracts the memo from the record buffer */
	/*------------------------------------------------------------------*/
        rc = dbgetm(dbt, &record[53], tmpbuf, 0);
        errorproc("dbgetm()", "retreived memo.", rc);
 
	/*--------------------------------------------------*/
        /* DBUPDM() - Updates the memofield for this record */
	/*--------------------------------------------------*/
        strcat(tmpbuf, " Appending this string to the end of memo...");
        rc = dbupdm(dbt, tmpbuf, &record[53], &record[53]);
        errorproc("dbupdm()", "updated memo.", rc);
 
 
	/*--------------------------------------------------------------*/
        /* DBPUTRK() - the following example adds a record and index    */
        /*             to the respective files.                         */
        /* DBRECOUT() - scatter the record stored in buffer 'record' to */
        /*              two dimensional character array 'fldbuf'        */
	/*--------------------------------------------------------------*/
 
	/*------------------------*/
        /* Read in 6 more records */
	/*------------------------*/
 
        for( i = 1; i <= 6; i++)  {
            dbrecout( dbf, dbfields, fldpos, text_table[i], fldbuf);
            rc = dbputrk(dbf, ndx, fldbuf[0], text_table[i]);
            errorproc("dbputrk()", "record placed by key.", rc);
        }
        errorproc("dbputrk()", "6 records placed by key.", rc);
 
	/*----------------------------------------------*/
        /* DBFLUSH() - flushes the record cache to disk */
	/*----------------------------------------------*/
        rc = dbflush(dbf);
        errorproc("dbflush()", "table cache flushed.", rc);
 
	/*---------------------------------------------*/
        /* DBIFLSH() - flushes the index cache to disk */
	/*---------------------------------------------*/
        rc = dbiflsh(ndx);
        errorproc("dbiflsh()", "index cache flushed.", rc);
 
	/*----------------------------------------------------*/
        /* DBXFLSH() - flushes the tagged index cache to disk */
	/*----------------------------------------------------*/
        rc = dbxflsh(dbx);
        errorproc("dbxflsh()", "Tagged index cache flushed.", rc);
 
	/*---------------------------------------------------------------*/
        /* DBFIELD() - this example extracts the field 'VESSEL' from the */
        /*             record (#5) stored in buffer 'record'             */
	/*---------------------------------------------------------------*/
        rc = dbgetr(dbf, (long)5, record, &status);
        /* rc = dbfield( dbf, record, "FLAG", tmpbuf); */
        rc = dbfield( dbf, record, fields[5].fieldnm, tmpbuf);
        errorproc("dbfield()", "field extracted.", rc);
        printf("\t\tFlag: \t%s\n", tmpbuf);
 
	/*------------------------------------------*/
        /* Modify a single field in record number 5 */
	/*------------------------------------------*/
 
	/*----------------------------------------------------------------*/
        /* DBSCATTER() - scatters the record into specified field buffers.*/
	/*----------------------------------------------------------------*/
        rc = dbscatter(dbf, record, fldbuf);
        errorproc("dbscatter()", "record scattered.", rc);
 
        strcpy(fldbuf[6], "Spanish");                /* Modify Field */
 
	/*----------------------------------------------------------------*/
        /* DBGATHER() - Gathers the field buffers and places the contents */
	/*----------------------------------------------------------------*/
        rc = dbgather(dbf, record, fldbuf);
        errorproc("dbgather()", "record gathered.", rc);
        printf("\t\t%s\n", record);
 
        rc = dbupdr(dbf, (long)5, record);              /* Finish Example    */
        errorproc("dbupdr()", "record updated.", rc);
 
        /*---------------------------------------------*/
        /* Perform index / index conversion functions. */
        /*---------------------------------------------*/
 
	/*-------------------------------------------------------------*/
        /* DBREWIND() - positions the record pointer to the top of the */
        /*              index file                                     */
	/*-------------------------------------------------------------*/
        rc = dbrewind(ndx);
        errorproc("dbrewind()", "index rewound.", rc);
 
	/*----------------------------------------------------------*/
        /* DBGETNR() - after 'rewind()ing' to the top of the table  */
        /*             the first record using the active key can be */
        /*             retrieved with dbgetnr()                     */
	/*----------------------------------------------------------*/
        for( i = 1; i <= 6; i++)  {
            rc = dbgetnr(dbf, ndx, record, &status);
            printf("\t\t%d: %s\n", i,record);
        }
        errorproc("dbgetnr()", "6 records retrieved by key.", rc);
 
	/*-------------------------*/
        /* DBNKEY() - get next key */
	/*-------------------------*/
        rc = dbnkey(ndx, nextkey[0], rec_no);
        errorproc("dbnkey()", "next key retrieved.", rc);
        printf("\t\tnext key: \t%s\n", nextkey[0]);
 
	/*--------------------------------------------------------*/
        /* DBFWD() - position the pointer to the end of the table */
	/*--------------------------------------------------------*/
        rc = dbfwd(ndx);
        errorproc("dbfwd()", "index pointer placed at bottom.", rc);
 
	/*-----------------------------*/
        /* DBPKEY() - get previous key */
	/*-----------------------------*/
        rc = dbpkey(ndx, nextkey[0], rec_no);
        errorproc("dbpkey()", "previous key found.", rc);
        printf("\t\tprev key: \t%s\n", nextkey[0]);
 
	/*-----------------------------------------------*/
        /* DBGETPR() - obtain the previous record by key */
	/*-----------------------------------------------*/
        rc = dbgetpr(dbf, ndx, record, &status);
        errorproc("dbgetpr()", "previous record (by key) retrieved.", rc);
        printf("Previous: \t%s\n", record);
 
	/*------------------*/
        /* Rewind the index */
	/*------------------*/
        dbrewind(ndx);
 
        /*--------------------------------------------------*/
        /* Perform table retrieval functions using indexes. */
        /*--------------------------------------------------*/
 
	/*-----------------------------------------------------*/
        /* DBTKEY() - translates supplied key to record number */
	/*-----------------------------------------------------*/
        rc = dbtkey(ndx, "Santa Rosa        ", &recno);
        errorproc("dbtkey()", "record number found by key.", rc);
        printf("\t\trecord number: \t%d\n", recno);
 
	/*-------------------------------------------------------*/
        /* DBGETRK() - obtains the record from the specified key */
	/*-------------------------------------------------------*/
        rc = dbgetrk(dbf, ndx, "Santa Rosa        ", record, &status);
        errorproc("dbgetrk()", "record retrieved by key.", rc);
        printf("\t\t%s\n", record);
 
	/*---------------------------------*/
        /* DBCKEY() - read the current key */
	/*---------------------------------*/
        rc = dbckey(ndx, key, &recno);
        errorproc("dbckey()", "current key read.", rc);
        printf("\t\tcurrent key: \t%s\n", key);
 
        /*---------------------------------*/
        /* Perform tagged index functions. */
        /*---------------------------------*/
 
	/*--------------------------------------------------------------*/
        /* DBXREWIND() - positions the record pointer to the top of the */
        /*              index file                                      */
	/*--------------------------------------------------------------*/
        rc = dbxrewind(dbx);
        errorproc("dbxrewind()", "Tagged index rewound.", rc);
 
	/*-----------------------------------------------------------*/
        /* DBXGETNR() - after 'rewind()ing' to the top of the table  */
        /*             the first record using the active key can be  */
        /*             retrieved with dbgetnr()                      */
	/*-----------------------------------------------------------*/
        for( i = 1; i <= 6; i++)  {
            rc = dbxgetnr(dbf, dbx, record, &status);
            printf("\t\t%d: %s\n", i,record);
        }
        errorproc("dbxgetnr()", "6 records retrieved by tag key.", rc);
 
	/*--------------------------*/
        /* DBXNKEY() - get next key */
	/*--------------------------*/
        rc = dbxnkey(dbx, nextkey[0], rec_no);
        errorproc("dbxnkey()", "next key retrieved in tagged index.", rc);
        printf("\t\tnext key: \t%s\n", nextkey[0]);
 
	/*---------------------------------------------------------*/
        /* DBXFWD() - position the pointer to the end of the table */
	/*---------------------------------------------------------*/
        rc = dbxfwd(dbx);
        errorproc("dbxfwd()", "index pointer placed at bottom.", rc);
 
	/*-----------------------------*/
        /* DBXPKEY() - get previous key */
	/*-----------------------------*/
        rc = dbxpkey(dbx, nextkey[0], rec_no);
        errorproc("dbxpkey()", "previous key found in tagged index.", rc);
        printf("\t\tprev key: \t%s\n", nextkey[0]);
 
	/*------------------------------------------------*/
        /* DBXGETPR() - obtain the previous record by key */
	/*------------------------------------------------*/
        rc = dbxgetpr(dbf, dbx, record, &status);
        errorproc("dbxgetpr()", "previous record (by key) retrieved.", rc);
        printf("Previous: \t%s\n", record);
 
	/*------------------*/
        /* Rewind the index */
	/*------------------*/
        dbxrewind(dbx);
 
        /*---------------------------------------------------------*/
        /* Perform table retrieval functions using tagged indexes. */
        /*---------------------------------------------------------*/
 
	/*-----------------------------------------------------*/
        /* DBTKEY() - translates supplied key to record number */
	/*-----------------------------------------------------*/
        rc = dbtkey(ndx, "Santa Rosa        ", &recno);
        errorproc("dbtkey()", "record number found by key.", rc);
        printf("\t\trecord number: \t%d\n", recno);
 
	/*--------------------------------------------------------*/
        /* DBXGETRK() - obtains the record from the specified key */
	/*--------------------------------------------------------*/
        rc = dbxgetrk(dbf, dbx, "Santa Rosa        ", record, &status);
        errorproc("dbxgetrk()", "record retrieved by key.", rc);
        printf("\t\t%s\n", record);
 
	/*---------------------------------*/
        /* DBXCKEY() - read the current key */
	/*---------------------------------*/
        rc = dbxckey(dbx, key, &recno);
        errorproc("dbxckey()", "current key read.", rc);
        printf("\t\tcurrent key: \t%s\n", key);
 
        /*---------------------------------------------------------------*/
        /* Perform field level functions including index/ASCII functions.*/
        /*---------------------------------------------------------------*/
 
	/*-------------------------------------------------------------*/
        /* DBATOFLD() - converts ASCII string to Recital compat. field */
	/*-------------------------------------------------------------*/
        rc = dbatofld("23.3", 4, 1, tmpbuf);
        errorproc("dbatofld()", "string converted.", rc);
 
	/*----------------------------------------------------------*/
        /* DBATOKEY() - converts a ASCII string to Recital date key */
	/*-----------------------------------------------------------*/
        key[0] = 'D';
        rc = dbatokey("16430411", key);
        errorproc("dbatokey()", "string converted to key.", rc);
 
	/*------------------------------------------------*/
        /* DBFLDTOA() - converts extracted field to ASCII */
	/*------------------------------------------------*/
        rc = dbfldtoa(record + 18, 4, tmpbuf);
        errorproc("dbfldtoa()", "field converted.", rc);
 
	/*---------------------------------------------------------*/
        /* DBSTRCPY() - formats character strings to Rectial types */
	/*---------------------------------------------------------*/
        dbstrcpy(key, 'L', 10, "  320000");
        printf("Function: \tdbstrcpy() \toutput: %s\n", key);
 
	/*---------------------------------------------------------------*/
        /* DBSTRING() - formats non-'C' strings to C strings (null term) */
	/*---------------------------------------------------------------*/
        dbstring("Santa Pedro", 13, tmpbuf);
        printf("Function: \tdbstring() \toutput: %s\n", tmpbuf);
 
	/*-------------------------------------------------*/
        /* DBKEYTOA() - converts an extracted key to ASCII */
	/*-------------------------------------------------*/
        tmpbuf[0] = 0;		/* Number of dec. places */
        tmpbuf[1] = 'N';	/* Key Type              */
        rc = dbkeytoa(key, tmpbuf);
        errorproc("dbkeytoa()", "key converted.", rc);
 
        /*-----------------------------------------------*/
        /* Perform record/index deletion and file access */
        /*-----------------------------------------------*/
 
	/*-------------------------------------------*/
        /* DBSIZE() - retrieve the size of the table */
	/*-------------------------------------------*/
        rc = dbsize(dbf, &db_size);
        errorproc("dbsize()", "size retrieved.", rc);
        printf("\t        No. of Records: \t%d\n", db_size);
 
	/*---------------------------------------------------------------*/
        /* DBPUTR() - adds a record to the end of the table              */
        /*            You can also 'insert' a record using this function */
	/*---------------------------------------------------------------*/
        rc = dbputr(dbf, db_size + 1L, text_table[7]);
        errorproc("dbputr()", "record placed.", rc);
        rc = dbakey(ndx,"Unknown Vessel    " , db_size + 1L);
        errorproc("dbakey()",  "key added.", rc);
        rc = dbxakey(dbx, db_size + 1L);
        errorproc("dbxakey()",  "key added.", rc);
 
        dbflush(dbf);                   /* Good Habit on shared files */
        dbiflsh(ndx);
	dbxflsh(dbx);
 
	/*----------------------------------------------------*/
        /* DBDELETE() - mark a record (number 8) for deletion */
	/*----------------------------------------------------*/
        rc = dbdelete(dbf, 8L);
        errorproc("dbdelete()", "record 8 marked for deletion.", rc);
 
	/*-------------------------------------------------------------*/
        /* DBRECALL() - recall a record marked for deletion (number 8) */
	/*-------------------------------------------------------------*/
        rc = dbrecall(dbf, 8L);
        errorproc("dbrecall()", "record 8 recalled.", rc);
 
	/*------------------------------------------------------------------*/
        /* DBRMVKEY() - physically remove a key.  As of v8.0, this function */
	/*              is not permitted on tables opened shareable.        */
	/*------------------------------------------------------------------*/
        /* rc = dbrmvkey(ndx, "Unknown Vessel    ", db_size+1L);            */
        /* errorproc("dbrmvkey()", "key physically removed.", rc);          */
 
	/*------------------------------------------------------------------*/
        /* DBRMVR() - physically remove a data record. As of v8.0 this      */
	/*            function is not permitted on tables opened shareable. */
	/*------------------------------------------------------------------*/
        /* rc = dbrmvr(dbf, db_size+1L);                                    */
        /* errorproc("dbrmvr()", "record 7 physically removed.", rc);       */
 
	/*------------------------------------*/
        /* DBUNLOCKF() - unlocks a table file */
	/*------------------------------------*/
        rc = dbunlockf(dbf);
        if ( rc == SUCCESS ) {
            printf("Function: \tdbunlockf() \tFile unlocked successfully\n");
        } else {
            printf("Unlock Failed. \tError: %d\n", rc);
	}
 
	/*-------------------------------------*/
        /* DBUNLOCKI() - unlocks an index file */
	/*-------------------------------------*/
        rc = dbunlocki(ndx);
        if ( rc == SUCCESS ) {
            printf("Function: \tdbunlocki() \tFile unlocked successfully\n");
        } else {
            printf("Unlock Failed. \tError: %d\n", rc);
	}
 
	/*---------------------------------------------------------------*/
        /* DBLOCKR() - tests available record locking in a multiuser     */
        /*              environment.  Same as DBTLOCKR() in multi access */
	/*---------------------------------------------------------------*/
        rc = dblockr(dbf, (long)7);
        if ( rc == SUCCESS ) {
            printf("Function: \tdblockr() \trecord locked successfully.\n");
        } else {
            printf("Lock Failed. \tError: %d\n", rc);
	}
 
	/*--------------------------------------*/
        /* DBUNLOCKR() - unlocks a table Record */
	/*--------------------------------------*/
        rc = dbunlockr(dbf, (long)7);
        if ( rc == SUCCESS ) {
            printf("Function \tdbunlockr(): \trecord unlocked successfully\n");
        } else {
            printf("Unlock Failed. \tError: %d\n", rc);
	}
 
 
        /*--------------------------------------*/
        /* Perform record/index close functions */
        /*--------------------------------------*/
 
	/*-------------------------------------*/
        /* DBICLOSE() - close the active index */
	/*-------------------------------------*/
        rc = dbiclose(ndx);
        errorproc("dbiclose()", "index closed.", rc);
 
	/*--------------------------------------------*/
        /* DBXCLOSE() - close the active tagged index */
	/*--------------------------------------------*/
        rc = dbxclose(dbx);
        errorproc("dbxclose()", "tagged index closed.", rc);
 
	/*------------------------------------*/
        /* DBCLOSE() - close the active table */
	/*------------------------------------*/
        rc = dbclose(dbf);
        errorproc("dbclose()", "table closed.", rc);
 
	/*------------------------------------------*/
        /* DBMCLOSE() - close the active memo table */
	/*------------------------------------------*/
        rc = dbmclose(dbt);
        errorproc("dbmclose()", "memo table closed.", rc);
 
 
        /*-------------------------------------------------*/
        /* Perform miscellaneous Recital/Library functions */
        /*-------------------------------------------------*/
 
	/*-----------------------------------------------------------*/
        /* DBONERROR() - enables/disables (1/0) recovery from errors */
	/*-----------------------------------------------------------*/
        dbonerror(0);                           /* Recovery disabled */
        printf("Function: \tdbonerror()  \terror checking disabled\n");
 
        printf("\nEnd of Recital C Library test program....\n");
 
        exit(0);
 
}
 
 
 
/*----------------------------------------------------------------------*/
/* This procedure handles the return codes from called RECITAL/library  */
/* functions.  Intended to eliminate cryptic  'if...else...' statements */
/* following library calls.                                             */
/*----------------------------------------------------------------------*/
 
static void errorproc(func, str, rc)
char    *func;
char    *str;
int     rc;
{
        if ( rc != SUCCESS )  {
            printf("\n  Error performing function %s -> %d\n", func, rc);
            exit(1);
        }
        printf("Function: \t%s, \t%s - Ok\n", func,str);
        return;
}