1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "wxexpr.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
36 #include "wx/wxexpr.h"
38 extern "C" void add_expr(char *);
39 extern "C" void LexFromFile(FILE *fd
);
40 extern "C" void LexFromString(char *buf
);
43 wxExprDatabase
*thewxExprDatabase
= NULL
;
44 wxExprErrorHandler currentwxExprErrorHandler
;
46 wxExpr::wxExpr(const wxString
& functor
)
53 wxExpr
*pfunctor
= new wxExpr(wxExprWord
, functor
);
58 wxExpr::wxExpr(wxExprType the_type
, const wxString
& word_or_string
)
65 value
.word
= copystring((const wxChar
*)word_or_string
);
68 value
.string
= copystring((const wxChar
*)word_or_string
);
83 wxExpr::wxExpr(wxExprType the_type
, wxChar
*word_or_string
, bool allocate
)
90 value
.word
= allocate
? copystring(word_or_string
) : word_or_string
;
93 value
.string
= allocate
? copystring(word_or_string
) : word_or_string
;
108 wxExpr::wxExpr(long the_integer
)
110 type
= wxExprInteger
;
111 value
.integer
= the_integer
;
116 wxExpr::wxExpr(double the_real
)
119 value
.real
= the_real
;
124 wxExpr::wxExpr(wxList
*the_list
)
131 wxExpr
*listExpr
= new wxExpr(wxExprList
);
133 wxNode
*node
= the_list
->First();
136 wxExpr
*expr
= (wxExpr
*)node
->Data();
137 listExpr
->Append(expr
);
145 wxExpr::~wxExpr(void)
156 delete[] value
.string
;
166 wxExpr
*expr
= value
.first
;
169 wxExpr
*expr1
= expr
->next
;
176 case wxExprNull
: break;
180 void wxExpr::Append(wxExpr
*expr
)
190 void wxExpr::Insert(wxExpr
*expr
)
192 expr
->next
= value
.first
;
199 wxExpr
*wxExpr::Copy(void) const
201 // This seems to get round an optimizer bug when
202 // using Watcom C++ 10a in WIN32 compilation mode.
203 // If these lines not present, the type seems to be
204 // interpreted wrongly as an integer.
205 // I don't want to turn optimization off since it's needed
206 // for reading in files quickly.
207 #if defined(__WATCOMC__)
215 return new wxExpr(value
.integer
);
217 return new wxExpr(value
.real
);
219 return new wxExpr(wxExprString
, wxString(value
.string
));
221 return new wxExpr(wxExprWord
, wxString(value
.word
));
224 wxExpr
*expr
= value
.first
;
225 wxExpr
*new_list
= new wxExpr(wxExprList
);
228 wxExpr
*expr2
= expr
->Copy();
229 new_list
->Append(expr2
);
241 // Get the wxExpr (containing (= wxExpr Value) form) for the given word
242 // or string, assuming that we have Attribute=Value, ...
243 wxExpr
*wxExpr::GetAttributeValueNode(const wxString
& word
) const // Use only for a clause or list
245 if (type
!= wxExprList
)
248 wxExpr
*expr
= value
.first
;
251 if (expr
->type
== wxExprList
)
253 wxExpr
*firstNode
= expr
->value
.first
;
254 if ((firstNode
->type
== wxExprWord
) && (firstNode
->value
.word
[0] == '='))
256 wxExpr
*secondNode
= firstNode
->next
;
257 if ((secondNode
->type
== wxExprWord
) &&
258 (wxStrcmp((const wxChar
*)word
, secondNode
->value
.word
) == 0))
269 // Get the value (in wxExpr form) for the given word or string, assuming
270 // that we have Attribute=Value, ...
271 wxExpr
*wxExpr::AttributeValue(const wxString
& word
) const // Use only for a clause or list
273 if (type
!= wxExprList
)
276 wxExpr
*attExpr
= GetAttributeValueNode(word
);
277 if (attExpr
&& attExpr
->value
.first
&& attExpr
->value
.first
->next
)
278 return attExpr
->value
.first
->next
->next
;
282 wxString
wxExpr::Functor(void) const // Use only for a clause
284 if ((type
!= wxExprList
) || !value
.first
)
285 return wxString(_T(""));
287 if (value
.first
->type
== wxExprWord
)
288 return wxString(value
.first
->value
.word
);
290 return wxString(_T(""));
293 bool wxExpr::IsFunctor(const wxString
& f
) const // Use only for a clause
295 if ((type
!= wxExprList
) || !value
.first
)
298 return (value
.first
->type
== wxExprWord
&&
299 (wxStrcmp((const wxChar
*)f
, value
.first
->value
.word
) == 0));
302 // Return nth argument of a clause (starting from 1)
303 wxExpr
*wxExpr::Arg(wxExprType theType
, int arg
) const
305 wxExpr
*expr
= value
.first
;
307 for (i
= 1; i
< arg
; i
++)
311 if (expr
&& (expr
->type
== theType
))
317 // Return nth argument of a list expression (starting from zero)
318 wxExpr
*wxExpr::Nth(int arg
) const
320 if (type
!= wxExprList
)
323 wxExpr
*expr
= value
.first
;
325 for (i
= 0; i
< arg
; i
++)
336 // Returns the number of elements in a list expression
337 int wxExpr::Number(void) const
339 if (type
!= wxExprList
)
343 wxExpr
*expr
= value
.first
;
352 void wxExpr::DeleteAttributeValue(const wxString
& attribute
)
354 if (type
!= wxExprList
)
357 wxExpr
*expr
= value
.first
;
358 wxExpr
*lastExpr
= this;
361 if (expr
->type
== wxExprList
)
363 wxExpr
*firstNode
= expr
->value
.first
;
364 if ((firstNode
->type
== wxExprWord
) && (firstNode
->value
.word
[0] == '='))
366 wxExpr
*secondNode
= firstNode
->next
;
367 if ((secondNode
->type
== wxExprWord
) &&
368 (wxStrcmp((const wxChar
*)attribute
, secondNode
->value
.word
) == 0))
370 wxExpr
*nextExpr
= expr
->next
;
373 lastExpr
->next
= nextExpr
;
388 void wxExpr::AddAttributeValue(const wxString
& attribute
, wxExpr
*val
)
390 if (type
!= wxExprList
)
392 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
395 // Warning - existing code may assume that any existing value
396 // is deleted first. For efficiency, we leave this to the application.
397 // DeleteAttributeValue(attribute);
399 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
400 wxExpr
*pequals
= new wxExpr(wxExprWord
, _T("="));
402 wxExpr
*listExpr
= new wxExpr(wxExprList
);
404 listExpr
->Append(pequals
);
405 listExpr
->Append(patt
);
406 listExpr
->Append(val
);
411 void wxExpr::AddAttributeValue(const wxString
& attribute
, long val
)
413 if (type
!= wxExprList
)
415 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
418 // Warning - existing code may assume that any existing value
419 // is deleted first. For efficiency, we leave this to the application.
420 // DeleteAttributeValue(attribute);
422 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
423 wxExpr
*pval
= new wxExpr(val
);
424 wxExpr
*pequals
= new wxExpr(wxExprWord
, _T("="));
426 wxExpr
*listExpr
= new wxExpr(wxExprList
);
428 listExpr
->Append(pequals
);
429 listExpr
->Append(patt
);
430 listExpr
->Append(pval
);
435 void wxExpr::AddAttributeValue(const wxString
& attribute
, double val
)
437 if (type
!= wxExprList
)
439 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
443 // DeleteAttributeValue(attribute);
444 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
445 wxExpr
*pval
= new wxExpr(val
);
446 wxExpr
*pequals
= new wxExpr(wxExprWord
, _T("="));
448 wxExpr
*listExpr
= new wxExpr(wxExprList
);
450 listExpr
->Append(pequals
);
451 listExpr
->Append(patt
);
452 listExpr
->Append(pval
);
457 void wxExpr::AddAttributeValueString(const wxString
& attribute
, const wxString
& val
)
459 if (type
!= wxExprList
)
461 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
465 // DeleteAttributeValue(attribute);
467 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
468 wxExpr
*pval
= new wxExpr(wxExprString
, val
);
469 wxExpr
*pequals
= new wxExpr(wxExprWord
, _T("="));
471 wxExpr
*listExpr
= new wxExpr(wxExprList
);
473 listExpr
->Append(pequals
);
474 listExpr
->Append(patt
);
475 listExpr
->Append(pval
);
480 void wxExpr::AddAttributeValueWord(const wxString
& attribute
, const wxString
& val
)
482 if (type
!= wxExprList
)
484 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
488 // DeleteAttributeValue(attribute);
490 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
491 wxExpr
*pval
= new wxExpr(wxExprWord
, val
);
492 wxExpr
*pequals
= new wxExpr(wxExprWord
, _T("="));
494 wxExpr
*listExpr
= new wxExpr(wxExprList
);
496 listExpr
->Append(pequals
);
497 listExpr
->Append(patt
);
498 listExpr
->Append(pval
);
503 void wxExpr::AddAttributeValue(const wxString
& attribute
, wxList
*val
)
505 if (type
!= wxExprList
)
507 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
513 // DeleteAttributeValue(attribute);
515 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
516 wxExpr
*pval
= new wxExpr(val
);
517 wxExpr
*pequals
= new wxExpr(wxExprWord
, _T("="));
519 wxExpr
*listExpr
= new wxExpr(wxExprList
);
521 listExpr
->Append(pequals
);
522 listExpr
->Append(patt
);
523 listExpr
->Append(pval
);
528 void wxExpr::AddAttributeValueStringList(const wxString
& attribute
, wxList
*string_list
)
530 if (type
!= wxExprList
)
532 // cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n";
538 // DeleteAttributeValue(attribute);
540 // First make a list of wxExpr strings
541 wxExpr
*listExpr
= new wxExpr(wxExprList
);
542 wxNode
*node
= string_list
->First();
545 char *string
= (char *)node
->Data();
546 wxExpr
*expr
= new wxExpr(wxExprString
, wxString(string
));
547 listExpr
->Append(expr
);
551 // Now make an (=, Att, Value) triple
552 wxExpr
*patt
= new wxExpr(wxExprWord
, attribute
);
553 wxExpr
*pequals
= new wxExpr(wxExprWord
, _T("="));
555 wxExpr
*listExpr2
= new wxExpr(wxExprList
);
557 listExpr2
->Append(pequals
);
558 listExpr2
->Append(patt
);
559 listExpr2
->Append(listExpr
);
564 bool wxExpr::GetAttributeValue(const wxString
& att
, int& var
) const
566 wxExpr
*expr
= AttributeValue(att
);
568 if (expr
&& (expr
->Type() == wxExprInteger
|| expr
->Type() == wxExprReal
))
570 var
= (int)(expr
->IntegerValue());
577 bool wxExpr::GetAttributeValue(const wxString
& att
, long& var
) const
579 wxExpr
*expr
= AttributeValue(att
);
581 if (expr
&& (expr
->Type() == wxExprInteger
|| expr
->Type() == wxExprReal
))
583 var
= expr
->IntegerValue();
590 bool wxExpr::GetAttributeValue(const wxString
& att
, float& var
) const
592 wxExpr
*expr
= AttributeValue(att
);
593 if (expr
&& (expr
->Type() == wxExprInteger
|| expr
->Type() == wxExprReal
))
595 var
= (float) expr
->RealValue();
602 bool wxExpr::GetAttributeValue(const wxString
& att
, double& var
) const
604 wxExpr
*expr
= AttributeValue(att
);
605 if (expr
&& (expr
->Type() == wxExprInteger
|| expr
->Type() == wxExprReal
))
607 var
= expr
->RealValue();
614 bool wxExpr::GetAttributeValue(const wxString
& att
, wxString
& var
) const // Word OR string -> string
616 wxExpr
*expr
= AttributeValue(att
);
617 if (expr
&& expr
->Type() == wxExprWord
)
619 var
= expr
->WordValue();
622 else if (expr
&& expr
->Type() == wxExprString
)
624 var
= expr
->StringValue();
631 bool wxExpr::GetAttributeValue(const wxString
& att
, wxExpr
**var
) const
633 wxExpr
*expr
= AttributeValue(att
);
643 bool wxExpr::GetAttributeValueStringList(const wxString
& att
, wxList
*var
) const
645 wxExpr
*expr
= AttributeValue(att
);
646 if (expr
&& expr
->Type() == wxExprList
)
648 wxExpr
*string_expr
= expr
->value
.first
;
651 if (string_expr
->Type() == wxExprString
)
652 var
->Append((wxObject
*)copystring(string_expr
->StringValue()));
654 string_expr
= string_expr
->next
;
663 void wxExpr::AssignAttributeValue(wxChar
*att
, wxChar
**var
) const
666 if (GetAttributeValue(att
, str
))
670 *var
= copystring((const wxChar
*) str
);
674 void wxExpr::WriteClause(ostream
& stream
) // Write this expression as a top-level clause
676 if (type
!= wxExprList
)
679 wxExpr
*node
= value
.first
;
682 node
->WriteExpr(stream
);
690 node
->WriteExpr(stream
);
692 if (node
) stream
<< ",\n";
699 void wxExpr::WriteExpr(ostream
& stream
) // Write as any other subexpression
701 // This seems to get round an optimizer bug when
702 // using Watcom C++ 10a in WIN32 compilation mode.
703 // If these lines not present, the type seems to be
704 // interpreted wrongly as an integer.
705 // I don't want to turn optimization off since it's needed
706 // for reading in files quickly.
707 #if defined(__WATCOMC__)
716 stream
<< value
.integer
;
721 double f
= value
.real
;
722 /* Now the parser can cope with this.
723 // Prevent printing in 'e' notation. Any better way?
724 if (fabs(f) < 0.00001)
728 sprintf(buf
, "%.6g", f
);
736 const wxWX2MBbuf val
= wxConv_libc
.cWX2MB(value
.string
);
737 int len
= strlen(val
);
738 for (i
= 0; i
< len
; i
++)
741 if (ch
== '"' || ch
== '\\')
751 bool quote_it
= FALSE
;
752 const wxWX2MBbuf val
= wxConv_libc
.cWX2MB(value
.word
);
753 int len
= strlen(val
);
754 if ((len
== 0) || (len
> 0 && (val
[0] > 64 && val
[0] < 91)))
759 for (i
= 0; i
< len
; i
++)
760 if ((!isalpha(val
[i
])) && (!isdigit(val
[i
])) &&
762 { quote_it
= TRUE
; i
= len
; }
781 wxExpr
*expr
= value
.first
;
783 if ((expr
->Type() == wxExprWord
) && (wxStrcmp(expr
->WordValue(), _T("=")) == 0))
785 wxExpr
*arg1
= expr
->next
;
786 wxExpr
*arg2
= arg1
->next
;
787 arg1
->WriteExpr(stream
);
789 arg2
->WriteExpr(stream
);
796 expr
->WriteExpr(stream
);
798 if (expr
) stream
<< ", ";
805 case wxExprNull
: break;
809 void wxExpr::WriteLispExpr(ostream
& stream
)
815 stream
<< value
.integer
;
820 stream
<< value
.real
;
825 stream
<< "\"" << value
.string
<< "\"";
830 stream
<< value
.word
;
835 wxExpr
*expr
= value
.first
;
840 expr
->WriteLispExpr(stream
);
842 if (expr
) stream
<< " ";
848 case wxExprNull
: break;
853 * wxExpr 'database' (list of expressions)
856 #if !USE_SHARED_LIBRARIES
857 IMPLEMENT_DYNAMIC_CLASS(wxExprDatabase
, wxList
)
860 wxExprDatabase::wxExprDatabase(wxExprErrorHandler handler
)
864 currentwxExprErrorHandler
= handler
;
868 wxExprDatabase::wxExprDatabase(wxExprType type
, const wxString
& attribute
, int size
,
869 wxExprErrorHandler handler
)
872 attribute_to_hash
= attribute
;
873 if (type
== wxExprString
)
874 hash_table
= new wxHashTable(wxKEY_STRING
, size
);
875 else if (type
== wxExprInteger
)
876 hash_table
= new wxHashTable(wxKEY_INTEGER
, size
);
877 else hash_table
= NULL
;
879 currentwxExprErrorHandler
= handler
;
883 wxExprDatabase::~wxExprDatabase(void)
890 void wxExprDatabase::BeginFind(void) // Initialise a search
895 wxExpr
*wxExprDatabase::FindClause(long id
) // Find a term based on an integer id attribute
896 // e.g. node(id=23, type=rectangle, ....).
898 wxExpr
*found
= NULL
;
899 while (position
&& !found
)
901 wxExpr
*term
= (wxExpr
*)position
->Data();
903 if (term
->Type() == wxExprList
)
905 wxExpr
*value
= term
->AttributeValue("id");
906 if (value
->Type() == wxExprInteger
&& value
->IntegerValue() == id
)
909 position
= position
->Next();
914 // Find on basis of attribute/value pairs, e.g. type=rectangle
915 wxExpr
*wxExprDatabase::FindClause(const wxString
& word
, const wxString
& val
)
917 wxExpr
*found
= NULL
;
918 while (position
&& !found
)
920 wxExpr
*term
= (wxExpr
*)position
->Data();
922 if (term
->Type() == wxExprList
)
924 wxExpr
*value
= term
->AttributeValue(word
);
925 if ((value
->Type() == wxExprWord
&& value
->WordValue() == val
) ||
926 (value
->Type() == wxExprString
&& value
->StringValue() == val
))
929 position
= position
->Next();
934 wxExpr
*wxExprDatabase::FindClause(const wxString
& word
, long val
)
936 wxExpr
*found
= NULL
;
937 while (position
&& !found
)
939 wxExpr
*term
= (wxExpr
*)position
->Data();
941 if (term
->Type() == wxExprList
)
943 wxExpr
*value
= term
->AttributeValue(word
);
944 if ((value
->Type() == wxExprInteger
) && (value
->IntegerValue() == val
))
947 position
= position
->Next();
952 wxExpr
*wxExprDatabase::FindClause(const wxString
& word
, double val
)
954 wxExpr
*found
= NULL
;
955 while (position
&& !found
)
957 wxExpr
*term
= (wxExpr
*)position
->Data();
959 if (term
->Type() == wxExprList
)
961 wxExpr
*value
= term
->AttributeValue(word
);
962 if ((value
->Type() == wxExprReal
) && (value
->RealValue() == val
))
965 position
= position
->Next();
970 wxExpr
*wxExprDatabase::FindClauseByFunctor(const wxString
& functor
)
972 wxExpr
*found
= NULL
;
973 while (position
&& !found
)
975 wxExpr
*term
= (wxExpr
*)position
->Data();
977 if (term
->Type() == wxExprList
)
979 if (term
->Functor() == functor
)
982 position
= position
->Next();
987 // If hashing is on, must store in hash table too
988 void wxExprDatabase::Append(wxExpr
*clause
)
990 wxList::Append((wxObject
*)clause
);
993 wxString
functor(clause
->Functor());
994 wxExpr
*expr
= clause
->AttributeValue(attribute_to_hash
);
997 long functor_key
= hash_table
->MakeKey(WXSTRINGCAST functor
);
999 if (expr
&& expr
->Type() == wxExprString
)
1001 value_key
= hash_table
->MakeKey(WXSTRINGCAST expr
->StringValue());
1002 hash_table
->Put(functor_key
+ value_key
, WXSTRINGCAST expr
->StringValue(), (wxObject
*)clause
);
1004 else if (expr
&& expr
->Type() == wxExprInteger
)
1006 value_key
= expr
->IntegerValue();
1007 hash_table
->Put(functor_key
+ value_key
, expr
->IntegerValue(), (wxObject
*)clause
);
1014 wxExpr
*wxExprDatabase::HashFind(const wxString
& functor
, long value
) const
1016 long key
= hash_table
->MakeKey(WXSTRINGCAST functor
) + value
;
1018 // The key alone isn't guaranteed to be unique:
1019 // must supply value too. Let's assume the value of the
1020 // id is going to be reasonably unique.
1021 return (wxExpr
*)hash_table
->Get(key
, value
);
1024 wxExpr
*wxExprDatabase::HashFind(const wxString
& functor
, const wxString
& value
) const
1026 long key
= hash_table
->MakeKey(WXSTRINGCAST functor
) + hash_table
->MakeKey(WXSTRINGCAST value
);
1027 return (wxExpr
*)hash_table
->Get(key
, WXSTRINGCAST value
);
1030 void wxExprDatabase::ClearDatabase(void)
1033 wxNode
*node
= First();
1036 wxExpr
*expr
= (wxExpr
*)node
->Data();
1043 hash_table
->Clear();
1046 bool wxExprDatabase::Read(const wxString
& filename
)
1050 FILE *f
= fopen(filename
.fn_str(), "r");
1053 thewxExprDatabase
= this;
1060 return (noErrors
== 0);
1068 bool wxExprDatabase::ReadFromString(const wxString
& buffer
)
1071 thewxExprDatabase
= this;
1073 const wxWX2MBbuf buf
= buffer
.mb_str();
1074 LexFromString(MBSTRINGCAST buf
);
1077 return (noErrors
== 0);
1080 bool wxExprDatabase::Write(const wxString
& fileName
)
1082 ofstream
str(MBSTRINGCAST fileName
.mb_str());
1088 bool wxExprDatabase::Write(ostream
& stream
)
1091 wxNode
*node
= First();
1094 wxExpr
*expr
= (wxExpr
*)node
->Data();
1095 expr
->WriteClause(stream
);
1096 node
= node
->Next();
1098 return (noErrors
== 0);
1101 void wxExprDatabase::WriteLisp(ostream
& stream
)
1104 wxNode
*node
= First();
1107 wxExpr
*expr
= (wxExpr
*)node
->Data();
1108 expr
->WriteLispExpr(stream
);
1110 node
= node
->Next();
1114 void add_expr(wxExpr
* expr
)
1116 thewxExprDatabase
->Append(expr
);
1120 bool wxExprIsFunctor(wxExpr
*expr
, const wxString
& functor
)
1122 if (expr
&& (expr
->Type() == wxExprList
))
1124 wxExpr
*first_expr
= expr
->value
.first
;
1126 if (first_expr
&& (first_expr
->Type() == wxExprWord
) &&
1127 (first_expr
->WordValue() == functor
))
1137 * Called from parser
1141 char *wxmake_integer(char *str
)
1143 wxExpr
*x
= new wxExpr(atol(str
));
1148 char *wxmake_real(char *str1
, char *str2
)
1152 sprintf(buf
, "%s.%s", str1
, str2
);
1153 double f
= (double)atof(buf
);
1154 wxExpr
*x
= new wxExpr(f
);
1159 // extern "C" double exp10(double);
1161 char *wxmake_exp(char *str1
, char *str2
)
1163 double mantissa
= (double)atoi(str1
);
1164 double exponent
= (double)atoi(str2
);
1166 double d
= mantissa
* pow(10.0, exponent
);
1168 wxExpr
*x
= new wxExpr(d
);
1173 char *wxmake_exp2(char *str1
, char *str2
, char *str3
)
1177 sprintf(buf
, "%s.%s", str1
, str2
);
1178 double mantissa
= (double)atof(buf
);
1179 double exponent
= (double)atoi(str3
);
1181 double d
= mantissa
* pow(10.0, exponent
);
1183 wxExpr
*x
= new wxExpr(d
);
1188 char *wxmake_word(char *str
)
1190 wxExpr
*x
= new wxExpr(wxExprWord
, str
);
1194 char *wxmake_string(char *str
)
1198 const wxMB2WXbuf sbuf
= wxConv_libc
.cMB2WX(str
);
1200 str
++; /* skip leading quote */
1201 len
= wxStrlen(sbuf
) - 1; /* ignore trailing quote */
1203 s
= new wxChar
[len
+ 1];
1206 for(i
=0; i
<len
; i
++)
1208 if (sbuf
[i
] == _T('\\') && sbuf
[i
+1] == _T('"'))
1213 else if (sbuf
[i
] == _T('\\') && sbuf
[i
+1] == _T('\\'))
1224 wxExpr
*x
= new wxExpr(wxExprString
, s
, FALSE
);
1228 char *proio_cons(char * ccar
, char * ccdr
)
1230 wxExpr
*car
= (wxExpr
*)ccar
;
1231 wxExpr
*cdr
= (wxExpr
*)ccdr
;
1235 cdr
= new wxExpr(wxExprList
);
1242 void process_command(char * cexpr
)
1244 wxExpr
*expr
= (wxExpr
*)cexpr
;
1248 void syntax_error(char *WXUNUSED(s
))
1250 if (currentwxExprErrorHandler
)
1251 (void)(*(currentwxExprErrorHandler
))(WXEXPR_ERROR_SYNTAX
, "syntax error");
1252 if (thewxExprDatabase
) thewxExprDatabase
->noErrors
+= 1;
1257 // char *__cdecl strdup(const char *s)
1258 WXDLLEXPORT
char *strdup(const char *s
)
1260 int len
= strlen(s
);
1261 char *new_s
= (char *)malloc(sizeof(char)*(len
+1));