#pragma hdrstop
#endif
-#if wxUSE_IOSTREAMH
- #include <fstream.h>
-#else
- #include <fstream>
-#endif
-
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
#include "wx/utils.h"
-
#include "wx/expr.h"
#include "wx/wxexpr.h"
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
// 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);
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);
// 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);
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);
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);
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);
// 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);
}
}
-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;
+ fprintf( stream, "\"" );
+ 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 == '\\')
- 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;
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] != '_'))
}
if (quote_it)
- stream << "'";
+ fprintf( stream ,"'" );
- stream << val;
+ 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) && (wxStrcmp(expr->WordValue(), _T("=")) == 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)
*/
-#if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxExprDatabase, wxList)
-#endif
wxExprDatabase::wxExprDatabase(wxExprErrorHandler handler)
{
{
noErrors = 0;
- FILE *f = fopen(filename.fn_str(), "r");
+ FILE *f = wxFopen(filename, _T("r"));
if (f)
{
thewxExprDatabase = this;
thewxExprDatabase = this;
const wxWX2MBbuf buf = buffer.mb_str();
- LexFromString(MBSTRINGCAST buf);
+ LexFromString(wxMBSTRINGCAST buf);
yyparse();
wxExprCleanUp();
return (noErrors == 0);
bool wxExprDatabase::Write(const wxString& fileName)
{
- ofstream str(MBSTRINGCAST fileName.mb_str());
- 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 *wxmake_string(char *str)
{
wxChar *s, *t;
- int len, i;
+ size_t len, i;
const wxMB2WXbuf sbuf = wxConvLibc.cMB2WX(str);
// str++; /* skip leading quote */
t = s;
for(i=1; i<len; i++) // 1 since we want to skip leading quote
{
- if (sbuf[i] == _T('\\') && sbuf[i+1] == _T('"'))
+ if (sbuf[i] == wxT('\\') && sbuf[i+1] == wxT('"'))
{
- *t++ = _T('"');
+ *t++ = wxT('"');
i ++;
}
- else if (sbuf[i] == _T('\\') && sbuf[i+1] == _T('\\'))
+ else if (sbuf[i] == wxT('\\') && sbuf[i+1] == wxT('\\'))
{
- *t++ = _T('\\');
+ *t++ = wxT('\\');
i ++;
}
else
*t++ = sbuf[i];
}
- *t = _T('\0');
+ *t = wxT('\0');
wxExpr *x = new wxExpr(wxExprString, s, FALSE);
return (char *)x;