1997-06-04 14:22:21 +00:00
|
|
|
|
// gestione livelli di giacenza e articoli
|
|
|
|
|
// oggetto movimento di magazzino
|
|
|
|
|
// funzione di ricostruzione saldi
|
1997-02-28 11:56:16 +00:00
|
|
|
|
|
1999-04-26 15:58:05 +00:00
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <execp.h>
|
2007-09-17 15:33:04 +00:00
|
|
|
|
#include <msksheet.h>
|
1997-06-24 17:06:52 +00:00
|
|
|
|
#include <tabutil.h>
|
1997-05-23 15:19:28 +00:00
|
|
|
|
|
1997-08-26 13:48:11 +00:00
|
|
|
|
#include "mglib.h"
|
1997-02-28 11:56:16 +00:00
|
|
|
|
|
|
|
|
|
// *******************************
|
|
|
|
|
// *******************************
|
1997-06-06 16:36:35 +00:00
|
|
|
|
#define MAXSIMBOLS 256
|
|
|
|
|
#define MAXSTATES 25
|
1998-02-18 13:46:52 +00:00
|
|
|
|
class TStateset
|
|
|
|
|
{
|
1997-06-06 16:36:35 +00:00
|
|
|
|
unsigned char _container[MAXSTATES];
|
|
|
|
|
int _current;
|
|
|
|
|
public:
|
|
|
|
|
TStateset & empty();
|
|
|
|
|
TStateset & enclose(int e);
|
|
|
|
|
TStateset & singleton(int e);
|
|
|
|
|
TStateset & cap(TStateset & s);
|
|
|
|
|
int get_first() ;
|
|
|
|
|
int get_next() ;
|
|
|
|
|
bool is_empty() const;
|
|
|
|
|
bool is_member(int e) const;
|
|
|
|
|
TStateset();
|
|
|
|
|
~TStateset() {};
|
|
|
|
|
};
|
|
|
|
|
|
1998-02-18 13:46:52 +00:00
|
|
|
|
struct TAutoma_state
|
|
|
|
|
{
|
1997-06-06 16:36:35 +00:00
|
|
|
|
short _transaction[MAXSIMBOLS];
|
1999-07-16 14:59:11 +00:00
|
|
|
|
TString80 * _label;
|
1997-06-06 16:36:35 +00:00
|
|
|
|
bool _final;
|
|
|
|
|
};
|
|
|
|
|
|
1997-07-07 10:27:25 +00:00
|
|
|
|
// *******************************
|
|
|
|
|
// *******************************
|
|
|
|
|
// automa per il riconoscimento di metacaratteri
|
|
|
|
|
#define EPSILON 0
|
|
|
|
|
#define FIRST_STATE 1
|
|
|
|
|
#define FIRST_NEMPTY_SYMBOL 1
|
|
|
|
|
|
1997-06-06 16:36:35 +00:00
|
|
|
|
// *******************************
|
|
|
|
|
// *******************************
|
|
|
|
|
// automa per il riconoscimento di metacaratteri
|
1998-02-18 13:46:52 +00:00
|
|
|
|
class TR_automa
|
|
|
|
|
{
|
1997-06-06 16:36:35 +00:00
|
|
|
|
TAutoma_state st[MAXSTATES];
|
|
|
|
|
short _maxstate;
|
|
|
|
|
protected:
|
|
|
|
|
TStateset union_of_closures(TStateset &s);
|
|
|
|
|
|
|
|
|
|
bool is_final(int statenum) const;
|
|
|
|
|
bool is_final(TStateset states) const;
|
|
|
|
|
|
|
|
|
|
TR_automa & set_label(int statenum, const char *label);
|
|
|
|
|
bool is_state(int statenum);
|
|
|
|
|
const char *label(int statenum);
|
|
|
|
|
int label2state(const char * label);
|
|
|
|
|
|
|
|
|
|
void del_trans(int statenum,unsigned char symbol);
|
|
|
|
|
int trans_to(int statenum,unsigned char symbol);
|
|
|
|
|
bool _isdeterministic;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
TR_automa & reset_state(int statenum=-1);
|
|
|
|
|
|
|
|
|
|
void add_tran(int statenum,unsigned char symbol,int next);// aggiunge una transizione
|
|
|
|
|
int add_state(const char * label);// aggiunge uno stato
|
|
|
|
|
TR_automa & set_final(int statenum,bool v=TRUE); // pone lo stato come finale
|
|
|
|
|
|
|
|
|
|
bool is_deterministic() {return _isdeterministic;}; //
|
|
|
|
|
bool recognized(const char * s); // tenta di riconoscere la stringa passata
|
|
|
|
|
|
|
|
|
|
TR_automa(TR_automa *a=NULL,bool makedet=FALSE); // duplica un automa (e lo rende deterministico)
|
|
|
|
|
~TR_automa();
|
1999-07-16 14:59:11 +00:00
|
|
|
|
static void set2label(const TStateset ss,TString & label);
|
|
|
|
|
static void label2set(const TString & label,TStateset & ss);
|
1997-06-06 16:36:35 +00:00
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
1997-02-28 11:56:16 +00:00
|
|
|
|
|
|
|
|
|
// *******************************
|
|
|
|
|
TStateset::TStateset()
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
empty();
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TStateset & TStateset::empty()
|
1998-02-18 13:46:52 +00:00
|
|
|
|
{
|
|
|
|
|
_current=0;
|
1997-06-02 10:32:22 +00:00
|
|
|
|
for (int i= 0; i< MAXSTATES; _container[i++]=0);
|
|
|
|
|
return *this;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TStateset & TStateset::enclose(int el)
|
1998-02-18 13:46:52 +00:00
|
|
|
|
{
|
|
|
|
|
if (el< MAXSTATES && el>=0)
|
1997-06-02 10:32:22 +00:00
|
|
|
|
_container[el]=1;
|
|
|
|
|
return *this;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TStateset & TStateset::singleton(int el)
|
1998-02-18 13:46:52 +00:00
|
|
|
|
{
|
|
|
|
|
empty();
|
1997-06-02 10:32:22 +00:00
|
|
|
|
_container[el]=1;
|
|
|
|
|
return *this;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TStateset & TStateset::cap(TStateset & s)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
for (int i= 0; i< MAXSTATES; i++)
|
|
|
|
|
_container[i]|=s._container[i];
|
|
|
|
|
return *this;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
1997-06-02 10:32:22 +00:00
|
|
|
|
|
1997-02-28 11:56:16 +00:00
|
|
|
|
bool TStateset::is_empty() const
|
|
|
|
|
{
|
1998-02-18 13:46:52 +00:00
|
|
|
|
for (int i= 0; i< MAXSTATES; i++)
|
|
|
|
|
if (_container[i])
|
|
|
|
|
return FALSE;
|
1997-06-02 10:32:22 +00:00
|
|
|
|
return TRUE;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TStateset::is_member(int e) const
|
|
|
|
|
{
|
1998-08-25 18:07:30 +00:00
|
|
|
|
return (e >= 0 && e < MAXSTATES) ? (_container[e] != 0) : FALSE;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TStateset::get_first()
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
_current=-1;
|
|
|
|
|
return(get_next());
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TStateset::get_next()
|
|
|
|
|
{
|
1998-02-18 13:46:52 +00:00
|
|
|
|
while (_current+1 < MAXSTATES)
|
1997-06-02 10:32:22 +00:00
|
|
|
|
if (_container[++_current])
|
|
|
|
|
return _current;
|
|
|
|
|
return (-1);
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// labels and states
|
|
|
|
|
bool TR_automa::is_state(int statenum)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
return(statenum<=_maxstate && statenum>0);
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// restituisce il numero dello stato con quella etichetta
|
|
|
|
|
int TR_automa::label2state(const char *label)
|
|
|
|
|
{
|
1998-02-18 13:46:52 +00:00
|
|
|
|
for (int s=0; s<_maxstate;s++)
|
1997-06-02 10:32:22 +00:00
|
|
|
|
if (*(st[s]._label)==label)
|
|
|
|
|
return(s+1);
|
|
|
|
|
return(0);
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// resetta uno stato dell'automa (senza eliminarlo)
|
|
|
|
|
TR_automa & TR_automa::reset_state(int statenum)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
int _from,_to;
|
1998-02-18 13:46:52 +00:00
|
|
|
|
if (statenum>0 && statenum<=_maxstate)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
_from=statenum;
|
|
|
|
|
_to=statenum;
|
1998-02-18 13:46:52 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
_maxstate=0;
|
|
|
|
|
_isdeterministic=TRUE;
|
|
|
|
|
_from=1;
|
|
|
|
|
_to=MAXSTATES;
|
|
|
|
|
}
|
1998-02-18 13:46:52 +00:00
|
|
|
|
for (int i=_from; i<=_to;i++)
|
1997-06-02 10:32:22 +00:00
|
|
|
|
{
|
1998-02-18 13:46:52 +00:00
|
|
|
|
set_label(i,"");
|
|
|
|
|
set_final(i,FALSE);
|
|
|
|
|
for (int j=0; j<MAXSIMBOLS;j++)
|
|
|
|
|
del_trans(i,j);
|
|
|
|
|
}
|
1997-06-02 10:32:22 +00:00
|
|
|
|
return *this;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// aggiunge una label
|
|
|
|
|
int TR_automa::add_state(const char * label)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
_maxstate++;
|
|
|
|
|
reset_state(_maxstate);
|
|
|
|
|
set_label(_maxstate,label);
|
|
|
|
|
return _maxstate;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TR_automa & TR_automa::set_label(int statenum, const char * name)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
(*(st[statenum-1]._label))=name;
|
|
|
|
|
return *this;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char * TR_automa::label(int statenum)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
return (*(st[statenum-1]._label));
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TR_automa::is_final(int statenum) const
|
1997-06-02 10:32:22 +00:00
|
|
|
|
{
|
|
|
|
|
return (st[statenum-1]._final);
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TR_automa::is_final(TStateset ss ) const
|
1997-06-02 10:32:22 +00:00
|
|
|
|
{
|
|
|
|
|
bool retv=FALSE;
|
|
|
|
|
int statenum=ss.get_first();
|
1998-02-18 13:46:52 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
retv=retv || is_final(statenum);
|
|
|
|
|
} while ((statenum=ss.get_next())>0);
|
|
|
|
|
|
|
|
|
|
return retv;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TR_automa & TR_automa::set_final(int statenum,bool v)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
st[statenum-1]._final=v;
|
|
|
|
|
return *this;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//*******************
|
|
|
|
|
// bows
|
|
|
|
|
void TR_automa::add_tran(int statenum, unsigned char symbol,int next)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
st[statenum-1]._transaction[symbol]=next;
|
|
|
|
|
if (symbol==EPSILON)
|
|
|
|
|
_isdeterministic=FALSE;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TR_automa::del_trans(int statenum, unsigned char symbol)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
st[statenum-1]._transaction[symbol]=0;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TR_automa::trans_to(int statenum, unsigned char symbol)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
return (st[statenum-1]._transaction[symbol]);
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-06-27 12:56:34 +00:00
|
|
|
|
// costruttore "di copi": crea un automa non deterministico
|
1997-02-28 11:56:16 +00:00
|
|
|
|
// (transazioni Epsilon ma nessuna transazione multipla)
|
1997-06-27 12:56:34 +00:00
|
|
|
|
// o ne crea l'equivalente automa deterministico
|
1997-02-28 11:56:16 +00:00
|
|
|
|
TR_automa::TR_automa(TR_automa * aa,bool makedet)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
TStateset arrival;
|
|
|
|
|
TStateset newstateset;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
TString80 tmplabel;
|
1997-06-02 10:32:22 +00:00
|
|
|
|
int curr_new_state;
|
|
|
|
|
|
1998-02-18 13:46:52 +00:00
|
|
|
|
for (int i=0; i<MAXSTATES;i++)
|
1999-07-16 14:59:11 +00:00
|
|
|
|
st[i]._label = new TString80;
|
1998-02-18 13:46:52 +00:00
|
|
|
|
if (aa==NULL)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
reset_state();
|
|
|
|
|
return;
|
|
|
|
|
}
|
1998-02-18 13:46:52 +00:00
|
|
|
|
if (makedet)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
reset_state();
|
|
|
|
|
// crea il primo stato nell'automa deterministico
|
|
|
|
|
set2label(aa->union_of_closures(newstateset.singleton(FIRST_STATE)),tmplabel);
|
|
|
|
|
add_state(tmplabel);
|
|
|
|
|
curr_new_state=FIRST_STATE;
|
1998-02-18 13:46:52 +00:00
|
|
|
|
while (is_state(curr_new_state))
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
// determina l'insieme degli stati dell'automa non deterministico
|
|
|
|
|
// che corrispondono a questo stato dell'automa deterministico
|
|
|
|
|
label2set(label(curr_new_state),newstateset);
|
|
|
|
|
// lo stato <20> finale se include stati finali dell'automa non det.
|
|
|
|
|
set_final(curr_new_state,aa->is_final(newstateset));
|
|
|
|
|
// determina tutte le transazioni
|
1998-02-18 13:46:52 +00:00
|
|
|
|
for (short symbol=FIRST_NEMPTY_SYMBOL; symbol<MAXSIMBOLS; symbol++)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
// determina lo stato di arrivo nell'automa det.:
|
1997-02-28 11:56:16 +00:00
|
|
|
|
// esso <20> pari all'insieme degli stati raggiunti col questo simbolo
|
|
|
|
|
// dal sottoinsieme degli stati dell'automa non det. che etichetta il nuovo stato nell'automa det.
|
|
|
|
|
arrival.empty();
|
1997-06-02 10:32:22 +00:00
|
|
|
|
int new_next,old_next;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
int old_state=newstateset.get_first() ;
|
1998-02-18 13:46:52 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
2004-03-16 07:43:45 +00:00
|
|
|
|
if ((old_next = aa->trans_to(old_state,(unsigned char)symbol)))
|
1997-06-02 10:32:22 +00:00
|
|
|
|
arrival.enclose(old_next);
|
1997-02-28 11:56:16 +00:00
|
|
|
|
} while ((old_state=newstateset.get_next())>0);
|
1998-02-18 13:46:52 +00:00
|
|
|
|
if (!arrival.is_empty())
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
// crea il nuovo arco nell'automa deterministico
|
|
|
|
|
set2label(aa->union_of_closures(arrival),tmplabel);
|
1998-02-18 13:46:52 +00:00
|
|
|
|
if (!(new_next=label2state(tmplabel)))
|
|
|
|
|
new_next=add_state(tmplabel);
|
1997-06-27 12:56:34 +00:00
|
|
|
|
add_tran(curr_new_state,(unsigned char)symbol,new_next);
|
1997-06-02 10:32:22 +00:00
|
|
|
|
}
|
1997-06-27 12:56:34 +00:00
|
|
|
|
} // loop symbol
|
1997-06-02 10:32:22 +00:00
|
|
|
|
curr_new_state++;
|
|
|
|
|
}
|
|
|
|
|
_isdeterministic=TRUE;
|
|
|
|
|
} // fine conversione
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*this=*aa;
|
1998-02-18 13:46:52 +00:00
|
|
|
|
for (int i=0; i<MAXSTATES;i++)
|
1997-06-02 10:32:22 +00:00
|
|
|
|
st[i]._label= aa->st[i]._label;
|
|
|
|
|
}
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TR_automa::~TR_automa()
|
|
|
|
|
{
|
1998-02-18 13:46:52 +00:00
|
|
|
|
for (int i=0; i<MAXSTATES;i++)
|
1997-06-02 10:32:22 +00:00
|
|
|
|
delete (st[i]._label);
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
void TR_automa::set2label(const TStateset ss,TString & label)
|
1997-02-28 11:56:16 +00:00
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
char coded[MAXSTATES];
|
2004-03-16 07:43:45 +00:00
|
|
|
|
unsigned char c = 0;
|
1998-02-18 13:46:52 +00:00
|
|
|
|
for (int i= 0; i< MAXSTATES; i++)
|
1997-06-02 10:32:22 +00:00
|
|
|
|
if (ss.is_member(i))
|
|
|
|
|
coded[c++]=(char)(i+'0');
|
|
|
|
|
coded[c]='\0';
|
|
|
|
|
label=coded;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
void TR_automa::label2set(const TString & label,TStateset & ss)
|
1997-02-28 11:56:16 +00:00
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
ss.empty();
|
|
|
|
|
for (int i= 0; i<= label.len();i++)
|
|
|
|
|
ss.enclose(int(label[i]-'0'));
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// costruisce l'unione delle epslilon closures
|
|
|
|
|
TStateset TR_automa::union_of_closures(TStateset &start_set)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
TStateset u_of_clo,clo;
|
|
|
|
|
int _state,_next;
|
|
|
|
|
bool toadd;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
u_of_clo.empty();
|
|
|
|
|
_state=start_set.get_first() ;
|
1998-02-18 13:46:52 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
// la chiusura <20> composta dallo stato e tutte le sue transazioni epsilon
|
|
|
|
|
clo.singleton(_state);
|
1998-02-18 13:46:52 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
int _state2=clo.get_first();
|
1998-02-18 13:46:52 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
toadd=((_next=trans_to(_state2,EPSILON)) && (!clo.is_member(_next)));
|
|
|
|
|
if (toadd)
|
|
|
|
|
clo.enclose(_next);
|
|
|
|
|
} while ((_state2=clo.get_next())>0);
|
|
|
|
|
} while (toadd) ;
|
|
|
|
|
u_of_clo.cap(clo);
|
|
|
|
|
} while ((_state=start_set.get_next())>0);
|
|
|
|
|
return u_of_clo;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// tenta di riconoscere la stringa passata
|
|
|
|
|
bool TR_automa::recognized(const char * t_str)
|
|
|
|
|
{
|
1998-02-18 13:46:52 +00:00
|
|
|
|
if (_isdeterministic)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
// ricoNosce la stringa di token
|
|
|
|
|
int curr_state=FIRST_STATE;
|
1998-02-18 13:46:52 +00:00
|
|
|
|
for (int i=0; t_str[i]; i++)
|
1997-06-02 10:32:22 +00:00
|
|
|
|
if (!(curr_state=trans_to(curr_state,t_str[i])))
|
1998-02-18 13:46:52 +00:00
|
|
|
|
return FALSE; // fine per mancanza di trasizioni
|
1997-06-02 10:32:22 +00:00
|
|
|
|
// fine per mancanza di caratteri di input della stringa
|
|
|
|
|
return (is_final(curr_state));
|
|
|
|
|
}
|
1998-02-18 13:46:52 +00:00
|
|
|
|
else
|
|
|
|
|
return FALSE; // ??
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// *******************************
|
|
|
|
|
// gestione di stringhe di metacaratteri
|
|
|
|
|
// *******************************
|
|
|
|
|
#define C_ESCAPEMETA '\\'
|
|
|
|
|
#define S_BLANK 1
|
|
|
|
|
#define S_DIGIT 2
|
|
|
|
|
#define S_LETTER 3
|
|
|
|
|
#define S_ANY 4
|
|
|
|
|
|
1997-07-07 10:27:25 +00:00
|
|
|
|
// *******************************
|
|
|
|
|
// *******************************
|
|
|
|
|
// riconoscimento di metacaratteri
|
|
|
|
|
class TR_automa;
|
|
|
|
|
|
|
|
|
|
|
1997-02-28 11:56:16 +00:00
|
|
|
|
bool TMetachar::recognized(const char * s)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
return(_au->recognized(s));
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TMetachar::add_tran(int s,unsigned char metasymbol, int nextstate)
|
|
|
|
|
{
|
1998-02-18 13:46:52 +00:00
|
|
|
|
unsigned char c;
|
|
|
|
|
switch (metasymbol)
|
|
|
|
|
{
|
|
|
|
|
case EPSILON:// blank
|
|
|
|
|
_au->add_tran(s,EPSILON,nextstate);
|
|
|
|
|
break;
|
|
|
|
|
case S_BLANK:// blank
|
|
|
|
|
_au->add_tran(s,' ',nextstate);
|
|
|
|
|
break;
|
|
|
|
|
case S_DIGIT:// cifra
|
|
|
|
|
for (c='0';c<='9';c++)
|
|
|
|
|
_au->add_tran(s,c,nextstate);
|
|
|
|
|
break;
|
|
|
|
|
case S_LETTER: // lettera
|
|
|
|
|
for (c='a';c<='z';c++)
|
|
|
|
|
_au->add_tran(s,c,nextstate);
|
|
|
|
|
for (c='A';c<='Z';c++)
|
|
|
|
|
_au->add_tran(s,c,nextstate);
|
|
|
|
|
break;
|
|
|
|
|
case S_ANY: // qualsiasi carattere
|
|
|
|
|
for (c=MAXSIMBOLS-1;c>=FIRST_NEMPTY_SYMBOL;c--)
|
|
|
|
|
_au->add_tran(s,c,nextstate);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
_au->add_tran(s,metasymbol,nextstate);
|
|
|
|
|
break;
|
|
|
|
|
}
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-07-07 10:27:25 +00:00
|
|
|
|
|
1997-02-28 11:56:16 +00:00
|
|
|
|
// restituisce la stringa di metacaratteri del linguaggio riconosciuto
|
|
|
|
|
const char * TMetachar::language() const
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
return(_language);
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TMetachar::set_language(const char * language)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
int s;
|
|
|
|
|
bool escaped_char=FALSE;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
TString label("-"),nextlabel("-");
|
2007-04-10 09:28:58 +00:00
|
|
|
|
|
1997-06-02 10:32:22 +00:00
|
|
|
|
_language=language;
|
|
|
|
|
// crea l'automa
|
|
|
|
|
_au->reset_state();
|
1998-02-18 13:46:52 +00:00
|
|
|
|
for (int i=0; language[i]; i++)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
label[0]='a'+i;
|
|
|
|
|
nextlabel[0]='a'+i+1;
|
1998-02-18 13:46:52 +00:00
|
|
|
|
if (language[i]!=C_ESCAPEMETA)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
if (!escaped_char)
|
|
|
|
|
{
|
|
|
|
|
// meta-caratteri e literal fuori set
|
|
|
|
|
s=_au->add_state(label);
|
1998-02-18 13:46:52 +00:00
|
|
|
|
switch (language[i])
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
case '#':// cifra o blank opzionale
|
|
|
|
|
add_tran(s,S_BLANK,s+1);
|
|
|
|
|
add_tran(s,'-',s+1);
|
|
|
|
|
add_tran(s,'+',s+1);
|
|
|
|
|
case '9':// cifra opzionale
|
|
|
|
|
add_tran(s,EPSILON,s+1);
|
|
|
|
|
case '0':// cifra obbligatoria
|
|
|
|
|
add_tran(s,S_DIGIT,s+1);
|
|
|
|
|
break;
|
|
|
|
|
case '?': // lettera opzionale
|
|
|
|
|
add_tran(s,EPSILON,s+1);
|
|
|
|
|
case 'L': // lettera obbligatoria
|
|
|
|
|
add_tran(s,S_LETTER,s+1);
|
|
|
|
|
break;
|
|
|
|
|
case 'a': // lettera o numero opzionale
|
|
|
|
|
add_tran(s,EPSILON,s+1);
|
|
|
|
|
case 'A': // lettera o numero obbligatorio
|
|
|
|
|
add_tran(s,S_LETTER,s+1);
|
|
|
|
|
add_tran(s,S_DIGIT,s+1);
|
|
|
|
|
break;
|
|
|
|
|
case 'c': // qualsiasi carattere opzionale
|
|
|
|
|
add_tran(s,EPSILON,s+1);
|
|
|
|
|
case '&': // qualsiasi carattere obbligatorio
|
|
|
|
|
add_tran(s,S_ANY,s+1);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
_au->add_tran(s,language[i],s+1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
1998-02-18 13:46:52 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
// escaped char
|
|
|
|
|
s=_au->add_state(label);
|
|
|
|
|
_au->add_tran(s,language[i],s+1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
escaped_char=(language[i]==C_ESCAPEMETA);
|
|
|
|
|
} // end of loop
|
|
|
|
|
// aggiunge lo stato finale
|
|
|
|
|
s=_au->add_state(nextlabel);
|
|
|
|
|
_au->set_final(s);
|
1997-02-28 11:56:16 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ricerca caratteri del set opzionale
|
|
|
|
|
bool TMetachar::has_opzchars(const char * pattern)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
int i=0;
|
|
|
|
|
bool next_literal=FALSE;
|
|
|
|
|
|
1998-02-18 13:46:52 +00:00
|
|
|
|
while (pattern[i])
|
|
|
|
|
{
|
2007-04-10 09:28:58 +00:00
|
|
|
|
if (!next_literal && strchr(opz_chars(),pattern[i]))
|
1997-06-02 10:32:22 +00:00
|
|
|
|
return(TRUE);
|
|
|
|
|
next_literal=(!next_literal && pattern[i]==C_ESCAPEMETA);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return(FALSE);
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ricerca caratteri del set opzionale
|
|
|
|
|
bool TMetachar::has_mandchars(const char * pattern)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
int i=0;
|
|
|
|
|
bool next_literal=FALSE;
|
|
|
|
|
|
1998-02-18 13:46:52 +00:00
|
|
|
|
while (pattern[i])
|
|
|
|
|
{
|
2007-04-10 09:28:58 +00:00
|
|
|
|
if (next_literal || strchr(mand_chars(),pattern[i]))
|
1997-06-02 10:32:22 +00:00
|
|
|
|
return(TRUE);
|
|
|
|
|
next_literal=(!next_literal && pattern[i]==C_ESCAPEMETA);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return(FALSE);
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stabilisce la lunghezza della stringa di metacaratteri
|
1997-07-24 14:47:52 +00:00
|
|
|
|
int TMetachar::maxstrlen(const char * pattern)
|
1997-02-28 11:56:16 +00:00
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
int i=0,l=0;
|
|
|
|
|
bool next_literal=FALSE;
|
|
|
|
|
|
1998-02-18 13:46:52 +00:00
|
|
|
|
while (pattern[i])
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
if (!next_literal)
|
|
|
|
|
l++;
|
|
|
|
|
next_literal=(!next_literal && pattern[i]==C_ESCAPEMETA);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return(l);
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// costruttore e distruttore
|
|
|
|
|
TMetachar::TMetachar ()
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
_au = new TR_automa;
|
|
|
|
|
set_language("");
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMetachar::TMetachar (const char * metastr)
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
// crea l'automa e lo trasforma in deterministico
|
|
|
|
|
// TR_automa auxau;
|
|
|
|
|
// set_language(&auxau,metastr);
|
|
|
|
|
_au=new TR_automa;
|
|
|
|
|
set_language(metastr);
|
1998-02-18 13:46:52 +00:00
|
|
|
|
if (!_au->is_deterministic())
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
TR_automa * auxau = new TR_automa(_au,TRUE);
|
|
|
|
|
delete _au;
|
|
|
|
|
_au=auxau;
|
|
|
|
|
}
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMetachar::~TMetachar ()
|
|
|
|
|
{
|
1997-06-02 10:32:22 +00:00
|
|
|
|
delete _au;
|
1997-02-28 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-07-24 14:47:52 +00:00
|
|
|
|
// **************************
|
|
|
|
|
// classe codice a livelli
|
|
|
|
|
|
1997-08-01 14:52:36 +00:00
|
|
|
|
|
1997-08-26 13:48:11 +00:00
|
|
|
|
void TCodice_livelli::update_firm()
|
|
|
|
|
{
|
|
|
|
|
_last_firm = prefix().get_codditta();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TCodice_livelli::test_firm()
|
|
|
|
|
{
|
|
|
|
|
long firm = prefix().get_codditta();
|
|
|
|
|
if (firm > 0 && firm != _last_firm)
|
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
update_firm(); // Lo dovrebbe gia' fare la init
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1997-08-01 14:52:36 +00:00
|
|
|
|
void TCodice_livelli::load(bool enabled, const char *tabname,const char *tabgrp)
|
|
|
|
|
{
|
1997-07-24 14:47:52 +00:00
|
|
|
|
TTable _tabformato(tabname);
|
|
|
|
|
|
1997-08-01 14:52:36 +00:00
|
|
|
|
_lev_enabled = enabled;
|
1997-07-24 14:47:52 +00:00
|
|
|
|
_last_level=0;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
for (int i=0; i < max_levels(); i++)
|
1997-08-26 13:48:11 +00:00
|
|
|
|
{
|
1997-12-05 11:44:55 +00:00
|
|
|
|
_name[i]="";
|
|
|
|
|
_code_length[i]=0;
|
|
|
|
|
_picture[i]="";
|
1998-08-25 18:07:30 +00:00
|
|
|
|
_autoinsert[i]=FALSE;
|
|
|
|
|
_codiceadata[i]=FALSE;
|
1997-12-05 11:44:55 +00:00
|
|
|
|
}
|
|
|
|
|
if (_lev_enabled)
|
|
|
|
|
{
|
2007-04-10 09:28:58 +00:00
|
|
|
|
int e = _tabformato.first();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
for (int i=0; e == NOERR && i < max_levels(); i++)
|
1997-08-26 13:48:11 +00:00
|
|
|
|
{
|
1997-07-24 14:47:52 +00:00
|
|
|
|
_name[i]=_tabformato.get("S0");
|
|
|
|
|
_picture[i]=_tabformato.get("S1");
|
1998-08-25 18:07:30 +00:00
|
|
|
|
_autoinsert[i]=_tabformato.get_bool("B0");
|
|
|
|
|
_codiceadata[i]=_tabformato.get_bool("B1");
|
1997-08-25 15:29:15 +00:00
|
|
|
|
_code_length[i]=TMetachar::maxstrlen(_picture[i]);
|
1997-07-24 14:47:52 +00:00
|
|
|
|
_last_level=i+1;
|
1997-12-05 11:44:55 +00:00
|
|
|
|
e = _tabformato.next();
|
1997-07-24 14:47:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1997-08-26 13:48:11 +00:00
|
|
|
|
|
|
|
|
|
if (_gruppi == NULL)
|
|
|
|
|
_gruppi = new TDecoder(tabgrp);
|
1997-07-24 14:47:52 +00:00
|
|
|
|
}
|
1997-07-07 10:27:25 +00:00
|
|
|
|
|
|
|
|
|
const char *TCodice_livelli::code_format(int levnum) const
|
|
|
|
|
{
|
1998-02-18 13:46:52 +00:00
|
|
|
|
if (levnum<0)
|
1998-11-04 18:04:26 +00:00
|
|
|
|
levnum=last_level();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1998-11-04 18:04:26 +00:00
|
|
|
|
CHECK(enabled(), "iu chent get de code format if levels ar disebold");
|
|
|
|
|
|
1997-07-24 14:47:52 +00:00
|
|
|
|
((TCodice_livelli *)this)->add_metachar(levnum);
|
1997-07-07 10:27:25 +00:00
|
|
|
|
return ((TMetachar*)_metachars.objptr(levnum-1))->language();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool TCodice_livelli::fit_to_format(const char *codepart,int levnum) const
|
|
|
|
|
{
|
1998-02-18 13:46:52 +00:00
|
|
|
|
if (levnum<0)
|
1998-11-04 18:04:26 +00:00
|
|
|
|
levnum=last_level();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1998-11-04 18:04:26 +00:00
|
|
|
|
CHECK(enabled(), "iu chent cec ueter de format fits if levels ar disebold");
|
1997-07-24 14:47:52 +00:00
|
|
|
|
((TCodice_livelli *)this)->add_metachar(levnum);
|
1997-07-07 10:27:25 +00:00
|
|
|
|
return ((TMetachar*)_metachars.objptr(levnum-1))->recognized(codepart);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TCodice_livelli::add_metachar(int levnum)
|
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1997-07-07 10:27:25 +00:00
|
|
|
|
if (_metachars.objptr(levnum-1)==NULL)
|
|
|
|
|
_metachars.add(new TMetachar(picture(levnum)),levnum-1);
|
|
|
|
|
}
|
|
|
|
|
|
1997-07-24 14:47:52 +00:00
|
|
|
|
const bool TCodice_livelli::enabled() const
|
|
|
|
|
{
|
|
|
|
|
return _lev_enabled && enabled(1);
|
1997-07-07 10:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool TCodice_livelli::enabled(int levnum) const
|
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
|
|
|
|
return (_lev_enabled && levnum<=max_levels() && levnum>0 && levnum<=_last_level);
|
1997-07-07 10:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-08-19 13:09:36 +00:00
|
|
|
|
const int TCodice_livelli::code_start(int levnum) const
|
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1997-08-26 13:48:11 +00:00
|
|
|
|
return packed_length(levnum-1)+1;
|
1997-08-19 13:09:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-08-25 15:29:15 +00:00
|
|
|
|
const int TCodice_livelli::code_length(int levnum) const
|
1997-08-21 07:21:00 +00:00
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1997-08-21 07:21:00 +00:00
|
|
|
|
/*
|
1999-04-06 15:34:39 +00:00
|
|
|
|
if (_lev_enabled && levnum <= max_levels() && levnum > 0)
|
1997-08-25 15:29:15 +00:00
|
|
|
|
return(_code_length[levnum-1]);
|
1997-07-07 10:27:25 +00:00
|
|
|
|
else
|
1997-08-21 07:21:00 +00:00
|
|
|
|
return(0);
|
|
|
|
|
*/
|
1998-11-04 18:04:26 +00:00
|
|
|
|
return enabled(levnum) ? _code_length[levnum-1] : 0;
|
1997-07-07 10:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-08-26 13:48:11 +00:00
|
|
|
|
const int TCodice_livelli::packed_length(int levnum) const
|
1997-07-07 10:27:25 +00:00
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() ,"I codici livello arrivano fino a max_levels()") ;
|
1997-07-07 10:27:25 +00:00
|
|
|
|
int start=0;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
for (int i=0; _lev_enabled && i<levnum && levnum<max_levels(); i++)
|
1997-08-25 15:29:15 +00:00
|
|
|
|
start+= _code_length[i];
|
1997-07-07 10:27:25 +00:00
|
|
|
|
return start;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString & TCodice_livelli::name(int levnum) const
|
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1998-11-04 18:04:26 +00:00
|
|
|
|
return(_name[levnum-1]);
|
1997-07-07 10:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
|
|
|
|
const bool TCodice_livelli::autoinsert(int levnum) const
|
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1998-11-04 18:04:26 +00:00
|
|
|
|
return _autoinsert[levnum-1];
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
1998-11-04 18:04:26 +00:00
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
const bool TCodice_livelli::codiceadata(int levnum) const
|
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1998-11-04 18:04:26 +00:00
|
|
|
|
return _codiceadata[levnum-1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool TCodice_livelli::autoinsert( int levnum, TMask_field & fld) const
|
|
|
|
|
{
|
|
|
|
|
TString16 value(fld.get());
|
|
|
|
|
if (!fit_to_format(value,levnum))
|
|
|
|
|
{
|
2004-05-18 10:44:57 +00:00
|
|
|
|
fld.error_box(FR("Codice non corrispondente al formato previsto (%s)"),(const char *)code_format(levnum));
|
1998-11-04 18:04:26 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
bool result = autoinsert( levnum, value);
|
|
|
|
|
fld.set_focus();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool TCodice_livelli::autoinsert(int levnum, TString & newcode) const
|
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1998-11-04 18:04:26 +00:00
|
|
|
|
const int result=group_search(newcode, levnum);
|
|
|
|
|
if (result == _iskeynotfound || result == _iseof || result == _iskeyerr)
|
|
|
|
|
{
|
|
|
|
|
TString grpcode;
|
|
|
|
|
grpcode << levnum;
|
|
|
|
|
grpcode << newcode;
|
|
|
|
|
// auto inserimento
|
|
|
|
|
TFilename ininame;
|
|
|
|
|
ininame.tempdir();
|
|
|
|
|
ininame.add("mglib01g.ini");
|
|
|
|
|
{
|
|
|
|
|
remove(ininame);
|
|
|
|
|
TConfig action(ininame,"Transaction");
|
|
|
|
|
action.set("Action","INSERT");
|
|
|
|
|
action.set("Firm", main_app().get_firm());
|
|
|
|
|
action.set("CODTAB", grpcode , "5");
|
|
|
|
|
}
|
|
|
|
|
TString cmd("mg0.exe -0 GCG -i");
|
|
|
|
|
cmd << ininame;
|
|
|
|
|
TExternal_app gesttab(cmd);
|
|
|
|
|
gesttab.run();
|
|
|
|
|
TConfig action(ininame,"Transaction");
|
|
|
|
|
if (action.get("Result")!="OK")
|
|
|
|
|
{
|
|
|
|
|
newcode="";
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
newcode=action.get("CODTAB","5").sub(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-07-07 10:27:25 +00:00
|
|
|
|
const TString & TCodice_livelli::picture(int levnum) const
|
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1998-11-04 18:04:26 +00:00
|
|
|
|
return(_picture[levnum-1]);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-28 14:29:23 +00:00
|
|
|
|
void TCodice_livelli::pack_maskgrpcodes(TString & pc, const TMask & mask, int field1, int levnum) const
|
1998-11-04 18:04:26 +00:00
|
|
|
|
{
|
|
|
|
|
for (int l=0 ; l<levnum; l++)
|
|
|
|
|
pack_grpcode(pc,mask.get(field1+l),1+l);
|
1997-07-07 10:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-28 14:29:23 +00:00
|
|
|
|
void TCodice_livelli::pack_grpcode(TString & pc, const TString &codlev, const int levnum) const
|
1997-07-07 10:27:25 +00:00
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1998-11-04 18:04:26 +00:00
|
|
|
|
pc.overwrite(codlev.left(_code_length[levnum-1]),packed_length(levnum-1));
|
1997-07-07 10:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-11-04 18:04:26 +00:00
|
|
|
|
|
2010-06-21 14:04:36 +00:00
|
|
|
|
const TString& TCodice_livelli::unpack_grpcode(const TString& pc, const int levnum) const
|
1997-07-07 10:27:25 +00:00
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1997-07-07 10:27:25 +00:00
|
|
|
|
int start=0;
|
1997-08-01 14:52:36 +00:00
|
|
|
|
for (int i=1; _lev_enabled && i<levnum; i++)
|
1997-08-25 15:29:15 +00:00
|
|
|
|
start+= _code_length[i-1];
|
1999-10-22 10:00:18 +00:00
|
|
|
|
if (start >= pc.len() || levnum < 1 || levnum > _last_level)
|
|
|
|
|
return EMPTY_STRING;
|
|
|
|
|
return pc.mid(start,levnum == _last_level ? -1 : _code_length[levnum-1]);
|
1997-07-07 10:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-11-04 18:04:26 +00:00
|
|
|
|
TString TCodice_livelli::build_tabcode(const TString & gcode, const int levnum) const
|
1997-07-07 10:27:25 +00:00
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1997-07-07 10:27:25 +00:00
|
|
|
|
TString valore;
|
|
|
|
|
valore << levnum;
|
1998-11-04 18:04:26 +00:00
|
|
|
|
valore << gcode;
|
1998-04-30 14:59:47 +00:00
|
|
|
|
if (!(_lev_enabled && valore.len()>1))
|
|
|
|
|
valore.cut(0);
|
|
|
|
|
return valore;
|
1997-07-07 10:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-11-04 18:04:26 +00:00
|
|
|
|
TString TCodice_livelli::build_tabcode_packed(const TString & pack, const int levnum) const
|
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
CHECK(levnum<=max_levels() && levnum>0,"I codici livello partono da 1") ;
|
1998-11-04 18:04:26 +00:00
|
|
|
|
return build_tabcode(unpack_grpcode(pack,levnum),levnum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString & TCodice_livelli::group_descr(const char * group_code, int levnum) const
|
|
|
|
|
{
|
|
|
|
|
return _gruppi->decode(build_tabcode(group_code,levnum));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString & TCodice_livelli::group_descr_packed(const char * packed_code, int levnum) const
|
|
|
|
|
{
|
|
|
|
|
return _gruppi->decode(build_tabcode_packed(packed_code,levnum));
|
|
|
|
|
}
|
1997-07-07 10:27:25 +00:00
|
|
|
|
|
1998-11-04 18:04:26 +00:00
|
|
|
|
const int TCodice_livelli::group_search(const char * group_code, int levnum) const
|
1997-07-07 10:27:25 +00:00
|
|
|
|
{
|
1998-11-04 18:04:26 +00:00
|
|
|
|
int res;
|
|
|
|
|
_gruppi->decode(build_tabcode(group_code,levnum)).empty();
|
|
|
|
|
res=_gruppi->io_result();
|
|
|
|
|
if (res!=NOERR)
|
|
|
|
|
_gruppi->discard(build_tabcode(group_code,levnum));
|
|
|
|
|
return res;
|
1997-07-07 10:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-11-04 18:04:26 +00:00
|
|
|
|
const int TCodice_livelli::group_search_packed(const char * packed_code, int levnum) const
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
1998-11-04 18:04:26 +00:00
|
|
|
|
_gruppi->decode(build_tabcode_packed(packed_code,levnum));
|
1998-08-25 18:07:30 +00:00
|
|
|
|
return _gruppi->io_result();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-07-24 14:47:52 +00:00
|
|
|
|
void TCodice_livelli::set_sheetcolumn(TSheet_field &fld_righe,int field, int lev) const
|
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
|
TMask& sm = fld_righe.sheet_mask();
|
|
|
|
|
TEdit_field& fld = sm.efield(field);
|
1997-08-26 13:48:11 +00:00
|
|
|
|
if (enabled(lev))
|
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
|
const TString& header = name(lev);
|
|
|
|
|
fld.set_prompt(header);
|
|
|
|
|
fld.show();
|
|
|
|
|
|
|
|
|
|
const int len = header.len() + 1;
|
|
|
|
|
const int f_len = code_length(lev);
|
|
|
|
|
fld_righe.set_column_header(field, header);
|
|
|
|
|
fld_righe.set_column_width(field, (len > f_len ? len : f_len) * 8);
|
1997-08-26 13:48:11 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
|
fld.hide();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
fld_righe.delete_column(field);
|
1997-07-24 14:47:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
void TCodice_livelli::set_sheet_columns(TSheet_field &sht, short dlg) const
|
|
|
|
|
{
|
|
|
|
|
for (int l = 0; l < max_levels(); l++)
|
|
|
|
|
set_sheetcolumn(sht, dlg+l, l+1);
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
|
void TCodice_livelli::set_mask_fields(TMask &m,int firstfield) const
|
|
|
|
|
{
|
|
|
|
|
for (int l = max_levels(); l>=1 ; l--)
|
|
|
|
|
set_mask_field(m,firstfield+l-1,l) ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TCodice_livelli::set_mask_field(TMask &m,int field, int l) const
|
|
|
|
|
{
|
|
|
|
|
if (enabled(l))
|
|
|
|
|
{
|
|
|
|
|
if (strlen(m.field(field).prompt()) > (unsigned int)name(l).len())
|
|
|
|
|
m.field(field).set_prompt(name(l));
|
|
|
|
|
}
|
|
|
|
|
m.field(field).show(enabled(l));
|
|
|
|
|
}
|
|
|
|
|
|
1997-08-26 13:48:11 +00:00
|
|
|
|
TCodice_livelli::TCodice_livelli()
|
|
|
|
|
: _last_firm(-1), _gruppi(NULL) {}
|
1997-07-24 14:47:52 +00:00
|
|
|
|
|
1997-08-26 13:48:11 +00:00
|
|
|
|
TCodice_livelli::~TCodice_livelli()
|
|
|
|
|
{
|
|
|
|
|
if (_gruppi)
|
|
|
|
|
delete _gruppi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TCodart_livelli::init()
|
1997-07-07 10:27:25 +00:00
|
|
|
|
{
|
1997-07-24 14:47:52 +00:00
|
|
|
|
TConfig mgconfig(CONFIG_DITTA, "mg");
|
1997-08-01 14:52:36 +00:00
|
|
|
|
load(mgconfig.get_bool("GESLIVART"), "FCA","GCA");
|
1997-07-07 10:27:25 +00:00
|
|
|
|
// imposta il riconoscimento dei caratteri del formato dell'ultima parte dell'articolo
|
1997-08-21 07:21:00 +00:00
|
|
|
|
TString80 format;
|
|
|
|
|
TTable tabfca("FCA");
|
|
|
|
|
if (tabfca.last() == NOERR)
|
|
|
|
|
format = tabfca.get("S1");
|
1997-08-26 13:48:11 +00:00
|
|
|
|
|
|
|
|
|
_metachars.destroy();
|
1997-07-07 10:27:25 +00:00
|
|
|
|
_metachars.add(new TMetachar(format),max(last_level()-1,0));
|
1997-08-26 13:48:11 +00:00
|
|
|
|
|
|
|
|
|
update_firm();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TCodart_livelli ::TCodart_livelli()
|
|
|
|
|
{
|
|
|
|
|
init();
|
1997-07-07 10:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-08-21 07:18:42 +00:00
|
|
|
|
|
1997-08-26 13:48:11 +00:00
|
|
|
|
TCodart_livelli::~TCodart_livelli()
|
1997-07-07 10:27:25 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
1997-08-26 13:48:11 +00:00
|
|
|
|
void TCodgiac_livelli::init()
|
1997-07-07 10:27:25 +00:00
|
|
|
|
{
|
1997-07-24 14:47:52 +00:00
|
|
|
|
TConfig mgconfig(CONFIG_DITTA, "mg");
|
1997-08-01 14:52:36 +00:00
|
|
|
|
load(mgconfig.get_bool("GESLIVGIAC"),"FCG","GCG");
|
1997-08-26 13:48:11 +00:00
|
|
|
|
update_firm();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TCodgiac_livelli::TCodgiac_livelli()
|
|
|
|
|
{
|
|
|
|
|
init();
|
1997-07-07 10:27:25 +00:00
|
|
|
|
}
|
1997-05-23 15:19:28 +00:00
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
|
static TCodgiac_livelli *_livelli_giacenza=NULL;
|
|
|
|
|
static TCodart_livelli *_livelli_articolo=NULL;
|
|
|
|
|
|
2005-09-19 12:45:16 +00:00
|
|
|
|
TCodgiac_livelli& livelli_giacenza()
|
1999-10-22 10:00:18 +00:00
|
|
|
|
{
|
|
|
|
|
if (_livelli_giacenza==NULL)
|
|
|
|
|
_livelli_giacenza=new TCodgiac_livelli();
|
|
|
|
|
return *_livelli_giacenza;
|
|
|
|
|
}
|
2005-09-19 12:45:16 +00:00
|
|
|
|
|
|
|
|
|
TCodart_livelli& livelli_articolo()
|
1999-10-22 10:00:18 +00:00
|
|
|
|
{
|
|
|
|
|
if (_livelli_articolo==NULL)
|
|
|
|
|
_livelli_articolo=new TCodart_livelli();
|
|
|
|
|
return *_livelli_articolo;
|
|
|
|
|
}
|
1997-06-04 14:22:21 +00:00
|
|
|
|
|
1997-08-21 07:18:42 +00:00
|
|
|
|
TMagazzini::TMagazzini() :
|
1998-04-30 14:59:47 +00:00
|
|
|
|
TRecord_cache("MAG") , _mgconfig(NULL),_last_firm(-1)
|
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMagazzini::~TMagazzini()
|
|
|
|
|
{
|
|
|
|
|
if (_mgconfig) delete _mgconfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TMagazzini::init()
|
1997-08-21 07:18:42 +00:00
|
|
|
|
{
|
1998-04-30 14:59:47 +00:00
|
|
|
|
if (_mgconfig) delete _mgconfig;
|
|
|
|
|
_mgconfig = new TConfig(CONFIG_DITTA, "mg");
|
|
|
|
|
_gestmag=_mgconfig->get_bool("GESMAG");
|
|
|
|
|
|
|
|
|
|
_gestdep=_gestmag && _mgconfig->get_bool("GESDEPOSITI");
|
|
|
|
|
_gestmultimag=_gestmag && _mgconfig->get_bool("GESMULTIMAG");
|
|
|
|
|
_gestubi=_mgconfig->get_char("GESUBICAZ");
|
|
|
|
|
|
1997-08-21 07:18:42 +00:00
|
|
|
|
TTable mag("MAG");
|
|
|
|
|
mag.first();
|
1998-04-30 14:59:47 +00:00
|
|
|
|
// look for standard mag & dep
|
1997-08-21 07:18:42 +00:00
|
|
|
|
while (!mag.eof() && !mag.get_bool("B1"))
|
|
|
|
|
mag.next();
|
1997-08-26 13:48:11 +00:00
|
|
|
|
if (!mag.eof())
|
|
|
|
|
{
|
|
|
|
|
const TString& codtab = mag.get("CODTAB");
|
|
|
|
|
_stdmag = codtab.left(3);
|
|
|
|
|
_stddep = codtab.mid(3);
|
1997-08-21 07:18:42 +00:00
|
|
|
|
}
|
1998-04-30 14:59:47 +00:00
|
|
|
|
else
|
|
|
|
|
_stdmag.cut(0);
|
|
|
|
|
|
|
|
|
|
_last_firm = prefix().get_codditta();
|
1997-08-21 07:18:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-04-30 14:59:47 +00:00
|
|
|
|
|
|
|
|
|
void TMagazzini::test_firm() const
|
|
|
|
|
{
|
|
|
|
|
long firm = prefix().get_codditta();
|
|
|
|
|
if (firm > 0 && firm != _last_firm)
|
|
|
|
|
((TMagazzini *)this)->init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMagazzini::gestmag(bool verbose) const
|
|
|
|
|
{
|
|
|
|
|
test_firm() ;
|
|
|
|
|
if (!_gestmag && verbose)
|
|
|
|
|
warning_box("La ditta corrente non gestisce il magazzino");
|
|
|
|
|
return _gestmag;
|
|
|
|
|
}
|
|
|
|
|
bool TMagazzini::gestdep() const
|
|
|
|
|
{
|
|
|
|
|
test_firm() ; return _gestdep;
|
|
|
|
|
}
|
|
|
|
|
bool TMagazzini::gestubi_man() const
|
|
|
|
|
{
|
|
|
|
|
test_firm() ; return _gestubi=='M';
|
|
|
|
|
}
|
|
|
|
|
bool TMagazzini::gestubi_tab() const
|
|
|
|
|
{
|
|
|
|
|
test_firm() ; return _gestubi=='T';
|
|
|
|
|
}
|
|
|
|
|
bool TMagazzini::gestmultimag() const
|
|
|
|
|
{
|
|
|
|
|
test_firm() ; return _gestmultimag;
|
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
const char * add_magcode(TString & str, const char * m)
|
|
|
|
|
{
|
|
|
|
|
str = m;
|
|
|
|
|
str.rpad(3);
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char * add_depcode(TString & str, const char * d)
|
|
|
|
|
{
|
|
|
|
|
str << d;
|
|
|
|
|
return str.trim();
|
|
|
|
|
}
|
2000-05-05 15:25:49 +00:00
|
|
|
|
|
|
|
|
|
bool riporta_ordinato()
|
|
|
|
|
{
|
|
|
|
|
static bool __riporta_ordinato = FALSE;
|
|
|
|
|
static long __firm = -883;
|
|
|
|
|
const long cur_firm = prefix().get_codditta();
|
|
|
|
|
|
|
|
|
|
if (__firm != cur_firm)
|
|
|
|
|
{
|
|
|
|
|
__firm = cur_firm;
|
|
|
|
|
TConfig c(CONFIG_DITTA, "mg");
|
|
|
|
|
__riporta_ordinato = c.get_bool("RIPORD");
|
|
|
|
|
}
|
|
|
|
|
return __riporta_ordinato;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char * get_magcode(TString & codmagdep)
|
|
|
|
|
{
|
|
|
|
|
return codmagdep.left(3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char * get_depcode(TString & codmagdep)
|
|
|
|
|
{
|
|
|
|
|
return codmagdep.mid(3);
|
|
|
|
|
}
|