From 980fbadf0b72638f7532ff525fec45c1585e571a Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 12 Mar 2004 14:52:53 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://10.65.10.50/trunk@11841 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/array.cpp | 12 +- include/array.h | 4 +- include/assoc.cpp | 11 +- include/automask.cpp | 1 - include/bagn005.h | 2 +- include/bagn006.h | 2 +- include/ccommon.h | 9 +- include/ccustio.c | 44 +- include/ccustio.h | 2 +- include/cfiles.c | 84 ++- include/codeb.c | 1276 +----------------------------------------- include/colors.cpp | 4 +- 12 files changed, 117 insertions(+), 1334 deletions(-) diff --git a/include/array.cpp b/include/array.cpp index ca85a2062..2e19f7725 100755 --- a/include/array.cpp +++ b/include/array.cpp @@ -179,19 +179,19 @@ bool TArray::destroy( TArray::TArray(int arraysize) - : _size(0), _items(0), _next(0), _data(NULL) + : _data(NULL), _size(0), _items(0), _next(0) { if (arraysize) resize(arraysize); } TArray::TArray() - : _size(0), _items(0), _next(0), _data(NULL) + : _data(NULL), _size(0), _items(0), _next(0) { } TArray::TArray(const TArray& a) - : _size(0), _items(0), _next(0), _data(NULL) + : _data(NULL), _size(0), _items(0), _next(0) { (*this) = a; } @@ -629,7 +629,7 @@ int TPointer_array::insert(const TObject& object, int index, bool force) /////////////////////////////////////////////////////////// TBit_array::TBit_array(long size) - : _bit(NULL), _size(0) + : _size(0), _bit(NULL) { if (size) resize(index(size)); @@ -653,7 +653,7 @@ void TBit_array::copy( memcpy(_bit, ba._bit, _size); } -TBit_array::TBit_array(const TBit_array& ba) : _bit(NULL), _size(0) +TBit_array::TBit_array(const TBit_array& ba) : _size(0), _bit(NULL) { copy(ba); } TBit_array& TBit_array::operator=(const TBit_array& ba) @@ -747,7 +747,7 @@ void TBit_array::reset(long n) } // Certified 99% -void TBit_array::not(long n) +void TBit_array::neg(long n) { const word i = index(n); if (i >= _size) resize(i); diff --git a/include/array.h b/include/array.h index 5c9fd3bdf..ada4a0e5c 100755 --- a/include/array.h +++ b/include/array.h @@ -208,7 +208,7 @@ inline TObject& TArray::operator[] (int index) const #define FOR_EACH_ARRAY_ITEM(__arr, __r, __obj) \ TObject* __obj; \ for (int __r = __arr.first(); \ - __obj = __arr.objptr(__r); \ + (__obj = __arr.objptr(__r)); \ __r = __arr.succ(__r)) #define FOR_EACH_ARRAY_ITEM_BACK(__arr, __r, __obj) \ @@ -309,7 +309,7 @@ public: // @cmember Setta a 0 il bit n-esimo dell'array void reset(long n); // @cmember Not logico del bit n-esimo dell'array - void not(long n); + void neg(long n); // @cmember Setta il bit n-esimo a seconda del valore passato come secondo elemento void set(long n, bool on) { on ? set(n) : reset(n); } diff --git a/include/assoc.cpp b/include/assoc.cpp index 89fbd6427..66b3c8529 100755 --- a/include/assoc.cpp +++ b/include/assoc.cpp @@ -43,8 +43,9 @@ THash_object* TAssoc_array::_lookup( TArray& arr = bucket(hv); THash_object* o = NULL; isnew = FALSE; + int i; - for (int i = 0; i < arr.items(); i++) + for (i = 0; i < arr.items(); i++) { THash_object* ob = (THash_object*)arr.objptr(i); if (ob->_key == key) @@ -198,7 +199,7 @@ bool TAssoc_array::add(const char* key, const TObject& obj, bool force) { // Non inserire l'Hash_object se non lo trovi (ci pensa la add sotto) bool isnew = FALSE; - THash_object* o = _lookup(key,isnew,FALSE); + _lookup(key,isnew,FALSE); if (!isnew && !force) return TRUE; return add(key,obj.dup(),force); @@ -221,7 +222,9 @@ bool TAssoc_array::remove( const word hv = key.hash() % HASH_SIZE; TArray& arr = bucket(hv); THash_object* o = NULL; - for (int i = 0; i < arr.items(); i++) + int i; + + for (i = 0; i < arr.items(); i++) { THash_object* ob = (THash_object*)&arr[i]; if (ob->_key == key) @@ -349,7 +352,7 @@ int TAssoc_array::get_keys(TString_array& kl, bool add_values) restart(); THash_object* o = NULL; TString tmp(80); - while (o = get_hashobj()) + while ((o = get_hashobj())) { TToken_string* tt = new TToken_string(o->key()); if (add_values) diff --git a/include/automask.cpp b/include/automask.cpp index d497e1d21..b022e7a17 100755 --- a/include/automask.cpp +++ b/include/automask.cpp @@ -60,7 +60,6 @@ TField_event TAutomask::key2event(TMask_field& f, KEY key) const case K_SPACE: if (!f.is_edit()) { - const TMask& wm = f.mask(); if (f.is_kind_of(CLASS_BUTTON_FIELD)) fe = fe_button; else if (f.is_kind_of(CLASS_TREE_FIELD)) diff --git a/include/bagn005.h b/include/bagn005.h index 60676a707..4b601bf31 100755 --- a/include/bagn005.h +++ b/include/bagn005.h @@ -1,4 +1,4 @@ #define F_STRING 101 #define F_DIRECT 102 #define F_REGEXP 104 -#define F_CASE 103 \ No newline at end of file +#define F_CASE 103 diff --git a/include/bagn006.h b/include/bagn006.h index 3a533e31b..5f54283b0 100755 --- a/include/bagn006.h +++ b/include/bagn006.h @@ -5,4 +5,4 @@ #define S_FILE 101 #define S_ALIAS 102 -#define S_LINK 103 \ No newline at end of file +#define S_LINK 103 diff --git a/include/ccommon.h b/include/ccommon.h index c935225c2..bcc8f4ce0 100755 --- a/include/ccommon.h +++ b/include/ccommon.h @@ -83,13 +83,15 @@ #define ntrrec "trc.gen" #define nditta "dta.gen" +#ifndef __STDTYPES_H typedef unsigned char byte; +#endif typedef char Str8[9]; typedef char Str25[26]; typedef char Str30[32]; typedef char Str80[82]; typedef char Str255[256]; -typedef byte StCh[256]; +typedef byte StCh[256]; typedef long TrDate; typedef char PathSt[82]; @@ -99,10 +101,7 @@ extern Str80 cprefix; #ifdef __cplusplus extern "C" { #endif - char *esc(char *); - - - int CIOResult(void ); + int CIOResult(void ); #ifdef WIN32 void tmpfname(char *,char *); #endif diff --git a/include/ccustio.c b/include/ccustio.c index 71bb9804e..4c95ace78 100755 --- a/include/ccustio.c +++ b/include/ccustio.c @@ -1,21 +1,15 @@ #include "ccustio.h" - -#include "checks.h" - +#include #ifdef WIN32 #include -#endif - -#include - -#ifdef LINUX -#include -#include -#include -#else #include #include #include +#else +#include "../xvaga/xvt.h" +#include +#include +#include #endif #define CalcPos(Rec, Len, Base) (((Rec) - 1) * ((RecNoType) (Len)) + ((RecNoType) (Base))) @@ -25,8 +19,8 @@ #define LOCKSEM "locksem" /* extern long lseek(int, long, int);*/ -extern int chsize(int, long); -extern int lockf(int, int, long); +// extern int chsize(int, long); +// extern int lockf(int, int, long); #endif unsigned setlock(unsigned); @@ -262,8 +256,13 @@ void CCreate(S, Name, Len, Base, MaxSec) if ((S->F = open(Name, O_RDWR | O_CREAT, 0666)) == -1) #endif if ((S->IOR = CIOResult()) != NoErr) return ; +#ifdef WIN32 if (chsize(S->F, ((RecNoType) MaxSec)*BlockLenIO) == -1) - S->IOR = CIOResult(); +#else + if (lseek(S->F, ((RecNoType) MaxSec)*BlockLenIO, SEEK_SET) == -1) +#endif + S->IOR = CIOResult(); + if (close(S->F) == -1) { junk = CIOResult(); @@ -300,7 +299,12 @@ void CChsize(S, Name, Len, Base, MaxSec) if ((S->F = open(Name, O_RDWR, 0666)) == -1) #endif if ((S->IOR = CIOResult()) != NoErr) return ; - if (chsize(S->F, ((RecNoType) MaxSec)*BlockLenIO) == -1) +#ifdef WIN32 + if (chsize(S->F, ((RecNoType) MaxSec)*BlockLenIO) == -1)#else +#else + if (lseek(S->F, ((RecNoType) MaxSec)*BlockLenIO, SEEK_SET) == -1) +#endif + S->IOR = CIOResult(); if (close(S->F) == -1) { @@ -731,9 +735,7 @@ void VS(sid) sid = identificatore del semaforo su locksem. - errno = numero errore. - - sb = struttura che contiene informazioni sullo stato del file (vedi "stat"). + errno = codice errore. @(FSV) */ @@ -747,7 +749,6 @@ int excllock(name,excl) char path[200], dir[200]; int fd, junk, sid; extern int errno; - struct stat sb; strcpy(path, lockpath(name)); strcpy(dir, dirname(path)); @@ -755,7 +756,8 @@ int excllock(name,excl) if (semres == -1) return(-1); PS(sid); if (semres == -1) return(-1); - if ((stat(dir, &sb) == -1) && (errno == ENOENT)) CMkDir(dir); + if (xvt_fsys_access(dir, F_OK) == ENOENT) + xvt_fsys_mkdir(dir); if (((fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0666)) == -1) && errno == EEXIST) { diff --git a/include/ccustio.h b/include/ccustio.h index f1b8a6a69..542421076 100755 --- a/include/ccustio.h +++ b/include/ccustio.h @@ -49,7 +49,7 @@ typedef struct { #define TESTLOCK(x) ((x) == 13 || (x) == 11) #define DEADLOCK(x) ((x) == EDEADLOCK) #else -#define TESTLOCK(x) (((x) == EACCES) || ((x) == EGAIN) || ((x) == ENOLCK)) +#define TESTLOCK(x) (((x) == EACCES) || ((x) == ENOLCK)) #define DEADLOCK(x) (((x) == EDEADLOCK) || ((x) == EDEADLK)) #endif #define BLOCKEXT(len,rec) (((((RecNoType) (len)) * ((RecNoType) (rec))) / BlockLenIO) + 1) diff --git a/include/cfiles.c b/include/cfiles.c index 08bea075d..32836f2ba 100755 --- a/include/cfiles.c +++ b/include/cfiles.c @@ -2,6 +2,11 @@ #include +#ifdef LINUX +extern const char * _c_user; +extern BOOLEAN _is_admin; +#endif + #include "cfiles.h" int dirfl[2] = {0, 0}, recfl[2] = {0, 0} ; @@ -390,8 +395,8 @@ int CGetCampoStpValue(const char* name, char* value, int valsize) break; } } -#endif +#endif return bFound; } @@ -413,13 +418,15 @@ const char* CGetCampoIni(void) static char* prawin = NULL; if (prawin == NULL) { - BOOLEAN bFound = FALSE; -#ifdef WIN32 - // Nelle installazioni sfigate con programmi in rete cerca di stabilire il percorso locale di Campo.ini - DIRECTORY dir; char exedir[_MAX_PATH], path[_MAX_PATH]; + DIRECTORY dir; + + // Nelle installazioni sfigate con programmi in rete cerca di stabilire il percorso locale di Campo.ini xvt_fsys_get_default_dir(&dir); xvt_fsys_convert_dir_to_str(&dir, exedir, sizeof(exedir)); +#ifdef WIN32 + BOOLEAN bFound = FALSE; + if (xvt_fsys_is_network_drive(exedir)) { bFound = CGetCampoStpValue("CampoIni", path, sizeof(path)); @@ -435,14 +442,9 @@ const char* CGetCampoIni(void) } } } -#endif if (!bFound) { -#ifdef LINUX - char ininame[32]; - sprintf(ininame, "campo%u", getuid()); - xvt_fsys_build_pathname(path, NULL, exedir, ininame, "ini", NULL); -#else +#endif xvt_fsys_build_pathname(path, NULL, exedir, "campo", "ini", NULL); if (! xvt_fsys_file_exists(path)) { @@ -450,8 +452,9 @@ const char* CGetCampoIni(void) sprintf(msg, "Impossibile aprire '%s'", (const char *)path); xvt_dm_post_fatal_exit(msg); } -#endif +#ifdef WIN32 } +#endif prawin = xvt_str_duplicate(path); } return prawin; @@ -463,12 +466,31 @@ HIDDEN BOOLEAN CGetFirmDir() BOOLEAN good = xvt_fsys_file_exists(prawin); if (good) { - const int len = xvt_sys_get_profile_string(prawin, "Main", "Study", "", __ptprf, sizeof(__ptprf)); - good = len > 0; + int len = 0; +#ifdef LINUX + good = FALSE; + if (!_is_admin) + { + char varname[80]; + sprintf(varname, "Study[%s]", _c_user); + len = xvt_sys_get_profile_string(prawin, "Main", varname, "", __ptprf, sizeof(__ptprf)); + good = len > 0; + } + if (!good) + { +#endif + len = xvt_sys_get_profile_string(prawin, "Main", "Study", "", __ptprf, sizeof(__ptprf)); + good = len > 0; +#ifdef LINUX + } +#endif if (good) { char firm[8]; long ditta; +#ifdef LINUX + char path[_MAX_PATH], user[80]; +#endif if (__ptprf[len-1] != '\\' && __ptprf[len-1] != '/') { @@ -476,9 +498,16 @@ HIDDEN BOOLEAN CGetFirmDir() __ptprf[len+1] = '\0'; } - xvt_sys_get_profile_string(prawin, "Main", "Firm", "COM", firm, sizeof(firm)); +#ifdef LINUX + strcpy(user, _c_user), + xvt_str_make_lower(user); + sprintf(path, "%sconfig%c%s.ini", __ptprf, DIRSEP, user); + len = xvt_sys_get_profile_string(path, "Main", "Firm", "", firm, sizeof(firm)); + if (len == 0) +#endif + xvt_sys_get_profile_string(prawin, "Main", "Firm", "com", firm, sizeof(firm)); ditta = atol(firm); - if (ditta > 0) sprintf(firm, "%05ldA", ditta); + if (ditta > 0) sprintf(firm, "%05lda", ditta); xvt_fsys_build_pathname(cprefix, NULL, __ptprf, firm, NULL, NULL); } } @@ -489,8 +518,27 @@ HIDDEN BOOLEAN CGetFirmDir() BOOLEAN CPutFirmDir(const char* pref) { const char* prawin = CGetCampoIni(); +#ifdef LINUX + char path[_MAX_PATH], user[80]; + + strcpy(user, _c_user), + xvt_str_make_lower(user); + sprintf(path, "%sconfig%c%s.ini", __ptprf, DIRSEP, user); + BOOLEAN good = xvt_sys_set_profile_string(path, "Main", "Firm", pref); +#else BOOLEAN good = xvt_sys_set_profile_string(prawin, "Main", "Firm", pref); - xvt_sys_set_profile_string(prawin, "Main", "Study", __ptprf); +#endif + +#ifdef LINUX + if (!_is_admin) + { + char varname[80]; + sprintf(varname, "Study[%s]", _c_user); + xvt_sys_set_profile_string(prawin, "Main", varname, __ptprf); + } + else +#endif + xvt_sys_set_profile_string(prawin, "Main", "Study", __ptprf); return good; } @@ -516,7 +564,7 @@ const char* CGetPref() { if (!CGetFirmDir()) { - strcpy(cprefix, "COM"); + strcpy(cprefix, "com"); CPutFirmDir(cprefix); } return cprefix; diff --git a/include/codeb.c b/include/codeb.c index 851d76e09..10e322b34 100755 --- a/include/codeb.c +++ b/include/codeb.c @@ -14,8 +14,6 @@ */ -#ifdef CB6 - #define XVT_INCL_NATIVE #include @@ -483,7 +481,7 @@ int DB_lockfile(int handle) return(rt); } -HIDDEN int is_inkey(RecDes *r, int numfield) +/* HIDDEN int is_inkey(RecDes *r, int numfield) { int found=0,i,j; @@ -492,7 +490,7 @@ HIDDEN int is_inkey(RecDes *r, int numfield) if (numfield == r->Ky[i].FieldSeq[j]) found=1; return(found); -} +} */ HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info, int n_keys) { @@ -503,7 +501,7 @@ HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info, int n_keys) strcpy(tiname,fname); dot = strchr(tiname, '.'); if (dot) *dot = '\0'; - _strupr(tiname); + xvt_str_make_upper(tiname); for (i=0; ((i < MaxKeys) && (i < n_keys)); i++) { tag_info[i].name=(char *)u4alloc(9); @@ -948,7 +946,7 @@ int DB_recinfo(const char * filename, FileDes *d, RecDes *r, char* keys) for (i=0; ((iFd[i].Name,field_info[i].name); - _strupr(r->Fd[i].Name); + xvt_str_make_upper(r->Fd[i].Name); r->Fd[i].Len = (unsigned char)field_info[i].len; r->Fd[i].Dec = (unsigned char)field_info[i].dec; switch(field_info[i].type) @@ -1187,1269 +1185,3 @@ int DB_memowrite( const int handle, const char * fieldname, const char * data ) return ret; } -#endif - -#ifdef CB5 - -#define XVT_INCL_NATIVE -#include - -#if XVT_OS == XVT_OS_WIN32 - #define S4DLL - #define S4WIN32 -#else - #define S4UNIX -#endif - -#include - -#include -#include -#include -#include - -#define MAXLEN 137 /* Lunghezza massima chiave */ - -static CODE4 code_base; -static DATA4 *dbdata[CB4FILES]; - -bool handle_ok(int handle) -{ - return handle >=0 && handle < CB4FILES && dbdata[handle] !=0; -} - -static char * find_slash_backslash(const char * str) -{ - static char* xstr = NULL; - int l=strlen(str); - xstr = str + l; - - while (xstr-- && l--) - if (*xstr == '\\' || *xstr == '/') - break; - if (l == 0) - return NULL; - else - return xstr; -} - - -/*-------------------------------------------------------------------------- - funzione di filtro usata su tutti i database - --------------------------------------------------------------------------*/ -int S4CALL notdelete(void *fd) -{ - if(d4deleted(fd)) return r4ignore; - else return r4keep; -} - -/*-------------------------------------------------------------------------- - inizializzazione di CodeBase e delle variabili necessarie - questa funzione deve essere chiamata SOLO una volta all'interno - di ciascun eseguibile - --------------------------------------------------------------------------*/ -void DB_init(void) -{ - int i; - for(i=0;i 0) - d4top(dbdata[found]); - return(found); -} - - -/*------------------------------------------------------------------------- - chiusura del database inviduato da handle - torna -1 se il database non puo essere chiuso - --------------------------------------------------------------------------*/ -int DB_close(int handle) -{ - if(!handle_ok(handle)) return(-1); - d4close(dbdata[handle]); - dbdata[handle]=(DATA4 *) 0; - code_base.error_code=0; - return(0); -} - -/*------------------------------------------------------------------------- - torna il puntatore al buffer del record del database individuato da - handle. In caso di errore torna (char *) 0 - --------------------------------------------------------------------------*/ -char *DB_getrecord(int handle) -{ - if(!handle_ok(handle)) return((char *) 0); - return(d4record(dbdata[handle])); -} - -/*------------------------------------------------------------------------- - torna la lunghezza del record - --------------------------------------------------------------------------*/ -int DB_reclen(int handle) -{ - if(!handle_ok(handle)) return(-1); - return((int) d4record_width(dbdata[handle])); -} - -/*------------------------------------------------------------------------- - torna la lunghezza della chiave corrente - --------------------------------------------------------------------------*/ - -int DB_keylen(int handle) -{ - TAG4 *t; - - if (!handle_ok(handle)) return(-1); - if ((t=d4tag_default(dbdata[handle]))== NULL) return (-1); - return(expr4key_len(t->expr)); -} - -/*------------------------------------------------------------------------- - torna il numero del record attuale - --------------------------------------------------------------------------*/ -long int DB_recno(int handle) -{ - if(!handle_ok(handle)) return(-1L); - return(d4recno(dbdata[handle])); -} - -/*------------------------------------------------------------------------- - torna il numero complessivo dei records presenti nell'archivio - --------------------------------------------------------------------------*/ -long int DB_reccount(int handle) -{ - if(!handle_ok(handle)) return(-1L); - return(d4reccount(dbdata[handle])); -} - -/*------------------------------------------------------------------------- - seleziona un indice sul database specificato - torna -1 se errore, altrimenti 0 - --------------------------------------------------------------------------*/ -int DB_tagselect(int handle,int index_no) -{ - TAG4 *tt; - int i; - - if(!handle_ok(handle)) return(-1); - /* si posiziona sul primo indice */ - tt=d4tag_next(dbdata[handle],NULL); - if(tt==NULL) return(-1); - for(i=1;iexpr); - k = t4key(tt); - while (len > 0 && k[len-1] == ' ') len--; - rc = strncmp(key, k, len); - if (rc == 0) - return 0; - else - if (rc < 0) - return r4after; - else - return r4eof; -} - -/*------------------------------------------------------------------------- - torna 1 se eof, 0 altrimenti - --------------------------------------------------------------------------*/ -int DB_eof(int handle) -{ - if(!handle_ok(handle)) return(-1); - return(d4eof(dbdata[handle])); -} - -/*------------------------------------------------------------------------- - torna 1 se tof, 0 altrimenti - --------------------------------------------------------------------------*/ -int DB_bof(int handle) -{ - if(!handle_ok(handle)) return(-1); - return(d4bof(dbdata[handle])); -} - -/*------------------------------------------------------------------------- - legge un record per numero record - --------------------------------------------------------------------------*/ -int DB_go(int handle,long recno) -{ - if(!handle_ok(handle)) return(-1); -// return(d4go(&xdb[handle],recno)); - return(d4go(dbdata[handle],recno)); -} - -/*------------------------------------------------------------------------- - cancella il record attuale. Non cancella le chiavi. - --------------------------------------------------------------------------*/ -int DB_delete(int handle) -{ - - if(!handle_ok(handle)) return(-1); - d4delete(dbdata[handle]); - return(0); -} - -/*------------------------------------------------------------------------- - ripristina il record attuale - --------------------------------------------------------------------------*/ -int DB_recall(int handle) -{ - - if(!handle_ok(handle)) return(-1); - d4recall(dbdata[handle]); - return(0); -} - - -/*------------------------------------------------------------------------- - cancella dall'indice corrente la chiave specificata - --------------------------------------------------------------------------*/ -int DB_delkey(int handle, char* key, long recno) -{ - INDEX4* i; - TAG4* t; - int rt=0; - int is_locked = 0; /* Diverso da 0 se il file e' bloccato in modo esclusivo */ - /* (dati o indice) da me stesso*/ - char fn[64]; - - if(!handle_ok(handle)) return(-1); - t=d4tag_default(dbdata[handle]); - - if (u4switch() & 2 || u4switch() & 8) /* Clipper & DBIII */ - u4name_piece(fn,64,dbdata[handle]->file.name,0,0); - else - strcpy(fn,dbdata[handle]->file.name); - if ((i=d4index(dbdata[handle],fn)) == NULL) - return(e4index); - is_locked = DB_file_locked(handle); - if (is_locked == 0) /* Se non e' stato bloccato in modo esclusivo */ - { - while ((rt=i4lock(i)) == r4locked) -#ifdef DBG - yesnofatal_box("Sono in attesa nella DB_delkey"); -#else - u4delay_sec(); -#endif - } - if (rt == 0) - rt=t4remove_calc(t,recno); - if (is_locked == 0) /* Siccome ho fatto il lock dell'indice, devo anche sbloccarlo */ - i4unlock(i); - return(rt); -} - -/*------------------------------------------------------------------------- - cancella dall'indice corrente la chiave specificata - --------------------------------------------------------------------------*/ -int DB_flush(int handle) -{ - int rt; - - while ((rt = d4flush(dbdata[handle])) == r4locked) -#ifdef DBG - yesnofatal_box("Sono in attesa nella DB_flush"); -#else - u4delay_sec(); -#endif - return rt; -} - -/*------------------------------------------------------------------------- - riscrive il record attuale - --------------------------------------------------------------------------*/ -int DB_rewrite(int handle) -{ - int rt; - if(!handle_ok(handle)) return(-1); - while ((rt=d4write(dbdata[handle],d4recno(dbdata[handle]))) == r4locked) -#ifdef DBG - yesnofatal_box("Sono in attesa nella DB_rewrite"); -#else - u4delay_sec(); -#endif - if (rt == 0) - { - while ((rt = d4flush(dbdata[handle])) == r4locked) -#ifdef DBG - yesnofatal_box("Sono in attesa nella DB_rewrite (d4flush)"); -#else - u4delay_sec(); -#endif - } - if (rt == e4unique) - { - DB_get_error(); - fatal_box("Errore in DB_rewrite(): chiave duplicata nel record %ld, file %s", - dbdata[handle]->rec_num + 1, dbdata[handle]->file.name); - } - rt=DB_unlock(handle); - return (rt); -} - - -/*------------------------------------------------------------------------- - appende il record attuale - --------------------------------------------------------------------------*/ -int DB_add(int handle) -{ - int rt; - int is_locked = 0; - DATA4 * data = dbdata[handle]; - - if (data==0) return(-1); - is_locked = DB_file_locked(handle); - if (is_locked == 0) /* Se non e' stato gia' bloccato in modo esclusivo */ - { - while (file4lock(&data->file, L4LOCK_POS_OLD, 1L) == r4locked) -#ifdef DBG - yesnofatal_box("Sono in attesa nella DB_add"); -#else - u4delay_sec(); -#endif - } - while ((rt = d4append_start(data,0)) == r4locked) -#ifdef DBG - yesnofatal_box("Sono in attesa nella DB_add (d4append_start)"); -#else - u4delay_sec(); -#endif - if (rt == 0) - { - d4recall(data); - while ((rt = d4append(data)) == r4locked) -#ifdef DBG - yesnofatal_box("Sono in attesa nella DB_add (d4append)"); -#else - u4delay_sec(); -#endif - if (rt == e4unique) - { - DB_get_error(); - if (data->rec_num > 0) - fatal_box("Errore in DB_add(): chiave duplicata nell' indice %ld, file %s", - data->rec_num + 1, data->file.name); - else - rt = _isreinsert; - } - else - if (rt == 0) - { - while ((rt = d4flush(data)) == r4locked) -#ifdef DBG - yesnofatal_box("Sono in attesa nella DB_add (d4flush)"); -#else - u4delay_sec(); -#endif - } - } - DB_unlock(handle); - if (is_locked == 0) - { - file4unlock(&data->file, L4LOCK_POS_OLD, 1L); - } - return(rt); -} - -/*------------------------------------------------------------------------- - Blocca in modo esclusivo il file dati ed indice - --------------------------------------------------------------------------*/ -int DB_lockfile(int handle) -{ - int rt; - - if(!handle_ok(handle)) return(-1); - rt = d4lock_file(dbdata[handle]); - if (rt==0) rt=d4lock_index(dbdata[handle]); - return(rt); -} - -HIDDEN int is_inkey(RecDes *r, int numfield) -{ - int found=0,i,j; - - for (i=0; ((i < MaxKeys) && (i < r->NKeys) && !found); i++) - for (j=0; ((j < r->Ky[i].NkFields) && !found); j++) - if (numfield == r->Ky[i].FieldSeq[j]) - found=1; - return(found); -} - -HIDDEN void do_key(char *fname, RecDes *r, TAG4INFO *tag_info, int n_keys) -{ - int i,j; - char tiname[9]; /* Tag name, max 8 characters long! */ - char* dot; - - strcpy(tiname,fname); - dot = strchr(tiname, '.'); - if (dot) *dot = '\0'; - _strupr(tiname); - for (i=0; ((i < MaxKeys) && (i < n_keys)); i++) - { - tag_info[i].name=(char *)u4alloc(9); - tag_info[i].expression=(char *)u4alloc(256); - tag_info[i].filter=(char*)u4alloc(20); - tag_info[i].descending=0; - if (r->Ky[i].DupKeys) - tag_info[i].unique=0; - else - tag_info[i].unique= i == 0 ? e4unique : r4unique_continue; -/* tag_info[i].unique=e4unique; */ - strcpy(tag_info[i].filter,".NOT.DELETED()"); /* Not available for DBIII and CLIPPER */ - strcpy(tag_info[i].name,tiname) ; - if (strlen(tiname) < 8) - strcat(tag_info[i].name," "); - tag_info[i].name[strlen(tag_info[i].name)-1] = '0' + i + 1; - for (j=0; j < r->Ky[i].NkFields; j++) - { - int nf= r->Ky[i].FieldSeq[j]; - if (nf > MaxFields) /* When Upper field is specified */ - { - nf -= MaxFields; - strcat(tag_info[i].expression,"UPPER("); - } - if (r->Ky[i].FromCh[j] != 255) /* When partial field is specified */ - strcat(tag_info[i].expression,"SUBSTR("); - - switch (r->Fd[nf].TypeF) /* When numeric field in key is specified */ - { - case _intfld: - case _longfld: - case _realfld: - case _wordfld: - case _intzerofld: - case _longzerofld: - strcat(tag_info[i].expression,"STR("); - break; - case _datefld: - strcat(tag_info[i].expression,"DTOS("); - break; - case _boolfld: - strcat(tag_info[i].expression,"IIF("); /* Logical fields are in key too.. */ - break; - default: /* It's a non sense to keep _realfld in key... */ - break; /* however it's possible to have it... */ - } /* Le chiavi composte da campi data non necessitano di funzioni di traduzione. */ - - strcat(tag_info[i].expression,r->Fd[nf].Name); /* Append field name */ - - /* If partial field was specified */ - /* add parameters to SUBSTR */ -/* - if (r->Ky[i].FromCh[j] != 255) - { - char ts[8]; - - strcat(tag_info[i].expression,","); - sprintf(ts,"%d",r->Ky[i].FromCh[j] + 1); - strcat(tag_info[i].expression,ts); - strcat(tag_info[i].expression,","); - sprintf(ts,"%d",r->Ky[i].ToCh[j] - r->Ky[i].FromCh[j] + 1); - strcat(tag_info[i].expression,ts); - strcat(tag_info[i].expression,")"); - } -*/ - - switch (r->Fd[nf].TypeF) /* If numeric field was specified */ - { /* add parameters to STR */ - case _intfld: - case _longfld: - case _realfld: /* Questo tipo di campo(real) non ha senso in un a chiave... */ - case _wordfld: - case _intzerofld: - case _longzerofld: - { - char ts[8]; - strcat(tag_info[i].expression,","); - sprintf(ts,"%d",r->Fd[nf].Len); - strcat(tag_info[i].expression,ts); - strcat(tag_info[i].expression,",0)"); - } - break; - case _boolfld: - strcat(tag_info[i].expression,",\"T\",\"F\")"); - break; - default: - break; - } - - /* Close parentheses if UPPER or DTOS operators were used: */ - if (r->Ky[i].FieldSeq[j] > MaxFields || (r->Fd[nf].TypeF == _datefld)) - strcat(tag_info[i].expression,")"); - if (r->Ky[i].FromCh[j] != 255) /* If partial field was specified */ - { /* add parameters to SUBSTR */ - char ts[8]; - - strcat(tag_info[i].expression,","); - sprintf(ts,"%d",r->Ky[i].FromCh[j] + 1); - strcat(tag_info[i].expression,ts); - strcat(tag_info[i].expression,","); - sprintf(ts,"%d",r->Ky[i].ToCh[j] - r->Ky[i].FromCh[j] + 1); - strcat(tag_info[i].expression,ts); - strcat(tag_info[i].expression,")"); - } - /* If there's another field in key adds "+" operator: */ - if ((j < (r->Ky[i].NkFields-1)) && (strlen(r->Fd[nf].Name) > 0)) - strcat(tag_info[i].expression,"+"); - } - } - tag_info[i].name=NULL; - tag_info[i].expression=NULL; - tag_info[i].filter=NULL; - tag_info[i].unique=0; - tag_info[i].descending=0; -} - -/*------------------------------------------------------------------------- - Compatta il file dati - --------------------------------------------------------------------------*/ -int DB_packfile(short vis, const char * filename, long eod) -{ - int rt=0,handle; - - /* - if(!handle_ok(handle)) return(-1); - codebase.auto_open = 0 cosi' non apre gli indici - */ - code_base.auto_open = 0; - handle=DB_open(filename,1,0); /* Exclusive mode open! */ - if (handle > -1) - { - char s[81]; - - if (vis) - { - strcpy(s, "Compattamento dati file : "); - strcat(s, filename); - progind_create(100L,s,0,0,60); - } - if (eod < d4reccount(dbdata[handle])) - { - rt=d4zap(dbdata[handle],++eod,d4reccount(dbdata[handle])); - } else - rt=d4pack(dbdata[handle]); - if (vis) - progind_destroy(); - } - DB_close(handle); - } - else - rt=code_base.error_code; - code_base.auto_open = 1; - return rt; -} - -/*------------------------------------------------------------------------- - Compatta il file dati - --------------------------------------------------------------------------*/ -int DB_packmemo(short vis, const char * filename) -{ - int rt=0,handle; - - code_base.auto_open = 0; - handle=DB_open(filename,1,0); /* Exclusive mode open! */ - if (handle > -1) - { - char s[81]; - - if (vis) - { - strcpy(s,"Compattamento memo file : "); - strcat(s,(char*)filename); - progind_create(100L,s,0,0,60); - } - rt=d4memo_compress(dbdata[handle]); - if (vis) - progind_destroy(); - DB_close(handle); - } - else - rt=code_base.error_code; - code_base.auto_open = 1; - return rt; -} - -/*------------------------------------------------------------------------- - Elimina i record duplicati - --------------------------------------------------------------------------*/ -int DB_clean_file(int handle, char * filename, char * ff, RecDes * r, short vis) -{ - TAG4INFO tags[2]; - TAG4 * t; - char s[256], s0[256]; - int l = 0, lt = 0, rt = 0; - long cnt = 0; - INDEX4 *w = NULL; - long items = DB_reccount(handle); - - if (items == 0) - return 0; - - s[0] = '\0'; - do_key(ff, r, tags, 1); - strcat(tags[0].expression, "+STR(RECNO(),9)"); - w = i4create(dbdata[handle],(char*)filename,tags); - u4free(tags[0].name); - u4free(tags[0].expression); - u4free(tags[0].filter); - if (w == NULL) return code_base.error_code; - t = d4tag_default(dbdata[handle]); - lt = expr4key_len(t->expr); - l = lt - 9; - if (vis) - progind_create(items,"Ricerca record duplicati",0,1,60); - - rt = t4bottom(t); - - while (code_base.error_code == 0) - { - strncpy(s0, t4key(t), lt); - - if (vis) - progind_set_status(++cnt); - - if (!strncmp(s, s0, l)) - { - d4go(dbdata[handle],t4recno(t)); - d4delete(dbdata[handle]); - t4seek(t, s0, lt); - } - strncpy(s, s0, lt); - if (t4skip(t, -1L) >= 0) - break; - - } // while - rt = code_base.error_code; - if (vis) - progind_destroy(); - - i4close(w); - return rt; -} - -/*------------------------------------------------------------------------- - Compatta gli indici - --------------------------------------------------------------------------*/ -int DB_packindex(short vis, const char * filename, RecDes *r, long *peod, bool ask) -{ - int rt=0,handle; - TAG4INFO tags[MaxKeys+1]; - char s[82]; - INDEX4 * w = NULL; - - strcpy(s,"Ricostruzione indici file : "); - strcat(s,filename); - - /* codebase.auto_open = 0 cosi' non apre gli indici */ - code_base.auto_open=0 ; - handle=DB_open(filename,1,0); /* Exclusive mode open */ - if (handle > -1) - { - int i; - char *ff = find_slash_backslash(filename); - if (vis) - progind_create((long)r->NKeys,s,0,1,60); - if ((ff == NULL) || *ff == '\0') - ff = (char *)filename; - else - ff++; - do_key(ff,r,tags, r->NKeys); - w = i4create(dbdata[handle],NULL,tags); - if (vis) - { - progind_set_status((long)r->NKeys); - progind_destroy(); - } - if (w == NULL) rt = code_base.error_code; - if (rt == e4unique || rt == r4unique) - { - rt = 0; - if (!ask || yesno_box("Sono stati rilevati alcuni records duplicati nel file %s. Devo eliminarli ?",filename)) - rt = DB_clean_file(handle, (char*) filename, ff, r, vis); - else - tags[0].unique = r4unique_continue; - if (rt == 0) - { - if (vis) - progind_create((long)r->NKeys,s,0,1,60); - w = i4create(dbdata[handle],(char*)filename,tags); - if (w == NULL) rt = code_base.error_code; - if (vis) - { - progind_set_status((long)r->NKeys); - progind_destroy(); - } - } - } - if (rt == 0) - { - if (u4switch() & 2 || u4switch() & 8) /* Clipper and DBIII */ - { - FILE *fp; - char cgp[81]; - - strcpy(cgp,filename); - strcat(cgp,".cgp"); - if ((fp=fopen(cgp,"w"))!=NULL) - { - int j; - - for (j=0; jNKeys;j++) - fprintf(fp,"%s\n",tags[j].name); - fclose(fp); - } - } -/* - else - if (u4switch() & 1 || u4switch() & 4) // FOXPRO and DBIV - { - } -*/ - } - for (i=0; ((i < MaxKeys) && (i < r->NKeys)); i++) - { - u4free(tags[i].name); - u4free(tags[i].expression); - u4free(tags[i].filter); - } - *peod=DB_reccount(handle); - DB_close(handle); - } - code_base.auto_open = 1; - return(rt); -} - - -/*------------------------------------------------------------------------- - costruisce il file filename - --------------------------------------------------------------------------*/ - -int DB_build(const char * filename, RecDes *r) -{ - - FIELD4INFO field_info[MaxFields+1]; /* Numero di campi in un record */ - TAG4INFO tag_info[MaxKeys+1]; /* Numero di chiavi in un file */ - DATA4 *dbuilded; - int rt=0,i; - char *ff = find_slash_backslash(filename); - - - for (i=0; ((iNFields) && (iFd[i].Name); - field_info[i].len = r->Fd[i].Len; - field_info[i].dec = r->Fd[i].Dec; - switch (r->Fd[i].TypeF) - { - case _intfld: - case _longfld: - case _realfld: /* It's a non sense to keep this in key! */ - case _wordfld: - case _intzerofld: - case _longzerofld: - field_info[i].type=r4num; - break; - case _boolfld: - field_info[i].type=r4log; - break; - case _datefld: - field_info[i].type=r4date; - break; - case _memofld: - field_info[i].type=r4memo; - field_info[i].len = 10; - field_info[i].dec = 0; - break; - case _charfld: - default: - field_info[i].type=r4str; - break; - } - } - field_info[i].name=NULL; - field_info[i].type=0; - field_info[i].len=0; - field_info[i].dec=0; - - if (ff == NULL || *ff == '\0') - ff = (char *) filename; - else - ff++; - do_key(ff,r,tag_info, r->NKeys); - - if ((dbuilded=d4create(&code_base, (char *)filename, field_info, tag_info))==0) /* deve solo creare il file dati vuoto */ - rt=code_base.error_code; - else - rt=d4close(dbuilded); - if (u4switch() & 2 || u4switch() & 8) /* Rebuild filename.cgp for CLIPPER AND DBIII only */ - { - FILE* fp; - char xx[81]; - - strcpy(xx,(char*)filename); - - strcat(xx,".cgp"); - if ((fp=fopen(xx,"w"))!=NULL) - { - int j; - for (j=0; tag_info[j].name ; j++) - fprintf(fp,"%s\n",tag_info[j].name); - fclose(fp); - } - } - if (rt!=0) - rt=code_base.error_code; - for (i=0; ((i < MaxFields) && (i < r->NFields)); i++) - u4free(field_info[i].name); - for (i=0; ((i < MaxKeys) && (i < r->NKeys)); i++) - { - u4free(tag_info[i].name); - u4free(tag_info[i].expression); - u4free(tag_info[i].filter); - } - return(rt) ; -} - -/*------------------------------------------------------------------------- - reperisce il tracciato record e la stringa di definizione delle chiavi - Stringa di definizione chiavi: - expression1|unique1$expression2|unique2$expression3|unique3 - --------------------------------------------------------------------------*/ - -int DB_recinfo(const char * filename, FileDes *d, RecDes *r, char* keys) -{ - /* filename must not have extension since it's used to search index name too*/ - FIELD4INFO *field_info; /* Definizione del tracciato record */ - TAG4INFO *tag_info; /* Definizione delle chiavi */ - INDEX4 *index_file; - DATA4 *data_file; - int rt=0,num_fields,i; - - data_file = d4open(&code_base, (char*)filename); - if (data_file != NULL) - { - field_info = d4field_info(data_file); -// index_file = d4index(data_file,(char*)filename); - index_file = d4index(data_file, ""); - if (index_file == NULL) - fatal_box("Il file %s e' senza indici.",filename); - tag_info = i4tag_info(index_file); - d->EOD = d->EOX = d4reccount(data_file); - d->LenR = (word)d4record_width(data_file); - d->Flags = 0L; - strcpy(d->Des,"File esterno"); - strcpy(d->FCalc,""); - strcpy(d->GenPrompt,""); - if (field_info != NULL && tag_info != NULL) - { - /* Compile field information */ - num_fields = d4num_fields(data_file); - r->NFields = num_fields; - for (i=0; ((iFd[i].Name,field_info[i].name); - _strupr(r->Fd[i].Name); - r->Fd[i].Len = field_info[i].len; - r->Fd[i].Dec = field_info[i].dec; - switch(field_info[i].type) - { - case r4str: - if (r->Fd[i].Len > 1) - r->Fd[i].TypeF = _alfafld; - else - r->Fd[i].TypeF = _charfld; - break; - case r4log: - r->Fd[i].TypeF = _boolfld; - break; - case r4date: - r->Fd[i].TypeF = _datefld; - break; - case r4memo: - r->Fd[i].TypeF = _memofld; - break; - case r4num: - if (r->Fd[i].Dec > 0) - r->Fd[i].TypeF = _realfld; - else - r->Fd[i].TypeF = r->Fd[i].Len < 6 ? _intfld : _longfld; - break; - default: - break; - } - } - - strcpy(keys,""); - /* Compile key definition */ - for (i=0; i < MaxKeys; i++) /* Browse all tags */ - { - if (tag_info[i].name == NULL) - break; - strcat(keys,tag_info[i].expression); - /* Tell me if you're unique my Boy... */ - strcat(keys,"|"); - strcat(keys,tag_info[i].unique == 0 ? "X" : " "); - strcat(keys,"$"); - } - r->NKeys = i; - u4free(field_info); - u4free(tag_info); - } - else - rt = code_base.error_code; - d4close(data_file); - } - else - rt = code_base.error_code; - return (rt); -} - -/*------------------------------------------------------------------------- - ritorna l'ultimo errore - --------------------------------------------------------------------------*/ - -int DB_get_error(void) -{ - int rt = code_base.error_code; - code_base.error_code=0; - return (rt); -} - -/*------------------------------------------------------------------------- - Azzera la viarabile globale d'errore - --------------------------------------------------------------------------*/ - -void DB_zero_error(void) -{ - code_base.error_code=0; -} - -/*------------------------------------------------------------------------- - Si posiziona sull'indice attivo alla chiave indicata, restituisce - la prima chiave che trova >= a from. (TCusrsor) - --------------------------------------------------------------------------*/ - -int DB_index_seek(int handle, char* from) -{ - TAG4 *t; - - if(!handle_ok(handle)) return(-1); - if ((t=d4tag_default(dbdata[handle]))==NULL) return(-1); - - if (t4seek(t,from,strlen(from)) < 0) return(DB_get_error()); - return(0); - -} - -/*------------------------------------------------------------------------- - Ritorna il numero di record corrispondente alla chiave corrente - --------------------------------------------------------------------------*/ - -long DB_index_recno(int handle) -{ - TAG4 *t; - - if(!handle_ok(handle)) return(-1); - if ((t=d4tag_default(dbdata[handle]))==NULL) return(-1); - - return(t4recno(t)); -} - -/*------------------------------------------------------------------------- - Si posiziona sulla chiave successiva dell'indice corrente - --------------------------------------------------------------------------*/ -long DB_index_next(int handle) -{ - TAG4 *t; - - if(!handle_ok(handle)) return(-1); - if ((t=d4tag_default(dbdata[handle]))==NULL) return(-1); - - return(t4skip(t,1L)); -} - -/*------------------------------------------------------------------------- - Restituisce la chiave corrente - --------------------------------------------------------------------------*/ - -char* DB_index_getkey(int handle) -{ - static char* key = NULL; - TAG4 *t; - int klen; - - if (key == NULL) - key = malloc(MAXLEN); - - if(!handle_ok(handle)) - return NULL; - - if ((t=d4tag_default(dbdata[handle]))==NULL) return(NULL); - klen=expr4key_len(t->expr); - if (klen > (MAXLEN-1)) klen=MAXLEN-1; - memcpy(key,t4key(t),klen); /* t4key non restituisce una null terminated string */ - key[klen]='\0'; - return key; -} - -/*------------------------------------------------------------------------- - Restituisce vero se l'indice e' alla fine - --------------------------------------------------------------------------*/ - -int DB_index_eof(int handle) -{ - TAG4 *t; - - if(!handle_ok(handle)) return(-1); - if ((t=d4tag_default(dbdata[handle]))==NULL) return(-1); - return(t4eof(t)); -} - -/*------------------------------------------------------------------------- - Blocca il record indicato - --------------------------------------------------------------------------*/ - -int DB_lock_rec(int handle,long nrec) -{ - if(!handle_ok(handle)) return(-1); - if(d4lock(dbdata[handle],nrec)==r4locked) return(-1); - else return(0); -} - -/*------------------------------------------------------------------------- - Ritorna vero(non zero) se il file dati od indice sono stati bloccati - in modo esclusivo dalla presente applicazione, non da altri programmi!!! - --------------------------------------------------------------------------*/ - - -int DB_file_locked(int handle) -{ - if(!handle_ok(handle)) return(-1); - return(d4lock_test_file(dbdata[handle]) + d4lock_test_index(dbdata[handle])); -} - -/*------------------------------------------------------------------------- - Ritorna vero se il record nrec e' bloccato dalla presente applicazione, - non da altri programmi!!! - --------------------------------------------------------------------------*/ - -int DB_rec_locked(int handle,long nrec) -{ - if(!handle_ok(handle)) return(-1); - return(d4lock_test(dbdata[handle],nrec)); -} - -/*------------------------------------------------------------------------- - restituisce la configurazione della libreria - --------------------------------------------------------------------------*/ - -long DB_getconf() -{ - return(u4switch()); -} - -/*------------------------------------------------------------------------- - Restituisce il numero di versione scritto sull'header dell'indice - --------------------------------------------------------------------------*/ - -long DB_changed(int handle) -{ - INDEX4 *i; - char fn[64]; - - if(!handle_ok(handle)) return(-1); - if (u4switch() & 2 || u4switch() & 8) /* Clipper & DBIII */ - u4name_piece(fn,64,dbdata[handle]->file.name,0,0); - else - strcpy(fn,dbdata[handle]->file.name); - i=d4index(dbdata[handle],fn); - if (i == NULL) return(-1); - - return(i4changed(i)); -} - -char* DB_memoptr( const int handle, const char * fieldname ) -{ - FIELD4 * f; - f = d4field( dbdata[ handle ], ( char *)fieldname ); - return f4memo_ptr( f ); -} - -int DB_memowrite( const int handle, const char * fieldname, const char * data ) -{ - int ret; - FIELD4 * f; - f = d4field( dbdata[ handle ], (char *)fieldname ); - ret = f4memo_assign( f, ( char * )data ); - d4flush_data( dbdata[ handle ] ); - d4unlock(dbdata[handle]); - return ret; -} - -#endif // CB5 diff --git a/include/colors.cpp b/include/colors.cpp index 7667a7324..59dbc5d46 100755 --- a/include/colors.cpp +++ b/include/colors.cpp @@ -61,7 +61,7 @@ unsigned int color_distance(COLOR col1, COLOR col2) const int g2 = XVT_COLOR_GET_GREEN(col2); const int b2 = XVT_COLOR_GET_BLUE(col2); const int r = abs(r1-r2); - const int g = abs(g1-b2); + const int g = abs(g1-g2); const int b = abs(b1-b2); return (r > g && r > b) ? r : (g > b ? g : b); } @@ -343,4 +343,4 @@ TSelect_color_mask::TSelect_color_mask(const char * mask_name, const char * para TSelect_color_mask::~TSelect_color_mask() { delete _sheet_mask; -} \ No newline at end of file +}