diff --git a/omnia/Omnia0.cpp b/omnia/Omnia0.cpp index 36f2e653a..436aa386e 100755 --- a/omnia/Omnia0.cpp +++ b/omnia/Omnia0.cpp @@ -19,6 +19,7 @@ protected: public: static void set_curr_recno(int n) { _curr_recno = n; } + static int curr_recno() { return _curr_recno; } TExpr_omnia(const char* exp) { set(exp, _strexpr); } }; @@ -93,6 +94,7 @@ void TExpr_omnia::evaluate_user_func(int index, int nparms, TEval_stack& stack, class TTextRecord : public TString_array { + TAssoc_array* m_vars; const TXmlItem* m_inrec; const TXmlItem* m_outrec; int m_nLines, m_nColumns; @@ -104,18 +106,19 @@ protected: const TXmlItem* FindInputField(const TString& name) const; public: - void SetTrc(const TXmlItem& trc); + void SetTrc(const TXmlItem& trc, TAssoc_array* vars = NULL); bool Read(istream& input); const TString& GetValue(const TString& name) const; const TString& Evaluate(TExpr_omnia& exp) const; - TTextRecord() : m_nLines(0), m_nColumns(0) { } - TTextRecord(const TXmlItem& trc) { SetTrc(trc); } + TTextRecord() : m_nLines(0), m_nColumns(0), m_vars(NULL) { } + TTextRecord(const TXmlItem& trc) : m_vars(NULL) { SetTrc(trc); } }; -void TTextRecord::SetTrc(const TXmlItem& trc) +void TTextRecord::SetTrc(const TXmlItem& trc, TAssoc_array* vars) { + m_vars = vars; const TXmlItem& input = *trc.FindFirst("Input"); m_nLines = input.GetIntAttr("Lines"); if (m_nLines <= 0) @@ -215,6 +218,13 @@ const TXmlItem* TTextRecord::FindInputField(const TString& name) const const TString& TTextRecord::GetValue(const TString& name) const { + if (m_vars != NULL) + { + const TString* val = (const TString*)m_vars->objptr(name); + if (val != NULL) + return *val; + } + const TXmlItem* f = FindInputField(name); if (f != NULL) return GetFieldValue(*f); @@ -227,7 +237,7 @@ const TString& TTextRecord::Evaluate(TExpr_omnia& exp) const TString& str = (TString&)m_str; const int nv = exp.numvar(); - if (nv > 0 || strchr(exp.string(), '(') != NULL) + if (nv > 0 || strchr(exp.string(), '(') != NULL) // C'e' qualche variabile o funzione { for (int i = nv-1; i >= 0; i--) { @@ -238,7 +248,14 @@ const TString& TTextRecord::Evaluate(TExpr_omnia& exp) const str = exp.as_string(); } else + { str = exp.string(); // Nessuna variabile = costante! + if (str[0] == '"') // Togli virgolette dalle costanti + { + str.rtrim(1); + str.ltrim(1); + } + } return str; } @@ -262,14 +279,19 @@ public: virtual~ TScrittore() { delete _out; } }; - /////////////////////////////////////////////////////////// // TCasaEditrice /////////////////////////////////////////////////////////// +enum TExportFormat { fmt_txt, fmt_slk }; + class TCasaEditrice : public TAssoc_array { const TXmlItem& m_trc; + const TXmlItem* m_pRecOut; + TExportFormat m_fmt; + TArray _expressions; + TString m_strPrefix, m_strExt; TExpr_omnia* m_exprSuffix; @@ -280,6 +302,10 @@ protected: TScrittore& Scrittore(const char* suffix); void WriteHeader(ostream& output) const; void WriteFooter(ostream& output) const; + void Translate(TString& str) const; + ofstream& ChooseOutput(const TTextRecord& rec); + const TString& evaluate(const TTextRecord& rec, int index) const; + void WriteField(ostream& output, int x, int y, const char* val) const; public: const TString& RecHead() const { return m_strRecHead; } @@ -287,11 +313,29 @@ public: const TString& FldHead() const { return m_strFldHead; } const TString& FldFoot() const { return m_strFldFoot; } - ofstream& ChooseOutput(const TTextRecord& rec); + void Write(const TTextRecord& rec); + TCasaEditrice(const TXmlItem& trc, const char* name); virtual ~TCasaEditrice(); }; +void TCasaEditrice::Translate(TString& str) const +{ + int ampersend = str.find("&#"); + TString tmp; + while (ampersend >= 0) + { + const int semicolon = str.find(';', ampersend+2); + if (semicolon < 0) + break; + const int k = hex2int(str.sub(ampersend+2, semicolon)); + tmp.format("%c", k); + tmp.insert(str.left(ampersend)); + tmp << str.mid(semicolon+1); + str = tmp; + ampersend = str.find("&#", ampersend+1); + } +} void TCasaEditrice::WriteHeader(ostream& output) const { @@ -300,33 +344,37 @@ void TCasaEditrice::WriteHeader(ostream& output) const TXmlItem* pHeader = pOutput->FindFirst("Header"); + TString strHeader; if (pHeader != NULL) { - TString strHeader; pHeader->GetEnclosedText(strHeader); - if (strHeader[0] == '"') + pHeader->GetEnclosedText(strHeader); + if (strHeader.not_empty()) { - strHeader.rtrim(1); - strHeader.ltrim(1); - } - strHeader = esc(strHeader); - output << strHeader; - - if (pHeader->GetAttr("Auto") == "1") - { - TXmlItem* pRecOut = pOutput->FindFirst("Record"); - CHECK(pRecOut, "NULL output record"); - - output << m_strRecHead; - for (int i = 0; i < pRecOut->GetChildren(); i++) + if (strHeader[0] == '"') { - const TXmlItem* outfield = pRecOut->GetChild(i); - output << m_strFldHead; - output << outfield->GetAttr("Name"); - output << m_strFldFoot; + strHeader.rtrim(1); + strHeader.ltrim(1); } - output << m_strRecFoot; + Translate(strHeader); } } + if (strHeader.empty() && m_fmt == fmt_slk) + strHeader = "ID;PWXL;N;E\n"; + output << strHeader; + + if (pHeader != NULL && pHeader->GetIntAttr("Auto") != 0) + { + TXmlItem* pRecOut = pOutput->FindFirst("Record"); + CHECK(pRecOut, "NULL output record"); + + output << m_strRecHead; + for (int i = 0; i < pRecOut->GetChildren(); i++) + { + const TXmlItem* outfield = pRecOut->GetChild(i); + WriteField(output, i, 0, outfield->GetAttr("Name")); + } + output << m_strRecFoot; + } } void TCasaEditrice::WriteFooter(ostream& output) const @@ -334,17 +382,22 @@ void TCasaEditrice::WriteFooter(ostream& output) const TXmlItem* pOutput = m_trc.FindFirst("Output"); CHECK(pOutput, "NULL output file"); TXmlItem* pFooter = pOutput->FindFirst("Footer"); + + TString strFooter; if (pFooter != NULL) { - TString strFooter; pFooter->GetEnclosedText(strFooter); + pFooter->GetEnclosedText(strFooter); if (strFooter[0] == '"') { strFooter.rtrim(1); strFooter.ltrim(1); } - strFooter = esc(strFooter); - output << strFooter; + Translate(strFooter); } + if (strFooter.empty() && m_fmt == fmt_slk) + strFooter = "E\n"; + + output << strFooter; } TScrittore& TCasaEditrice::Scrittore(const char* suffix) @@ -374,7 +427,41 @@ ofstream& TCasaEditrice::ChooseOutput(const TTextRecord& rec) return s.OutStream(); } -TCasaEditrice::TCasaEditrice(const TXmlItem& trc, const char* name) : m_trc(trc), m_exprSuffix(NULL) +const TString& TCasaEditrice::evaluate(const TTextRecord& rec, int index) const +{ + TExpr_omnia& exp = (TExpr_omnia&)_expressions[index]; + return rec.Evaluate(exp); +} + +void TCasaEditrice::WriteField(ostream& output, int x, int y, const char* val) const +{ + switch(m_fmt) + { + case fmt_slk: + output << "C;Y" << (y+1) << ";X" << (x+1) << ";K\"" << val << '"' << endl; + break; + default: + output << FldHead() << val << FldFoot(); + break; + } +} + +void TCasaEditrice::Write(const TTextRecord& rec) +{ + ofstream& output = ChooseOutput(rec); + output << RecHead(); + TString expr; + for (int i = 0; i < m_pRecOut->GetChildren(); i++) + { + TXmlItem* outfield = m_pRecOut->GetChild(i); + outfield->GetEnclosedText(expr); + const TString& val = evaluate(rec, i); + WriteField(output, i, TExpr_omnia::curr_recno(), val); + } + output << RecFoot(); +} + +TCasaEditrice::TCasaEditrice(const TXmlItem& trc, const char* name) : m_trc(trc), m_fmt(fmt_txt), m_exprSuffix(NULL) { const TFilename path(name); const int dot = path.rfind('.'); @@ -382,6 +469,9 @@ TCasaEditrice::TCasaEditrice(const TXmlItem& trc, const char* name) : m_trc(trc) { m_strPrefix = path.left(dot); m_strExt = path.mid(dot+1); + if (m_strExt.compare("slk", -1, true) == 0 || + m_strExt.compare("xls", -1, true) == 0) + m_fmt = fmt_slk; } else { @@ -392,18 +482,28 @@ TCasaEditrice::TCasaEditrice(const TXmlItem& trc, const char* name) : m_trc(trc) const TXmlItem* pOutFile = m_trc.FindFirst("Output"); CHECK(pOutFile, "NULL Output tag"); - const TString strSuffix = pOutFile->GetAttr("Suffix"); if (strSuffix.not_empty()) m_exprSuffix = new TExpr_omnia(strSuffix); - TXmlItem* pRecOut = pOutFile->FindFirst("Record"); - CHECK(pRecOut, "NULL output record"); + m_pRecOut = pOutFile->FindFirst("Record"); + CHECK(m_pRecOut, "NULL output record"); - m_strRecHead = esc(pRecOut->GetAttr("RecHead")); - m_strRecFoot = esc(pRecOut->GetAttr("RecFoot")); - m_strFldHead = esc(pRecOut->GetAttr("FldHead")); - m_strFldFoot = esc(pRecOut->GetAttr("FldFoot")); + if (m_fmt != fmt_slk) + { + m_strRecHead = m_pRecOut->GetAttr("RecHead"); Translate(m_strRecHead); + m_strRecFoot = m_pRecOut->GetAttr("RecFoot"); Translate(m_strRecFoot); + m_strFldHead = m_pRecOut->GetAttr("FldHead"); Translate(m_strFldHead); + m_strFldFoot = m_pRecOut->GetAttr("FldFoot"); Translate(m_strFldFoot); + } + + TString expr; + for (int i = 0; i < m_pRecOut->GetChildren(); i++) + { + const TXmlItem* outfield = m_pRecOut->GetChild(i); + outfield->GetEnclosedText(expr); + _expressions.add(new TExpr_omnia(expr)); + } } TCasaEditrice::~TCasaEditrice() @@ -424,17 +524,15 @@ class TLettore : public TObject { TXmlItem _trc; TTextRecord _curr; - TArray _expressions; protected: bool load_trc(const char* trc); const TString& get_field(const TXmlItem& field) const; const TXmlItem* find_field(const TXmlItem& record, const TString& name) const; - const TString& evaluate(int index) const; public: - int convert(const TFilename& src, const TFilename& trc, const TFilename& dst); + int convert(const TFilename& src, const TFilename& trc, const TFilename& dst, TAssoc_array& vars); int convert(const char* cmd); }; @@ -451,13 +549,7 @@ bool TLettore::load_trc(const char* t) return ok; } -const TString& TLettore::evaluate(int index) const -{ - TExpr_omnia& exp = (TExpr_omnia&)_expressions[index]; - return _curr.Evaluate(exp); -} - -int TLettore::convert(const TFilename& src, const TFilename& trc, const TFilename& dst) +int TLettore::convert(const TFilename& src, const TFilename& trc, const TFilename& dst, TAssoc_array& vars) { if (!src.exist()) { @@ -493,34 +585,15 @@ int TLettore::convert(const TFilename& src, const TFilename& trc, const TFilenam return 4; } - _curr.SetTrc(_trc); + TAssoc_array* varibili = (vars.items() > 0) ? &vars : NULL; + _curr.SetTrc(_trc, varibili); const int inmode = infile->GetIntAttr("Binary") != 0 ? (ios::in|ios::binary) : ios::in; ifstream input(src, inmode); TCasaEditrice mondadori(_trc, dst); - - TString expr; - for (int i = 0; i < recout->GetChildren(); i++) - { - const TXmlItem* outfield = recout->GetChild(i); - outfield->GetEnclosedText(expr); - _expressions.add(new TExpr_omnia(expr)); - } - while (_curr.Read(input)) - { - ofstream& output = mondadori.ChooseOutput(_curr); - output << mondadori.RecHead(); - for (int i = 0; i < recout->GetChildren(); i++) - { - TXmlItem* outfield = recout->GetChild(i); - outfield->GetEnclosedText(expr); - const TString& val = evaluate(i); - output << mondadori.FldHead() << val << mondadori.FldFoot(); - } - output << mondadori.RecFoot(); - } + mondadori.Write(_curr); return 0; } @@ -532,7 +605,24 @@ int TLettore::convert(const char* cmd) const TFilename src = str.get(); const TFilename trc = str.get(); const TFilename dst = str.get(); - return convert(src, trc, dst); + + TAssoc_array vars; + TString varname, value; + for (const char* t = str.get(); t; t = str.get()) + { + varname = t; + const int equal = varname.find('='); + if (equal > 0) + { + value = varname.mid(equal+1); + varname.cut(equal); + } + else + value.cut(0); + vars.add(varname, value); + } + + return convert(src, trc, dst, vars); } int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) diff --git a/omnia/omnia.xml b/omnia/omnia.xml index 84fdc172a..fc84179a4 100755 --- a/omnia/omnia.xml +++ b/omnia/omnia.xml @@ -7,8 +7,8 @@ - - + + @@ -19,7 +19,8 @@ - + + @@ -32,7 +33,7 @@
- + Impianto Progressivo 1 @@ -41,15 +42,15 @@ 000000 RECNO() BEFORE(Indirizzo, ",") - BETWEEN(Indirizzo, ",", "/") + IF(BETWEEN(Indirizzo,", ","/")!="S.N.", BETWEEN(Indirizzo,", ","/"), "") AFTER(Indirizzo, "/") - + IF(BETWEEN(Indirizzo,", ","/")=="S.N.", "S.N.", "") SUBSTR(Comune, 7, RFIND(Comune, " ")) RIGHT(Comune, 2) MID(Comune, 1, 5) - IF(SoggettoFognatura=="Servizio Fognatura", IF(SoggettoDepurazione=="Servizio Depurazione", 2, 1), IF(SoggettoDepurazione=="Servizio Depurazione", 3, 0)) + IF(D_TITOLO_FOG=="SERVIZIO FOGNATURA", IF(D_TITOLO_DEP=="SERVIZIO DEPURAZIONE", 2, 1), IF(D_TITOLO_DEP=="SERVIZIO DEPURAZIONE", 3, 0)) 1 @@ -64,7 +65,7 @@ 1 1 RECNO() - + DATA Impianto Progressivo 1 @@ -78,7 +79,7 @@ IF(StatoUtente=="BOLLETTA DI CHIUSURA CONTRATTO", "CESSATO", "ATTIVO") - + DATA CodiceFiscalePI 10 @@ -100,11 +101,11 @@ - BETWEEN(QuotaFissaContatore, "E/ms.", "=") + IF(D_RIP_NOL="",D_ADD_ACC_NOL,D_RIP_NOL) "NO" 4 Contratto - + DATA 0 Anticipo "01/01/2004" diff --git a/omnia/xml.cpp b/omnia/xml.cpp index 82db32e4d..71f5a9210 100755 --- a/omnia/xml.cpp +++ b/omnia/xml.cpp @@ -48,6 +48,11 @@ const TString& EscapeSequence(char cStart, istream& inf) { for (char c = inf.get(); c != ';'; c = inf.get()) str << c; + if (str[0] == '#') + { + char c = hex2int(str); + str = c; + } if (str == "lt") return str ="<"; if (str == "gt") return str =">"; if (str == "nbsp") return str =" ";