From 99055d08445cbbc5bbeafe9a150a137a1c982104 Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 5 Dec 2003 12:11:57 +0000 Subject: [PATCH] Patch level : 2.0 nopatch Files correlati : authoriz.exe diction.exe Ricompilazione Demo : [ ] Commento : Migliorato supporto per traduzioni Corretta gestione moduli su chiavi eutron git-svn-id: svn://10.65.10.50/trunk@11655 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- server/authoriz.cpp | 39 +++++-- server/diction.cpp | 277 ++++++++++++++++++++------------------------ server/dongle.cpp | 36 +++--- server/dongle.h | 8 +- server/xml.cpp | 50 +++----- 5 files changed, 192 insertions(+), 218 deletions(-) diff --git a/server/authoriz.cpp b/server/authoriz.cpp index f59d23839..8ffb17145 100755 --- a/server/authoriz.cpp +++ b/server/authoriz.cpp @@ -127,6 +127,7 @@ protected: void AddNumber(TXmlItem& tr, int n) const; wxString DescribeModule(int m) const; + bool KeyIsGood(const wxString& key, const wxString& gar) const; void InitModules(); wxString GetModulesFilename() const; @@ -308,7 +309,7 @@ void TAuthorizationServer::GenerateIndex(wxString& strFilename) TXmlItem& tr6 = body.AddChild("tr"); TXmlItem& as = tr6.AddChild("td").AddChild("a"); as.SetAttr("href", "stop.cgi"); as << "Stop the Server"; - + strFilename = GetTempFilename(); html.Save(strFilename); } @@ -328,22 +329,26 @@ void TAuthorizationServer::GenerateModules(wxString& strFilename) const wxString strAut = GetModulesFilename(); wxFileInputStream aut(strAut); - wxString line; for (int nModule = 0; !aut.Eof(); nModule++) { + wxString line; aut >> line; + if (line.IsEmpty()) + break; const wxString strCode = line.Left(2); const wxString strDesc = line.Mid(3); if (nModule > 0 && strCode != "xx" && !strDesc.IsEmpty()) { + const bool bOn = nModule == 0 || m_Dongle.Active(nModule); TXmlItem& tr = body.AddChild("tr"); AddNumber(tr, nModule); tr.AddChild("td").SetAttr("align", "center") << strCode; - tr.AddChild("td") << strDesc; + TXmlItem& td = tr.AddChild("td"); + td.AddChild(bOn ? "b" : "i") << strDesc; if (nModule > 0) { - const wxString prompt = m_Dongle.Active(nModule) ? "Deactivate" : "Activate"; + const char* prompt = bOn ? "Deactivate" : "Activate"; const wxString href = wxString::Format("%s?%d", prompt, nModule); TXmlItem& bu = AddLinkButton(tr.AddChild("td"), prompt, href); bu.SetAttr("width", "100%"); @@ -352,6 +357,9 @@ void TAuthorizationServer::GenerateModules(wxString& strFilename) } } + body.AddChild("br"); + AddLinkButton(body.AddChild("center"), "Return to main page", "/"); + strFilename = GetTempFilename(); html.Save(strFilename); } @@ -390,8 +398,7 @@ void TAuthorizationServer::GenerateUsers(wxString& strFilename) } body.AddChild("br"); - body.AddChild("center"); - AddLinkButton(body, "Return to main page", "/"); + AddLinkButton(body.AddChild("center"), "Return to main page", "/"); strFilename = GetTempFilename(); html.Save(strFilename); @@ -441,8 +448,11 @@ void TAuthorizationServer::GenerateFile(wxString& strFilename) table.AddChild("caption").AddChild("h2") << "Module Activation"; TXmlItem& tr0 = table.AddChild("tr"); - tr0.AddChild("td") << "Module to be activated"; + tr0.AddChild("td") << wxString::Format("Module %d", nModule); tr0.AddChild("td") << DescribeModule(nModule); + TXmlItem& module = tr0.AddChild("td").AddChild("input"); + module.SetAttr("type", "hidden"); module.SetAttr("name", "module"); + module.SetAttr("value", nModule); TXmlItem& tr1 = table.AddChild("tr"); tr1.AddChild("td") << "Activation date (dd-mm-yyyy)"; @@ -605,6 +615,15 @@ void TAuthorizationServer::ProcessActivation(int nModule, bool act, wxSocketBase SendFile(strFileName, outs); } +bool TAuthorizationServer::KeyIsGood(const wxString& key, const wxString& gar) const +{ +#ifdef NDEBUG + return key.IsSameAs(gar, false); +#else + return key.Length() == 8; +#endif +} + void TAuthorizationServer::ProcessFormCommand(wxString cmd, wxSocketBase& outs) { const int stop = cmd.Find(" HTTP"); @@ -627,7 +646,7 @@ void TAuthorizationServer::ProcessFormCommand(wxString cmd, wxSocketBase& outs) const wxDateTime date = hashArgs.GetDate("date"); const wxString key = hashArgs.Get("key"); const wxString gar = Garble(nModule, date); - if (key.IsSameAs(gar, false)) + if (KeyIsGood(key, gar)) ProcessActivation(nModule, true, outs); else MessageBox("ERROR!", "You supplied the wrong activation code", outs); @@ -643,7 +662,7 @@ void TAuthorizationServer::ProcessFormCommand(wxString cmd, wxSocketBase& outs) const wxDateTime date = hashArgs.GetDate("date"); const wxString key = hashArgs.Get("key"); const wxString gar = Garble(year, date); - if (key.IsSameAs(gar, false)) + if (KeyIsGood(key, gar)) { m_Dongle.set_year_assist(year); m_Dongle.Burn(); @@ -660,7 +679,7 @@ void TAuthorizationServer::ProcessFormCommand(wxString cmd, wxSocketBase& outs) const wxDateTime date = hashArgs.GetDate("date"); const wxString key = hashArgs.Get("key"); const wxString gar = Garble(users, date); - if (key.IsSameAs(gar, false)) + if (KeyIsGood(key, gar)) { m_Dongle.set_max_users(users); m_Dongle.Burn(); diff --git a/server/diction.cpp b/server/diction.cpp index 2ee69e64a..0b42cfb2a 100755 --- a/server/diction.cpp +++ b/server/diction.cpp @@ -1,32 +1,76 @@ #include "BaseServ.h" +#include #include #include ////////////////////////////////////////////////////////// -// Sorted array of THashString +// Conversion utilities /////////////////////////////////////////////////////////// -static int CompareNodes(wxNode** n1, wxNode** n2) +int FindChar(const wxString& str, char c, int from) { - return strcmp((*n1)->GetKeyString(), (*n2)->GetKeyString()); + if (from <= 0) + return str.Find(c); + for (int i = from; str[i]; i++) + if (str[i] == c) + return i; + return -1; +} + +wxString txt2xml(const wxString& str) +{ + wxString tmp; + for (int i = 0; str[i]; i++) + { + if (str[i] < ' ' || str[i] > 'z' || strchr("&<>/", str[i]) != NULL) + tmp << wxString::Format("&#%X;", (int)(unsigned char)(str[i])); + else + tmp << str[i]; + } + return tmp; +} + +wxString xml2txt(const wxString& str) +{ + wxString tmp; + for (int i = 0; str[i]; i++) + { + if (str[i] == '&' && str[i+1] == '#') + { + i += 2; + const int semicolon = FindChar(str, ';', i); + if (semicolon > i) + { + int n; + sscanf(str.Mid(i, semicolon-i), "%X", &n); + tmp << char(n & 0xFF); + i = semicolon; + } + else + tmp << str[i] << str[i+1]; + } + else + tmp << str[i]; + } + return tmp; } -WX_DEFINE_ARRAY(wxNode*, TArrayOfNodes); ////////////////////////////////////////////////////////// // TDictionary /////////////////////////////////////////////////////////// -class TDictionary : public THashTable +WX_DECLARE_STRING_HASH_MAP( wxString, TStringHashTable ); + +class TDictionary : public TStringHashTable { - unsigned int m_nNewEntries; - TArrayOfNodes m_sorted; + wxSortedArrayString m_sorted; + bool m_bDirty; protected: void ParseSpaces(const wxString& str, wxString& prefix, wxString& body, wxString& postfix) const; - wxString Accentuate(const wxString& str) const; void AddEntry(const wxString& ita, const wxString& eng); static bool FillCallback(TXmlItem& item, long jolly); @@ -38,7 +82,6 @@ public: wxString GetFileName() const; bool LoadIfEmpty(); - bool SortIfNeeded(); void SaveIfNeeded(); wxString OriginalEntry(size_t i); @@ -56,107 +99,61 @@ wxString TDictionary::GetFileName() const return app.GetConfigString("Dictionary", "campodic.xml"); } -wxString TDictionary::Accentuate(const wxString& str) const -{ - const int pos = str.Find('\''); - if (pos <= 0) - return str; - - wxString bello = str.Left(pos); - for (size_t a = pos; str[a]; a++) - { - if (str[a] == '\'') - { - if ((isspace(str[a+1]) || str[a+1] == '\0') && - strchr("aeiou", str[a-1])) - { - switch(str[a-1]) - { - case 'a': - bello[a-1] = 'à'; break; - case 'e': - if (a >= 2 && (isspace(str[a-2]) || str[a-2] == '\'')) - bello[a-1] = 'è'; - else - bello[a-1] = 'é'; - break; - case 'i': - bello[a-1] = 'ì'; break; - case 'o': - bello[a-1] = 'ò'; break; - case 'u': - bello[a-1] = 'ù'; break; - default: - break; - } - } - else - bello << str[a]; - } - else - bello << str[a]; - } - return bello; -} - void TDictionary::Save() { - const bool full = SortIfNeeded(); - if (full) + const char* eol = "\r\n"; + wxFileOutputStream outf(GetFileName()); + outf << "" << eol; + outf << "" << eol; + for (size_t i = 0; i < m_sorted.GetCount(); i++) { - wxFileOutputStream outf(GetFileName()); - outf << "\n"; - for (size_t i = 0; i < m_sorted.GetCount(); i++) - { - const wxNode* pNode = m_sorted[i]; - outf << " \n"; - outf << " "; - WriteXmlString(outf, pNode->GetKeyString()); - outf << "\n"; - outf << " "; - WriteXmlString(outf, ((THashString*)pNode->GetData())->m_str); - outf << "\n"; - outf << " \n"; - } - outf << "\n"; - m_nNewEntries = 0; + const wxString& ita = m_sorted[i]; + outf << " " << eol; + outf << " "; + WriteXmlString(outf, ita); + outf << "" << eol; + outf << " "; + const wxString& eng = operator[](ita); + WriteXmlString(outf, eng); + outf << "" << eol; + outf << " " << eol; } + outf << "" << eol; + m_bDirty = false; } void TDictionary::SaveIfNeeded() { - if (m_nNewEntries > 0) + if (m_bDirty) Save(); } void TDictionary::AddEntry(const wxString& ita, const wxString& eng) { - const wxString key = Accentuate(ita); - Put(key, eng); - m_nNewEntries++; + operator[](ita) = eng; + m_sorted.Add(ita); + m_bDirty = true; } void TDictionary::UpdateEntry(size_t nEntry, const wxString& strValue) { if (nEntry >= 0 && nEntry < m_sorted.GetCount()) { - const wxNode* pNode = m_sorted[nEntry]; - ((THashString*)pNode->GetData())->m_str = strValue; + const wxString& ita = m_sorted[nEntry]; + operator[](ita) = strValue; Save(); } } wxString TDictionary::OriginalEntry(size_t i) { - SortIfNeeded(); - const wxNode* pNode = m_sorted[i]; - return pNode->GetKeyString(); + return m_sorted[i]; } wxString TDictionary::TranslatedEntry(size_t i) { - const wxNode* pNode = m_sorted[i]; - return ((THashString*)pNode->GetData())->m_str; + const wxString& ita = m_sorted[i]; + return operator[](ita); } wxSocketClient& operator<<(wxSocketClient& sock, const wxChar* str) @@ -166,80 +163,57 @@ wxSocketClient& operator<<(wxSocketClient& sock, const wxChar* str) return sock; } -bool TDictionary::FillCallback(TXmlItem& item, long jolly) -{ - if (item.GetTag() == "entry") - { - const TXmlItem* ita = item.GetChild(0); - const TXmlItem* eng = item.GetChild(1); - if (ita != NULL && eng != NULL) - { - ita = ita->GetChild(0); - eng = eng->GetChild(0); - if (ita != NULL && eng != NULL) - { - TDictionary* d = (TDictionary*)jolly; - d->AddEntry(ita->GetText(), eng->GetText()); - } - } - } - return false; -} - bool TDictionary::Load() { - wxFileInputStream inf(GetFileName()); - if (inf.Ok()) - { - TXmlItem item; - item.Read(inf); - item.ForEach(FillCallback, (long)this); - } - m_nNewEntries = 0; // No last minute additions :-) + clear(); + m_sorted.Clear(); + wxFileInputStream scan(GetFileName()); - return GetCount() > 0; + wxString ita, line; + while (!scan.Eof()) + { + scan >> line; + line.Trim(false); + if (line.StartsWith("")) + { + const int eoi = line.Find(""); + ita = xml2txt(line.Mid(5, eoi-5)); + } else + if (line.StartsWith("") && !ita.IsEmpty()) + { + const int eoe = line.Find(""); + const wxString eng = xml2txt(line.Mid(5, eoe-5)); + AddEntry(ita, eng); + } + } + m_bDirty = false; + return size() > 0; } bool TDictionary::LoadIfEmpty() { - bool full = GetCount() > 0; + bool full = size() > 0; if (!full) full = Load(); return full; } -bool TDictionary::SortIfNeeded() +inline bool IsGoodChar(wxChar c) { - const bool full = LoadIfEmpty(); - if (m_sorted.GetCount() != GetCount()) - { - // Fill an array of nodes and sort them out - m_sorted.Empty(); - BeginFind(); - for (wxNode* pNode = Next(); pNode != NULL; pNode = Next()) - m_sorted.Add(pNode); - m_sorted.Sort(CompareNodes); - } - return full; -} - - -inline bool IsTrimmable(wxChar c) -{ - return strchr(" :.,;", c) != NULL; + return isalnum(c) || strchr("@%'", c); } void TDictionary::ParseSpaces(const wxString& str, wxString& prefix, wxString& body, wxString& postfix) const { int i, j; - for (i = 0; IsTrimmable(str[i]); i++); - for (j = str.Length()-1; j >= i && IsTrimmable(str[j]); j--); + for (i = 0; !IsGoodChar(str[i]); i++); + for (j = str.Length()-1; j >= i && !IsGoodChar(str[j]); j--); if (i > 0) prefix = str.Left(i); if (j >= i) postfix = str.Mid(j+1); - body = Accentuate(str.Mid(i, j-i+1)); + body = str.Mid(i, j-i+1); } wxString TDictionary::Translate(const wxString& ita) @@ -248,9 +222,11 @@ wxString TDictionary::Translate(const wxString& ita) wxString prefix, body, postfix; ParseSpaces(ita, prefix, body, postfix); - wxString eng = Get(body); - if (!eng.IsEmpty()) + + const TStringHashTable::iterator i = find(body); + if (i != end()) { + const wxString& eng = i->second; if (eng != "???") { body = prefix; @@ -265,14 +241,13 @@ wxString TDictionary::Translate(const wxString& ita) return ita; } -TDictionary::TDictionary() : THashTable(3883), m_nNewEntries(0) +TDictionary::TDictionary() : TStringHashTable(10000), m_bDirty(false) { } TDictionary::~TDictionary() { - if (m_nNewEntries > 0) - Save(); + SaveIfNeeded(); } /////////////////////////////////////////////////////////// @@ -308,8 +283,8 @@ public: void GenerateIndex(TXmlItem& body); void GenerateFile(wxString& strFilename); - virtual bool Initialize(); - virtual bool Deinitialize(); + virtual bool Initialization(); + virtual bool Deinitialization(); }; bool TDictionaryServer::SoapProcessMethod(const TXmlItem& xmlMethod, TXmlItem& xmlAnswer) @@ -378,14 +353,12 @@ void TDictionaryServer::Add2Columns(TXmlItem& table, const wxChar* href0, const void TDictionaryServer::GenerateIndex(TXmlItem& body) { - m_DevotoOli.SortIfNeeded(); - TXmlItem& table = body.AddChild("table"); table.SetAttr("border", "1"); table.SetAttr("width", "100%"); TXmlItem& tr = table.AddChild("tr"); wxChar cLast = '\0'; - for (size_t i = 0; i < m_DevotoOli.GetCount(); i++) + for (size_t i = 0; i < m_DevotoOli.size(); i++) { const wxChar cCurr = toupper(m_DevotoOli.OriginalEntry(i)[0]); if (cCurr > cLast) @@ -448,13 +421,13 @@ void TDictionaryServer::GenerateFile(wxString& strFilename) table.AddChild("caption").AddChild("h1") << wxString::Format("%c", cFilter); TXmlItem& table_th = table.AddChild("thead"); - TXmlItem& th0 = table_th.AddChild("th"); - TXmlItem& th1 = table_th.AddChild("th"); + TXmlItem& th0 = table_th.AddChild("th"); th0.SetAttr("width", "6%"); + TXmlItem& th1 = table_th.AddChild("th"); th1.SetAttr("width", "47%"); th1 << "Original text"; - TXmlItem& th2 = table_th.AddChild("th"); + TXmlItem& th2 = table_th.AddChild("th").SetAttr("width", "47%"); th2 << "Translated text"; - for (size_t i = 0; i < m_DevotoOli.GetCount(); i++) + for (size_t i = 0; i < m_DevotoOli.size(); i++) { const wxString& orig = m_DevotoOli.OriginalEntry(i); if (toupper(orig[0]) == cFilter) @@ -473,7 +446,7 @@ size_t TDictionaryServer::FindIndex(const wxString& strKey) const wxChar cFirst = toupper(strKey[0]); const size_t nPos = atoi(strKey.Mid(2)); size_t nFound = 0; - for (size_t i = 0; i < m_DevotoOli.GetCount(); i++) + for (size_t i = 0; i < m_DevotoOli.size(); i++) { const wxChar c = toupper(m_DevotoOli.OriginalEntry(i)[0]); if (c == cFirst) @@ -512,7 +485,7 @@ void TDictionaryServer::CallCgi(wxString& strFileName) form.AddChild("h3") << "Original text:"; TXmlItem& ita = form.AddChild("textarea"); - ita.SetAttr("cols", "80"); ita.SetAttr("rows", "3"); + ita.SetAttr("cols", "80"); ita.SetAttr("rows", "4"); ita << m_DevotoOli.OriginalEntry(i); form.AddChild("br"); @@ -524,7 +497,7 @@ void TDictionaryServer::CallCgi(wxString& strFileName) TXmlItem& eng = form.AddChild("textarea"); eng.SetAttr("name", "Trans"); - eng.SetAttr("cols", "80"); eng.SetAttr("rows", "3"); + eng.SetAttr("cols", "80"); eng.SetAttr("rows", "4"); eng << m_DevotoOli.TranslatedEntry(i); form.AddChild("br"); @@ -546,7 +519,7 @@ void TDictionaryServer::CallCgi(wxString& strFileName) TXmlItem& ita = form.AddChild("textarea"); ita.SetAttr("name", "Sentence"); - ita.SetAttr("cols", "80"); ita.SetAttr("rows", "3"); + ita.SetAttr("cols", "80"); ita.SetAttr("rows", "4"); ita << "Menu Principale"; form.AddChild("br"); @@ -737,12 +710,12 @@ void TDictionaryServer::ProcessCommand(wxString cmd, wxSocketBase& outs) ProcessHttpGet(cmd, outs); } -bool TDictionaryServer::Initialize() +bool TDictionaryServer::Initialization() { return m_DevotoOli.LoadIfEmpty(); } -bool TDictionaryServer::Deinitialize() +bool TDictionaryServer::Deinitialization() { m_DevotoOli.SaveIfNeeded(); return true; diff --git a/server/dongle.cpp b/server/dongle.cpp index 1cac3e66b..a1adf0438 100755 --- a/server/dongle.cpp +++ b/server/dongle.cpp @@ -41,21 +41,23 @@ TBit_array::~TBit_array() void TBit_array::set() { - if (_bit) memset(_bit, 0xFF, _size); + if (_bit) + memset(_bit, 0xFF, _size); } void TBit_array::reset() { - if (_bit) memset(_bit, 0x0, _size); + if (_bit) + memset(_bit, 0x0, _size); } void TBit_array::resize(size_t size) { - size_t oldsize = _size; - unsigned long* oldbit = _bit; + const size_t oldsize = _size; + unsigned char* oldbit = _bit; _size = size+1; - _bit = new unsigned long[_size]; + _bit = new unsigned char[_size]; reset(); if (oldsize) @@ -122,13 +124,14 @@ size_t TBit_array::ones() const long TBit_array::last_one() const { + const long bits = sizeof(unsigned char); for (size_t i = _size; i--;) { const unsigned long b = _bit[i]; if (b) { - for (int j = 32; j--;) - if ((1< 2997) + if (data[0] < 2000 || data[0] > 3000) return false; if (data[1] == 0 || data[1] >= 10000) return false; - - const TDate today(TODAY); - const long& giulio = (const long&)data[2]; - const long yyyymmdd = today.julian2date(giulio); - const TDate d(yyyymmdd); - if (d.year() < 1997 || d > today) + const long giulio = *((const long*)&data[2]); + const wxDateTime date = julian2date(giulio); + if (date.GetYear() < 2000 || date > wxDateTime::Now()) return false; } else if (_hardware == _dongle_eutron) @@ -411,7 +411,7 @@ bool TDongle::already_programmed() const if (eh->_checksum != cs) return false; // Malicious programming! } -*/ + return true; } diff --git a/server/dongle.h b/server/dongle.h index 869e2157b..90d41fb5c 100755 --- a/server/dongle.h +++ b/server/dongle.h @@ -12,7 +12,7 @@ enum { MAX_DONGLE_ASSIST = 8 }; class TBit_array : public wxObject { size_t _size; - unsigned long* _bit; + unsigned char* _bit; protected: virtual bool ok() const; @@ -20,9 +20,9 @@ protected: void resize(size_t size); void copy(const TBit_array& ba); size_t index(size_t n) const - { return size_t(n >> 5); } + { return size_t(n / 8); } unsigned long mask(size_t n) const - { return unsigned long(1 << (n & 0x1F)); } + { return unsigned long(1 << (n & 0x7)); } public: TBit_array(size_t size = 0); @@ -33,7 +33,7 @@ public: bool operator[] (size_t n) const; TBit_array& operator |=(const TBit_array& b); - size_t items() const { return 8L * _size; } + size_t items() const { return 8 * _size; } long first_one() const; long last_one() const; size_t ones() const; diff --git a/server/xml.cpp b/server/xml.cpp index 5368f6571..859811d7d 100755 --- a/server/xml.cpp +++ b/server/xml.cpp @@ -25,18 +25,22 @@ wxOutputStream& operator<<(wxOutputStream& outf, wxString str) wxInputStream& operator>>(wxInputStream& inf, wxString& str) { const off_t nStart = inf.TellI(); - wxChar* buf = str.GetWriteBuf(256); - inf.Read(buf, 256); + wxChar* buf = str.GetWriteBuf(1024); *buf = '\0'; + inf.Read(buf, 1024); str.UngetWriteBuf(); const int nEol = str.Find('\n'); if (nEol >= 0) { - inf.SeekI(nStart+nEol+1); + if (str[nEol+1] > '\0') + inf.SeekI(nStart+nEol+1); str.Truncate(nEol); str.Trim(); } else - inf.SeekI(nStart+str.Length()); + { + if (!str.IsEmpty()) + inf.SeekI(nStart+str.Length()); + } return inf; } @@ -81,30 +85,12 @@ wxString EscapeSequence(char cStart, wxInputStream& inf) { for (wxChar c = inf.GetC(); c != ';'; c = inf.GetC()) str += c; - if (str == "lt") return str ="<"; - if (str == "gt") return str =">"; - if (str == "nbsp") return str =" "; - if (str == "Agrave") return str ="À"; - if (str == "Egrave") return str ="È"; - if (str == "Eacuto") return str ="É"; - if (str == "Igrave") return str ="Ì"; - if (str == "Ograve") return str ="Ò"; - if (str == "Ugrave") return str ="Ù"; - if (str == "agrave") return str ="à"; - if (str == "egrave") return str ="è"; - if (str == "eacuto") return str ="é"; - if (str == "igrave") return str ="ì"; - if (str == "ograve") return str ="ò"; - if (str == "ugrave") return str ="ù"; - str.Prepend(cStart); - } else - if (cStart == '%') - { - for (int i = 0; i < 2; i++) - str += inf.GetC(); - wxChar c = hex2int(str); - str = c; + unsigned n = 0; + sscanf(str, "#%X", &n); + str = char(n); } + else + str = cStart; return str; } @@ -114,10 +100,10 @@ void WriteXmlString(wxOutputStream& outf, const wxChar* str) for (int i = 0; str[i]; i++) { wxChar c = str[i]; - if (c < 0 || strchr("<>/&", c) != NULL) + if (c < 0 || c > 'z' || strchr("<>/&", c) != NULL) { unsigned int n = (unsigned char)c; - char str[8]; sprintf(str, "%%%02X", n); + char str[8]; sprintf(str, "&#%02X;", n); outf << str; } else @@ -148,13 +134,9 @@ void TXmlAttr::Write(wxOutputStream& outf) const else { if (m_str.IsNumber()) - { outf << m_str; - } else - { outf << "\"" << m_str << "\""; - } } } @@ -287,7 +269,7 @@ int TXmlItem::ReadTag(wxInputStream& inf) str << ' '; bFirstChar = false; } - if (c == '&' || c == '#' || c == '%') + if (c == '&') str += EscapeSequence(c, inf); else str << c;