// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
-// Licence: wxWindows license
+// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma hdrstop
#endif
-#if wxUSE_IOSTREAMH
-#include <fstream.h>
-#else
-#include <fstream>
-# ifdef _MSC_VER
- using namespace std;
-# endif
-#endif
-
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
#include "wx/utils.h"
-
#include "wx/expr.h"
#include "wx/wxexpr.h"
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;
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;
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;
{
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;
}
wxString wxExpr::Functor(void) const // Use only for a clause
{
if ((type != wxExprList) || !value.first)
- return wxString("");
+ return wxString(wxT(""));
if (value.first->type == wxExprWord)
return wxString(value.first->value.word);
else
- return wxString("");
+ return wxString(wxT(""));
}
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)
{
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;
// DeleteAttributeValue(attribute);
wxExpr *patt = new wxExpr(wxExprWord, attribute);
- wxExpr *pequals = new wxExpr(wxExprWord, "=");
+ wxExpr *pequals = new wxExpr(wxExprWord, wxT("="));
wxExpr *listExpr = new wxExpr(wxExprList);
wxExpr *patt = new wxExpr(wxExprWord, attribute);
wxExpr *pval = new wxExpr(val);
- wxExpr *pequals = new wxExpr(wxExprWord, "=");
+ wxExpr *pequals = new wxExpr(wxExprWord, wxT("="));
wxExpr *listExpr = new wxExpr(wxExprList);
// DeleteAttributeValue(attribute);
wxExpr *patt = new wxExpr(wxExprWord, attribute);
wxExpr *pval = new wxExpr(val);
- wxExpr *pequals = new wxExpr(wxExprWord, "=");
+ wxExpr *pequals = new wxExpr(wxExprWord, wxT("="));
wxExpr *listExpr = new wxExpr(wxExprList);
wxExpr *patt = new wxExpr(wxExprWord, attribute);
wxExpr *pval = new wxExpr(wxExprString, val);
- wxExpr *pequals = new wxExpr(wxExprWord, "=");
+ wxExpr *pequals = new wxExpr(wxExprWord, wxT("="));
wxExpr *listExpr = new wxExpr(wxExprList);
wxExpr *patt = new wxExpr(wxExprWord, attribute);
wxExpr *pval = new wxExpr(wxExprWord, val);
- wxExpr *pequals = new wxExpr(wxExprWord, "=");
+ wxExpr *pequals = new wxExpr(wxExprWord, wxT("="));
wxExpr *listExpr = new wxExpr(wxExprList);
wxExpr *patt = new wxExpr(wxExprWord, attribute);
wxExpr *pval = new wxExpr(val);
- wxExpr *pequals = new wxExpr(wxExprWord, "=");
+ wxExpr *pequals = new wxExpr(wxExprWord, wxT("="));
wxExpr *listExpr = new wxExpr(wxExprList);
// Now make an (=, Att, Value) triple
wxExpr *patt = new wxExpr(wxExprWord, attribute);
- wxExpr *pequals = new wxExpr(wxExprWord, "=");
+ wxExpr *pequals = new wxExpr(wxExprWord, wxT("="));
wxExpr *listExpr2 = new wxExpr(wxExprList);
}
// 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);
}
}
-void wxExpr::WriteClause(ostream& stream) // Write this expression as a top-level clause
+void wxExpr::WriteClause(FILE* stream) // Write this expression as a top-level clause
{
if (type != wxExprList)
return;
if (node)
{
node->WriteExpr(stream);
- stream << "(";
+ fprintf( stream, "(" );
node = node->next;
bool first = TRUE;
while (node)
{
if (!first)
- stream << " ";
+ fprintf( stream, " " );
node->WriteExpr(stream);
node = node->next;
- if (node) stream << ",\n";
+ if (node)
+ fprintf( stream, ",\n" );
first = FALSE;
}
- stream << ").\n\n";
+ fprintf( stream, ").\n\n" );
}
}
-void wxExpr::WriteExpr(ostream& stream) // Write as any other subexpression
+void wxExpr::WriteExpr(FILE* stream) // Write as any other subexpression
{
// This seems to get round an optimizer bug when
// using Watcom C++ 10a in WIN32 compilation mode.
{
case wxExprInteger:
{
- stream << value.integer;
+ fprintf( stream, "%ld", value.integer );
break;
}
case wxExprReal:
{
double f = value.real;
-/* Now the parser can cope with this.
- // Prevent printing in 'e' notation. Any better way?
- if (fabs(f) < 0.00001)
- f = 0.0;
-*/
- char buf[40];
- sprintf(buf, "%.6g", f);
- stream << buf;
+ fprintf( stream, "%.6g", f);
break;
}
case wxExprString:
{
- stream << "\"";
- int i;
- int len = strlen(value.string);
+ fprintf( stream, "\"" );
+ size_t i;
+ const wxWX2MBbuf val = wxConvLibc.cWX2MB(value.string);
+ size_t len = strlen(val);
for (i = 0; i < len; i++)
{
- char ch = value.string[i];
+ char ch = val[i];
if (ch == '"' || ch == '\\')
- stream << "\\";
- stream << ch;
+ fprintf( stream, "\\" );
+ char tmp[2];
+ tmp[0] = ch;
+ tmp[1] = 0;
+ fprintf( stream, tmp );
}
-
- stream << "\"";
+ fprintf( stream, "\"" );
break;
}
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 = wxConvLibc.cWX2MB(value.word);
+ 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(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 << "'";
+ fprintf( stream ,"'" );
- stream << value.word;
+ fprintf( stream, val );
if (quote_it)
- stream << "'";
+ fprintf( stream, "'" );
break;
}
case wxExprList:
{
if (!value.first)
- stream << "[]";
+ fprintf( stream, "[]" );
else
{
wxExpr *expr = value.first;
- if ((expr->Type() == wxExprWord) && (strcmp(expr->WordValue(), "=") == 0))
+ if ((expr->Type() == wxExprWord) && (wxStrcmp(expr->WordValue(), wxT("=")) == 0))
{
wxExpr *arg1 = expr->next;
wxExpr *arg2 = arg1->next;
arg1->WriteExpr(stream);
- stream << " = ";
+ fprintf( stream, " = " );
arg2->WriteExpr(stream);
}
else
{
- stream << "[";
+ fprintf( stream, "[" );
while (expr)
{
expr->WriteExpr(stream);
expr = expr->next;
- if (expr) stream << ", ";
+ if (expr)
+ fprintf( stream, ", " );
}
- stream << "]";
+ fprintf( stream, "]" );
}
}
break;
}
}
-void wxExpr::WriteLispExpr(ostream& stream)
-{
- switch (type)
- {
- case wxExprInteger:
- {
- stream << value.integer;
- break;
- }
- case wxExprReal:
- {
- stream << value.real;
- break;
- }
- case wxExprString:
- {
- stream << "\"" << value.string << "\"";
- break;
- }
- case wxExprWord:
- {
- stream << value.word;
- break;
- }
- case wxExprList:
- {
- wxExpr *expr = value.first;
-
- stream << "(";
- while (expr)
- {
- expr->WriteLispExpr(stream);
- expr = expr->next;
- if (expr) stream << " ";
- }
-
- stream << ")";
- break;
- }
- case wxExprNull: break;
- }
-}
+/*
+ * wxExpr 'database' (list of expressions)
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxExprDatabase, wxList)
-// wxExpr 'database' (list of expressions)
wxExprDatabase::wxExprDatabase(wxExprErrorHandler handler)
{
position = NULL;
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)
{
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
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)
{
noErrors = 0;
- FILE *f = fopen((const char *)filename, "r");
+ FILE *f = wxFopen(filename, _T("r"));
if (f)
{
thewxExprDatabase = this;
noErrors = 0;
thewxExprDatabase = this;
- LexFromString((char *)(const char *)buffer);
+ const wxWX2MBbuf buf = buffer.mb_str();
+ LexFromString(wxMBSTRINGCAST buf);
yyparse();
wxExprCleanUp();
return (noErrors == 0);
bool wxExprDatabase::Write(const wxString& fileName)
{
- ofstream str((char *)(const char *)fileName);
- if (str.bad())
+ FILE *stream = wxFopen( fileName, _T("w+"));
+
+ if (!stream)
return FALSE;
- return Write(str);
+
+ bool success = Write(stream);
+ fclose(stream);
+ return success;
}
-bool wxExprDatabase::Write(ostream& stream)
+bool wxExprDatabase::Write(FILE *stream)
{
noErrors = 0;
wxNode *node = First();
return (noErrors == 0);
}
-void wxExprDatabase::WriteLisp(ostream& stream)
-{
- noErrors = 0;
- wxNode *node = First();
- while (node)
- {
- wxExpr *expr = (wxExpr *)node->Data();
- expr->WriteLispExpr(stream);
- stream << "\n\n";
- node = node->Next();
- }
-}
-
void add_expr(wxExpr * expr)
{
thewxExprDatabase->Append(expr);
*
*/
-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];
// 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);
return (char *)x;
}
-char *make_exp2(char *str1, char *str2, char *str3)
+char *wxmake_exp2(char *str1, char *str2, char *str3)
{
char buf[50];
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;
- int len, i;
+ wxChar *s, *t;
+ size_t len, i;
+ const wxMB2WXbuf sbuf = wxConvLibc.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<len; i++)
+ for(i=1; i<len; i++) // 1 since we want to skip leading quote
{
- if (str[i] == '\\' && str[i+1] == '"')
+ if (sbuf[i] == wxT('\\') && sbuf[i+1] == wxT('"'))
{
- *t++ = '"';
+ *t++ = wxT('"');
i ++;
}
- else if (str[i] == '\\' && str[i+1] == '\\')
+ else if (sbuf[i] == wxT('\\') && sbuf[i+1] == wxT('\\'))
{
- *t++ = '\\';
+ *t++ = wxT('\\');
i ++;
}
else
- *t++ = str[i];
+ *t++ = sbuf[i];
}
- *t = '\0';
+ *t = wxT('\0');
wxExpr *x = new wxExpr(wxExprString, s, FALSE);
return (char *)x;
void syntax_error(char *WXUNUSED(s))
{
if (currentwxExprErrorHandler)
- (void)(*(currentwxExprErrorHandler))(WXEXPR_ERROR_SYNTAX, "syntax error");
+ (void)(*(currentwxExprErrorHandler))(WXEXPR_ERROR_SYNTAX, (char *)"syntax error");
if (thewxExprDatabase) thewxExprDatabase->noErrors += 1;
}