X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fd15d8f1b0b437312a117b7e4509708a22e30806..787d22ec24ac07aa61154eb1eea9c4183e6efcc5:/src/common/wxexpr.cpp diff --git a/src/common/wxexpr.cpp b/src/common/wxexpr.cpp index 67e5f100e7..b470a98ecc 100644 --- a/src/common/wxexpr.cpp +++ b/src/common/wxexpr.cpp @@ -20,6 +20,8 @@ #pragma hdrstop #endif +#if wxUSE_PROLOGIO + #include #include #include @@ -33,6 +35,77 @@ extern "C" void LexFromFile(FILE *fd); extern "C" void LexFromString(char *buf); + +/* Rename all YACC/LEX stuff or we'll conflict with other + * applications + */ + +#define yyback PROIO_yyback +#define yylook PROIO_yylook +#define yywrap PROIO_yywrap +#define yyoutput PROIO_yyoutput +#define yylex PROIO_yylex +#define yyerror PROIO_yyerror +#define yyleng PROIO_yyleng +#define yytext PROIO_yytext +#define yymorfg PROIO_yymorfg +#define yylineno PROIO_yylineno +#define yytchar PROIO_yytchar +#define yyin PROIO_yyin +#define yyout PROIO_yyout +#define yysvf PROIO_yysvf +#define yyestate PROIO_yyestate +#define yysvec PROIO_yysvec +#define yybgin PROIO_yybgin +#define yyprevious PROIO_yyprevious +#define yylhs PROIO_yylhs +#define yylen PROIO_yylen +#define yydefred PROIO_yydefred +#define yydgoto PROIO_yydgoto +#define yysindex PROIO_yysindex +#define yyrindex PROIO_yyrindex +#define yygindex PROIO_yygindex +#define yytable PROIO_yytable +#define yycheck PROIO_yycheck +#define yyname PROIO_yyname +#define yyrule PROIO_yyrule +#define yydebug PROIO_yydebug +#define yynerrs PROIO_yynerrs +#define yyerrflag PROIO_yyerrflag +#define yychar PROIO_yychar +#define yyvsp PROIO_yyvsp +#define yyssp PROIO_yyssp +#define yyval PROIO_yyval +#define yylval PROIO_yylval +#define yyss PROIO_yyss +#define yyvs PROIO_yyvs +#define yyparse PROIO_yyparse + +/* +++steve162e: more defines necessary */ +#define yy_init_buffer PROIO_yy_init_buffer +#define yy_create_buffer PROIO_yy_create_buffer +#define yy_load_buffer_state PROIO_yy_load_buffer_state +#define yyrestart PROIO_yyrestart +#define yy_switch_to_buffer PROIO_yy_switch_to_buffer +#define yy_delete_buffer PROIO_yy_delete_buffer +/* ---steve162e */ + +/* WG 1/96: still more for flex 2.5 */ +#define yy_scan_buffer PROIO_scan_buffer +#define yy_scan_string PROIO_scan_string +#define yy_scan_bytes PROIO_scan_bytes +#define yy_flex_debug PROIO_flex_debug +#define yy_flush_buffer PROIO_flush_buffer +#if !defined(__VISAGECPP__) +/* multiply defined??? */ +#define yyleng PROIO_yyleng +#define yytext PROIO_yytext +#endif + +extern "C" WXDLLEXPORT_DATA(FILE*) yyin; +extern "C" WXDLLEXPORT int yyparse(void); + + wxExprDatabase *thewxExprDatabase = NULL; wxExprErrorHandler currentwxExprErrorHandler; @@ -275,12 +348,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(_T("")); + return wxString(wxT("")); if (value.first->type == wxExprWord) return wxString(value.first->value.word); else - return wxString(_T("")); + return wxString(wxT("")); } bool wxExpr::IsFunctor(const wxString& f) const // Use only for a clause @@ -390,7 +463,7 @@ void wxExpr::AddAttributeValue(const wxString& attribute, wxExpr *val) // DeleteAttributeValue(attribute); wxExpr *patt = new wxExpr(wxExprWord, attribute); - wxExpr *pequals = new wxExpr(wxExprWord, _T("=")); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); wxExpr *listExpr = new wxExpr(wxExprList); @@ -414,7 +487,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, _T("=")); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); wxExpr *listExpr = new wxExpr(wxExprList); @@ -436,7 +509,7 @@ void wxExpr::AddAttributeValue(const wxString& attribute, double val) // DeleteAttributeValue(attribute); wxExpr *patt = new wxExpr(wxExprWord, attribute); wxExpr *pval = new wxExpr(val); - wxExpr *pequals = new wxExpr(wxExprWord, _T("=")); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); wxExpr *listExpr = new wxExpr(wxExprList); @@ -459,7 +532,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, _T("=")); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); wxExpr *listExpr = new wxExpr(wxExprList); @@ -482,7 +555,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, _T("=")); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); wxExpr *listExpr = new wxExpr(wxExprList); @@ -507,7 +580,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, _T("=")); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); wxExpr *listExpr = new wxExpr(wxExprList); @@ -535,7 +608,7 @@ void wxExpr::AddAttributeValueStringList(const wxString& attribute, wxList *stri wxNode *node = string_list->First(); while (node) { - char *string = (char *)node->Data(); + wxChar *string = (wxChar*)node->GetData(); wxExpr *expr = new wxExpr(wxExprString, wxString(string)); listExpr->Append(expr); node = node->Next(); @@ -543,7 +616,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, _T("=")); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); wxExpr *listExpr2 = new wxExpr(wxExprList); @@ -719,17 +792,17 @@ void wxExpr::WriteExpr(FILE* stream) // Write as any other subexpression case wxExprString: { fprintf( stream, "\"" ); - int i; + size_t i; const wxWX2MBbuf val = wxConvLibc.cWX2MB(value.string); - int len = strlen(val); + size_t len = strlen(val); for (i = 0; i < len; i++) { char ch = val[i]; if (ch == '"' || ch == '\\') - fprintf( stream, "\\" ); - char tmp[2]; - tmp[0] = ch; - tmp[1] = 0; + fprintf( stream, "\\" ); + char tmp[2]; + tmp[0] = ch; + tmp[1] = 0; fprintf( stream, tmp ); } fprintf( stream, "\"" ); @@ -739,12 +812,12 @@ void wxExpr::WriteExpr(FILE* stream) // Write as any other subexpression { bool quote_it = FALSE; const wxWX2MBbuf val = wxConvLibc.cWX2MB(value.word); - int len = strlen(val); - if ((len == 0) || (len > 0 && (val[0] > 64 && val[0] < 91))) + size_t len = strlen(val); + if ((len == 0) || (len > 0 && (val[(size_t) 0] > 64 && val[(size_t) 0] < 91))) quote_it = TRUE; else { - int i; + size_t i; for (i = 0; i < len; i++) if ((!isalpha(val[i])) && (!isdigit(val[i])) && (val[i] != '_')) @@ -754,7 +827,7 @@ void wxExpr::WriteExpr(FILE* stream) // Write as any other subexpression if (quote_it) fprintf( stream ,"'" ); - fprintf( stream, (const char*) val ); + fprintf( stream, val ); if (quote_it) fprintf( stream, "'" ); @@ -769,7 +842,7 @@ void wxExpr::WriteExpr(FILE* stream) // Write as any other subexpression { wxExpr *expr = value.first; - if ((expr->Type() == wxExprWord) && (wxStrcmp(expr->WordValue(), _T("=")) == 0)) + if ((expr->Type() == wxExprWord) && (wxStrcmp(expr->WordValue(), wxT("=")) == 0)) { wxExpr *arg1 = expr->next; wxExpr *arg2 = arg1->next; @@ -785,7 +858,7 @@ void wxExpr::WriteExpr(FILE* stream) // Write as any other subexpression expr->WriteExpr(stream); expr = expr->next; if (expr) - fprintf( stream, ", " ); + fprintf( stream, ", " ); } fprintf( stream, "]" ); } @@ -796,61 +869,11 @@ void wxExpr::WriteExpr(FILE* stream) // Write as any other subexpression } } -void wxExpr::WriteLispExpr(FILE* stream) -{ - switch (type) - { - case wxExprInteger: - { - fprintf( stream, "%ld", value.integer ); - break; - } - case wxExprReal: - { - fprintf( stream, "%.6g", value.real ); - break; - } - case wxExprString: - { - fprintf( stream, "\"" ); - const wxWX2MBbuf val = wxConvLibc.cWX2MB(value.string); - fprintf( stream, (const char*) val ); - fprintf( stream, "\"" ); - break; - } - case wxExprWord: - { - const wxWX2MBbuf val = wxConvLibc.cWX2MB(value.word); - fprintf( stream, (const char*) val ); - break; - } - case wxExprList: - { - wxExpr *expr = value.first; - - fprintf( stream, "(" ); - while (expr) - { - expr->WriteLispExpr(stream); - expr = expr->next; - if (expr) - fprintf( stream, " " ); - } - - fprintf( stream, ")" ); - break; - } - case wxExprNull: break; - } -} - /* * wxExpr 'database' (list of expressions) */ -#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxExprDatabase, wxList) -#endif wxExprDatabase::wxExprDatabase(wxExprErrorHandler handler) { @@ -897,7 +920,7 @@ wxExpr *wxExprDatabase::FindClause(long id) // Find a term based on an integer if (term->Type() == wxExprList) { - wxExpr *value = term->AttributeValue("id"); + wxExpr *value = term->AttributeValue(wxT("id")); if (value->Type() == wxExprInteger && value->IntegerValue() == id) found = term; } @@ -1042,7 +1065,7 @@ bool wxExprDatabase::Read(const wxString& filename) { noErrors = 0; - FILE *f = fopen(filename.fn_str(), "r"); + FILE *f = wxFopen(filename, _T("r")); if (f) { thewxExprDatabase = this; @@ -1066,7 +1089,7 @@ bool wxExprDatabase::ReadFromString(const wxString& buffer) thewxExprDatabase = this; const wxWX2MBbuf buf = buffer.mb_str(); - LexFromString(MBSTRINGCAST buf); + LexFromString(wxMBSTRINGCAST buf); yyparse(); wxExprCleanUp(); return (noErrors == 0); @@ -1074,12 +1097,14 @@ bool wxExprDatabase::ReadFromString(const wxString& buffer) bool wxExprDatabase::Write(const wxString& fileName) { - FILE *stream = fopen( fileName.fn_str(), "w+" ); + FILE *stream = wxFopen( fileName, _T("w+")); if (!stream) return FALSE; - return Write(stream); + bool success = Write(stream); + fclose(stream); + return success; } bool wxExprDatabase::Write(FILE *stream) @@ -1095,19 +1120,6 @@ bool wxExprDatabase::Write(FILE *stream) return (noErrors == 0); } -void wxExprDatabase::WriteLisp(FILE* stream) -{ - noErrors = 0; - wxNode *node = First(); - while (node) - { - wxExpr *expr = (wxExpr *)node->Data(); - expr->WriteLispExpr(stream); - fprintf( stream, "\n\n" ); - node = node->Next(); - } -} - void add_expr(wxExpr * expr) { thewxExprDatabase->Append(expr); @@ -1184,14 +1196,14 @@ char *wxmake_exp2(char *str1, char *str2, char *str3) char *wxmake_word(char *str) { - wxExpr *x = new wxExpr(wxExprWord, str); + wxExpr *x = new wxExpr(wxExprWord, wxString(str, wxConvLibc).c_str()); return (char *)x; } char *wxmake_string(char *str) { wxChar *s, *t; - int len, i; + size_t len, i; const wxMB2WXbuf sbuf = wxConvLibc.cMB2WX(str); // str++; /* skip leading quote */ @@ -1202,21 +1214,21 @@ char *wxmake_string(char *str) t = s; for(i=1; inoErrors += 1; } @@ -1262,3 +1274,5 @@ WXDLLEXPORT char *strdup(const char *s) #endif #endif +#endif + // wxUSE_PROLOGIO