608 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			608 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
| #define __CFILES_C /* fv */
 | |
| 
 | |
| #include        "cfiles.h"
 | |
| #include        "fldtypes.h"
 | |
| 
 | |
| int hashfun(const 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 (%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
 | |
| 
 | |
| 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
 | |
|     {      
 | |
|       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 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) ;
 | |
| }
 |