diff --git a/include/fraction.cpp b/include/fraction.cpp index a041b14a2..f13206315 100755 --- a/include/fraction.cpp +++ b/include/fraction.cpp @@ -1,8 +1,32 @@ -#include -#include #include #include -#include + +static __int64 mcd(__int64 a, __int64 b) +{ + if (a < 0) + a = -a; + if (b < 0) + b = -b; + + __int64 r; + while (b > 0) + { + r = a % b; + a = b; + b = r; + } + return a; +} + +static __int64 mcm(__int64 a, __int64 b) +{ + if (a < 0) + a = -a; + if (b < 0) + b = -b; + return ((a * b) / mcd(a, b)); +} + void fraction::simplify() { @@ -22,9 +46,10 @@ void fraction::simplify() } } +// Crea una frazione a partire da una stringa avente la VIRGOLA come separatore dei decimali! void fraction::build_fraction (const char *s) { - TString n = get_tmp_string(80); n = s; + TString80 n = s; _num = 0; _den = 1; @@ -43,7 +68,7 @@ void fraction::build_fraction (const char *s) if (psls > 0) { - TString80 num(n.left(psls)); + TString80 num = n.left(psls); fraction a(num); num = n.mid(psls + 1); fraction b(num); @@ -124,25 +149,34 @@ void fraction::build_fraction (const char *s) simplify(); } -fraction::fraction () +fraction::fraction() { _num = 0; _den = 1; } -fraction::fraction(const fraction & b) +fraction::fraction(const fraction& b) { _num = b._num; _den = b._den; } +fraction::fraction(const real& num, const real& den) +{ + if (den == UNO) + build_fraction(num.stringa()); + else + { + real n = num; n /= den; + build_fraction(n.stringa()); + } +} + int fraction::sign() const { if ( _num == 0 || _den == 0) return 0; - if ( _num < 0) - return _den < 0 ? 1 : -1; - return _den < 0 ? -1 : 1; + return _num < 0 ? (_den < 0 ? +1 : -1) : (_den < 0 ? -1 : +1); } fraction& fraction::operator =(const fraction & b) @@ -154,7 +188,7 @@ fraction& fraction::operator =(const fraction & b) fraction& fraction::operator += (const fraction & b) { - __int64 m = mcm(_den, b._den); + const __int64 m = mcm(_den, b._den); _num = _num * ( m / _den) + b._num * ( m / b._den); _den = m; @@ -191,7 +225,6 @@ fraction& fraction::operator /= (const fraction & b) fraction fraction::operator - () const { fraction b(*this); - b._num = -b._num; return b; } @@ -203,13 +236,14 @@ TObject* fraction::dup () const return new fraction(*this); } -fraction::operator real () const +fraction::operator real() const { real n, d; n.set_int64(_num); d.set_int64(_den); - return n / d; + real q = n; q /= d; + return q; } // @doc EXTERNAL diff --git a/include/fraction.h b/include/fraction.h index 66ecf8496..1f3ed67fd 100755 --- a/include/fraction.h +++ b/include/fraction.h @@ -1,18 +1,10 @@ #ifndef __FRACTION_H #define __FRACTION_H -#ifndef __STRINGS_H -#include -#endif - #ifndef __REAL_H #include #endif -#ifndef __IOSTREAM_H -#include -#endif - // @doc EXTERNAL // @class fraction (per GREENLEAF) | Classe per la gestione dei numeri frazionari @@ -21,7 +13,7 @@ class fraction : public TObject -// @author:(INTERNAL) Guido +// @author:(INTERNAL) Alex { // @access:(INTERNAL) Private Member // @cmember:(INTERNAL) Numero fractione @@ -38,7 +30,9 @@ protected: virtual TObject* dup() const; // @cmember assegna il numero frazionario (vedi classe ) void simplify(); - void build_fraction(const char * s); + + // @cmember Crea una frazione a partire da una stringa avente la VIRGOLA come separatore dei decimali! + void build_fraction(const char* stringa); // @access Public Member public: @@ -46,11 +40,13 @@ public: bool is_zero() const { return _num == 0;} // @cmember Ritorna il segno del fraction int sign() const ; - // @cmember Trasforma il fractione in intero (operator int era troppo pericoloso) + // @cmember Trasforma il fraction in intero (operator int era troppo pericoloso) __int64 integer() const { return _num / _den;} // @cmember Assegna una frazione fraction& operator =(const fraction& b); + // @cmember Assegna una frazione + fraction& operator =(const real& b) { build_fraction(b.stringa()); return *this; } // @cmember Aggiunge ad un frazione il valore passato fraction& operator +=(const fraction& b); // @cmember Sottrae ad un frazione il valore passato @@ -64,21 +60,20 @@ public: // @cmember Ritorna il risultato della differenza tra due frazioni fraction operator -() const; - // @cmember converte la frazione in reale + // @cmember Trasforma il fraction in real operator real() const; // @cmember Costruttore fraction(); // @cmember Costruttore - fraction(const real & b) { build_fraction(b.stringa()); } - fraction(__int64 num, __int64 den = 1) : _num(num), _den(den) { simplify();} + fraction(const real &num, const real& den); + fraction(__int64 num, __int64 den = 1) : _num(num), _den(den) { simplify(); } // @cmember Costruttore fraction(const fraction& b) ; // @cmember Costruttore - fraction(const char* s) { build_fraction(s); } + fraction(const char* stringa) { build_fraction(stringa); } // @cmember Distruttore - virtual ~fraction() - {} + virtual ~fraction() { } }; /////////////////////////////////////////////////////////// @@ -86,46 +81,51 @@ public: /////////////////////////////////////////////////////////// fraction operator +(const fraction& a, const fraction& b) ; +fraction operator -(const fraction& a, const fraction& b) ; +fraction operator *(const fraction& a, const fraction& b) ; +fraction operator /(const fraction& a, const fraction& b) ; + +bool operator <(const fraction& a, const fraction& b) ; +bool operator >(const fraction& a, const fraction& b) ; +bool operator <=(const fraction& a, const fraction& b) ; +bool operator >=(const fraction& a, const fraction& b) ; +bool operator ==(const fraction& a, const fraction& b) ; +bool operator !=(const fraction& a, const fraction& b) ; + +#if 0 +// Valanga apparentemente inutile: aggiungere solo cio' che serve veramente! inline fraction operator +(const real& a, const fraction& b) { return ::operator +((fraction)a, b);} inline fraction operator +(const fraction& a, const real& b) { return ::operator +(b, a);} inline fraction operator +(const fraction& a, __int64 b) { return ::operator +(a, (fraction)b);} inline fraction operator +(__int64 a, const fraction& b) { return ::operator +(b, a);} -fraction operator -(const fraction& a, const fraction& b) ; inline fraction operator -(const real& a, const fraction& b) { return ::operator -((fraction)a, b);} inline fraction operator -(const fraction& a, const real& b) { return ::operator -(a, (fraction)b);} inline fraction operator -(const fraction& a, __int64 b) { return ::operator -(a, (fraction)b);} inline fraction operator -(__int64 a, const fraction& b) { return ::operator -((fraction)a, b);} -fraction operator *(const fraction& a, const fraction& b) ; inline fraction operator *(const real& a, const fraction& b) { return ::operator *((fraction)a, b);} inline fraction operator *(const fraction& a, const real& b) { return ::operator *(b, a);} fraction operator *(const fraction& a, __int64 b); inline fraction operator *(__int64 a, const fraction& b) { return ::operator *(b, a);} -fraction operator /(const fraction& a, const fraction& b) ; inline fraction operator /(const real& a, const fraction& b) { return ::operator /((fraction)a, b);} inline fraction operator /(const fraction& a, const real& b) { return ::operator /(a, (fraction)b);} fraction operator /(const fraction& a, __int64 b); fraction operator /(__int64 a, const fraction& b); -bool operator <(const fraction& a, const fraction& b) ; inline bool operator <(const real& a, const fraction& b) { return ::operator < (a, (real)b);} inline bool operator <(const fraction& a, const real& b) { return ::operator <((real) a, b);} -bool operator >(const fraction& a, const fraction& b) ; inline bool operator >(const real& a, const fraction& b) { return ::operator > (a, (real)b);}; inline bool operator >(const fraction& a, const real& b) { return ::operator >((real) a, b);} -bool operator <=(const fraction& a, const fraction& b) ; inline bool operator <=(const real& a, const fraction& b) { return ::operator <= (a, (real)b);} inline bool operator <=(const fraction& a, const real& b) { return operator <=((real) a, b);} -bool operator >=(const fraction& a, const fraction& b) ; inline bool operator >=(const real& a, const fraction& b) { return operator >=(a, (real) b);} inline bool operator >=(const fraction& a, const real& b) { return operator >=((real) a, b);} -bool operator ==(const fraction& a, const fraction& b) ; inline bool operator ==(const real& a, const fraction& b) { return operator ==(a, (real) b);} inline bool operator ==(const fraction& a, const real& b) { return operator ==((real) a, b);} -bool operator !=(const fraction& a, const fraction& b) ; inline bool operator !=(const real& a, const fraction& b) { return operator !=(a, (real) b);} inline bool operator !=(const fraction& a, const real& b) { return operator !=((real) a, b);} -real operator %(const real& a, const real& b) ; +#endif + void swap(fraction& a, fraction& b) ; const fraction& fnc_min(const fraction& a, const fraction& b); const fraction& fnc_max(const fraction& a, const fraction& b); diff --git a/include/isam.cpp b/include/isam.cpp index eab05b03f..8e20ae439 100755 --- a/include/isam.cpp +++ b/include/isam.cpp @@ -2854,8 +2854,9 @@ TObject* TRectype::dup() const const char* TRectype::build_key(int num) const { - __build_key(rec_des(), num, string(), __tmp_string, TRUE); - return __tmp_string; + TString& tmp = get_tmp_string(128); + __build_key(rec_des(), num, string(), tmp.get_buffer(), TRUE); + return tmp; } const char* TRectype::last_key_field(int key) const diff --git a/include/memo.cpp b/include/memo.cpp index e164e8e8f..13dd9a254 100755 --- a/include/memo.cpp +++ b/include/memo.cpp @@ -8,7 +8,6 @@ #define INFO_SIZE (sizeof(long)+sizeof(long)) // block size used in writes -// must not exceed sizeof(__tmp_string) #define BLOCK_SIZE (1024) // max allowed size for locking is 100k #define MAX_SIZE (100000l) diff --git a/include/prefix.cpp b/include/prefix.cpp index 65beeb785..8af55a1f3 100755 --- a/include/prefix.cpp +++ b/include/prefix.cpp @@ -1087,7 +1087,8 @@ const char* TPrefix::description( // Passando il nome di una tabella in

si ottiene la stessa cosa della // funzione , ma viene cercato la descrizione nel titolo della maschera. { - TFilename n(cod); + TString& n = get_tmp_string(); + n = cod; if (n[0] == '%') n.ltrim(1); @@ -1108,7 +1109,7 @@ const char* TPrefix::description( else n.cut(0); } - return strcpy(__tmp_string, n); + return n; } const char* TPrefix::description(int cod) const @@ -1134,7 +1135,7 @@ const TFirm& TPrefix::firm() const char* firm2dir( long codditta) // @parm Codice ditta da convertire { - TString16 firm; + TString8 firm; switch (codditta) { case -2: // Dati generali campione @@ -1145,8 +1146,10 @@ const char* firm2dir( default: // Dati ditta firm.format("%05lda", codditta); break; } - _makepath(__tmp_string, NULL, __ptprf, firm, NULL); - return __tmp_string; + + TString& path = get_tmp_string(256); + xvt_fsys_build_pathname(path.get_buffer(), NULL, __ptprf, firm, NULL, NULL); + return path; } int safely_close_closeable_isamfiles() diff --git a/include/printapp.cpp b/include/printapp.cpp index b6e0f5fdd..ef1b41e4c 100755 --- a/include/printapp.cpp +++ b/include/printapp.cpp @@ -504,10 +504,12 @@ void TPrint_application::set_header ( ...) // @parmvar Uno o piu' parametri corrispondenti ai codici in

{ + TString256 tmp; + CHECK (r >= 1, "Header rows start at 1"); va_list vl; va_start (vl, fmt); - vsprintf (__tmp_string, fmt, vl); + vsprintf (tmp.get_buffer(), fmt, vl); va_end (vl); TPrintrow *pp = (TPrintrow *)_header.objptr(r - 1); @@ -516,7 +518,7 @@ void TPrint_application::set_header ( pp = new TPrintrow; _header.add (pp, r - 1); } - pp->put (__tmp_string); + pp->put (tmp); } // @doc EXTERNAL @@ -529,9 +531,10 @@ void TPrint_application::set_footer ( { CHECK (r >= 1, "Footer rows start at 1"); + TString256 tmp; va_list vl; va_start (vl, fmt); - vsprintf (__tmp_string, fmt, vl); + vsprintf (tmp.get_buffer(), fmt, vl); va_end (vl); TPrintrow *pp = (TPrintrow *) _footer.objptr (r - 1); if (pp == NULL) @@ -539,7 +542,7 @@ void TPrint_application::set_footer ( pp = new TPrintrow; _footer.add (pp, r - 1); } - pp->put (__tmp_string); + pp->put (tmp); } void TPrint_application::reset_header () @@ -960,12 +963,10 @@ void TPrint_application::set_row ( else { #ifdef __LONGDOUBLE__ - sprintf (__tmp_string, formato, (long double)rrr); + sprintf (q.get_buffer(), formato, (long double)rrr); #else - char *fff = (char*)(const char *)formato; - dsprintf (__tmp_string, fff, rrr.ptr()); + dsprintf (q.get_buffer(), (char*)(const char*)formato, rrr.ptr()); #endif - q = __tmp_string; } if (rrr.is_zero () && !_print_zero) q.fill (' ', q.len()); @@ -1475,11 +1476,10 @@ bool TPrint_application::print_one ( else { #ifdef __LONGDOUBLE__ - sprintf(__tmp_string, fff, (long double)rrr); + sprintf(ps.get_buffer(), fff, (long double)rrr); #else - dsprintf(__tmp_string, (char*)fff, rrr.ptr()); + dsprintf(ps.get_buffer(), (char*)fff, rrr.ptr()); #endif - ps = __tmp_string; } if (rrr.is_zero () && !_print_zero) ps.fill (' ', ps.len()); diff --git a/include/printer.cpp b/include/printer.cpp index 1fa81ad39..8007f308e 100755 --- a/include/printer.cpp +++ b/include/printer.cpp @@ -614,6 +614,8 @@ const char* TPrintrow::row_codified() const char last_attr = -1; int last_color = -1; int k = 0, i = 0, len = 0; + + char* tmp = get_tmp_string(256).get_buffer(); // Calcolo lunghezza stringa for (i = _row.size()-1; i >= 0; i--) @@ -629,54 +631,54 @@ const char* TPrintrow::row_codified() const { if (_tab[i]) { - __tmp_string[k++] = '@'; - __tmp_string[k++] = 't'; + tmp[k++] = '@'; + tmp[k++] = 't'; } if (_attr[i] != last_attr) { - __tmp_string[k++] = '@'; + tmp[k++] = '@'; switch (_attr[i]) { case normalstyle: - __tmp_string[k++] = 'r'; + tmp[k++] = 'r'; break; case boldstyle: - __tmp_string[k++] = 'b'; + tmp[k++] = 'b'; break; case italicstyle: - __tmp_string[k++] = 'i'; + tmp[k++] = 'i'; break; case underlinedstyle: - __tmp_string[k++] = 'u'; + tmp[k++] = 'u'; break; } last_attr = _attr[i]; } if (_cols[i] != last_color) { - __tmp_string[k++] = '$'; - __tmp_string[k++] = '['; - __tmp_string[k++] = (char) (_cols[i] & 0x00ff); - __tmp_string[k++] = ','; - __tmp_string[k++] = (char) (_cols[i] >> 8); - __tmp_string[k++] = ']'; + tmp[k++] = '$'; + tmp[k++] = '['; + tmp[k++] = (char) (_cols[i] & 0x00ff); + tmp[k++] = ','; + tmp[k++] = (char) (_cols[i] >> 8); + tmp[k++] = ']'; last_color = _cols[i]; } if (_row[i] == '@' && strchr("<#>", _row[i+1]) == NULL) - __tmp_string[k++] = '@'; // Escape for @ - __tmp_string[k++] = _row[i]; + tmp[k++] = '@'; // Escape for @ + tmp[k++] = _row[i]; } - __tmp_string[k] = '\0'; + tmp[k] = '\0'; if (_images) { - strcat(__tmp_string, "$[w,w]"); // Bianco su bianco! + strcat(tmp, "$[w,w]"); // Bianco su bianco! FOR_EACH_TOKEN((*_images), tok) - strcat(__tmp_string, tok); + strcat(tmp, tok); } - return __tmp_string; + return tmp; } TPrintrow& TPrintrow::put(const char *str, int position, int len) @@ -1126,7 +1128,7 @@ void TPrinter::save_configuration() TConfig prini(_config == "Printer" ? CONFIG_USER : CONFIG_STAMPE, _config); prini.set("Type", _printertype); // Tipo stampante - prini.set("Name", _prname); // Numero stampante corrente + prini.set("Name", _prname); // Nome stampante corrente prini.set("File", _printerfile); // File di stampa prini.set("Font", _fontname); // Nome del font prini.set("Size", _ch_size); // Dimensione del font diff --git a/include/real.cpp b/include/real.cpp index 0c0c75ebe..97baf573a 100755 --- a/include/real.cpp +++ b/include/real.cpp @@ -3,15 +3,17 @@ #include -const real ZERO (0.0); +const real ZERO(0.0); +const real UNO(1.0); +const real CENTO(100.0); #ifdef __LONGDOUBLE__ #include + +#ifdef WIN32 + #include - -#if XVT_OS == XVT_OS_WIN32 - inline long double _atold(const char* str) { long double num = 0.0; diff --git a/include/real.h b/include/real.h index 5ec5711ce..3268d799a 100755 --- a/include/real.h +++ b/include/real.h @@ -320,6 +320,8 @@ real abs(const real& a) ; // TReal implementato coi maledetti DEC extern const real ZERO; +extern const real UNO; +extern const real CENTO; // @doc EXTERNAL diff --git a/include/strings.cpp b/include/strings.cpp index 8d3f5cbd4..6145b51cb 100755 --- a/include/strings.cpp +++ b/include/strings.cpp @@ -298,8 +298,9 @@ TObject* TString::dup() const void TString::read_from(istream& in) { - in >> __tmp_string; - set(__tmp_string); + char tmp[256]; + in >> tmp; + set(tmp); } diff --git a/include/utility.cpp b/include/utility.cpp index 49fc13856..e5699adfd 100755 --- a/include/utility.cpp +++ b/include/utility.cpp @@ -245,7 +245,9 @@ const char* cmd2name( app.cut(3); app << c << "00"; - return strcpy(__tmp_string, app); + TString& tmp = get_tmp_string(); + tmp = app; + return tmp; } @@ -446,10 +448,11 @@ const char * encode( // @xref { + char* tmp = get_tmp_string(50).get_buffer(); for (int i = 0; data[i]; i++) - __tmp_string[i] = data[i] + (i < 8 ? encryption_key[i] : data[i - 8]); - __tmp_string[i] = '\0'; - return __tmp_string; + tmp[i] = data[i] + (i < 8 ? encryption_key[i] : data[i - 8]); + tmp[i] = '\0'; + return tmp; } // @doc EXTERNAL @@ -462,38 +465,10 @@ const char * decode( // @xref { + char* tmp = get_tmp_string(50).get_buffer(); for (int i = 0; data[i]; i++) - __tmp_string[i] = data[i] - (i < 8 ? encryption_key[i] : __tmp_string[i - 8]); - __tmp_string[i] = '\0'; - return __tmp_string; + tmp[i] = data[i] - (i < 8 ? encryption_key[i] : tmp[i - 8]); + tmp[i] = '\0'; + return tmp; } -__int64 mcd(__int64 a, __int64 b) - -{ - if (a < 0) - a = -a; - if (b < 0) - b = -b; - - __int64 r; - - while (b > 0) - { - r = a % b; - a = b; - b = r; - } - return a; -} - -__int64 mcm(__int64 a, __int64 b) - -{ - if (a < 0) - a = -a; - if (b < 0) - b = -b; - - return ((a * b) / mcd(a, b)); -} diff --git a/include/utility.h b/include/utility.h index 607bcac67..315739e51 100755 --- a/include/utility.h +++ b/include/utility.h @@ -41,9 +41,6 @@ const char* unesc(const char* str); // Trasforma i caratteri '\n' nella sequenza #define ODD(x) (x & 1) #define EVEN(x) !(x & 1) -__int64 mcd(__int64 a, __int64 b); -__int64 mcm(__int64 a, __int64 b); - #ifdef __UTILITY_CPP char __tmp_string[1024]; #else