00001 // -*- C++ -*- 00002 // $Id: ETCL_Interpreter.cpp 85528 2009-06-05 18:16:40Z johnnyw $ 00003 00004 #include "ace/Guard_T.h" 00005 #include "ace/Truncate.h" 00006 00007 #include "ace/ETCL/ETCL_Interpreter.h" 00008 #include "ace/ETCL/ETCL_Constraint.h" 00009 00010 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00011 00012 ETCL_Parser_Export ACE_SYNCH_MUTEX ETCL_Interpreter::parserMutex__; 00013 00014 ETCL_Interpreter::ETCL_Interpreter (void) 00015 : root_ (0) 00016 { 00017 } 00018 00019 ETCL_Interpreter::~ETCL_Interpreter (void) 00020 { 00021 delete this->root_; 00022 } 00023 00024 int 00025 ETCL_Interpreter::build_tree (const char* constraints) 00026 { 00027 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, 00028 guard, 00029 ETCL_Interpreter::parserMutex__, 00030 -1); 00031 00032 Lex_String_Input::reset ((char*)constraints); 00033 00034 yyval.constraint = 0; 00035 int return_value = ::yyparse (); 00036 00037 if (return_value == 0 && yyval.constraint != 0) 00038 { 00039 this->root_ = yyval.constraint; 00040 } 00041 else 00042 { 00043 this->root_ = 0; 00044 } 00045 00046 return return_value; 00047 } 00048 00049 int 00050 ETCL_Interpreter::is_empty_string (const char* str) 00051 { 00052 int return_value = 0; 00053 00054 if (str != 0) 00055 { 00056 int i = 0; 00057 00058 while (str[i] != '\0') 00059 { 00060 if (str[i] != ' ') 00061 { 00062 break; 00063 } 00064 00065 ++i; 00066 } 00067 00068 if (str[i] == '\0') 00069 { 00070 return_value = 1; 00071 } 00072 } 00073 00074 return return_value; 00075 } 00076 00077 char* Lex_String_Input::string_ = 0; 00078 char* Lex_String_Input::current_ = 0; 00079 char* Lex_String_Input::end_ = 0; 00080 00081 // Routine to have Lex read its input from the constraint string. 00082 00083 int 00084 Lex_String_Input::copy_into (char* buf, 00085 int max_size) 00086 { 00087 int const chars_left = 00088 ACE_Utils::truncate_cast<int> ( 00089 Lex_String_Input::end_ - Lex_String_Input::current_); 00090 00091 int const n = max_size > chars_left ? chars_left : max_size; 00092 00093 if (n > 0) 00094 { 00095 ACE_OS::memcpy (buf, 00096 Lex_String_Input::current_, 00097 n); 00098 Lex_String_Input::current_ += n; 00099 } 00100 00101 return n; 00102 } 00103 00104 void 00105 Lex_String_Input::reset (char* input_string) 00106 { 00107 Lex_String_Input::string_ = input_string; 00108 Lex_String_Input::current_ = input_string; 00109 Lex_String_Input::end_ = 00110 input_string + ACE_OS::strlen (Lex_String_Input::string_); 00111 } 00112 00113 ACE_END_VERSIONED_NAMESPACE_DECL