void antSpeedOnlyProcessing::readDeviceFileLine ( const char *line ) { amSplitString words; unsigned int nbWords = words.split( line, C_COMMENT_SYMBOL_AS_STRING ); if ( nbWords > 1 ) { amString deviceType = words[ 0 ]; if ( deviceType == C_INCLUDE_FILE ) { amString curFileName = words.concatenate( 1 ); std::ifstream devicesIncludeFileStream( curFileName.c_str() ); if ( devicesIncludeFileStream.fail() ) { appendErrorMessage( "ERROR while opening devices ID include file \"" ); appendErrorMessage( curFileName ); appendErrorMessage( "\".\n" ); errorCode = E_READ_FILE_NOT_OPEN; } else { readDeviceFileStream( devicesIncludeFileStream ); devicesIncludeFileStream.close(); } } else { amString deviceName = words[ 1 ]; if ( isSpeedOnlySensor( deviceName ) ) { if ( deviceType == C_SPEED_DEVICE_ID ) { amString curErrorMessage; errorCode = antSpeedProcessing::readDeviceFileLine1( line, curErrorMessage ); if ( errorCode ) { appendErrorMessage( curErrorMessage ); } } } } } }
/** \brief parse the given file command */ void ParserSingleInstance::parse(const char *command) { size_t len = strlen(command); yylloc.first_line = yylloc.last_line = 1; yylloc.first_column = yylloc.last_column = 1; #ifdef _MSC_VER char szFile[MAX_PATH]; char* pstTmpDIr = getTMPDIR(); os_sprintf(szFile, "%s\\%s", pstTmpDIr, "command.temp"); FREE(pstTmpDIr); if (fileLocker) { fclose(fileLocker); } errno_t err; err = fopen_s(&yyin, szFile, "w"); if (err) { ParserSingleInstance::setExitStatus(Parser::Failed); ParserSingleInstance::resetErrorMessage(); wchar_t szError[bsiz]; wchar_t* wszFile = to_wide_string(szFile); os_swprintf(szError, bsiz, _W("%ls: Cannot open file %ls.\n").c_str(), L"parser", wszFile); FREE(wszFile); appendErrorMessage(szError); return; } fwrite(command, sizeof(char), len, yyin); fclose(yyin); fopen_s(&yyin, szFile, "r"); #endif #ifdef __APPLE__ char szFile[PATH_MAX]; char* pstTmpDIr = "/tmp"; sprintf(szFile, "%s/%s", getTMPDIR(), "command.temp"); //FREE(pstTmpDIr); if (fileLocker) { fclose(fileLocker); } yyin = fopen(szFile, "w"); fwrite(command, 1, len, yyin); fclose(yyin); yyin = fopen(szFile, "r"); #endif #ifndef _MSC_VER #ifndef __APPLE__ yyin = fmemopen((void*)command, len, "r"); #endif #endif ParserSingleInstance::disableStrictMode(); ParserSingleInstance::setFileName(L"prompt"); ParserSingleInstance::setTree(nullptr); ParserSingleInstance::setExitStatus(Parser::Succeded); ParserSingleInstance::resetControlStatus(); ParserSingleInstance::resetErrorMessage(); yyparse(); fclose(yyin); #ifdef _MSC_VER DeleteFileA(szFile); #endif #ifdef _MSC_VER //reopen a file to prevents max file opened. fopen_s(&fileLocker, szFile, "w"); #endif #ifdef __APPLE__ fileLocker = fopen(szFile, "w"); #endif }