analyzetool/commandlineengine/src/arguments.cpp
branchRCL_3
changeset 49 7fdc9a71d314
parent 19 da2cedce4920
child 59 8ad140f3dd41
equal deleted inserted replaced
46:e26895079d7c 49:7fdc9a71d314
    20 bool parseBaseArguments( vector<string>& vArgs, ARGUMENTS& args );
    20 bool parseBaseArguments( vector<string>& vArgs, ARGUMENTS& args );
    21 bool parseHookArguments( vector<string>& vArgs, ARGUMENTS& args );
    21 bool parseHookArguments( vector<string>& vArgs, ARGUMENTS& args );
    22 bool parseAnalyzeArguments( vector<string>& vArgs, ARGUMENTS& args );
    22 bool parseAnalyzeArguments( vector<string>& vArgs, ARGUMENTS& args );
    23 bool parseParseArguments( vector<string>& vArgs, ARGUMENTS& args );
    23 bool parseParseArguments( vector<string>& vArgs, ARGUMENTS& args );
    24 bool checkDataFileName( string& sFileName );
    24 bool checkDataFileName( string& sFileName );
       
    25 bool checkDataFilePath( string& sFilePath );
    25 bool parseSbsConfiguration( string& sConfiguration, ARGUMENTS& args );
    26 bool parseSbsConfiguration( string& sConfiguration, ARGUMENTS& args );
    26 
    27 
    27 // Constants for old "hooking" parameter parsing.
    28 // Constants for old "hooking" parameter parsing.
    28 #define INVALID_PARAMETER "AnalyzeTool : Error, invalid parameter: "
    29 #define INVALID_PARAMETER "AnalyzeTool : Error, invalid parameter: "
    29 const char DATAFILENAME_INVALID_CHARS[] = " &^+-@$%*()|\\/[]{}<>?;:,\"'";
    30 const char DATAFILENAME_INVALID_CHARS[] = " &^+-@$*()|\\/[]{}<>?;:,\"'";
       
    31 const char DATAFILEPATH_INVALID_CHARS[] = " &^+-@$%*()|/[]{}<>?;,\"'";
    30 
    32 
    31 /**
    33 /**
    32 * Check datafile name for invalid characters.
    34 * Check datafile name for invalid characters.
    33 * @return true if file name ok.
    35 * @return true if file name ok.
    34 */
    36 */
    38 	{
    40 	{
    39 		const char c = sFileName.at( i );
    41 		const char c = sFileName.at( i );
    40 		if( strchr( DATAFILENAME_INVALID_CHARS, c ) != 0 )
    42 		if( strchr( DATAFILENAME_INVALID_CHARS, c ) != 0 )
    41 			return false;
    43 			return false;
    42 	}
    44 	}
       
    45 	return true;
       
    46 }
       
    47 
       
    48 /**
       
    49 * Check datafile path for invalid characters and correct format.
       
    50 * @return true if file path ok.
       
    51 */
       
    52 bool checkDataFilePath( string& sFilePath )
       
    53 {
       
    54 	for ( size_t i = 0; i < sFilePath.length(); i++ )
       
    55 	{
       
    56 		char c = sFilePath.at( i );
       
    57 		if( strchr( DATAFILEPATH_INVALID_CHARS, c ) != 0 )
       
    58 			return false;
       
    59 		// first char must be drive letter a-z
       
    60 		if( i == 0 && ( c = tolower( c ) < 'a' || c > 'z' ) )
       
    61 			return false;
       
    62 		// if last char is not '\', add it
       
    63 		if( i == sFilePath.length()-1 &&  c != '\\' )
       
    64 			sFilePath.append( "\\" );
       
    65 	}
       
    66 
       
    67 	// ':\' after drive letter
       
    68 	if( sFilePath.find( ":\\" ) != 1 )
       
    69 		return false;
       
    70 
       
    71 	// there can be only one ':' on pos 1
       
    72 	if( sFilePath.find( ":", 2 ) != string::npos )
       
    73 		return false;
       
    74 
       
    75 	//check double slashes
       
    76 	if( sFilePath.find( "\\\\" ) != string::npos )
       
    77 		return false;
       
    78 
    43 	return true;
    79 	return true;
    44 }
    80 }
    45 
    81 
    46 /**
    82 /**
    47 * Parse base arguments from given vector of strings.
    83 * Parse base arguments from given vector of strings.
   176 			args.eMainSwitch = SWITCH_DBGHELP_VERSION;
   212 			args.eMainSwitch = SWITCH_DBGHELP_VERSION;
   177 		else if ( ! _stricmp( (*it).c_str(), "-help" ) )
   213 		else if ( ! _stricmp( (*it).c_str(), "-help" ) )
   178 			args.eMainSwitch = SWITCH_HELP;
   214 			args.eMainSwitch = SWITCH_HELP;
   179 		else if ( ! _stricmp( (*it).c_str(), "-me" ) )
   215 		else if ( ! _stricmp( (*it).c_str(), "-me" ) )
   180 		{
   216 		{
   181 			args.eMainSwitch = SWITCH_HOOK;
   217 			cout << AT_MSG << "This feature is no longer supported. You can use -tr parameter for output to trace. \n" << endl;
   182 			args.eHookSwitch = HOOK_EXTERNAL;
   218 		}
   183 		}
   219 		else if ( ! _stricmp( (*it).c_str(), "-e" ) ||  ! _stricmp( (*it).c_str(), "-tr" ) )
   184 		else if ( ! _stricmp( (*it).c_str(), "-e" ) )
       
   185 		{
   220 		{
   186 			args.eMainSwitch = SWITCH_HOOK;
   221 			args.eMainSwitch = SWITCH_HOOK;
   187 			args.eHookSwitch = HOOK_EXTERNAL_FAST;
   222 			args.eHookSwitch = HOOK_EXTERNAL_FAST;
   188 		}
   223 		}
   189 		else if ( ! _stricmp( (*it).c_str(), "-mi" ) )
   224 		else if ( ! _stricmp( (*it).c_str(), "-mi" ) )
       
   225 		{
       
   226 			cout << AT_MSG << "This feature is no longer supported. You can use -lf parameter for logging to file. \n" << endl;
       
   227 		}
       
   228 		else if ( ! _stricmp( (*it).c_str(), "-lf" ) )
   190 		{
   229 		{
   191 			args.eMainSwitch = SWITCH_HOOK;
   230 			args.eMainSwitch = SWITCH_HOOK;
   192 			args.eHookSwitch = HOOK_INTERNAL;
   231 			args.eHookSwitch = HOOK_INTERNAL;
   193 		}
   232 		}
   194 		else if ( ! _stricmp( (*it).c_str(), "-instrument_i" ) )
   233 		else if ( ! _stricmp( (*it).c_str(), "-instrument_i" ) )
   353 					cout << AT_MSG << "Error, missing call stack size parameter." << endl;
   392 					cout << AT_MSG << "Error, missing call stack size parameter." << endl;
   354 					break;
   393 					break;
   355 				}
   394 				}
   356 				else if ( ! _stricmp( it->c_str(), "sbs" ) 
   395 				else if ( ! _stricmp( it->c_str(), "sbs" ) 
   357 					|| ! _stricmp( it->c_str(), "abld" )
   396 					|| ! _stricmp( it->c_str(), "abld" )
   358 					|| ! _stricmp( it->c_str(), "-f" ) )
   397 					|| ! _stricmp( it->c_str(), "-f" )
       
   398 					|| ! _stricmp( it->c_str(), "-fp" ) )
   359 				{
   399 				{
   360 					bRet = false;
   400 					bRet = false;
   361 					cout << AT_MSG << "Error, missing call stack size parameter." << endl;
   401 					cout << AT_MSG << "Error, missing call stack size parameter." << endl;
   362 					break;
   402 					break;
   363 				}
   403 				}
   405 			{
   445 			{
   406 				it++;
   446 				it++;
   407 				if ( it == vArgs.end() )
   447 				if ( it == vArgs.end() )
   408 				{
   448 				{
   409 					bRet = false;
   449 					bRet = false;
   410 					cout << AT_MSG << "Error, missing internal data gathering file name." << endl;
   450 					cout << AT_MSG << "Error, missing log file name." << endl;
   411 					break;
   451 					break;
   412 				}
   452 				}
   413 				else if ( ! _stricmp( it->c_str(), "sbs" ) || ! _stricmp( it->c_str(), "abld" ) )
   453 				else if ( ! _stricmp( it->c_str(), "sbs" ) || ! _stricmp( it->c_str(), "abld" ) )
   414 				{
   454 				{
   415 					bRet = false;
   455 					bRet = false;
   416 					cout << AT_MSG << "Error, missing internal data gathering file name." << endl;
   456 					cout << AT_MSG << "Error, missing log file name." << endl;
   417 					break;
   457 					break;
   418 				}
   458 				}
   419 				else
   459 				else
   420 				{
   460 				{
   421 					if ( checkDataFileName( string( *it ) ) )
   461 					if ( checkDataFileName( string( *it ) ) )
   425 						args.HOOK.sDataFileName = *it;
   465 						args.HOOK.sDataFileName = *it;
   426 					}
   466 					}
   427 					else
   467 					else
   428 					{
   468 					{
   429 						bRet = false;
   469 						bRet = false;
   430 						cout << AT_MSG << "Error, specified internal data gathering file name contains invalid character(s)." << endl;
   470 						cout << AT_MSG << "Error, specified log file name contains invalid character(s)." << endl;
       
   471 						break;
       
   472 					}
       
   473 				}
       
   474 			}
       
   475 			// Data file path.
       
   476 			else if ( _stricmp( it->c_str(), "-fp" ) == 0 )
       
   477 			{
       
   478 				it++;
       
   479 				if ( it == vArgs.end() )
       
   480 				{
       
   481 					bRet = false;
       
   482 					cout << AT_MSG << "Error, missing path for log file." << endl;
       
   483 					break;
       
   484 				}
       
   485 				else if ( ! _stricmp( it->c_str(), "sbs" ) || ! _stricmp( it->c_str(), "abld" ) )
       
   486 				{
       
   487 					bRet = false;
       
   488 					cout << AT_MSG << "Error, missing path for log file." << endl;
       
   489 					break;
       
   490 				}
       
   491 				else
       
   492 				{
       
   493 					string sFormattedPath = string(*it);
       
   494 					if ( checkDataFilePath( sFormattedPath ) )
       
   495 					{
       
   496 						// Pickup filename.
       
   497 						args.HOOK.bDataFilePath = true;
       
   498 						args.HOOK.sDataFilePath = sFormattedPath;
       
   499 					}
       
   500 					else
       
   501 					{
       
   502 						bRet = false;
       
   503 						cout << AT_MSG << "Error, specified log file path contains invalid character(s) "
       
   504 							<< "or is in wrong format. Please, check help for correct format," << endl;
   431 						break;
   505 						break;
   432 					}
   506 					}
   433 				}
   507 				}
   434 			}
   508 			}
   435 			// Build command parsing.
   509 			// Build command parsing.