gCAD3D 2.40
ut_dbf.c File Reference

save retrieve key-value-Records in file More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Data Structures

struct  hdrDBF
 

Macros

#define SizkDBF   1024
 

Functions

int DBF_init (char *fNam)
 
int DBF_add__ (char *key, int keySiz, char *val, int valSiz)
 
int DBF_find__ (int *sizVal, char *key, int sizKey)
 
int DBF_find_nxt (char **foundKey, int *sizFoundKey, int *sizVal, char *findKey, int sizKey, int *iStart)
 
int DBF_getNxtKey (char **key, int *sizKey)
 
int DBF_getVal (void *val, int *sizVal)
 
int DBF_dump ()
 

Variables

static FILE * fDBF = NULL
 
static int DBF_stat
 
static hdrDBF hDBF
 
static int iDBF = -1
 
static int nDBF = 0
 
static char kDBF [SizkDBF+4]
 

Detailed Description

save retrieve key-value-Records in file

=====================================================
List_functions_start:
DBF_init open DataBaseFile
DBF_add__ add a new record
// DBF_add_uniq test if key already exists;
DBF_find_key find key; exact.
DBF_find_nxt find key; wildcard. Test if key starts with findKey
DBF_find__ find key
DBF_getNxtKey get key next record
DBF_getVal get the value of the active record
// DBF_mod modify active record
DBF_dump dump whole DBF
List_functions_end:
=====================================================

Macro Definition Documentation

#define SizkDBF   1024

Function Documentation

int DBF_init ( char *  fNam)

DBF_init open DataBaseFile

int DBF_add__ ( char *  key,
int  keySiz,
char *  val,
int  valSiz 
)
* DBF_add__ add a new record
* keySiz must not exceed SizkDBF
* RetCod: -1 keySiz > SizkDBF
* -2 no DBF_init
*
int DBF_find__ ( int *  sizVal,
char *  key,
int  sizKey 
)
* DBF_find__ find key; is active record if found
* Output:
* sizVal size of value; padded with max 3 0-bytes (to a multiple of 4)
* RetCod: -1 key not found
* else recordnumber of found record; is now the active record.
* Get value with DBF_getVal
*
int DBF_find_nxt ( char **  foundKey,
int *  sizFoundKey,
int *  sizVal,
char *  findKey,
int  sizKey,
int *  iStart 
)
* DBF_find_nxt find key; wildcard. Test if key starts with findKey
* Input:
* iStart must be set to 0 at start; do not modify.
* RetCod: -1 key not found
* -2 file not found
* >=0 recordnumber of found record; is now the active record.
*
* Example:
* // find all records starting with "abc"
* ii = 0;
* while (DBF_find_nxt (1, "abc", 3, &ii) >= 0) {
* i1 = 240; DBF_getVal ((void*)s2, &i1); // get value
* }
*
int DBF_getNxtKey ( char **  key,
int *  sizKey 
)
* read next key (and record-header)
* Output:
* key a pointer to key
* sizKey size of key in bytes
* RetCod recordnumber; first = 0
* -1 file empty or damaged
*
int DBF_getVal ( void *  val,
int *  sizVal 
)
* get the value of the active record
* Input:
* sizVal size of array val in bytes
* Output:
* val the value of the active record
* sizVal size of value; padded with max 3 0-bytes (to a multiple of 4)
*
int DBF_dump ( )

DBF_dump dump whole DBF

Variable Documentation

FILE* fDBF = NULL
static
int DBF_stat
static
hdrDBF hDBF
static
int iDBF = -1
static
int nDBF = 0
static
char kDBF[SizkDBF+4]
static