1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/deprecated/setup.h"
28 #include "wx/deprecated/expr.h"
29 #include "wx/deprecated/wxexpr.h"
31 #if !WXWIN_COMPATIBILITY_2_4
32 static inline wxChar
* copystring(const wxChar
* s
)
33 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
36 extern "C" void add_expr(char *);
37 extern "C" void LexFromFile(FILE *fd
);
38 extern "C" void LexFromString(char *buf
);
42 /* Rename all YACC/LEX stuff or we'll conflict with other
46 #define yyback PROIO_yyback
47 #define yylook PROIO_yylook
48 #define yywrap PROIO_yywrap
49 #define yyoutput PROIO_yyoutput
50 #define yylex PROIO_yylex
51 #define yyerror PROIO_yyerror
52 #define yyleng PROIO_yyleng
53 #define yytext PROIO_yytext
54 #define yymorfg PROIO_yymorfg
55 #define yylineno PROIO_yylineno
56 #define yytchar PROIO_yytchar
57 #define yyin PROIO_yyin
58 #define yyout PROIO_yyout
59 #define yysvf PROIO_yysvf
60 #define yyestate PROIO_yyestate
61 #define yysvec PROIO_yysvec
62 #define yybgin PROIO_yybgin
63 #define yyprevious PROIO_yyprevious
64 #define yylhs PROIO_yylhs
65 #define yylen PROIO_yylen
66 #define yydefred PROIO_yydefred
67 #define yydgoto PROIO_yydgoto
68 #define yysindex PROIO_yysindex
69 #define yyrindex PROIO_yyrindex
70 #define yygindex PROIO_yygindex
71 #define yytable PROIO_yytable
72 #define yycheck PROIO_yycheck
73 #define yyname PROIO_yyname
74 #define yyrule PROIO_yyrule
75 #define yydebug PROIO_yydebug
76 #define yynerrs PROIO_yynerrs
77 #define yyerrflag PROIO_yyerrflag
78 #define yychar PROIO_yychar
79 #define yyvsp PROIO_yyvsp
80 #define yyssp PROIO_yyssp
81 #define yyval PROIO_yyval
82 #define yylval PROIO_yylval
83 #define yyss PROIO_yyss
84 #define yyvs PROIO_yyvs
85 #define yyparse PROIO_yyparse
87 /* +++steve162e: more defines necessary */
88 #define yy_init_buffer PROIO_yy_init_buffer
89 #define yy_create_buffer PROIO_yy_create_buffer
90 #define yy_load_buffer_state PROIO_yy_load_buffer_state
91 #define yyrestart PROIO_yyrestart
92 #define yy_switch_to_buffer PROIO_yy_switch_to_buffer
93 #define yy_delete_buffer PROIO_yy_delete_buffer
96 /* WG 1/96: still more for flex 2.5 */
97 #define yy_scan_buffer PROIO_scan_buffer
98 #define yy_scan_string PROIO_scan_string
99 #define yy_scan_bytes PROIO_scan_bytes
100 #define yy_flex_debug PROIO_flex_debug
101 #define yy_flush_buffer PROIO_flush_buffer
102 #if !defined(__VISAGECPP__)
103 /* multiply defined??? */
104 #define yyleng PROIO_yyleng
105 #define yytext PROIO_yytext
108 extern "C" WXDLLIMPEXP_DATA_DEPRECATED(FILE*) yyin
;
109 extern "C" WXDLLIMPEXP_DEPRECATED
int yyparse(void);
112 wxExprDatabase
*thewxExprDatabase
= NULL
;
113 wxExprErrorHandler currentwxExprErrorHandler
;
115 wxExpr::wxExpr(const wxString
& functor
)
122 wxExpr
*pfunctor
= new wxExpr(wxExprWord
, functor
);
127 wxExpr::wxExpr(wxExprType the_type
, const wxString
& word_or_string
)
134 value
.word
= copystring((const wxChar
*)word_or_string
);
137 value
.string
= copystring((const wxChar
*)word_or_string
);
152 wxExpr::wxExpr(wxExprType the_type
, wxChar
*word_or_string
, bool allocate
)
159 value
.word
= allocate
? copystring(word_or_string
) : word_or_string
;
162 value
.string
= allocate
? copystring(word_or_string
) : word_or_string
;
177 wxExpr::wxExpr(long the_integer
)
179 type
= wxExprInteger
;
180 value
.integer
= the_integer
;
185 wxExpr::wxExpr(double the_real
)
188 value
.real
= the_real
;
193 wxExpr::wxExpr(wxList
*the_list
)
200 wxExpr
*listExpr
= new wxExpr(wxExprList
);
202 wxNode
*node
= the_list
->GetFirst();
205 wxExpr
*expr
= (wxExpr
*)node
->GetData();
206 listExpr
->Append(expr
);
207 node
= node
->GetNext();
214 wxExpr::~wxExpr(void)
225 delete[] value
.string
;
235 wxExpr
*expr
= value
.first
;
238 wxExpr
*expr1
= expr
->next
;
245 case wxExprNull
: break;
249 void wxExpr::Append(wxExpr
*expr
)
259 void wxExpr::Insert(wxExpr
*expr
)
261 expr
->next
= value
.first
;
268 wxExpr
*wxExpr::Copy(void) const
270 // This seems to get round an optimizer bug when
271 // using Watcom C++ 10a in WIN32 compilation mode.
272 // If these lines not present, the type seems to be
273 // interpreted wrongly as an integer.
274 // I don't want to turn optimization off since it's needed
275 // for reading in files quickly.
276 #if defined(__WATCOMC__)
284 return new wxExpr(value
.integer
);
286 return new wxExpr(value
.real
);
288 return new wxExpr(wxExprString
, wxString(value
.string
));
290 return new wxExpr(wxExprWord
, wxString(value
.word
));
293 wxExpr
*expr
= value
.first
;
294 wxExpr
*new_list
= new wxExpr(wxExprList
);
297 wxExpr
*expr2
= expr
->Copy();
298 new_list
->Append(expr2
);
310 // Get the wxExpr (containing (= wxExpr Value) form) for the given word
311 // or string, assuming that we have Attribute=Value, ...
312 wxExpr
*wxExpr::GetAttributeValueNode(const wxString
& word
) const // Use only for a clause or list
314 if (type
!= wxExprList
)
317 wxExpr
*expr
= value
.first
;
320 if (expr
->type
== wxExprList
)
322 wxExpr
*firstNode
= expr
->value
.first
;
323 if ((firstNode
->type
== wxExprWord
) && (firstNode
->value
.word
[0] == '='))
325 wxExpr
*secondNode
= firstNode
->next
;
326 if ((secondNode
->type
== wxExprWord
) &&
327 (wxStrcmp((const wxChar
*)word
, secondNode
->value
.word
) == 0))
338 // Get the value (in wxExpr form) for the given word or string, assuming
339 // that we have Attribute=Value, ...
340 wxExpr
*wxExpr::AttributeValue(const wxString
& word
) const // Use only for a clause or list
342 if (type
!= wxExprList
)
345 wxExpr
*attExpr
= GetAttributeValueNode(word
);
346 if (attExpr
&& attExpr
->value
.first
&& attExpr
->value
.first
->next
)
347 return attExpr
->value
.first
->next
->next
;
351 wxString
wxExpr::Functor(void) const // Use only for a clause
353 if ((type
!= wxExprList
) || !value
.first
)
354 return wxString(wxT(""));
356 if (value
.first
->type
== wxExprWord
)
357 return wxString(value
.first
->value
.word
);
359 return wxString(wxT(""));
362 bool wxExpr::IsFunctor(const wxString
& f
) const // Use only for a clause
364 if ((type
!= wxExprList
) || !value
.first
)
367 return (value
.first
->type
== wxExprWord
&&
368 (wxStrcmp((const wxChar
*)f
, value
.first
->value
.word
) == 0));
371 // Return nth argument of a clause (starting from 1)
372 wxExpr
*wxExpr::Arg(wxExprType theType
, int arg
) const
374 wxExpr
*expr
= value
.first
;
376 for (i
= 1; i
< arg
; i
++)
380 if (expr
&& (expr
->type
== theType
))
386 // Return nth argument of a list expression (starting from zero)
387 wxExpr
*wxExpr::Nth(int arg
) const
389 if (type
!= wxExprList
)
392 wxExpr
*expr
= value
.first
;
394 for (i
= 0; i
< arg
; i
++)
405 // Returns the number of elements in a list expression
406 int wxExpr::Number(void) const
408 if (type
!= wxExprList
)
412 wxExpr
*expr
= value
.first
;
421 void wxExpr::DeleteAttributeValue(const wxString
& attribute
)
423 if (type
!= wxExprList
)
426 wxExpr
*expr
= value
.first
;
427 wxExpr
*lastExpr
= this;
430 if (expr
->type
== wxExprList
)
432 wxExpr
*firstNode
= expr
->value
.first
;
433 if ((firstNode
->type
== wxExprWord
) && (firstNode
->value
.word
[0] == '='))
435 wxExpr
*secondNode
= firstNode
->next
;
436 if ((secondNode
->type
== wxExprWord
) &&
437 (wxStrcmp((const wxChar
*)attribute
, secondNode
->value
.word
) == 0))
439 wxExpr
*nextExpr
= expr
->next
;
442 lastExpr
->next
= nextExpr
;
457 void wxExpr::AddAttributeValue(const wxString
& attribute
, wxExpr
*val
)
459 if (type
!= wxExprList
)
461 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
464 // Warning - existing code may assume that any existing value
465 // is deleted first. For efficiency, we leave this to the application.
466 // DeleteAttributeValue(attribute);
468 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
469 wxExpr
*pequals
= new wxExpr(wxExprWord
, wxT("="));
471 wxExpr
*listExpr
= new wxExpr(wxExprList
);
473 listExpr
->Append(pequals
);
474 listExpr
->Append(patt
);
475 listExpr
->Append(val
);
480 void wxExpr::AddAttributeValue(const wxString
& attribute
, long val
)
482 if (type
!= wxExprList
)
484 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
487 // Warning - existing code may assume that any existing value
488 // is deleted first. For efficiency, we leave this to the application.
489 // DeleteAttributeValue(attribute);
491 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
492 wxExpr
*pval
= new wxExpr(val
);
493 wxExpr
*pequals
= new wxExpr(wxExprWord
, wxT("="));
495 wxExpr
*listExpr
= new wxExpr(wxExprList
);
497 listExpr
->Append(pequals
);
498 listExpr
->Append(patt
);
499 listExpr
->Append(pval
);
504 void wxExpr::AddAttributeValue(const wxString
& attribute
, double val
)
506 if (type
!= wxExprList
)
508 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
512 // DeleteAttributeValue(attribute);
513 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
514 wxExpr
*pval
= new wxExpr(val
);
515 wxExpr
*pequals
= new wxExpr(wxExprWord
, wxT("="));
517 wxExpr
*listExpr
= new wxExpr(wxExprList
);
519 listExpr
->Append(pequals
);
520 listExpr
->Append(patt
);
521 listExpr
->Append(pval
);
526 void wxExpr::AddAttributeValueString(const wxString
& attribute
, const wxString
& val
)
528 if (type
!= wxExprList
)
530 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
534 // DeleteAttributeValue(attribute);
536 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
537 wxExpr
*pval
= new wxExpr(wxExprString
, val
);
538 wxExpr
*pequals
= new wxExpr(wxExprWord
, wxT("="));
540 wxExpr
*listExpr
= new wxExpr(wxExprList
);
542 listExpr
->Append(pequals
);
543 listExpr
->Append(patt
);
544 listExpr
->Append(pval
);
549 void wxExpr::AddAttributeValueWord(const wxString
& attribute
, const wxString
& val
)
551 if (type
!= wxExprList
)
553 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
557 // DeleteAttributeValue(attribute);
559 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
560 wxExpr
*pval
= new wxExpr(wxExprWord
, val
);
561 wxExpr
*pequals
= new wxExpr(wxExprWord
, wxT("="));
563 wxExpr
*listExpr
= new wxExpr(wxExprList
);
565 listExpr
->Append(pequals
);
566 listExpr
->Append(patt
);
567 listExpr
->Append(pval
);
572 void wxExpr::AddAttributeValue(const wxString
& attribute
, wxList
*val
)
574 if (type
!= wxExprList
)
576 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
582 // DeleteAttributeValue(attribute);
584 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
585 wxExpr
*pval
= new wxExpr(val
);
586 wxExpr
*pequals
= new wxExpr(wxExprWord
, wxT("="));
588 wxExpr
*listExpr
= new wxExpr(wxExprList
);
590 listExpr
->Append(pequals
);
591 listExpr
->Append(patt
);
592 listExpr
->Append(pval
);
597 void wxExpr::AddAttributeValueStringList(const wxString
& attribute
, wxList
*string_list
)
599 if (type
!= wxExprList
)
601 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
607 // DeleteAttributeValue(attribute);
609 // First make a list of wxExpr strings
610 wxExpr
*listExpr
= new wxExpr(wxExprList
);
611 wxNode
*node
= string_list
->GetFirst();
614 wxChar
*string
= (wxChar
*)node
->GetData();
615 wxExpr
*expr
= new wxExpr(wxExprString
, wxString(string
));
616 listExpr
->Append(expr
);
617 node
= node
->GetNext();
620 // Now make an (=, Att, Value) triple
621 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
622 wxExpr
*pequals
= new wxExpr(wxExprWord
, wxT("="));
624 wxExpr
*listExpr2
= new wxExpr(wxExprList
);
626 listExpr2
->Append(pequals
);
627 listExpr2
->Append(patt
);
628 listExpr2
->Append(listExpr
);
633 bool wxExpr::GetAttributeValue(const wxString
& att
, int& var
) const
635 wxExpr
*expr
= AttributeValue(att
);
637 if (expr
&& (expr
->Type() == wxExprInteger
|| expr
->Type() == wxExprReal
))
639 var
= (int)(expr
->IntegerValue());
646 bool wxExpr::GetAttributeValue(const wxString
& att
, long& var
) const
648 wxExpr
*expr
= AttributeValue(att
);
650 if (expr
&& (expr
->Type() == wxExprInteger
|| expr
->Type() == wxExprReal
))
652 var
= expr
->IntegerValue();
659 bool wxExpr::GetAttributeValue(const wxString
& att
, float& var
) const
661 wxExpr
*expr
= AttributeValue(att
);
662 if (expr
&& (expr
->Type() == wxExprInteger
|| expr
->Type() == wxExprReal
))
664 var
= (float) expr
->RealValue();
671 bool wxExpr::GetAttributeValue(const wxString
& att
, double& var
) const
673 wxExpr
*expr
= AttributeValue(att
);
674 if (expr
&& (expr
->Type() == wxExprInteger
|| expr
->Type() == wxExprReal
))
676 var
= expr
->RealValue();
683 bool wxExpr::GetAttributeValue(const wxString
& att
, wxString
& var
) const // Word OR string -> string
685 wxExpr
*expr
= AttributeValue(att
);
686 if (expr
&& expr
->Type() == wxExprWord
)
688 var
= expr
->WordValue();
691 else if (expr
&& expr
->Type() == wxExprString
)
693 var
= expr
->StringValue();
700 bool wxExpr::GetAttributeValue(const wxString
& att
, wxExpr
**var
) const
702 wxExpr
*expr
= AttributeValue(att
);
712 bool wxExpr::GetAttributeValueStringList(const wxString
& att
, wxList
*var
) const
714 wxExpr
*expr
= AttributeValue(att
);
715 if (expr
&& expr
->Type() == wxExprList
)
717 wxExpr
*string_expr
= expr
->value
.first
;
720 if (string_expr
->Type() == wxExprString
)
721 var
->Append((wxObject
*)copystring(string_expr
->StringValue()));
723 string_expr
= string_expr
->next
;
732 void wxExpr::AssignAttributeValue(wxChar
*att
, wxChar
**var
) const
735 if (GetAttributeValue(att
, str
))
739 *var
= copystring((const wxChar
*) str
);
743 void wxExpr::WriteClause(FILE* stream
) // Write this expression as a top-level clause
745 if (type
!= wxExprList
)
748 wxExpr
*node
= value
.first
;
751 node
->WriteExpr(stream
);
752 fprintf( stream
, "(" );
758 fprintf( stream
, " " );
759 node
->WriteExpr(stream
);
762 fprintf( stream
, ",\n" );
765 fprintf( stream
, ").\n\n" );
769 void wxExpr::WriteExpr(FILE* stream
) // Write as any other subexpression
771 // This seems to get round an optimizer bug when
772 // using Watcom C++ 10a in WIN32 compilation mode.
773 // If these lines not present, the type seems to be
774 // interpreted wrongly as an integer.
775 // I don't want to turn optimization off since it's needed
776 // for reading in files quickly.
777 #if defined(__WATCOMC__)
786 fprintf( stream
, "%ld", value
.integer
);
791 double f
= value
.real
;
792 fprintf( stream
, "%.6g", f
);
797 fprintf( stream
, "\"" );
799 const wxWX2MBbuf val
= wxConvLibc
.cWX2MB(value
.string
);
800 size_t len
= strlen(val
);
801 for (i
= 0; i
< len
; i
++)
804 if (ch
== '"' || ch
== '\\')
805 fprintf( stream
, "\\" );
809 fprintf( stream
, tmp
);
811 fprintf( stream
, "\"" );
816 bool quote_it
= false;
817 const wxWX2MBbuf val
= wxConvLibc
.cWX2MB(value
.word
);
818 size_t len
= strlen(val
);
819 if ((len
== 0) || (len
> 0 && (val
[(size_t) 0] > 64 && val
[(size_t) 0] < 91)))
824 for (i
= 0; i
< len
; i
++)
825 if ((!isalpha(val
[i
])) && (!isdigit(val
[i
])) &&
827 { quote_it
= true; i
= len
; }
831 fprintf( stream
,"'" );
833 fprintf( stream
, val
);
836 fprintf( stream
, "'" );
843 fprintf( stream
, "[]" );
846 wxExpr
*expr
= value
.first
;
848 if ((expr
->Type() == wxExprWord
) && (wxStrcmp(expr
->WordValue(), wxT("=")) == 0))
850 wxExpr
*arg1
= expr
->next
;
851 wxExpr
*arg2
= arg1
->next
;
852 arg1
->WriteExpr(stream
);
853 fprintf( stream
, " = " );
854 arg2
->WriteExpr(stream
);
858 fprintf( stream
, "[" );
861 expr
->WriteExpr(stream
);
864 fprintf( stream
, ", " );
866 fprintf( stream
, "]" );
871 case wxExprNull
: break;
876 * wxExpr 'database' (list of expressions)
879 IMPLEMENT_DYNAMIC_CLASS(wxExprDatabase
, wxList
)
881 wxExprDatabase::wxExprDatabase(wxExprErrorHandler handler
)
885 currentwxExprErrorHandler
= handler
;
889 wxExprDatabase::wxExprDatabase(wxExprType type
, const wxString
& attribute
, int size
,
890 wxExprErrorHandler handler
)
893 attribute_to_hash
= attribute
;
894 if (type
== wxExprString
)
895 hash_table
= new wxHashTable(wxKEY_STRING
, size
);
896 else if (type
== wxExprInteger
)
897 hash_table
= new wxHashTable(wxKEY_INTEGER
, size
);
898 else hash_table
= NULL
;
900 currentwxExprErrorHandler
= handler
;
904 wxExprDatabase::~wxExprDatabase(void)
911 void wxExprDatabase::BeginFind(void) // Initialise a search
913 position
= GetFirst();
916 wxExpr
*wxExprDatabase::FindClause(long id
) // Find a term based on an integer id attribute
917 // e.g. node(id=23, type=rectangle, ....).
919 wxExpr
*found
= NULL
;
920 while (position
&& !found
)
922 wxExpr
*term
= (wxExpr
*)position
->GetData();
924 if (term
->Type() == wxExprList
)
926 wxExpr
*value
= term
->AttributeValue(wxT("id"));
927 if (value
->Type() == wxExprInteger
&& value
->IntegerValue() == id
)
930 position
= position
->GetNext();
935 // Find on basis of attribute/value pairs, e.g. type=rectangle
936 wxExpr
*wxExprDatabase::FindClause(const wxString
& word
, const wxString
& val
)
938 wxExpr
*found
= NULL
;
939 while (position
&& !found
)
941 wxExpr
*term
= (wxExpr
*)position
->GetData();
943 if (term
->Type() == wxExprList
)
945 wxExpr
*value
= term
->AttributeValue(word
);
946 if ((value
->Type() == wxExprWord
&& value
->WordValue() == val
) ||
947 (value
->Type() == wxExprString
&& value
->StringValue() == val
))
950 position
= position
->GetNext();
955 wxExpr
*wxExprDatabase::FindClause(const wxString
& word
, long val
)
957 wxExpr
*found
= NULL
;
958 while (position
&& !found
)
960 wxExpr
*term
= (wxExpr
*)position
->GetData();
962 if (term
->Type() == wxExprList
)
964 wxExpr
*value
= term
->AttributeValue(word
);
965 if ((value
->Type() == wxExprInteger
) && (value
->IntegerValue() == val
))
968 position
= position
->GetNext();
973 wxExpr
*wxExprDatabase::FindClause(const wxString
& word
, double val
)
975 wxExpr
*found
= NULL
;
976 while (position
&& !found
)
978 wxExpr
*term
= (wxExpr
*)position
->GetData();
980 if (term
->Type() == wxExprList
)
982 wxExpr
*value
= term
->AttributeValue(word
);
983 if ((value
->Type() == wxExprReal
) && (value
->RealValue() == val
))
986 position
= position
->GetNext();
991 wxExpr
*wxExprDatabase::FindClauseByFunctor(const wxString
& functor
)
993 wxExpr
*found
= NULL
;
994 while (position
&& !found
)
996 wxExpr
*term
= (wxExpr
*)position
->GetData();
998 if (term
->Type() == wxExprList
)
1000 if (term
->Functor() == functor
)
1003 position
= position
->GetNext();
1008 // If hashing is on, must store in hash table too
1009 void wxExprDatabase::Append(wxExpr
*clause
)
1011 wxList::Append((wxObject
*)clause
);
1014 wxString
functor(clause
->Functor());
1015 wxExpr
*expr
= clause
->AttributeValue(attribute_to_hash
);
1018 long functor_key
= hash_table
->MakeKey(WXSTRINGCAST functor
);
1020 if (expr
&& expr
->Type() == wxExprString
)
1022 value_key
= hash_table
->MakeKey(WXSTRINGCAST expr
->StringValue());
1023 hash_table
->Put(functor_key
+ value_key
, WXSTRINGCAST expr
->StringValue(), (wxObject
*)clause
);
1025 else if (expr
&& expr
->Type() == wxExprInteger
)
1027 value_key
= expr
->IntegerValue();
1028 hash_table
->Put(functor_key
+ value_key
, expr
->IntegerValue(), (wxObject
*)clause
);
1035 wxExpr
*wxExprDatabase::HashFind(const wxString
& functor
, long value
) const
1037 long key
= hash_table
->MakeKey(WXSTRINGCAST functor
) + value
;
1039 // The key alone isn't guaranteed to be unique:
1040 // must supply value too. Let's assume the value of the
1041 // id is going to be reasonably unique.
1042 return (wxExpr
*)hash_table
->Get(key
, value
);
1045 wxExpr
*wxExprDatabase::HashFind(const wxString
& functor
, const wxString
& value
) const
1047 long key
= hash_table
->MakeKey(WXSTRINGCAST functor
) + hash_table
->MakeKey(WXSTRINGCAST value
);
1048 return (wxExpr
*)hash_table
->Get(key
, WXSTRINGCAST value
);
1051 void wxExprDatabase::ClearDatabase(void)
1054 wxNode
*node
= GetFirst();
1057 wxExpr
*expr
= (wxExpr
*)node
->GetData();
1064 hash_table
->Clear();
1067 bool wxExprDatabase::Read(const wxString
& filename
)
1071 FILE *f
= wxFopen(filename
, _T("r"));
1074 thewxExprDatabase
= this;
1081 return (noErrors
== 0);
1089 bool wxExprDatabase::ReadFromString(const wxString
& buffer
)
1092 thewxExprDatabase
= this;
1094 const wxWX2MBbuf buf
= buffer
.mb_str();
1095 LexFromString(wxMBSTRINGCAST buf
);
1098 return (noErrors
== 0);
1101 bool wxExprDatabase::Write(const wxString
& fileName
)
1103 FILE *stream
= wxFopen( fileName
, _T("w+"));
1108 bool success
= Write(stream
);
1113 bool wxExprDatabase::Write(FILE *stream
)
1116 wxNode
*node
= GetFirst();
1119 wxExpr
*expr
= (wxExpr
*)node
->GetData();
1120 expr
->WriteClause(stream
);
1121 node
= node
->GetNext();
1123 return (noErrors
== 0);
1126 void add_expr(wxExpr
* expr
)
1128 thewxExprDatabase
->Append(expr
);
1132 bool wxExprIsFunctor(wxExpr
*expr
, const wxString
& functor
)
1134 if (expr
&& (expr
->Type() == wxExprList
))
1136 wxExpr
*first_expr
= expr
->value
.first
;
1138 if (first_expr
&& (first_expr
->Type() == wxExprWord
) &&
1139 (first_expr
->WordValue() == functor
))
1149 * Called from parser
1153 char *wxmake_integer(char *str
)
1155 wxExpr
*x
= new wxExpr(atol(str
));
1160 char *wxmake_real(char *str1
, char *str2
)
1164 sprintf(buf
, "%s.%s", str1
, str2
);
1165 double f
= (double)atof(buf
);
1166 wxExpr
*x
= new wxExpr(f
);
1171 // extern "C" double exp10(double);
1173 char *wxmake_exp(char *str1
, char *str2
)
1175 double mantissa
= (double)atoi(str1
);
1176 double exponent
= (double)atoi(str2
);
1178 double d
= mantissa
* pow(10.0, exponent
);
1180 wxExpr
*x
= new wxExpr(d
);
1185 char *wxmake_exp2(char *str1
, char *str2
, char *str3
)
1189 sprintf(buf
, "%s.%s", str1
, str2
);
1190 double mantissa
= (double)atof(buf
);
1191 double exponent
= (double)atoi(str3
);
1193 double d
= mantissa
* pow(10.0, exponent
);
1195 wxExpr
*x
= new wxExpr(d
);
1200 char *wxmake_word(char *str
)
1202 wxExpr
*x
= new wxExpr(wxExprWord
, wxString(str
, wxConvLibc
).c_str());
1206 char *wxmake_string(char *str
)
1210 const wxMB2WXbuf sbuf
= wxConvLibc
.cMB2WX(str
);
1212 // str++; /* skip leading quote */
1213 len
= wxStrlen(sbuf
) - 1; /* ignore trailing quote */
1215 s
= new wxChar
[len
+ 1];
1218 for(i
=1; i
<len
; i
++) // 1 since we want to skip leading quote
1220 if (sbuf
[i
] == wxT('\\') && sbuf
[i
+1] == wxT('"'))
1225 else if (sbuf
[i
] == wxT('\\') && sbuf
[i
+1] == wxT('\\'))
1236 wxExpr
*x
= new wxExpr(wxExprString
, s
, false);
1240 char *proio_cons(char * ccar
, char * ccdr
)
1242 wxExpr
*car
= (wxExpr
*)ccar
;
1243 wxExpr
*cdr
= (wxExpr
*)ccdr
;
1247 cdr
= new wxExpr(wxExprList
);
1254 void process_command(char * cexpr
)
1256 wxExpr
*expr
= (wxExpr
*)cexpr
;
1260 void syntax_error(char *WXUNUSED(s
))
1262 if (currentwxExprErrorHandler
)
1263 (void)(*(currentwxExprErrorHandler
))(WXEXPR_ERROR_SYNTAX
, (char *)"syntax error");
1264 if (thewxExprDatabase
) thewxExprDatabase
->noErrors
+= 1;
1269 // char *__cdecl strdup(const char *s)
1270 WXDLLEXPORT
char *strdup(const char *s
)
1272 int len
= strlen(s
);
1273 char *new_s
= (char *)malloc(sizeof(char)*(len
+1));