00001 // Interpreter.cpp,v 1.7 2006/03/14 06:14:35 jtc Exp 00002 00003 #include "orbsvcs/Trader/Interpreter.h" 00004 #include "ace/OS_NS_string.h" 00005 00006 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00007 00008 TAO_SYNCH_MUTEX TAO_Interpreter::parserMutex__; 00009 00010 TAO_Interpreter::TAO_Interpreter (void) 00011 : root_ (0) 00012 { 00013 } 00014 00015 TAO_Interpreter::~TAO_Interpreter (void) 00016 { 00017 delete root_; 00018 } 00019 00020 int 00021 TAO_Interpreter::build_tree (const char* constraints) 00022 { 00023 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, 00024 guard, 00025 TAO_Interpreter::parserMutex__, 00026 -1); 00027 00028 TAO_Lex_String_Input::reset ((char*)constraints); 00029 int return_value = 0; 00030 00031 yyval.constraint_ = 0; 00032 return_value = ::yyparse (); 00033 00034 if (return_value == 0 && yyval.constraint_ != 0) 00035 this->root_ = yyval.constraint_; 00036 else 00037 { 00038 while (yylex () > 0) 00039 continue; 00040 this->root_ = 0; 00041 } 00042 00043 return return_value; 00044 } 00045 00046 int 00047 TAO_Interpreter::is_empty_string (const char* str) 00048 { 00049 int return_value = 0; 00050 00051 if (str != 0) 00052 { 00053 int i = 0; 00054 while (str[i] != '\0') 00055 { 00056 if (str[i] != ' ') 00057 break; 00058 00059 i++; 00060 } 00061 00062 if (str[i] == '\0') 00063 return_value = 1; 00064 } 00065 00066 return return_value; 00067 } 00068 00069 char* TAO_Lex_String_Input::string_ = 0; 00070 char* TAO_Lex_String_Input::current_ = 0; 00071 char* TAO_Lex_String_Input::end_ = 0; 00072 00073 // Routine to have Lex read its input from the constraint string. 00074 00075 int 00076 TAO_Lex_String_Input::copy_into (char* buf, int max_size) 00077 { 00078 int chars_left = TAO_Lex_String_Input::end_ - TAO_Lex_String_Input::current_; 00079 int n = max_size > chars_left ? chars_left : max_size; 00080 00081 if (n > 0) 00082 { 00083 ACE_OS:: memcpy (buf, 00084 TAO_Lex_String_Input::current_, 00085 n); 00086 TAO_Lex_String_Input::current_ += n; 00087 } 00088 00089 return n; 00090 } 00091 00092 void 00093 TAO_Lex_String_Input::reset (char* input_string) 00094 { 00095 TAO_Lex_String_Input::string_ = input_string; 00096 TAO_Lex_String_Input::current_ = input_string; 00097 TAO_Lex_String_Input::end_ = input_string + 00098 ACE_OS::strlen (TAO_Lex_String_Input::string_); 00099 } 00100 00101 TAO_END_VERSIONED_NAMESPACE_DECL