Modificati commenti da C++ a C. Corretta DB_seek e DB_rewrite.
git-svn-id: svn://10.65.10.50/trunk@1555 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
ae730cd65f
commit
e1bca3bd19
106
include/codeb.c
106
include/codeb.c
@ -37,7 +37,7 @@
|
|||||||
#include <codeb.h>
|
#include <codeb.h>
|
||||||
#include <rectypes.h>
|
#include <rectypes.h>
|
||||||
#include <progind.h>
|
#include <progind.h>
|
||||||
#define MAXLEN 128 // Lunghezza massima chiave
|
#define MAXLEN 128 /* Lunghezza massima chiave */
|
||||||
|
|
||||||
extern char* CUpString(char *);
|
extern char* CUpString(char *);
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ int DB_open(const char *filename,int mode)
|
|||||||
int i,found;
|
int i,found;
|
||||||
|
|
||||||
if (mode) code_base.exclusive=1;
|
if (mode) code_base.exclusive=1;
|
||||||
// cerca il primo posto libero nel vettore dbdata
|
/* cerca il primo posto libero nel vettore dbdata */
|
||||||
found=-1;
|
found=-1;
|
||||||
for(i=0;i<CB4FILES;i++) {
|
for(i=0;i<CB4FILES;i++) {
|
||||||
if(dbdata[i]==(DATA4 *) 0) {
|
if(dbdata[i]==(DATA4 *) 0) {
|
||||||
@ -119,7 +119,7 @@ int DB_open(const char *filename,int mode)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// se non ci sono posti liberi torna -1
|
/* se non ci sono posti liberi torna -1 */
|
||||||
if(found==-1) return(found);
|
if(found==-1) return(found);
|
||||||
code_base.error_code=0;
|
code_base.error_code=0;
|
||||||
dbdata[found]=d4open(&code_base,(char*)filename);
|
dbdata[found]=d4open(&code_base,(char*)filename);
|
||||||
@ -172,10 +172,10 @@ int DB_reclen(int handle)
|
|||||||
int DB_keylen(int handle)
|
int DB_keylen(int handle)
|
||||||
{
|
{
|
||||||
TAG4 *t;
|
TAG4 *t;
|
||||||
|
|
||||||
if (dbdata[handle]==0) return(-1);
|
if (dbdata[handle]==0) return(-1);
|
||||||
if ((t=d4tag_default(dbdata[handle]))== NULL) return (-1);
|
if ((t=d4tag_default(dbdata[handle]))== NULL) return (-1);
|
||||||
return(strlen(t4key(t)));
|
return(expr4key_len(t->expr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
@ -206,7 +206,7 @@ int DB_tagselect(int handle,int index_no)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(dbdata[handle]==0) return(-1);
|
if(dbdata[handle]==0) return(-1);
|
||||||
// si posiziona sul primo indice
|
/* si posiziona sul primo indice */
|
||||||
tt=d4tag_next(dbdata[handle],NULL);
|
tt=d4tag_next(dbdata[handle],NULL);
|
||||||
if(tt==NULL) return(-1);
|
if(tt==NULL) return(-1);
|
||||||
for(i=1;i<index_no;i++) {
|
for(i=1;i<index_no;i++) {
|
||||||
@ -219,7 +219,7 @@ int DB_tagselect(int handle,int index_no)
|
|||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
torna il nuemero dell'indice selezionato
|
torna il numero dell'indice selezionato
|
||||||
torna -1 se errore
|
torna -1 se errore
|
||||||
--------------------------------------------------------------------------*/
|
--------------------------------------------------------------------------*/
|
||||||
int DB_tagget(int handle)
|
int DB_tagget(int handle)
|
||||||
@ -228,7 +228,7 @@ int DB_tagget(int handle)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(dbdata[handle]==0) return(-1);
|
if(dbdata[handle]==0) return(-1);
|
||||||
// si posiziona sul primo indice
|
/* si posiziona sul primo indice */
|
||||||
tt=d4tag_selected(dbdata[handle]);
|
tt=d4tag_selected(dbdata[handle]);
|
||||||
if(tt==NULL) return(-1);
|
if(tt==NULL) return(-1);
|
||||||
|
|
||||||
@ -325,11 +325,9 @@ int DB_seek(int handle,char *key)
|
|||||||
return rc;
|
return rc;
|
||||||
tt = d4tag_selected(dbdata[handle]);
|
tt = d4tag_selected(dbdata[handle]);
|
||||||
len = expr4key_len(tt->expr);
|
len = expr4key_len(tt->expr);
|
||||||
k = strdup(t4key(tt));
|
k = t4key(tt);
|
||||||
while (--len >= 0 && k[len] == ' ')
|
while (len > 0 && k[len-1] == ' ') len--;
|
||||||
k[len] = '\0';
|
rc = strncmp(key, k, len);
|
||||||
rc = strcmp(key, k);
|
|
||||||
free(k);
|
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
@ -367,7 +365,7 @@ int DB_go(int handle,long int recno)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
cancella il record attuale
|
cancella il record attuale. Non cancella le chiavi.
|
||||||
--------------------------------------------------------------------------*/
|
--------------------------------------------------------------------------*/
|
||||||
int DB_delete(int handle)
|
int DB_delete(int handle)
|
||||||
{
|
{
|
||||||
@ -397,13 +395,13 @@ int DB_delkey(int handle, char* key, long recno)
|
|||||||
INDEX4* i;
|
INDEX4* i;
|
||||||
TAG4* t;
|
TAG4* t;
|
||||||
int rt=0;
|
int rt=0;
|
||||||
char fn[32];
|
char fn[64];
|
||||||
|
|
||||||
if(dbdata[handle]==0) return(-1);
|
if(dbdata[handle]==0) return(-1);
|
||||||
t=d4tag_default(dbdata[handle]);
|
t=d4tag_default(dbdata[handle]);
|
||||||
|
|
||||||
if (u4switch() & 2 || u4switch() & 8) // Clipper & DBIII
|
if (u4switch() & 2 || u4switch() & 8) /* Clipper & DBIII */
|
||||||
u4name_piece(fn,32,dbdata[handle]->file.name,0,0);
|
u4name_piece(fn,64,dbdata[handle]->file.name,0,0);
|
||||||
else
|
else
|
||||||
strcpy(fn,dbdata[handle]->file.name);
|
strcpy(fn,dbdata[handle]->file.name);
|
||||||
if ((i=d4index(dbdata[handle],fn)) == NULL)
|
if ((i=d4index(dbdata[handle],fn)) == NULL)
|
||||||
@ -424,7 +422,7 @@ int DB_rewrite(int handle)
|
|||||||
if(dbdata[handle]==0) return(-1);
|
if(dbdata[handle]==0) return(-1);
|
||||||
rt=d4write(dbdata[handle],d4recno(dbdata[handle]));
|
rt=d4write(dbdata[handle],d4recno(dbdata[handle]));
|
||||||
if (rt==r4success)
|
if (rt==r4success)
|
||||||
DB_unlock(handle);
|
rt=DB_unlock(handle);
|
||||||
return (rt);
|
return (rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,7 +465,7 @@ HIDDEN int is_inkey(RecDes *r, int numfield)
|
|||||||
HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info)
|
HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info)
|
||||||
{
|
{
|
||||||
int i,j;
|
int i,j;
|
||||||
char tiname[9]; // Tag name, max 8 characters long!
|
char tiname[9]; /* Tag name, max 8 characters long! */
|
||||||
|
|
||||||
strcpy(tiname,fname);
|
strcpy(tiname,fname);
|
||||||
CUpString(tiname);
|
CUpString(tiname);
|
||||||
@ -481,7 +479,7 @@ HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info)
|
|||||||
tag_info[i].unique=0;
|
tag_info[i].unique=0;
|
||||||
else
|
else
|
||||||
tag_info[i].unique=e4unique;
|
tag_info[i].unique=e4unique;
|
||||||
strcpy(tag_info[i].filter,""); // Not available for DBIII and CLIPPER
|
strcpy(tag_info[i].filter,""); /* Not available for DBIII and CLIPPER */
|
||||||
strcpy(tag_info[i].name,tiname) ;
|
strcpy(tag_info[i].name,tiname) ;
|
||||||
if (strlen(tiname) < 8)
|
if (strlen(tiname) < 8)
|
||||||
strcat(tag_info[i].name," ");
|
strcat(tag_info[i].name," ");
|
||||||
@ -489,15 +487,15 @@ HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info)
|
|||||||
for (j=0; j < r->Ky[i].NkFields; j++)
|
for (j=0; j < r->Ky[i].NkFields; j++)
|
||||||
{
|
{
|
||||||
int nf= r->Ky[i].FieldSeq[j];
|
int nf= r->Ky[i].FieldSeq[j];
|
||||||
if (nf > MaxFields) // When Upper field is specified
|
if (nf > MaxFields) /* When Upper field is specified */
|
||||||
{
|
{
|
||||||
nf -= MaxFields;
|
nf -= MaxFields;
|
||||||
strcat(tag_info[i].expression,"UPPER(");
|
strcat(tag_info[i].expression,"UPPER(");
|
||||||
}
|
}
|
||||||
if (r->Ky[i].FromCh[j] != 255) // When partial field is specified
|
if (r->Ky[i].FromCh[j] != 255) /* When partial field is specified */
|
||||||
strcat(tag_info[i].expression,"SUBSTR(");
|
strcat(tag_info[i].expression,"SUBSTR(");
|
||||||
|
|
||||||
switch (r->Fd[nf].TypeF) // When numeric field in key is specified
|
switch (r->Fd[nf].TypeF) /* When numeric field in key is specified */
|
||||||
{
|
{
|
||||||
case _intfld:
|
case _intfld:
|
||||||
case _longfld:
|
case _longfld:
|
||||||
@ -511,16 +509,16 @@ HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info)
|
|||||||
strcat(tag_info[i].expression,"DTOS(");
|
strcat(tag_info[i].expression,"DTOS(");
|
||||||
break;
|
break;
|
||||||
case _boolfld:
|
case _boolfld:
|
||||||
strcat(tag_info[i].expression,"IIF("); // Logical fields are in key too...
|
strcat(tag_info[i].expression,"IIF("); /* Logical fields are in key too.. */
|
||||||
break;
|
break;
|
||||||
default: // It's a non sense to keep _realfld in key...
|
default: /* It's a non sense to keep _realfld in key... */
|
||||||
break; // however it's possible to have it...
|
break; /* however it's possible to have it... */
|
||||||
} // Le chiavi composte da campi data non necessitano di funzioni di traduzione.
|
} /* Le chiavi composte da campi data non necessitano di funzioni di traduzione. */
|
||||||
|
|
||||||
strcat(tag_info[i].expression,r->Fd[nf].Name); // Append field name
|
strcat(tag_info[i].expression,r->Fd[nf].Name); /* Append field name */
|
||||||
|
|
||||||
if (r->Ky[i].FromCh[j] != 255) // If partial field was specified
|
if (r->Ky[i].FromCh[j] != 255) /* If partial field was specified */
|
||||||
{ // add parameters to SUBSTR
|
{ /* add parameters to SUBSTR */
|
||||||
char ts[8];
|
char ts[8];
|
||||||
|
|
||||||
strcat(tag_info[i].expression,",");
|
strcat(tag_info[i].expression,",");
|
||||||
@ -532,11 +530,11 @@ HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info)
|
|||||||
strcat(tag_info[i].expression,")");
|
strcat(tag_info[i].expression,")");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (r->Fd[nf].TypeF) // If numeric field was specified
|
switch (r->Fd[nf].TypeF) /* If numeric field was specified */
|
||||||
{ // add parameters to STR
|
{ /* add parameters to STR */
|
||||||
case _intfld:
|
case _intfld:
|
||||||
case _longfld:
|
case _longfld:
|
||||||
case _realfld: // Questo tipo di campo(real) non ha senso in un a chiave...
|
case _realfld: /* Questo tipo di campo(real) non ha senso in un a chiave... */
|
||||||
case _wordfld:
|
case _wordfld:
|
||||||
case _intzerofld:
|
case _intzerofld:
|
||||||
case _longzerofld:
|
case _longzerofld:
|
||||||
@ -548,17 +546,17 @@ HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info)
|
|||||||
strcat(tag_info[i].expression,",0)");
|
strcat(tag_info[i].expression,",0)");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _boolfld: // Orgssbb... Che culo.
|
case _boolfld:
|
||||||
strcat(tag_info[i].expression,",\"T\",\"F\")");
|
strcat(tag_info[i].expression,",\"T\",\"F\")");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close parentheses if UPPER or DTOS operators were used:
|
/* Close parentheses if UPPER or DTOS operators were used: */
|
||||||
if (r->Ky[i].FieldSeq[j] > MaxFields || (r->Fd[nf].TypeF == _datefld))
|
if (r->Ky[i].FieldSeq[j] > MaxFields || (r->Fd[nf].TypeF == _datefld))
|
||||||
strcat(tag_info[i].expression,")");
|
strcat(tag_info[i].expression,")");
|
||||||
// If there's another field in key adds "+" operator:
|
/* If there's another field in key adds "+" operator: */
|
||||||
if (j < (r->Ky[i].NkFields-1))
|
if (j < (r->Ky[i].NkFields-1))
|
||||||
strcat(tag_info[i].expression,"+");
|
strcat(tag_info[i].expression,"+");
|
||||||
}
|
}
|
||||||
@ -577,10 +575,12 @@ int DB_packfile(short vis, const char * filename, long eod)
|
|||||||
{
|
{
|
||||||
int rt=0,handle;
|
int rt=0,handle;
|
||||||
|
|
||||||
// if(dbdata[handle]==0) return(-1);
|
/*
|
||||||
// codebase.auto_open = 0 cosi' non apre gli indici
|
if(dbdata[handle]==0) return(-1);
|
||||||
|
codebase.auto_open = 0 cosi' non apre gli indici
|
||||||
|
*/
|
||||||
code_base.auto_open = 0;
|
code_base.auto_open = 0;
|
||||||
handle=DB_open(filename,1); // Exclusive mode open!
|
handle=DB_open(filename,1); /* Exclusive mode open! */
|
||||||
if (handle > -1)
|
if (handle > -1)
|
||||||
{
|
{
|
||||||
char s[81];
|
char s[81];
|
||||||
@ -625,9 +625,9 @@ int DB_packindex(short vis, const char * filename, RecDes *r, long *peod)
|
|||||||
strcpy(s,"Ricostruzione indici file : ");
|
strcpy(s,"Ricostruzione indici file : ");
|
||||||
strcat(s,filename);
|
strcat(s,filename);
|
||||||
|
|
||||||
// codebase.auto_open = 0 cosi' non apre gli indici
|
/* codebase.auto_open = 0 cosi' non apre gli indici */
|
||||||
code_base.auto_open=0 ;
|
code_base.auto_open=0 ;
|
||||||
handle=DB_open(filename,1); // Exclusive mode open
|
handle=DB_open(filename,1); /* Exclusive mode open */
|
||||||
if (handle > -1)
|
if (handle > -1)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -643,7 +643,7 @@ int DB_packindex(short vis, const char * filename, RecDes *r, long *peod)
|
|||||||
else
|
else
|
||||||
ff++;
|
ff++;
|
||||||
do_key(ff,r,tags);
|
do_key(ff,r,tags);
|
||||||
if (u4switch() &2 || u4switch() & 8) // Clipper and DBIII
|
if (u4switch() &2 || u4switch() & 8) /* Clipper and DBIII */
|
||||||
{
|
{
|
||||||
rt = (int)i4create(dbdata[handle],(char*)filename,tags);
|
rt = (int)i4create(dbdata[handle],(char*)filename,tags);
|
||||||
#ifndef FOXPRO
|
#ifndef FOXPRO
|
||||||
@ -666,7 +666,7 @@ int DB_packindex(short vis, const char * filename, RecDes *r, long *peod)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (u4switch() & 1 || u4switch() & 4) // FOXPRO and DBIV
|
if (u4switch() & 1 || u4switch() & 4) /* FOXPRO and DBIV */
|
||||||
{
|
{
|
||||||
rt = (int)i4create(dbdata[handle],NULL,tags);
|
rt = (int)i4create(dbdata[handle],NULL,tags);
|
||||||
#ifndef FOXPRO
|
#ifndef FOXPRO
|
||||||
@ -700,14 +700,14 @@ int DB_packindex(short vis, const char * filename, RecDes *r, long *peod)
|
|||||||
int DB_build(const char * filename, RecDes *r)
|
int DB_build(const char * filename, RecDes *r)
|
||||||
{
|
{
|
||||||
|
|
||||||
FIELD4INFO field_info[MaxFields+1]; // Numero di campi in un record
|
FIELD4INFO field_info[MaxFields+1]; /* Numero di campi in un record */
|
||||||
TAG4INFO tag_info[MaxKeys+1]; // Numero di chiavi in un file
|
TAG4INFO tag_info[MaxKeys+1]; /* Numero di chiavi in un file */
|
||||||
DATA4 *dbuilded;
|
DATA4 *dbuilded;
|
||||||
int rt=0,i;
|
int rt=0,i;
|
||||||
char *ff = find_slash_backslash((char *)filename);
|
char *ff = find_slash_backslash((char *)filename);
|
||||||
|
|
||||||
|
|
||||||
for (i=0; ((i<r->NFields) && (i<MaxFields)); i++) // Construct field_info
|
for (i=0; ((i<r->NFields) && (i<MaxFields)); i++) /* Construct field_info */
|
||||||
{
|
{
|
||||||
field_info[i].name = (char*)u4alloc(12);
|
field_info[i].name = (char*)u4alloc(12);
|
||||||
strcpy(field_info[i].name,r->Fd[i].Name);
|
strcpy(field_info[i].name,r->Fd[i].Name);
|
||||||
@ -717,7 +717,7 @@ int DB_build(const char * filename, RecDes *r)
|
|||||||
{
|
{
|
||||||
case _intfld:
|
case _intfld:
|
||||||
case _longfld:
|
case _longfld:
|
||||||
case _realfld: // It's a non sense to keep this in key!
|
case _realfld: /* It's a non sense to keep this in key! */
|
||||||
case _wordfld:
|
case _wordfld:
|
||||||
case _intzerofld:
|
case _intzerofld:
|
||||||
case _longzerofld:
|
case _longzerofld:
|
||||||
@ -746,11 +746,11 @@ int DB_build(const char * filename, RecDes *r)
|
|||||||
ff++;
|
ff++;
|
||||||
do_key(ff,r,tag_info);
|
do_key(ff,r,tag_info);
|
||||||
|
|
||||||
if ((dbuilded=d4create(&code_base, (char *)filename, field_info, tag_info))==0) // deve solo creare il file dati vuoto
|
if ((dbuilded=d4create(&code_base, (char *)filename, field_info, tag_info))==0) /* deve solo creare il file dati vuoto */
|
||||||
rt=code_base.error_code;
|
rt=code_base.error_code;
|
||||||
else
|
else
|
||||||
rt=d4close(dbuilded);
|
rt=d4close(dbuilded);
|
||||||
if (u4switch() & 2 || u4switch() & 8) // Rebuild filename.cgp for CLIPPER AND DBIII only
|
if (u4switch() & 2 || u4switch() & 8) /* Rebuild filename.cgp for CLIPPER AND DBIII only */
|
||||||
{
|
{
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
char xx[81];
|
char xx[81];
|
||||||
@ -857,7 +857,7 @@ char* DB_index_getkey(int handle)
|
|||||||
if ((t=d4tag_default(dbdata[handle]))==NULL) return(NULL);
|
if ((t=d4tag_default(dbdata[handle]))==NULL) return(NULL);
|
||||||
klen=expr4key_len(t->expr);
|
klen=expr4key_len(t->expr);
|
||||||
if (klen > (MAXLEN-1)) klen=MAXLEN-1;
|
if (klen > (MAXLEN-1)) klen=MAXLEN-1;
|
||||||
memcpy(key,t4key(t),klen); // t4key non restituisce una null terminated string
|
memcpy(key,t4key(t),klen); /* t4key non restituisce una null terminated string */
|
||||||
key[klen]='\0';
|
key[klen]='\0';
|
||||||
return(key);
|
return(key);
|
||||||
}
|
}
|
||||||
@ -923,11 +923,11 @@ long DB_getconf()
|
|||||||
long DB_changed(int handle)
|
long DB_changed(int handle)
|
||||||
{
|
{
|
||||||
INDEX4 *i;
|
INDEX4 *i;
|
||||||
char fn[32];
|
char fn[64];
|
||||||
|
|
||||||
if(dbdata[handle]==0) return(-1);
|
if(dbdata[handle]==0) return(-1);
|
||||||
if (u4switch() & 2 || u4switch() & 8) // Clipper & DBIII
|
if (u4switch() & 2 || u4switch() & 8) /* Clipper & DBIII */
|
||||||
u4name_piece(fn,32,dbdata[handle]->file.name,0,0);
|
u4name_piece(fn,64,dbdata[handle]->file.name,0,0);
|
||||||
else
|
else
|
||||||
strcpy(fn,dbdata[handle]->file.name);
|
strcpy(fn,dbdata[handle]->file.name);
|
||||||
i=d4index(dbdata[handle],fn);
|
i=d4index(dbdata[handle],fn);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user