Modifica a BA1, aggiunti alcune features:
- creazione automatica di dir.gen e trc.gen (vuoti) in caso non esistano nel direttorio PRASSI. - aggiunta possibilita' di caricare tracciati nuovi oltre il numero prefissato da dir.gen. - corretti alcuni comportamenti anomali in conversione archivi (aggiunti piu' casi di controllo in cui il programma poteva piantarsi) Sono pronto anche per la crocifissione in sala mensa... git-svn-id: svn://10.65.10.50/trunk@4639 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
		
							parent
							
								
									0c393f206c
								
							
						
					
					
						commit
						f35f78fd63
					
				
							
								
								
									
										212
									
								
								ba/ba1100.cpp
									
									
									
									
									
								
							
							
						
						
									
										212
									
								
								ba/ba1100.cpp
									
									
									
									
									
								
							@ -1,5 +1,7 @@
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <share.h>
 | 
			
		||||
 | 
			
		||||
// Serve per GetFreeSpace
 | 
			
		||||
#define XVT_INCL_NATIVE
 | 
			
		||||
@ -33,6 +35,8 @@ struct direct
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define History_file "conv.his"
 | 
			
		||||
#define Dir_file     "dir.gen"
 | 
			
		||||
#define Trc_file     "trc.gen"
 | 
			
		||||
 | 
			
		||||
class TManutenzione_app : public TApplication
 | 
			
		||||
{
 | 
			
		||||
@ -67,7 +71,7 @@ protected:
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
  TManutenzione_app() : _browse(NULL), _rec(NULL), _mask(NULL), _firm(0), _level(0) {}
 | 
			
		||||
  TManutenzione_app();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
HIDDEN void build_filelist(const char *path, TArray & list)
 | 
			
		||||
@ -113,6 +117,52 @@ HIDDEN void build_filelist(const char *path, TArray & list)
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TManutenzione_app::TManutenzione_app() : _browse(NULL), _rec(NULL), _mask(NULL), _firm(0), _level(0)
 | 
			
		||||
{
 | 
			
		||||
  if (!fexist(Dir_file)) // controlla l'esistenza dei direttori standard (dir.gen e trc.gen)
 | 
			
		||||
  {                      // vengono creati se non esistono
 | 
			
		||||
    TDir d;
 | 
			
		||||
    FileDes* fd = d.filedesc();
 | 
			
		||||
    int handle;
 | 
			
		||||
    
 | 
			
		||||
    strcpy(fd->SysName,"$dir.gen");
 | 
			
		||||
    fd->LenR =160;
 | 
			
		||||
    fd->EOD = fd->EOX = 1L;
 | 
			
		||||
    fd->Flags = 0;
 | 
			
		||||
    strcpy(fd->Des ,"Directory");
 | 
			
		||||
    strcpy(fd->FCalc,"0");
 | 
			
		||||
    strcpy(fd->GenPrompt,"");
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN    
 | 
			
		||||
    if ((handle = sopen(Dir_file, O_RDWR|O_BINARY|O_CREAT,SH_DENYNO,S_IREAD|S_IWRITE)) != -1)
 | 
			
		||||
#else 
 | 
			
		||||
    if ((handle = open(Dir_file, O_RDWR|O_BINARY|O_CREAT,0666)) != -1)
 | 
			
		||||
#endif    
 | 
			
		||||
    {
 | 
			
		||||
      if (write( handle, (char*)fd, sizeof(FileDes)) == -1)
 | 
			
		||||
        fatal_box("Impossibile scrivere il file dir.gen per dati standard: errore %d",errno);
 | 
			
		||||
      close(handle);
 | 
			
		||||
    }
 | 
			
		||||
    else fatal_box("Impossibile creare il file dir.gen per dati standard: errore %d",errno);
 | 
			
		||||
  }
 | 
			
		||||
  if (!fexist(Trc_file))
 | 
			
		||||
  {
 | 
			
		||||
    TTrec r;
 | 
			
		||||
    RecDes* rd = r.rec();
 | 
			
		||||
    int handle;
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN    
 | 
			
		||||
    if ((handle = sopen(Trc_file, O_RDWR|O_BINARY|O_CREAT,SH_DENYNO,S_IREAD|S_IWRITE)) != -1)
 | 
			
		||||
#else 
 | 
			
		||||
    if ((handle = open(Trc_file, O_RDWR|O_BINARY|O_CREAT,0666)) != -1)
 | 
			
		||||
#endif    
 | 
			
		||||
    {
 | 
			
		||||
      if (write( handle, (char*)rd, sizeof(RecDes)) == -1)
 | 
			
		||||
        fatal_box("Impossibile scrivere il file trc.gen per dati standard: errore %d",errno);
 | 
			
		||||
      close(handle);
 | 
			
		||||
    }
 | 
			
		||||
    else fatal_box("Impossibile creare il file trc.gen per dati standard: errore %d",errno);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TManutenzione_app::do_print(TPrinter & p, TRec_sheet & r)
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
@ -703,6 +753,7 @@ void TManutenzione_app::update_dir()
 | 
			
		||||
    const bool is_firm = ds.is_firm();
 | 
			
		||||
    const bool to_create = (is_com ? ds.is_com() : ds.is_firm());
 | 
			
		||||
    
 | 
			
		||||
      
 | 
			
		||||
//    TString s(ds.name());
 | 
			
		||||
    TFilename fd(ds.filename());
 | 
			
		||||
 | 
			
		||||
@ -712,7 +763,18 @@ void TManutenzione_app::update_dir()
 | 
			
		||||
//    word len = ds.len();
 | 
			
		||||
//    prefix().set(pref);
 | 
			
		||||
    d.get(i);
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    TFilename fs(d.filename());
 | 
			
		||||
    if (strrchr(d.name(),'.') != NULL) // No extension please!
 | 
			
		||||
    {
 | 
			
		||||
      d.get(i, _nolock, _nordir, _sysdirop);
 | 
			
		||||
      TFilename ext(d.name());
 | 
			
		||||
      ext.ext("");
 | 
			
		||||
      d.set_name(ext);
 | 
			
		||||
      d.put(i, _nordir, _sysdirop);
 | 
			
		||||
    }
 | 
			
		||||
      
 | 
			
		||||
    
 | 
			
		||||
    if (!fexist(fs))
 | 
			
		||||
    {
 | 
			
		||||
@ -766,7 +828,19 @@ void TManutenzione_app::update_dir()
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    d.get(i, _nolock, _nordir, _sysdirop);
 | 
			
		||||
    if (to_create)
 | 
			
		||||
    
 | 
			
		||||
    bool cmn_file = FALSE;
 | 
			
		||||
    bool valid_file = i == LF_PCON || i == LF_CLIFO || i == LF_CAUSALI || i == LF_RCAUSALI;
 | 
			
		||||
    if (!is_com && valid_file  && d.is_com())
 | 
			
		||||
         cmn_file = TRUE; // Salta in questo caso:
 | 
			
		||||
                          // sto aggiornando le ditte, 
 | 
			
		||||
                          // il file in questione e' uno di quelli che possono essere comuni
 | 
			
		||||
                          // il file e' in comune
 | 
			
		||||
                          // Serve per evitare che durante l'aggiornamento i file
 | 
			
		||||
                          // PCON, CLIFO, CAUS ed RCAUS vengano spostati da COM alla
 | 
			
		||||
                          // prima ditta
 | 
			
		||||
    
 | 
			
		||||
    if (to_create && !cmn_file)
 | 
			
		||||
    {
 | 
			
		||||
/* non piu' necessario
 | 
			
		||||
     if (is_firm)
 | 
			
		||||
@ -777,7 +851,7 @@ void TManutenzione_app::update_dir()
 | 
			
		||||
      }
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
      if (flags < 10000L && fexist(fs) && (fd != fs))
 | 
			
		||||
      if (flags < 10000L && flags > -1L && fexist(fs) && (fd != fs))
 | 
			
		||||
      {
 | 
			
		||||
        bool ok = TRUE;
 | 
			
		||||
        TFilename path(fd.path());
 | 
			
		||||
@ -852,8 +926,7 @@ void TManutenzione_app::update_dir()
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      fs.ext("");
 | 
			
		||||
      if (fs.name()[0] == '\0') // Questo controlla se accidentalmente non e' piu' contenuto il nome del file
 | 
			
		||||
      if (!fexist(fs) && !valid_file) // Controlla eventali nomi di files non validi (ed es. %.dbf ecc.)
 | 
			
		||||
      {
 | 
			
		||||
        d.set(ds.name(), d.eox(), 0L, ds.des(), d.expr());
 | 
			
		||||
        towrite = TRUE;
 | 
			
		||||
@ -863,6 +936,9 @@ void TManutenzione_app::update_dir()
 | 
			
		||||
    {
 | 
			
		||||
      towrite = (TString(ds.des()) != d.des());
 | 
			
		||||
      if (towrite)
 | 
			
		||||
        if (!valid_file)
 | 
			
		||||
          d.set(ds.name(), d.eox(), d.eod(), ds.des(), d.expr());
 | 
			
		||||
        else
 | 
			
		||||
          strcpy((char *) d.des(), ds.des());
 | 
			
		||||
    }
 | 
			
		||||
    if (towrite)
 | 
			
		||||
@ -928,7 +1004,7 @@ void TManutenzione_app::convert_dir()
 | 
			
		||||
//    prefix().set(pref);
 | 
			
		||||
    if (ds.len() > 0)
 | 
			
		||||
    {
 | 
			
		||||
      if (flags < 10000L)
 | 
			
		||||
      if (flags < 10000L && flags > -1L)
 | 
			
		||||
      {
 | 
			
		||||
        TBaseisamfile b(i);
 | 
			
		||||
        const int module = abs((int)ds.flags());
 | 
			
		||||
@ -942,24 +1018,7 @@ void TManutenzione_app::convert_dir()
 | 
			
		||||
          else continue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        TSystemisamfile f(i);
 | 
			
		||||
  
 | 
			
		||||
        f.update(rs);
 | 
			
		||||
        
 | 
			
		||||
        if (f.status() == 8) // cio' significa che e' accaduto quasi l'irreparabile...
 | 
			
		||||
        {
 | 
			
		||||
          {
 | 
			
		||||
            TLocalisamfile u(LF_USER);
 | 
			
		||||
            u.zero(); u.put("USERNAME","PRASSI");
 | 
			
		||||
            if (u.read() == NOERR)
 | 
			
		||||
            {
 | 
			
		||||
              u.zero("AUTSTR");
 | 
			
		||||
              u.rewrite();
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          stop_run();
 | 
			
		||||
        }
 | 
			
		||||
        d.get(i, _nolock, _nordir, _sysdirop);
 | 
			
		||||
        //d.get(i, _nolock, _nordir, _sysdirop);
 | 
			
		||||
        bool to_create = (is_com ? d.is_com() : d.is_firm());
 | 
			
		||||
        const bool actual_create = to_create;
 | 
			
		||||
  
 | 
			
		||||
@ -978,10 +1037,30 @@ void TManutenzione_app::convert_dir()
 | 
			
		||||
          {
 | 
			
		||||
            TSystemisamfile f(i);
 | 
			
		||||
            set_autoload_new_files(actual_create); 
 | 
			
		||||
            f.build(10L);
 | 
			
		||||
            f.build(0L,rs);
 | 
			
		||||
            set_autoload_new_files(TRUE);
 | 
			
		||||
            // Anche se il file non esisteva, prosegue, perche' possono esserci conversioni
 | 
			
		||||
            // specificate in FCONV.INI
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        TSystemisamfile f(i);
 | 
			
		||||
 | 
			
		||||
        f.update(rs);
 | 
			
		||||
        if (f.status() == 8) // cio' significa che e' accaduto quasi l'irreparabile...
 | 
			
		||||
        {
 | 
			
		||||
          {
 | 
			
		||||
            TLocalisamfile u(LF_USER);
 | 
			
		||||
            u.zero(); u.put("USERNAME","PRASSI");
 | 
			
		||||
            if (u.read() == NOERR)
 | 
			
		||||
            {
 | 
			
		||||
              u.zero("AUTSTR");
 | 
			
		||||
              u.rewrite();
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          stop_run();
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      else // altrimenti se i flags sono oltre i fatidici 10000...
 | 
			
		||||
      {
 | 
			
		||||
@ -1026,47 +1105,82 @@ void TManutenzione_app::load_des()
 | 
			
		||||
  
 | 
			
		||||
  if (standard) // carica eventuali nuove descrizioni ed il nuovo livello archivi
 | 
			
		||||
  {
 | 
			
		||||
     // Cerca in RECDESC i files f[nnn].dir, la cui numerazione inizia da items+1
 | 
			
		||||
     // Cerca in RECDESC i files f[nnn].dir
 | 
			
		||||
     ifstream infile;
 | 
			
		||||
     TString ws;
 | 
			
		||||
     TFilename fn;
 | 
			
		||||
     TDir td;
 | 
			
		||||
     TDir td,new_dir;
 | 
			
		||||
     TTrec tr;
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN          
 | 
			
		||||
     struct _find_t  c_file;
 | 
			
		||||
#endif     
 | 
			
		||||
     int ln = items,last_newln = items;
 | 
			
		||||
     bool firstime = TRUE,ok;
 | 
			
		||||
     tr.zero();
 | 
			
		||||
     fn << DESCDIR << "/level.dir";
 | 
			
		||||
     
 | 
			
		||||
     if (fexist(fn))
 | 
			
		||||
     {
 | 
			
		||||
     {
 | 
			
		||||
       long fl;
 | 
			
		||||
         ifstream level(fn);
 | 
			
		||||
         level >> fl;
 | 
			
		||||
       infile.open(fn);
 | 
			
		||||
       infile >> fl;
 | 
			
		||||
       if (fl > flags) flags = fl;
 | 
			
		||||
       }
 | 
			
		||||
       infile.close();
 | 
			
		||||
       unlink(fn);
 | 
			
		||||
     }
 | 
			
		||||
     
 | 
			
		||||
     for (int xf=2;;xf++)
 | 
			
		||||
     // scandisce *.dir in RECDESC tramite dos_findfirst e _dos_findnext
 | 
			
		||||
     // eventuali "buchi" oltre al numero attuale di items vengono rimpiazzati 
 | 
			
		||||
     // con tracciati vuoti.
 | 
			
		||||
 | 
			
		||||
     fn.format("%s/f*.dir",DESCDIR);
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN     
 | 
			
		||||
     do 
 | 
			
		||||
     {
 | 
			
		||||
       fn = DESCDIR;
 | 
			
		||||
       fn << "/f" << xf;
 | 
			
		||||
       fn.ext("dir");
 | 
			
		||||
       if (!fexist(fn) && xf > items) // appena non ne trova uno oltre il numero di items ha finito
 | 
			
		||||
        break;
 | 
			
		||||
       // altrimenti lo carica nel direttorio standard,
 | 
			
		||||
       // aggiungendo un tracciato vuoto
 | 
			
		||||
       if (fexist(fn))
 | 
			
		||||
       if (firstime)
 | 
			
		||||
       {
 | 
			
		||||
         ifstream in(fn);
 | 
			
		||||
         in >> td;
 | 
			
		||||
         td.put(xf,_nordir,_sysdirop);
 | 
			
		||||
         if (xf > items)
 | 
			
		||||
           tr.put(xf);
 | 
			
		||||
         ok = _dos_findfirst(fn, _A_NORMAL, &c_file ) == 0;
 | 
			
		||||
         firstime = FALSE;
 | 
			
		||||
       }
 | 
			
		||||
       fn.format("%s/%s",DESCDIR,c_file.name);
 | 
			
		||||
       if (ok)
 | 
			
		||||
       {
 | 
			
		||||
         infile.open(fn);
 | 
			
		||||
         infile >> td;
 | 
			
		||||
         ln = td.num();
 | 
			
		||||
         const bool is_new = ln > last_newln; // memorizza l'ultimo record scritto come nuovo
 | 
			
		||||
         if (is_new) // aggiunge i files che mancano
 | 
			
		||||
         {
 | 
			
		||||
           for (int i = last_newln+1; i<ln; i++)
 | 
			
		||||
           {
 | 
			
		||||
             ws.format("$f%d",i);
 | 
			
		||||
             new_dir.set(ws,0L,-1L,"File non presente","");
 | 
			
		||||
             new_dir.put(i,_nordir,_sysdirop);
 | 
			
		||||
             tr.put(i);             
 | 
			
		||||
           }
 | 
			
		||||
           last_newln = ln;
 | 
			
		||||
         }
 | 
			
		||||
         td.put(ln,_nordir,_sysdirop);
 | 
			
		||||
         if (is_new)
 | 
			
		||||
           tr.put(ln);
 | 
			
		||||
         infile.close();
 | 
			
		||||
         unlink(fn);
 | 
			
		||||
       }
 | 
			
		||||
     xf--;
 | 
			
		||||
     d.eod() = (long)xf;
 | 
			
		||||
     d.eox() = (long)xf;
 | 
			
		||||
     } while( _dos_findnext( &c_file ) == 0 );
 | 
			
		||||
#endif     
 | 
			
		||||
     // Aggiorna il numero di files presenti in totale nel direttorio
 | 
			
		||||
     if (last_newln > items) // rialloca openf altrimenti la TPrefix::closeall() provoca un grazioso errore in applicazione
 | 
			
		||||
     {
 | 
			
		||||
       isfdptr *newopenf = new isfdptr[last_newln];
 | 
			
		||||
       for (int i = 0; i<last_newln; i++)
 | 
			
		||||
          newopenf[i] = (i<items) ? openf[i] : NULL;
 | 
			
		||||
       delete openf;
 | 
			
		||||
       openf = newopenf;          
 | 
			
		||||
     }
 | 
			
		||||
     d.eod() = (long)last_newln;
 | 
			
		||||
     d.eox() = (long)last_newln;
 | 
			
		||||
     d.flags() = flags;
 | 
			
		||||
     set_std_level(flags);
 | 
			
		||||
     d.put(LF_DIR,_nordir,_sysdirop);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -1172,7 +1286,7 @@ void TManutenzione_app::update()
 | 
			
		||||
  begin_wait();
 | 
			
		||||
  prefix().set("");
 | 
			
		||||
  load_des();
 | 
			
		||||
  prefix().set("com");
 | 
			
		||||
  prefix().set_codditta(0L);
 | 
			
		||||
/*  if (prefix().filelevel() <= 199502L)
 | 
			
		||||
  {
 | 
			
		||||
    TExternal_app app("bacnv 4 0");
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,10 @@
 | 
			
		||||
 | 
			
		||||
#include "ba1100.h"
 | 
			
		||||
 | 
			
		||||
extern "C"  {
 | 
			
		||||
  extern isfdptr* openf;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
TMask*       TRec_sheet::_mask = NULL;
 | 
			
		||||
 | 
			
		||||
void TDir_sheet::add ()
 | 
			
		||||
@ -27,6 +31,12 @@ void TDir_sheet::add ()
 | 
			
		||||
  d.zero();
 | 
			
		||||
  d.put(nitems, _nordir, _sysdirop);
 | 
			
		||||
  _items = nitems;
 | 
			
		||||
  
 | 
			
		||||
   isfdptr *newopenf = new isfdptr[_items];
 | 
			
		||||
   for (int i = 0; i<_items; i++)
 | 
			
		||||
      newopenf[i] = i<(_items-1) ? openf[i] : NULL;
 | 
			
		||||
   delete openf;
 | 
			
		||||
   openf = newopenf;          
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TDir_sheet::TDir_sheet(const char* title, byte buttons, const char* colonne)
 | 
			
		||||
 | 
			
		||||
@ -171,7 +171,10 @@ KEY  TEdit_file::edit_record(TRectype& rec, bool readonly)
 | 
			
		||||
    switch (rec.type(cp))
 | 
			
		||||
    {
 | 
			
		||||
    case _alfafld:
 | 
			
		||||
      m.add_string(nid++,curpage, s, 3, currow, len, "", len > 50 ? 50 : len);
 | 
			
		||||
      {
 | 
			
		||||
        TString16 f; f << flags << '_';
 | 
			
		||||
        m.add_string(nid++,curpage, s, 3, currow, len, f, len > 50 ? 50 : len);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case _intfld:
 | 
			
		||||
    case _longfld:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user