From 9a59449da39c383f1d91d8f1f89afff3f59c7df8 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 15 Mar 1995 17:01:27 +0000 Subject: [PATCH] Aggiunto malloc.h per il WATCOM C++ compiler git-svn-id: svn://10.65.10.50/trunk@1127 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/btrbase.c | 852 +++++++++--------- include/cisam.c | 2166 +++++++++++++++++++++++---------------------- include/isreorg.c | 220 ++--- 3 files changed, 1625 insertions(+), 1613 deletions(-) diff --git a/include/btrbase.c b/include/btrbase.c index cb2e6471b..978f7cf79 100755 --- a/include/btrbase.c +++ b/include/btrbase.c @@ -7,7 +7,11 @@ #include "btrread.h" #include "btrbase.h" #include "checks.h" +#ifdef __WATCOMC__ +#include +#else #include +#endif void Move(byte ,int ,int ,int ,char *,char *); @@ -21,20 +25,20 @@ Azzera una pagina del B+TREE. @(FD) */ - void ZPage(ActPage) - Page *ActPage; /* pagina attuale */ + void ZPage(ActPage) + Page *ActPage; /* pagina attuale */ - { + { - ActPage->PA.PageHeader.TPage = EmptyPage; - ActPage->PA.PageHeader.PathNumber = 0; - ActPage->PA.PageHeader.Flags = 0; - ActPage->PA.PageHeader.Father = NoLink; - ActPage->PA.PageHeader.Prev = NoLink; - ActPage->PA.PageHeader.Next = NoLink; - ActPage->PA.PageHeader.NKey = 0; - memset(ActPage->PA.AreaForKey, ' ', AreaLen); - } + ActPage->PA.PageHeader.TPage = EmptyPage; + ActPage->PA.PageHeader.PathNumber = 0; + ActPage->PA.PageHeader.Flags = 0; + ActPage->PA.PageHeader.Father = NoLink; + ActPage->PA.PageHeader.Prev = NoLink; + ActPage->PA.PageHeader.Next = NoLink; + ActPage->PA.PageHeader.NKey = 0; + memset(ActPage->PA.AreaForKey, ' ', AreaLen); + } /* @($) GetHeader B+TREE @@ -53,21 +57,21 @@ w = descrittore della finestra. */ - int GetHeader(FilCheck, HPage, LockMode, Err) - FilCtrl *FilCheck; /* identificatore indice */ - Page *HPage; /* pagina dell' indice */ - int LockMode; /* lock sull'header */ - int *Err; /* codice di errore */ + int GetHeader(FilCheck, HPage, LockMode, Err) + FilCtrl *FilCheck; /* identificatore indice */ + Page *HPage; /* pagina dell' indice */ + int LockMode; /* lock sull'header */ + int *Err; /* codice di errore */ - { - do - { - CRead(&FilCheck->Fil, (char *) HPage, 1L, LockMode); - if (TESTLOCK(FilCheck->Fil.IOR)) - message_box("Sono in attesa dell' indice"); - } while TESTLOCK(FilCheck->Fil.IOR); - return((*Err = FilCheck->Fil.IOR)); - } + { + do + { + CRead(&FilCheck->Fil, (char *) HPage, 1L, LockMode); + if (TESTLOCK(FilCheck->Fil.IOR)) + message_box("Sono in attesa dell' indice"); + } while TESTLOCK(FilCheck->Fil.IOR); + return((*Err = FilCheck->Fil.IOR)); + } /* @($) PutHeader B+TREE @@ -78,16 +82,16 @@ Restituisce il codice di errore. @(FD) */ - int PutHeader(FilCheck, HPage, LockMode, Err) - FilCtrl *FilCheck; /* identificatore indice */ - Page *HPage; /* pagina in cui scrivere l'header */ - int LockMode; /* lock sull'header */ - int *Err; /* errore */ + int PutHeader(FilCheck, HPage, LockMode, Err) + FilCtrl *FilCheck; /* identificatore indice */ + Page *HPage; /* pagina in cui scrivere l'header */ + int LockMode; /* lock sull'header */ + int *Err; /* errore */ - { - CWrite(&FilCheck->Fil, (char *) HPage, 1L, LockMode); - return((*Err = FilCheck->Fil.IOR)); - } + { + CWrite(&FilCheck->Fil, (char *) HPage, 1L, LockMode); + return((*Err = FilCheck->Fil.IOR)); + } /* @($) GetAPage B+TREE @@ -98,17 +102,17 @@ Restituisce il codice di errore. @(FD) */ - int GetAPage(FilCheck, ActPage, Pg, Err) - FilCtrl *FilCheck; /* identificatore indice */ - Page *ActPage; /* pagina letta */ - RecNoType Pg; /* numero di pagina */ - int *Err; /* codice di errore */ + int GetAPage(FilCheck, ActPage, Pg, Err) + FilCtrl *FilCheck; /* identificatore indice */ + Page *ActPage; /* pagina letta */ + RecNoType Pg; /* numero di pagina */ + int *Err; /* codice di errore */ - { - CRead(&FilCheck->Fil, (char *) ActPage, Pg + FilCheck->FHead.CABlock + 1, - NoLock); - return((*Err = FilCheck->Fil.IOR)); - } + { + CRead(&FilCheck->Fil, (char *) ActPage, Pg + FilCheck->FHead.CABlock + 1, + NoLock); + return((*Err = FilCheck->Fil.IOR)); + } /* @($) PutAPage B+TREE @@ -119,17 +123,17 @@ Restituisce il codice di errore. @(FD) */ - int PutAPage(FilCheck, ActPage, Pg, Err) - FilCtrl *FilCheck; /* identificatore indice */ - Page *ActPage; /* pagina attiva */ - RecNoType Pg; /* numero della pagina */ - int *Err; /* codice errore */ + int PutAPage(FilCheck, ActPage, Pg, Err) + FilCtrl *FilCheck; /* identificatore indice */ + Page *ActPage; /* pagina attiva */ + RecNoType Pg; /* numero della pagina */ + int *Err; /* codice errore */ - { - CWrite(&FilCheck->Fil, (char *) ActPage, Pg + FilCheck->FHead.CABlock + 1, - NoLock); - return((*Err = FilCheck->Fil.IOR)); - } + { + CWrite(&FilCheck->Fil, (char *) ActPage, Pg + FilCheck->FHead.CABlock + 1, + NoLock); + return((*Err = FilCheck->Fil.IOR)); + } /* @($) GetAKey B+TREE @@ -143,20 +147,20 @@ BgnItem = numero di byte precedenti alla chiave dall'inizio della pagina. @(FSV) */ - void GetAKey(ActPage, KeyLen, Pstion, KKey, Index) - Page ActPage; /* pagina attiva */ - int KeyLen; /* lunghezza della chiave */ - int Pstion; /* numero chiave nella pagina */ - TKey KKey; /* Valore chiave (in output) */ - RecNoType *Index; /* indice associato a questa chiave */ + void GetAKey(ActPage, KeyLen, Pstion, KKey, Index) + Page ActPage; /* pagina attiva */ + int KeyLen; /* lunghezza della chiave */ + int Pstion; /* numero chiave nella pagina */ + TKey KKey; /* Valore chiave (in output) */ + RecNoType *Index; /* indice associato a questa chiave */ - { - int BgnItem; + { + int BgnItem; - BgnItem = (Pstion - 1) * (KeyLen + IndLen); - strcpy(KKey, (char *)(ActPage.PA.AreaForKey + BgnItem)); - *Index = *((RecNoType *)(ActPage.PA.AreaForKey + BgnItem + KeyLen)); - } + BgnItem = (Pstion - 1) * (KeyLen + IndLen); + strcpy(KKey, (char *)(ActPage.PA.AreaForKey + BgnItem)); + *Index = *((RecNoType *)(ActPage.PA.AreaForKey + BgnItem + KeyLen)); + } /* @($) PutAKey B+TREE @@ -170,20 +174,20 @@ BgnItem = numero di byte precedenti alla chiave dall'inizio della pagina. @(FSV) */ - void PutAKey(KKey, Index, Pstion, KeyLen, ActPage) - TKey KKey; /* valore della chiave */ - RecNoType Index; /* indice */ - int Pstion; /* posizione nella quale scrivere la chiave */ - int KeyLen; /* lunghezza della chiave */ - Page *ActPage;/* pagina attiva */ + void PutAKey(KKey, Index, Pstion, KeyLen, ActPage) + TKey KKey; /* valore della chiave */ + RecNoType Index; /* indice */ + int Pstion; /* posizione nella quale scrivere la chiave */ + int KeyLen; /* lunghezza della chiave */ + Page *ActPage;/* pagina attiva */ - { - register int BgnItem; + { + register int BgnItem; - BgnItem = (Pstion - 1) * (KeyLen + IndLen); - strcpy((char *)(ActPage->PA.AreaForKey + BgnItem), KKey); - *((RecNoType *)(ActPage->PA.AreaForKey + BgnItem + KeyLen)) = Index; - } + BgnItem = (Pstion - 1) * (KeyLen + IndLen); + strcpy((char *)(ActPage->PA.AreaForKey + BgnItem), KKey); + *((RecNoType *)(ActPage->PA.AreaForKey + BgnItem + KeyLen)) = Index; + } /* @($) Repos B+TREE @@ -207,59 +211,59 @@ Serve solo in multiutenza (XENIX). @(FN) */ - void Repos(FilCheck, BError) - FilCtrl *FilCheck; /* identificatore indice */ - int *BError; /* codice errore (in output) */ + void Repos(FilCheck, BError) + FilCtrl *FilCheck; /* identificatore indice */ + int *BError; /* codice errore (in output) */ - { - TKey WKey, WKey1; - int WPos = FilCheck->Pos, WError; - RecNoType WPag = FilCheck->CurPag, WInd, WInd1; + { + TKey WKey, WKey1; + int WPos = FilCheck->Pos, WError; + RecNoType WPag = FilCheck->CurPag, WInd, WInd1; - if (GetAPage(FilCheck, &PathPage, WPag, BError) != NoErr) return; - if (PathPage.PA.PageHeader.NKey < WPos) WPos = PathPage.PA.PageHeader.NKey ; - GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, WPos, WKey, &WInd); - if ((strcmp(WKey, FilCheck->Key) == 0) && (WInd == FilCheck->Ind)) return ; - strcpy(WKey1, FilCheck->Key) ; - WInd = FilCheck->Ind ; - BTrRead(FilCheck, FilCheck->Key, WKey, &WInd1, BError) ; - WPag = FilCheck->CurPag ; - WPos = FilCheck->Pos ; - if (*BError == BTrEmptyTree) return ; - if (FilCheck->Base[FilCheck->PN].DupKeys == TRUE) - { - while ((strcmp(WKey, WKey1) == 0) && (WInd1 < WInd)) - { - if (WPos < PathPage.PA.PageHeader.NKey) WPos++; - else - if (PathPage.PA.PageHeader.Next == NoLink) break; - else - { - WPag = PathPage.PA.PageHeader.Next; - if (GetAPage(FilCheck, &PathPage, WPag, BError) != NoErr) return; - WPos = 1; - } - GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, WPos, WKey, &WInd1); - } - } - if (GetAPage(FilCheck, &PathPage, WPag, &WError) != NoErr) return; - if ((strcmp(WKey, WKey1) == 0) && (WInd == WInd1)) - { - FilCheck->CurPag = WPag; - FilCheck->Pos = WPos; - } - else - { - if (*BError != BTrEOF) - { - FilCheck->CurPag = WPag; - FilCheck->Pos = WPos; - strcpy(FilCheck->Key, WKey) ; - FilCheck->Ind = WInd1; - *BError = BTrKeyNotFound; - } - } - } + if (GetAPage(FilCheck, &PathPage, WPag, BError) != NoErr) return; + if (PathPage.PA.PageHeader.NKey < WPos) WPos = PathPage.PA.PageHeader.NKey ; + GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, WPos, WKey, &WInd); + if ((strcmp(WKey, FilCheck->Key) == 0) && (WInd == FilCheck->Ind)) return ; + strcpy(WKey1, FilCheck->Key) ; + WInd = FilCheck->Ind ; + BTrRead(FilCheck, FilCheck->Key, WKey, &WInd1, BError) ; + WPag = FilCheck->CurPag ; + WPos = FilCheck->Pos ; + if (*BError == BTrEmptyTree) return ; + if (FilCheck->Base[FilCheck->PN].DupKeys == TRUE) + { + while ((strcmp(WKey, WKey1) == 0) && (WInd1 < WInd)) + { + if (WPos < PathPage.PA.PageHeader.NKey) WPos++; + else + if (PathPage.PA.PageHeader.Next == NoLink) break; + else + { + WPag = PathPage.PA.PageHeader.Next; + if (GetAPage(FilCheck, &PathPage, WPag, BError) != NoErr) return; + WPos = 1; + } + GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, WPos, WKey, &WInd1); + } + } + if (GetAPage(FilCheck, &PathPage, WPag, &WError) != NoErr) return; + if ((strcmp(WKey, WKey1) == 0) && (WInd == WInd1)) + { + FilCheck->CurPag = WPag; + FilCheck->Pos = WPos; + } + else + { + if (*BError != BTrEOF) + { + FilCheck->CurPag = WPag; + FilCheck->Pos = WPos; + strcpy(FilCheck->Key, WKey) ; + FilCheck->Ind = WInd1; + *BError = BTrKeyNotFound; + } + } + } /* @($) BTrNext B+TREE @@ -275,59 +279,59 @@ WKey = variabile di lavoro contenente la chiave. @(FSV) */ - void BTrNext(FilCheck, KKey, IndSr, BError) - FilCtrl *FilCheck; /* identificatore indice */ - TKey KKey; /* valore della chiave */ - RecNoType *IndSr; /* indice associato */ - int *BError; /* codice errore */ + void BTrNext(FilCheck, KKey, IndSr, BError) + FilCtrl *FilCheck; /* identificatore indice */ + TKey KKey; /* valore della chiave */ + RecNoType *IndSr; /* indice associato */ + int *BError; /* codice errore */ - { - TKey WKey; + { + TKey WKey; - if (FilCheck->CurPag == NoLink) - { - MaxKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key); - BTrRead(FilCheck, FilCheck->Key, WKey, IndSr, BError) ; - *BError = BTrEOF; - } - else - { - Repos(FilCheck, BError) ; - if (*BError != NoErr) - { - if (*BError == BTrKeyNotFound) - { - strcpy(KKey,FilCheck->Key); - *IndSr = FilCheck->Ind ; - *BError = NoErr ; - } - return; - } - if (FilCheck->Pos < PathPage.PA.PageHeader.NKey) - { - FilCheck->Pos++; - GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); - } - else - { - if (PathPage.PA.PageHeader.Next == NoLink) - { - GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); - /*MaxKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key);*/ - *BError = BTrEOF; - } - else - { - FilCheck->CurPag = PathPage.PA.PageHeader.Next; - if (GetAPage(FilCheck, &PathPage, FilCheck->CurPag, BError) != NoErr) return; - FilCheck->Pos = 1; - GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); - } - } - strcpy(KKey,FilCheck->Key); - FilCheck->Ind = *IndSr ; - } - } + if (FilCheck->CurPag == NoLink) + { + MaxKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key); + BTrRead(FilCheck, FilCheck->Key, WKey, IndSr, BError) ; + *BError = BTrEOF; + } + else + { + Repos(FilCheck, BError) ; + if (*BError != NoErr) + { + if (*BError == BTrKeyNotFound) + { + strcpy(KKey,FilCheck->Key); + *IndSr = FilCheck->Ind ; + *BError = NoErr ; + } + return; + } + if (FilCheck->Pos < PathPage.PA.PageHeader.NKey) + { + FilCheck->Pos++; + GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); + } + else + { + if (PathPage.PA.PageHeader.Next == NoLink) + { + GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); + /*MaxKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key);*/ + *BError = BTrEOF; + } + else + { + FilCheck->CurPag = PathPage.PA.PageHeader.Next; + if (GetAPage(FilCheck, &PathPage, FilCheck->CurPag, BError) != NoErr) return; + FilCheck->Pos = 1; + GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); + } + } + strcpy(KKey,FilCheck->Key); + FilCheck->Ind = *IndSr ; + } + } /* @($) BTrPrev B+TREE @@ -343,60 +347,60 @@ WKey = variabile di lavoro contenente una chiave. @(FSV) */ - void BTrPrev(FilCheck, KKey, IndSr, BError) - FilCtrl *FilCheck; /* identificatore indice */ - TKey KKey; /* valore della chiave (in output) */ - RecNoType *IndSr; /* indice associato */ - int *BError; /* codice di errore */ + void BTrPrev(FilCheck, KKey, IndSr, BError) + FilCtrl *FilCheck; /* identificatore indice */ + TKey KKey; /* valore della chiave (in output) */ + RecNoType *IndSr; /* indice associato */ + int *BError; /* codice di errore */ - { - TKey WKey; + { + TKey WKey; - if (FilCheck->CurPag == NoLink) - { - MinKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key); - BTrRead(FilCheck, FilCheck->Key, WKey, IndSr, BError) ; - *BError = BTrBOF; - } - else - { - Repos(FilCheck, BError) ; - if ((*BError != NoErr) && (*BError != BTrKeyNotFound)) - { - if (*BError == BTrEOF) - { - strcpy(KKey,FilCheck->Key); - *IndSr = FilCheck->Ind ; - *BError = NoErr ; - } - return; - } - *BError = NoErr; - if (FilCheck->Pos > 1) - { - FilCheck->Pos--; - GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); - } - else - { - if (PathPage.PA.PageHeader.Prev == NoLink) - { - GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); - /*MinKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key);*/ - *BError = BTrBOF; - } - else - { - FilCheck->CurPag = PathPage.PA.PageHeader.Prev; - if (GetAPage(FilCheck, &PathPage, FilCheck->CurPag, BError) != NoErr) return; - FilCheck->Pos = PathPage.PA.PageHeader.NKey; - GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); - } - } - strcpy(KKey, FilCheck->Key); - FilCheck->Ind = *IndSr ; - } - } + if (FilCheck->CurPag == NoLink) + { + MinKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key); + BTrRead(FilCheck, FilCheck->Key, WKey, IndSr, BError) ; + *BError = BTrBOF; + } + else + { + Repos(FilCheck, BError) ; + if ((*BError != NoErr) && (*BError != BTrKeyNotFound)) + { + if (*BError == BTrEOF) + { + strcpy(KKey,FilCheck->Key); + *IndSr = FilCheck->Ind ; + *BError = NoErr ; + } + return; + } + *BError = NoErr; + if (FilCheck->Pos > 1) + { + FilCheck->Pos--; + GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); + } + else + { + if (PathPage.PA.PageHeader.Prev == NoLink) + { + GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); + /*MinKey(FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Key);*/ + *BError = BTrBOF; + } + else + { + FilCheck->CurPag = PathPage.PA.PageHeader.Prev; + if (GetAPage(FilCheck, &PathPage, FilCheck->CurPag, BError) != NoErr) return; + FilCheck->Pos = PathPage.PA.PageHeader.NKey; + GetAKey(PathPage, FilCheck->Base[FilCheck->PN].KeyLen, FilCheck->Pos, FilCheck->Key, IndSr); + } + } + strcpy(KKey, FilCheck->Key); + FilCheck->Ind = *IndSr ; + } + } /* @($) Move B+TREE @@ -411,20 +415,20 @@ w = area di transito. @(FSV) */ - void Move(RghOrLft, NByt, BytBeg, BytDest, Buff1, Buff2) - byte RghOrLft; /* destra o sinistra */ - int NByt; /* numero di byte da spostare */ - int BytBeg; /* num. byte inizio sorgente */ - int BytDest; /* num. byte inizio destinazione */ - AreaKey Buff1; /* sorgente */ - AreaKey Buff2; /* destinazione */ + void Move(RghOrLft, NByt, BytBeg, BytDest, Buff1, Buff2) + byte RghOrLft; /* destra o sinistra */ + int NByt; /* numero di byte da spostare */ + int BytBeg; /* num. byte inizio sorgente */ + int BytDest; /* num. byte inizio destinazione */ + AreaKey Buff1; /* sorgente */ + AreaKey Buff2; /* destinazione */ - { - AreaKey w; + { + AreaKey w; - memcpy(w, &Buff1[BytBeg], NByt); - memcpy(&Buff2[BytDest], w, NByt); - } + memcpy(w, &Buff1[BytBeg], NByt); + memcpy(&Buff2[BytDest], w, NByt); + } /* @($) ShiftPage B+TREE @@ -443,40 +447,40 @@ Dest = byte al quale si deve postare la coppia chiave-puntatore. @(FSV) */ - void ShiftPage(RghOrLft, StartK, NPos, MxKey, KeyLen, Page1) - byte RghOrLft; /* destra o sinistra */ - int StartK; /* chiave di partenza */ - int NPos; /* numero di posizioni da saltare */ - int MxKey; /* numero max chiavi in una pagina */ - int KeyLen; /* lunghezza di una chiave */ - Page *Page1; /* pagina attiva */ + void ShiftPage(RghOrLft, StartK, NPos, MxKey, KeyLen, Page1) + byte RghOrLft; /* destra o sinistra */ + int StartK; /* chiave di partenza */ + int NPos; /* numero di posizioni da saltare */ + int MxKey; /* numero max chiavi in una pagina */ + int KeyLen; /* lunghezza di una chiave */ + Page *Page1; /* pagina attiva */ - { - register int Len = KeyLen + IndLen; - register int Beg = (StartK - 1) * Len; - register int Dest; + { + register int Len = KeyLen + IndLen; + register int Beg = (StartK - 1) * Len; + register int Dest; - if (RghOrLft == RightDir) - { - Dest = Beg + NPos * Len; - if (Page1->PA.PageHeader.NKey + NPos <= MxKey) - { - Move(RightDir, (Page1->PA.PageHeader.NKey - StartK + 1) * Len, Beg, Dest, Page1->PA.AreaForKey, Page1->PA.AreaForKey); - Page1->PA.PageHeader.NKey += NPos; - } - } - else - { - Dest = Beg - NPos * Len; - if (StartK - NPos > 0) - { - if (StartK <= Page1->PA.PageHeader.NKey) - Move(LeftDir, (Page1->PA.PageHeader.NKey - StartK + 1) * Len, Beg, Dest, Page1->PA.AreaForKey, Page1->PA.AreaForKey); - Page1->PA.PageHeader.NKey -= NPos; - memset(&Page1->PA.AreaForKey[Page1->PA.PageHeader.NKey * Len], ' ', NPos * Len); - } - } - } + if (RghOrLft == RightDir) + { + Dest = Beg + NPos * Len; + if (Page1->PA.PageHeader.NKey + NPos <= MxKey) + { + Move(RightDir, (Page1->PA.PageHeader.NKey - StartK + 1) * Len, Beg, Dest, Page1->PA.AreaForKey, Page1->PA.AreaForKey); + Page1->PA.PageHeader.NKey += NPos; + } + } + else + { + Dest = Beg - NPos * Len; + if (StartK - NPos > 0) + { + if (StartK <= Page1->PA.PageHeader.NKey) + Move(LeftDir, (Page1->PA.PageHeader.NKey - StartK + 1) * Len, Beg, Dest, Page1->PA.AreaForKey, Page1->PA.AreaForKey); + Page1->PA.PageHeader.NKey -= NPos; + memset(&Page1->PA.AreaForKey[Page1->PA.PageHeader.NKey * Len], ' ', NPos * Len); + } + } + } /* @($) ShiftOut B+TREE @@ -490,20 +494,20 @@ Len = lunghezza coppia chiave-puntatore. @(FSV) */ - void ShiftOut(FromK, Numk, ToK, KeyLen, Page1, Page2) - int FromK; /* prima chiave da spostare */ - int Numk; /* numero di chiavi da spostare */ - int ToK; /* posizione nella pagina destinazione */ - int KeyLen;/* lunghezza della chiave */ - Page *Page1;/* puntatore alla pagina destinazione */ - Page *Page2;/* puntatore alla pagina sorgente */ + void ShiftOut(FromK, Numk, ToK, KeyLen, Page1, Page2) + int FromK; /* prima chiave da spostare */ + int Numk; /* numero di chiavi da spostare */ + int ToK; /* posizione nella pagina destinazione */ + int KeyLen;/* lunghezza della chiave */ + Page *Page1;/* puntatore alla pagina destinazione */ + 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) - Move(LeftDir, Numk * Len, (FromK - 1) * Len, (ToK - 1) * Len, Page2->PA.AreaForKey, Page1->PA.AreaForKey); - } + 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); + } /* @($) FindPos B+TREE @@ -521,27 +525,27 @@ j = incremento in byte di coppia chiave puntatore. */ - int FindPos(ActPage, KKey, KeyLen, KeyOut, IndOut) - Page *ActPage; /* pagina attiva */ - TKey KKey; /* valore chiave (input) */ - int KeyLen; /* lunghezza della chiave */ - TKey KeyOut; /* valore chiave (output) */ - RecNoType *IndOut; /* indice associato */ + int FindPos(ActPage, KKey, KeyLen, KeyOut, IndOut) + Page *ActPage; /* pagina attiva */ + TKey KKey; /* valore chiave (input) */ + int KeyLen; /* lunghezza della chiave */ + TKey KeyOut; /* valore chiave (output) */ + 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) - { - low++; - j += (KeyLen + IndLen); - } - else break; - strcpy(KeyOut, (char *)(ActPage->PA.AreaForKey + j)); - *IndOut = *((RecNoType *)(ActPage->PA.AreaForKey + j + KeyLen)); - return(low); - } + { + low++; + j += (KeyLen + IndLen); + } + else break; + strcpy(KeyOut, (char *)(ActPage->PA.AreaForKey + j)); + *IndOut = *((RecNoType *)(ActPage->PA.AreaForKey + j + KeyLen)); + return(low); + } /* @($) PerformOp B+TREE @@ -559,111 +563,111 @@ OldKey = variabile di lavoro contenente il valore di chiavi. @(FSV) */ - void PerformOp(RecOp,ActPage,Pg,OvUnFlow,Temp,MxKey,MnKey,KeyLen,BError) - KOp RecOp; /* struttura contenente le operazioni da effettuare */ - Page *ActPage; /* pagina attiva */ - RecNoType Pg; /* numero pagina */ - BOOLEAN *OvUnFlow;/* underflow opp. overflow */ - KeyInd *Temp; /* di lavoro, contiene una coppia chiave-puntatore */ - int MxKey; /* numero max chiave */ - int MnKey; /* numero min chiave */ - int KeyLen; /* lunghezza della chiave */ - int *BError; /* codice errore */ + void PerformOp(RecOp,ActPage,Pg,OvUnFlow,Temp,MxKey,MnKey,KeyLen,BError) + KOp RecOp; /* struttura contenente le operazioni da effettuare */ + Page *ActPage; /* pagina attiva */ + RecNoType Pg; /* numero pagina */ + BOOLEAN *OvUnFlow;/* underflow opp. overflow */ + KeyInd *Temp; /* di lavoro, contiene una coppia chiave-puntatore */ + int MxKey; /* numero max chiave */ + int MnKey; /* numero min chiave */ + int KeyLen; /* lunghezza della chiave */ + int *BError; /* codice errore */ - { - int Pst, W, i; - TKey OldKey; + { + int Pst, W, i; + TKey OldKey; - for (W = 0; W <= 1; W++) - { - if (RecOp[W].FlagOp) - { - RecOp[W].FlagOp = FALSE; - if (RecOp[W].Which == Inser) - { - Pst = 0; - while (Pst < ActPage->PA.PageHeader.NKey ) - { - GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); - if (IntIndex == RecOp[W].where) break; - } - if (ActPage->PA.PageHeader.NKey == MxKey) - { - GetAKey(*ActPage, KeyLen, MxKey, IntKey, &IntIndex); - if (strcmp(IntKey, RecOp[W].KeyAndInd.KKey) < 0) - { - strcpy(Temp->KKey, RecOp[W].KeyAndInd.KKey); - Temp->Ind = RecOp[W].KeyAndInd.Ind; - } - else - { - strcpy(Temp->KKey, IntKey); - Temp->Ind = IntIndex; - ActPage->PA.PageHeader.NKey--; - ShiftPage(RightDir, Pst, OnePos, MxKey, KeyLen, ActPage); - PutAKey(RecOp[W].KeyAndInd.KKey, RecOp[W].KeyAndInd.Ind, Pst, KeyLen, ActPage); - } - *OvUnFlow = TRUE; - } - else - { - *OvUnFlow = FALSE; - if (strcmp(IntKey, RecOp[W].KeyAndInd.KKey) < 0) - { - ActPage->PA.PageHeader.NKey++; - PutAKey(RecOp[W].KeyAndInd.KKey, RecOp[W].KeyAndInd.Ind, ActPage->PA.PageHeader.NKey, KeyLen, ActPage); - RecOp[W].FlagOp = TRUE; - RecOp[W].Which = Change; - RecOp[W].KeyAndInd.Ind = Pg; - } - else - { - ShiftPage(RightDir, Pst, OnePos, MxKey, KeyLen, ActPage); - PutAKey(RecOp[W].KeyAndInd.KKey, RecOp[W].KeyAndInd.Ind, Pst, KeyLen, ActPage); - } - } - } - else - if (RecOp[W].Which == Change) - { - Pst = 0; - GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); - while ((IntIndex != RecOp[W].KeyAndInd.Ind) && (Pst < ActPage->PA.PageHeader.NKey)) - GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); - if (IntIndex == RecOp[W].KeyAndInd.Ind) - PutAKey(RecOp[W].KeyAndInd.KKey, IntIndex, Pst, KeyLen, ActPage); - *OvUnFlow = FALSE; - if ((IntIndex == RecOp[W].KeyAndInd.Ind) && (Pst == ActPage->PA.PageHeader.NKey)) - { - RecOp[W].FlagOp = TRUE; - RecOp[W].Which = Change; - RecOp[W].KeyAndInd.Ind = Pg; - } - } - else - if (RecOp[W].Which == Delet) - { - Pst = 0; - GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); - while ((IntIndex != RecOp[W].KeyAndInd.Ind) && (Pst < ActPage->PA.PageHeader.NKey)) - GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); - if (IntIndex == RecOp[W].KeyAndInd.Ind) - { - *OvUnFlow = (ActPage->PA.PageHeader.NKey == MnKey); - ShiftPage(LeftDir, ++Pst, OnePos, MxKey, KeyLen, ActPage); - } - } - if ((!OvUnFlow) && (Pst >= ActPage->PA.PageHeader.NKey)) - { - RecOp[W].FlagOp = TRUE; - RecOp[W].Which = Change; - GetAKey(*ActPage, KeyLen, ActPage->PA.PageHeader.NKey, IntKey, &IntIndex); - strcpy(RecOp[W].KeyAndInd.KKey, IntKey); - RecOp[W].KeyAndInd.Ind = Pg; - } - } - } - } + for (W = 0; W <= 1; W++) + { + if (RecOp[W].FlagOp) + { + RecOp[W].FlagOp = FALSE; + if (RecOp[W].Which == Inser) + { + Pst = 0; + while (Pst < ActPage->PA.PageHeader.NKey ) + { + GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); + if (IntIndex == RecOp[W].where) break; + } + if (ActPage->PA.PageHeader.NKey == MxKey) + { + GetAKey(*ActPage, KeyLen, MxKey, IntKey, &IntIndex); + if (strcmp(IntKey, RecOp[W].KeyAndInd.KKey) < 0) + { + strcpy(Temp->KKey, RecOp[W].KeyAndInd.KKey); + Temp->Ind = RecOp[W].KeyAndInd.Ind; + } + else + { + strcpy(Temp->KKey, IntKey); + Temp->Ind = IntIndex; + ActPage->PA.PageHeader.NKey--; + ShiftPage(RightDir, Pst, OnePos, MxKey, KeyLen, ActPage); + PutAKey(RecOp[W].KeyAndInd.KKey, RecOp[W].KeyAndInd.Ind, Pst, KeyLen, ActPage); + } + *OvUnFlow = TRUE; + } + else + { + *OvUnFlow = FALSE; + if (strcmp(IntKey, RecOp[W].KeyAndInd.KKey) < 0) + { + ActPage->PA.PageHeader.NKey++; + PutAKey(RecOp[W].KeyAndInd.KKey, RecOp[W].KeyAndInd.Ind, ActPage->PA.PageHeader.NKey, KeyLen, ActPage); + RecOp[W].FlagOp = TRUE; + RecOp[W].Which = Change; + RecOp[W].KeyAndInd.Ind = Pg; + } + else + { + ShiftPage(RightDir, Pst, OnePos, MxKey, KeyLen, ActPage); + PutAKey(RecOp[W].KeyAndInd.KKey, RecOp[W].KeyAndInd.Ind, Pst, KeyLen, ActPage); + } + } + } + else + if (RecOp[W].Which == Change) + { + Pst = 0; + GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); + while ((IntIndex != RecOp[W].KeyAndInd.Ind) && (Pst < ActPage->PA.PageHeader.NKey)) + GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); + if (IntIndex == RecOp[W].KeyAndInd.Ind) + PutAKey(RecOp[W].KeyAndInd.KKey, IntIndex, Pst, KeyLen, ActPage); + *OvUnFlow = FALSE; + if ((IntIndex == RecOp[W].KeyAndInd.Ind) && (Pst == ActPage->PA.PageHeader.NKey)) + { + RecOp[W].FlagOp = TRUE; + RecOp[W].Which = Change; + RecOp[W].KeyAndInd.Ind = Pg; + } + } + else + if (RecOp[W].Which == Delet) + { + Pst = 0; + GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); + while ((IntIndex != RecOp[W].KeyAndInd.Ind) && (Pst < ActPage->PA.PageHeader.NKey)) + GetAKey(*ActPage, KeyLen, ++Pst, IntKey, &IntIndex); + if (IntIndex == RecOp[W].KeyAndInd.Ind) + { + *OvUnFlow = (ActPage->PA.PageHeader.NKey == MnKey); + ShiftPage(LeftDir, ++Pst, OnePos, MxKey, KeyLen, ActPage); + } + } + if ((!OvUnFlow) && (Pst >= ActPage->PA.PageHeader.NKey)) + { + RecOp[W].FlagOp = TRUE; + RecOp[W].Which = Change; + GetAKey(*ActPage, KeyLen, ActPage->PA.PageHeader.NKey, IntKey, &IntIndex); + strcpy(RecOp[W].KeyAndInd.KKey, IntKey); + RecOp[W].KeyAndInd.Ind = Pg; + } + } + } + } /* @($) ZrecOp B+TREE @@ -677,20 +681,20 @@ i = contatore. @(FSV) */ - void ZRecOp(R) - KOp R; /* struttura operazioni da azzerare */ + void ZRecOp(R) + KOp R; /* struttura operazioni da azzerare */ - { - int i; + { + int i; - for (i = 0; i <= 1; i++) - { - R[i].FlagOp = FALSE; - R[i].Which = Nothing; - R[i].Posit = NoLink; - R[i].where = -1; - MinKey(MaxArray, R[i].KeyAndInd.KKey); - R[i].KeyAndInd.Ind = NoLink; - } - } + for (i = 0; i <= 1; i++) + { + R[i].FlagOp = FALSE; + R[i].Which = Nothing; + R[i].Posit = NoLink; + R[i].where = -1; + MinKey(MaxArray, R[i].KeyAndInd.KKey); + R[i].KeyAndInd.Ind = NoLink; + } + } diff --git a/include/cisam.c b/include/cisam.c index cd911966d..fc3c67b6e 100755 --- a/include/cisam.c +++ b/include/cisam.c @@ -17,33 +17,37 @@ openf : array di TUTTI i puntatori ai descrittori dei file ISAM aperti */ #include "cisam.h" #include "libdefs.h" -#include "checks.h" +#include "checks.h" +#ifdef __WATCOMC__ +#include +#else #include +#endif #define logname "log.gen" #define INTTLOCK 0xF000 #define ISLOCKED 225 #define NOALLOC (char **) -1 - TKey KSv; - int PosSv; - RecNoType PagSv,IndSv; - BOOLEAN IndActive = TRUE; - int isstate = NOTRANS ; - int wln = -1; - isfdptr wisfd; - extern BOOLEAN isjournal; + TKey KSv; + int PosSv; + RecNoType PagSv,IndSv; + BOOLEAN IndActive = TRUE; + int isstate = NOTRANS ; + int wln = -1; + isfdptr wisfd; + extern BOOLEAN isjournal; /* Guy moved them here from extcdecl.h */ Str80 cprefix; isfdptr* openf; - void savekeystat(isdef *); - void restkeystat(isdef *,int ); - int addkeys(isdef *,RecType ,int ,int *); - int delkeys(isdef *,RecType ,int ,int *); - int replkeys(isdef *,RecType ,RecType ,int ,int *); + void savekeystat(isdef *); + void restkeystat(isdef *,int ); + int addkeys(isdef *,RecType ,int ,int *); + int delkeys(isdef *,RecType ,int ,int *); + int replkeys(isdef *,RecType ,RecType ,int ,int *); #ifndef DOS - void writeundo(int ,isdef *,RecType); - void writelog(int ,isdef *,RecType); - char *undoname(void); - void getopenf(int ,RecType *); + void writeundo(int ,isdef *,RecType); + void writelog(int ,isdef *,RecType); + char *undoname(void); + void getopenf(int ,RecType *); #endif /* @($) savekeystat ISAM @@ -51,76 +55,76 @@ openf : array di TUTTI i puntatori ai descrittori dei file ISAM aperti Salva la chiave corrente. @(FD) */ - void savekeystat(isfd) - isfdptr isfd; /* descrittore del file ISAM */ - { - strcpy(KSv,isfd->i.Key); - IndSv = isfd->i.Ind; - PosSv = isfd->i.Pos; - PagSv = isfd->i.CurPag; - } + void savekeystat(isfd) + isfdptr isfd; /* descrittore del file ISAM */ + { + strcpy(KSv,isfd->i.Key); + IndSv = isfd->i.Ind; + PosSv = isfd->i.Pos; + PagSv = isfd->i.CurPag; + } /* @($) restkeystat ISAM @(ID) Ripristina la chiave corrente. @(FD) */ - void restkeystat(isfd,knum) - isfdptr isfd; /* descrittore del file ISAM */ - int knum; /* numero della chiave */ - { - isfd->i.PN = knum - 1; - strcpy(isfd->i.Key,KSv); - isfd->i.Ind = IndSv; - isfd->i.Pos = PosSv; - isfd->i.CurPag = PagSv; - } + void restkeystat(isfd,knum) + isfdptr isfd; /* descrittore del file ISAM */ + int knum; /* numero della chiave */ + { + isfd->i.PN = knum - 1; + strcpy(isfd->i.Key,KSv); + isfd->i.Ind = IndSv; + isfd->i.Pos = PosSv; + isfd->i.CurPag = PagSv; + } /* @($) relisfd ISAM @(ID) Vuota il descrittore del file . @(FD) */ - void relisfd(isfd) - isfdptr *isfd; /* descrittore del file ISAM */ - { - free((char *) (*isfd)->d); - free((char *) (*isfd)->r); - free((char *) (*isfd)); - } + void relisfd(isfd) + isfdptr *isfd; /* descrittore del file ISAM */ + { + free((char *) (*isfd)->d); + free((char *) (*isfd)->r); + free((char *) (*isfd)); + } /* @($) getisfd ISAM @(ID) Alloca e carica il descrittore del file con numero logico "logicname". @(FD) */ - void getisfd(isfd, logicname) - isdef **isfd; /* descrittore del file ISAM */ - int logicname; /* numero logico del file */ - { - (*isfd) = (isfdptr) malloc(sizeof(**isfd)); - (*isfd)->d = (FileDes *) malloc(sizeof(*((*isfd)->d))); - (*isfd)->r = (RecDes *) malloc(sizeof(*((*isfd)->r))); - COpenDir(ManuLock, NORDIR); - CGetFile(logicname, (*isfd)->d, NoLock, NORDIR); - if ((!(STREMPTY((*isfd)->d->SysName))) && ((*isfd)->d->SysName[0] == '%')) - (*isfd)->ft = COMDIR; - else - (*isfd)->ft = NORDIR; - CCloseDir(NORDIR); - COpenDir(ManuLock, (*isfd)->ft); - COpenFile(logicname, (*isfd)->d, NoLock, (*isfd)->ft); - CCloseDir((*isfd)->ft); - COpenRecDir(ManuLock, (*isfd)->ft); - CGetRec(logicname,(*isfd)->r, (*isfd)->ft); - CCloseRecDir((*isfd)->ft); - } - /*void dump(s,l) - RecType s; - int l; - { - message_box("dump : record: %s ", &s[1]); - }*/ + void getisfd(isfd, logicname) + isdef **isfd; /* descrittore del file ISAM */ + int logicname; /* numero logico del file */ + { + (*isfd) = (isfdptr) malloc(sizeof(**isfd)); + (*isfd)->d = (FileDes *) malloc(sizeof(*((*isfd)->d))); + (*isfd)->r = (RecDes *) malloc(sizeof(*((*isfd)->r))); + COpenDir(ManuLock, NORDIR); + CGetFile(logicname, (*isfd)->d, NoLock, NORDIR); + if ((!(STREMPTY((*isfd)->d->SysName))) && ((*isfd)->d->SysName[0] == '%')) + (*isfd)->ft = COMDIR; + else + (*isfd)->ft = NORDIR; + CCloseDir(NORDIR); + COpenDir(ManuLock, (*isfd)->ft); + COpenFile(logicname, (*isfd)->d, NoLock, (*isfd)->ft); + CCloseDir((*isfd)->ft); + COpenRecDir(ManuLock, (*isfd)->ft); + CGetRec(logicname,(*isfd)->r, (*isfd)->ft); + CCloseRecDir((*isfd)->ft); + } + /*void dump(s,l) + RecType s; + int l; + { + message_box("dump : record: %s ", &s[1]); + }*/ /* @(#) cisupdflags ISAM @(ID) @@ -137,31 +141,31 @@ Il campo Flags viene aggiornato comunque, mentre EOD viene aggiornato solo se il parametro di input "updateeod" e' TRUE. @(FN) */ - int cisupdflags(isfd,err,updateeod) - isdef *isfd; /* puntatore al descrittore del file ISAM */ - int *err; /* codice di errore */ - BOOLEAN updateeod; /* se TRUE si aggiorna anche EOD */ + int cisupdflags(isfd,err,updateeod) + isdef *isfd; /* puntatore al descrittore del file ISAM */ + int *err; /* codice di errore */ + BOOLEAN updateeod; /* se TRUE si aggiorna anche EOD */ - { - FileDes wd; + { + FileDes wd; - *err = NoErr ; - if (isfd->ln <= 0) return(*err) ; - COpenDir( ManuLock, isfd->ft); - COpenFile(isfd->ln, &wd, Lock, isfd->ft); - if ((*err = fdir[isfd->ft].IOR) == NoErr) - { - wd.Flags = isfd->d->Flags; + *err = NoErr ; + if (isfd->ln <= 0) return(*err) ; + COpenDir( ManuLock, isfd->ft); + COpenFile(isfd->ln, &wd, Lock, isfd->ft); + if ((*err = fdir[isfd->ft].IOR) == NoErr) + { + wd.Flags = isfd->d->Flags; /* #ifdef DOS - if (updateeod) wd.EOD = isfd->d->EOD; + if (updateeod) wd.EOD = isfd->d->EOD; #else */ - if ((updateeod) && (isfd->f.LockMode == ExclLock)) wd.EOD = isfd->d->EOD; + if ((updateeod) && (isfd->f.LockMode == ExclLock)) wd.EOD = isfd->d->EOD; /* #endif */ - CCloseFile(isfd->ln, &wd, isfd->ft); - } - CCloseDir(isfd->ft); - return(*err); - } + CCloseFile(isfd->ln, &wd, isfd->ft); + } + CCloseDir(isfd->ft); + return(*err); + } /* @(#) cisgeteod ISAM @@ -177,21 +181,21 @@ Ritorna l' EOD del file. */ - RecNoType cisgeteod(isfd,err) - isfdptr isfd; /* puntatore al descrittore del file ISAM */ - int *err; /* codice di errore */ + RecNoType cisgeteod(isfd,err) + isfdptr isfd; /* puntatore al descrittore del file ISAM */ + int *err; /* codice di errore */ - { + { - *err = NoErr ; - if (isfd->ln > 0) - { - COpenDir( ManuLock , isfd->ft); - COpenFile(isfd->ln, isfd->d, NoLock, isfd->ft); - CCloseDir(isfd->ft); - } - return(isfd->d->EOD) ; - } + *err = NoErr ; + if (isfd->ln > 0) + { + COpenDir( ManuLock , isfd->ft); + COpenFile(isfd->ln, isfd->d, NoLock, isfd->ft); + CCloseDir(isfd->ft); + } + return(isfd->d->EOD) ; + } /* @(#) cisopen ISAM @@ -213,64 +217,64 @@ s = stringa di lavoro per messaggi di errore. @(FN) */ - int cisopen (isfd,logicname,record,mode,err) - isfdptr *isfd; /* puntatore al descrittore del file */ - int logicname; /* numero logico */ - RecType *record; /* buffer per contenere un record */ - unsigned int mode; /* modo di apertura (lock) */ - int *err; /* codice di errore */ + int cisopen (isfd,logicname,record,mode,err) + isfdptr *isfd; /* puntatore al descrittore del file */ + int logicname; /* numero logico */ + RecType *record; /* buffer per contenere un record */ + unsigned int mode; /* modo di apertura (lock) */ + int *err; /* codice di errore */ - { - *err = NoErr; - if (openf[logicname - 1] != NULL) - fatal_box("File n. %d already open", logicname); + { + *err = NoErr; + if (openf[logicname - 1] != NULL) + fatal_box("File n. %d already open", logicname); #ifndef DOS - if ((excllock(CInsPref(glockname, NORDIR), FALSE) == -1) && (errno == EACCES)) - fatal_box("Can't open directory : Error n. %d ", errno); + if ((excllock(CInsPref(glockname, NORDIR), FALSE) == -1) && (errno == EACCES)) + fatal_box("Can't open directory : Error n. %d ", errno); #endif - getisfd (isfd,logicname); - COpen(&((*isfd)->f), (*isfd)->d->SysName, (*isfd)->d->LenR, 0, mode); - if (*err = (*isfd)->f.IOR) - { - Str80 name; strcpy(name, (*isfd)->d->SysName); - relisfd(isfd); - fatal_box("Can't open file n. %d (%s): error %d ", - logicname, name, *err); - } - if ((*isfd)->r->NKeys) - { - Str80 name; strcpy(name, CGetIdxName((*isfd)->d->SysName)); - CBOpenFile (&((*isfd)->i), name, mode, err); - if (*err) - { - CClose(&((*isfd)->f)); - relisfd(isfd); - fatal_box("Can't open file n. %d (%s): error %d ", - logicname, name, *err); - } + getisfd (isfd,logicname); + COpen(&((*isfd)->f), (*isfd)->d->SysName, (*isfd)->d->LenR, 0, mode); + if (*err = (*isfd)->f.IOR) + { + Str80 name; strcpy(name, (*isfd)->d->SysName); + relisfd(isfd); + fatal_box("Can't open file n. %d (%s): error %d ", + logicname, name, *err); + } + if ((*isfd)->r->NKeys) + { + Str80 name; strcpy(name, CGetIdxName((*isfd)->d->SysName)); + CBOpenFile (&((*isfd)->i), name, mode, err); + if (*err) + { + CClose(&((*isfd)->f)); + relisfd(isfd); + fatal_box("Can't open file n. %d (%s): error %d ", + logicname, name, *err); + } #ifndef DOS - else - if (mode == ExclLock) - { - CBLockFile(&((*isfd)->i), err); - if (*err) - { - int werr; - CClose(&((*isfd)->f)); - CBCloseFile(&((*isfd)->i), &werr); - relisfd(isfd); - fatal_box("Can't open exclusively file n. %d: error %d ", logicname, *err); - } - } + else + if (mode == ExclLock) + { + CBLockFile(&((*isfd)->i), err); + if (*err) + { + int werr; + CClose(&((*isfd)->f)); + CBCloseFile(&((*isfd)->i), &werr); + relisfd(isfd); + fatal_box("Can't open exclusively file n. %d: error %d ", logicname, *err); + } + } #endif - } - if (record != NOALLOC) - *record = (RecType) malloc((*isfd)->d->LenR); - (*isfd)->ln = logicname; - openf[logicname - 1] = *isfd; - if ((*isfd)->r->NKeys) (*isfd)->i.PN = 0; - return (*err); - } + } + if (record != NOALLOC) + *record = (RecType) malloc((*isfd)->d->LenR); + (*isfd)->ln = logicname; + openf[logicname - 1] = *isfd; + if ((*isfd)->r->NKeys) (*isfd)->i.PN = 0; + return (*err); + } /* @(#) ciscopyrec ISAM @@ -288,32 +292,32 @@ d = riga del direttorio corrispondente al file in esame. @(FN) */ - int ciscopyrec(logicname,recdest, recsrc ,err) - int logicname; /* numero logico del file ISAM */ - RecType recdest; /* buffer destinazione */ - RecType recsrc; /* buffer sorgente */ - int *err; /* codice di errore */ + int ciscopyrec(logicname,recdest, recsrc ,err) + int logicname; /* numero logico del file ISAM */ + RecType recdest; /* buffer destinazione */ + RecType recsrc; /* buffer sorgente */ + int *err; /* codice di errore */ - { - FileDes d; - int ft; + { + FileDes d; + int ft; - *err = NoErr; - if (logicname < 0) logicname = -logicname; - if (openf[logicname - 1] != NULL) d = *(openf[logicname - 1]->d); - { - COpenDir(ManuLock, NORDIR); - CGetFile(logicname, &d, NoLock, NORDIR); - if ((!(STREMPTY(d.SysName))) && (d.SysName[0] == '%')) ft = COMDIR; - else ft = NORDIR; - CCloseDir(NORDIR); - COpenDir(ManuLock, ft); - COpenFile(logicname, &d, NoLock, ft); - CCloseDir(ft); - } - memcpy(recdest, recsrc, d.LenR); - return(*err); - } + *err = NoErr; + if (logicname < 0) logicname = -logicname; + if (openf[logicname - 1] != NULL) d = *(openf[logicname - 1]->d); + { + COpenDir(ManuLock, NORDIR); + CGetFile(logicname, &d, NoLock, NORDIR); + if ((!(STREMPTY(d.SysName))) && (d.SysName[0] == '%')) ft = COMDIR; + else ft = NORDIR; + CCloseDir(NORDIR); + COpenDir(ManuLock, ft); + COpenFile(logicname, &d, NoLock, ft); + CCloseDir(ft); + } + memcpy(recdest, recsrc, d.LenR); + return(*err); + } /* @(#) cisallocrec ISAM @@ -331,33 +335,33 @@ d = riga del direttorio corrispondente al file in esame. @(FN) */ - int cisallocrec(logicname,record,err) - int logicname; /* numero logico del file ISAM */ - RecType *record; /* buffer per il record */ - int *err; /* codice di errore */ + int cisallocrec(logicname,record,err) + int logicname; /* numero logico del file ISAM */ + RecType *record; /* buffer per il record */ + int *err; /* codice di errore */ - { - FileDes d; - int ft; + { + FileDes d; + int ft; - *err = NoErr; - if (logicname < 0) logicname = -logicname; - if (openf[logicname - 1] != NULL) d = *(openf[logicname - 1]->d); - else - { - COpenDir(ManuLock, NORDIR); - CGetFile(logicname, &d, NoLock, NORDIR); - if ((!(STREMPTY(d.SysName))) && (d.SysName[0] == '%')) ft = COMDIR; - else ft = NORDIR; - CCloseDir(NORDIR); - COpenDir(ManuLock, ft); - COpenFile(logicname, &d, NoLock, ft); - CCloseDir(ft); - } - *record = (RecType) malloc(d.LenR); - if (*record == ((RecType) NULL)) return(ENOMEM); - else return(*err); - } + *err = NoErr; + if (logicname < 0) logicname = -logicname; + if (openf[logicname - 1] != NULL) d = *(openf[logicname - 1]->d); + else + { + COpenDir(ManuLock, NORDIR); + CGetFile(logicname, &d, NoLock, NORDIR); + if ((!(STREMPTY(d.SysName))) && (d.SysName[0] == '%')) ft = COMDIR; + else ft = NORDIR; + CCloseDir(NORDIR); + COpenDir(ManuLock, ft); + COpenFile(logicname, &d, NoLock, ft); + CCloseDir(ft); + } + *record = (RecType) malloc(d.LenR); + if (*record == ((RecType) NULL)) return(ENOMEM); + else return(*err); + } /* @(#) cisclose ISAM @@ -380,41 +384,41 @@ Restituisce il codice di errore @(FN) */ - int cisclose(isfd,rec,err) - isdef **isfd; /* puntatore al descrittore del file */ - RecType *rec; /* buffer per il record */ - int *err; /* codice di errore */ + int cisclose(isfd,rec,err) + isdef **isfd; /* puntatore al descrittore del file */ + RecType *rec; /* buffer per il record */ + int *err; /* codice di errore */ - { - int werr = NoErr; + { + int werr = NoErr; - *err = NoErr; - if (((*isfd)->ln > 0) && ((*isfd == NULL) || (openf[(*isfd)->ln - 1] == NULL))) - { - if (*isfd != NULL) - error_box("File n. % isclose : Error n. %d ", (*isfd)->ln, IsNotOpen); - else - error_box("isclose : errore n. %d ", IsNotOpen); - } - CClose(&((*isfd)->f)); - *err = ((*isfd)->f.IOR); - if ((*isfd)->r->NKeys) - { - CBCloseFile(&((*isfd)->i), &werr); - if (werr != NoErr ) *err = werr; - } - if ((*isfd)->ln > 0) - openf[(*isfd)->ln - 1] = NULL ; - if ((rec != NULL) && (*rec != NULL)) - free(*rec); - relisfd(isfd); + *err = NoErr; + if (((*isfd)->ln > 0) && ((*isfd == NULL) || (openf[(*isfd)->ln - 1] == NULL))) + { + if (*isfd != NULL) + error_box("File n. % isclose : Error n. %d ", (*isfd)->ln, IsNotOpen); + else + error_box("isclose : errore n. %d ", IsNotOpen); + } + CClose(&((*isfd)->f)); + *err = ((*isfd)->f.IOR); + if ((*isfd)->r->NKeys) + { + CBCloseFile(&((*isfd)->i), &werr); + if (werr != NoErr ) *err = werr; + } + if ((*isfd)->ln > 0) + openf[(*isfd)->ln - 1] = NULL ; + if ((rec != NULL) && (*rec != NULL)) + free(*rec); + relisfd(isfd); #ifndef DOS - exclunlock(CInsPref(glockname, NORDIR), FALSE); + exclunlock(CInsPref(glockname, NORDIR), FALSE); #endif - if (*err) - fatal_box("isclose : Error n. %d ", *err); - return (*err); - } + if (*err) + fatal_box("isclose : Error n. %d ", *err); + return (*err); + } /* @(#) cisstart ISAM @@ -425,31 +429,31 @@ Ritorna il codice di errore. @(FD) @(IN) - La variabile record in input contiene i campi necessari per la ricerca, - in output contiene il record letto. + La variabile record in input contiene i campi necessari per la ricerca, + in output contiene il record letto. - La variabile mode e' formata da un comando di lock + comando di posizionamento - . Se non si utilizza ISEQUAL o ISGREAT o ISGTEQ, il valore della variabile - record non ha nessuna importanza. + La variabile mode e' formata da un comando di lock + comando di posizionamento + . Se non si utilizza ISEQUAL o ISGREAT o ISGTEQ, il valore della variabile + record non ha nessuna importanza. @(FN) */ - int cisstart(isfd,keynum,record,mode,err) - isfdptr isfd; /* descrittore del file ISAM */ - int keynum; /* numero della chiave */ - RecType record; /* buffer per il record */ - unsigned int mode; /* comando di lettura */ - int *err; /* codice di errore */ + int cisstart(isfd,keynum,record,mode,err) + isfdptr isfd; /* descrittore del file ISAM */ + int keynum; /* numero della chiave */ + RecType record; /* buffer per il record */ + unsigned int mode; /* comando di lettura */ + int *err; /* codice di errore */ - { - if(isfd == ((isfdptr) NULL)) return ((*err = IsNotOpen)); - *err = NoErr; - if(!(keynum >= 1) && (keynum <= isfd->r->NKeys)) - return((*err = BTrPathErr)); - isfd->i.PN = keynum - 1; - *err = cisread(isfd,record,mode,err); - return(*err); - } + { + if(isfd == ((isfdptr) NULL)) return ((*err = IsNotOpen)); + *err = NoErr; + if(!(keynum >= 1) && (keynum <= isfd->r->NKeys)) + return((*err = BTrPathErr)); + isfd->i.PN = keynum - 1; + *err = cisread(isfd,record,mode,err); + return(*err); + } /* @(#) cisread ISAM @@ -479,112 +483,112 @@ internaltlock = flag che verifica se la isread e' stata chiamata da iswrite per @(FSV) @(IN) - La variabile record in input contiene i campi necessari per la ricerca, - in output contiene il record letto. + La variabile record in input contiene i campi necessari per la ricerca, + in output contiene il record letto. - La variabile mode e' formata da un comando di lock + comando di posizionamento - . Se non si utilizza ISEQUAL o ISGREAT o ISGTEQ, il valore della variabile - record non ha nessuna importanza. + La variabile mode e' formata da un comando di lock + comando di posizionamento + . Se non si utilizza ISEQUAL o ISGREAT o ISGTEQ, il valore della variabile + record non ha nessuna importanza. @(FN) */ - int cisread(isfd,record,mode,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType record;/* buffer per il record */ - unsigned int mode; /* modo di lettura */ - int *err; /* codice di errore */ + int cisread(isfd,record,mode,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType record;/* buffer per il record */ + unsigned int mode; /* modo di lettura */ + int *err; /* codice di errore */ - { - unsigned int rmode = (mode & READTYPES), - lmode = (mode & RecLockTypes), - knum = (isfd->i.PN+1); - int junk,times = 1; - TKey key,key1,key2; -/* char s[120]; */ - BOOLEAN internaltlock = (lmode == INTTLOCK); + { + unsigned int rmode = (mode & READTYPES), + lmode = (mode & RecLockTypes), + knum = (isfd->i.PN+1); + int junk,times = 1; + TKey key,key1,key2; +/* char s[120]; */ + BOOLEAN internaltlock = (lmode == INTTLOCK); - if (internaltlock) lmode = ShareLock; - *err = NoErr ; - if (isfd == ((isfdptr) NULL)) return ((*err = IsNotOpen)); - if (rmode & (IsPrevN + IsNextN)) - { - times = rmode & BYTEMASK; - if (rmode & IsPrevN) rmode = IsPrev; - else rmode = IsNext; - } - if (rmode == IsCurr) - { - if (!isfd->RecNo) return((*err = IsNotCurr)); - } - else - { - if (rmode == IsNext) - { - while ((times--) && (!*err)) - { - CBNext(&isfd->i,knum,key1,&isfd->RecNo,err); - } - } - else - { - if (rmode == IsPrev) - { - while ((times--) && (!*err)) - { - CBPrev(&isfd->i,knum,key1,&isfd->RecNo,err); - } - } - else - { - if (rmode == IsFirst) MinKey(CCalcLenKey(isfd->r,knum),key); - else - if (rmode == IsLast) MaxKey(CCalcLenKey(isfd->r,knum),key); - else - CBuildKey(isfd->r,knum,record,key); - CBRead(&isfd->i,knum,key,key1,&isfd->RecNo,err); - if ((rmode == IsGreat) && (!*err)) - while ((strcmp(key,key1) == 0) && (!*err)) - CBNext (&isfd->i,knum,key1,&isfd->RecNo,err); - } - } - } - do - { - if (((*err) && (rmode == IsEqual)) || - ((*err == BTrEOF) && (rmode == IsGreat))) - CRead(&isfd->f,record,isfd->RecNo,NoLock); - else - CRead(&isfd->f,record,isfd->RecNo,lmode); - if (TESTLOCK(isfd->f.IOR)) - { - if (lmode == ShareLock) - { - if (!*err) *err = ISLOCKED; - break; - } - message_box("Codice %s in uso da parte\ndi un altro utente.", key1); - if (rmode != IsCurr) - { - CBReRead(&isfd->i,knum,key1,key2,isfd->RecNo,&isfd->RecNo,&junk); - if (junk) strcpy(key1, key2) ; - } - } - else - if (!*err) *err = isfd->f.IOR; - } while (TESTLOCK(isfd->f.IOR)) ; - if (((rmode == IsFirst) || (rmode == IsLast)) && (*err != BTrEmptyTree)) - *err = NoErr; - if ((rmode == IsGtEq) && (*err != BTrEOF) && (*err != BTrEmptyTree)) - *err = NoErr ; - if (DEADLOCK(*err)) return(*err = IsDeadLock); - if (rmode == IsCurr) - { - CBuildKey(isfd->r,knum,record,key); - CBReRead(&isfd->i,knum,key,key1,isfd->RecNo,&isfd->RecNo,&junk); - } - if (*err == BTrEmptyTree) CZeroRec(isfd->r, record); - return(*err); - } + if (internaltlock) lmode = ShareLock; + *err = NoErr ; + if (isfd == ((isfdptr) NULL)) return ((*err = IsNotOpen)); + if (rmode & (IsPrevN + IsNextN)) + { + times = rmode & BYTEMASK; + if (rmode & IsPrevN) rmode = IsPrev; + else rmode = IsNext; + } + if (rmode == IsCurr) + { + if (!isfd->RecNo) return((*err = IsNotCurr)); + } + else + { + if (rmode == IsNext) + { + while ((times--) && (!*err)) + { + CBNext(&isfd->i,knum,key1,&isfd->RecNo,err); + } + } + else + { + if (rmode == IsPrev) + { + while ((times--) && (!*err)) + { + CBPrev(&isfd->i,knum,key1,&isfd->RecNo,err); + } + } + else + { + if (rmode == IsFirst) MinKey(CCalcLenKey(isfd->r,knum),key); + else + if (rmode == IsLast) MaxKey(CCalcLenKey(isfd->r,knum),key); + else + CBuildKey(isfd->r,knum,record,key); + CBRead(&isfd->i,knum,key,key1,&isfd->RecNo,err); + if ((rmode == IsGreat) && (!*err)) + while ((strcmp(key,key1) == 0) && (!*err)) + CBNext (&isfd->i,knum,key1,&isfd->RecNo,err); + } + } + } + do + { + if (((*err) && (rmode == IsEqual)) || + ((*err == BTrEOF) && (rmode == IsGreat))) + CRead(&isfd->f,record,isfd->RecNo,NoLock); + else + CRead(&isfd->f,record,isfd->RecNo,lmode); + if (TESTLOCK(isfd->f.IOR)) + { + if (lmode == ShareLock) + { + if (!*err) *err = ISLOCKED; + break; + } + message_box("Codice %s in uso da parte\ndi un altro utente.", key1); + if (rmode != IsCurr) + { + CBReRead(&isfd->i,knum,key1,key2,isfd->RecNo,&isfd->RecNo,&junk); + if (junk) strcpy(key1, key2) ; + } + } + else + if (!*err) *err = isfd->f.IOR; + } while (TESTLOCK(isfd->f.IOR)) ; + if (((rmode == IsFirst) || (rmode == IsLast)) && (*err != BTrEmptyTree)) + *err = NoErr; + if ((rmode == IsGtEq) && (*err != BTrEOF) && (*err != BTrEmptyTree)) + *err = NoErr ; + if (DEADLOCK(*err)) return(*err = IsDeadLock); + if (rmode == IsCurr) + { + CBuildKey(isfd->r,knum,record,key); + CBReRead(&isfd->i,knum,key,key1,isfd->RecNo,&isfd->RecNo,&junk); + } + if (*err == BTrEmptyTree) CZeroRec(isfd->r, record); + return(*err); + } /* @($) addkeys ISAM @@ -606,34 +610,34 @@ key = valore delle chiavi. @(FN) */ - int addkeys (isfd,record,knum,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType record; /* buffer per il record */ - int knum; /* numero chiave corrente */ - int *err; /* codice errore */ + int addkeys (isfd,record,knum,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType record; /* buffer per il record */ + int knum; /* numero chiave corrente */ + int *err; /* codice errore */ - { - int i,j,werr; - TKey key; + { + int i,j,werr; + TKey key; - for (i = 1;(i <= isfd->r->NKeys) && (!*err);i++) - { - CBuildKey(isfd->r,i,record,key); - CBWrite(&isfd->i,i,key,isfd->RecNo,err); - if (i == knum) savekeystat(isfd); - } - if (*err) - { - if (i == 2 && *err == BTrDupKeysNotAll) *err = IsReInsert; - for (j = 1; (j < i); j++) - { - CBuildKey(isfd->r,j,record,key); - CBDelete(&isfd->i,j,key,isfd->RecNo,&werr); - } - } - else restkeystat(isfd,knum); - return(*err); - } + for (i = 1;(i <= isfd->r->NKeys) && (!*err);i++) + { + CBuildKey(isfd->r,i,record,key); + CBWrite(&isfd->i,i,key,isfd->RecNo,err); + if (i == knum) savekeystat(isfd); + } + if (*err) + { + if (i == 2 && *err == BTrDupKeysNotAll) *err = IsReInsert; + for (j = 1; (j < i); j++) + { + CBuildKey(isfd->r,j,record,key); + CBDelete(&isfd->i,j,key,isfd->RecNo,&werr); + } + } + else restkeystat(isfd,knum); + return(*err); + } /* @(#) ciswrite ISAM @@ -654,134 +658,134 @@ wrec = buffer di lavoro. @(FSV) @(IN) - La variabile record in input contiene il record da aggiungere. + La variabile record in input contiene il record da aggiungere. @(FN) */ - - int ciswrite (isfd,record,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType record; /* buffer per il record */ - int *err; /* codice di errore */ + + int ciswrite (isfd,record,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType record; /* buffer per il record */ + int *err; /* codice di errore */ - { - int knum = (isfd->i.PN+1), werr, junk; - RecNoType neweox; + { + int knum = (isfd->i.PN+1), werr, junk; + RecNoType neweox; - *err = NoErr; - if(isfd == ((isfdptr) NULL)) return((*err = IsNotOpen)); - if (isfd->ln > 0) - { - COpenDir (ManuLock, isfd->ft); - COpenFile(isfd->ln,isfd->d, NoLock, isfd->ft); - } - if (isfd->d->EOD == isfd->d->EOX) - { - neweox = isfd->d->EOX / 20 + 1; - if (neweox < 10) neweox = 10; - if (demoflag) - *err = IsFileFull; - else - { - neweox += isfd->d->EOX; - cisextend(isfd, isfd->ln, neweox, err); - } - if (*err == NoErr) - { - if (isfd->ln > 0) - { - COpenFile(isfd->ln,isfd->d, NoLock, isfd->ft); - for (junk = 0; junk < isfd->r->NKeys; junk++) - isfd->i.Base[junk].PEOX = neweox; - } - else - { - isfd->d->EOX = neweox; - if (isfd->f.LockMode == ExclLock) - for (junk = 0; junk < isfd->r->NKeys; junk++) - isfd->i.Base[junk].PEOX = neweox; - } - } - else - { - if (isfd->ln > 0) - CCloseDir(isfd->ft); - isfd->RecNo = 0; - if (DEADLOCK(*err)) *err = IsDeadLock; - return((*err ? *err : (*err = IsFileFull))); - } - } - IRecallRec(record); - if (test_share() && isfd->f.LockMode != ExclLock) - { - RecType wrec = malloc(isfd->d->LenR); - memcpy(wrec, record, isfd->d->LenR); - savekeystat(isfd); - junk = cisstart(isfd, 1, wrec, NoLock+IsEqual, &junk); - restkeystat(isfd, knum); - free(wrec); + *err = NoErr; + if(isfd == ((isfdptr) NULL)) return((*err = IsNotOpen)); + if (isfd->ln > 0) + { + COpenDir (ManuLock, isfd->ft); + COpenFile(isfd->ln,isfd->d, NoLock, isfd->ft); + } + if (isfd->d->EOD == isfd->d->EOX) + { + neweox = isfd->d->EOX / 20 + 1; + if (neweox < 10) neweox = 10; + if (demoflag) + *err = IsFileFull; + else + { + neweox += isfd->d->EOX; + cisextend(isfd, isfd->ln, neweox, err); + } + if (*err == NoErr) + { + if (isfd->ln > 0) + { + COpenFile(isfd->ln,isfd->d, NoLock, isfd->ft); + for (junk = 0; junk < isfd->r->NKeys; junk++) + isfd->i.Base[junk].PEOX = neweox; + } + else + { + isfd->d->EOX = neweox; + if (isfd->f.LockMode == ExclLock) + for (junk = 0; junk < isfd->r->NKeys; junk++) + isfd->i.Base[junk].PEOX = neweox; + } + } + else + { + if (isfd->ln > 0) + CCloseDir(isfd->ft); + isfd->RecNo = 0; + if (DEADLOCK(*err)) *err = IsDeadLock; + return((*err ? *err : (*err = IsFileFull))); + } + } + IRecallRec(record); + if (test_share() && isfd->f.LockMode != ExclLock) + { + RecType wrec = malloc(isfd->d->LenR); + memcpy(wrec, record, isfd->d->LenR); + savekeystat(isfd); + junk = cisstart(isfd, 1, wrec, NoLock+IsEqual, &junk); + restkeystat(isfd, knum); + free(wrec); - if ((junk == NoErr) || (junk == ISLOCKED)) - { - *err = IsReInsert; - if (isfd->ln > 0) - CCloseDir(isfd->ft); - isfd->RecNo = 0; - return(*err); - } - } - if (isfd->ln > 0) - { - COpenFile(isfd->ln,isfd->d, Lock, isfd->ft); - } - isfd->RecNo = (++isfd->d->EOD); - if ((isfd->r->NKeys) && IndActive) - { - if(test_share() && isfd->f.LockMode != ExclLock) - CBLockFile(&isfd->i,err) ; - if (!addkeys(isfd, record, knum, err)) - { - CWrite(&isfd->f,record,isfd->RecNo,NoLock); - if ((*err = isfd->f.IOR)) - { - isfd->RecNo = 0; - junk = delkeys(isfd, record, knum, &werr); - } -/* else - if (isfd->ln > 0) - CCloseFile(isfd->ln,isfd->d, isfd->ft) ; */ - } - else isfd->d->EOD-- ; - if (isfd->ln > 0) - { - CCloseFile(isfd->ln,isfd->d, isfd->ft) ; - } - if(test_share() && isfd->f.LockMode != ExclLock) - CBUnLockFile(&isfd->i, &werr) ; - } - else - { - CWrite(&isfd->f,record,isfd->RecNo,NoLock); - if ((*err = isfd->f.IOR)) isfd->RecNo = 0; - else CCloseFile(isfd->ln,isfd->d, isfd->ft) ; - } - if (!(*err)) - { + if ((junk == NoErr) || (junk == ISLOCKED)) + { + *err = IsReInsert; + if (isfd->ln > 0) + CCloseDir(isfd->ft); + isfd->RecNo = 0; + return(*err); + } + } + if (isfd->ln > 0) + { + COpenFile(isfd->ln,isfd->d, Lock, isfd->ft); + } + isfd->RecNo = (++isfd->d->EOD); + if ((isfd->r->NKeys) && IndActive) + { + if(test_share() && isfd->f.LockMode != ExclLock) + CBLockFile(&isfd->i,err) ; + if (!addkeys(isfd, record, knum, err)) + { + CWrite(&isfd->f,record,isfd->RecNo,NoLock); + if ((*err = isfd->f.IOR)) + { + isfd->RecNo = 0; + junk = delkeys(isfd, record, knum, &werr); + } +/* else + if (isfd->ln > 0) + CCloseFile(isfd->ln,isfd->d, isfd->ft) ; */ + } + else isfd->d->EOD-- ; + if (isfd->ln > 0) + { + CCloseFile(isfd->ln,isfd->d, isfd->ft) ; + } + if(test_share() && isfd->f.LockMode != ExclLock) + CBUnLockFile(&isfd->i, &werr) ; + } + else + { + CWrite(&isfd->f,record,isfd->RecNo,NoLock); + if ((*err = isfd->f.IOR)) isfd->RecNo = 0; + else CCloseFile(isfd->ln,isfd->d, isfd->ft) ; + } + if (!(*err)) + { #ifndef DOS - if (isstate == NOTRANS) writelog(FNWRITE, isfd, record); - else writeundo(FNWRITE, isfd, record); + if (isstate == NOTRANS) writelog(FNWRITE, isfd, record); + else writeundo(FNWRITE, isfd, record); #endif - } - if (isfd->ln > 0) - CCloseDir(isfd->ft); - if (test_share()) - { - junk = cisunlock(isfd, &junk); - if (isstate == NOTRANS) - CLockRec(&isfd->f,isfd->RecNo,UnLock); - if (DEADLOCK(*err)) *err = IsDeadLock; - } - return(*err); - } + } + if (isfd->ln > 0) + CCloseDir(isfd->ft); + if (test_share()) + { + junk = cisunlock(isfd, &junk); + if (isstate == NOTRANS) + CLockRec(&isfd->f,isfd->RecNo,UnLock); + if (DEADLOCK(*err)) *err = IsDeadLock; + } + return(*err); + } /* @($) delkeys ISAM @@ -803,32 +807,32 @@ key = valori chiave. @(FN) */ - int delkeys (isfd,record,knum,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType record; /* buffer per il record */ - int knum; /* numero della chiave attuale */ - int *err; /* codice di errore */ + int delkeys (isfd,record,knum,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType record; /* buffer per il record */ + int knum; /* numero della chiave attuale */ + int *err; /* codice di errore */ - { - int i,j,werr; - TKey key; + { + int i,j,werr; + TKey key; - for (i = 1;(i <= isfd->r->NKeys)&&(!*err);i++) - { - CBuildKey(isfd->r,i,record,key); - CBDelete(&isfd->i,i,key,isfd->RecNo,err); - } - if (*err) - { - for (j = 1;(j < i);j++) - { - CBuildKey(isfd->r,j,record,key); - CBWrite(&isfd->i,j,key,isfd->RecNo,&werr); - } - } - else restkeystat(isfd,knum); - return(*err); - } + for (i = 1;(i <= isfd->r->NKeys)&&(!*err);i++) + { + CBuildKey(isfd->r,i,record,key); + CBDelete(&isfd->i,i,key,isfd->RecNo,err); + } + if (*err) + { + for (j = 1;(j < i);j++) + { + CBuildKey(isfd->r,j,record,key); + CBWrite(&isfd->i,j,key,isfd->RecNo,&werr); + } + } + else restkeystat(isfd,knum); + return(*err); + } /* @(#) cisdelete ISAM @@ -849,75 +853,75 @@ key1,key = valori chiave. @(FSV) @(IN) - La variabile record in input contiene il record da cancellare. + La variabile record in input contiene il record da cancellare. @(FN) */ - int cisdelete(isfd,record,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType record; /* buffer per il record */ - int *err; /* codice di errore */ + int cisdelete(isfd,record,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType record; /* buffer per il record */ + int *err; /* codice di errore */ - { - int knum = (isfd->i.PN+1), werr; - TKey key,key1; + { + int knum = (isfd->i.PN+1), werr; + TKey key,key1; - if(isfd == ((isfdptr) NULL)) return((*err = IsNotOpen)); - *err = NoErr; - savekeystat(isfd); - CBuildKey(isfd->r,1,record,key); - *err = NoErr ; - CBRead(&isfd->i,1,key,key1,&isfd->RecNo,err); - if (*err) - { - restkeystat(isfd,knum); - return(*err); - } - CRead(&isfd->f, record, isfd->RecNo, NoLock); - if ((*err = isfd->f.IOR)) - { - restkeystat(isfd,knum); - return(*err); - } - if ((isfd->r->NKeys) && IndActive) - { - if(test_share() && isfd->f.LockMode != ExclLock) - CBLockFile(&isfd->i,err) ; - delkeys(isfd, record, knum, err) ; - } - IDeleteRec(record); - CWrite(&isfd->f,record,isfd->RecNo,UnLock); - if((*err = isfd->f.IOR)) - { - IRecallRec(record); - CWrite(&isfd->f,record,isfd->RecNo,NoLock); - if ((isfd->r->NKeys) && IndActive) addkeys(isfd, record, knum, err) ; - restkeystat(isfd,knum); - } + if(isfd == ((isfdptr) NULL)) return((*err = IsNotOpen)); + *err = NoErr; + savekeystat(isfd); + CBuildKey(isfd->r,1,record,key); + *err = NoErr ; + CBRead(&isfd->i,1,key,key1,&isfd->RecNo,err); + if (*err) + { + restkeystat(isfd,knum); + return(*err); + } + CRead(&isfd->f, record, isfd->RecNo, NoLock); + if ((*err = isfd->f.IOR)) + { + restkeystat(isfd,knum); + return(*err); + } + if ((isfd->r->NKeys) && IndActive) + { + if(test_share() && isfd->f.LockMode != ExclLock) + CBLockFile(&isfd->i,err) ; + delkeys(isfd, record, knum, err) ; + } + IDeleteRec(record); + CWrite(&isfd->f,record,isfd->RecNo,UnLock); + if((*err = isfd->f.IOR)) + { + IRecallRec(record); + CWrite(&isfd->f,record,isfd->RecNo,NoLock); + if ((isfd->r->NKeys) && IndActive) addkeys(isfd, record, knum, err) ; + restkeystat(isfd,knum); + } #ifndef DOS - else - { - if (isstate == NOTRANS) - { - writelog(FNDELETE, isfd, NULL); - CRead(&isfd->f,record,isfd->RecNo,UnLock); - } - else writeundo(FNDELETE, isfd, NULL); - } - if (test_share() && (isfd->r->NKeys) && IndActive && - (isfd->f.LockMode != ExclLock)) - CBUnLockFile(&isfd->i, &werr) ; + else + { + if (isstate == NOTRANS) + { + writelog(FNDELETE, isfd, NULL); + CRead(&isfd->f,record,isfd->RecNo,UnLock); + } + else writeundo(FNDELETE, isfd, NULL); + } + if (test_share() && (isfd->r->NKeys) && IndActive && + (isfd->f.LockMode != ExclLock)) + CBUnLockFile(&isfd->i, &werr) ; #else - if (test_share()) - { - CRead(&isfd->f,record,isfd->RecNo,UnLock); - if (isfd->r->NKeys && IndActive && - (isfd->f.LockMode != ExclLock)) - CBUnLockFile(&isfd->i, &werr) ; - } + if (test_share()) + { + CRead(&isfd->f,record,isfd->RecNo,UnLock); + if (isfd->r->NKeys && IndActive && + (isfd->f.LockMode != ExclLock)) + CBUnLockFile(&isfd->i, &werr) ; + } #endif - return(*err); - } + return(*err); + } /* @($) replkeys ISAM @@ -936,46 +940,46 @@ key,key1 = valori delle chiavi. @(FSV) */ - int replkeys (isfd,oldrec,record,knum,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType oldrec; /* buffer contenente il vecchio record */ - RecType record; /* buffer contenente il nuovo record */ - int knum; /* numero della chiave attuale */ - int *err; /* codice di errore */ + int replkeys (isfd,oldrec,record,knum,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType oldrec; /* buffer contenente il vecchio record */ + RecType record; /* buffer contenente il nuovo record */ + int knum; /* numero della chiave attuale */ + int *err; /* codice di errore */ - { - int i,j,werr; - TKey key,key1; + { + int i,j,werr; + TKey key,key1; - for (i = 1;(i <= isfd->r->NKeys)&&(!*err);i++) - { - CBuildKey(isfd->r,i,record,key); - CBuildKey(isfd->r,i,oldrec,key1); - if (strcmp(key,key1) != 0) - { - CBDelete(&isfd->i,i,key1,isfd->RecNo,err); - if (*err) break; - CBWrite(&isfd->i,i,key,isfd->RecNo,err); - if (*err) CBWrite(&isfd->i,i,key1,isfd->RecNo,err); - if (i == knum) savekeystat(isfd); - } - } - if (*err) - { - for (j = 1;(j < i);j++) - { - CBuildKey(isfd->r,j,record,key); - CBuildKey(isfd->r,j,oldrec,key1); - if (strcmp(key,key1) != 0) - { - CBDelete (&isfd->i,j,key,isfd->RecNo,&werr); - CBWrite(&isfd->i,j,key1,isfd->RecNo,&werr); - } - } - } - else restkeystat(isfd,knum); - return(*err); - } + for (i = 1;(i <= isfd->r->NKeys)&&(!*err);i++) + { + CBuildKey(isfd->r,i,record,key); + CBuildKey(isfd->r,i,oldrec,key1); + if (strcmp(key,key1) != 0) + { + CBDelete(&isfd->i,i,key1,isfd->RecNo,err); + if (*err) break; + CBWrite(&isfd->i,i,key,isfd->RecNo,err); + if (*err) CBWrite(&isfd->i,i,key1,isfd->RecNo,err); + if (i == knum) savekeystat(isfd); + } + } + if (*err) + { + for (j = 1;(j < i);j++) + { + CBuildKey(isfd->r,j,record,key); + CBuildKey(isfd->r,j,oldrec,key1); + if (strcmp(key,key1) != 0) + { + CBDelete (&isfd->i,j,key,isfd->RecNo,&werr); + CBWrite(&isfd->i,j,key1,isfd->RecNo,&werr); + } + } + } + else restkeystat(isfd,knum); + return(*err); + } /* @(#) cisrewrite ISAM @@ -998,81 +1002,81 @@ oldrec = buffer di lavoro. @(FSV) @(IN) - La variabile record in input contiene il record da aggiornare. + La variabile record in input contiene il record da aggiornare. Utilizza la chiave 1 per ritrovare il record da aggiornare. @(FN) */ - int cisrewrite(isfd,record,err) - isfdptr isfd; /* descrittore del file isam */ - RecType record; /* buffer contenente i record */ - int *err; /* codice di errore */ + int cisrewrite(isfd,record,err) + isfdptr isfd; /* descrittore del file isam */ + RecType record; /* buffer contenente i record */ + int *err; /* codice di errore */ - { - int knum = (isfd->i.PN+1), werr; - TKey key,key1; - RecType oldrec; + { + int knum = (isfd->i.PN+1), werr; + TKey key,key1; + RecType oldrec; - *err = NoErr ; - if(isfd == ((isfdptr) NULL)) return((*err = IsNotOpen)); - oldrec = (RecType) malloc(isfd->d->LenR); - savekeystat(isfd); - IRecallRec(record); - CBuildKey(isfd->r,1,record,key); - CBRead(&isfd->i,1,key,key1,&isfd->RecNo,err); - if(*err) - { - restkeystat(isfd,knum); - return(*err); - } - CRead(&isfd->f,oldrec,isfd->RecNo,NoLock); - if ((*err = isfd->f.IOR)) - { - restkeystat(isfd,knum); - free(oldrec); - return(*err); - } - if (memcmp(oldrec,record,isfd->d->LenR) == 0) - { - *err = NoErr; - restkeystat(isfd,knum); - CLockRec(&isfd->f,isfd->RecNo,UnLock); - free(oldrec); - return(*err); - } - if ((isfd->r->NKeys) && IndActive) - { - if(test_share() && isfd->f.LockMode != ExclLock) - CBLockFile(&isfd->i, err) ; - replkeys(isfd, oldrec, record, knum, err) ; - if(test_share() && isfd->f.LockMode != ExclLock) - CBUnLockFile(&isfd->i, &werr) ; - } - CWrite(&isfd->f,record,isfd->RecNo,NoLock); - if ((*err = isfd->f.IOR)) - { - CWrite(&isfd->f,oldrec,isfd->RecNo,NoLock); - replkeys(isfd, record, oldrec, knum, err) ; - restkeystat(isfd,knum); - } - else + *err = NoErr ; + if(isfd == ((isfdptr) NULL)) return((*err = IsNotOpen)); + oldrec = (RecType) malloc(isfd->d->LenR); + savekeystat(isfd); + IRecallRec(record); + CBuildKey(isfd->r,1,record,key); + CBRead(&isfd->i,1,key,key1,&isfd->RecNo,err); + if(*err) + { + restkeystat(isfd,knum); + return(*err); + } + CRead(&isfd->f,oldrec,isfd->RecNo,NoLock); + if ((*err = isfd->f.IOR)) + { + restkeystat(isfd,knum); + free(oldrec); + return(*err); + } + if (memcmp(oldrec,record,isfd->d->LenR) == 0) + { + *err = NoErr; + restkeystat(isfd,knum); + CLockRec(&isfd->f,isfd->RecNo,UnLock); + free(oldrec); + return(*err); + } + if ((isfd->r->NKeys) && IndActive) + { + if(test_share() && isfd->f.LockMode != ExclLock) + CBLockFile(&isfd->i, err) ; + replkeys(isfd, oldrec, record, knum, err) ; + if(test_share() && isfd->f.LockMode != ExclLock) + CBUnLockFile(&isfd->i, &werr) ; + } + CWrite(&isfd->f,record,isfd->RecNo,NoLock); + if ((*err = isfd->f.IOR)) + { + CWrite(&isfd->f,oldrec,isfd->RecNo,NoLock); + replkeys(isfd, record, oldrec, knum, err) ; + restkeystat(isfd,knum); + } + else #ifndef DOS - { - if (isstate == NOTRANS) - { - writelog(FNREWRITE, isfd, record); - CLockRec(&isfd->f,isfd->RecNo,UnLock); - } - else writeundo(FNREWRITE, isfd, oldrec); - } + { + if (isstate == NOTRANS) + { + writelog(FNREWRITE, isfd, record); + CLockRec(&isfd->f,isfd->RecNo,UnLock); + } + else writeundo(FNREWRITE, isfd, oldrec); + } #else - if (test_share()) - CLockRec(&isfd->f,isfd->RecNo,UnLock); + if (test_share()) + CLockRec(&isfd->f,isfd->RecNo,UnLock); #endif - free(oldrec); - return(*err); - } + free(oldrec); + return(*err); + } /* @(#) cisdelcurr ISAM @@ -1083,15 +1087,15 @@ Ritorna il codice di errore. @(FD) */ - int cisdelcurr(isfd,err) - isfdptr isfd; /* descrittore del file ISAM */ - int *err; /* codice di errore */ + int cisdelcurr(isfd,err) + isfdptr isfd; /* descrittore del file ISAM */ + int *err; /* codice di errore */ - { - if(isfd->RecNo) cisdelrec(isfd,isfd->RecNo,err); - else *err = IsNotCurr; - return(*err); - } + { + if(isfd->RecNo) cisdelrec(isfd,isfd->RecNo,err); + else *err = IsNotCurr; + return(*err); + } /* @(#) cisrewcurr ISAM @@ -1102,20 +1106,20 @@ Ritorna il codice di errore. @(FD) @(IN) - La variabile record in input contiene il record da aggiornare. + La variabile record in input contiene il record da aggiornare. @(FN) */ - int cisrewcurr(isfd,record,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType record; /* buffer contenente il record */ - int *err; /* codice di errore */ + int cisrewcurr(isfd,record,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType record; /* buffer contenente il record */ + int *err; /* codice di errore */ - { - if(isfd->RecNo) cisrewrec(isfd,isfd->RecNo,record,err); - else *err = IsNotCurr; - return (*err); - } + { + if(isfd->RecNo) cisrewrec(isfd,isfd->RecNo,record,err); + else *err = IsNotCurr; + return (*err); + } /* @(#) cisreadrec ISAM @@ -1126,17 +1130,17 @@ Ritorna il codice di errore. @(FD) */ - int cisreadrec(isfd,recnum,record,mode,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecNoType recnum; /* numero del record */ - RecType record; /* buffer per il record */ - unsigned int mode; /* modo di lock */ - int *err; /* codice di errore */ + int cisreadrec(isfd,recnum,record,mode,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecNoType recnum; /* numero del record */ + RecType record; /* buffer per il record */ + unsigned int mode; /* modo di lock */ + int *err; /* codice di errore */ - { - isfd->RecNo = recnum; - return(cisread(isfd,record,IsCurr+(mode & RecLockTypes),err)); - } + { + isfd->RecNo = recnum; + return(cisread(isfd,record,IsCurr+(mode & RecLockTypes),err)); + } /* @(#) ciswriterec ISAM @@ -1146,7 +1150,7 @@ Riscrive un record di numero "recnum". @(FD) @(IN) - La variabile record in input contiene il record da aggiornare. + La variabile record in input contiene il record da aggiornare. @(FN) @(ISV) @@ -1160,67 +1164,67 @@ oldrec = buffer di lavoro. @(FSV) */ - int cisrewrec(isfd,recnum,record,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecNoType recnum; /* numero del record da riscrivere */ - RecType record; /* buffer per il record */ - int *err; /* codice di errore */ + int cisrewrec(isfd,recnum,record,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecNoType recnum; /* numero del record da riscrivere */ + RecType record; /* buffer per il record */ + int *err; /* codice di errore */ - { - int knum = (isfd->i.PN+1), werr; - RecType oldrec; + { + int knum = (isfd->i.PN+1), werr; + RecType oldrec; - *err = NoErr; - if (isfd == ((isfdptr) NULL)) return ((*err = IsNotOpen)); - oldrec = (RecType) malloc(isfd->d->LenR); - isfd->RecNo = recnum; - IRecallRec(record); - CRead(&isfd->f,oldrec,isfd->RecNo,NoLock); - if ((*err = isfd->f.IOR)) - { - free(oldrec); - return(*err); - } - if (memcmp(oldrec,record,isfd->d->LenR) == 0) - { - *err = NoErr; - if (test_share()) - CLockRec(&isfd->f,isfd->RecNo,UnLock); - free(oldrec); - return(*err); - } - if ((isfd->r->NKeys) && IndActive) - { - if (test_share() && isfd->f.LockMode != ExclLock) - CBLockFile(&isfd->i, err) ; - replkeys(isfd, oldrec, record, knum, err) ; - if (test_share() && isfd->f.LockMode != ExclLock) - CBUnLockFile(&isfd->i, &werr) ; - } - if (isstate == NOTRANS) CWrite(&isfd->f,record,isfd->RecNo,UnLock); - else CWrite(&isfd->f,record,isfd->RecNo,NoLock); - if ((*err = isfd->f.IOR)) - { - CWrite(&isfd->f,oldrec,isfd->RecNo,NoLock); - replkeys(isfd, record, oldrec, knum, err) ; - } + *err = NoErr; + if (isfd == ((isfdptr) NULL)) return ((*err = IsNotOpen)); + oldrec = (RecType) malloc(isfd->d->LenR); + isfd->RecNo = recnum; + IRecallRec(record); + CRead(&isfd->f,oldrec,isfd->RecNo,NoLock); + if ((*err = isfd->f.IOR)) + { + free(oldrec); + return(*err); + } + if (memcmp(oldrec,record,isfd->d->LenR) == 0) + { + *err = NoErr; + if (test_share()) + CLockRec(&isfd->f,isfd->RecNo,UnLock); + free(oldrec); + return(*err); + } + if ((isfd->r->NKeys) && IndActive) + { + if (test_share() && isfd->f.LockMode != ExclLock) + CBLockFile(&isfd->i, err) ; + replkeys(isfd, oldrec, record, knum, err) ; + if (test_share() && isfd->f.LockMode != ExclLock) + CBUnLockFile(&isfd->i, &werr) ; + } + if (isstate == NOTRANS) CWrite(&isfd->f,record,isfd->RecNo,UnLock); + else CWrite(&isfd->f,record,isfd->RecNo,NoLock); + if ((*err = isfd->f.IOR)) + { + CWrite(&isfd->f,oldrec,isfd->RecNo,NoLock); + replkeys(isfd, record, oldrec, knum, err) ; + } #ifndef DOS - else - { - if (isstate == NOTRANS) - { - writelog(FNREWRITE, isfd, record); - CLockRec(&isfd->f,isfd->RecNo,UnLock); - } - else writeundo(FNREWRITE, isfd, oldrec); - } + else + { + if (isstate == NOTRANS) + { + writelog(FNREWRITE, isfd, record); + CLockRec(&isfd->f,isfd->RecNo,UnLock); + } + else writeundo(FNREWRITE, isfd, oldrec); + } #else - if (test_share()) - CLockRec(&isfd->f,isfd->RecNo,UnLock); + if (test_share()) + CLockRec(&isfd->f,isfd->RecNo,UnLock); #endif - free(oldrec); - return(*err); - } + free(oldrec); + return(*err); + } /* @(#) cisdelrec ISAM @(ID) @@ -1228,7 +1232,7 @@ Cancella un record utilizzando un numero di record. Ritorna il codice di errore. @(FD) @(IN) - La variabile record in input contiene il record da cancellare. + La variabile record in input contiene il record da cancellare. @(FN) @(ISV) knum = numero della chiave attiva. @@ -1238,80 +1242,80 @@ key1 = valore della chiave. - Versione DOS e XENIX @(FSV) */ - int cisdelrec(isfd,recnum,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecNoType recnum; /* numero di record */ - int *err; /* codice di errore */ - { - int knum = (isfd->i.PN+1), werr; - int junk; - RecType oldrec ; - TKey key1 ; - *err = NoErr; - if(isfd == (isfdptr) NULL) return ((*err = IsNotOpen)); - oldrec = (RecType) malloc(isfd->d->LenR); - isfd->RecNo = recnum; - savekeystat(isfd); - CRead(&isfd->f, oldrec, isfd->RecNo, NoLock); - if ((*err = isfd->f.IOR)) - { - free(oldrec); - return(*err); - } - if ((isfd->r->NKeys) && IndActive) - { - if(test_share() && isfd->f.LockMode != ExclLock) - CBLockFile(&isfd->i, err) ; - delkeys(isfd, oldrec, knum, err); - } - IDeleteRec(oldrec); - CWrite(&isfd->f,oldrec,isfd->RecNo,UnLock); - if ((*err = isfd->f.IOR)) - { - IRecallRec(oldrec); - CWrite(&isfd->f,oldrec,isfd->RecNo,NoLock); - if ((isfd->r->NKeys) && IndActive) addkeys(isfd, oldrec, knum, err); - } + int cisdelrec(isfd,recnum,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecNoType recnum; /* numero di record */ + int *err; /* codice di errore */ + { + int knum = (isfd->i.PN+1), werr; + int junk; + RecType oldrec ; + TKey key1 ; + *err = NoErr; + if(isfd == (isfdptr) NULL) return ((*err = IsNotOpen)); + oldrec = (RecType) malloc(isfd->d->LenR); + isfd->RecNo = recnum; + savekeystat(isfd); + CRead(&isfd->f, oldrec, isfd->RecNo, NoLock); + if ((*err = isfd->f.IOR)) + { + free(oldrec); + return(*err); + } + if ((isfd->r->NKeys) && IndActive) + { + if(test_share() && isfd->f.LockMode != ExclLock) + CBLockFile(&isfd->i, err) ; + delkeys(isfd, oldrec, knum, err); + } + IDeleteRec(oldrec); + CWrite(&isfd->f,oldrec,isfd->RecNo,UnLock); + if ((*err = isfd->f.IOR)) + { + IRecallRec(oldrec); + CWrite(&isfd->f,oldrec,isfd->RecNo,NoLock); + if ((isfd->r->NKeys) && IndActive) addkeys(isfd, oldrec, knum, err); + } #ifndef DOS - else - { - if (isstate == NOTRANS) - { - writelog(FNDELETE, isfd, NULL); - CLockRec(&isfd->f,isfd->RecNo,UnLock); - } - else writeundo(FNDELETE, isfd, NULL); - } - if (test_share() && (isfd->r->NKeys) && IndActive && (isfd->f.LockMode != ExclLock)) - CBUnLockFile(&isfd->i, &werr) ; + else + { + if (isstate == NOTRANS) + { + writelog(FNDELETE, isfd, NULL); + CLockRec(&isfd->f,isfd->RecNo,UnLock); + } + else writeundo(FNDELETE, isfd, NULL); + } + if (test_share() && (isfd->r->NKeys) && IndActive && (isfd->f.LockMode != ExclLock)) + CBUnLockFile(&isfd->i, &werr) ; #else - if (test_share()) - { - CLockRec(&isfd->f,isfd->RecNo,UnLock); - if (isfd->r->NKeys && IndActive && - (isfd->f.LockMode != ExclLock)) - CBUnLockFile(&isfd->i, &werr) ; - } + if (test_share()) + { + CLockRec(&isfd->f,isfd->RecNo,UnLock); + if (isfd->r->NKeys && IndActive && + (isfd->f.LockMode != ExclLock)) + CBUnLockFile(&isfd->i, &werr) ; + } #endif - free(oldrec); - isfd->RecNo = 0; - return(*err); - } + free(oldrec); + isfd->RecNo = 0; + return(*err); + } /* @(#) cisgetrecno ISAM @(ID) Restituisce il numero del record corrente. @(FD) */ - RecNoType cisgetrecno(isfd, err) - isfdptr isfd; /* descrittore del file ISAM */ - int *err; /* codice di errore */ - - { - if (!isfd->RecNo) *err = IsNotCurr; - else *err = NoErr; - return(isfd->RecNo); - } + RecNoType cisgetrecno(isfd, err) + isfdptr isfd; /* descrittore del file ISAM */ + int *err; /* codice di errore */ + + { + if (!isfd->RecNo) *err = IsNotCurr; + else *err = NoErr; + return(isfd->RecNo); + } /* @(#) cislock ISAM @(ID) @@ -1321,61 +1325,61 @@ Blocca il file ISAM. junk = variabile spazzatura per la chiamata di sleep. @(FSV) */ - int cislock(isfd,err) - isfdptr isfd; /* descrittore del file ISAM */ - int *err; /* codice di errore */ - { - int junk; - *err = NoErr ; - if (lseek(isfd->f.F, 0L, 0) == -1) return ((*err = CIOResult())); + int cislock(isfd,err) + isfdptr isfd; /* descrittore del file ISAM */ + int *err; /* codice di errore */ + { + int junk; + *err = NoErr ; + if (lseek(isfd->f.F, 0L, 0) == -1) return ((*err = CIOResult())); #ifndef DOS - do - { - if (lockf(isfd->f.F,F_TLOCK,0L) == -1) - { - *err = CIOResult() ; - junk = sleep(1) ; - } - } while (TESTLOCK(*err)) ; + do + { + if (lockf(isfd->f.F,F_TLOCK,0L) == -1) + { + *err = CIOResult() ; + junk = sleep(1) ; + } + } while (TESTLOCK(*err)) ; #endif - if(test_share() && isfd->f.LockMode != ExclLock) - CBLockFile(&isfd->i,err); - return(*err); - } + if(test_share() && isfd->f.LockMode != ExclLock) + CBLockFile(&isfd->i,err); + return(*err); + } /* @(#) cisunlock ISAM @(ID) Sblocca un file ISAM. @(FD) */ - int cisunlock(isfd,err) - isfdptr isfd; /* descrittore del file */ - int *err; /* codice di errore */ - { - return(cisrelease(isfd,err)); - } + int cisunlock(isfd,err) + isfdptr isfd; /* descrittore del file */ + int *err; /* codice di errore */ + { + return(cisrelease(isfd,err)); + } /* @(#) cisrelease ISAM @(ID) Sblocca un file ISAM. @(FD) */ - int cisrelease(isfd,err) - isfdptr isfd; /* descrittore del file ISAM */ - int *err; /* codice di errore */ - { - *err = NoErr ; + int cisrelease(isfd,err) + isfdptr isfd; /* descrittore del file ISAM */ + int *err; /* codice di errore */ + { + *err = NoErr ; #ifndef DOS - if (lseek(isfd->f.F, 0L, 0) == -1) return ((*err = CIOResult())); - do - { - if (lockf(isfd->f.F,F_ULOCK,0L) == -1) *err = CIOResult() ; - } while (TESTLOCK(*err)) ; + if (lseek(isfd->f.F, 0L, 0) == -1) return ((*err = CIOResult())); + do + { + if (lockf(isfd->f.F,F_ULOCK,0L) == -1) *err = CIOResult() ; + } while (TESTLOCK(*err)) ; #endif - if(test_share() && isfd->f.LockMode != ExclLock) - CBUnLockFile(&isfd->i,err); - return(*err); - } + if(test_share() && isfd->f.LockMode != ExclLock) + CBUnLockFile(&isfd->i,err); + return(*err); + } /* @(#) IndexOn ISAM @(ID) @@ -1386,9 +1390,9 @@ Di default gli indici sono attivi. @(FN) */ void IndexOn() - { - IndActive = TRUE ; - } + { + IndActive = TRUE ; + } /* @(#) IndexOff ISAM @(ID) @@ -1396,9 +1400,9 @@ Disattiva l'aggiornamento Indici. @(FD) */ void IndexOff() - { - IndActive = FALSE ; - } + { + IndActive = FALSE ; + } #ifndef DOS /* @($) undoname ISAM @@ -1410,11 +1414,11 @@ path = stringa contenente il nome file. @(FSV) */ char *undoname() - { - static PathSt path; - TMPFNAME(path, "undo"); - return(path); - } + { + static PathSt path; + TMPFNAME(path, "undo"); + return(path); + } /* @($) writeundo ISAM @(ID) @@ -1430,30 +1434,30 @@ lgh = variabile di lavoro che contiene l' header del record di undo. int fntype; /* operazione da effettuare */ isfdptr isfd; /* descrittore del file */ RecType record; /* buffer contenente il record */ - { - int fd; - PathSt uname; - loghead lgh; - - if (isfd->ln <= 0) return ; - strcpy(uname ,undoname()); - if ((fd = open(uname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) - fatal_box("Writeundo : Error n. %d ", errno); - lgh.type = fntype; - lgh.time = time(NULL); - lgh.procid = getpid(); - lgh.userid = getuid(); - lgh.filenum = isfd->ln; - lgh.recnum = isfd->RecNo; - lgh.lenrec = isfd->d->LenR; - if (write(fd, &lgh, sizeof(lgh)) == -1) - fatal_box("Writeundo : Error n. %d ", errno); - if (fntype & (FNREWRITE)) - if (write(fd, record, lgh.lenrec) == -1) - fatal_box("Writeundo : Error n. %d ", errno); - if (close(fd) == -1) - fatal_box("Writeundo : Error n. %d ", errno); - } + { + int fd; + PathSt uname; + loghead lgh; + + if (isfd->ln <= 0) return ; + strcpy(uname ,undoname()); + if ((fd = open(uname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) + fatal_box("Writeundo : Error n. %d ", errno); + lgh.type = fntype; + lgh.time = time(NULL); + lgh.procid = getpid(); + lgh.userid = getuid(); + lgh.filenum = isfd->ln; + lgh.recnum = isfd->RecNo; + lgh.lenrec = isfd->d->LenR; + if (write(fd, &lgh, sizeof(lgh)) == -1) + fatal_box("Writeundo : Error n. %d ", errno); + if (fntype & (FNREWRITE)) + if (write(fd, record, lgh.lenrec) == -1) + fatal_box("Writeundo : Error n. %d ", errno); + if (close(fd) == -1) + fatal_box("Writeundo : Error n. %d ", errno); + } /* @($) writelog ISAM @(ID) @@ -1470,52 +1474,52 @@ lgh = testata del file giornale. int fntype; /* operazione effetuata */ isfdptr isfd; /* descrittore del file ISAM */ RecType record; /* buffer per il record */ - { - int fd,junk; - PathSt lname; - loghead lgh; - if (!isjournal) return; - if (isfd->ln <= 0) return ; - strcpy(lname, CInsPref(logname, NORDIR)); - while (excllock(lname,TRUE) == -1) sleep(1); - if ((fd = open(lname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) - { - junk = exclunlock(lname,TRUE); - fatal_box("Writelog : Error n. %d ", errno); - } - lgh.type = fntype + FNSTTRANS; - lgh.time = time(NULL); - lgh.procid = getpid(); - lgh.userid = getuid(); - if (fntype & (FNREWRITE + FNWRITE + FNDELETE)) - { - lgh.filenum = isfd->ln; - lgh.recnum = isfd->RecNo; - lgh.lenrec = isfd->d->LenR; - } - else - { - lgh.filenum = 0; - if (fntype == FNREORG) lgh.recnum = *((RecNoType *) record); - else lgh.recnum = 0L; - if (fntype == FNCHGREC) lgh.lenrec = sizeof(RecDes); - else lgh.lenrec = 0; - } - if (write(fd, &lgh, sizeof(lgh)) == -1) - { - junk = exclunlock(lname,TRUE); - fatal_box("Writelog : Error n. %d ", errno); - } - if (fntype & (FNREWRITE + FNWRITE + FNCHGREC)) - if (write(fd, record, lgh.lenrec) == -1) - { - junk = exclunlock(lname,TRUE); - fatal_box("Writelog : Error n. %d ", errno); - } - if (close(fd) == -1) - fatal_box("Writelog : Error n. %d ", errno); - junk = exclunlock(lname,TRUE); - } + { + int fd,junk; + PathSt lname; + loghead lgh; + if (!isjournal) return; + if (isfd->ln <= 0) return ; + strcpy(lname, CInsPref(logname, NORDIR)); + while (excllock(lname,TRUE) == -1) sleep(1); + if ((fd = open(lname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) + { + junk = exclunlock(lname,TRUE); + fatal_box("Writelog : Error n. %d ", errno); + } + lgh.type = fntype + FNSTTRANS; + lgh.time = time(NULL); + lgh.procid = getpid(); + lgh.userid = getuid(); + if (fntype & (FNREWRITE + FNWRITE + FNDELETE)) + { + lgh.filenum = isfd->ln; + lgh.recnum = isfd->RecNo; + lgh.lenrec = isfd->d->LenR; + } + else + { + lgh.filenum = 0; + if (fntype == FNREORG) lgh.recnum = *((RecNoType *) record); + else lgh.recnum = 0L; + if (fntype == FNCHGREC) lgh.lenrec = sizeof(RecDes); + else lgh.lenrec = 0; + } + if (write(fd, &lgh, sizeof(lgh)) == -1) + { + junk = exclunlock(lname,TRUE); + fatal_box("Writelog : Error n. %d ", errno); + } + if (fntype & (FNREWRITE + FNWRITE + FNCHGREC)) + if (write(fd, record, lgh.lenrec) == -1) + { + junk = exclunlock(lname,TRUE); + fatal_box("Writelog : Error n. %d ", errno); + } + if (close(fd) == -1) + fatal_box("Writelog : Error n. %d ", errno); + junk = exclunlock(lname,TRUE); + } #endif /* @(#) StTrans ISAM @@ -1524,12 +1528,12 @@ Inizia una transazione. @(FD) */ void StTrans() - { + { #ifndef DOS - if (isstate == TRANS) EndTrans(); + if (isstate == TRANS) EndTrans(); #endif - isstate = TRANS; - } + isstate = TRANS; + } #ifndef DOS /* @($) getopenf ISAM @@ -1544,19 +1548,19 @@ err = codice di errore ritornato dalla cisopen. void getopenf(ln,record) int ln; /* numero logico del file */ RecType *record; /* puntatore al buffer per il record */ - { - int err,junk; - if (openf[ln - 1] == NULL) - { - if (wln != ln) - { - if (wln != -1) junk = cisclose(&wisfd ,record ,&err); - cisopen(&wisfd, ln, record, ManuLock, &err); - wln = ln; - } - } - else *record = realloc(*record, openf[ln - 1]->d->LenR); - } + { + int err,junk; + if (openf[ln - 1] == NULL) + { + if (wln != ln) + { + if (wln != -1) junk = cisclose(&wisfd ,record ,&err); + cisopen(&wisfd, ln, record, ManuLock, &err); + wln = ln; + } + } + else *record = realloc(*record, openf[ln - 1]->d->LenR); + } #endif /* @(#) EndTrans ISAM @@ -1575,58 +1579,58 @@ record = buffer di lavoro. @(FSV) */ void EndTrans() - { + { #ifndef DOS - int fdl, fdu; - PathSt lname, uname; - loghead lgh, lgh1; - int nread, werr, junk, start = FNSTTRANS; - RecType record; - strcpy(lname ,CInsPref(logname, NORDIR)); - while (excllock(lname,TRUE) == -1) sleep(1); - if (((fdl = open(lname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) || - ((fdu = open(uname, O_RDONLY, 0666)) == -1)) - { - junk = exclunlock(lname,TRUE); - fatal_box("Endtrans : Error n. %d ", errno); - } - while ((nread = read(fdu, &lgh, sizeof(lgh))) > 0) - { - lgh.type += start; - start = 0; - if (write(fdl, &lgh, sizeof(lgh)) == -1) - { - junk = exclunlock(lname,TRUE); - fatal_box("Endtrans : Error n. %d ", errno); - } - if (lgh.type == FNREWRITE) - if (lseek(fdu, (long) lgh.lenrec, 1) == -1) - { - junk = exclunlock(lname,TRUE); - fatal_box("Endtrans : Error n. %d ", errno); - } - getopenf(lgh.filenum, &record); - CRead(&(openf[lgh.filenum - 1]->f), record, lgh.recnum, UnLock); - if (write(fdl, record, lgh.lenrec) == -1) - { - junk = exclunlock(lname,TRUE); - fatal_box("Endtrans : Error n. %d ", errno); - } - } - if ((nread <= 0) || (close(fdu) == -1) || (close(fdl) == -1) || - (unlink(uname) == -1)) - { - junk = exclunlock(lname,TRUE); - fatal_box("Endtrans : Error n. %d ", errno); - } - if (wln != -1) - { - junk = cisclose(&wisfd, &record, &werr); - wln = -1; - } - junk = exclunlock(lname,TRUE); + int fdl, fdu; + PathSt lname, uname; + loghead lgh, lgh1; + int nread, werr, junk, start = FNSTTRANS; + RecType record; + strcpy(lname ,CInsPref(logname, NORDIR)); + while (excllock(lname,TRUE) == -1) sleep(1); + if (((fdl = open(lname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) || + ((fdu = open(uname, O_RDONLY, 0666)) == -1)) + { + junk = exclunlock(lname,TRUE); + fatal_box("Endtrans : Error n. %d ", errno); + } + while ((nread = read(fdu, &lgh, sizeof(lgh))) > 0) + { + lgh.type += start; + start = 0; + if (write(fdl, &lgh, sizeof(lgh)) == -1) + { + junk = exclunlock(lname,TRUE); + fatal_box("Endtrans : Error n. %d ", errno); + } + if (lgh.type == FNREWRITE) + if (lseek(fdu, (long) lgh.lenrec, 1) == -1) + { + junk = exclunlock(lname,TRUE); + fatal_box("Endtrans : Error n. %d ", errno); + } + getopenf(lgh.filenum, &record); + CRead(&(openf[lgh.filenum - 1]->f), record, lgh.recnum, UnLock); + if (write(fdl, record, lgh.lenrec) == -1) + { + junk = exclunlock(lname,TRUE); + fatal_box("Endtrans : Error n. %d ", errno); + } + } + if ((nread <= 0) || (close(fdu) == -1) || (close(fdl) == -1) || + (unlink(uname) == -1)) + { + junk = exclunlock(lname,TRUE); + fatal_box("Endtrans : Error n. %d ", errno); + } + if (wln != -1) + { + junk = cisclose(&wisfd, &record, &werr); + wln = -1; + } + junk = exclunlock(lname,TRUE); #endif - } + } /* @(#) AbTrans ISAM @(ID) @@ -1634,58 +1638,58 @@ Abortisce una transazione. @(FD) */ void AbTrans() - { + { #ifndef DOS - int fd; - PathSt uname; - loghead lgh; - int nread, werr, junk; - RecType record; - RecType oldrec; - strcpy(uname ,undoname()); - if ((fd = open(uname, O_RDONLY, 0666)) == -1) - fatal_box("Abtrans : Error n. %d ", errno); - while ((nread = read(fd, &lgh, sizeof(lgh))) > 0) - { - getopenf(lgh.filenum, &record); - if (oldrec == NULL) oldrec = malloc(lgh.lenrec); - else oldrec = realloc(oldrec, lgh.lenrec); - if (lgh.type & (FNREWRITE)) - { - if ((nread = read(fd, record, lgh.lenrec)) <= 0) - fatal_box("Abtrans : Error n. %d ", errno); - } - if (lgh.lenrec != openf[lgh.filenum - 1]->d->LenR) - fatal_box("Abtrans : Error n. %d ", IsNoMatch); - CRead(&(openf[lgh.filenum - 1]->f), oldrec, lgh.recnum, NoLock); - switch (lgh.type) - { - case FNREWRITE : - junk = replkeys(openf[lgh.filenum - 1], oldrec, record, - openf[lgh.filenum - 1]->i.PN + 1, &werr); - CWrite(&(openf[lgh.filenum - 1]->f), record, lgh.recnum, UnLock); - break; - case FNDELETE : - IRecallRec(oldrec); - junk = addkeys(openf[lgh.filenum - 1], oldrec, - openf[lgh.filenum - 1]->i.PN + 1, &werr); - CWrite(&(openf[lgh.filenum - 1]->f), oldrec, lgh.recnum, UnLock); - break; - case FNWRITE : - IDeleteRec(oldrec); - junk = delkeys(openf[lgh.filenum - 1], oldrec, - openf[lgh.filenum - 1]->i.PN + 1, &werr); - CWrite(&(openf[lgh.filenum - 1]->f), record, lgh.recnum, UnLock); - break; - } - } - if ((nread == -1) || (close(fd) == -1) || (unlink(uname) == -1)) - fatal_box("Abtrans : Error n. %d ", errno); - if (wln != -1) - { - junk = cisclose(&wisfd, &record, &werr); - wln = -1; - } + int fd; + PathSt uname; + loghead lgh; + int nread, werr, junk; + RecType record; + RecType oldrec; + strcpy(uname ,undoname()); + if ((fd = open(uname, O_RDONLY, 0666)) == -1) + fatal_box("Abtrans : Error n. %d ", errno); + while ((nread = read(fd, &lgh, sizeof(lgh))) > 0) + { + getopenf(lgh.filenum, &record); + if (oldrec == NULL) oldrec = malloc(lgh.lenrec); + else oldrec = realloc(oldrec, lgh.lenrec); + if (lgh.type & (FNREWRITE)) + { + if ((nread = read(fd, record, lgh.lenrec)) <= 0) + fatal_box("Abtrans : Error n. %d ", errno); + } + if (lgh.lenrec != openf[lgh.filenum - 1]->d->LenR) + fatal_box("Abtrans : Error n. %d ", IsNoMatch); + CRead(&(openf[lgh.filenum - 1]->f), oldrec, lgh.recnum, NoLock); + switch (lgh.type) + { + case FNREWRITE : + junk = replkeys(openf[lgh.filenum - 1], oldrec, record, + openf[lgh.filenum - 1]->i.PN + 1, &werr); + CWrite(&(openf[lgh.filenum - 1]->f), record, lgh.recnum, UnLock); + break; + case FNDELETE : + IRecallRec(oldrec); + junk = addkeys(openf[lgh.filenum - 1], oldrec, + openf[lgh.filenum - 1]->i.PN + 1, &werr); + CWrite(&(openf[lgh.filenum - 1]->f), oldrec, lgh.recnum, UnLock); + break; + case FNWRITE : + IDeleteRec(oldrec); + junk = delkeys(openf[lgh.filenum - 1], oldrec, + openf[lgh.filenum - 1]->i.PN + 1, &werr); + CWrite(&(openf[lgh.filenum - 1]->f), record, lgh.recnum, UnLock); + break; + } + } + if ((nread == -1) || (close(fd) == -1) || (unlink(uname) == -1)) + fatal_box("Abtrans : Error n. %d ", errno); + if (wln != -1) + { + junk = cisclose(&wisfd, &record, &werr); + wln = -1; + } #endif - } + } diff --git a/include/isreorg.c b/include/isreorg.c index 384b326e6..a8a8a9065 100755 --- a/include/isreorg.c +++ b/include/isreorg.c @@ -3,15 +3,19 @@ ------------------------------------------------------------------------------- */ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __WATCOMC__ +#include +#else +#include +#endif +#include /* @(#) creorgfile ISAM @@ -43,54 +47,54 @@ s = stringa messaggio. @(FSV) */ -int creorgfile(logicname,vis,err) -int logicname; /* numero logico del file */ -BOOLEAN vis; /* se true visualizza le operazioni che sta facendo */ -int *err; /* codice errore */ +int creorgfile(logicname,vis,err) +int logicname; /* numero logico del file */ +BOOLEAN vis; /* se true visualizza le operazioni che sta facendo */ +int *err; /* codice errore */ - { - isfdptr wisfd; - RecType rec; - RecNoType i = 0L,k = 0L,oldeod; - int junk; - char s[80]; + { + isfdptr wisfd; + RecType rec; + RecNoType i = 0L,k = 0L,oldeod; + int junk; + char s[80]; - *err = NoErr; - if (cisopen(&wisfd, logicname, &rec, ExclLock, err)) return(*err); - oldeod = wisfd->d->EOD; - if (vis && (oldeod > 0)) - { - sprintf(s,"Compatta - %s", wisfd->d->Des); - progind_create(wisfd->d->EOD, s, FALSE, TRUE, 70); - } - while (i < wisfd->d->EOD) - { - i++; - CRead(&wisfd->f, rec, i, NoLock); - if ((*err = wisfd->f.IOR)) break ; - if (!IRecIsDeleted(rec)) - { - k++; - if (k < i) CWrite(&wisfd->f, rec, k, NoLock); - } - if (vis && (oldeod > 0) && (!(i % 10))) - progind_set_status(i); - } - if (vis && (oldeod > 0)) - progind_set_status(i); - if (!*err) - { - wisfd->d->EOD = k; + *err = NoErr; + if (cisopen(&wisfd, logicname, &rec, ExclLock, err)) return(*err); + oldeod = wisfd->d->EOD; + if (vis && (oldeod > 0)) + { + sprintf(s,"Compatta - %s", wisfd->d->Des); + progind_create(wisfd->d->EOD, s, FALSE, TRUE, 70); + } + while (i < wisfd->d->EOD) + { + i++; + CRead(&wisfd->f, rec, i, NoLock); + if ((*err = wisfd->f.IOR)) break ; + if (!IRecIsDeleted(rec)) + { + k++; + if (k < i) CWrite(&wisfd->f, rec, k, NoLock); + } + if (vis && (oldeod > 0) && (!(i % 10))) + progind_set_status(i); + } + if (vis && (oldeod > 0)) + progind_set_status(i); + if (!*err) + { + wisfd->d->EOD = k; #ifndef DOS - writelog(FNREORG, NULL, (RecType) &oldeod); + writelog(FNREORG, NULL, (RecType) &oldeod); #endif - junk = cisupdflags(wisfd, &junk, TRUE); - } - junk = cisclose(&wisfd, &rec, &junk); - if (vis && oldeod > 0) - progind_destroy(); - return(*err); - } + junk = cisupdflags(wisfd, &junk, TRUE); + } + junk = cisclose(&wisfd, &rec, &junk); + if (vis && oldeod > 0) + progind_destroy(); + return(*err); + } /* @(#) creorgindex ISAM @@ -119,62 +123,62 @@ Deve essere usata in coppia con la "creorgfile". @(FN) */ -int creorgindex(logicname,vis,err) -int logicname; /* numero logico del file */ -BOOLEAN vis; /* se true visualizza cio' che sta facendo */ -int *err; /* codice errore */ +int creorgindex(logicname,vis,err) +int logicname; /* numero logico del file */ +BOOLEAN vis; /* se true visualizza cio' che sta facendo */ +int *err; /* codice errore */ - { - isfdptr wisfd; - RecType rec; - int junk, j; - char s[80]; - int werr = NoErr; + { + isfdptr wisfd; + RecType rec; + int junk, j; + char s[80]; + int werr = NoErr; - *err = NoErr; - getisfd(&wisfd, logicname); - CBInitFile(&wisfd->i); - for (j = 1; j <= wisfd->r->NKeys;j++) - { - CBInitPath(j,CCalcLenKey(wisfd->r,j),wisfd->d->EOX, - wisfd->r->Ky[j-1].DupKeys,&(wisfd->i),err); - if (*err) - { - relisfd(&wisfd); - return (*err); - } - } - junk = unlink(CGetIdxName(wisfd->d->SysName)); - CBCreate(&wisfd->i, CGetIdxName(wisfd->d->SysName),err); - relisfd(&wisfd); - if (*err) return (*err); - if (cisopen(&wisfd, logicname, &rec, ExclLock, err)) return(*err); - wisfd->RecNo = 0L; - if (vis && (wisfd->d->EOD > 0)) - { - sprintf(s,"Crea indice - %s", wisfd->d->Des); - progind_create(wisfd->d->EOD, s, FALSE, TRUE, 70); - } - while (wisfd->RecNo < wisfd->d->EOD) - { - wisfd->RecNo++; - CRead(&wisfd->f, rec, wisfd->RecNo, NoLock); - werr = wisfd->f.IOR; - if (!IRecIsDeleted(rec)) - addkeys(wisfd,rec,1,&werr); - if (vis && (wisfd->d->EOD > 0) && (!(wisfd->RecNo % 10))) - progind_set_status(wisfd->RecNo); - if (werr != NoErr && *err == NoErr) - *err = werr; - } - if (vis && (wisfd->d->EOD > 0)) - progind_set_status(wisfd->RecNo); - junk = cisclose(&wisfd, &rec, &junk); - if (vis) - progind_destroy(); - if (*err != NoErr) - error_box("Si e' verificato almeno un errore n. %d\nVerificare l'archivio e ripetere il compattamento", *err); - return(*err); - } + *err = NoErr; + getisfd(&wisfd, logicname); + CBInitFile(&wisfd->i); + for (j = 1; j <= wisfd->r->NKeys;j++) + { + CBInitPath(j,CCalcLenKey(wisfd->r,j),wisfd->d->EOX, + wisfd->r->Ky[j-1].DupKeys,&(wisfd->i),err); + if (*err) + { + relisfd(&wisfd); + return (*err); + } + } + junk = unlink(CGetIdxName(wisfd->d->SysName)); + CBCreate(&wisfd->i, CGetIdxName(wisfd->d->SysName),err); + relisfd(&wisfd); + if (*err) return (*err); + if (cisopen(&wisfd, logicname, &rec, ExclLock, err)) return(*err); + wisfd->RecNo = 0L; + if (vis && (wisfd->d->EOD > 0)) + { + sprintf(s,"Crea indice - %s", wisfd->d->Des); + progind_create(wisfd->d->EOD, s, FALSE, TRUE, 70); + } + while (wisfd->RecNo < wisfd->d->EOD) + { + wisfd->RecNo++; + CRead(&wisfd->f, rec, wisfd->RecNo, NoLock); + werr = wisfd->f.IOR; + if (!IRecIsDeleted(rec)) + addkeys(wisfd,rec,1,&werr); + if (vis && (wisfd->d->EOD > 0) && (!(wisfd->RecNo % 10))) + progind_set_status(wisfd->RecNo); + if (werr != NoErr && *err == NoErr) + *err = werr; + } + if (vis && (wisfd->d->EOD > 0)) + progind_set_status(wisfd->RecNo); + junk = cisclose(&wisfd, &rec, &junk); + if (vis) + progind_destroy(); + if (*err != NoErr) + error_box("Si e' verificato almeno un errore n. %d\nVerificare l'archivio e ripetere il compattamento", *err); + return(*err); + }