From d24f85fc6c47567670d7cb1723245961d585cc0a Mon Sep 17 00:00:00 2001 From: angelo Date: Mon, 11 Sep 1995 15:31:07 +0000 Subject: [PATCH] Rif. mod. 95/19. Svincolati definitivamente i sorgenti dal direttorio /disk1/p.uno. git-svn-id: svn://10.65.10.50/trunk@1811 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/ccommon.h | 281 +++++ include/ccustio.c | 26 +- include/ccustio.h | 81 ++ include/cfiles.c | 2796 ++++++++++++++++++++++---------------------- include/cfiles.h | 152 +++ include/csort.c | 1056 ++++++++--------- include/csort.h | 37 +- include/fldtypes.h | 13 + include/genconst.h | 117 ++ include/getaut.c | 72 ++ include/hlapi_c.h | 172 +++ include/hlprot.c | 142 +++ include/ioresult.c | 23 + include/keye.h | 37 + include/libdefs.h | 127 ++ include/mshell.h | 101 ++ include/tmpfname.c | 20 + include/upstring.c | 16 + 18 files changed, 3238 insertions(+), 2031 deletions(-) create mode 100755 include/ccommon.h create mode 100755 include/ccustio.h create mode 100755 include/cfiles.h create mode 100755 include/fldtypes.h create mode 100755 include/genconst.h create mode 100755 include/getaut.c create mode 100755 include/hlapi_c.h create mode 100755 include/hlprot.c create mode 100755 include/ioresult.c create mode 100755 include/keye.h create mode 100755 include/libdefs.h create mode 100755 include/mshell.h create mode 100755 include/tmpfname.c create mode 100755 include/upstring.c diff --git a/include/ccommon.h b/include/ccommon.h new file mode 100755 index 000000000..fe63f3b13 --- /dev/null +++ b/include/ccommon.h @@ -0,0 +1,281 @@ +#ifndef __CCOMMON_H +#define __CCOMMON_H + +#define M_TERMINFO + +#ifdef __WATCOMC__ +#pragma aux MS_C "_*" parm caller [] value struct float struct routine [ax] modify [ax bx cx dx es]; +#endif + +#ifdef XVT +#include +#undef BOOLEAN +#include +#endif + +#ifdef __GNUC__ +#define __PACKED__ __attribute__ ((packed)) +#define __ALIGNED__ __attribute__ ((aligned(2))) +#define __PACK_1__ +#else +#define __PACKED__ +#define __ALIGNED__ +#endif + +#ifdef DOS +#include +#include +#define _NO_STDIO +#include +#include +#include +#include +#include +#include +#include +#else +#ifdef __cplusplus +#include +#include +#include +#define _NO_STDIO +#include +#include +#include +#include +#include +#include +#include +#include +#else +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif +#endif + +#include + +#if !defined(__MSHELL_H) && !defined(FOXPRO) +#include "mshell.h" +#endif + +#define CHR(c) (c) +#define ORD(c) (c) +#define ODD(c) (((c) % 2) != 0) +#ifdef DOS +/* @(!) 2.3.01.316 modif. #define TMPFNAME(p,n) sprintf(p, "\\tmp\\%s.tmp", (n)); */ +#define TMPFNAME(p,n) tmpfname((p),(n)) +/* @(:) 2.3.01.316 */ +#define DIRSEP '\\' +#else +#define TMPFNAME(p,n) sprintf(p, "/usr/tmp/%s%-d", (n), getpid()); +#define DIRSEP '/' +#endif +#define HIDDEN static +#define UPCASE(c) toupper(c) +#define LOWCASE(c) tolower(c) +#define LENGTH(s) strlen(s) +#define STREMPTY(s) (!(LENGTH(s))) +#define STRNOTEMPTY(s) (!STREMPTY(s)) +#define STRCMP(s1,op,s2) (strcmp(s1,s2) op 0) +#define CSTR(n,s) sprintf((s), "%-d", (n)) +#define CSTR4(n,s) sprintf((s), "%-ld", (n)) +#define MAXDATA cpackdata("31-12-50") +#define MINDATA cpackdata("01-01-51") +#define EMPTYDATA cpackdata(" - - ") +#define MONTHNAME(i) months[(i) - 1] +#define CCONVINT(s) atoi(s) +#define CONVLONG(s) atol(s) +#define BADR(x) ((x) - 1) +#define WINHND(hw) warr[(hw)].w +/* @(!) 2.3.01.69 */ +#define WINHNDB(hw) warr[(hw)].wb +/* @(:) 2.3.01.69 */ +#define WINFLD(hw,f) warr[(hw)].f +#define POSTWIN(hw) WINFLD(hw,posted) = TRUE +#define UNPOSTWIN(hw) WINFLD(hw,posted) = FALSE +#define CCLEAREOL(w) xwclrtoeol(WINHND(w)) +#define CCLEAREOS(w) xwclrtobot(WINHND(w)) +#define CCLEARWIN(w) xpaint(WINHND(w), setattr[warr[(w)].bkat][iscolordisp]) +#define INSET(c,s) (ustrchr((s), (c)) != (uchar *) NULL) +#define CBITTEST(w,p) (((w) & (0x0001 << (p))) != 0) +#define CBITSET(w,p,v) ((v) ? ((w) |= (0x0001 << (p))) : ((w) &= (~(0x0001 << (p))))) +/* @(!) 2.3.01.temp */ +#ifdef M_I386 +#define BOOLEAN short +#else +/* @(:) 2.3.01.temp */ +#define BOOLEAN int +/* @(!) 2.3.01.temp */ +#endif +/* @(:) 2.3.01.temp */ +#define NoErr 0 +#define BADSIG (int (*)()) -1 +#define MAXMENUITEM 21 +#define MAXWIN 20 +#define MAXBORDERS 8 +#define MAXATTRS 20 +#define BackCh '_' +#define directory "dir.gen" +#define ntrrec "trc.gen" +#define nditta "dta.gen" +#define printers "prt.gen" +#define prcodes "prc.gen" +#define WWMESS 0 +#define WWBAR 1 + +/* gia' definito in gm.h + typedef unsigned int word; + */ +typedef unsigned char byte; +#ifndef DOS +typedef unsigned char uchar; +#endif +#ifdef XVT_OS +#ifdef DOS +typedef unsigned char uchar; +#endif +typedef long HWND; +#else +#endif +typedef struct { + char nome[52] __PACKED__ ; + char indirizzo[32] __PACKED__ ; + char citta[32] __PACKED__ ; + char cap[6] __PACKED__ ; + char partiva[12] __PACKED__ ; + char codfisc[18] __PACKED__ ; + /* @(!) 2.3.01.temp */ +#ifdef M_I386 + short numero __PACKED__ ; + short tab0[20] __PACKED__ ; +#else + /* @(:) 2.3.01.temp */ + int numero; + int tab0[20]; + /* @(!) 2.3.01.temp */ +#endif + /* @(:) 2.3.01.temp */ + long tab1 __PACKED__ ; + char nome1[52] __PACKED__ ; + char indirizzo1[32] __PACKED__ ; + char citta1[32] __PACKED__ ; + char cap1[6] __PACKED__ ; + char partiva1[12] __PACKED__ ; + char codfisc1[18] __PACKED__ ; +} TDitta; +typedef char Str8[9]; +typedef char Str25[26]; +typedef char Str30[32]; +typedef char Str80[82]; +typedef char Str255[256]; +typedef uchar StCh[256]; +typedef long TrDate; +typedef struct { + char name[26]; + char explic[82]; +} MenuItem; +typedef MenuItem MenuArray[MAXMENUITEM + 1]; +typedef char PathSt[42]; + +extern Str80 cprefix; +extern TDitta cditta; +extern TrDate dt; +extern Str8 sdt; +extern char months[12][12]; +extern BOOLEAN iscolordisp; + +#ifdef __cplusplus +extern "C" { +#endif + uchar *ustrchr(uchar *, uchar); + uchar *setof(uchar *, ELLIPSES); + uchar *delset(uchar *, ELLIPSES); + int positn(char *, char *, int); + void cdate(char *); + void ctimeloc(char *); + uchar CReadKeyb(void); + char *ToASCIIZ(char *); + char *ToASCII(char *); + void CDispStatus(char *); + BOOLEAN cverdata(char *); + TrDate cpackdata(char *); + void ceditdata(TrDate ,char *); + void cgetdata(TrDate *,char *); + void cputdata(char *); + int month(TrDate); + int year(TrDate); + int day(TrDate); + TrDate makedata(int,int,int); + TrDate addmonth(TrDate,int); + TrDate addyear(TrDate,int); + void cgettime(char *); + char *CCopy(char *,int ,int ); + int CBitPos(int ); + BOOLEAN CGetAut(int ); + char *CGetConf(int ); + void CMaskP(char *,char *,int , int); + char *CUpString(char *); + char *CLowString(char *); + /* @(!) 2.3.00.21 */ + char *strfset(char *, char *); + /* @(:) 2.3.00.21 */ + char CSetDrive(char ); + char CGetDrive(void ); + int CMkDir(char *); + int CRmDir(char *); + int CChgDir(char *); + int CRenameFil(char *,char *); + int CRenameDir(char *,char *); + int CGetDir(char *); + long CDiskSpace(char ); + void CSetString(char *,char *,BOOLEAN, BOOLEAN, int ,int ,char ); + BOOLEAN ckeypress(void ); + void genhelp(void ); + uchar CReadKeyb(void ); + char *esc(char *); + void CInitProg(void ); + void CEndProg(void ); + int execprog(int ,char *, ELLIPSES); + + void CEditDec(DEC *,int ,int ,char *); + void CConvDec(char *,DEC *); + + int CIOResult(void ); + TDitta *CGetDitta(char *); + void CPutDitta(char *,TDitta *); + void CClearKb(void ); + void crtrim(char *); + void cltrim(char *); + void CSplitString(char *,int ,char *,char *); + void CSpace(char *, int); + uchar editpref(BOOLEAN, BOOLEAN, BOOLEAN); + char **getlinefd(char *, char, char); + word getkeyid(void); + void addtokeybar(char *, word); + void delfromkeybar(word); + uchar *setofkeybar(word); + /* @(!) 2.3.01.134 */ + uchar *strsetofkeybar(char *); + /* @(:) 2.3.01.134 */ + /* @(!) 2.3.01.223 */ + void suspendkey(char *); + void resumekey(char *); + /* @(:) 2.3.01.223 */ + /* @(!) 2.3.01.316 */ +#ifdef DOS + void tmpfname(char *,char *); +#endif + /* @(:) 2.3.01.316 */ +#ifdef __cplusplus +}; +#endif +#endif /* __CCOMMON_H */ diff --git a/include/ccustio.c b/include/ccustio.c index 7f2475c67..4ef443c2e 100755 --- a/include/ccustio.c +++ b/include/ccustio.c @@ -1,29 +1,9 @@ -/* - @(SH) Funzioni per la gestione dei file a record. - - @(M$) PRIVATE - - CalcPos(Rec,Len,Base) : Calcola la posizione del record nel file - - @(C$) PRIVATE - - LOCKSEM : 'locksem' ; nome del semaforo utilizzato per il lock - - @(VG$) PRIVATE - - ld : struttura su disco che contien i dati per i lock sui file - sizeld : numero di byte occupati dalla struttura ld - semres : flag per l'ok delle operazioni sui semafori - ------------------------------------------------------------------------------- - ------------------------------------------------------------------------------- - */ - -#include "ccustio.h" +#include "ccustio.h" #include "checks.h" #ifdef DOS -#include +#include #endif -#include +#include #ifndef DOS #include #include diff --git a/include/ccustio.h b/include/ccustio.h new file mode 100755 index 000000000..5d4573e35 --- /dev/null +++ b/include/ccustio.h @@ -0,0 +1,81 @@ +#ifndef __CCUSTIO_H +#define __CCUSTIO_H + +#ifndef DOS +#include +#endif +#include + +#ifndef __CCOMMON_H +#include "ccommon.h" +#endif +#ifndef __GENCONST_H +#include "genconst.h" +#endif + +#define BlockLenIO 512 +#define Valid 0 +#define Deleted 1 + +typedef char *FileName; +typedef char *RecType; +typedef long RecNoType; +typedef struct { + int F; + FILE *Fd; + int IOR; + int LenRec; + int BaseFil; + unsigned LockMode; + RecNoType lpos; + PathSt name; + /* @(!) 2.3.01.325 */ + RecNoType lkpos; + /* @(:) 2.3.01.325 */ +} SecDef ; + +#ifdef DOS +#define TESTLOCK(x) (/*test_share() && */ ((x) == EACCES || (x) == EAGAIN)) +#define DEADLOCK(x) (/*test_share() && */ (x) == EDEADLOCK) +#else +#define TESTLOCK(x) (((x) == EACCES) || ((x) == EAGAIN) || ((x) == ENOLCK)) +#define DEADLOCK(x) (((x) == EDEADLOCK) || ((x) == EDEADLK)) +#endif +#define BLOCKEXT(len,rec) (((((RecNoType) (len)) * ((RecNoType) (rec))) / BlockLenIO) + 1) + +/* @(!) 2.3.01.325 */ +#ifdef DOS +#define ASPETTA(x) (sleep_dos(x)) +#else +#define ASPETTA(x) (sleep(x)) +#endif +/* @(:) 2.3.01.325 */ + + +#ifdef __cplusplus +extern "C" { +#endif + void CLockRec(SecDef *, RecNoType, unsigned); + void CVerify(SecDef *,char *); + void COpen(SecDef *,char *, unsigned, unsigned, unsigned); + void CCreate(SecDef *,char *,unsigned ,unsigned ,RecNoType); + void CChsize(SecDef *,char *,unsigned ,unsigned ,RecNoType); + void CClose(SecDef *); + void CDelete(SecDef *,char *); + void CRead(SecDef *,RecType,RecNoType ,unsigned ); + void CWrite(SecDef *,RecType,RecNoType ,unsigned ); + void IDeleteRec(RecType); + void IRecallRec(RecType); + BOOLEAN IRecIsDeleted(RecType); + BOOLEAN ITestLock(int ); + /* @(!) 2.3.01.325 modificata int excllock(char *,BOOLEAN);*/ + /* @(!) 2.3.01.325 modificata int exclunlock(char *,BOOLEAN);*/ + int excllock(char *,BOOLEAN); + int exclunlock(char *,BOOLEAN); + int sleep_dos(int); + /* @(:) 2.3.01.325 */ + BOOLEAN test_share(void); +#ifdef __cplusplus +}; +#endif +#endif /* __CCUSTIO_H */ diff --git a/include/cfiles.c b/include/cfiles.c index 273908653..10229ba76 100755 --- a/include/cfiles.c +++ b/include/cfiles.c @@ -1,1406 +1,1390 @@ -/* -@(SH) Funzioni per la manipolazione dei files in direttorio ------------------------------------------------------------------------------- -@(VG$) PRIVATE - -fdir : identificatori per il direttori -rdir : identificatori per i tracciati record -dispferr : flag che attiva segnalazione errore per campo inesistente -dirfl : flags che permettono aperture e chiusure multiple per i direttori -recfl : flags che permettono aperture e chiusure multiple per i Tr. record ------------------------------------------------------------------------------- -*/ - -#define __CFILES_C /* fv */ - -#include "cfiles.h" -#include "fldtypes.h" -#include "lffilesc.h" - - int hashfun(char *); - void setdec(char *, int); - char *prefname(void); - - HIDDEN BOOLEAN pathpread = FALSE; - - BOOLEAN dispferr = TRUE; - int dirfl[2] = {0, 0}, recfl[2] = {0, 0} ; - char __ptprf[80] = ""; - -/* -@(#) COpenDir FILES - -@(ID) -Apre il file directory di una ditta. -@(FD) - -@(ISV) -name = percorso per il file di direttorio. - -Versione DOS e XENIX. -@(FSV) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegare dettagliatamente il motivo. -@(FN) -*/ - - void COpenDir(lockmode, dirflg) - int lockmode; /* modo di apertura */ - int dirflg; /* flag per file comuni */ - - { - PathSt name; - - if (dirfl[dirflg]++) return; -#ifndef DOS - if ((excllock(CInsPref(glockname, dirflg), (lockmode == ExclLock)) == -1) - && (errno == EACCES)) - fatal_box("Locked Directory. Error number : %d ", errno); -#endif - strcpy(name, CInsPref(directory, dirflg)) ; - COpen(&fdir[dirflg], name, sizeof(FileDes), 0, lockmode) ; - if (fdir[dirflg].IOR != NoErr) - fatal_box("Can't open Directory. Error number : %d ", fdir[dirflg].IOR); - } - -/* -@(#) CCloseDir FILES - -@(ID) -Chiude il file di direttorio di una ditta. -@(FD) - -@(ISV) -Versione DOS e XENIX. -@(FSV) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - void CCloseDir(dirflg) - int dirflg; /* flag per file comuni */ - - { -#ifndef DOS - exclunlock(CInsPref(glockname, dirflg), (fdir[dirflg].LockMode == ExclLock)); -#endif - if (dirfl[dirflg]) dirfl[dirflg]--; - if (!dirfl[dirflg]) CClose(&fdir[dirflg]) ; - } - -/* -@(#) COpenFile FILES - -@(ID) -Legge i dati di un archivio dal Direttorio. -@(FD) - -@(ISV) -junk = variabile spazzatura per la chiamata della funzione "sleep". - -s = stringa contenente messaggio di attesa. - -w = descrittore finestra di attesa. - -Versione DOS e XENIX. -@(FSV) - -@(IN) -Sostituisce l'eventuale simbolo "$" con il prefisso corrente. - -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - void COpenFile(logicname,filed,lockmode,dirflg) - int logicname; /* numero logico file */ - FileDes *filed; /* puntatore alla struttura che contiene i dati letti dal direttorio */ - int lockmode; /* tipo di lock effettuato sul record */ - int dirflg; /* flag per file comuni */ - -{ - do - { - CRead(&fdir[dirflg],(RecType) filed,(long) logicname, lockmode); - - if (TESTLOCK(fdir[dirflg].IOR)) - message_box("Sono in attesa della directory n.ro %d", logicname); - } while TESTLOCK(fdir[dirflg].IOR) ; - strcpy(filed->SysName, CAddPref(filed->SysName)) ; -} - -/* -@(#) CCloseFile FILES - -@(ID) -Chiude e Riscrive i dati di un file sul direttorio. -@(FD) - -@(ISV) -wd = descrittore di una riga di direttorio. - -junk = variabile spazzatura per la chiamata della funzione "sleep". - -s = messaggio di attesa. - -w = descrittore della finestra di attesa. -@(FSV) - -@(IN) -ATTENZIONE : questa funzione aggiorna esclusivamente i campi EOD e Flags . - -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - void CCloseFile(logicname,filed,dirflg) - int logicname; /* numero logico file */ - FileDes *filed; /* puntatore al descrittore di un archivio */ - int dirflg; /* flag per file comuni */ - - { - FileDes wd; - - CRead(&fdir[dirflg],(RecType) &wd,(long) logicname, NoLock); - wd.EOD = filed->EOD; - wd.Flags = filed->Flags; - CWrite(&fdir[dirflg],(RecType) &wd,(long) logicname, UnLock); - } -/* -@($) CGetFile FILES - -@(ID) -Legge i dati relativi ad un archivio nel direttorio. -Non sostituisce con il prefisso l'eventuale carattere "$". -@(FD) - -@(ISV) -junk = variabile spazzatura per la chiamata della funzione "sleep". - -s = messaggio di attesa. - -w = descrittore finestra di attesa. - -Versione DOS e XENIX. -@(FSV) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - void CGetFile(logicname,filed,lockmode,dirflg) - int logicname; /* numero logico file */ - FileDes *filed; /* puntatore al descrittore archivio nel direttorio */ - int lockmode; /* tipo di lock sul record */ - int dirflg; /* flag per file comuni */ - { - - do - { - CRead(&fdir[dirflg],(RecType) filed,(long) logicname, lockmode); - if (TESTLOCK(fdir[dirflg].IOR)) - message_box("Sono in attesa della directory n.ro %d", logicname); - } - while TESTLOCK(fdir[dirflg].IOR) ; - } - -/* -@($) CPutFile FILES - -@(ID) -Chiude il direttorio e Riscrive i dati relativi ad un archivo. -Aggiorna tutti i campi. -@(FD) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - void CPutFile(logicname,filed,dirflg) - int logicname; /* numero logico file */ - FileDes *filed; /* puntatore al descrittore dell'archivio */ - int dirflg; /* flag per file comuni */ - - { - CWrite(&fdir[dirflg],(RecType) filed,(long) logicname, UnLock); - } - -/* -@($) zerofdes FILES - -@(ID) -Azzera un descrittore di directory. -@(FD) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - - void zerofdes(d) - FileDes *d; /* puntatore al descrittore di un archivio nella direttorio */ - - { - strcpy(d->SysName, ""); - d->EOD = 0; - d->EOX = 0; - d->LenR = 0; - d->Flags = 0; - strcpy(d->Des, ""); - strcpy(d->FCalc, ""); - strcpy(d->GenPrompt, ""); - } - -/* -@(#) COpenRecDir FILES - -@(ID) -Apre l'Archivio dei Tracciati Record. -@(FD) - -@(ISV) -name = nome dell'archivio dei Tracciati Record. - -Versione DOS e XENIX. -@(FSV) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - void COpenRecDir(lockmode,dirflg) - int lockmode; /* modo di apertura */ - int dirflg; /* flag per file comuni */ - - { - PathSt name; - - if (recfl[dirflg]++) return; - strcpy(name, CInsPref(ntrrec, dirflg)) ; - COpen(&rdir[dirflg], name, sizeof(RecDes), 0, lockmode) ; - if (rdir[dirflg].IOR != NoErr) - fatal_box("Can't open record description file. Error number : %d ", rdir[dirflg].IOR); - - } - -/* -@(#) CCloseRecDir FILES - -@(ID) -Chiude l'Archivio dei Tracciati Record -@(FD) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo -@(FN) -*/ - - void CCloseRecDir(dirflg) - int dirflg; /* flag per file comuni */ - - { - if (recfl[dirflg]) recfl[dirflg]--; - if (!recfl[dirflg]) CClose(&rdir[dirflg]) ; - } - -/* -@(#) CGetRec FILES - -@(ID) -Legge il tracciato record del file "logicname" e lo mette in "recd". -@(FD) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - void CGetRec(logicname,recd,dirflg) - int logicname; /* numero file */ - RecDes *recd; /* descrittore record */ - int dirflg; /* flag per file comuni */ - - { - CRead(&rdir[dirflg],(RecType) recd,(long) logicname, NoLock); - } - - -/* -@($) CPutRec FILES - -@(ID) -Aggiorna il file dei Tracciati Record. -@(FD) - -*/ - - void CPutRec(logicname,recd,dirflg) - int logicname; /* numero file */ - RecDes *recd; /* descrittore record */ - int dirflg; /* flag per file comuni */ - - { - CWrite(&rdir[dirflg],(RecType) recd,(long) logicname, NoLock); - } - -/* -@($) zerodes FILES - -@(ID) -Azzera il Tracciato Record "r". -@(FD) - -@(ISV) -i,j = contatori. -@(FSV) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - void zerordes(r) - RecDes *r; /* descrittore record */ - - { - int i,j ; - - r->NFields = 0; - for (i = 0; i < MaxFields; i++) - { - strcpy(r->Fd[i].Name, ""); - r->Fd[i].TypeF = NullF; - r->Fd[i].Len = 0; - r->Fd[i].Dec = 0; - r->Fd[i].RecOff = 0; - } - for (i = 0; i < MaxFields; i++) r->SortFd[i] = INVFLD; - r->NKeys = 0; - for (i = 1; i < MaxKeys; i++) - { - r->Ky[i].DupKeys = FALSE; - r->Ky[i].NkFields = 0; - for (j = 0; j < MKFields; j++) r->Ky[i].FieldSeq[j] = INVFLD; - for (j = 0; j < MKFields; j++) r->Ky[i].FromCh[j] = INVFLD; - for (j = 0; j < MKFields; j++) r->Ky[i].ToCh[j] = INVFLD; - } - } - -/* -@($) setrdes FILES - -@(ID) -Dato il tracciato record crea la struttura HASH (sortFd) per l'accesso veloce -ai campi. -@(FD) - -@(ISV) -pos = indirizzo Hash. - -i = contatore. - -nf = variabile di lavoro. - -tmppos = indirizzo hash per l'accesso ai campi. -@(FSV) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - word setrdes(r) - RecDes *r; /* descrittore record */ - - { - int pos, tmppos, nf, i; - - for (i = 0; i < MaxFields; i++) r->SortFd[i] = INVFLD; - if (r->NFields) - { - for (i = 0; i < r->NFields; i++) - { - nf = i; - pos = hashfun(r->Fd[nf].Name); - while (TRUE) - { - if (r->SortFd[pos] == INVFLD) - { - r->SortFd[pos] = (byte) nf; - break; - } - else - { - if (strcmp(r->Fd[r->SortFd[pos]].Name, r->Fd[nf].Name) <= 0) - { - pos++; - if (pos >= MaxFields) - pos = 0; - } - else - { - tmppos = r->SortFd[pos]; - r->SortFd[pos] = (byte) nf; - nf = tmppos; - } - } - } - } - r->Fd[0].RecOff = 1; - for (i = 1; i < r->NFields; i++) - r->Fd[i].RecOff = r->Fd[i - 1].RecOff + r->Fd[i - 1].Len; - return(r->Fd[r->NFields - 1].RecOff + r->Fd[r->NFields - 1].Len); - } - return(0); - } - -/* -@(SHF) Funzioni per la gestione dei campi dei record -@($) setdec FILES - -@(ID) -Data la stringa "s" (contenente un numero) Aggiusta il numero dei decimali in -base a "dec". -@(FD) - -@(ISV) -s1 = stringa di lavoro. - -i = contatore. - -l = lunghezza stringa s1. - -carry = eventuale riporto approssimazione. - -@(FSV) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - void setdec(s,dec) - char *s; /* stringa che deve contenere un numero */ - int dec; /* numero di decimali che deve avere il numero */ - - { - char *s1; - int i, l, carry; - - if (LENGTH(s) == 0) strcpy(s, "0"); - if ((s1 = strchr(s, ',')) != NULL) *s1 = '.'; - s1 = strchr(s, '.'); - if ((dec) && (s1 == NULL)) - { - strcat(s, "."); - s1 = strchr(s, '.'); - } - else - if (!dec) - { - if (s1 == NULL) return ; - l = LENGTH(s1); /* occhio verificare */ - carry = (s1[1] >= '5'); - *s1 = '\0'; - while (carry) - { - s1--; - if (*s1 == '-') break; - if (*s1 == '9') - { - *s1 = '0'; - if (s == s1) break; - } - else - { - (*s1)++; - carry = FALSE; - } - } - if (carry) - { - for (i = l; i > (*s1 == '-'); i--) s[i] = s[i - 1]; - s[(*s1 == '-')] = '1'; - } - return; - } - s1++; - l = LENGTH(s1); - if (l > dec) - { - carry = (s1[dec] >= '5'); - s1[dec] = '\0'; - while (carry) - { - dec--; - if (s1[dec] == '9') - { - s1[dec] = '0'; - if (!dec) break; - } - else - { - s1[dec]++; - carry = FALSE; - } - } - s1--; - while (carry) - { - s1--; - if (*s1 == '-') break; - if (*s1 == '9') - { - *s1 = '0'; - if (s == s1) break; - } - else - { - (*s1)++; - carry = FALSE; - } - } - if (carry) - { - for (i = l; i > (*s1 == '-'); i--) s[i] = s[i - 1]; - s[(*s1 == '-')] = '1'; - } - } - else - while (l++ < dec) strcat(s1, "0"); - } - -/* -@($) hashfun FILES - -@(ID) -Data la stringa "s" costruisce la chiave Hash. -@(FD) - -@(ISV) -l = lunghezza della stringa "s". - -w[82] = copia di lavoro della stringa "s". - -temp = variabile di lavoro. - -pw = puntatore ai caratteri della stringa. - -Utilizza l'operatore OR Esclusivo. -@(FSV) - -@(IN) -Restituisce l'indirizzo HASH. -@(FN) -*/ - - int hashfun(s) - char *s; /* stringa da eleborare */ - - { - int l; - char w[82]; - unsigned short temp = 0, *pw = (unsigned short *) w; - - strcpy(w, s); - if (ODD(LENGTH(s))) strcat(w, " "); - l = LENGTH(s); - while ((char *) pw < w + l) - { - temp ^= *pw; - pw++; - } - l = (short) (temp % (MaxFields - 3)); - if (l < 0) l = -l; - return(l); - } - -/* -@($) findfld FILES - -@(ID) -Ricerca all'interno di un record il campo di nome "s". -@(FD) - -@(ISV) -i= variabile di lavoro. -startp = variabile di lavoro. -cmp = variabile di lavoro. -@(FSV) -*/ - - int findfld(recd,s) - RecDes *recd; /* Descrittore record Tracciato Record */ - char *s; /* stringa contenente il nome del campo */ - - { - int i, cmp, startp; - - i = hashfun(s); - startp = i; - if (recd->SortFd[i] == INVFLD) return(-1); - do - { - if (!(cmp = strcmp(recd->Fd[recd->SortFd[i]].Name, s))) - return((int) (recd->SortFd[i])); - else - if (cmp > 0) return(-1); - else - if (++i >= MaxFields) i = 0; - if (recd->SortFd[i] == INVFLD) return(-1); - } - while (i != startp) ; - return(-1); - } - -/* -@(#) CFieldSize FILES - -@(ID) -Restituisce la lunghezza del campo. -@(FD) - -@(ISV) -p = puntatore al campo. -@(FSV) -*/ - - unsigned int CFieldSize(fieldname,recd) - char *fieldname; /* nome del campo */ - RecDes *recd; /* descrittore record */ - - { - int p; - - if ((p = findfld(recd, fieldname)) != -1) return(recd->Fd[p].Len); - else return(0); - } - -/* -@(#) CFieldDec FILES - -@(ID) -Restituisce il numero di decimali presenti nel campo. -@(FD) - -@(ISV) -p = puntatore al campo. -@(FSV) -*/ - - unsigned int CFieldDec(fieldname,recd) - char *fieldname; /* nome del campo */ - RecDes *recd; /* descrittore record */ - - { - int p; - - if ((p = findfld(recd, fieldname)) != -1) return(recd->Fd[p].Dec); - else return(0); - } - -/* -@(#) CFieldType FILES - -@(ID) -Restituisce un intero rappresentante il tipo del campo. -@(FD) - -@(ISV) -p = posizione all'interno del record del campo. -@(FSV) -*/ - - int CFieldType(fieldname,recd) - char *fieldname; /* nome del campo */ - RecDes *recd; /* descrittore record */ - - { - int p; - - if ((p = findfld(recd, fieldname)) != -1) return(recd->Fd[p].TypeF); - else return(NullF); - } - -/* -@($) getfrmt FILES - -@(ID) -Prepara il il formato per dsprintf per il campo "nf" del tracciato record "recd". -@(FD) - -@(ISV) -len = lunghezza del campo. - -dec = numero di decimali presenti nel campo. -@(FSV) -*/ - - void getfrmt(recd,nf,frm) - RecDes *recd; /* descrittore record */ - int nf; /* numero campo */ - char *frm; /* stringa in formato per dsprintf */ - - { - int len, dec; - - strcpy(frm, ""); - len = recd->Fd[nf].Len; - dec = recd->Fd[nf].Dec; - if (recd->Fd[nf].TypeF == IntF) sprintf(frm, "%%%dd", len); - else - if (recd->Fd[nf].TypeF == Int4F) sprintf(frm, "%%%dld", len); - else - if (recd->Fd[nf].TypeF == RealF) sprintf(frm, "%%%d.%dt",len, dec); - /*cambiare */ - else - if (recd->Fd[nf].TypeF == WordF) sprintf(frm, "%%%du", len); - else - if (recd->Fd[nf].TypeF == ZeroF) sprintf(frm, "%%0%dd", len); - else - if (recd->Fd[nf].TypeF == EZeroF) sprintf(frm, "%%0%dld", len); - } - -/* -@(#) CGetField FILES - -@(ID) -Estrae il valore di un campo dal record e lo pone in "fout". - -Restituisce un eventuale codice errore. -@(FD) - -@(ISV) -r = variabile che contiene l'eventuale codice errore. - -p = variabile per la chiamata di "findfld". - -s = puntatore alla zona di memoria allocata. - -frm= stringa per contenere un formato per la dsprintf. -@(FSV) - -@(IN) -Si osservi che "fout" deve essere un puntatore a una variabile di tipo coerente con il campo da leggere. -@(FN) -*/ - -#ifndef FOXPRO - -/* -@(#) CPutField FILES - -@(ID) -Scrive il contenuto della variabile puntata da "fin" nel campo "fieldname" del record. - -Restituisce un eventuale codice errore. -@(FD) - -@(ISV) -r = variabile che contiene l'eventuale codice errore. - -p = variabile per la chiamata di "findfld". - -s = puntatore alla zona di memoria allocata. - -frm= stringa per contenere un formato per la dsprintf. -@(FSV) - -@(IN) -Si osservi che "fin" deve essere un puntatore a una variabile di tipo coerente con il campo da leggere. -@(FN) -*/ - - int CPutField(fieldname,recd,fin,recout) - char *fieldname; /* nome del campo */ - RecDes *recd; /* descrittore record */ - void *fin; /* puntatore al valore da scrivere */ - RecType recout; /* buffer contenetnte il record */ - - { - int p; - char s[256], frm[30]; - - strcpy(s, ""); - p = findfld(recd, fieldname); - getfrmt(recd, p, frm); - if (recd->Fd[p].TypeF == AlfaF) strcpy(s, (char *) fin); - else - if ((recd->Fd[p].TypeF == IntF) || (recd->Fd[p].TypeF == ZeroF)) - sprintf(s, frm, *((int *) fin)); - else - if ((recd->Fd[p].TypeF == Int4F) || (recd->Fd[p].TypeF == EZeroF)) - sprintf(s, frm, *((long *) fin)) ; - else - if (recd->Fd[p].TypeF == RealF) dsprintf(s, frm, (DEC *) fin); - else - if (recd->Fd[p].TypeF == WordF) sprintf(s, frm, *((unsigned *) fin)) ; - else - if (recd->Fd[p].TypeF == CharF) - { - s[0] = *((char *) fin); - s[1] = '\0'; - } - else - if (recd->Fd[p].TypeF == BoolF) - { - s[0] = *((BOOLEAN*) fin) ? 'X' : ' '; - s[1] = '\0'; - } - return CPutFieldBuff(fieldname, recd, s, recout); - } - -#endif /* FOXPRO */ - -/* -@(#) CGetFieldBuff FILES - -@(ID) -Estrae il valore di un campo dal record e lo pone nella stringa "s". - -Restituisce un eventuale codice errore. -@(FD) - -@(ISV) -p = puntatore al campo. - -i = contatore. - -Off = offest in byte all'interno del record per il campo in oggetto. - -len = lunghezza campo. - -s1 = stringa di lavoro. - -d = data in formato stringa. -@(FSV) - -@(IN) -Utilizzato per il Data Entry. -@(FN) -*/ - - int CGetFieldBuff(fieldname,recd,recin,s) - char *fieldname; /* nome del campo */ - RecDes *recd; /* descrittore record */ - RecType recin; /* buffer contenente il record */ - char *s; /* stringa per l'output */ - - { - int p, i; - char *s1; - TrDate d; - - if ((p = findfld(recd, fieldname)) != -1) - { - const int tipo = recd->Fd[p].TypeF; - unsigned int off = recd->Fd[p].RecOff; - byte len = recd->Fd[p].Len; - - if ((tipo != AlfaF) && (tipo != DateF) && (tipo != ZeroF) && (tipo != EZeroF)) - { - while ((recin[off] == ' ') && (len)) - { - off++; - len--; - } - if ((tipo != RealF) && (tipo != CharF)) - { - while ((recin[off] == '0') && (len)) - { - off++; - len--; - } - } - } - else - if ((tipo == ZeroF) || (tipo == EZeroF)) - { - char* c = &recin[off]; - for (i = 0; i < len; i++, c++) - { - if (*c == ' ') - *c = '0'; - else - if (*c != '0') - break; - } - if (i == len) - { - off += len; - len = 0; - } - } - if (len) - { - s1 = recin + off; - for (i = 0; i < len; i++) s[i] = s1[i]; - s[len] = '\0'; - while ((len) && (s[len - 1] == ' ')) s[--len] = '\0'; - } - else strcpy(s, ""); - - if ((tipo == RealF)) - if ((s1 = strchr(s, ',')) != NULL) *s1 = '.'; - return(0); - } - else - { - strcpy(s, ""); - return(-1); - } - } - -/* -@(#) CPutFieldBuff FILES - -@(ID) -Scrive il contenuto della stringa "s" nel campo "fieldname" del record. - -Restituisce un eventuale codice errore. -@(FD) - -@(ISV) -p = puntatore al campo. - -i = contatore. - -l = variabile di lavoro. - -off = offest in byte all'interno del record per il campo in oggetto. - -len = lunghezza campo. - -s1,s2 = stringa di lavoro. - -d = data in formato stringa. -@(FSV) - -@(IN) -Utilizzato per il Data Entry -@(FN) -*/ - - int CPutFieldBuff(fieldname,recd,s,recout) - char *fieldname; /* nome del campo */ - RecDes *recd; /* descrittore record */ - char *s; /* stringa contenente il valore da scrivere nel campo */ - RecType recout; /* buffer contenente il record */ - - { - int p, off, len, l, i; - TrDate d; - char *s1; -/* - char *s2; - s2 = malloc(256); -*/ - char s2[256]; - - strcpy(s2, s); - if ((p = findfld(recd, fieldname)) != -1) - { - off = recd->Fd[p].RecOff; - len = recd->Fd[p].Len; - if (recd->Fd[p].TypeF == RealF) setdec(s2, recd->Fd[p].Dec); - l = LENGTH(s2); - if (l > len) - { -/* free(s2); */ - return(-1); - } - s1 = recout + off ; - for (i = 0; i < l ; i++) s1[i] = s2[i] ; - if ((recd->Fd[p].TypeF == IntF) || - (recd->Fd[p].TypeF == Int4F) || - (recd->Fd[p].TypeF == WordF) || - (recd->Fd[p].TypeF == RealF) || - (recd->Fd[p].TypeF == ZeroF) || - (recd->Fd[p].TypeF == EZeroF)) - { - char c; - if ((recd->Fd[p].TypeF == ZeroF) || - (recd->Fd[p].TypeF == EZeroF)) - c = '0'; - else c = ' '; - if (l == 0) s1[l++] = '0'; - while (l < len) - { - for (i = l; i > 0; i--) s1[i] = s1[i - 1]; - s1[0] = c; - l++; - } - } - else - while (l < len) s1[l++] = ' '; -/* free(s2); */ - return(0); - } - else - { - strcpy(s, ""); -/* free(s2); */ - return(-1); - } - } - - -/* -@(#) CZeroField FILES - -@(ID) -Azzera un campo. -@(FD) - -@(ISV) -p = puntatore al campo. - -s = stringa messaggio. -@(FSV) -*/ - - int CZeroField(fieldname,recd,recout) - char *fieldname; /* nonme del campo */ - RecDes *recd; /* descrittore record */ - RecType recout; /* buffer contenente il record */ - - { - int p; - - if ((p = findfld(recd, fieldname)) != -1) - { - if (recd->Fd[p].TypeF == DateF) - memset(recout + recd->Fd[p].RecOff, '0', recd->Fd[p].Len); - else - { - memset(recout + recd->Fd[p].RecOff, Blank, recd->Fd[p].Len); - if ((recd->Fd[p].TypeF == IntF) || - (recd->Fd[p].TypeF == Int4F) || - (recd->Fd[p].TypeF == WordF)) - { - *(recout + recd->Fd[p].RecOff + recd->Fd[p].Len - 1) = '0'; - } - else - if (recd->Fd[p].TypeF == RealF) - { - if (recd->Fd[p].Dec) - { - memset(recout + recd->Fd[p].RecOff + recd->Fd[p].Len - - recd->Fd[p].Dec - 2, '0', recd->Fd[p].Dec + 2); - *(recout + recd->Fd[p].RecOff + recd->Fd[p].Len - - recd->Fd[p].Dec - 1) = '.'; - } - else *(recout + recd->Fd[p].RecOff + recd->Fd[p].Len - 1) = '0'; - } - return(NoErr); - } - } - else return(-1); - return(NoErr); - } - -/* -@(#) CZeroRec FILES - -@(ID) -Azzera tutto il record. -@(FD) - -@(ISV) -i = contatore. - -junk = variabile spazzatura per la chiamata di CZeroField. -@(FSV) -*/ - - void CZeroRec(recd,recout) - RecDes *recd; /* descrittore record */ - RecType recout; /* buffer contenente il record */ - - { - int i, junk; - - IRecallRec(recout) ; - for (i = 0; i < recd->NFields; i++) junk = CZeroField(recd->Fd[i].Name, - recd, recout); - } - - -/* -@($) prefname FILES - -@(ID) -Restituisce il nome del file che contiene il prefisso corrente. -@(FD) - -@(ISV) -s,s1 = stringhe di lavoro. - -Versione DOS e XENIX. -@(FSV) -*/ - -#ifndef FOXPRO - - char *prefname() - - { - static PathSt s; -#ifdef DOS - char *s1 = getenv("PREFPATH"); - if (s1 == NULL) s1 = "prefix.txt"; - strcpy(s, s1); -#else - sprintf(s, "prefix.%-d", getuid()); -#endif - return(s) ; - } - -#endif - -/* -@(#) CGetPref FILES - -@(ID) -Legge dal file prefisso il prefisso dati corrente. -@(FD) - -@(ISV) -f = puntatore al file. -@(FSV) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - char *CGetPref() - - { - const char* p = prefname(); - FILE *f = fopen(p, "r"); - - if (f == NULL) - { - strcpy(cprefix, ""); - } - else - { - if (fgets(cprefix, 42, f) != NULL) - { - const int len = LENGTH(cprefix)-1; - if (len >= 0 && cprefix[len] <= ' ') cprefix[len] = '\0'; - } - else - *cprefix = '\0'; - fclose(f); - } - if (!pathpread) - { - const char* p = "pathpref.ini"; - FILE* f = fopen(p, "r"); - pathpread = TRUE; - if (f != NULL) - { - if (fgets(__ptprf, 42, f) != NULL) - { - const int len = LENGTH(__ptprf)-1; - if (len >= 0 && __ptprf[len] <= ' ') - { - __ptprf[len] = '\0'; - if (len > 0) strcat(__ptprf, "/"); - } - } - else - *__ptprf = '\0'; - fclose(f); - } - } - if (*__ptprf) - { - char ws[200]; - sprintf(ws, "%s%s", __ptprf, cprefix); - strcpy(cprefix, ws); - } - return(cprefix); - } - -/* -@($) CPutPref FILES - -@(ID) -Aggiorna sul file prefisso il prefisso dati corrente. -@(FD) - -@(ISV) -f = puntatore a file. -@(FSV) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - void CPutPref(pref) - char *pref; /* stringa contenente il nuovo prefisso */ - - { - FILE *f; - const int l = strlen(__ptprf); - - if (l && strncmp(pref, __ptprf, l) == 0) pref += l; - if ((f = fopen(prefname(), "w")) == NULL) - fatal_box("Put prefix. Error number : %d ", errno); - fprintf(f, "%s\n", pref); - fclose(f); - } - -/* -@($) CAddPref FILES - -@(ID) -Cerca il carattere "$" nel nome file e lo sostituisce con il prefisso corrente. -@(FD) - -@(ISV) -s = stringa che contiene il nome. -@(FSV) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - -char *CAddPref(name) -char *name; /* nome file */ - -{ - static PathSt s; - - if (*name == '$') - { - name++; - return(CInsPref(name, NORDIR)) ; - } - else - if (*name == '%') - { - name++; - return(CInsPref(name, COMDIR)) ; - } - else - { - sprintf(s, "%s%s", __ptprf, name); - return(s); - } - } - -/* -@($) CInsPref FILES - -@(ID) -Aggiunge (a sinistra) il prefisso corrente. -@(FD) - -@(ISV) -s = stringa di lavoro. -@(FSV) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. -@(FN) -*/ - - char *CInsPref(name,dirflg) - char *name; /* nome del file cui aggiungere il prefisso */ - int dirflg; /* flag per file comuni */ - - { - static PathSt s; - - if (dirflg == NORDIR) - { - if (LENGTH(cprefix) == 0) sprintf(s,"%s", name); - else sprintf(s,"%s%c%s",cprefix, DIRSEP, name); - } - else sprintf(s,"%scom%c%s", __ptprf, DIRSEP, name); - return(s); - } - -/* -@(#) CGetIdxName FILES - -@(ID) -Dato un nome file costruisce il nome del file indice corrispondente. -@(FD) - -@(ISV) -fdst,s1,s2 = stringhe di lavoro. -@(FSV) - -@(IN) -NON UTILIZZARE !!. - -Se si utilizza spiegarne dettagliatamente il motivo. - -L' estensione dei file indice e' ndx; e' quindi vietato utilizzare un nome -di file che abbia tale estensione. L' estensione dei file dati e' dta. -@(FN) -*/ - - char *CGetIdxName(s) - char *s; /* stringa contenente il nome file */ - - { - static PathSt fdst; - char *s1, *s2; - - strcpy(fdst, s) ; - s1 = strrchr(fdst,DIRSEP) ; - if (s1 == NULL) s1 = fdst; - s2 = strchr(s1,'.') ; - if (s2 != NULL) s2[0] = '\0' ; - s1 = strcat(fdst, ".ndx") ; - return(fdst) ; - } +#define __CFILES_C /* fv */ + +#include "cfiles.h" +#include "fldtypes.h" + +int hashfun(char *); +void setdec(char *, int); +char *prefname(void); + +HIDDEN BOOLEAN pathpread = FALSE; + +BOOLEAN dispferr = TRUE; +int dirfl[2] = {0, 0}, recfl[2] = {0, 0} ; +char __ptprf[80] = ""; + +/* + @(#) COpenDir FILES + + @(ID) + Apre il file directory di una ditta. + @(FD) + + @(ISV) + name = percorso per il file di direttorio. + + Versione DOS e XENIX. + @(FSV) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegare dettagliatamente il motivo. + @(FN) + */ + +void COpenDir(lockmode, dirflg) + int lockmode; /* modo di apertura */ + int dirflg; /* flag per file comuni */ + +{ + PathSt name; + + if (dirfl[dirflg]++) return; +#ifndef DOS + if ((excllock(CInsPref(glockname, dirflg), (lockmode == ExclLock)) == -1) + && (errno == EACCES)) + fatal_box("Locked Directory. Error number : %d ", errno); +#endif + strcpy(name, CInsPref(directory, dirflg)) ; + COpen(&fdir[dirflg], name, sizeof(FileDes), 0, lockmode) ; + if (fdir[dirflg].IOR != NoErr) + fatal_box("Can't open Directory. Error number : %d ", fdir[dirflg].IOR); +} + +/* + @(#) CCloseDir FILES + + @(ID) + Chiude il file di direttorio di una ditta. + @(FD) + + @(ISV) + Versione DOS e XENIX. + @(FSV) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +void CCloseDir(dirflg) + int dirflg; /* flag per file comuni */ + +{ +#ifndef DOS + exclunlock(CInsPref(glockname, dirflg), (fdir[dirflg].LockMode == ExclLock)); +#endif + if (dirfl[dirflg]) dirfl[dirflg]--; + if (!dirfl[dirflg]) CClose(&fdir[dirflg]) ; +} + +/* + @(#) COpenFile FILES + + @(ID) + Legge i dati di un archivio dal Direttorio. + @(FD) + + @(ISV) + junk = variabile spazzatura per la chiamata della funzione "sleep". + + s = stringa contenente messaggio di attesa. + + w = descrittore finestra di attesa. + + Versione DOS e XENIX. + @(FSV) + + @(IN) + Sostituisce l'eventuale simbolo "$" con il prefisso corrente. + + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +void COpenFile(logicname,filed,lockmode,dirflg) + int logicname; /* numero logico file */ + FileDes *filed; /* puntatore alla struttura che contiene i dati letti dal direttorio */ + int lockmode; /* tipo di lock effettuato sul record */ + int dirflg; /* flag per file comuni */ + +{ + do + { + CRead(&fdir[dirflg],(RecType) filed,(long) logicname, lockmode); + + if (TESTLOCK(fdir[dirflg].IOR)) + message_box("Sono in attesa della directory n.ro %d", logicname); + } while TESTLOCK(fdir[dirflg].IOR) ; + strcpy(filed->SysName, CAddPref(filed->SysName)) ; +} + +/* + @(#) CCloseFile FILES + + @(ID) + Chiude e Riscrive i dati di un file sul direttorio. + @(FD) + + @(ISV) + wd = descrittore di una riga di direttorio. + + junk = variabile spazzatura per la chiamata della funzione "sleep". + + s = messaggio di attesa. + + w = descrittore della finestra di attesa. + @(FSV) + + @(IN) + ATTENZIONE : questa funzione aggiorna esclusivamente i campi EOD e Flags . + + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +void CCloseFile(logicname,filed,dirflg) + int logicname; /* numero logico file */ + FileDes *filed; /* puntatore al descrittore di un archivio */ + int dirflg; /* flag per file comuni */ + +{ + FileDes wd; + + CRead(&fdir[dirflg],(RecType) &wd,(long) logicname, NoLock); + wd.EOD = filed->EOD; + wd.Flags = filed->Flags; + CWrite(&fdir[dirflg],(RecType) &wd,(long) logicname, UnLock); +} +/* + @($) CGetFile FILES + + @(ID) + Legge i dati relativi ad un archivio nel direttorio. + Non sostituisce con il prefisso l'eventuale carattere "$". + @(FD) + + @(ISV) + junk = variabile spazzatura per la chiamata della funzione "sleep". + + s = messaggio di attesa. + + w = descrittore finestra di attesa. + + Versione DOS e XENIX. + @(FSV) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +void CGetFile(logicname,filed,lockmode,dirflg) + int logicname; /* numero logico file */ + FileDes *filed; /* puntatore al descrittore archivio nel direttorio */ + int lockmode; /* tipo di lock sul record */ + int dirflg; /* flag per file comuni */ +{ + + do + { + CRead(&fdir[dirflg],(RecType) filed,(long) logicname, lockmode); + if (TESTLOCK(fdir[dirflg].IOR)) + message_box("Sono in attesa della directory n.ro %d", logicname); + } + while TESTLOCK(fdir[dirflg].IOR) ; +} + +/* + @($) CPutFile FILES + + @(ID) + Chiude il direttorio e Riscrive i dati relativi ad un archivo. + Aggiorna tutti i campi. + @(FD) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +void CPutFile(logicname,filed,dirflg) + int logicname; /* numero logico file */ + FileDes *filed; /* puntatore al descrittore dell'archivio */ + int dirflg; /* flag per file comuni */ + +{ + CWrite(&fdir[dirflg],(RecType) filed,(long) logicname, UnLock); +} + +/* + @($) zerofdes FILES + + @(ID) + Azzera un descrittore di directory. + @(FD) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + + +void zerofdes(d) + FileDes *d; /* puntatore al descrittore di un archivio nella direttorio */ + +{ + strcpy(d->SysName, ""); + d->EOD = 0; + d->EOX = 0; + d->LenR = 0; + d->Flags = 0; + strcpy(d->Des, ""); + strcpy(d->FCalc, ""); + strcpy(d->GenPrompt, ""); +} + +/* + @(#) COpenRecDir FILES + + @(ID) + Apre l'Archivio dei Tracciati Record. + @(FD) + + @(ISV) + name = nome dell'archivio dei Tracciati Record. + + Versione DOS e XENIX. + @(FSV) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +void COpenRecDir(lockmode,dirflg) + int lockmode; /* modo di apertura */ + int dirflg; /* flag per file comuni */ + +{ + PathSt name; + + if (recfl[dirflg]++) return; + strcpy(name, CInsPref(ntrrec, dirflg)) ; + COpen(&rdir[dirflg], name, sizeof(RecDes), 0, lockmode) ; + if (rdir[dirflg].IOR != NoErr) + fatal_box("Can't open record description file. Error number : %d ", rdir[dirflg].IOR); + +} + +/* + @(#) CCloseRecDir FILES + + @(ID) + Chiude l'Archivio dei Tracciati Record + @(FD) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo + @(FN) + */ + +void CCloseRecDir(dirflg) + int dirflg; /* flag per file comuni */ + +{ + if (recfl[dirflg]) recfl[dirflg]--; + if (!recfl[dirflg]) CClose(&rdir[dirflg]) ; +} + +/* + @(#) CGetRec FILES + + @(ID) + Legge il tracciato record del file "logicname" e lo mette in "recd". + @(FD) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +void CGetRec(logicname,recd,dirflg) + int logicname; /* numero file */ + RecDes *recd; /* descrittore record */ + int dirflg; /* flag per file comuni */ + +{ + CRead(&rdir[dirflg],(RecType) recd,(long) logicname, NoLock); +} + + +/* + @($) CPutRec FILES + + @(ID) + Aggiorna il file dei Tracciati Record. + @(FD) + + */ + +void CPutRec(logicname,recd,dirflg) + int logicname; /* numero file */ + RecDes *recd; /* descrittore record */ + int dirflg; /* flag per file comuni */ + +{ + CWrite(&rdir[dirflg],(RecType) recd,(long) logicname, NoLock); +} + +/* + @($) zerodes FILES + + @(ID) + Azzera il Tracciato Record "r". + @(FD) + + @(ISV) + i,j = contatori. + @(FSV) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +void zerordes(r) + RecDes *r; /* descrittore record */ + +{ + int i,j ; + + r->NFields = 0; + for (i = 0; i < MaxFields; i++) + { + strcpy(r->Fd[i].Name, ""); + r->Fd[i].TypeF = NullF; + r->Fd[i].Len = 0; + r->Fd[i].Dec = 0; + r->Fd[i].RecOff = 0; + } + for (i = 0; i < MaxFields; i++) r->SortFd[i] = INVFLD; + r->NKeys = 0; + for (i = 1; i < MaxKeys; i++) + { + r->Ky[i].DupKeys = FALSE; + r->Ky[i].NkFields = 0; + for (j = 0; j < MKFields; j++) r->Ky[i].FieldSeq[j] = INVFLD; + for (j = 0; j < MKFields; j++) r->Ky[i].FromCh[j] = INVFLD; + for (j = 0; j < MKFields; j++) r->Ky[i].ToCh[j] = INVFLD; + } +} + +/* + @($) setrdes FILES + + @(ID) + Dato il tracciato record crea la struttura HASH (sortFd) per l'accesso veloce + ai campi. + @(FD) + + @(ISV) + pos = indirizzo Hash. + + i = contatore. + + nf = variabile di lavoro. + + tmppos = indirizzo hash per l'accesso ai campi. + @(FSV) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +word setrdes(r) + RecDes *r; /* descrittore record */ + +{ + int pos, tmppos, nf, i; + + for (i = 0; i < MaxFields; i++) r->SortFd[i] = INVFLD; + if (r->NFields) + { + for (i = 0; i < r->NFields; i++) + { + nf = i; + pos = hashfun(r->Fd[nf].Name); + while (TRUE) + { + if (r->SortFd[pos] == INVFLD) + { + r->SortFd[pos] = (byte) nf; + break; + } + else + { + if (strcmp(r->Fd[r->SortFd[pos]].Name, r->Fd[nf].Name) <= 0) + { + pos++; + if (pos >= MaxFields) + pos = 0; + } + else + { + tmppos = r->SortFd[pos]; + r->SortFd[pos] = (byte) nf; + nf = tmppos; + } + } + } + } + r->Fd[0].RecOff = 1; + for (i = 1; i < r->NFields; i++) + r->Fd[i].RecOff = r->Fd[i - 1].RecOff + r->Fd[i - 1].Len; + return(r->Fd[r->NFields - 1].RecOff + r->Fd[r->NFields - 1].Len); + } + return(0); +} + +/* + @(SHF) Funzioni per la gestione dei campi dei record + @($) setdec FILES + + @(ID) + Data la stringa "s" (contenente un numero) Aggiusta il numero dei decimali in + base a "dec". + @(FD) + + @(ISV) + s1 = stringa di lavoro. + + i = contatore. + + l = lunghezza stringa s1. + + carry = eventuale riporto approssimazione. + + @(FSV) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +void setdec(s,dec) + char *s; /* stringa che deve contenere un numero */ + int dec; /* numero di decimali che deve avere il numero */ + +{ + char *s1; + int i, l, carry; + + if (LENGTH(s) == 0) strcpy(s, "0"); + if ((s1 = strchr(s, ',')) != NULL) *s1 = '.'; + s1 = strchr(s, '.'); + if ((dec) && (s1 == NULL)) + { + strcat(s, "."); + s1 = strchr(s, '.'); + } + else + if (!dec) + { + if (s1 == NULL) return ; + l = LENGTH(s1); /* occhio verificare */ + carry = (s1[1] >= '5'); + *s1 = '\0'; + while (carry) + { + s1--; + if (*s1 == '-') break; + if (*s1 == '9') + { + *s1 = '0'; + if (s == s1) break; + } + else + { + (*s1)++; + carry = FALSE; + } + } + if (carry) + { + for (i = l; i > (*s1 == '-'); i--) s[i] = s[i - 1]; + s[(*s1 == '-')] = '1'; + } + return; + } + s1++; + l = LENGTH(s1); + if (l > dec) + { + carry = (s1[dec] >= '5'); + s1[dec] = '\0'; + while (carry) + { + dec--; + if (s1[dec] == '9') + { + s1[dec] = '0'; + if (!dec) break; + } + else + { + s1[dec]++; + carry = FALSE; + } + } + s1--; + while (carry) + { + s1--; + if (*s1 == '-') break; + if (*s1 == '9') + { + *s1 = '0'; + if (s == s1) break; + } + else + { + (*s1)++; + carry = FALSE; + } + } + if (carry) + { + for (i = l; i > (*s1 == '-'); i--) s[i] = s[i - 1]; + s[(*s1 == '-')] = '1'; + } + } + else + while (l++ < dec) strcat(s1, "0"); +} + +/* + @($) hashfun FILES + + @(ID) + Data la stringa "s" costruisce la chiave Hash. + @(FD) + + @(ISV) + l = lunghezza della stringa "s". + + w[82] = copia di lavoro della stringa "s". + + temp = variabile di lavoro. + + pw = puntatore ai caratteri della stringa. + + Utilizza l'operatore OR Esclusivo. + @(FSV) + + @(IN) + Restituisce l'indirizzo HASH. + @(FN) + */ + +int hashfun(s) + char *s; /* stringa da eleborare */ + +{ + int l; + char w[82]; + unsigned short temp = 0, *pw = (unsigned short *) w; + + strcpy(w, s); + if (ODD(LENGTH(s))) strcat(w, " "); + l = LENGTH(s); + while ((char *) pw < w + l) + { + temp ^= *pw; + pw++; + } + l = (short) (temp % (MaxFields - 3)); + if (l < 0) l = -l; + return(l); +} + +/* + @($) findfld FILES + + @(ID) + Ricerca all'interno di un record il campo di nome "s". + @(FD) + + @(ISV) + i= variabile di lavoro. + startp = variabile di lavoro. + cmp = variabile di lavoro. + @(FSV) + */ + +int findfld(recd,s) + RecDes *recd; /* Descrittore record Tracciato Record */ + char *s; /* stringa contenente il nome del campo */ + +{ + int i, cmp, startp; + + i = hashfun(s); + startp = i; + if (recd->SortFd[i] == INVFLD) return(-1); + do + { + if (!(cmp = strcmp(recd->Fd[recd->SortFd[i]].Name, s))) + return((int) (recd->SortFd[i])); + else + if (cmp > 0) return(-1); + else + if (++i >= MaxFields) i = 0; + if (recd->SortFd[i] == INVFLD) return(-1); + } + while (i != startp) ; + return(-1); +} + +/* + @(#) CFieldSize FILES + + @(ID) + Restituisce la lunghezza del campo. + @(FD) + + @(ISV) + p = puntatore al campo. + @(FSV) + */ + +unsigned int CFieldSize(fieldname,recd) + char *fieldname; /* nome del campo */ + RecDes *recd; /* descrittore record */ + +{ + int p; + + if ((p = findfld(recd, fieldname)) != -1) return(recd->Fd[p].Len); + else return(0); +} + +/* + @(#) CFieldDec FILES + + @(ID) + Restituisce il numero di decimali presenti nel campo. + @(FD) + + @(ISV) + p = puntatore al campo. + @(FSV) + */ + +unsigned int CFieldDec(fieldname,recd) + char *fieldname; /* nome del campo */ + RecDes *recd; /* descrittore record */ + +{ + int p; + + if ((p = findfld(recd, fieldname)) != -1) return(recd->Fd[p].Dec); + else return(0); +} + +/* + @(#) CFieldType FILES + + @(ID) + Restituisce un intero rappresentante il tipo del campo. + @(FD) + + @(ISV) + p = posizione all'interno del record del campo. + @(FSV) + */ + +int CFieldType(fieldname,recd) + char *fieldname; /* nome del campo */ + RecDes *recd; /* descrittore record */ + +{ + int p; + + if ((p = findfld(recd, fieldname)) != -1) return(recd->Fd[p].TypeF); + else return(NullF); +} + +/* + @($) getfrmt FILES + + @(ID) + Prepara il il formato per dsprintf per il campo "nf" del tracciato record "recd". + @(FD) + + @(ISV) + len = lunghezza del campo. + + dec = numero di decimali presenti nel campo. + @(FSV) + */ + +void getfrmt(recd,nf,frm) + RecDes *recd; /* descrittore record */ + int nf; /* numero campo */ + char *frm; /* stringa in formato per dsprintf */ + +{ + int len, dec; + + strcpy(frm, ""); + len = recd->Fd[nf].Len; + dec = recd->Fd[nf].Dec; + if (recd->Fd[nf].TypeF == IntF) sprintf(frm, "%%%dd", len); + else + if (recd->Fd[nf].TypeF == Int4F) sprintf(frm, "%%%dld", len); + else + if (recd->Fd[nf].TypeF == RealF) sprintf(frm, "%%%d.%dt",len, dec); + /*cambiare */ + else + if (recd->Fd[nf].TypeF == WordF) sprintf(frm, "%%%du", len); + else + if (recd->Fd[nf].TypeF == ZeroF) sprintf(frm, "%%0%dd", len); + else + if (recd->Fd[nf].TypeF == EZeroF) sprintf(frm, "%%0%dld", len); +} + +/* + @(#) CGetField FILES + + @(ID) + Estrae il valore di un campo dal record e lo pone in "fout". + + Restituisce un eventuale codice errore. + @(FD) + + @(ISV) + r = variabile che contiene l'eventuale codice errore. + + p = variabile per la chiamata di "findfld". + + s = puntatore alla zona di memoria allocata. + + frm= stringa per contenere un formato per la dsprintf. + @(FSV) + + @(IN) + Si osservi che "fout" deve essere un puntatore a una variabile di tipo coerente con il campo da leggere. + @(FN) + */ + +#ifndef FOXPRO + +/* + @(#) CPutField FILES + + @(ID) + Scrive il contenuto della variabile puntata da "fin" nel campo "fieldname" del record. + + Restituisce un eventuale codice errore. + @(FD) + + @(ISV) + r = variabile che contiene l'eventuale codice errore. + + p = variabile per la chiamata di "findfld". + + s = puntatore alla zona di memoria allocata. + + frm= stringa per contenere un formato per la dsprintf. + @(FSV) + + @(IN) + Si osservi che "fin" deve essere un puntatore a una variabile di tipo coerente con il campo da leggere. + @(FN) + */ + +int CPutField(fieldname,recd,fin,recout) + char *fieldname; /* nome del campo */ + RecDes *recd; /* descrittore record */ + void *fin; /* puntatore al valore da scrivere */ + RecType recout; /* buffer contenetnte il record */ + +{ + int p; + char s[256], frm[30]; + + strcpy(s, ""); + p = findfld(recd, fieldname); + getfrmt(recd, p, frm); + if (recd->Fd[p].TypeF == AlfaF) strcpy(s, (char *) fin); + else + if ((recd->Fd[p].TypeF == IntF) || (recd->Fd[p].TypeF == ZeroF)) + sprintf(s, frm, *((int *) fin)); + else + if ((recd->Fd[p].TypeF == Int4F) || (recd->Fd[p].TypeF == EZeroF)) + sprintf(s, frm, *((long *) fin)) ; + else + if (recd->Fd[p].TypeF == RealF) dsprintf(s, frm, (DEC *) fin); + else + if (recd->Fd[p].TypeF == WordF) sprintf(s, frm, *((unsigned *) fin)) ; + else + if (recd->Fd[p].TypeF == CharF) + { + s[0] = *((char *) fin); + s[1] = '\0'; + } + else + if (recd->Fd[p].TypeF == BoolF) + { + s[0] = *((BOOLEAN*) fin) ? 'X' : ' '; + s[1] = '\0'; + } + return CPutFieldBuff(fieldname, recd, s, recout); +} + +#endif /* FOXPRO */ + +/* + @(#) CGetFieldBuff FILES + + @(ID) + Estrae il valore di un campo dal record e lo pone nella stringa "s". + + Restituisce un eventuale codice errore. + @(FD) + + @(ISV) + p = puntatore al campo. + + i = contatore. + + Off = offest in byte all'interno del record per il campo in oggetto. + + len = lunghezza campo. + + s1 = stringa di lavoro. + + d = data in formato stringa. + @(FSV) + + @(IN) + Utilizzato per il Data Entry. + @(FN) + */ + +int CGetFieldBuff(fieldname,recd,recin,s) + char *fieldname; /* nome del campo */ + RecDes *recd; /* descrittore record */ + RecType recin; /* buffer contenente il record */ + char *s; /* stringa per l'output */ + +{ + int p, i; + char *s1; + + if ((p = findfld(recd, fieldname)) != -1) + { + const int tipo = recd->Fd[p].TypeF; + unsigned int off = recd->Fd[p].RecOff; + byte len = recd->Fd[p].Len; + + if ((tipo != AlfaF) && (tipo != DateF) && (tipo != ZeroF) && (tipo != EZeroF)) + { + while ((recin[off] == ' ') && (len)) + { + off++; + len--; + } + if ((tipo != RealF) && (tipo != CharF)) + { + while ((recin[off] == '0') && (len)) + { + off++; + len--; + } + } + } + else + if ((tipo == ZeroF) || (tipo == EZeroF)) + { + char* c = &recin[off]; + for (i = 0; i < len; i++, c++) + { + if (*c == ' ') + *c = '0'; + else + if (*c != '0') + break; + } + if (i == len) + { + off += len; + len = 0; + } + } + if (len) + { + s1 = recin + off; + for (i = 0; i < len; i++) s[i] = s1[i]; + s[len] = '\0'; + while ((len) && (s[len - 1] == ' ')) s[--len] = '\0'; + } + else strcpy(s, ""); + + if ((tipo == RealF)) + if ((s1 = strchr(s, ',')) != NULL) *s1 = '.'; + return(0); + } + else + { + strcpy(s, ""); + return(-1); + } +} + +/* + @(#) CPutFieldBuff FILES + + @(ID) + Scrive il contenuto della stringa "s" nel campo "fieldname" del record. + + Restituisce un eventuale codice errore. + @(FD) + + @(ISV) + p = puntatore al campo. + + i = contatore. + + l = variabile di lavoro. + + off = offest in byte all'interno del record per il campo in oggetto. + + len = lunghezza campo. + + s1,s2 = stringa di lavoro. + + d = data in formato stringa. + @(FSV) + + @(IN) + Utilizzato per il Data Entry + @(FN) + */ + +int CPutFieldBuff(fieldname,recd,s,recout) + char *fieldname; /* nome del campo */ + RecDes *recd; /* descrittore record */ + char *s; /* stringa contenente il valore da scrivere nel campo */ + RecType recout; /* buffer contenente il record */ + +{ + int p, off, len, l, i; + char *s1; + /* + char *s2; + s2 = malloc(256); + */ + char s2[256]; + + strcpy(s2, s); + if ((p = findfld(recd, fieldname)) != -1) + { + off = recd->Fd[p].RecOff; + len = recd->Fd[p].Len; + if (recd->Fd[p].TypeF == RealF) setdec(s2, recd->Fd[p].Dec); + l = LENGTH(s2); + if (l > len) + { + /* free(s2); */ + return(-1); + } + s1 = recout + off ; + for (i = 0; i < l ; i++) s1[i] = s2[i] ; + if ((recd->Fd[p].TypeF == IntF) || + (recd->Fd[p].TypeF == Int4F) || + (recd->Fd[p].TypeF == WordF) || + (recd->Fd[p].TypeF == RealF) || + (recd->Fd[p].TypeF == ZeroF) || + (recd->Fd[p].TypeF == EZeroF)) + { + char c; + if ((recd->Fd[p].TypeF == ZeroF) || + (recd->Fd[p].TypeF == EZeroF)) + c = '0'; + else c = ' '; + if (l == 0) s1[l++] = '0'; + while (l < len) + { + for (i = l; i > 0; i--) s1[i] = s1[i - 1]; + s1[0] = c; + l++; + } + } + else + while (l < len) s1[l++] = ' '; + /* free(s2); */ + return(0); + } + else + { + strcpy(s, ""); + /* free(s2); */ + return(-1); + } +} + + +/* + @(#) CZeroField FILES + + @(ID) + Azzera un campo. + @(FD) + + @(ISV) + p = puntatore al campo. + + s = stringa messaggio. + @(FSV) + */ + +int CZeroField(fieldname,recd,recout) + char *fieldname; /* nonme del campo */ + RecDes *recd; /* descrittore record */ + RecType recout; /* buffer contenente il record */ + +{ + int p; + + if ((p = findfld(recd, fieldname)) != -1) + { + if (recd->Fd[p].TypeF == DateF) + memset(recout + recd->Fd[p].RecOff, '0', recd->Fd[p].Len); + else + { + memset(recout + recd->Fd[p].RecOff, Blank, recd->Fd[p].Len); + if ((recd->Fd[p].TypeF == IntF) || + (recd->Fd[p].TypeF == Int4F) || + (recd->Fd[p].TypeF == WordF)) + { + *(recout + recd->Fd[p].RecOff + recd->Fd[p].Len - 1) = '0'; + } + else + if (recd->Fd[p].TypeF == RealF) + { + if (recd->Fd[p].Dec) + { + memset(recout + recd->Fd[p].RecOff + recd->Fd[p].Len - + recd->Fd[p].Dec - 2, '0', recd->Fd[p].Dec + 2); + *(recout + recd->Fd[p].RecOff + recd->Fd[p].Len - + recd->Fd[p].Dec - 1) = '.'; + } + else *(recout + recd->Fd[p].RecOff + recd->Fd[p].Len - 1) = '0'; + } + return(NoErr); + } + } + else return(-1); + return(NoErr); +} + +/* + @(#) CZeroRec FILES + + @(ID) + Azzera tutto il record. + @(FD) + + @(ISV) + i = contatore. + + junk = variabile spazzatura per la chiamata di CZeroField. + @(FSV) + */ + +void CZeroRec(recd,recout) + RecDes *recd; /* descrittore record */ + RecType recout; /* buffer contenente il record */ + +{ + int i, junk; + + IRecallRec(recout) ; + for (i = 0; i < recd->NFields; i++) junk = CZeroField(recd->Fd[i].Name, + recd, recout); +} + + +/* + @($) prefname FILES + + @(ID) + Restituisce il nome del file che contiene il prefisso corrente. + @(FD) + + @(ISV) + s,s1 = stringhe di lavoro. + + Versione DOS e XENIX. + @(FSV) + */ + +#ifndef FOXPRO + +char *prefname() + +{ + static PathSt s; +#ifdef DOS + char *s1 = getenv("PREFPATH"); + if (s1 == NULL) s1 = "prefix.txt"; + strcpy(s, s1); +#else + sprintf(s, "prefix.%-d", getuid()); +#endif + return(s) ; +} + +#endif + +/* + @(#) CGetPref FILES + + @(ID) + Legge dal file prefisso il prefisso dati corrente. + @(FD) + + @(ISV) + f = puntatore al file. + @(FSV) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +char *CGetPref() + +{ + const char* p = prefname(); + FILE *f = fopen(p, "r"); + + if (f == NULL) + { + strcpy(cprefix, ""); + } + else + { + if (fgets(cprefix, 42, f) != NULL) + { + const int len = LENGTH(cprefix)-1; + if (len >= 0 && cprefix[len] <= ' ') cprefix[len] = '\0'; + } + else + *cprefix = '\0'; + fclose(f); + } + if (!pathpread) + { + const char* p = "pathpref.ini"; + FILE* f = fopen(p, "r"); + pathpread = TRUE; + if (f != NULL) + { + if (fgets(__ptprf, 42, f) != NULL) + { + const int len = LENGTH(__ptprf)-1; + if (len >= 0 && __ptprf[len] <= ' ') + { + __ptprf[len] = '\0'; + if (len > 0) strcat(__ptprf, "/"); + } + } + else + *__ptprf = '\0'; + fclose(f); + } + } + if (*__ptprf) + { + char ws[200]; + sprintf(ws, "%s%s", __ptprf, cprefix); + strcpy(cprefix, ws); + } + return(cprefix); +} + +/* + @($) CPutPref FILES + + @(ID) + Aggiorna sul file prefisso il prefisso dati corrente. + @(FD) + + @(ISV) + f = puntatore a file. + @(FSV) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +void CPutPref(pref) + char *pref; /* stringa contenente il nuovo prefisso */ + +{ + FILE *f; + const int l = strlen(__ptprf); + + if (l && strncmp(pref, __ptprf, l) == 0) pref += l; + if ((f = fopen(prefname(), "w")) == NULL) + fatal_box("Put prefix. Error number : %d ", errno); + fprintf(f, "%s\n", pref); + fclose(f); +} + +/* + @($) CAddPref FILES + + @(ID) + Cerca il carattere "$" nel nome file e lo sostituisce con il prefisso corrente. + @(FD) + + @(ISV) + s = stringa che contiene il nome. + @(FSV) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +char *CAddPref(name) + char *name; /* nome file */ + +{ + static PathSt s; + + if (*name == '$') + { + name++; + return(CInsPref(name, NORDIR)) ; + } + else + if (*name == '%') + { + name++; + return(CInsPref(name, COMDIR)) ; + } + else + { + sprintf(s, "%s%s", __ptprf, name); + return(s); + } +} + +/* + @($) CInsPref FILES + + @(ID) + Aggiunge (a sinistra) il prefisso corrente. + @(FD) + + @(ISV) + s = stringa di lavoro. + @(FSV) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + @(FN) + */ + +char *CInsPref(name,dirflg) + char *name; /* nome del file cui aggiungere il prefisso */ + int dirflg; /* flag per file comuni */ + +{ + static PathSt s; + + if (dirflg == NORDIR) + { + if (LENGTH(cprefix) == 0) sprintf(s,"%s", name); + else sprintf(s,"%s%c%s",cprefix, DIRSEP, name); + } + else sprintf(s,"%scom%c%s", __ptprf, DIRSEP, name); + return(s); +} + +/* + @(#) CGetIdxName FILES + + @(ID) + Dato un nome file costruisce il nome del file indice corrispondente. + @(FD) + + @(ISV) + fdst,s1,s2 = stringhe di lavoro. + @(FSV) + + @(IN) + NON UTILIZZARE !!. + + Se si utilizza spiegarne dettagliatamente il motivo. + + L' estensione dei file indice e' ndx; e' quindi vietato utilizzare un nome + di file che abbia tale estensione. L' estensione dei file dati e' dta. + @(FN) + */ + +char *CGetIdxName(s) + char *s; /* stringa contenente il nome file */ + +{ + static PathSt fdst; + char *s1, *s2; + + strcpy(fdst, s) ; + s1 = strrchr(fdst,DIRSEP) ; + if (s1 == NULL) s1 = fdst; + s2 = strchr(s1,'.') ; + if (s2 != NULL) s2[0] = '\0' ; + s1 = strcat(fdst, ".ndx") ; + return(fdst) ; +} diff --git a/include/cfiles.h b/include/cfiles.h new file mode 100755 index 000000000..86c1d22b4 --- /dev/null +++ b/include/cfiles.h @@ -0,0 +1,152 @@ +#ifndef __CFILES_H +#define __CFILES_H + +#ifndef __CCUSTIO_H +#include "ccustio.h" +#endif + +#define MaxFilesDir 70 +#define MKFields 10 +#define MaxFields 100 +#define MaxKeys 8 +#define glockname "xx" +#define INVFLD 255 +/* @(!) 2.3.01.144 */ +#define NORDIR 0 +#define COMDIR 1 +/* @(:) 2.3.01.144 */ + +typedef char FieldName[12] ; + +typedef struct +{ + char SysName[42] __PACKED__ ; + RecNoType EOD __PACKED__ ; + RecNoType EOX __PACKED__ ; + /* @(!) 2.3.01.temp */ +#ifdef M_I386 + unsigned short LenR __PACKED__ ; +#else + /* @(:) 2.3.01.temp */ + unsigned int LenR ; + /* @(!) 2.3.01.temp */ +#endif + /* @(:) 2.3.01.temp */ + RecNoType Flags __PACKED__ ; + char Des[42] __PACKED__ ; + char FCalc[32] __PACKED__ ; + char GenPrompt[32] __PACKED__ ; +} FileDes; + +typedef struct +{ + FieldName Name __PACKED__ ; + byte TypeF __PACKED__ ; + byte Len __PACKED__ ; + byte Dec __PACKED__ ; +#ifdef __PACK_1__ + byte junk __PACKED__ ; +#endif + /* @(!) 2.3.01.temp */ +#ifdef M_I386 + unsigned short RecOff __PACKED__ ; +#else + /* @(:) 2.3.01.temp */ + unsigned int RecOff ; + /* @(!) 2.3.01.temp */ +#endif + /* @(:) 2.3.01.temp */ +} RecFieldDes ; + +#if XVT_OS == XVT_OS_DOS || XVT_OS == XVT_OS_WIN +#pragma pack(2) +#endif + +typedef struct +{ + BOOLEAN DupKeys __ALIGNED__ ; + byte NkFields __ALIGNED__ ; + byte FieldSeq[MKFields] __PACKED__ ; + byte FromCh[MKFields] __PACKED__ ; + byte ToCh[MKFields] __PACKED__ ; +} KeyDes ; + +typedef struct +{ + /* @(!) 2.3.01.temp */ +#ifdef M_I386 + short NFields __PACKED__ ; +#else + /* @(:) 2.3.01.temp */ + int NFields ; + /* @(!) 2.3.01.temp */ +#endif + /* @(:) 2.3.01.temp */ + RecFieldDes Fd[MaxFields] __PACKED__ ; + byte SortFd[MaxFields] __PACKED__ ; + /* @(!) 2.3.01.temp */ +#ifdef M_I386 + short NKeys __PACKED__ ; +#else + /* @(:) 2.3.01.temp */ + int NKeys ; + /* @(!) 2.3.01.temp */ +#endif + /* @(:) 2.3.01.temp */ + KeyDes Ky[MaxKeys] __PACKED__ ; +} RecDes; +#ifdef __CFILES_C +SecDef rdir[2], fdir[2]; +#else +extern SecDef rdir[2], fdir[2]; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + /* @(!) 2.3.01.144 */ + void COpenDir(int, int); + void CCloseDir(int); + void COpenFile(int, FileDes *, int, int); + void CCloseFile(int, FileDes *, int); + void CGetFile(int, FileDes *, int, int); + void CPutFile(int, FileDes *, int); + /* @(:) 2.3.01.144 */ + void zerofdes(FileDes *); + /* @(!) 2.3.01.144 */ + void COpenRecDir(int, int); + void CCloseRecDir(int); + void CGetRec(int, RecDes *, int); + void CPutRec(int, RecDes *, int); + /* @(:) 2.3.01.144 */ + void zerordes(RecDes *); + word setrdes(RecDes *); + int findfld(RecDes *,char *); + unsigned int CFieldSize(char *, RecDes *); + unsigned int CFieldDec(char *, RecDes *); + int CFieldType(char *, RecDes *); + int CGetField(char *, RecDes *, RecType, void *); + int CPutField(char *, RecDes *, void *, RecType); + int CGetFieldBuff(char *, RecDes *, RecType, char *); + int CPutFieldBuff(char *, RecDes *, char *, RecType); + int CZeroField(char *, RecDes *, RecType); + void CZeroRec(RecDes *, RecType); + int CBuildKey(RecDes *,int ,RecType, char *); + int CCalcLenKey(RecDes *,int); + char *CGetPref(void); + void CPutPref(char *); + char *CAddPref(char *); + /* @(!) 2.3.01.144 */ + char *CInsPref(char *, int); + /* @(:) 2.3.01.144 */ + char *CGetIdxName(char *); + /* @(!) 2.3.01.155 */ + char **getlinesdf(char *, int *); + void loadrfd(RecDes *, RecType, char **, char **); + void dumprfd(RecDes *, RecType, char **, int *, int *, int *, char *); + /* @(:) 2.3.01.155 */ + +#ifdef __cplusplus +}; +#endif +#endif /* __CFILES_H */ diff --git a/include/csort.c b/include/csort.c index a4b8938e4..838fe21f9 100755 --- a/include/csort.c +++ b/include/csort.c @@ -1,30 +1,10 @@ -/* -@(SH) Funzioni per l'esecuzione di sort -@(VG$) PRIVATE -datisort : copia struttura del sort attivo -nsortfield : Numero campi definiti dal sort -sp : struttura dei parametri sort -totrcd : numero totale di record ordinati -no_seq : contatore sequenze -no_seq1 : contatore sequenze -bspace : spazio disponibile nel buffer -nrcds : numero di records nel buffer di sort -nrcds1 : numero di records nel buffer di sort -bf, bf1 : puntatori al buffer di sort -inbf : records variabili nel buffer di sort -sptr : puntatore al vettore dei puntatori ai buffer -init_sptr : puntatore al buffer appropriato -rcds_seq : sequenza record nel buffer di merge -fp1, fp2 : puntatori a file di lavoro per il sort -fdname : nome di lavoro del sort -f2name : nome di lavoro del sort -------------------------------------------------------------------------------- - @(H) 2.3.00.112 23/11/91 Bonazzi Corretta fine sort - @(H) 2.3.01.245 08/03/94 Soragna Corretto sort_op per 386 -*/ - #include "csort.h" +#ifdef __WATCOMC__ +#include +#include +#else #include +#endif /*----------------------- STATIC PER PRIMA PARTE ----------------------------*/ @@ -72,183 +52,183 @@ void dummy(void); /*----------------------- PRIMA PARTE ---------------------------------------*/ /* -@(#) init_sort SORT + @(#) init_sort SORT -@(ID) -Inizializza le variabili globali per il sort. -@(FD) -*/ + @(ID) + Inizializza le variabili globali per il sort. + @(FD) + */ int init_sort(prms) -struct s_prm *prms; /* struttura di descrizione del sort */ + struct s_prm *prms; /* struttura di descrizione del sort */ { - sp = prms; - if ((bf = appr_mem(&bspace)) != NULL) { - nrcds1 = nrcds = bspace / (sp->rc_len + sizeof(char *)); - init_sptr = bf; - sptr = (char **) bf; - bf += nrcds * sizeof(char *); - fp1 = fp2 = NULL; - totrcd = no_seq = inbf = 0; - return 0; - } - else - return -1; + sp = prms; + if ((bf = appr_mem(&bspace)) != NULL) { + nrcds1 = nrcds = bspace / (sp->rc_len + sizeof(char *)); + init_sptr = bf; + sptr = (char **) bf; + bf += nrcds * sizeof(char *); + fp1 = fp2 = NULL; + totrcd = no_seq = inbf = 0; + return 0; + } + else + return -1; } /* -@(#) sort SORT + @(#) sort SORT -@(ID) -Funzione per l'input dei record da ordinare. -@(FD) + @(ID) + Funzione per l'input dei record da ordinare. + @(FD) -@(IN) -La chiamata sort(char *) NULL) chiude la fase di input dei record. -@(FN) -*/ + @(IN) + La chiamata sort(char *) NULL) chiude la fase di input dei record. + @(FN) + */ void sort(s_rcd) -char *s_rcd; /* buffer contenente il record da ordinare */ + char *s_rcd; /* buffer contenente il record da ordinare */ { -/* @(!) 2.3.00.112 */ - if (inbf == nrcds) { /* if the sort buffer is full */ -/* @(:) 2.3.00.112 */ - qsort(init_sptr, inbf, sizeof (char *), sortcomp); - if (s_rcd) { /* if there are more records to sort */ - dumpbuff(); /* dump the buffer to a sort work file*/ - no_seq++; /* count the sorted sequences */ - } - } - if (s_rcd !=NULL) { - /* --- this is a record to sort --- */ - totrcd++; - /* --- put the rcd addr in the pointer array --- */ - *sptr = bf + inbf * sp->rc_len; - inbf++; - /* --- move the rcd to the buffer --- */ - memcpy(*sptr, s_rcd, sp->rc_len); - sptr++; /* point to next array entry*/ - } - else { /* null pointer means no more rcds */ - if (inbf) { /* any records in the buffer? */ - qsort(init_sptr, inbf, sizeof (char *), sortcomp); - if (no_seq) /* if this isn't the only sequence*/ - dumpbuff(); /* dump the buffer to a work file */ - no_seq++; /* count the sequence */ - } - no_seq1 = no_seq; - if (no_seq > 1) /* if there is more than 1 sequence */ - prep_merge(); /* prepare for the merge */ - } + /* @(!) 2.3.00.112 */ + if (inbf == nrcds) { /* if the sort buffer is full */ + /* @(:) 2.3.00.112 */ + qsort(init_sptr, inbf, sizeof (char *), sortcomp); + if (s_rcd) { /* if there are more records to sort */ + dumpbuff(); /* dump the buffer to a sort work file*/ + no_seq++; /* count the sorted sequences */ + } + } + if (s_rcd !=NULL) { + /* --- this is a record to sort --- */ + totrcd++; + /* --- put the rcd addr in the pointer array --- */ + *sptr = bf + inbf * sp->rc_len; + inbf++; + /* --- move the rcd to the buffer --- */ + memcpy(*sptr, s_rcd, sp->rc_len); + sptr++; /* point to next array entry*/ + } + else { /* null pointer means no more rcds */ + if (inbf) { /* any records in the buffer? */ + qsort(init_sptr, inbf, sizeof (char *), sortcomp); + if (no_seq) /* if this isn't the only sequence*/ + dumpbuff(); /* dump the buffer to a work file */ + no_seq++; /* count the sequence */ + } + no_seq1 = no_seq; + if (no_seq > 1) /* if there is more than 1 sequence */ + prep_merge(); /* prepare for the merge */ + } } /* -@($) prep_merge SORT + @($) prep_merge SORT -@(ID) -Funzione per la preparazione del Merge. -@(FD) + @(ID) + Funzione per la preparazione del Merge. + @(FD) -@(ISV) -i = contatore. + @(ISV) + i = contatore. -rr = puntatore ad una struttura di sequenza (di lavoro). + rr = puntatore ad una struttura di sequenza (di lavoro). -n_bfsz = ampiezza in byte del merge buffer. + n_bfsz = ampiezza in byte del merge buffer. -@(FSV) -*/ + @(FSV) + */ static void prep_merge() { -int i; -struct bp *rr; -unsigned n_bfsz; + int i; + struct bp *rr; + unsigned n_bfsz; -memset(init_sptr, '\0', bspace); - /* -------- merge buffer size ------ */ -n_bfsz = bspace - no_seq * sizeof(struct bp); -/* ------ # rcds/seq in merge buffer ------- */ -rcds_seq = n_bfsz / no_seq / sp->rc_len; -if (rcds_seq < 2) { - /* ---- more sequence blocks than will fit in buffer, - merge down ---- */ - while (rcds_seq < 2) { - FILE *hd; -/* @(!) 2.3.00.112 */ - char wname[42]; /* sort work name */ + memset(init_sptr, '\0', bspace); + /* -------- merge buffer size ------ */ + n_bfsz = bspace - no_seq * sizeof(struct bp); + /* ------ # rcds/seq in merge buffer ------- */ + rcds_seq = n_bfsz / no_seq / sp->rc_len; + if (rcds_seq < 2) { + /* ---- more sequence blocks than will fit in buffer, + merge down ---- */ + while (rcds_seq < 2) { + FILE *hd; + /* @(!) 2.3.00.112 */ + char wname[42]; /* sort work name */ - fp2 = wopen(f2name); /* open a sort work file */ -/* @(:) 2.3.00.112 */ - merge(); /* binary merge */ - hd = fp1; /* swap fds */ - fp1 = fp2; - fp2 = hd; -/* @(!) 2.3.00.112 */ - strcpy(wname, fdname); - strcpy(fdname, f2name); - strcpy(f2name, wname); - fclose(fp2); - unlink(f2name); - fp2 = NULL; -/* @(:) 2.3.00.112 */ - nrcds *= 2; - /* ------ adjust number of sequence ------ */ - no_seq = (no_seq + 1) / 2; - n_bfsz = bspace - no_seq * sizeof(struct bp); - rcds_seq = n_bfsz / no_seq / sp->rc_len; - } -} -bf1 = init_sptr; -rr = (struct bp *) init_sptr; -bf1 += no_seq * sizeof(struct bp); -bf = bf1; + fp2 = wopen(f2name); /* open a sort work file */ + /* @(:) 2.3.00.112 */ + merge(); /* binary merge */ + hd = fp1; /* swap fds */ + fp1 = fp2; + fp2 = hd; + /* @(!) 2.3.00.112 */ + strcpy(wname, fdname); + strcpy(fdname, f2name); + strcpy(f2name, wname); + fclose(fp2); + unlink(f2name); + fp2 = NULL; + /* @(:) 2.3.00.112 */ + nrcds *= 2; + /* ------ adjust number of sequence ------ */ + no_seq = (no_seq + 1) / 2; + n_bfsz = bspace - no_seq * sizeof(struct bp); + rcds_seq = n_bfsz / no_seq / sp->rc_len; + } + } + bf1 = init_sptr; + rr = (struct bp *) init_sptr; + bf1 += no_seq * sizeof(struct bp); + bf = bf1; -/* fill the merge buffer with records from all sequences */ + /* fill the merge buffer with records from all sequences */ -for (i = 0; i < no_seq; i++) { - fseek(fp1, (long) i * ((long) nrcds * sp->rc_len), 0); - /* ------ read them all at once ------ */ -/* @(!) 2.3.00.112 modificata fread(bf1, rcds_seq * sp->rc_len, 1, fp1); */ - fread(bf1, sp->rc_len, rcds_seq, fp1); -/* @(:) 2.3.00.112 */ - rr->rc = bf1; - /* --- the last seq has fewer rcds than the rest --- */ - if (i == no_seq-1) { - if (totrcd % nrcds > rcds_seq) { - rr->rbuf = rcds_seq; -/* @(!) 2.3.00.112 */ - rr->rdsk = (unsigned) (totrcd % nrcds) - rcds_seq; -/* @(:) 2.3.00.112 */ - } - else { -/* @(!) 2.3.00.112 */ - rr->rbuf = (unsigned) (totrcd % nrcds); -/* @(:) 2.3.00.112 */ - rr->rdsk = 0; - } - } - else { - rr->rbuf = rcds_seq; - rr->rdsk = nrcds - rcds_seq; - } - rr++; - bf1 += rcds_seq * sp->rc_len; -} + for (i = 0; i < no_seq; i++) { + fseek(fp1, (long) i * ((long) nrcds * sp->rc_len), 0); + /* ------ read them all at once ------ */ + /* @(!) 2.3.00.112 modificata fread(bf1, rcds_seq * sp->rc_len, 1, fp1); */ + fread(bf1, sp->rc_len, rcds_seq, fp1); + /* @(:) 2.3.00.112 */ + rr->rc = bf1; + /* --- the last seq has fewer rcds than the rest --- */ + if (i == no_seq-1) { + if (totrcd % nrcds > rcds_seq) { + rr->rbuf = rcds_seq; + /* @(!) 2.3.00.112 */ + rr->rdsk = (unsigned) (totrcd % nrcds) - rcds_seq; + /* @(:) 2.3.00.112 */ + } + else { + /* @(!) 2.3.00.112 */ + rr->rbuf = (unsigned) (totrcd % nrcds); + /* @(:) 2.3.00.112 */ + rr->rdsk = 0; + } + } + else { + rr->rbuf = rcds_seq; + rr->rdsk = nrcds - rcds_seq; + } + rr++; + bf1 += rcds_seq * sp->rc_len; + } } /* @(!) 2.3.01.245 */ /* Funzione che non fa assolutamente nulla, ma e' estremamente - utile all'interno di sort_op, quando si supera una certa mole di - dati immessi nel buffer di sort; e' necessaria solo per la - compilazione di eseguibili per 386. Questa funzione inserita tra - le righe rtn= k+..... e memcpy(..) evita il fastidioso memory - fault che si ottiene utilizzando strutture molto ampie o molto - numerose. Probabilmente evita, in fase di compilazione, che vengano - creati indirizzi strani, oppure in fase di esecuzione, che vengano - reperite zone di memoria che non c'entrano per nulla. -*/ + utile all'interno di sort_op, quando si supera una certa mole di + dati immessi nel buffer di sort; e' necessaria solo per la + compilazione di eseguibili per 386. Questa funzione inserita tra + le righe rtn= k+..... e memcpy(..) evita il fastidioso memory + fault che si ottiene utilizzando strutture molto ampie o molto + numerose. Probabilmente evita, in fase di compilazione, che vengano + creati indirizzi strani, oppure in fase di esecuzione, che vengano + reperite zone di memoria che non c'entrano per nulla. + */ void dummy() { } @@ -256,498 +236,440 @@ void dummy() /* -@($) merge SORT + @($) merge SORT -@(ID) -Effettua un merge. -E' un merge binario di records dalla sequenza fp1 in fp2. -@(FD + @(ID) + Effettua un merge. + E' un merge binario di records dalla sequenza fp1 in fp2. + @(FD -@(ISV) -i = contatore. + @(ISV) + i = contatore. -needy,needx = se true necessita un record da (x/y). + needy,needx = se true necessita un record da (x/y). -xcnt,ycnt = numero di records lasciati in ogni sequenza. + xcnt,ycnt = numero di records lasciati in ogni sequenza. -x,y = contatori per le sequenze. + x,y = contatori per le sequenze. -adx,ady = indirizzi sul disco delle sequenze di record. + adx,ady = indirizzi sul disco delle sequenze di record. -ysptr = stringa di lavoro. -@(FSV) -*/ + ysptr = stringa di lavoro. + @(FSV) + */ static void merge() { - int i; - int needy, needx; /* true = need a rcd from (x/y) */ -/* @(!) 2.3.00.112 */ - unsigned xcnt, ycnt; /* # rcds left each sequence */ -/* @(:) 2.3.00.112 */ - int x, y; /* sequence counters */ - long adx, ady; /* sequence record disk addresses */ -/* @(!) 2.3.00.112 */ - char *ysptr = init_sptr + sp->rc_len; -/* @(:) 2.3.00.112 */ + int i; + int needy, needx; /* true = need a rcd from (x/y) */ + /* @(!) 2.3.00.112 */ + unsigned xcnt, ycnt; /* # rcds left each sequence */ + /* @(:) 2.3.00.112 */ + int x, y; /* sequence counters */ + long adx, ady; /* sequence record disk addresses */ + /* @(!) 2.3.00.112 */ + char *ysptr = init_sptr + sp->rc_len; + /* @(:) 2.3.00.112 */ - /* --- the two sets of sequences are x and y ----- */ - fseek (fp2, 0L, 0); - for (i = 0; i < no_seq; i += 2) { - x = y = i; - y++; - ycnt = - y == no_seq ? 0 : y == no_seq - 1 ? -/* @(!) 2.3.00.112 */ - (unsigned) (totrcd % nrcds) : nrcds; - xcnt = y == no_seq ? (unsigned) (totrcd % nrcds) : nrcds; -/* @(:) 2.3.00.112 */ - adx = (long) x * (long) nrcds * sp->rc_len; - ady = adx + (long) nrcds * sp ->rc_len; - needy = needx = 1; - while (xcnt || ycnt) { - if (needx && xcnt) { /* need a rcd from x? */ - fseek(fp1, adx, 0); - adx += (long) sp->rc_len; - fread(init_sptr, sp->rc_len, 1, fp1); - needx = 0; - } - if (needy && ycnt) { /* need a rcd from y? */ - fseek(fp1, ady, 0); - ady += sp->rc_len; -/* @(!) 2.3.00.112 modificata fread(init_sptr+sp->rc_len, sp->rc_len, 1, fp1); */ - fread(ysptr, sp->rc_len, 1, fp1); -/* @(:) 2.3.00.112 */ - needy = 0; - } - if (xcnt || ycnt) { /* if anything is left */ - /* ---- compare the two sequences --- */ -/* @(!) 2.3.00.112 modificata if (!ycnt || (xcnt && (sortcomp(&init_sptr, &init_sptr + sp->rc_len)) < 0)) { */ - if (!ycnt || (xcnt && (sortcomp(&init_sptr, &ysptr)) < 0)) { -/* @(:) 2.3.00.112 */ - /* ----- record from x is lower ---- */ - fwrite(init_sptr, sp->rc_len, 1, fp2); - --xcnt; - needx = 1; - } - else if (ycnt) { /* record from y is lower */ -/* @(!) 2.3.00.112 */ - fwrite(ysptr, sp->rc_len, 1, fp2); -/* @(:) 2.3.00.112 */ - --ycnt; - needy = 1; - } - } - } - } + /* --- the two sets of sequences are x and y ----- */ + fseek (fp2, 0L, 0); + for (i = 0; i < no_seq; i += 2) { + x = y = i; + y++; + ycnt = + y == no_seq ? 0 : y == no_seq - 1 ? + /* @(!) 2.3.00.112 */ + (unsigned) (totrcd % nrcds) : nrcds; + xcnt = y == no_seq ? (unsigned) (totrcd % nrcds) : nrcds; + /* @(:) 2.3.00.112 */ + adx = (long) x * (long) nrcds * sp->rc_len; + ady = adx + (long) nrcds * sp ->rc_len; + needy = needx = 1; + while (xcnt || ycnt) { + if (needx && xcnt) { /* need a rcd from x? */ + fseek(fp1, adx, 0); + adx += (long) sp->rc_len; + fread(init_sptr, sp->rc_len, 1, fp1); + needx = 0; + } + if (needy && ycnt) { /* need a rcd from y? */ + fseek(fp1, ady, 0); + ady += sp->rc_len; + /* @(!) 2.3.00.112 modificata fread(init_sptr+sp->rc_len, sp->rc_len, 1, fp1); */ + fread(ysptr, sp->rc_len, 1, fp1); + /* @(:) 2.3.00.112 */ + needy = 0; + } + if (xcnt || ycnt) { /* if anything is left */ + /* ---- compare the two sequences --- */ + /* @(!) 2.3.00.112 modificata if (!ycnt || (xcnt && (sortcomp(&init_sptr, &init_sptr + sp->rc_len)) < 0)) { */ + if (!ycnt || (xcnt && (sortcomp(&init_sptr, &ysptr)) < 0)) { + /* @(:) 2.3.00.112 */ + /* ----- record from x is lower ---- */ + fwrite(init_sptr, sp->rc_len, 1, fp2); + --xcnt; + needx = 1; + } + else if (ycnt) { /* record from y is lower */ + /* @(!) 2.3.00.112 */ + fwrite(ysptr, sp->rc_len, 1, fp2); + /* @(:) 2.3.00.112 */ + --ycnt; + needy = 1; + } + } + } + } } /* -@($) dumpbuff SORT + @($) dumpbuff SORT -@(ID) -Copia il buffer di sort nel file di lavoro. -@(FD) + @(ID) + Copia il buffer di sort nel file di lavoro. + @(FD) -@(ISV) -i = contatore. -@(FSV) -*/ + @(ISV) + i = contatore. + @(FSV) + */ static void dumpbuff() { -/* @(!) 2.3.00.112 */ - unsigned i; -/* @(:) 2.3.00.112 */ + /* @(!) 2.3.00.112 */ + unsigned i; + /* @(:) 2.3.00.112 */ - if (fp1 == NULL) -/* @(!) 2.3.00.112 */ - fp1 = wopen(fdname); -/* @(:) 2.3.00.112 */ - sptr = (char **) init_sptr; - for (i = 0; i < inbf; i++) { - fwrite(*(sptr + i), sp->rc_len, 1, fp1); -/* @(!) 2.3.00.112 */ - *(sptr + i) = 0; -/* @(:) 2.3.00.112 */ -} -inbf = 0; + if (fp1 == NULL) + /* @(!) 2.3.00.112 */ + fp1 = wopen(fdname); + /* @(:) 2.3.00.112 */ + sptr = (char **) init_sptr; + for (i = 0; i < inbf; i++) { + fwrite(*(sptr + i), sp->rc_len, 1, fp1); + /* @(!) 2.3.00.112 */ + *(sptr + i) = 0; + /* @(:) 2.3.00.112 */ + } + inbf = 0; } /* -@($) wopen SORT + @($) wopen SORT -@(ID) -Apre un file di lavoro temporaneo (per il sort). -@(FD) + @(ID) + Apre un file di lavoro temporaneo (per il sort). + @(FD) -@(ISV) -fp = puntatore al file temporaneo. + @(ISV) + fp = puntatore al file temporaneo. -s = stringa di formato. + s = stringa di formato. -n = numero del file. + n = numero del file. -@(FSV) -*/ + @(FSV) + */ /* @(!) 2.3.00.112 */ static FILE *wopen(name) -char *name; /* nome del file temporaneo */ -/* @(:) 2.3.00.112 */ + char *name; /* nome del file temporaneo */ + /* @(:) 2.3.00.112 */ { - FILE *fp; - char s[42]; -/* @(!) 2.3.00.112 */ - static int n = 0; -/* @(:) 2.3.00.112 */ + FILE *fp; + char s[42]; + /* @(!) 2.3.00.112 */ + static int n = 0; + /* @(:) 2.3.00.112 */ - sprintf(s, "srt%03d", ++n); - TMPFNAME(name,s); + /* @(!) 2.3.00.316 */ + sprintf(s, "srt%02d", ++n); + /* @(:) 2.3.00.316 */ + TMPFNAME(name,s); #ifdef DOS - if ((fp = fopen(name, "wb+")) == NULL) { + if ((fp = fopen(name, "wb+")) == NULL) { #else - if ((fp = fopen(name, "w+")) == NULL) { + if ((fp = fopen(name, "w+")) == NULL) { #endif #ifndef XVT_OS - printf("\nFile error"); - exit(1); + printf("\nFile error"); + exit(1); #else - fatal_box("Can't open SORT file"); + fatal_box("Can't open SORT file"); #endif - } - return fp; -} + } + return fp; + } -/* -@(#) sort_op SORT + /* + @(#) sort_op SORT -@(ID) -Ritorna il puntatore al primo record non ancora elaborato nella sequenza ordinata. -@(FD) + @(ID) + Ritorna il puntatore al primo record non ancora elaborato nella sequenza ordinata. + @(FD) -@(ISV) -j = e' true se una qualche sequenza contiene ancora dei records. + @(ISV) + j = e' true se una qualche sequenza contiene ancora dei records. -i = contatore. + i = contatore. -k,nrd,l = variabili di lavoro. + k,nrd,l = variabili di lavoro. -rr = variabile di lavoro. + rr = variabile di lavoro. -r1 = variabile di lavoro. + r1 = variabile di lavoro. -rtn = indirizzo del buffer da ritornare. + rtn = indirizzo del buffer da ritornare. -ad,tr = variabili di lavoro. -@(FSV) + ad,tr = variabili di lavoro. + @(FSV) -@(FN) - Se la funzione sort_op ritorna NULL non ci sono piu' records nella sequenza ordinata. -@(FN) -*/ + @(FN) + Se la funzione sort_op ritorna NULL non ci sono piu' records nella sequenza ordinata. + @(FN) + */ -char *sort_op() -{ - int j = 0; -/* @(!) 2.3.00.112 */ - unsigned i, k, nrd, l; -/* @(:) 2.3.00.112 */ - struct bp *rr; -/* @(!) 2.3.00.112 */ - static unsigned r1 = 0; -/* @(:) 2.3.00.112 */ - char *rtn; - long ad, tr; + char *sort_op() + { + int j = 0; + /* @(!) 2.3.00.112 */ + unsigned i, k, nrd, l; + /* @(:) 2.3.00.112 */ + struct bp *rr; + /* @(!) 2.3.00.112 */ + static unsigned r1 = 0; + /* @(:) 2.3.00.112 */ + char *rtn; + long ad, tr; - if (init_sptr == NULL) return NULL; + if (init_sptr == NULL) return NULL; - sptr = (char **) init_sptr; - if (no_seq < 2) { - /* -- with only 1 sequence, mo merge has been done -- */ -/* @(!) 2.3.00.112 */ - if (r1 == (unsigned) totrcd) { -/* @(:) 2.3.00.112 */ - if (init_sptr != NULL) free(init_sptr); -/* @(!) 2.3.00.112 */ - init_sptr = NULL; -/* @(:) 2.3.00.112 */ - fp1 = fp2 = NULL; - r1 = 0; - return NULL; - } - return *(sptr + r1++); - } + sptr = (char **) init_sptr; + if (no_seq < 2) { + /* -- with only 1 sequence, mo merge has been done -- */ + /* @(!) 2.3.00.112 */ + if (r1 == (unsigned) totrcd) { + /* @(:) 2.3.00.112 */ + if (init_sptr != NULL) free(init_sptr); + /* @(!) 2.3.00.112 */ + init_sptr = NULL; + /* @(:) 2.3.00.112 */ + fp1 = fp2 = NULL; + r1 = 0; + return NULL; + } + return *(sptr + r1++); + } - rr = (struct bp *) init_sptr; - for (i = 0; i < no_seq; i++) -/* @(!) 2.3.00.112 */ - j |= (int) (rr + i)->rbuf | (rr + i)->rdsk; -/* @(:) 2.3.00.112 */ + rr = (struct bp *) init_sptr; + for (i = 0; i < no_seq; i++) + /* @(!) 2.3.00.112 */ + j |= (int) (rr + i)->rbuf | (rr + i)->rdsk; + /* @(:) 2.3.00.112 */ - /* -- j will be true if any sequence still has records - */ - if (!j) - { - fclose(fp1); /* none left */ - unlink(fdname); -/* @(!) 2.3.00.112 eliminata if (fp2) */ -/* @(!) 2.3.00.112 eliminata { */ -/* @(!) 2.3.00.112 eliminata fclose(fp2); */ -/* @(!) 2.3.00.112 eliminata unlink(f2name); */ -/* @(!) 2.3.00.112 eliminata } */ -/* @(:) 2.3.00.112 */ - if (init_sptr != NULL) free(init_sptr); -/* @(!) 2.3.00.112 */ - init_sptr = NULL; -/* @(:) 2.3.00.112 */ - fp1 = fp2 = NULL; - r1 = 0; - return NULL; - } - k = 0; + /* -- j will be true if any sequence still has records - */ + if (!j) + { + fclose(fp1); /* none left */ + unlink(fdname); + /* @(!) 2.3.00.112 eliminata if (fp2) */ + /* @(!) 2.3.00.112 eliminata { */ + /* @(!) 2.3.00.112 eliminata fclose(fp2); */ + /* @(!) 2.3.00.112 eliminata unlink(f2name); */ + /* @(!) 2.3.00.112 eliminata } */ + /* @(:) 2.3.00.112 */ + if (init_sptr != NULL) free(init_sptr); + /* @(!) 2.3.00.112 */ + init_sptr = NULL; + /* @(:) 2.3.00.112 */ + fp1 = fp2 = NULL; + r1 = 0; + return NULL; + } + k = 0; - /* --- find the sequence in the merge buffer - with the lowest record --- */ - for (i = 0; i < no_seq; i++) - k = ((sortcomp( &(rr + k)->rc, &(rr + i)->rc) < 0) ? k : i); + /* --- find the sequence in the merge buffer + with the lowest record --- */ + for (i = 0; i < no_seq; i++) + k = ((sortcomp( &(rr + k)->rc, &(rr + i)->rc) < 0) ? k : i); - /* --- k is an integer sequence number that offsets to the - sequence with the lowest record ---- */ + /* --- k is an integer sequence number that offsets to the + sequence with the lowest record ---- */ - (rr + k)->rbuf--; /* decrement the rcd counter */ - rtn = (rr + k)->rc; /* set the return pointer */ - (rr + k)->rc += sp->rc_len; - if ((rr + k)->rbuf == 0) { - /* ---- the sequence got empty ---- */ - /* --- so get some more if there are any --- */ - rtn = bf + k * rcds_seq * sp->rc_len; -/* @(!) 2.3.01.245 */ - dummy(); -/* @(:) 2.3.01.245 */ - memcpy(rtn, (rr + k)->rc - sp->rc_len, sp->rc_len); - (rr + k)->rc = rtn + sp->rc_len; - if ((rr + k)->rdsk != 0) { - l = ((rcds_seq-1) < (rr+k)->rdsk) ? rcds_seq-1 : (rr+k)->rdsk; -/* @(!) 2.3.00.112 */ - nrd = k == no_seq - 1 ? (unsigned) (totrcd % nrcds) : nrcds; -/* @(:) 2.3.00.112 */ - tr = (long) ((k * nrcds + (nrd - (rr + k)->rdsk))); - ad = tr * sp->rc_len; - fseek(fp1, ad, 0); -/* @(!) 2.3.00.112 modificata fread(rtn + sp->rc_len, l * sp->rc_len, 1, fp1); */ - fread(rtn + sp->rc_len, sp->rc_len, l, fp1); -/* @(:) 2.3.00.112 */ - (rr + k)->rbuf = l; - (rr + k)->rdsk -= l; - } - else - memset((rr + k)->rc, 127, sp->rc_len); - } - return rtn; -} + (rr + k)->rbuf--; /* decrement the rcd counter */ + rtn = (rr + k)->rc; /* set the return pointer */ + (rr + k)->rc += sp->rc_len; + if ((rr + k)->rbuf == 0) { + /* ---- the sequence got empty ---- */ + /* --- so get some more if there are any --- */ + rtn = bf + k * rcds_seq * sp->rc_len; + /* @(!) 2.3.01.245 */ + dummy(); + /* @(:) 2.3.01.245 */ + memcpy(rtn, (rr + k)->rc - sp->rc_len, sp->rc_len); + (rr + k)->rc = rtn + sp->rc_len; + if ((rr + k)->rdsk != 0) { + l = ((rcds_seq-1) < (rr+k)->rdsk) ? rcds_seq-1 : (rr+k)->rdsk; + /* @(!) 2.3.00.112 */ + nrd = k == no_seq - 1 ? (unsigned) (totrcd % nrcds) : nrcds; + /* @(:) 2.3.00.112 */ + tr = (long) ((k * nrcds + (nrd - (rr + k)->rdsk))); + ad = tr * sp->rc_len; + fseek(fp1, ad, 0); + /* @(!) 2.3.00.112 modificata fread(rtn + sp->rc_len, l * sp->rc_len, 1, fp1); */ + fread(rtn + sp->rc_len, sp->rc_len, l, fp1); + /* @(:) 2.3.00.112 */ + (rr + k)->rbuf = l; + (rr + k)->rdsk -= l; + } + else + memset((rr + k)->rc, 127, sp->rc_len); + } + return rtn; + } -/* -@(#) sort_stats SORT + /* + @(#) sort_stats SORT -@(ID) -Visualizza la statistica sul sort. -@(FD) -*/ + @(ID) + Visualizza la statistica sul sort. + @(FD) + */ -void sort_stats() -{ + void sort_stats() + { #ifndef XVT_OS - printf("\n\r\n\r\n\rRecord Length = %d",sp->rc_len); -/* @(!) 2.3.00.112 */ - printf("\n\r%u records sorted",totrcd); - printf("\n\r%u sequence",no_seq); -/* @(:) 2.3.00.112 */ - if (no_seq1 != 1) putchar('s'); - printf("\n\r%u characters of sort buffer", bspace); -/* @(!) 2.3.00.112 */ - printf("\n\r%u records per buffer\n\n",nrcds); -/* @(:) 2.3.00.112 */ + printf("\n\r\n\r\n\rRecord Length = %d",sp->rc_len); + /* @(!) 2.3.00.112 */ + printf("\n\r%u records sorted",totrcd); + printf("\n\r%u sequence",no_seq); + /* @(:) 2.3.00.112 */ + if (no_seq1 != 1) putchar('s'); + printf("\n\r%u characters of sort buffer", bspace); + /* @(!) 2.3.00.112 */ + printf("\n\r%u records per buffer\n\n",nrcds); + /* @(:) 2.3.00.112 */ #else - message_box( - "Record length = %d\n" - "%u records sorted\n" - "%u sequences\n" - "%u bytes of sort buffer\n" - "%u records per buffer", - sp->rc_len, totrcd, no_seq, bspace, nrcds - ); + message_box( + "Record length = %d\n" + "%u records sorted\n" + "%u sequences\n" + "%u bytes of sort buffer\n" + "%u records per buffer", + sp->rc_len, totrcd, no_seq, bspace, nrcds + ); #endif -} + } -/* -@($) appr_mem SORT + /* + @($) appr_mem SORT -@(ID) -Alloca memoria per un buffer. -@(FD) + @(ID) + Alloca memoria per un buffer. + @(FD) -@(ISV) -buff = buffer di memoria allocato. -@(FSV) + @(ISV) + buff = buffer di memoria allocato. + @(FSV) -@(IN) -Se puo' alloca MOSTMEM altrimenti ne alloca quanto puo', -non scendendo mai sotto il minimo LEASTMEM -@(FN) -*/ + @(IN) + Se puo' alloca MOSTMEM altrimenti ne alloca quanto puo', + non scendendo mai sotto il minimo LEASTMEM + @(FN) + */ -static char *appr_mem(h) -unsigned *h; /* puntatore alla quantita' di byte allocati */ + static char *appr_mem(h) + unsigned *h; /* puntatore alla quantita' di byte allocati */ { - char *buff = NULL; + char *buff = NULL; - *h = (unsigned) MOSTMEM + 1024; - while (buff == NULL && *h > LEASTMEM) { - *h -= 1024; - buff = malloc(*h); - } - return buff; + *h = (unsigned) MOSTMEM + 1024; + while (buff == NULL && *h > LEASTMEM) { + *h -= 1024; + buff = malloc(*h); + } + return buff; } /* -@($) sortcomp SORT + @($) sortcomp SORT -@(ID) -Esegue i confronti per il sort ed il merge. -@(FD) + @(ID) + Esegue i confronti per il sort ed il merge. + @(FD) -@(ISV) -i = contatore. + @(ISV) + i = contatore. -k = risultato della comparazione. -@(FSV) + k = risultato della comparazione. + @(FSV) -@(IN) -Ritorna un intero < 0 se a < b - 0 se a = b - > 0 se a > b -@(FN) -*/ + @(IN) + Ritorna un intero < 0 se a < b + 0 se a = b + > 0 se a > b + @(FN) + */ static int sortcomp(a,b) -char **a; char **b; /* puntatori ai puntatori ai record da confrontare */ + char **a; char **b; /* puntatori ai puntatori ai record da confrontare */ { - int i, k; + int i, k; - if (**a == 127 || **b == 127) - return (int) **a - (int) **b; - for (i = 0; i < NOFLDS; i++) - { - if (sp->s_fld[i].f_pos == 0) break; - if (sp->s_fld[i].f_len >= 0) /* string compare */ - { - if ( ( k=strncmp ( (*a)+sp->s_fld[i].f_pos-1, - (*b)+sp->s_fld[i].f_pos-1, - sp->s_fld[i].f_len - ) ) != 0) - return (sp->s_fld[i].ad == 'd')?-k:k; - } + if (**a == 127 || **b == 127) + return (int) **a - (int) **b; + for (i = 0; i < NOFLDS; i++) + { + if (sp->s_fld[i].f_pos == 0) break; + if (sp->s_fld[i].f_len >= 0) /* string compare */ + { + if ( ( k=strncmp ( (*a)+sp->s_fld[i].f_pos-1, + (*b)+sp->s_fld[i].f_pos-1, + sp->s_fld[i].f_len + ) ) != 0) + return (sp->s_fld[i].ad == 'd')?-k:k; + } - if (sp->s_fld[i].f_len == -1) /* integer compare */ - { - if ( (*( (int*) (*a)+sp->s_fld[i].f_pos-1 )) != - (*( (int*) (*b)+sp->s_fld[i].f_pos-1 )) ) - { - k=(*( (int*) (*a)+sp->s_fld[i].f_pos-1 )) - (*( (int*) (*b)+sp->s_fld[i].f_pos-1 )); - return (sp->s_fld[i].ad == 'd')?-k:k; - } - } + if (sp->s_fld[i].f_len == -1) /* integer compare */ + { + if ( (*( (int*) (*a)+sp->s_fld[i].f_pos-1 )) != + (*( (int*) (*b)+sp->s_fld[i].f_pos-1 )) ) + { + k=(*( (int*) (*a)+sp->s_fld[i].f_pos-1 )) - (*( (int*) (*b)+sp->s_fld[i].f_pos-1 )); + return (sp->s_fld[i].ad == 'd')?-k:k; + } + } - if (sp->s_fld[i].f_len == -2) /* BOOLEAN compare */ - { - if ( (*( (BOOLEAN*) (*a)+sp->s_fld[i].f_pos-1 )) != - (*( (BOOLEAN*) (*b)+sp->s_fld[i].f_pos-1 )) ) - { - k=(int) ( (*( (BOOLEAN*) (*a)+sp->s_fld[i].f_pos-1 )) - (*( (BOOLEAN*) (*b)+sp->s_fld[i].f_pos-1 )) ); - return (sp->s_fld[i].ad == 'd')?-k:k; - } - } - } - return 0; + if (sp->s_fld[i].f_len == -2) /* BOOLEAN compare */ + { + if ( (*( (BOOLEAN*) (*a)+sp->s_fld[i].f_pos-1 )) != + (*( (BOOLEAN*) (*b)+sp->s_fld[i].f_pos-1 )) ) + { + k=(int) ( (*( (BOOLEAN*) (*a)+sp->s_fld[i].f_pos-1 )) - (*( (BOOLEAN*) (*b)+sp->s_fld[i].f_pos-1 )) ); + return (sp->s_fld[i].ad == 'd')?-k:k; + } + } + } + return 0; } /*---------------------------- SECONDA PARTE --------------------------------*/ /* -@(#) initsortfield SORT + @(#) initsortfield SORT -@(ID) -Definizione di sort per un record ISAM. -@(FD) -*/ + @(ID) + Definizione di sort per un record ISAM. + @(FD) + */ void initsortfield () { - nsortfield = datisort.s_fld[0].f_pos = 0; /* sort su nessun campo */ + nsortfield = datisort.s_fld[0].f_pos = 0; /* sort su nessun campo */ } -/* -@(#) addsortfield SORT - -@(ID) -Aggiunge campi alla descrizione. -@(FD) - -@(ISV) -i = variablie di lavoro. - -n = variablie di lavoro. -@(FSV) -*/ - -int addsortfield (isfd,ncampo,da,a,ad) -isfdptr isfd; /* puntatore al descrittore del file ISAM */ -FieldName ncampo; /* nome campo */ -int da; /* carattere da cui considerare il campo per il sort */ -int a; /* carattere fino al quale considerare il campo per il sort */ -char ad; /* ordine crescente o decrescente */ - -{ - int i,n; - - if (((n = findfld(isfd->r, ncampo)) != -1) && (nsortfield < NOFLDS)) - { - /* sostituito i con n in Fd[_].RecOff e Fd[_].len */ -/* @(!) 2.3.01.temp */ - datisort.s_fld[nsortfield].f_pos = (da==0) ? (isfd->r->Fd[n].RecOff + 1) : (isfd->r->Fd[n].RecOff+da); - datisort.s_fld[nsortfield].f_len = (a==0) ? (isfd->r->Fd[n].Len) : (a-da+1); /* carica FLDLEN */ - datisort.s_fld[nsortfield].ad = ad; /* carica AD */ - nsortfield++; -/* @(:) 2.3.01.temp */ - return 0; - } - else return -1; -} - -/* -@(#) finesortfield SORT - -@(ID) -Chiude la descrizione del sort per i record ISAM. -@(FD) - -@(IN) -Attenzione : questa funzione inizializza anche il sort. -@(FN) -*/ - -int finesortfield (isfd) -isfdptr isfd; /* puntatore al descrittore del file ISAM */ -{ - datisort.rc_len=isfd->d->LenR; -/* @(!) 2.3.01.temp */ - if (nsortfield < NOFLDS) - datisort.s_fld[nsortfield].f_pos = 0; /* chiude l'elenco campi */ -/* @(:) 2.3.01.temp */ - return (init_sort (&datisort)); -} /*---------------------------------------------------------------------------*/ diff --git a/include/csort.h b/include/csort.h index c0aff34da..1ca4030f2 100755 --- a/include/csort.h +++ b/include/csort.h @@ -1,39 +1,8 @@ -/* - @(SH) Header - - @(C#) PUBBLICHE - NOFLDS : massimo numero di chiavi da ordinare - - @(C$) PRIVATE - MOSTMEM : numero massimo di bytes di memoria per il buffer di sort - LEASTMEM : numero minimo di bytes di memoria per il buffer di sort - @(VG#) PUBBLICHE - s_prm : struttura di un sort - s_prm.rc_len : lunghezza del record - s_prm.s_fld : vettore della struttura dei campi di sort - s_prm.s_fld[].f_pos : prima posizione del campo (contando da 1) - s_prm.s_fld[].f_len : lunghezza del campo e tipo del campo; se f_len > 0 e' una stringa; se f_len = -1 e' un intero; se f_len = -2 e' un boolean - s_prm.s_fld[].ad : a = crescente; d = decrescente - - @(VG$) PRIVATE - bp : struttura di una sequenza in un buffer di merge - bp.rc : puntatore al record nel merge buffer - bp.rbuf : record rimasti nel buffer in questa sequenza di sort - bp.rdsk : record rimasti nel disco in questa sequenza di sort - ------------------------------------------------------------------------------- - */ - #ifndef __CSORT_H #define __CSORT_H -#ifndef __CCOMMON_H -#include "ccommon.h" -#endif -#ifndef __CCUSTIO_H -#include "ccustio.h" -#endif -#ifndef __CISAM_H -#include "cisam.h" +#ifndef __CFILES_H +#include "cfiles.h" #endif #define NOFLDS 10 @@ -70,8 +39,6 @@ extern "C" { /*----------------------- FUNZIONI VISIBILI SECONDA PARTE -------------------*/ void initsortfield (void); - int addsortfield (isfdptr, FieldName, int, int, char); - int finesortfield (isfdptr); /* azzera l'elenco dei campi in base a cui eseguire il sort */ /* ritorna 0 se tutto ok, -1 se chiamata piu' di NOFLDS volte dopo l'ultimo initsortfield */ diff --git a/include/fldtypes.h b/include/fldtypes.h new file mode 100755 index 000000000..c46cea1ce --- /dev/null +++ b/include/fldtypes.h @@ -0,0 +1,13 @@ +#define NullF 0 +#define AlfaF 1 +#define IntF 2 +#define Int4F 3 +#define RealF 4 +#define DateF 5 +#define WordF 6 +#define CharF 7 +/* @(!) 2.3.01.196 */ +#define BoolF 8 +#define ZeroF 9 +#define EZeroF 10 +/* @(:) 2.3.01.196 */ diff --git a/include/genconst.h b/include/genconst.h new file mode 100755 index 000000000..055be142d --- /dev/null +++ b/include/genconst.h @@ -0,0 +1,117 @@ +#ifndef __GENCONST_H +#define __GENCONST_H + +#define NoAut 0 + +#define ScrVal 0 +#define ScrSal 1 +#define ScrNoClear 2 +#define ScrNum 3 +#define ScrUpp 4 +#define ScrDate 5 +/* @(!) 2.3.01.163 */ +#define ScrNumNoTrim 6 +/* @(:) 2.3.01.163 */ +#define ScrAutoHlp 7 +#define ScrAutoCnt 8 +#define ScrAutoReq 9 +#define BrGoEnd 1 +#define BrInsLine 2 +#define FdSt 0 +#define FdEnd -1 + + +#define NulC CHR(0) +#define C01 CHR(1) +#define C02 CHR(2) +#define Bell CHR(7) +#define BkSp CHR(8) +#define Tab CHR(9) +#define CtrlRet CHR(10) +#define Home CHR(11) +#define EndK CHR(12) +#define Ret CHR(13) +#define PgUp CHR(14) +#define PgDn CHR(15) +#define CtrlHome CHR(16) +#define CtrlEndK CHR(17) +#define CtrlPgUp CHR(18) +#define CtrlPgDn CHR(19) +#define Ins CHR(20) +#define Del CHR(127) +#define ShiftTab CHR(22) +#define Esc CHR(27) +#define Right CHR(28) +#define Left CHR(29) +#define Up CHR(30) +#define Down CHR(31) +#define Blank CHR(32) +#define LBr CHR(91) +#define F1 CHR(177) +#define F2 CHR(178) +#define F3 CHR(179) +#define F4 CHR(180) +#define F5 CHR(181) +#define F6 CHR(182) +#define F7 CHR(183) +#define F8 CHR(184) +#define F9 CHR(185) +#define F10 CHR(186) +#define SF1 CHR(187) +#define SF2 CHR(188) +#define SF3 CHR(189) +#define SF4 CHR(190) +#define SF5 CHR(191) +#define SF6 CHR(192) +#define SF7 CHR(193) +#define SF8 CHR(194) +#define SF9 CHR(195) +#define SF10 CHR(196) +#define CF1 CHR(197) +#define CF2 CHR(198) +#define CF3 CHR(199) +#define CF4 CHR(200) +#define CF5 CHR(201) +#define CF6 CHR(202) +#define CF7 CHR(203) +#define CF8 CHR(204) +#define CF9 CHR(205) +#define CF10 CHR(206) +#undef ON +#define ON TRUE +#undef OFF +#define OFF FALSE +#define NoErr 0 + +#define ExclLock 256 /*16#0100*/ +#define AutoLock 512 /*16#0200*/ +#define ManuLock 1024 /*16#0400*/ + +#define UnLock 4096 /*16#1000*/ +#define NoLock 8192 /*16#2000*/ +#define Lock 16384 /*16#4000*/ +#define ShareLock 32768 /*16#8000*/ +#define RecLockTypes 61440 /*16#F000*/ + +#define IsFirst 0 /*16#0*/ +#define IsLast 1 /*16#1*/ +#define IsNext 2 /*16#2*/ +#define IsPrev 4 /*16#4*/ +#define IsCurr 8 /*16#8*/ +#define IsEqual 16 /*16#10*/ +#define IsGreat 32 /*16#20*/ +#define IsGtEq 64 /*16#40*/ +#define IsNextN 256 /*16#100*/ +#define IsPrevN 512 /*16#200*/ + + +#define DefPrinter 1 + + +#ifndef M_TERMINFO +#define Refresh(w) RefScrn +#define WINDOW HWND +#define Window HWND +#define window HWND +#endif +#endif /* __GENCONST_H */ diff --git a/include/getaut.c b/include/getaut.c new file mode 100755 index 000000000..0d3e8cfe0 --- /dev/null +++ b/include/getaut.c @@ -0,0 +1,72 @@ + +#include "ccommon.h" +#include "libdefs.h" + +Word _int_tab0[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0x0000}; + +/* + @(#) CGetAut + + @(ID) + Restituisce l'autorizzazione ad utilizzare un modulo. Vedi il file modaut.h. + @(FD) + + */ + +BOOLEAN CGetAut(af) + int af; /* numero del modulo */ + +{ + int i; +#ifndef DOS + BOOLEAN ok; +#endif + if (!af) return(!af); + if (af > 48) return(FALSE); + /* @(!) 2.3.01.176 */ + if (demoflag) + { + /* @(!) 2.3.01.276 */ + if (formflag) + _int_tab0[0] = 0x019D; + else + _int_tab0[0] = 0x010D; + /* @(:) 2.3.01.276 */ + _int_tab0[1] = 0x0000; + _int_tab0[2] = 0x0000; + _int_tab0[3] = 0x0000; + af--; + return(CBITTEST(_int_tab0[af / 16], af % 16)); + } + /* @(:) 2.3.01.176 */ + if (!SerNo) return(!getser()); + /* @(!) 2.3.01.178 */ +#ifdef DOS + HL_READ(48, &_int_tab0[0]); + HL_READ(49, &_int_tab0[1]); + HL_READ(50, &_int_tab0[2]); + HL_READ(51, &_int_tab0[3]); + HL_CODE(EYECAST &_int_tab0[0], HLBLOCK); +#else + /* @(:) 2.3.01.178 */ + INT_OFF(); + HL_ON(Port, ModAd); + _int_tab0[0] = HL_RD(Port, 48); + _int_tab0[1] = HL_RD(Port, 49); + _int_tab0[2] = HL_RD(Port, 50); + _int_tab0[3] = HL_RD(Port, 51); + HL_OFF(Port); + INT_ON(); + INT_OFF(); + HL_ON(Port, ModAd); + ok = K_EYE(Port, EYECAST &_int_tab0[0], HLBLOCK); + HL_OFF(Port); + INT_ON(); + /* @(!) 2.3.01.178 */ +#endif + /* @(:) 2.3.01.178 */ + for (i = 0; i < 4; i++) _int_tab0[i] ^= SerNo; + if (_int_tab0[3]) return(FALSE); + af--; + return(CBITTEST(_int_tab0[af / 16], af % 16)); +} diff --git a/include/hlapi_c.h b/include/hlapi_c.h new file mode 100755 index 000000000..7a38384d8 --- /dev/null +++ b/include/hlapi_c.h @@ -0,0 +1,172 @@ +#ifndef __HLAPI_H +#define __HLAPI_H + +/****************************************************************************/ +/** **/ +/** Hardlock E-Y-E **/ +/** API-Structures and definitions **/ +/** **/ +/** This file contains some helpful defines to access a Hardlock using **/ +/** the application programing interface (API) for Hardlock E-Y-E. **/ +/** **/ +/** (c) 1992 by ///FAST Electronic **/ +/** **/ +/** **/ +/** Authors : Thomas Schr”ter **/ +/** Henri Volk **/ +/** Version : 3.0 **/ +/** Date : 01-Sep-1992 **/ +/** **/ +/****************************************************************************/ + +#define EYECAST (char huge *) + +/* -------------------------------- */ +/* Definitions and API structures : */ +/* -------------------------------- */ +typedef unsigned char Byte; +typedef signed short Word; +typedef unsigned long Long; + +typedef struct +{ + Word Use_Key; + Byte Key[8]; +} +DES_MODE; + +typedef struct +{ + Word ModAd; /* Moduleaddress EYE */ + Word Register; /* Memory register adress */ + Word Value; /* Memory value */ + Byte Reserved[4]; +} +EYE_MODE; + +typedef union +{ + DES_MODE Des; + EYE_MODE Eye; +} +HARDWARE; + +typedef struct hl_api +{ + Byte API_Version_ID[2]; /* Version */ + Word API_Options[2]; /* API Optionflags */ + Word ModID; /* Modul-ID (EYE = 0...) */ + HARDWARE Module; /* Hardware type */ + void far *Data; /* Pointer to cipher data */ + Word Bcnt; /* Number of blocks */ + Word Function; /* Function number */ + Word Status; /* Actual status */ + Word Remote; /* Remote or local?? */ + Word Port; /* Port address if local */ + Word Speed; /* Speed of port if local */ + Word NetUsers; /* Current Logins (HLSERVER) */ + Byte ID_Ref[8]; /* Referencestring */ + Byte ID_Verify[8]; /* Encrypted ID_Ref */ + Long Task_ID; /* Multitasking program ID */ + Byte Reserved[200]; /* Reserved area */ +} +HL_API; + +/* ------------- */ +/* Module-ID's : */ +/* ------------- */ +#define EYE_DONGLE 0 /* Hardlock E-Y-E */ +#define DES_DONGLE 1 /* FAST DES */ + +/* --------------------- */ +/* API function calls : */ +/* --------------------- */ +#define API_INIT 0 /* Init API structure */ +#define API_DOWN 1 /* Free API structure */ +#define API_FORCE_DOWN 31 /* Force deinintialization */ +#define API_MULTI_SHELL_ON 2 /* MTS is enabled */ +#define API_MULTI_SHELL_OFF 3 /* MTS is disabled */ +#define API_MULTI_ON 4 /* Enable MTS */ +#define API_MULTI_OFF 5 /* Disable MTS */ +#define API_AVAIL 6 /* Dongle available? */ +#define API_LOGIN 7 /* Login dongle server */ +#define API_LOGOUT 8 /* Logout dongle server */ +#define API_INFO 9 /* Get API informations */ + +/* --------------------------- */ +/* Data and memory functions : */ +/* --------------------------- */ +#define API_KEYE 11 /* Use KEYE for encryption */ +#define API_READ 20 /* Read one word of dongle EEPROM */ +#define API_WRITE 21 /* Write one word of dongle EEPROM */ +#define API_READ_BLOCK 23 /* Read EEPROM in one block */ +#define API_WRITE_BLOCK 24 /* Write EEPROM in one block */ +#define API_GET_ID_KEY 30 /* Encrypt ID_Ref to ID_Verify */ +#define API_ABORT 53 /* Critical Error Abort */ + +/* -------------------- */ +/* Dongle access mode : */ +/* -------------------- */ +#define LOCAL_DEVICE 1 /* Query local HL only */ +#define NET_DEVICE 2 /* Query remote HL only */ +#define DONT_CARE 3 /* Query local or remote HL */ + +/* ------------------ */ +/* API Status Codes : */ +/* ------------------ */ +#define STATUS_OK 0 /* API call was succesfull */ +#define NOT_INIT 1 /* DONGLE not initialized */ +#define ALREADY_INIT 2 /* Already initialized */ +#define UNKNOWN_DONGLE 3 /* Device not supported */ +#define UNKNOWN_FUNCTION 4 /* Function not supported */ +#define NO_DONGLE 7 /* No device available */ +#define NETWORK_ERROR 8 /* A network error occured */ +#define NO_ACCESS 9 /* No device available */ +#define INVALID_PARAM 10 /* A wrong parameter occured */ +#define VERSION_MISMATCH 11 /* HL-Server not API version */ + +#ifdef __cplusplus +extern "C" { +#endif + + /* --------------------- */ + /* Function prototypes : */ + /* --------------------- */ + static int CALL_API (HL_API far *as); + Word far HL_LOGIN (Word ModAd, Word Access, char * RefKey, char * VerKey); + Word far HL_LOGOUT (void); + Word far HL_AVAIL (void); + Word far HL_PORTINF (void); + Word far HL_ACCINF (void); + Word far HL_USERINF (void); + Word far HL_MAXUSER (void); + Word far HL_MEMINF (void); + Word far HL_CODE (void far *Data, Word Count); + Word far HL_WRITE (Word Register, Word Value); + Word far HL_READ (Word Register, int far *Value); + char far * HL_GET_ID (char * id_ref); + Word far HL_READBL (char * Eeprom); + Word far HL_WRITEBL (char * Eeprom); + Word far HL_ABORT (void); + Word far HL_VERSION (void); + + /****************************************************************************/ + /****************************************************************************/ + /* The following functions map the old Hardlock Calls on the new API. These */ + /* functions are defined only for compatibility reasons. */ + /* !!! Don't mix old and new functions. Don't use if it is not necessary.!!!*/ + /****************************************************************************/ + /****************************************************************************/ + void far HL_ON (int Port, Word ModAd); + void far HL_OFF (int Port); + int far K_EYE (int Port, char huge *Inp, int BlkCnt); + void far HL_WR (int Port, int Register, Word Val); + Word far HL_RD (int Port, int Register); + void far INT_ON (void); + void far INT_OFF (void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/hlprot.c b/include/hlprot.c new file mode 100755 index 000000000..3c893e1f1 --- /dev/null +++ b/include/hlprot.c @@ -0,0 +1,142 @@ +/* + @(SH) Funzioni per i controlli sulla chiave di protezione + -------------------------------------------------------------------------------- + @(H) 2.3.01.176 09/03/93 Bonazzi Implementazione demo e formazione + @(H) 2.3.01.178 09/03/93 Bonazzi Implementazione EYE-API in DOS + */ + +#include "ccommon.h" +#include "libdefs.h" + +Word ModAd = 26952, Port = 0, SerNo = -1; +/* @(!) 2.3.01.176 */ +BOOLEAN demoflag = FALSE, formflag = FALSE; +/* @(:) 2.3.01.176 */ + +/* + @(%) HL_Port LIBDEFS + + @(ID) + Ricerca la chiave di protezione. + @(FD) + + @(IN) + Restituisce l'indirizzo della porta parallela ove ha trovato la chiave di prot. + @(FN) + */ + +#ifndef DOS +Word Hl_Port(ModAd) + Word ModAd; /* indirizzo del modulo */ +{ + Byte Dummy[10]; + Word n, PortAdr[3]; + + PortAdr[0] = 0x3BC; + PortAdr[1] = 0x378; + PortAdr[2] = 0x278; + + INT_OFF(); + for(n = 0; n < 3; n++) + { + strcpy(Dummy, "HARDLOCK"); + HL_ON(PortAdr[n], ModAd); + if(K_EYE(PortAdr[n], EYECAST Dummy, HLBLOCK)) + if(K_EYE(PortAdr[n], EYECAST Dummy, HLBLOCK)) + if(!strncmp("HARDLOCK", Dummy, 8)) + { + HL_OFF(PortAdr[n]); + INT_ON(); + return(PortAdr[n]); + } + HL_OFF(PortAdr[n]); + } + INT_ON(); + return(0); +} +#endif + +/* + @(%) getser LIBDEFS + + @(ID) + Restituisce il numero di serie del cliente. + @(FD) + + @(IN) + Utilizza la chiave di protezione. + @(FN) + */ + +Word getser() + +{ + Word Val[4]; +#ifndef DOS + BOOLEAN ok; + int i; +#endif + SerNo = -1; + /* @(!) 2.3.01.178 */ +#ifdef DOS + if (HL_AVAIL() == STATUS_OK) +#else + /* @(:) 2.3.01.178 */ + if (Port = Hl_Port(ModAd)) + /* @(!) 2.3.01.178 */ +#endif + /* @(:) 2.3.01.178 */ + { + SerNo = 0; + /* @(!) 2.3.01.178 */ +#ifdef DOS + HL_READ(0, &Val[0]); + HL_READ(1, &Val[1]); + HL_READ(2, &Val[2]); + HL_READ(3, &Val[3]); + HL_CODE(EYECAST &Val[0], HLBLOCK); +#else + /* @(:) 2.3.01.178 */ + INT_OFF(); + HL_ON(Port, ModAd); + Val[0] = HL_RD(Port, 0); + Val[1] = HL_RD(Port, 1); + Val[2] = HL_RD(Port, 2); + Val[3] = HL_RD(Port, 3); + HL_OFF(Port); + INT_ON(); + INT_OFF(); + HL_ON(Port, ModAd); + ok = K_EYE(Port, EYECAST &Val[0], HLBLOCK); + HL_OFF(Port); + INT_ON(); + /* @(!) 2.3.01.178 */ +#endif + /* @(:) 2.3.01.178 */ + if (Val[0] == 0xFAE8) + { + SerNo = Val[1]; + return(Val[1]); + } + else + return(0); + } + else + /* @(!) 2.3.01.176 */ + { +#ifdef DOS + FILE *f = fopen("c:\\command.com", "r"); + char s[4]; + + if (f == NULL) return(-1); + if (fseek(f, 46500L, SEEK_SET) != 0) return(-1); + if (fread(s, 1, 1, f) == -1) return(-1); + fclose(f); + if (*s != 'm') return(-1); +#endif + SerNo = 0; + demoflag = TRUE; + return(0); + } + /* @(:) 2.3.01.176 */ +} diff --git a/include/ioresult.c b/include/ioresult.c new file mode 100755 index 000000000..fbc2c8e8e --- /dev/null +++ b/include/ioresult.c @@ -0,0 +1,23 @@ +#include "ccommon.h" + +/* + @(#) CIOResult COMMON + + @(ID) + Legge il codice di errore e lo ritorna. + @(FD) + + @(ISV) + res = intero contenente il codice di errore. + @(FSV) + + */ + +int CIOResult() + +{ + int res = errno ; + + errno = NoErr ; + return(res) ; +} diff --git a/include/keye.h b/include/keye.h new file mode 100755 index 000000000..e412c567a --- /dev/null +++ b/include/keye.h @@ -0,0 +1,37 @@ + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef DOS + typedef unsigned char Byte; + typedef unsigned int Word; + typedef unsigned long Long; + +#define EYECAST (char huge *) + extern void far HL_ON (int Port, Word ModAd); + extern void far HL_OFF (int Port); + extern int far K_EYE (int Port, char huge *Inp, int BlkCnt); + extern void far HL_WR (int Port, int Register, Word Val); + extern Word far HL_RD (int Port, int Register); + + extern void far INT_ON (void); + extern void far INT_OFF (void); + +#else +#define INT_ON() +#define INT_OFF() +#define EYECAST + + typedef unsigned long Long; + typedef unsigned short Word; + typedef unsigned char Byte; + + void HL_ON (Word, Word); /* Activate the Hardlock */ + void HL_OFF (Word); /* Deactivate the Hardlock */ + Word HL_RD (Word, Word); /* Read from the EEProm */ + void HL_WR (Word, Word, Word); /* Write to the EEProm */ + Word K_EYE (Word, Byte *, Word); /* Encrypt Blocks */ +#endif +#ifdef __cplusplus +}; +#endif diff --git a/include/libdefs.h b/include/libdefs.h new file mode 100755 index 000000000..8fc2c993b --- /dev/null +++ b/include/libdefs.h @@ -0,0 +1,127 @@ +/* @(!) 2.3.01.178 */ +#ifdef DOS +#include "hlapi_c.h" +#else +#include "keye.h" +#endif +/* @(:) 2.3.01.178 */ +#define MAXCKEY 5 +#define MAXCLEN 10 +#define MAXENTRYNAME 16 +#define MAXTENTRY 48 +/* @(!) 2.3.01.temp */ +#define MAXENTRYSIZE 4096 +/* @(:) 2.3.01.temp */ +#define MAXDISPCOLS 4 +#define CONFFILE "conf.gen" +#ifdef DOS +#define HLBLOCK 1 +/* @(!) 2.3.01.178 */ +#define REFKEY "CAMPOKEY" +#define VERKEY "ìpÙˆ¬cê<" +/* @(:) 2.3.01.178 */ +#else +#define HLBLOCK 2 +#endif + +/* + @(H) 2.3.00.10 24/09/91 Bonazzi Dichiarato numero di versione globale + @(H) 2.3.01.69 15/05/92 Bonazzi Modificato algoritmo di refresh delle finestre + @(H) 2.3.01.130 08/10/92 Bonazzi Corretto algoritmo lettura caratteri per >128 + */ + +typedef union +{ + BOOLEAN b; /*tipo BL*/ + int i; /*tipo I*/ + word w; /*tipo U*/ + byte by; /*tipo BY*/ + long l; /*tipo E*/ + DEC r; /*tipo R*/ + char c; /*tipo C*/ + TrDate d; /*tipo D*/ + Str80 s; /*tipo A*/ +} conftype; + +#ifndef DOS +struct capentry { + /* @(!) 2.3.01.130 */ + uchar key[MAXCKEY]; + uchar str[MAXCLEN]; + /* @(:) 2.3.01.130 */ + char charcode; +}; +#endif +struct keybar { + word id; + uchar key; + char *explic; + struct keybar *next; + struct keybar *prev; + /* @(!) 2.3.01.223 */ + BOOLEAN nosusp; + /* @(:) 2.3.01.223 */ +}; + +extern conftype _int_cf; +extern char _int_res[513]; +extern uchar _int_s1[256]; +/* @(!) 2.3.01.temp */ +#ifdef M_I386 +extern short _int_cnt[8]; +#else +/* @(:) 2.3.01.temp */ +extern int _int_cnt[8]; +/* @(!) 2.3.01.temp */ +#endif +/* @(:) 2.3.01.temp */ +#ifndef XVT_OS +extern chtype boxstr[MAXBORDERS][6]; +extern int termlines; +extern int nwin; +extern int worder[MAXWIN]; +#endif +extern BOOLEAN insstate; +extern BOOLEAN retins; +extern Word ModAd; +extern Word Port; +extern Word SerNo; +extern char *modname[]; +#ifndef XVT_OS +extern int dispcol[MAXDISPCOLS][2]; +#endif +extern char *keybarstr; +/* @(!) 2.3.00.10 */ +extern char vers[]; +/* @(H) 2.3.00.10 */ +/* @(!) 2.3.01.69 */ +#ifndef XVT_OS +extern BOOLEAN border; +#endif +/* @(:) 2.3.01.69 */ +/* @(!) 2.3.01.150 */ +extern BOOLEAN flprassi; +/* @(:) 2.3.01.150 */ +/* @(!) 2.3.01.158 */ +extern BOOLEAN flaltmodins; +/* @(:) 2.3.01.158 */ +/* @(!) 2.3.01.176 */ +extern BOOLEAN demoflag; +extern BOOLEAN formflag; +/* @(:) 2.3.01.176 */ + +/* @(!) 2.3.01.325 aggiunto pre-prefisso */ +extern Str80 __ptprf; +/* @(:) 2.3.01.325 */ + +int setblock(int, BOOLEAN); +/* @(!) 2.3.01.130 */ +char *custgetcap(uchar *, uchar *, int); +void readkeysdef (uchar *, struct capentry *); +int gettdef ( char *, uchar *); +/* @(:) 2.3.01.130 */ +void initctab(struct capentry *); +void createaut (struct capentry *); +void putconf(int, conftype *); +Word Hl_Port(Word); +Word getser(void); diff --git a/include/mshell.h b/include/mshell.h new file mode 100755 index 000000000..57d1d38cd --- /dev/null +++ b/include/mshell.h @@ -0,0 +1,101 @@ +#ifndef __MSHELL_H +#define __MSHELL_H + +#ifdef XVT_OS + +#ifdef __cplusplus +extern "C" { +#endif + +#if XVT_OS == XVT_OS_NOTUSED + +#define ALIGNSIZE sizeof(double) +#define CALCSIZE(x) ((((x) + (ALIGNSIZE - 1)) / ALIGNSIZE) * ALIGNSIZE) + +#define malloc(a) win_malloc((a)) +#define realloc(a,b) win_realloc((a), (b)) +#define free(a) win_free((a)) +#define calloc(a,b) win_calloc((a), (b)) +#define strdup(a) win_strdup((a)) + + void setmemsize(long); + char* win_malloc(size_t); + char* win_realloc(char*, size_t); + void win_free(char*); + char* win_calloc(size_t, size_t); + char* win_strdup(char*); + +#else + + /* + #define malloc(a) xvt_fmalloc((a)) + #define realloc(a,b) xvt_frealloc((a), (b)) + #define free(a) xvt_ffree((a)) + #define calloc(a,b) xvt_calloc((a), (b)) + #define strdup(a) xvt_strdup((a)) + #define setmemsize(a) + + char *xvt_calloc(size_t, size_t); + char *xvt_strdup(char*); + */ + +#endif + +#ifdef __cplusplus +}; +#endif + +#else + +#define size_t unsigned + +#define MEMLIST +#define MEMWHERE + +/* interface functions */ +unsigned long memused(void); +void memdisplay(FILE *); + +/* interface macros */ +#define ALIGNSIZE sizeof(double) +#define CALCSIZE(x) ((((x) + (ALIGNSIZE - 1)) / ALIGNSIZE) * ALIGNSIZE) + +/* interface functions to access only through macros */ +#ifdef MEMWHERE +#ifdef __cplusplus +extern "C" { +#endif + char *memalloc(size_t, char *, int); + char *memrealloc(char *, size_t, char *, int); + void memfree(char *, char *, int); + char *memcalloc(size_t, size_t, char *, int); + char *memstrdup(char *, char *, int); +#else + char *memalloc(size_t); + char *memrealloc(char *); + void memfree(char *); + char *memcalloc(size_t, size_t); + char *memstrdup(char *); +#ifdef __cplusplus +}; +#endif +#endif + +/* Interface macros */ +#ifndef __MSHELL__ +#ifdef MEMWHERE +#define malloc(a) memalloc((a), __FILE__, __LINE__) +#define realloc(a,b) memrealloc((a), (b), __FILE__, __LINE__) +#define free(a) memfree((a), __FILE__, __LINE__) +#define calloc(a,b) memcalloc((a), (b), __FILE__, __LINE__) +#define strdup(a) memstrdup((a), __FILE__, __LINE__) +#else +#define malloc(a) memalloc((a)) +#define realloc(a,b) memrealloc((a), (b)) +#define free(a) memfree((a)) +#define calloc(a,b) memcalloc((a), (b)) +#define strdup(a) memstrdup((a)) +#endif +#endif +#endif /* XVT_OS */ +#endif /* __MSHELL_H */ diff --git a/include/tmpfname.c b/include/tmpfname.c new file mode 100755 index 000000000..64bdd7e92 --- /dev/null +++ b/include/tmpfname.c @@ -0,0 +1,20 @@ +#include +#include +#include +/* + @(H) 2.3.01.316 14/3/95 Vignali Gestione nomi temporanei intelligente + */ + +/* @(!) 2.3.01.316 */ + +void tmpfname(p,n) + char *p; + char *n; +{ + char *pp; + pp = (char *) tempnam("/tmp/",n); + strcpy(p,pp); + free((void *) pp); +} + +/* @(:) 2.3.01.316 */ diff --git a/include/upstring.c b/include/upstring.c new file mode 100755 index 000000000..e2ce19df3 --- /dev/null +++ b/include/upstring.c @@ -0,0 +1,16 @@ +#include "ccommon.h" + + +char *CUpString(s) + char *s; /* stringa da trasformare in maiuscolo */ + +{ + char *s1 = s; + + while (*s1) + { + *s1 = UPCASE(*s1); + s1++; + } + return(s); +}