real.cpp Aggiunto _atold per 32 bit relation.cpp Tolti linkrecinst stdtypes.cpp Tolte variabili inutili di campo strings.* Aggiunto metodo TFilename::input tabutil.* Tolti linkrecinst git-svn-id: svn://10.65.10.50/trunk@6353 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			202 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			202 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <checks.h>
 | 
						|
 | 
						|
#define __TABUTIL_CPP
 | 
						|
#include <tabutil.h>
 | 
						|
#include <extcdecl.h>
 | 
						|
#include <scanner.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
int TTable::name2log(const char* n)
 | 
						|
{
 | 
						|
  return *n == '%' ? LF_TABCOM : (*n == '#' ? LF_TABGEN : LF_TAB);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
TTable::TTable(const char* tabname)
 | 
						|
: TLocalisamfile(name2log(tabname)), _cod(curr(), "COD")
 | 
						|
{
 | 
						|
  if ((*tabname == '%') || (*tabname == '#')) tabname++;
 | 
						|
  _tabname = tabname;
 | 
						|
  _tabname.upper();
 | 
						|
  curr().settab(_tabname);
 | 
						|
  _des_mod_loaded = FALSE;
 | 
						|
}
 | 
						|
 | 
						|
TTable::~TTable()
 | 
						|
{}
 | 
						|
 | 
						|
int TTable::skip(TRecnotype nrec, word lockop)
 | 
						|
 | 
						|
{
 | 
						|
  if (!nrec) return NOERR;
 | 
						|
  TBaseisamfile::skip(nrec, lockop);
 | 
						|
  if (_tabname != (const char *)_cod)
 | 
						|
  {
 | 
						|
    if (nrec > 0)
 | 
						|
    {
 | 
						|
      if (lockop == _lock) TBaseisamfile::reread(_unlock);
 | 
						|
      last(lockop);
 | 
						|
      setstatus(_iseof);
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {
 | 
						|
      if (lockop == _lock) TBaseisamfile::reread(_unlock);
 | 
						|
      first(lockop);
 | 
						|
      setstatus(_isbof);
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return status();
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
int TTable::_read(TRectype& rec, word op, word lockop)
 | 
						|
 | 
						|
{
 | 
						|
  if (op == _isfirst)
 | 
						|
  {
 | 
						|
    zero();
 | 
						|
    TBaseisamfile::_read(rec, _isgteq, lockop);
 | 
						|
    if (_tabname != (const char *)_cod)
 | 
						|
      setstatus(_isemptyfile);
 | 
						|
    if (bad())
 | 
						|
      zero();
 | 
						|
  }
 | 
						|
  else
 | 
						|
    if (op == _islast)
 | 
						|
    {
 | 
						|
      zero();
 | 
						|
      put("CODTAB", "\xFF");
 | 
						|
      TBaseisamfile::_read(rec, _isgteq);
 | 
						|
      if (!eof())
 | 
						|
        TBaseisamfile::_read(rec, _isprev, lockop);
 | 
						|
      else
 | 
						|
        setstatus(NOERR);
 | 
						|
      if (bof())
 | 
						|
        setstatus(NOERR);
 | 
						|
      if (_tabname != (const char *)_cod)
 | 
						|
        setstatus(_isemptyfile);
 | 
						|
      if (bad())
 | 
						|
        zero();
 | 
						|
    }
 | 
						|
    else
 | 
						|
      if (op == _isprev)
 | 
						|
      {
 | 
						|
        const TRecnotype nrec = recno();
 | 
						|
      
 | 
						|
        TBaseisamfile::_read(rec, _isprev, lockop);
 | 
						|
        if (_tabname != (const char *)_cod)
 | 
						|
        {
 | 
						|
          if (lockop == _lock) reread(_unlock);
 | 
						|
          readat(rec, nrec, lockop);
 | 
						|
          setstatus(_isbof);
 | 
						|
        }
 | 
						|
      }
 | 
						|
      else
 | 
						|
      if (op == _isnext)
 | 
						|
      {
 | 
						|
        const TRecnotype nrec = recno();
 | 
						|
      
 | 
						|
        TBaseisamfile::_read(rec, _isnext, lockop);
 | 
						|
        if (_tabname != (const char *)_cod)
 | 
						|
        {
 | 
						|
          if (lockop == _lock) reread(_unlock);
 | 
						|
          readat(rec, nrec, lockop);
 | 
						|
          setstatus(_iseof);
 | 
						|
        }
 | 
						|
      }
 | 
						|
      else
 | 
						|
      {
 | 
						|
        TBaseisamfile::_read(rec, op, lockop);
 | 
						|
        if (_tabname != (const char *)_cod)
 | 
						|
        {
 | 
						|
          if (lockop == _lock) reread(_unlock);
 | 
						|
          last(lockop);
 | 
						|
          setstatus(_iseof);
 | 
						|
        }             
 | 
						|
      }
 | 
						|
  return status();
 | 
						|
}
 | 
						|
 | 
						|
int TTable::_readat(TRectype& rec ,TRecnotype nrec, word lockop)
 | 
						|
 | 
						|
{
 | 
						|
  TBaseisamfile::_readat(rec, nrec, lockop);
 | 
						|
 | 
						|
  CHECKS(_tabname == (const char *)_cod, "Invalid position : Table ", (const char *)_tabname);
 | 
						|
  return status();
 | 
						|
}
 | 
						|
 | 
						|
void  TTable::load_module_description()
 | 
						|
{
 | 
						|
  // Setta il modulo al quale appartiene la tabella e la relativa descrizione.
 | 
						|
  // Cerca prima in RECDESC il relativo file di descrizione: D<TAB_NAME>.DES
 | 
						|
  // Se il file esiste, se il paragrafo [TabDescr] esiste e se esiste la
 | 
						|
  // variabile Module ne prende il valore.
 | 
						|
  // Se non si verificano le suddette condizioni procede come segue:
 | 
						|
  // cerca se esiste il file ??<TAB_NAME>.MSK tramite la funzione list_files(),
 | 
						|
  // ne estrae il module dai primi 2 caratteri e la descrizione dalla intestazione
 | 
						|
  // della prima pagina.
 | 
						|
  _des_mod_loaded = TRUE;
 | 
						|
  TFilename n;
 | 
						|
  n << "recdesc/d" << _tabname;
 | 
						|
  n.ext("des");
 | 
						|
  n.lower();
 | 
						|
  if (fexist(n))
 | 
						|
  {
 | 
						|
    TConfig des(n);
 | 
						|
    _module = des.get("Module","TabDescr");
 | 
						|
  }
 | 
						|
  n = "??tb";
 | 
						|
  n << _tabname;
 | 
						|
  n.ext("msk");
 | 
						|
  n.lower();
 | 
						|
 | 
						|
  TString_array f;
 | 
						|
  if (list_files(n, f) == 1)
 | 
						|
  {
 | 
						|
    n = f.row(0);
 | 
						|
    if (!fexist(n))
 | 
						|
      n.overwrite("ba",0);
 | 
						|
    if (fexist(n))
 | 
						|
    {
 | 
						|
      if (_module.empty())
 | 
						|
        _module = n.left(2);
 | 
						|
      TScanner m(n);
 | 
						|
      bool ok = TRUE;             
 | 
						|
      while (ok) 
 | 
						|
      {
 | 
						|
        const TString& l2 = m.line().left(2);
 | 
						|
        if (l2.empty())
 | 
						|
          ok = FALSE; 
 | 
						|
        else
 | 
						|
          if (l2 == "PA")
 | 
						|
            break;  
 | 
						|
      }  
 | 
						|
      if (ok)
 | 
						|
      {
 | 
						|
        const int apicia = m.token().find('"')+1;
 | 
						|
        const int apicic = m.token().find('"', apicia);
 | 
						|
        _description = m.token().sub(apicia, apicic);
 | 
						|
      }  
 | 
						|
    } 
 | 
						|
    else
 | 
						|
      _module = "ba";
 | 
						|
  }
 | 
						|
  else
 | 
						|
    _module = "ba";
 | 
						|
}
 | 
						|
 | 
						|
const char*  TTable::module()
 | 
						|
{
 | 
						|
  if (!_des_mod_loaded)
 | 
						|
    load_module_description();
 | 
						|
  return _module;
 | 
						|
}
 | 
						|
 | 
						|
const char*  TTable::description()
 | 
						|
{
 | 
						|
  if (!_des_mod_loaded)
 | 
						|
    load_module_description();
 | 
						|
  return _description;
 | 
						|
}
 |