config.cpp Aggiustamenti minimi alla read_paragraph

config.h       Aggiunta funzione get_paragraph
isam.cpp       Eliminato warning per null_char = (char)0xFF;
relapp.cpp     Aggiunto supporto per transazioni mediante .ini
relapp.h       Aggiunte dichiarazioni per funzioni di gestione .ini
realtion.cpp   Aggiunta possibilita' di leggere e scrivere i TFieldref su .ini
relation.h     Aggiunte dichiarazioni dei metodi suddetti
rmov.h         Aggiunta dichiarazione dei NUMGIO
strings.cpp    Aggiunto operatore di copia tra TString_array
string.h       Dichiarato operatore di copia di array di stringhe


git-svn-id: svn://10.65.10.50/trunk@4243 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1997-03-28 12:07:58 +00:00
parent a7d9d26979
commit cfeded0c58
10 changed files with 242 additions and 40 deletions

View File

@ -128,16 +128,18 @@ void TConfig::_write_file()
::remove(temp); // Cancella file temporaneo
}
void TConfig::set_paragraph(const char* section)
bool TConfig::set_paragraph(const char* section)
{
bool ok = TRUE;
if (section != NULL && _paragraph != section)
{
if (_dirty)
_write_file();
_paragraph = section;
_dirty = FALSE;
_read_paragraph();
ok = _read_paragraph();
}
return ok;
}
// @doc EXTERNAL

View File

@ -121,9 +121,11 @@ public:
// @cmember Ritorna quanti elementi dell'array nominato sono presenti nella
// sezione indicata.
word items(const char* var, const char* section);
// @cmember Ritorna il nome del paragrafo attivo
const TString& get_paragraph() const { return _paragraph; }
// @cmember Setta il paragrafo passato come quello attivo
void set_paragraph(const char* par);
bool set_paragraph(const char* par);
// @cmember Riempie pl con la lista dei paragrafi
int list_paragraphs(TString_array& pl);

View File

@ -369,7 +369,7 @@ HIDDEN int __build_key(RecDes *recd, int numkey, RecType recin, char *key, bool
{
CHECKD(numkey > 0, "Can't build key ", numkey);
const char null_char = (char)0xFF;
const char null_char = -1;
key[0] = '\0';
if (numkey-- <= recd->NKeys)
{

View File

@ -308,6 +308,9 @@ void TRelation_application::query_mode(
set_mode(MODE_QUERY);
init_query_mode(*_mask);
}
if (_transaction.not_empty())
ini2query_mask();
}
@ -344,7 +347,11 @@ void TRelation_application::insert_mode()
set_mode(MODE_INS);
get_relation()->zero(); // Azzera tutta la relazione!
init_insert_mode(*_mask);
if (_transaction == "INSERT")
ini2insert_mask();
}
bool TRelation_application::modify_mode()
@ -664,22 +671,22 @@ bool TRelation_application::relation_remove()
// @comm Se la maschera e' in MODE_MOD non e' possibile cancellare il record e viene
// emesso un <f CHECK> di errore.
{
CHECK(_mask->mode() == MODE_MOD, "You can call remove in MODE_MOD only");
TRelation *r = get_relation();
CHECK(_mask->edit_mode(), "You can call remove in edit mode only");
TRelation& r = *get_relation();
r->restore_status();
r.restore_status();
if (protected_record(r->curr()))
if (protected_record(r.curr()))
return message_box("Registrazione non eliminabile");
if (yesno_box("Confermare l'eliminazione"))
if (_transaction == "DELETE" || yesno_box("Confermare l'eliminazione"))
{
r->restore_status();
r.restore_status();
const bool ok = remove();
if (ok)
set_limits();
else
return error_box("Errore di cancellazione %d", r->status());
return error_box("Errore di cancellazione %d", r.status());
}
return TRUE;
}
@ -708,7 +715,13 @@ bool TRelation_application::main_loop()
KEY k;
// Provoca l'autopremimento per il messaggio di LINK
if (_lnflag) _mask->send_key(K_AUTO_ENTER, 0);
if (_lnflag)
{
if (_transaction == "INSERT")
_mask->send_key(K_CTRL+'N', 0);
else
_mask->send_key(K_AUTO_ENTER, 0);
}
do
{
@ -717,6 +730,9 @@ bool TRelation_application::main_loop()
enable_menu_item(M_FILE_NEW, change);
// Dis/abilita cambio parametri
enable_menu_item(M_FILE_REVERT, change);
if (_mask->edit_mode() && _transaction == "DELETE")
_mask->send_key(K_CTRL+'E', 0);
k = _mask->run();
@ -739,7 +755,7 @@ bool TRelation_application::main_loop()
case K_SAVE:
if (save(FALSE))
{
if (_autoins_caller.not_empty())
if (_autoins_caller.not_empty() || _transaction.not_empty())
{
k = K_QUIT;
}
@ -772,12 +788,14 @@ bool TRelation_application::main_loop()
break;
case K_DEL:
if (relation_remove())
{
query_mode();
if (_autoins_caller.not_empty())
{
if (_lnflag) _recins = 0;
k = K_QUIT;
}
if (_autoins_caller.not_empty() || _transaction.not_empty())
{
if (_lnflag) _recins = 0;
k = K_QUIT;
}
}
break;
case K_F9:
if (_mask->query_mode() || save(TRUE))
@ -807,8 +825,10 @@ bool TRelation_application::main_loop()
default:
break;
}
if (err == NOERR || err == _islocked) modify_mode();
else query_mode();
if (err == NOERR || err == _islocked)
modify_mode();
else
query_mode();
}
break;
}
@ -824,12 +844,32 @@ bool TRelation_application::main_loop()
TMessage msg(autoins_caller(), _lnflag ? MSG_LN : MSG_AI, format("%ld", _recins));
msg.send();
}
if (_transaction.not_empty())
{
TConfig ini(_ini, "Transaction");
if (_recins >= 0)
{
ini.set("Result", "OK");
ini.set("Error", "0");
edit_mask2ini();
}
else
{
const int err = get_relation()->status();
ini.set("Result", err == NOERR ? "CANCEL" : "ERROR");
ini.set("Error", err);
}
}
return k != K_QUIT;
}
bool TRelation_application::filter()
{
{
if (parse_command_line())
return TRUE;
TMailbox mail;
TMessage* msg = mail.next_s(MSG_FS);
@ -963,7 +1003,6 @@ bool TRelation_application::filter()
}
void TRelation_application::set_link(TMask & m, const char * keyexpr)
{
CHECK(keyexpr != NULL, "Invalid expression");
TToken_string body(keyexpr);
@ -988,3 +1027,93 @@ void TRelation_application::set_link(TMask & m, const char * keyexpr)
}
bool TRelation_application::parse_command_line()
{
_ini = _transaction = "";
TFilename ini;
for (int i = argc()-1; i > 0; i--)
{
ini = argv(i);
ini.upper();
if (ini.left(2) == "-F" || ini.left(2) == "/F")
{
_ini = ini.mid(2);
break;
}
}
_lnflag = _ini.not_empty();
if (_lnflag)
{
TConfig cnf(_ini, "Transaction");
_transaction = cnf.get("Action");
_transaction.upper();
}
return _lnflag;
}
void TRelation_application::ini2query_mask()
{
if (_transaction.not_empty())
{
TConfig ini(_ini, format("%d", get_relation()->lfile().num()));
ini2mask(ini, *_mask, TRUE);
}
}
void TRelation_application::ini2insert_mask()
{
if (_transaction.not_empty())
{
TConfig ini(_ini, format("%d", get_relation()->lfile().num()));
ini2mask(ini, *_mask, FALSE);
}
}
void TRelation_application::ini2mask(TConfig& ini, TMask& m, bool query)
{
const TString defpar = ini.get_paragraph();
TString str;
for (int f = m.fields()-1; f >= 0; f--)
{
TMask_field& campo = m.fld(f);
if (campo.field())
{
if (!query || campo.in_key(1))
{
str = campo.field()->read(ini, defpar);
if (str.not_empty())
campo.set(str);
}
}
}
ini.set_paragraph(defpar);
}
void TRelation_application::edit_mask2ini()
{
if (_ini.not_empty())
{
TString head;
head.format("%d", get_relation()->lfile().num());
TConfig ini(_ini, head);
mask2ini(*_mask, ini);
}
}
void TRelation_application::mask2ini(TMask& m, TConfig& ini)
{
const TString defpar = ini.get_paragraph();
TString str;
for (int f = m.fields()-1; f >= 0; f--)
{
TMask_field& campo = m.fld(f);
if (campo.field() && campo.shown())
{
str = campo.get();
campo.field()->write(ini, defpar, str);
}
}
}

View File

@ -46,6 +46,11 @@ class TRelation_application : public TApplication
// @cmember:(INTERNAL) Messaggio da passare all'utente per indicare che e' stata fatta la rinumerazione
TString _renum_message;
// @cmember:(INTERNAL) Nome del file .ini con la transazione da eseguire
TString _ini;
// @cmember:(INTERNAL) Azione della transazione corrente
TString _transaction;
// @cmember:(INTERNAL) Setta i campi fissati da <md TRelation_application::_fixed>
bool filter();
// @cmember:(INTERNAL) Controlla se una chiave e' completa ed esiste su file
@ -184,6 +189,15 @@ protected:
// @cmember Impone il campo da utilizzare col bottone Ricerca
void set_search_field(short id)
{ _search_id = id;}
bool parse_command_line();
void ini2query_mask();
void ini2insert_mask();
void edit_mask2ini();
virtual void ini2mask(TConfig& ini, TMask& m, bool query);
virtual void mask2ini(TMask& m, TConfig& ini);
// @access Public Member
public:

View File

@ -1781,10 +1781,45 @@ void TFieldref::print_on(ostream& out) const
}
}
static TString buffer;
const char* TFieldref::read(TConfig& ini, const char* defpar) const
{
ini.set_paragraph(_id.empty() ? defpar : _id);
if (!ini.exist(_name))
return "";
buffer = ini.get(_name);
if (_from > 0 || _to > 0)
{
const int l = buffer.len();
if (_to < l && _to > 0) buffer.cut(_to);
if (_from > 0) buffer.ltrim(_from);
}
return buffer;
}
void TFieldref::write(TConfig& ini, const char* defpar, const char* val) const
{
if ((val == NULL || *val == '\0') && !ini.exist(_name))
return;
const char* para = _id.empty() ? defpar : _id;
if (_from > 0)
{
buffer = ini.get(_name, para);
buffer.overwrite(val, _from);
ini.set(_name, buffer, para);
}
else
{
ini.set(_name, val, para);
}
}
const char* TFieldref::read(const TRectype& rec) const
{
static TString buffer;
if (_fileid >= CNF_GENERAL)
{
TToken_string s(_name, '.');

View File

@ -536,14 +536,21 @@ public:
{ return _to; }
// @cmember Ritorna la lunghezza del campo di <p TRectype>
int len(const TRectype &rec) const;
// @cmember Cerca nella relazione il campo e ne ritorna il contenuto
const char* read(const TRelation&) const;
// @cmember Cerca nel record il campo e ne ritorna il contenuto
const char* read(const TRectype&) const;
// @cmember Cerca nella relazione il campo e vi scrive <p val>
void write(const char* val, TRelation&) const;
// @cmember Cerca nel record il campo e vi scrive <p val>
void write(const char* val, TRectype& rec) const;
// @cmember Cerca nella relazione il campo e ne ritorna il contenuto
const char* read(const TRelation&) const;
// @cmember Cerca nella relazione il campo e vi scrive <p val>
void write(const char* val, TRelation&) const;
// @cmember Cerca nel file .ini il campo e ne ritorna il valore
const char* read(TConfig& ini, const char* defpar) const;
// @cmember Cerca nel file .ini il campo e vi scrive <p val>
void write(TConfig& ini, const char* defpar, const char* val) const;
};
int name2log(const char* name);

View File

@ -19,6 +19,7 @@
#define RMV_ROWTYPE "ROWTYPE"
// To be removed soon
#define RMV_NUMGIO "NUMGIO"
#define RMV_RCONTR "RCONTR"
#endif

View File

@ -764,16 +764,16 @@ TString& TString::overwrite(
{
if (s)
{
const int l = len();
if (pos < 0) pos = l;
const int max = pos+strlen(s);
if (max > size()) resize(max, TRUE); // resize needed?
const int l = len();
if (pos < 0) pos = l;
const int max = pos+strlen(s);
if (max > size()) resize(max, TRUE); // resize needed?
const bool over = max > l; // beyond end of string?
for (int i = l; i < pos; i++) _str[i] = ' '; // space padding
for (; *s; s++) _str[pos++] = *s; // write
if (over) _str[pos] = '\0'; // end of string
}
const bool over = max > l; // beyond end of string?
for (int i = l; i < pos; i++) _str[i] = ' '; // space padding
for (; *s; s++) _str[pos++] = *s; // write
if (over) _str[pos] = '\0'; // end of string
}
return *this;
}
@ -1349,7 +1349,7 @@ void TToken_string::add(
// @syntax void add(int n, int pos = -1);
//
// @comm Permette, a seconda del parametro passato, di aggiungere alla Token
// string un nuovo elemnto gi completo del carattere di separazione
// string un nuovo elemnto gia' completo del carattere di separazione
{
if (s == NULL || *s == '\0') s = " ";
if (pos < 0)
@ -1484,6 +1484,17 @@ int TString_array::add(const TToken_string& s, int n)
return n;
}
const TString_array& TString_array::operator=(const TString_array& a)
{
destroy();
for (int i = a.last(); i >= 0; i = a.pred(i))
{
const TToken_string& s = a.row(i);
add(s, i);
}
return a;
}
// @doc EXTERNAL
// @mfunc Cerca una stringa nell'array

View File

@ -560,7 +560,8 @@ public:
// @cmember Restituisce il puntatore alla stringa n dell'array (NULL se non esiste)
TToken_string* rowptr(int n)
{ return (TToken_string*)objptr(n); }
// @cmember assegnamento di un array
const TString_array& operator=(const TString_array& a);
// @cmember Aggiunge una Token string all'array (chiama <mf TArray::add>)
int add(TToken_string* s, int n = -1)
{ return TArray::add(s, n); }