memana/analyzetoolclient/commandlineengine/internal/src/arguments.cpp
changeset 0 f0f2b8682603
equal deleted inserted replaced
-1:000000000000 0:f0f2b8682603
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Argument parsing functions.
       
    15 */
       
    16 #include "../inc/ATCommonDefines.h"
       
    17 #include "../inc/CATBase.h"
       
    18 
       
    19 //Forward declarations.
       
    20 bool parseBaseArguments( vector<string>& vArgs, ARGUMENTS& args );
       
    21 bool parseHookArguments( vector<string>& vArgs, ARGUMENTS& args );
       
    22 bool parseOldHookArguments( vector<string>& vArgs, ARGUMENTS& args );
       
    23 bool parseAnalyzeArguments( vector<string>& vArgs, ARGUMENTS& args );
       
    24 bool parseHtiArguments( vector<string>& vArgs, ARGUMENTS& args );
       
    25 bool parseParseArguments( vector<string>& vArgs, ARGUMENTS& args );
       
    26 bool checkDataFileName( string& sFileName );
       
    27 
       
    28 // Constants for old "hooking" parameter parsing.
       
    29 #define INVALID_PARAMETER "AnalyzeTool : Error, invalid parameter: "
       
    30 const char LOG_S60[] = "s60";
       
    31 const char LOG_XTI[] = "xti";
       
    32 const char DATAFILENAME_INVALID_CHARS[] = " &^+-@$%*()|\\/[]{}<>?;:,\"'";
       
    33 
       
    34 /**
       
    35 * Check datafile name for invalid characters.
       
    36 * @return true if file name ok.
       
    37 */
       
    38 bool checkDataFileName( string& sFileName )
       
    39 {
       
    40 	for ( size_t i = 0; i < sFileName.length(); i++ )
       
    41 	{
       
    42 		const char c = sFileName.at( i );
       
    43 		if( strchr( DATAFILENAME_INVALID_CHARS, c ) != 0 )
       
    44 			return false;
       
    45 	}
       
    46 	return true;
       
    47 }
       
    48 
       
    49 /**
       
    50 * Parse base arguments from given vector of strings.
       
    51 * Removes debug / help arguments from vector.
       
    52 */
       
    53 bool parseBaseArguments( vector<string>& vArgs, ARGUMENTS& args )
       
    54 {
       
    55 	// Iterator used in this function.
       
    56 	vector<string>::iterator it;
       
    57 	// If no arguments set show help true.
       
    58  	if ( vArgs.size() == 0 )
       
    59 	{
       
    60 		args.eMainSwitch = SWITCH_UNKNOWN;
       
    61 		args.bHelp = true;
       
    62 	}
       
    63 	//Try find help and debug switches.
       
    64 	//Note: -help is main switch what shows syntax examples.
       
    65 	for(it = vArgs.begin(); it != vArgs.end(); it++ )
       
    66 	{
       
    67 		//Help switches.
       
    68 		if ( ! _stricmp( (*it).c_str(), "-?" ) )
       
    69 		{
       
    70 			args.bHelp = true;
       
    71 			it = vArgs.erase( it );
       
    72 			if ( it == vArgs.end() )
       
    73 				break;
       
    74 		}
       
    75 		else if ( ! _stricmp( (*it).c_str(), "--?" ) )
       
    76 		{
       
    77 			args.bHelp = true;
       
    78 			it = vArgs.erase( it );
       
    79 			if ( it == vArgs.end() )
       
    80 				break;
       
    81 		}
       
    82 		else if ( ! _stricmp( (*it).c_str(), "--help" ) )
       
    83 		{
       
    84 			args.bHelp = true;
       
    85 			it = vArgs.erase( it );
       
    86 			if ( it == vArgs.end() )
       
    87 				break;
       
    88 		}
       
    89 		else if ( ! _stricmp( (*it).c_str(), "/?" ) )
       
    90 		{
       
    91 			args.bHelp = true;
       
    92 			it = vArgs.erase( it );
       
    93 			if ( it == vArgs.end() )
       
    94 				break;
       
    95 		}
       
    96 		//Debug switches.
       
    97 		else if ( ! _stricmp( (*it).c_str(), "-show_debug" ) )
       
    98 		{
       
    99 			args.bDebugConsole = true;
       
   100 			it = vArgs.erase( it );
       
   101 			if ( it == vArgs.end() )
       
   102 				break;
       
   103 		}
       
   104 		else if ( ! _stricmp( (*it).c_str(), "--show_debug" ) )
       
   105 		{
       
   106 			args.bDebugConsole = true;
       
   107 			it = vArgs.erase( it );
       
   108 			if ( it == vArgs.end() )
       
   109 				break;
       
   110 		}
       
   111 		else if ( ! _stricmp( (*it).c_str(), "-show_debug_all" ) )
       
   112 		{
       
   113 			args.bDebugConsole = true;
       
   114 			args.bDebugLowLevel = true;
       
   115 			it = vArgs.erase( it );
       
   116 			if ( it == vArgs.end() )
       
   117 				break;
       
   118 		}
       
   119 		else if ( ! _stricmp( (*it).c_str(), "--show_debug_all" ) )
       
   120 		{
       
   121 			args.bDebugConsole = true;
       
   122 			args.bDebugLowLevel = true;
       
   123 			it = vArgs.erase( it );
       
   124 			if ( it == vArgs.end() )
       
   125 				break;
       
   126 		}
       
   127 		else if ( ! _stricmp( (*it).c_str(), "-show_dbgview" ) )
       
   128 		{
       
   129 			args.bDebugDbgView = true;
       
   130 			it = vArgs.erase( it );
       
   131 			if ( it == vArgs.end() )
       
   132 				break;
       
   133 		}
       
   134 		else if ( ! _stricmp( (*it).c_str(), "--show_dbgview" ) )
       
   135 		{
       
   136 			args.bDebugDbgView = true;
       
   137 			it = vArgs.erase( it );
       
   138 			if ( it == vArgs.end() )
       
   139 				break;
       
   140 		}
       
   141 		else if ( ! _stricmp( (*it).c_str(), "-show_dbgview_all" ) )
       
   142 		{
       
   143 			args.bDebugDbgView = true;
       
   144 			args.bDebugLowLevel = true;
       
   145 			it = vArgs.erase( it );
       
   146 			if ( it == vArgs.end() )
       
   147 				break;
       
   148 		}
       
   149 		else if ( ! _stricmp( (*it).c_str(), "--show_dbgview_all" ) )
       
   150 		{
       
   151 			args.bDebugDbgView = true;
       
   152 			args.bDebugLowLevel = true;
       
   153 			it = vArgs.erase( it );
       
   154 			if ( it == vArgs.end() )
       
   155 				break;
       
   156 		}
       
   157 		//Raptor switch.
       
   158 		else if ( ! _stricmp( (*it).c_str(), "-sbs2" ) )
       
   159 		{
       
   160 			args.bEnableSbs2 = true;
       
   161 			it = vArgs.erase( it );
       
   162 			if ( it == vArgs.end() )
       
   163 				break;
       
   164 		}
       
   165 	}
       
   166 	if ( vArgs.size() > 0 )
       
   167 	{
       
   168 		//Pick up main switch.
       
   169 		it = vArgs.begin();
       
   170 		if ( ! _stricmp( (*it).c_str(), "-a" ) )
       
   171 			args.eMainSwitch = SWITCH_ANALYZE;
       
   172 		else if ( ! _stricmp( (*it).c_str(), "-p" ) )
       
   173 			args.eMainSwitch = SWITCH_PARSE_TRACE;
       
   174 		else if ( ! _stricmp( (*it).c_str(), "-c" ) )
       
   175 			args.eMainSwitch = SWITCH_CLEAN;
       
   176 		else if ( ! _stricmp( (*it).c_str(), "-g" ) )
       
   177 			args.eMainSwitch = SWITCH_HTI_GET;
       
   178 		else if ( ! _stricmp( (*it).c_str(), "-delete" ) )
       
   179 			args.eMainSwitch = SWITCH_HTI_DELETE;
       
   180 		else if ( ! _stricmp( (*it).c_str(), "-v" ) )
       
   181 			args.eMainSwitch = SWITCH_VERSION;
       
   182 		else if ( ! _stricmp( (*it).c_str(), "-help" ) )
       
   183 			args.eMainSwitch = SWITCH_HELP;
       
   184 		else if ( ! _stricmp( (*it).c_str(), "-me" ) )
       
   185 		{
       
   186 			args.eMainSwitch = SWITCH_HOOK;
       
   187 			args.eHookSwitch = HOOK_EXTERNAL;
       
   188 		}
       
   189 		else if ( ! _stricmp( (*it).c_str(), "-e" ) )
       
   190 		{
       
   191 			args.eMainSwitch = SWITCH_HOOK;
       
   192 			args.eHookSwitch = HOOK_EXTERNAL_FAST;
       
   193 		}
       
   194 		else if ( ! _stricmp( (*it).c_str(), "-mi" ) )
       
   195 		{
       
   196 			args.eMainSwitch = SWITCH_HOOK;
       
   197 			args.eHookSwitch = HOOK_INTERNAL;
       
   198 		}
       
   199 		else if ( ! _stricmp( (*it).c_str(), "-instrument_i" ) )
       
   200 		{
       
   201 			args.eMainSwitch = SWITCH_HOOK;
       
   202 			args.eHookSwitch = HOOK_EXTENSION_INTERNAL;
       
   203 		}
       
   204 		else if ( ! _stricmp( (*it).c_str(), "-instrument_e" ) )
       
   205 		{
       
   206 			args.eMainSwitch = SWITCH_HOOK;
       
   207 			args.eHookSwitch = HOOK_EXTENSION_EXTERNAL;
       
   208 		}
       
   209 		else if ( ! _stricmp( (*it).c_str(), "-instrument_ef" ) )
       
   210 		{
       
   211 			args.eMainSwitch = SWITCH_HOOK;
       
   212 			args.eHookSwitch = HOOK_EXTENSION_EXTERNAL_FAST;
       
   213 		}
       
   214 		else if ( ! _stricmp( (*it).c_str(), "-uninstrument" ) )
       
   215 		{
       
   216 			args.eMainSwitch = SWITCH_UNHOOK;
       
   217 			args.eHookSwitch = HOOK_EXTENSION_UNINSTRUMENT;
       
   218 		}
       
   219 		else if ( ! _stricmp( (*it).c_str(), "-uninstrument_failed" ) )
       
   220 		{
       
   221 			args.eMainSwitch = SWITCH_UNHOOK;
       
   222 			args.eHookSwitch = HOOK_EXTENSION_FAILED;
       
   223 		}
       
   224 		else if ( ! _stricmp( (*it).c_str(), "-inst" ) )
       
   225 		{
       
   226 			args.eMainSwitch = SWITCH_OLD_HOOK;
       
   227 			args.eHookSwitch = HOOK_OLD_EXTENSION_INSTRUMENT;
       
   228 		}
       
   229 		else if ( ! _stricmp( (*it).c_str(), "-uninst" ) )
       
   230 		{
       
   231 			args.eMainSwitch = SWITCH_OLD_HOOK;
       
   232 			args.eHookSwitch = HOOK_OLD_EXTENSION_UNINSTRUMENT;
       
   233 		}
       
   234 		else if ( ! _stricmp( (*it).c_str(), "-uninst_failed" ) )
       
   235 		{
       
   236 			args.eMainSwitch = SWITCH_OLD_HOOK;
       
   237 			args.eHookSwitch = HOOK_OLD_EXTENSION_FAILED;
       
   238 		}
       
   239 	}
       
   240 	return true;
       
   241 }
       
   242 
       
   243 /**
       
   244 * Parse analyze related arguments from given vector of strings.
       
   245 */
       
   246 bool parseAnalyzeArguments( vector<string>& vArgs, ARGUMENTS& args )
       
   247 {
       
   248 	bool bRet = true;
       
   249 	if ( vArgs.size() < 2 )
       
   250 	{
       
   251 		cout << AT_MSG << "Error, missing datafile." << endl;
       
   252 		return false;
       
   253 	}
       
   254 	// Iterator used in this function.
       
   255 	vector<string>::const_iterator it;
       
   256 	for(it = vArgs.begin()+1; it != vArgs.end(); it++ )
       
   257 	{
       
   258 		if ( it->find("-l") != string::npos )
       
   259 		{
       
   260 			if ( it->length() == 3 )
       
   261 			{
       
   262 				// Create char array for atoi function
       
   263 				char level[2];
       
   264 				level[0] = it->at(2);
       
   265 				level[1] = 0; // null terminate
       
   266 				// check that its digit first
       
   267 				if ( isdigit(level[0]) )
       
   268 				{
       
   269 					// pass array to atoi
       
   270 					int iLoggingLevel = atoi( level );
       
   271 					if ( iLoggingLevel >= 0 && iLoggingLevel <= 3 )
       
   272 					{
       
   273 						// log level ok
       
   274 						args.ANALYZE.iLoggingLevel = iLoggingLevel;
       
   275 						continue;
       
   276 					}
       
   277 				}
       
   278 				bRet = false;
       
   279 				cout << AT_MSG << "Invalid logging level specified (0-3)." << endl;
       
   280 				args.ANALYZE.iLoggingLevel = -1;
       
   281 			}
       
   282 		}
       
   283 		// No else here because logging level check is done to all args in list.
       
   284 		// Rom symbol file
       
   285 		if( _stricmp( it->c_str(), "-s" ) == 0 )
       
   286 		{
       
   287 			it++;
       
   288 			if ( it == vArgs.end() )
       
   289 			{
       
   290 				bRet = false;
       
   291 				cout << AT_MSG << "Missing symbol file." << endl;
       
   292 				break; // Leave for loop.
       
   293 			}
       
   294 			else
       
   295 			{
       
   296 				args.ANALYZE.bSymbolFile = true;
       
   297 				args.ANALYZE.vSymbolFiles.push_back( *it );
       
   298 				continue;
       
   299 			}
       
   300 		}
       
   301 		else 
       
   302 		{
       
   303 			// If we got datafile we must assume this is output
       
   304 			if( ! args.ANALYZE.sDataFile.empty() )
       
   305 			{
       
   306 				if ( args.ANALYZE.sOutputFile.empty() )
       
   307 					args.ANALYZE.sOutputFile = *it;
       
   308 				else
       
   309 				{
       
   310 					bRet = false;
       
   311 					cout << AT_MSG << "Invalid parameter: " << *it << endl;
       
   312 				}
       
   313 			}
       
   314 			// If this is file we assume datafile
       
   315 			else if( CATBase::FileExists( it->c_str() ) )
       
   316 			{
       
   317 				args.ANALYZE.sDataFile = *it;
       
   318 			}
       
   319 			else
       
   320 			{
       
   321 				bRet = false;
       
   322 				cout << AT_MSG << "Specified datafile does not exist." << endl;
       
   323 			}
       
   324 		}
       
   325 	}
       
   326 	if ( args.ANALYZE.sDataFile.empty() )
       
   327 		bRet = false;
       
   328 	return bRet;
       
   329 }
       
   330 
       
   331 
       
   332 /**
       
   333 * Parse hooking related arguments from given vector of strings.
       
   334 */
       
   335 bool parseHookArguments( vector<string>& vArgs, ARGUMENTS& args )
       
   336 {
       
   337 	bool bRet = true;
       
   338 	try {
       
   339 		// Iterator used in this function.
       
   340 		vector<string>::const_iterator it;
       
   341 
       
   342 		// Check that we have some arguments except main switch.
       
   343 		if ( vArgs.size() < 2 )
       
   344 		{
       
   345 			if ( args.eHookSwitch == HOOK_EXTENSION_UNINSTRUMENT
       
   346 				|| args.eHookSwitch == HOOK_EXTENSION_FAILED
       
   347 				)
       
   348 				return bRet;
       
   349 			cout << AT_MSG << "Error, Missing build command." << endl;
       
   350 			bRet = false;
       
   351 		}
       
   352 		bool bBuildFound = false;
       
   353 		for(it = vArgs.begin()+1; it != vArgs.end(); it++ )
       
   354 		{
       
   355 			// If's to pickup atool options
       
   356 			// no build switch
       
   357 			if ( _stricmp( it->c_str(), "-nobuild" ) == 0 )
       
   358 			{
       
   359 				args.HOOK.bNoBuild = true;
       
   360 			}
       
   361 			// call stack size(s)
       
   362 			else if ( _stricmp( it->c_str(), "-acs" ) == 0 || _stricmp( it->c_str(), "-fcs" ) == 0 )
       
   363 			{
       
   364 				// Free vs Alloc
       
   365 				bool bAlloc = true;
       
   366 				if ( _stricmp( it->c_str(), "-fcs" ) == 0 )
       
   367 					bAlloc = false;
       
   368 				// Value
       
   369 				it++;
       
   370 				if ( it== vArgs.end() )
       
   371 				{
       
   372 					bRet = false;
       
   373 					cout << AT_MSG << "Error, missing call stack size parameter." << endl;
       
   374 					break;
       
   375 				}
       
   376 				else if ( ! _stricmp( it->c_str(), "sbs" ) 
       
   377 					|| ! _stricmp( it->c_str(), "abld" )
       
   378 					|| ! _stricmp( it->c_str(), "-f" ) )
       
   379 				{
       
   380 					bRet = false;
       
   381 					cout << AT_MSG << "Error, missing call stack size parameter." << endl;
       
   382 					break;
       
   383 				}
       
   384 				else
       
   385 				{
       
   386 					int i;
       
   387 					// Try to parse integer value using stream.
       
   388 					istringstream ss( *it );
       
   389 					if ( ss>>i )
       
   390 					{
       
   391 						// Value parsed ok now check bounds.
       
   392 						if ( i < AT_CALL_STACK_SIZE_MIN  )
       
   393 						{
       
   394 							bRet = false;
       
   395 							cout << AT_MSG << "Error, specified call stack size value too small." << endl;
       
   396 							break;
       
   397 						}
       
   398 						else if ( i > AT_CALL_STACK_SIZE_MAX )
       
   399 						{
       
   400 							bRet = false;
       
   401 							cout << AT_MSG << "Error, specified call stack size value too big." << endl;
       
   402 							break;
       
   403 						}
       
   404 						else
       
   405 						{
       
   406 							// Value valid.
       
   407 							if ( bAlloc )
       
   408 								args.HOOK.iAllocCallStackSize = i;
       
   409 							else
       
   410 								args.HOOK.iFreeCallStackSize = i;
       
   411 						}
       
   412 					}
       
   413 					else
       
   414 					{
       
   415 						// Error parsing value using stream.
       
   416 						bRet = false;
       
   417 						cout << AT_MSG << "Error, specified call stack size value invalid." << endl;
       
   418 						break;
       
   419 					}
       
   420 
       
   421 				}
       
   422 			}
       
   423 			// Data file name.
       
   424 			else if ( _stricmp( it->c_str(), "-f" ) == 0 )
       
   425 			{
       
   426 				it++;
       
   427 				if ( it == vArgs.end() )
       
   428 				{
       
   429 					bRet = false;
       
   430 					cout << AT_MSG << "Error, missing internal data gathering file name." << endl;
       
   431 					break;
       
   432 				}
       
   433 				else if ( ! _stricmp( it->c_str(), "sbs" ) || ! _stricmp( it->c_str(), "abld" ) )
       
   434 				{
       
   435 					bRet = false;
       
   436 					cout << AT_MSG << "Error, missing internal data gathering file name." << endl;
       
   437 					break;
       
   438 				}
       
   439 				else
       
   440 				{
       
   441 					if ( checkDataFileName( string( *it ) ) )
       
   442 					{
       
   443 						// Pickup filename.
       
   444 						args.HOOK.bDataFileName = true;
       
   445 						args.HOOK.sDataFileName = *it;
       
   446 					}
       
   447 					else
       
   448 					{
       
   449 						bRet = false;
       
   450 						cout << AT_MSG << "Error, specified internal data gathering file name contains invalid character(s)." << endl;
       
   451 						break;
       
   452 					}
       
   453 				}
       
   454 			}
       
   455 			// Build command parsing.
       
   456 			else if ( _stricmp( it->c_str(), "sbs" ) == 0 )
       
   457 			{
       
   458 				bBuildFound = true;
       
   459 				// Use raptor build system, pickup all rest arguments to sbs commmand.
       
   460 				bool bFoundConfig = false; // Have we found config already?
       
   461 				args.HOOK.iBuildSystem = 2;
       
   462 				vector<string>::const_iterator itC = it;
       
   463 				args.HOOK.sBuildCmd.clear();
       
   464 				for ( ; itC != vArgs.end() ; itC++ )
       
   465 				{
       
   466 					args.HOOK.sBuildCmd.append( *itC );
       
   467 					args.HOOK.sBuildCmd.append( " " );
       
   468 					args.HOOK.vBuildCmd.push_back( *itC );
       
   469 				}
       
   470 				// Remove last space
       
   471 				if ( args.HOOK.vBuildCmd.size() > 1 )
       
   472 					args.HOOK.sBuildCmd.erase( args.HOOK.sBuildCmd.size()-1 );
       
   473 
       
   474 				// Parse needed variables from sbs command.
       
   475 				vector<string>::iterator itSbs;
       
   476 				for( itSbs = args.HOOK.vBuildCmd.begin(); itSbs != args.HOOK.vBuildCmd.end() ; itSbs++ )
       
   477 				{
       
   478 					// Program(s).
       
   479 					if ( _stricmp( itSbs->c_str(), "-p" ) == 0 )
       
   480 					{
       
   481 						// Next is program.
       
   482 						itSbs++;
       
   483 						args.HOOK.vTargetPrograms.push_back( *itSbs );
       
   484 					}
       
   485 					else if ( itSbs->find( "--project=" ) != string::npos )
       
   486 					{
       
   487 						itSbs->erase(0, 10 );
       
   488 						args.HOOK.vTargetPrograms.push_back( *itSbs );
       
   489 					}
       
   490 					// platform & build type
       
   491 					else if ( _stricmp( itSbs->c_str(), "-c" ) == 0 )
       
   492 					{
       
   493 						itSbs++;
       
   494 
       
   495 						// Error message if config found more than once.
       
   496 						if ( bFoundConfig )
       
   497 						{
       
   498 							bRet = false;
       
   499 							cout << AT_MSG << "Error, AnalyzeTool does not support defining more than one configuration (platform & build type)." << endl;
       
   500 							continue;
       
   501 						}
       
   502 						bFoundConfig = true;
       
   503 
       
   504 						// Check for '_' which separates platform and type.
       
   505 						if ( itSbs->find("_") != string::npos )
       
   506 						{
       
   507 							args.HOOK.sPlatform = itSbs->substr(0, itSbs->find("_") );
       
   508 							args.HOOK.sBuildType = itSbs->substr( itSbs->find("_")+1, itSbs->size()- itSbs->find("_")+1 );
       
   509 						}
       
   510 						else
       
   511 							args.HOOK.sPlatform = *itSbs;
       
   512 					}
       
   513 					else if ( itSbs->find( "--config=" ) != string::npos )
       
   514 					{
       
   515 						// Error message if config found more than once.
       
   516 						if ( bFoundConfig )
       
   517 						{
       
   518 							bRet = false;
       
   519 							cout << AT_MSG << "Error, AnalyzeTool does not support defining more than one configuration (platform & build type)." << endl;
       
   520 							continue;
       
   521 						}
       
   522 						bFoundConfig = true;
       
   523 
       
   524 						itSbs->erase( 0, 9 );
       
   525 						// Check for '_' which separates platform and type.
       
   526 						if ( itSbs->find("_") != string::npos )
       
   527 						{
       
   528 							args.HOOK.sPlatform = itSbs->substr(0, itSbs->find("_") );
       
   529 							args.HOOK.sBuildType = itSbs->substr( itSbs->find("_")+1, itSbs->size()- itSbs->find("_")+1 );
       
   530 						}
       
   531 						else
       
   532 							args.HOOK.sPlatform = *itSbs;
       
   533 					}
       
   534 				}
       
   535 				// Check platform and build type
       
   536 				if ( args.HOOK.sPlatform.empty() )
       
   537 				{					
       
   538 					// not platform was found.
       
   539 					cout << AT_MSG << "Error, no supported platform found in sbs parameters (armv5/winscw/gcce)." << endl;
       
   540 					bRet = false;
       
   541 				}
       
   542 				else
       
   543 				{
       
   544 					// check is platform supported.
       
   545 					bool bOk = false;
       
   546 					if ( _stricmp( args.HOOK.sPlatform.c_str(), "armv5" ) == 0 )
       
   547 						bOk = true;
       
   548 					else if ( _stricmp( args.HOOK.sPlatform.c_str(), "winscw" ) == 0 )
       
   549 						bOk = true;
       
   550 					else if ( _stricmp( args.HOOK.sPlatform.c_str(), "gcce" ) == 0 )
       
   551 						bOk = true;
       
   552 					if ( ! bOk )
       
   553 					{
       
   554 						// not supported.
       
   555 						cout << AT_MSG << "Error, no supported platform found in sbs parameters (armv5/winscw/gcce)." << endl;
       
   556 						bRet = false;
       
   557 					}
       
   558 				}
       
   559 				if ( args.HOOK.sBuildType.empty() )
       
   560 				{
       
   561 					// no build type specified.
       
   562 					cout << AT_MSG << "Error, no build type specified in sbs parameters (udeb/urel)." << endl;
       
   563 					bRet = false;
       
   564 				}
       
   565 				else
       
   566 				{
       
   567 					// check is build type supported.
       
   568 					bool bOk = false;
       
   569 					if ( _stricmp( args.HOOK.sBuildType.c_str(), "urel" ) == 0 )
       
   570 						bOk = true;
       
   571 					else if ( _stricmp( args.HOOK.sBuildType.c_str(), "udeb" ) == 0 )
       
   572 						bOk = true;
       
   573 					if ( ! bOk )
       
   574 					{
       
   575 						// not supported.
       
   576 						cout << AT_MSG << "Error, no build type specified in sbs parameters (udeb/urel)." << endl;
       
   577 						bRet = false;
       
   578 					}
       
   579 				}
       
   580 			}
       
   581 			else if ( _stricmp( it->c_str(), "abld" ) == 0 )
       
   582 			{
       
   583 				bBuildFound = true;
       
   584 				// Use abld build system, pickup all rest argumenst as abld options.
       
   585 				args.HOOK.iBuildSystem = 1;
       
   586 				
       
   587 				vector<string>::const_iterator itC = it;
       
   588 				args.HOOK.sBuildCmd.clear();
       
   589 				for ( ; itC != vArgs.end() ; itC++ )
       
   590 				{
       
   591 					args.HOOK.sBuildCmd.append( *itC );
       
   592 					args.HOOK.sBuildCmd.append( " " );
       
   593 					args.HOOK.vBuildCmd.push_back( *itC );
       
   594 				}
       
   595 				
       
   596 				string sCmd( args.HOOK.sBuildCmd ); // build command to lower case here.
       
   597 				for( size_t i = 0 ; i < sCmd.size(); i++ )
       
   598 					sCmd.at(i) = tolower( sCmd.at(i) );
       
   599 				
       
   600 				sCmd.erase(0,11); // remove "abld build "
       
   601 				
       
   602 				//Is -debug switch in command?
       
   603 				if( sCmd.find( "-debug " ) != string::npos )
       
   604 				{
       
   605 					sCmd.erase( sCmd.find( "-debug " ), 7 );
       
   606 				}
       
   607 
       
   608 				// Parse needed "variables" from command.
       
   609 				bool bOk = false;
       
   610 
       
   611 				// Find platform
       
   612 				if ( sCmd.find( "armv5" ) != string::npos )
       
   613 				{
       
   614 					bOk = true;
       
   615 					args.HOOK.sPlatform = "armv5";
       
   616 					sCmd.erase( sCmd.find( "armv5" ), 5 );
       
   617 				}
       
   618 				else if ( sCmd.find( "winscw" ) != string::npos )
       
   619 				{
       
   620 					bOk = true;
       
   621 					args.HOOK.sPlatform = "winscw";
       
   622 					sCmd.erase( sCmd.find( "winscw" ), 6 );
       
   623 				}
       
   624 				else if ( sCmd.find( "gcce" ) != string::npos )
       
   625 				{
       
   626 					bOk = true;
       
   627 					args.HOOK.sPlatform = "gcce";
       
   628 					sCmd.erase( sCmd.find( "gcce" ), 4 );
       
   629 				}
       
   630 				if ( bOk )
       
   631 				{
       
   632 					// Feature variant.
       
   633 					if ( sCmd.at(0 ) == '.' )
       
   634 					{
       
   635 						sCmd.erase(0,1);
       
   636 						args.HOOK.sFeatureVariant = sCmd.substr( 0, sCmd.find_first_of(' ') );
       
   637 						sCmd.erase(0, sCmd.find_first_of(' ')+1 );
       
   638 					}
       
   639 				}
       
   640 				else
       
   641 				{
       
   642 					// not platform specified.
       
   643 					cout << AT_MSG << "Error, no supported platform found in abld parameters (armv5/winscw/gcce)." << endl;
       
   644 					bRet = false;
       
   645 				}
       
   646 				
       
   647 				// find build type
       
   648 				bOk = false;
       
   649 				if (  sCmd.find( "urel" ) != string::npos )
       
   650 				{
       
   651 					bOk = true;
       
   652 					args.HOOK.sBuildType = "urel";
       
   653 					sCmd.erase( sCmd.find( "urel" ), 4 );
       
   654 				}
       
   655 
       
   656 				else if ( sCmd.find( "udeb" ) != string::npos )
       
   657 				{
       
   658 					bOk = true;
       
   659 					args.HOOK.sBuildType = "udeb";
       
   660 					sCmd.erase( sCmd.find( "udeb" ), 4 );
       
   661 				}
       
   662 				if( !bOk )
       
   663 				{
       
   664 					// no build type specified.
       
   665 					cout << AT_MSG << "Error, no build type specified in abld parameters (udeb/urel)." << endl;
       
   666 					bRet = false;
       
   667 				}
       
   668 		
       
   669 				// Is there multiple programs (only should be used from extension).
       
   670 				if ( sCmd.find(" -p") != string::npos )
       
   671 				{
       
   672 					sCmd.erase( sCmd.find(" -p" ), sCmd.size() - sCmd.find(" -p" ) );
       
   673 					// Loop thru all parameters and pick up programs.
       
   674 					vector<string>::iterator it;
       
   675 					for( it = args.HOOK.vBuildCmd.begin(); it != args.HOOK.vBuildCmd.end(); it++ )
       
   676 					{
       
   677 						if ( _stricmp( it->c_str(), "-p" ) == 0 )
       
   678 						{
       
   679 							// Next is program.
       
   680 							it++;
       
   681 							string sProgram = *it;
       
   682 							// Make sure program name ends with ".mmp".
       
   683 							CATBase::ChangeToLower( sProgram );
       
   684 							if ( sProgram.length() >= 4 )
       
   685 							{
       
   686                                 string sEnd = sProgram.substr( sProgram.length()-4, 4 );
       
   687 								if ( sEnd.compare( ".mmp" ) != 0 )
       
   688 									sProgram.append( ".mmp" );
       
   689 							}
       
   690 							else
       
   691 								sProgram.append( ".mmp" );
       
   692 							args.HOOK.vTargetPrograms.push_back( sProgram );
       
   693 						}
       
   694 					}
       
   695 				}
       
   696 				else {
       
   697 					// find single defined program.
       
   698 					if ( sCmd.find_first_not_of(' ') != string::npos )
       
   699 					{
       
   700 						size_t iS = sCmd.find_first_not_of(' ');
       
   701 						size_t iE = sCmd.find_first_of(' ', iS );
       
   702 						string sProgram;
       
   703 						if ( iE == string::npos )
       
   704 							sProgram = sCmd.substr( iS, sCmd.size()-iS );
       
   705 						else
       
   706 							sProgram =  sCmd.substr( iS, iE-iS);
       
   707 						// Make sure program name ends with ".mmp".
       
   708 						CATBase::ChangeToLower( sProgram );
       
   709 						if ( sProgram.length() >= 4 )
       
   710 						{
       
   711                             string sEnd = sProgram.substr( sProgram.length()-4, 4 );
       
   712 							if ( sEnd.compare( ".mmp" ) != 0 )
       
   713 								sProgram.append( ".mmp" );
       
   714 						}
       
   715 						else
       
   716 							sProgram.append( ".mmp" );
       
   717 						args.HOOK.vTargetPrograms.push_back( sProgram );
       
   718 					}
       
   719 				}
       
   720 			}
       
   721 			else
       
   722 			{
       
   723 				if ( ! bBuildFound )
       
   724 				{
       
   725 					bRet = false;
       
   726 					cout << AT_MSG << "Error, invalid parameter :" << *it << endl;
       
   727 					break;
       
   728 				}
       
   729 			}
       
   730 		}
       
   731 	}
       
   732 	catch(...)
       
   733 	{
       
   734 		bRet = false;
       
   735 		cout << AT_MSG << "Error parsing arguments." << endl;
       
   736 	}
       
   737 	return bRet;
       
   738 }
       
   739 
       
   740 
       
   741 /**
       
   742 * Parse old style hooking related arguments from given vector of strings.
       
   743 */
       
   744 bool parseOldHookArguments( vector<string>& vArgs, ARGUMENTS& args )
       
   745 {
       
   746 	// Only supporting extension here atm.
       
   747 	// This is frozen do not change anything in this else if.
       
   748 	bool bRet = true;
       
   749 	vector<string>::iterator it = vArgs.begin()+1;
       
   750 	string sMmpFileName;
       
   751 	string sPhoneDataFileName;
       
   752 	vector<string> vMmpFileNames;
       
   753 	string sVariant;
       
   754 	bool bBuildUdeb = true;
       
   755 	bool bLogTargetS60 = false;
       
   756 	bool bLogTargetXTI = false;
       
   757 	bool bPhoneDataFileName = false;
       
   758 	bool bMmpFileName = false;
       
   759 	bool bVariant = false;
       
   760 	bool bEmulator = false;
       
   761 	bool bGcce = false;
       
   762 
       
   763 	while( it != vArgs.end() )
       
   764 	{
       
   765 		string sArgument( *it );
       
   766 		CATBase::ChangeToLower( sArgument );
       
   767 		//Mmp filename given?
       
   768 		if( sArgument.find( ".mmp" ) != string::npos )
       
   769 		{
       
   770 			if( bMmpFileName && ! args.bEnableSbs2 )
       
   771 			{
       
   772 				cout<<INVALID_PARAMETER<<*it<<"."<<endl;
       
   773 				return 0;
       
   774 			}
       
   775 			sMmpFileName = *it;
       
   776 			vMmpFileNames.push_back( *it );
       
   777 			bMmpFileName = true;
       
   778 		}
       
   779 		else
       
   780 		//Logging mode XTI?
       
   781 		if( stricmp( sArgument.c_str(), LOG_XTI ) == 0 )
       
   782 		{
       
   783 			if ( bLogTargetS60 )
       
   784 			{
       
   785 				cout<<INVALID_PARAMETER<<*it<<"."<<endl;
       
   786 				return 0;
       
   787 			}
       
   788 			bLogTargetXTI = true;
       
   789 		}
       
   790 		else
       
   791 		//Logging mode S60?
       
   792 		if( stricmp( sArgument.c_str(), LOG_S60 ) == 0 )
       
   793 		{
       
   794 			if ( bLogTargetXTI )
       
   795 			{
       
   796 				cout<<INVALID_PARAMETER<<*it<<"."<<endl;
       
   797 				return 0;
       
   798 			}
       
   799 			bLogTargetS60 = true;
       
   800 		}
       
   801 		else
       
   802 		//Variant
       
   803 		//if( sArgument.find( "-variant" ) != string::npos )
       
   804 		if( stricmp( sArgument.c_str(), "-variant") == 0 )
       
   805 		{
       
   806 			// use variant
       
   807 			bVariant = true;
       
   808 			// pickup variant name
       
   809 			it++;
       
   810 			if ( it == vArgs.end() )
       
   811 			{
       
   812 				cout << "When using -variant, variant name must be specified." << endl;
       
   813 				return 0;
       
   814 			}
       
   815 			sVariant.append( *it );
       
   816 		}
       
   817 		else
       
   818 		//Build urel?
       
   819 		if( stricmp( sArgument.c_str(), "urel" ) == 0 )
       
   820 		{
       
   821 			bBuildUdeb = false;
       
   822 		}
       
   823 		else
       
   824 		//Build udeb?
       
   825 		//if( sArgument.find( "udeb" ) != string::npos && sArgument.length() == 4)
       
   826 		if( stricmp( sArgument.c_str(), "udeb" ) == 0 )
       
   827 		{
       
   828 			bBuildUdeb = true;
       
   829 		}
       
   830 		else
       
   831 		//Build for emulator
       
   832 		if( stricmp( sArgument.c_str(), "-e" ) == 0 || stricmp( sArgument.c_str(), "-winscw") == 0 )
       
   833 		{
       
   834 			bEmulator = true;
       
   835 		}
       
   836 		else
       
   837 		if( stricmp( sArgument.c_str(), "-gcce") == 0 )
       
   838 		{
       
   839 			bGcce = true;
       
   840 		}
       
   841 		else
       
   842 		//Assume its data file name
       
   843 		if( bLogTargetS60 )
       
   844 		{
       
   845 			if ( bPhoneDataFileName )
       
   846 			{
       
   847 				cout<<INVALID_PARAMETER<<*it<<"."<<endl;
       
   848 				bRet = false;
       
   849 			}
       
   850 			// Check that datafile name is <= 50 chars long
       
   851 			if ( sArgument.size() > 50 )
       
   852 			{
       
   853 				cout << AT_MSG << "Error, specified datafile name too long (Max 50 chars)." << endl;
       
   854 				bRet = false;
       
   855 			}
       
   856 			sPhoneDataFileName = sArgument;
       
   857 			bPhoneDataFileName = true;
       
   858 		}
       
   859 		// unregognized build parameter
       
   860 		else
       
   861 		{
       
   862 			// print error and exit 
       
   863 			cout<<INVALID_PARAMETER<<*it<<"."<<endl;
       
   864 			bRet = false;
       
   865 		}
       
   866 		it++;
       
   867 	}
       
   868 	// platform
       
   869 	if ( bEmulator )
       
   870 		args.HOOK.sPlatform = "winscw";
       
   871 	else
       
   872 		args.HOOK.sPlatform = "armv5";
       
   873 	if ( bGcce )
       
   874 		args.HOOK.sPlatform = "gcce";
       
   875 	// build type
       
   876 	if ( bBuildUdeb )
       
   877 		args.HOOK.sBuildType = "udeb";
       
   878 	else
       
   879 		args.HOOK.sBuildType = "urel";
       
   880 	// Variant
       
   881 	if ( bVariant )
       
   882 		args.HOOK.sFeatureVariant = sVariant;
       
   883 	if ( ! bLogTargetS60 && ! bLogTargetXTI )
       
   884 		args.HOOK.iLoggingMode = 1;
       
   885 	if ( bLogTargetS60 )
       
   886 		args.HOOK.iLoggingMode = 2;
       
   887 	else if ( bLogTargetXTI )
       
   888 		args.HOOK.iLoggingMode = 1;
       
   889 	// If selected modules to be compiled
       
   890 	if ( vMmpFileNames.size() > 0 )
       
   891 		args.HOOK.vTargetPrograms = vMmpFileNames;
       
   892 	// S60 data file name
       
   893 	if ( ! sPhoneDataFileName.empty() )
       
   894 	{
       
   895 		args.HOOK.bDataFileName = true;
       
   896 		args.HOOK.sDataFileName = sPhoneDataFileName;
       
   897 	}
       
   898 	return bRet;
       
   899 }
       
   900 
       
   901 /**
       
   902 * Parse HTI related arguments from given vector of strings.
       
   903 */
       
   904 bool parseHtiArguments( vector<string>& /* vArgs */, ARGUMENTS& /* args*/)
       
   905 {
       
   906 	//Implementation currently in hti.cpp, should be moved here.
       
   907 	return false;
       
   908 }
       
   909 
       
   910 /**
       
   911 * Parse trace parsing related arguments from given vector of strings.
       
   912 */
       
   913 bool parseParseArguments( vector<string>& vArgs, ARGUMENTS& args )
       
   914 {
       
   915 	// Iterator used in this function.
       
   916 	vector<string>::const_iterator it = vArgs.begin();
       
   917 
       
   918 	if ( it == vArgs.end() )
       
   919 		return false;
       
   920 
       
   921 	it++;
       
   922 
       
   923 	if ( it == vArgs.end() )
       
   924 	{
       
   925 		cout << AT_MSG << "Error, input file not defined (raw data file)." << endl;
       
   926 		return false;
       
   927 	}
       
   928 
       
   929 	//Input.
       
   930 	args.PARSE.bDataFile = true;
       
   931 	args.PARSE.sDataFile = *it;
       
   932 	
       
   933 	it++;
       
   934 	if ( it == vArgs.end() )
       
   935 	{
       
   936 	
       
   937 		cout << AT_MSG << "Error, output file not defined (device data file)." << endl;
       
   938 		return false;
       
   939 	}
       
   940 
       
   941 	//Output.
       
   942 	args.PARSE.bOutputFile = true;
       
   943 	args.PARSE.sOutputFile = *it;
       
   944 	return true;
       
   945 }
       
   946 
       
   947 //EOF