306e964e2c
cui nomen inditum est Victorius XXXII Aggiunte maschere senza handler statici, TAutomask Tolto file inutile libdefs.h Megafigata per un significativo speed-up dei TCursori git-svn-id: svn://10.65.10.50/trunk@6304 c028cbd2-c16b-5b4b-a496-9718f37d4682
739 lines
15 KiB
C
Executable File
739 lines
15 KiB
C
Executable File
#define __CFILES_C /* fv */
|
|
|
|
#ifdef DOS
|
|
|
|
#define XVT_INCL_NATIVE
|
|
#include <xvt.h>
|
|
#include <checks.h>
|
|
|
|
#include <io.h>
|
|
#include <stdlib.h>
|
|
#include <direct.h>
|
|
|
|
#endif // DOS
|
|
|
|
#include "cfiles.h"
|
|
#include "fldtypes.h"
|
|
|
|
|
|
int hashfun(const char *);
|
|
void setdec(char *, int);
|
|
const char* prefname();
|
|
|
|
HIDDEN BOOLEAN pathpread = 0;
|
|
|
|
BOOLEAN dispferr = 1;
|
|
int dirfl[2] = {0, 0}, recfl[2] = {0, 0} ;
|
|
PathSt __ptprf = "";
|
|
|
|
/*
|
|
@(#) 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))
|
|
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 (%s)", fdir[dirflg].IOR,name);
|
|
}
|
|
|
|
/*
|
|
@(#) 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 (%s)", rdir[dirflg].IOR,name);
|
|
|
|
}
|
|
|
|
/*
|
|
@(#) 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);
|
|
}
|
|
|
|
/*
|
|
|
|
@($) 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
|
|
|
|
HIDDEN const char* prefname()
|
|
{
|
|
static char* s = NULL;
|
|
|
|
if (s == NULL)
|
|
{
|
|
#ifdef DOS
|
|
char *s1 = getenv("PREFPATH");
|
|
if (s1 == NULL) s1 = "prefix.txt";
|
|
s = strdup(s1);
|
|
#else
|
|
s = malloc(32);
|
|
sprintf(s, "prefix.%-d", getuid());
|
|
#endif
|
|
}
|
|
|
|
return s;
|
|
}
|
|
|
|
#ifdef DOS
|
|
|
|
const char* CGetPrawinName(void)
|
|
{
|
|
static char* prawin = NULL;
|
|
if (prawin == NULL)
|
|
{
|
|
char drive[_MAX_DRIVE];
|
|
char path[_MAX_PATH];
|
|
char tmp[_MAX_PATH];
|
|
_splitpath(prefname(), drive, path, NULL, NULL);
|
|
_makepath(tmp, drive, path, "prawin", ".ini");
|
|
if (access(tmp, 0) != 0) // se non esiste ...
|
|
{
|
|
FILE* pw = fopen(tmp, "w"); // ... lo creo
|
|
fclose(pw);
|
|
}
|
|
prawin = malloc(_MAX_PATH);
|
|
if (*path)
|
|
strcpy(prawin,tmp);
|
|
else
|
|
_searchenv(tmp, NULL, prawin);
|
|
}
|
|
return prawin;
|
|
}
|
|
|
|
HIDDEN BOOLEAN CGetPrawin()
|
|
{
|
|
const char* prawin = CGetPrawinName();
|
|
BOOLEAN good = _access(prawin, 0x00) == 0;
|
|
if (good)
|
|
{
|
|
UINT len = GetPrivateProfileString("Main", "Study", "", __ptprf, sizeof(__ptprf), prawin);
|
|
good = len > 0;
|
|
if (good)
|
|
{
|
|
char firm[8];
|
|
long ditta;
|
|
|
|
if (__ptprf[len-1] != '\\' && __ptprf[len-1] != '/')
|
|
{
|
|
__ptprf[len] = DIRSEP;
|
|
__ptprf[len+1] = '\0';
|
|
}
|
|
|
|
GetPrivateProfileString("Main", "Firm", "COM", firm, sizeof(firm), prawin);
|
|
ditta = atol(firm);
|
|
if (ditta > 0) sprintf(firm, "%05ldA", ditta);
|
|
_makepath(cprefix, NULL, __ptprf, firm, NULL);
|
|
}
|
|
}
|
|
|
|
return good;
|
|
}
|
|
|
|
BOOLEAN CPutPrawin(const char* pref)
|
|
{
|
|
const char* prawin = CGetPrawinName();
|
|
BOOLEAN good = WritePrivateProfileString("Main", "Firm", pref, prawin);
|
|
int disk = toupper(*prawin) - 'A';
|
|
WritePrivateProfileString("Main", "Study", __ptprf, prawin);
|
|
|
|
#if XVT_OS == XVT_OS_WIN32
|
|
if (GetDriveType("") == DRIVE_FIXED)
|
|
#else
|
|
if (GetDriveType(_getdrive() -1 ) == DRIVE_FIXED)
|
|
#endif
|
|
{
|
|
// Aggiorna anche il vecchio pathpref.ini, ma solo sui dischi locali:
|
|
// nei dischi remoti lo studio va cambiato modificando direttamente il file
|
|
FILE* pppi; // PathPrefPuntoIni
|
|
pppi = fopen("pathpref.ini", "w");
|
|
fprintf(pppi, "%s\n", __ptprf);
|
|
fclose(pppi);
|
|
}
|
|
return good;
|
|
}
|
|
|
|
#endif
|
|
|
|
#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)
|
|
*/
|
|
|
|
const char* CGetPref()
|
|
{
|
|
#ifdef DOS
|
|
if (!CGetPrawin())
|
|
#endif
|
|
{
|
|
const char* p = prefname();
|
|
FILE *f = fopen(p, "r");
|
|
|
|
if (f == NULL)
|
|
{
|
|
strcpy(cprefix, "");
|
|
}
|
|
else
|
|
{
|
|
if (fgets(cprefix, 42, f) != NULL)
|
|
{
|
|
int len;
|
|
for (len = LENGTH(cprefix)-1; len >= 0 && cprefix[len] <= ' '; len--)
|
|
cprefix[len] = '\0';
|
|
}
|
|
else
|
|
*cprefix = '\0';
|
|
fclose(f);
|
|
}
|
|
|
|
if (!pathpread)
|
|
{
|
|
FILE* f = fopen("pathpref.ini", "r");
|
|
pathpread = 1;
|
|
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 && __ptprf[len-1] != '\\' && __ptprf[len-1] != '/')
|
|
{
|
|
#ifdef DOS
|
|
strcat(__ptprf, "\\");
|
|
#else
|
|
strcat(__ptprf, "/");
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
else
|
|
*__ptprf = '\0';
|
|
fclose(f);
|
|
}
|
|
}
|
|
CPutPrawin(cprefix);
|
|
if (*__ptprf)
|
|
{
|
|
char* copy_of_prefix = strdup(cprefix);
|
|
strcpy(cprefix, __ptprf);
|
|
strcat(cprefix, copy_of_prefix);
|
|
free(copy_of_prefix);
|
|
}
|
|
}
|
|
|
|
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(const char* pref) /* stringa contenente il nuovo prefisso */
|
|
{
|
|
#ifdef DOS
|
|
CPutPrawin(pref);
|
|
#endif
|
|
{
|
|
FILE *f;
|
|
const int l = strlen(__ptprf);
|
|
if (l && strncmp(pref, __ptprf, l) == 0) pref += l;
|
|
f = fopen(prefname(), "w");
|
|
if (f != NULL)
|
|
{
|
|
fprintf(f, "%s\n", pref);
|
|
fclose(f);
|
|
}
|
|
else
|
|
message_box("Impossibile scrivere %s", prefname());
|
|
}
|
|
}
|
|
|
|
/*
|
|
@($) 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 char* s = NULL;
|
|
|
|
if (*name == '$')
|
|
{
|
|
name++;
|
|
return(CInsPref(name, NORDIR)) ;
|
|
}
|
|
else
|
|
{
|
|
if (*name == '%')
|
|
{
|
|
name++;
|
|
return(CInsPref(name, COMDIR)) ;
|
|
}
|
|
else
|
|
{
|
|
if (s == NULL)
|
|
s = malloc(_MAX_PATH);
|
|
if (strncmp(__ptprf, name, strlen(__ptprf)) != 0)
|
|
sprintf(s, "%s%s", __ptprf, name);
|
|
else
|
|
strcpy(s, 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 char* s = NULL;
|
|
if (s == NULL)
|
|
s = malloc(_MAX_PATH);
|
|
|
|
if (dirflg == NORDIR)
|
|
{
|
|
if (*cprefix == '\0')
|
|
strcpy(s, name);
|
|
else
|
|
// sprintf(s,"%s%c%s",cprefix, DIRSEP, name);
|
|
_makepath(s, NULL, cprefix, name, NULL);
|
|
}
|
|
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 char* fdst = NULL;
|
|
char *s1, *s2;
|
|
|
|
if (fdst == NULL)
|
|
fdst = malloc(_MAX_PATH);
|
|
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) ;
|
|
}
|