1994-09-19 09:50:07 +00:00
|
|
|
#include <applicat.h>
|
1996-11-12 14:53:09 +00:00
|
|
|
#include <colors.h>
|
1994-09-19 09:50:07 +00:00
|
|
|
#include <config.h>
|
1995-04-20 14:35:14 +00:00
|
|
|
#include <date.h>
|
|
|
|
#include <scanner.h>
|
1995-02-28 10:25:02 +00:00
|
|
|
#include <prefix.h>
|
1994-09-19 09:50:07 +00:00
|
|
|
#include <utility.h>
|
|
|
|
|
1996-11-12 14:53:09 +00:00
|
|
|
extern "C" { int rename(const char*, const char*); };
|
1994-09-19 09:50:07 +00:00
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
1995-05-26 10:16:03 +00:00
|
|
|
|
|
|
|
// @mfunc Legge i dati del paragrafo
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna i seguenti valori:
|
|
|
|
//
|
|
|
|
// @flag TRUE | Se il paragrafo c'ere
|
|
|
|
// @flag FALSE | Se il pragarafo non e' esitente
|
1994-09-19 09:50:07 +00:00
|
|
|
bool TConfig::_read_paragraph()
|
1995-05-26 10:16:03 +00:00
|
|
|
|
|
|
|
// @comm Legge il contenuto di tutte le variabili del paragrafo attivo
|
1994-09-19 09:50:07 +00:00
|
|
|
{
|
|
|
|
bool itwas = FALSE;
|
|
|
|
_data.destroy();
|
|
|
|
TScanner scan(_file);
|
|
|
|
if (scan.paragraph(_paragraph))
|
1994-09-22 16:47:50 +00:00
|
|
|
{
|
|
|
|
itwas = TRUE;
|
|
|
|
// populate array
|
1995-02-06 13:38:34 +00:00
|
|
|
TString key, val;
|
1994-09-22 16:47:50 +00:00
|
|
|
for (;;)
|
1994-09-19 09:50:07 +00:00
|
|
|
{
|
1995-02-06 13:38:34 +00:00
|
|
|
const TString& l = scan.line();
|
|
|
|
if (l == "" || l[0] == '[') break; // Fine paragrafo
|
|
|
|
if (l[0] == '#' || l[0] == '/') continue; // Riga di commento
|
|
|
|
|
|
|
|
const int ind = l.find('=');
|
1994-09-22 16:47:50 +00:00
|
|
|
if (ind == -1)
|
|
|
|
{
|
1996-05-14 10:08:10 +00:00
|
|
|
error_box("Errore configurazione:\n file %s, vicino alla riga %u\n %s",
|
1995-02-06 13:38:34 +00:00
|
|
|
(const char*)_file, scan.linenum(), (const char*)l);
|
1994-09-22 16:47:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = l.left(ind); key.trim();
|
|
|
|
val = l.mid(ind+1); val.trim();
|
1995-02-06 13:38:34 +00:00
|
|
|
|
|
|
|
if (val[0] == '%')
|
|
|
|
{
|
|
|
|
if (val == "%yr%") val.format("%04d", TDate(TODAY).year()); else
|
1995-06-01 09:09:30 +00:00
|
|
|
if (val == "%frm%") val.format("%05ld", prefix().get_codditta());
|
1995-02-06 13:38:34 +00:00
|
|
|
}
|
1994-09-22 16:47:50 +00:00
|
|
|
// sostituzione abilitata
|
|
|
|
_data.add(key,val,TRUE);
|
1994-09-19 09:50:07 +00:00
|
|
|
}
|
1994-09-22 16:47:50 +00:00
|
|
|
}
|
1994-09-19 09:50:07 +00:00
|
|
|
return itwas;
|
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
// @mfunc Scrive i dati del paragrafo
|
|
|
|
void TConfig::_write_paragraph(
|
|
|
|
ofstream& out) // @parm Indirizzo dell'utput sul quale scrivere il paragrafo
|
|
|
|
|
1996-11-12 14:53:09 +00:00
|
|
|
// @comm Scrive sullo stream <p>out le variabili del paragrafo attivo.
|
|
|
|
{
|
|
|
|
if (_data.items() > 0) // Inutile scrivere paragrafi vuoti!
|
1994-09-22 16:47:50 +00:00
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
out << '[' << _paragraph << ']' << endl;
|
1997-10-30 16:14:49 +00:00
|
|
|
/*
|
1996-11-12 14:53:09 +00:00
|
|
|
_data.restart();
|
|
|
|
for (THash_object* o = _data.get_hashobj(); o; o = _data.get_hashobj())
|
|
|
|
out << o->key() << " = " << (TString&)(o->obj()) << '\n';
|
1997-10-30 16:14:49 +00:00
|
|
|
*/
|
|
|
|
TString_array a; list_variables(a, TRUE);
|
|
|
|
a.sort();
|
|
|
|
for (int i = 0; i < a.items(); i++)
|
|
|
|
{
|
|
|
|
TToken_string& row = a.row(i);
|
|
|
|
out << row.get(0) << " = ";
|
|
|
|
out << row.get() << endl;
|
|
|
|
}
|
|
|
|
|
1996-11-12 14:53:09 +00:00
|
|
|
out << endl;
|
|
|
|
}
|
1994-09-19 09:50:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TConfig::_write_file()
|
1995-05-26 10:16:03 +00:00
|
|
|
|
1994-09-19 09:50:07 +00:00
|
|
|
{
|
|
|
|
ifstream in(_file);
|
|
|
|
TFilename temp;
|
1994-12-13 13:51:04 +00:00
|
|
|
temp.temp("cnf");
|
1994-09-19 09:50:07 +00:00
|
|
|
ofstream out(temp);
|
|
|
|
|
1996-05-14 10:08:10 +00:00
|
|
|
TString l(1024);
|
1996-11-12 14:53:09 +00:00
|
|
|
TString cnf; cnf << '[' << _paragraph << ']';
|
1995-03-22 09:07:04 +00:00
|
|
|
|
1996-11-12 14:53:09 +00:00
|
|
|
bool skip = FALSE, done = FALSE, skip_empty = TRUE;
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
|
|
while (!in.eof())
|
1994-09-22 16:47:50 +00:00
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
in.getline((char*)(const char*)l, l.size());
|
1994-09-22 16:47:50 +00:00
|
|
|
l.trim();
|
|
|
|
|
|
|
|
if (cnf == l)
|
1994-09-19 09:50:07 +00:00
|
|
|
{
|
1994-09-22 16:47:50 +00:00
|
|
|
// write paragraph and all variables
|
|
|
|
_write_paragraph(out);
|
1996-11-12 14:53:09 +00:00
|
|
|
skip = skip_empty = done = TRUE;
|
1994-09-22 16:47:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
if (skip)
|
|
|
|
skip = l[0] != '[';
|
|
|
|
if (!skip)
|
|
|
|
{
|
|
|
|
const bool empty = l.empty();
|
|
|
|
if (!empty || !skip_empty)
|
|
|
|
out << l << endl;
|
|
|
|
skip_empty = empty;
|
|
|
|
}
|
1994-09-19 09:50:07 +00:00
|
|
|
}
|
1994-09-22 16:47:50 +00:00
|
|
|
}
|
1994-09-19 09:50:07 +00:00
|
|
|
// new paragraph
|
|
|
|
if (!done) _write_paragraph(out);
|
|
|
|
|
|
|
|
out.close(); in.close();
|
1995-01-27 18:00:47 +00:00
|
|
|
|
1996-07-08 07:25:19 +00:00
|
|
|
if (fexist(_file))
|
|
|
|
{
|
|
|
|
while (access(_file, 02) != 0)
|
|
|
|
message_box("Il file %s e' gia' in uso", (const char*)_file);
|
|
|
|
}
|
1994-12-13 13:51:04 +00:00
|
|
|
fcopy(temp, _file); // Copia dalla tempdir al nuovo .ini
|
1996-11-21 08:01:39 +00:00
|
|
|
::remove(temp); // Cancella file temporaneo
|
1994-09-19 09:50:07 +00:00
|
|
|
}
|
|
|
|
|
1997-03-28 12:07:58 +00:00
|
|
|
bool TConfig::set_paragraph(const char* section)
|
1994-09-19 09:50:07 +00:00
|
|
|
{
|
1997-03-28 12:07:58 +00:00
|
|
|
bool ok = TRUE;
|
1996-11-12 14:53:09 +00:00
|
|
|
if (section != NULL && _paragraph != section)
|
1994-09-22 16:47:50 +00:00
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
if (_dirty)
|
|
|
|
_write_file();
|
1994-09-22 16:47:50 +00:00
|
|
|
_paragraph = section;
|
|
|
|
_dirty = FALSE;
|
1997-03-28 12:07:58 +00:00
|
|
|
ok = _read_paragraph();
|
1994-09-22 16:47:50 +00:00
|
|
|
}
|
1997-03-28 12:07:58 +00:00
|
|
|
return ok;
|
1994-09-19 09:50:07 +00:00
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
// @mfunc Controlla se esite una variabile nel paragrafo attivo
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna i seguenti valori:
|
|
|
|
//
|
|
|
|
// @flag TRUE | Se la variabile esite
|
|
|
|
// @flag FALSE | Se la variabile non esite
|
|
|
|
bool TConfig::exist(
|
|
|
|
const char* var, // @parm Nome della variabile
|
|
|
|
int index) // @parm Indice dell'elemento dell'array (default -1)
|
|
|
|
|
|
|
|
// @comm Se <p index> e' <gt>= 0 viene costruito il nome dell'elemento
|
|
|
|
// dell'array da cercare, diversamente viene cercata la variabile
|
|
|
|
// normale passata in <p var>.
|
1994-10-26 12:23:12 +00:00
|
|
|
{
|
1995-03-22 09:07:04 +00:00
|
|
|
if (index >= 0)
|
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
TString key(80);
|
|
|
|
key << var << '(' << index << ')';
|
|
|
|
return _data.is_key(key);
|
1995-03-22 09:07:04 +00:00
|
|
|
}
|
|
|
|
return _data.is_key(var);
|
1994-10-26 12:23:12 +00:00
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1996-11-12 14:53:09 +00:00
|
|
|
// @mfunc Elimina una variabile dal paragrafo corrente
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna i seguenti valori:
|
|
|
|
//
|
|
|
|
// @flag TRUE | Se la variabile esiteva
|
|
|
|
// @flag FALSE | Se la variabile non esiteva
|
|
|
|
bool TConfig::remove(
|
|
|
|
const char* var, // @parm Nome della variabile
|
|
|
|
int index) // @parm Indice dell'elemento dell'array (default -1)
|
|
|
|
|
|
|
|
// @comm Se <p index> e' <gt>= 0 viene costruito il nome dell'elemento
|
|
|
|
// dell'array da cercare, diversamente viene cercata la variabile
|
|
|
|
// normale passata in <p var>.
|
|
|
|
{
|
|
|
|
TString key(var);
|
|
|
|
if (index >= 0)
|
|
|
|
key << '(' << index << ')';
|
|
|
|
const bool ok = _data.remove(key);
|
|
|
|
if (ok) _dirty = TRUE;
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
// @mfunc Ritorna il valore della variabile nella sezione corrente o in
|
|
|
|
// quella specificata
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna la stringa contenuta nella variabile, se questa esiste, altrimenti
|
|
|
|
// il valore di default che dovrebbe assumere determinato dal parametro
|
|
|
|
// <p def>
|
|
|
|
TString& TConfig::get(
|
|
|
|
const char* var, // @parm Variabile della quale ritornare il valore
|
|
|
|
const char* section, // @parm Sezione della varaibile (default NULL)
|
|
|
|
int index, // @parm Eventuale indice della varaibailie (default -1)
|
|
|
|
const char* def) // @parm Valore default della varaibile (default "")
|
|
|
|
|
|
|
|
// @comm Passando <p index> <gt>= 0 viene appeso al nome della variabile per
|
|
|
|
// implementare un array.
|
|
|
|
// <nl>Il paragrafo passato in <p section> diventa quello attivo.
|
|
|
|
//
|
|
|
|
// @xref <mf TConfig::get_long> <mf TConfig::get_int> <mf TConfig::get_bool>
|
|
|
|
// <mf TConfig::get_color>
|
1994-09-19 09:50:07 +00:00
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
if (section) // Cambia paragrafo se necessario
|
|
|
|
set_paragraph(section);
|
1995-03-22 09:07:04 +00:00
|
|
|
|
1996-11-12 14:53:09 +00:00
|
|
|
TString* val;
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
TString v(80);
|
|
|
|
v << var << '(' << index << ')';
|
|
|
|
val = (TString*)_data.objptr(v);
|
1995-03-22 09:07:04 +00:00
|
|
|
}
|
1996-11-12 14:53:09 +00:00
|
|
|
else
|
|
|
|
val = (TString*)_data.objptr(var);
|
1994-09-19 09:50:07 +00:00
|
|
|
|
1996-11-12 14:53:09 +00:00
|
|
|
if (val == NULL) // Se non la trova inserisci il default
|
1995-01-05 17:50:40 +00:00
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
set(var, def, section, TRUE, index);
|
|
|
|
val = &get(var, NULL, index);
|
1995-01-05 17:50:40 +00:00
|
|
|
}
|
1996-11-12 14:53:09 +00:00
|
|
|
|
|
|
|
return *val;
|
1994-09-19 09:50:07 +00:00
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
// @mfunc Ritorna il valore della variabile nella sezione corrente o in
|
|
|
|
// quella specificata
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna il numero contenuto nella variabile, se questa esiste, altrimenti
|
|
|
|
// il valore di default che dovrebbe assumere determinato dal parametro
|
|
|
|
// <p def>
|
|
|
|
long TConfig::get_long(
|
|
|
|
const char* var, // @parm Variabile della quale ritornare il valore
|
|
|
|
const char* section, // @parm Sezione della varaibile (default NULL)
|
|
|
|
int index, // @parm Eventuale indice della varaibailie (default -1)
|
|
|
|
long def) // @parm Valore default della varaibile (default 0L)
|
|
|
|
|
|
|
|
// @comm Passando <p index> <gt>= 0 viene appeso al nome variabile per
|
|
|
|
// implementare un array.
|
|
|
|
// <nl>Il paragrafo passato in <p section> diventa quello attivo.
|
|
|
|
//
|
|
|
|
// @xref <mf TConfig::get> <mf TConfig::get_int> <mf TConfig::get_bool>
|
|
|
|
// <mf TConfig::get_color>
|
1995-01-02 09:33:00 +00:00
|
|
|
{
|
|
|
|
const char* n = get(var,section,index);
|
1995-01-05 17:50:40 +00:00
|
|
|
if (*n)
|
|
|
|
def = atol(n);
|
|
|
|
else
|
1996-05-08 11:09:13 +00:00
|
|
|
{
|
|
|
|
TString16 d; d << def;
|
|
|
|
set(var, d, section, TRUE, index);
|
|
|
|
}
|
1995-01-05 17:50:40 +00:00
|
|
|
return def;
|
1995-11-22 13:40:15 +00:00
|
|
|
|
1994-09-19 09:50:07 +00:00
|
|
|
}
|
1996-02-05 19:00:53 +00:00
|
|
|
|
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-11-22 13:40:15 +00:00
|
|
|
// @mfunc Ritorna il valore della variabile nella sezione corrente o in
|
|
|
|
// quella specificata
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna il primo carattere della variabile, se questa esiste, altrimenti
|
|
|
|
// il valore di default che dovrebbe assumere determinato dal parametro
|
|
|
|
// <p def>
|
|
|
|
char TConfig::get_char(
|
|
|
|
const char* var, // @parm Variabile della quale ritornare il valore
|
|
|
|
const char* section, // @parm Sezione della varaibile (default NULL)
|
|
|
|
int index, // @parm Eventuale indice della varaibailie (default -1)
|
|
|
|
char def) // @parm Valore default della varaibile (default ' ')
|
|
|
|
|
|
|
|
// @comm Passando <p index> <gt>= 0 viene appeso al nome variabile per
|
|
|
|
// implementare un array.
|
|
|
|
// <nl>Il paragrafo passato in <p section> diventa quello attivo.
|
|
|
|
//
|
|
|
|
// @xref <mf TConfig::get> <mf TConfig::get_int> <mf TConfig::get_bool>
|
|
|
|
// <mf TConfig::get_color>
|
|
|
|
{
|
|
|
|
const char* n = get(var,section,index);
|
|
|
|
if (*n)
|
|
|
|
def = *n;
|
1996-05-08 11:09:13 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
const char d[2] = { def, '\0' };
|
|
|
|
set(var, d, section, TRUE, index);
|
|
|
|
}
|
1995-11-22 13:40:15 +00:00
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
1994-09-19 09:50:07 +00:00
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
// @mfunc Ritorna il valore della variabile nella sezione corrente o in
|
|
|
|
// quella specificata
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna l'intero contenuto nella variabile, se questa esiste, altrimenti
|
|
|
|
// il valore di default che dovrebbe assumere determinato dal parametro
|
|
|
|
// <p def>
|
|
|
|
int TConfig::get_int(
|
|
|
|
const char* var, // @parm Variabile della quale ritornare il valore
|
|
|
|
const char* section, // @parm Sezione della varaibile (default NULL)
|
|
|
|
int index, // @parm Eventuale indice della varaibailie (default -1)
|
|
|
|
int def) // @parm Valore default della varaibile (default 0)
|
|
|
|
|
|
|
|
// @comm Chiama la funzione <mf TConfig::get_long> e ne ritorna un intero.
|
|
|
|
// <nl>Passando <p index> <gt>= 0 viene appeso al nome variabile per
|
|
|
|
// implementare un array.
|
|
|
|
// <nl>Il paragrafo passato in <p section> diventa quello attivo.
|
|
|
|
//
|
|
|
|
// @xref <mf TConfig::get> <mf TConfig::get_long> <mf TConfig::get_bool>
|
|
|
|
// <mf TConfig::get_color>
|
1995-01-24 08:52:49 +00:00
|
|
|
{
|
|
|
|
return (int)get_long(var, section, index, def);
|
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
1995-01-24 08:52:49 +00:00
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
// @mfunc Ritorna il valore della variabile nella sezione corrente o in
|
|
|
|
// quella specificata
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna i seguenti valori
|
|
|
|
//
|
|
|
|
// @flag TRUE | Se la varabile e' settata con X
|
|
|
|
// @flag FALSE | Se la varabile nen e' settata con X
|
|
|
|
// @flag <p def> | Se la varabile non esiste
|
|
|
|
bool TConfig::get_bool(
|
|
|
|
const char* var, // @parm Variabile della quale ritornare il valore
|
|
|
|
const char* section, // @parm Sezione della varaibile (default NULL)
|
|
|
|
int index, // @parm Eventuale indice della varaibailie (default -1)
|
|
|
|
bool def) // @parm Valore default della varaibile (default FALSE)
|
|
|
|
|
|
|
|
// @comm Viene chiamata la funzione <mf TConfig::get>.
|
|
|
|
// <nl>Passando <p index> <gt>= 0 viene appeso al nome variabile per
|
|
|
|
// implementare un array.
|
|
|
|
// <nl>Il paragrafo passato in <p section> diventa quello attivo.
|
|
|
|
//
|
|
|
|
// @xref <mf TConfig::get> <mf TConfig::get_long> <mf TConfig::get_int>
|
|
|
|
// <mf TConfig::get_color>
|
1996-05-08 11:09:13 +00:00
|
|
|
{
|
1996-12-10 08:28:14 +00:00
|
|
|
const char* d = def ? "X" : "";
|
1996-05-08 11:09:13 +00:00
|
|
|
const TString& s = get(var, section, index, d).upper();
|
1994-09-19 09:50:07 +00:00
|
|
|
return s != "" && (s == "X" || s == "ON" || s == "YES" || s == "OK" || s == "TRUE");
|
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
// @mfunc Ritorna il valore del colore settato nella variabile nella
|
|
|
|
// sezione corrente o in quella specificata
|
|
|
|
COLOR TConfig::get_color(
|
|
|
|
const char* var, // @parm Variabile della quale ritornare il valore
|
|
|
|
const char* section, // @parm Sezione della varaibile (default NULL)
|
|
|
|
int index, // @parm Eventuale indice della varaibailie (default -1)
|
|
|
|
COLOR def) // @parm Valore default della varaibile (default 0)
|
|
|
|
|
|
|
|
// @comm Passando <p index> <gt>= 0 viene appeso al nome variabile per
|
|
|
|
// implementare un array.
|
|
|
|
// <nl>Il paragrafo passato in <p section> diventa quello attivo.
|
|
|
|
//
|
|
|
|
// @xref <mf TConfig::get> <mf TConfig::get_long> <mf TConfig::get_int>
|
|
|
|
// <mf TConfig::get_bool>
|
1995-01-02 09:33:00 +00:00
|
|
|
{
|
|
|
|
const char* c = get(var, section, index);
|
|
|
|
if (*c)
|
|
|
|
{
|
|
|
|
TToken_string s(c, ',');
|
1996-07-26 15:41:29 +00:00
|
|
|
const byte r = (byte)s.get_int();
|
|
|
|
const byte g = (byte)s.get_int();
|
|
|
|
const byte b = (byte)s.get_int();
|
|
|
|
def = RGB2COLOR(r, g, b);
|
1995-01-02 09:33:00 +00:00
|
|
|
}
|
1995-01-05 17:50:40 +00:00
|
|
|
else
|
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
TString16 d;
|
|
|
|
d.format("%d,%d,%d",
|
|
|
|
XVT_COLOR_GET_RED(def), XVT_COLOR_GET_GREEN(def), XVT_COLOR_GET_BLUE(def));
|
1996-05-08 11:09:13 +00:00
|
|
|
set(var, d, section, TRUE, index);
|
1996-07-08 07:25:19 +00:00
|
|
|
}
|
|
|
|
|
1995-01-02 09:33:00 +00:00
|
|
|
return def;
|
|
|
|
}
|
1994-09-19 09:50:07 +00:00
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
// @mfunc Setta la variabile nella sezione corrente o specificata
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna i seguenti valori:
|
|
|
|
//
|
|
|
|
// @flag TRUE | Se la variabile era gia' esistente
|
|
|
|
// @flag FALSE | Se la variabile non era gia' esistente
|
|
|
|
bool TConfig::set(
|
|
|
|
const char* var, // @parm Nome della variabile da settare
|
|
|
|
const char* value, // @parm Stringa da assegnare alla variabile
|
|
|
|
const char* section, // @parm Nome del paragrafo a cui appartiene la variabile
|
|
|
|
bool force, // @parm Per la creazione di una variabile inesistente
|
|
|
|
int index) // @parm Eventuale indice della variabile
|
|
|
|
// @parm long | value | Valore da assegnare alla variabile
|
1994-09-19 09:50:07 +00:00
|
|
|
{
|
1995-05-26 10:16:03 +00:00
|
|
|
// @syntax set(const char* var, const char* value, const char* section, bool force, int index);
|
|
|
|
// @syntax set(const char* var, long value, const char* section, bool force, int index);
|
|
|
|
//
|
|
|
|
// @comm Se <p force> == TRUE crea il paragrafo e la variabile se non esistono;
|
|
|
|
// altrimenti da' errore.
|
|
|
|
// <nl>Passando <p index> <gt>= 0 viene appeso al nome variabile per
|
|
|
|
// implementare un array.
|
|
|
|
// <nl>Il paragrafo passato in <p section> diventa quello attivo.
|
1996-11-12 14:53:09 +00:00
|
|
|
|
|
|
|
if (section)
|
|
|
|
set_paragraph(section);
|
1994-09-19 09:50:07 +00:00
|
|
|
|
1996-11-12 14:53:09 +00:00
|
|
|
const bool itwas = exist(var, index);
|
1994-09-22 16:47:50 +00:00
|
|
|
|
1994-09-19 09:50:07 +00:00
|
|
|
if (itwas && !force)
|
1996-11-12 14:53:09 +00:00
|
|
|
warning_box("Tentativo di ridefinizione simbolo: %s(%d)", var, index);
|
1994-09-19 09:50:07 +00:00
|
|
|
else
|
1994-09-22 16:47:50 +00:00
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
TString256 vvar(var); if (index >= 0) vvar << '(' << index << ')';
|
1994-09-22 16:47:50 +00:00
|
|
|
_data.add(vvar, new TString(value), force);
|
1996-11-12 14:53:09 +00:00
|
|
|
_dirty = TRUE;
|
1994-09-22 16:47:50 +00:00
|
|
|
}
|
1994-09-19 09:50:07 +00:00
|
|
|
return itwas;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TConfig::set(const char* var, long value, const char* section,
|
1994-09-22 16:47:50 +00:00
|
|
|
bool force, int index)
|
1994-09-19 09:50:07 +00:00
|
|
|
{
|
1994-10-24 15:06:49 +00:00
|
|
|
TString16 t; t << value;
|
1994-09-19 09:50:07 +00:00
|
|
|
return set(var,t,section,force,index);
|
|
|
|
}
|
|
|
|
|
1996-11-12 14:53:09 +00:00
|
|
|
bool TConfig::set_color(const char* var, COLOR col, const char* section,
|
|
|
|
bool force, int index)
|
|
|
|
{
|
|
|
|
TString16 t;
|
|
|
|
t.format("%d,%d,%d", XVT_COLOR_GET_RED(col), XVT_COLOR_GET_GREEN(col), XVT_COLOR_GET_BLUE(col));
|
|
|
|
return set(var,t,section,force,index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
// @mfunc Ritorna quanti elementi dell'array nominato sono presenti nella
|
|
|
|
// sezione indicata.
|
|
|
|
word TConfig::items(
|
|
|
|
const char* var, // @parm Nome dell'array
|
|
|
|
const char* section) // @parm Sezione indicata
|
|
|
|
|
|
|
|
// @comm Il paragrafo passato in <p section> diventa quello attivo.
|
|
|
|
// <nl>Possono esserci dei "buchi" causati da set() errate
|
1994-09-19 09:50:07 +00:00
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
if (section) set_paragraph(section);
|
|
|
|
for (int cnt = 0; exist(var, cnt); cnt++);
|
1994-09-19 09:50:07 +00:00
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
1995-05-26 10:16:03 +00:00
|
|
|
|
|
|
|
// @mfunc Inizializza il paragrafo leggendo dal file i dati
|
|
|
|
void TConfig::init(
|
|
|
|
const char *fn, // @parm Nome del file da leggere
|
1997-09-30 10:40:28 +00:00
|
|
|
const char* pa, // @parm Nome del paragrafo da utilizzare
|
|
|
|
bool warning) // @parm Segnala assenza del file
|
1995-05-26 10:16:03 +00:00
|
|
|
|
|
|
|
// @comm Apre il file <p fn> e cerca il paragrafo <p pa>. Se il file non esiste
|
|
|
|
// viene creato con il paragrafo passato.
|
1994-09-22 16:47:50 +00:00
|
|
|
{
|
|
|
|
_file = fn;
|
|
|
|
_paragraph = pa;
|
|
|
|
_dirty = FALSE;
|
|
|
|
|
|
|
|
if (!fexist(_file))
|
1995-03-22 09:07:04 +00:00
|
|
|
{
|
1997-09-30 10:40:28 +00:00
|
|
|
if (warning)
|
|
|
|
warning_box("Creazione del file di configurazione %s", fn );
|
1995-03-22 09:07:04 +00:00
|
|
|
ofstream c(fn);
|
|
|
|
c.close();
|
|
|
|
}
|
1994-09-22 16:47:50 +00:00
|
|
|
|
1996-11-12 14:53:09 +00:00
|
|
|
if (_paragraph.blank())
|
1994-09-22 16:47:50 +00:00
|
|
|
{
|
|
|
|
_paragraph = main_app().name();
|
|
|
|
_paragraph.cut(2);
|
|
|
|
}
|
1996-11-12 14:53:09 +00:00
|
|
|
|
1994-09-22 16:47:50 +00:00
|
|
|
_ispresent = _read_paragraph();
|
|
|
|
}
|
|
|
|
|
1995-06-28 16:35:30 +00:00
|
|
|
int TConfig::list_paragraphs(TString_array& pl)
|
|
|
|
{
|
|
|
|
TScanner s(_file);
|
|
|
|
pl.destroy();
|
|
|
|
while (s.line().not_empty())
|
1996-11-12 14:53:09 +00:00
|
|
|
{
|
1995-06-28 16:35:30 +00:00
|
|
|
if (s.token()[0] == '[')
|
|
|
|
{
|
|
|
|
TToken_string* p = new TToken_string(s.token());
|
|
|
|
p->strip("[]");
|
|
|
|
pl.add(p);
|
|
|
|
}
|
1996-11-12 14:53:09 +00:00
|
|
|
}
|
1995-06-28 16:35:30 +00:00
|
|
|
return pl.items();
|
|
|
|
}
|
1994-09-22 16:47:50 +00:00
|
|
|
|
1995-11-14 10:28:24 +00:00
|
|
|
int TConfig::list_variables(TString_array& vl, bool value, const char* section)
|
|
|
|
{
|
|
|
|
set_paragraph(section);
|
|
|
|
vl.destroy();
|
|
|
|
_data.restart();
|
|
|
|
|
|
|
|
for (int i = 0; i < _data.items(); i++)
|
|
|
|
{
|
|
|
|
THash_object* o = _data.get_hashobj();
|
|
|
|
TToken_string* t = new TToken_string(o->key());
|
|
|
|
if (value) t->add((TString&)(o->obj()));
|
|
|
|
vl.add(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
return vl.items();
|
|
|
|
}
|
|
|
|
|
1996-06-18 13:33:27 +00:00
|
|
|
const TAssoc_array& TConfig::list_variables(const char* section)
|
|
|
|
{
|
|
|
|
set_paragraph(section);
|
|
|
|
return _data;
|
|
|
|
}
|
|
|
|
|
1995-11-14 10:28:24 +00:00
|
|
|
|
1994-09-22 16:47:50 +00:00
|
|
|
TConfig::TConfig(int which_config, const char* paragraph)
|
1995-02-28 10:25:02 +00:00
|
|
|
{
|
|
|
|
switch (which_config)
|
1994-09-27 10:07:50 +00:00
|
|
|
{
|
1995-02-28 10:25:02 +00:00
|
|
|
case CONFIG_DITTA:
|
|
|
|
_file << main_app().get_firm_dir() << '/' << "prassid.ini";
|
1996-11-12 14:53:09 +00:00
|
|
|
if (!fexist(_file))
|
|
|
|
fcopy("prassid.ini", _file);
|
1995-02-28 10:25:02 +00:00
|
|
|
break;
|
|
|
|
case CONFIG_STUDIO:
|
|
|
|
case CONFIG_USER:
|
1995-05-12 09:24:47 +00:00
|
|
|
case CONFIG_STAMPE:
|
1995-07-03 16:19:39 +00:00
|
|
|
_file = firm2dir(-1); // Directory dati
|
1996-11-12 14:53:09 +00:00
|
|
|
_file.add("config"); // Directory config
|
|
|
|
if (!fexist(_file)) // Creala se becessario
|
1995-03-22 09:07:04 +00:00
|
|
|
make_dir(_file);
|
1995-05-16 09:35:12 +00:00
|
|
|
|
|
|
|
switch (which_config)
|
|
|
|
{
|
1995-06-28 16:35:30 +00:00
|
|
|
case CONFIG_STUDIO:
|
1995-07-03 08:11:45 +00:00
|
|
|
_file.add("prassis.ini");
|
1996-11-12 14:53:09 +00:00
|
|
|
if (!fexist(_file))
|
|
|
|
fcopy("prassis.ini", _file);
|
1995-06-28 16:35:30 +00:00
|
|
|
break;
|
1995-05-16 09:35:12 +00:00
|
|
|
case CONFIG_STAMPE:
|
1995-06-02 13:09:46 +00:00
|
|
|
_file.add("print.ini");
|
|
|
|
break;
|
1996-09-04 07:53:02 +00:00
|
|
|
case CONFIG_USER:
|
|
|
|
{
|
|
|
|
TString16 u = user();
|
|
|
|
if (u.blank())
|
|
|
|
u = "PRASSI";
|
|
|
|
else
|
|
|
|
u.upper();
|
|
|
|
_file.add(u);
|
|
|
|
_file.ext("ini");
|
|
|
|
if (u != "PRASSI" && !fexist(_file))
|
|
|
|
{
|
|
|
|
TFilename prassi = _file.path();
|
|
|
|
prassi.add("prassi.ini");
|
|
|
|
fcopy(prassi, _file);
|
|
|
|
}
|
|
|
|
}
|
1995-06-02 13:09:46 +00:00
|
|
|
break;
|
1996-09-04 07:53:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
1995-05-16 09:35:12 +00:00
|
|
|
}
|
1995-02-28 10:25:02 +00:00
|
|
|
break;
|
1995-04-21 08:54:00 +00:00
|
|
|
case CONFIG_FCONV:
|
|
|
|
_file = "fconv.ini";
|
|
|
|
break;
|
1995-05-16 09:35:12 +00:00
|
|
|
case CONFIG_GOLEM:
|
|
|
|
_file.add("golem.ini");
|
|
|
|
break;
|
1995-02-28 10:25:02 +00:00
|
|
|
default:
|
1995-06-28 16:35:30 +00:00
|
|
|
_file = "prassi.ini";
|
|
|
|
CHECK(0, "Chi ca$$o usa prassi.ini?");
|
1995-02-28 10:25:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1997-09-30 10:40:28 +00:00
|
|
|
init(_file, paragraph, TRUE);
|
1994-09-19 09:50:07 +00:00
|
|
|
}
|
|
|
|
|
1994-09-22 16:47:50 +00:00
|
|
|
TConfig::TConfig(const char *fn, const char* pa)
|
1997-09-30 10:40:28 +00:00
|
|
|
{ init(fn, pa, FALSE); }
|
1994-09-22 16:47:50 +00:00
|
|
|
|
|
|
|
|
1994-09-19 09:50:07 +00:00
|
|
|
TConfig::~TConfig()
|
|
|
|
{
|
|
|
|
// il distruttore riscrive il file con le modifiche se necessario
|
|
|
|
if (_dirty) _write_file();
|
|
|
|
}
|
|
|
|
|