#include <Svc_Conf_Lexer.h>
Static Public Member Functions | |
int | yylex (ACE_YYSTYPE *ace_yylval, ACE_Svc_Conf_Param *param) |
Static Private Member Functions | |
size_t | input (ACE_Svc_Conf_Param *param, char *buf, size_t max_size) |
int | scan (ACE_YYSTYPE *ace_yylval, ACE_Svc_Conf_Param *param) |
Definition at line 33 of file Svc_Conf_Lexer.h.
|
Definition at line 210 of file Svc_Conf_Lexer.cpp. References ACE_TCHAR, ace_yyerror(), ACE_Svc_Conf_Param::buffer, ACE_OS::clearerr(), ACE_OS::exit(), ACE_OS::fprintf(), ACE_OS::fread(), ACE_OS::memcpy(), ACE_Svc_Conf_Param::source, ace_yy_buffer_state::start_, ACE_OS::strlen(), ACE_Svc_Conf_Param::type, ACE_Svc_Conf_Param::yyerrno, and ACE_Svc_Conf_Param::yylineno. Referenced by yylex().
00212 { 00213 size_t result = 0; 00214 00215 switch (param->type) 00216 { 00217 case ACE_Svc_Conf_Param::SVC_CONF_FILE: 00218 errno = 0; 00219 while ((result = ACE_OS::fread (buf, 1, 00220 max_size, param->source.file)) == 0 && 00221 ferror (param->source.file)) 00222 { 00223 if (errno == EINTR) 00224 { 00225 errno = 0; 00226 #if !defined (ACE_LACKS_CLEARERR) 00227 ACE_OS::clearerr (param->source.file); 00228 #endif /* !ACE_LACKS_CLEARERR */ 00229 } 00230 else 00231 { 00232 ACE_OS::fprintf (stderr, "ERROR: input in scanner failed\n"); 00233 ACE_OS::exit (2); 00234 } 00235 } 00236 break; 00237 case ACE_Svc_Conf_Param::SVC_CONF_DIRECTIVE: 00238 result = ACE_OS::strlen (param->source.directive + 00239 param->buffer->start_) * sizeof (ACE_TCHAR); 00240 if (result != 0) 00241 { 00242 // Make sure that the amount we are going to copy 00243 // fits in the buffer 00244 if (result > max_size) 00245 { 00246 result = max_size; 00247 } 00248 ACE_OS::memcpy (buf, 00249 param->source.directive + param->buffer->start_, 00250 result); 00251 param->buffer->start_ += (result / sizeof (ACE_TCHAR)); 00252 } 00253 break; 00254 default: 00255 ace_yyerror (++param->yyerrno, 00256 param->yylineno, 00257 "Invalid Service Configurator type in " 00258 "ACE_Svc_Conf_Lexer::input"); 00259 } 00260 00261 return result; 00262 } |
|
Definition at line 265 of file Svc_Conf_Lexer.cpp. References ACE_ACTIVE, ACE_COMMENT, ACE_DYNAMIC, ACE_IDENT, ACE_INACTIVE, ACE_OS::ace_isdigit(), ACE_MODULE_T, ACE_NO_STATE, ACE_PATHNAME, ACE_REMOVE, ACE_RESUME, ACE_STATIC, ACE_STREAM_T, ACE_STRING, ACE_SUSPEND, ACE_SVC_OBJ_T, ACE_TCHAR, ACE_TEMPORARY_STRING, ACE_TEXT, ACE_OS::ace_tolower(), ACE_USTREAM, ACE_YY_CONVERSION_SPACE, ace_yyerror(), ACE_Svc_Conf_Param::buffer, ACE_Obstack_T< ACE_TCHAR >::copy(), ace_yy_buffer_state::eof_, ACE_YYSTYPE::ident_, ace_yy_buffer_state::index_, ace_yy_buffer_state::input_, ACE_OS::memmove(), ace_yy_buffer_state::need_more_, ACE_Svc_Conf_Param::obstack, ace_yy_buffer_state::size_, ssize_t, ace_yy_buffer_state::state_, ACE_OS::strchr(), ACE_OS::strcmp(), ace_yy_buffer_state::string_start_, ACE_OS::strncpy(), ACE_Svc_Conf_Param::yyerrno, and ACE_Svc_Conf_Param::yylineno. Referenced by yylex().
00268 { 00269 ace_yy_buffer_state* buffer = param->buffer; 00270 00271 // If we are not currently in any state, skip over whitespace 00272 if (buffer->state_ == ACE_NO_STATE) 00273 { 00274 while (buffer->index_ < buffer->size_ && 00275 isspace (buffer->input_[buffer->index_])) 00276 { 00277 // Make sure that we count all of the new lines 00278 if (buffer->input_[buffer->index_] == '\n') 00279 { 00280 ++param->yylineno; 00281 } 00282 ++buffer->index_; 00283 } 00284 } 00285 00286 size_t current; 00287 size_t last = buffer->size_ + (buffer->eof_ ? 1 : 0); 00288 for (current = buffer->index_; current < last; current++) 00289 { 00290 static const char* separators = " \t\r\n:*(){}"; 00291 char c = (buffer->eof_ && current == buffer->size_ ? 00292 '\n' : buffer->input_[current]); 00293 switch (buffer->state_) 00294 { 00295 case ACE_COMMENT: 00296 if (c == '\n') 00297 { 00298 buffer->state_ = ACE_NO_STATE; 00299 buffer->index_ = current + 1; 00300 ++param->yylineno; 00301 } 00302 break; 00303 case ACE_STRING: 00304 if (!(c >= ' ' && c <= '~')) 00305 { 00306 // The character at currrent is definitely not part of 00307 // the string so we need to move current back one. 00308 --current; 00309 00310 // Get the starting point of our string (skipping the quote) 00311 char* source = buffer->input_ + buffer->index_ + 1; 00312 00313 // Now, we need to move back in the string until we find the 00314 // same character that started the string 00315 bool string_end_found = false; 00316 for(ssize_t i = (current - 1) - buffer->index_; i >= 0; i--) 00317 { 00318 if (source[i] == buffer->string_start_) 00319 { 00320 current = buffer->index_ + i + 1; 00321 string_end_found = true; 00322 break; 00323 } 00324 } 00325 00326 if (!string_end_found) 00327 { 00328 ace_yyerror (++param->yyerrno, 00329 param->yylineno, 00330 "Unable to find the end of the string"); 00331 return ACE_NO_STATE; 00332 } 00333 00334 size_t amount = (current - buffer->index_) - 1; 00335 #if defined (ACE_USES_WCHAR) 00336 ACE_TCHAR target[ACE_YY_CONVERSION_SPACE] = ACE_TEXT (""); 00337 size_t length = 0; 00338 if (!convert_from_utf8 (buffer->converter_, 00339 source, 00340 amount, 00341 target, 00342 ACE_YY_CONVERSION_SPACE, 00343 length)) 00344 { 00345 ace_yyerror (++param->yyerrno, 00346 param->yylineno, 00347 "Unable to convert string from UTF-8"); 00348 return ACE_NO_STATE; 00349 } 00350 amount = length; 00351 #else 00352 char* target = source; 00353 #endif /* ACE_USES_WCHAR */ 00354 ace_yylval->ident_ = param->obstack.copy (target, amount); 00355 buffer->state_ = ACE_NO_STATE; 00356 buffer->index_ = current + 1; 00357 return ACE_STRING; 00358 } 00359 break; 00360 case ACE_NO_STATE: 00361 if (c == '"' || c == '\'') 00362 { 00363 buffer->string_start_ = c; 00364 buffer->state_ = ACE_STRING; 00365 } 00366 else if (c == '#') 00367 { 00368 buffer->state_ = ACE_COMMENT; 00369 } 00370 else if (ACE_OS::strchr (separators, c) != 0) 00371 { 00372 if (c == '\n') 00373 { 00374 ++param->yylineno; 00375 } 00376 00377 if (current == buffer->index_ + 1) 00378 { 00379 int lower = ACE_OS::ace_tolower ( 00380 buffer->input_[current - 1]); 00381 if (c == ':' && 00382 (buffer->input_[current - 1] == '%' || 00383 (lower >= 'a' && lower <= 'z'))) 00384 { 00385 // This is considered a path, so we need to 00386 // skip over the ':' and go around the loop 00387 // again 00388 break; 00389 } 00390 } 00391 00392 if (current == buffer->index_) 00393 { 00394 buffer->index_ = current + 1; 00395 if (isspace (c)) 00396 { 00397 // This is an empty line. 00398 // Let's look for something else. 00399 break; 00400 } 00401 else 00402 { 00403 return c; 00404 } 00405 } 00406 00407 // String from buffer->index_ to current (inclusive) 00408 size_t size = (current - buffer->index_) + 1; 00409 ACE_TEMPORARY_STRING (str, size); 00410 ACE_OS::strncpy (str, buffer->input_ + buffer->index_, 00411 size - 1); 00412 str[size - 1] = '\0'; 00413 00414 00415 if (ACE_OS::strcmp (str, "dynamic") == 0) 00416 { 00417 buffer->index_ = current; 00418 return ACE_DYNAMIC; 00419 } 00420 else if (ACE_OS::strcmp (str, "static") == 0) 00421 { 00422 buffer->index_ = current; 00423 return ACE_STATIC; 00424 } 00425 else if (ACE_OS::strcmp (str, "suspend") == 0) 00426 { 00427 buffer->index_ = current; 00428 return ACE_SUSPEND; 00429 } 00430 else if (ACE_OS::strcmp (str, "resume") == 0) 00431 { 00432 buffer->index_ = current; 00433 return ACE_RESUME; 00434 } 00435 else if (ACE_OS::strcmp (str, "remove") == 0) 00436 { 00437 buffer->index_ = current; 00438 return ACE_REMOVE; 00439 } 00440 else if (ACE_OS::strcmp (str, "stream") == 0) 00441 { 00442 buffer->index_ = current; 00443 return ACE_USTREAM; 00444 } 00445 else if (ACE_OS::strcmp (str, "Module") == 0) 00446 { 00447 buffer->index_ = current; 00448 return ACE_MODULE_T; 00449 } 00450 else if (ACE_OS::strcmp (str, "Service_Object") == 0) 00451 { 00452 buffer->index_ = current; 00453 return ACE_SVC_OBJ_T; 00454 } 00455 else if (ACE_OS::strcmp (str, "STREAM") == 0) 00456 { 00457 buffer->index_ = current; 00458 return ACE_STREAM_T; 00459 } 00460 else if (ACE_OS::strcmp (str, "active") == 0) 00461 { 00462 buffer->index_ = current; 00463 return ACE_ACTIVE; 00464 } 00465 else if (ACE_OS::strcmp (str, "inactive") == 0) 00466 { 00467 buffer->index_ = current; 00468 return ACE_INACTIVE; 00469 } 00470 else 00471 { 00472 // Get the string and save it in ace_yylval 00473 int token = ACE_IDENT; 00474 size_t amount = size - 1; 00475 #if defined (ACE_USES_WCHAR) 00476 ACE_TCHAR target[ACE_YY_CONVERSION_SPACE] = ACE_TEXT (""); 00477 size_t length = 0; 00478 if (!convert_from_utf8 (buffer->converter_, 00479 str, 00480 amount, 00481 target, 00482 ACE_YY_CONVERSION_SPACE, 00483 length)) 00484 { 00485 ace_yyerror (++param->yyerrno, 00486 param->yylineno, 00487 "Unable to convert " 00488 "identifier from UTF-8"); 00489 return ACE_NO_STATE; 00490 } 00491 amount = length; 00492 #else 00493 char* target = str; 00494 #endif /* ACE_USES_WCHAR */ 00495 ace_yylval->ident_ = param->obstack.copy (target, amount); 00496 00497 // Determine the difference between pathname and ident 00498 if (ACE_OS::ace_isdigit (ace_yylval->ident_[0])) 00499 { 00500 token = ACE_PATHNAME; 00501 } 00502 else 00503 { 00504 static const ACE_TCHAR* path_parts = 00505 ACE_TEXT ("/\\:%.~-"); 00506 for (const ACE_TCHAR* p = path_parts; *p != '\0'; p++) 00507 { 00508 if (ACE_OS::strchr (ace_yylval->ident_, *p) != 0) 00509 { 00510 token = ACE_PATHNAME; 00511 break; 00512 } 00513 } 00514 } 00515 00516 buffer->state_ = ACE_NO_STATE; 00517 buffer->index_ = current; 00518 return token; 00519 } 00520 } 00521 break; 00522 default: 00523 ace_yyerror (++param->yyerrno, 00524 param->yylineno, 00525 "Unexpected state in ACE_Svc_Conf_Lexer::scan"); 00526 return ACE_NO_STATE; 00527 } 00528 } 00529 00530 // We need more from the input source so, we will move the remainder of 00531 // the buffer to the front and signal that we need more 00532 if (!buffer->eof_) 00533 { 00534 buffer->need_more_ = true; 00535 if (buffer->state_ == ACE_COMMENT) 00536 { 00537 buffer->index_ = 0; 00538 buffer->size_ = 0; 00539 } 00540 else 00541 { 00542 buffer->size_ = current - buffer->index_; 00543 if (buffer->size_ != 0 && buffer->index_ != 0) 00544 ACE_OS::memmove (buffer->input_, 00545 buffer->input_ + buffer->index_, buffer->size_); 00546 buffer->index_ = 0; 00547 buffer->state_ = ACE_NO_STATE; 00548 } 00549 } 00550 return ACE_NO_STATE; 00551 } |
|
This is similar to the C function, ace_yylex, which a bison generated parser expects. It returns information in the ace_yylval parameter and uses input stored in the param parameter. Definition at line 133 of file Svc_Conf_Lexer.cpp. References ACE_NEW_RETURN, ACE_NO_STATE, ACE_YY_BUF_SIZE, ace_yyerror(), ACE_Svc_Conf_Param::buffer, ace_yy_buffer_state::eof_, input(), ace_yy_buffer_state::input_, ACE_OS::memmove(), ace_yy_buffer_state::need_more_, normalize(), scan(), ace_yy_buffer_state::size_, ACE_Svc_Conf_Param::yyerrno, and ACE_Svc_Conf_Param::yylineno. Referenced by ace_yylex().
00135 { 00136 #if defined (ACE_USES_WCHAR) 00137 bool look_for_bom = false; 00138 ACE_Encoding_Converter_Factory::Encoding_Hint hint = 00139 ACE_Encoding_Converter_Factory::ACE_NONE; 00140 #endif /* ACE_USES_WCHAR */ 00141 if (param->buffer == 0) 00142 { 00143 #if defined (ACE_USES_WCHAR) 00144 look_for_bom = true; 00145 #endif /* ACE_USES_WCHAR */ 00146 ACE_NEW_RETURN (param->buffer, 00147 ace_yy_buffer_state, 00148 -1); 00149 } 00150 00151 int token = ACE_NO_STATE; 00152 do { 00153 if (param->buffer->need_more_) 00154 { 00155 size_t skip_bytes = 0; 00156 param->buffer->need_more_ = false; 00157 size_t amount = 00158 input (param, 00159 param->buffer->input_ + param->buffer->size_, 00160 normalize (ACE_YY_BUF_SIZE - 00161 param->buffer->size_)); 00162 if (amount == 0) 00163 { 00164 param->buffer->eof_ = true; 00165 skip_bytes = param->buffer->size_; 00166 } 00167 else 00168 { 00169 #if defined (ACE_USES_WCHAR) 00170 if (look_for_bom) 00171 { 00172 size_t read_more = 0; 00173 00174 look_for_bom = false; 00175 hint = locate_bom (param->buffer->input_, amount, read_more); 00176 00177 if (read_more != 0) 00178 { 00179 input (param, 00180 param->buffer->input_ + amount, 00181 read_more); 00182 ACE_OS::memmove (param->buffer->input_, 00183 param->buffer->input_ + read_more, 00184 amount); 00185 } 00186 } 00187 #endif /* ACE_USES_WCHAR */ 00188 skip_bytes = param->buffer->size_; 00189 param->buffer->size_ += amount; 00190 } 00191 00192 #if defined (ACE_USES_WCHAR) 00193 if (!convert_to_utf8 (param, skip_bytes, hint)) 00194 { 00195 ace_yyerror (++param->yyerrno, 00196 param->yylineno, 00197 "Unable to convert input stream to UTF-8"); 00198 return ACE_NO_STATE; 00199 } 00200 #endif /* ACE_USES_WCHAR */ 00201 } 00202 00203 token = scan (ace_yylval, param); 00204 } while (token == ACE_NO_STATE && param->buffer->need_more_); 00205 00206 return token; 00207 } |