X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/10b959e3729a77b95ab15614d1bdce74da327d8b..34636400a0018eba4a1f63dda18cf32e944b959e:/src/common/wxexpr.cpp?ds=sidebyside diff --git a/src/common/wxexpr.cpp b/src/common/wxexpr.cpp index bb046c5fa8..227efb2850 100644 --- a/src/common/wxexpr.cpp +++ b/src/common/wxexpr.cpp @@ -6,7 +6,7 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -20,7 +20,12 @@ #pragma hdrstop #endif -#include +#if wxUSE_IOSTREAMH + #include +#else + #include +#endif + #include #include #include @@ -34,11 +39,10 @@ extern "C" void add_expr(char *); extern "C" void LexFromFile(FILE *fd); extern "C" void LexFromString(char *buf); + wxExprDatabase *thewxExprDatabase = NULL; wxExprErrorHandler currentwxExprErrorHandler; -IMPLEMENT_DYNAMIC_CLASS(wxExprDatabase, wxList) - wxExpr::wxExpr(const wxString& functor) { type = wxExprList; @@ -58,10 +62,10 @@ wxExpr::wxExpr(wxExprType the_type, const wxString& word_or_string) switch (the_type) { case wxExprWord: - value.word = copystring((const char *)word_or_string); + value.word = copystring((const wxChar *)word_or_string); break; case wxExprString: - value.string = copystring((const char *)word_or_string); + value.string = copystring((const wxChar *)word_or_string); break; case wxExprList: last = NULL; @@ -76,7 +80,7 @@ wxExpr::wxExpr(wxExprType the_type, const wxString& word_or_string) next = NULL; } -wxExpr::wxExpr(wxExprType the_type, char *word_or_string, bool allocate) +wxExpr::wxExpr(wxExprType the_type, wxChar *word_or_string, bool allocate) { type = the_type; @@ -109,7 +113,7 @@ wxExpr::wxExpr(long the_integer) next = NULL; } -wxExpr::wxExpr(float the_real) +wxExpr::wxExpr(double the_real) { type = wxExprReal; value.real = the_real; @@ -251,7 +255,7 @@ wxExpr *wxExpr::GetAttributeValueNode(const wxString& word) const // Use only fo { wxExpr *secondNode = firstNode->next; if ((secondNode->type == wxExprWord) && - (strcmp((const char *)word, secondNode->value.word) == 0)) + (wxStrcmp((const wxChar *)word, secondNode->value.word) == 0)) { return expr; } @@ -278,12 +282,12 @@ wxExpr *wxExpr::AttributeValue(const wxString& word) const // Use only for a cla wxString wxExpr::Functor(void) const // Use only for a clause { if ((type != wxExprList) || !value.first) - return wxString(""); + return wxString(_T("")); if (value.first->type == wxExprWord) return wxString(value.first->value.word); else - return wxString(""); + return wxString(_T("")); } bool wxExpr::IsFunctor(const wxString& f) const // Use only for a clause @@ -292,7 +296,7 @@ bool wxExpr::IsFunctor(const wxString& f) const // Use only for a clause return FALSE; return (value.first->type == wxExprWord && - (strcmp((const char *)f, value.first->value.word) == 0)); + (wxStrcmp((const wxChar *)f, value.first->value.word) == 0)); } // Return nth argument of a clause (starting from 1) @@ -361,7 +365,7 @@ void wxExpr::DeleteAttributeValue(const wxString& attribute) { wxExpr *secondNode = firstNode->next; if ((secondNode->type == wxExprWord) && - (strcmp((const char *)attribute, secondNode->value.word) == 0)) + (wxStrcmp((const wxChar *)attribute, secondNode->value.word) == 0)) { wxExpr *nextExpr = expr->next; delete expr; @@ -393,7 +397,7 @@ void wxExpr::AddAttributeValue(const wxString& attribute, wxExpr *val) // DeleteAttributeValue(attribute); wxExpr *patt = new wxExpr(wxExprWord, attribute); - wxExpr *pequals = new wxExpr(wxExprWord, "="); + wxExpr *pequals = new wxExpr(wxExprWord, _T("=")); wxExpr *listExpr = new wxExpr(wxExprList); @@ -417,7 +421,7 @@ void wxExpr::AddAttributeValue(const wxString& attribute, long val) wxExpr *patt = new wxExpr(wxExprWord, attribute); wxExpr *pval = new wxExpr(val); - wxExpr *pequals = new wxExpr(wxExprWord, "="); + wxExpr *pequals = new wxExpr(wxExprWord, _T("=")); wxExpr *listExpr = new wxExpr(wxExprList); @@ -428,7 +432,7 @@ void wxExpr::AddAttributeValue(const wxString& attribute, long val) Append(listExpr); } -void wxExpr::AddAttributeValue(const wxString& attribute, float val) +void wxExpr::AddAttributeValue(const wxString& attribute, double val) { if (type != wxExprList) { @@ -439,7 +443,7 @@ void wxExpr::AddAttributeValue(const wxString& attribute, float val) // DeleteAttributeValue(attribute); wxExpr *patt = new wxExpr(wxExprWord, attribute); wxExpr *pval = new wxExpr(val); - wxExpr *pequals = new wxExpr(wxExprWord, "="); + wxExpr *pequals = new wxExpr(wxExprWord, _T("=")); wxExpr *listExpr = new wxExpr(wxExprList); @@ -462,7 +466,7 @@ void wxExpr::AddAttributeValueString(const wxString& attribute, const wxString& wxExpr *patt = new wxExpr(wxExprWord, attribute); wxExpr *pval = new wxExpr(wxExprString, val); - wxExpr *pequals = new wxExpr(wxExprWord, "="); + wxExpr *pequals = new wxExpr(wxExprWord, _T("=")); wxExpr *listExpr = new wxExpr(wxExprList); @@ -485,7 +489,7 @@ void wxExpr::AddAttributeValueWord(const wxString& attribute, const wxString& va wxExpr *patt = new wxExpr(wxExprWord, attribute); wxExpr *pval = new wxExpr(wxExprWord, val); - wxExpr *pequals = new wxExpr(wxExprWord, "="); + wxExpr *pequals = new wxExpr(wxExprWord, _T("=")); wxExpr *listExpr = new wxExpr(wxExprList); @@ -510,7 +514,7 @@ void wxExpr::AddAttributeValue(const wxString& attribute, wxList *val) wxExpr *patt = new wxExpr(wxExprWord, attribute); wxExpr *pval = new wxExpr(val); - wxExpr *pequals = new wxExpr(wxExprWord, "="); + wxExpr *pequals = new wxExpr(wxExprWord, _T("=")); wxExpr *listExpr = new wxExpr(wxExprList); @@ -546,7 +550,7 @@ void wxExpr::AddAttributeValueStringList(const wxString& attribute, wxList *stri // Now make an (=, Att, Value) triple wxExpr *patt = new wxExpr(wxExprWord, attribute); - wxExpr *pequals = new wxExpr(wxExprWord, "="); + wxExpr *pequals = new wxExpr(wxExprWord, _T("=")); wxExpr *listExpr2 = new wxExpr(wxExprList); @@ -584,6 +588,18 @@ bool wxExpr::GetAttributeValue(const wxString& att, long& var) const } bool wxExpr::GetAttributeValue(const wxString& att, float& var) const +{ + wxExpr *expr = AttributeValue(att); + if (expr && (expr->Type() == wxExprInteger || expr->Type() == wxExprReal)) + { + var = (float) expr->RealValue(); + return TRUE; + } + else + return FALSE; +} + +bool wxExpr::GetAttributeValue(const wxString& att, double& var) const { wxExpr *expr = AttributeValue(att); if (expr && (expr->Type() == wxExprInteger || expr->Type() == wxExprReal)) @@ -644,14 +660,14 @@ bool wxExpr::GetAttributeValueStringList(const wxString& att, wxList *var) const } // Compatibility -void wxExpr::AssignAttributeValue(char *att, char **var) const +void wxExpr::AssignAttributeValue(wxChar *att, wxChar **var) const { wxString str; if (GetAttributeValue(att, str)) { if (*var) delete[] *var; - *var = copystring((const char *) str); + *var = copystring((const wxChar *) str); } } @@ -702,7 +718,7 @@ void wxExpr::WriteExpr(ostream& stream) // Write as any other subexpression } case wxExprReal: { - float f = value.real; + double f = value.real; /* Now the parser can cope with this. // Prevent printing in 'e' notation. Any better way? if (fabs(f) < 0.00001) @@ -717,10 +733,11 @@ void wxExpr::WriteExpr(ostream& stream) // Write as any other subexpression { stream << "\""; int i; - int len = strlen(value.string); + const wxWX2MBbuf val = wxConv_libc.cWX2MB(value.string); + int len = strlen(val); for (i = 0; i < len; i++) { - char ch = value.string[i]; + char ch = val[i]; if (ch == '"' || ch == '\\') stream << "\\"; stream << ch; @@ -732,22 +749,23 @@ void wxExpr::WriteExpr(ostream& stream) // Write as any other subexpression case wxExprWord: { bool quote_it = FALSE; - int len = strlen(value.word); - if ((len == 0) || (len > 0 && (value.word[0] > 64 && value.word[0] < 91))) + const wxWX2MBbuf val = wxConv_libc.cWX2MB(value.word); + int len = strlen(val); + if ((len == 0) || (len > 0 && (val[0] > 64 && val[0] < 91))) quote_it = TRUE; else { int i; for (i = 0; i < len; i++) - if ((!isalpha(value.word[i])) && (!isdigit(value.word[i])) && - (value.word[i] != '_')) + if ((!isalpha(val[i])) && (!isdigit(val[i])) && + (val[i] != '_')) { quote_it = TRUE; i = len; } } if (quote_it) stream << "'"; - stream << value.word; + stream << val; if (quote_it) stream << "'"; @@ -762,7 +780,7 @@ void wxExpr::WriteExpr(ostream& stream) // Write as any other subexpression { wxExpr *expr = value.first; - if ((expr->Type() == wxExprWord) && (strcmp(expr->WordValue(), "=") == 0)) + if ((expr->Type() == wxExprWord) && (wxStrcmp(expr->WordValue(), _T("=")) == 0)) { wxExpr *arg1 = expr->next; wxExpr *arg2 = arg1->next; @@ -831,7 +849,14 @@ void wxExpr::WriteLispExpr(ostream& stream) } } -// wxExpr 'database' (list of expressions) +/* + * wxExpr 'database' (list of expressions) + */ + +#if !USE_SHARED_LIBRARIES +IMPLEMENT_DYNAMIC_CLASS(wxExprDatabase, wxList) +#endif + wxExprDatabase::wxExprDatabase(wxExprErrorHandler handler) { position = NULL; @@ -924,7 +949,7 @@ wxExpr *wxExprDatabase::FindClause(const wxString& word, long val) return found; } -wxExpr *wxExprDatabase::FindClause(const wxString& word, float val) +wxExpr *wxExprDatabase::FindClause(const wxString& word, double val) { wxExpr *found = NULL; while (position && !found) @@ -969,12 +994,12 @@ void wxExprDatabase::Append(wxExpr *clause) wxExpr *expr = clause->AttributeValue(attribute_to_hash); if (expr) { - long functor_key = hash_table->MakeKey((char *)(const char *)functor); + long functor_key = hash_table->MakeKey(WXSTRINGCAST functor); long value_key = 0; if (expr && expr->Type() == wxExprString) { - value_key = hash_table->MakeKey((char *)(const char *)expr->StringValue()); - hash_table->Put(functor_key + value_key, (char *)(const char *)expr->StringValue(), (wxObject *)clause); + value_key = hash_table->MakeKey(WXSTRINGCAST expr->StringValue()); + hash_table->Put(functor_key + value_key, WXSTRINGCAST expr->StringValue(), (wxObject *)clause); } else if (expr && expr->Type() == wxExprInteger) { @@ -988,7 +1013,7 @@ void wxExprDatabase::Append(wxExpr *clause) wxExpr *wxExprDatabase::HashFind(const wxString& functor, long value) const { - long key = hash_table->MakeKey((char *)(const char *)functor) + value; + long key = hash_table->MakeKey(WXSTRINGCAST functor) + value; // The key alone isn't guaranteed to be unique: // must supply value too. Let's assume the value of the @@ -998,8 +1023,8 @@ wxExpr *wxExprDatabase::HashFind(const wxString& functor, long value) const wxExpr *wxExprDatabase::HashFind(const wxString& functor, const wxString& value) const { - long key = hash_table->MakeKey((char *)(const char *)functor) + hash_table->MakeKey((char *)(const char *)value); - return (wxExpr *)hash_table->Get(key, (char *)(const char *)value); + long key = hash_table->MakeKey(WXSTRINGCAST functor) + hash_table->MakeKey(WXSTRINGCAST value); + return (wxExpr *)hash_table->Get(key, WXSTRINGCAST value); } void wxExprDatabase::ClearDatabase(void) @@ -1022,7 +1047,7 @@ bool wxExprDatabase::Read(const wxString& filename) { noErrors = 0; - FILE *f = fopen((const char *)filename, "r"); + FILE *f = fopen(filename.fn_str(), "r"); if (f) { thewxExprDatabase = this; @@ -1045,7 +1070,8 @@ bool wxExprDatabase::ReadFromString(const wxString& buffer) noErrors = 0; thewxExprDatabase = this; - LexFromString((char *)(const char *)buffer); + const wxWX2MBbuf buf = buffer.mb_str(); + LexFromString(MBSTRINGCAST buf); yyparse(); wxExprCleanUp(); return (noErrors == 0); @@ -1053,7 +1079,7 @@ bool wxExprDatabase::ReadFromString(const wxString& buffer) bool wxExprDatabase::Write(const wxString& fileName) { - ofstream str((char *)(const char *)fileName); + ofstream str(MBSTRINGCAST fileName.mb_str()); if (str.bad()) return FALSE; return Write(str); @@ -1112,19 +1138,19 @@ bool wxExprIsFunctor(wxExpr *expr, const wxString& functor) * */ -char *make_integer(char *str) +char *wxmake_integer(char *str) { wxExpr *x = new wxExpr(atol(str)); return (char *)x; } -char *make_real(char *str1, char *str2) +char *wxmake_real(char *str1, char *str2) { char buf[50]; sprintf(buf, "%s.%s", str1, str2); - float f = (float)atof(buf); + double f = (double)atof(buf); wxExpr *x = new wxExpr(f); return (char *)x; @@ -1132,19 +1158,19 @@ char *make_real(char *str1, char *str2) // extern "C" double exp10(double); -char *make_exp(char *str1, char *str2) +char *wxmake_exp(char *str1, char *str2) { double mantissa = (double)atoi(str1); double exponent = (double)atoi(str2); double d = mantissa * pow(10.0, exponent); - wxExpr *x = new wxExpr((float)d); + wxExpr *x = new wxExpr(d); return (char *)x; } -char *make_exp2(char *str1, char *str2, char *str3) +char *wxmake_exp2(char *str1, char *str2, char *str3) { char buf[50]; @@ -1154,45 +1180,46 @@ char *make_exp2(char *str1, char *str2, char *str3) double d = mantissa * pow(10.0, exponent); - wxExpr *x = new wxExpr((float)d); + wxExpr *x = new wxExpr(d); return (char *)x; } -char *make_word(char *str) +char *wxmake_word(char *str) { wxExpr *x = new wxExpr(wxExprWord, str); return (char *)x; } -char *make_string(char *str) +char *wxmake_string(char *str) { - char *s, *t; + wxChar *s, *t; int len, i; + const wxMB2WXbuf sbuf = wxConv_libc.cMB2WX(str); - str++; /* skip leading quote */ - len = strlen(str) - 1; /* ignore trailing quote */ +// str++; /* skip leading quote */ + len = wxStrlen(sbuf) - 1; /* ignore trailing quote */ - s = new char[len + 1]; + s = new wxChar[len + 1]; t = s; - for(i=0; i