Aggiunto malloc.h per il WATCOM C++ compiler

git-svn-id: svn://10.65.10.50/trunk@1127 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
alex 1995-03-15 17:01:27 +00:00
parent dee73f8605
commit 9a59449da3
3 changed files with 1625 additions and 1613 deletions

View File

@ -7,7 +7,11 @@
#include "btrread.h" #include "btrread.h"
#include "btrbase.h" #include "btrbase.h"
#include "checks.h" #include "checks.h"
#ifdef __WATCOMC__
#include <malloc.h>
#else
#include <memory.h> #include <memory.h>
#endif
void Move(byte ,int ,int ,int ,char *,char *); void Move(byte ,int ,int ,int ,char *,char *);
@ -21,20 +25,20 @@ Azzera una pagina del B+TREE.
@(FD) @(FD)
*/ */
void ZPage(ActPage) void ZPage(ActPage)
Page *ActPage; /* pagina attuale */ Page *ActPage; /* pagina attuale */
{ {
ActPage->PA.PageHeader.TPage = EmptyPage; ActPage->PA.PageHeader.TPage = EmptyPage;
ActPage->PA.PageHeader.PathNumber = 0; ActPage->PA.PageHeader.PathNumber = 0;
ActPage->PA.PageHeader.Flags = 0; ActPage->PA.PageHeader.Flags = 0;
ActPage->PA.PageHeader.Father = NoLink; ActPage->PA.PageHeader.Father = NoLink;
ActPage->PA.PageHeader.Prev = NoLink; ActPage->PA.PageHeader.Prev = NoLink;
ActPage->PA.PageHeader.Next = NoLink; ActPage->PA.PageHeader.Next = NoLink;
ActPage->PA.PageHeader.NKey = 0; ActPage->PA.PageHeader.NKey = 0;
memset(ActPage->PA.AreaForKey, ' ', AreaLen); memset(ActPage->PA.AreaForKey, ' ', AreaLen);
} }
/* /*
@($) GetHeader B+TREE @($) GetHeader B+TREE
@ -53,21 +57,21 @@ w = descrittore della finestra.
*/ */
int GetHeader(FilCheck, HPage, LockMode, Err) int GetHeader(FilCheck, HPage, LockMode, Err)
FilCtrl *FilCheck; /* identificatore indice */ FilCtrl *FilCheck; /* identificatore indice */
Page *HPage; /* pagina dell' indice */ Page *HPage; /* pagina dell' indice */
int LockMode; /* lock sull'header */ int LockMode; /* lock sull'header */
int *Err; /* codice di errore */ int *Err; /* codice di errore */
{ {
do do
{ {
CRead(&FilCheck->Fil, (char *) HPage, 1L, LockMode); CRead(&FilCheck->Fil, (char *) HPage, 1L, LockMode);
if (TESTLOCK(FilCheck->Fil.IOR)) if (TESTLOCK(FilCheck->Fil.IOR))
message_box("Sono in attesa dell' indice"); message_box("Sono in attesa dell' indice");
} while TESTLOCK(FilCheck->Fil.IOR); } while TESTLOCK(FilCheck->Fil.IOR);
return((*Err = FilCheck->Fil.IOR)); return((*Err = FilCheck->Fil.IOR));
} }
/* /*
@($) PutHeader B+TREE @($) PutHeader B+TREE
@ -78,16 +82,16 @@ Restituisce il codice di errore.
@(FD) @(FD)
*/ */
int PutHeader(FilCheck, HPage, LockMode, Err) int PutHeader(FilCheck, HPage, LockMode, Err)
FilCtrl *FilCheck; /* identificatore indice */ FilCtrl *FilCheck; /* identificatore indice */
Page *HPage; /* pagina in cui scrivere l'header */ Page *HPage; /* pagina in cui scrivere l'header */
int LockMode; /* lock sull'header */ int LockMode; /* lock sull'header */
int *Err; /* errore */ int *Err; /* errore */
{ {
CWrite(&FilCheck->Fil, (char *) HPage, 1L, LockMode); CWrite(&FilCheck->Fil, (char *) HPage, 1L, LockMode);
return((*Err = FilCheck->Fil.IOR)); return((*Err = FilCheck->Fil.IOR));
} }
/* /*
@($) GetAPage B+TREE @($) GetAPage B+TREE
@ -98,17 +102,17 @@ Restituisce il codice di errore.
@(FD) @(FD)
*/ */
int GetAPage(FilCheck, ActPage, Pg, Err) int GetAPage(FilCheck, ActPage, Pg, Err)
FilCtrl *FilCheck; /* identificatore indice */ FilCtrl *FilCheck; /* identificatore indice */
Page *ActPage; /* pagina letta */ Page *ActPage; /* pagina letta */
RecNoType Pg; /* numero di pagina */ RecNoType Pg; /* numero di pagina */
int *Err; /* codice di errore */ int *Err; /* codice di errore */
{ {
CRead(&FilCheck->Fil, (char *) ActPage, Pg + FilCheck->FHead.CABlock + 1, CRead(&FilCheck->Fil, (char *) ActPage, Pg + FilCheck->FHead.CABlock + 1,
NoLock); NoLock);
return((*Err = FilCheck->Fil.IOR)); return((*Err = FilCheck->Fil.IOR));
} }
/* /*
@($) PutAPage B+TREE @($) PutAPage B+TREE
@ -119,17 +123,17 @@ Restituisce il codice di errore.
@(FD) @(FD)
*/ */
int PutAPage(FilCheck, ActPage, Pg, Err) int PutAPage(FilCheck, ActPage, Pg, Err)
FilCtrl *FilCheck; /* identificatore indice */ FilCtrl *FilCheck; /* identificatore indice */
Page *ActPage; /* pagina attiva */ Page *ActPage; /* pagina attiva */
RecNoType Pg; /* numero della pagina */ RecNoType Pg; /* numero della pagina */
int *Err; /* codice errore */ int *Err; /* codice errore */
{ {
CWrite(&FilCheck->Fil, (char *) ActPage, Pg + FilCheck->FHead.CABlock + 1, CWrite(&FilCheck->Fil, (char *) ActPage, Pg + FilCheck->FHead.CABlock + 1,
NoLock); NoLock);
return((*Err = FilCheck->Fil.IOR)); return((*Err = FilCheck->Fil.IOR));
} }
/* /*
@($) GetAKey B+TREE @($) GetAKey B+TREE
@ -143,20 +147,20 @@ BgnItem = numero di byte precedenti alla chiave dall'inizio della pagina.
@(FSV) @(FSV)
*/ */
void GetAKey(ActPage, KeyLen, Pstion, KKey, Index) void GetAKey(ActPage, KeyLen, Pstion, KKey, Index)
Page ActPage; /* pagina attiva */ Page ActPage; /* pagina attiva */
int KeyLen; /* lunghezza della chiave */ int KeyLen; /* lunghezza della chiave */
int Pstion; /* numero chiave nella pagina */ int Pstion; /* numero chiave nella pagina */
TKey KKey; /* Valore chiave (in output) */ TKey KKey; /* Valore chiave (in output) */
RecNoType *Index; /* indice associato a questa chiave */ RecNoType *Index; /* indice associato a questa chiave */
{ {
int BgnItem; int BgnItem;
BgnItem = (Pstion - 1) * (KeyLen + IndLen); BgnItem = (Pstion - 1) * (KeyLen + IndLen);
strcpy(KKey, (char *)(ActPage.PA.AreaForKey + BgnItem)); strcpy(KKey, (char *)(ActPage.PA.AreaForKey + BgnItem));
*Index = *((RecNoType *)(ActPage.PA.AreaForKey + BgnItem + KeyLen)); *Index = *((RecNoType *)(ActPage.PA.AreaForKey + BgnItem + KeyLen));
} }
/* /*
@($) PutAKey B+TREE @($) PutAKey B+TREE
@ -170,20 +174,20 @@ BgnItem = numero di byte precedenti alla chiave dall'inizio della pagina.
@(FSV) @(FSV)
*/ */
void PutAKey(KKey, Index, Pstion, KeyLen, ActPage) void PutAKey(KKey, Index, Pstion, KeyLen, ActPage)
TKey KKey; /* valore della chiave */ TKey KKey; /* valore della chiave */
RecNoType Index; /* indice */ RecNoType Index; /* indice */
int Pstion; /* posizione nella quale scrivere la chiave */ int Pstion; /* posizione nella quale scrivere la chiave */
int KeyLen; /* lunghezza della chiave */ int KeyLen; /* lunghezza della chiave */
Page *ActPage;/* pagina attiva */ Page *ActPage;/* pagina attiva */
{ {
register int BgnItem; register int BgnItem;
BgnItem = (Pstion - 1) * (KeyLen + IndLen); BgnItem = (Pstion - 1) * (KeyLen + IndLen);
strcpy((char *)(ActPage->PA.AreaForKey + BgnItem), KKey); strcpy((char *)(ActPage->PA.AreaForKey + BgnItem), KKey);
*((RecNoType *)(ActPage->PA.AreaForKey + BgnItem + KeyLen)) = Index; *((RecNoType *)(ActPage->PA.AreaForKey + BgnItem + KeyLen)) = Index;
} }
/* /*
@($) Repos B+TREE @($) Repos B+TREE
@ -207,59 +211,59 @@ Serve solo in multiutenza (XENIX).
@(FN) @(FN)
*/ */
void Repos(FilCheck, BError) void Repos(FilCheck, BError)
FilCtrl *FilCheck; /* identificatore indice */ FilCtrl *FilCheck; /* identificatore indice */
int *BError; /* codice errore (in output) */ int *BError; /* codice errore (in output) */
{ {
TKey WKey, WKey1; TKey WKey, WKey1;
int WPos = FilCheck->Pos, WError; int WPos = FilCheck->Pos, WError;
RecNoType WPag = FilCheck->CurPag, WInd, WInd1; RecNoType WPag = FilCheck->CurPag, WInd, WInd1;
if (GetAPage(FilCheck, &PathPage, WPag, BError) != NoErr) return; if (GetAPage(FilCheck, &PathPage, WPag, BError) != NoErr) return;
if (PathPage.PA.PageHeader.NKey < WPos) WPos = PathPage.PA.PageHeader.NKey ; if (PathPage.PA.PageHeader.NKey < WPos) WPos = PathPage.PA.PageHeader.NKey ;
GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, WPos, WKey, &WInd); GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, WPos, WKey, &WInd);
if ((strcmp(WKey, FilCheck->Key) == 0) && (WInd == FilCheck->Ind)) return ; if ((strcmp(WKey, FilCheck->Key) == 0) && (WInd == FilCheck->Ind)) return ;
strcpy(WKey1, FilCheck->Key) ; strcpy(WKey1, FilCheck->Key) ;
WInd = FilCheck->Ind ; WInd = FilCheck->Ind ;
BTrRead(FilCheck, FilCheck->Key, WKey, &WInd1, BError) ; BTrRead(FilCheck, FilCheck->Key, WKey, &WInd1, BError) ;
WPag = FilCheck->CurPag ; WPag = FilCheck->CurPag ;
WPos = FilCheck->Pos ; WPos = FilCheck->Pos ;
if (*BError == BTrEmptyTree) return ; if (*BError == BTrEmptyTree) return ;
if (FilCheck->Base[FilCheck->PN].DupKeys == TRUE) if (FilCheck->Base[FilCheck->PN].DupKeys == TRUE)
{ {
while ((strcmp(WKey, WKey1) == 0) && (WInd1 < WInd)) while ((strcmp(WKey, WKey1) == 0) && (WInd1 < WInd))
{ {
if (WPos < PathPage.PA.PageHeader.NKey) WPos++; if (WPos < PathPage.PA.PageHeader.NKey) WPos++;
else else
if (PathPage.PA.PageHeader.Next == NoLink) break; if (PathPage.PA.PageHeader.Next == NoLink) break;
else else
{ {
WPag = PathPage.PA.PageHeader.Next; WPag = PathPage.PA.PageHeader.Next;
if (GetAPage(FilCheck, &PathPage, WPag, BError) != NoErr) return; if (GetAPage(FilCheck, &PathPage, WPag, BError) != NoErr) return;
WPos = 1; WPos = 1;
} }
GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, WPos, WKey, &WInd1); GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, WPos, WKey, &WInd1);
} }
} }
if (GetAPage(FilCheck, &PathPage, WPag, &WError) != NoErr) return; if (GetAPage(FilCheck, &PathPage, WPag, &WError) != NoErr) return;
if ((strcmp(WKey, WKey1) == 0) && (WInd == WInd1)) if ((strcmp(WKey, WKey1) == 0) && (WInd == WInd1))
{ {
FilCheck->CurPag = WPag; FilCheck->CurPag = WPag;
FilCheck->Pos = WPos; FilCheck->Pos = WPos;
} }
else else
{ {
if (*BError != BTrEOF) if (*BError != BTrEOF)
{ {
FilCheck->CurPag = WPag; FilCheck->CurPag = WPag;
FilCheck->Pos = WPos; FilCheck->Pos = WPos;
strcpy(FilCheck->Key, WKey) ; strcpy(FilCheck->Key, WKey) ;
FilCheck->Ind = WInd1; FilCheck->Ind = WInd1;
*BError = BTrKeyNotFound; *BError = BTrKeyNotFound;
} }
} }
} }
/* /*
@($) BTrNext B+TREE @($) BTrNext B+TREE
@ -275,59 +279,59 @@ WKey = variabile di lavoro contenente la chiave.
@(FSV) @(FSV)
*/ */
void BTrNext(FilCheck, KKey, IndSr, BError) void BTrNext(FilCheck, KKey, IndSr, BError)
FilCtrl *FilCheck; /* identificatore indice */ FilCtrl *FilCheck; /* identificatore indice */
TKey KKey; /* valore della chiave */ TKey KKey; /* valore della chiave */
RecNoType *IndSr; /* indice associato */ RecNoType *IndSr; /* indice associato */
int *BError; /* codice errore */ int *BError; /* codice errore */
{ {
TKey WKey; TKey WKey;
if (FilCheck->CurPag == NoLink) if (FilCheck->CurPag == NoLink)
{ {
MaxKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key); MaxKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key);
BTrRead(FilCheck, FilCheck->Key, WKey, IndSr, BError) ; BTrRead(FilCheck, FilCheck->Key, WKey, IndSr, BError) ;
*BError = BTrEOF; *BError = BTrEOF;
} }
else else
{ {
Repos(FilCheck, BError) ; Repos(FilCheck, BError) ;
if (*BError != NoErr) if (*BError != NoErr)
{ {
if (*BError == BTrKeyNotFound) if (*BError == BTrKeyNotFound)
{ {
strcpy(KKey,FilCheck->Key); strcpy(KKey,FilCheck->Key);
*IndSr = FilCheck->Ind ; *IndSr = FilCheck->Ind ;
*BError = NoErr ; *BError = NoErr ;
} }
return; return;
} }
if (FilCheck->Pos < PathPage.PA.PageHeader.NKey) if (FilCheck->Pos < PathPage.PA.PageHeader.NKey)
{ {
FilCheck->Pos++; FilCheck->Pos++;
GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr);
} }
else else
{ {
if (PathPage.PA.PageHeader.Next == NoLink) if (PathPage.PA.PageHeader.Next == NoLink)
{ {
GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr);
/*MaxKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key);*/ /*MaxKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key);*/
*BError = BTrEOF; *BError = BTrEOF;
} }
else else
{ {
FilCheck->CurPag = PathPage.PA.PageHeader.Next; FilCheck->CurPag = PathPage.PA.PageHeader.Next;
if (GetAPage(FilCheck, &PathPage, FilCheck->CurPag, BError) != NoErr) return; if (GetAPage(FilCheck, &PathPage, FilCheck->CurPag, BError) != NoErr) return;
FilCheck->Pos = 1; FilCheck->Pos = 1;
GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr);
} }
} }
strcpy(KKey,FilCheck->Key); strcpy(KKey,FilCheck->Key);
FilCheck->Ind = *IndSr ; FilCheck->Ind = *IndSr ;
} }
} }
/* /*
@($) BTrPrev B+TREE @($) BTrPrev B+TREE
@ -343,60 +347,60 @@ WKey = variabile di lavoro contenente una chiave.
@(FSV) @(FSV)
*/ */
void BTrPrev(FilCheck, KKey, IndSr, BError) void BTrPrev(FilCheck, KKey, IndSr, BError)
FilCtrl *FilCheck; /* identificatore indice */ FilCtrl *FilCheck; /* identificatore indice */
TKey KKey; /* valore della chiave (in output) */ TKey KKey; /* valore della chiave (in output) */
RecNoType *IndSr; /* indice associato */ RecNoType *IndSr; /* indice associato */
int *BError; /* codice di errore */ int *BError; /* codice di errore */
{ {
TKey WKey; TKey WKey;
if (FilCheck->CurPag == NoLink) if (FilCheck->CurPag == NoLink)
{ {
MinKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key); MinKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key);
BTrRead(FilCheck, FilCheck->Key, WKey, IndSr, BError) ; BTrRead(FilCheck, FilCheck->Key, WKey, IndSr, BError) ;
*BError = BTrBOF; *BError = BTrBOF;
} }
else else
{ {
Repos(FilCheck, BError) ; Repos(FilCheck, BError) ;
if ((*BError != NoErr) && (*BError != BTrKeyNotFound)) if ((*BError != NoErr) && (*BError != BTrKeyNotFound))
{ {
if (*BError == BTrEOF) if (*BError == BTrEOF)
{ {
strcpy(KKey,FilCheck->Key); strcpy(KKey,FilCheck->Key);
*IndSr = FilCheck->Ind ; *IndSr = FilCheck->Ind ;
*BError = NoErr ; *BError = NoErr ;
} }
return; return;
} }
*BError = NoErr; *BError = NoErr;
if (FilCheck->Pos > 1) if (FilCheck->Pos > 1)
{ {
FilCheck->Pos--; FilCheck->Pos--;
GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr);
} }
else else
{ {
if (PathPage.PA.PageHeader.Prev == NoLink) if (PathPage.PA.PageHeader.Prev == NoLink)
{ {
GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr);
/*MinKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key);*/ /*MinKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key);*/
*BError = BTrBOF; *BError = BTrBOF;
} }
else else
{ {
FilCheck->CurPag = PathPage.PA.PageHeader.Prev; FilCheck->CurPag = PathPage.PA.PageHeader.Prev;
if (GetAPage(FilCheck, &PathPage, FilCheck->CurPag, BError) != NoErr) return; if (GetAPage(FilCheck, &PathPage, FilCheck->CurPag, BError) != NoErr) return;
FilCheck->Pos = PathPage.PA.PageHeader.NKey; FilCheck->Pos = PathPage.PA.PageHeader.NKey;
GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr);
} }
} }
strcpy(KKey, FilCheck->Key); strcpy(KKey, FilCheck->Key);
FilCheck->Ind = *IndSr ; FilCheck->Ind = *IndSr ;
} }
} }
/* /*
@($) Move B+TREE @($) Move B+TREE
@ -411,20 +415,20 @@ w = area di transito.
@(FSV) @(FSV)
*/ */
void Move(RghOrLft, NByt, BytBeg, BytDest, Buff1, Buff2) void Move(RghOrLft, NByt, BytBeg, BytDest, Buff1, Buff2)
byte RghOrLft; /* destra o sinistra */ byte RghOrLft; /* destra o sinistra */
int NByt; /* numero di byte da spostare */ int NByt; /* numero di byte da spostare */
int BytBeg; /* num. byte inizio sorgente */ int BytBeg; /* num. byte inizio sorgente */
int BytDest; /* num. byte inizio destinazione */ int BytDest; /* num. byte inizio destinazione */
AreaKey Buff1; /* sorgente */ AreaKey Buff1; /* sorgente */
AreaKey Buff2; /* destinazione */ AreaKey Buff2; /* destinazione */
{ {
AreaKey w; AreaKey w;
memcpy(w, &Buff1[BytBeg], NByt); memcpy(w, &Buff1[BytBeg], NByt);
memcpy(&Buff2[BytDest], w, NByt); memcpy(&Buff2[BytDest], w, NByt);
} }
/* /*
@($) ShiftPage B+TREE @($) ShiftPage B+TREE
@ -443,40 +447,40 @@ Dest = byte al quale si deve postare la coppia chiave-puntatore.
@(FSV) @(FSV)
*/ */
void ShiftPage(RghOrLft, StartK, NPos, MxKey, KeyLen, Page1) void ShiftPage(RghOrLft, StartK, NPos, MxKey, KeyLen, Page1)
byte RghOrLft; /* destra o sinistra */ byte RghOrLft; /* destra o sinistra */
int StartK; /* chiave di partenza */ int StartK; /* chiave di partenza */
int NPos; /* numero di posizioni da saltare */ int NPos; /* numero di posizioni da saltare */
int MxKey; /* numero max chiavi in una pagina */ int MxKey; /* numero max chiavi in una pagina */
int KeyLen; /* lunghezza di una chiave */ int KeyLen; /* lunghezza di una chiave */
Page *Page1; /* pagina attiva */ Page *Page1; /* pagina attiva */
{ {
register int Len = KeyLen + IndLen; register int Len = KeyLen + IndLen;
register int Beg = (StartK - 1) * Len; register int Beg = (StartK - 1) * Len;
register int Dest; register int Dest;
if (RghOrLft == RightDir) if (RghOrLft == RightDir)
{ {
Dest = Beg + NPos * Len; Dest = Beg + NPos * Len;
if (Page1->PA.PageHeader.NKey + NPos <= MxKey) if (Page1->PA.PageHeader.NKey + NPos <= MxKey)
{ {
Move(RightDir, (Page1->PA.PageHeader.NKey - StartK + 1) * Len, Beg, Dest, Page1->PA.AreaForKey, Page1->PA.AreaForKey); Move(RightDir, (Page1->PA.PageHeader.NKey - StartK + 1) * Len, Beg, Dest, Page1->PA.AreaForKey, Page1->PA.AreaForKey);
Page1->PA.PageHeader.NKey += NPos; Page1->PA.PageHeader.NKey += NPos;
} }
} }
else else
{ {
Dest = Beg - NPos * Len; Dest = Beg - NPos * Len;
if (StartK - NPos > 0) if (StartK - NPos > 0)
{ {
if (StartK <= Page1->PA.PageHeader.NKey) if (StartK <= Page1->PA.PageHeader.NKey)
Move(LeftDir, (Page1->PA.PageHeader.NKey - StartK + 1) * Len, Beg, Dest, Page1->PA.AreaForKey, Page1->PA.AreaForKey); Move(LeftDir, (Page1->PA.PageHeader.NKey - StartK + 1) * Len, Beg, Dest, Page1->PA.AreaForKey, Page1->PA.AreaForKey);
Page1->PA.PageHeader.NKey -= NPos; Page1->PA.PageHeader.NKey -= NPos;
memset(&Page1->PA.AreaForKey[Page1->PA.PageHeader.NKey * Len], ' ', NPos * Len); memset(&Page1->PA.AreaForKey[Page1->PA.PageHeader.NKey * Len], ' ', NPos * Len);
} }
} }
} }
/* /*
@($) ShiftOut B+TREE @($) ShiftOut B+TREE
@ -490,20 +494,20 @@ Len = lunghezza coppia chiave-puntatore.
@(FSV) @(FSV)
*/ */
void ShiftOut(FromK, Numk, ToK, KeyLen, Page1, Page2) void ShiftOut(FromK, Numk, ToK, KeyLen, Page1, Page2)
int FromK; /* prima chiave da spostare */ int FromK; /* prima chiave da spostare */
int Numk; /* numero di chiavi da spostare */ int Numk; /* numero di chiavi da spostare */
int ToK; /* posizione nella pagina destinazione */ int ToK; /* posizione nella pagina destinazione */
int KeyLen;/* lunghezza della chiave */ int KeyLen;/* lunghezza della chiave */
Page *Page1;/* puntatore alla pagina destinazione */ Page *Page1;/* puntatore alla pagina destinazione */
Page *Page2;/* puntatore alla pagina sorgente */ Page *Page2;/* puntatore alla pagina sorgente */
{ {
register int Len = KeyLen + IndLen; register int Len = KeyLen + IndLen;
if (Page1->PA.PageHeader.TPage == Page2->PA.PageHeader.TPage) if (Page1->PA.PageHeader.TPage == Page2->PA.PageHeader.TPage)
Move(LeftDir, Numk * Len, (FromK - 1) * Len, (ToK - 1) * Len, Page2->PA.AreaForKey, Page1->PA.AreaForKey); Move(LeftDir, Numk * Len, (FromK - 1) * Len, (ToK - 1) * Len, Page2->PA.AreaForKey, Page1->PA.AreaForKey);
} }
/* /*
@($) FindPos B+TREE @($) FindPos B+TREE
@ -521,27 +525,27 @@ j = incremento in byte di coppia chiave puntatore.
*/ */
int FindPos(ActPage, KKey, KeyLen, KeyOut, IndOut) int FindPos(ActPage, KKey, KeyLen, KeyOut, IndOut)
Page *ActPage; /* pagina attiva */ Page *ActPage; /* pagina attiva */
TKey KKey; /* valore chiave (input) */ TKey KKey; /* valore chiave (input) */
int KeyLen; /* lunghezza della chiave */ int KeyLen; /* lunghezza della chiave */
TKey KeyOut; /* valore chiave (output) */ TKey KeyOut; /* valore chiave (output) */
RecNoType *IndOut; /* indice associato */ RecNoType *IndOut; /* indice associato */
{ {
register int low = 1, j = 0; register int low = 1, j = 0;
while (strcmp((char *)(ActPage->PA.AreaForKey + j), KKey) < 0) while (strcmp((char *)(ActPage->PA.AreaForKey + j), KKey) < 0)
if (low < ActPage->PA.PageHeader.NKey) if (low < ActPage->PA.PageHeader.NKey)
{ {
low++; low++;
j += (KeyLen + IndLen); j += (KeyLen + IndLen);
} }
else break; else break;
strcpy(KeyOut, (char *)(ActPage->PA.AreaForKey + j)); strcpy(KeyOut, (char *)(ActPage->PA.AreaForKey + j));
*IndOut = *((RecNoType *)(ActPage->PA.AreaForKey + j + KeyLen)); *IndOut = *((RecNoType *)(ActPage->PA.AreaForKey + j + KeyLen));
return(low); return(low);
} }
/* /*
@($) PerformOp B+TREE @($) PerformOp B+TREE
@ -559,111 +563,111 @@ OldKey = variabile di lavoro contenente il valore di chiavi.
@(FSV) @(FSV)
*/ */
void PerformOp(RecOp,ActPage,Pg,OvUnFlow,Temp,MxKey,MnKey,KeyLen,BError) void PerformOp(RecOp,ActPage,Pg,OvUnFlow,Temp,MxKey,MnKey,KeyLen,BError)
KOp RecOp; /* struttura contenente le operazioni da effettuare */ KOp RecOp; /* struttura contenente le operazioni da effettuare */
Page *ActPage; /* pagina attiva */ Page *ActPage; /* pagina attiva */
RecNoType Pg; /* numero pagina */ RecNoType Pg; /* numero pagina */
BOOLEAN *OvUnFlow;/* underflow opp. overflow */ BOOLEAN *OvUnFlow;/* underflow opp. overflow */
KeyInd *Temp; /* di lavoro, contiene una coppia chiave-puntatore */ KeyInd *Temp; /* di lavoro, contiene una coppia chiave-puntatore */
int MxKey; /* numero max chiave */ int MxKey; /* numero max chiave */
int MnKey; /* numero min chiave */ int MnKey; /* numero min chiave */
int KeyLen; /* lunghezza della chiave */ int KeyLen; /* lunghezza della chiave */
int *BError; /* codice errore */ int *BError; /* codice errore */
{ {
int Pst, W, i; int Pst, W, i;
TKey OldKey; TKey OldKey;
for (W = 0; W <= 1; W++) for (W = 0; W <= 1; W++)
{ {
if (RecOp[W].FlagOp) if (RecOp[W].FlagOp)
{ {
RecOp[W].FlagOp = FALSE; RecOp[W].FlagOp = FALSE;
if (RecOp[W].Which == Inser) if (RecOp[W].Which == Inser)
{ {
Pst = 0; Pst = 0;
while (Pst < ActPage->PA.PageHeader.NKey ) while (Pst < ActPage->PA.PageHeader.NKey )
{ {
GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex);
if (IntIndex == RecOp[W].where) break; if (IntIndex == RecOp[W].where) break;
} }
if (ActPage->PA.PageHeader.NKey == MxKey) if (ActPage->PA.PageHeader.NKey == MxKey)
{ {
GetAKey(*ActPage, KeyLen, MxKey, IntKey, &IntIndex); GetAKey(*ActPage, KeyLen, MxKey, IntKey, &IntIndex);
if (strcmp(IntKey, RecOp[W].KeyAndInd.KKey) < 0) if (strcmp(IntKey, RecOp[W].KeyAndInd.KKey) < 0)
{ {
strcpy(Temp->KKey, RecOp[W].KeyAndInd.KKey); strcpy(Temp->KKey, RecOp[W].KeyAndInd.KKey);
Temp->Ind = RecOp[W].KeyAndInd.Ind; Temp->Ind = RecOp[W].KeyAndInd.Ind;
} }
else else
{ {
strcpy(Temp->KKey, IntKey); strcpy(Temp->KKey, IntKey);
Temp->Ind = IntIndex; Temp->Ind = IntIndex;
ActPage->PA.PageHeader.NKey--; ActPage->PA.PageHeader.NKey--;
ShiftPage(RightDir, Pst, OnePos, MxKey, KeyLen, ActPage); ShiftPage(RightDir, Pst, OnePos, MxKey, KeyLen, ActPage);
PutAKey(RecOp[W].KeyAndInd.KKey, RecOp[W].KeyAndInd.Ind, Pst, KeyLen, ActPage); PutAKey(RecOp[W].KeyAndInd.KKey, RecOp[W].KeyAndInd.Ind, Pst, KeyLen, ActPage);
} }
*OvUnFlow = TRUE; *OvUnFlow = TRUE;
} }
else else
{ {
*OvUnFlow = FALSE; *OvUnFlow = FALSE;
if (strcmp(IntKey, RecOp[W].KeyAndInd.KKey) < 0) if (strcmp(IntKey, RecOp[W].KeyAndInd.KKey) < 0)
{ {
ActPage->PA.PageHeader.NKey++; ActPage->PA.PageHeader.NKey++;
PutAKey(RecOp[W].KeyAndInd.KKey, RecOp[W].KeyAndInd.Ind, ActPage->PA.PageHeader.NKey, KeyLen, ActPage); PutAKey(RecOp[W].KeyAndInd.KKey, RecOp[W].KeyAndInd.Ind, ActPage->PA.PageHeader.NKey, KeyLen, ActPage);
RecOp[W].FlagOp = TRUE; RecOp[W].FlagOp = TRUE;
RecOp[W].Which = Change; RecOp[W].Which = Change;
RecOp[W].KeyAndInd.Ind = Pg; RecOp[W].KeyAndInd.Ind = Pg;
} }
else else
{ {
ShiftPage(RightDir, Pst, OnePos, MxKey, KeyLen, ActPage); ShiftPage(RightDir, Pst, OnePos, MxKey, KeyLen, ActPage);
PutAKey(RecOp[W].KeyAndInd.KKey, RecOp[W].KeyAndInd.Ind, Pst, KeyLen, ActPage); PutAKey(RecOp[W].KeyAndInd.KKey, RecOp[W].KeyAndInd.Ind, Pst, KeyLen, ActPage);
} }
} }
} }
else else
if (RecOp[W].Which == Change) if (RecOp[W].Which == Change)
{ {
Pst = 0; Pst = 0;
GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex);
while ((IntIndex != RecOp[W].KeyAndInd.Ind) && (Pst < ActPage->PA.PageHeader.NKey)) while ((IntIndex != RecOp[W].KeyAndInd.Ind) && (Pst < ActPage->PA.PageHeader.NKey))
GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex);
if (IntIndex == RecOp[W].KeyAndInd.Ind) if (IntIndex == RecOp[W].KeyAndInd.Ind)
PutAKey(RecOp[W].KeyAndInd.KKey, IntIndex, Pst, KeyLen, ActPage); PutAKey(RecOp[W].KeyAndInd.KKey, IntIndex, Pst, KeyLen, ActPage);
*OvUnFlow = FALSE; *OvUnFlow = FALSE;
if ((IntIndex == RecOp[W].KeyAndInd.Ind) && (Pst == ActPage->PA.PageHeader.NKey)) if ((IntIndex == RecOp[W].KeyAndInd.Ind) && (Pst == ActPage->PA.PageHeader.NKey))
{ {
RecOp[W].FlagOp = TRUE; RecOp[W].FlagOp = TRUE;
RecOp[W].Which = Change; RecOp[W].Which = Change;
RecOp[W].KeyAndInd.Ind = Pg; RecOp[W].KeyAndInd.Ind = Pg;
} }
} }
else else
if (RecOp[W].Which == Delet) if (RecOp[W].Which == Delet)
{ {
Pst = 0; Pst = 0;
GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex);
while ((IntIndex != RecOp[W].KeyAndInd.Ind) && (Pst < ActPage->PA.PageHeader.NKey)) while ((IntIndex != RecOp[W].KeyAndInd.Ind) && (Pst < ActPage->PA.PageHeader.NKey))
GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex);
if (IntIndex == RecOp[W].KeyAndInd.Ind) if (IntIndex == RecOp[W].KeyAndInd.Ind)
{ {
*OvUnFlow = (ActPage->PA.PageHeader.NKey == MnKey); *OvUnFlow = (ActPage->PA.PageHeader.NKey == MnKey);
ShiftPage(LeftDir, ++Pst, OnePos, MxKey, KeyLen, ActPage); ShiftPage(LeftDir, ++Pst, OnePos, MxKey, KeyLen, ActPage);
} }
} }
if ((!OvUnFlow) && (Pst >= ActPage->PA.PageHeader.NKey)) if ((!OvUnFlow) && (Pst >= ActPage->PA.PageHeader.NKey))
{ {
RecOp[W].FlagOp = TRUE; RecOp[W].FlagOp = TRUE;
RecOp[W].Which = Change; RecOp[W].Which = Change;
GetAKey(*ActPage, KeyLen, ActPage->PA.PageHeader.NKey, IntKey, &IntIndex); GetAKey(*ActPage, KeyLen, ActPage->PA.PageHeader.NKey, IntKey, &IntIndex);
strcpy(RecOp[W].KeyAndInd.KKey, IntKey); strcpy(RecOp[W].KeyAndInd.KKey, IntKey);
RecOp[W].KeyAndInd.Ind = Pg; RecOp[W].KeyAndInd.Ind = Pg;
} }
} }
} }
} }
/* /*
@($) ZrecOp B+TREE @($) ZrecOp B+TREE
@ -677,20 +681,20 @@ i = contatore.
@(FSV) @(FSV)
*/ */
void ZRecOp(R) void ZRecOp(R)
KOp R; /* struttura operazioni da azzerare */ KOp R; /* struttura operazioni da azzerare */
{ {
int i; int i;
for (i = 0; i <= 1; i++) for (i = 0; i <= 1; i++)
{ {
R[i].FlagOp = FALSE; R[i].FlagOp = FALSE;
R[i].Which = Nothing; R[i].Which = Nothing;
R[i].Posit = NoLink; R[i].Posit = NoLink;
R[i].where = -1; R[i].where = -1;
MinKey(MaxArray, R[i].KeyAndInd.KKey); MinKey(MaxArray, R[i].KeyAndInd.KKey);
R[i].KeyAndInd.Ind = NoLink; R[i].KeyAndInd.Ind = NoLink;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -3,15 +3,19 @@
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*/ */
#include <ccommon.h> #include <ccommon.h>
#include <genconst.h> #include <genconst.h>
#include <ccustio.h> #include <ccustio.h>
#include <cfiles.h> #include <cfiles.h>
#include <cbpltree.h> #include <cbpltree.h>
#include <cbplcre.h> #include <cbplcre.h>
#include <cisam.h> #include <cisam.h>
#include <memory.h> #ifdef __WATCOMC__
#include <progind.h> #include <malloc.h>
#else
#include <memory.h>
#endif
#include <progind.h>
/* /*
@(#) creorgfile ISAM @(#) creorgfile ISAM
@ -43,54 +47,54 @@ s = stringa messaggio.
@(FSV) @(FSV)
*/ */
int creorgfile(logicname,vis,err) int creorgfile(logicname,vis,err)
int logicname; /* numero logico del file */ int logicname; /* numero logico del file */
BOOLEAN vis; /* se true visualizza le operazioni che sta facendo */ BOOLEAN vis; /* se true visualizza le operazioni che sta facendo */
int *err; /* codice errore */ int *err; /* codice errore */
{ {
isfdptr wisfd; isfdptr wisfd;
RecType rec; RecType rec;
RecNoType i = 0L,k = 0L,oldeod; RecNoType i = 0L,k = 0L,oldeod;
int junk; int junk;
char s[80]; char s[80];
*err = NoErr; *err = NoErr;
if (cisopen(&wisfd, logicname, &rec, ExclLock, err)) return(*err); if (cisopen(&wisfd, logicname, &rec, ExclLock, err)) return(*err);
oldeod = wisfd->d->EOD; oldeod = wisfd->d->EOD;
if (vis && (oldeod > 0)) if (vis && (oldeod > 0))
{ {
sprintf(s,"Compatta - %s", wisfd->d->Des); sprintf(s,"Compatta - %s", wisfd->d->Des);
progind_create(wisfd->d->EOD, s, FALSE, TRUE, 70); progind_create(wisfd->d->EOD, s, FALSE, TRUE, 70);
} }
while (i < wisfd->d->EOD) while (i < wisfd->d->EOD)
{ {
i++; i++;
CRead(&wisfd->f, rec, i, NoLock); CRead(&wisfd->f, rec, i, NoLock);
if ((*err = wisfd->f.IOR)) break ; if ((*err = wisfd->f.IOR)) break ;
if (!IRecIsDeleted(rec)) if (!IRecIsDeleted(rec))
{ {
k++; k++;
if (k < i) CWrite(&wisfd->f, rec, k, NoLock); if (k < i) CWrite(&wisfd->f, rec, k, NoLock);
} }
if (vis && (oldeod > 0) && (!(i % 10))) if (vis && (oldeod > 0) && (!(i % 10)))
progind_set_status(i); progind_set_status(i);
} }
if (vis && (oldeod > 0)) if (vis && (oldeod > 0))
progind_set_status(i); progind_set_status(i);
if (!*err) if (!*err)
{ {
wisfd->d->EOD = k; wisfd->d->EOD = k;
#ifndef DOS #ifndef DOS
writelog(FNREORG, NULL, (RecType) &oldeod); writelog(FNREORG, NULL, (RecType) &oldeod);
#endif #endif
junk = cisupdflags(wisfd, &junk, TRUE); junk = cisupdflags(wisfd, &junk, TRUE);
} }
junk = cisclose(&wisfd, &rec, &junk); junk = cisclose(&wisfd, &rec, &junk);
if (vis && oldeod > 0) if (vis && oldeod > 0)
progind_destroy(); progind_destroy();
return(*err); return(*err);
} }
/* /*
@(#) creorgindex ISAM @(#) creorgindex ISAM
@ -119,62 +123,62 @@ Deve essere usata in coppia con la "creorgfile".
@(FN) @(FN)
*/ */
int creorgindex(logicname,vis,err) int creorgindex(logicname,vis,err)
int logicname; /* numero logico del file */ int logicname; /* numero logico del file */
BOOLEAN vis; /* se true visualizza cio' che sta facendo */ BOOLEAN vis; /* se true visualizza cio' che sta facendo */
int *err; /* codice errore */ int *err; /* codice errore */
{ {
isfdptr wisfd; isfdptr wisfd;
RecType rec; RecType rec;
int junk, j; int junk, j;
char s[80]; char s[80];
int werr = NoErr; int werr = NoErr;
*err = NoErr; *err = NoErr;
getisfd(&wisfd, logicname); getisfd(&wisfd, logicname);
CBInitFile(&wisfd->i); CBInitFile(&wisfd->i);
for (j = 1; j <= wisfd->r->NKeys;j++) for (j = 1; j <= wisfd->r->NKeys;j++)
{ {
CBInitPath(j,CCalcLenKey(wisfd->r,j),wisfd->d->EOX, CBInitPath(j,CCalcLenKey(wisfd->r,j),wisfd->d->EOX,
wisfd->r->Ky[j-1].DupKeys,&(wisfd->i),err); wisfd->r->Ky[j-1].DupKeys,&(wisfd->i),err);
if (*err) if (*err)
{ {
relisfd(&wisfd); relisfd(&wisfd);
return (*err); return (*err);
} }
} }
junk = unlink(CGetIdxName(wisfd->d->SysName)); junk = unlink(CGetIdxName(wisfd->d->SysName));
CBCreate(&wisfd->i, CGetIdxName(wisfd->d->SysName),err); CBCreate(&wisfd->i, CGetIdxName(wisfd->d->SysName),err);
relisfd(&wisfd); relisfd(&wisfd);
if (*err) return (*err); if (*err) return (*err);
if (cisopen(&wisfd, logicname, &rec, ExclLock, err)) return(*err); if (cisopen(&wisfd, logicname, &rec, ExclLock, err)) return(*err);
wisfd->RecNo = 0L; wisfd->RecNo = 0L;
if (vis && (wisfd->d->EOD > 0)) if (vis && (wisfd->d->EOD > 0))
{ {
sprintf(s,"Crea indice - %s", wisfd->d->Des); sprintf(s,"Crea indice - %s", wisfd->d->Des);
progind_create(wisfd->d->EOD, s, FALSE, TRUE, 70); progind_create(wisfd->d->EOD, s, FALSE, TRUE, 70);
} }
while (wisfd->RecNo < wisfd->d->EOD) while (wisfd->RecNo < wisfd->d->EOD)
{ {
wisfd->RecNo++; wisfd->RecNo++;
CRead(&wisfd->f, rec, wisfd->RecNo, NoLock); CRead(&wisfd->f, rec, wisfd->RecNo, NoLock);
werr = wisfd->f.IOR; werr = wisfd->f.IOR;
if (!IRecIsDeleted(rec)) if (!IRecIsDeleted(rec))
addkeys(wisfd,rec,1,&werr); addkeys(wisfd,rec,1,&werr);
if (vis && (wisfd->d->EOD > 0) && (!(wisfd->RecNo % 10))) if (vis && (wisfd->d->EOD > 0) && (!(wisfd->RecNo % 10)))
progind_set_status(wisfd->RecNo); progind_set_status(wisfd->RecNo);
if (werr != NoErr && *err == NoErr) if (werr != NoErr && *err == NoErr)
*err = werr; *err = werr;
} }
if (vis && (wisfd->d->EOD > 0)) if (vis && (wisfd->d->EOD > 0))
progind_set_status(wisfd->RecNo); progind_set_status(wisfd->RecNo);
junk = cisclose(&wisfd, &rec, &junk); junk = cisclose(&wisfd, &rec, &junk);
if (vis) if (vis)
progind_destroy(); progind_destroy();
if (*err != NoErr) if (*err != NoErr)
error_box("Si e' verificato almeno un errore n. %d\nVerificare l'archivio e ripetere il compattamento", *err); error_box("Si e' verificato almeno un errore n. %d\nVerificare l'archivio e ripetere il compattamento", *err);
return(*err); return(*err);
} }